Alright, I was up all night, and finally gave up with a dequeue_event
function. Basically my goal was not to have to repeat the code 3 times,
each for 3 sections of the union of owner of the event. I just started
putting in events, so I'm not really good at them yet. I got the
idea/inspiration/partial code from Brian excellent about it
(http://www.daimi.au.dk/~jobo/pages/event_queue.php) Also, on the site in
his example for how to use them, he uses a macro to link it locally, i
wasn't able to do this, I ended up needing a whole function, just for the
'CH' version of the link_locally.
heres the link_locally
void link_locally( CHAR_DATA *ch, EVENT_DATA *event )
{
if( event == NULL )
{
bug("link_locally: event is NULL");
return;
}
if( ch->event_first == NULL && ch->event_last == NULL)
{
ch->event_first = event;
ch->event_last = event;
}
else
{
if(ch->event_first == NULL || ch->event_last == NULL)
{
bug("link_locally: event_first or event_last is NULL");
return;
}
ch->event_last->next_local = event;
ch->event_last = event;
}
}
Heres the dequeue_event function... Its fugly...
void dequeue_event( EVENT_DATA *event )
{
CHAR_DATA *ch;
OBJ_DATA *obj;
ROOM_INDEX_DATA *room;
EVENT_DATA *prev = NULL;
if( event == NULL )
{
bug("dequeue_event: event is NULL");
return;
}
if ( event == eventqueue[event->bucket] )
{
eventqueue[event->bucket] = eventqueue[event->bucket]->next_global;
}
else
{
for ( prev = eventqueue[event->bucket] ; prev != NULL ; prev =
prev->next$
{
if ( prev->next_global == event )
{
prev->next_global = event->next_global;
break;
}
}
if ( prev == NULL )
{
bug( "dequeue_event: cannot find event globally." );
return;
}
}
if( ( ch = event->owner.ch) != NULL)
{
prev = ch->event_first;
}
if( ( obj = event->owner.obj) != NULL)
{
prev = obj->event_first;
}
if( ( room = event->owner.room) != NULL)
{
prev = room->event_first;
}
if( !room && !obj && !ch )
{
bug("dequeue event: no owner.");
return;
}
if ( ch && ch->event_first == event )
{
ch->event_first = ch->event_first->next_local;
}
else if ( obj && obj->event_first == event )
{
obj->event_first = obj->event_first->next_local;
}
else if ( room && room->event_first == event )
{
room->event_first = room->event_first->next_local;
}
else
{
for ( ; prev != NULL ; prev = prev->next_local )
{
if ( prev->next_local == event )
{
prev->next_local = event->next_local;
break;
}
}
if ( prev == NULL )
{
bug( "dequeue_event: cannot find event locally." );
return;
}
}
if(ch)
prev = ch->event_first;
else if(obj)
prev = obj->event_first;
else
prev = room->event_first;
for( ; prev ; prev = prev->next_local)
{
if(prev->next_local == NULL)
break;
}
if(ch)
ch->event_last = prev;
else if(obj)
obj->event_last = prev;
else
room->event_last = prev;
if(pEventNext == event)
pEventNext = pEventNext->next_global;
free_event(event);
return;
}
Most of the other info is on that website... if you need any more info, just
let me know, Any help would be appreciated...
I think this finally works... or it did for a player save, I think, but I
know im just missing something major. I tried a void pointer,
and a pointer to a pointer, but couldnt even come close to getting it to
work.
Josh