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; }
/* event_game_tick is just to show how to make global events * which can be used to update the game. */ bool event_game_tick(EVENT_DATA *event) { ITERATOR Iter; D_MOBILE *dMob; /* send a tick message to everyone */ /* AttachIterator(&Iter, dmobile_list); while ((dMob = (D_MOBILE *) NextInList(&Iter)) != NULL) { text_to_mobile(dMob, "Tick!\n\r"); } DetachIterator(&Iter); */ /* enqueue another game tick in 10 minutes */ event = alloc_event(); event->fun = &event_game_tick; event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); return FALSE; }
/* function :: init_event_queue() * arguments :: what section to initialize. * ====================================================== * This function is used to initialize the event queue, * and the first section should be initialized at boot, * the second section should be called after all areas, * players, monsters, etc has been loaded into memory, * and it should contain all maintanence events. */ void init_event_queue(int section) { EVENT_DATA *event; int i; if (section == 1) { for (i = 0; i < MAX_EVENT_HASH; i++) { eventqueue[i] = AllocList(); } event_free = AllocStack(); global_events = AllocList(); } else if (section == 2) { event = alloc_event(); event->fun = &event_game_tick; event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); } }
static void load_area( const char * name ) { lua_State *L = area_loader; //shortcut name int status; char filename[MAX_BUFFER]; D_AREA *area; EVENT_DATA *event; log_string( "--Loading %s", name ); snprintf( filename, MAX_BUFFER, "../areas/%s", name ); if( ( status = luaL_loadfile( L, filename ) ) ) { bug( "ERROR: Can not find area file %s(%s)", filename, lua_tostring( L, -1 ) ); return; } if( lua_pcall( L, 0, 1, 0 ) ) { bug( "ERROR: Unable to parse area file (%s)", lua_tostring( L, -1 ) ); return; } if( ( area = new_area() ) == NULL ) { bug( "ERROR: Unable to allocate memory for area." ); return; } //load the area stats if( load_area_stats( L, area ) == FALSE ) //syntax errors in the area file { log_string( "----stats (failed)" ); return; } else { log_string( "----stats" ); } //load the actual rooms, stored in the table 'rooms' if( load_area_rooms( L, area ) == FALSE ) { log_string( "----rooms(failed)" ); //failing room load == fail area load return; } else { log_string( "----rooms" ); } //load the objects, stored in table 'objects' if( load_area_objects( L, area ) == FALSE ) { log_string( "----objects(failed)" ); } else { log_string( "----objects" ); } //load the NPCs, stored in table 'mobiles' if( load_area_mobiles( L, area ) == FALSE ) { log_string( "----mobiles(failed)" ); } else { log_string( "----mobiles" ); } //enqueue its first reset if( ( event = alloc_event() ) == NULL ) { bug( "Error: (System) Unable to allocate memory for new event!" ); exit( 1 ); } event->fun = event_reset_area; event->type = EVENT_RESET_AREA; event->owner.dArea = area; add_event_game( event, area->reset_time * 60 * PULSES_PER_SECOND ); return; }