void BrowseView::NextClicked() { tasks->GiveUp(); if (mainList != NULL) { const char *lk = NULL; if (linksList != NULL) { int n = linksList->CurrentSelection(); if (n>=0) lk = ((BStringItem*)linksList->ItemAt(n))->Text(); } int sel = mainList->CurrentSelection(); if (sel >= 0) { BListItem *item = mainList->ItemAt(sel); NextInList(mainList,((BStringItem*)item)->Text(),item); } if (lk != NULL) NextInList(linksList,lk); } }
/* function :: heartbeat() * arguments :: none * ====================================================== * This function is called once per game pulse, and it will * check the queue, and execute any pending events, which * has been enqueued to execute at this specific time. */ void heartbeat() { EVENT_DATA *event; ITERATOR Iter; /* current_bucket should be global, it is also used in enqueue_event * to figure out what bucket to place the new event in. */ current_bucket = (current_bucket + 1) % MAX_EVENT_HASH; AttachIterator(&Iter, eventqueue[current_bucket]); while ((event = (EVENT_DATA *) NextInList(&Iter)) != NULL) { /* Here we use the event->passes integer, to keep track of * how many times we have ignored this event. */ if (event->passes-- > 0) continue; /* execute event and extract if needed. We assume that all * event functions are of the following prototype * * bool event_function ( EVENT_DATA *event ); * * Any event returning TRUE is not dequeued, it is assumed * that the event has dequeued itself. */ if (!((*event->fun)(event))) dequeue_event(event); } DetachIterator(&Iter); }
void save_id_handler( ID_HANDLER *handler ) { FILE *fp; ITERATOR Iter; I_ID *id; char location[MAX_BUFFER]; mud_printf( location, "../system/%s.handler", id_handler_names[handler->type] ); if( ( fp = fopen( location, "w" ) ) == NULL ) { bug( "%s: unable to open file to write: %s", __FUNCTION__, location ); return; } fwrite_id_handler( handler, fp ); AttachIterator( &Iter, handler->free_ids ); while( ( id = (I_ID *)NextInList(&Iter) ) != NULL ) fwrite_i_id( id, fp ); DetachIterator( &Iter ); fprintf( fp, "%s\n", FILE_TERMINATOR ); fclose( fp ); return; }
void BrowseView::SetLinkNum(int n,HappyLink *list) { HappyLink *father,*sun; m_DontUpdateURL = true; if (list->Find(&father,&sun,n)) { if (mainList != NULL) { if (!NextInList(mainList,sun->name.String())) // si on ne trouve pas le fils, NextInList(mainList,father->name.String()); // on cherche le père } if (linksList != NULL) NextInList(linksList,sun->name.String()); // là on ne cherche que le fils } m_DontUpdateURL = false; ((MainWindow*)Window())->GoTo(n); }
/* utility */ ID_HANDLER *get_id_handler( int type ) { ID_HANDLER *handler = NULL; ITERATOR Iter; AttachIterator( &Iter, id_handlers ); while( ( handler = (ID_HANDLER *)NextInList( &Iter ) ) != NULL ) if( handler->type == type ) break; DetachIterator( &Iter ); return handler; }
/* function :: strip_event_socket() * arguments :: the socket and the type of event * ====================================================== * This function will dequeue all events of a given type * from the given socket. */ void strip_event_socket(D_SOCKET *dSock, int type) { EVENT_DATA *event; ITERATOR Iter; AttachIterator(&Iter, dSock->events); while ((event = (EVENT_DATA *) NextInList(&Iter)) != NULL) { if (event->type == type) dequeue_event(event); } DetachIterator(&Iter); }
static void link_exits() { D_ROOM *r, *d; //room and destination room D_EXIT *e; //the exit we're linking in the room ITERATOR iterRoom, iterExit; //iterators for rooms and exits if( room_list == NULL ) { bug( "ERROR: Global room list does not exist. Aborting game!!" ); exit(1); } AttachIterator( &iterRoom, room_list );//iterate through all the rooms in the game while( ( r = (D_ROOM*)NextInList( &iterRoom ) ) != NULL ) { if( r->exits ) { AttachIterator( &iterExit, r->exits ); //iterate through each room's exits while( ( e = (D_EXIT*)NextInList(&iterExit ) ) != NULL ) { if( e->dest ) continue;//If it's already linked, skip it if( ( d = frbv( e->destVnum ) ) == NULL ) { bug( "Error: Attempting to link exit to room that does not exist( Room: %i Exit: %s to room %i.)", r->vnum, e->name, e->destVnum ); continue; } e->dest = d; } DetachIterator( &iterExit ); } else { bug( "Error: Room created with unallocated exit list. Correcting now..." ); r->exits = AllocList(); } } DetachIterator( &iterRoom ); return; }
/* function :: strip_event_mobile() * arguments :: the mobile and the type of event * ====================================================== * This function will dequeue all events of a given type * from the given mobile. */ void strip_event_mobile(D_MOBILE *dMob, int type) { EVENT_DATA *event; ITERATOR Iter; AttachIterator(&Iter, dMob->events); while ((event = (EVENT_DATA *) NextInList(&Iter)) != NULL) { if (event->type == type) dequeue_event(event); } DetachIterator(&Iter); }
I_ID *check_free( ID_HANDLER *handler ) { ITERATOR Iter; I_ID *id; if( SizeOfList( handler->free_ids ) <= 0 ) return NULL; AttachIterator( &Iter, handler->free_ids ); id = NextInList( &Iter ); DetachFromList( id, handler->free_ids ); DetachIterator( &Iter ); return id; }
/* function :: event_isset_socket() * arguments :: the socket and the type of event * ====================================================== * This function checks to see if a given type of event * is enqueued/attached to a given socket, and if it is, * it will return a pointer to this event. */ EVENT_DATA *event_isset_socket(D_SOCKET *dSock, int type) { EVENT_DATA *event; ITERATOR Iter; AttachIterator(&Iter, dSock->events); while ((event = (EVENT_DATA *) NextInList(&Iter)) != NULL) { if (event->type == type) break; } DetachIterator(&Iter); return event; }
/* deletion */ void free_id_handler( ID_HANDLER *handler ) { I_ID *id; ITERATOR Iter; /* no other pointers to free at the moment */ DetachFromList( handler, id_handlers ); AttachIterator( &Iter, handler->free_ids ); while ( ( id = (I_ID *)NextInList(&Iter) ) == NULL ) free_i_id( id ); DetachIterator( &Iter ); free( handler ); /*free the memory alotted for the handler*/ return; }
/* function :: event_isset_mobile() * arguments :: the mobile and the type of event * ====================================================== * This function checks to see if a given type of event * is enqueued/attached to a given mobile, and if it is, * it will return a pointer to this event. */ EVENT_DATA *event_isset_mobile(D_MOBILE *dMob, int type) { EVENT_DATA *event; ITERATOR Iter; AttachIterator(&Iter, dMob->events); while ((event = (EVENT_DATA *) NextInList(&Iter)) != NULL) { if (event->type == type) break; } DetachIterator(&Iter); return event; }
bool event_game_tick(EVENT_DATA *event) { ITERATOR Iter; ENTITY_INSTANCE *instance; AttachIterator(&Iter, eInstances_list); while ((instance = (ENTITY_INSTANCE *) NextInList(&Iter)) != NULL) text_to_entity( instance, "Tick! The event queue is working.\r\n" ); DetachIterator(&Iter); event = alloc_event(); event->fun = &event_game_tick; event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); return FALSE; }
D_MOBILE *get_char(D_MOBILE * ch, char *argument) { D_MOBILE *wch; ITERATOR *pIter; char arg[MIL]; // char buf[MSL]; pIter = AllocIterator(dmobile_list); while ((wch = (D_MOBILE *) NextInList(pIter)) != NULL) { if (wch == ch) continue; else if (str_cmp(arg,wch->name)) return wch; else return NULL; } FreeIterator(pIter); return NULL; }
bool event_instance_lua_callback( EVENT_DATA *event ) { ENTITY_INSTANCE *instance = (ENTITY_INSTANCE *)event->owner; ENTITY_INSTANCE *arg_entity; void *content; ITERATOR Iter; int ret, counter = 0; prep_stack( get_frame_script_path( instance->framework ), event->argument ); if( SizeOfList( event->lua_args ) > 0 ) { AttachIterator( &Iter, event->lua_args ); while( ( content = NextInList( &Iter ) ) != NULL ) { switch( tolower( event->lua_cypher[counter++] ) ) { case 's': lua_pushstring( lua_handle, (const char *)content ); break; case 'n': lua_pushnumber( lua_handle, *((int *)content) ); break; case 'i': if( ( arg_entity = get_active_instance_by_id( *((int *)content ) ) ) == NULL ) { bug( "%s: instance with ID:%d is no longer active.", __FUNCTION__, *((int *)content ) ); lua_pushnil( lua_handle ); break; } push_instance( arg_entity, lua_handle ); break; } } DetachIterator( &Iter ); } if( ( ret = lua_pcall( lua_handle, strlen( event->lua_cypher ), LUA_MULTRET, 0 ) ) ) bug( "%s: ret %d: path: %s\r\n - error message: %s.", __FUNCTION__, ret, get_frame_script_path( instance->framework ), lua_tostring( lua_handle, -1 ) ); return FALSE; }
//The world list is just a file with a line-by-line list of all the areas //in the game. void load_world() { FILE *fp; ITERATOR iter; D_AREA *area; char buf[MAX_BUFFER]; area_loader = luaL_newstate(); luaL_openlibs( area_loader ); log_string( "Loading World" ); if( ( fp = fopen( "../areas/list.are", "r" ) ) == NULL ) { log_string( "FATAL ERROR: Area List (areas/list.are) does not exist!" ); abort(); return; } while( !feof( fp ) ) { fgets( buf, MAX_BUFFER, fp ); buf[strlen(buf)-1] = '\0'; //fgets includes the newline in the read, so we kill it here. if( !strcasecmp( buf, "END" ) ) break; load_area( buf ); } fclose( fp ); link_exits(); AttachIterator( &iter, area_list ); while( ( area = (D_AREA*)NextInList( &iter ) ) != NULL ) reset_area( area ); DetachIterator( &iter ); return; }
void do_movement(D_MOBILE *dMob, int dir) { D_MOBILE *xMob; ITERATOR *pIter; bool leftr = FALSE; pIter = AllocIterator(dmobile_list); while ((xMob = (D_MOBILE *) NextInList(pIter)) != NULL) { if (xMob == dMob) continue; if ((dMob->coordx != xMob->coordx) && (dMob->coordz != xMob->coordz) && (dMob->coordy != xMob->coordy)) leftr = TRUE; } switch (dir) { case NORTH: /* North */ stcf(dMob, "You leave for the north.\n\r"); dMob->coordy++; break; case SOUTH: /* South */ stcf(dMob, "You leave for the south.\n\r"); dMob->coordy--; break; case EAST: /* East */ stcf(dMob, "You head eastward.\n\r"); dMob->coordx++; break; case WEST: /* West */ stcf(dMob, "You head westward.\n\r"); dMob->coordx--; break; case UP: /* Up */ stcf(dMob, "You fly upwards.\n\r"); dMob->coordz++; break; case DOWN: /* Down */ stcf(dMob, "You you head downwards.\n\r"); dMob->coordz--; break; case NORTHEAST: /* NorthEast */ dMob->coordy++; dMob->coordx++; break; case SOUTHEAST: /* SouthEast */ dMob->coordy--; dMob->coordx++; break; case SOUTHWEST: /* SouthWest */ dMob->coordy--; dMob->coordx--; break; case NORTHWEST: /* NorthWest */ dMob->coordy++; dMob->coordx--; break; } if (dMob->coordx > HI_XLIMIT) { dMob->coordx--; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordy > HI_YLIMIT) { dMob->coordy--; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordz > HI_ZLIMIT) { dMob->coordz--; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordx < LO_XLIMIT) { dMob->coordx++; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordy < LO_YLIMIT) { dMob->coordy++; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordz < LO_ZLIMIT) { dMob->coordz++; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (leftr) stcf(xMob, "%s has left the room.\n\r",dMob->name); cmd_look(dMob, NULL); return; }
void reset_area( D_AREA *area ) { ITERATOR it,rIt; // it = room iterator, rIt = reset iterator D_OBJ *o; D_RESET *reset; D_MOBILE *m; D_ROOM *room; AttachIterator( &it, area->rooms ); while( ( room = (D_ROOM*)NextInList( &it ) ) != NULL ) { AttachIterator( &rIt, room->resets ); while( ( reset = (D_RESET*)NextInList(&rIt) ) != NULL ) { switch( reset->type ) { default: { bug( "Invalid reset type %c.", reset->type ); break; } case 'o': case 'O': { //if the reset has already fired once we need to see if the object //is still there, if its not, make a new one. if( reset->ptr ) { //if object is still there skip this reset if( IsInList( reset->ptr, room->objects ) ) continue; } if( ( o = clone_obj( fobv( reset->vnum ) ) ) == NULL ) { bug( "Reset calls for object vnum %i which does not exist.", reset->vnum ); continue; } AttachToList( o, room->objects ); //does the reset reference any subresets (contained objects)? if( reset->nest && SizeOfList( reset->nest ) > 0 ) { } o->reset = reset; reset->ptr = o; break; } case 'm': case 'M': { if( reset->ptr ) { if( IsInList( reset->ptr, npc_list ) ) continue; } if( ( m = clone_npc( fmbv( reset->vnum ) ) ) == NULL ) { bug( "Reset calls for NPC vnum %i which does not exist.", reset->vnum ); continue; } AttachToList( m, room->mobiles ); m->npc_data->reset = reset; reset->ptr = m; break; } } } DetachIterator( &rIt ); } DetachIterator( &it ); return; }