Exemple #1
0
int PyObj_setfurntype(PyObject *self, PyObject *value, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) {
    PyErr_Format(PyExc_StandardError, "Tried to set furniture type for "
		 "nonexistent furniture, %d", PyObj_AsUid(self));
    return -1;
  }
  else if(!objIsType(obj, "furniture")) {
    PyErr_Format(PyExc_TypeError, "Tried to set furniture type for "
		 "non-furniture, %s", objGetClass(obj));
    return -1;
  }

  if(!PyString_Check(value)) {
    PyErr_Format(PyExc_TypeError, "furniture type must be a string.");
    return -1;
  }
  else if(furnitureTypeGetNum(PyString_AsString(value)) == FURNITURE_NONE) {
    PyErr_Format(PyExc_TypeError, "Invalid furniture type, %s", 
		 PyString_AsString(value));
    return -1;
  }

  furnitureSetType(obj, furnitureTypeGetNum(PyString_AsString(value)));
  return 0;
}
Exemple #2
0
int PyObj_setcontainerlocked  (PyObject *self, PyObject *value, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) {
    PyErr_Format(PyExc_StandardError, "Tried to change locked on nonexistent "
		 "container, %d", PyObj_AsUid(self));
    return -1;
  }
  else if(!objIsType(obj, "container")) {
    PyErr_Format(PyExc_TypeError, "Tried to set locked for non-container, %s",
		 objGetClass(obj));
    return -1;
  }

  if(!PyInt_Check(value)) {
    PyErr_Format(PyExc_TypeError, "container lock status must be a boolean.");
    return -1;
  }

  containerSetLocked(obj, PyInt_AsLong(value));
  if(PyInt_AsLong(value) != 0) {
    containerSetClosable(obj, TRUE);
    containerSetClosed(obj, TRUE);
  }
  return 0;
}
Exemple #3
0
PyObject *PyObj_getcontainerpickdiff(PyObject *self, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) return NULL;
  else if(objIsType(obj, "container"))
    return Py_BuildValue("i", containerGetPicKDiff(obj));
  else {
    PyErr_Format(PyExc_TypeError, "Can only check pick diffs on containers.");
    return NULL;
  }
}
Exemple #4
0
PyObject *PyObj_getcontainerlocked  (PyObject *self, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) return NULL;
  else if(objIsType(obj, "container"))
    return Py_BuildValue("i", containerIsLocked(obj));
  else {
    PyErr_Format(PyExc_TypeError, "Can only check if containers are locked.");
    return NULL;
  }
}
Exemple #5
0
PyObject *PyObj_getfurntype(PyObject *self, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL)
    return NULL;
  else if(objIsType(obj, "furniture"))
    return Py_BuildValue("s", furnitureTypeGetName(furnitureGetType(obj)));
  else {
    PyErr_Format(PyExc_TypeError, "Can only get furniture type for furniture.");
    return NULL;
  }
}
Exemple #6
0
//*****************************************************************************
// pyobj getters and setters
//*****************************************************************************
PyObject *PyObj_getfurncapacity(PyObject *self, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL)
    return NULL;
  else if(objIsType(obj, "furniture"))
    return Py_BuildValue("i", furnitureGetCapacity(obj));
  else {
    PyErr_Format(PyExc_TypeError, "Can only get capacity for furniture.");
    return NULL;
  }
}
Exemple #7
0
PyObject *PyObj_getcontainerkey(PyObject *self, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL)
    return NULL;
  else if(objIsType(obj, "container"))
    return Py_BuildValue("s", containerGetKey(obj));
  else {
    PyErr_Format(PyExc_TypeError, "Can only get keys for containers.");
    return NULL;
  }
}
Exemple #8
0
int PyObj_setcontainerkey(PyObject *self, PyObject *value, void *closure) {
  OBJ_DATA   *obj = PyObj_AsObj(self);
  const char *key = NULL;
  if(obj == NULL) {
    PyErr_Format(PyExc_StandardError, "Tried to set key for nonexistent "
		 "container, %d", PyObj_AsUid(self));
    return -1;
  }
  else if(!objIsType(obj, "container")) {
    PyErr_Format(PyExc_TypeError, "Tried to set key for non-container, %s",
		 objGetClass(obj));
    return -1;
  }

  if(PyString_Check(value))
    key =get_fullkey(PyString_AsString(value),get_key_locale(objGetClass(obj)));
  else if(PyObj_Check(value)) {
    OBJ_DATA *key_obj = PyObj_AsObj(value);
    if(key_obj != NULL)
      key = objGetClass(key_obj);
    else {
      PyErr_Format(PyExc_TypeError, "Tried to set key for %s as nonexistaent "
		   "obj, %d", objGetClass(obj), PyObj_AsUid(value));
      return -1;
    }
  }

  // make sure we have a key
  if(key == NULL) {
    PyErr_Format(PyExc_TypeError, "Container keys must be strings or objects.");
    return -1;
  }

  containerSetKey(obj, key);
  return 0;
}
Exemple #9
0
int PyObj_setfurncapacity(PyObject *self, PyObject *value, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) {
    PyErr_Format(PyExc_StandardError, "Tried to set capacity for nonexistent "
		 "furniture, %d", PyObj_AsUid(self));
    return -1;
  }
  else if(!objIsType(obj, "furniture")) {
    PyErr_Format(PyExc_TypeError, "Tried to set capacity for non-furniture, %s",
		 objGetClass(obj));
    return -1;
  }

  if(!PyInt_Check(value)) {
    PyErr_Format(PyExc_TypeError, "furniture capacity must be an integer.");
    return -1;
  }

  furnitureSetCapacity(obj, PyInt_AsLong(value));
  return 0;
}
Exemple #10
0
int PyObj_setcontainerpickdiff(PyObject *self, PyObject *value, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) {
    PyErr_Format(PyExc_StandardError, "Tried to change pickdiff on nonexistent "
		 "container, %d", PyObj_AsUid(self));
    return -1;
  }
  else if(!objIsType(obj, "container")) {
    PyErr_Format(PyExc_TypeError, "Tried to set pick for non-container, %s",
		 objGetClass(obj));
    return -1;
  }

  if(!PyInt_Check(value)) {
    PyErr_Format(PyExc_TypeError, "container pickdiff must be an integer.");
    return -1;
  }

  containerSetPickDiff(obj, PyInt_AsLong(value));
  return 0;
}
Exemple #11
0
int PyObj_setcontainercapacity(PyObject *self, PyObject *value, void *closure) {
  OBJ_DATA *obj = PyObj_AsObj(self);
  if(obj == NULL) {
    PyErr_Format(PyExc_StandardError, "Tried to set capacity for nonexistent "
		 "container, %d", PyObj_AsUid(self));
    return -1;
  }
  else if(!objIsType(obj, "container")) {
    PyErr_Format(PyExc_TypeError, "Tried to set capacity for non-container, %s",
		 objGetClass(obj));
    return -1;
  }

  if(!PyFloat_Check(value)) {
    PyErr_Format(PyExc_TypeError, "container capacity must be a double.");
    return -1;
  }

  containerSetCapacity(obj, PyFloat_AsDouble(value));
  return 0;
}
Exemple #12
0
//
// interrupt an event involving the given room, object, or mobile
PyObject *PyEvent_interrupt_event(PyObject *self, PyObject *args) {
  PyObject *PyOwner = NULL; // the python representation of our owner

  // parse our owner
  if(!PyArg_ParseTuple(args, "O", &PyOwner)) {
    PyErr_Format(PyExc_TypeError,
		 "A target must be specified for interrupting events.");
    return NULL;
  }

  // check the possibilities
  if(PyOwner == Py_None)
    interrupt_events_involving(NULL);
  else if(PyChar_Check(PyOwner))
    interrupt_events_involving(PyChar_AsChar(PyOwner));
  else if(PyRoom_Check(PyOwner))
    interrupt_events_involving(PyRoom_AsRoom(PyOwner));
  else if(PyObj_Check(PyOwner))
    interrupt_events_involving(PyObj_AsObj(PyOwner));

  // everything ok
  return Py_BuildValue("i", 1);
}
Exemple #13
0
//
// no point in reinventing the wheel; start_event and start_update both
// need to be handled exactly the same, so here's a function to do just that
PyObject *PyEvent_start(PyObject *self, PyObject *args, void *func) {
  void (* start_func)(void *, int, void *, void *, void *, const char *) = func;
  PyObject *PyOwner = NULL;    // the python representation of our owner
  PyObject   *efunc = NULL;    // the event function
  PyObject   *edata = Py_None; // the event data
  char         *arg = NULL;    // the arg we will be supplying to the function
  double      delay = 0;       // how long the event delay is (in seconds)
  void       *owner = NULL;    // actual owner supplied to the event handler
  char    otype[20];           // is the owner a char, room, obj, or None?

  // try to parse all of our values
  if(!PyArg_ParseTuple(args, "OdO|Os", &PyOwner, &delay, &efunc, &edata, &arg)){
    //PyErr_Format(PyExc_TypeError, 
    //"Invalid arguments provided to event handler");
    return NULL;
  }

  // make sure our event is a function
  if(!PyFunction_Check(efunc)) {
    PyErr_Format(PyExc_TypeError,
		 "The event handler supplied must be a python function");
    return NULL;
  }

  // figure out what type of data our owner is
  if(PyOwner == Py_None) {
    owner = NULL;
    sprintf(otype, "none");
  }
  else if(PyChar_Check(PyOwner)) {
    owner = PyChar_AsChar(PyOwner);
    sprintf(otype, "char");
  }
  else if(PyRoom_Check(PyOwner)) {
    owner = PyRoom_AsRoom(PyOwner);
    sprintf(otype, "room");
  }
  else if(PyObj_Check(PyOwner)) {
    owner = PyObj_AsObj(PyOwner);
    sprintf(otype, "obj");
  }
  // invalid type
  else {
    PyErr_Format(PyExc_TypeError,
		 "An event owner must be a room, char, obj, or none");
    return NULL;
  }

  // make sure the owner exists
  if(PyOwner != Py_None && owner == NULL) {
    PyErr_Format(PyExc_StandardError, "Owner supplied does not exist in game");
    return NULL;
  }
  
  // now, queue up the action
  start_func(owner, (int)(delay SECONDS), PyEvent_on_complete, NULL, 
	     Py_BuildValue("sOO", otype, efunc, edata), arg);

  // everything seems ok. exit normally
  return Py_BuildValue("i", 1);
}
PyObject *py_gen_do_trigs(PyObject *self, PyObject *args, PyObject *kwds) {
  static char *kwlist[] ={ "type","ch","obj","room","exit","cmd","arg","opts",NULL };
  char       *type = NULL;
  char        *cmd = NULL;
  char        *arg = NULL;
  PyObject   *pych = NULL;
  PyObject  *pyobj = NULL;
  PyObject *pyroom = NULL;
  PyObject *pyexit = NULL;
  PyObject *pyopts = NULL;
  LIST       *opts = NULL;
  CHAR_DATA    *ch = NULL;
  OBJ_DATA    *obj = NULL;
  ROOM_DATA  *room = NULL;
  EXIT_DATA  *exit = NULL;
  void         *me = NULL;
  int      me_type = -1;
  bool        fail = FALSE;

  // first, parse all of our arguments
  if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|OOOOssO", kwlist, 
				  &type, &pych, &pyobj, &pyroom, &pyexit,
				  &cmd, &arg, &pyopts)) {
    PyErr_Format(PyExc_TypeError, "do_trigs supplied invalid arguments.");
    return NULL;
  }

  // make sure we exist, and are of a valid type
  if(PyChar_Check(self)) {
    me = PyChar_AsChar(self);
    me_type = TRIGVAR_CHAR;
  }
  else if(PyObj_Check(self)) {
    me = PyObj_AsObj(self);
    me_type = TRIGVAR_OBJ;
  }
  else if(PyRoom_Check(self)) {
    me = PyRoom_AsRoom(self);
    me_type = TRIGVAR_ROOM;
  }

  // did we find a character?
  if(me == NULL) {
    PyErr_Format(PyExc_TypeError,"do_trigs owner does not exist.");
    return NULL;
  }

  // make sure ch is of the specified type
  if(pych!=NULL && (!PyChar_Check(pych) || (ch=PyChar_AsChar(pych)) == NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects ch to be character.");
    return NULL;
  }

  // make sure obj is of the specified type
  if(pyobj!=NULL && (!PyObj_Check(pyobj) || (obj=PyObj_AsObj(pyobj)) == NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects obj to be object.");
    return NULL;
  }

  // make sure room is of the specified type
  if(pyroom!=NULL&&(!PyRoom_Check(pyroom)||(room=PyRoom_AsRoom(pyroom))==NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects room to be room.");
    return NULL;
  }

  // make sure exit is of the specified type
  if(pyexit!=NULL&&(!PyExit_Check(pyexit)||(exit=PyExit_AsExit(pyexit))==NULL)){
    PyErr_Format(PyExc_TypeError,"do_trigs expects exit to be an exit.");
    return NULL;
  }

  // parse opts
  if(pyopts != NULL && !PyDict_Check(pyopts)) {
    PyErr_Format(PyExc_TypeError,"do_trigs expects opts to be a dict.");
    return NULL;
  }
  else if(pyopts != NULL) {
    PyObject  *pairs = PyDict_Items(pyopts);
    int            i = 0;
    opts             = newList();
    // go through each pair and add it to the pyopts list
    for(; i < PyList_Size(pairs); i++) {
      PyObject  *pair = PyList_GetItem(pairs, i);
      PyObject *pykey = PyTuple_GetItem(pair, 0);
      PyObject *pyval = PyTuple_GetItem(pair, 1);
      OPT_VAR    *opt = NULL;
      char       *key = NULL;

      // make sure the key is a string
      if(PyString_Check(pykey))
	key = PyString_AsString(pykey);
      else {
	PyErr_Format(PyExc_TypeError, "do_trigs opt keys must be strings.");
	fail = TRUE;
	break;
      }

      // check to make sure the val is a valid type
      if(PyChar_Check(pyval)) {
	CHAR_DATA *val = PyChar_AsChar(pyval);
	if(val != NULL)
	  opt = newOptVar(key, val, TRIGVAR_CHAR);
	else {
	  PyErr_Format(PyExc_TypeError,"%s opt provided nonexistent char.",key);
	  fail = TRUE;
	  break;
	}
      }
      else if(PyObj_Check(pyval)) {
	OBJ_DATA *val = PyObj_AsObj(pyval);
	if(val != NULL)
	  opt = newOptVar(key, val, TRIGVAR_OBJ);
	else {
	  PyErr_Format(PyExc_TypeError,"%s opt provided nonexistent obj.", key);
	  fail = TRUE;
	  break;
	}
      }
      else if(PyRoom_Check(pyval)) {
	ROOM_DATA *val = PyRoom_AsRoom(pyval);
	if(val != NULL)
	  opt = newOptVar(key, val, TRIGVAR_ROOM);
	else {
	  PyErr_Format(PyExc_TypeError,"%s opt provided nonexistent room.",key);
	  fail = TRUE;
	  break;
	}
      }
      else {
	PyErr_Format(PyExc_TypeError,"%s opt provided invalid value.",key);
	fail = TRUE;
	break;
      }

      // append the opt to the opt list
      listPut(opts, opt);
    }
    Py_DECREF(pairs);
  }

  // did everything succeed?
  if(fail == FALSE)
    gen_do_trigs(me,me_type,type,ch,obj,room,exit,cmd,arg,opts);

  // garbage collection
  if(opts != NULL)
    deleteListWith(opts, deleteOptVar);

  if(fail == TRUE)
    return NULL;
  return Py_BuildValue("");
}