Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9356) Allow different starting units with split tech t
Home

[Freeciv-Dev] (PR#9356) Allow different starting units with split tech t

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9356) Allow different starting units with split tech trees
From: "Per Inge Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 12 Jul 2004 15:18:49 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9356 >

This patch enables nations with split tech trees to start the game with
different starting units. The way it does this is rather crude and simple,
but it works. First we check if there are any role units matching what we
want that the player can actually build (eg not Explorer for default,
since it requires Seafaring). Then if we don't find anything, we check for
any unit matching this role.

  - Per

Index: server/gamehand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamehand.c,v
retrieving revision 1.136
diff -u -r1.136 gamehand.c
--- server/gamehand.c   3 Jul 2004 17:11:35 -0000       1.136
+++ server/gamehand.c   12 Jul 2004 22:15:45 -0000
@@ -102,7 +102,10 @@
 
   /* Create the unit of an appropriate type, if it exists */
   if (num_role_units(role) > 0) {
-    utype = get_role_unit(role, 0);
+    utype = first_role_unit_for_player(pplayer, role);
+    if (utype == U_LAST) {
+      utype = get_role_unit(role, 0);
+    }
     (void) create_unit(pplayer, x, y, utype, FALSE, 0, -1);
   }
 }
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.35
diff -u -r1.35 unittype.c
--- common/unittype.c   6 Jul 2004 21:48:48 -0000       1.35
+++ common/unittype.c   12 Jul 2004 22:15:45 -0000
@@ -661,6 +661,26 @@
   return U_LAST;
 }
 
+/**************************************************************************
+  Return first unit the player can build, with given role/flag.
+  Returns U_LAST if none match.  Used eg when placing starting units.
+**************************************************************************/
+Unit_Type_id first_role_unit_for_player(struct player *pplayer, int role)
+{
+  int j;
+
+  assert((role >= 0 && role < F_LAST) || (role >= L_FIRST && role < L_LAST));
+
+  for(j = 0; j < n_with_role[role]; j++) {
+    Unit_Type_id utype = with_role[role][j];
+
+    if (can_player_build_unit(pplayer, utype)) {
+      return utype;
+    }
+  }
+
+  return U_LAST;
+}
 
 /**************************************************************************
   Frees the memory associated with this unit type.
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.28
diff -u -r1.28 unittype.h
--- common/unittype.h   6 Jul 2004 21:48:48 -0000       1.28
+++ common/unittype.h   12 Jul 2004 22:15:45 -0000
@@ -274,6 +274,7 @@
 Unit_Type_id get_role_unit(int role, int index);
 Unit_Type_id best_role_unit(struct city *pcity, int role);
 Unit_Type_id best_role_unit_for_player(struct player *pplayer, int role);
+Unit_Type_id first_role_unit_for_player(struct player *pplayer, int role);
 
 void unit_types_free(void);
 
Index: data/default/units.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/units.ruleset,v
retrieving revision 1.58
diff -u -r1.58 units.ruleset
--- data/default/units.ruleset  3 Jul 2004 17:11:35 -0000       1.58
+++ data/default/units.ruleset  12 Jul 2004 22:15:46 -0000
@@ -18,7 +18,10 @@
 ; You should sort role units from worst to better, as often the best
 ; available role unit of a given sort will be picked by choosing
 ; the first available (not obsolete) such unit, or by picking the last
-; such unit directly.
+; such unit directly. When determining starting units, the first 
+; unit with the relevant role that the player can build will be chosen.
+; If no such unit can be found (eg Explorers that require Seafaring),
+; then the first unit with this role will be chosen.
 
 [datafile]
 description="Default unit_type data for Freeciv"

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9356) Allow different starting units with split tech trees, Per Inge Mathisen <=