Eliminate some parameters that are always *resources::game_map.

This commit is contained in:
J. Tyne 2013-02-15 02:38:42 +00:00
parent ceef0aa07d
commit 51273aceb4
9 changed files with 56 additions and 59 deletions

View File

@ -319,16 +319,15 @@ private:
int ai_default_recruitment_stage::average_resistance_against(const unit_type& a, const unit_type& b) const
{
int weighting_sum = 0, defense = 0;
gamemap &map_ = *resources::game_map;
const std::map<t_translation::t_terrain, size_t>& terrain =
map_.get_weighted_terrain_frequencies();
resources::game_map->get_weighted_terrain_frequencies();
for (std::map<t_translation::t_terrain, size_t>::const_iterator j = terrain.begin(),
j_end = terrain.end(); j != j_end; ++j)
{
// Use only reachable tiles when computing the average defense.
if (a.movement_type().movement_cost(map_, j->first) < unit_movement_type::UNREACHABLE) {
defense += a.movement_type().defense_modifier(map_, j->first) * j->second;
if (a.movement_type().movement_cost(j->first) < unit_movement_type::UNREACHABLE) {
defense += a.movement_type().defense_modifier(j->first) * j->second;
weighting_sum += j->second;
}
}
@ -340,7 +339,7 @@ int ai_default_recruitment_stage::average_resistance_against(const unit_type& a,
for (std::map<t_translation::t_terrain, size_t>::const_iterator jj = terrain.begin(),
jj_end = terrain.end(); jj != jj_end; ++jj)
{
defense += a.movement_type().defense_modifier(map_, jj->first) * jj->second;
defense += a.movement_type().defense_modifier(jj->first) * jj->second;
weighting_sum += jj->second;
}
}

View File

@ -81,9 +81,9 @@ class unit_adapter {
}
}
int movement_cost(const gamemap& map, const t_translation::t_terrain & terrain) const {
int movement_cost(const t_translation::t_terrain & terrain) const {
if(unit_type_ != NULL) {
return unit_type_->movement_type().movement_cost(map, terrain);
return unit_type_->movement_type().movement_cost(terrain);
} else {
return unit_->movement_cost(terrain);
}
@ -232,7 +232,7 @@ private:
// test if the current path to locs[i] is better than this one could possibly be.
// we do this a couple more times below
if (next_visited && !(n < next) ) continue;
const int move_cost = u.movement_cost(map, map[locs[i]]);
const int move_cost = u.movement_cost(map[locs[i]]);
node t = node(n.movement_cost_ + move_cost, locs[i]);
@ -1536,14 +1536,14 @@ private:
{
const unit_type& un = u_type->get_unit_type();
if( un.movement() < un.movement_type().movement_cost(*resources::game_map, (*resources::game_map)[loc]) )
return variant();
if( un.movement() < un.movement_type().movement_cost((*resources::game_map)[loc]) )
return variant();
if(!resources::game_map->on_board(loc)) {
return variant();
}
return variant(100 - un.movement_type().defense_modifier(*resources::game_map, (*resources::game_map)[loc]));
return variant(100 - un.movement_type().defense_modifier((*resources::game_map)[loc]));
}
return variant();
@ -1587,7 +1587,7 @@ private:
return variant();
}
return variant(un.movement_type().defense_modifier(*resources::game_map, (*resources::game_map)[loc]));
return variant(un.movement_type().defense_modifier((*resources::game_map)[loc]));
}
return variant();
@ -1631,7 +1631,7 @@ private:
return variant();
}
return variant(un.movement_type().movement_cost(*resources::game_map, (*resources::game_map)[loc]));
return variant(un.movement_type().movement_cost((*resources::game_map)[loc]));
}
return variant();

View File

