Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] (PR#3934) add adjust_workers_button_pressed() to mapctrl_c
Home

[Freeciv-Dev] (PR#3934) add adjust_workers_button_pressed() to mapctrl_c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3934) add adjust_workers_button_pressed() to mapctrl_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 4 Apr 2003 15:27:00 -0800
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch adds a new function, adjust_workers_button_pressed,
to mapctrl_common, and calls this function from the GUI code in win32,
XAW, GTK, and GTK2 clients.

This fixes several bug(let)s in several clients:
- Correctly checks can_client_send_orders (XAW, Win32).
- Correctly handles iso view (XAW).
- Correctly handles unreal positions (XAW).
- Correctly checks for CMA control (XAW, Win32).
- Correctly handles C_TILE_UNAVAILABLE state (all).

I also moved the city_workers_display variable out of mapctrl and into
mapctrl_common, and added comments here and elsewhere.

It is tested under some, but not all, clients.

jason

Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.10
diff -u -r1.10 mapctrl_common.c
--- client/mapctrl_common.c     2003/04/04 18:34:37     1.10
+++ client/mapctrl_common.c     2003/04/04 23:21:56
@@ -19,6 +19,8 @@
 
 #include "agents.h"
 #include "civclient.h"
+#include "clinet.h"
+#include "cma_core.h"
 #include "control.h"
 #include "goto.h"
 #include "mapctrl_g.h"
@@ -27,6 +29,9 @@
 
 #include "mapctrl_common.h"
 
+/* Update the workers for a city on the map, when the update is received */
+struct city *city_workers_display = NULL;
+
 static bool turn_done_state;
 static bool is_turn_done_state_valid = FALSE;
 
@@ -76,6 +81,51 @@
   if (can_client_issue_orders()) {
     if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
       wakeup_sentried_units(map_x, map_y);
+    }
+  }
+}
+
+/**************************************************************************
+  Adjust the position of city workers from the mapview.  Usually this is
+  done with SHIFT+left-click.
+**************************************************************************/
+void adjust_workers_button_pressed(int canvas_x, int canvas_y)
+{
+  int map_x, map_y, city_x, city_y;
+  struct city *pcity;
+  struct packet_city_request packet;
+  enum city_tile_type worker;
+
+  if (can_client_issue_orders()) {
+    if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
+      pcity = find_city_near_tile(map_x, map_y);
+      if (pcity && !cma_is_city_under_agent(pcity, NULL)) {
+       if (!map_to_city_map(&city_x, &city_y, pcity, map_x, map_y)) {
+         assert(0);
+       }
+
+       packet.city_id = pcity->id;
+       packet.worker_x = city_x;
+       packet.worker_y = city_y;
+
+       worker = get_worker_city(pcity, city_x, city_y);
+       if (worker == C_TILE_WORKER) {
+         send_packet_city_request(&aconnection, &packet,
+                                  PACKET_CITY_MAKE_SPECIALIST);
+       } else if (worker == C_TILE_EMPTY) {
+         send_packet_city_request(&aconnection, &packet,
+                                  PACKET_CITY_MAKE_WORKER);
+       } else {
+         /* If worker == C_TILE_UNAVAILABLE then we can't use this tile.  No
+          * packet is sent and city_workers_display is not updated. */
+         return;
+       }
+       
+       /* When the city info packet is received, update the workers on the
+        * map.  This is a bad hack used to selectively update the mapview
+        * when we receive the corresponding city packet. */
+       city_workers_display = pcity;
+      }
     }
   }
 }
Index: client/mapctrl_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.h,v
retrieving revision 1.5
diff -u -r1.5 mapctrl_common.h
--- client/mapctrl_common.h     2003/04/04 18:34:37     1.5
+++ client/mapctrl_common.h     2003/04/04 23:21:56
@@ -20,7 +20,10 @@
 bool get_turn_done_button_state(void);
 void scroll_mapview(enum direction8 gui_dir);
 void wakeup_button_pressed(int canvas_x, int canvas_y);
+void adjust_workers_button_pressed(int canvas_x, int canvas_y);
 void update_turn_done_button_state(void);
 void update_line(int canvas_x, int canvas_y);
+
+extern struct city *city_workers_display;
 
 #endif /* FC__MAPVIEW_COMMON_H */
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.79
diff -u -r1.79 mapctrl.c
--- client/gui-gtk/mapctrl.c    2003/04/04 18:34:37     1.79
+++ client/gui-gtk/mapctrl.c    2003/04/04 23:21:57
@@ -48,8 +48,6 @@
 
 #include "mapctrl.h"
 
-/* Update the workers for a city on the map, when the update is received */
-struct city *city_workers_display = NULL;
 /* Color to use to display the workers */
 int city_workers_color = COLOR_STD_WHITE;
 
@@ -317,9 +315,8 @@
     return TRUE;
   }
 
-  if (can_client_issue_orders()
-      && (ev->button == 1) && (ev->state & GDK_SHIFT_MASK)) {
-    adjust_workers(w, ev);
+  if (ev->button == 1 && (ev->state & GDK_SHIFT_MASK)) {
+    adjust_workers_button_pressed(ev->x, ev->y);
     return TRUE;
   }
 
@@ -359,51 +356,6 @@
 {
   update_line(event->x, event->y);
   return TRUE;
-}
-
-/**************************************************************************
-  Adjust the position of city workers from the mapcanvas
-**************************************************************************/
-void adjust_workers(GtkWidget *widget, GdkEventButton *ev)
-{
-  int x, y, map_x, map_y, is_valid;
-  struct city *pcity;
-  struct packet_city_request packet;
-  enum city_tile_type wrk;
-
-  if (!can_client_issue_orders()) {
-    return;
-  }
-
-  if (!canvas_to_map_pos(&map_x, &map_y, ev->x, ev->y)) {
-    return;
-  }
-
-  pcity = find_city_near_tile(map_x, map_y);
-  if (!pcity) {
-    return;
-  }
-
-  if (cma_is_city_under_agent(pcity, NULL)) {
-    return;
-  }
-
-  is_valid = map_to_city_map(&x, &y, pcity, map_x, map_y);
-  assert(is_valid);
-
-  packet.city_id = pcity->id;
-  packet.worker_x = x;
-  packet.worker_y = y;
-  
-  wrk = get_worker_city(pcity, x, y);
-  if (wrk == C_TILE_WORKER)
-    send_packet_city_request(&aconnection, &packet, 
-                           PACKET_CITY_MAKE_SPECIALIST);
-  else if (wrk == C_TILE_EMPTY)
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_MAKE_WORKER);
-
-  /* When the city info packet is received, update the workers on the map*/
-  city_workers_display = pcity;
 }
 
 /**************************************************************************
Index: client/gui-gtk/mapctrl.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.h,v
retrieving revision 1.11
diff -u -r1.11 mapctrl.h
--- client/gui-gtk/mapctrl.h    2003/01/09 19:21:17     1.11
+++ client/gui-gtk/mapctrl.h    2003/04/04 23:21:57
@@ -21,7 +21,6 @@
 struct t_popup_pos {int xroot, yroot;};
 
 void key_city_workers(GtkWidget *w, GdkEventKey *ev);
-void adjust_workers(GtkWidget *widget, GdkEventButton *ev);
 
 gint butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev);
 gint butt_down_wakeup(GtkWidget *w, GdkEventButton *ev);
Index: client/gui-gtk-2.0/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.c,v
retrieving revision 1.19
diff -u -r1.19 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        2003/04/04 18:34:37     1.19
+++ client/gui-gtk-2.0/mapctrl.c        2003/04/04 23:21:57
@@ -46,8 +46,6 @@
 
 #include "mapctrl.h"
 
-/* Update the workers for a city on the map, when the update is received */
-struct city *city_workers_display = NULL;
 /* Color to use to display the workers */
 int city_workers_color=COLOR_STD_WHITE;
 
@@ -309,9 +307,8 @@
     return TRUE;
   }
 
-  if (can_client_issue_orders()
-      && (ev->button == 1) && (ev->state & GDK_SHIFT_MASK)) {
-    adjust_workers(w, ev);
+  if (ev->button == 1 && (ev->state & GDK_SHIFT_MASK)) {
+    adjust_workers_button_pressed(ev->x, ev->y);
     return TRUE;
   }
 
@@ -351,51 +348,6 @@
 {
   update_line(event->x, event->y);
   return TRUE;
-}
-
-/**************************************************************************
-  Adjust the position of city workers from the mapcanvas
-**************************************************************************/
-void adjust_workers(GtkWidget *widget, GdkEventButton *ev)
-{
-  int x, y, map_x, map_y, is_valid;
-  struct city *pcity;
-  struct packet_city_request packet;
-  enum city_tile_type wrk;
-
-  if (!can_client_issue_orders()) {
-    return;
-  }
-
-  if (!canvas_to_map_pos(&map_x, &map_y, ev->x, ev->y)) {
-    return;
-  }
-
-  pcity = find_city_near_tile(map_x, map_y);
-  if (!pcity) {
-    return;
-  }
-
-  if (cma_is_city_under_agent(pcity, NULL)) {
-    return;
-  }
-
-  is_valid = map_to_city_map(&x, &y, pcity, map_x, map_y);
-  assert(is_valid);
-
-  packet.city_id = pcity->id;
-  packet.worker_x = x;
-  packet.worker_y = y;
-  
-  wrk = get_worker_city(pcity, x, y);
-  if(wrk == C_TILE_WORKER)
-    send_packet_city_request(&aconnection, &packet, 
-                           PACKET_CITY_MAKE_SPECIALIST);
-  else if(wrk == C_TILE_EMPTY)
-    send_packet_city_request(&aconnection, &packet, PACKET_CITY_MAKE_WORKER);
-
-  /* When the city info packet is received, update the workers on the map*/
-  city_workers_display = pcity;
 }
 
 /**************************************************************************
Index: client/gui-gtk-2.0/mapctrl.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.h,v
retrieving revision 1.3
diff -u -r1.3 mapctrl.h
--- client/gui-gtk-2.0/mapctrl.h        2003/01/09 19:21:17     1.3
+++ client/gui-gtk-2.0/mapctrl.h        2003/04/04 23:21:57
@@ -20,7 +20,6 @@
 struct unit;
 
 void key_city_workers(GtkWidget *w, GdkEventKey *ev);
-void adjust_workers(GtkWidget *widget, GdkEventButton *ev);
 
 gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data);
 gboolean butt_down_wakeup(GtkWidget *w, GdkEventButton *ev, gpointer data);
Index: client/gui-mui/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapctrl.c,v
retrieving revision 1.14
diff -u -r1.14 mapctrl.c
--- client/gui-mui/mapctrl.c    2003/01/09 19:21:17     1.14
+++ client/gui-mui/mapctrl.c    2003/04/04 23:21:57
@@ -50,9 +50,6 @@
 #include "muistuff.h"
 #include "mapclass.h"
 
-/* Update the workers for a city on the map, when the update is received */
-struct city *city_workers_display = NULL;
-
 /****************************************************************
 ...
 *****************************************************************/
Index: client/gui-sdl/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapctrl.c,v
retrieving revision 1.15
diff -u -r1.15 mapctrl.c
--- client/gui-sdl/mapctrl.c    2003/04/03 04:13:49     1.15
+++ client/gui-sdl/mapctrl.c    2003/04/04 23:21:57
@@ -69,8 +69,6 @@
 
 #include "mapctrl.h"
 
-struct city *city_workers_display = NULL;
-
 /* New City Dialog */
 static struct SMALL_DLG *pNewCity_Dlg = NULL;
   
Index: client/gui-stub/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapctrl.c,v
retrieving revision 1.6
diff -u -r1.6 mapctrl.c
--- client/gui-stub/mapctrl.c   2003/04/04 15:47:48     1.6
+++ client/gui-stub/mapctrl.c   2003/04/04 23:21:57
@@ -19,8 +19,6 @@
 
 #include "mapctrl.h"
 
-struct city *city_workers_display = NULL;
-
 /**************************************************************************
   Popup a dialog to ask for the name of a new city.  The given string
   should be used as a suggestion.
Index: client/gui-win32/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapctrl.c,v
retrieving revision 1.22
diff -u -r1.22 mapctrl.c
--- client/gui-win32/mapctrl.c  2003/04/04 18:34:37     1.22
+++ client/gui-win32/mapctrl.c  2003/04/04 23:21:58
@@ -50,8 +50,6 @@
 #include "mapctrl.h"
 #include "gui_main.h"
 
-struct city *city_workers_display = NULL;
-
 HWND popit_popup=NULL;
 /*************************************************************************
 
@@ -218,41 +216,6 @@
 /**************************************************************************
 
 **************************************************************************/
-static void adjust_workers(int map_x, int map_y)
-{
-  int x, y, is_valid;
-  struct city *pcity;
-  struct packet_city_request packet;
-  enum city_tile_type wrk;
-  
-
-  pcity = find_city_near_tile(map_x, map_y);
-  if (!pcity) {
-    return;
-  }
-  
-  is_valid = map_to_city_map(&x, &y, pcity, map_x, map_y);
-  assert(is_valid);
-  
-  packet.city_id=pcity->id;
-  packet.worker_x=x;
-  packet.worker_y=y;
-  
-  wrk = get_worker_city(pcity, x, y);
-  if(wrk==C_TILE_WORKER)
-    send_packet_city_request(&aconnection, &packet, 
-                            PACKET_CITY_MAKE_SPECIALIST);
-  else if(wrk==C_TILE_EMPTY)
-    send_packet_city_request(&aconnection, &packet, 
-                            PACKET_CITY_MAKE_WORKER);
-  
-  /* When the city info packet is received, update the workers on the map*/
-  city_workers_display = pcity;
-}
-
-/**************************************************************************
-
-**************************************************************************/
 static LONG CALLBACK map_wnd_proc(HWND hwnd,UINT message,WPARAM wParam, LPARAM 
lParam)
 {
   HDC hdc;
@@ -271,7 +234,7 @@
       break;
     }
     if (wParam&MK_SHIFT) {
-      adjust_workers(xtile,ytile);
+      adjust_workers_button_pressed(LOWORD(lParam), HIWORD(lParam));
       wakeup_button_pressed(LOWORD(lParam), HIWORD(lParam));
     } else if (wParam&MK_CONTROL){
       popit(LOWORD(lParam),HIWORD(lParam),xtile,ytile);
Index: client/gui-xaw/actions.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/actions.c,v
retrieving revision 1.14
diff -u -r1.14 actions.c
--- client/gui-xaw/actions.c    2003/02/05 07:23:48     1.14
+++ client/gui-xaw/actions.c    2003/04/04 23:21:58
@@ -53,7 +53,7 @@
 
 static void xaw_btn_adjust_workers(Widget w, XEvent *event, String *argv, 
Cardinal *argc)
 {
-  mapctrl_btn_adjust_workers(event);
+  adjust_workers_button_pressed(event->xbutton.x, event->xbutton.y);
 }
 
 static void xaw_btn_select_citymap(Widget w, XEvent *event, String *argv, 
Cardinal *argc)
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.67
diff -u -r1.67 mapctrl.c
--- client/gui-xaw/mapctrl.c    2003/04/04 18:34:37     1.67
+++ client/gui-xaw/mapctrl.c    2003/04/04 23:21:58
@@ -57,8 +57,6 @@
 
 #include "mapctrl.h"
 
-/* Update the workers for a city on the map, when the update is received */
-struct city *city_workers_display = NULL;
 /* Color to use to display the workers */
 int city_workers_color=COLOR_STD_WHITE;
 
@@ -285,50 +283,6 @@
   if (on_same_screen) {
     update_line(x, y);
   }
-}
-
-/**************************************************************************
-  Adjust the position of city workers from the mapcanvas
-**************************************************************************/
-void mapctrl_btn_adjust_workers(XEvent *event)
-{
-  int map_x, map_y, x, y, is_valid;
-  XButtonEvent *ev=&event->xbutton;
-  struct city *pcity;
-  struct packet_city_request packet;
-  enum city_tile_type wrk;
-
-  if (!can_client_change_view()) {
-    return;
-  }
-
-  map_x = map_view_x0 + ev->x / NORMAL_TILE_WIDTH;
-  map_y = map_view_y0 + ev->y / NORMAL_TILE_HEIGHT;
-  is_valid = normalize_map_pos(&map_x, &map_y);
-  assert(is_valid);
-
-  if (!(pcity = find_city_near_tile(map_x, map_y)))
-    return;
-
-  is_valid = map_to_city_map(&x, &y, pcity, map_x, map_y);
-  assert(is_valid);
-
-  packet.city_id=pcity->id;
-  packet.worker_x=x;
-  packet.worker_y=y;
-
-  wrk = get_worker_city(pcity, x, y);
-  if(wrk==C_TILE_WORKER)
-    send_packet_city_request(&aconnection, &packet, 
-                            PACKET_CITY_MAKE_SPECIALIST);
-  else if(wrk==C_TILE_EMPTY)
-    send_packet_city_request(&aconnection, &packet, 
-                            PACKET_CITY_MAKE_WORKER);
-
-  /* When the city info packet is received, update the workers on the map*/
-  city_workers_display = pcity;
-
-  return;
 }
 
 /**************************************************************************
Index: client/gui-xaw/mapctrl.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.h,v
retrieving revision 1.14
diff -u -r1.14 mapctrl.h
--- client/gui-xaw/mapctrl.h    2003/01/09 19:21:18     1.14
+++ client/gui-xaw/mapctrl.h    2003/04/04 23:21:58
@@ -19,7 +19,6 @@
 
 
 void mapctrl_key_city_workers(XEvent *event);
-void mapctrl_btn_adjust_workers(XEvent *event);
 
 void mapctrl_btn_mapcanvas(XEvent *event);
 void mapctrl_btn_overviewcanvas(XEvent *event);
Index: client/include/mapctrl_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapctrl_g.h,v
retrieving revision 1.9
diff -u -r1.9 mapctrl_g.h
--- client/include/mapctrl_g.h  2002/08/24 14:37:49     1.9
+++ client/include/mapctrl_g.h  2003/04/04 23:21:58
@@ -20,8 +20,6 @@
 struct unit;
 struct city;
 
-extern struct city *city_workers_display;
-
 void popup_newcity_dialog(struct unit *punit, char *suggestname);
 
 void set_turn_done_button_state(bool state);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#3934) add adjust_workers_button_pressed() to mapctrl_common, Jason Short <=