From be4c4f59ba66056662369a41900392c407226484 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 23 Mar 2022 16:48:17 +0200 Subject: [PATCH 35/35] Adjust AI_LEVEL_EXPERIMENTAL by ai_level_name_update_cb() For non-debug builds with no support for Experimental AI level we need to convert such AIs from savegames to Hard AI. Centralize such conversions to ai_level specenum name updater callback. See osdn #44164 Signed-off-by: Marko Lindqvist --- common/ai.c | 16 ++++++++++++++++ common/fc_types.h | 4 ++++ server/savegame/savegame2.c | 6 ------ server/savegame/savegame3.c | 6 ------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/common/ai.c b/common/ai.c index 12f73c74b0..3eee2ad5b3 100644 --- a/common/ai.c +++ b/common/ai.c @@ -361,3 +361,19 @@ const char *ai_type_name_or_fallback(const char *orig_name) return NULL; } + +/*************************************************************************//** + Return AI level name legal in current build best matching the old name. +*****************************************************************************/ +const char *ai_level_name_update_cb(const char *old) +{ +#ifndef FREECIV_DEBUG + /* No experimental level in !FREECIV_DEBUG build */ + if (!strcasecmp("Experimental", old)) { + /* Convert it to hard */ + return ai_level_name(AI_LEVEL_HARD); + } +#endif /* FREECIV_DEBUG */ + + return old; +} diff --git a/common/fc_types.h b/common/fc_types.h index 4e21d986a1..c3bd1840ff 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -461,6 +461,9 @@ typedef int Unit_Class_id; * compatibility code to server/rscompat.c. */ #define CASUS_BELLI_OUTRAGE 1000 +/* Really in ai.c */ +const char *ai_level_name_update_cb(const char *old); + /* Used in the network protocol. */ /* server/commands.c must match these */ #define SPECENUM_NAME ai_level @@ -485,6 +488,7 @@ typedef int Unit_Class_id; #endif /* FREECIV_DEBUG */ #define SPECENUM_COUNT AI_LEVEL_COUNT +#define SPECENUM_NAME_UPDATER #include "specenum_gen.h" /* pplayer->ai.barbarian_type and nations use this enum. */ diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index d7c411ff1a..113e7b44ed 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -2938,12 +2938,6 @@ static void sg_load_player_main(struct loaddata *loading, } else { plr->ai_common.skill_level = ai_level_by_name(level, fc_strcasecmp); } - - /* In builds where level "Experimental" is not supported, convert it to "Hard" */ - if (!ai_level_is_valid(plr->ai_common.skill_level) - && !fc_strcasecmp(level, "Experimental")) { - plr->ai_common.skill_level = AI_LEVEL_HARD; - } } else { plr->ai_common.skill_level = ai_level_invalid(); } diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index c9d12b5857..4f820139d4 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -4116,12 +4116,6 @@ static void sg_load_player_main(struct loaddata *loading, } else { plr->ai_common.skill_level = ai_level_by_name(level, fc_strcasecmp); } - - /* In builds where level "Experimental" is not supported, convert it to "Hard" */ - if (!ai_level_is_valid(plr->ai_common.skill_level) - && !fc_strcasecmp(level, "Experimental")) { - plr->ai_common.skill_level = AI_LEVEL_HARD; - } } else { plr->ai_common.skill_level = ai_level_invalid(); } -- 2.35.1