Feature #219 ยป 0035-Keep-track-of-world-peace-start-turn.patch
| common/game.c | ||
|---|---|---|
|   game.info.trading_gold     = GAME_DEFAULT_TRADING_GOLD; | ||
|   game.info.trading_tech     = GAME_DEFAULT_TRADING_TECH; | ||
|   game.info.turn             = 0; | ||
|   game.info.warminglevel     = 0; /* set later */ | ||
|   game.info.warminglevel     = 0; /* Set later */ | ||
|   game.info.year_0_hack      = FALSE; | ||
|   game.info.year             = GAME_DEFAULT_START_YEAR; | ||
|   game.info.top_cities_count = GAME_DEFAULT_TOP_CITIES_COUNT; | ||
| ... | ... | |
|     game.server.unitwaittime      = GAME_DEFAULT_UNITWAITTIME; | ||
|     game.server.plr_colors        = NULL; | ||
|     game.server.random_move_time  = NULL; | ||
|     game.server.world_peace_start = 0; | ||
|   } else { | ||
|     /* Client side takes care of itself in client_main() */ | ||
|   } | ||
| common/game.h | ||
|---|---|---|
|                           * the server we need to remember the old setting */ | ||
|       bool last_updated_year; /* last_updated is still counted as year in this | ||
|                                * game. */ | ||
|       int world_peace_start; | ||
|       char rulesetdir[MAX_LEN_NAME]; | ||
|       char demography[MAX_LEN_DEMOGRAPHY]; | ||
|       char allow_take[MAX_LEN_ALLOW_TAKE]; | ||
| server/savegame/savecompat.c | ||
|---|---|---|
|   secfile_insert_bool(loading->file, FALSE, "map.altitude"); | ||
|   /* World Peace has never started in the old savegame. */ | ||
|   game.info.turn = secfile_lookup_int_default(loading->file, 0, "game.turn"); | ||
|   secfile_insert_int(loading->file, game.info.turn, "game.world_peace_start"); | ||
|   { | ||
|     int ssa_count; | ||
| ... | ... | |
|     secfile_insert_bool(loading->file, FALSE, "map.altitude"); | ||
|     /* World Peace has never started in the old savegame. */ | ||
|     game.info.turn | ||
|       = secfile_lookup_int_default(loading->file, 0, "game.turn"); | ||
|     game.server.world_peace_start | ||
|       = secfile_lookup_int_default(loading->file, game.info.turn, | ||
|                                    "game.world_peace_start"); | ||
|     secfile_replace_int(loading->file, game.server.world_peace_start, | ||
|                         "game.world_peace_start"); | ||
|     /* Add actions for unit activities */ | ||
|     loading->activities.size | ||
|       = secfile_lookup_int_default(loading->file, 0, | ||
| server/savegame/savegame2.c | ||
|---|---|---|
|     = secfile_lookup_int_default(loading->file, 0, "game.turn"); | ||
|   sg_failure_ret(secfile_lookup_int(loading->file, &game.info.year, | ||
|                                     "game.year"), "%s", secfile_error()); | ||
|   game.server.world_peace_start = game.info.turn; | ||
|   game.info.year_0_hack | ||
|     = secfile_lookup_bool_default(loading->file, FALSE, "game.year_0_hack"); | ||
| server/savegame/savegame3.c | ||
|---|---|---|
|     = secfile_lookup_int_default(loading->file, 0, "game.turn"); | ||
|   sg_failure_ret(secfile_lookup_int(loading->file, &game.info.year, | ||
|                                     "game.year"), "%s", secfile_error()); | ||
|   sg_failure_ret(secfile_lookup_int(loading->file, &game.server.world_peace_start, | ||
|                                     "game.world_peace_start"), "%s", secfile_error()); | ||
|   game.info.year_0_hack | ||
|     = secfile_lookup_bool_default(loading->file, FALSE, "game.year_0_hack"); | ||
| ... | ... | |
|   secfile_insert_int(saving->file, game.info.turn, "game.turn"); | ||
|   secfile_insert_int(saving->file, game.info.year, "game.year"); | ||
|   secfile_insert_int(saving->file, game.server.world_peace_start, "game.world_peace_start"); | ||
|   secfile_insert_bool(saving->file, game.info.year_0_hack, | ||
|                       "game.year_0_hack"); | ||
| server/srv_main.c | ||
|---|---|---|
| static void handle_observer_ready(struct connection *pconn); | ||
| static void world_peace_update(void); | ||
| /* command-line arguments to server */ | ||
| struct server_arguments srvarg; | ||
| ... | ... | |
|     } whole_map_iterate_end; | ||
|   } extra_type_by_cause_iterate_end; | ||
|   world_peace_update(); | ||
|   update_diplomatics(); | ||
|   make_history_report(); | ||
|   settings_turn(); | ||
| ... | ... | |
|       } | ||
|       while (server_sniff_all_input() == S_E_OTHERWISE) { | ||
|         /* nothing */ | ||
|         /* Nothing */ | ||
|       } | ||
|       between_turns = timer_renew(between_turns, TIMER_USER, TIMER_ACTIVE, | ||
| ... | ... | |
| 	/* endturn was reached - rank users based on team scores */ | ||
| 	rank_users(TRUE); | ||
|       } else {  | ||
| 	/* game ended for victory conditions - rank users based on survival */ | ||
| 	/* Game ended for victory conditions - rank users based on survival */ | ||
| 	rank_users(FALSE); | ||
|       } | ||
|     } else if (S_S_OVER == server_state()) { | ||
|       /* game terminated by /endgame command - calculate team scores */ | ||
|       /* Game terminated by /endgame command - calculate team scores */ | ||
|       rank_users(TRUE); | ||
|     } | ||
|   } | ||
| ... | ... | |
|     } | ||
|   } | ||
| } | ||
| /**********************************************************************//** | ||
|   Does this turn count as world peace turn? | ||
| **************************************************************************/ | ||
| static bool world_peace_turn(void) | ||
| { | ||
|   players_iterate_alive(pplayer) { | ||
|     bool contact = FALSE; | ||
|     players_iterate_alive(other) { | ||
|       if (pplayer != other) { | ||
|         struct player_diplstate *dstate = player_diplstate_get(pplayer, other); | ||
|         if (dstate->type == DS_WAR) { | ||
|           return FALSE; | ||
|         } | ||
|         if (dstate->type != DS_NO_CONTACT) { | ||
|           contact = TRUE; | ||
|         } | ||
|       } | ||
|     } players_iterate_alive_end; | ||
|     if (!contact) { | ||
|       /* Peace only because there's nobody to show aggression against does not count. */ | ||
|       return FALSE; | ||
|     } | ||
|   } players_iterate_alive_end; | ||
|   return TRUE; | ||
| } | ||
| /**********************************************************************//** | ||
|   Update world peace data. | ||
| **************************************************************************/ | ||
| static void world_peace_update(void) | ||
| { | ||
|   if (!world_peace_turn()) { | ||
|     /* Consecutive world peace turns begin *earliest* after this turn, overwrite older claims. */ | ||
|     game.server.world_peace_start = game.info.turn; | ||
|   } | ||
| } | ||