Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4707) new function city_sell_improvement
Home

[Freeciv-Dev] (PR#4707) new function city_sell_improvement

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4707) new function city_sell_improvement
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 27 Jul 2003 22:10:42 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch adds a function city_sell_improvement that is a wrapper for
a send_packet_city_request(..., CITY_SELL).  It cuts out lots of code
and avoids sending uninitalized data over the network.

Similar functions can be/have been written for other city requests.

jason

Index: citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.17
diff -u -r1.17 citydlg_common.c
--- citydlg_common.c    2003/07/28 04:00:29     1.17
+++ citydlg_common.c    2003/07/28 05:08:33
@@ -359,3 +359,21 @@
 
   return send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
 }
+
+/**************************************************************************
+  Change the production of a given city.  Return the request ID.
+**************************************************************************/
+int city_sell_improvement(struct city *pcity, Impr_Type_id sell_id)
+{
+  struct packet_city_request packet;
+
+  packet.city_id = pcity->id;
+  packet.build_id = sell_id;
+
+  /* Fill out unused fields. */
+  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_SELL);
+}
Index: citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.10
diff -u -r1.10 citydlg_common.h
--- citydlg_common.h    2003/07/28 04:00:29     1.10
+++ citydlg_common.h    2003/07/28 05:08:33
@@ -16,6 +16,7 @@
 
 #include <stddef.h>            /* size_t */
 
+#include "improvement.h"       /* Impr_Type_id */
 #include "shared.h"            /* bool type */
 
 struct city;
@@ -51,5 +52,6 @@
 void activate_all_units(int map_x, int map_y);
 
 int city_change_production(struct city *pcity, bool is_unit, int build_id);
+int city_sell_improvement(struct city *pcity, Impr_Type_id sell_id);
 
 #endif /* FC__CITYDLG_COMMON_H */
Index: repodlgs_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.h,v
retrieving revision 1.2
diff -u -r1.2 repodlgs_common.h
--- repodlgs_common.h   2002/06/27 00:59:12     1.2
+++ repodlgs_common.h   2003/07/28 05:08:33
@@ -16,6 +16,8 @@
 
 #include "improvement.h"
 
+#include "citydlg_common.h" /* for city request functions */
+
 struct improvement_entry
 {
   Impr_Type_id type;
Index: gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.164
diff -u -r1.164 citydlg.c
--- gui-gtk/citydlg.c   2003/07/28 04:00:29     1.164
+++ gui-gtk/citydlg.c   2003/07/28 05:08:34
@@ -3196,14 +3196,9 @@
 *****************************************************************/
 static void sell_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;
-  packet.build_id = pdialog->sell_id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+  city_sell_improvement(pdialog->pcity, pdialog->sell_id);
 }
 
 /****************************************************************
Index: gui-gtk/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v
retrieving revision 1.71
diff -u -r1.71 repodlgs.c
--- gui-gtk/repodlgs.c  2003/06/26 23:03:12     1.71
+++ gui-gtk/repodlgs.c  2003/07/28 05:08:34
@@ -686,7 +686,6 @@
 void economy_selloff_callback(GtkWidget *w, gpointer data)
 {
   int i,count=0,gold=0;
-  struct packet_city_request packet;
   char str[64];
   GList              *selection;
   gint                row;
@@ -702,9 +701,7 @@
        improvement_obsolete(game.player_ptr,i) ||
         wonder_replacement(pcity, i) ))  {
        count++; gold+=improvement_value(i);
-        packet.city_id=pcity->id;
-        packet.build_id=i;
-        send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+       city_sell_improvement(pcity, i);
     }
   } city_list_iterate_end;
 
Index: gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.56
diff -u -r1.56 citydlg.c
--- gui-gtk-2.0/citydlg.c       2003/07/28 04:00:29     1.56
+++ gui-gtk-2.0/citydlg.c       2003/07/28 05:08:34
@@ -2482,16 +2482,10 @@
 *****************************************************************/
 static void sell_callback_response(GtkWidget *w, gint response, gpointer data)
 {
-  struct city_dialog *pdialog = (struct city_dialog *) data;
-
   if (response == GTK_RESPONSE_YES) {
-    struct packet_city_request packet;
-
-    pdialog = (struct city_dialog *) data;
+    struct city_dialog *pdialog = data;
 
-    packet.city_id = pdialog->pcity->id;
-    packet.build_id = pdialog->sell_id;
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+    city_sell_improvement(pdialog->pcity, pdialog->sell_id);
   }
   gtk_widget_destroy(w);
   
Index: gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.32
diff -u -r1.32 repodlgs.c
--- gui-gtk-2.0/repodlgs.c      2003/06/26 23:03:12     1.32
+++ gui-gtk-2.0/repodlgs.c      2003/07/28 05:08:34
@@ -715,7 +715,6 @@
 static void economy_command_callback(GtkWidget *w, gint response_id)
 {
   int i, count = 0, gold = 0;
-  struct packet_city_request packet;
   gint row;
   GtkWidget *shell;
 
@@ -735,9 +734,7 @@
        improvement_obsolete(game.player_ptr,i) ||
         wonder_replacement(pcity, i) ))  {
        count++; gold+=improvement_value(i);
-        packet.city_id=pcity->id;
-        packet.build_id=i;
-        send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+       city_sell_improvement(pcity, i);
     }
   } city_list_iterate_end;
 
