<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39620 >
On 27/08/2007, Marko Lindqvist wrote: > > <URL: http://bugs.freeciv.org/Ticket/Display.html?id=39620 > > > Nothing happens when one tries to sell buildings in current trunk > using gtk-client. Fix. Includes some generic cleanup-style changes I made while debugging problem. Actual fix is citydlg.c:1621. It was storing improvement pointer instead of number. Original report referring to TRUNK only is older than S2_2 branch. - ML
diff -Nurd -X.diff_ignore freeciv/client/climisc.c freeciv/client/climisc.c --- freeciv/client/climisc.c 2008-01-15 04:53:51.000000000 +0200 +++ freeciv/client/climisc.c 2008-01-28 10:26:51.000000000 +0200 @@ -489,21 +489,42 @@ /************************************************************************** Decode the CID into a city_production structure. **************************************************************************/ -struct universal cid_decode(cid cid) +struct universal cid_decode(cid cid_value) { struct universal target; - if (cid >= B_LAST) { + if (cid_value >= B_LAST) { target.kind = VUT_UTYPE; - target.value.utype = utype_by_number(cid - B_LAST); + target.value.utype = utype_by_number(cid_value - B_LAST); } else { target.kind = VUT_IMPROVEMENT; - target.value.building = improvement_by_number(cid); + target.value.building = improvement_by_number(cid_value); } return target; } +/************************************************************************** + Decode the CID into a improvement type id. It's an error to call + this if you are not sure that cid is for building. +**************************************************************************/ +Impr_type_id cid_decode_improvement(cid cid_value) +{ + assert(cid_value <= B_LAST); + + return cid_value; +} +/************************************************************************** + Decode the CID into a unit type id. It's an error to call + this if you are not sure that cid is for unit. +**************************************************************************/ +Unit_type_id cid_decode_unit(cid cid_value) +{ + assert(cid_value > B_LAST); + + return cid_value - B_LAST; +} + /**************************************************************************** Return TRUE if the city supports at least one unit of the given production type (returns FALSE if the production is a building). diff -Nurd -X.diff_ignore freeciv/client/climisc.h freeciv/client/climisc.h --- freeciv/client/climisc.h 2007-09-14 14:52:09.000000000 +0300 +++ freeciv/client/climisc.h 2008-01-28 01:23:10.000000000 +0200 @@ -60,6 +60,8 @@ struct universal cid_decode(cid cid); #define cid_production cid_decode +Impr_type_id cid_decode_improvement(cid cid_value); +Unit_type_id cid_decode_unit(cid cid_value); bool city_unit_supported(const struct city *pcity, struct universal target); diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/citydlg.c freeciv/client/gui-gtk-2.0/citydlg.c --- freeciv/client/gui-gtk-2.0/citydlg.c 2008-01-15 04:53:47.000000000 +0200 +++ freeciv/client/gui-gtk-2.0/citydlg.c 2008-01-28 10:45:24.000000000 +0200 @@ -1618,7 +1618,7 @@ gtk_list_store_append(store, &it); gtk_list_store_set(store, &it, - 0, target.value, + 0, improvement_number(target.value.building), 1, sprite_get_pixbuf(sprite), 2, items[item].descr, 3, upkeep, @@ -2547,7 +2547,8 @@ GtkTreeModel *model; GtkTreeIter it; GdkModifierType mask; - int id; + cid cid_value; + Impr_type_id id; model = gtk_tree_view_get_model(view); @@ -2555,8 +2556,9 @@ return; } - gtk_tree_model_get(model, &it, 0, &id, -1); + gtk_tree_model_get(model, &it, 0, &cid_value, -1); gdk_window_get_pointer(NULL, NULL, NULL, &mask); + id = cid_decode_improvement(cid_value); if (!(mask & GDK_CONTROL_MASK)) { sell_callback(id, data); diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c --- freeciv/common/improvement.c 2007-09-14 14:51:37.000000000 +0300 +++ freeciv/common/improvement.c 2008-01-28 10:45:54.000000000 +0200 @@ -537,4 +537,3 @@ { return (city_has_building(pcity, pimprove) && is_improvement(pimprove)); } -
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev