Author: cazfi Date: Wed Dec 16 23:57:52 2015 New Revision: 31032 URL: http://svn.gna.org/viewcvs/freeciv?rev=31032&view=rev Log: Remove third party units seen in allied cities from the client when the alliance gets cancelled.
See bug #24169 Modified: branches/S2_5/server/diplhand.c branches/S2_5/server/plrhand.c branches/S2_5/server/unittools.c branches/S2_5/server/unittools.h Modified: branches/S2_5/server/diplhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/diplhand.c?rev=31032&r1=31031&r2=31032&view=diff ============================================================================== --- branches/S2_5/server/diplhand.c (original) +++ branches/S2_5/server/diplhand.c Wed Dec 16 23:57:52 2015 @@ -515,8 +515,8 @@ } case CLAUSE_CEASEFIRE: if (old_diplstate == DS_ALLIANCE) { - pgiver_seen_units = get_seen_units(pgiver, pdest); - pdest_seen_units = get_seen_units(pdest, pgiver); + pgiver_seen_units = get_units_seen_via_ally(pgiver, pdest); + pdest_seen_units = get_units_seen_via_ally(pdest, pgiver); } ds_giverdest->type = DS_CEASEFIRE; ds_giverdest->turns_left = TURNS_LEFT; @@ -540,8 +540,8 @@ break; case CLAUSE_PEACE: if (old_diplstate == DS_ALLIANCE) { - pgiver_seen_units = get_seen_units(pgiver, pdest); - pdest_seen_units = get_seen_units(pdest, pgiver); + pgiver_seen_units = get_units_seen_via_ally(pgiver, pdest); + pdest_seen_units = get_units_seen_via_ally(pdest, pgiver); } ds_giverdest->type = DS_ARMISTICE; ds_destgiver->type = DS_ARMISTICE; Modified: branches/S2_5/server/plrhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/plrhand.c?rev=31032&r1=31031&r2=31032&view=diff ============================================================================== --- branches/S2_5/server/plrhand.c (original) +++ branches/S2_5/server/plrhand.c Wed Dec 16 23:57:52 2015 @@ -648,8 +648,8 @@ ds_plr2plr = player_diplstate_get(pplayer2, pplayer); if (old_type == DS_ALLIANCE) { - pplayer_seen_units = get_seen_units(pplayer, pplayer2); - pplayer2_seen_units = get_seen_units(pplayer2, pplayer); + pplayer_seen_units = get_units_seen_via_ally(pplayer, pplayer2); + pplayer2_seen_units = get_units_seen_via_ally(pplayer2, pplayer); } /* do the change */ Modified: branches/S2_5/server/unittools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.c?rev=31032&r1=31031&r2=31032&view=diff ============================================================================== --- branches/S2_5/server/unittools.c (original) +++ branches/S2_5/server/unittools.c Wed Dec 16 23:57:52 2015 @@ -1350,20 +1350,34 @@ } /**************************************************************************** - Returns the list of the units owned by 'aplayer' seen by 'pplayer'. The - returned pointer is newly allocated and should be freed by the caller, - using unit_list_destroy(). + Returns the list of the units seen by 'pplayer' potentially seen only + thanks to an alliance with 'aplayer'. The returned pointer is newly + allocated and should be freed by the caller, using unit_list_destroy(). ****************************************************************************/ -struct unit_list *get_seen_units(const struct player *pplayer, - const struct player *aplayer) +struct unit_list *get_units_seen_via_ally(const struct player *pplayer, + const struct player *aplayer) { struct unit_list *seen_units = unit_list_new(); + /* Anybody's units inside ally's cities */ + city_list_iterate(aplayer->cities, pcity) { + unit_list_iterate(city_tile(pcity)->units, punit) { + if (can_player_see_unit(pplayer, punit)) { + unit_list_append(seen_units, punit); + } + } unit_list_iterate_end; + } city_list_iterate_end; + + /* Ally's own units inside transports */ unit_list_iterate(aplayer->units, punit) { - if (can_player_see_unit(pplayer, punit)) { + if (unit_transported(punit) && can_player_see_unit(pplayer, punit)) { unit_list_append(seen_units, punit); } } unit_list_iterate_end; + + /* Make sure the same unit is not added in multiple phases + * (unit within transport in a city) */ + unit_list_unique(seen_units); return seen_units; } Modified: branches/S2_5/server/unittools.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.h?rev=31032&r1=31031&r2=31032&view=diff ============================================================================== --- branches/S2_5/server/unittools.h (original) +++ branches/S2_5/server/unittools.h Wed Dec 16 23:57:52 2015 @@ -99,8 +99,8 @@ bool verbose); void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose); -struct unit_list *get_seen_units(const struct player *pplayer, - const struct player *aplayer); +struct unit_list *get_units_seen_via_ally(const struct player *pplayer, + const struct player *aplayer); void remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units); void give_allied_visibility(struct player *pplayer, struct player *aplayer); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits