[EVENTS] obj timers and delayed spells

From: Stephen Wolfe (siv@CYBERENET.NET)
Date: 07/20/98

>   Has anyone implemented Object timers? If so can you give me a some info
> on how to go about it. Also, will Oasis automatically be able to use
> timers (I know its in there) or will more code be needed for that?

i implemented object timers using an event system..basically, i added this
struct to the obj_data struct (or obj_flag_data..whatever) in place of the
timer var..

struct obj_timer_data
  struct event_info *event;     /* pointer to timer event       */
  int type;                     /* bitvector for type of timer  */
  struct obj_timer_data *next;  /* link to next timer on obj    */

the type variable is used to differentiate between object affections, and
other types of timers (extract obj..like corpses)..to save the timers, i
made another struct 'timer_data_save'

struct timer_data_save
  long delay;   /* this would be in pulses      */
  int type;

then just changed timer in obj_file_elem to be like:
struct timer_data_save[MAX_OBJ_TIMER];

then i just modified the saving and loading to start events when there are

> How easy it is to incorporate casting times into spells using events?

easy..change the spell_info struct to include a 'delay' element (i also
put in a 'lag' element for wait_states)..then:

declare this struct:
struct delayed_spell_info {
  struct char_data *ch;
  struct char_data *tch;
  struct obj_data *tobj;
  int spell;

int cast_spell(struct char_data * ch, struct char_data * tch,
                   struct obj_data * tobj, int spellnum)
  struct delayed_spell_info *event_obj;
  if (IS_SET(SINFO.routines, MAG_GROUPS) && !AFF_FLAGGED(ch, AFF_GROUP)) {
    send_to_char("You can't cast this spell if you're not in a group!\r\n",ch);
    return 0;
  send_to_char(OK, ch);
  say_spell(ch, spellnum, tch, tobj);

  if (spell_info[spellnum].delay)
    CREATE(event_obj, struct delayed_spell_info, 1);
    event_obj->ch = ch;
    event_obj->tch = tch;
    event_obj->tobj = tobj;
    event_obj->spell = spellnum;
    add_event(spell_info[spellnum].delay, delayed_spell, ch)
    return 1; /* note that this is always shown as success upon casting */

  return (call_magic(ch, tch, tobj, spellnum, GET_LEVEL(ch), CAST_SPELL));

  struct delayed_spell_info *ev_o = (struct delayed_spell_info *)event_object;

  call_magic(ev_o->ch, ev_o->tch, ev_o->tobj, ev_o->spell,
        GET_LEVEL(ev_o->ch), CAST_SPELL);


of course you'll have to change the add_event call to whatever you use,
and add in delays to all of the spello's on spell_parser.c


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |

This archive was generated by hypermail 2b30 : 12/15/00 PST