--- deliantra/server/plugins/cfperl/cfperl.xs 2006/03/07 13:48:27 1.31 +++ deliantra/server/plugins/cfperl/cfperl.xs 2006/03/31 19:47:55 1.43 @@ -44,6 +44,7 @@ #endif #include +#include #include @@ -78,6 +79,13 @@ static HV *obj_cache; static PerlInterpreter *perl; +#define PUSHcfapi(type,ctype) PUSHs (sv_2mortal (newSVcfapi ((type), va_arg (args, ctype)))) +#define PUSH_OB PUSHcfapi(CFAPI_POBJECT, object *) +#define PUSH_PL PUSHcfapi(CFAPI_PPLAYER, player *) +#define PUSH_MAP PUSHcfapi(CFAPI_PMAP, mapstruct *) +#define PUSH_PV PUSHcfapi(CFAPI_STRING, const char *) +#define PUSH_IV PUSHcfapi(CFAPI_INT, int) + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // garbage collect some perl objects, if possible @@ -218,7 +226,7 @@ break; case CFAPI_LONG: - sv = newSViv (*va_arg (args, long *)); + sv = newSVnv ((double)*va_arg (args, sint64 *)); /* oh, the humanity! */ break; case CFAPI_DOUBLE: @@ -297,6 +305,8 @@ PUSHMARK (SP); + EXTEND (SP, 10); + HV *hv = newHV (); #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) hv_context (CFAPI_POBJECT, ,who); @@ -309,7 +319,7 @@ hv_context (CFAPI_STRING , ,options); hv_context (CFAPI_STRING , ,extension); - XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); + PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); PUTBACK; int count = call_pv (func, G_SCALAR | G_EVAL); @@ -458,6 +468,8 @@ registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); + registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); + registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); char *argv[] = { "", @@ -493,96 +505,109 @@ globalEventListener (int *type, ...) { va_list args; - static int rv = 0; - CFPContext context; - char *buf; - player *pl; - object *op; + static int rv; + int event_code; if (!perl) return; - memset (&context, 0, sizeof (context)); - va_start (args, type); - context.event_code = va_arg (args, int); + event_code = va_arg (args, int); - switch (context.event_code) + if (event_code == EVENT_FREE_OB) { - case EVENT_CRASH: - printf ("Unimplemented for now\n"); - break; + player *pl; + object *op; + SV *sv; - case EVENT_MAPLOAD: - case EVENT_MAPOUT: - case EVENT_MAPIN: - case EVENT_MAPCLEAN: - context.map = va_arg (args, mapstruct *); - break; + op = va_arg (args, object *); + sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0); - case EVENT_MAPENTER: - case EVENT_MAPLEAVE: - case EVENT_FREE_OB: - case EVENT_BORN: - case EVENT_REMOVE: - context.activator = va_arg (args, object *); - break; + if (sv) + clearSVptr (sv); - case EVENT_PLAYER_DEATH: - context.who = va_arg (args, object *); - break; + rv = 0; + } + else + { + dSP; - case EVENT_GKILL: - context.who = va_arg (args, object *); - context.activator = va_arg (args, object *); - break; + ENTER; + SAVETMPS; - case EVENT_LOGIN: - case EVENT_LOGOUT: - pl = va_arg (args, player *); - context.activator = pl->ob; - buf = va_arg (args, char *); - if (buf != 0) - strncpy (context.message, buf, sizeof (context.message)); - break; + PUSHMARK (SP); - case EVENT_SHOUT: - case EVENT_MUZZLE: - case EVENT_KICK: - context.activator = va_arg (args, object *); - buf = va_arg (args, char *); - if (buf != 0) - strncpy (context.message, buf, sizeof (context.message)); - break; + EXTEND (SP, 10); + PUSHs (sv_2mortal (newSViv (event_code))); - case EVENT_CLOCK: - clean_obj_cache (); - break; - - case EVENT_TELL: - break; + switch (event_code) + { + case EVENT_CRASH: + break; - case EVENT_MAPRESET: - /* stupid, should be the map itself, not "message"??? */ - buf = va_arg (args, char *); - if (buf != 0) - strncpy (context.message, buf, sizeof (context.message)); - break; - } + case EVENT_PLAYER_LOAD: + case EVENT_PLAYER_SAVE: + PUSH_OB; + PUSH_PV; + break; + + case EVENT_MAPLOAD: + case EVENT_MAPOUT: + case EVENT_MAPIN: + case EVENT_MAPCLEAN: + case EVENT_MAPRESET: + PUSH_MAP; + break; + + case EVENT_MAPENTER: + case EVENT_MAPLEAVE: + case EVENT_BORN: + case EVENT_REMOVE: + case EVENT_PLAYER_DEATH: + PUSH_OB; + break; + + case EVENT_GKILL: + PUSH_OB; + PUSH_OB; + break; + + case EVENT_LOGIN: + case EVENT_LOGOUT: + PUSH_PL; + PUSH_PV; + break; + + case EVENT_SHOUT: + case EVENT_MUZZLE: + case EVENT_KICK: + PUSH_OB; + PUSH_PV; + break; + + case EVENT_CLOCK: + clean_obj_cache (); + break; - va_end (args); + case EVENT_TELL: + break; + } - if (context.event_code == EVENT_FREE_OB) - { - SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); + va_end (args); - if (sv) - clearSVptr (sv); + PUTBACK; + int count = call_pv ("cf::inject_global_event", G_SCALAR | G_EVAL); + SPAGAIN; + + if (SvTRUE (ERRSV)) + LOG (llevError, "event '%d' callback evaluation error: %s", event_code, SvPV_nolen (ERRSV)); + + rv = count > 0 ? POPi : 0; + + PUTBACK; + FREETMPS; + LEAVE; } - else - inject_event ("cf::inject_global_event", &context); - - rv = context.returnvalue; return &rv; } @@ -594,6 +619,7 @@ va_list args; char *buf; CFPContext context; + object *eob; if (!perl) return; @@ -614,6 +640,7 @@ context.fix = va_arg (args, int); strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); strncpy (context.options, va_arg (args, char *), sizeof (context.options)); + eob = va_arg (args, object *); context.returnvalue = 0; va_end (args); @@ -655,6 +682,7 @@ const_iv (llevMonster) const_iv (PLAYER) + const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) const_iv (POTION) @@ -669,7 +697,6 @@ const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) - const_iv (CONFUSION) const_iv (LOCKED_DOOR) const_iv (SPECIAL_KEY) const_iv (MAP) @@ -780,6 +807,7 @@ const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) + const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) @@ -990,6 +1018,89 @@ const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) + + const_iv (M_PAPER) + const_iv (M_IRON) + const_iv (M_GLASS) + const_iv (M_LEATHER) + const_iv (M_WOOD) + const_iv (M_ORGANIC) + const_iv (M_STONE) + const_iv (M_CLOTH) + const_iv (M_ADAMANT) + const_iv (M_LIQUID) + const_iv (M_SOFT_METAL) + const_iv (M_BONE) + const_iv (M_ICE) + const_iv (M_SPECIAL) + + const_iv (SK_EXP_ADD_SKILL) + const_iv (SK_EXP_TOTAL) + const_iv (SK_EXP_NONE) + const_iv (SK_SUBTRACT_SKILL_EXP) + + const_iv (SK_LOCKPICKING) + const_iv (SK_HIDING) + const_iv (SK_SMITHERY) + const_iv (SK_BOWYER) + const_iv (SK_JEWELER) + const_iv (SK_ALCHEMY) + const_iv (SK_STEALING) + const_iv (SK_LITERACY) + const_iv (SK_BARGAINING) + const_iv (SK_JUMPING) + const_iv (SK_DET_MAGIC) + const_iv (SK_ORATORY) + const_iv (SK_SINGING) + const_iv (SK_DET_CURSE) + const_iv (SK_FIND_TRAPS) + const_iv (SK_MEDITATION) + const_iv (SK_PUNCHING) + const_iv (SK_FLAME_TOUCH) + const_iv (SK_KARATE) + const_iv (SK_CLIMBING) + const_iv (SK_WOODSMAN) + const_iv (SK_INSCRIPTION) + const_iv (SK_ONE_HANDED_WEAPON) + const_iv (SK_MISSILE_WEAPON) + const_iv (SK_THROWING) + const_iv (SK_USE_MAGIC_ITEM) + const_iv (SK_DISARM_TRAPS) + const_iv (SK_SET_TRAP) + const_iv (SK_THAUMATURGY) + const_iv (SK_PRAYING) + const_iv (SK_CLAWING) + const_iv (SK_LEVITATION) + const_iv (SK_SUMMONING) + const_iv (SK_PYROMANCY) + const_iv (SK_EVOCATION) + const_iv (SK_SORCERY) + const_iv (SK_TWO_HANDED_WEAPON) + + const_iv (SOUND_NEW_PLAYER) + const_iv (SOUND_FIRE_ARROW) + const_iv (SOUND_LEARN_SPELL) + const_iv (SOUND_FUMBLE_SPELL) + const_iv (SOUND_WAND_POOF) + const_iv (SOUND_OPEN_DOOR) + const_iv (SOUND_PUSH_PLAYER) + const_iv (SOUND_PLAYER_HITS1) + const_iv (SOUND_PLAYER_HITS2) + const_iv (SOUND_PLAYER_HITS3) + const_iv (SOUND_PLAYER_HITS4) + const_iv (SOUND_PLAYER_IS_HIT1) + const_iv (SOUND_PLAYER_IS_HIT2) + const_iv (SOUND_PLAYER_IS_HIT3) + const_iv (SOUND_PLAYER_KILLS) + const_iv (SOUND_PET_IS_KILLED) + const_iv (SOUND_PLAYER_DIES) + const_iv (SOUND_OB_EVAPORATE) + const_iv (SOUND_OB_EXPLODE) + const_iv (SOUND_CLOCK) + const_iv (SOUND_TURN_HANDLE) + const_iv (SOUND_FALL_HOLE) + const_iv (SOUND_DRINK_POISON) + const_iv (SOUND_CAST_SPELL_0) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) @@ -1019,6 +1130,8 @@ const_event (CLOCK) const_event (CRASH) const_event (PLAYER_DEATH) + const_event (PLAYER_LOAD) + const_event (PLAYER_SAVE) const_event (GKILL) const_event (LOGIN) const_event (LOGOUT) @@ -1028,6 +1141,7 @@ const_event (MAPLOAD) const_event (MAPOUT) const_event (MAPIN) + const_event (MAPCLEAN) const_event (REMOVE) const_event (SHOUT) const_event (TELL) @@ -1140,7 +1254,6 @@ prop (CFAPI_STRING, OBJECT_PROP_SHORT_NAME) prop (CFAPI_INT, OBJECT_PROP_MAGICAL) prop (CFAPI_INT, OBJECT_PROP_LUCK) - prop (CFAPI_LONG, OBJECT_PROP_EXP) prop (CFAPI_POBJECT, OBJECT_PROP_OWNER) prop (CFAPI_POBJECT, OBJECT_PROP_PRESENT) prop (CFAPI_INT, OBJECT_PROP_CHEATER) @@ -1264,6 +1377,7 @@ RETVAL = obj->attacktype; OUTPUT: RETVAL +# missing in plug-in api, of course void set_food (object *obj, int food) CODE: @@ -1307,7 +1421,7 @@ object *cf_object_present_archname_inside (object *op, char *whatstr) -int cf_object_transfer (object *op, int x, int y, int r, object *orig) +int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) int cf_object_change_map (object *op, int x, int y, mapstruct *map) @@ -1367,6 +1481,11 @@ object *cf_create_object_by_name (const char *name) +void change_exp (object *op, double exp, const char *skill_name = 0, int flag = 0) + +void player_lvl_adj (object *who, object *skill = 0) + + MODULE = cf PACKAGE = cf::object PREFIX = cf_ void cf_fix_object (object *pl) @@ -1392,6 +1511,10 @@ RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); } +const char *get_ob_key_value (object *op, const char *key) + +bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) + object *get_nearest_player (object *ob) ALIAS: nearest_player = 0 PREINIT: @@ -1422,6 +1545,12 @@ RETVAL = cf_query_base_name (ob, plural); OUTPUT: RETVAL +living * +stats (object *ob) + CODE: + RETVAL = &ob->stats; + OUTPUT: RETVAL + MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ @@ -1452,6 +1581,7 @@ void cf_player_set_party (object *op, partylist *party) +void change_skill (object *op, double exp, char *skill_name = 0, int flag = 0) MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ @@ -1464,6 +1594,8 @@ void MapNewmapCmd (player *pl) +void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); + # nonstandard object *ob (player *pl) CODE: @@ -1480,6 +1612,21 @@ RETVAL = pl->next; OUTPUT: RETVAL +void get_savebed (player *pl) + ALIAS: + savebed = 0 + PPCODE: + EXTEND (SP, 3); + PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); + PUSHs (sv_2mortal (newSViv (pl->bed_x))); + PUSHs (sv_2mortal (newSViv (pl->bed_y))); + +void set_savebed (player *pl, char *map_path, int x, int y) + CODE: + strcpy (pl->savebed_map, map_path); + pl->bed_x = x; + pl->bed_y = y; + void list () PPCODE: @@ -1489,6 +1636,28 @@ XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); } +bool +peaceful (player *pl, bool new_setting = 0) + PROTOTYPE: $;$ + CODE: + RETVAL = pl->peaceful; + if (items > 1) + pl->peaceful = new_setting; + OUTPUT: + RETVAL + +living * +orig_stats (player *pl) + CODE: + RETVAL = &pl->orig_stats; + OUTPUT: RETVAL + +living * +last_stats (player *pl) + CODE: + RETVAL = &pl->last_stats; + OUTPUT: RETVAL + MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ @@ -1520,6 +1689,12 @@ OUTPUT: RETVAL +void delete_map (mapstruct *map) + +void clean_tmp_map (mapstruct *map) + +void play_sound_map (mapstruct *map, int x, int y, int sound_num) + mapstruct *cf_map_get_map (char *name) PROTOTYPE: $ ALIAS: map = 0 @@ -1528,6 +1703,23 @@ PROTOTYPE: ALIAS: first = 0 +# whoever "designed" the plug-in api should have wasted +# his/her time with staying away form the project - would have +# saved others a lot of time, without doubt. +void set_path (mapstruct *where, char *path) + CODE: + strcpy (where->path, path); + +bool unique (mapstruct *map) + CODE: + RETVAL = map->unique; + OUTPUT: + RETVAL + +void set_unique (mapstruct *map, bool unique) + CODE: + map->unique = unique; + object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) @@ -1650,6 +1842,7 @@ } } + MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ archetype *cf_archetype_get_first() @@ -1711,3 +1904,55 @@ ALIAS: message = 0 +MODULE = cf PACKAGE = cf::living PREFIX = cf_living_ + +double +exp (living *liv, double new_val = 0.) + PROTOTYPE: $;$ + ALIAS: + Str = 1 + Dex = 2 + Con = 3 + Wis = 4 + Cha = 5 + Int = 6 + Pow = 7 + wc = 8 + ac = 9 + hp = 10 + maxhp = 11 + sp = 12 + maxsp = 13 + grace = 14 + maxgrace = 15 + food = 16 + dam = 17 + luck = 18 + CODE: +# define LIVING_ACC(acc,idx) case idx: RETVAL = liv->acc; if (items > 1) liv->acc = new_val; break + switch (ix) + { + LIVING_ACC (exp , 0); + LIVING_ACC (Str , 1); + LIVING_ACC (Dex , 2); + LIVING_ACC (Con , 3); + LIVING_ACC (Wis , 4); + LIVING_ACC (Cha , 5); + LIVING_ACC (Int , 6); + LIVING_ACC (Pow , 7); + LIVING_ACC (wc , 8); + LIVING_ACC (ac , 9); + LIVING_ACC (hp , 10); + LIVING_ACC (maxhp , 11); + LIVING_ACC (sp , 12); + LIVING_ACC (maxsp , 13); + LIVING_ACC (grace , 14); + LIVING_ACC (maxgrace, 15); + LIVING_ACC (food , 16); + LIVING_ACC (dam , 17); + LIVING_ACC (luck , 18); + } +# undef LIVING_ACC + OUTPUT: + RETVAL +