Author: cazfi
Date: Sat Nov 14 19:01:19 2015
New Revision: 30610

URL: http://svn.gna.org/viewcvs/freeciv?rev=30610&view=rev
Log:
Make a savegame loading time check if player has multiple units of a type that 
should
never have more than one instance (unique unit).

See patch #6561

Modified:
    trunk/server/savegame2.c
    trunk/server/savegame3.c

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=30610&r1=30609&r2=30610&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Sat Nov 14 19:01:19 2015
@@ -5003,6 +5003,25 @@
                                sizeof(server.game_identifier));
   }
 
+  /* Check if some player has more than one of some UTYF_UNIQUE unit type */
+  players_iterate(pplayer) {
+    int utype_count[U_LAST];
+
+    memset(utype_count, 0, sizeof(utype_count));
+
+    unit_list_iterate(pplayer->units, punit) {
+      utype_count[utype_index(unit_type_get(punit))]++;
+    } unit_list_iterate_end;
+
+    unit_type_iterate(ut) {
+      if (utype_count[utype_index(ut)] > 1 && utype_has_flag(ut, UTYF_UNIQUE)) 
{
+        log_sg(_("%s has multiple units of type %s though it should be 
possible "
+                 "to have only one."),
+               player_name(pplayer), utype_name_translation(ut));
+      }
+    } unit_type_iterate_end;
+  } players_iterate_end;
+
   /* Restore game random state, just in case various initialization code
    * inexplicably altered the previously existing state. */
   if (!game.info.is_new_game) {

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=30610&r1=30609&r2=30610&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Sat Nov 14 19:01:19 2015
@@ -6755,6 +6755,25 @@
     }
   } researches_iterate_end;
 
+  /* Check if some player has more than one of some UTYF_UNIQUE unit type */
+  players_iterate(pplayer) {
+    int utype_count[U_LAST];
+
+    memset(utype_count, 0, sizeof(utype_count));
+
+    unit_list_iterate(pplayer->units, punit) {
+      utype_count[utype_index(unit_type_get(punit))]++;
+    } unit_list_iterate_end;
+
+    unit_type_iterate(ut) {
+      if (utype_count[utype_index(ut)] > 1 && utype_has_flag(ut, UTYF_UNIQUE)) 
{
+        log_sg(_("%s has multiple units of type %s though it should be 
possible "
+                 "to have only one."),
+               player_name(pplayer), utype_name_translation(ut));
+      }
+    } unit_type_iterate_end;
+  } players_iterate_end;
+
   if (0 == strlen(server.game_identifier)
       || !is_base64url(server.game_identifier)) {
     /* This uses fc_rand(), so random state has to be initialized before. */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to