The Battle for Wesnoth  1.15.3+dev
display_context.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  *
17  * This class is an abstract base class designed to simplify the use
18  * of the display object.
19  *
20  **/
21 
22 #pragma once
23 
24 #include <string>
25 #include <vector>
26 #include "units/ptr.hpp"
27 
28 class team;
29 class gamemap;
30 class unit_map;
31 
32 class unit;
33 struct map_location;
34 
36 {
37 public:
38  virtual const std::vector<team> & teams() const = 0;
39  virtual const gamemap & map() const = 0;
40  virtual const unit_map & units() const = 0;
41  virtual const std::vector<std::string> & hidden_label_categories() const = 0;
42  virtual std::vector<std::string> & hidden_label_categories() = 0;
43  const team& get_team(int side) const;
44 
45  // this one is only a template function to prevent compilation erros when class team is an incomplete type.
46  template<typename T = void>
47  bool has_team(int side) const
48  {
49  return side > 0 && side <= static_cast<int>(teams().size());
50  }
51 
52  // Helper for is_visible_to_team
53 
54  /**
55  * Given a location and a side number, indicates whether an invisible unit of that side at that
56  * location would be revealed (perhaps ambushed), based on what team side_num can see.
57  * If see_all is true then the calculation ignores fog, and enemy ambushers.
58  */
59  bool would_be_discovered(const map_location & loc, int side_num, bool see_all = true);
60 
61  // Needed for reports
62 
63  const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;
64  unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all = false) const;
65 
66  // From actions:: namespace
67 
68  bool unit_can_move(const unit & u) const;
69 
70  // From class team
71 
72  /**
73  * Given the location of a village, will return the 1-based number
74  * of the team that currently owns it, and 0 if it is unowned.
75  */
76  int village_owner(const map_location & loc) const;
77 
78  // Accessors from unit.cpp
79 
80  /** Returns the number of units of the side @a side_num. */
81  int side_units(int side_num) const;
82 
83  /** Returns the total cost of units of side @a side_num. */
84  int side_units_cost(int side_num) const ;
85 
86  int side_upkeep(int side_num) const ;
87 
88  // Accessor from team.cpp
89 
90  /// Check if we are an observer in this game
91  bool is_observer() const;
92 
93  // Dtor
94 
95  virtual ~display_context() {}
96 };
97 
98 struct team_data
99 {
100  team_data(const display_context& dc, const team& tm);
101 
102  int side = 0, units = 0, upkeep = 0, expenses = 0, net_income = 0;
103 };
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it...
const team & get_team(int side) const
This class represents a single unit of a specific type.
Definition: unit.hpp:129
const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all=false) const
bool unit_can_move(const unit &u) const
Will return true iff the unit u has any possible moves it can do (including attacking etc)...
virtual const gamemap & map() const =0
bool has_team(int side) const
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:29
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
virtual ~display_context()
int side_upkeep(int side_num) const
Encapsulates the map of the game.
Definition: map.hpp:36
virtual const unit_map & units() const =0
Encapsulates the map of the game.
Definition: location.hpp:42
int side_units_cost(int side_num) const
Returns the total cost of units of side side_num.
virtual const std::vector< team > & teams() const =0
bool is_observer() const
Check if we are an observer in this game.
unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all=false) const
Container associating units to locations.
Definition: map.hpp:99
int side_units(int side_num) const
Returns the number of units of the side side_num.
virtual const std::vector< std::string > & hidden_label_categories() const =0
bool would_be_discovered(const map_location &loc, int side_num, bool see_all=true)
Given a location and a side number, indicates whether an invisible unit of that side at that location...