<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.000000000 +0300
+++ freeciv/client/gui-gtk-2.0/citydlg.c	2007-08-14 23:02:58.000000000 +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.000000000 +0300
+++ freeciv/client/gui-sdl/citydlg.c	2007-08-14 23:19:44.000000000 +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.000000000 +0300
+++ freeciv/client/gui-win32/citydlg.c	2007-08-14 23:20:58.000000000 +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.000000000 +0300
+++ freeciv/client/gui-xaw/citydlg.c	2007-08-14 23:22:48.000000000 +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.000000000 +0300
+++ freeciv/common/improvement.c	2007-08-14 23:05:51.000000000 +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.000000000 +0300
+++ freeciv/common/improvement.h	2007-08-14 23:03:21.000000000 +0300
@@ -109,6 +109,9 @@
 bool can_sell_building(struct impr_type *pimprove);
 bool can_city_sell_building(struct city *pcity,
 			    struct impr_type *pimprove);
+bool can_player_sell_building_now(struct player *pplayer,
+                                  struct city *pcity,
+                                  struct impr_type *pimprove);
 
 struct city *find_city_from_great_wonder(const struct impr_type *pimprove);
 struct city *find_city_from_small_wonder(const struct player *pplayer,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to