[Freeciv-Dev] Re: (PR#5789) Don't send info about transported units to c
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#5789) Don't send info about transported units to clients without shared vision |
From: |
"Rafa³ Bursig" <bursig@xxxxxxxxx> |
Date: |
Sun, 21 Sep 2003 02:16:07 -0700 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
Hi All
This is my add on to last jason patch that fix some draw bugs in client.
Rafal
diff -u -r freeciv/client/control.c fc/client/control.c
--- freeciv/client/control.c 2003-09-18 14:34:48.000000000 +0200
+++ fc/client/control.c 2003-09-21 09:52:35.080733184 +0200
@@ -344,12 +344,14 @@
(always return first in stack). */
unit_list_iterate(ptile->units, punit)
if (unit_owner(punit) == game.player_ptr) {
- if (get_transporter_capacity(punit) > 0) {
- return punit;
- } else if (!panyowned) {
- panyowned = punit;
+ if (!punit->transported_by) {
+ if (get_transporter_capacity(punit) > 0) {
+ return punit;
+ } else if (!panyowned) {
+ panyowned = punit;
+ }
}
- } else if (!ptptother &&
+ } else if (!ptptother && !punit->transported_by &&
player_can_see_unit(game.player_ptr, punit)) {
if (get_transporter_capacity(punit) > 0) {
ptptother = punit;
@@ -1361,14 +1363,15 @@
return;
}
- if(unit_list_size(&ptile->units) == 1) {
+ if (unit_list_size(&ptile->units) == 1
+ && !unit_list_get(&ptile->units, 0)->client.occupied) {
struct unit *punit=unit_list_get(&ptile->units, 0);
if(game.player_idx==punit->owner) {
if(can_unit_do_activity(punit, ACTIVITY_IDLE)) {
set_unit_focus_and_select(punit);
}
}
- } else if(unit_list_size(&ptile->units) >= 2) {
+ } else if(unit_list_size(&ptile->units) > 0) {
/* The stack list is always popped up, even if it includes enemy units.
* If the server doesn't want the player to know about them it shouldn't
* tell him! The previous behavior would only pop up the stack if you
diff -u -r freeciv/client/mapview_common.c fc/client/mapview_common.c
--- freeciv/client/mapview_common.c 2003-08-13 08:09:31.000000000 +0200
+++ fc/client/mapview_common.c 2003-09-20 15:43:53.000000000 +0200
@@ -416,9 +416,9 @@
int unit_offset_x, int unit_offset_y,
int unit_width, int unit_height)
{
- struct drawn_sprite sprites[40];
+ struct drawn_sprite drawn_sprites[40];
bool solid_bg;
- int count = fill_unit_sprite_array(sprites, punit, &solid_bg), i;
+ int count = fill_unit_sprite_array(drawn_sprites, punit, &solid_bg), i;
if (!is_isometric && solid_bg) {
gui_put_rectangle(pcanvas_store, player_color(unit_owner(punit)),
@@ -426,16 +426,22 @@
}
for (i = 0; i < count; i++) {
- if (sprites[i].sprite) {
- int ox = sprites[i].offset_x, oy = sprites[i].offset_y;
+ if (drawn_sprites[i].sprite) {
+ int ox = drawn_sprites[i].offset_x, oy = drawn_sprites[i].offset_y;
/* units are never fogged */
gui_put_sprite(pcanvas_store, canvas_x + ox, canvas_y + oy,
- sprites[i].sprite,
+ drawn_sprites[i].sprite,
unit_offset_x - ox, unit_offset_y - oy,
unit_width - ox, unit_height - oy);
}
}
+
+ if (punit->client.occupied) {
+ gui_put_sprite(pcanvas_store, canvas_x, canvas_y,
+ sprites.unit.stack,
+ unit_offset_x, unit_offset_y, unit_width, unit_height);
+ }
}
/**************************************************************************
diff -u -r freeciv/client/packhand.c fc/client/packhand.c
--- freeciv/client/packhand.c 2003-09-18 14:34:48.000000000 +0200
+++ fc/client/packhand.c 2003-09-21 09:04:38.984966200 +0200
@@ -109,7 +109,12 @@
punit->activity_target = packet->activity_target;
punit->paradropped = packet->paradropped;
punit->connecting = packet->connecting;
-
+ punit->client.occupied = FALSE;
+ if (packet->carried) {
+ punit->transported_by = 1;
+ } else {
+ punit->transported_by = 0;
+ }
return punit;
}
@@ -130,7 +135,9 @@
punit->veteran = packet->veteran;
punit->hp = packet->hp;
punit->activity = packet->activity;
-
+ punit->client.occupied = packet->occupied;
+ punit->transported_by = 0;
+
return punit;
}
@@ -892,6 +899,7 @@
if (punit) {
int dest_x, dest_y;
punit->activity_count = packet_unit->activity_count;
+ punit->transported_by = packet_unit->transported_by;
if (punit->ai.control != packet_unit->ai.control) {
punit->ai.control = packet_unit->ai.control;
repaint_unit = TRUE;
diff -u -r freeciv/client/tilespec.c fc/client/tilespec.c
--- freeciv/client/tilespec.c 2003-08-28 16:58:42.000000000 +0200
+++ fc/client/tilespec.c 2003-09-20 15:43:53.000000000 +0200
@@ -2079,8 +2079,10 @@
if (punit && (draw_units || (draw_focus_unit && pfocus == punit))) {
sprs += fill_unit_sprite_array(sprs, punit, solid_bg);
*pplayer = unit_owner(punit);
- if (unit_list_size(&ptile->units) > 1)
+ if (unit_list_size(&ptile->units) > 1
+ || unit_list_get(&ptile->units, 0)->client.occupied) {
ADD_SPRITE_SIMPLE(sprites.unit.stack);
+ }
return sprs - save_sprs;
}
@@ -2234,7 +2236,8 @@
no_backdrop = (pcity != NULL);
sprs += fill_unit_sprite_array(sprs, punit, &dummy);
no_backdrop = FALSE;
- if (unit_list_size(&ptile->units) > 1) {
+ if (unit_list_size(&ptile->units) > 1
+ || unit_list_get(&ptile->units, 0)->client.occupied) {
ADD_SPRITE_SIMPLE(sprites.unit.stack);
}
}
diff -u -r freeciv/common/capstr.c fc/common/capstr.c
--- freeciv/common/capstr.c 2003-09-14 13:08:42.000000000 +0200
+++ fc/common/capstr.c 2003-09-20 15:43:53.000000000 +0200
@@ -80,7 +80,7 @@
"+no_nation_selected +diplomacy +no_extra_tiles " \
"+diplomacy2 +citizens_style +root_tech auth " \
"+nat_ulimit +retake +goto_pack borders dip " \
- "+packet_short_unit"
+ "+packet_short_unit +unit_occupied"
/* "+1.14.0" is protocol for 1.14.0 release.
*
@@ -149,6 +149,9 @@
*
* "packet_short_unit" is packet sent instead of full packet_unit_info to
* enemies, so that not all info about the unit is sent.
+ *
+ * "unit_occupied" means units occupying transporters are not sent to enemies.
+ * instead an 'occupied' flag is set for the transporter.
*/
void init_our_capability(void)
diff -u -r freeciv/common/packets.c fc/common/packets.c
--- freeciv/common/packets.c 2003-09-18 14:34:50.000000000 +0200
+++ fc/common/packets.c 2003-09-20 15:43:53.000000000 +0200
@@ -1980,7 +1980,8 @@
dio_put_uint8(&dout, req->activity);
pack = (COND_SET_BIT(req->carried, 3)
- | COND_SET_BIT(req->veteran, 4));
+ | COND_SET_BIT(req->veteran, 4)
+ | COND_SET_BIT(req->occupied, 5));
dio_put_uint8(&dout, pack);
dio_put_uint8(&dout, req->packet_use);
@@ -2010,6 +2011,7 @@
dio_get_uint8(&din, &pack);
packet->carried = TEST_BIT(pack, 3);
packet->veteran = TEST_BIT(pack, 4);
+ packet->occupied = TEST_BIT(pack, 5);
dio_get_uint8(&din, &packet->packet_use);
dio_get_uint16(&din, &packet->info_city_id);
diff -u -r freeciv/common/packets.h fc/common/packets.h
--- freeciv/common/packets.h 2003-09-18 14:34:50.000000000 +0200
+++ fc/common/packets.h 2003-09-20 15:43:53.000000000 +0200
@@ -345,6 +345,7 @@
int type;
int hp;
int activity;
+ bool occupied;
/* in packet only, not in unit struct */
int carried; /* FIXME: should not send carried units at all? */
diff -u -r freeciv/common/unit.c fc/common/unit.c
--- freeciv/common/unit.c 2003-08-26 18:26:41.000000000 +0200
+++ fc/common/unit.c 2003-09-20 15:43:53.000000000 +0200
@@ -1481,6 +1481,7 @@
punit->ord_map = 0;
punit->ord_city = 0;
set_unit_activity(punit, ACTIVITY_IDLE);
+ punit->client.occupied = FALSE;
return punit;
}
diff -u -r freeciv/common/unit.h fc/common/unit.h
--- freeciv/common/unit.h 2003-08-26 18:26:41.000000000 +0200
+++ fc/common/unit.h 2003-09-20 15:43:53.000000000 +0200
@@ -137,6 +137,10 @@
bool paradropped;
bool connecting;
int transported_by;
+ struct {
+ /* Only used at the client (the server is omniscient). */
+ bool occupied; /* True iff the transporter is occupied. */
+ } client;
struct goto_route *pgr;
};
diff -u -r freeciv/server/unithand.c fc/server/unithand.c
--- freeciv/server/unithand.c 2003-09-21 10:07:43.788588592 +0200
+++ fc/server/unithand.c 2003-09-21 09:37:15.000000000 +0200
@@ -1476,7 +1474,7 @@
punit->pgr = NULL;
}
- send_unit_info_to_onlookers(NULL, punit, punit->x, punit->y, FALSE);
+ send_unit_info_to_onlookers(NULL, punit, punit->x, punit->y);
handle_unit_activity_dependencies(punit, old_activity, old_target);
}
Tylko w fc/server: unithand.o
diff -u -r freeciv/server/unittools.c fc/server/unittools.c
--- freeciv/server/unittools.c 2003-09-21 10:07:43.841580536 +0200
+++ fc/server/unittools.c 2003-09-21 09:39:31.000000000 +0200
@@ -1881,11 +1881,12 @@
dest = NULL means all connections (game.game_connections)
**************************************************************************/
void send_unit_info_to_onlookers(struct conn_list *dest, struct unit *punit,
- int x, int y, bool carried)
+ int x, int y)
{
struct packet_unit_info info;
struct packet_short_unit sinfo;
-
+ bool carried = punit->transported_by != -1;
+
if (!dest) {
dest = &game.game_connections;
}
@@ -1893,21 +1894,27 @@
package_unit(punit, &info, carried);
package_short_unit(punit, &sinfo, carried,
UNIT_INFO_IDENTITY, FALSE, FALSE);
-
+
conn_list_iterate(*dest, pconn) {
struct player *pplayer = pconn->player;
- bool see_pos =
- can_player_see_unit_at(pplayer, punit, punit->x, punit->y);
- bool see_xy = see_pos;
-
- if (!same_pos(x, y, punit->x, punit->y)) {
- see_xy = can_player_see_unit_at(pplayer, punit, x, y);
- }
+
if ((!pplayer && pconn->observer)
|| pplayer->player_no == punit->owner) {
send_packet_unit_info(pconn, &info);
- } else if (see_pos || see_xy) {
- send_packet_short_unit(pconn, &sinfo);
+ } else {
+ bool see_unit = (!carried || (carried
+ && gives_shared_vision(unit_owner(punit), pplayer)));
+ bool see_pos = see_unit
+ && can_player_see_unit_at(pplayer, punit, punit->x, punit->y);
+ bool see_xy = see_pos;
+
+ if (see_unit && !same_pos(x, y, punit->x, punit->y)) {
+ see_xy = can_player_see_unit_at(pplayer, punit, x, y);
+ }
+
+ if (see_pos || see_xy) {
+ send_packet_short_unit(pconn, &sinfo);
+ }
}
} conn_list_iterate_end;
}
@@ -1920,7 +1927,7 @@
{
struct conn_list *conn_dest = (dest ? &dest->connections
: &game.game_connections);
- send_unit_info_to_onlookers(conn_dest, punit, punit->x, punit->y, FALSE);
+ send_unit_info_to_onlookers(conn_dest, punit, punit->x, punit->y);
}
/**************************************************************************
@@ -1943,7 +1950,7 @@
if (!pplayer
|| map_is_known_and_seen(punit->x, punit->y, pplayer)) {
send_unit_info_to_onlookers(&pconn->self, punit,
- punit->x, punit->y, FALSE);
+ punit->x, punit->y);
}
}
unit_list_iterate_end;
@@ -2880,7 +2887,7 @@
unit_list_insert(&pdesttile->units, pcargo);
check_unit_activity(pcargo);
- send_unit_info_to_onlookers(NULL, pcargo, src_x, src_y, TRUE);
+ send_unit_info_to_onlookers(NULL, pcargo, src_x, src_y);
fog_area(unit_owner(pcargo), src_x, src_y,
unit_type(pcargo)->vision_range);
handle_unit_move_consequences(pcargo, src_x, src_y, dest_x, dest_y);
} unit_list_iterate_end;
@@ -2942,7 +2949,7 @@
/* Send updated information to anyone watching. If the unit moves
* in or out of a city we update the 'occupied' field. Note there may
* be cities at both src and dest under some rulesets. */
- send_unit_info_to_onlookers(NULL, punit, src_x, src_y, FALSE);
+ send_unit_info_to_onlookers(NULL, punit, src_x, src_y);
if ((pcity = map_get_city(src_x, src_y))) {
refresh_dumb_city(pcity);
}
diff -u -r freeciv/server/unittools.h fc/server/unittools.h
--- freeciv/server/unittools.h 2003-09-20 11:39:42.000000000 +0200
+++ fc/server/unittools.h 2003-09-21 09:32:55.000000000 +0200
@@ -71,7 +71,7 @@
int info_city_id, bool new_serial_num);
void send_unit_info(struct player *dest, struct unit *punit);
void send_unit_info_to_onlookers(struct conn_list *dest, struct unit *punit,
- int x, int y, bool carried);
+ int x, int y);
void send_all_known_units(struct conn_list *dest);
|
|