Author: cazfi Date: Mon Dec 7 16:21:39 2015 New Revision: 30875 URL: http://svn.gna.org/viewcvs/freeciv?rev=30875&view=rev Log: Added scenario property "allow_ai_type_fallback" that gives freeciv server permission to use ai type other than one specified in the savegame, if that one is not available. Currently the only supported fallback mechanism is from "threaded" to "classic".
See patch #6593 Modified: branches/S2_6/ai/classic/classicai.c branches/S2_6/client/packhand.c branches/S2_6/common/ai.c branches/S2_6/common/ai.h branches/S2_6/common/game.c branches/S2_6/common/packets.def branches/S2_6/common/player.c branches/S2_6/common/player.h branches/S2_6/fc_version branches/S2_6/server/animals.c branches/S2_6/server/barbarian.c branches/S2_6/server/connecthand.c branches/S2_6/server/edithand.c branches/S2_6/server/plrhand.c branches/S2_6/server/plrhand.h branches/S2_6/server/savegame.c branches/S2_6/server/savegame2.c branches/S2_6/server/srv_main.c branches/S2_6/server/stdinhand.c Modified: branches/S2_6/ai/classic/classicai.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/classic/classicai.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/ai/classic/classicai.c (original) +++ branches/S2_6/ai/classic/classicai.c Mon Dec 7 16:21:39 2015 @@ -105,7 +105,6 @@ /************************************************************************** Call default ai with classic ai type as parameter. - Classicai stores information to "ai" like the default ai common code. **************************************************************************/ static void cai_player_load_relations(struct player *pplayer, struct player *other, Modified: branches/S2_6/client/packhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/client/packhand.c (original) +++ branches/S2_6/client/packhand.c Mon Dec 7 16:21:39 2015 @@ -2888,6 +2888,7 @@ game.scenario.prevent_new_cities = packet->prevent_new_cities; game.scenario.save_random = packet->save_random; game.scenario.handmade = packet->handmade; + game.scenario.allow_ai_type_fallback = packet->allow_ai_type_fallback; editgui_notify_object_changed(OBJTYPE_GAME, 1, FALSE); } Modified: branches/S2_6/common/ai.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/ai.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/common/ai.c (original) +++ branches/S2_6/common/ai.c Mon Dec 7 16:21:39 2015 @@ -328,3 +328,32 @@ fc_assert_ret_val(ai, NULL); return ai->name; } + +/***************************************************************************** + Return usable ai type name, if possible. This is either the name + given as parameter or some fallback name for it. NULL is returned if + no name matches. +*****************************************************************************/ +const char *ai_type_name_or_fallback(const char *orig_name) +{ + if (orig_name == NULL) { + return NULL; + } + + if (ai_type_by_name(orig_name) != NULL) { + return orig_name; + } + + if (!strcmp("threaded", orig_name)) { + struct ai_type *fb; + + fb = ai_type_by_name("classic"); + + if (fb != NULL) { + /* Get pointer to persistent name of the ai_type */ + return ai_name(fb); + } + } + + return NULL; +} Modified: branches/S2_6/common/ai.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/ai.h?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/common/ai.h (original) +++ branches/S2_6/common/ai.h Mon Dec 7 16:21:39 2015 @@ -269,6 +269,7 @@ const char *ai_name(const struct ai_type *ai); struct ai_type *ai_type_by_name(const char *search); +const char *ai_type_name_or_fallback(const char *orig_name); #ifdef DEBUG_AITIMERS void ai_timer_init(void); Modified: branches/S2_6/common/game.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/common/game.c (original) +++ branches/S2_6/common/game.c Mon Dec 7 16:21:39 2015 @@ -345,6 +345,7 @@ game.scenario.handmade = FALSE; game.scenario.prevent_new_cities = FALSE; game.scenario.save_random = FALSE; + game.scenario.allow_ai_type_fallback = FALSE; /* Veteran system. */ game.veteran = NULL; Modified: branches/S2_6/common/packets.def URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/common/packets.def (original) +++ branches/S2_6/common/packets.def Mon Dec 7 16:21:39 2015 @@ -1853,6 +1853,7 @@ BOOL save_random; BOOL prevent_new_cities; BOOL handmade; + BOOL allow_ai_type_fallback; end PACKET_SAVE_SCENARIO = 181; cs, handle-per-conn, dsend Modified: branches/S2_6/common/player.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/common/player.c (original) +++ branches/S2_6/common/player.c Mon Dec 7 16:21:39 2015 @@ -578,6 +578,7 @@ pplayer->ai = NULL; pplayer->was_created = FALSE; + pplayer->savegame_ai_type_name = NULL; pplayer->random_name = TRUE; pplayer->is_connected = FALSE; pplayer->current_conn = NULL; @@ -628,6 +629,11 @@ if (pplayer == NULL) { return; + } + + if (pplayer->savegame_ai_type_name != NULL) { + free(pplayer->savegame_ai_type_name); + pplayer->savegame_ai_type_name = NULL; } /* Clears the attribute blocks. */ Modified: branches/S2_6/common/player.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/player.h?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/common/player.h (original) +++ branches/S2_6/common/player.h Mon Dec 7 16:21:39 2015 @@ -256,6 +256,7 @@ bool ai_controlled; /* 0: not automated; 1: automated */ struct player_ai ai_common; const struct ai_type *ai; + char *savegame_ai_type_name; bool was_created; /* if the player was /created */ bool random_name; Modified: branches/S2_6/fc_version URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/fc_version (original) +++ branches/S2_6/fc_version Mon Dec 7 16:21:39 2015 @@ -54,7 +54,7 @@ # - Avoid adding a new mandatory capability to the development branch for # as long as possible. We want to maintain network compatibility with # the stable branch for as long as possible. -NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Nov.26" +NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Dec.07" NETWORK_CAPSTRING_OPTIONAL="" FREECIV_DISTRIBUTOR="" Modified: branches/S2_6/server/animals.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/animals.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/animals.c (original) +++ branches/S2_6/server/animals.c Mon Dec 7 16:21:39 2015 @@ -100,7 +100,7 @@ return; } - plr = server_create_player(-1, default_ai_type_name(), NULL); + plr = server_create_player(-1, default_ai_type_name(), NULL, FALSE); if (plr == NULL) { return; } Modified: branches/S2_6/server/barbarian.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/barbarian.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/barbarian.c (original) +++ branches/S2_6/server/barbarian.c Mon Dec 7 16:21:39 2015 @@ -125,7 +125,7 @@ } players_iterate_end; /* make a new player, or not */ - barbarians = server_create_player(-1, default_ai_type_name(), NULL); + barbarians = server_create_player(-1, default_ai_type_name(), NULL, FALSE); if (!barbarians) { return NULL; } Modified: branches/S2_6/server/connecthand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/connecthand.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/connecthand.c (original) +++ branches/S2_6/server/connecthand.c Mon Dec 7 16:21:39 2015 @@ -585,7 +585,8 @@ /* Should only be called in such a way as to create a new player * in the pregame */ fc_assert_ret_val(!game_was_started(), FALSE); - pplayer = server_create_player(-1, default_ai_type_name(), NULL); + pplayer = server_create_player(-1, default_ai_type_name(), + NULL, FALSE); /* Pregame => no need to assign_player_colors() */ if (!pplayer) { return FALSE; Modified: branches/S2_6/server/edithand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/edithand.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/edithand.c (original) +++ branches/S2_6/server/edithand.c Mon Dec 7 16:21:39 2015 @@ -1092,7 +1092,8 @@ return; } - pplayer = server_create_player(-1, default_ai_type_name(), NULL); + pplayer = server_create_player(-1, default_ai_type_name(), + NULL, FALSE); if (!pplayer) { notify_conn(pc->self, NULL, E_BAD_COMMAND, ftc_editor, _("Player creation failed.")); Modified: branches/S2_6/server/plrhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/plrhand.c (original) +++ branches/S2_6/server/plrhand.c Mon Dec 7 16:21:39 2015 @@ -1540,8 +1540,9 @@ May return NULL if creation was not possible. ***********************************************************************/ -struct player *server_create_player(int player_id, const char *ai_type, - struct rgbcolor *prgbcolor) +struct player *server_create_player(int player_id, const char *ai_tname, + struct rgbcolor *prgbcolor, + bool allow_ai_type_fallbacking) { struct player_slot *pslot; struct player *pplayer; @@ -1554,7 +1555,12 @@ return NULL; } - pplayer->ai = ai_type_by_name(ai_type); + if (allow_ai_type_fallbacking) { + pplayer->savegame_ai_type_name = fc_strdup(ai_tname); + ai_tname = ai_type_name_or_fallback(ai_tname); + } + + pplayer->ai = ai_type_by_name(ai_tname); if (pplayer->ai == NULL) { player_destroy(pplayer); @@ -2384,7 +2390,8 @@ struct nation_type *rebel_nation; /* make a new player, or not */ - cplayer = server_create_player(-1, ai_name(pplayer->ai), NULL); + cplayer = server_create_player(-1, ai_name(pplayer->ai), + NULL, FALSE); if (!cplayer) { return NULL; } Modified: branches/S2_6/server/plrhand.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.h?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/plrhand.h (original) +++ branches/S2_6/server/plrhand.h Mon Dec 7 16:21:39 2015 @@ -23,8 +23,9 @@ enum plr_info_level { INFO_MINIMUM, INFO_MEETING, INFO_EMBASSY, INFO_FULL }; -struct player *server_create_player(int player_id, const char *ai_type, - struct rgbcolor *prgbcolor); +struct player *server_create_player(int player_id, const char *ai_tname, + struct rgbcolor *prgbcolor, + bool allow_ai_type_fallbacking); const struct rgbcolor *player_preferred_color(struct player *pplayer); void assign_player_colors(void); void server_player_set_color(struct player *pplayer, Modified: branches/S2_6/server/savegame.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/savegame.c (original) +++ branches/S2_6/server/savegame.c Mon Dec 7 16:21:39 2015 @@ -3899,7 +3899,8 @@ /* Create player */ pplayer = server_create_player(player_slot_index(pslot), - default_ai_type_name(), NULL); + default_ai_type_name(), NULL, + FALSE); server_player_init(pplayer, FALSE, FALSE); loaded_players++; } player_slots_iterate_end; Modified: branches/S2_6/server/savegame2.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/savegame2.c (original) +++ branches/S2_6/server/savegame2.c Mon Dec 7 16:21:39 2015 @@ -2602,6 +2602,9 @@ game.scenario.handmade = secfile_lookup_bool_default(loading->file, FALSE, "scenario.handmade"); + game.scenario.allow_ai_type_fallback + = secfile_lookup_bool_default(loading->file, FALSE, + "scenario.allow_ai_type_fallback"); sg_failure_ret(loading->server_state == S_S_INITIAL || (loading->server_state == S_S_RUNNING @@ -2655,6 +2658,10 @@ if (game.scenario.handmade) { secfile_insert_bool(saving->file, game.scenario.handmade, "scenario.handmade"); + } + if (game.scenario.allow_ai_type_fallback) { + secfile_insert_bool(saving->file, game.scenario.allow_ai_type_fallback, + "scenario.allow_ai_type_fallback"); } } @@ -3613,7 +3620,7 @@ /* Create player. */ pplayer = server_create_player(player_slot_index(pslot), string, - prgbcolor); + prgbcolor, game.scenario.allow_ai_type_fallback); sg_failure_ret(pplayer != NULL, "Invalid AI type: '%s'!", string); server_player_init(pplayer, FALSE, FALSE); Modified: branches/S2_6/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/srv_main.c (original) +++ branches/S2_6/server/srv_main.c Mon Dec 7 16:21:39 2015 @@ -2182,7 +2182,8 @@ int filled = 1; struct player *pplayer; - pplayer = server_create_player(-1, default_ai_type_name(), NULL); + pplayer = server_create_player(-1, default_ai_type_name(), + NULL, FALSE); /* !game_was_started() so no need to assign_player_colors() */ if (!pplayer) { break; Modified: branches/S2_6/server/stdinhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=30875&r1=30874&r2=30875&view=diff ============================================================================== --- branches/S2_6/server/stdinhand.c (original) +++ branches/S2_6/server/stdinhand.c Mon Dec 7 16:21:39 2015 @@ -865,8 +865,8 @@ new_slot = TRUE; } - if (new_slot) { - if (normal_player_count() == game.server.max_players) { + if (new_slot) { + if (normal_player_count() == game.server.max_players) { fc_assert(game.server.max_players < MAX_NUM_PLAYERS); @@ -876,7 +876,7 @@ } /* Create the new player. */ - pplayer = server_create_player(-1, ai, NULL); + pplayer = server_create_player(-1, ai, NULL, FALSE); if (!pplayer) { fc_snprintf(buf, buflen, _("Failed to create new player %s."), name); return C_FAIL; @@ -1023,7 +1023,7 @@ pplayer->ai = ai_type_by_name(ai); } else { /* add new player */ - pplayer = server_create_player(-1, ai, NULL); + pplayer = server_create_player(-1, ai, NULL, FALSE); /* pregame so no need to assign_player_colors() */ if (!pplayer) { fc_snprintf(buf, buflen, _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits