/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* Envy Diku Mud improvements copyright (C) 1994 by Michael Quan, David *
* Love, Guilherme 'Willie' Arnold, and Mitchell Tse. *
* *
* EnvyMud 2.0 improvements copyright (C) 1995 by Michael Quan and *
* Mitchell Tse. *
* *
* In order to use any part of this Envy Diku Mud, you must comply with *
* the original Diku license in 'license.doc', the Merc license in *
* 'license.txt', as well as the Envy license in 'license.nvy'. *
* In particular, you may not remove either of these copyright notices. *
* *
* 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. *
***************************************************************************/
#if defined( macintosh )
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
EVENT_DATA * event_first = NULL;
EVENT_DATA * event_free = NULL;
// Event creation function - Veygoth
// Once it is finished, deleted events should be recycled.
void create_event( int type, int time, void * arg1, void * arg2, int var )
{
EVENT_DATA *event;
event = alloc_perm( sizeof( *event ) );
memset( event, 0, sizeof( EVENT_DATA ) );
event->type = type;
event->time = time;
event->arg1 = arg1;
event->arg2 = arg2;
event->var = var;
event->deleted = FALSE;
event->next = event_first;
event_first = event;
top_event++;
return;
}
// This is called once per pulse - Veygoth
void event_update( )
{
EVENT_DATA *event;
int count;
char buf[MAX_STRING_LENGTH];
static int pulse_db_dump = PULSE_DB_DUMP;
// Handle all the events
for( event = event_first; event; event = event->next )
{
if( event->deleted )
continue;
event->time -= 1;
// be sure and send them the stars for spellcast ticks.
if( event->type == EVENT_SPELL_CAST
&& !IS_NPC( (CHAR_DATA *)event->arg1 )
&& IS_SET( ((CHAR_DATA *)event->arg1 )->act, PLR_CAST_TICK )
&& event->time > 0
&& event->time % PULSE_PER_SECOND == 0 )
{
sprintf( buf, "Casting %s: ", spells_table[event->var].name );
for( count = 0; count < (event->time / PULSE_PER_SECOND);
count++ )
strcat( buf, "*" );
strcat( buf, "\n\r" );
send_to_char( buf, (CHAR_DATA *)event->arg1 );
}
if( event->time <= 0 )
switch( event->type )
{
case EVENT_SPELL_CAST:
event->deleted = TRUE;
// We stored the CHAR_DATA in arg1
// We stored the sn in var
// We stored the target argument in arg2
finish_spell( event->arg1, event->var, event->arg2 );
break;
case EVENT_HIT_GAIN:
hit_update( );
event->time = PULSE_HITGAIN;
break;
case EVENT_MANA_GAIN:
mana_update( );
event->time = PULSE_MANAGAIN;
break;
case EVENT_MOVE_GAIN:
move_update( );
event->time = PULSE_MOVEGAIN;
break;
case EVENT_MEMORIZE_UPDATE:
wiznet( NULL, WIZ_TICKS, LEVEL_HERO, "Memorize update event" );
memorize_update( );
event->time = PULSE_MEMORIZE;
break;
case EVENT_AGGR_UPDATE:
wiznet( NULL, WIZ_TICKS, LEVEL_HERO, "Aggression event" );
aggr_update( );
event->time = PULSE_AGGRESS;
break;
case EVENT_WEATHER_UPDATE:
wiznet( NULL, WIZ_TICKS, LEVEL_HERO, "Weather update event" );
weather_update ( );
event->time = PULSE_WEATHER;
break;
case EVENT_CHAR_UPDATE:
wiznet( NULL, WIZ_TICKS, LEVEL_HERO, "Char update event" );
char_update ( );
event->time = PULSE_CHAR_UPDATE;
break;
case EVENT_OBJECT_SPECIAL:
wiznet( NULL, WIZ_TICKS, LEVEL_HERO, "Object special event" );
obj_spec_update ( );
event->time = PULSE_OBJECT;
break;
case EVENT_LIST_UPDATE:
wiznet( NULL, WIZ_TICKS, LEVEL_HERO, "List update event" );
list_update ( );
event->time = PULSE_LIST;
break;
case EVENT_AREA_UPDATE:
wiznet( NULL, WIZ_TICKS, L_APP, "Area update event" );
area_update ( );
event->time = PULSE_AREA;
break;
case EVENT_ROOM_UPDATE:
wiznet( NULL, WIZ_TICKS, L_APP, "Room update event" );
room_update ( );
event->time = PULSE_ROOM;
break;
case EVENT_MOBILE_UPDATE:
wiznet( NULL, WIZ_TICKS, L_APP, "Mobile update event" );
mobile_update ( );
event->time = PULSE_MOBILE;
break;
case EVENT_OBJECT_UPDATE:
// Object special functions only...
wiznet( NULL, WIZ_TICKS, L_APP, "Object update event" );
object_update ( );
event->time = PULSE_OBJECT;
break;
case EVENT_VIOLENCE_UPDATE:
wiznet( NULL, WIZ_TICKS, L_APP, "Violence update pulse" );
violence_update ( );
event->time = PULSE_VIOLENCE;
break;
case EVENT_SAVE_SYSDATA:
wiznet( NULL, WIZ_TICKS, L_APP, "Save sysdata event" );
save_sysdata( );
event->time = PULSE_SAVE_SYSDATA;
break;
case EVENT_SAVE_CORPSES:
wiznet( NULL, WIZ_TICKS, L_APP, "Save corpse event" );
save_corpses( );
event->time = PULSE_SAVE_CORPSES;
break;
default:
bug( "Unsupported Event Type %d", event->type );
break;
}
}
// Deal with stuff that hasn't been converted to event format
// yet
if ( IS_SET( sysdata.act, MUD_AUTOSAVE_DB ) )
{
if ( --pulse_db_dump <= 0 )
{
wiznet( NULL, WIZ_TICKS, L_DIR, "Dump Area pulse (OLC)" );
pulse_db_dump = PULSE_DB_DUMP;
do_asave( NULL, "" );
}
}
/* Maniac, added this warning so it can be delayed on time... */
switch ( pulse_db_dump )
{
case 5: wiznet( NULL, WIZ_TICKS, L_JUN,
"Dump Area pulse coming soon... beware of lag" );
case 100: wiznet( NULL, WIZ_TICKS, L_SEN,
"Dump Area Pulse in 100 pulses..." );
}
time_update( );
tail_chain( );
return;
}