[Freeciv-Dev] (PR#5789) Don't send info about transported units to clien
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#5789) Don't send info about transported units to clients without shared vision. |
From: |
"Rafa³ Bursig" <bursig@xxxxxxxxx> |
Date: |
Wed, 3 Sep 2003 02:23:06 -0700 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
Hi All
This code add restriction in sending transported units info only to
owner player (plus all players that owner player give shared vision)
and transport owner (plus all players that transport owner player give
shared vision) for rest players this unit is hidden in transport unit
(remove unit package is send in enter transport phase)
Additionaly this patch allow sending to client transported_by info and
unload code search in units loaded on transport , not in units with
sentry activity.
Rafal
diff -u -r freeciv/client/control.c fc3/client/control.c
--- freeciv/client/control.c 2003-08-28 16:49:08.000000000 +0200
+++ fc3/client/control.c 2003-09-01 20:30:44.000000000 +0200
@@ -313,21 +313,21 @@
/* If a unit is attacking we should show that on top */
if (punit_attacking && map_get_tile(punit_attacking->x,punit_attacking->y)
== ptile) {
unit_list_iterate(ptile->units, punit)
- if(punit == punit_attacking) return punit;
+ if(punit == punit_attacking && punit->transported_by == -1) return punit;
unit_list_iterate_end;
}
/* If a unit is defending we should show that on top */
if (punit_defending && map_get_tile(punit_defending->x,punit_defending->y)
== ptile) {
unit_list_iterate(ptile->units, punit)
- if(punit == punit_defending) return punit;
+ if(punit == punit_defending && punit->transported_by == -1) return punit;
unit_list_iterate_end;
}
/* If the unit in focus is at this tile, show that on top */
if (punit_focus && map_get_tile(punit_focus->x,punit_focus->y) == ptile) {
unit_list_iterate(ptile->units, punit)
- if(punit == punit_focus) return punit;
+ if(punit == punit_focus && punit->transported_by == -1) return punit;
unit_list_iterate_end;
}
@@ -343,14 +343,14 @@
4: any unit
(always return first in stack). */
unit_list_iterate(ptile->units, punit)
- if (unit_owner(punit) == game.player_ptr) {
+ if (unit_owner(punit) == game.player_ptr && punit->transported_by == -1) {
if (get_transporter_capacity(punit) > 0) {
return punit;
} else if (!panyowned) {
panyowned = punit;
}
- } else if (!ptptother &&
- player_can_see_unit(game.player_ptr, punit)) {
+ } else if (!ptptother && punit->transported_by == -1
+ && player_can_see_unit(game.player_ptr, punit)) {
if (get_transporter_capacity(punit) > 0) {
ptptother = punit;
} else if (!panyother) {
@@ -1261,8 +1261,8 @@
refresh_tile_mapcanvas(x, y, FALSE);
if(game.player_idx==punit->owner && punit->activity!=ACTIVITY_GOTO &&
- auto_center_on_unit && punit->activity!=ACTIVITY_SENTRY &&
- !tile_visible_and_not_on_border_mapcanvas(pinfo->x, pinfo->y))
+ auto_center_on_unit && punit->activity!=ACTIVITY_SENTRY && !pinfo->carried
+ && !tile_visible_and_not_on_border_mapcanvas(pinfo->x, pinfo->y))
center_tile_mapcanvas(pinfo->x, pinfo->y);
if(!pinfo->carried && !was_teleported) {
@@ -1280,19 +1280,25 @@
punit->hp=pinfo->hp;
unit_list_insert(&map_get_tile(punit->x, punit->y)->units, punit);
- square_iterate(punit->x, punit->y, 2, x, y) {
- bool refresh = FALSE;
- unit_list_iterate(map_get_tile(x, y)->units, pu) {
- if (unit_flag(pu, F_PARTIAL_INVIS)) {
- refresh = TRUE;
- goto out;
+ /* transported units can't search subs */
+ if (!pinfo->carried) {
+ square_iterate(punit->x, punit->y, 2, x, y) {
+ bool refresh = FALSE;
+ if (x == punit->x && y == punit->y) {
+ continue;
}
- } unit_list_iterate_end;
- out:
- if (refresh) {
- refresh_tile_mapcanvas(x, y, FALSE);
- }
- } square_iterate_end;
+ unit_list_iterate(map_get_tile(x, y)->units, pu) {
+ if (unit_flag(pu, F_PARTIAL_INVIS)) {
+ refresh = TRUE;
+ goto out;
+ }
+ } unit_list_iterate_end;
+ out:
+ if (refresh) {
+ refresh_tile_mapcanvas(x, y, FALSE);
+ }
+ } square_iterate_end;
+ }
if(!pinfo->carried && tile_get_known(punit->x,punit->y) == TILE_KNOWN)
refresh_tile_mapcanvas(punit->x, punit->y, FALSE);
diff -u -r freeciv/client/packhand.c fc3/client/packhand.c
--- freeciv/client/packhand.c 2003-08-19 23:29:51.000000000 +0200
+++ fc3/client/packhand.c 2003-09-01 20:00:07.000000000 +0200
@@ -106,6 +106,11 @@
clear_goto_dest(punit);
}
punit->activity_target = packet->activity_target;
+ if (packet->carried) {
+ punit->transported_by = packet->transported_by;
+ } else {
+ punit->transported_by = -1;
+ }
punit->paradropped = packet->paradropped;
punit->connecting = packet->connecting;
@@ -890,6 +895,11 @@
if(punit) {
int dest_x,dest_y;
punit->activity_count = packet->activity_count;
+ if (packet->carried) {
+ punit->transported_by = packet->transported_by;
+ } else {
+ punit->transported_by = -1;
+ }
if (punit->ai.control!=packet->ai) {
punit->ai.control = packet->ai;
repaint_unit = TRUE;
@@ -1083,7 +1093,7 @@
dest_x = packet->x;
dest_y = packet->y;
/*fog of war*/
- if (!(tile_get_known(punit->x,punit->y) == TILE_KNOWN)) {
+ if (!packet->carried && !(tile_get_known(punit->x,punit->y) ==
TILE_KNOWN)) {
client_remove_unit(punit);
refresh_tile_mapcanvas(dest_x, dest_y, FALSE);
}
diff -u -r freeciv/common/packets.c fc3/common/packets.c
--- freeciv/common/packets.c 2003-08-07 22:49:19.000000000 +0200
+++ fc3/common/packets.c 2003-09-01 14:32:39.000000000 +0200
@@ -1287,6 +1287,7 @@
dio_put_uint8(&dout, req->goto_dest_x);
dio_put_uint8(&dout, req->goto_dest_y);
dio_put_uint16(&dout, req->activity_target);
+ dio_put_uint16(&dout, req->transported_by);
dio_put_uint8(&dout, req->packet_use);
dio_put_uint16(&dout, req->info_city_id);
dio_put_uint16(&dout, req->serial_num);
@@ -1569,6 +1570,7 @@
dio_get_uint8(&din, &packet->goto_dest_x);
dio_get_uint8(&din, &packet->goto_dest_y);
dio_get_uint16(&din, (int *) &packet->activity_target);
+ dio_get_uint16(&din, &packet->transported_by);
dio_get_uint8(&din, &packet->packet_use);
dio_get_uint16(&din, &packet->info_city_id);
dio_get_uint16(&din, &packet->serial_num);
diff -u -r freeciv/common/packets.h fc3/common/packets.h
--- freeciv/common/packets.h 2003-08-05 09:49:28.000000000 +0200
+++ fc3/common/packets.h 2003-09-01 14:32:54.000000000 +0200
@@ -321,6 +321,7 @@
int fuel;
int goto_dest_x, goto_dest_y;
enum tile_special_type activity_target;
+ int transported_by;
bool paradropped;
bool connecting;
/* in packet only, not in unit struct */
diff -u -r freeciv/server/unithand.c fc3/server/unithand.c
--- freeciv/server/unithand.c 2003-08-26 18:26:49.000000000 +0200
+++ fc3/server/unithand.c 2003-09-01 22:46:56.000000000 +0200
@@ -1418,8 +1418,8 @@
free(punit->pgr);
punit->pgr = NULL;
}
- send_unit_info(NULL, punit);
handle_unit_activity_dependencies(punit, old_activity, old_target);
+ send_unit_info(NULL, punit);
}
}
@@ -1462,7 +1462,7 @@
}
unit_list_iterate(map_get_tile(punit->x, punit->y)->units, punit2) {
- if (punit != punit2 && punit2->activity == ACTIVITY_SENTRY) {
+ if (punit != punit2 && punit2->transported_by == punit->id) {
bool wakeup = FALSE;
if (is_ground_units_transport(punit)) {
@@ -1470,12 +1470,12 @@
wakeup = TRUE;
}
- if (unit_flag(punit, F_MISSILE_CARRIER)) {
+ if (!wakeup && unit_flag(punit, F_MISSILE_CARRIER)) {
if (unit_flag(punit2, F_MISSILE))
wakeup = TRUE;
}
- if (unit_flag(punit, F_CARRIER)) {
+ if (!wakeup && unit_flag(punit, F_CARRIER)) {
if (is_air_unit(punit2))
wakeup = TRUE;
}
diff -u -r freeciv/server/unittools.c fc3/server/unittools.c
--- freeciv/server/unittools.c 2003-09-03 09:51:41.288924008 +0200
+++ fc3/server/unittools.c 2003-09-01 22:31:22.000000000 +0200
@@ -1819,6 +1819,7 @@
assert(!is_normal_map_pos(255, 255));
}
packet->activity_target = punit->activity_target;
+ packet->transported_by = punit->transported_by;
packet->paradropped = punit->paradropped;
packet->connecting = punit->connecting;
packet->carried = carried;
@@ -1846,12 +1847,14 @@
conn_list_iterate(*dest, pconn) {
struct player *pplayer = pconn->player;
+ bool see_unit = (!carried || (carried && ((unit_owner(punit) == pplayer)
+ || gives_shared_vision(unit_owner(punit), pplayer))));
bool see_pos =
- can_player_see_unit_at(pplayer, punit, punit->x, punit->y);
+ see_unit && 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);
+ see_xy = see_unit && can_player_see_unit_at(pplayer, punit, x, y);
}
if ((!pplayer && pconn->observer) || see_pos || see_xy) {
send_packet_unit_info(pconn, &info);
@@ -1868,7 +1871,8 @@
{
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,
+ (punit->transported_by != -1));
}
/**************************************************************************
@@ -1891,7 +1895,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, (punit->transported_by != -1));
}
}
unit_list_iterate_end;
@@ -1902,11 +1906,6 @@
flush_packets();
}
-
-
-
-
-
/**************************************************************************
For all units which are transported by the given unit and that are
currently idle, sentry them.
@@ -2314,6 +2313,42 @@
}
/**************************************************************************
+ This happend when unit enter to transport and for all players
+ (without shared vision) this unit should be hiddend in transport unit.
+**************************************************************************/
+static void put_unit_to_transport(struct unit *punit, struct unit *ptrans)
+{
+ struct packet_generic_integer packet;
+ struct player *punit_owner = unit_owner(punit);
+ struct player *ptrans_owner = unit_owner(ptrans);
+ struct packet_unit_info info;
+
+ /* set to transport */
+ punit->transported_by = ptrans->id;
+ set_unit_activity(punit, ACTIVITY_SENTRY);
+
+ package_unit(punit, &info, TRUE,
+ UNIT_INFO_IDENTITY, FALSE, FALSE);
+ packet.value = punit->id;
+
+ /* update clients info */
+ conn_list_iterate(game.game_connections, pconn) {
+ struct player *pplayer = pconn->player;
+ if ((!pplayer && pconn->observer) || (pplayer
+ && (punit_owner == pplayer || ptrans_owner == pplayer
+ || gives_shared_vision(punit_owner, pplayer)
+ || gives_shared_vision(ptrans_owner, pplayer)))) {
+ send_packet_unit_info(pconn, &info);
+ } else {
+ if (pplayer
+ && can_player_see_unit_at(pplayer, punit, punit->x, punit->y)) {
+ send_packet_generic_integer(pconn, PACKET_REMOVE_UNIT, &packet);
+ }
+ }
+ } conn_list_iterate_end;
+}
+
+/**************************************************************************
Assigns units on ptrans' tile to ptrans if they should be. This is done
by setting their transported_by fields to the id of ptrans.
@@ -2380,7 +2415,7 @@
&& (pcargo->owner == playerid
|| pplayers_allied(unit_owner(pcargo), unit_owner(ptrans))))
{
capacity--;
- pcargo->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo, ptrans);
}
} unit_list_iterate_end;
}
@@ -2407,7 +2442,7 @@
} unit_list_iterate_end;
if (!has_trans) {
capacity--;
- pcargo->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo, ptrans);
}
}
} unit_list_iterate_end;
@@ -2464,7 +2499,7 @@
} unit_list_iterate_end;
if (!has_trans) {
capacity--;
- pcargo->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo, ptrans);
}
}
} unit_list_iterate_end;
@@ -2488,7 +2523,7 @@
&& (pcargo->owner == playerid
|| pplayers_allied(unit_owner(pcargo),
unit_owner(ptrans)))) {
capacity--;
- pcargo->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo, ptrans);
}
} unit_list_iterate_end;
}
@@ -2505,7 +2540,7 @@
&& (pcargo->owner == playerid
|| pplayers_allied(unit_owner(pcargo), unit_owner(ptrans))))
{
capacity--;
- pcargo->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo, ptrans);
}
} unit_list_iterate_end;
}
@@ -2546,7 +2581,7 @@
&& (pcargo2->owner == playerid
|| pplayers_allied(unit_owner(pcargo2), unit_owner(ptrans)))
&& pcargo2 != ptrans) {
- pcargo2->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo2, ptrans);
totcap--;
} else
pcargo2->transported_by = -1;
@@ -2562,7 +2597,7 @@
&& (pcargo2->owner == playerid
|| pplayers_allied(unit_owner(pcargo2), unit_owner(ptrans)))
&& pcargo2->transported_by != ptrans->id) {
- pcargo2->transported_by = ptrans->id;
+ put_unit_to_transport(pcargo2, ptrans);
totcap--;
}
} unit_list_iterate_end;
@@ -2624,6 +2659,26 @@
}
/**************************************************************************
+ Find freandly transport and assign unit to them.
+ **************************************************************************/
+bool handle_unit_enter_transport(struct unit *punit, struct tile *pdst_tile)
+{
+ if (!pdst_tile->city && is_ocean(pdst_tile->terrain) && is_ground_unit(punit)
+ && punit->transported_by == -1) {
+ struct player *pplayer = unit_owner(punit);
+ unit_list_iterate(pdst_tile->units, ptrans) {
+ if (punit->id != ptrans->id && is_ground_units_transport(ptrans)
+ && pplayers_allied(pplayer, unit_owner(ptrans))
+ && get_transporter_capacity(ptrans)) {
+ put_unit_to_transport(punit, ptrans);
+ return TRUE;
+ }
+ } unit_list_iterate_end;
+ }
+ return FALSE;
+}
+
+/**************************************************************************
Does: 1) updates the units homecity and the city it enters/leaves (the
cities happiness varies). This also takes into account if the
unit enters/leaves a fortress.
@@ -2637,18 +2692,22 @@
int dest_x, int dest_y)
{
struct city *fromcity = map_get_city(src_x, src_y);
- struct city *tocity = map_get_city(dest_x, dest_y);
+ struct tile *dst_tile = map_get_tile(dest_x, dest_y);
+ struct city *tocity = dst_tile->city;
struct city *homecity = NULL;
struct player *pplayer = unit_owner(punit);
/* struct government *g = get_gov_pplayer(pplayer);*/
bool senthome = FALSE;
+ if (tocity) {
+ handle_unit_enter_city(punit, tocity);
+ } else {
+ handle_unit_enter_transport(punit, dst_tile);
+ }
+
if (punit->homecity != 0)
homecity = find_city_by_id(punit->homecity);
-
- if (tocity)
- handle_unit_enter_city(punit, tocity);
-
+
/* We only do this for non-AI players to now make sure the AI turns
doesn't take too long. Perhaps we should make a special refresh_city
functions that only refreshed happiness. */
@@ -2684,7 +2743,7 @@
}
/* entering/leaving a fortress */
- if (map_has_special(dest_x, dest_y, S_FORTRESS)
+ if (tile_has_special(dst_tile, S_FORTRESS)
&& homecity
&& is_friendly_city_near(unit_owner(punit), dest_x, dest_y)
&& !senthome) {
diff -u -r freeciv/server/unittools.h fc3/server/unittools.h
--- freeciv/server/unittools.h 2003-08-26 18:26:49.000000000 +0200
+++ fc3/server/unittools.h 2003-09-01 22:23:38.000000000 +0200
@@ -71,7 +71,6 @@
int x, int y, bool carried);
void send_all_known_units(struct conn_list *dest);
-
/* doing a unit activity */
void do_nuclear_explosion(struct player *pplayer, int x, int y);
bool try_move_unit(struct unit *punit, int dest_x, int dest_y);
@@ -81,5 +80,6 @@
bool move_unit(struct unit *punit, int dest_x, int dest_y,
bool transport_units, bool take_from_land, int move_cost);
enum goto_result goto_route_execute(struct unit *punit);
-
+bool handle_unit_enter_transport(struct unit *punit, struct tile *pdst_tile);
+
#endif /* FC__UNITTOOLS_H */
- [Freeciv-Dev] (PR#5789) Don't send info about transported units to clients without shared vision.,
Rafa³ Bursig <=
|
|