made it so if a unit has a little movement left...

...but can't actually move to surrounding terrain, it is displayed as
having moved
This commit is contained in:
Dave White 2003-10-21 13:03:27 +00:00
parent 4dae65c945
commit 89ead17a34
4 changed files with 37 additions and 7 deletions

View file

@ -943,3 +943,34 @@ bool clear_shroud(display& disp, const gamemap& map, const game_data& gamedata,
return true;
}
bool unit_can_move(const gamemap::location& loc, const unit_map& units,
const gamemap& map, const std::vector<team>& teams)
{
const unit_map::const_iterator u_it = units.find(loc);
assert(u_it != units.end());
const unit& u = u_it->second;
const team& current_team = teams[u.side()-1];
if(!u.can_attack())
return false;
gamemap::location locs[6];
get_adjacent_tiles(loc,locs);
for(int n = 0; n != 6; ++n) {
if(map.on_board(locs[n])) {
const unit_map::const_iterator i = units.find(locs[n]);
if(i != units.end()) {
if(current_team.is_enemy(i->second.side())) {
return true;
}
} else if(u.movement_cost(map,map[locs[n].x][locs[n].y]) <=
u.movement_left()) {
return true;
}
}
}
return false;
}

View file

@ -116,4 +116,7 @@ size_t move_unit(display* disp, const gamemap& map,
bool clear_shroud(display& disp, const gamemap& map, const game_data& gamedata,
const unit_map& units, std::vector<team>& teams, int team);
bool unit_can_move(const gamemap::location& loc, const unit_map& units,
const gamemap& map, const std::vector<team>& teams);
#endif

View file

@ -964,7 +964,7 @@ void display::draw_tile(int x, int y, SDL_Surface* unit_image,
} else {
if(unit_move == unit_total_move) {
energy_file = "unmoved-energy.png";
} else if(unit_move > 0) {
} else if(unit_can_move(loc,units_,map_,teams_)) {
energy_file = "partmoved-energy.png";
} else {
energy_file = "moved-energy.png";

View file

@ -895,9 +895,7 @@ bool turn_slice(game_data& gameinfo, game_state& state_of_game,
unit_map::const_iterator it = units.find(next_unit);
if(it != units.end()) {
for(++it; it != units.end(); ++it) {
if(it->second.side() == team_num &&
it->second.movement_left() > 0 &&
it->second.get_goto().valid() == false) {
if(unit_can_move(it->first,units,map,teams)) {
break;
}
}
@ -905,9 +903,7 @@ bool turn_slice(game_data& gameinfo, game_state& state_of_game,
if(it == units.end()) {
for(it = units.begin(); it != units.end(); ++it) {
if(it->second.side() == team_num &&
it->second.movement_left() > 0 &&
it->second.get_goto().valid() == false) {
if(unit_can_move(it->first,units,map,teams)) {
break;
}
}