--- deliantra/server/plugins/cfperl/cfperl.xs 2006/03/17 01:23:48 1.37 +++ deliantra/server/plugins/cfperl/cfperl.xs 2006/03/28 16:08:28 1.41 @@ -44,6 +44,7 @@ #endif #include +#include #include @@ -218,7 +219,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: @@ -495,104 +496,116 @@ 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_PLAYER_LOAD: - case EVENT_PLAYER_SAVE: - context.who = va_arg (args, object *); - buf = va_arg (args, char *); - if (buf != 0) - strncpy (context.message, buf, sizeof (context.message)); - break; + op = va_arg (args, object *); + sv = hv_delete (obj_cache, (char *)&op, sizeof (void *), 0); - case EVENT_MAPLOAD: - case EVENT_MAPOUT: - case EVENT_MAPIN: - case EVENT_MAPCLEAN: - context.map = va_arg (args, mapstruct *); - break; - - 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; +#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) - 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; } @@ -604,6 +617,7 @@ va_list args; char *buf; CFPContext context; + object *eob; if (!perl) return; @@ -624,6 +638,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); @@ -1016,6 +1031,74 @@ 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; ) @@ -1169,7 +1252,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) @@ -1397,6 +1479,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) @@ -1422,6 +1509,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: @@ -1488,6 +1579,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_ @@ -1500,6 +1592,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: @@ -1583,6 +1677,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