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

[Freeciv-Dev] (PR#4688) new function city_change_production

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4688) new function city_change_production
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Jul 2003 08:35:22 -0700
Reply-to: rt@xxxxxxxxxxxxxx

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

Similar functions can/will be written for other city requests.

jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.16
diff -u -r1.16 citydlg_common.c
--- client/citydlg_common.c     2003/04/04 15:47:45     1.16
+++ client/citydlg_common.c     2003/07/25 15:32:30
@@ -20,6 +20,7 @@
 #include "log.h"
 #include "support.h"
 
+#include "clinet.h"
 #include "control.h"
 #include "options.h"           /* for concise_city_production */
 #include "tilespec.h"          /* for is_isometric */
@@ -339,4 +340,22 @@
     /* Put the focus on one of the activated units. */
     set_unit_focus(pmyunit);
   }
+}
+
+/**************************************************************************
+  Change the production of a given city.  Return the request ID.
+**************************************************************************/
+int city_change_production(struct city *pcity, bool is_unit, int build_id)
+{
+  struct packet_city_request packet;
+
+  packet.city_id = pcity->id;
+  packet.build_id = build_id;
+  packet.is_build_id_unit_id = is_unit;
+
+  /* Fill out unused fields. */
+  packet.worker_x = packet.worker_y = -1;
+  packet.specialist_from = packet.specialist_to = -1;
+
+  return send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
 }
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.9
diff -u -r1.9 citydlg_common.h
--- client/citydlg_common.h     2003/01/29 05:00:04     1.9
+++ client/citydlg_common.h     2003/07/25 15:32:30
@@ -50,4 +50,6 @@
 
 void activate_all_units(int map_x, int map_y);
 
+int city_change_production(struct city *pcity, bool is_unit, int build_id);
+
 #endif /* FC__CITYDLG_COMMON_H */
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.118
diff -u -r1.118 climisc.c
--- client/climisc.c    2003/04/17 20:06:35     1.118
+++ client/climisc.c    2003/07/25 15:32:30
@@ -153,7 +153,6 @@
 {
   int fr_id = cid_id(x), to_id = cid_id(y);
   bool fr_is_unit = cid_is_unit(x), to_is_unit = cid_is_unit(y);
-  struct packet_city_request packet;
   char buf[512];
   int last_request_id = 0;
 
@@ -178,11 +177,7 @@
         (!to_is_unit &&
          can_build_improvement (pcity, to_id))))
       {
-       packet.city_id = pcity->id;
-       packet.build_id = to_id;
-       packet.is_build_id_unit_id = to_is_unit;
-       last_request_id = send_packet_city_request(&aconnection, &packet,
-                                                  PACKET_CITY_CHANGE);
+       last_request_id = city_change_production(pcity, to_is_unit, to_id);
       }
   } city_list_iterate_end;
 
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.163
diff -u -r1.163 citydlg.c
--- client/gui-gtk/citydlg.c    2003/04/04 15:47:46     1.163
+++ client/gui-gtk/citydlg.c    2003/07/25 15:32:30
@@ -3100,16 +3100,11 @@
   GList *selection = GTK_CLIST(pdialog->change_list)->selection;
 
   if (selection) {
-    struct packet_city_request packet;
     cid cid = GPOINTER_TO_INT(
                   gtk_clist_get_row_data(GTK_CLIST(pdialog->change_list),
                                         GPOINTER_TO_INT(selection->data)));
 
-    packet.city_id = pdialog->pcity->id;
-    packet.build_id = cid_id(cid);
-    packet.is_build_id_unit_id = cid_is_unit(cid);
-
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+    city_change_production(pdialog->pcity, cid_is_unit(cid), cid_id(cid));
   }
   gtk_widget_destroy(w->parent->parent->parent);
   pdialog->change_shell = NULL;
@@ -3303,13 +3298,8 @@
        (!is_unit && can_build_improvement(pdialog->pcity, id))) {
       /* ...but we're not yet building it, then switch. */
       if (!same_as_current_build) {
-
        /* Change the current target */
-       packet.city_id = pdialog->pcity->id;
-       packet.build_id = id;
-       packet.is_build_id_unit_id = is_unit;
-       send_packet_city_request(&aconnection, &packet,
-                                PACKET_CITY_CHANGE);
+       city_change_production(pdialog->pcity, is_unit, id);
       }
 
       /* This item is now (and may have always been) the current
Index: client/gui-gtk/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cityrep.c,v
retrieving revision 1.79
diff -u -r1.79 cityrep.c
--- client/gui-gtk/cityrep.c    2003/04/04 15:47:46     1.79
+++ client/gui-gtk/cityrep.c    2003/07/25 15:32:31
@@ -311,13 +311,8 @@
 
       connection_do_buffer(&aconnection);  
       for (; selection; selection = g_list_next(selection)) {
-       struct packet_city_request packet;
-
-       packet.city_id = city_from_glist(selection)->id;
-       packet.build_id = id;
-       packet.is_build_id_unit_id = is_unit;
-       last_request_id = send_packet_city_request(&aconnection, &packet,
-                                                  PACKET_CITY_CHANGE);
+       last_request_id = city_change_production(city_from_glist(selection),
+                                                is_unit, id);
       }
 
       connection_do_unbuffer(&aconnection);
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.55
diff -u -r1.55 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        2003/05/19 22:09:25     1.55
+++ client/gui-gtk-2.0/citydlg.c        2003/07/25 15:32:31
@@ -736,16 +736,8 @@
 
     if (gtk_tree_model_get_iter(model, &it, path)) {
       cid cid;
-      struct packet_city_request packet;
-
       gtk_tree_model_get(model, &it, 0, &cid, -1);
-
-      packet.city_id = pdialog->pcity->id;
-      packet.build_id = cid_id(cid);
-      packet.is_build_id_unit_id = cid_is_unit(cid);
-
-      send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
-
+      city_change_production(pdialog->pcity, cid_id(cid), cid_is_unit(cid));
       gtk_drag_finish(context, TRUE, FALSE, time);
     }
     gtk_tree_path_free(path);
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.45
diff -u -r1.45 cityrep.c
--- client/gui-gtk-2.0/cityrep.c        2003/05/18 16:19:29     1.45
+++ client/gui-gtk-2.0/cityrep.c        2003/07/25 15:32:31
@@ -287,11 +287,12 @@
   struct packet_city_request packet;
   gint id;
 
+  /* FIXME: don't use network packet structures here. */
   packet = *(struct packet_city_request *)data;
   gtk_tree_model_get(model, it, 1, &id, -1);
 
-  packet.city_id = id;
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+  city_change_production(find_city_by_id(id),
+                        packet->is_build_id_unit_id, packet->build_id);
 }
 
 /****************************************************************
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/wldlg.c,v
retrieving revision 1.24
diff -u -r1.24 wldlg.c
--- client/gui-gtk-2.0/wldlg.c  2003/06/26 23:09:23     1.24
+++ client/gui-gtk-2.0/wldlg.c  2003/07/25 15:32:31
@@ -547,15 +547,9 @@
   if (gtk_tree_selection_get_selected(selection, &model, &it)) {
     gint cid;
 
-    struct packet_city_request packet;
-
     gtk_tree_model_get(model, &it, 0, &cid, -1);
-
-    packet.city_id = ptr->pcity->id;
-    packet.build_id = cid_id(cid);
-    packet.is_build_id_unit_id = cid_is_unit(cid);
 
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+    city_change_production(ptr->pcity, cid_is_unit(cid), cid_id(cid));
   }
 }
 
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.66
diff -u -r1.66 citydlg.c
--- client/gui-mui/citydlg.c    2003/03/29 09:57:37     1.66
+++ client/gui-mui/citydlg.c    2003/07/25 15:32:31
@@ -274,19 +274,6 @@
 /****************************************************************
  ...
 *****************************************************************/
