timer.c
timer.c · 3.2 KB
From the archive event-queue.zip
Download the archive « Back to the archive contents
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <stdarg.h>
#include "merc.h"
#include "recycle.h"
char *nsprintf(char *fr, char *fmt, ...)
{
char buf[2*MSL];
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
free_string(fr);
return str_dup(buf);
}
void printf_to_world(char *fmt, ...)
{
char buf[2*MSL];
va_list args;
DESCRIPTOR_DATA *d;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
for(d=descriptor_list;d;d=d->next)
{
if(d->character==NULL)
continue;
send_to_char(buf, d->character);
}
return;
}
void printf_to_room(ROOM_INDEX_DATA *rm, char *fmt, ...)
{
char buf[2*MSL];
va_list args;
CHAR_DATA *ch;
va_start(args,fmt);
vsprintf(buf,fmt,args);
va_end(args);
for(ch=rm->people;ch;ch=ch->next_in_room)
send_to_char(buf, ch);
return;
}
EVENT_DATA *create_event(int delay, char *act)
{
EVENT_DATA *ev;
if(!str_cmp(act, "print"))
{
ev=new_event();
ev->action=ACTION_PRINT;
} else if(!str_cmp(act, "wait"))
{
ev=new_event();
ev->action=ACTION_WAIT;
} else if(!str_cmp(act, "act"))
{
ev=new_event();
ev->action=ACTION_ACT;
} else if(!str_cmp(act, "function"))
{ ev=new_event();
ev->action=ACTION_FUNCTION;
}
else { /* Bad Action */
return NULL;
}
ev->delay= delay;
ev->next = events;
events = ev;
return ev;
}
void wait_act(int delay, char *msg, void *a1, void *a2, void *a3, int type)
{
EVENT_DATA *ev=create_event(delay, "act");
ev->args[0]=str_dup(msg);
ev->argv[0]=a1;
ev->argv[1]=a2;
ev->argv[2]=a3;
ev->argi[0]=type;
return;
}
void wait_printf(CHAR_DATA *ch, int delay, char * fmt, ...)
{
char buf[2*MSL];
va_list args;
EVENT_DATA *ev = create_event(delay, "print");
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
ev->args[0] = str_dup(buf);
ev->argv[0] = ch;
return;
}
/* after the delay has been met..it will freeze
* the targeted victim for the set amount of 'dur'ation
* ex: wait_wait(ch,2,5); would:
* cause player who triggered this call to be frozen
* for 5 seconds after 2 seconds of function call
*/
void wait_wait(CHAR_DATA *ch, int delay, int dur)
{
EVENT_DATA *ev = create_event(delay,"wait");
ev->argv[0]=ch;
ev->argi[0]=dur;
}
void wait_function (CHAR_DATA *ch, int delay, DO_FUN *do_fun, char *argument)
{
EVENT_DATA *ev = create_event(delay,"function");
ev->argv[0] = ch;
ev->do_fun = do_fun;
ev->args[0] = str_dup( argument );
return;
}