Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] Re: (PR#3396) Buying coinage
Home

[Freeciv-Dev] Re: (PR#3396) Buying coinage

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: ChrisK@xxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#3396) Buying coinage
From: "Raimar Falke" <rf13@xxxxxxxxxxxxxxxxx>
Date: Fri, 14 Feb 2003 11:02:58 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, Feb 12, 2003 at 03:57:17AM -0800, ChrisK@xxxxxxxx via RT wrote:
> 
> CVS 12 FEB 2003 GTK 1.2
> 
> If you try to "buy" coinage in the city report, and you have
> less than 3996 Gold, you get a message:
> 
> Game: Coinage costs 3996 gold and you only have 3953 gold.
> 
> If you *have* that money, it says:
> 
> Game: You don't buy Coinage!

The attacked patch fixes that. I also took the opportunity to unify
the code and create a new cityrep_buy function in climisc.c (I didn't
found a better file).

While I change all guis except sdl (which doesn't have a city report)
I only tested gtk1.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "That's fundamental game play!  My main enemy is *ALWAYS* fighting 
  a 4-front war.  I make sure of it!"
    -- Tony Stuckey, freeciv-dev

Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.111
diff -u -u -r1.111 climisc.c
--- client/climisc.c    2003/02/12 22:22:33     1.111
+++ client/climisc.c    2003/02/14 19:01:45
@@ -1117,3 +1117,44 @@
 
   return buffer;
 }
+
+/**************************************************************************
+  Called when the "Buy" button is pressed in the city report for every
+  selected city. Checks for coinage and sufficient founds or send the
+  PACKET_CITY_BUY if everything is ok.
+**************************************************************************/
+void cityrep_buy(struct city *pcity)
+{
+  int value = city_buy_cost(pcity);
+
+  if (!pcity->is_building_unit && pcity->currently_building == B_CAPITAL) {
+    char buf[512];
+
+    my_snprintf(buf, sizeof(buf),
+               _("Game: You don't buy %s in %s!"),
+               improvement_types[B_CAPITAL].name, pcity->name);
+    append_output_window(buf);
+    return;
+  }
+
+  if (game.player_ptr->economic.gold >= value) {
+    struct packet_city_request packet;
+
+    packet.city_id = pcity->id;
+    send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
+  } else {
+    char buf[512];
+    const char *name;
+
+    if (pcity->is_building_unit) {
+      name = get_unit_type(pcity->currently_building)->name;
+    } else {
+      name = get_impr_name_ex(pcity, pcity->currently_building);
+    }
+
+    my_snprintf(buf, sizeof(buf),
+               _("Game: %s costs %d gold and you only have %d gold."),
+               name, value, game.player_ptr->economic.gold);
+    append_output_window(buf);
+  }
+}
Index: client/climisc.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.h,v
retrieving revision 1.43
diff -u -u -r1.43 climisc.h
--- client/climisc.h    2003/01/05 23:24:51     1.43
+++ client/climisc.h    2003/02/14 19:01:45
@@ -122,4 +122,6 @@
 
 const char *unit_description(struct unit *punit);
 
+void cityrep_buy(struct city *pcity);
+
 #endif  /* FC__CLIMISC_H */
Index: client/gui-gtk/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cityrep.c,v
retrieving revision 1.75
diff -u -u -r1.75 cityrep.c
--- client/gui-gtk/cityrep.c    2003/02/10 21:43:41     1.75
+++ client/gui-gtk/cityrep.c    2003/02/14 19:01:48
@@ -1161,32 +1161,8 @@
 
   g_assert(current);
 
-  for(; current; current = g_list_next(current))
-  {
-      struct city *pcity = city_from_glist (current);
-      int value;
-      const char *name;
-      char buf[512];
-
-      value=city_buy_cost(pcity);    
-      if(pcity->is_building_unit)
-       name=get_unit_type(pcity->currently_building)->name;
-      else
-       name=get_impr_name_ex(pcity, pcity->currently_building);
-
-      if (game.player_ptr->economic.gold >= value)
-       {
-         struct packet_city_request packet;
-         packet.city_id=pcity->id;
-         send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-       }
-      else
-       {
-         my_snprintf(buf, sizeof(buf),
-                     _("Game: %s costs %d gold and you only have %d gold."),
-                     name,value,game.player_ptr->economic.gold);
-         append_output_window(buf);
-       }
+  for (; current; current = g_list_next(current)) {
+    cityrep_buy(city_from_glist(current));
   }
 }
 
Index: client/gui-gtk-2.0/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/cityrep.c,v
retrieving revision 1.32
diff -u -u -r1.32 cityrep.c
--- client/gui-gtk-2.0/cityrep.c        2003/02/10 21:43:41     1.32
+++ client/gui-gtk-2.0/cityrep.c        2003/02/14 19:01:51
@@ -863,32 +863,11 @@
 static void buy_iterate(GtkTreeModel *model, GtkTreePath *path,
                        GtkTreeIter *it, gpointer data)
 {
-  struct city *pcity;
-  int value;
-  const char *name;
-  char buf[512];
   gpointer res;
 
   gtk_tree_model_get(model, it, 0, &res, -1);
-  pcity = res;
 
-  value = city_buy_cost(pcity);         
-  if (pcity->is_building_unit)
-    name = get_unit_type(pcity->currently_building)->name;
-  else
-    name = get_impr_name_ex(pcity, pcity->currently_building);
-
-  if (game.player_ptr->economic.gold >= value) {
-      struct packet_city_request packet;
-
-      packet.city_id = pcity->id;
-      send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-  } else {
-    my_snprintf(buf, sizeof(buf),
-               _("Game: %s costs %d gold and you only have %d gold."),
-               name,value, game.player_ptr->economic.gold);
-    append_output_window(buf);
-  }
+  cityrep_buy(res);
 }
 
 /****************************************************************
Index: client/gui-mui/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/cityrep.c,v
retrieving revision 1.25
diff -u -u -r1.25 cityrep.c
--- client/gui-mui/cityrep.c    2003/01/29 05:10:49     1.25
+++ client/gui-mui/cityrep.c    2003/02/14 19:01:52
@@ -161,33 +161,11 @@
 {
   struct city *pcity;
 
-  DoMethod(cityrep_listview, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active, 
&pcity);
+  DoMethod(cityrep_listview, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active,
+          &pcity);
 
-  if (pcity)
-  {
-    int value;
-    char *name;
-    char buf[512];
-
-    value=city_buy_cost(pcity);    
-    if(pcity->is_building_unit)
-      name=get_unit_type(pcity->currently_building)->name;
-    else
-      name=get_impr_name_ex(pcity, pcity->currently_building);
-
-    if(game.player_ptr->economic.gold >= value)
-    {
-      struct packet_city_request packet;
-      packet.city_id=pcity->id;
-      send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-    }
-    else
-    {
-      my_snprintf(buf, sizeof(buf),
-        _("Game: %s costs %d gold and you only have %d gold."),
-        name,value,game.player_ptr->economic.gold);
-      append_output_window(buf);
-    }
+  if (pcity) {
+    cityrep_buy(pcity);
   }
 }
 
Index: client/gui-win32/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/cityrep.c,v
retrieving revision 1.22
diff -u -u -r1.22 cityrep.c
--- client/gui-win32/cityrep.c  2003/02/10 21:43:41     1.22
+++ client/gui-win32/cityrep.c  2003/02/14 19:01:55
@@ -350,42 +350,20 @@
 static void cityrep_buy(HWND hWnd)
 {
   int cityids[256];
-  int selcount;
   int i;
-  struct city *pcity;
-   selcount=ListBox_GetSelCount(GetDlgItem(hWnd,ID_CITYREP_LIST));
-  if (selcount==LB_ERR) return;
-  selcount=MIN(256,selcount);
-  selcount=ListBox_GetSelItems(GetDlgItem(hWnd,ID_CITYREP_LIST),
-                              selcount,&cityids[0]);
-  for(i=0;i<selcount;i++)
-    {
-      int value;
-      const char *name;
-      char buf[512];            
-      pcity=(struct city *)ListBox_GetItemData(GetDlgItem(hWnd,
-                                                         ID_CITYREP_LIST),
-                                              cityids[i]);
-      value=city_buy_cost(pcity);
-      if(pcity->is_building_unit)
-        name=get_unit_type(pcity->currently_building)->name;
-      else
-        name=get_impr_name_ex(pcity, pcity->currently_building);
- 
-      if (game.player_ptr->economic.gold >= value)
-        {
-          struct packet_city_request packet;
-          packet.city_id=pcity->id;
-          send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-        }
-      else
-        {
-          my_snprintf(buf, sizeof(buf),
-                      _("Game: %s costs %d gold and you only have %d gold."),
-                      name,value,game.player_ptr->economic.gold);
-          append_output_window(buf);
-        }             
-    }
+  int selcount = ListBox_GetSelCount(GetDlgItem(hWnd, ID_CITYREP_LIST));
+
+  if (selcount == LB_ERR) {
+    return;
+  }
+  selcount = MIN(256, selcount);
+  selcount = ListBox_GetSelItems(GetDlgItem(hWnd, ID_CITYREP_LIST),
+                                selcount, &cityids[0]);
+  for (i = 0; i < selcount; i++) {
+    cityrep_buy((struct city *) ListBox_GetItemData(GetDlgItem(hWnd,
+                                                              ID_CITYREP_LIST),
+                                                   cityids[i]));
+  }
 }
   
 #if 0
Index: client/gui-xaw/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/cityrep.c,v
retrieving revision 1.46
diff -u -u -r1.46 cityrep.c
--- client/gui-xaw/cityrep.c    2002/11/29 20:11:59     1.46
+++ client/gui-xaw/cityrep.c    2003/02/14 19:01:57
@@ -403,37 +403,14 @@
 /****************************************************************
 ...
 *****************************************************************/
-void city_buy_callback(Widget w, XtPointer client_data, 
-                        XtPointer call_data)
+void city_buy_callback(Widget w, XtPointer client_data, XtPointer call_data)
 {
-  XawListReturnStruct *ret=XawListShowCurrent(city_list);
+  XawListReturnStruct *ret = XawListShowCurrent(city_list);
 
-  if(ret->list_index!=XAW_LIST_NONE) {
-    struct city *pcity;
-    if((pcity=cities_in_list[ret->list_index])) {
-      int value;
-      const char *name;
-      char buf[512];
-
-      value=city_buy_cost(pcity);    
-      if(pcity->is_building_unit)
-       name=get_unit_type(pcity->currently_building)->name;
-      else
-       name=get_impr_name_ex(pcity, pcity->currently_building);
-
-      if (game.player_ptr->economic.gold >= value)
-       {
-         struct packet_city_request packet;
-         packet.city_id=pcity->id;
-         send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-       }
-      else
-       {
-         my_snprintf(buf, sizeof(buf),
-                     _("Game: %s costs %d gold and you only have %d gold."),
-                     name,value,game.player_ptr->economic.gold);
-         append_output_window(buf);
-       }
+  if (ret->list_index != XAW_LIST_NONE) {
+    struct city *pcity = cities_in_list[ret->list_index];
+    if (pcity) {
+      cityrep_buy(pcity);
     }
   }
 }

[Prev in Thread] Current Thread [Next in Thread]