<URL: http://bugs.freeciv.org/Ticket/Display.html?id=34692 >

 This replaces is_barbarian with barbarian_type in nation rulesets. So
we can control if given nation is land or sea barbarian.
 Applies on top of #34111 and pirate nation from #18430.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-01-26 16:37:21.000000000 +0200
+++ freeciv/client/packhand.c	2007-01-27 22:14:13.000000000 +0200
@@ -2516,7 +2516,7 @@
   pl->city_style = p->city_style;
 
   pl->is_playable = p->is_playable;
-  pl->is_barbarian = p->is_barbarian;
+  pl->barb_type = p->barbarian_type;
 
   memcpy(pl->init_techs, p->init_techs, sizeof(pl->init_techs));
   memcpy(pl->init_buildings, p->init_buildings, 
diff -Nurd -X.diff_ignore freeciv/common/fc_types.h freeciv/common/fc_types.h
--- freeciv/common/fc_types.h	2007-01-26 20:05:25.000000000 +0200
+++ freeciv/common/fc_types.h	2007-01-27 22:06:05.000000000 +0200
@@ -162,4 +162,14 @@
 #define DIR8_LAST 8
 #define DIR8_COUNT DIR8_LAST
 
+/*
+ * pplayer->ai.barbarian_type and nations use this enum. Note that the values
+ * have to stay since they are used in savegames.
+ */
+enum barbarian_type {
+  NOT_A_BARBARIAN = 0,
+  LAND_BARBARIAN = 1,
+  SEA_BARBARIAN = 2
+};
+
 #endif /* FC__FC_TYPES_H */
diff -Nurd -X.diff_ignore freeciv/common/nation.c freeciv/common/nation.c
--- freeciv/common/nation.c	2006-07-17 23:56:46.000000000 +0300
+++ freeciv/common/nation.c	2007-01-27 22:07:07.000000000 +0200
@@ -124,17 +124,16 @@
 }
 
 /****************************************************************************
-  Return whether a nation is usable as a barbarian.  If true then barbarians
-  can use this nation.
+  Returns which kind of barbarians can use this nation.
 
   This does not check whether a nation is "used" or "available".
 ****************************************************************************/
-bool is_nation_barbarian(const struct nation_type *nation)
+enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
 {
-  if (!bounds_check_nation(nation, LOG_FATAL, "is_nation_barbarian")) {
+  if (!bounds_check_nation(nation, LOG_FATAL, "nation_barbarian_type")) {
     die("wrong nation %d", nation->index);
   }
-  return nation->is_barbarian;
+  return nation->barb_type;
 }
 
 /***************************************************************
diff -Nurd -X.diff_ignore freeciv/common/nation.h freeciv/common/nation.h
--- freeciv/common/nation.h	2006-07-17 23:56:46.000000000 +0300
+++ freeciv/common/nation.h	2007-01-27 22:05:12.000000000 +0200
@@ -79,7 +79,8 @@
   struct city_name *city_names;		/* The default city names. */
   char *legend;				/* may be empty */
 
-  bool is_playable, is_barbarian;
+  bool is_playable;
+  enum barbarian_type barb_type;
 
   /* civilwar_nations is a NO_NATION_SELECTED-terminated list of index of
    * the nations that can fork from this one.  parent_nations is the inverse
@@ -118,7 +119,7 @@
 const char *get_nation_name_plural(const struct nation_type *nation);
 const char *get_nation_name_orig(const struct nation_type *nation);
 bool is_nation_playable(const struct nation_type *nation);
-bool is_nation_barbarian(const struct nation_type *nation);
+enum barbarian_type nation_barbarian_type(const struct nation_type *nation);
 struct leader *get_nation_leaders(const struct nation_type *nation, int *dim);
 struct nation_type **get_nation_civilwar(const struct nation_type *nation);
 bool get_nation_leader_sex(const struct nation_type *nation,
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-01-26 16:37:21.000000000 +0200
+++ freeciv/common/packets.def	2007-01-27 22:10:44.000000000 +0200
@@ -1184,7 +1184,8 @@
   STRING leader_name[MAX_NUM_LEADERS:leader_count][MAX_LEN_NAME];
   BOOL leader_sex[MAX_NUM_LEADERS:leader_count];
 
-  BOOL is_available, is_playable, is_barbarian;
+  BOOL is_available, is_playable;
+  UINT8 barbarian_type;
   
   UINT8 ngroups;
   UINT8 groups[MAX_NUM_NATION_GROUPS:ngroups];
diff -Nurd -X.diff_ignore freeciv/common/player.h freeciv/common/player.h
--- freeciv/common/player.h	2007-01-26 20:05:25.000000000 +0200
+++ freeciv/common/player.h	2007-01-27 22:06:17.000000000 +0200
@@ -30,16 +30,6 @@
 #define ANON_PLAYER_NAME "noname"
 #define ANON_USER_NAME "Unassigned"
 
-/*
- * pplayer->ai.barbarian_type uses this enum. Note that the values
- * have to stay since they are used in savegames.
- */
-enum barbarian_type {
-  NOT_A_BARBARIAN = 0,
-  LAND_BARBARIAN = 1,
-  SEA_BARBARIAN = 2
-};
-
 enum handicap_type {
   H_NONE = 0,         /* No handicaps */
   H_DIPLOMAT = 1,     /* Can't build offensive diplomats */
diff -Nurd -X.diff_ignore freeciv/data/nation/barbarian.ruleset freeciv/data/nation/barbarian.ruleset
--- freeciv/data/nation/barbarian.ruleset	2006-07-17 23:56:23.000000000 +0300
+++ freeciv/data/nation/barbarian.ruleset	2007-01-27 22:16:06.000000000 +0200
@@ -25,6 +25,6 @@
 
 is_playable = 0
 is_observer = 0
-is_barbarian = 1
+barbarian_type = "Land"
 
 ; nothing more needed for barbarians
diff -Nurd -X.diff_ignore freeciv/data/nation/pirate.ruleset freeciv/data/nation/pirate.ruleset
--- freeciv/data/nation/pirate.ruleset	2007-01-27 22:19:46.000000000 +0200
+++ freeciv/data/nation/pirate.ruleset	2007-01-27 22:16:35.000000000 +0200
@@ -30,6 +30,6 @@
 
 is_playable = 0
 is_observer = 0
-is_barbarian = 1
+barbarian_type = "Sea"
 
 ; nothing more needed for barbarians
diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c
--- freeciv/server/plrhand.c	2007-01-27 22:19:54.000000000 +0200
+++ freeciv/server/plrhand.c	2007-01-27 22:09:12.000000000 +0200
@@ -1364,10 +1364,8 @@
   nations_iterate(pnation) {
     if (pnation->player
         || (only_available && !pnation->is_available)
-        || (barb_type != NOT_A_BARBARIAN && !is_nation_barbarian(pnation))
-        || (barb_type == NOT_A_BARBARIAN
-            && (is_nation_barbarian(pnation)
-                || !is_nation_playable(pnation)))) {
+        || (barb_type != nation_barbarian_type(pnation))
+        || (barb_type == NOT_A_BARBARIAN && !is_nation_playable(pnation))) {
       /* Nation is unplayable or already used: don't consider it. */
       nations_used[pnation->index] = UNAVAILABLE;
       match[pnation->index] = 0;
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-01-26 16:37:20.000000000 +0200
+++ freeciv/server/ruleset.c	2007-01-27 22:15:22.000000000 +0200
@@ -2177,6 +2177,8 @@
   char temp_name[MAX_LEN_NAME];
   char **leaders, **sec, **civilwar_nations, **groups, **conflicts;
   char* name;
+  int barb_land_count = 0;
+  int barb_sea_count = 0;
   const char *filename = secfile_filename(file);
 
   (void) check_ruleset_capabilities(file, "+1.9", filename);
@@ -2194,6 +2196,7 @@
 
   for (i = 0; i < game.control.nation_count; i++) {
     char tmp[200] = "\0";
+    char *barb_type;
 
     pl = get_nation_by_idx(i);
     
@@ -2277,8 +2280,25 @@
 
     pl->is_playable = secfile_lookup_bool_default(file, TRUE,
 						  "%s.is_playable", sec[i]);
-    pl->is_barbarian = secfile_lookup_bool_default(file, FALSE,
-						  "%s.is_barbarian", sec[i]);
+
+
+    /* Check barbarian type. Default is "None" meaning not a barbarian */    
+    barb_type = secfile_lookup_str_default(file, "None",
+                                           "%s.barbarian_type", sec[i]);
+    if (mystrcasecmp(barb_type, "None") == 0) {
+      pl->barb_type = NOT_A_BARBARIAN;
+    } else if (mystrcasecmp(barb_type, "Land") == 0) {
+      pl->barb_type = LAND_BARBARIAN;
+      barb_land_count++;
+    } else if (mystrcasecmp(barb_type, "Sea") == 0) {
+      pl->barb_type = SEA_BARBARIAN;
+      barb_sea_count++;
+    } else {
+      /* TRANS: Do not translate "None", "Land" or "Sea" */
+      freelog(LOG_ERROR, _("Nation %s, barbarian_type is \"%s\". Must be "
+              "\"None\" or \"Land\" or \"Sea\""), pl->name, barb_type);
+      exit(EXIT_FAILURE);
+    }
 
     /* Flags */
 
@@ -2418,6 +2438,17 @@
   free(sec);
   section_file_check_unused(file, filename);
   section_file_free(file);
+
+  if (barb_land_count == 0) {
+    freelog(LOG_ERROR,
+            _("No land barbarian nation defined. At least one required!"));
+    exit(EXIT_FAILURE);
+  }
+  if (barb_sea_count == 0) {
+    freelog(LOG_ERROR,
+            _("No sea barbarian nation defined. At least one required!"));
+    exit(EXIT_FAILURE);
+  }
 }
 
 /**************************************************************************
@@ -3147,7 +3178,7 @@
     packet.city_style = n->city_style;
     packet.is_playable = n->is_playable;
     packet.is_available = n->is_available;
-    packet.is_barbarian = n->is_barbarian;
+    packet.barbarian_type = n->barb_type;
     memcpy(packet.init_techs, n->init_techs, sizeof(packet.init_techs));
     memcpy(packet.init_buildings, n->init_buildings, 
            sizeof(packet.init_buildings));
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to