add static const members ZERO, default_dirs, of map_location
Replace local constants appearing elsewhere with these. The definitions are inlined.
This commit is contained in:
parent
4b64eea0a6
commit
c73b5945d9
10 changed files with 25 additions and 23 deletions
|
@ -175,7 +175,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
}
|
||||
}
|
||||
|
||||
double corner_distance = distance_between(map_location(0,0), map_location(map_.w(),map_.h()));
|
||||
double corner_distance = distance_between(map_location::ZERO(), map_location(map_.w(),map_.h()));
|
||||
double village_value = get_village_value();
|
||||
if(has_leader && village_value > 0.0) {
|
||||
std::map<map_location,pathfind::paths> friends_possible_moves;
|
||||
|
|
|
@ -224,7 +224,7 @@ class editor_action_area : public editor_action_extendable
|
|||
class editor_action_paste : public editor_action_extendable
|
||||
{
|
||||
public:
|
||||
editor_action_paste(const map_fragment& paste, const map_location& offset = map_location(0,0))
|
||||
editor_action_paste(const map_fragment& paste, const map_location& offset = map_location::ZERO())
|
||||
: offset_(offset), paste_(paste)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ void map_fragment::rotate_60_cw()
|
|||
{
|
||||
area_.clear();
|
||||
BOOST_FOREACH(tile_info& ti, items_) {
|
||||
map_location l(0,0);
|
||||
map_location l = map_location::ZERO();
|
||||
int x = ti.offset.x;
|
||||
int y = ti.offset.y;
|
||||
// rotate the X-Y axes to SOUTH/SOUTH_EAST - SOUTH_WEST axes
|
||||
|
@ -123,7 +123,7 @@ void map_fragment::rotate_60_ccw()
|
|||
{
|
||||
area_.clear();
|
||||
BOOST_FOREACH(tile_info& ti, items_) {
|
||||
map_location l(0,0);
|
||||
map_location l = map_location::ZERO();
|
||||
int x = ti.offset.x;
|
||||
int y = ti.offset.y;
|
||||
// rotate the X-Y axes to NORTH/NORTH_EAST - SOUTH_EAST axes'
|
||||
|
|
15
src/halo.cpp
15
src/halo.cpp
|
@ -119,9 +119,8 @@ effect::effect(int xpos, int ypos, const animated<image::locator>::anim_descript
|
|||
|
||||
void effect::set_location(int x, int y)
|
||||
{
|
||||
const map_location zero_loc(0,0);
|
||||
int new_x = x - disp->get_location_x(zero_loc);
|
||||
int new_y = y - disp->get_location_y(zero_loc);
|
||||
int new_x = x - disp->get_location_x(map_location::ZERO());
|
||||
int new_y = y - disp->get_location_y(map_location::ZERO());
|
||||
if (new_x != x_ || new_y != y_) {
|
||||
x_ = new_x;
|
||||
y_ = new_y;
|
||||
|
@ -165,9 +164,8 @@ bool effect::render()
|
|||
surf_.assign(flop_surface(surf_));
|
||||
}
|
||||
|
||||
const map_location zero_loc(0,0);
|
||||
const int screenx = disp->get_location_x(zero_loc);
|
||||
const int screeny = disp->get_location_y(zero_loc);
|
||||
const int screenx = disp->get_location_x(map_location::ZERO());
|
||||
const int screeny = disp->get_location_y(map_location::ZERO());
|
||||
|
||||
const int xpos = x_ + screenx - surf_->w/2;
|
||||
const int ypos = y_ + screeny - surf_->h/2;
|
||||
|
@ -231,9 +229,8 @@ void effect::unrender()
|
|||
|
||||
// Due to scrolling, the location of the rendered halo
|
||||
// might have changed; recalculate
|
||||
const map_location zero_loc(0,0);
|
||||
const int screenx = disp->get_location_x(zero_loc);
|
||||
const int screeny = disp->get_location_y(zero_loc);
|
||||
const int screenx = disp->get_location_x(map_location::ZERO());
|
||||
const int screeny = disp->get_location_y(map_location::ZERO());
|
||||
|
||||
const int xpos = x_ + screenx - surf_->w/2;
|
||||
const int ypos = y_ + screeny - surf_->h/2;
|
||||
|
|
|
@ -645,7 +645,7 @@ const std::map<t_translation::t_terrain, size_t>& gamemap::get_weighted_terrain_
|
|||
|
||||
const map_location center(w()/2,h()/2);
|
||||
|
||||
const size_t furthest_distance = distance_between(map_location(0,0),center);
|
||||
const size_t furthest_distance = distance_between(map_location::ZERO(),center);
|
||||
|
||||
const size_t weight_at_edge = 100;
|
||||
const size_t additional_weight_at_center = 200;
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "resources.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
|
||||
#define ERR_CF LOG_STREAM(err, config)
|
||||
#define LOG_G LOG_STREAM(info, general)
|
||||
#define DBG_G LOG_STREAM(debug, general)
|
||||
|
|
|
@ -24,6 +24,7 @@ class variable_set;
|
|||
#include <vector>
|
||||
#include <set>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
|
||||
/**
|
||||
* Encapsulates the map of the game.
|
||||
|
@ -38,6 +39,15 @@ struct map_location {
|
|||
enum DIRECTION { NORTH=0, NORTH_EAST=1, SOUTH_EAST=2, SOUTH=3,
|
||||
SOUTH_WEST=4, NORTH_WEST=5, NDIRECTIONS=6 };
|
||||
|
||||
static const std::vector<DIRECTION> & default_dirs() {
|
||||
static const std::vector<map_location::DIRECTION> dirs = boost::assign::list_of(map_location::NORTH)(map_location::NORTH_EAST)(map_location::SOUTH_EAST)(map_location::SOUTH)(map_location::SOUTH_WEST)(map_location::NORTH_WEST);
|
||||
return dirs;
|
||||
}
|
||||
|
||||
static const map_location & ZERO() {
|
||||
static const map_location z(0,0);
|
||||
return z;
|
||||
}
|
||||
|
||||
static inline DIRECTION rotate_right(DIRECTION d, unsigned int k = 1u) {
|
||||
return (d == NDIRECTIONS) ? NDIRECTIONS : static_cast<map_location::DIRECTION>((d + (k%6u)) % 6u);
|
||||
|
@ -105,7 +115,7 @@ struct map_location {
|
|||
// Rotates the map_location clockwise in 60 degree increments around a center point. Negative numbers of steps are permitted.
|
||||
map_location rotate_right_around_center(const map_location & center, int k) const;
|
||||
|
||||
static const map_location null_location;
|
||||
static const map_location null_location;
|
||||
|
||||
friend std::size_t hash_value(map_location const &a);
|
||||
};
|
||||
|
|
|
@ -185,10 +185,8 @@ bool terrain_filter::match_internal(const map_location& loc, const bool ignore_x
|
|||
for (i = i_begin, i_end = adj_cfgs.end(); i != i_end; ++i) {
|
||||
int match_count = 0;
|
||||
vconfig::child_list::difference_type index = i - i_begin;
|
||||
static std::vector<map_location::DIRECTION> default_dirs
|
||||
= map_location::parse_directions("n,ne,se,s,sw,nw");
|
||||
std::vector<map_location::DIRECTION> dirs = (*i).has_attribute("adjacent")
|
||||
? map_location::parse_directions((*i)["adjacent"]) : default_dirs;
|
||||
? map_location::parse_directions((*i)["adjacent"]) : map_location::default_dirs();
|
||||
std::vector<map_location::DIRECTION>::const_iterator j, j_end = dirs.end();
|
||||
for (j = dirs.begin(); j != j_end; ++j) {
|
||||
map_location &adj = adjacent[*j];
|
||||
|
|
|
@ -38,7 +38,7 @@ struct MLFixture
|
|||
va = map_location(3,4);
|
||||
vb = map_location(10,8);
|
||||
vc = map_location(0,9);
|
||||
vz = map_location(0,0);
|
||||
vz = map_location::ZERO();
|
||||
vt1 = map_location(va.vector_negation());
|
||||
vt2 = map_location(vb.vector_sum(vc));
|
||||
vt3 = map_location(va.vector_sum(vc.vector_negation()));
|
||||
|
|
|
@ -1609,11 +1609,9 @@ bool unit::internal_matches_filter(const vconfig& cfg, const map_location& loc,
|
|||
const vconfig::child_list& adj_filt = cfg.get_children("filter_adjacent");
|
||||
for (i = adj_filt.begin(), i_end = adj_filt.end(); i != i_end; ++i) {
|
||||
int match_count=0;
|
||||
static std::vector<map_location::DIRECTION> default_dirs
|
||||
= map_location::parse_directions("n,ne,se,s,sw,nw");
|
||||
config::attribute_value i_adjacent = (*i)["adjacent"];
|
||||
std::vector<map_location::DIRECTION> dirs = !i_adjacent.blank() ?
|
||||
map_location::parse_directions(i_adjacent) : default_dirs;
|
||||
map_location::parse_directions(i_adjacent) : map_location::default_dirs();
|
||||
std::vector<map_location::DIRECTION>::const_iterator j, j_end = dirs.end();
|
||||
for (j = dirs.begin(); j != j_end; ++j) {
|
||||
unit_map::const_iterator unit_itor = units.find(adjacent[*j]);
|
||||
|
|
Loading…
Add table
Reference in a new issue