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: Sun, 18 Sep 2005 05:05:35 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch allows to specify which nations shouldn't be considered by AI
when selecting a nation in the same.

The patch contains code and two examples in nation rulesets.
--
mateusz
Index: common/nation.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.c,v
retrieving revision 1.56
diff -u -r1.56 nation.c
--- common/nation.c     18 Jul 2005 22:46:28 -0000      1.56
+++ common/nation.c     18 Sep 2005 12:00:19 -0000
@@ -294,6 +294,11 @@
     free(pnation->groups);
     pnation->groups = NULL;
   }
+  
+  if (pnation->conflicts_with) {
+    free(pnation->conflicts_with);
+    pnation->conflicts_with = NULL;
+  }
 
   nation_city_names_free(pnation->city_names);
   pnation->city_names = NULL;
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.56
diff -u -r1.56 nation.h
--- common/nation.h     4 Sep 2005 04:31:17 -0000       1.56
+++ common/nation.h     18 Sep 2005 12:00:20 -0000
@@ -98,6 +98,11 @@
   /* Groups which this nation is assigned to */
   int num_groups;
   struct nation_group **groups;
+  
+  /* Nations which we don't want in the same game.
+   * For example, British and English. */
+  int num_conflicts;
+  struct nation_type **conflicts_with;
 
   /* Unavailable nations aren't allowed in the scenario. */
   bool is_available;
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    18 Sep 2005 12:00:24 -0000
@@ -1302,11 +1302,25 @@
 }
 
 /**************************************************************************
-  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)
 {
   int i, sum = 0;
+  
+  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)) {
@@ -1326,15 +1340,17 @@
 struct nation_type *pick_available_nation(struct nation_type **choices)
 {
   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 +1366,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);
+       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);
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    18 Sep 2005 12:00:31 -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: data/nation/british.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/nation/british.ruleset,v
retrieving revision 1.1
diff -u -r1.1 british.ruleset
--- data/nation/british.ruleset 3 Sep 2005 02:06:41 -0000       1.1
+++ data/nation/british.ruleset 18 Sep 2005 12:00:31 -0000
@@ -3,6 +3,8 @@
 name=_("British")
 plural=_("?plural:British")
 groups=_("Modern"), _("European")
+; We don't want British nation in the same game with English
+conflicts_with="english", "scottish", "welsh"
 legend=_("The United Kingdom was created in 1707 as a negotiated agreement\
  between the kingdom of England and the kingdom of Scotland. The country -\
  also known as Great Britain - became the leading industrial and maritime\
Index: data/nation/italian.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/nation/italian.ruleset,v
retrieving revision 1.14
diff -u -r1.14 italian.ruleset
--- data/nation/italian.ruleset 3 Sep 2005 00:58:08 -0000       1.14
+++ data/nation/italian.ruleset 18 Sep 2005 12:00:31 -0000
@@ -3,6 +3,7 @@
 name = _("Italian")
 plural = _("?plural:Italians")
 groups=_("Medieval"), _("Modern"), _("European")
+conflicts_with="roman"
 legend=_("The Italian nation was unified in 1870AD after decades of \
 campaigning by indigenous nationalists. It was a monarchy under the \
 House of Savoy until 1922, then a fascist state until 1945 after which \

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14015) Conflicting nations. British and English, for example, Mateusz Stefek <=