[Freeciv-Dev] (PR#4723) new client function city_toggle_worker
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch provides a single new function in citydlg_common:
city_toggle_worker. It can be called by the GUI and CMA code to toggle
the worker on a particular city tile.
jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.19
diff -u -r1.19 citydlg_common.c
--- client/citydlg_common.c 2003/07/30 20:26:10 1.19
+++ client/citydlg_common.c 2003/07/30 21:04:03
@@ -432,3 +432,38 @@
return send_packet_city_request(&aconnection, &packet,
PACKET_CITY_CHANGE_SPECIALIST);
}
+
+/**************************************************************************
+ Toggle a worker<->specialist at the given city tile. Return the
+ request ID.
+**************************************************************************/
+int city_toggle_worker(struct city *pcity, int city_x, int city_y)
+{
+ struct packet_city_request packet;
+ enum packet_type ptype;
+
+ assert(is_valid_city_coords(city_x, city_y));
+
+ packet.city_id = pcity->id;
+ packet.worker_x = city_x;
+ packet.worker_y = city_y;
+
+ /* Fill out unused fields. */
+ packet.build_id = -1;
+ packet.is_build_id_unit_id = FALSE;
+ packet.specialist_from = packet.specialist_to = -1;
+
+ if (pcity->city_map[city_x][city_y] == C_TILE_WORKER) {
+ ptype = PACKET_CITY_MAKE_SPECIALIST;
+ } else if (pcity->city_map[city_x][city_y] == C_TILE_EMPTY) {
+ ptype = PACKET_CITY_MAKE_WORKER;
+ } else {
+ return 0;
+ }
+
+ freelog(LOG_DEBUG, "city_toggle_worker(city='%s'(%d), x=%d, y=%d, %s)",
+ pcity->name, pcity->id, city_x, city_y,
+ (ptype == PACKET_CITY_MAKE_SPECIALIST) ? "clear" : "set");
+
+ return send_packet_city_request(&aconnection, &packet, ptype);
+}
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.12
diff -u -r1.12 citydlg_common.h
--- client/citydlg_common.h 2003/07/30 20:26:10 1.12
+++ client/citydlg_common.h 2003/07/30 21:04:03
@@ -57,5 +57,6 @@
int city_sell_improvement(struct city *pcity, Impr_Type_id sell_id);
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);
#endif /* FC__CITYDLG_COMMON_H */
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.46
diff -u -r1.46 cma_core.c
--- client/agents/cma_core.c 2003/07/30 20:26:10 1.46
+++ client/agents/cma_core.c 2003/07/30 21:04:03
@@ -149,24 +149,6 @@
#undef T
/****************************************************************************
- Simple send_packet_* wrapper. Will return the id of the request.
-*****************************************************************************/
-static int set_worker(struct city *pcity, int x, int y, bool set_clear)
-{
- struct packet_city_request packet;
-
- freelog(LOG_DEBUG, "set_worker(city='%s'(%d), x=%d, y=%d, %s)",
- pcity->name, pcity->id, x, y, set_clear ? "set" : "clear");
-
- packet.city_id = pcity->id;
- packet.worker_x = x;
- packet.worker_y = y;
- return send_packet_city_request(&aconnection, &packet,
- (set_clear ? PACKET_CITY_MAKE_WORKER :
- PACKET_CITY_MAKE_SPECIALIST));
-}
-
-/****************************************************************************
Print the current state of the given city via
freelog(LOG_NORMAL,...).
*****************************************************************************/
@@ -383,7 +365,7 @@
my_city_map_iterate(pcity, x, y) {
if ((pcity->city_map[x][y] == C_TILE_WORKER) &&
!result->worker_positions_used[x][y]) {
- last_request_id = set_worker(pcity, x, y, FALSE);
+ last_request_id = city_toggle_worker(pcity, x, y);
if (first_request_id == 0) {
first_request_id = last_request_id;
}
@@ -412,7 +394,8 @@
my_city_map_iterate(pcity, x, y) {
if (result->worker_positions_used[x][y] &&
pcity->city_map[x][y] != C_TILE_WORKER) {
- last_request_id = set_worker(pcity, x, y, TRUE);
+ assert(pcity->city_map[x][y] == C_TILE_EMPTY);
+ last_request_id = city_toggle_worker(pcity, x, y);
if (first_request_id == 0) {
first_request_id = last_request_id;
}
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.166
diff -u -r1.166 citydlg.c
--- client/gui-gtk/citydlg.c 2003/07/30 20:26:11 1.166
+++ client/gui-gtk/citydlg.c 2003/07/30 21:04:03
@@ -2792,19 +2792,9 @@
if (pcity) {
int xtile, ytile;
- struct packet_city_request packet;
canvas_pos_to_city_pos(ev->x, ev->y, &xtile, &ytile);
- packet.city_id = pcity->id;
- packet.worker_x = xtile;
- packet.worker_y = ytile;
-
- if (pcity->city_map[xtile][ytile] == C_TILE_WORKER)
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_SPECIALIST);
- else if (pcity->city_map[xtile][ytile] == C_TILE_EMPTY)
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_WORKER);
+ city_toggle_worker(pcity, xtile, ytile);
}
return TRUE;
}
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.59
diff -u -r1.59 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 2003/07/30 20:26:11 1.59
+++ client/gui-gtk-2.0/citydlg.c 2003/07/30 21:04:03
@@ -2327,19 +2327,9 @@
if (pcity) {
int xtile, ytile;
- struct packet_city_request packet;
canvas_pos_to_city_pos(ev->x, ev->y, &xtile, &ytile);
- packet.city_id = pcity->id;
- packet.worker_x = xtile;
- packet.worker_y = ytile;
-
- if (pcity->city_map[xtile][ytile] == C_TILE_WORKER)
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_SPECIALIST);
- else if (pcity->city_map[xtile][ytile] == C_TILE_EMPTY)
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_WORKER);
+ city_toggle_worker(pcity, xtile, ytile);
}
return TRUE;
}
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.69
diff -u -r1.69 citydlg.c
--- client/gui-mui/citydlg.c 2003/07/30 20:26:11 1.69
+++ client/gui-mui/citydlg.c 2003/07/30 21:04:03
@@ -274,24 +274,6 @@
/****************************************************************
...
*****************************************************************/
-static void request_city_toggle_worker(struct city *pcity, int xtile, int
ytile)
-{
- if(is_valid_city_coords(xtile, ytile))
- {
- struct packet_city_request packet;
- packet.city_id = pcity->id;
- packet.worker_x = xtile;
- packet.worker_y = ytile;
-
- if (pcity->city_map[xtile][ytile] == C_TILE_WORKER)
- send_packet_city_request(&aconnection, &packet,
PACKET_CITY_MAKE_SPECIALIST);
- else if (pcity->city_map[xtile][ytile] == C_TILE_EMPTY)
- send_packet_city_request(&aconnection, &packet, PACKET_CITY_MAKE_WORKER);
- }
-}
-/****************************************************************
- ...
-*****************************************************************/
static void request_city_buy(struct city *pcity)
{
struct packet_city_request packet;
@@ -1050,7 +1032,9 @@
int xtile = msg->click->x;
int ytile = msg->click->y;
- request_city_toggle_worker(pcity, xtile, ytile);
+ if (is_valid_city_coords(xtile, ytile)) {
+ city_toggle_worker(pcity, xtile, ytile);
+ }
}
/**************************************************************************
Index: client/gui-sdl/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/citydlg.c,v
retrieving revision 1.26
diff -u -r1.26 citydlg.c
--- client/gui-sdl/citydlg.c 2003/07/30 20:26:11 1.26
+++ client/gui-sdl/citydlg.c 2003/07/30 21:04:03
@@ -1911,19 +1911,7 @@
if (get_citymap_cr(Main.event.motion.x - pMap->size.x,
Main.event.motion.y - pMap->size.y, &col, &row)) {
- struct packet_city_request packet;
-
- packet.city_id = pCityDlg->pCity->id;
- packet.worker_x = col;
- packet.worker_y = row;
-
- if (pCityDlg->pCity->city_map[col][row] == C_TILE_WORKER) {
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_SPECIALIST);
- } else if (pCityDlg->pCity->city_map[col][row] == C_TILE_EMPTY) {
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_WORKER);
- }
+ city_toggle_worker(pCityDlg->pCity, col, row);
}
return -1;
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.55
diff -u -r1.55 citydlg.c
--- client/gui-win32/citydlg.c 2003/07/30 20:26:11 1.55
+++ client/gui-win32/citydlg.c 2003/07/30 21:04:03
@@ -1663,28 +1663,6 @@
/**************************************************************************
...
**************************************************************************/
-
-
-static void city_dlg_click_map(struct city_dialog *pdialog, int x, int y)
-{
- struct packet_city_request packet;
- struct city *pcity;
- pcity=pdialog->pcity;
- packet.city_id=pcity->id;
- packet.worker_x=x;
- packet.worker_y=y;
-
- if(pcity->city_map[x][y]==C_TILE_WORKER)
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_SPECIALIST);
- else if(pcity->city_map[x][y]==C_TILE_EMPTY)
- send_packet_city_request(&aconnection, &packet, PACKET_CITY_MAKE_WORKER);
-
-}
-
-/**************************************************************************
-...
-**************************************************************************/
static void city_dlg_click_citizens(struct city_dialog *pdialog, int n)
{
enum specialist_type from, to;
@@ -1751,7 +1729,7 @@
xr=x-pdialog->map.x;
yr=y-pdialog->map.y;
canvas_pos_to_city_pos(xr,yr,&tile_x,&tile_y);
- city_dlg_click_map(pdialog,tile_x,tile_y);
+ city_toggle_worker(pdialog->pcity, tile_x, tile_y);
}
}
xr=x-pdialog->pop_x;
@@ -2265,7 +2243,7 @@
canvas_pos_to_city_pos(x-pdialog->maph.x,
y-pdialog->maph.y,
&tile_x,&tile_y);
- city_dlg_click_map(pdialog,tile_x,tile_y);
+ city_toggle_worker(pdialog->pcity, tile_x, tile_y);
}
break;
case WM_PAINT:
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.98
diff -u -r1.98 citydlg.c
--- client/gui-xaw/citydlg.c 2003/07/30 20:26:11 1.98
+++ client/gui-xaw/citydlg.c 2003/07/30 21:04:03
@@ -1884,21 +1884,9 @@
if (pcity) {
if (!cma_is_city_under_agent(pcity, NULL)) {
int xtile, ytile;
- struct packet_city_request packet;
- xtile = ev->x/NORMAL_TILE_WIDTH;
- ytile = ev->y/NORMAL_TILE_HEIGHT;
- packet.city_id = pcity->id;
- packet.worker_x = xtile;
- packet.worker_y = ytile;
-
- if (pcity->city_map[xtile][ytile] == C_TILE_WORKER) {
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_SPECIALIST);
- } else if (pcity->city_map[xtile][ytile] == C_TILE_EMPTY) {
- send_packet_city_request(&aconnection, &packet,
- PACKET_CITY_MAKE_WORKER);
- }
+ canvas_pos_to_city_pos(ev->x, ev->y, &xtile, &ytile);
+ city_toggle_worker(pcity, xtile, ytile);
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#4723) new client function city_toggle_worker,
Jason Short <=
|
|