<URL: 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.000000000 +0200
+++ freeciv/client/packhand.c 2007-03-06 02:43:54.000000000 +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.000000000 +0200
+++ freeciv/common/base.c 2007-03-06 02:46:02.000000000 +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.000000000 +0200
+++ freeciv/common/base.h 2007-03-06 02:43:54.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 {
@@ -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.000000000 +0200
+++ freeciv/common/packets.def 2007-03-06 02:43:54.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)
@@ -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.000000000 +0200
+++ freeciv/data/civ1/terrain.ruleset 2007-03-06 02:43:54.000000000 +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. Fortress/Airbase/Other
; flags
; - "NoAggressive" = Units inside are not considered aggressive
; - "DefenseBonus" = Units inside gain defense bonus
@@ -618,6 +619,7 @@
"Tech", "Construction", "Player"
"TerrainClass", "Land", "Local"
}
+gui_type = "Fortress"
flags = "NoAggressive", "DefenseBonus", "Watchtower", "ClaimTerritory",
"NoStackDeath", "DiplomatDefense"
@@ -627,5 +629,6 @@
{ "type", "name", "range"
"Tech", "Never", "Player"
}
+gui_type = "Airbase"
flags = "NoStackDeath", "DiplomatDefense", "Refuel", "NoHPLoss",
"AttackUnreachable", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/data/civ2/terrain.ruleset freeciv/data/civ2/terrain.ruleset
--- freeciv/data/civ2/terrain.ruleset 2007-03-04 22:55:02.000000000 +0200
+++ freeciv/data/civ2/terrain.ruleset 2007-03-06 02:43:54.000000000 +0200
@@ -691,6 +691,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. Fortress/Airbase/Other
; flags
; - "NoAggressive" = Units inside are not considered aggressive
; - "DefenseBonus" = Units inside gain defense bonus
@@ -710,6 +711,7 @@
"Tech", "Construction", "Player"
"TerrainClass", "Land", "Local"
}
+gui_type = "Fortress"
flags = "NoAggressive", "DefenseBonus", "Watchtower", "ClaimTerritory",
"NoStackDeath", "DiplomatDefense"
@@ -720,5 +722,6 @@
"Tech", "Radio", "Player"
"TerrainClass", "Land", "Local"
}
+gui_type = "Airbase"
flags = "NoStackDeath", "DiplomatDefense", "Refuel", "NoHPLoss",
"AttackUnreachable", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset 2007-03-04 22:55:02.000000000 +0200
+++ freeciv/data/default/terrain.ruleset 2007-03-06 02:43:54.000000000 +0200
@@ -758,6 +758,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. Fortress/Airbase/Other
; flags
; - "NoAggressive" = Units inside are not considered aggressive
; - "DefenseBonus" = Units inside gain defense bonus
@@ -777,6 +778,7 @@
"Tech", "Construction", "Player"
"TerrainClass", "Land", "Local"
}
+gui_type = "Fortress"
flags = "NoAggressive", "DefenseBonus", "Watchtower", "ClaimTerritory",
"NoStackDeath", "DiplomatDefense"
@@ -787,5 +789,6 @@
"Tech", "Radio", "Player"
"TerrainClass", "Land", "Local"
}
+gui_type = "Airbase"
flags = "NoStackDeath", "DiplomatDefense", "Refuel", "NoHPLoss",
"AttackUnreachable", "ParadropFrom"
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c 2007-03-04 16:55:04.000000000 +0200
+++ freeciv/server/ruleset.c 2007-03-06 02:43:54.000000000 +0200
@@ -1790,6 +1790,7 @@
int j;
char *section;
struct requirement_vector *reqs;
+ char *gui_str;
pbase->name = Q_(pbase->name_orig);
@@ -1804,6 +1805,13 @@
reqs = lookup_req_list(file, section, "reqs");
requirement_vector_copy(&pbase->reqs, reqs);
+ 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++) {
@@ -3068,6 +3076,8 @@
} requirement_vector_iterate_end;
packet.reqs_count = j;
+ 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-03 23:02:09.000000000 +0200
+++ freeciv/version.in 2007-03-06 02:44:16.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.03")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.06")
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev