The Battle for Wesnoth  1.17.0-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 
68  {
69  /**
70  * The unit can move to another hex, taking account of enemies' locations, ZoC and
71  * terrain costs vs current movement points.
72  */
73  bool move = false;
74 
75  /**
76  * The unit can make an attack from the hex that it's currently on, this
77  * requires attack points and a non-petrified enemy in an adjacent hex.
78  */
79  bool attack_here = false;
80 
81  operator bool() const
82  {
83  return move || attack_here;
84  }
85  };
86 
87  /**
88  * Work out what @a u can do - this does not check which player's turn is currently active, the
89  * result is calculated assuming that the unit's owner is currently active.
90  */
91  can_move_result unit_can_move(const unit& u) const;
92 
93  /**
94  * Returns an enumurated summary of whether this unit can move and/or attack.
95  *
96  * This does not check which player's turn is currently active, the result is calculated
97  * assuming that the unit's owner is currently active. For this reason this never returns
98  * orb_status::enemy nor orb_status::allied.
99  */
100  orb_status unit_orb_status(const unit& u) const;
101 
102  /**
103  * Given the location of a village, will return the 1-based number
104  * of the team that currently owns it, and 0 if it is unowned.
105  */
106  int village_owner(const map_location & loc) const;
107 
108  // Accessors from unit.cpp
109 
110  /** Returns the number of units of the side @a side_num. */
111  int side_units(int side_num) const;
112 
113  /** Returns the total cost of units of side @a side_num. */
114  int side_units_cost(int side_num) const ;
115 
116  int side_upkeep(int side_num) const ;
117 
118  // Accessor from team.cpp
119 
120  /** Check if we are an observer in this game */
121  bool is_observer() const;
122 
123  // Dtor
124  virtual ~display_context() {}
125 };
126 
127 struct team_data
128 {
129  team_data(const display_context& dc, const team& tm);
130 
131  int side = 0, units = 0, upkeep = 0, expenses = 0, net_income = 0;
132 };
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:120
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: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:71
virtual ~display_context()
int side_upkeep(int side_num) const
Encapsulates the map of the game.
Definition: map.hpp:170
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
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...