void expand_char_dynamic_descs(const char *info) { CHAR_DATA *me = NULL; CHAR_DATA *ch = NULL; hookParseInfo(info, &me, &ch); // if we're an NPC, do some special work for displaying us. We don't do // dynamic descs for PCs because they will probably be describing themselves, // and we don't want to give them access to the scripting language. //if(charIsNPC(me)) { PyObject *pyme = charGetPyForm(me); char *locale = strdup(get_key_locale(charGetClass(me))); expand_dynamic_descs(charGetLookBuffer(ch), pyme, ch, locale); Py_DECREF(pyme); free(locale); //} }
// // 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); }