Check for occupied tunnel exits at teleport map creation

Previously this was done in the move execution, which resulted in:
1. own and allied units on tunnel/teleport exits effectively acting as
ambushers and
2. unit reaches and shortest paths not being consistent with actually
possible moves.
Both issues occurred even without fog being active.

The former was unintuitive at best, while the latter could cause
serious problems, for example with AI code. By moving the check for
units on tunnel exits to the teleport map creation, both these issues
are taken care of simultaneously.

Only visible units are considered. In the presence of fog, enemy units
and units from allies without shared vision continue to interrupt the
move as expected.
This commit is contained in:
mattsc 2016-09-15 13:50:30 -07:00
parent dc89612dc4
commit 0452848966
2 changed files with 13 additions and 7 deletions

View file

@ -453,12 +453,6 @@ namespace { // Private helpers for move_unit()
if ( blocking_unit == resources::units->end() )
return false;
if ( !tiles_adjacent(hex, prev_hex) ) {
// Cannot teleport to an occupied hex.
teleport_failed_ = true;
return true;
}
if ( current_team_->is_enemy(blocking_unit->side()) ) {
// Trying to go through an enemy.
blocked_loc_ = hex;

View file

@ -182,8 +182,20 @@ teleport_map::teleport_map(
locations.first.swap(filter_locs.first);
locations.second.swap(filter_locs.second);
}
std::string teleport_id = group.get_teleport_id();
if (!ignore_units) {
std::set<map_location>::iterator loc = locations.second.begin();
while(loc != locations.second.end()) {
const unit *v = resources::gameboard->get_visible_unit(*loc, viewing_team, see_all);
if (v) {
loc = locations.second.erase(loc);
} else {
++loc;
}
}
}
std::string teleport_id = group.get_teleport_id();
std::set<map_location>::iterator source_it = locations.first.begin();
for (; source_it != locations.first.end(); ++source_it ) {
if(teleport_map_.count(*source_it) == 0) {