inline the definition map_location::null_location

If we decided it was worth it to inline map_location ==, then
surely this is also worth it to inline null_location, as the
compiler may be able to reduce tests for == null location to
"x == ... && y == ...", without having to move to a different
compilation unit.
This commit is contained in:
Chris Beck 2014-05-20 10:42:13 -04:00
parent c73b5945d9
commit c5838b9513
43 changed files with 137 additions and 136 deletions

View file

@ -250,9 +250,9 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
// Get the weapon characteristics, if any.
if (weapon) {
weapon->set_specials_context(map_location::null_location, attacking);
weapon->set_specials_context(map_location::null_location(), attacking);
if (opp_weapon) {
opp_weapon->set_specials_context(map_location::null_location, !attacking);
opp_weapon->set_specials_context(map_location::null_location(), !attacking);
}
slows = weapon->get_special_bool("slow");
drains = !opp_type->musthave_status("undrainable") && weapon->get_special_bool("drains");
@ -1604,7 +1604,7 @@ map_location under_leadership(const unit_map& units, const map_location& loc,
{
const unit_map::const_iterator un = units.find(loc);
if(un == units.end()) {
return map_location::null_location;
return map_location::null_location();
}
unit_ability_list abil = un->get_abilities("leadership");
if(bonus) {

View file

@ -237,7 +237,7 @@ void advance_unit(map_location loc, const std::string &advance_to,
* function which tests if the unit at loc is currently affected by leadership.
* (i.e. has a higher-level 'leadership' unit next to it).
* If it does, then the location of the leader unit will be returned,
* Otherwise map_location::null_location will be returned.
* Otherwise map_location::null_location() will be returned.
* If 'bonus' is not NULL, the % bonus will be stored in it.
*/
map_location under_leadership(const unit_map& units, const map_location& loc,

View file

@ -143,7 +143,7 @@ map_location unit_creator::find_location(const config &cfg, const unit* pass_che
map_location loc;
if ( place == "recall" ) {
return map_location::null_location;
return map_location::null_location();
}
else if ( place == "leader" || place == "leader_passable" ) {
@ -173,7 +173,7 @@ map_location unit_creator::find_location(const config &cfg, const unit* pass_che
}
}
return map_location::null_location;
return map_location::null_location();
}
@ -283,7 +283,7 @@ bool can_recruit_from(const map_location& leader_loc, int side)
return pathfind::find_vacant_tile(leader_loc, pathfind::VACANT_CASTLE, NULL,
&(*resources::teams)[side-1])
!= map_location::null_location;
!= map_location::null_location();
}
/**
@ -419,7 +419,7 @@ namespace { // Helpers for get_recalls()
// Only units that match the leader's recall filter are valid.
scoped_recall_unit this_unit("this_unit", save_id, &recall_unit - &recall_list[0]);
if ( recall_unit.matches_filter(vconfig(leader.recall_filter()), map_location::null_location) )
if ( recall_unit.matches_filter(vconfig(leader.recall_filter()), map_location::null_location()) )
{
result.push_back(&recall_unit);
if ( already_added != NULL )
@ -519,7 +519,7 @@ namespace { // Helpers for check_recall_location()
scoped_recall_unit this_unit("this_unit", recall_team.save_id(),
&recall_unit - &recall_team.recall_list()[0]);
if ( !recall_unit.matches_filter(vconfig(recaller.recall_filter()),
map_location::null_location) )
map_location::null_location()) )
return RECRUIT_NO_ABLE_LEADER;
// Make sure the unit is on a keep.
@ -555,7 +555,7 @@ RECRUIT_CHECK check_recall_location(const int side, map_location& recall_locatio
// If the specified location is occupied, proceed as if no location was specified.
if ( resources::units->count(recall_location) != 0 )
check_location = map_location::null_location;
check_location = map_location::null_location();
// If the check location is not valid, we will never get an "OK" result.
RECRUIT_CHECK const goal_result = check_location.valid() ? RECRUIT_OK :
@ -686,7 +686,7 @@ RECRUIT_CHECK check_recruit_location(const int side, map_location &recruit_locat
// If the specified location is occupied, proceed as if no location was specified.
if ( resources::units->count(recruit_location) != 0 )
check_location = map_location::null_location;
check_location = map_location::null_location();
// If the specified unit type is in the team's recruit list, there is no
// need to check each leader's list.
@ -818,7 +818,7 @@ namespace { // Helpers for place_recruit()
return leader->get_location();
// No usable leader found.
return map_location::null_location;
return map_location::null_location();
}
/**
@ -859,7 +859,7 @@ bool place_recruit(const unit &u, const map_location &recruit_location, const ma
new_unit.set_hidden(true);
// Get the leader location before adding the unit to the board.
const map_location leader_loc = !show ? map_location::null_location :
const map_location leader_loc = !show ? map_location::null_location() :
find_recruit_leader(new_unit.side(), recruit_location, recruited_from);
// Add the unit to the board.

View file

@ -41,7 +41,7 @@ public:
/**
* finds a suitable location for unit
* @retval map_location::null_location if unit is to be put into recall list
* @retval map_location::null_location() if unit is to be put into recall list
* @retval valid on-board map location otherwise
*/
map_location find_location(const config &cfg, const unit* pass_check=NULL);

View file

@ -224,7 +224,7 @@ namespace { // Private helpers for move_unit()
private: // functions
/// Returns whether or not movement was blocked by a non-ambushing enemy.
bool blocked() const { return blocked_loc_ != map_location::null_location; }
bool blocked() const { return blocked_loc_ != map_location::null_location(); }
/// Checks the expected route for hidden units.
void cache_hidden_units(const route_iterator & start,
const route_iterator & stop);
@ -371,9 +371,9 @@ namespace { // Private helpers for move_unit()
move_loc_(begin_),
do_move_track_(game_events::wml_tracking()),
// The remaining fields are set to some sort of "zero state".
zoc_stop_(map_location::null_location),
ambush_stop_(map_location::null_location),
blocked_loc_(map_location::null_location),
zoc_stop_(map_location::null_location()),
ambush_stop_(map_location::null_location()),
blocked_loc_(map_location::null_location()),
ambushed_(false),
show_ambush_alert_(false),
event_mutated_(false),
@ -393,7 +393,7 @@ namespace { // Private helpers for move_unit()
if ( !is_ai_move() )
// Clear the "goto" instruction during movement.
// (It will be reset in the destructor if needed.)
move_it_->set_goto(map_location::null_location);
move_it_->set_goto(map_location::null_location());
}
@ -401,7 +401,7 @@ namespace { // Private helpers for move_unit()
{
// Set the "goto" order? (Not if WML set it.)
if ( !is_ai_move() && move_it_.valid() &&
move_it_->get_goto() == map_location::null_location )
move_it_->get_goto() == map_location::null_location() )
{
// Only set the goto if movement was not complete and was not
// interrupted.
@ -634,7 +634,7 @@ namespace { // Private helpers for move_unit()
{
// Clear the old cache.
obstructed_ = full_end_;
blocked_loc_ = map_location::null_location;
blocked_loc_ = map_location::null_location();
teleport_failed_ = false;
// The ambush cache needs special treatment since we cannot re-detect
// an ambush if we are already at the ambushed location.
@ -644,7 +644,7 @@ namespace { // Private helpers for move_unit()
ambushed_ = !ambushers_.empty();
}
if ( !ambushed_ ) {
ambush_stop_ = map_location::null_location;
ambush_stop_ = map_location::null_location();
ambushers_.clear();
}
@ -730,7 +730,7 @@ namespace { // Private helpers for move_unit()
int remaining_moves = move_it_->movement_left();
zoc_stop_ = map_location::null_location;
zoc_stop_ = map_location::null_location();
moves_left_.clear();
if ( start != begin_ ) {
@ -746,7 +746,7 @@ namespace { // Private helpers for move_unit()
for ( ; end != stop; ++end )
{
// Break out of the loop if we cannot leave the previous hex.
if ( zoc_stop_ != map_location::null_location && !is_replay_ )
if ( zoc_stop_ != map_location::null_location() && !is_replay_ )
break;
remaining_moves -= move_it_->movement_cost(map[*end]);
if ( remaining_moves < 0 ) {
@ -1012,7 +1012,7 @@ namespace { // Private helpers for move_unit()
// Update those to reflect whether or not we got to them.
ambushed_ = ambushed_ && real_end_ == ambush_limit_;
if ( !obstructed_stop )
blocked_loc_ = map_location::null_location;
blocked_loc_ = map_location::null_location();
teleport_failed_ = teleport_failed_ && obstructed_stop;
// event_mutated_ does not get unset, regardless of other reasons
// for stopping, but we do save its current value.
@ -1043,7 +1043,7 @@ namespace { // Private helpers for move_unit()
move_it_->set_interrupted_move(
sighted_stop_ && !resources::whiteboard->is_executing_actions() ?
*(full_end_-1) :
map_location::null_location);
map_location::null_location());
if ( ambushed_ || final_loc == zoc_stop_ )
move_it_->set_movement(0, true);
@ -1239,7 +1239,7 @@ size_t move_unit_and_record(const std::vector<map_location> &steps,
// Avoid some silliness.
if ( steps.size() < 2 || (steps.size() == 2 && steps.front() == steps.back()) ) {
DBG_NG << "Ignoring a unit trying to jump on its hex at " <<
( steps.empty() ? map_location::null_location : steps.front() ) << ".\n";
( steps.empty() ? map_location::null_location() : steps.front() ) << ".\n";
return 0;
}
//if we have no fog activated then we always skip sighted

View file

@ -433,7 +433,7 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team,
// Locate the unit in question.
unit_map::const_iterator find_it = resources::units->find(viewer.underlying_id);
const map_location & real_loc = find_it == resources::units->end() ?
map_location::null_location :
map_location::null_location() :
find_it->get_location();
return clear_unit(view_loc, view_team, viewer.underlying_id,
@ -559,7 +559,7 @@ bool shroud_clearer::fire_events()
// Try to locate the sighting unit.
unit_map::const_iterator find_it = units.find(event.sighter_id);
const map_location & sight_loc =
find_it == units.end() ? map_location::null_location :
find_it == units.end() ? map_location::null_location() :
find_it->get_location();
{ // Raise the event based on the latest data.

View file

@ -587,7 +587,7 @@ std::string recall_result::do_describe() const
s << "recall by side ";
s << get_side();
s << " of unit id ["<<unit_id_;
if (where_ != map_location::null_location){
if (where_ != map_location::null_location()){
s << "] on location "<<where_;
} else {
s << "] on any suitable location";
@ -731,7 +731,7 @@ std::string recruit_result::do_describe() const
s << "recruitment by side ";
s << get_side();
s << " of unit type ["<<unit_name_;
if (where_ != map_location::null_location){
if (where_ != map_location::null_location()){
s << "] on location "<<where_;
} else {
s << "] on any suitable location";
@ -899,7 +899,7 @@ void synced_command_result::do_execute()
assert(is_success());
std::stringstream s;
if (location_ != map_location::null_location){
if (location_ != map_location::null_location()){
s << "local x1 = " << location_.x << " local y1 = " << location_.y << " ";
}
s << lua_code_;

View file

@ -1080,7 +1080,7 @@ const map_location& readonly_context_impl::nearest_keep(const map_location& loc)
if (res) {
return *res;
} else {
return map_location::null_location;
return map_location::null_location();
}
}
@ -1263,10 +1263,10 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
return leader_location; //if leader already on keep, then return leader_location
}
map_location const* best_free_keep = &map_location::null_location;
map_location const* best_free_keep = &map_location::null_location();
double move_left_at_best_free_keep = 0.0;
map_location const* best_occupied_keep = &map_location::null_location;
map_location const* best_occupied_keep = &map_location::null_location();
double move_left_at_best_occupied_keep = 0.0;
BOOST_FOREACH(const pathfind::paths::step &dest, leader_paths.destinations)
@ -1276,12 +1276,12 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
const int move_left_at_loc = dest.move_left;
if (resources::units->count(loc) == 0) {
if ((*best_free_keep==map_location::null_location)||(move_left_at_loc>move_left_at_best_free_keep)){
if ((*best_free_keep==map_location::null_location())||(move_left_at_loc>move_left_at_best_free_keep)){
best_free_keep = &loc;
move_left_at_best_free_keep = move_left_at_loc;
}
} else {
if ((*best_occupied_keep==map_location::null_location)||(move_left_at_loc>move_left_at_best_occupied_keep)){
if ((*best_occupied_keep==map_location::null_location())||(move_left_at_loc>move_left_at_best_occupied_keep)){
best_occupied_keep = &loc;
move_left_at_best_occupied_keep = move_left_at_loc;
}
@ -1289,11 +1289,11 @@ const map_location& readonly_context_impl::suitable_keep(const map_location& lea
}
}
if (*best_free_keep != map_location::null_location){
if (*best_free_keep != map_location::null_location()){
return *best_free_keep; // if there is a free keep reachable during current turn, return it
}
if (*best_occupied_keep != map_location::null_location){
if (*best_occupied_keep != map_location::null_location()){
return *best_occupied_keep; // if there is an occupied keep reachable during current turn, return it
}

View file

@ -184,10 +184,10 @@ public:
virtual void log_message(const std::string& msg) = 0;
virtual attack_result_ptr check_attack_action(const map_location& attacker_loc, const map_location& defender_loc, int attacker_weapon) = 0;
virtual move_result_ptr check_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) = 0;
virtual recall_result_ptr check_recall_action(const std::string& id, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location) = 0;
virtual recruit_result_ptr check_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location) = 0;
virtual recall_result_ptr check_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) = 0;
virtual recruit_result_ptr check_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) = 0;
virtual stopunit_result_ptr check_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) = 0;
virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location) = 0;
virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) = 0;
virtual void calculate_possible_moves(std::map<map_location,pathfind::paths>& possible_moves,
move_map& srcdst, move_map& dstsrc, bool enemy,
bool assume_full_movement=false,
@ -436,16 +436,16 @@ public:
virtual move_result_ptr execute_move_action(const map_location& from, const map_location& to, bool remove_movement=true, bool unreach_is_ok=false) = 0;
virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location) = 0;
virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) = 0;
virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location) = 0;
virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location()) = 0;
virtual stopunit_result_ptr execute_stopunit_action(const map_location& unit_location, bool remove_movement = true, bool remove_attacks = false) = 0;
virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location) = 0;
virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location()) = 0;
virtual team& current_team_w() = 0;
@ -566,15 +566,15 @@ public:
}
virtual recall_result_ptr check_recall_action(const std::string &id, const map_location &where = map_location::null_location,
const map_location &from = map_location::null_location)
virtual recall_result_ptr check_recall_action(const std::string &id, const map_location &where = map_location::null_location(),
const map_location &from = map_location::null_location())
{
return target_->check_recall_action(id, where, from);
}
virtual recruit_result_ptr check_recruit_action(const std::string &unit_name, const map_location &where = map_location::null_location,
const map_location &from = map_location::null_location)
virtual recruit_result_ptr check_recruit_action(const std::string &unit_name, const map_location &where = map_location::null_location(),
const map_location &from = map_location::null_location())
{
return target_->check_recruit_action(unit_name, where, from);
}
@ -584,7 +584,7 @@ public:
return target_->check_stopunit_action(unit_location, remove_movement, remove_attacks);
}
virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location)
virtual synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location())
{
return target_->check_synced_command_action(lua_code, location);
}
@ -1064,13 +1064,13 @@ public:
}
virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location)
virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location())
{
return target_->execute_recall_action(id,where,from);
}
virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location)
virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location())
{
return target_->execute_recruit_action(unit_name,where,from);
}
@ -1082,7 +1082,7 @@ public:
}
virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location)
virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location())
{
return target_->execute_synced_command_action(lua_code,location);
}
@ -1242,7 +1242,7 @@ public:
* @retval possible_result: no free space on keep
* @retval possible_result: not enough gold
*/
recall_result_ptr check_recall_action(const std::string& id, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location);
recall_result_ptr check_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location());
/**
@ -1255,7 +1255,7 @@ public:
* @retval possible_result: no free space on keep
* @retval possible_result: not enough gold
*/
recruit_result_ptr check_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location);
recruit_result_ptr check_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location());
/**
@ -1278,7 +1278,7 @@ public:
* @retval possible_result: something wrong
* @retval possible_result: nothing to do
*/
synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location);
synced_command_result_ptr check_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location());
/**
@ -1647,7 +1647,7 @@ public:
* @retval possible_result: no free space on keep
* @retval possible_result: not enough gold
*/
virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location);
virtual recall_result_ptr execute_recall_action(const std::string& id, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location());
/**
@ -1660,7 +1660,7 @@ public:
* @retval possible_result: no free space on keep
* @retval possible_result: not enough gold
*/
virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location, const map_location &from = map_location::null_location);
virtual recruit_result_ptr execute_recruit_action(const std::string& unit_name, const map_location &where = map_location::null_location(), const map_location &from = map_location::null_location());
/**
@ -1683,7 +1683,7 @@ public:
* @retval possible_result: something wrong
* @retval possible_result: nothing to do
*/
virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location);
virtual synced_command_result_ptr execute_synced_command_action(const std::string& lua_code, const map_location& location = map_location::null_location());
/** Return a reference to the 'team' object for the AI. */

