Pyrogenesis  trunk
ICmpTerritoryManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2020 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_ICMPTERRITORYMANAGER
19 #define INCLUDED_ICMPTERRITORYMANAGER
20 
22 
25 
26 #include <vector>
27 
28 template<typename T>
29 class Grid;
30 
32 {
33 public:
34  /**
35  * Returns whether the territory texture needs to be updated.
36  */
37  virtual bool NeedUpdateTexture(size_t* dirtyID) = 0;
38 
39  /**
40  * Returns whether the AI territory map needs to be updated.
41  */
42  virtual bool NeedUpdateAI(size_t* dirtyID, size_t* dirtyBlinkingID) const = 0;
43 
44  /**
45  * Number of pathfinder navcells per territory tile.
46  * Passability data is stored per navcell, but we probably don't need that much
47  * resolution, and a lower resolution can make the boundary lines look prettier
48  * and will take less memory, so we downsample the passability data.
49  */
50  static const int NAVCELLS_PER_TERRITORY_TILE = 8;
51 
52  static const int TERRITORY_PLAYER_MASK = 0x1F;
53  static const int TERRITORY_CONNECTED_MASK = 0x20;
54  static const int TERRITORY_BLINKING_MASK = 0x40;
55  static const int TERRITORY_PROCESSED_MASK = 0x80; //< For internal use; marks a tile as processed.
56 
57  /**
58  * For each tile, the TERRITORY_PLAYER_MASK bits are player ID;
59  * TERRITORY_CONNECTED_MASK is set if the tile is connected to a root object
60  * (civ center etc).
61  */
62  virtual const Grid<u8>& GetTerritoryGrid() = 0;
63 
64  /**
65  * Get owner of territory at given position.
66  * @return player ID of owner; 0 if neutral territory
67  */
69 
70  /**
71  * get the number of neighbour tiles for per player for the selected position
72  * @return A list with the number of neighbour tiles per player
73  */
74  virtual std::vector<u32> GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) = 0;
75 
76  /**
77  * Get whether territory at given position is connected to a root object
78  * (civ center etc) owned by that territory's player.
79  */
80  virtual bool IsConnected(entity_pos_t x, entity_pos_t z) = 0;
81 
82  /**
83  * Set a piece of territory to blinking. Must be updated on every territory calculation
84  */
85  virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable) = 0;
86 
87  /**
88  * Check if a piece of territory is blinking.
89  */
90  virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0;
91 
92  /**
93  * Returns the percentage of the world controlled by a given player as defined by
94  * the number of territory cells the given player owns
95  */
96  virtual u8 GetTerritoryPercentage(player_id_t player) = 0;
97 
98  /**
99  * Enables or disables rendering of an territory borders.
100  */
101  virtual void SetVisibility(bool visible) = 0;
102 
103  /**
104  * Updates the boundary and territory colors.
105  */
106  virtual void UpdateColors() = 0;
107 
108  DECLARE_INTERFACE_TYPE(TerritoryManager)
109 };
110 
111 #endif // INCLUDED_ICMPTERRITORYMANAGER
Definition: IComponent.h:32
A simple fixed-point number class.
Definition: Fixed.h:119
virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z)=0
Check if a piece of territory is blinking.
virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable)=0
Set a piece of territory to blinking.
virtual u8 GetTerritoryPercentage(player_id_t player)=0
Returns the percentage of the world controlled by a given player as defined by the number of territor...
virtual const Grid< u8 > & GetTerritoryGrid()=0
For each tile, the TERRITORY_PLAYER_MASK bits are player ID; TERRITORY_CONNECTED_MASK is set if the t...
virtual bool NeedUpdateAI(size_t *dirtyID, size_t *dirtyBlinkingID) const =0
Returns whether the AI territory map needs to be updated.
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: TerritoryBoundary.h:27
uint8_t u8
Definition: types.h:37
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:24
static const int TERRITORY_BLINKING_MASK
Definition: ICmpTerritoryManager.h:54
virtual void UpdateColors()=0
Updates the boundary and territory colors.
virtual void SetVisibility(bool visible)=0
Enables or disables rendering of an territory borders.
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
virtual bool IsConnected(entity_pos_t x, entity_pos_t z)=0
Get whether territory at given position is connected to a root object (civ center etc) owned by that ...
static const int TERRITORY_CONNECTED_MASK
Definition: ICmpTerritoryManager.h:53
virtual std::vector< u32 > GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected)=0
get the number of neighbour tiles for per player for the selected position
static const int NAVCELLS_PER_TERRITORY_TILE
Number of pathfinder navcells per territory tile.
Definition: ICmpTerritoryManager.h:50
static const int TERRITORY_PLAYER_MASK
Definition: ICmpTerritoryManager.h:52
static const int TERRITORY_PROCESSED_MASK
Definition: ICmpTerritoryManager.h:55
virtual player_id_t GetOwner(entity_pos_t x, entity_pos_t z)=0
Get owner of territory at given position.
Definition: ICmpTerritoryManager.h:31
virtual bool NeedUpdateTexture(size_t *dirtyID)=0
Returns whether the territory texture needs to be updated.