Move some functions
Now its a bit easier to understand which functions are in play_controller adn which in playsingle_controller as all turn related functiosn are now in playsingle_controller
This commit is contained in:
parent
c9fcce6be0
commit
2638ce8afc
4 changed files with 59 additions and 61 deletions
|
@ -767,30 +767,6 @@ const team& play_controller::current_team() const
|
|||
return gamestate().board_.get_team(current_side());
|
||||
}
|
||||
|
||||
bool play_controller::is_team_visible(int team_num, bool observer) const
|
||||
{
|
||||
const team& t = gamestate().board_.get_team(team_num);
|
||||
if(observer) {
|
||||
return !t.get_disallow_observers() && !t.is_empty();
|
||||
} else {
|
||||
return t.is_local_human() && !t.is_idle();
|
||||
}
|
||||
}
|
||||
|
||||
int play_controller::find_viewing_side() const
|
||||
{
|
||||
const int num_teams = get_teams().size();
|
||||
const bool observer = is_observer();
|
||||
|
||||
for(int i = 0; i < num_teams; i++) {
|
||||
const int team_num = modulo(current_side() + i, num_teams, 1);
|
||||
if(is_team_visible(team_num, observer)) {
|
||||
return team_num;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
events::mouse_handler& play_controller::get_mouse_handler_base()
|
||||
{
|
||||
|
@ -1279,33 +1255,6 @@ std::set<std::string> play_controller::all_players() const
|
|||
return res;
|
||||
}
|
||||
|
||||
void play_controller::play_side()
|
||||
{
|
||||
do {
|
||||
if(std::find_if(get_teams().begin(), get_teams().end(), [](const team& t) { return !t.is_empty(); }) == get_teams().end()){
|
||||
throw game::game_error("The scenario has no (non-empty) sides defined");
|
||||
}
|
||||
update_viewing_player();
|
||||
|
||||
maybe_do_init_side();
|
||||
if(is_regular_game_end()) {
|
||||
return;
|
||||
}
|
||||
// This flag can be set by derived classes (in overridden functions).
|
||||
player_type_changed_ = false;
|
||||
|
||||
|
||||
play_side_impl();
|
||||
|
||||
if(is_regular_game_end()) {
|
||||
return;
|
||||
}
|
||||
} while(player_type_changed_);
|
||||
|
||||
// Keep looping if the type of a team (human/ai/networked) has changed mid-turn
|
||||
sync_end_turn();
|
||||
}
|
||||
|
||||
void play_controller::check_time_over()
|
||||
{
|
||||
const bool time_left = gamestate().tod_manager_.next_turn(&gamestate().gamedata_);
|
||||
|
|
|
@ -272,10 +272,6 @@ public:
|
|||
|
||||
void maybe_throw_return_to_play_side() const;
|
||||
|
||||
virtual void play_side_impl() {}
|
||||
|
||||
void play_side();
|
||||
|
||||
team& current_team();
|
||||
const team& current_team() const;
|
||||
|
||||
|
@ -338,12 +334,9 @@ protected:
|
|||
void textbox_move_vertically(bool up);
|
||||
void tab();
|
||||
|
||||
|
||||
bool is_team_visible(int team_num, bool observer) const;
|
||||
public:
|
||||
/** returns 0 if no such team was found. */
|
||||
int find_viewing_side() const;
|
||||
|
||||
virtual int find_viewing_side() const = 0;
|
||||
private:
|
||||
const int ticks_;
|
||||
|
||||
|
|
|
@ -230,6 +230,33 @@ void playsingle_controller::play_some()
|
|||
}
|
||||
}
|
||||
|
||||
void playsingle_controller::play_side()
|
||||
{
|
||||
do {
|
||||
if(std::find_if(get_teams().begin(), get_teams().end(), [](const team& t) { return !t.is_empty(); }) == get_teams().end()){
|
||||
throw game::game_error("The scenario has no (non-empty) sides defined");
|
||||
}
|
||||
update_viewing_player();
|
||||
|
||||
maybe_do_init_side();
|
||||
if(is_regular_game_end()) {
|
||||
return;
|
||||
}
|
||||
// This flag can be set by derived classes (in overridden functions).
|
||||
player_type_changed_ = false;
|
||||
|
||||
|
||||
play_side_impl();
|
||||
|
||||
if(is_regular_game_end()) {
|
||||
return;
|
||||
}
|
||||
} while(player_type_changed_);
|
||||
|
||||
// Keep looping if the type of a team (human/ai/networked) has changed mid-turn
|
||||
sync_end_turn();
|
||||
}
|
||||
|
||||
void playsingle_controller::finish_side_turn()
|
||||
{
|
||||
if(is_regular_game_end()) {
|
||||
|
@ -766,11 +793,36 @@ void playsingle_controller::sync_end_turn()
|
|||
}
|
||||
}
|
||||
|
||||
bool playsingle_controller::is_team_visible(int team_num, bool observer) const
|
||||
{
|
||||
const team& t = gamestate().board_.get_team(team_num);
|
||||
if(observer) {
|
||||
return !t.get_disallow_observers() && !t.is_empty();
|
||||
} else {
|
||||
return t.is_local_human() && !t.is_idle();
|
||||
}
|
||||
}
|
||||
|
||||
int playsingle_controller::find_viewing_side() const
|
||||
{
|
||||
const int num_teams = get_teams().size();
|
||||
const bool observer = is_observer();
|
||||
|
||||
for(int i = 0; i < num_teams; i++) {
|
||||
const int team_num = modulo(current_side() + i, num_teams, 1);
|
||||
if(is_team_visible(team_num, observer)) {
|
||||
return team_num;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void playsingle_controller::update_viewing_player()
|
||||
{
|
||||
if(replay_controller_ && replay_controller_->is_controlling_view()) {
|
||||
replay_controller_->update_viewing_player();
|
||||
} else if(int side_num = play_controller::find_viewing_side()) {
|
||||
} else if(int side_num = find_viewing_side()) {
|
||||
if(side_num != gui_->viewing_side() || gui_->show_everything()) {
|
||||
update_gui_to_player(side_num - 1);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
/// also true if no non-empty side was found.
|
||||
ses_result skip_empty_sides(int side_num);
|
||||
void play_some();
|
||||
void play_side();
|
||||
void finish_side_turn();
|
||||
void do_end_level();
|
||||
void play_scenario_main_loop();
|
||||
|
@ -85,7 +86,7 @@ public:
|
|||
void enable_replay(bool is_unit_test = false);
|
||||
void on_replay_end(bool is_unit_test);
|
||||
protected:
|
||||
virtual void play_side_impl() override;
|
||||
void play_side_impl();
|
||||
void before_human_turn();
|
||||
void show_turn_dialog();
|
||||
void execute_gotos();
|
||||
|
@ -111,6 +112,9 @@ protected:
|
|||
void linger();
|
||||
void update_gui_linger();
|
||||
void sync_end_turn() override;
|
||||
bool is_team_visible(int team_num, bool observer) const;
|
||||
/** returns 0 if no such team was found. */
|
||||
int find_viewing_side() const override;
|
||||
void update_viewing_player() override;
|
||||
void reset_replay();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue