Map Location: convert direction to a scoped enum
This commit is contained in:
parent
08e514bc4b
commit
f4fda31707
35 changed files with 296 additions and 279 deletions
|
@ -618,7 +618,7 @@ namespace { // Helpers for place_recruit()
|
|||
}// anonymous namespace
|
||||
//Used by recalls and recruits
|
||||
place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_location, const map_location& recruited_from,
|
||||
int cost, bool is_recall, map_location::DIRECTION facing, bool show, bool fire_event, bool full_movement,
|
||||
int cost, bool is_recall, map_location::direction facing, bool show, bool fire_event, bool full_movement,
|
||||
bool wml_triggered)
|
||||
{
|
||||
place_recruit_result res(false, 0, false);
|
||||
|
@ -645,7 +645,7 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat
|
|||
|
||||
map_location current_loc = recruit_location;
|
||||
|
||||
if (facing == map_location::NDIRECTIONS) {
|
||||
if (facing == map_location::direction::indeterminate) {
|
||||
set_recruit_facing(new_unit_itor, *u, recruit_location, leader_loc);
|
||||
} else {
|
||||
new_unit_itor->set_facing(facing);
|
||||
|
@ -720,7 +720,7 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l
|
|||
|
||||
|
||||
// Place the recruit.
|
||||
place_recruit_result res = place_recruit(new_unit, loc, from, u_type.cost(), false, map_location::NDIRECTIONS, show);
|
||||
place_recruit_result res = place_recruit(new_unit, loc, from, u_type.cost(), false, map_location::direction::indeterminate, show);
|
||||
resources::controller->statistics().recruit_unit(*new_unit);
|
||||
|
||||
// To speed things a bit, don't bother with the undo stack during
|
||||
|
@ -743,7 +743,7 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l
|
|||
|
||||
bool recall_unit(const std::string & id, team & current_team,
|
||||
const map_location & loc, const map_location & from,
|
||||
map_location::DIRECTION facing, bool show, bool use_undo)
|
||||
map_location::direction facing, bool show, bool use_undo)
|
||||
{
|
||||
unit_ptr recall = current_team.recall_list().extract_if_matches_id(id);
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ typedef std::tuple<bool /*event modified*/, int /*previous village owner side*/,
|
|||
* @param recruited_from the location it was recruited from.
|
||||
* @param cost the unit's cost.
|
||||
* @param is_recall whether the unit was recalled.
|
||||
* @param facing the desired facing for the unit, map_location::NDIRECTIONS to determine facing automatically.
|
||||
* @param facing the desired facing for the unit, map_location::direction::indeterminate to determine facing automatically.
|
||||
* @param show
|
||||
* @param fire_event whether to fire events for the unit placement.
|
||||
* @param full_movement whether the unit starts with full movement points.
|
||||
|
@ -159,7 +159,7 @@ typedef std::tuple<bool /*event modified*/, int /*previous village owner side*/,
|
|||
* @returns true if an event (or fog clearing) has mutated the game state.
|
||||
*/
|
||||
place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_location, const map_location& recruited_from,
|
||||
int cost, bool is_recall, map_location::DIRECTION facing = map_location::NDIRECTIONS, bool show = false, bool fire_event = true, bool full_movement = false, bool wml_triggered = false);
|
||||
int cost, bool is_recall, map_location::direction facing = map_location::direction::indeterminate, bool show = false, bool fire_event = true, bool full_movement = false, bool wml_triggered = false);
|
||||
|
||||
/**
|
||||
* Recruits a unit of the given type for the given side.
|
||||
|
@ -183,13 +183,13 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l
|
|||
* @param current_team the team to recall the unit to.
|
||||
* @param loc the location it was recalled onto.
|
||||
* @param from the location it was recalled from.
|
||||
* @param facing the desired facing for the unit, map_location::NDIRECTIONS to determine facing automatically.
|
||||
* @param facing the desired facing for the unit, map_location::direction::indeterminate to determine facing automatically.
|
||||
* @param show
|
||||
* @param use_undo if it's possible to undo the recall.
|
||||
* @returns false if the recall could not be found in the team's recall list.
|
||||
*/
|
||||
bool recall_unit(const std::string & id, team & current_team,
|
||||
const map_location & loc, const map_location & from,
|
||||
map_location::DIRECTION facing = map_location::NDIRECTIONS,
|
||||
map_location::direction facing = map_location::direction::indeterminate,
|
||||
bool show=true, bool use_undo=true);
|
||||
}//namespace actions
|
||||
|
|
|
@ -313,7 +313,7 @@ namespace { // Private helpers for move_unit()
|
|||
// This data stores the state from before the move started.
|
||||
const int orig_side_;
|
||||
const int orig_moves_;
|
||||
const map_location::DIRECTION orig_dir_;
|
||||
const map_location::direction orig_dir_;
|
||||
const map_location goto_;
|
||||
|
||||
// This data tracks the current state as the move is in progress.
|
||||
|
|
|
@ -157,7 +157,7 @@ void undo_list::add_move(const unit_const_ptr u,
|
|||
const std::vector<map_location>::const_iterator & begin,
|
||||
const std::vector<map_location>::const_iterator & end,
|
||||
int start_moves, int timebonus, int village_owner,
|
||||
const map_location::DIRECTION dir)
|
||||
const map_location::direction dir)
|
||||
{
|
||||
add(new undo::move_action(u, begin, end, start_moves, timebonus, village_owner, dir));
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
const std::vector<map_location>::const_iterator & begin,
|
||||
const std::vector<map_location>::const_iterator & end,
|
||||
int start_moves, int timebonus=0, int village_owner=-1,
|
||||
const map_location::DIRECTION dir=map_location::NDIRECTIONS);
|
||||
const map_location::direction dir=map_location::direction::indeterminate);
|
||||
/** Adds a recall to the undo stack. */
|
||||
void add_recall(const unit_const_ptr u, const map_location& loc,
|
||||
const map_location& from, int orig_village_owner, bool time_bonus);
|
||||
|
|
|
@ -35,11 +35,11 @@ namespace undo
|
|||
move_action::move_action(const unit_const_ptr moved,
|
||||
const std::vector<map_location>::const_iterator & begin,
|
||||
const std::vector<map_location>::const_iterator & end,
|
||||
int sm, int timebonus, int orig, const map_location::DIRECTION dir)
|
||||
int sm, int timebonus, int orig, const map_location::direction dir)
|
||||
: undo_action()
|
||||
, shroud_clearing_action(moved, begin, end, orig, timebonus != 0)
|
||||
, starting_moves(sm)
|
||||
, starting_dir(dir == map_location::NDIRECTIONS ? moved->facing() : dir)
|
||||
, starting_dir(dir == map_location::direction::indeterminate ? moved->facing() : dir)
|
||||
, goto_hex(moved->get_goto())
|
||||
{
|
||||
}
|
||||
|
|
|
@ -26,16 +26,16 @@ namespace undo
|
|||
struct move_action : undo_action, shroud_clearing_action
|
||||
{
|
||||
int starting_moves;
|
||||
map_location::DIRECTION starting_dir;
|
||||
map_location::direction starting_dir;
|
||||
map_location goto_hex;
|
||||
|
||||
|
||||
move_action(const unit_const_ptr moved,
|
||||
const std::vector<map_location>::const_iterator & begin,
|
||||
const std::vector<map_location>::const_iterator & end,
|
||||
int sm, int timebonus, int orig, const map_location::DIRECTION dir);
|
||||
int sm, int timebonus, int orig, const map_location::direction dir);
|
||||
move_action(const config & cfg, const config & unit_cfg,
|
||||
int sm, const map_location::DIRECTION dir)
|
||||
int sm, const map_location::direction dir)
|
||||
: undo_action(cfg)
|
||||
, shroud_clearing_action(cfg)
|
||||
, starting_moves(sm)
|
||||
|
|
|
@ -757,7 +757,7 @@ void recruitment::show_important_hexes() const {
|
|||
display::get_singleton()->labels().clear_all();
|
||||
for (const map_location& loc : important_hexes_) {
|
||||
// Little hack: use map_location north from loc and make 2 linebreaks to center the "X".
|
||||
display::get_singleton()->labels().set_label(loc.get_direction(map_location::NORTH), "\n\nX");
|
||||
display::get_singleton()->labels().set_label(loc.get_direction(map_location::direction::north), "\n\nX");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
|
|||
|
||||
if( dst_un != units_.end() ) {
|
||||
//there is unit standing at dst, let's try to find free hex to move to
|
||||
const map_location::DIRECTION preferred = destination.get_relative_dir(src);
|
||||
const map_location::direction preferred = destination.get_relative_dir(src);
|
||||
|
||||
int best_rating = 100;//smaller is better
|
||||
const auto adj = get_adjacent_tiles(destination);
|
||||
|
@ -220,10 +220,10 @@ pathfind::plain_route formula_ai::shortest_path_calculator(const map_location &s
|
|||
continue;
|
||||
}
|
||||
|
||||
static const std::size_t NDIRECTIONS = map_location::NDIRECTIONS;
|
||||
unsigned int difference = std::abs(static_cast<int>(preferred - n));
|
||||
if(difference > NDIRECTIONS/2) {
|
||||
difference = NDIRECTIONS - difference;
|
||||
static constexpr std::size_t ndirections = static_cast<int>(map_location::direction::indeterminate);
|
||||
unsigned int difference = std::abs(static_cast<int>(static_cast<int>(preferred) - n));
|
||||
if(difference > ndirections/2) {
|
||||
difference = ndirections - difference;
|
||||
}
|
||||
|
||||
const int rating = difference * 2;
|
||||
|
|
|
@ -196,12 +196,12 @@ void arrow::update_symbols()
|
|||
teleport_out = true;
|
||||
|
||||
// calculate enter and exit directions, if available
|
||||
map_location::DIRECTION enter_dir = map_location::NDIRECTIONS;
|
||||
map_location::direction enter_dir = map_location::direction::indeterminate;
|
||||
if (!start && !teleport_in)
|
||||
{
|
||||
enter_dir = hex->get_relative_dir(*(hex-1));
|
||||
}
|
||||
map_location::DIRECTION exit_dir = map_location::NDIRECTIONS;
|
||||
map_location::direction exit_dir = map_location::direction::indeterminate;
|
||||
if (!end && !teleport_out)
|
||||
{
|
||||
exit_dir = hex->get_relative_dir(*(hex+1));
|
||||
|
@ -211,7 +211,7 @@ void arrow::update_symbols()
|
|||
if (teleport_out)
|
||||
{
|
||||
prefix = "teleport-out";
|
||||
if (enter_dir != map_location::NDIRECTIONS)
|
||||
if (enter_dir != map_location::direction::indeterminate)
|
||||
{
|
||||
suffix = map_location::write_direction(enter_dir);
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ void arrow::update_symbols()
|
|||
else if (teleport_in)
|
||||
{
|
||||
prefix = "teleport-in";
|
||||
if (exit_dir != map_location::NDIRECTIONS)
|
||||
if (exit_dir != map_location::direction::indeterminate)
|
||||
{
|
||||
suffix = map_location::write_direction(exit_dir);
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ void arrow::update_symbols()
|
|||
exit = exit + "_ending";
|
||||
}
|
||||
|
||||
assert(std::abs(enter_dir - exit_dir) > 1); //impossible turn?
|
||||
//assert(std::abs(enter_dir - exit_dir) > 1); //impossible turn?
|
||||
if (enter_dir < exit_dir)
|
||||
{
|
||||
prefix = enter;
|
||||
|
|
|
@ -98,7 +98,7 @@ class editor_action_item_facing : public editor_action_location
|
|||
{
|
||||
public:
|
||||
editor_action_item_facing(
|
||||
map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
|
||||
map_location loc, map_location::direction new_direction, map_location::direction old_direction)
|
||||
: editor_action_location(loc)
|
||||
, new_direction_(new_direction)
|
||||
, old_direction_(old_direction)
|
||||
|
@ -111,8 +111,8 @@ public:
|
|||
const std::string& get_name() const override;
|
||||
|
||||
protected:
|
||||
map_location::DIRECTION new_direction_;
|
||||
map_location::DIRECTION old_direction_;
|
||||
map_location::direction new_direction_;
|
||||
map_location::direction old_direction_;
|
||||
};
|
||||
|
||||
} // end namespace editor
|
||||
|
|
|
@ -92,7 +92,7 @@ class editor_action_unit_facing : public editor_action_location
|
|||
{
|
||||
public:
|
||||
editor_action_unit_facing(
|
||||
map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
|
||||
map_location loc, map_location::direction new_direction, map_location::direction old_direction)
|
||||
: editor_action_location(loc)
|
||||
, new_direction_(new_direction)
|
||||
, old_direction_(old_direction)
|
||||
|
@ -105,8 +105,8 @@ public:
|
|||
const std::string& get_name() const override;
|
||||
|
||||
protected:
|
||||
map_location::DIRECTION new_direction_;
|
||||
map_location::DIRECTION old_direction_;
|
||||
map_location::direction new_direction_;
|
||||
map_location::direction old_direction_;
|
||||
};
|
||||
|
||||
} // end namespace editor
|
||||
|
|
|
@ -668,7 +668,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(const hotkey::ui_comman
|
|||
{
|
||||
unit_map::const_unit_iterator un = get_current_map_context().units().find(gui_->mouseover_hex());
|
||||
assert(un != get_current_map_context().units().end());
|
||||
return un->facing() == index ? ACTION_SELECTED : ACTION_DESELECTED;
|
||||
return un->facing() == map_location::direction{index} ? ACTION_SELECTED : ACTION_DESELECTED;
|
||||
}
|
||||
}
|
||||
return ACTION_ON;
|
||||
|
@ -768,7 +768,7 @@ bool editor_controller::do_execute_command(const hotkey::ui_command& cmd, bool p
|
|||
{
|
||||
unit_map::unit_iterator un = get_current_map_context().units().find(gui_->mouseover_hex());
|
||||
assert(un != get_current_map_context().units().end());
|
||||
un->set_facing(map_location::DIRECTION(index));
|
||||
un->set_facing(map_location::direction(index));
|
||||
un->anim_comp().set_standing();
|
||||
return true;
|
||||
}
|
||||
|
@ -1236,8 +1236,8 @@ void editor_controller::show_menu(const std::vector<config>& items_arg, int xloc
|
|||
active_menu_ = editor::UNIT_FACING;
|
||||
auto pos = items.erase(items.begin());
|
||||
int dir = 0;
|
||||
std::generate_n(std::inserter<std::vector<config>>(items, pos), static_cast<int>(map_location::NDIRECTIONS), [&dir]() -> config {
|
||||
return config {"label", map_location::write_translated_direction(map_location::DIRECTION(dir++))};
|
||||
std::generate_n(std::inserter<std::vector<config>>(items, pos), static_cast<int>(map_location::direction::indeterminate), [&dir]() -> config {
|
||||
return config {"label", map_location::write_translated_direction(map_location::direction(dir++))};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -104,11 +104,11 @@ void map_fragment::rotate_60_cw()
|
|||
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
|
||||
// rotate the X-Y axes to direction::south/direction::south_east - direction::south_west axes
|
||||
// but if x is odd, simply using x/2 + x/2 will lack a step
|
||||
l = l.get_direction(map_location::SOUTH, (x+is_odd(x))/2);
|
||||
l = l.get_direction(map_location::SOUTH_EAST, (x-is_odd(x))/2 );
|
||||
l = l.get_direction(map_location::SOUTH_WEST, y);
|
||||
l = l.get_direction(map_location::direction::south, (x+is_odd(x))/2);
|
||||
l = l.get_direction(map_location::direction::south_east, (x-is_odd(x))/2 );
|
||||
l = l.get_direction(map_location::direction::south_west, y);
|
||||
ti.offset = l;
|
||||
area_.insert(l);
|
||||
}
|
||||
|
@ -124,11 +124,11 @@ void map_fragment::rotate_60_ccw()
|
|||
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'
|
||||
// rotate the X-Y axes to direction::north/direction::north_east - direction::south_east axes'
|
||||
// reverse of what the cw rotation does
|
||||
l = l.get_direction(map_location::NORTH, (x-is_odd(x))/2);
|
||||
l = l.get_direction(map_location::NORTH_EAST, (x+is_odd(x))/2 );
|
||||
l = l.get_direction(map_location::SOUTH_EAST, y);
|
||||
l = l.get_direction(map_location::direction::north, (x-is_odd(x))/2);
|
||||
l = l.get_direction(map_location::direction::north_east, (x+is_odd(x))/2 );
|
||||
l = l.get_direction(map_location::direction::south_east, y);
|
||||
ti.offset = l;
|
||||
area_.insert(l);
|
||||
}
|
||||
|
|
|
@ -502,10 +502,10 @@ std::vector<texture> footsteps_images(const map_location& loc, const pathfind::m
|
|||
}
|
||||
|
||||
// In function of the half, use the incoming or outgoing direction
|
||||
map_location::DIRECTION dir = (i+(h-1))->get_relative_dir(*(i+h));
|
||||
map_location::direction dir = (i+(h-1))->get_relative_dir(*(i+h));
|
||||
|
||||
std::string rotate;
|
||||
if (dir > map_location::SOUTH_EAST) {
|
||||
if (dir > map_location::direction::south_east) {
|
||||
// No image, take the opposite direction and do a 180 rotation
|
||||
dir = i->get_opposite_dir(dir);
|
||||
rotate = "~FL(horiz)~FL(vert)";
|
||||
|
|
|
@ -374,7 +374,7 @@ WML_HANDLER_FUNCTION(move_unit_fake,, cfg)
|
|||
const std::vector<map_location>& path = fake_unit_path(*dummy_unit, xvals, yvals);
|
||||
if (!path.empty()) {
|
||||
// Always scroll.
|
||||
unit_display::move_unit(path, dummy_unit.get_unit_ptr(), true, map_location::NDIRECTIONS, force_scroll);
|
||||
unit_display::move_unit(path, dummy_unit.get_unit_ptr(), true, map_location::direction::indeterminate, force_scroll);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ WML_HANDLER_FUNCTION(move_units_fake,, cfg)
|
|||
DBG_NG << "Moving unit " << un << ", doing step " << step;
|
||||
path_step[0] = paths[un][step - 1];
|
||||
path_step[1] = paths[un][step];
|
||||
unit_display::move_unit(path_step, units[un].get_unit_ptr(), true, map_location::NDIRECTIONS, force_scroll);
|
||||
unit_display::move_unit(path_step, units[un].get_unit_ptr(), true, map_location::direction::indeterminate, force_scroll);
|
||||
units[un]->set_location(path_step[1]);
|
||||
units[un]->anim_comp().set_standing(false);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
inline bool is_shrouded(const display* disp, const map_location& loc)
|
||||
{
|
||||
return disp->shrouded(loc) || disp->shrouded(loc.get_direction(map_location::SOUTH));
|
||||
return disp->shrouded(loc) || disp->shrouded(loc.get_direction(map_location::direction::south));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,8 +535,8 @@ void terrain_label::recalculate()
|
|||
}
|
||||
|
||||
// Note: the y part of loc_nextx is not used at all.
|
||||
const map_location loc_nextx = loc_.get_direction(map_location::NORTH_EAST);
|
||||
const map_location loc_nexty = loc_.get_direction(map_location::SOUTH);
|
||||
const map_location loc_nextx = loc_.get_direction(map_location::direction::north_east);
|
||||
const map_location loc_nexty = loc_.get_direction(map_location::direction::south);
|
||||
const int xloc = (disp->get_location_x(loc_) + disp->get_location_x(loc_nextx) * 2) / 3;
|
||||
const int yloc = disp->get_location_y(loc_nexty) - scale_to_map_zoom(font::SIZE_NORMAL);
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ map_location::map_location(const config_attribute_value& x, const config_attribu
|
|||
* Default list of directions
|
||||
*
|
||||
**/
|
||||
const std::vector<map_location::DIRECTION> & map_location::default_dirs() {
|
||||
static const std::vector<map_location::DIRECTION> dirs {map_location::NORTH,
|
||||
map_location::NORTH_EAST, map_location::SOUTH_EAST, map_location::SOUTH,
|
||||
map_location::SOUTH_WEST, map_location::NORTH_WEST};
|
||||
const std::vector<map_location::direction> & map_location::default_dirs() {
|
||||
static const std::vector<map_location::direction> dirs {map_location::direction::north,
|
||||
map_location::direction::north_east, map_location::direction::south_east, map_location::direction::south,
|
||||
map_location::direction::south_west, map_location::direction::north_west};
|
||||
return dirs;
|
||||
}
|
||||
|
||||
|
@ -67,10 +67,10 @@ std::size_t hash_value(const map_location& a){
|
|||
}
|
||||
|
||||
|
||||
map_location::DIRECTION map_location::parse_direction(const std::string& str)
|
||||
map_location::direction map_location::parse_direction(const std::string& str)
|
||||
{
|
||||
if(str.empty()) {
|
||||
return NDIRECTIONS;
|
||||
return direction::indeterminate;
|
||||
}
|
||||
|
||||
// Syntax: [-] (n|ne|se|s|sw|nw) [:cw|:ccw]
|
||||
|
@ -81,7 +81,7 @@ map_location::DIRECTION map_location::parse_direction(const std::string& str)
|
|||
const std::size_t open = str.find_first_of('('), close = str.find_last_of(')');
|
||||
if (open != std::string::npos && close != std::string::npos) {
|
||||
std::string sub = str.substr(open + 1, close - open - 1);
|
||||
map_location::DIRECTION dir = parse_direction(sub);
|
||||
map_location::direction dir = parse_direction(sub);
|
||||
sub = str;
|
||||
sub.replace(open, close - open + 1, write_direction(dir));
|
||||
return parse_direction(sub);
|
||||
|
@ -90,22 +90,22 @@ map_location::DIRECTION map_location::parse_direction(const std::string& str)
|
|||
const std::size_t start = str[0] == '-' ? 1 : 0;
|
||||
const std::size_t end = str.find_first_of(':');
|
||||
const std::string& main_dir = str.substr(start, end - start);
|
||||
map_location::DIRECTION dir;
|
||||
map_location::direction dir;
|
||||
|
||||
if (main_dir == "n") {
|
||||
dir = NORTH;
|
||||
dir = direction::north;
|
||||
} else if (main_dir == "ne") {
|
||||
dir = NORTH_EAST;
|
||||
dir = direction::north_east;
|
||||
} else if (main_dir == "se") {
|
||||
dir = SOUTH_EAST;
|
||||
dir = direction::south_east;
|
||||
} else if (main_dir == "s") {
|
||||
dir = SOUTH;
|
||||
dir = direction::south;
|
||||
} else if (main_dir == "sw") {
|
||||
dir = SOUTH_WEST;
|
||||
dir = direction::south_west;
|
||||
} else if (main_dir == "nw") {
|
||||
dir = NORTH_WEST;
|
||||
dir = direction::north_west;
|
||||
} else {
|
||||
return NDIRECTIONS;
|
||||
return direction::indeterminate;
|
||||
}
|
||||
|
||||
if (start == 1) {
|
||||
|
@ -119,43 +119,43 @@ map_location::DIRECTION map_location::parse_direction(const std::string& str)
|
|||
} else if (rel_dir == "ccw") {
|
||||
dir = rotate_right(dir, -1);
|
||||
} else {
|
||||
return NDIRECTIONS;
|
||||
return direction::indeterminate;
|
||||
}
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
std::vector<map_location::DIRECTION> map_location::parse_directions(const std::string& str)
|
||||
std::vector<map_location::direction> map_location::parse_directions(const std::string& str)
|
||||
{
|
||||
map_location::DIRECTION temp;
|
||||
std::vector<map_location::DIRECTION> to_return;
|
||||
map_location::direction temp;
|
||||
std::vector<map_location::direction> to_return;
|
||||
std::vector<std::string> dir_strs = utils::split(str);
|
||||
std::vector<std::string>::const_iterator i, i_end=dir_strs.end();
|
||||
for(i = dir_strs.begin(); i != i_end; ++i) {
|
||||
temp = map_location::parse_direction(*i);
|
||||
// Filter out any invalid directions
|
||||
if(temp != NDIRECTIONS) {
|
||||
if(temp != direction::indeterminate) {
|
||||
to_return.push_back(temp);
|
||||
}
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
|
||||
std::string map_location::write_direction(map_location::DIRECTION dir)
|
||||
std::string map_location::write_direction(map_location::direction dir)
|
||||
{
|
||||
switch(dir) {
|
||||
case NORTH:
|
||||
case direction::north:
|
||||
return std::string("n");
|
||||
case NORTH_EAST:
|
||||
case direction::north_east:
|
||||
return std::string("ne");
|
||||
case NORTH_WEST:
|
||||
case direction::north_west:
|
||||
return std::string("nw");
|
||||
case SOUTH:
|
||||
case direction::south:
|
||||
return std::string("s");
|
||||
case SOUTH_EAST:
|
||||
case direction::south_east:
|
||||
return std::string("se");
|
||||
case SOUTH_WEST:
|
||||
case direction::south_west:
|
||||
return std::string("sw");
|
||||
default:
|
||||
return std::string();
|
||||
|
@ -163,20 +163,20 @@ std::string map_location::write_direction(map_location::DIRECTION dir)
|
|||
}
|
||||
}
|
||||
|
||||
std::string map_location::write_translated_direction(map_location::DIRECTION dir)
|
||||
std::string map_location::write_translated_direction(map_location::direction dir)
|
||||
{
|
||||
switch(dir) {
|
||||
case NORTH:
|
||||
case direction::north:
|
||||
return _("North");
|
||||
case NORTH_EAST:
|
||||
case direction::north_east:
|
||||
return _("North East");
|
||||
case NORTH_WEST:
|
||||
case direction::north_west:
|
||||
return _("North West");
|
||||
case SOUTH:
|
||||
case direction::south:
|
||||
return _("South");
|
||||
case SOUTH_EAST:
|
||||
case direction::south_east:
|
||||
return _("South East");
|
||||
case SOUTH_WEST:
|
||||
case direction::south_west:
|
||||
return _("South West");
|
||||
default:
|
||||
return std::string();
|
||||
|
@ -223,37 +223,37 @@ static bool is_vertically_higher_than ( const map_location & m1, const map_locat
|
|||
return (is_odd(m1.wml_x()) && is_even(m2.wml_x())) ? (m1.wml_y() <= m2.wml_y()) : (m1.wml_y() < m2.wml_y());
|
||||
}
|
||||
|
||||
map_location::DIRECTION map_location::get_relative_dir(const map_location & loc) const
|
||||
map_location::direction map_location::get_relative_dir(const map_location & loc) const
|
||||
{
|
||||
return get_relative_dir(loc, map_location::RADIAL_SYMMETRY);
|
||||
}
|
||||
|
||||
map_location::DIRECTION map_location::get_relative_dir(const map_location & loc, map_location::RELATIVE_DIR_MODE opt) const
|
||||
map_location::direction map_location::get_relative_dir(const map_location & loc, map_location::RELATIVE_DIR_MODE opt) const
|
||||
{
|
||||
if (opt == map_location::DEFAULT) {
|
||||
map_location::DIRECTION dir = NDIRECTIONS;
|
||||
map_location::direction dir = direction::indeterminate;
|
||||
|
||||
int dx = loc.x - x;
|
||||
int dy = loc.y - y;
|
||||
if (loc.x%2==0 && x%2==1) dy--;
|
||||
|
||||
if (dx==0 && dy==0) return NDIRECTIONS;
|
||||
if (dx==0 && dy==0) return direction::indeterminate;
|
||||
|
||||
int dist = std::abs(dx); // Distance from north-south line
|
||||
int dist_diag_SW_NE = std::abs(dy + (dx + (dy>0?0:1) )/2); // Distance from diagonal line SW-NE
|
||||
int dist_diag_SE_NW = std::abs(dy - (dx - (dy>0?0:1) )/2); // Distance from diagonal line SE-NW
|
||||
|
||||
if (dy > 0) dir = SOUTH;
|
||||
else dir = NORTH;
|
||||
if (dy > 0) dir = direction::south;
|
||||
else dir = direction::north;
|
||||
|
||||
if (dist_diag_SE_NW < dist) {
|
||||
if (dx>0) dir = SOUTH_EAST;
|
||||
else dir = NORTH_WEST;
|
||||
if (dx>0) dir = direction::south_east;
|
||||
else dir = direction::north_west;
|
||||
dist = dist_diag_SE_NW;
|
||||
}
|
||||
if (dist_diag_SW_NE < dist) {
|
||||
if (dx>0) dir = NORTH_EAST;
|
||||
else dir = SOUTH_WEST;
|
||||
if (dx>0) dir = direction::north_east;
|
||||
else dir = direction::south_west;
|
||||
}
|
||||
return dir;
|
||||
} else {
|
||||
|
@ -262,29 +262,29 @@ map_location::DIRECTION map_location::get_relative_dir(const map_location & loc,
|
|||
if (is_vertically_higher_than(temp,*this)) {
|
||||
temp = temp.rotate_right_around_center(*this,1u);
|
||||
if (!is_vertically_higher_than(temp,*this)) {
|
||||
return map_location::NORTH_EAST;
|
||||
return map_location::direction::north_east;
|
||||
}
|
||||
temp = temp.rotate_right_around_center(*this,1u);
|
||||
if (!is_vertically_higher_than(temp,*this)) {
|
||||
return map_location::NORTH;
|
||||
return map_location::direction::north;
|
||||
}
|
||||
return map_location::NORTH_WEST;
|
||||
return map_location::direction::north_west;
|
||||
} else if (is_vertically_higher_than(*this,temp)) {
|
||||
temp = temp.rotate_right_around_center(*this,1u);
|
||||
if (!is_vertically_higher_than(*this,temp)) {
|
||||
return map_location::SOUTH_WEST;
|
||||
return map_location::direction::south_west;
|
||||
}
|
||||
temp = temp.rotate_right_around_center(*this,1u);
|
||||
if (!is_vertically_higher_than(*this,temp)) {
|
||||
return map_location::SOUTH;
|
||||
return map_location::direction::south;
|
||||
}
|
||||
return map_location::SOUTH_EAST;
|
||||
return map_location::direction::south_east;
|
||||
} else if (temp.x > x) {
|
||||
return map_location::SOUTH_EAST;
|
||||
return map_location::direction::south_east;
|
||||
} else if (temp.x < x) {
|
||||
return map_location::NORTH_WEST;
|
||||
return map_location::direction::north_west;
|
||||
} else {
|
||||
return map_location::NDIRECTIONS;
|
||||
return map_location::direction::indeterminate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -352,23 +352,23 @@ bool map_location::matches_range(const std::string& xloc, const std::string &ylo
|
|||
return false;
|
||||
}
|
||||
|
||||
map_location map_location::get_direction(map_location::DIRECTION dir, unsigned int n) const
|
||||
map_location map_location::get_direction(map_location::direction dir, unsigned int n) const
|
||||
{
|
||||
if (dir == map_location::NDIRECTIONS) {
|
||||
if (dir == map_location::direction::indeterminate) {
|
||||
return map_location::null_location();
|
||||
}
|
||||
|
||||
if (dir == NORTH) {
|
||||
if (dir == direction::north) {
|
||||
return map_location(x,y-n);
|
||||
}
|
||||
|
||||
if (dir == SOUTH) {
|
||||
if (dir == direction::south) {
|
||||
return map_location(x,y+n);
|
||||
}
|
||||
|
||||
int x_factor = (static_cast<unsigned int> (dir) <= 2u) ? 1 : -1; //whether we go east + or west -
|
||||
|
||||
unsigned int tmp_y = dir - 2; //South East => 0, South => 1, South West => 2, North West => 3, North => INT_MAX, North East => INT_MAX - 1
|
||||
unsigned int tmp_y = static_cast<unsigned int> (dir) - 2; //South East => 0, South => 1, South West => 2, North West => 3, North => INT_MAX, North East => INT_MAX - 1
|
||||
int y_factor = (tmp_y <= 2u) ? 1 : -1; //whether we go south + or north -
|
||||
|
||||
if (tmp_y <= 2u) {
|
||||
|
@ -379,12 +379,12 @@ map_location map_location::get_direction(map_location::DIRECTION dir, unsigned i
|
|||
|
||||
/*
|
||||
switch(dir) {
|
||||
case NORTH: return map_location(x, y - n);
|
||||
case SOUTH: return map_location(x, y + n);
|
||||
case SOUTH_EAST: return map_location(x + n, y + (n+is_odd(x))/2 );
|
||||
case SOUTH_WEST: return map_location(x - n, y + (n+is_odd(x))/2 );
|
||||
case NORTH_EAST: return map_location(x + n, y - (n+is_even(x))/2 );
|
||||
case NORTH_WEST: return map_location(x - n, y - (n+is_even(x))/2 );
|
||||
case direction::north: return map_location(x, y - n);
|
||||
case direction::south: return map_location(x, y + n);
|
||||
case direction::south_east: return map_location(x + n, y + (n+is_odd(x))/2 );
|
||||
case direction::south_west: return map_location(x - n, y + (n+is_odd(x))/2 );
|
||||
case direction::north_east: return map_location(x + n, y - (n+is_even(x))/2 );
|
||||
case direction::north_west: return map_location(x - n, y - (n+is_even(x))/2 );
|
||||
default:
|
||||
assert(false);
|
||||
return map_location::null_location();
|
||||
|
|
|
@ -44,35 +44,42 @@ struct cubic_location {
|
|||
/** Represents a location on the map. */
|
||||
struct map_location {
|
||||
/** Valid directions which can be moved in our hexagonal world. */
|
||||
enum DIRECTION { NORTH=0, NORTH_EAST=1, SOUTH_EAST=2, SOUTH=3,
|
||||
SOUTH_WEST=4, NORTH_WEST=5, NDIRECTIONS=6 };
|
||||
enum class direction {
|
||||
north,
|
||||
north_east,
|
||||
south_east,
|
||||
south,
|
||||
south_west,
|
||||
north_west,
|
||||
indeterminate
|
||||
};
|
||||
|
||||
static const std::vector<DIRECTION> & default_dirs();
|
||||
static const std::vector<direction> & default_dirs();
|
||||
|
||||
static DIRECTION rotate_right(DIRECTION d, unsigned int k = 1u)
|
||||
static direction rotate_right(direction d, unsigned int k = 1u)
|
||||
{
|
||||
return (d == map_location::NDIRECTIONS) ? map_location::NDIRECTIONS : static_cast<map_location::DIRECTION>((d + (k%6u)) % 6u);
|
||||
return d == direction::indeterminate ? direction::indeterminate : direction{(static_cast<int>(d) + (k % 6u)) % 6u};
|
||||
}
|
||||
|
||||
static DIRECTION rotate_right(DIRECTION d, signed int k)
|
||||
static direction rotate_right(direction d, signed int k)
|
||||
{
|
||||
return (k>=0) ? rotate_right(d, static_cast<unsigned int> (k)) : rotate_right(d, (static_cast<unsigned int>(-k) % 6u) * 5u);
|
||||
}
|
||||
|
||||
static DIRECTION get_opposite_dir(DIRECTION d)
|
||||
static direction get_opposite_dir(direction d)
|
||||
{
|
||||
return rotate_right(d,3u);
|
||||
}
|
||||
|
||||
static DIRECTION parse_direction(const std::string& str);
|
||||
static direction parse_direction(const std::string& str);
|
||||
|
||||
/**
|
||||
* Parse_directions takes a comma-separated list, and filters out any
|
||||
* invalid directions
|
||||
*/
|
||||
static std::vector<DIRECTION> parse_directions(const std::string& str);
|
||||
static std::string write_direction(DIRECTION dir);
|
||||
static std::string write_translated_direction(DIRECTION dir);
|
||||
static std::vector<direction> parse_directions(const std::string& str);
|
||||
static std::string write_direction(direction dir);
|
||||
static std::string write_translated_direction(direction dir);
|
||||
|
||||
map_location() : x(-1000), y(-1000) {}
|
||||
map_location(int x, int y) : x(x), y(y) {}
|
||||
|
@ -140,15 +147,15 @@ struct map_location {
|
|||
}
|
||||
|
||||
// Do n step in the direction d
|
||||
map_location get_direction(DIRECTION dir, unsigned int n = 1u) const;
|
||||
map_location get_direction(DIRECTION dir, signed int n) const
|
||||
map_location get_direction(direction dir, unsigned int n = 1u) const;
|
||||
map_location get_direction(direction dir, signed int n) const
|
||||
{
|
||||
return (n >= 0) ? get_direction(dir, static_cast<unsigned int> (n)) : get_direction(get_opposite_dir(dir), static_cast<unsigned int> (-n));
|
||||
}
|
||||
|
||||
enum RELATIVE_DIR_MODE { DEFAULT , RADIAL_SYMMETRY };
|
||||
DIRECTION get_relative_dir(const map_location & loc, map_location::RELATIVE_DIR_MODE mode /*= map_location::RADIAL_SYMMETRY*/ ) const;
|
||||
DIRECTION get_relative_dir(const map_location & loc) const; //moved the default setting to .cpp file for ease of testing
|
||||
direction get_relative_dir(const map_location & loc, map_location::RELATIVE_DIR_MODE mode /*= map_location::RADIAL_SYMMETRY*/ ) const;
|
||||
direction get_relative_dir(const map_location & loc) const; //moved the default setting to .cpp file for ease of testing
|
||||
|
||||
cubic_location to_cubic() const {
|
||||
int q = x;
|
||||
|
|
|
@ -754,8 +754,8 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
}
|
||||
}
|
||||
|
||||
const map_location::DIRECTION preferred = loc.get_relative_dir(previous_hex_);
|
||||
const map_location::DIRECTION second_preferred = loc.get_relative_dir(previous_free_hex_);
|
||||
const map_location::direction preferred = loc.get_relative_dir(previous_hex_);
|
||||
const map_location::direction second_preferred = loc.get_relative_dir(previous_free_hex_);
|
||||
|
||||
int best_rating = 100; // smaller is better
|
||||
|
||||
|
@ -772,16 +772,16 @@ map_location mouse_handler::current_unit_attacks_from(const map_location& loc) c
|
|||
}
|
||||
|
||||
if(current_paths_.destinations.contains(adj[n])) {
|
||||
static const std::size_t NDIRECTIONS = map_location::NDIRECTIONS;
|
||||
static const std::size_t ndirections = static_cast<int>(map_location::direction::indeterminate);
|
||||
|
||||
unsigned int difference = std::abs(static_cast<int>(preferred - n));
|
||||
if(difference > NDIRECTIONS / 2) {
|
||||
difference = NDIRECTIONS - difference;
|
||||
unsigned int difference = std::abs(static_cast<int>(static_cast<int>(preferred) - n));
|
||||
if(difference > ndirections / 2) {
|
||||
difference = ndirections - difference;
|
||||
}
|
||||
|
||||
unsigned int second_difference = std::abs(static_cast<int>(second_preferred - n));
|
||||
if(second_difference > NDIRECTIONS / 2) {
|
||||
second_difference = NDIRECTIONS - second_difference;
|
||||
unsigned int second_difference = std::abs(static_cast<int>(static_cast<int>(second_preferred) - n));
|
||||
if(second_difference > ndirections / 2) {
|
||||
second_difference = ndirections - second_difference;
|
||||
}
|
||||
|
||||
const int rating = difference * 2 + (second_difference > difference);
|
||||
|
|
|
@ -36,10 +36,10 @@ void get_tile_ring(const map_location& center, const int radius,
|
|||
return;
|
||||
}
|
||||
|
||||
map_location loc = center.get_direction(map_location::SOUTH_WEST, radius);
|
||||
map_location loc = center.get_direction(map_location::direction::south_west, radius);
|
||||
|
||||
for(int n = 0; n != 6; ++n) {
|
||||
const map_location::DIRECTION dir = static_cast<map_location::DIRECTION>(n);
|
||||
const map_location::direction dir{ n };
|
||||
for(int i = 0; i != radius; ++i) {
|
||||
result.push_back(loc);
|
||||
loc = loc.get_direction(dir, 1);
|
||||
|
@ -99,10 +99,14 @@ namespace { // Helpers for get_tiles_radius() without a radius filter.
|
|||
const std::size_t radius,
|
||||
const int col_begin, const int col_end)
|
||||
{
|
||||
#ifdef __cpp_using_enum // c++20
|
||||
using enum map_location::direction;
|
||||
#else
|
||||
// Shorter names for the directions we'll use.
|
||||
const map_location::DIRECTION NORTH_WEST = map_location::NORTH_WEST;
|
||||
const map_location::DIRECTION NORTH_EAST = map_location::NORTH_EAST;
|
||||
const map_location::DIRECTION SOUTH_EAST = map_location::SOUTH_EAST;
|
||||
const map_location::direction north_west = map_location::direction::north_west;
|
||||
const map_location::direction north_east = map_location::direction::north_east;
|
||||
const map_location::direction south_east = map_location::direction::south_east;
|
||||
#endif
|
||||
|
||||
// Perform this conversion once.
|
||||
const int radius_i = static_cast<int>(radius);
|
||||
|
@ -112,28 +116,28 @@ namespace { // Helpers for get_tiles_radius() without a radius filter.
|
|||
{
|
||||
// Calculate the circle of hexes around this one.
|
||||
std::size_t height = radius;
|
||||
map_location top = loc.get_direction(NORTH_WEST, radius_i);
|
||||
map_location top = loc.get_direction(north_west, radius_i);
|
||||
// Don't start off the map edge.
|
||||
if ( top.x < col_begin ) {
|
||||
const int col_shift = std::min(col_begin, loc.x) - top.x;
|
||||
top = top.get_direction(NORTH_EAST, col_shift);
|
||||
top = top.get_direction(north_east, col_shift);
|
||||
height += col_shift;
|
||||
}
|
||||
// The left side.
|
||||
const int end_l = std::min(loc.x, col_end);
|
||||
for ( ; top.x < end_l; top = top.get_direction(NORTH_EAST, 1) )
|
||||
for ( ; top.x < end_l; top = top.get_direction(north_east, 1) )
|
||||
collected_tiles[top.x].insert(row_range(top.y, ++height));
|
||||
// Extra increment so the middle column is tall enough.
|
||||
height += 2;
|
||||
// Don't start off the map edge (we allow loc to be off-board).
|
||||
if ( top.x < col_begin ) {
|
||||
const int col_shift = col_begin - top.x;
|
||||
top = top.get_direction(SOUTH_EAST, col_shift);
|
||||
top = top.get_direction(south_east, col_shift);
|
||||
height -= col_shift;
|
||||
}
|
||||
// The middle column and right side.
|
||||
const int end_r = std::min(loc.x + radius_i + 1, col_end);
|
||||
for ( ; top.x < end_r; top = top.get_direction(SOUTH_EAST, 1) )
|
||||
for ( ; top.x < end_r; top = top.get_direction(south_east, 1) )
|
||||
collected_tiles[top.x].insert(row_range(top.y, --height));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ int intf_get_direction(lua_State* L)
|
|||
lua_pop(L,1);
|
||||
}
|
||||
|
||||
map_location::DIRECTION d;
|
||||
map_location::direction d;
|
||||
if (lua_isstring(L, -1)) {
|
||||
d = map_location::parse_direction(luaL_checkstring(L,-1));
|
||||
lua_pop(L,1);
|
||||
|
|
|
@ -139,7 +139,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(recall, child, use_undo, show, error_handler)
|
|||
map_location loc(child, resources::gamedata);
|
||||
map_location from(child.child_or_empty("from"), resources::gamedata);
|
||||
|
||||
if ( !actions::recall_unit(unit_id, current_team, loc, from, map_location::NDIRECTIONS, show, use_undo) ) {
|
||||
if ( !actions::recall_unit(unit_id, current_team, loc, from, map_location::direction::indeterminate, show, use_undo) ) {
|
||||
error_handler("illegal recall: unit_id '" + unit_id + "' could not be found within the recall list.\n");
|
||||
//when recall_unit returned false nothing happened so we can safety return false;
|
||||
return false;
|
||||
|
|
|
@ -212,11 +212,11 @@ bool terrain_filter::match_internal(const map_location& loc, const unit* ref_uni
|
|||
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;
|
||||
std::vector<map_location::DIRECTION> dirs = (*i).has_attribute("adjacent")
|
||||
std::vector<map_location::direction> dirs = (*i).has_attribute("adjacent")
|
||||
? map_location::parse_directions((*i)["adjacent"]) : map_location::default_dirs();
|
||||
std::vector<map_location::DIRECTION>::const_iterator j, j_end = dirs.end();
|
||||
std::vector<map_location::direction>::const_iterator j, j_end = dirs.end();
|
||||
for (j = dirs.begin(); j != j_end; ++j) {
|
||||
const map_location &adj = adjacent[*j];
|
||||
const map_location &adj = adjacent[static_cast<int>(*j)];
|
||||
if (fc_->get_disp_context().map().on_board(adj)) {
|
||||
if(cache_.adjacent_matches == nullptr) {
|
||||
while(index >= std::distance(cache_.adjacent_match_cache.begin(), cache_.adjacent_match_cache.end())) {
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
|
||||
static std::vector<map_location> preset_locs;
|
||||
static map_location va,vb,vc,vz,vt1,vt2,vt3,vs1,vs2,vs3,vs4;
|
||||
static map_location::DIRECTION n = map_location::NORTH;
|
||||
static map_location::DIRECTION ne = map_location::NORTH_EAST;
|
||||
static map_location::DIRECTION nw = map_location::NORTH_WEST;
|
||||
static map_location::DIRECTION s = map_location::SOUTH;
|
||||
static map_location::DIRECTION se = map_location::SOUTH_EAST;
|
||||
static map_location::DIRECTION sw = map_location::SOUTH_WEST;
|
||||
static map_location::direction n = map_location::direction::north;
|
||||
static map_location::direction ne = map_location::direction::north_east;
|
||||
static map_location::direction nw = map_location::direction::north_west;
|
||||
static map_location::direction s = map_location::direction::south;
|
||||
static map_location::direction se = map_location::direction::south_east;
|
||||
static map_location::direction sw = map_location::direction::south_west;
|
||||
|
||||
|
||||
struct MLFixture
|
||||
|
@ -76,11 +76,11 @@ static map_location vector_difference(const map_location & v1, const map_locatio
|
|||
}
|
||||
#endif
|
||||
|
||||
static void characterization_distance_direction (const std::vector<map_location> & locs, const std::vector<map_location::DIRECTION> & dir_answers, const std::vector<std::size_t> & int_answers, map_location::RELATIVE_DIR_MODE mode)
|
||||
static void characterization_distance_direction (const std::vector<map_location> & locs, const std::vector<map_location::direction> & dir_answers, const std::vector<std::size_t> & int_answers, map_location::RELATIVE_DIR_MODE mode)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(dir_answers.size(), int_answers.size());
|
||||
|
||||
std::vector<map_location::DIRECTION>::const_iterator dir_it = dir_answers.begin();
|
||||
std::vector<map_location::direction>::const_iterator dir_it = dir_answers.begin();
|
||||
std::vector<std::size_t>::const_iterator int_it = int_answers.begin();
|
||||
|
||||
for (std::vector<map_location>::const_iterator it_a = locs.begin(); it_a != locs.end(); ++it_a) {
|
||||
|
@ -92,7 +92,7 @@ static void characterization_distance_direction (const std::vector<map_location>
|
|||
<< map_location::write_direction( a.get_relative_dir(b,mode)) << "\"))" << std::endl;
|
||||
#else
|
||||
int expected_dist = *(int_it++);
|
||||
map_location::DIRECTION expected_dir = *(dir_it++);
|
||||
map_location::direction expected_dir = *(dir_it++);
|
||||
BOOST_CHECK_EQUAL( expected_dist, distance_between(a,b) );
|
||||
BOOST_CHECK_EQUAL( expected_dist, distance_between(b,a) );
|
||||
BOOST_CHECK_EQUAL( expected_dir, a.get_relative_dir(b, mode) );
|
||||
|
@ -127,7 +127,7 @@ static void characterization_distance_direction (const std::vector<map_location>
|
|||
}
|
||||
|
||||
static std::size_t get_first (std::pair<std::size_t, std::string> arg) {return arg.first; }
|
||||
static map_location::DIRECTION get_second (std::pair<std::size_t, std::string> arg) {return map_location::parse_direction(arg.second); }
|
||||
static map_location::direction get_second (std::pair<std::size_t, std::string> arg) {return map_location::parse_direction(arg.second); }
|
||||
|
||||
/* This has to be recomputed, I'm commenting out the test so that it doesn't fail in the meantime. --iceiceice
|
||||
|
||||
|
@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE ( map_location_characterization_test_default_mode )
|
|||
(std::make_pair(1, "sw")).to_container(generated_answers);
|
||||
|
||||
std::vector<std::size_t> ans1;
|
||||
std::vector<map_location::DIRECTION> ans2;
|
||||
std::vector<map_location::direction> ans2;
|
||||
std::transform(generated_answers.begin(), generated_answers.end(), back_inserter(ans1), &get_first);
|
||||
std::transform(generated_answers.begin(), generated_answers.end(), back_inserter(ans2), &get_second);
|
||||
|
||||
|
@ -257,14 +257,14 @@ std::make_pair(3, "s"),
|
|||
std::make_pair(1, "nw")};
|
||||
|
||||
std::vector<std::size_t> ans1;
|
||||
std::vector<map_location::DIRECTION> ans2;
|
||||
std::vector<map_location::direction> ans2;
|
||||
std::transform(generated_answers.begin(), generated_answers.end(), back_inserter(ans1), &get_first);
|
||||
std::transform(generated_answers.begin(), generated_answers.end(), back_inserter(ans2), &get_second);
|
||||
|
||||
characterization_distance_direction(preset_locs, ans2, ans1, map_location::RADIAL_SYMMETRY);
|
||||
}
|
||||
|
||||
static std::pair<map_location , map_location> mirror_walk( std::pair<map_location,map_location> p, map_location::DIRECTION d)
|
||||
static std::pair<map_location , map_location> mirror_walk( std::pair<map_location,map_location> p, map_location::direction d)
|
||||
{
|
||||
p.first = p.first.get_direction(d);
|
||||
p.second = p.second.get_direction(map_location::get_opposite_dir(d));
|
||||
|
@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE ( reality_check_vector_negation )
|
|||
p = mirror_walk(p, sw);
|
||||
}
|
||||
|
||||
static void reality_check_get_direction_helper(const map_location & loc, const map_location::DIRECTION d)
|
||||
static void reality_check_get_direction_helper(const map_location & loc, const map_location::direction d)
|
||||
{
|
||||
map_location lz(vz.get_direction(d));
|
||||
|
||||
|
@ -322,58 +322,58 @@ BOOST_AUTO_TEST_CASE ( reality_check_get_direction )
|
|||
reality_check_get_direction_helper(b,se);
|
||||
}
|
||||
|
||||
static map_location::DIRECTION legacy_get_opposite_dir(map_location::DIRECTION d)
|
||||
static map_location::direction legacy_get_opposite_dir(map_location::direction d)
|
||||
{
|
||||
switch (d) {
|
||||
case map_location::NORTH:
|
||||
return map_location::SOUTH;
|
||||
case map_location::NORTH_EAST:
|
||||
return map_location::SOUTH_WEST;
|
||||
case map_location::SOUTH_EAST:
|
||||
return map_location::NORTH_WEST;
|
||||
case map_location::SOUTH:
|
||||
return map_location::NORTH;
|
||||
case map_location::SOUTH_WEST:
|
||||
return map_location::NORTH_EAST;
|
||||
case map_location::NORTH_WEST:
|
||||
return map_location::SOUTH_EAST;
|
||||
case map_location::NDIRECTIONS:
|
||||
case map_location::direction::north:
|
||||
return map_location::direction::south;
|
||||
case map_location::direction::north_east:
|
||||
return map_location::direction::south_west;
|
||||
case map_location::direction::south_east:
|
||||
return map_location::direction::north_west;
|
||||
case map_location::direction::south:
|
||||
return map_location::direction::north;
|
||||
case map_location::direction::south_west:
|
||||
return map_location::direction::north_east;
|
||||
case map_location::direction::north_west:
|
||||
return map_location::direction::south_east;
|
||||
case map_location::direction::indeterminate:
|
||||
default:
|
||||
return map_location::NDIRECTIONS;
|
||||
return map_location::direction::indeterminate;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( check_get_opposite_dir_refactor )
|
||||
{
|
||||
for (unsigned int i = 0; i < 7; i++ ) {
|
||||
map_location::DIRECTION d = static_cast<map_location::DIRECTION> (i);
|
||||
map_location::direction d = static_cast<map_location::direction> (i);
|
||||
BOOST_CHECK_EQUAL ( map_location::get_opposite_dir(d), legacy_get_opposite_dir(d) );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE ( check_rotate )
|
||||
{
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::NORTH) , map_location::NORTH_EAST );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::NORTH_EAST,-1) , map_location::NORTH);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::north) , map_location::direction::north_east );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::north_east,-1) , map_location::direction::north);
|
||||
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::NORTH_EAST) , map_location::SOUTH_EAST );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::SOUTH_EAST,-1) , map_location::NORTH_EAST );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::north_east) , map_location::direction::south_east );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::south_east,-1) , map_location::direction::north_east );
|
||||
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::SOUTH_EAST) , map_location::SOUTH );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::SOUTH, -1) , map_location::SOUTH_EAST );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::south_east) , map_location::direction::south );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::south, -1) , map_location::direction::south_east );
|
||||
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::SOUTH), map_location::SOUTH_WEST);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::SOUTH_WEST,-1) , map_location::SOUTH );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::south), map_location::direction::south_west);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::south_west,-1) , map_location::direction::south );
|
||||
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::SOUTH_WEST), map_location::NORTH_WEST);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::NORTH_WEST,-1) , map_location::SOUTH_WEST );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::south_west), map_location::direction::north_west);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::north_west,-1) , map_location::direction::south_west );
|
||||
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::NORTH_WEST), map_location::NORTH);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::NORTH,-1) , map_location::NORTH_WEST );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::north_west), map_location::direction::north);
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(map_location::direction::north,-1) , map_location::direction::north_west );
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < 7; i++ ) {
|
||||
map_location::DIRECTION d = static_cast<map_location::DIRECTION> (i);
|
||||
map_location::direction d = static_cast<map_location::direction> (i);
|
||||
BOOST_CHECK_EQUAL ( map_location::get_opposite_dir(d), map_location::rotate_right(d,3) );
|
||||
BOOST_CHECK_EQUAL ( map_location::rotate_right(d,-2), map_location::rotate_right(d,4) );
|
||||
}
|
||||
|
@ -408,15 +408,15 @@ BOOST_AUTO_TEST_CASE ( check_rotate_around_center )
|
|||
*/
|
||||
|
||||
/*
|
||||
static std::string dir_to_terrain (const map_location::DIRECTION dir)
|
||||
static std::string dir_to_terrain (const map_location::direction dir)
|
||||
{
|
||||
switch(dir) {
|
||||
case map_location::NORTH: return "Gg";
|
||||
case map_location::SOUTH: return "Ai";
|
||||
case map_location::SOUTH_EAST: return "Gs^Fp";
|
||||
case map_location::SOUTH_WEST: return "Ss";
|
||||
case map_location::NORTH_EAST: return "Hd";
|
||||
case map_location::NORTH_WEST: return "Md";
|
||||
case map_location::direction::north: return "Gg";
|
||||
case map_location::direction::south: return "Ai";
|
||||
case map_location::direction::south_east: return "Gs^Fp";
|
||||
case map_location::direction::south_west: return "Ss";
|
||||
case map_location::direction::north_east: return "Hd";
|
||||
case map_location::direction::north_west: return "Md";
|
||||
default: return "Xv";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ static lg::log_domain log_wml("wml");
|
|||
namespace {
|
||||
class temporary_facing
|
||||
{
|
||||
map_location::DIRECTION save_dir_;
|
||||
map_location::direction save_dir_;
|
||||
unit_const_ptr u_;
|
||||
public:
|
||||
temporary_facing(unit_const_ptr u, map_location::DIRECTION new_dir)
|
||||
: save_dir_(u ? u->facing() : map_location::NDIRECTIONS)
|
||||
temporary_facing(unit_const_ptr u, map_location::direction new_dir)
|
||||
: save_dir_(u ? u->facing() : map_location::direction::indeterminate)
|
||||
, u_(u)
|
||||
{
|
||||
if (u_) {
|
||||
|
@ -458,12 +458,12 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
std::size_t count = 0;
|
||||
unit_filter ufilt{ vconfig(i) };
|
||||
ufilt.set_use_flat_tod(illuminates);
|
||||
std::vector<map_location::DIRECTION> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
for (const map_location::DIRECTION index : dirs)
|
||||
std::vector<map_location::direction> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
for (const map_location::direction index : dirs)
|
||||
{
|
||||
if (index == map_location::NDIRECTIONS)
|
||||
if (index == map_location::direction::indeterminate)
|
||||
continue;
|
||||
unit_map::const_iterator unit = units.find(adjacent[index]);
|
||||
unit_map::const_iterator unit = units.find(adjacent[static_cast<int>(index)]);
|
||||
if (unit == units.end())
|
||||
return false;
|
||||
if (!ufilt(*unit, *this))
|
||||
|
@ -492,13 +492,13 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const map
|
|||
terrain_filter adj_filter(vconfig(i), resources::filter_con, false);
|
||||
adj_filter.flatten(illuminates);
|
||||
|
||||
std::vector<map_location::DIRECTION> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
for (const map_location::DIRECTION index : dirs)
|
||||
std::vector<map_location::direction> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
for (const map_location::direction index : dirs)
|
||||
{
|
||||
if (index == map_location::NDIRECTIONS) {
|
||||
if (index == map_location::direction::indeterminate) {
|
||||
continue;
|
||||
}
|
||||
if(!adj_filter.match(adjacent[index])) {
|
||||
if(!adj_filter.match(adjacent[static_cast<int>(index)])) {
|
||||
return false;
|
||||
}
|
||||
count++;
|
||||
|
@ -526,12 +526,12 @@ bool unit::ability_affects_adjacent(const std::string& ability, const config& cf
|
|||
bool illuminates = ability == "illuminates";
|
||||
|
||||
assert(dir >=0 && dir <= 5);
|
||||
map_location::DIRECTION direction = static_cast<map_location::DIRECTION>(dir);
|
||||
map_location::direction direction{ dir };
|
||||
|
||||
for (const config &i : cfg.child_range("affect_adjacent"))
|
||||
{
|
||||
if (i.has_attribute("adjacent")) { //key adjacent defined
|
||||
std::vector<map_location::DIRECTION> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
std::vector<map_location::direction> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
if (std::find(dirs.begin(), dirs.end(), direction) == dirs.end()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -2218,14 +2218,14 @@ bool attack_type::special_active_impl(
|
|||
for (const config &i : special.child_range("filter_adjacent"))
|
||||
{
|
||||
std::size_t count = 0;
|
||||
std::vector<map_location::DIRECTION> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
std::vector<map_location::direction> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
unit_filter filter{ vconfig(i) };
|
||||
for (const map_location::DIRECTION index : dirs)
|
||||
for (const map_location::direction index : dirs)
|
||||
{
|
||||
if (index == map_location::NDIRECTIONS)
|
||||
if (index == map_location::direction::indeterminate)
|
||||
continue;
|
||||
unit_map::const_iterator unit = units.find(adjacent[index]);
|
||||
if (unit == units.end() || !filter.matches(*unit, adjacent[index], *self))
|
||||
unit_map::const_iterator unit = units.find(adjacent[static_cast<int>(index)]);
|
||||
if (unit == units.end() || !filter.matches(*unit, adjacent[static_cast<int>(index)], *self))
|
||||
return false;
|
||||
if (i.has_attribute("is_enemy")) {
|
||||
const display_context& dc = resources::filter_con->get_disp_context();
|
||||
|
@ -2247,13 +2247,13 @@ bool attack_type::special_active_impl(
|
|||
for (const config &i : special.child_range("filter_adjacent_location"))
|
||||
{
|
||||
std::size_t count = 0;
|
||||
std::vector<map_location::DIRECTION> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
std::vector<map_location::direction> dirs = map_location::parse_directions(i["adjacent"]);
|
||||
terrain_filter adj_filter(vconfig(i), resources::filter_con, false);
|
||||
for (const map_location::DIRECTION index : dirs)
|
||||
for (const map_location::direction index : dirs)
|
||||
{
|
||||
if (index == map_location::NDIRECTIONS)
|
||||
if (index == map_location::direction::indeterminate)
|
||||
continue;
|
||||
if(!adj_filter.match(adjacent[index])) {
|
||||
if(!adj_filter.match(adjacent[static_cast<int>(index)])) {
|
||||
return false;
|
||||
}
|
||||
count++;
|
||||
|
|
|
@ -314,7 +314,7 @@ unit_animation::unit_animation(const config& cfg,const std::string& frame_string
|
|||
|
||||
const std::vector<std::string>& my_directions = utils::split(cfg["direction"]);
|
||||
for(const auto& direction : my_directions) {
|
||||
const map_location::DIRECTION d = map_location::parse_direction(direction);
|
||||
const map_location::direction d = map_location::parse_direction(direction);
|
||||
directions_.push_back(d);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ private:
|
|||
t_translation::ter_list terrain_types_;
|
||||
std::vector<config> unit_filter_;
|
||||
std::vector<config> secondary_unit_filter_;
|
||||
std::vector<map_location::DIRECTION> directions_;
|
||||
std::vector<map_location::direction> directions_;
|
||||
int frequency_;
|
||||
int base_score_;
|
||||
std::vector<std::string> event_;
|
||||
|
|
|
@ -170,7 +170,7 @@ void unit_drawer::redraw_unit(const unit& u) const
|
|||
|
||||
bool hidden = u.get_hidden();
|
||||
bool is_flying = u.is_flying();
|
||||
map_location::DIRECTION facing = u.facing();
|
||||
map_location::direction facing = u.facing();
|
||||
int hitpoints = u.hitpoints();
|
||||
int max_hitpoints = u.max_hitpoints();
|
||||
|
||||
|
|
|
@ -131,14 +131,14 @@ struct unit_filter_adjacent : public unit_filter_base
|
|||
int match_count=0;
|
||||
|
||||
config::attribute_value i_adjacent = cfg_["adjacent"];
|
||||
std::vector<map_location::DIRECTION> dirs;
|
||||
std::vector<map_location::direction> dirs;
|
||||
if (i_adjacent.empty()) {
|
||||
dirs = map_location::default_dirs();
|
||||
} else {
|
||||
dirs = map_location::parse_directions(i_adjacent);
|
||||
}
|
||||
for (map_location::DIRECTION dir : dirs) {
|
||||
unit_map::const_iterator unit_itor = units.find(adjacent[dir]);
|
||||
for (map_location::direction dir : dirs) {
|
||||
unit_map::const_iterator unit_itor = units.find(adjacent[static_cast<int>(dir)]);
|
||||
if (unit_itor == units.end() || !child_.matches(unit_filter_args{*unit_itor, unit_itor->get_location(), &args.u, args.fc, args.use_flat_tod} )) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -633,7 +633,7 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
|
|||
|
||||
const auto [xsrc, ysrc] = game_disp->get_location(src);
|
||||
const auto [xdst, ydst] = game_disp->get_location(dst);
|
||||
const map_location::DIRECTION direction = src.get_relative_dir(dst);
|
||||
const map_location::direction direction = src.get_relative_dir(dst);
|
||||
|
||||
const frame_parameters current_data = merge_parameters(frame_time,animation_val,engine_val);
|
||||
double tmp_offset = current_data.offset;
|
||||
|
@ -655,7 +655,7 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
|
|||
}
|
||||
|
||||
image::locator image_loc;
|
||||
if(direction != map_location::NORTH && direction != map_location::SOUTH) {
|
||||
if(direction != map_location::direction::north && direction != map_location::direction::south) {
|
||||
image_loc = current_data.image_diagonal.clone(current_data.image_mod);
|
||||
}
|
||||
|
||||
|
@ -676,13 +676,13 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
|
|||
|
||||
if(image_size.x && image_size.y) {
|
||||
bool facing_west = (
|
||||
direction == map_location::NORTH_WEST ||
|
||||
direction == map_location::SOUTH_WEST);
|
||||
direction == map_location::direction::north_west ||
|
||||
direction == map_location::direction::south_west);
|
||||
|
||||
bool facing_north = (
|
||||
direction == map_location::NORTH_WEST ||
|
||||
direction == map_location::NORTH ||
|
||||
direction == map_location::NORTH_EAST);
|
||||
direction == map_location::direction::north_west ||
|
||||
direction == map_location::direction::north ||
|
||||
direction == map_location::direction::north_east);
|
||||
|
||||
if(!current_data.auto_hflip) { facing_west = false; }
|
||||
if(!current_data.auto_vflip) { facing_north = true; }
|
||||
|
@ -743,35 +743,35 @@ void unit_frame::redraw(const int frame_time, bool on_start_time, bool in_scope_
|
|||
halo::ORIENTATION orientation;
|
||||
switch(direction)
|
||||
{
|
||||
case map_location::NORTH:
|
||||
case map_location::NORTH_EAST:
|
||||
case map_location::direction::north:
|
||||
case map_location::direction::north_east:
|
||||
orientation = halo::NORMAL;
|
||||
break;
|
||||
case map_location::SOUTH_EAST:
|
||||
case map_location::SOUTH:
|
||||
case map_location::direction::south_east:
|
||||
case map_location::direction::south:
|
||||
if(!current_data.auto_vflip) {
|
||||
orientation = halo::NORMAL;
|
||||
} else {
|
||||
orientation = halo::VREVERSE;
|
||||
}
|
||||
break;
|
||||
case map_location::SOUTH_WEST:
|
||||
case map_location::direction::south_west:
|
||||
if(!current_data.auto_vflip) {
|
||||
orientation = halo::HREVERSE;
|
||||
} else {
|
||||
orientation = halo::HVREVERSE;
|
||||
}
|
||||
break;
|
||||
case map_location::NORTH_WEST:
|
||||
case map_location::direction::north_west:
|
||||
orientation = halo::HREVERSE;
|
||||
break;
|
||||
case map_location::NDIRECTIONS:
|
||||
case map_location::direction::indeterminate:
|
||||
default:
|
||||
orientation = halo::NORMAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if(direction != map_location::SOUTH_WEST && direction != map_location::NORTH_WEST) {
|
||||
if(direction != map_location::direction::south_west && direction != map_location::direction::north_west) {
|
||||
halo_id = halo_man.add(
|
||||
static_cast<int>(x + current_data.halo_x * disp_zoom),
|
||||
static_cast<int>(y + current_data.halo_y * disp_zoom),
|
||||
|
@ -797,7 +797,7 @@ std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time, const
|
|||
|
||||
const auto [xsrc, ysrc] = disp->get_location(src);
|
||||
const auto [xdst, ydst] = disp->get_location(dst);
|
||||
const map_location::DIRECTION direction = src.get_relative_dir(dst);
|
||||
const map_location::direction direction = src.get_relative_dir(dst);
|
||||
|
||||
const frame_parameters current_data = merge_parameters(frame_time, animation_val, engine_val);
|
||||
|
||||
|
@ -805,7 +805,7 @@ std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time, const
|
|||
const int d2 = display::get_singleton()->hex_size() / 2;
|
||||
|
||||
image::locator image_loc;
|
||||
if(direction != map_location::NORTH && direction != map_location::SOUTH) {
|
||||
if(direction != map_location::direction::north && direction != map_location::direction::south) {
|
||||
image_loc = current_data.image_diagonal.clone(current_data.image_mod);
|
||||
}
|
||||
|
||||
|
@ -820,9 +820,9 @@ std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time, const
|
|||
result.insert(src);
|
||||
|
||||
bool facing_north = (
|
||||
direction == map_location::NORTH_WEST ||
|
||||
direction == map_location::NORTH ||
|
||||
direction == map_location::NORTH_EAST);
|
||||
direction == map_location::direction::north_west ||
|
||||
direction == map_location::direction::north ||
|
||||
direction == map_location::direction::north_east);
|
||||
|
||||
if(!current_data.auto_vflip) { facing_north = true; }
|
||||
|
||||
|
@ -834,13 +834,13 @@ std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time, const
|
|||
}
|
||||
|
||||
if(my_y < 0) {
|
||||
result.insert(src.get_direction(map_location::NORTH));
|
||||
result.insert(src.get_direction(map_location::NORTH_EAST));
|
||||
result.insert(src.get_direction(map_location::NORTH_WEST));
|
||||
result.insert(src.get_direction(map_location::direction::north));
|
||||
result.insert(src.get_direction(map_location::direction::north_east));
|
||||
result.insert(src.get_direction(map_location::direction::north_west));
|
||||
} else if(my_y > 0) {
|
||||
result.insert(src.get_direction(map_location::SOUTH));
|
||||
result.insert(src.get_direction(map_location::SOUTH_EAST));
|
||||
result.insert(src.get_direction(map_location::SOUTH_WEST));
|
||||
result.insert(src.get_direction(map_location::direction::south));
|
||||
result.insert(src.get_direction(map_location::direction::south_east));
|
||||
result.insert(src.get_direction(map_location::direction::south_west));
|
||||
}
|
||||
} else {
|
||||
int w = 0, h = 0;
|
||||
|
@ -858,13 +858,13 @@ std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time, const
|
|||
const double disp_zoom = display::get_singleton()->get_zoom_factor();
|
||||
|
||||
bool facing_west = (
|
||||
direction == map_location::NORTH_WEST ||
|
||||
direction == map_location::SOUTH_WEST);
|
||||
direction == map_location::direction::north_west ||
|
||||
direction == map_location::direction::south_west);
|
||||
|
||||
bool facing_north = (
|
||||
direction == map_location::NORTH_WEST ||
|
||||
direction == map_location::NORTH ||
|
||||
direction == map_location::NORTH_EAST);
|
||||
direction == map_location::direction::north_west ||
|
||||
direction == map_location::direction::north ||
|
||||
direction == map_location::direction::north_east);
|
||||
|
||||
if(!current_data.auto_hflip) { facing_west = false; }
|
||||
if(!current_data.auto_vflip) { facing_north = true; }
|
||||
|
|
|
@ -430,7 +430,7 @@ void unit_mover::wait_for_anims()
|
|||
* If @a dir is not supplied, the final direction will be determined by (the
|
||||
* last two traversed hexes of) the path.
|
||||
*/
|
||||
void unit_mover::finish(unit_ptr u, map_location::DIRECTION dir)
|
||||
void unit_mover::finish(unit_ptr u, map_location::direction dir)
|
||||
{
|
||||
// Nothing to do here if the display is not valid.
|
||||
if ( !can_draw_ ) {
|
||||
|
@ -442,7 +442,7 @@ void unit_mover::finish(unit_ptr u, map_location::DIRECTION dir)
|
|||
}
|
||||
|
||||
const map_location & end_loc = path_[current_];
|
||||
const map_location::DIRECTION final_dir = current_ == 0 ?
|
||||
const map_location::direction final_dir = current_ == 0 ?
|
||||
path_[0].get_relative_dir(path_[1]) :
|
||||
path_[current_-1].get_relative_dir(end_loc);
|
||||
|
||||
|
@ -476,7 +476,7 @@ void unit_mover::finish(unit_ptr u, map_location::DIRECTION dir)
|
|||
}
|
||||
|
||||
// Facing gets set even when not animating.
|
||||
u->set_facing(dir == map_location::NDIRECTIONS ? final_dir : dir);
|
||||
u->set_facing(dir == map_location::direction::indeterminate ? final_dir : dir);
|
||||
u->anim_comp().set_standing(true); // Need to reset u's animation so the new facing takes effect.
|
||||
|
||||
// Redraw path ends (even if not animating).
|
||||
|
@ -503,7 +503,7 @@ void unit_mover::finish(unit_ptr u, map_location::DIRECTION dir)
|
|||
* will still display the correct number of units.
|
||||
*/
|
||||
void move_unit(const std::vector<map_location>& path, unit_ptr u,
|
||||
bool animate, map_location::DIRECTION dir,
|
||||
bool animate, map_location::direction dir,
|
||||
bool force_scroll)
|
||||
{
|
||||
unit_mover mover(path, animate, force_scroll);
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
void start(unit_ptr u);
|
||||
void proceed_to(unit_ptr u, std::size_t path_index, bool update=false, bool wait=true);
|
||||
void wait_for_anims();
|
||||
void finish(unit_ptr u, map_location::DIRECTION dir = map_location::NDIRECTIONS);
|
||||
void finish(unit_ptr u, map_location::direction dir = map_location::direction::indeterminate);
|
||||
|
||||
private: // functions
|
||||
void replace_temporary(unit_ptr u);
|
||||
|
@ -82,7 +82,7 @@ private: // data
|
|||
*/
|
||||
void move_unit(const std::vector<map_location>& path, unit_ptr u,
|
||||
bool animate=true,
|
||||
map_location::DIRECTION dir=map_location::NDIRECTIONS,
|
||||
map_location::direction dir=map_location::direction::indeterminate,
|
||||
bool force_scroll=false);
|
||||
|
||||
/**
|
||||
|
|
|
@ -198,6 +198,12 @@ namespace
|
|||
u.set_state(unit::STATE_POISONED, poisoned && !u.get_state("unpoisonable"));
|
||||
};
|
||||
}
|
||||
|
||||
map_location::direction get_random_direction()
|
||||
{
|
||||
constexpr int last_facing = static_cast<int>(map_location::direction::indeterminate) - 1;
|
||||
return map_location::direction{randomness::rng::default_instance().get_random_int(0, last_facing)};
|
||||
}
|
||||
} // end anon namespace
|
||||
|
||||
/**
|
||||
|
@ -367,7 +373,7 @@ unit::unit(unit_ctor_t)
|
|||
, overlays_()
|
||||
, role_()
|
||||
, attacks_()
|
||||
, facing_(map_location::NDIRECTIONS)
|
||||
, facing_(map_location::direction::indeterminate)
|
||||
, trait_names_()
|
||||
, trait_descriptions_()
|
||||
, trait_nonhidden_ids_()
|
||||
|
@ -408,7 +414,7 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
gender_ = generate_gender(*type_, cfg);
|
||||
name_ = gender_value(cfg, gender_, "male_name", "female_name", "name").t_str();
|
||||
role_ = cfg["role"].str();
|
||||
//, facing_(map_location::NDIRECTIONS)
|
||||
//, facing_(map_location::direction::indeterminate)
|
||||
//, anim_comp_(new unit_animation_component(*this))
|
||||
hidden_ = cfg["hidden"].to_bool(false);
|
||||
hp_bar_scaling_ = cfg["hp_bar_scaling"].blank() ? type_->hp_bar_scaling() : cfg["hp_bar_scaling"].to_double();
|
||||
|
@ -485,7 +491,7 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
|
||||
random_traits_ = cfg["random_traits"].to_bool(true);
|
||||
facing_ = map_location::parse_direction(cfg["facing"]);
|
||||
if(facing_ == map_location::NDIRECTIONS) facing_ = static_cast<map_location::DIRECTION>(randomness::rng::default_instance().get_random_int(0, map_location::NDIRECTIONS-1));
|
||||
if(facing_ == map_location::direction::indeterminate) facing_ = get_random_direction();
|
||||
|
||||
for(const config& mods : cfg.child_range("modifications")) {
|
||||
modifications_.append_children(mods);
|
||||
|
@ -747,7 +753,7 @@ void unit::init(const unit_type& u_type, int side, bool real_unit, unit_race::GE
|
|||
variation_ = variation.empty() ? type_->default_variation() : variation;
|
||||
side_ = side;
|
||||
gender_ = gender != unit_race::NUM_GENDERS ? gender : generate_gender(u_type, real_unit);
|
||||
facing_ = static_cast<map_location::DIRECTION>(randomness::rng::default_instance().get_random_int(0, map_location::NDIRECTIONS-1));
|
||||
facing_ = get_random_direction();
|
||||
upkeep_ = upkeep_full{};
|
||||
|
||||
// Apply the unit type's data to this unit.
|
||||
|
@ -1672,9 +1678,9 @@ void unit::write(config& cfg, bool write_all) const
|
|||
cfg.append(back);
|
||||
}
|
||||
|
||||
void unit::set_facing(map_location::DIRECTION dir) const
|
||||
void unit::set_facing(map_location::direction dir) const
|
||||
{
|
||||
if(dir != map_location::NDIRECTIONS && dir != facing_) {
|
||||
if(dir != map_location::direction::indeterminate && dir != facing_) {
|
||||
appearance_changed_ = true;
|
||||
facing_ = dir;
|
||||
}
|
||||
|
|
|
@ -1417,13 +1417,13 @@ public:
|
|||
}
|
||||
|
||||
/** The current direction this unit is facing within its hex. */
|
||||
map_location::DIRECTION facing() const
|
||||
map_location::direction facing() const
|
||||
{
|
||||
return facing_;
|
||||
}
|
||||
|
||||
/** The this unit's facing. */
|
||||
void set_facing(map_location::DIRECTION dir) const;
|
||||
void set_facing(map_location::direction dir) const;
|
||||
|
||||
/** Gets whether this unit has a multi-turn destination set. */
|
||||
bool has_goto() const
|
||||
|
@ -2063,7 +2063,7 @@ private:
|
|||
protected:
|
||||
// TODO: I think we actually consider this to be part of the gamestate, so it might be better if it's not mutable,
|
||||
// but it's not easy to separate this guy from the animation code right now.
|
||||
mutable map_location::DIRECTION facing_;
|
||||
mutable map_location::direction facing_;
|
||||
|
||||
private:
|
||||
std::vector<t_string> trait_names_;
|
||||
|
|
Loading…
Add table
Reference in a new issue