The Battle for Wesnoth  1.19.5+dev
display_context.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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 #pragma once
17 
18 #include "units/orb_status.hpp"
19 #include "units/ptr.hpp"
20 #include <string>
21 #include <vector>
22 
23 class team;
24 class gamemap;
25 class unit_map;
26 
27 class unit;
28 struct map_location;
29 
30 /**
31  * Abstract class for exposing game data that doesn't depend on the GUI, however which for historical
32  * reasons is generally accessed via the GUI method display::get_singleton().
33  */
35 {
36 public:
37  virtual const std::vector<team> & teams() const = 0;
38  virtual const gamemap & map() const = 0;
39  virtual const unit_map & units() const = 0;
40  virtual const std::vector<std::string> & hidden_label_categories() const = 0;
41  virtual std::vector<std::string> & hidden_label_categories() = 0;
42 
43  /** This getter takes a 1-based side number, not a 0-based team number. */
44  const team& get_team(int side) const;
45 
46  bool has_team(int side) const;
47 
48  // Helper for is_visible_to_team
49 
50  /**
51  * Given a location and a side number, indicates whether an invisible unit of that side at that
52  * location would be revealed (perhaps ambushed), based on what team side_num can see.
53  * If see_all is true then the calculation ignores fog, and enemy ambushers.
54  */
55  bool would_be_discovered(const map_location & loc, int side_num, bool see_all = true);
56 
57  // Needed for reports
58 
59  const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;
60  unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all = false) const;
61 
63  {
64  /**
65  * The unit can move to another hex, taking account of enemies' locations, ZoC and
66  * terrain costs vs current movement points.
67  */
68  bool move = false;
69 
70  /**
71  * The unit can make an attack from the hex that it's currently on, this
72  * requires attack points and a non-petrified enemy in an adjacent hex.
73  */
74  bool attack_here = false;
75 
76  operator bool() const
77  {
78  return move || attack_here;
79  }
80  };
81 
82  /**
83  * Work out what @a u can do - this does not check which player's turn is currently active, the
84  * result is calculated assuming that the unit's owner is currently active.
85  */
86  can_move_result unit_can_move(const unit& u) const;
87 
88  /**
89  * Returns an enumurated summary of whether this unit can move and/or attack.
90  *
91  * This does not check which player's turn is currently active, the result is calculated
92  * assuming that the unit's owner is currently active. For this reason this never returns
93  * orb_status::enemy nor orb_status::allied.
94  */
95  orb_status unit_orb_status(const unit& u) const;
96 
97  /**
98  * Given the location of a village, will return the 1-based number
99  * of the team that currently owns it, and 0 if it is unowned.
100  */
101  int village_owner(const map_location & loc) const;
102 
103  // Accessors from unit.cpp
104 
105  /** Returns the number of units of the side @a side_num. */
106  int side_units(int side_num) const;
107 
108  /** Returns the total cost of units of side @a side_num. */
109  int side_units_cost(int side_num) const ;
110 
111  int side_upkeep(int side_num) const ;
112 
113  // Accessor from team.cpp
114 
115  /** Check if we are an observer in this game */
116  bool is_observer() const;
117 
118  // Dtor
119  virtual ~display_context() {}
120 };
121 
122 struct team_data
123 {
124  team_data(const display_context& dc, const team& tm);
125 
126  int side = 0, units = 0, upkeep = 0, expenses = 0, net_income = 0;
127 };
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
const team & get_team(int side) const
This getter takes a 1-based side number, not a 0-based team number.
orb_status unit_orb_status(const unit &u) const
Returns an enumurated summary of whether this unit can move and/or attack.
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 unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all=false) const
bool is_observer() const
Check if we are an observer in this game.
can_move_result unit_can_move(const unit &u) const
Work out what u can do - this does not check which player's turn is currently active,...
virtual const gamemap & map() const =0
bool has_team(int side) const
virtual const std::vector< std::string > & hidden_label_categories() const =0
int side_units(int side_num) const
Returns the number of units of the side side_num.
virtual ~display_context()
virtual std::vector< std::string > & hidden_label_categories()=0
virtual const std::vector< team > & teams() const =0
unit_const_ptr get_visible_unit_shared_ptr(const map_location &loc, const team &current_team, bool see_all=false) const
int side_units_cost(int side_num) const
Returns the total cost of units of side side_num.
virtual const unit_map & units() 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...
int side_upkeep(int side_num) const
Encapsulates the map of the game.
Definition: map.hpp:172
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:75
Container associating units to locations.
Definition: map.hpp:98
This class represents a single unit of a specific type.
Definition: unit.hpp:133
orb_status
Corresponds to the colored orbs displayed above units' hp-bar and xp-bar.
Definition: orb_status.hpp:23
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27
bool attack_here
The unit can make an attack from the hex that it's currently on, this requires attack points and a no...
bool move
The unit can move to another hex, taking account of enemies' locations, ZoC and terrain costs vs curr...
Encapsulates the map of the game.
Definition: location.hpp:45
team_data(const display_context &dc, const team &tm)