<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.000000000 +0300
+++ freeciv/client/gui-gtk-2.0/citydlg.c	2007-08-27 01:01:27.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-20 00:55:46.000000000 +0300
+++ freeciv/client/gui-sdl/citydlg.c	2007-08-27 01:02:55.000000000 +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.000000000 +0300
+++ freeciv/client/gui-win32/citydlg.c	2007-08-27 01:01:27.000000000 +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.000000000 +0300
+++ freeciv/client/gui-xaw/citydlg.c	2007-08-27 01:01:27.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-27 01:10:05.000000000 +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.000000000 +0300
+++ freeciv/common/improvement.h	2007-08-27 01:01:27.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