Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] Re: (PR#9380) new client function city_can_buy
Home

[Freeciv-Dev] Re: (PR#9380) new client function city_can_buy

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#9380) new client function city_can_buy
From: "Jason Dorje Short" <jdorje@xxxxxxxxxxx>
Date: Tue, 13 Jul 2004 21:05:28 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9380 >

Jason Dorje Short wrote:

> This patch adds a new function city_can_buy(), and adds capitalization 
> (B_CAPITAL) support to impr_buy_gold_cost().

jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.41
diff -u -r1.41 citydlg_common.c
--- client/citydlg_common.c     13 Jul 2004 18:16:53 -0000      1.41
+++ client/citydlg_common.c     14 Jul 2004 03:56:46 -0000
@@ -26,6 +26,7 @@
 #include "mapview_g.h"
 
 #include "citydlg_common.h"
+#include "civclient.h"         /* for can_client_issue_orders() */
 #include "climap.h"
 #include "clinet.h"
 #include "control.h"
@@ -544,6 +545,16 @@
 }
 
 /**************************************************************************
+  Return TRUE iff the city can buy.
+**************************************************************************/
+bool city_can_buy(const struct city *pcity)
+{
+  return (can_client_issue_orders()
+         && !pcity->did_buy
+         && city_buy_cost(pcity) > 0);
+}
+
+/**************************************************************************
   Change the production of a given city.  Return the request ID.
 **************************************************************************/
 int city_sell_improvement(struct city *pcity, Impr_Type_id sell_id)
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.22
diff -u -r1.22 citydlg_common.h
--- client/citydlg_common.h     10 Jul 2004 18:48:17 -0000      1.22
+++ client/citydlg_common.h     14 Jul 2004 03:56:46 -0000
@@ -64,6 +64,7 @@
 int city_set_worklist(struct city *pcity, struct worklist *pworklist);
 void city_get_queue(struct city *pcity, struct worklist *pqueue);
 void city_set_queue(struct city *pcity, struct worklist *pqueue);
+bool city_can_buy(const struct city *pcity);
 int city_sell_improvement(struct city *pcity, Impr_Type_id sell_id);
 int city_buy_production(struct city *pcity);
 int city_change_specialist(struct city *pcity, enum specialist_type from,
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.184
diff -u -r1.184 citydlg.c
--- client/gui-gtk/citydlg.c    10 Jul 2004 18:48:17 -0000      1.184
+++ client/gui-gtk/citydlg.c    14 Jul 2004 03:56:47 -0000
@@ -1786,7 +1786,7 @@
   int cost;
 
   gtk_widget_set_sensitive(pdialog->overview.buy_command,
-                          can_client_issue_orders() && !pcity->did_buy);
+                          city_can_buy(pcity));
   gtk_widget_set_sensitive(pdialog->overview.sell_command,
                           can_client_issue_orders() && !pcity->did_sell);
                        
@@ -1796,13 +1796,7 @@
     cost = unit_build_shield_cost(pcity->currently_building);
     descr = get_unit_type(pcity->currently_building)->name;
   } else {
-    if (pcity->currently_building == B_CAPITAL) {
-      /* You can't buy capitalization */
-      gtk_widget_set_sensitive(pdialog->overview.buy_command, FALSE);
-      cost = 0;
-    } else {
-      cost = impr_build_shield_cost(pcity->currently_building);;
-    }
+    cost = impr_build_shield_cost(pcity->currently_building);;
     descr = get_impr_name_ex(pcity, pcity->currently_building);
   }
 
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.89
diff -u -r1.89 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        10 Jul 2004 18:48:18 -0000      1.89
+++ client/gui-gtk-2.0/citydlg.c        14 Jul 2004 03:56:47 -0000
@@ -1406,9 +1406,8 @@
   struct city *pcity = pdialog->pcity;
   gdouble pct;
   int cost;
-  gboolean sensitive;
+  gboolean sensitive = city_can_buy(pcity);
 
-  sensitive = (can_client_issue_orders() && !pcity->did_buy);
   gtk_widget_set_sensitive(pdialog->overview.buy_command, sensitive);
   gtk_widget_set_sensitive(pdialog->production.buy_command, sensitive);
 
