Author: cazfi Date: Tue Nov 10 21:39:05 2015 New Revision: 30514 URL: http://svn.gna.org/viewcvs/freeciv?rev=30514&view=rev Log: Made is_native_to_class() to take extras parameter as an pointer.
See patch #6552 Modified: branches/S2_6/client/editor.c branches/S2_6/client/gui-gtk-2.0/editprop.c branches/S2_6/client/gui-gtk-3.0/editprop.c branches/S2_6/client/helpdata.c branches/S2_6/client/tilespec.c branches/S2_6/common/movement.c branches/S2_6/common/movement.h branches/S2_6/common/tile.c branches/S2_6/common/tile.h branches/S2_6/common/unittype.c branches/S2_6/server/advisors/advruleset.c branches/S2_6/server/generator/mapgen.c branches/S2_6/server/rssanity.c branches/S2_6/server/unittools.c Modified: branches/S2_6/client/editor.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/editor.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/client/editor.c (original) +++ branches/S2_6/client/editor.c Tue Nov 10 21:39:05 2015 @@ -1588,7 +1588,7 @@ return; } packet->tile = tile_index(ptile); - packet->extras = tile_extras(ptile); + packet->extras = *tile_extras(ptile); presource = tile_resource(ptile); packet->resource = presource Modified: branches/S2_6/client/gui-gtk-2.0/editprop.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/editprop.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-2.0/editprop.c (original) +++ branches/S2_6/client/gui-gtk-2.0/editprop.c Tue Nov 10 21:39:05 2015 @@ -2204,7 +2204,7 @@ } packet->tile = tile_index(ptile); - packet->extras = tile_extras(ptile); + packet->extras = *tile_extras(ptile); /* TODO: Set more packet fields. */ } return; Modified: branches/S2_6/client/gui-gtk-3.0/editprop.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/editprop.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/client/gui-gtk-3.0/editprop.c (original) +++ branches/S2_6/client/gui-gtk-3.0/editprop.c Tue Nov 10 21:39:05 2015 @@ -2204,7 +2204,7 @@ } packet->tile = tile_index(ptile); - packet->extras = tile_extras(ptile); + packet->extras = *tile_extras(ptile); /* TODO: Set more packet fields. */ } return; Modified: branches/S2_6/client/helpdata.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/helpdata.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/client/helpdata.c (original) +++ branches/S2_6/client/helpdata.c Tue Nov 10 21:39:05 2015 @@ -4544,12 +4544,9 @@ { const char *classes[uclass_count()]; int i = 0; - bv_extras extras; - - BV_CLR_ALL(extras); unit_class_iterate(uclass) { - if (is_native_to_class(uclass, pterrain, extras)) { + if (is_native_to_class(uclass, pterrain, NULL)) { classes[i++] = uclass_name_translation(uclass); } } unit_class_iterate_end; Modified: branches/S2_6/client/tilespec.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/tilespec.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/client/tilespec.c (original) +++ branches/S2_6/client/tilespec.c Tue Nov 10 21:39:05 2015 @@ -3832,7 +3832,7 @@ if (NULL != terrain1) { tterrain_near[dir] = terrain1; - textras_near[dir] = tile_extras(tile1); + textras_near[dir] = *tile_extras(tile1); continue; } log_error("build_tile_data() tile (%d,%d) has no terrain!", @@ -5095,7 +5095,7 @@ } if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) { - textras = tile_extras(ptile); + textras = *tile_extras(ptile); pterrain = tile_terrain(ptile); if (NULL != pterrain) { Modified: branches/S2_6/common/movement.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/movement.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/common/movement.c (original) +++ branches/S2_6/common/movement.c Tue Nov 10 21:39:05 2015 @@ -102,10 +102,7 @@ int utype_unknown_move_cost(const struct unit_type *utype) { const struct unit_class *uclass = utype_class(utype); - bv_extras extras; int move_cost; - - BV_CLR_ALL(extras); if (!uclass_has_flag(uclass, UCF_TERRAIN_SPEED)) { /* Unit is not subject to terrain movement costs. */ @@ -117,7 +114,7 @@ /* Unit is subject to terrain movement costs. */ move_cost = 1; /* Arbitrary minimum. */ terrain_type_iterate(pterrain) { - if (is_native_to_class(uclass, pterrain, extras) + if (is_native_to_class(uclass, pterrain, NULL) && pterrain->movement_cost > move_cost) { /* Exact movement cost matters only if we can enter * the tile. */ @@ -132,7 +129,7 @@ * N.B.: We don't take in account terrain no unit can enter here. */ terrain_type_iterate(pterrain) { if (BV_ISSET_ANY(pterrain->native_to) - && !is_native_to_class(uclass, pterrain, extras)) { + && !is_native_to_class(uclass, pterrain, NULL)) { /* Units that may encounter unsuitable terrain explore less. */ move_cost *= 2; break; @@ -292,7 +289,7 @@ ****************************************************************************/ bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, - bv_extras extras) + const bv_extras *extras) { if (!pterrain) { /* Unknown is considered native terrain */ @@ -303,11 +300,13 @@ return TRUE; } - extra_type_list_iterate(punitclass->cache.native_tile_extras, pextra) { - if (BV_ISSET(extras, extra_index(pextra))) { - return TRUE; - } - } extra_type_list_iterate_end; + if (extras != NULL) { + extra_type_list_iterate(punitclass->cache.native_tile_extras, pextra) { + if (BV_ISSET(*extras, extra_index(pextra))) { + return TRUE; + } + } extra_type_list_iterate_end; + } return FALSE; } @@ -324,16 +323,14 @@ const struct tile *dst_tile) { const struct road_type *proad; - bv_extras none; - - BV_CLR_ALL(none); - if (is_native_to_class(punitclass, tile_terrain(dst_tile), none)) { + + if (is_native_to_class(punitclass, tile_terrain(dst_tile), NULL)) { /* We aren't using extras to make the destination native. */ return TRUE; } else if (!is_native_tile_to_class(punitclass, src_tile)) { /* Disembarking or leaving port, so ignore road connectivity. */ return TRUE; - } else if (is_native_to_class(punitclass, tile_terrain(src_tile), none)) { + } else if (is_native_to_class(punitclass, tile_terrain(src_tile), NULL)) { /* Native source terrain depends entirely on destination tile nativity. */ return is_native_tile_to_class(punitclass, dst_tile); } Modified: branches/S2_6/common/movement.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/movement.h?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/common/movement.h (original) +++ branches/S2_6/common/movement.h Tue Nov 10 21:39:05 2015 @@ -68,7 +68,7 @@ const struct tile *ptile); bool is_native_to_class(const struct unit_class *punitclass, const struct terrain *pterrain, - bv_extras extras); + const bv_extras *extras); bool is_native_move(const struct unit_class *punitclass, const struct tile *src_tile, const struct tile *dst_tile); Modified: branches/S2_6/common/tile.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/tile.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/common/tile.c (original) +++ branches/S2_6/common/tile.c Tue Nov 10 21:39:05 2015 @@ -30,6 +30,8 @@ #include "unitlist.h" #include "tile.h" + +static bv_extras empty_extras; #ifndef tile_index /**************************************************************************** @@ -150,16 +152,20 @@ /**************************************************************************** Returns a bit vector of the extras present at the tile. ****************************************************************************/ -bv_extras tile_extras(const struct tile *ptile) +const bv_extras *tile_extras(const struct tile *ptile) { if (!ptile) { - bv_extras empty; - - BV_CLR_ALL(empty); - return empty; - } - - return ptile->extras; + static bool empty_cleared = FALSE; + + if (!empty_cleared) { + BV_CLR_ALL(empty_extras); + empty_cleared = TRUE; + } + + return &(empty_extras); + } + + return &(ptile->extras); } /**************************************************************************** Modified: branches/S2_6/common/tile.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/tile.h?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/common/tile.h (original) +++ branches/S2_6/common/tile.h Tue Nov 10 21:39:05 2015 @@ -108,7 +108,7 @@ /* struct city *tile_worked(const struct tile *ptile); */ void tile_set_worked(struct tile *ptile, struct city *pcity); -bv_extras tile_extras(const struct tile *ptile); +const bv_extras *tile_extras(const struct tile *ptile); void tile_set_bases(struct tile *ptile, bv_bases bases); bool tile_has_base(const struct tile *ptile, const struct base_type *pbase); void tile_add_base(struct tile *ptile, const struct base_type *pbase); Modified: branches/S2_6/common/unittype.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/common/unittype.c (original) +++ branches/S2_6/common/unittype.c Tue Nov 10 21:39:05 2015 @@ -1874,11 +1874,7 @@ } extra_type_iterate_end; terrain_type_iterate(pterrain) { - bv_extras extras; - - BV_CLR_ALL(extras); - - if (is_native_to_class(puclass, pterrain, extras)) { + if (is_native_to_class(puclass, pterrain, NULL)) { if (is_ocean(pterrain)) { sea_moving = TRUE; } else { Modified: branches/S2_6/server/advisors/advruleset.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/advruleset.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/server/advisors/advruleset.c (original) +++ branches/S2_6/server/advisors/advruleset.c Tue Nov 10 21:39:05 2015 @@ -28,10 +28,6 @@ **************************************************************************/ void adv_units_ruleset_init(void) { - bv_extras extras; - - BV_CLR_ALL(extras); /* Can it move even without road */ - unit_class_iterate(pclass) { bool move_land_enabled = FALSE; /* Can move at some land terrains */ bool move_land_disabled = FALSE; /* Cannot move at some land terrains */ @@ -39,7 +35,7 @@ bool move_sea_disabled = FALSE; /* Cannot move at some ocean terrains */ terrain_type_iterate(pterrain) { - if (is_native_to_class(pclass, pterrain, extras)) { + if (is_native_to_class(pclass, pterrain, NULL)) { /* Can move at terrain */ if (is_ocean(pterrain)) { move_sea_enabled = TRUE; Modified: branches/S2_6/server/generator/mapgen.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/generator/mapgen.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/server/generator/mapgen.c (original) +++ branches/S2_6/server/generator/mapgen.c Tue Nov 10 21:39:05 2015 @@ -3605,7 +3605,7 @@ } pftile->pterrain = tile_terrain(ptile); pftile->presource = tile_resource(ptile); - pftile->extras = tile_extras(ptile); + pftile->extras = *tile_extras(ptile); } whole_map_iterate_end; /* Create main player island. */ Modified: branches/S2_6/server/rssanity.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/rssanity.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/server/rssanity.c (original) +++ branches/S2_6/server/rssanity.c Tue Nov 10 21:39:05 2015 @@ -849,11 +849,7 @@ terrain_type_iterate(pterr) { if (pterr->animal != NULL) { - bv_extras no_extras; - - BV_CLR_ALL(no_extras); - - if (!is_native_to_class(utype_class(pterr->animal), pterr, no_extras)) { + if (!is_native_to_class(utype_class(pterr->animal), pterr, NULL)) { ruleset_error(LOG_ERROR, "%s has %s as animal to appear, but it's not native to the terrain.", terrain_rule_name(pterr), utype_rule_name(pterr->animal)); Modified: branches/S2_6/server/unittools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=30514&r1=30513&r2=30514&view=diff ============================================================================== --- branches/S2_6/server/unittools.c (original) +++ branches/S2_6/server/unittools.c Tue Nov 10 21:39:05 2015 @@ -1011,7 +1011,7 @@ struct tile *ptile = unit_tile(punit); struct extra_type *tgt; - bv_extras extras = tile_extras(ptile); + bv_extras extras = *tile_extras(ptile); while ((tgt = get_preferred_pillage(extras))) { @@ -2707,7 +2707,7 @@ if (NULL == plrtile->site && !is_native_to_class(unit_class_get(punit), plrtile->terrain, - plrtile->extras)) { + &(plrtile->extras))) { notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server, _("This unit cannot paradrop into %s."), terrain_name_translation(plrtile->terrain)); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits