Neatening:

use unit_map everywhere in preparation for making it a real class to
speed up AI
This commit is contained in:
Rusty Russell 2006-05-28 05:21:57 +00:00
parent ee1e406e42
commit bbae6cf1c2
19 changed files with 76 additions and 94 deletions

View file

@ -97,10 +97,9 @@ std::string recruit_unit(const gamemap& map, int side,
const events::command_disabler disable_commands;
LOG_NG << "recruiting unit for side " << side << "\n";
typedef std::map<gamemap::location,unit> units_map;
//find the unit that can recruit
units_map::const_iterator u = units.begin();
unit_map::const_iterator u = units.begin();
for(; u != units.end(); ++u) {
if(u->second.can_recruit() && (int)u->second.side() == side) {
@ -208,7 +207,7 @@ void validate_recruit_unit()
}
gamemap::location under_leadership(const units_map& units,
gamemap::location under_leadership(const unit_map& units,
const gamemap::location& loc, int* bonus)
{
@ -226,7 +225,7 @@ gamemap::location under_leadership(const units_map& units,
unsigned int num_battle_contexts;
battle_context::battle_context(const gamemap& map, const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
battle_context::battle_context(const gamemap& map, const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc,
int attacker_weapon, double harm_weight, const combatant *prev_def)
@ -288,7 +287,7 @@ battle_context& battle_context::operator=(const battle_context &other)
// FIXME: Hand previous defender unit in here...
int battle_context::choose_defender_weapon(const unit &attacker, const unit &defender, unsigned attacker_weapon,
const gamemap& map, const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc,
const combatant *prev_def)
@ -344,7 +343,7 @@ int battle_context::choose_defender_weapon(const unit &attacker, const unit &def
}
unsigned battle_context::choose_attacker_weapon(const unit &attacker, const unit &defender,
const gamemap& map, const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc,
double harm_weight, int *defender_weapon, const combatant *prev_def)
@ -478,7 +477,7 @@ battle_context::unit_stats::unit_stats(const unit &u, const gamemap::location& u
int u_attack_num, bool attacking,
const unit &opp, const gamemap::location& opp_loc,
const attack_type *opp_weapon,
const std::map<gamemap::location,unit>& units,
const unit_map& units,
const std::vector<team>& teams,
const gamestatus& status,
const gamemap& map,
@ -634,7 +633,7 @@ void attack(display& gui, const gamemap& map,
gamemap::location attacker,
gamemap::location defender,
int attack_with,
units_map& units,
unit_map& units,
const gamestatus& state,
const game_data& info,
bool update_display)
@ -642,8 +641,8 @@ void attack(display& gui, const gamemap& map,
//stop the user from issuing any commands while the units are fighting
const events::command_disabler disable_commands;
units_map::iterator a = units.find(attacker);
units_map::iterator d = units.find(defender);
unit_map::iterator a = units.find(attacker);
unit_map::iterator d = units.find(defender);
if(a == units.end() || d == units.end()) {
return;
@ -1288,7 +1287,7 @@ unit_map::const_iterator find_leader(const unit_map& units, int side)
}
// Simple algorithm: no maximum number of patients per healer.
void reset_resting(std::map<gamemap::location,unit>& units, unsigned int side)
void reset_resting(unit_map& units, unsigned int side)
{
for (unit_map::iterator i = units.begin(); i != units.end(); ++i) {
if (i->second.side() == side)
@ -1297,7 +1296,7 @@ void reset_resting(std::map<gamemap::location,unit>& units, unsigned int side)
}
void calculate_healing(display& disp, const gamemap& map,
units_map& units, unsigned int side,
unit_map& units, unsigned int side,
const std::vector<team>& teams, bool update_display)
{
// We look for all allied units, then we see if our healer is near them.
@ -1484,11 +1483,11 @@ void calculate_healing(display& disp, const gamemap& map,
unit get_advanced_unit(const game_data& info,
units_map& units,
unit_map& units,
const gamemap::location& loc, const std::string& advance_to)
{
const std::map<std::string,unit_type>::const_iterator new_type = info.unit_types.find(advance_to);
const units_map::iterator un = units.find(loc);
const unit_map::iterator un = units.find(loc);
if(new_type != info.unit_types.end() && un != units.end()) {
unit new_unit(un->second);
new_unit.get_experience(-new_unit.max_experience());
@ -1501,7 +1500,7 @@ unit get_advanced_unit(const game_data& info,
}
void advance_unit(const game_data& info,
units_map& units,
unit_map& units,
gamemap::location loc, const std::string& advance_to)
{
if(units.count(loc) == 0) {
@ -1521,11 +1520,11 @@ void advance_unit(const game_data& info,
game_events::fire("post_advance",loc);
}
void check_victory(units_map& units,
void check_victory(unit_map& units,
std::vector<team>& teams)
{
std::vector<int> seen_leaders;
for(units_map::const_iterator i = units.begin();
for(unit_map::const_iterator i = units.begin();
i != units.end(); ++i) {
if(i->second.can_recruit()) {
LOG_NG << "seen leader for side " << i->second.side() << "\n";
@ -1616,7 +1615,7 @@ time_of_day timeofday_at(const gamestatus& status,const unit_map& units,const ga
}
int combat_modifier(const gamestatus& status,
const units_map& units,
const unit_map& units,
const gamemap::location& loc,
unit_type::ALIGNMENT alignment,
const gamemap& map)
@ -1849,7 +1848,7 @@ size_t move_unit(display* disp, const game_data& gamedata,
if(adjacent[i] == ui->first)
continue;
const units_map::const_iterator it = units.find(adjacent[i]);
const unit_map::const_iterator it = units.find(adjacent[i]);
if(it != units.end() && teams[u.side()-1].is_enemy(it->second.side()) &&
it->second.invisible(it->first,units,teams)) {
discovered_unit = true;
@ -2127,9 +2126,9 @@ void apply_shroud_changes(undo_list& undos, display* disp, const gamestatus& sta
bool backstab_check(const gamemap::location& attacker_loc,
const gamemap::location& defender_loc,
const units_map& units, const std::vector<team>& teams)
const unit_map& units, const std::vector<team>& teams)
{
const units_map::const_iterator defender =
const unit_map::const_iterator defender =
units.find(defender_loc);
if(defender == units.end()) return false; // No defender
@ -2142,7 +2141,7 @@ bool backstab_check(const gamemap::location& attacker_loc,
}
if(i >= 6) return false; // Attack not from adjacent location
const units_map::const_iterator opp =
const unit_map::const_iterator opp =
units.find(adj[(i+3)%6]);
if(opp == units.end()) return false; // No opposite unit
if(opp->second.incapacitated()) return false;

View file

@ -25,7 +25,6 @@ struct combatant;
#include "unit.hpp"
#include <deque>
typedef std::map<gamemap::location,unit> units_map;
#define RECRUIT_POS -2
@ -88,7 +87,7 @@ public:
int u_attack_num, bool attacking,
const unit &opp, const gamemap::location& opp_loc,
const attack_type *opp_weapon,
const std::map<gamemap::location,unit>& units,
const unit_map& units,
const std::vector<team>& teams,
const gamestatus& status, const gamemap& map, const game_data& gamedata);
@ -99,7 +98,7 @@ public:
// If no attacker_weapon is given, we select best one, based on
// harm_weight (1.0 means 1 hp lost counters 1 hp damage, 0.0
// means we ignore harm weight). prev_def is for predicting multiple attacks against a defender.
battle_context(const gamemap& map, const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
battle_context(const gamemap& map, const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc,
int attacker_weapon = -1, double harm_weight = 1.0, const combatant *prev_def = NULL);
@ -128,13 +127,13 @@ private:
double harm_weight);
unsigned int choose_attacker_weapon(const unit &attacker, const unit &defender,
const gamemap& map, const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc,
double harm_weight, int *defender_weapon, const combatant *prev_def);
int choose_defender_weapon(const unit &attacker, const unit &defender, unsigned attacker_weapon,
const gamemap& map, const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const gamemap& map, const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc, const combatant *prev_def);
@ -151,7 +150,7 @@ void attack(display& gui, const gamemap& map,
gamemap::location attacker,
gamemap::location defender,
int attack_with,
units_map& units,
unit_map& units,
const gamestatus& state,
const game_data& info,
bool update_display = true);
@ -176,23 +175,19 @@ unit_map::const_iterator find_leader(const unit_map& units, int side);
// Resets resting for all units on this side: should be called after calculate_healing().
// FIXME: Try moving this to unit::new_turn, then move it above calculate_healing().
void reset_resting(std::map<gamemap::location,unit>& units, unsigned int side);
void reset_resting(unit_map& units, unsigned int side);
//calculates healing for all units for the given side. Should be called
//at the beginning of a side's turn.
void calculate_healing(display& disp, const gamemap& map,
units_map& units, unsigned int side,
unit_map& units, unsigned int side,
const std::vector<team>& teams, bool update_display);
// Resets resting for all units on this side: should be called after calculate_healing().
// FIXME: Try moving this to unit::new_turn, then move it above calculate_healing().
void reset_resting(std::map<gamemap::location,unit>& units, unsigned int side);
//function which, given the location of a unit that is advancing, and the
//name of the unit it is advancing to, will return the advanced version of
//this unit. (with traits and items retained).
unit get_advanced_unit(const game_data& info,
units_map& units,
unit_map& units,
const gamemap::location& loc, const std::string& advance_to);
//function which will advance the unit at loc to 'advance_to'.
@ -200,7 +195,7 @@ unit get_advanced_unit(const game_data& info,
//safely pass in a reference to the item in the map that we're going to delete,
//since deletion would invalidate the reference.
void advance_unit(const game_data& info,
units_map& units,
unit_map& units,
gamemap::location loc, const std::string& advance_to);
//function which tests if the unit at loc is currently affected
@ -208,26 +203,26 @@ void advance_unit(const game_data& info,
//if it does, then the location of the leader unit will be returned, otherwise
//gamemap::location::null_location will be returned
//if 'bonus' is not NULL, the % bonus will be stored in it
gamemap::location under_leadership(const units_map& units,
gamemap::location under_leadership(const unit_map& units,
const gamemap::location& loc, int* bonus=NULL);
//checks to see if a side has won, and will throw an end_level_exception
//if one has. Will also remove control of villages from sides with dead leaders
void check_victory(units_map& units,
void check_victory(unit_map& units,
std::vector<team>& teams);
//gets the time of day at a certain tile. Certain tiles may have a time of
//day that differs from 'the' time of day, if a unit that illuminates is
//in that tile or adjacent.
time_of_day timeofday_at(const gamestatus& status,
const units_map& units,
const unit_map& units,
const gamemap::location& loc,
const gamemap& map);
//returns the amount that a unit's damage should be multiplied by due to
//the current time of day.
int combat_modifier(const gamestatus& status,
const units_map& units,
const unit_map& units,
const gamemap::location& loc,
unit_type::ALIGNMENT alignment,
const gamemap& map);
@ -298,6 +293,6 @@ namespace victory_conditions {
//be made to make sure the opposite unit isn't also the attacker.
bool backstab_check(const gamemap::location& attacker_loc,
const gamemap::location& defender_loc,
const units_map& units, const std::vector<team>& teams);
const unit_map& units, const std::vector<team>& teams);
#endif

View file

@ -627,7 +627,7 @@ void ai::attack_enemy(const location& attacking_unit, const location& target, in
void ai_interface::calculate_possible_moves(std::map<location,paths>& res, move_map& srcdst, move_map& dstsrc, bool enemy, bool assume_full_movement, const std::set<gamemap::location>* remove_destinations)
{
for(units_map::iterator un_it = info_.units.begin(); un_it != info_.units.end(); ++un_it) {
for(unit_map::iterator un_it = info_.units.begin(); un_it != info_.units.end(); ++un_it) {
//if we are looking for the movement of enemies, then this unit must be an enemy unit
//if we are looking for movement of our own units, it must be on our side.
//if we are assuming full movement, then it may be a unit on our side, or allied

View file

@ -23,14 +23,12 @@
#include "config.hpp"
#include "gamestatus.hpp"
class unit;
typedef std::map<gamemap::location,unit> units_map;
//This module is responsible for constructing objects like 'team'
//or 'unit' out of config-information, that is based on WML.
std::string get_unique_saveid(const config& cfg, std::set<std::string>& seen_save_ids);
int get_first_human_team(const config::child_list::const_iterator& cfg, const config::child_list& unit_cfg);
void get_player_info(const config& cfg, game_state& gamestate, std::string save_id, std::vector<team>& teams, const config& level, const game_data& gameinfo, gamemap& map, units_map& units, gamestatus& game_status);
void get_player_info(const config& cfg, game_state& gamestate, std::string save_id, std::vector<team>& teams, const config& level, const game_data& gameinfo, gamemap& map, unit_map& units, gamestatus& game_status);
const config* get_theme(const config& game_config, std::string theme_name);
#endif

View file

@ -52,11 +52,11 @@ namespace dialogs
void advance_unit(const game_data& info,
const gamemap& map,
units_map& units,
unit_map& units,
gamemap::location loc,
display& gui, bool random_choice)
{
units_map::iterator u = units.find(loc);
unit_map::iterator u = units.find(loc);
if(u == units.end() || u->second.advances() == false)
return;
@ -116,7 +116,7 @@ bool animate_unit_advancement(const game_data& info,unit_map& units, gamemap::lo
{
const events::command_disabler cmd_disabler;
units_map::iterator u = units.find(loc);
unit_map::iterator u = units.find(loc);
if(u == units.end() || u->second.advances() == false) {
return false;
}

View file

@ -965,7 +965,7 @@ void display::draw_sidebar()
if(invalidateUnit_) {
//we display the unit the mouse is over if it is over a unit
//otherwise we display the unit that is selected
units_map::const_iterator i =
unit_map::const_iterator i =
find_visible_unit(units_,mouseoverHex_,
map_,
teams_,teams_[viewing_team()]);

View file

@ -50,8 +50,6 @@ class gamestatus;
class display
{
public:
typedef std::map<gamemap::location,unit> unit_map;
display(unit_map& units, CVideo& video,
const gamemap& map, const gamestatus& status,
const std::vector<team>& t, const config& theme_cfg,

View file

@ -243,7 +243,7 @@ display& game_controller::disp()
throw CVideo::error();
}
static display::unit_map dummy_umap;
static unit_map dummy_umap;
static config dummy_cfg;
static gamemap dummy_map(dummy_cfg, "1");
static gamestatus dummy_status(dummy_cfg, 0);

View file

@ -49,7 +49,7 @@ namespace {
display* screen = NULL;
gamemap* game_map = NULL;
units_map* units = NULL;
unit_map* units = NULL;
std::vector<team>* teams = NULL;
game_state* state_of_game = NULL;
const game_data* game_data_ptr = NULL;
@ -59,7 +59,7 @@ int floating_label = 0;
namespace game_events {
bool conditional_passed(const units_map* units,
bool conditional_passed(const unit_map* units,
const vconfig cond)
{
//an 'and' statement means that if the contained statements are false,
@ -91,7 +91,7 @@ bool conditional_passed(const units_map* units,
if(units == NULL)
return false;
units_map::const_iterator itor;
unit_map::const_iterator itor;
for(itor = units->begin(); itor != units->end(); ++itor) {
if(itor->second.hitpoints() > 0 && game_events::unit_matches_filter(itor, *u)) {
break;
@ -924,7 +924,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
item["role"] = "";
vconfig filter(&item);
units_map::iterator itor;
unit_map::iterator itor;
for(itor = units->begin(); itor != units->end(); ++itor) {
if(game_events::unit_matches_filter(itor, filter)) {
itor->second.assign_role(cfg["role"]);
@ -995,7 +995,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
}
else if(cmd == "unit_overlay") {
for(units_map::iterator itor = units->begin(); itor != units->end(); ++itor) {
for(unit_map::iterator itor = units->begin(); itor != units->end(); ++itor) {
if(game_events::unit_matches_filter(itor,cfg)) {
itor->second.add_overlay(cfg["image"]);
break;
@ -1004,7 +1004,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
}
else if(cmd == "remove_unit_overlay") {
for(units_map::iterator itor = units->begin(); itor != units->end(); ++itor) {
for(unit_map::iterator itor = units->begin(); itor != units->end(); ++itor) {
if(game_events::unit_matches_filter(itor,cfg)) {
itor->second.remove_overlay(cfg["image"]);
break;
@ -1287,7 +1287,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
//displaying a message dialog
else if(cmd == "message") {
units_map::iterator speaker = units->end();
unit_map::iterator speaker = units->end();
std::string speaker_str = cfg["speaker"];
wassert(state_of_game != NULL);
@ -1976,7 +1976,7 @@ config::child_list unit_wml_configs;
std::set<std::string> unit_wml_ids;
manager::manager(const config& cfg, display& gui_, gamemap& map_,
units_map& units_,
unit_map& units_,
std::vector<team>& teams_,
game_state& state_of_game_, gamestatus& status,
const game_data& game_data_) :
@ -2089,7 +2089,7 @@ bool pump()
bool result = false;
if(units != NULL) {
for(units_map::const_iterator u_it = units->begin(); u_it != units->end(); ++u_it) {
for(unit_map::const_iterator u_it = units->begin(); u_it != units->end(); ++u_it) {
if(std::find(unit_wml_ids.begin(),unit_wml_ids.end(),u_it->second.id()) == unit_wml_ids.end()) {
unit_wml_ids.insert(u_it->second.id());
config::child_list ev_list = u_it->second.wml_events();

View file

@ -37,7 +37,6 @@ class display;
//movement, keyboard events, etc. See events.hpp for how they are handled.
namespace game_events
{
typedef std::map<gamemap::location,unit> units_map;
//the game event manager loads the scenario configuration object, and
//ensures that events are handled according to the scenario configuration
//for its lifetime.
@ -48,7 +47,7 @@ struct manager {
//note that references will be maintained, and must remain valid
//for the life of the object.
manager(const config& scenario_cfg, display& disp, gamemap& map,
units_map& units, std::vector<team>& teams,
unit_map& units, std::vector<team>& teams,
game_state& state_of_game, gamestatus& status, const game_data& data);
~manager();
@ -73,7 +72,7 @@ void raise(const std::string& event,
const gamemap::location& loc2=gamemap::location::null_location,
const config& data=config());
bool conditional_passed(const units_map* units,
bool conditional_passed(const unit_map* units,
const vconfig cond);
bool pump();

View file

@ -425,7 +425,7 @@ namespace events{
buf << side_num;
side["side"] = buf.str();
for(units_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
if(i->second.side() == side_num) {
config& u = side.add_child("unit");
i->first.write(u);

View file

@ -58,7 +58,7 @@ namespace{
// Lengthy constructor.
battle_prediction_pane(display &disp, const battle_context& bc, const gamemap& map,
const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc);
@ -159,7 +159,7 @@ namespace{
const int battle_prediction_pane::max_hp_distrib_rows_ = 10;
battle_prediction_pane::battle_prediction_pane(display &disp, const battle_context& bc, const gamemap& map,
const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc)
: gui::preview_pane(disp.video()), disp_(disp), bc_(bc), map_(map), teams_(teams), units_(units), status_(status),
@ -628,7 +628,7 @@ namespace{
{
public:
attack_prediction_displayer(display& disp, const std::vector<battle_context>& bc_vector, const gamemap& map,
const std::vector<team>& teams, const std::map<gamemap::location,unit>& units,
const std::vector<team>& teams, const unit_map& units,
const gamestatus& status, const game_data& gamedata,
const gamemap::location& attacker_loc, const gamemap::location& defender_loc)
: disp_(disp), bc_vector_(bc_vector), map_(map), teams_(teams), units_(units), status_(status),

View file

@ -218,7 +218,7 @@ label_AStarSearch_end:
namespace {
gamemap::location find_vacant(const gamemap& map,
const units_map& units,
const unit_map& units,
const gamemap::location& loc, int depth,
VACANT_TILE_TYPE vacancy,
std::set<gamemap::location>& touched)
@ -254,7 +254,7 @@ namespace {
}
gamemap::location find_vacant_tile(const gamemap& map,
const units_map& units,
const unit_map& units,
const gamemap::location& loc,
VACANT_TILE_TYPE vacancy)
{
@ -327,7 +327,7 @@ void get_tiles_radius(gamemap const &map, std::vector<gamemap::location> const &
}
bool enemy_zoc(gamemap const &map,
std::map<gamemap::location, unit> const &units,
unit_map const &units,
std::vector<team> const &teams,
gamemap::location const &loc, team const &viewing_team, unsigned int side)
{
@ -335,7 +335,7 @@ bool enemy_zoc(gamemap const &map,
const team &current_team = teams[side-1];
get_adjacent_tiles(loc,locs);
for(int i = 0; i != 6; ++i) {
const units_map::const_iterator it
const unit_map::const_iterator it
= find_visible_unit(units, locs[i], map, teams, viewing_team);
if (it != units.end() && it->second.side() != side &&
current_team.is_enemy(it->second.side()) && it->second.emits_zoc()) {
@ -350,7 +350,7 @@ namespace {
void find_routes(const gamemap& map, const gamestatus& status,
const game_data& gamedata,
const units_map& units,
const unit_map& units,
const unit& u,
const gamemap::location& loc,
int move_left,
@ -398,7 +398,7 @@ namespace {
continue;
//see if the tile is on top of an enemy unit
const units_map::const_iterator unit_it =
const unit_map::const_iterator unit_it =
find_visible_unit(units, locs[i], map, teams, viewing_team);
if (unit_it != units.end() &&
@ -450,13 +450,13 @@ namespace {
paths::paths(gamemap const &map, gamestatus const &status,
game_data const &gamedata,
std::map<gamemap::location, unit> const &units,
unit_map const &units,
gamemap::location const &loc,
std::vector<team> const &teams,
bool ignore_zocs, bool allow_teleport, const team &viewing_team,
int additional_turns)
{
const units_map::const_iterator i = units.find(loc);
const unit_map::const_iterator i = units.find(loc);
if(i == units.end()) {
std::cerr << "unit not found\n";
return;

View file

@ -29,7 +29,6 @@ class gamestatus;
//a convenient type for storing a list of tiles adjacent to a certain tile
typedef util::array<gamemap::location,6> adjacent_tiles_array;
typedef std::map<gamemap::location,unit> units_map;
//function which, given a location, will find all tiles within 'radius' of that tile
void get_tiles_radius(const gamemap::location& a, size_t radius, std::set<gamemap::location>& res);
@ -47,13 +46,13 @@ enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
//
//if no valid location can be found, it will return a null location.
gamemap::location find_vacant_tile(const gamemap& map,
const units_map& un,
const unit_map& un,
const gamemap::location& loc,
VACANT_TILE_TYPE vacancy=VACANT_ANY);
//function which determines if a given location is an enemy zone of control
bool enemy_zoc(gamemap const &map,
std::map<gamemap::location, unit> const &units,
unit_map const &units,
std::vector<team> const &teams, gamemap::location const &loc,
team const &viewing_team, unsigned int side);
@ -79,7 +78,7 @@ struct paths
//viewing_team is usually current team, except for Show Enemy Moves etc.
paths(gamemap const &map, gamestatus const &status,
game_data const &gamedata,
std::map<gamemap::location, unit> const &units,
unit_map const &units,
gamemap::location const &loc, std::vector<team> const &teams,
bool ignore_zocs, bool allow_teleport,
const team &viewing_team, int additional_turns = 0);

View file

@ -653,7 +653,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const gamemap::location loc(*child);
const std::string& name = (*child)["name"];
units_map::iterator u = units.find(loc);
unit_map::iterator u = units.find(loc);
if(u->second.unrenamable()) {
ERR_NW << "renaming unrenamable unit " << u->second.name() << "\n";
@ -794,7 +794,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const gamemap::location src(*source);
const gamemap::location dst(*destination);
units_map::iterator u = units.find(dst);
unit_map::iterator u = units.find(dst);
if(u != units.end()) {
ERR_NW << "destination already occupied: "
<< dst << '\n';
@ -888,7 +888,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const std::string& weapon = (*child)["weapon"];
const int weapon_num = atoi(weapon.c_str());
units_map::iterator u = units.find(src);
unit_map::iterator u = units.find(src);
if(u == units.end()) {
ERR_NW << "unfound location for source of attack\n";
throw replay::error();
@ -899,7 +899,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
if (!game_config::ignore_replay_errors) throw replay::error();
}
units_map::const_iterator tgt = units.find(dst);
unit_map::const_iterator tgt = units.find(dst);
if(tgt == units.end()) {
ERR_NW << "unfound defender for attack: " << src << " -> " << dst << '\n';

View file

@ -20,7 +20,6 @@
#include "unit.hpp"
class display;
typedef std::map<gamemap::location,unit> units_map;
struct verification_manager
{
@ -131,7 +130,7 @@ extern replay recorder;
//replays up to one turn from the recorder object
//returns true if it got to the end of the turn without data running out
bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
units_map& units,
unit_map& units,
std::vector<team>& teams, int team_num, const gamestatus& state,
game_state& state_of_game, replay* obj=NULL);

View file

@ -31,10 +31,6 @@ class gamestatus;
#include <string>
#include <vector>
typedef std::map<gamemap::location,unit> unit_map;
class unit_ability_list
{
public:

View file

@ -20,8 +20,6 @@
#include <deque>
typedef std::map<gamemap::location,unit> units_map;
/*
*
* [abilities]
@ -302,7 +300,7 @@ bool unit::ability_active(const std::string& ability,const config& cfg,const gam
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
index = gamemap::location::parse_direction(*j);
if(index != gamemap::location::NDIRECTIONS) {
units_map::const_iterator unit = units_->find(adjacent[index]);
unit_map::const_iterator unit = units_->find(adjacent[index]);
if(unit == units_->end()) {
return false;
}
@ -721,7 +719,7 @@ bool attack_type::special_active(const config& cfg,bool self,bool report) const
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
index = gamemap::location::parse_direction(*j);
if(index != gamemap::location::NDIRECTIONS) {
units_map::const_iterator unit = unitmap_->find(adjacent[index]);
unit_map::const_iterator unit = unitmap_->find(adjacent[index]);
if(unit == unitmap_->end()) {
return false;
}

View file

@ -31,6 +31,7 @@ struct game_data;
class gamestatus;
class team;
typedef std::map<gamemap::location,unit> unit_map;
//and how much damage it does.
class attack_type
{