Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] (PR#14015) Conflicting nations. British and English, for e
Home

[Freeciv-Dev] (PR#14015) Conflicting nations. British and English, for e

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14015) Conflicting nations. British and English, for example
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Tue, 20 Sep 2005 03:40:26 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [jdorje - Mon Sep 19 15:35:50 2005]:
> 
> Sounds like a good move.  Make sure this is ignored when looking for a 
> civil war nation for that nation however (e.g., English/Scottish/Welsh 
> should all be good civil war nations for the British).
> 
> -jason
> 
Ok.
--
mateusz
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.424
diff -u -r1.424 plrhand.c
--- server/plrhand.c    18 Sep 2005 07:26:02 -0000      1.424
+++ server/plrhand.c    20 Sep 2005 10:37:55 -0000
@@ -1302,12 +1302,30 @@
 }
 
 /**************************************************************************
-  Returns how much two nations looks good in the same game
+  Returns how much two nations looks good in the same game.
+  Negative return value means that we really really don't want these
+  nations together.
 **************************************************************************/
-static int nations_match(struct nation_type* n1, struct nation_type* n2)
+static int nations_match(struct nation_type* n1, struct nation_type* n2,
+                         bool ignore_conflicts)
 {
   int i, sum = 0;
+  
+  /* Scottish is a good civil war nation for British */
+  if (!ignore_conflicts) {
+  
+    for (i = 0; i < n1->num_conflicts; i++) {
+      if (n1->conflicts_with[i] == n2) {
+        return -1;
+      }
+    }
 
+    for (i = 0; i < n2->num_conflicts; i++) {
+      if (n2->conflicts_with[i] == n1) {
+        return -1;
+      }
+    }
+  }
   for (i = 0; i < n1->num_groups; i++) {
     if (nation_in_group(n2, n1->groups[i]->name)) {
       sum += n1->groups[i]->match;
@@ -1323,18 +1341,21 @@
 
   choices may be NULL; if so it's ignored.
 ****************************************************************************/
-struct nation_type *pick_available_nation(struct nation_type **choices)
+struct nation_type *pick_available_nation(struct nation_type **choices,
+                                          bool ignore_conflicts)
 {
   enum {
-    UNAVAILABLE, AVAILABLE, PREFERRED
+    UNAVAILABLE, AVAILABLE, PREFERRED, UNWANTED
   } nations_used[game.control.nation_count], looking_for;
   int match[game.control.nation_count], pick;
   int num_nations_avail = 0, pref_nations_avail = 0;
 
   /* Values of nations_used: 
-   * 0: not available
-   * 1: available
-   * 2: preferred choice */
+   * 0: not available - nation is already used or is a special nation
+   * 1: available - we can use this nation
+   * 2: preferred - we can use this nation and it is on the choices list 
+   * 3: unwanted - we can used this nation, but we really don't want to
+   */
   nations_iterate(pnation) {
     if (!is_nation_playable(pnation)
        || pnation->player
@@ -1350,20 +1371,34 @@
     match[pnation->index] = 1;
     players_iterate(pplayer) {
       if (pplayer->nation != NO_NATION_SELECTED) {
-       match[pnation->index]
-         += nations_match(pplayer->nation, pnation) * 100;
+        int x = nations_match(pnation, pplayer->nation, ignore_conflicts);
+       if (x < 0) {
+         nations_used[pnation->index] = UNWANTED;
+         match[pnation->index] = 1;
+         break;
+       } else {
+         match[pnation->index] += x * 100;
+       }
       }
     } players_iterate_end;
 
     num_nations_avail += match[pnation->index];
   } nations_iterate_end;
 
+  /* Mark as prefered those nations which are on the choices list and
+   * which are AVAILABLE, but no UNWANTED */
   for (; choices && *choices != NO_NATION_SELECTED; choices++) {
     if (nations_used[(*choices)->index] == AVAILABLE) {
       pref_nations_avail += match[(*choices)->index];
       nations_used[(*choices)->index] = PREFERRED;
     }
   }
+  
+  nations_iterate(pnation) {
+    if (nations_used[pnation->index] == UNWANTED) {
+      nations_used[pnation->index] = AVAILABLE;
+    }
+  } nations_iterate_end;
 
   assert(num_nations_avail > 0);
   assert(pref_nations_avail >= 0);
@@ -1521,7 +1556,7 @@
 
   /* select a new name and nation for the copied player. */
   /* Rebel will always be an AI player */
-  cplayer->nation = pick_available_nation(civilwar_nations);
+  cplayer->nation = pick_available_nation(civilwar_nations, TRUE);
   pick_random_player_name(cplayer->nation, cplayer->name);
 
   sz_strlcpy(cplayer->username, ANON_USER_NAME);
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.86
diff -u -r1.86 plrhand.h
--- server/plrhand.h    13 Sep 2005 08:43:32 -0000      1.86
+++ server/plrhand.h    20 Sep 2005 10:37:55 -0000
@@ -36,7 +36,8 @@
 void kill_dying_players(void);
 void update_revolution(struct player *pplayer);
 
-struct nation_type *pick_available_nation(struct nation_type **choices);
+struct nation_type *pick_available_nation(struct nation_type **choices,
+                                          bool ignore_conflicts);
 
 void check_player_government_rates(struct player *pplayer);
 void make_contact(struct player *pplayer1, struct player *pplayer2,
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.284
diff -u -r1.284 ruleset.c
--- server/ruleset.c    17 Sep 2005 07:58:21 -0000      1.284
+++ server/ruleset.c    20 Sep 2005 10:38:06 -0000
@@ -2042,7 +2042,7 @@
   struct government *gov;
   int dim, i, j, k, nval, numgroups;
   char temp_name[MAX_LEN_NAME];
-  char **leaders, **sec, **civilwar_nations, **groups;
+  char **leaders, **sec, **civilwar_nations, **groups, **conflicts;
   char* name;
   const char *filename = secfile_filename(file);
 
@@ -2071,6 +2071,16 @@
       pl->groups[j] = add_new_nation_group(groups[j]);
     }
     free(groups);
+    
+    conflicts = 
+      secfile_lookup_str_vec(file, &dim, "%s.conflicts_with", sec[i]);
+    pl->num_conflicts = dim;
+    pl->conflicts_with = fc_malloc(sizeof(*(pl->conflicts_with)) * dim);
+    for (j = 0; j < dim; j++) {
+      /* NO_NATION_SELECTED is allowed here */
+      pl->conflicts_with[j] = find_nation_by_name(conflicts[j]);
+    }
+    free(conflicts);
 
     /* nation leaders */
 
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.293
diff -u -r1.293 srv_main.c
--- server/srv_main.c   18 Sep 2005 07:26:02 -0000      1.293
+++ server/srv_main.c   20 Sep 2005 10:38:06 -0000
@@ -1448,7 +1448,7 @@
       continue;
     }
 
-    player_set_nation(pplayer, pick_available_nation(NULL));
+    player_set_nation(pplayer, pick_available_nation(NULL, FALSE));
     assert(pplayer->nation != NO_NATION_SELECTED);
 
     pplayer->city_style = get_nation_city_style(pplayer->nation);

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