The Battle for Wesnoth  1.15.9+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 "units/orb_status.hpp"
25 #include "units/ptr.hpp"
26 #include <string>
27 #include <vector>
28 
29 class team;
30 class gamemap;
31 class unit_map;
32 
33 class unit;
34 struct map_location;
35 
37 {
38 public:
39  virtual const std::vector<team> & teams() const = 0;
40  virtual const gamemap & map() const = 0;
41  virtual const unit_map & units() const = 0;
42  virtual const std::vector<std::string> & hidden_label_categories() const = 0;
43  virtual std::vector<std::string> & hidden_label_categories() = 0;
44  const team& get_team(int side) const;
45 
46  // this one is only a template function to prevent compilation erros when class team is an incomplete type.
47  template<typename T = void>
48  bool has_team(int side) const
49  {
50  return side > 0 && side <= static_cast<int>(teams().size());
51  }
52 
53  // Helper for is_visible_to_team
54 
55  /**
56  * Given a location and a side number, indicates whether an invisible unit of that side at that
57  * location would be revealed (perhaps ambushed), based on what team side_num can see.
58  * If see_all is true then the calculation ignores fog, and enemy ambushers.
59  */
60  bool would_be_discovered(const map_location & loc, int side_num, bool see_all = true);
61 
62  // Needed for reports
63 
64  const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;
65  unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all = false) const;
66 
67  /**
68  * True if, and only if, at least one of the following is true:
69  *
70  * (a) the unit can move to another hex, taking account of ZoC and
71  * terrain costs vs current movement points.
72  *
73  * (b) the unit can make an attack from the hex that it's currently on,
74  * requires attack points and a non-petrified enemy in an adjacent hex.
75  *
76  * This does not check which player's turn is currently active, the result is calculated
77  * assuming that the unit's owner is currently active.
78  */
79  bool unit_can_move(const unit& u) const;
80 
81  /**
82  * Returns an enumurated summary of whether this unit can move and/or attack.
83  *
84  * This does not check which player's turn is currently active, the result is calculated
85  * assuming that the unit's owner is currently active. For this reason this never returns
86  * orb_status::enemy nor orb_status::allied.
87  */
88  orb_status unit_orb_status(const unit& u) const;
89 
90  /**
91  * Given the location of a village, will return the 1-based number
92  * of the team that currently owns it, and 0 if it is unowned.
93  */
94  int village_owner(const map_location & loc) const;
95 
96  // Accessors from unit.cpp
97 
98  /** Returns the number of units of the side @a side_num. */
99  int side_units(int side_num) const;
100 
101  /** Returns the total cost of units of side @a side_num. */
102  int side_units_cost(int side_num) const ;
103 
104  int side_upkeep(int side_num) const ;
105 
106  // Accessor from team.cpp
107 
108  /** Check if we are an observer in this game */
109  bool is_observer() const;
110 
111  // Dtor
112  virtual ~display_context() {}
113 };
114 
115 struct team_data
116 {
117  team_data(const display_context& dc, const team& tm);
118 
119  int side = 0, units = 0, upkeep = 0, expenses = 0, net_income = 0;
120 };
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:119
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
True if, and only if, at least one of the following is true:
orb_status
Corresponds to the colored orbs displayed above units&#39; hp-bar and xp-bar.
Definition: orb_status.hpp:23
virtual const gamemap & map() const =0
bool has_team(int side) const
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:26
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:33
virtual const unit_map & units() const =0
Encapsulates the map of the game.
Definition: location.hpp:37
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
orb_status unit_orb_status(const unit &u) const
Returns an enumurated summary of whether this unit can move and/or attack.
Container associating units to locations.
Definition: map.hpp:97
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...