[Freeciv-Dev] pauses during client-side goto (PR#4683)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Here's an improved patch to allow pauses during client-side goto. It
should fix the focus problems.
A new flag punit->done_moving is introduced. It's set by the server
(for the most part) and sent to the client. When done_moving is set the
unit won't be focused on, and if that unit is focused the focus will be
advanced.
Thus if we have a unit on goto with some MP left, we can tell whether it
is done moving for this turn (because of a goto pause) or not.
Hopefull the use of this flag can improve other fast-focus problems as well.
jason
? diff
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.113
diff -u -r1.113 control.c
--- client/control.c 2003/09/22 16:54:09 1.113
+++ client/control.c 2003/09/30 00:37:43
@@ -193,6 +193,7 @@
if(!punit_focus
|| (punit_focus->activity!=ACTIVITY_IDLE
&& punit_focus->activity!=ACTIVITY_GOTO)
+ || punit_focus->done_moving
|| punit_focus->moves_left==0
|| punit_focus->ai.control) {
advance_unit_focus();
@@ -284,7 +285,8 @@
unit_list_iterate(game.player_ptr->units, punit) {
if(punit!=punit_focus) {
if(punit->focus_status==FOCUS_AVAIL && punit->activity==ACTIVITY_IDLE &&
- punit->moves_left > 0 && !punit->ai.control) {
+ punit->moves_left > 0 && !punit->done_moving
+ && !punit->ai.control) {
int d;
d=sq_map_distance(punit->x, punit->y, x, y);
if(d<best_dist) {
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.332
diff -u -r1.332 packhand.c
--- client/packhand.c 2003/09/23 22:01:41 1.332
+++ client/packhand.c 2003/09/30 00:37:43
@@ -109,6 +109,7 @@
punit->activity_target = packet->activity_target;
punit->paradropped = packet->paradropped;
punit->connecting = packet->connecting;
+ punit->done_moving = packet->done_moving;
punit->occupy = packet->occupy;
if (packet->carried) {
punit->transported_by = 1;
@@ -1098,6 +1099,10 @@
}
punit->paradropped = packet_unit->paradropped;
punit->connecting = packet_unit->connecting;
+ if (punit->done_moving != packet_unit->done_moving) {
+ punit->done_moving = packet_unit->done_moving;
+ check_focus = TRUE;
+ }
dest_x = packet_unit->x;
dest_y = packet_unit->y;
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.257
diff -u -r1.257 packets.c
--- common/packets.c 2003/09/22 16:54:09 1.257
+++ common/packets.c 2003/09/30 00:37:43
@@ -1278,7 +1278,8 @@
dio_put_uint16(&dout, req->id);
dio_put_uint8(&dout, req->owner);
- pack = (COND_SET_BIT((req->occupy > 0), 2) |
+ pack = (COND_SET_BIT(req->done_moving, 1) |
+ COND_SET_BIT((req->occupy > 0), 2) |
COND_SET_BIT(req->carried, 3) |
COND_SET_BIT(req->veteran, 4) |
COND_SET_BIT(req->ai, 5) |
@@ -1560,6 +1561,7 @@
dio_get_uint16(&din, &packet->id);
dio_get_uint8(&din, &packet->owner);
dio_get_uint8(&din, &pack);
+ packet->done_moving = TEST_BIT(pack, 1);
packet->carried = TEST_BIT(pack, 3);
packet->veteran = TEST_BIT(pack, 4);
packet->ai = TEST_BIT(pack, 5);
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.154
diff -u -r1.154 packets.h
--- common/packets.h 2003/09/22 16:54:09 1.154
+++ common/packets.h 2003/09/30 00:37:43
@@ -327,6 +327,7 @@
enum tile_special_type activity_target;
bool paradropped;
bool connecting;
+ bool done_moving;
int occupy;
/* in packet only, not in unit struct */
bool carried; /* FIXME: should not send carried units at all?
*/
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.184
diff -u -r1.184 unit.c
--- common/unit.c 2003/09/28 17:44:16 1.184
+++ common/unit.c 2003/09/30 00:37:43
@@ -809,6 +809,10 @@
punit->activity_count=0;
punit->activity_target = S_NO_SPECIAL;
punit->connecting = FALSE;
+ if (new_activity == ACTIVITY_IDLE && punit->moves_left > 0) {
+ /* No longer done. */
+ punit->done_moving = FALSE;
+ }
}
/**************************************************************************
@@ -818,10 +822,8 @@
enum unit_activity new_activity,
enum tile_special_type new_target)
{
- punit->activity=new_activity;
- punit->activity_count=0;
+ set_unit_activity(punit, new_activity);
punit->activity_target=new_target;
- punit->connecting = FALSE;
}
/**************************************************************************
@@ -1466,6 +1468,7 @@
punit->moved = FALSE;
punit->paradropped = FALSE;
punit->connecting = FALSE;
+ punit->done_moving = FALSE;
if (is_barbarian(pplayer)) {
punit->fuel = BARBARIAN_LIFE;
}
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.101
diff -u -r1.101 unit.h
--- common/unit.h 2003/09/28 17:44:16 1.101
+++ common/unit.h 2003/09/30 00:37:43
@@ -137,6 +137,14 @@
bool moved;
bool paradropped;
bool connecting;
+
+ /* This value is set if the unit is done moving for this turn. This
+ * information is used by the client. The invariant is:
+ * - If the unit has no more moves, it's done moving.
+ * - If the unit is on a goto but is waiting, it's done moving.
+ * - Otherwise the unit is not done moving. */
+ bool done_moving;
+
int transported_by;
int occupy; /* number of units that occupy transporter */
struct goto_route *pgr;
Index: server/gotohand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.h,v
retrieving revision 1.27
diff -u -r1.27 gotohand.h
--- server/gotohand.h 2003/02/20 09:45:22 1.27
+++ server/gotohand.h 2003/09/30 00:37:43
@@ -24,6 +24,7 @@
GR_DIED, /* pretty obvious that */
GR_ARRIVED, /* arrived to the destination */
GR_OUT_OF_MOVEPOINTS, /* either no moves left or plane refueling */
+ GR_WAITING, /* waiting due to danger, has moves */
GR_FOUGHT, /* was stopped due to fighting, has moves */
GR_FAILED /* failed for some other reason, has moves */
};
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.137
diff -u -r1.137 savegame.c
--- server/savegame.c 2003/09/22 16:05:39 1.137
+++ server/savegame.c 2003/09/30 00:37:43
@@ -1003,6 +1003,8 @@
punit->connecting=secfile_lookup_bool_default(file, FALSE,
"player%d.u%d.connecting",
plrno, i);
+ punit->done_moving = secfile_lookup_bool_default(file,
+ (punit->moves_left == 0), "player%d.u%d.done_moving", plrno, i);
/* Load the goto information. Older savegames will not have the
* "go" field, so we just load the goto destination by default. */
if (secfile_lookup_bool_default(file, TRUE,
@@ -1443,6 +1445,8 @@
secfile_insert_bool(file, punit->connecting,
"player%d.u%d.connecting",
plrno, i);
+ secfile_insert_bool(file, punit->done_moving,
+ "player%d.u%d.done_moving", plrno, i);
secfile_insert_int(file, punit->moves_left, "player%d.u%d.moves",
plrno, i);
secfile_insert_int(file, punit->fuel, "player%d.u%d.fuel",
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.256
diff -u -r1.256 unittools.c
--- server/unittools.c 2003/09/29 21:47:58 1.256
+++ server/unittools.c 2003/09/30 00:37:43
@@ -552,6 +552,7 @@
static void unit_restore_movepoints(struct player *pplayer, struct unit *punit)
{
punit->moves_left=unit_move_rate(punit);
+ punit->done_moving = FALSE;
}
/**************************************************************************
@@ -1875,6 +1876,7 @@
packet->activity_target = punit->activity_target;
packet->paradropped = punit->paradropped;
packet->connecting = punit->connecting;
+ packet->done_moving = punit->done_moving;
packet->carried = carried;
packet->occupy = get_transporter_occupancy(punit);
}
@@ -2968,6 +2970,9 @@
}
punit->transported_by = -1;
punit->moves_left = MAX(0, punit->moves_left - move_cost);
+ if (punit->moves_left == 0) {
+ punit->done_moving = TRUE;
+ }
unit_list_insert(&pdesttile->units, punit);
check_unit_activity(punit);
@@ -3148,7 +3153,7 @@
{
struct goto_route *pgr = punit->pgr;
int index, x, y;
- bool res, last_tile;
+ bool res, last_tile, moved;
int patrol_stop_index = pgr->last_index;
int unitid = punit->id;
struct player *pplayer = unit_owner(punit);
@@ -3188,7 +3193,12 @@
}
/* Move unit */
- res = handle_unit_move_request(punit, x, y, FALSE, !last_tile);
+ moved = !same_pos(punit->x, punit->y, x, y);
+ if (moved) {
+ res = handle_unit_move_request(punit, x, y, FALSE, !last_tile);
+ } else {
+ res = TRUE;
+ }
if (!player_find_unit_by_id(pplayer, unitid)) {
return GR_DIED;
@@ -3211,6 +3221,15 @@
if (maybe_cancel_patrol_due_to_enemy(punit)) {
return GR_FAILED;
}
+ }
+
+ if (!moved) {
+ /* Sometimes the goto route will have us sit still for a moment -
+ * for instance a trireme will do this to have enough MP to
+ * cross the ocean in one turn. */
+ punit->done_moving = TRUE;
+ send_unit_info(unit_owner(punit), punit);
+ return GR_WAITING;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] pauses during client-side goto (PR#4683),
Jason Short <=
|
|