Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2934) Eliminate an order dependency in ruleset loading
Home

[Freeciv-Dev] (PR#2934) Eliminate an order dependency in ruleset loading

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2934) Eliminate an order dependency in ruleset loading
From: "Eric S. Raymond via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 28 Jan 2003 22:12:26 -0800
Reply-to: rt@xxxxxxxxxxxxxx

--- common/nation.c.~1.33.~     2003-01-27 17:53:01.000000000 -0500
+++ common/nation.c     2003-01-29 00:45:24.000000000 -0500
@@ -248,6 +248,30 @@
 }
 
 /***************************************************************
+This ensures that no matter what order the nations were read in, the
+barbarians will come last.  The data/default/nations.ruleset file used
+to insist on this, and various obscure things in the barbarian code
+may still depend on it.  Defensive programming...
+***************************************************************/
+void canonicalize_nation_array(void)
+{
+  int j;
+
+  for(j=0; j < game.nation_count; j++)
+      if (strcmp(nations[j].name, "Barbarian") == 0)
+         break;
+  if (j != game.nation_count - 1) {
+      struct nation_type       scratch;
+      memcpy(&scratch, &nations[game.nation_count-1], 
+            sizeof(struct nation_type));
+      memcpy(&nations[game.nation_count-1], &nations[j], 
+            sizeof(struct nation_type));
+      memcpy(&nations[j], &scratch, 
+            sizeof(struct nation_type));
+  }
+}
+
+/***************************************************************
   Returns the id of a team given its name, or TEAM_NONE if 
   not found.
 ***************************************************************/
--- common/nation.h.~1.20.~     2003-01-27 17:53:01.000000000 -0500
+++ common/nation.h     2003-01-29 00:11:23.000000000 -0500
@@ -119,6 +119,7 @@
 void nations_free(void);
 void nation_city_names_free(struct city_name *city_names);
 int get_nation_city_style(Nation_Type_id nation);
+void canonicalize_nation_array(void);
 
 void team_init(void);
 Team_Type_id team_find_by_name(const char *team_name);
--- server/ruleset.c.~1.130.~   2003-01-13 18:27:12.000000000 -0500
+++ server/ruleset.c    2003-01-29 00:08:13.000000000 -0500
@@ -2192,6 +2192,9 @@
     pl->city_names = load_city_name_list(file, sec[i], ".cities");
   }
 
+  /* perform post-load actions on the nations array */
+  canonicalize_nation_array();
+
   /* read miscellaneous city names */
   misc_city_names = load_city_name_list(file, "misc.cities", "");


-- 
                <a href="http://www.catb.org/~esr/";>Eric S. Raymond</a>

Americans have the will to resist because you have weapons. 
If you don't have a gun, freedom of speech has no power.
         -- Yoshimi Ishikawa, Japanese author, in the LA Times 15 Oct 1992



[Prev in Thread] Current Thread [Next in Thread]