[Freeciv-Dev] (PR#13609) remove more CID code from the climisc API
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13609 >
This patch changes most remaining users of CIDs in the client API to use
city_production.
CIDs are still used internally in a few places where serialization is
needed. This includes some climisc functions as well as the GUI code.
-jason
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.177
diff -p -u -r1.177 climisc.c
--- client/climisc.c 4 Aug 2005 17:45:24 -0000 1.177
+++ client/climisc.c 4 Aug 2005 19:16:21 -0000
@@ -156,9 +156,9 @@ void client_remove_city(struct city *pci
Change all cities building X to building Y, if possible. X and Y
could be improvements or units. X and Y are compound ids.
**************************************************************************/
-void client_change_all(cid x, cid y)
+void client_change_all(struct city_production from,
+ struct city_production to)
{
- struct city_production from = cid_production(x), to = cid_production(y);
char buf[512];
int last_request_id = 0;
@@ -549,10 +549,8 @@ bool city_building_present(const struct
/**************************************************************************
Return the numerical "section" of an item. This is used for sorting.
**************************************************************************/
-static int cid_get_section(cid cid)
+static int target_get_section(struct city_production target)
{
- struct city_production target = cid_decode(cid);
-
if (target.is_unit) {
if (unit_type_flag(get_unit_type(target.value), F_NONMIL)) {
return 2;
@@ -576,7 +574,8 @@ static int cid_get_section(cid cid)
static int my_cmp(const void *p1, const void *p2)
{
const struct item *i1 = p1, *i2 = p2;
- int s1 = cid_get_section(i1->cid), s2 = cid_get_section(i2->cid);
+ int s1 = target_get_section(i1->item);
+ int s2 = target_get_section(i2->item);
if (s1 == s2) {
return mystrcasecmp(i1->descr, i2->descr);
@@ -594,18 +593,19 @@ static int my_cmp(const void *p1, const
section 3: other units
section 4: wonders
**************************************************************************/
-void name_and_sort_items(int *pcids, int num_cids, struct item *items,
+void name_and_sort_items(struct city_production *targets, int num_targets,
+ struct item *items,
bool show_cost, struct city *pcity)
{
int i;
- for (i = 0; i < num_cids; i++) {
- struct city_production target = cid_decode(pcids[i]);
+ for (i = 0; i < num_targets; i++) {
+ struct city_production target = targets[i];
int cost;
struct item *pitem = &items[i];
const char *name;
- pitem->cid = pcids[i];
+ pitem->item = target;
if (target.is_unit) {
name = get_unit_name(get_unit_type(target.value));
@@ -630,13 +630,14 @@ void name_and_sort_items(int *pcids, int
}
}
- qsort(items, num_cids, sizeof(struct item), my_cmp);
+ qsort(items, num_targets, sizeof(struct item), my_cmp);
}
/**************************************************************************
...
**************************************************************************/
-int collect_production_targets(cid * dest_cids, struct city **selected_cities,
+int collect_production_targets(struct city_production *targets,
+ struct city **selected_cities,
int num_selected_cities, bool append_units,
bool append_wonders, bool change_prod,
TestCityFunc test_func)
@@ -672,7 +673,7 @@ int collect_production_targets(cid * des
if (!append)
continue;
- dest_cids[items_used] = cid;
+ targets[items_used] = target;
items_used++;
}
return items_used;
@@ -682,9 +683,9 @@ int collect_production_targets(cid * des
Collect the cids of all targets (improvements and units) which are
currently built in a city.
**************************************************************************/
-int collect_currently_building_targets(cid * dest_cids)
+int collect_currently_building_targets(struct city_production *targets)
{
- bool mapping[B_LAST + U_LAST];
+ bool mapping[MAX_NUM_PRODUCTION_TARGETS];
int cids_used = 0;
cid cid;
@@ -696,7 +697,7 @@ int collect_currently_building_targets(c
for (cid = 0; cid < ARRAY_SIZE(mapping); cid++) {
if (mapping[cid]) {
- dest_cids[cids_used] = cid;
+ targets[cids_used] = cid_decode(cid);
cids_used++;
}
}
@@ -707,20 +708,22 @@ int collect_currently_building_targets(c
Collect the cids of all targets (improvements and units) which can
be build in a city.
**************************************************************************/
-int collect_buildable_targets(cid * dest_cids)
+int collect_buildable_targets(struct city_production *targets)
{
int cids_used = 0;
impr_type_iterate(id) {
if (can_player_build_improvement(game.player_ptr, id)) {
- dest_cids[cids_used] = cid_encode_building(id);
+ targets[cids_used].is_unit = FALSE;
+ targets[cids_used].value = id;
cids_used++;
}
} impr_type_iterate_end;
unit_type_iterate(punittype) {
if (can_player_build_unit(game.player_ptr, punittype)) {
- dest_cids[cids_used] = cid_encode_unit(punittype);
+ targets[cids_used].is_unit = TRUE;
+ targets[cids_used].value = punittype->index;
cids_used++;
}
} unit_type_iterate_end
@@ -732,7 +735,7 @@ int collect_buildable_targets(cid * dest
Collect the cids of all targets which can be build by this city or
in general.
**************************************************************************/
-int collect_eventually_buildable_targets(cid * dest_cids,
+int collect_eventually_buildable_targets(struct city_production *targets,
struct city *pcity,
bool advanced_tech)
{
@@ -752,7 +755,8 @@ int collect_eventually_buildable_targets
if ((advanced_tech && can_eventually_build) ||
(!advanced_tech && can_build)) {
- dest_cids[cids_used] = cid_encode_building(id);
+ targets[cids_used].is_unit = FALSE;
+ targets[cids_used].value = id;
cids_used++;
}
} impr_type_iterate_end;
@@ -771,7 +775,8 @@ int collect_eventually_buildable_targets
if ((advanced_tech && can_eventually_build) ||
(!advanced_tech && can_build)) {
- dest_cids[cids_used] = cid_encode_unit(punittype);
+ targets[cids_used].is_unit = TRUE;
+ targets[cids_used].value = punittype->index;
cids_used++;
}
} unit_type_iterate_end;
@@ -782,14 +787,16 @@ int collect_eventually_buildable_targets
/**************************************************************************
Collect the cids of all improvements which are built in the given city.
**************************************************************************/
-int collect_already_built_targets(cid * dest_cids, struct city *pcity)
+int collect_already_built_targets(struct city_production *targets,
+ struct city *pcity)
{
int cids_used = 0;
assert(pcity != NULL);
built_impr_iterate(pcity, id) {
- dest_cids[cids_used] = cid_encode_building(id);
+ targets[cids_used].is_unit = FALSE;
+ targets[cids_used].value = id;
cids_used++;
} built_impr_iterate_end;
Index: client/climisc.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v
retrieving revision 1.60
diff -p -u -r1.60 climisc.h
--- client/climisc.h 4 Aug 2005 17:45:24 -0000 1.60
+++ client/climisc.h 4 Aug 2005 19:16:21 -0000
@@ -26,7 +26,8 @@ void client_remove_player(int plrno);
void client_remove_city(struct city *pcity);
void client_remove_unit(struct unit *punit);
-void client_change_all(cid x, cid y);
+void client_change_all(struct city_production from,
+ struct city_production to);
const char *get_embassy_status(const struct player *me,
const struct player *them);
@@ -68,24 +69,28 @@ bool city_building_present(const struct
struct city_production target);
struct item {
- cid cid;
+ struct city_production item;
char descr[MAX_LEN_NAME + 40];
};
typedef bool (*TestCityFunc)(const struct city *, struct city_production);
-void name_and_sort_items(int *pcids, int num_cids, struct item *items,
+#define MAX_NUM_PRODUCTION_TARGETS (U_LAST + B_LAST)
+void name_and_sort_items(struct city_production *targets, int num_items,
+ struct item *items,
bool show_cost, struct city *pcity);
-int collect_production_targets(cid * dest_cids, struct city **selected_cities,
+int collect_production_targets(struct city_production *targets,
+ struct city **selected_cities,
int num_selected_cities, bool append_units,
bool append_wonders, bool change_prod,
TestCityFunc test_func);
-int collect_currently_building_targets(cid * dest_cids);
-int collect_buildable_targets(cid * dest_cids);
-int collect_eventually_buildable_targets(cid * dest_cids,
+int collect_currently_building_targets(struct city_production *targets);
+int collect_buildable_targets(struct city_production *targets);
+int collect_eventually_buildable_targets(struct city_production *targets,
struct city *pcity,
bool advanced_tech);
-int collect_already_built_targets(cid * dest_cids, struct city *pcity);
+int collect_already_built_targets(struct city_production *targets,
+ struct city *pcity);
/* the number of units in city */
int num_present_units_in_city(struct city* pcity);
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.139
diff -p -u -r1.139 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 4 Aug 2005 17:45:24 -0000 1.139
+++ client/gui-gtk-2.0/citydlg.c 4 Aug 2005 19:16:23 -0000
@@ -1510,9 +1510,9 @@ static void city_dialog_update_building(
GtkListStore* store;
GtkTreeIter iter;
- cid cids[U_LAST + B_LAST];
- struct item items[U_LAST + B_LAST];
- int cids_used, item;
+ struct city_production targets[MAX_NUM_PRODUCTION_TARGETS];
+ struct item items[MAX_NUM_PRODUCTION_TARGETS];
+ int targets_used, item;
gtk_widget_set_sensitive(pdialog->overview.buy_command, sensitive);
gtk_widget_set_sensitive(pdialog->production.buy_command, sensitive);
@@ -1551,14 +1551,15 @@ static void city_dialog_update_building(
-1);
gtk_list_store_clear(store);
- cids_used = collect_eventually_buildable_targets(cids, pdialog->pcity,
FALSE);
- name_and_sort_items(cids, cids_used, items, FALSE, pcity);
+ targets_used
+ = collect_eventually_buildable_targets(targets, pdialog->pcity, FALSE);
+ name_and_sort_items(targets, targets_used, items, FALSE, pcity);
- for (item = 0; item < cids_used; item++) {
- if (city_can_build_impr_or_unit(pcity, cid_decode(items[item].cid))) {
+ for (item = 0; item < targets_used; item++) {
+ if (city_can_build_impr_or_unit(pcity, items[item].item)) {
const char* name;
struct sprite* sprite;
- struct city_production target = cid_decode(items[item].cid);
+ struct city_production target = items[item].item;
if (target.is_unit) {
name = unit_name(get_unit_type(target.value));
@@ -1569,7 +1570,7 @@ static void city_dialog_update_building(
}
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, sprite_get_pixbuf(sprite),
- 1, name, 2, (gint)items[item].cid, -1);
+ 1, name, 2, (gint)cid_encode(items[item].item), -1);
}
}
@@ -1583,9 +1584,9 @@ static void city_dialog_update_building(
*****************************************************************/
static void city_dialog_update_improvement_list(struct city_dialog *pdialog)
{
- int total, item, cids_used;
- cid cids[U_LAST + B_LAST];
- struct item items[U_LAST + B_LAST];
+ int total, item, targets_used;
+ struct city_production targets[MAX_NUM_PRODUCTION_TARGETS];
+ struct item items[MAX_NUM_PRODUCTION_TARGETS];
GtkTreeModel *model;
GtkListStore *store;
@@ -1593,17 +1594,17 @@ static void city_dialog_update_improveme
gtk_tree_view_get_model(GTK_TREE_VIEW(pdialog->overview.improvement_list));
store = GTK_LIST_STORE(model);
- cids_used = collect_already_built_targets(cids, pdialog->pcity);
- name_and_sort_items(cids, cids_used, items, FALSE, pdialog->pcity);
+ targets_used = collect_already_built_targets(targets, pdialog->pcity);
+ name_and_sort_items(targets, targets_used, items, FALSE, pdialog->pcity);
gtk_list_store_clear(store);
total = 0;
- for (item = 0; item < cids_used; item++) {
+ for (item = 0; item < targets_used; item++) {
GtkTreeIter it;
int upkeep;
struct sprite *sprite;
- struct city_production target = cid_decode(items[item].cid);
+ struct city_production target = items[item].item;
assert(!target.is_unit);
/* This takes effects (like Adam Smith's) into account. */
Index: client/gui-gtk-2.0/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cityrep.c,v
retrieving revision 1.78
diff -p -u -r1.78 cityrep.c
--- client/gui-gtk-2.0/cityrep.c 4 Aug 2005 17:45:24 -0000 1.78
+++ client/gui-gtk-2.0/cityrep.c 4 Aug 2005 19:16:23 -0000
@@ -199,9 +199,9 @@ static void append_impr_or_unit_to_menu_
int size)
{
GtkWidget *menu;
- cid cids[U_LAST + B_LAST];
- struct item items[U_LAST + B_LAST];
- int i, item, cids_used;
+ struct city_production targets[MAX_NUM_PRODUCTION_TARGETS];
+ struct item items[MAX_NUM_PRODUCTION_TARGETS];
+ int i, item, targets_used;
char *row[4];
char buf[4][64];
@@ -237,15 +237,18 @@ static void append_impr_or_unit_to_menu_
}
data = (struct city **)g_ptr_array_free(selected, FALSE);
- cids_used = collect_production_targets(cids, data, num_selected,
append_units,
- append_wonders, TRUE, test_func);
+ targets_used
+ = collect_production_targets(targets, data, num_selected, append_units,
+ append_wonders, TRUE, test_func);
g_free(data);
} else {
- cids_used = collect_production_targets(cids, NULL, 0, append_units,
- append_wonders, FALSE, test_func);
+ targets_used = collect_production_targets(targets, NULL, 0, append_units,
+ append_wonders, FALSE,
+ test_func);
}
- name_and_sort_items(cids, cids_used, items, city_operation != CO_NONE, NULL);
+ name_and_sort_items(targets, targets_used, items,
+ city_operation != CO_NONE, NULL);
for (i = 0; i < 4; i++) {
row[i] = buf[i];
@@ -259,14 +262,12 @@ static void append_impr_or_unit_to_menu_
group[i] = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
}
- for (item = 0; item < cids_used; item++) {
- cid cid = items[item].cid;
+ for (item = 0; item < targets_used; item++) {
+ struct city_production target = items[item].item;
GtkWidget *menu_item, *hbox, *label;
char txt[256];
- get_city_dialog_production_row(row, sizeof(buf[0]), cid_production(cid),
- NULL);
-
+ get_city_dialog_production_row(row, sizeof(buf[0]), target, NULL);
menu_item = gtk_menu_item_new();
hbox = gtk_hbox_new(FALSE, 18);
@@ -295,7 +296,7 @@ static void append_impr_or_unit_to_menu_
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
g_signal_connect(menu_item, "activate", callback,
- GINT_TO_POINTER(items[item].cid));
+ GINT_TO_POINTER(cid_encode(target)));
}
for (i = 0; i < 3; i++) {
@@ -304,7 +305,7 @@ static void append_impr_or_unit_to_menu_
gtk_widget_show_all(menu);
- gtk_widget_set_sensitive(GTK_WIDGET(parent_item), (cids_used > 0));
+ gtk_widget_set_sensitive(GTK_WIDGET(parent_item), (targets_used > 0));
}
/****************************************************************
@@ -313,12 +314,12 @@ static void append_impr_or_unit_to_menu_
static void impr_or_unit_iterate(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *it, gpointer data)
{
- cid cid = GPOINTER_TO_INT(data);
+ struct city_production target = cid_decode(GPOINTER_TO_INT(data));
gint id;
gtk_tree_model_get(model, it, 1, &id, -1);
- city_change_production(find_city_by_id(id), cid_production(cid));
+ city_change_production(find_city_by_id(id), target);
}
/****************************************************************
@@ -332,14 +333,14 @@ static void worklist_last_impr_or_unit_i
GtkTreeIter *it,
gpointer data)
{
- cid cid = GPOINTER_TO_INT(data);
+ struct city_production target = cid_decode(GPOINTER_TO_INT(data));
gint id;
struct city *pcity;
gtk_tree_model_get(model, it, 1, &id, -1);
pcity = find_city_by_id(id);
- (void) city_queue_insert(pcity, -1, cid_production(cid));
+ (void) city_queue_insert(pcity, -1, target);
/* perhaps should warn the user if not successful? */
}
@@ -356,14 +357,14 @@ static void worklist_first_impr_or_unit_
GtkTreeIter *it,
gpointer data)
{
- cid cid = GPOINTER_TO_INT(data);
+ struct city_production target = cid_decode(GPOINTER_TO_INT(data));
gint id;
struct city *pcity;
gtk_tree_model_get(model, it, 1, &id, -1);
pcity = find_city_by_id(id);
- (void) city_queue_insert(pcity, 0, cid_production(cid));
+ (void) city_queue_insert(pcity, 0, target);
/* perhaps should warn the user if not successful? */
}
@@ -380,12 +381,12 @@ static void worklist_next_impr_or_unit_i
{
struct city *pcity;
gint id;
- cid cid = GPOINTER_TO_INT(data);
+ struct city_production target = cid_decode(GPOINTER_TO_INT(data));
gtk_tree_model_get(model, it, 1, &id, -1);
pcity = find_city_by_id(id);
- (void) city_queue_insert(pcity, 1, cid_production(cid));
+ (void) city_queue_insert(pcity, 1, target);
/* perhaps should warn the user if not successful? */
}
@@ -394,7 +395,7 @@ static void worklist_next_impr_or_unit_i
*****************************************************************/
static void select_impr_or_unit_callback(GtkWidget *w, gpointer data)
{
- cid cid = GPOINTER_TO_INT(data);
+ struct city_production target = cid_decode(GPOINTER_TO_INT(data));
GObject *parent = G_OBJECT(w->parent);
TestCityFunc test_func = g_object_get_data(parent, "freeciv_test_func");
enum city_operation_type city_operation =
@@ -413,7 +414,7 @@ static void select_impr_or_unit_callback
itree_get(&it, 0, &res, -1);
pcity = res;
- if (test_func(pcity, cid_decode(cid))) {
+ if (test_func(pcity, target)) {
itree_select(city_selection, &it);
}
}
@@ -423,21 +424,22 @@ static void select_impr_or_unit_callback
case CO_LAST:
gtk_tree_selection_selected_foreach(city_selection,
worklist_last_impr_or_unit_iterate,
- GINT_TO_POINTER(cid));
+ GINT_TO_POINTER(cid_encode(target)));
break;
case CO_CHANGE:
gtk_tree_selection_selected_foreach(city_selection,
- impr_or_unit_iterate,
GINT_TO_POINTER(cid));
+ impr_or_unit_iterate,
+ GINT_TO_POINTER(cid_encode(target)));
break;
case CO_FIRST:
gtk_tree_selection_selected_foreach(city_selection,
worklist_first_impr_or_unit_iterate,
- GINT_TO_POINTER(cid));
+ GINT_TO_POINTER(cid_encode(target)));
break;
case CO_NEXT:
gtk_tree_selection_selected_foreach(city_selection,
worklist_next_impr_or_unit_iterate,
- GINT_TO_POINTER(cid));
+ GINT_TO_POINTER(cid_encode(target)));
break;
default:
assert(FALSE); /* should never get here. */
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/wldlg.c,v
retrieving revision 1.50
diff -p -u -r1.50 wldlg.c
--- client/gui-gtk-2.0/wldlg.c 4 Aug 2005 17:45:24 -0000 1.50
+++ client/gui-gtk-2.0/wldlg.c 4 Aug 2005 19:16:23 -0000
@@ -1331,9 +1331,9 @@ void refresh_worklist(GtkWidget *editor)
struct worklist_data *ptr;
struct worklist *pwl, queue;
- cid cids[U_LAST + B_LAST];
- int i, cids_used;
- struct item items[U_LAST + B_LAST];
+ struct city_production targets[MAX_NUM_PRODUCTION_TARGETS];
+ int i, targets_used;
+ struct item items[MAX_NUM_PRODUCTION_TARGETS];
bool selected;
gint id;
@@ -1360,15 +1360,15 @@ void refresh_worklist(GtkWidget *editor)
}
gtk_list_store_clear(ptr->src);
- cids_used = collect_eventually_buildable_targets(cids, ptr->pcity,
ptr->future);
- name_and_sort_items(cids, cids_used, items, FALSE, ptr->pcity);
+ targets_used = collect_eventually_buildable_targets(targets, ptr->pcity,
ptr->future);
+ name_and_sort_items(targets, targets_used, items, FALSE, ptr->pcity);
path = NULL;
- for (i = 0; i < cids_used; i++) {
+ for (i = 0; i < targets_used; i++) {
gtk_list_store_append(ptr->src, &it);
- gtk_list_store_set(ptr->src, &it, 0, (gint) items[i].cid, -1);
+ gtk_list_store_set(ptr->src, &it, 0, (gint) cid_encode(items[i].item), -1);
- if (selected && items[i].cid == id) {
+ if (selected && cid_encode(items[i].item) == id) {
path = gtk_tree_model_get_path(GTK_TREE_MODEL(ptr->src), &it);
}
}
@@ -1390,13 +1390,13 @@ void refresh_worklist(GtkWidget *editor)
}
for (i = 0; i < worklist_length(&queue); i++) {
- cid cid = cid_encode(queue.entries[i]);
+ struct city_production target = queue.entries[i];
if (!exists) {
gtk_list_store_append(ptr->dst, &it);
}
- gtk_list_store_set(ptr->dst, &it, 0, (gint) cid, -1);
+ gtk_list_store_set(ptr->dst, &it, 0, (gint) cid_encode(target), -1);
if (exists) {
exists = gtk_tree_model_iter_next(model, &it);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13609) remove more CID code from the climisc API,
Jason Short <=
|
|