Index: gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.67
diff -u -r1.67 citydlg.c
--- gui-mui/citydlg.c   2003/07/28 04:00:29     1.67
+++ gui-mui/citydlg.c   2003/07/28 05:08:34
@@ -311,18 +311,7 @@
   packet.city_id = pcity->id;
   send_packet_city_request(&aconnection, &packet, PACKET_CITY_BUY);
 }
-/****************************************************************
- ...
-*****************************************************************/
-static void request_city_sell(struct city *pcity, int sell_id)
-{
-  struct packet_city_request packet;
 
-  packet.city_id = pcity->id;
-  packet.build_id = sell_id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
-}
-
 /* End GUI Independed */
 
 
@@ -767,8 +756,9 @@
 {
   struct city_dialog *pdialog = (struct city_dialog *) data->data;
 
-  if (pdialog->sell_id >= 0)
-    request_city_sell(pdialog->pcity, pdialog->sell_id);
+  if (pdialog->sell_id >= 0) {
+    city_sell_improvement(pdialog->pcity, pdialog->sell_id);
+  }
 
   destroy_message_dialog(data->wnd);
   pdialog->sell_wnd = NULL;
Index: gui-mui/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/repodlgs.c,v
retrieving revision 1.30
diff -u -r1.30 repodlgs.c
--- gui-mui/repodlgs.c  2003/06/26 23:03:12     1.30
+++ gui-mui/repodlgs.c  2003/07/28 05:08:34
@@ -513,14 +513,10 @@
       if (!pcity->did_sell && city_got_building(pcity, i) &&
          (*data || improvement_obsolete(game.player_ptr, i) || 
wonder_replacement(pcity, i)))
     {
-      struct packet_city_request packet;
-
       count++;
       gold += improvement_value(i);
 
-      packet.city_id = pcity->id;
-      packet.build_id = i;
-      send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+      city_sell_improvement(pcity, i);
     }
     city_list_iterate_end
 
Index: gui-sdl/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/citydlg.c,v
retrieving revision 1.24
diff -u -r1.24 citydlg.c
--- gui-sdl/citydlg.c   2003/07/20 20:41:38     1.24
+++ gui-sdl/citydlg.c   2003/07/28 05:08:34
@@ -1624,12 +1624,9 @@
 **************************************************************************/
 static int sell_imprvm_dlg_ok_callback(struct GUI *pOK_Button)
 {
-
-  struct packet_city_request packet;
   struct GUI *pTmp = (struct GUI *)pOK_Button->data.ptr;
 
-  packet.city_id = pCityDlg->pCity->id;
-  packet.build_id = MAX_ID - 3000 - pTmp->ID;
+  city_sell_improvement(pCityDlg->pCity, MAX_ID - 3000 - pTmp->ID);
   
   /* popdown, we don't redraw and flush becouse this is make by redraw city 
dlg.
      when response from server come */
@@ -1641,8 +1638,6 @@
   /* del imprv from widget list */
   del_widget_from_vertical_scroll_widget_list(pCityDlg->pImprv, pTmp);
   
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
-
   enable_city_dlg_widgets();
 
   if (pCityDlg->pImprv->pEndWidgetList) {
Index: gui-sdl/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/repodlgs.c,v
retrieving revision 1.21
diff -u -r1.21 repodlgs.c
--- gui-sdl/repodlgs.c  2003/07/20 20:41:38     1.21
+++ gui-sdl/repodlgs.c  2003/07/28 05:08:34
@@ -1359,7 +1359,6 @@
 static int ok_sell_impv_callback(struct GUI *pWidget)
 {
   int imp, total_count, count = 0;
-  struct packet_city_request packet;
   struct GUI *pImpr = (struct GUI *)pWidget->data.ptr;
     
   imp = pImpr->data.cont->id0;
@@ -1375,10 +1374,8 @@
   city_list_iterate(game.player_ptr->cities, pCity) {
     if(!pCity->did_sell && city_got_building(pCity, imp)){
        count++;
-      
-        packet.city_id=pCity->id;
-        packet.build_id=imp;
-        send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+
+       city_sell_improvement(pCity, imp);
       
     }
   } city_list_iterate_end;
Index: gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.53
diff -u -r1.53 citydlg.c
--- gui-win32/citydlg.c 2003/07/28 04:00:30     1.53
+++ gui-win32/citydlg.c 2003/07/28 05:08:34
@@ -1011,14 +1011,9 @@
 *****************************************************************/
 static void sell_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;
-  packet.build_id=pdialog->sell_id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+  struct city_dialog *pdialog = data;
+
+  city_sell_improvement(pdialog->pcity, pdialog->sell_id);
  
   destroy_message_dialog(w);
 }
Index: gui-win32/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/repodlgs.c,v
retrieving revision 1.29
diff -u -r1.29 repodlgs.c
--- gui-win32/repodlgs.c        2003/06/26 23:09:23     1.29
+++ gui-win32/repodlgs.c        2003/07/28 05:08:34
@@ -357,7 +357,6 @@
 {
   HWND lv;
   int n,i,count=0,gold=0;
-  struct packet_city_request packet;
   char str[64];
   int row;
   lv=GetDlgItem(hWnd,ID_TRADEREP_LIST);
@@ -374,9 +373,7 @@
            improvement_obsolete(game.player_ptr,i) ||
            wonder_replacement(pcity, i) ))  {
          count++; gold+=improvement_value(i);
-         packet.city_id=pcity->id;
-         packet.build_id=i;
-         send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+         city_sell_improvement(pcity, i);
        }            
       } city_list_iterate_end;
 
Index: gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.96
diff -u -r1.96 citydlg.c
--- gui-xaw/citydlg.c   2003/07/28 04:00:30     1.96
+++ gui-xaw/citydlg.c   2003/07/28 05:08:34
@@ -2390,14 +2390,9 @@
 static void sell_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;
-  packet.build_id=pdialog->sell_id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+  city_sell_improvement(pdialog->pcity, pdialog->sell_id);
 
   destroy_message_dialog(w);
 }
Index: gui-xaw/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/repodlgs.c,v
retrieving revision 1.50
diff -u -r1.50 repodlgs.c
--- gui-xaw/repodlgs.c  2003/06/26 23:03:12     1.50
+++ gui-xaw/repodlgs.c  2003/07/28 05:08:34
@@ -739,7 +739,6 @@
                            XtPointer call_data)
 {
   int i,count=0,gold=0;
-  struct packet_city_request packet;
   char str[64];
   XawListReturnStruct *ret=XawListShowCurrent(economy_list);
 
@@ -753,9 +752,7 @@
        improvement_obsolete(game.player_ptr,i) ||
         wonder_replacement(pcity, i) ))  {
        count++; gold+=improvement_value(i);
-        packet.city_id=pcity->id;
-        packet.build_id=i;
-        send_packet_city_request(&aconnection, &packet, PACKET_CITY_SELL);
+       city_sell_improvement(pcity, i);
     }
   } city_list_iterate_end;
 

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