Author: cazfi Date: Mon Dec 21 11:03:08 2015 New Revision: 31137 URL: http://svn.gna.org/viewcvs/freeciv?rev=31137&view=rev Log: Avoid temporary complete removal of border source when city size reduces and border radius might change.
See bug #24194 Modified: branches/S2_6/server/citytools.c branches/S2_6/server/cityturn.c branches/S2_6/server/maphand.c branches/S2_6/server/maphand.h Modified: branches/S2_6/server/citytools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/citytools.c?rev=31137&r1=31136&r2=31137&view=diff ============================================================================== --- branches/S2_6/server/citytools.c (original) +++ branches/S2_6/server/citytools.c Mon Dec 21 11:03:08 2015 @@ -1258,7 +1258,7 @@ * This could leave a border ring around the city, updated later by * map_calculate_borders() at the next turn. */ - map_claim_border(pcenter, ptaker); + map_claim_border(pcenter, ptaker, -1); /* city_thaw_workers_queue() later */ auto_arrange_workers(pcity); /* does city_map_update_all() */ @@ -1510,7 +1510,7 @@ /* This is dependent on the current vision, so must be done after * vision is prepared and before arranging workers. */ - map_claim_border(ptile, pplayer); + map_claim_border(ptile, pplayer, -1); /* city_thaw_workers_queue() later */ /* Refresh the city. First a city refresh is done (this shouldn't Modified: branches/S2_6/server/cityturn.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/cityturn.c?rev=31137&r1=31136&r2=31137&view=diff ============================================================================== --- branches/S2_6/server/cityturn.c (original) +++ branches/S2_6/server/cityturn.c Mon Dec 21 11:03:08 2015 @@ -33,6 +33,7 @@ /* common */ #include "achievements.h" +#include "borders.h" #include "calendar.h" #include "citizens.h" #include "city.h" @@ -677,6 +678,7 @@ struct player *destroyer) { citizens loss_remain; + int old_radius_sq; if (pop_loss == 0) { return TRUE; @@ -692,9 +694,10 @@ remove_city(pcity); return FALSE; } - map_clear_border(pcity->tile); + old_radius_sq = tile_border_source_radius_sq(pcity->tile); city_size_add(pcity, -pop_loss); - map_claim_border(pcity->tile, pcity->owner); + map_update_border(pcity->tile, pcity->owner, old_radius_sq, + tile_border_source_radius_sq(pcity->tile)); /* Cap the food stock at the new granary size. */ if (pcity->food_stock > city_granary_size(city_size_get(pcity))) { @@ -910,7 +913,7 @@ return city_reduce_size(pcity, city_size_get(pcity) - size, NULL); } - map_claim_border(pcity->tile, pcity->owner); + map_claim_border(pcity->tile, pcity->owner, -1); return TRUE; } @@ -935,7 +938,7 @@ pcity->food_stock = MIN(pcity->food_stock, granary_size); } else { city_increase_size(pcity, nationality); - map_claim_border(pcity->tile, pcity->owner); + map_claim_border(pcity->tile, pcity->owner, -1); } } else if (pcity->food_stock < 0) { /* FIXME: should this depend on units with ability to build Modified: branches/S2_6/server/maphand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/maphand.c?rev=31137&r1=31136&r2=31137&view=diff ============================================================================== --- branches/S2_6/server/maphand.c (original) +++ branches/S2_6/server/maphand.c Mon Dec 21 11:03:08 2015 @@ -1964,12 +1964,44 @@ } /************************************************************************* + Update borders for this source. Changes the radius without temporary + clearing. +*************************************************************************/ +void map_update_border(struct tile *ptile, struct player *owner, + int old_radius_sq, int new_radius_sq) +{ + if (old_radius_sq == new_radius_sq) { + /* No change */ + return; + } + + if (BORDERS_DISABLED == game.info.borders) { + return; + } + + if (old_radius_sq < new_radius_sq) { + map_claim_border(ptile, owner, new_radius_sq); + } else { + circle_dxyr_iterate(ptile, old_radius_sq, dtile, dx, dy, dr) { + if (dr > new_radius_sq) { + struct tile *claimer = tile_claimer(dtile); + + if (claimer == ptile) { + map_claim_ownership(dtile, NULL, NULL, FALSE); + } + } + } circle_dxyr_iterate_end; + } +} + +/************************************************************************* Update borders for this source. Call this for each new source. + + If radius_sq is -1, get value from the border source on tile. *************************************************************************/ -void map_claim_border(struct tile *ptile, struct player *owner) -{ - int radius_sq = tile_border_source_radius_sq(ptile); - +void map_claim_border(struct tile *ptile, struct player *owner, + int radius_sq) +{ if (BORDERS_DISABLED == game.info.borders) { return; } @@ -1982,8 +2014,17 @@ return; } + if (radius_sq < 0) { + radius_sq = tile_border_source_radius_sq(ptile); + } + circle_dxyr_iterate(ptile, radius_sq, dtile, dx, dy, dr) { struct tile *dclaimer = tile_claimer(dtile); + + if (dclaimer == ptile) { + /* Already claimed by the ptile */ + continue; + } if (dr != 0 && is_border_source(dtile)) { /* Do not claim border sources other than self */ @@ -2060,7 +2101,7 @@ whole_map_iterate(ptile) { if (is_border_source(ptile)) { - map_claim_border(ptile, ptile->owner); + map_claim_border(ptile, ptile->owner, -1); } } whole_map_iterate_end; @@ -2116,7 +2157,7 @@ * ploser == powner and above check will abort the recursion. */ if (powner != NULL) { map_claim_border_ownership(ptile, powner, ptile); - map_claim_border(ptile, powner); + map_claim_border(ptile, powner, -1); } city_thaw_workers_queue(); city_refresh_queue_processing(); Modified: branches/S2_6/server/maphand.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/maphand.h?rev=31137&r1=31136&r2=31137&view=diff ============================================================================== --- branches/S2_6/server/maphand.h (original) +++ branches/S2_6/server/maphand.h Mon Dec 21 11:03:08 2015 @@ -104,10 +104,13 @@ void disable_fog_of_war_player(struct player *pplayer); void map_calculate_borders(void); -void map_claim_border(struct tile *ptile, struct player *powner); +void map_claim_border(struct tile *ptile, struct player *powner, + int radius_sq); void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases); void map_clear_border(struct tile *ptile); +void map_update_border(struct tile *ptile, struct player *owner, + int old_radius_sq, int new_radius_sq); void tile_claim_bases(struct tile *ptile, struct player *powner); void map_claim_base(struct tile *ptile, struct base_type *pbase, _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits