Skip to content

Commit

Permalink
move some of the savegame code from play_controller to game_board
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 1, 2014
1 parent 0e7769a commit 6fff2e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
59 changes: 32 additions & 27 deletions src/play_controller.cpp
Expand Up @@ -738,32 +738,7 @@ config play_controller::to_config() const
cfg["init_side_done"] = init_side_done_;
cfg.merge_attributes(level_);

for(std::vector<team>::const_iterator t = gameboard_.teams_.begin(); t != gameboard_.teams_.end(); ++t) {
int side_num = t - gameboard_.teams_.begin() + 1;

config& side = cfg.add_child("side");
t->write(side);
side["no_leader"] = true;
side["side"] = str_cast(side_num);

{
//current visible units
BOOST_FOREACH(const unit & i, gameboard_.units_) {
if (i.side() == side_num) {
config& u = side.add_child("unit");
i.get_location().write(u);
i.write(u);
}
}
}
//recall list
{
BOOST_FOREACH(const unit & j, t->recall_list()) {
config& u = side.add_child("unit");
j.write(u);
}
}
}
gameboard_.write_config(cfg);

cfg.merge_with(tod_manager_.to_config());

Expand All @@ -779,7 +754,6 @@ config play_controller::to_config() const
}

//write out the current state of the map
cfg["map_data"] = gameboard_.map_.write();
cfg.merge_with(pathfind_manager_->to_config());

config display;
Expand Down Expand Up @@ -1544,3 +1518,34 @@ void game_board::set_all_units_user_end_turn() {
}
}

void game_board::write_config(config & cfg) const {
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
int side_num = t - teams_.begin() + 1;

config& side = cfg.add_child("side");
t->write(side);
side["no_leader"] = true;
side["side"] = str_cast(side_num);

//current units
{
BOOST_FOREACH(const unit & i, units_) {
if (i.side() == side_num) {
config& u = side.add_child("unit");
i.get_location().write(u);
i.write(u);
}
}
}
//recall list
{
BOOST_FOREACH(const unit & j, t->recall_list()) {
config& u = side.add_child("unit");
j.write(u);
}
}
}

//write the map
cfg["map_data"] = map_.write();
}
2 changes: 2 additions & 0 deletions src/play_controller.hpp
Expand Up @@ -80,6 +80,8 @@ struct game_board {
void new_turn(int pnum);
void end_turn(int pnum);
void set_all_units_user_end_turn();

void write_config(config & cfg) const;
};


Expand Down

0 comments on commit 6fff2e8

Please sign in to comment.