Author: pepeto Date: Fri Oct 24 18:29:18 2014 New Revision: 26846 URL: http://svn.gna.org/viewcvs/freeciv?rev=26846&view=rev Log: Make transfer_city() hides/reveals units for players. Removed similar but incomplete code in unit_enter_city().
>From a report by Marko Lindqvist <cazfi> See gna bug #20705 Modified: trunk/server/citytools.c Modified: trunk/server/citytools.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=26846&r1=26845&r2=26846&view=diff ============================================================================== --- trunk/server/citytools.c (original) +++ trunk/server/citytools.c Fri Oct 24 18:29:18 2014 @@ -977,8 +977,27 @@ const citizens old_giver_content_citizens = player_content_citizens(pgiver); bool taker_had_no_cities = (city_list_size(ptaker->cities) == 0); bool new_extras; + const int units_num = unit_list_size(pcenter->units); + bv_player *could_see_unit = (units_num > 0 + ? fc_malloc(sizeof(*could_see_unit) + * units_num) + : NULL); + int i; fc_assert_ret_val(pgiver != ptaker, TRUE); + + /* Remember what player see what unit. */ + i = 0; + unit_list_iterate(pcenter->units, aunit) { + BV_CLR_ALL(could_see_unit[i]); + players_iterate(aplayer) { + if (can_player_see_unit(aplayer, aunit)) { + BV_SET(could_see_unit[i], player_index(aplayer)); + } + } players_iterate_end; + i++; + } unit_list_iterate_end; + fc_assert(i == units_num); /* Remove AI control of the old owner. */ CALL_PLR_AI_FUNC(city_lost, pcity->owner, pcity->owner, pcity); @@ -1050,6 +1069,29 @@ pcity->owner = ptaker; map_claim_ownership(pcenter, ptaker, pcenter, TRUE); city_list_prepend(ptaker->cities, pcity); + + /* Hide/reveal units. Do it after vision have been given to taker, city + * owner has been changed, and before any script could be spawned. */ + i = 0; + unit_list_iterate(pcenter->units, aunit) { + players_iterate(aplayer) { + if (can_player_see_unit(aplayer, aunit)) { + if (!BV_ISSET(could_see_unit[i], player_index(aplayer))) { + /* Reveal 'aunit'. */ + send_unit_info(aplayer->connections, aunit); + } + } else { + if (BV_ISSET(could_see_unit[i], player_index(aplayer))) { + /* Hide 'aunit'. */ + unit_goes_out_of_sight(aplayer, aunit); + } + } + } players_iterate_end; + i++; + } unit_list_iterate_end; + fc_assert(i == units_num); + free(could_see_unit); + could_see_unit = NULL; transfer_city_units(ptaker, pgiver, old_city_units, pcity, NULL, @@ -1695,7 +1737,6 @@ int coins; struct player *pplayer = unit_owner(punit); struct player *cplayer = city_owner(pcity); - bv_player saw_entering; /* If not at war, may peacefully enter city. Or, if we cannot occupy * the city, this unit entering will not trigger the effects below. */ @@ -1711,15 +1752,6 @@ - Kris Bubendorfer Also check spaceships --dwp */ - - /* Store information who saw unit entering city. - * This means old owner + allies + shared vision */ - BV_CLR_ALL(saw_entering); - players_iterate(pplayer) { - if (map_is_known_and_seen(pcity->tile, pplayer, V_MAIN)) { - BV_SET(saw_entering, player_index(pplayer)); - } - } players_iterate_end; if (is_capital(pcity) && (cplayer->spaceship.state == SSHIP_STARTED @@ -1835,22 +1867,6 @@ !is_barbarian(pplayer)); if (city_remains) { - /* After city has been transferred, some players may no longer see - * inside. */ - players_iterate(pplayer) { - if (BV_ISSET(saw_entering, player_index(pplayer)) - && !can_player_see_unit(pplayer, punit)) { - /* Player saw unit entering, but now unit is hiding inside city */ - unit_goes_out_of_sight(pplayer, punit); - } else if (!BV_ISSET(saw_entering, player_index(pplayer)) - && can_player_see_unit(pplayer, punit)) { - /* Player sees inside cities of new owner */ - send_unit_info(pplayer->connections, punit); - } - } players_iterate_end; - } - - if (city_remains) { /* reduce size should not destroy this city */ fc_assert(city_size_get(pcity) > 1); city_reduce_size(pcity, 1, pplayer); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits