Author: cazfi
Date: Mon Dec  7 16:21:08 2015
New Revision: 30874

URL: http://svn.gna.org/viewcvs/freeciv?rev=30874&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:
    trunk/ai/classic/classicai.c
    trunk/client/packhand.c
    trunk/common/ai.c
    trunk/common/ai.h
    trunk/common/game.c
    trunk/common/packets.def
    trunk/common/player.c
    trunk/common/player.h
    trunk/fc_version
    trunk/server/animals.c
    trunk/server/barbarian.c
    trunk/server/connecthand.c
    trunk/server/edithand.c
    trunk/server/plrhand.c
    trunk/server/plrhand.h
    trunk/server/savegame.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/server/srv_main.c
    trunk/server/stdinhand.c

Modified: trunk/ai/classic/classicai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/classic/classicai.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/ai/classic/classicai.c        (original)
+++ trunk/ai/classic/classicai.c        Mon Dec  7 16:21:08 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: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Mon Dec  7 16:21:08 2015
@@ -2927,6 +2927,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: trunk/common/ai.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/ai.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/common/ai.c   (original)
+++ trunk/common/ai.c   Mon Dec  7 16:21:08 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: trunk/common/ai.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/ai.h?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/common/ai.h   (original)
+++ trunk/common/ai.h   Mon Dec  7 16:21:08 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: trunk/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/common/game.c (original)
+++ trunk/common/game.c Mon Dec  7 16:21:08 2015
@@ -346,6 +346,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: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Mon Dec  7 16:21:08 2015
@@ -1888,6 +1888,7 @@
   BOOL   save_random;
   BOOL   prevent_new_cities;
   BOOL   handmade;
+  BOOL   allow_ai_type_fallback;
   BOOL   ruleset_locked;
 end
 

Modified: trunk/common/player.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/player.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/common/player.c       (original)
+++ trunk/common/player.c       Mon Dec  7 16:21:08 2015
@@ -581,6 +581,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;
@@ -631,6 +632,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: trunk/common/player.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/player.h?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/common/player.h       (original)
+++ trunk/common/player.h       Mon Dec  7 16:21:08 2015
@@ -269,6 +269,7 @@
 
   struct player_ai ai_common;
   const struct ai_type *ai;
+  char *savegame_ai_type_name;
 
   bv_plr_flags flags;
 

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Mon Dec  7 16:21:08 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-3.0-2015.Nov.25b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Dec.07"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/animals.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/animals.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/animals.c      (original)
+++ trunk/server/animals.c      Mon Dec  7 16:21:08 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: trunk/server/barbarian.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/barbarian.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/barbarian.c    (original)
+++ trunk/server/barbarian.c    Mon Dec  7 16:21:08 2015
@@ -127,7 +127,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: trunk/server/connecthand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/connecthand.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/connecthand.c  (original)
+++ trunk/server/connecthand.c  Mon Dec  7 16:21:08 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: trunk/server/edithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/edithand.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/edithand.c     (original)
+++ trunk/server/edithand.c     Mon Dec  7 16:21:08 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: trunk/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/plrhand.c      (original)
+++ trunk/server/plrhand.c      Mon Dec  7 16:21:08 2015
@@ -1542,8 +1542,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;
@@ -1556,7 +1557,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);
@@ -2395,7 +2401,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: trunk/server/plrhand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.h?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/plrhand.h      (original)
+++ trunk/server/plrhand.h      Mon Dec  7 16:21:08 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: trunk/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/savegame.c     (original)
+++ trunk/server/savegame.c     Mon Dec  7 16:21:08 2015
@@ -3925,7 +3925,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: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Mon Dec  7 16:21:08 2015
@@ -1764,6 +1764,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
@@ -2384,7 +2387,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: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Mon Dec  7 16:21:08 2015
@@ -2245,6 +2245,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");
 
   game.scenario.ruleset_locked
     = secfile_lookup_bool_default(loading->file, TRUE,
@@ -2302,6 +2305,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");
   }
 }
 
@@ -3162,7 +3169,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: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Mon Dec  7 16:21:08 2015
@@ -2278,7 +2278,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: trunk/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=30874&r1=30873&r2=30874&view=diff
==============================================================================
--- trunk/server/stdinhand.c    (original)
+++ trunk/server/stdinhand.c    Mon Dec  7 16:21:08 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

Reply via email to