-static void request_city_change_production(struct city *pcity, int id, bool 
is_unit_id)
-{
-  struct packet_city_request packet;
-
-  packet.city_id = pcity->id;
-  packet.build_id = id;
-  packet.is_build_id_unit_id = is_unit_id;
-
-  send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
-}
-/****************************************************************
- ...
-*****************************************************************/
 static void request_city_change_specialist(struct city *pcity, int from, int 
to)
 {
   struct packet_city_request packet;
@@ -909,13 +896,8 @@
        (!is_unit && can_build_improvement(pdialog->pcity, id))) {
       /* ...but we're not yet building it, then switch. */
       if (!same_as_current_build) {
-
        /* Change the current target */
-       packet.city_id = pdialog->pcity->id;
-       packet.build_id = id;
-       packet.is_build_id_unit_id = is_unit;
-       send_packet_city_request(&aconnection, &packet,
-                                PACKET_CITY_CHANGE);
+       city_change_production(pdialog->pcity, is_unit, id);
       }
 
       /* This item is now (and may have always been) the current
@@ -1173,7 +1155,7 @@
     else
       which--;
 
-    request_city_change_production(pcprod->pcity, which, is_unit);
+    city_change_production(pcprod->pcity, is_unit, which);
     city_prod_destroy(ppcprod);
   }
 }
Index: client/gui-sdl/wldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/wldlg.c,v
retrieving revision 1.5
diff -u -r1.5 wldlg.c
--- client/gui-sdl/wldlg.c      2003/06/05 23:10:46     1.5
+++ client/gui-sdl/wldlg.c      2003/07/25 15:32:31
@@ -177,12 +177,9 @@
     
     /* change production */
     if(pEditor->is_building_unit != pCity->is_building_unit ||
-      pEditor->currently_building != pCity->currently_building) {
-         
-      packet.build_id = pEditor->currently_building;
-      packet.is_build_id_unit_id = pEditor->is_building_unit;
-       
-      send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+       pEditor->currently_building != pCity->currently_building) {
+      city_change_production(pCity, pEditor->is_building_unit,
+                            pEditor->currently_building);
       same_prod = FALSE;
     }
     
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.52
diff -u -r1.52 citydlg.c
--- client/gui-win32/citydlg.c  2003/04/08 08:47:31     1.52
+++ client/gui-win32/citydlg.c  2003/07/25 15:32:31
@@ -1122,12 +1122,7 @@
        case ID_PRODCHANGE_CHANGE:
          if (sel>=0)
            {
-             struct packet_city_request packet;  
-             packet.city_id=pdialog->pcity->id;
-             packet.build_id=idx;
-             packet.is_build_id_unit_id=is_unit;
-             
-             send_packet_city_request(&aconnection, &packet, 
PACKET_CITY_CHANGE);
+             city_change_production(pdialog->pcidy, is_unit, idx);
              DestroyWindow(hWnd);
            }
          break;
@@ -1264,13 +1259,8 @@
         (!is_unit && can_build_improvement(pdialog->pcity, id))) {
       /* ...but we're not yet building it, then switch. */
       if (!same_as_current_build) {
-
         /* Change the current target */
-        packet.city_id = pdialog->pcity->id;
-        packet.build_id = id;
-        packet.is_build_id_unit_id = is_unit;
-        send_packet_city_request(&aconnection, &packet,
-                                 PACKET_CITY_CHANGE);
+       city_change_production(pdialog->pcity, is_unit, id);
       }
 
       /* This item is now (and may have always been) the current
Index: client/gui-win32/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/cityrep.c,v
retrieving revision 1.25
diff -u -r1.25 cityrep.c
--- client/gui-win32/cityrep.c  2003/03/29 09:57:37     1.25
+++ client/gui-win32/cityrep.c  2003/07/25 15:32:31
@@ -498,15 +498,11 @@
 
   connection_do_buffer(&aconnection);
   for (i = 0; i < selcount; i++) {
-    struct packet_city_request packet;
     pcity = (struct city *) ListBox_GetItemData(GetDlgItem(hWnd,
                                                           ID_CITYREP_LIST),
                                                cityids[i]);
-    packet.city_id = pcity->id;
-    packet.build_id = number;
-    packet.is_build_id_unit_id = is_unit;
     last_request_id =
-       send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+      city_change_production(pcity, is_unit, number);
     ListBox_SetSel(GetDlgItem(hWnd, ID_CITYREP_LIST), FALSE, cityids[i]);
   }
 
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.94
diff -u -r1.94 citydlg.c
--- client/gui-xaw/citydlg.c    2003/07/18 01:12:09     1.94
+++ client/gui-xaw/citydlg.c    2003/07/25 15:32:31
@@ -2091,14 +2091,10 @@
   ret=XawListShowCurrent(pdialog->change_list);
 
   if(ret->list_index!=XAW_LIST_NONE) {
-    struct packet_city_request packet;
-  
-    packet.city_id=pdialog->pcity->id;
-    packet.build_id=pdialog->change_list_ids[ret->list_index];
-    packet.is_build_id_unit_id=
-      (ret->list_index >= pdialog->change_list_num_improvements);
-    
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+    bool is_unit = ret->list_index >= pdialog->change_list_num_improvements;
+    int build_id = pdialog->change_list_ids[ret->list_index];
+
+    city_change_production(pdialog->pcity, is_unit, build_id);
   }
   
   XtDestroyWidget(XtParent(XtParent(w)));
@@ -2338,12 +2334,8 @@
        (!is_unit && can_build_improvement(pdialog->pcity, id))) {
       /* ...but we're not yet building it, then switch. */
       if (!same_as_current_build) {
-
        /* Change the current target */
-       packet.city_id=pdialog->pcity->id;
-       packet.build_id = id;
-       packet.is_build_id_unit_id = is_unit;
-       send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+       city_change_production(pdialog->pcity, is_unit, id);
       }
 
       /* This item is now (and may have always been) the current
Index: client/gui-xaw/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/cityrep.c,v
retrieving revision 1.50
diff -u -r1.50 cityrep.c
--- client/gui-xaw/cityrep.c    2003/04/04 15:47:48     1.50
+++ client/gui-xaw/cityrep.c    2003/07/25 15:32:31
@@ -384,7 +384,6 @@
 
   if(ret->list_index!=XAW_LIST_NONE && 
      (pcity=cities_in_list[ret->list_index])) {
-    struct packet_city_request packet;
     cid my_cid = (cid) XTPOINTER_TO_INT(client_data);
     Boolean unit;
     int build_nr;
@@ -392,10 +391,7 @@
     unit = cid_is_unit(my_cid);
     build_nr = cid_id(my_cid);
 
-    packet.city_id=pcity->id;
-    packet.build_id=build_nr;
-    packet.is_build_id_unit_id=unit;
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_CHANGE);
+    city_change_production(pcity, unit, build_nr);
   }
 }
 

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