@ -363,18 +363,16 @@ bool recruitment_phase::recruit_usage(const std::string& usage)
int recruitment_phase::average_resistance_against(const unit_type& a, const unit_type& b) const
{
gamemap &map_ = *resources::game_map;
int weighting_sum = 0, defense = 0;
const std::map<t_translation::t_terrain, size_t>& terrain =
map_.get_weighted_terrain_frequencies();
resources::game_map->get_weighted_terrain_frequencies();
for (std::map<t_translation::t_terrain, size_t>::const_iterator j = terrain.begin(),
j_end = terrain.end(); j != j_end; ++j)
{
// Use only reachable tiles when computing the average defense.
if (a.movement_type().movement_cost(map_, j->first) < unit_movement_type::UNREACHABLE) {
defense += a.movement_type().defense_modifier(map_, j->first) * j->second;
if (a.movement_type().movement_cost(j->first) < unit_movement_type::UNREACHABLE) {
defense += a.movement_type().defense_modifier(j->first) * j->second;
weighting_sum += j->second;
}
}
@ -386,7 +384,7 @@ int recruitment_phase::average_resistance_against(const unit_type& a, const unit
for (std::map<t_translation::t_terrain, size_t>::const_iterator jj = terrain.begin(),
jj_end = terrain.end(); jj != jj_end; ++jj)
{
defense += a.movement_type().defense_modifier(map_, jj->first) * jj->second;
defense += a.movement_type().defense_modifier(jj->first) * jj->second;
weighting_sum += jj->second;
}
}

View File

@ -249,18 +249,16 @@ class fake_team
static int average_resistance_against(const unit_type& a, const unit_type& b)
{
gamemap &map_ = *resources::game_map;
int weighting_sum = 0, defense = 0;
const std::map<t_translation::t_terrain, size_t>& terrain =
map_.get_weighted_terrain_frequencies();
resources::game_map->get_weighted_terrain_frequencies();
for (std::map<t_translation::t_terrain, size_t>::const_iterator j = terrain.begin(),
j_end = terrain.end(); j != j_end; ++j)
{
// Use only reachable tiles when computing the average defense.
if (a.movement_type().movement_cost(map_, j->first) < unit_movement_type::UNREACHABLE) {
defense += a.movement_type().defense_modifier(map_, j->first) * j->second;
if (a.movement_type().movement_cost(j->first) < unit_movement_type::UNREACHABLE) {
defense += a.movement_type().defense_modifier(j->first) * j->second;
weighting_sum += j->second;
}
}
@ -272,7 +270,7 @@ static int average_resistance_against(const unit_type& a, const unit_type& b)
for (std::map<t_translation::t_terrain, size_t>::const_iterator jj = terrain.begin(),
jj_end = terrain.end(); jj != jj_end; ++jj)
{
defense += a.movement_type().defense_modifier(map_, jj->first) * jj->second;
defense += a.movement_type().defense_modifier(jj->first) * jj->second;
weighting_sum += jj->second;
}
}

View File

@ -1630,9 +1630,9 @@ public:
std::vector<item> row;
const std::string& name = info.name();
const std::string id = info.id();
const int moves = movement_type.movement_cost(*map,terrain);
const int views = movement_type.vision_cost(*map,terrain);
const int jamms = movement_type.jamming_cost(*map,terrain);
const int moves = movement_type.movement_cost(terrain);
const int views = movement_type.vision_cost(terrain);
const int jamms = movement_type.jamming_cost(terrain);
std::stringstream str;
str << "<ref>text='" << escape(name) << "' dst='"
<< escape(std::string("terrain_") + id) << "'</ref>";
@ -1642,7 +1642,7 @@ public:
//defense - range: +10 % .. +70 %
str.str(clear_stringstream);
const int defense =
100 - movement_type.defense_modifier(*map,terrain);
100 - movement_type.defense_modifier(terrain);
std::string color;
if (defense <= 10)
color = "red";

View File

@ -706,7 +706,7 @@ double pathfind::move_type_path_calculator::cost(const map_location& loc, const
return getNoPathValue();
const t_translation::t_terrain terrain = map_[loc];
int const terrain_cost = movement_type_.movement_cost(map_, terrain);
int const terrain_cost = movement_type_.movement_cost(terrain);
if (total_movement_ < terrain_cost)
return getNoPathValue();

View File

@ -2213,9 +2213,8 @@ bool unit::loyal() const
int unit::movement_cost(const t_translation::t_terrain & terrain) const
{
assert(resources::game_map != NULL);
const int res = movement_cost_internal(movement_costs_,
cfg_.child("movement_costs"), NULL, *resources::game_map, terrain);
cfg_.child("movement_costs"), NULL, terrain);
if (res == unit_movement_type::UNREACHABLE) {
return res;
@ -2229,9 +2228,8 @@ int unit::vision_cost(const t_translation::t_terrain & terrain) const
{
if (cfg_.child_count("vision_costs") == 0) return movement_cost(terrain);
assert(resources::game_map != NULL);
const int res = movement_cost_internal(vision_costs_,
cfg_.child("vision_costs"), NULL, *resources::game_map, terrain);
cfg_.child("vision_costs"), NULL, terrain);
if (res == unit_movement_type::UNREACHABLE) {
return res;
@ -2245,9 +2243,8 @@ int unit::jamming_cost(const t_translation::t_terrain & terrain) const
{
// if (cfg_.child_count("jamming_costs") == 0) return movement_cost(terrain);
assert(resources::game_map != NULL);
const int res = movement_cost_internal(jamming_costs_,
cfg_.child("jamming_costs"), NULL, *resources::game_map, terrain);
cfg_.child("jamming_costs"), NULL, terrain);
if (res == unit_movement_type::UNREACHABLE) {
return res;
@ -2259,8 +2256,7 @@ int unit::jamming_cost(const t_translation::t_terrain & terrain) const
int unit::defense_modifier(const t_translation::t_terrain & terrain) const
{
assert(resources::game_map != NULL);
int def = defense_modifier_internal(defense_mods_, cfg_, NULL, *resources::game_map, terrain);
int def = defense_modifier_internal(defense_mods_, cfg_, NULL, terrain);
#if 0
// A [defense] ability is too costly and doesn't take into account target locations.
// Left as a comment in case someone ever wonders why it isn't a good idea.

View File

@ -27,6 +27,7 @@
#include "loadscreen.hpp"
#include "log.hpp"
#include "map.hpp"
#include "resources.hpp"
#include <boost/foreach.hpp>
@ -432,8 +433,10 @@ bool unit_movement_type::is_flying() const
int movement_cost_internal(std::map<t_translation::t_terrain, int>& move_costs,
const config& cfg, const unit_movement_type* parent,
const gamemap& map, const t_translation::t_terrain & terrain, int recurse_count)
const t_translation::t_terrain & terrain, int recurse_count)
{
assert(resources::game_map != NULL);
const gamemap & map = *resources::game_map;
const int impassable = unit_movement_type::UNREACHABLE;
const std::map<t_translation::t_terrain, int>::const_iterator i = move_costs.find(terrain);
@ -466,7 +469,7 @@ int movement_cost_internal(std::map<t_translation::t_terrain, int>& move_costs,
continue;
}
const int value = movement_cost_internal(move_costs, cfg,
parent, map, *i, recurse_count + 1);
parent, *i, recurse_count + 1);
if (value < ret_value && !revert) {
ret_value = value;
@ -499,7 +502,7 @@ int movement_cost_internal(std::map<t_translation::t_terrain, int>& move_costs,
}
if (!result_found && parent != NULL) {
res = parent->movement_cost(map, terrain);
res = parent->movement_cost(terrain);
}
if (res <= 0) {
@ -514,8 +517,11 @@ int movement_cost_internal(std::map<t_translation::t_terrain, int>& move_costs,
const defense_range &defense_range_modifier_internal(defense_cache &defense_mods,
const config& cfg, const unit_movement_type* parent,
const gamemap& map, const t_translation::t_terrain & terrain, int recurse_count)
const t_translation::t_terrain & terrain, int recurse_count)
{
assert(resources::game_map != NULL);
const gamemap & map = *resources::game_map;
defense_range dummy = { 0, 100 };
std::pair<defense_cache::iterator, bool> ib =
defense_mods.insert(defense_cache::value_type(terrain, dummy));
@ -554,7 +560,7 @@ const defense_range &defense_range_modifier_internal(defense_cache &defense_mods
continue;
}
const defense_range &inh = defense_range_modifier_internal
(defense_mods, cfg, parent, map, *i, recurse_count + 1);
(defense_mods, cfg, parent, *i, recurse_count + 1);
if (!revert) {
if (inh.max_ < res.max_) res.max_ = inh.max_;
@ -581,7 +587,7 @@ const defense_range &defense_range_modifier_internal(defense_cache &defense_mods
if (parent) {
/* Assign to the reference res to put the value in the defense_cache. */
res = parent->defense_range_modifier(map, terrain);
res = parent->defense_range_modifier(terrain);
return res;
}
@ -601,10 +607,10 @@ const defense_range &defense_range_modifier_internal(defense_cache &defense_mods
int defense_modifier_internal(defense_cache &defense_mods,
const config &cfg, const unit_movement_type *parent,
const gamemap &map, const t_translation::t_terrain & terrain, int recurse_count)
const t_translation::t_terrain & terrain, int recurse_count)
{
const defense_range &def = defense_range_modifier_internal(defense_mods,
cfg, parent, map, terrain, recurse_count);
cfg, parent, terrain, recurse_count);
return (std::max)(def.max_, def.min_);
}

View File

@ -119,15 +119,15 @@ typedef std::map<t_translation::t_terrain, defense_range> defense_cache;
const defense_range &defense_range_modifier_internal(defense_cache &defense_mods,
const config &cfg, const unit_movement_type *parent,
const gamemap &map, const t_translation::t_terrain & terrain, int recurse_count = 0);
const t_translation::t_terrain & terrain, int recurse_count = 0);
int defense_modifier_internal(defense_cache &defense_mods,
const config &cfg, const unit_movement_type *parent,
const gamemap &map, const t_translation::t_terrain & terrain, int recurse_count = 0);
const t_translation::t_terrain & terrain, int recurse_count = 0);
int movement_cost_internal(std::map<t_translation::t_terrain, int> &move_costs,
const config &cfg, const unit_movement_type *parent,
const gamemap &map, const t_translation::t_terrain & terrain, int recurse_count = 0);
const t_translation::t_terrain & terrain, int recurse_count = 0);
//the 'unit movement type' is the basic size of the unit - flying, small land,
//large land, etc etc.
@ -145,16 +145,16 @@ public:
unit_movement_type();
std::string name() const;
int movement_cost(const gamemap &map, const t_translation::t_terrain & terrain) const
{ return movement_cost_internal(moveCosts_, cfg_.child("movement_costs"), parent_, map, terrain); }
int vision_cost(const gamemap &map, const t_translation::t_terrain & terrain) const
{ return movement_cost_internal(visionCosts_, cfg_.child("vision_costs"), parent_, map, terrain); }
int jamming_cost(const gamemap &map, const t_translation::t_terrain & terrain) const
{ return movement_cost_internal(jammingCosts_, cfg_.child("jamming_costs"), parent_, map, terrain); }
int defense_modifier(const gamemap &map, const t_translation::t_terrain & terrain) const
{ return defense_modifier_internal(defenseMods_, cfg_, parent_, map, terrain); }
const defense_range &defense_range_modifier(const gamemap &map, const t_translation::t_terrain & terrain) const
{ return defense_range_modifier_internal(defenseMods_, cfg_, parent_, map, terrain); }
int movement_cost(const t_translation::t_terrain & terrain) const
{ return movement_cost_internal(moveCosts_, cfg_.child("movement_costs"), parent_, terrain); }
int vision_cost(const t_translation::t_terrain & terrain) const
{ return movement_cost_internal(visionCosts_, cfg_.child("vision_costs"), parent_, terrain); }
int jamming_cost(const t_translation::t_terrain & terrain) const
{ return movement_cost_internal(jammingCosts_, cfg_.child("jamming_costs"), parent_, terrain); }
int defense_modifier(const t_translation::t_terrain & terrain) const
{ return defense_modifier_internal(defenseMods_, cfg_, parent_, terrain); }
const defense_range &defense_range_modifier(const t_translation::t_terrain & terrain) const
{ return defense_range_modifier_internal(defenseMods_, cfg_, parent_, terrain); }
int damage_against(const attack_type& attack) const { return resistance_against(attack); }
int resistance_against(const attack_type& attack) const;