From 0f98b3ff434e87bb63ff4ac75ea78cf5e684c445 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 11 Feb 2024 23:23:51 +0200 Subject: [PATCH 44/44] Add World Peace victory See osdn #48664 Signed-off-by: Marko Lindqvist --- common/fc_types.h | 3 ++- common/game.h | 4 +++- server/settings.c | 7 +++++-- server/srv_main.c | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/common/fc_types.h b/common/fc_types.h index 322e3c4b96..871550d858 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -1278,7 +1278,8 @@ enum victory_condition_type { VC_SPACERACE = 0, VC_ALLIED, - VC_CULTURE + VC_CULTURE, + VC_WORLDPEACE }; enum environment_upset_type diff --git a/common/game.h b/common/game.h index df8ae0c7f2..22a2bdd8a1 100644 --- a/common/game.h +++ b/common/game.h @@ -754,7 +754,9 @@ static inline bool is_ruleset_compat_mode(void) /* Max number of recursive transports. */ #define GAME_TRANSPORT_MAX_RECURSIVE 5 -/* ruleset settings */ +#define WORLD_PEACE_TURNS 20 + +/* Ruleset settings */ #define RS_MAX_VALUE 1000000 diff --git a/server/settings.c b/server/settings.c index a0287c9ee8..60ff1ad62d 100644 --- a/server/settings.c +++ b/server/settings.c @@ -376,9 +376,10 @@ static const struct sset_val_name *victory_conditions_name(int condition_bit) NAME_CASE(VC_SPACERACE, "SPACERACE", N_("Spacerace")); NAME_CASE(VC_ALLIED, "ALLIED", N_("Allied victory")); NAME_CASE(VC_CULTURE, "CULTURE", N_("Culture victory")); + NAME_CASE(VC_WORLDPEACE, "WORLDPEACE", N_("World Peace victory")); }; - return NULL; + return nullptr; } /************************************************************************//** @@ -2662,7 +2663,9 @@ static struct setting settings[] = { "- \"Allied\" (ALLIED): After defeating enemies, all remaining " "players are allied.\n" "- \"Culture\" (CULTURE): Player meets ruleset defined cultural " - "domination criteria.\n"), + "domination criteria.\n" + "- \"World Peace\" (WORLDPEACE): There's no wars in the world for " + "the specified amount of turns.\n"), NULL, NULL, victory_conditions_name, GAME_DEFAULT_VICTORY_CONDITIONS) GEN_BOOL("endspaceship", game.server.endspaceship, SSET_RULES_FLEXIBLE, diff --git a/server/srv_main.c b/server/srv_main.c index 7edf693839..55fcec3a14 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -403,7 +403,7 @@ bool check_for_game_over(void) candidates = 0; defeated = 0; victor = NULL; - /* Do not use player_iterate_alive here - dead player must be counted as + /* Do not use player_iterate_alive() here - dead player must be counted as * defeated to end the game with a victory. */ players_iterate(pplayer) { if (is_barbarian(pplayer)) { @@ -521,6 +521,39 @@ bool check_for_game_over(void) } } + /* Check for World Peace victory. */ + if (1 < candidates && victory_enabled(VC_WORLDPEACE)) { + if (game.info.turn - game.server.world_peace_start >= WORLD_PEACE_TURNS) { + bool first = TRUE; + + astr_init(&str); + + players_iterate_alive(pplayer) { + if (first) { + /* TRANS: Beginning of the winners list ("the French") */ + astr_add(&str, Q_("?winners:the %s"), + nation_plural_for_player(pplayer)); + first = FALSE; + } else { + /* TRANS: Another entry in winners list (", the Tibetans") */ + astr_add(&str, Q_("?winners:, the %s"), + nation_plural_for_player(pplayer)); + } + + pplayer->is_winner = TRUE; + + } players_iterate_alive_end; + + notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server, + /* TRANS: There can be several winners listed */ + _("World Peace victory to %s."), astr_str(&str)); + log_normal(_("World Peace victory to %s."), astr_str(&str)); + astr_free(&str); + + return TRUE; + } + } + /* Check for single player victory. */ if (1 == candidates && NULL != victor) { bool found = FALSE; /* We need at least one enemy defeated. */ -- 2.43.0