Пример #1
0
void expand_exit_dynamic_descs(const char *info) {
  EXIT_DATA *me = NULL;
  CHAR_DATA *ch = NULL;
  hookParseInfo(info, &me, &ch);

  PyObject *pyme = newPyExit(me);
  char   *locale = strdup(get_key_locale(roomGetClass(exitGetRoom(me)))); 
  expand_dynamic_descs(charGetLookBuffer(ch), pyme, ch, locale);
  Py_DECREF(pyme);
  free(locale);
}
Пример #2
0
//
// generalized function for setting up a dictionary and running a trigger. The
// common types of variables can be supplied in the function. Additional ones
// can be added in the optional list, which must be deleted after use
void gen_do_trig(TRIGGER_DATA *trig, 
		 void *me, int me_type, CHAR_DATA *ch, OBJ_DATA *obj,
		 ROOM_DATA *room, EXIT_DATA *exit, const char *command,
		 const char *arg, LIST *optional) {
  // make our basic dictionary, and fill it up with these new variables
  PyObject *dict = restricted_script_dict();
  LIST *varnames = newList(); 
  // now, import all of our variables
  if(command) {
    PyObject *pycmd = PyString_FromString(command);
    PyDict_SetItemString(dict, "cmd", pycmd);
    listPut(varnames, strdup("cmd"));
    Py_DECREF(pycmd);
  }
  if(arg) {
    PyObject *pyarg = PyString_FromString(arg);
    PyDict_SetItemString(dict, "arg", pyarg);
    listPut(varnames, strdup("arg"));
    Py_DECREF(pyarg);
  }
  if(ch) {
    PyObject *pych = charGetPyForm(ch);
    PyDict_SetItemString(dict, "ch", pych);
    listPut(varnames, strdup("ch"));
    Py_DECREF(pych);
  }
  if(room) {
    PyObject *pyroom = roomGetPyForm(room);
    PyDict_SetItemString(dict, "room", pyroom);
    listPut(varnames, strdup("room"));
    Py_DECREF(pyroom);
  }    
  if(obj) {
    PyObject *pyobj = objGetPyForm(obj);
    PyDict_SetItemString(dict, "obj", pyobj);
    listPut(varnames, strdup("obj"));
    Py_DECREF(pyobj);
  }
  if(exit) {
    PyObject *pyexit = newPyExit(exit);
    PyDict_SetItemString(dict, "ex", pyexit);
    listPut(varnames, strdup("ex"));
    Py_DECREF(pyexit);
  }

  // add the thing the trigger is attached to
  if(me) {
    PyObject *pyme = NULL;
    switch(me_type) {
    case TRIGVAR_CHAR:  pyme = charGetPyForm(me); break;
    case TRIGVAR_OBJ:   pyme = objGetPyForm(me);  break;
    case TRIGVAR_ROOM:  pyme = roomGetPyForm(me); break;
    }
    PyDict_SetItemString(dict, "me", pyme);
    listPut(varnames, strdup("me"));
    Py_DECREF(pyme);
  }

  // now, add any optional variables
  if(optional) {
    LIST_ITERATOR *opt_i = newListIterator(optional);
    OPT_VAR         *opt = NULL;
    PyObject      *pyopt = NULL;
    ITERATE_LIST(opt, opt_i) {
      pyopt = NULL;
      switch(opt->type) {
      case TRIGVAR_CHAR:  pyopt = charGetPyForm(opt->data); break;
      case TRIGVAR_OBJ:   pyopt = objGetPyForm(opt->data);  break;
      case TRIGVAR_ROOM:  pyopt = roomGetPyForm(opt->data); break;
      }
      PyDict_SetItemString(dict, opt->name, pyopt);
      listPut(varnames, strdup(opt->name));
      Py_XDECREF(pyopt);
    } deleteListIterator(opt_i);
  }