From 5f9f09768d52af87520b5ce73254e1f163bc5f67 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Mon, 12 Apr 2021 14:17:25 +0200 Subject: [PATCH 2/2] Use scenario ruleset as fall back. Some scenarios aren't ruleset locked. They can still require that the ruleset has certain ruleset_caps. The current ruleset may not fulfill that requirement. Fall back to the ruleset specified in the scenario's rulesetdir when that happens. The previous behavior was to both fail to load the scenario and to reset the ruleset. See osdn #41994 --- server/savegame/savegame3.c | 63 +++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 304c16f59a..acfab7f2ef 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -1217,6 +1217,7 @@ static void sg_load_savefile(struct loaddata *loading) int i; const char *terr_name; bool ruleset_datafile; + bool current_ruleset_rejected; /* Check status and return if not OK (sg_success != TRUE). */ sg_check_ret(); @@ -1236,7 +1237,40 @@ static void sg_load_savefile(struct loaddata *loading) ruleset_datafile = TRUE; } - if (!game.scenario.is_scenario || game.scenario.ruleset_locked) { + current_ruleset_rejected = FALSE; + if (game.scenario.is_scenario && !game.scenario.ruleset_locked) { + const char *req_caps; + + if (!load_rulesets(NULL, NULL, FALSE, NULL, TRUE, FALSE, + ruleset_datafile)) { + /* Failed to load correct ruleset */ + sg_failure_ret(FALSE, _("Failed to load ruleset '%s'."), + game.server.rulesetdir); + } + + req_caps = secfile_lookup_str_default(loading->file, "", + "scenario.ruleset_caps"); + strncpy(game.scenario.req_caps, req_caps, + sizeof(game.scenario.req_caps) - 1); + game.scenario.req_caps[sizeof(game.scenario.req_caps) - 1] = '\0'; + + if (!has_capabilities(req_caps, game.ruleset_capabilities)) { + /* Current ruleset lacks required capabilities. */ + log_normal(_("Scenario requires ruleset capabilities: %s"), req_caps); + log_normal(_("Ruleset has capabilities: %s"), + game.ruleset_capabilities); + /* TRANS: ... ruleset dir ... scenario name ... */ + log_error(_("Current ruleset %s not compatible with the scenario %s." + " Trying to switch to the ruleset specified by the" + " scenario."), + game.server.rulesetdir, game.scenario.name); + + current_ruleset_rejected = TRUE; + } + } + + if (!game.scenario.is_scenario || game.scenario.ruleset_locked + || current_ruleset_rejected) { const char *ruleset, *alt_dir; ruleset = secfile_lookup_str_default(loading->file, @@ -1269,11 +1303,10 @@ static void sg_load_savefile(struct loaddata *loading) ruleset); } } - } else { - if (!load_rulesets(NULL, NULL, FALSE, NULL, TRUE, FALSE, ruleset_datafile)) { - /* Failed to load correct ruleset */ - sg_failure_ret(FALSE, _("Failed to load ruleset '%s'."), - game.server.rulesetdir); + + if (current_ruleset_rejected) { + /* TRANS: ruleset dir */ + log_normal(_("Successfully loaded the scenario's ruleset %s."), ruleset); } } @@ -1281,24 +1314,6 @@ static void sg_load_savefile(struct loaddata *loading) * with correct skill level etc. */ (void) aifill(0); - if (game.scenario.is_scenario && !game.scenario.ruleset_locked) { - const char *req_caps; - - req_caps = secfile_lookup_str_default(loading->file, "", - "scenario.ruleset_caps"); - strncpy(game.scenario.req_caps, req_caps, sizeof(game.scenario.req_caps) - 1); - game.scenario.req_caps[sizeof(game.scenario.req_caps) - 1] = '\0'; - - if (!has_capabilities(req_caps, game.ruleset_capabilities)) { - /* Current ruleset lacks required capabilities. */ - log_normal(_("Scenario requires ruleset capabilities: %s"), req_caps); - log_normal(_("Ruleset has capabilities: %s"), game.ruleset_capabilities); - log_error(_("Current ruleset not compatible with the scenario.")); - sg_success = FALSE; - return; - } - } - /* Time to load scenario specific luadata */ if (game.scenario.datafile[0] != '\0') { if (!fc_strcasecmp("none", game.scenario.datafile)) { -- 2.30.2