Skip to content

Commit

Permalink
Merge branch 'fixup_editor'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jul 6, 2014
2 parents e3d34a3 + f63f133 commit da1aa63
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
15 changes: 15 additions & 0 deletions src/display_context.cpp
Expand Up @@ -20,6 +20,8 @@
#include "unit.hpp"
#include "unit_map.hpp"

#include <boost/foreach.hpp>

const unit * display_context::get_visible_unit(const map_location & loc, const team &current_team, bool see_all) const
{
if (!map().on_board(loc)) return NULL;
Expand Down Expand Up @@ -82,3 +84,16 @@ int display_context::village_owner(const map_location& loc) const
return -1;
}

/**
* Determine if we are an observer, by checking if every team is not locally controlled
*/
bool display_context::is_observer() const
{
BOOST_FOREACH(const team &t, teams()) {
if (t.is_local())
return false;
}

return true;
}

5 changes: 5 additions & 0 deletions src/display_context.hpp
Expand Up @@ -53,6 +53,11 @@ class display_context {
*/
int village_owner(const map_location & loc) const;

// Accessor from team.cpp

/// Check if we are an observer in this game
bool is_observer() const;

// Dtor

virtual ~display_context() {}
Expand Down
11 changes: 0 additions & 11 deletions src/game_board.cpp
Expand Up @@ -237,17 +237,6 @@ 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: 0 additions & 4 deletions src/game_board.hpp
Expand Up @@ -136,10 +136,6 @@ 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
8 changes: 4 additions & 4 deletions src/map_label.cpp
Expand Up @@ -461,7 +461,7 @@ void terrain_label::draw()
return;
clear();

if ( !viewable() )
if ( !viewable(parent_->disp().get_disp_context()) )
return;

const map_location loc_nextx(loc_.x+1,loc_.y);
Expand Down Expand Up @@ -514,17 +514,17 @@ bool terrain_label::hidden() const
* creating a label. Conditions that can change during unit movement (disregarding
* potential WML events) should not be listed here; they belong in hidden().
*/
bool terrain_label::viewable() const
bool terrain_label::viewable(const display_context & dc) const
{
if ( !parent_->enabled() )
return false;

// In the editor, all labels are viewable.
if ( team::nteams() == 0 )
if ( dc.teams().empty() )
return true;

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

// Global labels are shown unless covered by a team label.
if ( team_name_.empty() )
Expand Down
3 changes: 2 additions & 1 deletion src/map_label.hpp
Expand Up @@ -22,6 +22,7 @@

class config;
class display;
class display_context;
//class team;
class terrain_label;

Expand Down Expand Up @@ -139,7 +140,7 @@ class terrain_label
void clear();
void draw();
bool hidden() const;
bool viewable() const;
bool viewable(const display_context & dc) const;
std::string cfg_color() const;

int handle_;
Expand Down

0 comments on commit da1aa63

Please sign in to comment.