Skip to content

Commit

Permalink
move some functionality out of play controller to game_board
Browse files Browse the repository at this point in the history
This moves some simple code which manipulates the end turn status
of the units on the map.
  • Loading branch information
cbeck88 committed Jun 1, 2014
1 parent 5fa0836 commit 0e7769a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
30 changes: 24 additions & 6 deletions src/play_controller.cpp
Expand Up @@ -684,12 +684,7 @@ void play_controller::do_init_side(bool is_replay, bool only_visual) {
// Healing/income happen if it's not the first turn of processing,
// or if we are loading a game.
if (!only_visual && turn() > 1) {
BOOST_FOREACH(unit & i, gameboard_.units_) {
if (i.side() == player_number_) {
i.new_turn();
}
}

gameboard_.new_turn(player_number_);
current_team().new_turn();

// If the expense is less than the number of villages owned
Expand Down Expand Up @@ -1526,3 +1521,26 @@ void play_controller::toggle_accelerated_speed()
gui_->announce(_("Accelerated speed disabled!"), font::NORMAL_COLOR);
}
}

void game_board::new_turn(int player_num) {
BOOST_FOREACH (unit & i, units_) {
if (i.side() == player_num) {
i.new_turn();
}
}
}

void game_board::end_turn(int player_num) {
BOOST_FOREACH (unit & i, units_) {
if (i.side() == player_num) {
i.end_turn();
}
}
}

void game_board::set_all_units_user_end_turn() {
BOOST_FOREACH (unit & i, units_) {
i.set_user_end_turn(true);
}
}

4 changes: 4 additions & 0 deletions src/play_controller.hpp
Expand Up @@ -76,6 +76,10 @@ struct game_board {

gamemap map_;
unit_map units_;

void new_turn(int pnum);
void end_turn(int pnum);
void set_all_units_user_end_turn();
};


Expand Down
4 changes: 1 addition & 3 deletions src/playmp_controller.cpp
Expand Up @@ -313,9 +313,7 @@ void playmp_controller::linger()
// stay stuck in linger state when the *next* scenario is over.
gamestate_.classification().completion = "running";
// End all unit moves
BOOST_FOREACH(unit &u, gameboard_.units_) {
u.set_user_end_turn(true);
}
gameboard_.set_all_units_user_end_turn();
//current_team().set_countdown_time(0);
//halt and cancel the countdown timer
reset_countdown();
Expand Down
4 changes: 1 addition & 3 deletions src/playsingle_controller.cpp
Expand Up @@ -844,9 +844,7 @@ void playsingle_controller::linger()
gui_->redraw_everything();

// End all unit moves
BOOST_FOREACH (unit & u, gameboard_.units_) {
u.set_user_end_turn(true);
}
gameboard_.set_all_units_user_end_turn();
try {
// Same logic as single-player human turn, but
// *not* the same as multiplayer human turn.
Expand Down
6 changes: 1 addition & 5 deletions src/replay_controller.cpp
Expand Up @@ -482,11 +482,7 @@ void replay_controller::play_side(){
}

// This is necessary for replays in order to show possible movements.
BOOST_FOREACH(unit &u, gameboard_.units_) {
if (u.side() == player_number_) {
u.new_turn();
}
}
gameboard_.new_turn(player_number_);

update_teams();
update_gui();
Expand Down

0 comments on commit 0e7769a

Please sign in to comment.