View file

@ -1204,7 +1204,7 @@ private:
return variant();
}
map_location loc = map_location::null_location;
map_location loc = map_location::null_location();
const ai::moves_map &possible_moves = ai_.get_possible_moves();
const ai::moves_map::const_iterator& p_it = possible_moves.find(unit_loc);
if (p_it==possible_moves.end() ) {
@ -1219,7 +1219,7 @@ private:
break;
}
}
if (loc==map_location::null_location) {
if (loc==map_location::null_location()) {
return variant();
}
return variant(new location_callable(loc));

View file

@ -315,7 +315,7 @@ static int ai_recruit(lua_State *L, bool exec)
where.y = lua_tonumber(L, 3) - 1;
}
//TODO fendrin: talk to Crab about the from argument.
map_location from = map_location::null_location;
map_location from = map_location::null_location();
ai::recruit_result_ptr recruit_result = ai::actions::execute_recruit_action(side,exec,std::string(unit_name),where,from);
return transform_ai_action(L,recruit_result);
}
@ -340,7 +340,7 @@ static int ai_recall(lua_State *L, bool exec)
where.y = lua_tonumber(L, 3) - 1;
}
//TODO fendrin: talk to Crab about the from argument.
map_location from = map_location::null_location;
map_location from = map_location::null_location();
ai::recall_result_ptr recall_result = ai::actions::execute_recall_action(side,exec,std::string(unit_id),where,from);
return transform_ai_action(L,recall_result);
}

