Skip to content

Commit

Permalink
team::build takes a pointer to the game_data obj we want to use
Browse files Browse the repository at this point in the history
This eliminates another use of resources:: in class team
  • Loading branch information
cbeck88 committed Jul 6, 2014
1 parent 6f4763c commit 4286b13
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/editor/map/map_context.cpp
Expand Up @@ -303,7 +303,7 @@ void map_context::load_scenario(const config& game_config)
{
team t;
side["side"] = i;
t.build(side, map_);
t.build(side, map_, NULL); //It's okay to pass a NULL gamedata ptr here, it is only used ultimately in map_location ctor and checked for null.
teams_.push_back(t);

BOOST_FOREACH(config &a_unit, side.child_range("unit")) {
Expand Down
4 changes: 2 additions & 2 deletions src/game_data.cpp
Expand Up @@ -205,7 +205,7 @@ team_builder_ptr game_data::create_team_builder(const config& side_cfg,
const config& level, gamemap& map, unit_map& units,
const config& starting_pos)
{
return team_builder_ptr(new team_builder(side_cfg, save_id, teams, level, map, units, starting_pos));
return team_builder_ptr(new team_builder(side_cfg, save_id, teams, level, map, units, *this, starting_pos));
}

void game_data::build_team_stage_one(team_builder_ptr tb_ptr)
Expand Down Expand Up @@ -266,4 +266,4 @@ void game_data::activate_scope_variable(std::string var_name) const
break;
}
}
}
}
4 changes: 2 additions & 2 deletions src/team.cpp
Expand Up @@ -280,7 +280,7 @@ team::~team()
{
}

void team::build(const config &cfg, const gamemap& map, int gold)
void team::build(const config &cfg, const gamemap& map, const game_data * gamedata, int gold)
{
gold_ = gold;
info_.read(cfg);
Expand Down Expand Up @@ -314,7 +314,7 @@ void team::build(const config &cfg, const gamemap& map, int gold)
// Load in the villages the side controls at the start
BOOST_FOREACH(const config &v, cfg.child_range("village"))
{
map_location loc(v, resources::gamedata);
map_location loc(v, gamedata);
if (map.is_village(loc)) {
villages_.insert(loc);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/team.hpp
Expand Up @@ -157,7 +157,7 @@ class team : public savegame::savegame_config
/// from a side's config before using it to create the side's leader.
static const std::set<std::string> attributes;

void build(const config &cfg, const gamemap &map, int gold = default_team_gold_);
void build(const config &cfg, const gamemap &map, const game_data * gamedata, int gold = default_team_gold_);

void write(config& cfg) const;

Expand Down
5 changes: 4 additions & 1 deletion src/teambuilder.hpp
Expand Up @@ -40,6 +40,7 @@ class team_builder {
team_builder(const config& side_cfg,
const std::string &save_id, std::vector<team>& teams,
const config& level, gamemap& map, unit_map& units,
game_data & gamedata,
const config &starting_pos)
: gold_info_ngold_(0)
, leader_configs_()
Expand All @@ -55,6 +56,7 @@ class team_builder {
, teams_(teams)
, unit_configs_()
, units_(units)
, gamedata_(gamedata)
{
}

Expand Down Expand Up @@ -110,6 +112,7 @@ class team_builder {
std::vector<team> &teams_;
std::vector<const config*> unit_configs_;
unit_map &units_;
game_data & gamedata_;


void log_step(const char *s) const
Expand Down Expand Up @@ -167,7 +170,7 @@ class team_builder {
void new_team()
{
log_step("new team");
t_->build(side_cfg_, map_, gold_info_ngold_);
t_->build(side_cfg_, map_, &gamedata_, gold_info_ngold_);
//t_->set_gold_add(gold_info_add_);
}

Expand Down

0 comments on commit 4286b13

Please sign in to comment.