Added lists .c .h and mud_event .c .h

This commit is contained in:
Vatiken
2012-02-12 22:09:38 +00:00
parent dd280c1b58
commit b34c23da96
4 changed files with 487 additions and 0 deletions

89
src/mud_event.c Normal file
View File

@@ -0,0 +1,89 @@
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "db.h"
#include "dg_event.h"
#include "constants.h"
#include "comm.h" /* For access to the game pulse */
#include "mud_event.h"
/* Global List */
struct list_data * world_events = NULL;
void init_events(void)
{
/* Allocate Event List */
world_events = create_list();
/* Attach Our Events */
attach_mud_event(display_usage, new_mud_event(EVENT_WORLD, NULL, NULL), 10 * PASSES_PER_SEC);
}
void attach_mud_event(void (*func), 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->isMudEvent = TRUE;
pMudEvent->pEvent = pEvent;
switch (pMudEvent->iEvent_Type) {
case EVENT_WORLD:
add_to_list(pEvent, world_events);
break;
case EVENT_DESC:
d = (struct descriptor_data *) pMudEvent->pStruct;
add_to_list(pEvent, d->events);
break;
case EVENT_CHAR:
ch = (struct char_data *) pMudEvent->pStruct;
add_to_list(pEvent, ch->events);
break;
}
}
struct mud_event_data *new_mud_event(int iEvent_Type, void *pStruct, char *sVariables)
{
struct mud_event_data *pMudEvent;
char *varString;
CREATE(pMudEvent, struct mud_event_data, 1);
varString = (sVariables != NULL) ? strdup(sVariables) : NULL;
pMudEvent->iEvent_Type = iEvent_Type;
pMudEvent->pStruct = pStruct;
pMudEvent->sVariables = varString;
pMudEvent->pEvent = NULL;
return (pMudEvent);
}
void free_mud_event(struct mud_event_data *pMudEvent)
{
struct descriptor_data * d;
struct char_data * ch;
switch (pMudEvent->iEvent_Type) {
case EVENT_WORLD:
remove_from_list(pMudEvent->pEvent, world_events);
break;
case EVENT_DESC:
d = (struct descriptor_data *) pMudEvent->pStruct;
remove_from_list(pMudEvent->pEvent, d->events);
break;
case EVENT_CHAR:
ch = (struct char_data *) pMudEvent->pStruct;
remove_from_list(pMudEvent->pEvent, ch->events);
break;
}
if (pMudEvent->sVariables != NULL)
free(pMudEvent->sVariables);
pMudEvent->pEvent->event_obj = NULL;
free(pMudEvent);
}