void fight_round( char_data* ch ) { int time; ch->fighting->shown = 1; time = ( ch->species != NULL ? mob_round( ch, ch->fighting ) : player_round( ch, ch->fighting ) ); if( !ch->Is_Valid( ) ) return; time = modify_delay( ch, time ); if( ch->species != NULL ) add_round( ch->species, time ); if( ch->active.time == -1 ) add_queue( &ch->active, time ); }
void game_one_game() { should_end_game = 0; game_time = 0; // Zeitinfo an Client game_send_info(SEND_BROADCAST); // Regeln laden lua_pushliteral(L, "rules_init"); lua_rawget(L, LUA_GLOBALSINDEX); if (lua_pcall(L, 0, 0, 0) != 0) { fprintf(stderr, "error calling rules_init: %s\n", lua_tostring(L, -1)); lua_pop(L, 1); } // Karte laden world_init(); // Alle Viecher tot. vm_id = 0 creature_init(); // Initialer Worldtick. ruft level_init und ersten level_tick auf. world_tick(); // Beginn der Zeitrechnung... int lasttick = 0; gettimeofday(&game_start, NULL); // onPlayerCreated Event an Rules, PLAYER_CREATED an VM player_game_start(); // Spiel gestartet lua_pushliteral(L, "on_game_started"); lua_rawget(L, LUA_GLOBALSINDEX); if (lua_pcall(L, 0, 0, 0) != 0) { fprintf(stderr, "error calling on_game_started: %s\n", lua_tostring(L, -1)); lua_pop(L, 1); } // Rule Handler game_call_rule_handler("onNewGame", 0); while (!game_exit && !should_end_game) { int tick = get_tick(&game_start); int delta; if (realtime) { delta = tick - lasttick; if (delta < 0 || delta > 200) { // Timewarp? lasttick = tick; continue; } else if (delta < 100) { #ifdef WIN32 Sleep(max(95 - delta, 10)); #else usleep(max(95000 - delta * 1000, 1000)); #endif continue; } } else { delta = 100; } lasttick = tick; // Realtime update real_time = time(NULL) - server_start; // GC lua_gc(L, LUA_GCSTEP, 1); if (!game_paused) { // Runde starten game_send_round_info(SEND_BROADCAST, delta); // Rule Handler game_call_rule_handler("onRound", 0); // World Zeugs world_tick(); } player_round(); if (!game_paused) { // Spielerprogramme ausfuehren player_think(); } player_sync(); if (!game_paused) { // Viecher bewegen creature_moveall(delta); // Zeit weiterlaufen lassen game_time += delta; } // IO Lesen/Schreiben server_tick(); } // Spiel beendet lua_pushliteral(L, "on_game_ended"); lua_rawget(L, LUA_GLOBALSINDEX); if (lua_pcall(L, 0, 0, 0) != 0) { fprintf(stderr, "error calling on_game_ended: %s\n", lua_tostring(L, -1)); lua_pop(L, 1); } server_game_end(); creature_shutdown(); world_shutdown(); }