diff --git a/lib/world/mob/12.mob b/lib/world/mob/12.mob index 6f830d0..dff7238 100644 --- a/lib/world/mob/12.mob +++ b/lib/world/mob/12.mob @@ -17,7 +17,7 @@ The Immortal Postmaster is hard at work here. ~ Scary... A postal worker... Working? ~ -712714 0 0 0 65536 0 0 0 0 E +188426 0 0 0 65536 0 0 0 0 E 14 16 1 2d2+140 2d2+2 140 19600 8 8 2 @@ -212,11 +212,11 @@ test mob~ the test mob~ .the test mob is our friend. ~ - Test mobs can be whatever you want them to be. + Test mobs can be whatever you want them to be. ~ -61454 0 0 0 983040 0 0 0 0 E -3 19 8 0d0+30 1d2+0 -30 900 +8 0 0 0 0 0 0 0 0 E +0 20 10 1d1+0 1d1+0 +0 0 8 8 0 E $ diff --git a/src/act.informative.c b/src/act.informative.c index 4eaea04..7ede884 100644 --- a/src/act.informative.c +++ b/src/act.informative.c @@ -1263,20 +1263,12 @@ ACMD(do_who) CCNRM(ch, C_SPR), ((!(++num_can_see % 4)) ? "\r\n" : "")); } else { num_can_see++; - if (GET_LEVEL(tch) >= LVL_IMMORT) { - send_to_char(ch, "%s%s%s%s%s", - (GET_LEVEL(tch) >= LVL_IMMORT ? CCYEL(ch, C_SPR) : ""), - GET_NAME(tch), (*GET_TITLE(tch) ? " " : ""), GET_TITLE(tch), - CCNRM(ch, C_SPR)); - } else { - send_to_char(ch, "%s[%2d %s] %s%s%s%s", + send_to_char(ch, "%s[%2d %s] %s%s%s%s", (GET_LEVEL(tch) >= LVL_IMMORT ? CCYEL(ch, C_SPR) : ""), GET_LEVEL(tch), CLASS_ABBR(tch), GET_NAME(tch), (*GET_TITLE(tch) ? " " : ""), GET_TITLE(tch), CCNRM(ch, C_SPR)); - } - if (GET_INVIS_LEV(tch)) send_to_char(ch, " (i%d)", GET_INVIS_LEV(tch)); else if (AFF_FLAGGED(tch, AFF_INVISIBLE)) @@ -2377,6 +2369,10 @@ ACMD(do_whois) { CREATE(victim, struct char_data, 1); clear_char(victim); + + /* Allocate mobile event list */ + victim->events = create_list(); + CREATE(victim->player_specials, struct player_special_data, 1); if (load_char(buf, victim) > -1) diff --git a/src/act.wizard.c b/src/act.wizard.c index 5f045eb..b7067fb 100644 --- a/src/act.wizard.c +++ b/src/act.wizard.c @@ -1008,6 +1008,8 @@ ACMD(do_stat) CREATE(victim, struct char_data, 1); clear_char(victim); CREATE(victim->player_specials, struct player_special_data, 1); + /* Allocate mobile event list */ + victim->events = create_list(); if (load_char(buf2, victim) >= 0) { char_to_room(victim, 0); if (GET_LEVEL(victim) > GET_LEVEL(ch)) @@ -2047,6 +2049,8 @@ ACMD(do_last) CREATE(vict, struct char_data, 1); clear_char(vict); CREATE(vict->player_specials, struct player_special_data, 1); + /* Allocate mobile event list */ + vict->events = create_list(); if (load_char(name, vict) < 0) { send_to_char(ch, "There is no such player.\r\n"); free_char(vict); @@ -2567,6 +2571,8 @@ ACMD(do_show) CREATE(vict, struct char_data, 1); clear_char(vict); CREATE(vict->player_specials, struct player_special_data, 1); + /* Allocate mobile event list */ + vict->events = create_list(); if (load_char(value, vict) < 0) { send_to_char(ch, "There is no such player.\r\n"); free_char(vict); @@ -3347,6 +3353,8 @@ ACMD(do_set) CREATE(cbuf, struct char_data, 1); clear_char(cbuf); CREATE(cbuf->player_specials, struct player_special_data, 1); + /* Allocate mobile event list */ + cbuf->events = create_list(); if ((player_i = load_char(name, cbuf)) > -1) { if (GET_LEVEL(cbuf) > GET_LEVEL(ch)) { free_char(cbuf); @@ -4613,6 +4621,8 @@ bool change_player_name(struct char_data *ch, struct char_data *vict, char *new_ CREATE(temp_ch, struct char_data, 1); clear_char(temp_ch); CREATE(temp_ch->player_specials, struct player_special_data, 1); + /* Allocate mobile event list */ + temp_ch->events = create_list(); if ((plr_i = load_char(new_name, temp_ch)) > -1) { free_char(temp_ch); send_to_char(ch, "Sorry, the new name already exists.\r\n"); diff --git a/src/comm.c b/src/comm.c index efa2b1e..c79ffae 100644 --- a/src/comm.c +++ b/src/comm.c @@ -371,6 +371,7 @@ int main(int argc, char **argv) free_save_list(); /* genolc.c */ free_strings(&config_info, OASIS_CFG); /* oasis_delete.c */ free_ibt_lists(); /* ibt.c */ + free_list(world_events); } if (last_act_message) @@ -378,7 +379,7 @@ int main(int argc, char **argv) /* probably should free the entire config here.. */ free(CONFIG_CONFFILE); - + log("Done."); #ifdef MEMORY_DEBUG @@ -444,6 +445,10 @@ void copyover_recover() CREATE(d->character, struct char_data, 1); clear_char(d->character); CREATE(d->character->player_specials, struct player_special_data, 1); + + /* Allocate mobile event list */ + d->character->events = create_list(); + d->character->desc = d; if ((player_i = load_char(name, d->character)) >= 0) { @@ -1589,7 +1594,7 @@ static int new_descriptor(socket_t s) descriptor_list = newd; /* Attach Event */ - attach_mud_event(get_protocols, new_mud_event(EVENT_DESC, newd, NULL), 1.5 * PASSES_PER_SEC); + attach_mud_event(new_mud_event(ePROTOCOLS, newd, NULL), 1.5 * PASSES_PER_SEC); /* KaVir's plugin*/ write_to_output(newd, "Attempting to Detect Client, Please Wait...\r\n"); diff --git a/src/db.c b/src/db.c index 6b077f8..bc08d9f 100644 --- a/src/db.c +++ b/src/db.c @@ -629,9 +629,6 @@ void destroy_db(void) /* Events */ event_free_all(); - /* Lists */ - free_list(world_events); - } /* body of the booting system */ @@ -2324,6 +2321,10 @@ struct char_data *create_char(void) CREATE(ch, struct char_data, 1); clear_char(ch); + + /* Allocate mobile event list */ + ch->events = create_list(); + ch->next = character_list; character_list = ch; @@ -2350,10 +2351,14 @@ struct char_data *read_mobile(mob_vnum nr, int type) /* and mob_rnum */ CREATE(mob, struct char_data, 1); clear_char(mob); + *mob = mob_proto[i]; mob->next = character_list; character_list = mob; - + + /* Allocate mobile event list */ + mob->events = create_list(); + if (!mob->points.max_hit) { mob->points.max_hit = dice(mob->points.hit, mob->points.mana) + mob->points.move; @@ -3191,6 +3196,17 @@ void free_char(struct char_data *ch) if (SCRIPT(ch)) extract_script(ch, MOB_TRIGGER); + /* Mud Events */ + if (ch->events != NULL) { + if (ch->events->iSize > 0) { + struct event * pEvent; + + while ((pEvent = simple_list(ch->events)) != NULL) + event_cancel(pEvent); + } + free_list(ch->events); + } + /* new version of free_followers take the followers pointer as arg */ free_followers(ch->followers); @@ -3359,7 +3375,8 @@ void clear_char(struct char_data *ch) GET_WAS_IN(ch) = NOWHERE; GET_POS(ch) = POS_STANDING; ch->mob_specials.default_pos = POS_STANDING; - + ch->events = NULL; + GET_AC(ch) = 100; /* Basic Armor */ if (ch->points.max_mana < 100) ch->points.max_mana = 100; diff --git a/src/interpreter.c b/src/interpreter.c index 1e2187c..3d66755 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -1352,6 +1352,10 @@ void nanny(struct descriptor_data *d, char *arg) CREATE(d->character, struct char_data, 1); clear_char(d->character); CREATE(d->character->player_specials, struct player_special_data, 1); + + /* Allocate mobile event list */ + d->character->events = create_list(); + GET_HOST(d->character) = strdup(d->host); d->character->desc = d; } @@ -1387,6 +1391,9 @@ void nanny(struct descriptor_data *d, char *arg) clear_char(d->character); CREATE(d->character->player_specials, struct player_special_data, 1); + /* Allocate mobile event list */ + d->character->events = create_list(); + if (GET_HOST(d->character)) free(GET_HOST(d->character)); GET_HOST(d->character) = strdup(d->host); diff --git a/src/lists.c b/src/lists.c index 8ebfbe8..0cbb60c 100644 --- a/src/lists.c +++ b/src/lists.c @@ -1,12 +1,8 @@ /************************************************************************** * File: lists.c Part of tbaMUD * -* Usage: Loading/saving/editing of Ideas, Bugs and Typos lists * +* Usage: Handling of in-game lists * * * -* All rights reserved. See license for complete information. * -* * -* Written by Joseph Arnusch (Vatiken) for the tbaMUD codebase * -* Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University * -* CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. * +* By Vatiken. Copyright 2012 by Joseph Arnusch * **************************************************************************/ #include "conf.h" @@ -32,12 +28,11 @@ struct list_data * create_list(void) pNewList->iSize = 0; /* Add to global lists, primarily for debugging purposes */ - if (first_list == FALSE) { - mudlog(CMP, LVL_GOD, TRUE, "Adding to global list."); + if (first_list == FALSE) add_to_list(pNewList, global_lists); - } else - first_list = FALSE; - + else + first_list = FALSE; + return (pNewList); } @@ -58,17 +53,18 @@ void free_list(struct list_data * pList) { void * pContent; + simple_list(NULL); + if (pList->iSize) - while ((pContent = simple_list(pList))) + while ((pContent = simple_list(pList))) remove_from_list(pContent, pList); if (pList->iSize > 0) mudlog(CMP, LVL_GOD, TRUE, "List being freed while not empty."); - /* Global List for debugging */ - mudlog(CMP, LVL_GOD, TRUE, "Removing from global list."); + /* Global List for debugging */ remove_from_list(pList, global_lists); - + free(pList); } @@ -93,7 +89,7 @@ void add_to_list(void * pContent, struct list_data * pList) pLastItem = pList->pLastItem; pLastItem->pNextItem = pNewItem; pNewItem->pPrevItem = pLastItem; - } + } /* Make our new item our last item in the list */ pList->pLastItem = pNewItem; @@ -249,8 +245,15 @@ void * simple_list(struct list_data * pList) static struct list_data *pLastList = NULL; void * pContent; + /* Reset List */ + if (pList == NULL) { + loop = FALSE; + pLastList = NULL; + return NULL; + } + if (!loop || pLastList != pList) { - if (pLastList != pList) + if (loop && pLastList != pList) mudlog(CMP, LVL_GRGOD, TRUE, "SYSERR: simple_list() forced to reset itself."); pContent = merge_iterator(&Iterator, pList); diff --git a/src/lists.h b/src/lists.h index c7b0a2b..44991a2 100644 --- a/src/lists.h +++ b/src/lists.h @@ -1,5 +1,14 @@ -/* file: list.h - */ +/** +* @file lists.h +* Lists Header file. +* +* Part of the core tbaMUD source code distribution, which is a derivative +* of, and continuation of, CircleMUD. +* +* This source code, which was not part of the CircleMUD legacy code, +* is attributed to: +* Copyright 2012 by Joseph Arnusch. +*/ #ifndef _LISTS_HEADER #define _LISTS_HEADER @@ -13,8 +22,8 @@ struct item_data { struct list_data { struct item_data * pFirstItem; struct item_data * pLastItem; - int iIterators; - int iSize; + unsigned short int iIterators; + unsigned short int iSize; }; struct iterator_data { @@ -25,7 +34,7 @@ struct iterator_data { /* Externals */ extern struct list_data * global_lists; extern struct list_data * ticker_list; - +extern int total_lists; /* Locals */ void add_to_list(void * pContent, struct list_data * pList); void * random_from_list(struct list_data * pList); diff --git a/src/mud_event.c b/src/mud_event.c index 42f81c9..48312d6 100644 --- a/src/mud_event.c +++ b/src/mud_event.c @@ -1,3 +1,9 @@ +/************************************************************************** +* File: mud_event.c Part of tbaMUD * +* Usage: Handling of the mud event system * +* * +* By Vatiken. Copyright 2012 by Joseph Arnusch * +**************************************************************************/ #include "conf.h" #include "sysdep.h" @@ -12,38 +18,70 @@ /* Global List */ struct list_data * world_events = NULL; +struct mud_event_list mud_event_index[] = { + { "Null" , NULL , -1 }, /* eNULL */ + { "Protocol" , get_protocols, EVENT_DESC } /* ePROTOCOLS */ +}; + void init_events(void) { /* Allocate Event List */ world_events = create_list(); } -void attach_mud_event(void (*func), struct mud_event_data *pMudEvent, long time) +EVENTFUNC(event_countdown) +{ + struct mud_event_data * pMudEvent; + struct char_data * ch = NULL; + + pMudEvent = (struct mud_event_data * ) event_obj; + + switch (mud_event_index[pMudEvent->iId].iEvent_Type) { + case EVENT_CHAR: + ch = (struct char_data * ) pMudEvent->pStruct; + break; + default: + break; + } + + switch (pMudEvent->iId) { + default: + break; + } + + free_mud_event(pMudEvent); + return 0; +} + +void attach_mud_event(struct mud_event_data *pMudEvent, long time) { struct event * pEvent; struct descriptor_data * d; struct char_data * ch; - - pEvent = event_create(func, pMudEvent, time); + + pEvent = event_create(mud_event_index[pMudEvent->iId].func, pMudEvent, time); pEvent->isMudEvent = TRUE; pMudEvent->pEvent = pEvent; - switch (pMudEvent->iEvent_Type) { + switch (mud_event_index[pMudEvent->iId].iEvent_Type) { case EVENT_WORLD: add_to_list(pEvent, world_events); + mudlog(CMP, LVL_GRGOD, TRUE, "INFO: Mud Event '%s' added to world", mud_event_index[pMudEvent->iId].event_name); break; case EVENT_DESC: d = (struct descriptor_data *) pMudEvent->pStruct; add_to_list(pEvent, d->events); + mudlog(CMP, LVL_GRGOD, TRUE, "INFO: Mud Event '%s' added to %s", mud_event_index[pMudEvent->iId].event_name, d->host ? d->host : "descriptor"); break; case EVENT_CHAR: ch = (struct char_data *) pMudEvent->pStruct; add_to_list(pEvent, ch->events); + mudlog(CMP, LVL_GRGOD, TRUE, "INFO: Mud Event '%s' added to %s", mud_event_index[pMudEvent->iId].event_name, GET_NAME(ch)); break; } } -struct mud_event_data *new_mud_event(int iEvent_Type, void *pStruct, char *sVariables) +struct mud_event_data *new_mud_event(event_id iId, void *pStruct, char *sVariables) { struct mud_event_data *pMudEvent; char *varString; @@ -51,7 +89,7 @@ struct mud_event_data *new_mud_event(int iEvent_Type, void *pStruct, char *sVari CREATE(pMudEvent, struct mud_event_data, 1); varString = (sVariables != NULL) ? strdup(sVariables) : NULL; - pMudEvent->iEvent_Type = iEvent_Type; + pMudEvent->iId = iId; pMudEvent->pStruct = pStruct; pMudEvent->sVariables = varString; pMudEvent->pEvent = NULL; @@ -64,7 +102,9 @@ void free_mud_event(struct mud_event_data *pMudEvent) struct descriptor_data * d; struct char_data * ch; - switch (pMudEvent->iEvent_Type) { + mudlog(CMP, LVL_GRGOD, TRUE, "INFO: Freeing mud event '%s' : %d", mud_event_index[pMudEvent->iId].event_name, pMudEvent->iId); + + switch (mud_event_index[pMudEvent->iId].iEvent_Type) { case EVENT_WORLD: remove_from_list(pMudEvent->pEvent, world_events); break; @@ -84,3 +124,29 @@ void free_mud_event(struct mud_event_data *pMudEvent) pMudEvent->pEvent->event_obj = NULL; free(pMudEvent); } + +struct mud_event_data * char_has_mud_event(struct char_data * ch, event_id iId) +{ + struct event * pEvent; + struct mud_event_data * pMudEvent; + bool found = FALSE; + + simple_list(NULL); + + while ((pEvent = (struct event *) simple_list(ch->events)) != NULL) { + if (!pEvent->isMudEvent) + continue; + pMudEvent = (struct mud_event_data * ) pEvent->event_obj; + if (pMudEvent->iId == iId) { + found = TRUE; + break; + } + } + + simple_list(NULL); + + if (found) + return (pMudEvent); + + return NULL; +} diff --git a/src/mud_event.h b/src/mud_event.h index 1f0d218..f2ac91d 100644 --- a/src/mud_event.h +++ b/src/mud_event.h @@ -1,9 +1,15 @@ /** * @file mud_event.h +* Mud_Event Header file. * * Part of the core tbaMUD source code distribution, which is a derivative * of, and continuation of, CircleMUD. +* +* This source code, which was not part of the CircleMUD legacy code, +* is attributed to: +* Copyright 2012 by Joseph Arnusch. */ + #ifndef _MUD_EVENT_H_ #define _MUD_EVENT_H_ @@ -13,23 +19,36 @@ #define EVENT_DESC 1 #define EVENT_CHAR 2 +typedef enum { + eNULL, + ePROTOCOLS, +} event_id; + +struct mud_event_list { + const char * event_name; + EVENTFUNC(*func); + int iEvent_Type; +}; + struct mud_event_data { - struct event * pEvent; - int iEvent_Type; - void * pStruct; - char * sVariables; + struct event * pEvent; /***< Pointer reference to the event */ + event_id iId; /***< General ID reference */ + void * pStruct; /***< Pointer to NULL, Descriptor, Character .... */ + char * sVariables; /***< String variable */ }; /* Externals */ extern struct list_data * world_events; - +extern struct mud_event_list mud_event_index[]; /* Local Functions */ void init_events(void); -struct mud_event_data *new_mud_event(int iEvent_Type, void *pStruct, char *sVariables); -void attach_mud_event(void (*func), struct mud_event_data *pMudEvent, long time); +struct mud_event_data *new_mud_event(event_id iId, void *pStruct, char *sVariables); +void attach_mud_event(struct mud_event_data *pMudEvent, long time); void free_mud_event(struct mud_event_data *pMudEvent); +struct mud_event_data * char_has_mud_event(struct char_data * ch, event_id iId); /* Events */ +EVENTFUNC(event_countdown); EVENTFUNC(get_protocols); #endif /* _MUD_EVENT_H_ */ diff --git a/src/protocol.c b/src/protocol.c index 6282b64..3e5bb29 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -344,7 +344,8 @@ void ProtocolDestroy( protocol_t *apProtocol ) for ( i = eMSDP_NONE+1; i < eMSDP_MAX; ++i ) { - free(apProtocol->pVariables[i]->pValueString); + if (apProtocol->pVariables[i]->pValueString) + free(apProtocol->pVariables[i]->pValueString); free(apProtocol->pVariables[i]); } @@ -1730,7 +1731,8 @@ static void PerformSubnegotiation( descriptor_t *apDescriptor, char aCmd, char * const char *pStartPos = strstr( pClientName, "-" ); /* Store the TTYPE */ - free(pProtocol->pLastTTYPE); + if (pProtocol->pLastTTYPE) + free(pProtocol->pLastTTYPE); pProtocol->pLastTTYPE = AllocString(pClientName); /* Look for 256 colour support */