The Battle for Wesnoth  1.17.0-dev
display_context.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  *
18  * This class is an abstract base class designed to simplify the use
19  * of the display object.
20  *
21  **/
22 
23 #pragma once
24 
25 #include "units/orb_status.hpp"
26 #include "units/ptr.hpp"
27 #include <string>
28 #include <vector>
29 
30 class team;
31 class gamemap;
32 class unit_map;
33 
34 class unit;
35 struct map_location;
36 
38 {
39 public:
40  virtual const std::vector<team> & teams() const = 0;
41  virtual const gamemap & map() const = 0;
42  virtual const unit_map & units() const = 0;
43  virtual const std::vector<std::string> & hidden_label_categories() const = 0;
44  virtual std::vector<std::string> & hidden_label_categories() = 0;
45  const team& get_team(int side) const;
46 
47  // this one is only a template function to prevent compilation erros when class team is an incomplete type.
48  template<typename T = void>
49  bool has_team(int side) const
50  {
51  return side > 0 && side <= static_cast<int>(teams().size());
52  }
53 
54  // Helper for is_visible_to_team
55 
56  /**
57  * Given a location and a side number, indicates whether an invisible unit of that side at that
58  * location would be revealed (perhaps ambushed), based on what team side_num can see.
59  * If see_all is true then the calculation ignores fog, and enemy ambushers.
60  */
61  bool would_be_discovered(const map_location & loc, int side_num, bool see_all = true);
62 
63  // Needed for reports
64 
65  const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;
66  unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all = false) const;
67 
69  {
70  /**
71  * The unit can move to another hex, taking account of enemies' locations, ZoC and
72  * terrain costs vs current movement points.
73  */
74  bool move = false;
75 
76  /**
77  * The unit can make an attack from the hex that it's currently on, this
78  * requires attack points and a non-petrified enemy in an adjacent hex.
79  */
80  bool attack_here = false;
81 
82  operator bool() const
83  {
84  return move || attack_here;
85  }
86  };
87 
88  /**
89  * Work out what @a u can do - this does not check which player's turn is currently active, the
90  * result is calculated assuming that the unit's owner is currently active.
91  */
92  can_move_result unit_can_move(const unit& u) const;
93 
94  /**
95  * Returns an enumurated summary of whether this unit can move and/or attack.
96  *
97  * This does not check which player's turn is currently active, the result is calculated
98  * assuming that the unit's owner is currently active. For this reason this never returns
99  * orb_status::enemy nor orb_status::allied.
100  */
101  orb_status unit_orb_status(const unit& u) const;
102 
103  /**
104  * Given the location of a village, will return the 1-based number
105  * of the team that currently owns it, and 0 if it is unowned.
106  */
107  int village_owner(const map_location & loc) const;
108 
109  // Accessors from unit.cpp
110 
111  /** Returns the number of units of the side @a side_num. */
112  int side_units(int side_num) const;
113 
114  /** Returns the total cost of units of side @a side_num. */
115  int side_units_cost(int side_num) const ;
116 
117  int side_upkeep(int side_num) const ;
118 
119  // Accessor from team.cpp
120 
121  /** Check if we are an observer in this game */
122  bool is_observer() const;
123 
124  // Dtor
125  virtual ~display_context() {}
126 };
127 
128 struct team_data
129 {
130  team_data(const display_context& dc, const team& tm);
131 
132  int side = 0, units = 0, upkeep = 0, expenses = 0, net_income = 0;
133 };
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:121
const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all=false) const
can_move_result unit_can_move(const unit &u) const
Work out what u can do - this does not check which player&#39;s turn is currently active, the result is calculated assuming that the unit&#39;s owner is currently active.
bool attack_here
The unit can make an attack from the hex that it&#39;s currently on, this requires attack points and a no...
orb_status
Corresponds to the colored orbs displayed above units&#39; hp-bar and xp-bar.
Definition: orb_status.hpp:24
virtual const gamemap & map() const =0
bool has_team(int side) const
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
virtual ~display_context()
int side_upkeep(int side_num) const
Encapsulates the map of the game.
Definition: map.hpp:171
virtual const unit_map & units() const =0
Encapsulates the map of the game.
Definition: location.hpp:38
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:98
bool move
The unit can move to another hex, taking account of enemies&#39; locations, ZoC and terrain costs vs curr...
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...