Re: [Freeciv-Dev] (PR#39568) cannot sell an improvement
URL: http://bugs.freeciv.org/Ticket/Display.html?id=39568 Daniel Markstedt wrote: URL: http://bugs.freeciv.org/Ticket/Display.html?id=39568 [dmarks - Sun Jun 29 01:22:46 2008]: [jdorje - Sun Jun 29 01:17:09 2008]: [pepeto - Mon Oct 15 17:07:29 2007]: Isn't this ticket resolved? Or does it need some more improvement? What about 2.0? Is it still broken there? -jason Yes it is. Tried to merge the first revision of the patch to S2_0, but just worsens the issue. With attached patch selling buildings is completely broken. Ahh so. pcity-owner is a player id not a pointer. So this patch does the trick. -jason Index: client/gui-gtk-2.0/citydlg.c === --- client/gui-gtk-2.0/citydlg.c(revision 14909) +++ client/gui-gtk-2.0/citydlg.c(working copy) @@ -2389,8 +2389,7 @@ return; } - if (pdialog-pcity-did_buy || pdialog-pcity-did_sell || - pdialog-pcity-owner != game.player_idx) { + if (pdialog-pcity-did_sell || pdialog-pcity-owner != game.player_idx) { return; } ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#39568) cannot sell an improvement
URL: http://bugs.freeciv.org/Ticket/Display.html?id=39568 On 14/08/07, Marko Lindqvist [EMAIL PROTECTED] wrote: More intrusive trunk version attached. Untested. Corrected comments. Cannot test because of #39620 and #39621. - ML 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 2007-08-13 20:51:06.0 +0300 +++ freeciv/client/gui-gtk-2.0/citydlg.c 2007-08-27 01:01:27.0 +0300 @@ -2495,12 +2495,8 @@ return; } - if (pdialog-pcity-did_buy || pdialog-pcity-did_sell - || pdialog-pcity-owner != game.player_ptr) { -return; - } - - if (!can_city_sell_building(pdialog-pcity, pimprove)) { + if (!can_player_sell_building_now(game.player_ptr, pdialog-pcity, +pimprove)) { return; } diff -Nurd -X.diff_ignore freeciv/client/gui-sdl/citydlg.c freeciv/client/gui-sdl/citydlg.c --- freeciv/client/gui-sdl/citydlg.c 2007-08-20 00:55:46.0 +0300 +++ freeciv/client/gui-sdl/citydlg.c 2007-08-27 01:02:55.0 +0300 @@ -1490,14 +1490,21 @@ set_wstate(pCityDlg-pImprv-pScroll-pDown_Right_Button, FC_WS_NORMAL); /* down */ } - if (pCityDlg-pCity-did_sell) { + /* There is common function can_player_sell_building_now(), + * but we are not using it here, since we want to use set_group_state() + * when possible */ + if (pCityDlg-pCity-did_sell + || pCityDlg-pCity-owner != game.player_ptr) { set_group_state(pCityDlg-pImprv-pBeginActiveWidgetList, pCityDlg-pImprv-pEndActiveWidgetList, FC_WS_DISABLED); } else { struct widget *pTmpWidget = pCityDlg-pImprv-pEndActiveWidgetList; while (TRUE) { - if (is_wonder(improvement_by_number(MAX_ID - 3000 - pTmpWidget-ID))) { + struct impr_type *pimpr = improvement_by_number(MAX_ID - 3000 - + pTmpWidget-ID); + + if (!can_city_sell_building(pCityDlg-pCity, pimpr)) { set_wstate(pTmpWidget, FC_WS_DISABLED); } else { set_wstate(pTmpWidget, FC_WS_NORMAL); diff -Nurd -X.diff_ignore freeciv/client/gui-win32/citydlg.c freeciv/client/gui-win32/citydlg.c --- freeciv/client/gui-win32/citydlg.c 2007-08-15 01:04:35.0 +0300 +++ freeciv/client/gui-win32/citydlg.c 2007-08-27 01:01:27.0 +0300 @@ -411,7 +411,11 @@ const char *descr = city_production_name_translation(pcity); EnableWindow(pdialog-buy_but, city_can_buy(pcity)); - EnableWindow(pdialog-sell_but, !pcity-did_sell); + + /* FIXME: Should not pass NULL as improvement + * to can_player_sell_building_now(). It skips many tests. */ + EnableWindow(pdialog-sell_but, + can_player_sell_building_now(game.player_ptr, pcity, NULL)); get_city_dialog_production(pcity, buf, sizeof(buf)); diff -Nurd -X.diff_ignore freeciv/client/gui-xaw/citydlg.c freeciv/client/gui-xaw/citydlg.c --- freeciv/client/gui-xaw/citydlg.c 2007-08-13 20:51:06.0 +0300 +++ freeciv/client/gui-xaw/citydlg.c 2007-08-27 01:01:27.0 +0300 @@ -1476,7 +1476,10 @@ struct city *pcity=pdialog-pcity; XtSetSensitive(pdialog-buy_command, city_can_buy(pcity)); - XtSetSensitive(pdialog-sell_command, !pcity-did_sell); + /* FIXME: Should not pass NULL as improvement + * to can_player_sell_building_now(). It skips many tests. */ + XtSetSensitive(pdialog-sell_command, + can_player_sell_building_now(game.player_ptr, pcity, NULL)); xaw_set_label(pdialog-building_label, city_production_name_translation(pcity)); diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c --- freeciv/common/improvement.c 2007-08-13 20:51:03.0 +0300 +++ freeciv/common/improvement.c 2007-08-27 01:10:05.0 +0300 @@ -538,3 +538,25 @@ return (city_has_building(pcity, pimprove) is_improvement(pimprove)); } +/ + Return TRUE iff the player can sell the given improvement from city. + If pimprove is NULL, returns iff city could sell some building type (this + does not check if such building is in this city) +/ +bool can_player_sell_building_now(struct player *pplayer, + struct city *pcity, + struct impr_type *pimprove) +{ + /* Check if player can sell anything from this city */ + if (pcity-did_sell || pcity-owner != pplayer) { +return FALSE; + } + + /* Check if particular building can be built */ + if (pimprove != NULL + !can_city_sell_building(pcity, pimprove)) { +return FALSE; + } + + return TRUE; +} diff -Nurd -X.diff_ignore freeciv/common/improvement.h freeciv/common/improvement.h --- freeciv/common/improvement.h 2007-08-13 20:51:03.0 +0300 +++ freeciv/common/improvement.h
Re: [Freeciv-Dev] (PR#39568) cannot sell an improvement
URL: http://bugs.freeciv.org/Ticket/Display.html?id=39568 On 14/08/07, Pepeto _ [EMAIL PROTECTED] wrote: In the gtk2.0 client, you cannot sell an improvement by clicking on this in the city dialog if you bought in the same turn. This quite annoying... Thanks. Your patch is good for S2_1. More intrusive trunk version attached. Untested. - ML 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 2007-08-13 20:51:06.0 +0300 +++ freeciv/client/gui-gtk-2.0/citydlg.c 2007-08-14 23:02:58.0 +0300 @@ -2495,12 +2495,8 @@ return; } - if (pdialog-pcity-did_buy || pdialog-pcity-did_sell - || pdialog-pcity-owner != game.player_ptr) { -return; - } - - if (!can_city_sell_building(pdialog-pcity, pimprove)) { + if (!can_player_sell_building_now(game.player_ptr, pdialog-pcity, +pimprove)) { return; } diff -Nurd -X.diff_ignore freeciv/client/gui-sdl/citydlg.c freeciv/client/gui-sdl/citydlg.c --- freeciv/client/gui-sdl/citydlg.c 2007-08-13 22:44:48.0 +0300 +++ freeciv/client/gui-sdl/citydlg.c 2007-08-14 23:19:44.0 +0300 @@ -1490,14 +1490,20 @@ set_wstate(pCityDlg-pImprv-pScroll-pDown_Right_Button, FC_WS_NORMAL); /* down */ } - if (pCityDlg-pCity-did_sell) { + /* There is common_function_sell_building_now(), but we are not using + * it here, since we want to use set_group_state() when possible */ + if (pCityDlg-pCity-did_sell + || pCityDlg-pCity-owner != game.player_ptr) { set_group_state(pCityDlg-pImprv-pBeginActiveWidgetList, pCityDlg-pImprv-pEndActiveWidgetList, FC_WS_DISABLED); } else { struct widget *pTmpWidget = pCityDlg-pImprv-pEndActiveWidgetList; while (TRUE) { - if (is_wonder(improvement_by_number(MAX_ID - 3000 - pTmpWidget-ID))) { + struct impr_type *pimpr = improvement_by_number(MAX_ID - 3000 - + pTmpWidget-ID); + + if (!can_city_sell_building(pCityDlg-pCity, pimpr)) { set_wstate(pTmpWidget, FC_WS_DISABLED); } else { set_wstate(pTmpWidget, FC_WS_NORMAL); diff -Nurd -X.diff_ignore freeciv/client/gui-win32/citydlg.c freeciv/client/gui-win32/citydlg.c --- freeciv/client/gui-win32/citydlg.c 2007-08-13 20:51:06.0 +0300 +++ freeciv/client/gui-win32/citydlg.c 2007-08-14 23:20:58.0 +0300 @@ -397,7 +397,11 @@ const char *descr = city_production_name_translation(pcity); EnableWindow(pdialog-buy_but, city_can_buy(pcity)); - EnableWindow(pdialog-sell_but, !pcity-did_sell); + + /* FIXME: Should not pass NULL as improvement + * to can_player_sell_building_now(). It skips many tests. */ + EnableWindow(pdialog-sell_but, + can_player_sell_building_now(game.player_ptr, pcity, NULL)); get_city_dialog_production(pcity, buf, sizeof(buf)); diff -Nurd -X.diff_ignore freeciv/client/gui-xaw/citydlg.c freeciv/client/gui-xaw/citydlg.c --- freeciv/client/gui-xaw/citydlg.c 2007-08-13 20:51:06.0 +0300 +++ freeciv/client/gui-xaw/citydlg.c 2007-08-14 23:22:48.0 +0300 @@ -1476,7 +1476,10 @@ struct city *pcity=pdialog-pcity; XtSetSensitive(pdialog-buy_command, city_can_buy(pcity)); - XtSetSensitive(pdialog-sell_command, !pcity-did_sell); + /* FIXME: Should not pass NULL as improvement + * to can_player_sell_building_now(). It skips many tests. */ + XtSetSensitive(pdialog-sell_command, + can_player_sell_building_now(game.player_ptr, pcity, NULL)); xaw_set_label(pdialog-building_label, city_production_name_translation(pcity)); diff -Nurd -X.diff_ignore freeciv/common/improvement.c freeciv/common/improvement.c --- freeciv/common/improvement.c 2007-08-13 20:51:03.0 +0300 +++ freeciv/common/improvement.c 2007-08-14 23:05:51.0 +0300 @@ -538,3 +538,21 @@ return (city_has_building(pcity, pimprove) is_improvement(pimprove)); } +/ + Return TRUE iff the player can sell the given improvement from city. +/ +bool can_player_sell_building_now(struct player *pplayer, + struct city *pcity, + struct impr_type *pimprove) +{ + if (pcity-did_sell || pcity-owner != pplayer) { +return FALSE; + } + + if (pimprove != NULL + !can_city_sell_building(pcity, pimprove)) { +return FALSE; + } + + return TRUE; +} diff -Nurd -X.diff_ignore freeciv/common/improvement.h freeciv/common/improvement.h --- freeciv/common/improvement.h 2007-08-13 20:51:03.0 +0300 +++ freeciv/common/improvement.h 2007-08-14 23:03:21.0 +0300 @@ -109,6 +109,9 @@ bool can_sell_building(struct impr_type *pimprove); bool