<URL: http://bugs.freeciv.org/Ticket/Display.html?id=37425 >
This adds gui_type to base_type structure. This patch does not
implement any use for it, just reading from ruleset & sending to
client.
In the future clients will use this to determine what base is built
by pressing 'F' etc. Possible values for gui_type are 'Fortress',
'Airbase' and 'Other'.
- ML
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c 2007-03-02 15:10:46.000000000 +0200
+++ freeciv/client/packhand.c 2007-03-03 17:30:49.000000000 +0200
@@ -2464,6 +2464,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-02 15:10:46.000000000 +0200
+++ freeciv/common/base.c 2007-03-03 17:34:18.000000000 +0200
@@ -29,6 +29,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
****************************************************************************/
@@ -122,3 +127,38 @@
requirement_vector_init(&base_types[i].reqs);
}
}
+
+/**************************************************************************
+ 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
+ && 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-02 15:10:46.000000000 +0200
+++ freeciv/common/base.h 2007-03-03 17:34:06.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);
#define base_type_iterate(pbase) \
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def 2007-03-02 15:10:46.000000000 +0200
+++ freeciv/common/packets.def 2007-03-03 17:30:21.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-02 15:10:39.000000000 +0200
+++ freeciv/data/civ1/terrain.ruleset 2007-03-03 17:27:18.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
@@ -617,6 +618,7 @@
{ "type", "name", "range"
"Tech", "Construction", "Player"
}
+gui_type = "Fortress"
flags = "NoAggressive", "DefenseBonus", "Watchtower", "ClaimTerritory",
"NoStackDeath", "DiplomatDefense"
@@ -626,5 +628,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-02 15:10:39.000000000 +0200
+++ freeciv/data/civ2/terrain.ruleset 2007-03-03 17:27:18.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
@@ -709,6 +710,7 @@
{ "type", "name", "range"
"Tech", "Construction", "Player"
}
+gui_type = "Fortress"
flags = "NoAggressive", "DefenseBonus", "Watchtower", "ClaimTerritory",
"NoStackDeath", "DiplomatDefense"
@@ -718,5 +720,6 @@
{ "type", "name", "range"
"Tech", "Radio", "Player"
}
+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-02 15:10:39.000000000 +0200
+++ freeciv/data/default/terrain.ruleset 2007-03-03 17:27:18.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
@@ -776,6 +777,7 @@
{ "type", "name", "range"
"Tech", "Construction", "Player"
}
+gui_type = "Fortress"
flags = "NoAggressive", "DefenseBonus", "Watchtower", "ClaimTerritory",
"NoStackDeath", "DiplomatDefense"
@@ -785,5 +787,6 @@
{ "type", "name", "range"
"Tech", "Radio", "Player"
}
+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-02 15:10:38.000000000 +0200
+++ freeciv/server/ruleset.c 2007-03-03 17:30:15.000000000 +0200
@@ -1788,6 +1788,7 @@
int j;
char *section;
struct requirement_vector *reqs;
+ char *gui_str;
pbase->name = Q_(pbase->name_orig);
@@ -1802,6 +1803,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++) {
@@ -3066,6 +3074,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-02 15:10:46.000000000 +0200
+++ freeciv/version.in 2007-03-03 17:31:06.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.02")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2007.Mar.03")
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev