/*___________________________________________________________________________* )()( DalekenMUD 1.12 (C) 2000 )()( `][' by Martin Thomson, Lee Brooks, `][' || Ken Herbert and David Jacques || || ----------------------------------------------------------------- || || Envy Diku Mud improvements copyright (C) 1994 by Michael Quan, || || David Love, Guilherme 'Willie' Arnold, and Mitchell Tse. || || Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael || || Chastain, Michael Quan, and Mitchell Tse. || || Original Diku Mud copyright (C) 1990, 1991 || || by Sebastian Hammer, Michael Seifert, Hans Henrik St{rfeldt, || || Tom Madsen, and Katja Nyboe. || || ----------------------------------------------------------------- || || Any use of this software must follow the licenses of the || || creators. Much time and thought has gone into this software and || || you are benefitting. We hope that you share your changes too. || || What goes around, comes around. || || ----------------------------------------------------------------- || || event.h || || Contains information on the event system structures etc... || || Please don't tinker with the event system unless you understand || || EVERYTHING there is to know about it there is NO protection in C! || *_/<>\_________________________________________________________________/<>\_*/ #define MAX_EVENT_HASH 256 /* The hash bucket size. */ #define MAX_EVENT_DATA 4 /* The amount of data required. */ /* * Target type identifier. */ #define TARGET_VOID 0 #define TARGET_CHAR 1 #define TARGET_OBJ 2 #define TARGET_ROOM 3 #define TARGET_AREA 4 #define TARGET_PLANE 5 /* * Special Event flags. * These flags are set/unset in the event table. Individual events may * override this by setting them on the flags and the value will be toggled, * using an XOR (^). * E = only used when set on an event. * T = only used when set in the event table. */ #define EVENT_LOADING 1 /* Event has just been loaded. (E) */ #define EVENT_TEMPORARY 2 /* Event doesn't need saving etc... */ #define EVENT_DEATH_REMOVE 4 /* Event removed when target killed. */ #define EVENT_NO_QUIT 8 /* Target cannot be removed. */ #define EVENT_STACKABLE 16 /* Multiple events can be added. (T) */ typedef struct multi_target_type TARGET_TYPE; typedef void EVENT_CALLBACK args( ( EVENT *ev ) ); #define DECLARE_EVENT_CALLBACK( evf ) EVENT_CALLBACK evf /* * This is where OO programming would REALLY come in handy. * Programming like this is a little ugly. * Still, this could be a useful structure, think about how act() works... */ struct multi_target_type { uint_8 type; union { void *typeless; OBJ_DATA *obj; CHAR_DATA *ch; ROOM_INDEX_DATA *room; AREA_DATA *area; PLANE_DATA *plane; } target; }; /* * The information required for an event. * Some effort could be made to slightly reduce the size required. */ struct event_data { EVENT *next_local; EVENT *next_global; TARGET_TYPE actor; /* Where the event was generated. */ time_t when; /* Which game pulse it goes off on. */ int flags; /* See above for flag descriptions. */ int type; /* Determines the callback function. */ /* Storage elements, used for miscellaneous information, normally * dependant on the event. */ char *text; int data[ MAX_EVENT_DATA ]; TARGET_TYPE extra; }; /* * The event table. */ struct event_table_type { const char *name; int *type; EVENT_CALLBACK *callback; int flags; }; extern struct event_table_type event_table []; /* * Function declarations. */ void event_update args( ( void ) ); EVENT *load_event args( ( FILE *fp ) ); void save_event args( ( FILE *fp, EVENT *e ) ); void inject_events args( ( CHAR_DATA *ch ) ); EVENT *create_char_event args( ( CHAR_DATA *ch, int type, int delay ) ); EVENT *create_obj_event args( ( OBJ_DATA *obj, int type, int delay ) ); EVENT *create_room_event args( ( ROOM_INDEX_DATA *room, int type, int delay ) ); EVENT *create_area_event args( ( AREA_DATA *area, int type, int delay ) ); EVENT *create_plane_event args( ( PLANE_DATA *plane, int type, int delay ) ); EVENT *create_typeless_event args( ( void *vo, int type, int delay ) ); EVENT *duplicate_event args( ( EVENT *e, int delay ) ); void event_remove_global args( ( EVENT *e ) ); void event_remove_local args( ( EVENT **list, EVENT *e ) ); void strip_events args( ( EVENT **list, int type ) ); int get_time_left args( ( EVENT *e, int type ) ); void set_timer args( ( OBJ_DATA *obj, int pulses ) ); void set_timer_tick args( ( OBJ_DATA *obj, int ticks ) ); void set_imp_timer args( ( OBJ_DATA *obj ) ); EVENT *new_event args( ( void ) ); void free_event args( ( EVENT *e ) ); const char *print_event args( ( EVENT *e ) ); /* for mud programs */ void add_mob_triggers args( ( CHAR_DATA *mob ) ); void add_mob_fight_triggers args( ( CHAR_DATA *mob ) ); void add_obj_triggers args( ( OBJ_DATA *obj ) ); void add_room_triggers args( ( ROOM_INDEX_DATA *room ) ); /* callback.c */ int event_lookup args( ( const char *name ) ); struct event_table_type *event_table_lookup args( ( const char *name ) ); /* * Event callback types and functions. */ /* Player actions */ extern int evn_picklock; DECLARE_EVENT_CALLBACK( ecb_finish_pick ); extern int evn_picktrap; DECLARE_EVENT_CALLBACK( ecb_pick_trap ); extern int evn_mercenary; DECLARE_EVENT_CALLBACK( ecb_mercenary ); extern int evn_gate_demon; DECLARE_EVENT_CALLBACK( ecb_gate_demon ); extern int evn_raised_undead; DECLARE_EVENT_CALLBACK( ecb_raised_undead ); extern int evn_swan_song; DECLARE_EVENT_CALLBACK( ecb_swan_song ); extern int evn_char_fall; DECLARE_EVENT_CALLBACK( ecb_char_fall ); extern int evn_char_sink; DECLARE_EVENT_CALLBACK( ecb_char_sink ); extern int evn_char_drown; DECLARE_EVENT_CALLBACK( ecb_char_drown ); extern int evn_char_suffocate; DECLARE_EVENT_CALLBACK( ecb_char_suffocate ); extern int evn_web_struggle; DECLARE_EVENT_CALLBACK( ecb_web_struggle ); extern int evn_stand_up; DECLARE_EVENT_CALLBACK( ecb_stand_up ); extern int evn_regeneration; DECLARE_EVENT_CALLBACK( ecb_regeneration ); /* object events */ extern int evn_plant_grow; DECLARE_EVENT_CALLBACK( ecb_plant_grow ); extern int evn_plant_die; DECLARE_EVENT_CALLBACK( ecb_plant_die ); extern int evn_explode; DECLARE_EVENT_CALLBACK( ecb_explode ); /* update events */ extern int evn_obj_decay; DECLARE_EVENT_CALLBACK( ecb_obj_decay ); extern int evn_imp_grab; DECLARE_EVENT_CALLBACK( ecb_imp_grab ); extern int evn_obj_fall; DECLARE_EVENT_CALLBACK( ecb_obj_fall ); extern int evn_spec_fun; DECLARE_EVENT_CALLBACK( ecb_spec_fun ); extern int evn_class_action; DECLARE_EVENT_CALLBACK( ecb_class_action ); extern int evn_hunt_fleer; DECLARE_EVENT_CALLBACK( ecb_hunt_fleer ); extern int evn_scavenge; DECLARE_EVENT_CALLBACK( ecb_scavenge ); extern int evn_wander; DECLARE_EVENT_CALLBACK( ecb_wander ); extern int evn_cone_remove; DECLARE_EVENT_CALLBACK( ecb_cone_remove ); extern int evn_room_violence; DECLARE_EVENT_CALLBACK( ecb_room_violence ); /* mud program events */ extern int evn_prog_trigger; DECLARE_EVENT_CALLBACK( ecb_prog_trigger ); extern int evn_prog_wait; DECLARE_EVENT_CALLBACK( ecb_prog_wait ); /* area events */ extern int evn_area_reset; DECLARE_EVENT_CALLBACK( ecb_area_reset );