Skip to content

Commit

Permalink
move is_observer to gameboard, with accessor in playcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 26, 2014
1 parent f5a9de4 commit e625531
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 29 deletions.
11 changes: 11 additions & 0 deletions src/game_board.cpp
Expand Up @@ -237,6 +237,17 @@ bool game_board::change_terrain(const map_location &loc, const std::string &t_st
return true;
}

bool game_board::is_observer() const
{
BOOST_FOREACH(const team &t, teams_) {
if (t.is_local())
return false;
}

return true;
}


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;
Expand Down
4 changes: 4 additions & 0 deletions src/game_board.hpp
Expand Up @@ -136,6 +136,10 @@ class game_board : public display_context {
// Wrapped functions from unit_map. These should ultimately provide notification to observers, pathfinding.

unit_map::iterator find_unit(const map_location & loc) { return units_.find(loc); }

// Accessor from team.cpp

bool is_observer() const;
};

void swap(game_board & one, game_board & other);
Expand Down
2 changes: 1 addition & 1 deletion src/game_display.cpp
Expand Up @@ -930,7 +930,7 @@ void game_display::add_chat_message(const time_t& time, const std::string& speak
preferences::parse_admin_authentication(sender, message);

if (bell) {
if ((type == events::chat_handler::MESSAGE_PRIVATE && (!is_observer() || whisper))
if ((type == events::chat_handler::MESSAGE_PRIVATE && (!resources::gameboard->is_observer() || whisper))
|| utils::word_match(message, preferences::login())) {
sound::play_UI_sound(game_config::sounds::receive_message_highlight);
} else if (preferences::is_friend(sender)) {
Expand Down
3 changes: 2 additions & 1 deletion src/map_label.cpp
Expand Up @@ -15,6 +15,7 @@
#include "global.hpp"

#include "display.hpp"
#include "game_board.hpp"
#include "game_data.hpp"
#include "map_label.hpp"
#include "resources.hpp"
Expand Down Expand Up @@ -523,7 +524,7 @@ bool terrain_label::viewable() const
return true;

// Observers are not privvy to team labels.
const bool can_see_team_labels = !is_observer();
const bool can_see_team_labels = !resources::gameboard->is_observer();

// Global labels are shown unless covered by a team label.
if ( team_name_.empty() )
Expand Down
12 changes: 6 additions & 6 deletions src/menu_events.cpp
Expand Up @@ -517,7 +517,7 @@ void menu_handler::show_help()
void menu_handler::speak()
{
textbox_info_.show(gui::TEXTBOX_MESSAGE,_("Message:"),
has_friends() ? is_observer() ? _("Send to observers only") : _("Send to allies only")
has_friends() ? resources::gameboard->is_observer() ? _("Send to observers only") : _("Send to allies only")
: "", preferences::message_private(), *gui_);
}

Expand All @@ -535,7 +535,7 @@ void menu_handler::shout()

bool menu_handler::has_friends() const
{
if(is_observer()) {
if(resources::gameboard->is_observer()) {
return !gui_->observers().empty();
}

Expand Down Expand Up @@ -1199,7 +1199,7 @@ void menu_handler::label_terrain(mouse_handler& mousehandler, bool team_only)
void menu_handler::clear_labels()
{
if (gui_->team_valid()
&& !is_observer())
&& !resources::gameboard->is_observer())
{
gui_->labels().clear(gui_->current_team_name(), false);
recorder.clear_labels(gui_->current_team_name(), false);
Expand Down Expand Up @@ -2549,15 +2549,15 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
ss << time;
cfg["time"] = ss.str();

const int side = is_observer() ? 0 : gui_->viewing_side();
if(!is_observer()) {
const int side = resources::gameboard->is_observer() ? 0 : gui_->viewing_side();
if(!resources::gameboard->is_observer()) {
cfg["side"] = side;
}

bool private_message = has_friends() && allies_only;

if(private_message) {
if (is_observer()) {
if (resources::gameboard->is_observer()) {
cfg["team_name"] = game_config::observer_team_name;
} else {
cfg["team_name"] = teams_[gui_->viewing_team()].team_name();
Expand Down
4 changes: 4 additions & 0 deletions src/play_controller.hpp
Expand Up @@ -149,6 +149,10 @@ class play_controller : public controller_base, public events::observer, public
return gamestate_.tod_manager_;
}

bool is_observer() const {
return gamestate_.board_.is_observer();
}

/**
* Checks to see if a side has won, and throws an end_level_exception.
* Will also remove control of villages from sides with dead leaders.
Expand Down
2 changes: 1 addition & 1 deletion src/playcampaign.cpp
Expand Up @@ -68,7 +68,7 @@ static void show_carryover_message(saved_game& gamestate, playsingle_controller&
std::ostringstream report;
std::string title;

bool obs = is_observer();
bool obs = playcontroller.is_observer();

if (obs) {
title = _("Scenario Report");
Expand Down
2 changes: 1 addition & 1 deletion src/playturn.cpp
Expand Up @@ -207,7 +207,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
resources::controller->on_not_observer();
}

if (is_observer() || (resources::gameboard->teams())[resources::screen->playing_team()].is_human()) {
if (resources::gameboard->is_observer() || (resources::gameboard->teams())[resources::screen->playing_team()].is_human()) {
resources::screen->set_team(resources::screen->playing_team());
resources::screen->redraw_everything();
resources::screen->recalculate_minimap();
Expand Down
14 changes: 0 additions & 14 deletions src/team.cpp
Expand Up @@ -607,20 +607,6 @@ int team::nteams()
}
}

bool is_observer()
{
if(teams == NULL) {
return true;
}

BOOST_FOREACH(const team &t, *teams) {
if (t.is_local())
return false;
}

return true;
}

void validate_side(int side)
{
if(teams == NULL) {
Expand Down
4 changes: 0 additions & 4 deletions src/team.hpp
Expand Up @@ -381,10 +381,6 @@ namespace teams_manager {
const std::vector<team> &get_teams();
}

//FIXME: this global method really needs to be moved into play_controller,
//or somewhere else that makes sense.
bool is_observer();

//function which will validate a side. Throws game::game_error
//if the side is invalid
void validate_side(int side); //throw game::game_error
Expand Down
2 changes: 1 addition & 1 deletion src/whiteboard/manager.cpp
Expand Up @@ -146,7 +146,7 @@ bool manager::can_modify_game_state() const
if(wait_for_side_init_
|| resources::teams == NULL
|| executing_actions_
|| is_observer()
|| resources::gameboard->is_observer()
|| resources::controller->is_linger_mode())
{
return false;
Expand Down

0 comments on commit e625531

Please sign in to comment.