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

On 1/20/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>  For S2_1 adding ruleset for another barbarian nation is sufficient,
> but in trunk code should be changed so that it doesn't even accept
> same nation for both barbarian players.

 Here is untested code patch for trunk. Ruleset changes need to go in
before this.

 pick_a_nation() is modified so that it can handle barbarian players.
Special pick_barbarian_nation() is removed.
 This does not only mean that no longer is same nation accepted for
both barbarian players. pick_a_nation() has more features that
pick_barbarian_nation() lacked. For instance, pick_barbarian_nation()
always took first available barbarian nation, pick_a_nation() will get
random nation if there is more than needed.


 - ML

diff -Nurd -X.diff_ignore freeciv/server/barbarian.c freeciv/server/barbarian.c
--- freeciv/server/barbarian.c	2006-07-17 23:56:22.000000000 +0300
+++ freeciv/server/barbarian.c	2007-01-21 12:01:31.000000000 +0200
@@ -81,30 +81,6 @@
   return (pplayer->ai.barbarian_type == SEA_BARBARIAN);
 }
 
-/****************************************************************************
-  Return an available barbarian nation.  This simply returns the first
-  available nation, or the first nation already in use by another barbarian
-  player.
-****************************************************************************/
-struct nation_type *pick_barbarian_nation(void)
-{
-  nations_iterate(pnation) {
-    if (is_nation_barbarian(pnation) && !pnation->player) {
-      return pnation;
-    }
-  } nations_iterate_end;
-
-  players_iterate(pplayer) {
-    if (is_barbarian(pplayer)) {
-      assert(is_nation_barbarian(pplayer->nation));
-      return pplayer->nation;
-    }
-  } players_iterate_end;
-
-  assert(0);
-  return NO_NATION_SELECTED;
-}
-
 /**************************************************************************
   Creates the land/sea barbarian player and inits some stuff. If 
   barbarian player already exists, return player pointer. If barbarians 
@@ -112,15 +88,17 @@
 
   Dead barbarians forget the map and lose the money.
 **************************************************************************/
-static struct player *create_barbarian_player(bool land)
+static struct player *create_barbarian_player(enum barbarian_type type)
 {
   int newplayer = game.info.nplayers;
   struct player *barbarians;
-  struct nation_type *nation = pick_barbarian_nation();
+  struct nation_type *nation;
+
+  nation = pick_a_nation(NULL, FALSE, TRUE, type);
 
   players_iterate(barbarians) {
-    if ((land && is_land_barbarian(barbarians))
-        || (!land && is_sea_barbarian(barbarians))) {
+    if ((type == LAND_BARBARIAN && is_land_barbarian(barbarians))
+        || (type == SEA_BARBARIAN && is_sea_barbarian(barbarians))) {
       if (!barbarians->is_alive) {
         barbarians->economic.gold = 0;
         barbarians->is_alive = TRUE;
@@ -165,11 +143,7 @@
 
   /* Do the ai */
   barbarians->ai.control = TRUE;
-  if (land) {
-    barbarians->ai.barbarian_type = LAND_BARBARIAN;
-  } else {
-    barbarians->ai.barbarian_type = SEA_BARBARIAN;
-  }
+  barbarians->ai.barbarian_type = type;
   set_ai_level_directer(barbarians, game.info.skill_level);
   init_tech(barbarians);
   give_initial_techs(barbarians);
@@ -239,7 +213,7 @@
     return FALSE;
   }
 
-  barbarians = create_barbarian_player(TRUE);
+  barbarians = create_barbarian_player(LAND_BARBARIAN);
   if (!barbarians) {
     return FALSE;
   }
@@ -426,7 +400,7 @@
     int rand_factor = myrand(3);
 
     /* land (disembark) barbarians */
-    barbarians = create_barbarian_player(TRUE);
+    barbarians = create_barbarian_player(LAND_BARBARIAN);
     if (city_list_size(victim->cities) > UPRISE_CIV_MOST) {
       uprise = 3;
     }
@@ -443,7 +417,7 @@
     struct unit *ptrans;
     struct unit_type *boat;
 
-    barbarians = create_barbarian_player(FALSE);
+    barbarians = create_barbarian_player(SEA_BARBARIAN);
     boat = find_a_unit_type(L_BARBARIAN_BOAT,-1);
     ptrans = create_unit(barbarians, utile, boat, 0, 0, -1);
     cap = get_transporter_capacity(unit_list_get(utile->units, 0));
diff -Nurd -X.diff_ignore freeciv/server/barbarian.h freeciv/server/barbarian.h
--- freeciv/server/barbarian.h	2006-07-17 23:56:22.000000000 +0300
+++ freeciv/server/barbarian.h	2007-01-21 11:55:40.000000000 +0200
@@ -27,7 +27,6 @@
 
 #define MAP_FACTOR     2000  /* adjust this to get a good uprising frequency */
 
-struct nation_type *pick_barbarian_nation(void);
 bool unleash_barbarians(struct tile *ptile);
 void summon_barbarians(void);
 bool is_land_barbarian(struct player *pplayer);
diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c
--- freeciv/server/plrhand.c	2006-07-21 23:18:07.000000000 +0300
+++ freeciv/server/plrhand.c	2007-01-21 12:02:52.000000000 +0200
@@ -1346,7 +1346,8 @@
 ****************************************************************************/
 struct nation_type *pick_a_nation(struct nation_type **choices,
                                   bool ignore_conflicts,
-				  bool only_available)
+                                  bool only_available,
+                                  enum barbarian_type barb_type)
 {
   enum {
     UNAVAILABLE, AVAILABLE, PREFERRED, UNWANTED
@@ -1363,7 +1364,9 @@
   nations_iterate(pnation) {
     if (!is_nation_playable(pnation)
 	|| pnation->player
-	|| (only_available && !pnation->is_available)) {
+	|| (only_available && !pnation->is_available)
+        || (barb_type == NOT_A_BARBARIAN && is_nation_barbarian(pnation))
+        || (barb_type != NOT_A_BARBARIAN && !is_nation_barbarian(pnation))) {
       /* Nation is unplayable or already used: don't consider it. */
       nations_used[pnation->index] = UNAVAILABLE;
       match[pnation->index] = 0;
@@ -1464,7 +1467,8 @@
 
   /* select a new name and nation for the copied player. */
   /* Rebel will always be an AI player */
-  player_set_nation(cplayer, pick_a_nation(civilwar_nations, TRUE, FALSE));
+  player_set_nation(cplayer, pick_a_nation(civilwar_nations, TRUE, FALSE,
+                                           NOT_A_BARBARIAN));
   pick_random_player_name(cplayer->nation, cplayer->name);
 
   sz_strlcpy(cplayer->username, ANON_USER_NAME);
diff -Nurd -X.diff_ignore freeciv/server/plrhand.h freeciv/server/plrhand.h
--- freeciv/server/plrhand.h	2006-07-17 23:56:22.000000000 +0300
+++ freeciv/server/plrhand.h	2007-01-21 11:59:59.000000000 +0200
@@ -38,7 +38,8 @@
 
 struct nation_type *pick_a_nation(struct nation_type **choices,
                                   bool ignore_conflicts,
-				  bool only_available);
+                                  bool only_available,
+                                  enum barbarian_type barb_type);
 
 void check_player_government_rates(struct player *pplayer);
 void make_contact(struct player *pplayer1, struct player *pplayer2,
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c	2006-07-17 23:56:22.000000000 +0300
+++ freeciv/server/savegame.c	2007-01-21 12:12:41.000000000 +0200
@@ -1916,8 +1916,14 @@
    * necessary.  The savegame should already mark those techs as known.
    * give_initial_techs will crash if the nation is unset. */
 
+  /* It is important that barbarian_type is loaded before
+   * calling is_barbarian() and is_land_barbarian() */
   if (is_barbarian(plr) && plr->nation == NO_NATION_SELECTED) {
-    plr->nation = pick_barbarian_nation();
+    if (is_land_barbarian(plr)) {
+      plr->nation = pick_a_nation(NULL, FALSE, TRUE, LAND_BARBARIAN);
+    } else {
+      plr->nation = pick_a_nation(NULL, FALSE, TRUE, SEA_BARBARIAN);
+    }
   }
 
   /* government */
@@ -3839,7 +3845,8 @@
       /* Some players may have invalid nations in the ruleset.  Pick new
        * nations for them. */
       if (pplayer->nation == NO_NATION_SELECTED) {
-	player_set_nation(pplayer, pick_a_nation(NULL, FALSE, TRUE));
+	player_set_nation(pplayer, pick_a_nation(NULL, FALSE, TRUE,
+                                                 NOT_A_BARBARIAN));
 	freelog(LOG_NORMAL, "%s had invalid nation; changing to %s.",
 		pplayer->name, pplayer->nation->name);
       }
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2007-01-20 01:44:41.000000000 +0200
+++ freeciv/server/srv_main.c	2007-01-21 12:09:42.000000000 +0200
@@ -1571,7 +1571,8 @@
       continue;
     }
 
-    player_set_nation(pplayer, pick_a_nation(NULL, FALSE, TRUE));
+    player_set_nation(pplayer, pick_a_nation(NULL, FALSE, TRUE,
+                                             NOT_A_BARBARIAN));
     assert(pplayer->nation != NO_NATION_SELECTED);
 
     pplayer->city_style = get_nation_city_style(pplayer->nation);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to