Use std::array for adjacent map_location arrays
I left the implementation of get_adjacent_tiles using messy C ptr arithmetic since it most simply accounts for a few cases using arrays that are larger than 6 (such as in tod_manager) or underlying vector storage. Also made use of std::array::size where applicable, and one case of std::array iterators. aspect_attacks_base::analyze_targets was changed to take a adjacent_loc_array_t reference.
This commit is contained in:
parent
bac3ab530a
commit
ae53a38835
32 changed files with 142 additions and 139 deletions
|
@ -1633,12 +1633,12 @@ bool backstab_check(const map_location& attacker_loc,
|
|||
return false; // No defender
|
||||
}
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(defender_loc, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(defender_loc, adj.data());
|
||||
|
||||
int i;
|
||||
unsigned i;
|
||||
|
||||
for(i = 0; i != 6; ++i) {
|
||||
for(i = 0; i < adj.size(); ++i) {
|
||||
if(adj[i] == attacker_loc) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -420,9 +420,9 @@ namespace { // Private helpers for move_unit()
|
|||
const unit_map &units = resources::gameboard->units();
|
||||
|
||||
// Need to check each adjacent hex for hidden enemies.
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(hex, adjacent);
|
||||
for ( int i = 0; i != 6; ++i )
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(hex, adjacent.data());
|
||||
for (unsigned i = 0; i < adjacent.size(); ++i )
|
||||
{
|
||||
const unit_map::const_iterator neighbor_it = units.find(adjacent[i]);
|
||||
|
||||
|
|
|
@ -275,9 +275,9 @@ bool shroud_clearer::clear_loc(team &tm, const map_location &loc,
|
|||
display::get_singleton()->invalidate(loc);
|
||||
// Need to also invalidate adjacent hexes to get rid of the
|
||||
// "fog edge" graphics.
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc, adjacent);
|
||||
for ( int i = 0; i != 6; ++i )
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(loc, adjacent.data());
|
||||
for (unsigned i = 0; i < adjacent.size(); ++i )
|
||||
display::get_singleton()->invalidate(adjacent[i]);
|
||||
}
|
||||
|
||||
|
@ -511,9 +511,9 @@ bool shroud_clearer::clear_dest(const map_location &dest, const unit &viewer)
|
|||
|
||||
// Clear the adjacent hexes (will be seen even if vision is 0, and the
|
||||
// graphics do not work so well for an isolated cleared hex).
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(dest, adjacent);
|
||||
for ( int i = 0; i != 6; ++i )
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(dest, adjacent.data());
|
||||
for (unsigned i = 0; i < adjacent.size(); ++i )
|
||||
if ( clear_loc(viewing_team, adjacent[i], dest, real_loc, viewer_id,
|
||||
true, enemies, friends) )
|
||||
cleared_something = true;
|
||||
|
|
|
@ -981,9 +981,9 @@ const std::set<map_location>& keeps_cache::get()
|
|||
for(int y = 0; y != map_->h(); ++y) {
|
||||
const map_location loc(x,y);
|
||||
if(map_->is_keep(loc)) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(map_->is_castle(adj[n])) {
|
||||
keeps_.insert(loc);
|
||||
break;
|
||||
|
@ -1058,8 +1058,8 @@ double readonly_context_impl::power_projection(const map_location& loc, const mo
|
|||
std::fill_n(ratings, 0, 6);
|
||||
int num_used_locs = 0;
|
||||
|
||||
map_location locs[6];
|
||||
get_adjacent_tiles(loc,locs);
|
||||
adjacent_loc_array_t locs;
|
||||
get_adjacent_tiles(loc,locs.data());
|
||||
|
||||
const gamemap& map_ = resources::gameboard->map();
|
||||
unit_map& units_ = resources::gameboard->units();
|
||||
|
|
|
@ -109,8 +109,8 @@ std::shared_ptr<attacks_vector> aspect_attacks_base::analyze_targets() const
|
|||
if (!is_allowed_enemy(*j)) {
|
||||
continue;
|
||||
}
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(j->get_location(), adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(j->get_location(), adjacent.data());
|
||||
attack_analysis analysis;
|
||||
analysis.target = j->get_location();
|
||||
analysis.vulnerability = 0.0;
|
||||
|
@ -130,7 +130,7 @@ void aspect_attacks_base::do_attack_analysis(
|
|||
const move_map& srcdst, const move_map& dstsrc,
|
||||
const move_map& fullmove_srcdst, const move_map& fullmove_dstsrc,
|
||||
const move_map& enemy_srcdst, const move_map& enemy_dstsrc,
|
||||
const map_location* tiles, bool* used_locations,
|
||||
const adjacent_loc_array_t& tiles, bool* used_locations,
|
||||
std::vector<map_location>& units,
|
||||
std::vector<attack_analysis>& result,
|
||||
attack_analysis& cur_analysis,
|
||||
|
@ -193,8 +193,8 @@ void aspect_attacks_base::do_attack_analysis(
|
|||
bool is_flanked = false;
|
||||
int enemy_units_around = 0;
|
||||
int accessible_tiles = 0;
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(current_unit, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(current_unit, adj.data());
|
||||
|
||||
size_t tile;
|
||||
for(tile = 0; tile != 3; ++tile) {
|
||||
|
@ -237,7 +237,7 @@ void aspect_attacks_base::do_attack_analysis(
|
|||
int cur_position = -1;
|
||||
|
||||
// Iterate over positions adjacent to the unit, finding the best rated one.
|
||||
for(int j = 0; j != 6; ++j) {
|
||||
for(unsigned j = 0; j < tiles.size(); ++j) {
|
||||
|
||||
// If in this planned attack, a unit is already in this location.
|
||||
if(used_locations[j]) {
|
||||
|
|
|
@ -55,7 +55,7 @@ protected:
|
|||
const move_map& srcdst, const move_map& dstsrc,
|
||||
const move_map& fullmove_srcdst, const move_map& fullmove_dstsrc,
|
||||
const move_map& enemy_srcdst, const move_map& enemy_dstsrc,
|
||||
const map_location* tiles, bool* used_locations,
|
||||
const adjacent_loc_array_t& tiles, bool* used_locations,
|
||||
std::vector<map_location>& units,
|
||||
std::vector<attack_analysis>& result,
|
||||
attack_analysis& cur_analysis,
|
||||
|
|
|
@ -51,10 +51,10 @@ void attack_analysis::analyze(const gamemap& map, unit_map& units,
|
|||
assert(defend_it != units.end());
|
||||
|
||||
// See if the target is a threat to our leader or an ally's leader.
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(target,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(target,adj.data());
|
||||
size_t tile;
|
||||
for(tile = 0; tile != 6; ++tile) {
|
||||
for(tile = 0; tile < adj.size(); ++tile) {
|
||||
const unit_map::const_iterator leader = units.find(adj[tile]);
|
||||
if(leader != units.end() && leader->can_recruit() && !ai_obj.current_team().is_enemy(leader->side())) {
|
||||
break;
|
||||
|
|
|
@ -1406,15 +1406,15 @@ double retreat_phase::evaluate()
|
|||
calculate_possible_moves(dummy_possible_moves, fullmove_srcdst, fullmove_dstsrc,
|
||||
false, true, &get_avoid());
|
||||
|
||||
/*map_location leader_adj[6];
|
||||
/*adjacent_loc_array_t leader_adj;
|
||||
if(leader != units_.end()) {
|
||||
get_adjacent_tiles(leader->get_location(), leader_adj);
|
||||
get_adjacent_tiles(leader->get_location(), leader_adj.data());
|
||||
}*/
|
||||
//int leader_adj_count = 0;
|
||||
std::vector<map_location> leaders_adj_v;
|
||||
for (unit_map::const_iterator leader : leaders) {
|
||||
map_location tmp_leader_adj[6];
|
||||
get_adjacent_tiles(leader->get_location(), tmp_leader_adj);
|
||||
adjacent_loc_array_t tmp_leader_adj;
|
||||
get_adjacent_tiles(leader->get_location(), tmp_leader_adj.data());
|
||||
for (map_location &loc : tmp_leader_adj) {
|
||||
bool found = false;
|
||||
for (map_location &new_loc : leaders_adj_v) {
|
||||
|
|
|
@ -664,9 +664,9 @@ double move_to_targets_phase::compare_groups(const std::set<map_location>& our_g
|
|||
void move_to_targets_phase::enemies_along_path(const std::vector<map_location>& route, const move_map& dstsrc, std::set<map_location>& res)
|
||||
{
|
||||
for(std::vector<map_location>::const_iterator i = route.begin(); i != route.end(); ++i) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(*i,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(*i,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
const std::pair<move_map::const_iterator,move_map::const_iterator> itors = dstsrc.equal_range(adj[n]);
|
||||
for(move_map::const_iterator j = itors.first; j != itors.second; ++j) {
|
||||
res.insert(j->second);
|
||||
|
@ -743,10 +743,10 @@ bool move_to_targets_phase::move_group(const map_location& dst, const std::vecto
|
|||
}
|
||||
|
||||
if(next.valid()) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(dst,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(dst,adj.data());
|
||||
|
||||
direction = std::find(adj,adj+6,next) - adj;
|
||||
direction = std::distance(adj.begin(), std::find(adj.begin(), adj.end(), next));
|
||||
}
|
||||
|
||||
std::deque<map_location> preferred_moves;
|
||||
|
@ -803,9 +803,9 @@ bool move_to_targets_phase::move_group(const map_location& dst, const std::vecto
|
|||
preferred_moves.erase(std::find(preferred_moves.begin(),preferred_moves.end(),best_loc));
|
||||
|
||||
//find locations that are 'perpendicular' to the direction of movement for further units to move to.
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(best_loc,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(best_loc,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(n != direction && ((n+3)%6) != direction && map_.on_board(adj[n]) &&
|
||||
units_.count(adj[n]) == 0 && std::count(preferred_moves.begin(),preferred_moves.end(),adj[n]) == 0) {
|
||||
preferred_moves.push_front(adj[n]);
|
||||
|
|
|
@ -70,9 +70,9 @@ int default_ai_context_impl::count_free_hexes_in_castle(const map_location &loc,
|
|||
{
|
||||
int ret = 0;
|
||||
unit_map &units_ = resources::gameboard->units();
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if (checked_hexes.find(adj[n]) != checked_hexes.end())
|
||||
continue;
|
||||
checked_hexes.insert(adj[n]);
|
||||
|
@ -149,9 +149,9 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
//find the location of enemy threats
|
||||
std::set<map_location> threats;
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(leader->get_location(), adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(leader->get_location(), adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
std::pair<move_map::const_iterator,move_map::const_iterator> itors = enemy_dstsrc.equal_range(adj[n]);
|
||||
while(itors.first != itors.second) {
|
||||
if(units_.count(itors.first->second)) {
|
||||
|
|
|
@ -221,10 +221,10 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
|
|||
const map_location::DIRECTION preferred = destination.get_relative_dir(src);
|
||||
|
||||
int best_rating = 100;//smaller is better
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(destination,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(destination,adj.data());
|
||||
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(resources::gameboard->map().on_board(adj[n]) == false) {
|
||||
continue;
|
||||
}
|
||||
|
@ -606,9 +606,9 @@ variant formula_ai::get_keeps() const
|
|||
for(size_t y = 0; y != size_t(resources::gameboard->map().h()); ++y) {
|
||||
const map_location loc(x,y);
|
||||
if(resources::gameboard->map().is_keep(loc)) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(resources::gameboard->map().is_castle(adj[n])) {
|
||||
vars.emplace_back(std::make_shared<location_callable>(loc));
|
||||
break;
|
||||
|
|
|
@ -271,10 +271,10 @@ void attack_map_callable::get_inputs(formula_input_vector& inputs) const {
|
|||
|
||||
/* add to vars all attacks on enemy units around <attack_position> tile. attacker_location is tile where unit is currently standing. It's moved to attack_position first and then performs attack.*/
|
||||
void attack_map_callable::collect_possible_attacks(std::vector<variant>& vars, map_location attacker_location, map_location attack_position) const {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(attack_position, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(attack_position, adj.data());
|
||||
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
for(unsigned n = 0; n < adj.size(); ++n) {
|
||||
/* if adjacent tile is outside the board */
|
||||
if (! resources::gameboard->map().on_board(adj[n]))
|
||||
continue;
|
||||
|
|
|
@ -207,7 +207,7 @@ namespace {
|
|||
pq.pop_back();
|
||||
n.in = search_counter;
|
||||
|
||||
get_adjacent_tiles(n.loc_, &locs[0]);
|
||||
get_adjacent_tiles(n.loc_, locs.data());
|
||||
for (int i = teleports.count(n.loc_) ? locs.size() : 6; i-- > 0;) {
|
||||
if (!locs[i].valid(map.w(), map.h())) continue;
|
||||
|
||||
|
@ -444,10 +444,10 @@ DEFINE_WFL_FUNCTION(castle_locs, 1, 1)
|
|||
|
||||
visited_locs.insert(loc);
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc, adj.data());
|
||||
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
for(unsigned n = 0; n < adj.size(); ++n) {
|
||||
if (resources::gameboard->map().on_board(adj[n]) && visited_locs.find( adj[n] ) == visited_locs.end() ) {
|
||||
if (resources::gameboard->map().get_terrain_info(adj[n]).is_keep() ||
|
||||
resources::gameboard->map().get_terrain_info(adj[n]).is_castle() ) {
|
||||
|
|
|
@ -981,7 +981,7 @@ std::vector<surface> display::get_fog_shroud_images(const map_location& loc, ima
|
|||
{
|
||||
std::vector<std::string> names;
|
||||
|
||||
std::array<map_location, 6> adjacent;
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(loc, adjacent.data());
|
||||
|
||||
enum visibility {FOG=0, SHROUD=1, CLEAR=2};
|
||||
|
@ -990,7 +990,7 @@ std::vector<surface> display::get_fog_shroud_images(const map_location& loc, ima
|
|||
const std::string* image_prefix[] =
|
||||
{ &game_config::fog_prefix, &game_config::shroud_prefix};
|
||||
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
for(int i = 0; i < 6; ++i) {
|
||||
if(shrouded(adjacent[i])) {
|
||||
tiles[i] = SHROUD;
|
||||
} else if(!fogged(loc) && fogged(adjacent[i])) {
|
||||
|
@ -1084,7 +1084,7 @@ void display::get_terrain_images(const map_location &loc,
|
|||
const time_of_day& tod = get_time_of_day(loc);
|
||||
|
||||
//get all the light transitions
|
||||
std::array<map_location, 6> adjs;
|
||||
adjacent_loc_array_t adjs;
|
||||
std::array<const time_of_day*, 6> atods;
|
||||
get_adjacent_tiles(loc, adjs.data());
|
||||
for(size_t d = 0; d < adjs.size(); ++d){
|
||||
|
|
|
@ -31,8 +31,8 @@ const team& display_context::get_team(int side) const
|
|||
|
||||
bool display_context::would_be_discovered(const map_location & loc, int side_num, bool see_all)
|
||||
{
|
||||
map_location adjs[6];
|
||||
get_adjacent_tiles(loc,adjs);
|
||||
adjacent_loc_array_t adjs;
|
||||
get_adjacent_tiles(loc,adjs.data());
|
||||
|
||||
for (const map_location &u_loc : adjs)
|
||||
{
|
||||
|
@ -83,9 +83,9 @@ bool display_context::unit_can_move(const unit &u) const
|
|||
|
||||
const team ¤t_team = get_team(u.side());
|
||||
|
||||
map_location locs[6];
|
||||
get_adjacent_tiles(u.get_location(), locs);
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t locs;
|
||||
get_adjacent_tiles(u.get_location(), locs.data());
|
||||
for(unsigned n = 0; n < locs.size(); ++n) {
|
||||
if (map().on_board(locs[n])) {
|
||||
const unit_map::const_iterator i = units().find(locs[n]);
|
||||
if (i.valid() && !i->incapacitated() &&
|
||||
|
|
|
@ -34,10 +34,10 @@ void mouse_action_item::move(editor_display& disp, const map_location& hex)
|
|||
update_brush_highlights(disp, hex);
|
||||
|
||||
std::set<map_location> adjacent_set;
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(previous_move_hex_, adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(previous_move_hex_, adjacent.data());
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
for (unsigned i = 0; i < adjacent.size(); i++)
|
||||
adjacent_set.insert(adjacent[i]);
|
||||
|
||||
disp.invalidate(adjacent_set);
|
||||
|
|
|
@ -38,10 +38,10 @@ void mouse_action_unit::move(editor_display& disp, const map_location& hex)
|
|||
update_brush_highlights(disp, hex);
|
||||
|
||||
std::set<map_location> adjacent_set;
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(previous_move_hex_, adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(previous_move_hex_, adjacent.data());
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
for (unsigned i = 0; i < adjacent.size(); i++)
|
||||
adjacent_set.insert(adjacent[i]);
|
||||
|
||||
disp.invalidate(adjacent_set);
|
||||
|
|
|
@ -122,9 +122,9 @@ std::set<map_location> editor_map::get_contiguous_terrain_tiles(const map_locati
|
|||
queue.push_back(start);
|
||||
//this is basically a breadth-first search along adjacent hexes
|
||||
do {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(queue.front(), adj);
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(queue.front(), adj.data());
|
||||
for (unsigned i = 0; i < adj.size(); ++i) {
|
||||
if (on_board_with_border(adj[i]) && get_terrain(adj[i]) == terrain
|
||||
&& result.find(adj[i]) == result.end()) {
|
||||
result.insert(adj[i]);
|
||||
|
|
|
@ -1226,11 +1226,11 @@ DEFINE_WFL_FUNCTION(adjacent_locs, 1, 1)
|
|||
.convert_to<location_callable>()
|
||||
->loc();
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc, adj.data());
|
||||
|
||||
std::vector<variant> v;
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
for(unsigned n = 0; n < adj.size(); ++n) {
|
||||
v.emplace_back(std::make_shared<location_callable>(adj[n]));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,11 +29,11 @@ namespace gamestate {
|
|||
DEFINE_WFL_FUNCTION(adjacent_locs, 1, 1)
|
||||
{
|
||||
const map_location loc = args()[0]->evaluate(variables, add_debug_info(fdb, 0, "adjacent_locs:location")).convert_to<location_callable>()->loc();
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc, adj.data());
|
||||
|
||||
std::vector<variant> v;
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
for(unsigned n = 0; n < adj.size(); ++n) {
|
||||
if(resources::gameboard->map().on_board(adj[n])) {
|
||||
v.emplace_back(std::make_shared<location_callable>(adj[n]));
|
||||
}
|
||||
|
|
|
@ -130,9 +130,9 @@ void cave_map_generator::cave_map_generator_job::build_chamber(map_location loc,
|
|||
|
||||
locs.insert(loc);
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(int(rng_() % 100) < (100l - static_cast<long>(jagged))) {
|
||||
build_chamber(adj[n],locs,size-1,jagged);
|
||||
}
|
||||
|
@ -359,9 +359,9 @@ void cave_map_generator::cave_map_generator_job::place_castle(int starting_posit
|
|||
starting_positions_.insert(t_translation::starting_positions::value_type(std::to_string(starting_position), coord));
|
||||
}
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc,adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
set_terrain(adj[n], params.castle_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -456,8 +456,8 @@ bool default_map_generator_job::generate_river_internal(const height_map& height
|
|||
}
|
||||
|
||||
map_location current_loc(x,y);
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(current_loc,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(current_loc,adj.data());
|
||||
std::shuffle(std::begin(adj), std::end(adj), rng_);
|
||||
|
||||
// Mark that we have attempted from this map_location
|
||||
|
@ -629,9 +629,9 @@ static map_location place_village(const t_translation::ter_map& map,
|
|||
}
|
||||
|
||||
int rating = child["rating"];
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(map_location(i.x,i.y),adj);
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(map_location(i.x,i.y),adj.data());
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(adj[n].x < 0 || adj[n].y < 0 ||
|
||||
adj[n].x >= map.w ||
|
||||
adj[n].y >= map.h) {
|
||||
|
@ -658,8 +658,8 @@ static void flood_name(const map_location& start, const std::string& name, std::
|
|||
const t_translation::ter_match& tile_types, const terrain_map& terrain,
|
||||
unsigned width, unsigned height,
|
||||
size_t label_count, std::map<map_location,std::string>* labels, const std::string& full_name) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(start,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(start,adj.data());
|
||||
size_t n;
|
||||
//if adjacent tiles are tiles and unnamed, name them
|
||||
for(n = 0; n < 6; n++) {
|
||||
|
@ -1060,8 +1060,8 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
|
|||
const map_location& last = *(step-1);
|
||||
const map_location& next = *(step+1);
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(*step,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(*step,adj.data());
|
||||
|
||||
int direction = -1;
|
||||
|
||||
|
@ -1290,8 +1290,8 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
|
|||
|
||||
const map_location loc(res.x-data.width/3,res.y-data.height/3);
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc,adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc,adj.data());
|
||||
|
||||
std::string name_type = "village";
|
||||
const t_translation::ter_list
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
class config;
|
||||
class variable_set;
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
|
@ -125,6 +126,8 @@ struct map_location {
|
|||
int x, y;
|
||||
};
|
||||
|
||||
using adjacent_loc_array_t = std::array<map_location, 6>;
|
||||
|
||||
/** Function which tells if two locations are adjacent. */
|
||||
bool tiles_adjacent(const map_location& a, const map_location& b);
|
||||
|
||||
|
|
|
@ -447,10 +447,10 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
int best_rating = 100; // smaller is better
|
||||
|
||||
map_location res;
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc, adj.data());
|
||||
|
||||
for(size_t n = 0; n != 6; ++n) {
|
||||
for(size_t n = 0; n < adj.size(); ++n) {
|
||||
if(pc_.gamestate().board_.map().on_board(adj[n]) == false) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1085,8 +1085,8 @@ std::set<map_location> mouse_handler::get_adj_enemies(const map_location& loc, i
|
|||
|
||||
const team& uteam = pc_.gamestate().board_.teams_[side - 1];
|
||||
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(loc, adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(loc, adj.data());
|
||||
|
||||
for(const map_location& aloc : adj) {
|
||||
unit_map::const_iterator i = find_unit(aloc);
|
||||
|
@ -1117,8 +1117,8 @@ void mouse_handler::show_attack_options(const unit_map::const_iterator& u)
|
|||
const team& u_team = pc_.gamestate().board_.teams_[u->side() - 1];
|
||||
|
||||
// Check each adjacent hex.
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(u->get_location(), adj);
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(u->get_location(), adj.data());
|
||||
|
||||
for(const map_location& loc : adj) {
|
||||
// No attack option shown if no visible unit present.
|
||||
|
|
|
@ -196,7 +196,7 @@ plain_route a_star_search(const map_location& src, const map_location& dst,
|
|||
|
||||
int i = locs.size();
|
||||
|
||||
get_adjacent_tiles(n.curr, &locs[0]);
|
||||
get_adjacent_tiles(n.curr, locs.data());
|
||||
|
||||
for (; i-- > 0;) {
|
||||
if (!locs[i].valid(width, height, border)) continue;
|
||||
|
|
|
@ -92,8 +92,8 @@ map_location find_vacant_tile(const map_location& loc, VACANT_TILE_TYPE vacancy,
|
|||
if (pass_check_and_unreachable && distance > 10) continue;
|
||||
//If the hex is empty and we do either no pass check or the hex is reachable, return it.
|
||||
if (units.find(l) == units.end() && !pass_check_and_unreachable) return l;
|
||||
map_location adjs[6];
|
||||
get_adjacent_tiles(l,adjs);
|
||||
adjacent_loc_array_t adjs;
|
||||
get_adjacent_tiles(l,adjs.data());
|
||||
for (const map_location &l2 : adjs)
|
||||
{
|
||||
if (!map.on_board(l2)) continue;
|
||||
|
@ -137,9 +137,9 @@ bool enemy_zoc(const team& current_team, const map_location& loc,
|
|||
const team& viewing_team, bool see_all)
|
||||
{
|
||||
// Check the adjacent tiles.
|
||||
map_location locs[6];
|
||||
get_adjacent_tiles(loc,locs);
|
||||
for (int i = 0; i != 6; ++i)
|
||||
adjacent_loc_array_t locs;
|
||||
get_adjacent_tiles(loc,locs.data());
|
||||
for (unsigned i = 0; i < locs.size(); ++i)
|
||||
{
|
||||
const unit *u = resources::gameboard->get_visible_unit(locs[i], viewing_team, see_all);
|
||||
if ( u && current_team.is_enemy(u->side()) && u->emits_zoc() )
|
||||
|
@ -345,7 +345,7 @@ static void find_routes(
|
|||
|
||||
// Get the locations adjacent to current.
|
||||
std::vector<map_location> adj_locs(6);
|
||||
get_adjacent_tiles(cur_hex, &adj_locs[0]);
|
||||
get_adjacent_tiles(cur_hex, adj_locs.data());
|
||||
|
||||
// Sort adjacents by on-boardness
|
||||
auto off_board_it = std::partition(adj_locs.begin(), adj_locs.end(), [&index](map_location loc){
|
||||
|
|
|
@ -249,9 +249,9 @@ void get_tiles_radius(const gamemap& map, const std::vector<map_location>& locs,
|
|||
|
||||
result.insert(it, it_end);
|
||||
for(; it != it_end; ++it) {
|
||||
map_location adj[6];
|
||||
get_adjacent_tiles(*it, adj);
|
||||
for(size_t i = 0; i != 6; ++i) {
|
||||
adjacent_loc_array_t adj;
|
||||
get_adjacent_tiles(*it, adj.data());
|
||||
for(size_t i = 0; i < adj.size(); ++i) {
|
||||
const map_location& loc = adj[i];
|
||||
if ( with_border ? map.on_board_with_border(loc) :
|
||||
map.on_board(loc) ) {
|
||||
|
|
|
@ -199,8 +199,8 @@ bool terrain_filter::match_internal(const map_location& loc, const unit* ref_uni
|
|||
|
||||
//Allow filtering on adjacent locations
|
||||
if(cfg_.has_child("filter_adjacent_location")) {
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc, adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(loc, adjacent.data());
|
||||
const vconfig::child_list& adj_cfgs = cfg_.get_children("filter_adjacent_location");
|
||||
vconfig::child_list::const_iterator i, i_end, i_begin = adj_cfgs.begin();
|
||||
for (i = i_begin, i_end = adj_cfgs.end(); i != i_end; ++i) {
|
||||
|
|
|
@ -234,10 +234,10 @@ const time_of_day tod_manager::get_illuminated_time_of_day(const unit_map & unit
|
|||
int most_sub = 0;
|
||||
|
||||
// Find the "illuminates" effects from units that can affect loc.
|
||||
map_location locs[7];
|
||||
std::array<map_location, 7> locs;
|
||||
locs[0] = loc;
|
||||
get_adjacent_tiles(loc,locs+1);
|
||||
for ( size_t i = 0; i != 7; ++i ) {
|
||||
get_adjacent_tiles(loc, locs.data() + 1); // start at [1]
|
||||
for ( size_t i = 0; i < locs.size(); ++i ) {
|
||||
const unit_map::const_iterator itor = units.find(locs[i]);
|
||||
if (itor != units.end() &&
|
||||
itor->get_ability_bool("illuminates", *resources::gameboard) &&
|
||||
|
|
|
@ -149,9 +149,9 @@ bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc
|
|||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(loc,adjacent.data());
|
||||
for(unsigned i = 0; i < adjacent.size(); ++i) {
|
||||
const unit_map::const_iterator it = units.find(adjacent[i]);
|
||||
if (it == units.end() || it->incapacitated())
|
||||
continue;
|
||||
|
@ -190,9 +190,9 @@ unit_ability_list unit::get_abilities(const std::string& tag_name, const map_loc
|
|||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
for(int i = 0; i != 6; ++i) {
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(loc,adjacent.data());
|
||||
for(unsigned i = 0; i < adjacent.size(); ++i) {
|
||||
const unit_map::const_iterator it = units.find(adjacent[i]);
|
||||
if (it == units.end() || it->incapacitated())
|
||||
continue;
|
||||
|
@ -312,8 +312,8 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
if ( !unit_filter(vconfig(afilter)).set_use_flat_tod(illuminates).matches(*this, loc) )
|
||||
return false;
|
||||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(loc,adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(loc,adjacent.data());
|
||||
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
|
@ -946,8 +946,8 @@ bool attack_type::special_active(const config& special, AFFECTS whom,
|
|||
if (!special_unit_matches(def, att, def_loc, def_weapon, special, is_for_listing_, "filter_defender"))
|
||||
return false;
|
||||
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(self_loc_, adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(self_loc_, adjacent.data());
|
||||
|
||||
// Filter the adjacent units.
|
||||
for (const config &i : special.child_range("filter_adjacent"))
|
||||
|
|
|
@ -125,8 +125,8 @@ struct unit_filter_adjacent : public unit_filter_base
|
|||
virtual bool matches(const unit_filter_args& args) const override
|
||||
{
|
||||
const unit_map& units = args.fc->get_disp_context().units();
|
||||
map_location adjacent[6];
|
||||
get_adjacent_tiles(args.loc, adjacent);
|
||||
adjacent_loc_array_t adjacent;
|
||||
get_adjacent_tiles(args.loc, adjacent.data());
|
||||
int match_count=0;
|
||||
|
||||
config::attribute_value i_adjacent = cfg_["adjacent"];
|
||||
|
|
|
@ -381,12 +381,12 @@ void unit_mover::wait_for_anims()
|
|||
/// not left on screen after unit movement in particular.
|
||||
if ( disp_ ) { // Should always be true if we get here.
|
||||
// Invalidate the hexes around the move that prompted this wait.
|
||||
map_location arr[6];
|
||||
get_adjacent_tiles(path_[current_-1], arr);
|
||||
for ( unsigned i = 0; i < 6; ++i )
|
||||
adjacent_loc_array_t arr;
|
||||
get_adjacent_tiles(path_[current_-1], arr.data());
|
||||
for ( unsigned i = 0; i < arr.size(); ++i )
|
||||
disp_->invalidate(arr[i]);
|
||||
get_adjacent_tiles(path_[current_], arr);
|
||||
for ( unsigned i = 0; i < 6; ++i )
|
||||
get_adjacent_tiles(path_[current_], arr.data());
|
||||
for ( unsigned i = 0; i < arr.size(); ++i )
|
||||
disp_->invalidate(arr[i]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue