[Freeciv-Dev] (PR#12558) remove "section" field of item struct
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12558 >
This patch removes the section field of the item struct - it can easily
be calculated on demand.
I'd like to remove the description field too (with a
cid_get_description) function, and remove the item structure entirely.
With cid's and wid's, the overabundance of types just adds confusion to
the cityrep interface.
-jason
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.157
diff -u -r1.157 climisc.c
--- client/climisc.c 18 Mar 2005 11:26:24 -0000 1.157
+++ client/climisc.c 20 Mar 2005 04:24:40 -0000
@@ -582,16 +582,42 @@
}
/**************************************************************************
+ Return the numerical "section" of an item. This is used for sorting.
+**************************************************************************/
+static int cid_get_section(cid cid)
+{
+ bool is_unit = cid_is_unit(cid);
+ int id = cid_id(cid);
+
+ if (is_unit) {
+ if (unit_type_flag(id, F_NONMIL)) {
+ return 2;
+ } else {
+ return 3;
+ }
+ } else {
+ if (building_has_effect(id, EFT_PROD_TO_GOLD)) {
+ return 1;
+ } else if (is_great_wonder(id)) {
+ return 4;
+ } else {
+ return 0;
+ }
+ }
+}
+
+/**************************************************************************
Helper for name_and_sort_items.
**************************************************************************/
static int my_cmp(const void *p1, const void *p2)
{
- const struct item *i1 = (const struct item *) p1;
- const struct item *i2 = (const struct item *) p2;
+ const struct item *i1 = p1, *i2 = p2;
+ int s1 = cid_get_section(i1->cid), s2 = cid_get_section(i2->cid);
- if (i1->section == i2->section)
+ if (s1 == s2) {
return mystrcasecmp(i1->descr, i2->descr);
- return (i1->section - i2->section);
+ }
+ return s1 - s2;
}
/**************************************************************************
@@ -620,19 +646,12 @@
if (is_unit) {
name = get_unit_name(id);
cost = unit_build_shield_cost(id);
- pitem->section = unit_type_flag(id, F_NONMIL) ? 2 : 3;
} else {
name = get_impr_name_ex(pcity, id);
if (building_has_effect(id, EFT_PROD_TO_GOLD)) {
cost = -1;
- pitem->section = 1;
} else {
cost = impr_build_shield_cost(id);
- if (is_great_wonder(id)) {
- pitem->section = 4;
- } else {
- pitem->section = 0;
- }
}
}
Index: client/climisc.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v
retrieving revision 1.54
diff -u -r1.54 climisc.h
--- client/climisc.h 17 Feb 2005 03:12:54 -0000 1.54
+++ client/climisc.h 20 Mar 2005 04:24:40 -0000
@@ -83,9 +83,6 @@
struct item {
cid cid;
char descr[MAX_LEN_NAME + 40];
-
- /* Privately used for sorting */
- int section;
};
void name_and_sort_items(int *pcids, int num_cids, struct item *items,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12558) remove "section" field of item struct,
Jason Short <=
|
|