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

On 3/6/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
> On 3/3/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> >
> >  This adds gui_type to base_type structure. This patch does not
> > implement any use for it, just reading from ruleset & sending to
> > client.
>
>  - Updated against svn
>  - One can call get_base_by_gui_type() with NULL unit to find any base
> of the gui_type.

 - Updated


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-03-08 21:00:52.000000000 +0200
+++ freeciv/client/packhand.c	2007-03-08 21:02:02.000000000 +0200
@@ -2484,6 +2484,8 @@
 
   pbase->native_to = p->native_to;
 
+  pbase->gui_type = p->gui_type;
+
   pbase->flags = p->flags;
 
   tileset_setup_base(tileset, pbase);
diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c	2007-03-06 03:31:58.000000000 +0200
+++ freeciv/common/base.c	2007-03-08 21:02:02.000000000 +0200
@@ -29,6 +29,11 @@
   "ClaimTerritory", "DiplomatDefense", "ParadropFrom"
 };
 
+/* This must correspond to enum base_gui_type in base.h */
+static const char *base_gui_type_names[] = {
+  "Fortress", "Airbase", "Other"
+};
+
 /****************************************************************************
   Check if base provides effect
 ****************************************************************************/
@@ -161,3 +166,38 @@
     requirement_vector_free(&pbase->reqs);
   } base_type_iterate_end;
 }
+
+/**************************************************************************
+  Convert base gui type names to enum; case insensitive;
+  returns BASE_GUI_LAST if can't match.
+**************************************************************************/
+enum base_gui_type base_gui_type_from_str(const char *s)
+{
+  enum base_gui_type i;
+  
+  assert(ARRAY_SIZE(base_gui_type_names) == BASE_GUI_LAST);
+  
+  for(i = 0; i < BASE_GUI_LAST; i++) {
+    if (mystrcasecmp(base_gui_type_names[i], s)==0) {
+      return i;
+    }
+  }
+  return BASE_GUI_LAST;
+}
+
+/**************************************************************************
+  Get best gui_type base for given parameters
+**************************************************************************/
+struct base_type *get_base_by_gui_type(enum base_gui_type type,
+                                       const struct unit *punit,
+                                       const struct tile *ptile)
+{
+  base_type_iterate(pbase) {
+    if (type == pbase->gui_type
+        && (!punit || can_build_base(punit, pbase, ptile))) {
+      return pbase;
+    }
+  } base_type_iterate_end;
+
+  return NULL;
+}
diff -Nurd -X.diff_ignore freeciv/common/base.h freeciv/common/base.h
--- freeciv/common/base.h	2007-03-08 21:00:52.000000000 +0200
+++ freeciv/common/base.h	2007-03-08 21:02:38.000000000 +0200
@@ -19,6 +19,10 @@
 
 enum base_type_id { BASE_FORTRESS = 0, BASE_AIRBASE, BASE_LAST };
 
+/* This must correspond to base_gui_type_names[] in base.c */
+enum base_gui_type { BASE_GUI_FORTRESS = 0, BASE_GUI_AIRBASE, BASE_GUI_OTHER,
+                     BASE_GUI_LAST };
+
 typedef enum base_type_id Base_type_id;
 
 enum base_flag_id {
@@ -42,6 +46,7 @@
   char graphic_alt[MAX_LEN_NAME];
   char activity_gfx[MAX_LEN_NAME];
   struct requirement_vector reqs;
+  enum base_gui_type gui_type;
   bv_unit_classes native_to;
 
   bv_base_flags flags;
@@ -65,6 +70,11 @@
 enum base_flag_id base_flag_from_str(const char *s);
 struct base_type *base_type_get_by_id(Base_type_id id);
 
+enum base_gui_type base_gui_type_from_str(const char *s);
+struct base_type *get_base_by_gui_type(enum base_gui_type type,
+                                       const struct unit *punit,
+                                       const struct tile *ptile);
+
 void base_types_init(void);
 void base_types_free(void);
 
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def	2007-03-08 21:00:52.000000000 +0200
+++ freeciv/common/packets.def	2007-03-08 21:03:20.000000000 +0200
@@ -194,6 +194,8 @@
 type REQ_TYPE	        = uint8(enum req_source_type)
 type REQ_RANGE		= uint8(enum req_range)
 type EFFECT_TYPE	= uint8(enum effect_type)
+type BASE_GUI           = uint8(enum base_gui_type)
+
 type BV_IMPRS		= bitvector(bv_imprs)
 type BV_UCLASS_FLAGS    = bitvector(bv_unit_class_flags)
 type BV_FLAGS		= bitvector(bv_flags)
@@ -1276,6 +1278,7 @@
   STRING activity_gfx[MAX_LEN_NAME];
   UINT8 reqs_count;
   REQUIREMENT reqs[MAX_NUM_REQS:reqs_count];
+  BASE_GUI gui_type;
   BV_UNIT_CLASSES native_to;
   BV_BASE_FLAGS flags;
 end
diff -Nurd -X.diff_ignore freeciv/data/civ1/terrain.ruleset freeciv/data/civ1/terrain.ruleset
--- freeciv/data/civ1/terrain.ruleset	2007-03-08 21:00:51.000000000 +0200
+++ freeciv/data/civ1/terrain.ruleset	2007-03-08 21:05:51.000000000 +0200
@@ -603,6 +603,7 @@
 ; activity_gfx            = tag specifing graphic for unit building base
 ; reqs 	                  = requirements to build the base (see effects.ruleset
 ;                           and README.effects for help on requirements)
+; gui_type                = How gui should handle this base. Fortress/Airbase/Other 
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
 ;   - "DefenseBonus"      = Units inside gain defense bonus
@@ -621,6 +622,7 @@
       "Tech", "Construction", "Player"
       "TerrainClass", "Land", "Local"
     }
+gui_type     = "Fortress"
 native_to    = "Land"
 flags        = "NoAggressive", "DefenseBonus", "ClaimTerritory",
                "NoStackDeath", "DiplomatDefense"
@@ -634,5 +636,6 @@
     { "type", "name", "range"
       "Tech", "Never", "Player"
     }
+gui_type     = "Airbase"
 native_to    = "Air", "Missile"
 flags        = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/data/civ2/terrain.ruleset freeciv/data/civ2/terrain.ruleset
--- freeciv/data/civ2/terrain.ruleset	2007-03-08 21:00:51.000000000 +0200
+++ freeciv/data/civ2/terrain.ruleset	2007-03-08 21:05:22.000000000 +0200
@@ -695,6 +695,7 @@
 ; activity_gfx            = tag specifing graphic for unit building base
 ; reqs 	                  = requirements to build the base (see effects.ruleset
 ;                           and README.effects for help on requirements)
+; gui_type                = How gui should handle this base. Fortress/Airbase/Other 
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
 ;   - "DefenseBonus"      = Units inside gain defense bonus
@@ -713,6 +714,7 @@
       "Tech", "Construction", "Player"
       "TerrainClass", "Land", "Local"
     }
+gui_type     = "Fortress"
 native_to    = "Land"
 flags        = "NoAggressive", "DefenseBonus", "ClaimTerritory",
                "NoStackDeath", "DiplomatDefense"
@@ -727,5 +729,6 @@
       "Tech", "Radio", "Player"
       "TerrainClass", "Land", "Local"
     }
+gui_type     = "Airbase"
 native_to    = "Air", "Helicopter", "Missile"
 flags        = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset	2007-03-08 21:00:52.000000000 +0200
+++ freeciv/data/default/terrain.ruleset	2007-03-08 21:04:47.000000000 +0200
@@ -762,6 +762,7 @@
 ; activity_gfx            = tag specifing graphic for unit building base
 ; reqs 	                  = requirements to build the base (see effects.ruleset
 ;                           and README.effects for help on requirements)
+; gui_type                = How gui should handle this base. Fortress/Airbase/Other
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
 ;   - "DefenseBonus"      = Units inside gain defense bonus
@@ -780,6 +781,7 @@
       "Tech", "Construction", "Player"
       "TerrainClass", "Land", "Local"
     }
+gui_type     = "Fortress"
 native_to    = "Land"
 flags        = "NoAggressive", "DefenseBonus", "ClaimTerritory",
                "NoStackDeath", "DiplomatDefense"
@@ -794,5 +796,6 @@
       "Tech", "Radio", "Player"
       "TerrainClass", "Land", "Local"
     }
+gui_type     = "Airbase"
 native_to    = "Air", "Helicopter", "Missile"
 flags        = "NoStackDeath", "DiplomatDefense", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-08 21:00:51.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-08 21:02:02.000000000 +0200
@@ -1790,6 +1790,7 @@
     int j;
     char *section;
     struct requirement_vector *reqs;
+    char *gui_str;
 
     pbase->name = Q_(pbase->name_orig);
 
@@ -1830,6 +1831,13 @@
     }
     free(slist);
 
+    gui_str = secfile_lookup_str(file,"%s.gui_type", section);
+    pbase->gui_type = base_gui_type_from_str(gui_str);
+    if (pbase->gui_type == BASE_GUI_LAST) {
+      freelog(LOG_ERROR, "Unknown gui_type %s for base %s.", gui_str, pbase->name);
+      exit(EXIT_FAILURE);
+    }
+
     slist = secfile_lookup_str_vec(file, &nval, "%s.flags", section);
     BV_CLR_ALL(pbase->flags);
     for (j = 0; j < nval; j++) {
@@ -3101,6 +3109,8 @@
     packet.reqs_count = j;
     packet.native_to = b->native_to;
 
+    packet.gui_type = b->gui_type;
+
     packet.flags = b->flags;
 
     lsend_packet_ruleset_base(dest, &packet);
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in	2007-03-08 21:00:52.000000000 +0200
+++ freeciv/version.in	2007-03-08 21:06:14.000000000 +0200
@@ -24,4 +24,4 @@
 #   - Avoid adding a new manditory capbility to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.08-3")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.08-4")
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to