View file

@ -178,7 +178,7 @@ double recruitment::evaluate() {
const map_location& loc = leader->get_location();
if (resources::game_map->is_keep(loc) &&
pathfind::find_vacant_castle(*leader) != map_location::null_location) {
pathfind::find_vacant_castle(*leader) != map_location::null_location()) {
return get_score();
}
}
@ -210,7 +210,7 @@ void recruitment::execute() {
LOG_AI_RECRUITMENT << "Leader " << leader->name() << " is not on keep. \n";
continue;
}
if (pathfind::find_vacant_castle(*leader) == map_location::null_location) {
if (pathfind::find_vacant_castle(*leader) == map_location::null_location()) {
LOG_AI_RECRUITMENT << "Leader " << leader->name() << " has no free hexes \n";
continue;
}
@ -250,7 +250,7 @@ void recruitment::execute() {
BOOST_FOREACH(const unit& recall, current_team().recall_list()) {
// Check if this leader is allowed to recall this unit.
vconfig filter = vconfig(leader->recall_filter());
if (!recall.matches_filter(filter, map_location::null_location)) {
if (!recall.matches_filter(filter, map_location::null_location())) {
continue;
}
data.recruits.insert(recall.type_id());
@ -433,7 +433,7 @@ void recruitment::execute() {
*/
action_result_ptr recruitment::execute_recall(const std::string& id, data& leader_data) {
recall_result_ptr recall_result;
recall_result = check_recall_action(id, map_location::null_location,
recall_result = check_recall_action(id, map_location::null_location(),
leader_data.leader->get_location());
if (recall_result->is_ok()) {
recall_result->execute();
@ -447,7 +447,7 @@ action_result_ptr recruitment::execute_recall(const std::string& id, data& leade
*/
action_result_ptr recruitment::execute_recruit(const std::string& type, data& leader_data) {
recruit_result_ptr recruit_result;
recruit_result = check_recruit_action(type, map_location::null_location,
recruit_result = check_recruit_action(type, map_location::null_location(),
leader_data.leader->get_location());
if (recruit_result->is_ok()) {
@ -475,7 +475,7 @@ const std::string* recruitment::get_appropriate_recall(const std::string& type,
}
// Check if this leader is allowed to recall this unit.
vconfig filter = vconfig(leader_data.leader->recall_filter());
if (!recall_unit.matches_filter(filter, map_location::null_location)) {
if (!recall_unit.matches_filter(filter, map_location::null_location())) {
LOG_AI_RECRUITMENT << "Refused recall because of filter: " << recall_unit.id() << "\n";
continue;
}

View file

@ -798,7 +798,7 @@ double move_leader_to_keep_phase::evaluate()
const pathfind::paths leader_paths = p_it->second;
const map_location& keep = suitable_keep(leader->get_location(), leader_paths);
if (keep == map_location::null_location || keep == leader->get_location()) {
if (keep == map_location::null_location() || keep == leader->get_location()) {
continue;
}
@ -846,7 +846,7 @@ double move_leader_to_keep_phase::evaluate()
route = pathfind::a_star_search(leader->get_location(), keep, 10000.0, &calc, resources::game_map->w(), resources::game_map->h(), &allowed_teleports);
// find next hop
map_location next_hop = map_location::null_location;
map_location next_hop = map_location::null_location();
int next_hop_cost = 0;
BOOST_FOREACH(const map_location& step, route.steps) {
if (leader_paths.destinations.contains(step)) {
@ -856,7 +856,7 @@ double move_leader_to_keep_phase::evaluate()
break;
}
}
if (next_hop == map_location::null_location) {
if (next_hop == map_location::null_location()) {
return BAD_SCORE;
}
//define the next hop to have the lowest cost (0)
@ -980,13 +980,13 @@ void get_villages_phase::get_villages(
DBG_AI_TESTING_AI_DEFAULT << "deciding which villages we want...\n";
unit_map &units_ = *resources::units;
const int ticks = SDL_GetTicks();
best_leader_loc_ = map_location::null_location;
best_leader_loc_ = map_location::null_location();
if(leader != units_.end()) {
keep_loc_ = nearest_keep(leader->get_location());
leader_loc_ = leader->get_location();
} else {
keep_loc_ = map_location::null_location;
leader_loc_ = map_location::null_location;
keep_loc_ = map_location::null_location();
leader_loc_ = map_location::null_location();
}
debug_ = !lg::debug.dont_log(log_ai_testing_ai_default);
@ -1096,7 +1096,7 @@ void get_villages_phase::find_villages(
// If it is a neutral village, and we have no leader,
// then the village is of no use to us, and we don't want it.
if(!owned && leader_loc_ == map_location::null_location) {
if(!owned && leader_loc_ == map_location::null_location()) {
continue;
}
@ -1331,7 +1331,7 @@ get_villages_phase::treachmap::iterator get_villages_phase::remove_unit(
{
assert(unit->second.empty());
if(unit->first == leader_loc_ && best_leader_loc_ != map_location::null_location) {
if(unit->first == leader_loc_ && best_leader_loc_ != map_location::null_location()) {
DBG_AI_TESTING_AI_DEFAULT << "Dispatch leader at " << leader_loc_ << " closer to the keep at "
<< best_leader_loc_ << '\n';
@ -1966,7 +1966,7 @@ double simple_move_and_targeting_phase::evaluate()
unit_map &units_ = *resources::units;
unit_map::const_iterator leader = units_.find_leader(get_side());
map_location my_leader_loc = map_location::null_location;
map_location my_leader_loc = map_location::null_location();
if (leader.valid()) {
my_leader_loc = leader->get_location();
}

View file

@ -139,19 +139,19 @@ int attack_type_callable::do_compare(const formula_callable* callable) const
variant unit_callable::get_value(const std::string& key) const
{
if(key == "x") {
if (loc_==map_location::null_location) {
if (loc_==map_location::null_location()) {
return variant();
} else {
return variant(loc_.x+1);
}
} else if(key == "y") {
if (loc_==map_location::null_location) {
if (loc_==map_location::null_location()) {
return variant();
} else {
return variant(loc_.y+1);
}
} else if(key == "loc") {
if (loc_==map_location::null_location) {
if (loc_==map_location::null_location()) {
return variant();
} else {
return variant(new location_callable(loc_));

View file

@ -253,7 +253,7 @@ void controller_base::play_slice(bool is_delay_enabled)
/* TODO fendrin enable when the relative cursor movement is implemented well enough
const map_location& selected_hex = get_display().selected_hex();
if (selected_hex != map_location::null_location) {
if (selected_hex != map_location::null_location()) {
if (joystick_manager_.next_highlighted_hex(highlighted_hex, selected_hex)) {
get_mouse_handler_base().mouse_motion(0,0, true, true, highlighted_hex);
get_display().scroll_to_tile(highlighted_hex, display::ONSCREEN_WARP, false, true);

View file

@ -595,7 +595,7 @@ public:
*/
void redraw_minimap() { redrawMinimap_ = true; }
virtual const time_of_day& get_time_of_day(const map_location& loc = map_location::null_location) const;
virtual const time_of_day& get_time_of_day(const map_location& loc = map_location::null_location()) const;
virtual bool has_time_area() const {return false;}

View file

@ -148,7 +148,7 @@ class editor_controller : public controller_base,
void add_area();
/* mouse_handler_base overrides */
void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc = map_location::null_location);
void mouse_motion(int x, int y, const bool browse, bool update, map_location new_loc = map_location::null_location());
editor_display& gui() { return *gui_; }
const editor_display& gui() const { return *gui_; }
bool allow_mouse_wheel_scroll(int x, int y);

View file

@ -742,7 +742,7 @@ void game_display::set_attack_indicator(const map_location& src, const map_locat
void game_display::clear_attack_indicator()
{
set_attack_indicator(map_location::null_location, map_location::null_location);
set_attack_indicator(map_location::null_location(), map_location::null_location());
}

View file

@ -242,7 +242,7 @@ namespace { // Support functions
/**
* Converts a vconfig to a location (based on x,y=).
* The default parameter values cause the default return value (if neither
* x nor y is specified) to equal map_location::null_location.
* x nor y is specified) to equal map_location::null_location().
*/
map_location cfg_to_loc(const vconfig& cfg, int defaultx = -999, int defaulty = -999)
{
@ -446,7 +446,7 @@ namespace { // Support functions
screen.highlight_hex(spl);
} else if(speaker_str == "narrator") {
LOG_NG << "no speaker\n";
screen.highlight_hex(map_location::null_location);
screen.highlight_hex(map_location::null_location());
} else {
return speaker;
}
@ -1658,7 +1658,7 @@ WML_HANDLER_FUNCTION(recall, /*event_info*/, cfg)
if (resources::game_map->on_board(loc)) {
DBG_NG << "No usable leader found, but found usable location. Recalling.\n";
avail.erase(u); // Erase before recruiting, since recruiting can fire more events
map_location null_location = map_location::null_location;
map_location null_location = map_location::null_location();
actions::place_recruit(to_recruit, loc, null_location, 0, true, cfg["show"].to_bool(true),
cfg["fire_event"].to_bool(false), true, true);
return;

View file

@ -27,7 +27,7 @@
// This file is in the game_events namespace.
namespace game_events {
const entity_location entity_location::null_entity(map_location::null_location);
const entity_location entity_location::null_entity(map_location::null_location());
/**
* Constructor for when an event has a location but not necessarily a unit.

View file

@ -633,7 +633,7 @@ protected:
game_data::game_data()
: scoped_variables()
, last_selected(map_location::null_location)
, last_selected(map_location::null_location())
, wml_menu_items_()
, rng_()
, variables_()
@ -648,7 +648,7 @@ game_data::game_data()
game_data::game_data(const config& level)
: scoped_variables()
, last_selected(map_location::null_location)
, last_selected(map_location::null_location())
, wml_menu_items_()
, rng_(level)
, variables_(level.child_or_empty("variables"))

View file

@ -400,7 +400,7 @@ double joystick_manager::get_angle() {
const map_location joystick_manager::get_next_hex(int x_axis, int y_axis, map_location loc) {
map_location new_loc = map_location::null_location;
map_location new_loc = map_location::null_location();
if (x_axis == 0) return (y_axis > 0) ? get_direction(loc, SOUTH) : get_direction(loc, NORTH);
if (y_axis == 0) return (x_axis > 0) ? get_direction(loc, EAST) : get_direction(loc, WEST);

View file

@ -483,7 +483,7 @@ t_translation::t_terrain gamemap::get_terrain(const map_location& loc) const
return tiles_[loc.x + border_size_][loc.y + border_size_];
}
if ( loc == map_location::null_location ) {
if ( loc == map_location::null_location() ) {
return t_translation::NONE_TERRAIN;
}

View file

@ -45,8 +45,6 @@ std::ostream &operator<<(std::ostream &s, std::vector<map_location> const &v) {
return s;
}
const map_location map_location::null_location;
map_location::DIRECTION map_location::parse_direction(const std::string& str)
{
if(!str.empty()) {

View file

@ -49,6 +49,11 @@ struct map_location {
return z;
}
static const map_location & null_location() {
static const map_location l;
return l;
}
static inline DIRECTION rotate_right(DIRECTION d, unsigned int k = 1u) {
return (d == NDIRECTIONS) ? NDIRECTIONS : static_cast<map_location::DIRECTION>((d + (k%6u)) % 6u);
}
@ -115,8 +120,6 @@ 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;
friend std::size_t hash_value(map_location const &a);
};

View file

@ -630,7 +630,7 @@ bool menu_handler::do_recruit(const std::string &name, int side_num,
const events::command_disabler disable_commands;
map_location loc = last_hex;
map_location recruited_from = map_location::null_location;
map_location recruited_from = map_location::null_location();
std::string msg;
{ wb::future_map_if_active future; /* start planned unit map scope if in planning mode */
msg = actions::find_recruit_location(side_num, loc, recruited_from, name);
@ -721,7 +721,7 @@ void menu_handler::recall(int side_num, const map_location &last_hex)
const events::command_disabler disable_commands;
map_location recall_location = last_hex;
map_location recall_from = map_location::null_location;
map_location recall_from = map_location::null_location();
std::string err;
{ wb::future_map_if_active future; // future unit map removes invisible units from map, don't do this outside of planning mode
err = actions::find_recall_location(side_num, recall_location, recall_from, *(recall_list_team[res]));

View file

@ -102,7 +102,7 @@ void mouse_handler::mouse_motion(int x, int y, const bool browse, bool update, m
if (mouse_handler_base::mouse_motion_default(x, y, update)) return;
if (new_hex == map_location::null_location)
if (new_hex == map_location::null_location())
new_hex = gui().hex_clicked_on(x,y);
if(new_hex != last_hex_) {

View file

@ -100,7 +100,7 @@ protected:
/**
* Use update to force an update of the mouse state.
*/
void mouse_motion(int x, int y, const bool browse, bool update=false, map_location loc = map_location::null_location);
void mouse_motion(int x, int y, const bool browse, bool update=false, map_location loc = map_location::null_location());
bool right_click_show_menu(int x, int y, const bool browse);
// bool left_click(int x, int y, const bool browse);
bool move_unit_along_current_route();

View file

@ -73,7 +73,7 @@ public:
* Called when a mouse motion event takes place. Derived classes must provide an
* implementation, possibly using mouse_motion_default().
*/
virtual void mouse_motion(int x, int y, const bool browse, bool update=false, map_location new_loc = map_location::null_location) = 0;
virtual void mouse_motion(int x, int y, const bool browse, bool update=false, map_location new_loc = map_location::null_location()) = 0;
virtual void mouse_press(const SDL_MouseButtonEvent& event, const bool browse);
bool is_left_click(const SDL_MouseButtonEvent& event) const;

View file

@ -173,7 +173,7 @@ plain_route a_star_search(const map_location& src, const map_location& dst,
comp node_comp(nodes);
nodes[index(dst)].g = stop_at + 1;
nodes[index(src)] = node(0, src, map_location::null_location, dst, true, teleports);
nodes[index(src)] = node(0, src, map_location::null_location(), dst, true, teleports);
std::vector<int> pq;
pq.push_back(index(src));
@ -229,7 +229,7 @@ plain_route a_star_search(const map_location& src, const map_location& dst,
if (nodes[index(dst)].g <= stop_at) {
DBG_PF << "found solution; calculating it...\n";
route.move_cost = static_cast<int>(nodes[index(dst)].g);
for (node curr = nodes[index(dst)]; curr.prev != map_location::null_location; curr = nodes[index(curr.prev)]) {
for (node curr = nodes[index(dst)]; curr.prev != map_location::null_location(); curr = nodes[index(curr.prev)]) {
route.steps.push_back(curr.curr);
}
route.steps.push_back(src);

View file

@ -317,7 +317,7 @@ static void find_routes(
// Record the starting location.
assert(index(origin) >= 0);
nodes[index(origin)] = findroute_node(moves_left, turns_left,
map_location::null_location,
map_location::null_location(),
search_counter);
// Begin the search at the starting location.
std::vector<int> hexes_to_process(1, index(origin)); // Will be maintained as a heap.

View file

@ -110,7 +110,7 @@ namespace { // Helpers for get_tiles_radius() without a radius filter.
const int radius_i = static_cast<int>(radius);
BOOST_FOREACH (const map_location &loc, locs)
if ( loc != map_location::null_location )
if ( loc != map_location::null_location() )
{
// Calculate the circle of hexes around this one.
size_t height = radius;

View file

@ -621,7 +621,7 @@ void play_controller::init_side(const unsigned int team_index, bool is_replay){
gui_->set_playing_team(size_t(team_index));
gamedata_.get_variable("side_number") = player_number_;
gamedata_.last_selected = map_location::null_location;
gamedata_.last_selected = map_location::null_location();
maybe_do_init_side(team_index, is_replay);
}

View file

@ -110,7 +110,7 @@ int tod_manager::get_current_area_time(int index) const {
int tod_manager::get_current_time(const map_location& loc) const
{
if ( loc != map_location::null_location ) {
if ( loc != map_location::null_location() ) {
for ( std::vector<area_time_of_day>::const_reverse_iterator
i = areas_.rbegin(), i_end = areas_.rend(); i != i_end; ++i )
{
@ -124,7 +124,7 @@ int tod_manager::get_current_time(const map_location& loc) const
const std::vector<time_of_day>& tod_manager::times(const map_location& loc) const
{
if ( loc != map_location::null_location ) {
if ( loc != map_location::null_location() ) {
for ( std::vector<area_time_of_day>::const_reverse_iterator
i = areas_.rbegin(), i_end = areas_.rend(); i != i_end; ++i )
{
@ -141,7 +141,7 @@ const time_of_day& tod_manager::get_time_of_day(const map_location& loc, int n_t
if(n_turn == 0)
n_turn = turn_;
if ( loc != map_location::null_location )
if ( loc != map_location::null_location() )
{
for ( std::vector<area_time_of_day>::const_reverse_iterator
i = areas_.rbegin(), i_end = areas_.rend(); i != i_end; ++i )

View file

@ -33,7 +33,7 @@ class tod_manager : public savegame::savegame_config
config to_config() const;
int get_current_time(const map_location& loc = map_location::null_location) const;
int get_current_time(const map_location& loc = map_location::null_location()) const;
void set_current_time(int time) { currentTime_ = time; }
@ -135,7 +135,7 @@ class tod_manager : public savegame::savegame_config
bool has_time_area() const {return !areas_.empty();}
const std::vector<time_of_day>& times(const map_location& loc = map_location::null_location) const;
const std::vector<time_of_day>& times(const map_location& loc = map_location::null_location()) const;
const std::vector<time_of_day>& times(int index) const {
assert(index < static_cast<int>(areas_.size()));

View file

@ -347,7 +347,7 @@ public:
const unit_animation* choose_animation(const display& disp,
const map_location& loc, const std::string& event,
const map_location& second_loc = map_location::null_location,
const map_location& second_loc = map_location::null_location(),
const int damage=0,
const unit_animation::hit_type hit_type = unit_animation::INVALID,
const attack_type* attack=NULL,const attack_type* second_attack = NULL,

View file

@ -670,7 +670,7 @@ void attack_type::set_specials_context(const map_location& unit_loc,
void attack_type::set_specials_context(const map_location& loc, bool attacking) const
{
self_loc_ = loc;
other_loc_ = map_location::null_location;
other_loc_ = map_location::null_location();
is_attacker_ = attacking;
other_attack_ = NULL;
}

View file

@ -30,7 +30,7 @@ enum value_modifier {NOT_USED,SET,ADD,MUL,DIV};
struct individual_effect
{
individual_effect() : type(NOT_USED), value(0), ability(NULL),
loc(map_location::null_location) {}
loc(map_location::null_location()) {}
void set(value_modifier t, int val, const config *abil,const map_location &l);
value_modifier type;
int value;

View file

@ -51,8 +51,8 @@ class unit_animation
int get_animation_time() const{ return unit_anim_.get_animation_time() ; }
int get_animation_time_potential() const{ return unit_anim_.get_animation_time_potential() ; }
void start_animation(int start_time
, const map_location &src = map_location::null_location
, const map_location &dst = map_location::null_location
, const map_location &src = map_location::null_location()
, const map_location &dst = map_location::null_location()
, const std::string& text = ""
, const Uint32 text_color = 0
, const bool accelerate = true);
@ -157,14 +157,14 @@ class unit_animator
void add_animation(unit* animated_unit
, const unit_animation * animation
, const map_location &src = map_location::null_location
, const map_location &src = map_location::null_location()
, bool with_bars = false
, const std::string& text = ""
, const Uint32 text_color = 0);
void add_animation(unit* animated_unit
, const std::string& event
, const map_location &src = map_location::null_location
, const map_location &dst = map_location::null_location
, const map_location &src = map_location::null_location()
, const map_location &dst = map_location::null_location()
, const int value = 0
, bool with_bars = false
, const std::string& text = ""
@ -176,8 +176,8 @@ class unit_animator
, int value2 = 0);
void replace_anim_if_invalid(unit* animated_unit
, const std::string& event
, const map_location &src = map_location::null_location
, const map_location &dst = map_location::null_location
, const map_location &src = map_location::null_location()
, const map_location &dst = map_location::null_location()
, const int value = 0
, bool with_bars = false
, const std::string& text = ""

View file

@ -575,7 +575,7 @@ void unit_attack(
return;
}
unit_map& units = disp->get_units();
disp->select_hex(map_location::null_location);
disp->select_hex(map_location::null_location());
// scroll such that there is at least half a hex spacing around fighters
disp->scroll_to_tiles(a,b,game_display::ONSCREEN,true,0.5,false);
@ -697,7 +697,7 @@ void unit_recruited(const map_location& loc,const map_location& leader_loc)
u->set_hidden(true);
unit_animator animator;
if(leader_loc != map_location::null_location) {
if(leader_loc != map_location::null_location()) {
unit_map::iterator leader = disp->get_units().find(leader_loc);
if(leader == disp->get_units().end()) return;
disp->scroll_to_tiles(loc,leader_loc,game_display::ONSCREEN,true,0.0,false);
@ -736,17 +736,17 @@ void unit_healing(unit &healed, const std::vector<unit *> &healers, int healing,
if (healing < 0) {
animator.add_animation(&healed, "poisoned", healed_loc,
map_location::null_location, -healing, false,
map_location::null_location(), -healing, false,
number_and_text(-healing, extra_text),
display::rgb(255,0,0));
} else if ( healing > 0 ) {
animator.add_animation(&healed, "healed", healed_loc,
map_location::null_location, healing, false,
map_location::null_location(), healing, false,
number_and_text(healing, extra_text),
display::rgb(0,255,0));
} else {
animator.add_animation(&healed, "healed", healed_loc,
map_location::null_location, 0, false,
map_location::null_location(), 0, false,
extra_text, display::rgb(0,255,0));
}
animator.start_animations();
@ -754,7 +754,7 @@ void unit_healing(unit &healed, const std::vector<unit *> &healers, int healing,
animator.set_all_standing();
}
void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const map_location &default_location = map_location::null_location);
void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const map_location &default_location = map_location::null_location());
void wml_animation(const vconfig &cfg, const map_location &default_location)
{
@ -827,7 +827,7 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
}
resources::screen->scroll_to_tile(u->get_location(), game_display::ONSCREEN, true, false);
vconfig t_filter = cfg.child("facing");
map_location secondary_loc = map_location::null_location;
map_location secondary_loc = map_location::null_location();
if(!t_filter.empty()) {
terrain_filter filter(t_filter, *resources::units);
std::set<map_location> locs;

View file

@ -83,13 +83,13 @@ void move_unit(const std::vector<map_location>& path, unit& u,
* Play a pre-fight animation
* First unit is the attacker, second unit the defender
*/
void unit_draw_weapon( const map_location& loc, unit& u, const attack_type* attack=NULL, const attack_type*secondary_attack=NULL,const map_location& defender_loc = map_location::null_location, unit * defender=NULL);
void unit_draw_weapon( const map_location& loc, unit& u, const attack_type* attack=NULL, const attack_type*secondary_attack=NULL,const map_location& defender_loc = map_location::null_location(), unit * defender=NULL);
/**
* Play a post-fight animation
* Both unit can be set to null, only valid units will play their animation
*/
void unit_sheath_weapon( const map_location& loc, unit* u=NULL, const attack_type* attack=NULL, const attack_type*secondary_attack=NULL,const map_location& defender_loc = map_location::null_location, unit * defender=NULL);
void unit_sheath_weapon( const map_location& loc, unit* u=NULL, const attack_type* attack=NULL, const attack_type*secondary_attack=NULL,const map_location& defender_loc = map_location::null_location(), unit * defender=NULL);
/**
* Show a unit fading out.
@ -98,7 +98,7 @@ void unit_sheath_weapon( const map_location& loc, unit* u=NULL, const attack_typ
*/
void unit_die( const map_location& loc, unit& u,
const attack_type* attack=NULL, const attack_type* secondary_attack=NULL,
const map_location& winner_loc=map_location::null_location,
const map_location& winner_loc=map_location::null_location(),
unit* winner=NULL);
@ -117,7 +117,7 @@ void unit_attack(const map_location& a, const map_location& b, int damage,
void unit_recruited(const map_location& loc,
const map_location& leader_loc=map_location::null_location);
const map_location& leader_loc=map_location::null_location());
/**
* This will use a poisoning anim if healing<0.
@ -134,7 +134,7 @@ void unit_healing(unit &healed, const std::vector<unit *> &healers, int healing,
* other wml-described animations are needed.
*/
void wml_animation(const vconfig &cfg,
const map_location& default_location=map_location::null_location);
const map_location& default_location=map_location::null_location());
}

View file

@ -1104,7 +1104,7 @@ int unit_type::resistance_against(const std::string& damage_name, bool attacker)
if (!resistance_filter_matches(cfg, attacker, damage_name, 100 - resistance)) {
continue;
}
resistance_abilities.push_back(unit_ability(&cfg, map_location::null_location));
resistance_abilities.push_back(unit_ability(&cfg, map_location::null_location()));
}
}
if (!resistance_abilities.empty()) {

View file

@ -123,7 +123,7 @@ void recall::execute(bool& success, bool& complete)
}
current_team.get_side_actions()->change_gold_spent_by(-cost);
bool const result = synced_context::run_in_synced_context("recall",
replay_helper::get_recall(temp_unit_->id(), recall_hex_, map_location::null_location),
replay_helper::get_recall(temp_unit_->id(), recall_hex_, map_location::null_location()),
true,
true,
true,