Re: [Freeciv-Dev] (PR#37425) [Patch] base gui_type

2007-03-08 Thread Marko Lindqvist

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.0 +0200
+++ freeciv/client/packhand.c	2007-03-08 21:02:02.0 +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.0 +0200
+++ freeciv/common/base.c	2007-03-08 21:02:02.0 +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.0 +0200
+++ freeciv/common/base.h	2007-03-08 21:02:38.0 +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.0 +0200
+++ freeciv/common/packets.def	2007-03-08 21:03:20.0 +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.0 +0200
+++ freeciv/data/civ1/terrain.ruleset	2007-03-08 21:05:51.0 +0200
@@ -603,6 +603,7 @@
 ; activity_gfx= tag specifing graphic for unit 

Re: [Freeciv-Dev] (PR#37425) [Patch] base gui_type

2007-03-05 Thread Marko Lindqvist

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

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.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-03-04 18:03:59.0 +0200
+++ freeciv/client/packhand.c	2007-03-06 02:43:54.0 +0200
@@ -2479,6 +2479,8 @@
   }
   assert(pbase->reqs.size == p->reqs_count);
 
+  pbase->gui_type = p->gui_type;
+
   pbase->flags = p->flags;
 }
 
diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c	2007-03-05 00:51:27.0 +0200
+++ freeciv/common/base.c	2007-03-06 02:46:02.0 +0200
@@ -30,6 +30,11 @@
   "AttackUnreachable", "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
 /
@@ -133,3 +138,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-05 00:51:27.0 +0200
+++ freeciv/common/base.h	2007-03-06 02:43:54.0 +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 {
@@ -43,6 +47,7 @@
   char name_orig[MAX_LEN_NAME];
   int id;
   struct requirement_vector reqs;
+  enum base_gui_type gui_type;
   bv_base_flags flags;
 };
 
@@ -57,6 +62,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-03 23:02:08.0 +0200
+++ freeciv/common/packets.def	2007-03-06 02:43:54.0 +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)
@@ -1272,6 +1274,7 @@
   STRING name[MAX_LEN_NAME];
   UINT8 reqs_count;
   REQUIREMENT reqs[MAX_NUM_REQS:reqs_count];
+  BASE_GUI gui_type;
   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-04 22:55:01.0 +0200
+++ freeciv/data/civ1/terrain.ruleset	2007-03-06 02:43:54.0 +0200
@@ -599,6 +599,7 @@
 ; name= Name of the base type.
 ; reqs 	  = requirements to build the base (see effects.ruleset
 ;   and README.effects for help on requirements)
+; gui_type= How gui should handle this base. Fort