Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2003:
[Freeciv-Dev] (PR#4752) new client function city_buy_production
Home

[Freeciv-Dev] (PR#4752) new client function city_buy_production

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4752) new client function city_buy_production
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 4 Aug 2003 22:13:38 -0700
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch adds a new function to citydlg_common, 
city_buy_production.  This is called by the GUI code to make a request 
of the server to buy the production.  It cuts down on GUI code and 
avoids sending uninitialized data over the network.

jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.22
diff -u -r1.22 citydlg_common.c
--- client/citydlg_common.c     2003/08/04 20:57:14     1.22
+++ client/citydlg_common.c     2003/08/05 05:11:29
@@ -436,6 +436,24 @@
 }
 
 /**************************************************************************
+  Buy the current production item in a given city.  Return the request ID.
+**************************************************************************/
+int city_buy_production(struct city *pcity)
+{
+  struct packet_city_request packet;
+
+  packet.city_id = pcity->id;
+
+  /* Fill out unused fields. */
+  packet.build_id = -1;
+  packet.is_build_id_unit_id = FALSE;
+  packet.worker_x = packet.worker_y = -1;
+  packet.specialist_from = packet.specialist_to = -1;
+
+  return send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
+}
+
+/**************************************************************************
   Change a specialist in the given city.  Return the request ID.
 **************************************************************************/
 int city_change_specialist(struct city *pcity, enum specialist_type from,
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.15
diff -u -r1.15 citydlg_common.h
--- client/citydlg_common.h     2003/08/04 20:57:14     1.15
+++ client/citydlg_common.h     2003/08/05 05:11:29
@@ -56,6 +56,7 @@
 int city_change_production(struct city *pcity, bool is_unit, int build_id);
 int city_set_worklist(struct city *pcity, struct worklist *pworklist);
 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,
                           enum specialist_type to);
 int city_toggle_worker(struct city *pcity, int city_x, int city_y);
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.119
diff -u -r1.119 climisc.c
--- client/climisc.c    2003/07/28 04:00:29     1.119
+++ client/climisc.c    2003/08/05 05:11:29
@@ -1135,8 +1135,8 @@
 
 /**************************************************************************
   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.
+  selected city. Checks for coinage and sufficient founds or request the
+  purchase if everything is ok.
 **************************************************************************/
 void cityrep_buy(struct city *pcity)
 {
@@ -1153,10 +1153,7 @@
   }
 
   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);
+    city_buy_production(pcity);
   } else {
     char buf[512];
     const char *name;
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.170
diff -u -r1.170 citydlg.c
--- client/gui-gtk/citydlg.c    2003/08/04 20:57:14     1.170
+++ client/gui-gtk/citydlg.c    2003/08/05 05:11:29
@@ -2906,13 +2906,9 @@
 *****************************************************************/
 static void buy_callback_yes(gpointer data)
 {
-  struct city_dialog *pdialog;
-  struct packet_city_request packet;
+  struct city_dialog *pdialog = data;
 
-  pdialog = (struct city_dialog *) data;
-
-  packet.city_id = pdialog->pcity->id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
+  city_buy_production(pdialog->pcity);
 }
 
 /****************************************************************
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.61
diff -u -r1.61 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        2003/08/01 20:27:09     1.61
+++ client/gui-gtk-2.0/citydlg.c        2003/08/05 05:11:29
@@ -2377,10 +2377,7 @@
     gtk_dialog_set_default_response(GTK_DIALOG(shell), GTK_RESPONSE_NO);
 
     if (gtk_dialog_run(GTK_DIALOG(shell)) == GTK_RESPONSE_YES) {
-      struct packet_city_request packet;
-
-      packet.city_id = pdialog->pcity->id;
-      send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
+      city_buy_production(pdialog->pcity);
     }
     gtk_widget_destroy(shell);
   } else {
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.72
diff -u -r1.72 citydlg.c
--- client/gui-mui/citydlg.c    2003/08/04 20:57:14     1.72
+++ client/gui-mui/citydlg.c    2003/08/05 05:11:30
@@ -271,16 +271,6 @@
   Object *sell_wnd;
 };
 
-/****************************************************************
- ...
-*****************************************************************/
-static void request_city_buy(struct city *pcity)
-{
-  struct packet_city_request packet;
-  packet.city_id = pcity->id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-}
-
 /* End GUI Independed */
 
 
@@ -701,7 +691,8 @@
 static void city_buy_yes(struct popup_message_data *data)
 {
   struct city *pcity = (struct city *) data->data;
-  request_city_buy(pcity);
+
+  city_buy_production(pcity);
   destroy_message_dialog(data->wnd);
 }
 
Index: client/gui-sdl/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/citydlg.c,v
retrieving revision 1.28
diff -u -r1.28 citydlg.c
--- client/gui-sdl/citydlg.c    2003/08/01 20:27:09     1.28
+++ client/gui-sdl/citydlg.c    2003/08/05 05:11:30
@@ -1341,9 +1341,7 @@
 **************************************************************************/
 static int ok_buy_prod_city_dlg_callback(struct GUI *pButton)
 {
-  struct packet_city_request packet;
-
-  packet.city_id = pButton->data.city->id;
+  city_buy_production(pButton->data.city);
   
   if (pCityDlg)
   {
@@ -1362,8 +1360,6 @@
     popdown_hurry_production_dialog();
   }
     
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
-
   return -1;
 }
 
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.59
diff -u -r1.59 citydlg.c
--- client/gui-win32/citydlg.c  2003/08/04 20:57:14     1.59
+++ client/gui-win32/citydlg.c  2003/08/05 05:11:30
@@ -950,13 +950,9 @@
 
 static void buy_callback_yes(HWND w, void * data)
 {
-  struct city_dialog *pdialog;
-  struct packet_city_request packet;
- 
-  pdialog=(struct city_dialog *)data;
- 
-  packet.city_id=pdialog->pcity->id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
+  struct city_dialog *pdialog = data;
+
+  city_buy_production(pdialog->pcity);
  
   destroy_message_dialog(w);
 }
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.102
diff -u -r1.102 citydlg.c
--- client/gui-xaw/citydlg.c    2003/08/04 20:57:15     1.102
+++ client/gui-xaw/citydlg.c    2003/08/05 05:11:30
@@ -1931,13 +1931,9 @@
 static void buy_callback_yes(Widget w, XtPointer client_data,
                             XtPointer call_data)
 {
-  struct city_dialog *pdialog;
-  struct packet_city_request packet;
+  struct city_dialog *pdialog = client_data;
 
-  pdialog=(struct city_dialog *)client_data;
-
-  packet.city_id=pdialog->pcity->id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
+  city_buy_production(pdialog->pcity);
 
   destroy_message_dialog(w);
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4752) new client function city_buy_production, Jason Short <=