@@ -1418,14 +1417,7 @@
     cost = unit_build_shield_cost(pcity->currently_building);
     descr = get_unit_type(pcity->currently_building)->name;
   } else {
-    if (pcity->currently_building == B_CAPITAL) {
-      /* You can't buy capitalization */
-      gtk_widget_set_sensitive(pdialog->overview.buy_command, FALSE);
-      gtk_widget_set_sensitive(pdialog->production.buy_command, FALSE);
-      cost = 0;
-    } else {
-      cost = impr_build_shield_cost(pcity->currently_building);;
-    }
+    cost = impr_build_shield_cost(pcity->currently_building);;
     descr = get_impr_name_ex(pcity, pcity->currently_building);
   }
 
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.76
diff -u -r1.76 citydlg.c
--- client/gui-mui/citydlg.c    10 Jul 2004 18:48:18 -0000      1.76
+++ client/gui-mui/citydlg.c    14 Jul 2004 03:56:48 -0000
@@ -1756,27 +1756,17 @@
   struct city *pcity = pdialog->pcity;
   int max_shield, shield;
 
-  set(pdialog->buy_button, MUIA_Disabled, pcity->did_buy);
+  set(pdialog->buy_button, MUIA_Disabled, city_can_buy(pcity));
   set(pdialog->sell_button, MUIA_Disabled, pcity->did_sell || 
pdialog->sell_wnd);
 
   get_city_dialog_production(pcity, buf, sizeof(buf));
 
+  shield = pcity->shield_stock;
   if (pcity->is_building_unit) {
-    shield = pcity->shield_stock;
     max_shield = unit_build_shield_cost(pcity->currently_building);
     descr = get_unit_type(pcity->currently_building)->name;
   } else {
-    if (pcity->currently_building == B_CAPITAL) {
-      /* You can't buy Capitalization */
-      set(pdialog->buy_button, MUIA_Disabled, TRUE);
-
-      shield = 0;
-      max_shield = 1;
-    } else {
-      shield = pcity->shield_stock;
-      max_shield =
-         impr_build_shield_cost(pcity->currently_building);
-    }
+    max_shield = impr_build_shield_cost(pcity->currently_building);
     descr = get_impr_name_ex(pcity, pcity->currently_building);
   }
 
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.78
diff -u -r1.78 citydlg.c
--- client/gui-win32/citydlg.c  10 Jul 2004 18:48:18 -0000      1.78
+++ client/gui-win32/citydlg.c  14 Jul 2004 03:56:49 -0000
@@ -476,7 +476,7 @@
   const char *descr;
   struct city *pcity=pdialog->pcity;    
   
-  EnableWindow(pdialog->buy_but,!pcity->did_buy);
+  EnableWindow(pdialog->buy_but, city_can_buy(pcity));
   EnableWindow(pdialog->sell_but, !pcity->did_sell);
 
   get_city_dialog_production(pcity, buf, sizeof(buf));
@@ -484,10 +484,6 @@
   if (pcity->is_building_unit) {
     descr = get_unit_type(pcity->currently_building)->name;
   } else {
-    if (pcity->currently_building == B_CAPITAL) {
-      /* You can't buy Capitalization. */
-      EnableWindow(pdialog->buy_but, FALSE);
-    }
     descr = get_impr_name_ex(pcity, pcity->currently_building);
   }
 
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.117
diff -u -r1.117 citydlg.c
--- client/gui-xaw/citydlg.c    10 Jul 2004 18:48:18 -0000      1.117
+++ client/gui-xaw/citydlg.c    14 Jul 2004 03:56:49 -0000
@@ -1476,10 +1476,7 @@
   char buf[32];
   struct city *pcity=pdialog->pcity;
 
-  if (pcity->currently_building==B_CAPITAL)
-    XtSetSensitive(pdialog->buy_command, False);
-  else
-    XtSetSensitive(pdialog->buy_command, !pcity->did_buy);
+  XtSetSensitive(pdialog->buy_command, city_can_buy(pcity));
   XtSetSensitive(pdialog->sell_command, !pcity->did_sell);
 
   xaw_set_label(pdialog->building_label,
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.38
diff -u -r1.38 improvement.c
--- common/improvement.c        25 Jun 2004 23:43:01 -0000      1.38
+++ common/improvement.c        14 Jul 2004 03:56:50 -0000
@@ -169,6 +169,11 @@
   int cost = 0, missing =
       improvement_types[id].build_cost - shields_in_stock;
 
+  if (id == B_CAPITAL) {
+    /* Can't buy capitalization. */
+    return 0;
+  }
+
   if (missing > 0) {
     cost = 2 * missing;
   }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#9380) new client function city_can_buy, Jason Dorje Short <=