Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ICmpTerritoryManager.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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
25
26#include <cstddef>
27#include <js/Value.h>
28#include <vector>
29
30template<typename T> class Grid;
31
33{
34public:
35 /**
36 * Returns whether the territory texture needs to be updated.
37 */
38 virtual bool NeedUpdateTexture(size_t* dirtyID) = 0;
39
40 /**
41 * Returns whether the AI territory map needs to be updated.
42 */
43 virtual bool NeedUpdateAI(size_t* dirtyID, size_t* dirtyBlinkingID) const = 0;
44
45 /**
46 * Number of pathfinder navcells per territory tile.
47 * Passability data is stored per navcell, but we probably don't need that much
48 * resolution, and a lower resolution can make the boundary lines look prettier
49 * and will take less memory, so we downsample the passability data.
50 */
51 static const int NAVCELLS_PER_TERRITORY_TILE = 8;
52
53 static const int TERRITORY_PLAYER_MASK = 0x1F;
54 static const int TERRITORY_CONNECTED_MASK = 0x20;
55 static const int TERRITORY_BLINKING_MASK = 0x40;
56 static const int TERRITORY_PROCESSED_MASK = 0x80; //< For internal use; marks a tile as processed.
57
58 /**
59 * For each tile, the TERRITORY_PLAYER_MASK bits are player ID;
60 * TERRITORY_CONNECTED_MASK is set if the tile is connected to a root object
61 * (civ center etc).
62 */
64
65 /**
66 * Get owner of territory at given position.
67 * @return player ID of owner; 0 if neutral territory
68 */
70
71 /**
72 * get the number of neighbour tiles for per player for the selected position
73 * @return A list with the number of neighbour tiles per player
74 */
75 virtual std::vector<std::uint32_t> GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) = 0;
76
77 /**
78 * Get whether territory at given position is connected to a root object
79 * (civ center etc) owned by that territory's player.
80 */
81 virtual bool IsConnected(entity_pos_t x, entity_pos_t z) = 0;
82
83 /**
84 * Set a piece of territory to blinking. Must be updated on every territory calculation
85 */
86 virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable) = 0;
87
88 /**
89 * Check if a piece of territory is blinking.
90 */
92
93 /**
94 * Returns the percentage of the world controlled by a given player as defined by
95 * the number of territory cells the given player owns
96 */
97 virtual std::uint8_t GetTerritoryPercentage(player_id_t player) = 0;
98
99 /**
100 * Enables or disables rendering of an territory borders.
101 */
102 virtual void SetVisibility(bool visible) = 0;
103
104 /**
105 * Updates the boundary and territory colors.
106 */
107 virtual void UpdateColors() = 0;
108
109 /**
110 * Whether the territory lines are visible.
111 */
112 virtual bool IsVisible() const = 0;
113
114 DECLARE_INTERFACE_TYPE(TerritoryManager)
115};
116
117#endif // INCLUDED_ICMPTERRITORYMANAGER
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:26
Entity coordinate types.
A simple fixed-point number class.
Definition: Fixed.h:129
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: Grid.h:46
Definition: ICmpTerritoryManager.h:33
virtual void SetVisibility(bool visible)=0
Enables or disables rendering of an territory borders.
virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable)=0
Set a piece of territory to blinking.
virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z)=0
Check if a piece of territory is blinking.
virtual player_id_t GetOwner(entity_pos_t x, entity_pos_t z)=0
Get owner of territory at given position.
static const int TERRITORY_PROCESSED_MASK
Definition: ICmpTerritoryManager.h:56
virtual std::vector< std::uint32_t > 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 TERRITORY_BLINKING_MASK
Definition: ICmpTerritoryManager.h:55
virtual bool NeedUpdateTexture(size_t *dirtyID)=0
Returns whether the territory texture needs to be updated.
static const int NAVCELLS_PER_TERRITORY_TILE
Number of pathfinder navcells per territory tile.
Definition: ICmpTerritoryManager.h:51
static const int TERRITORY_PLAYER_MASK
Definition: ICmpTerritoryManager.h:53
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 ...
virtual void UpdateColors()=0
Updates the boundary and territory colors.
virtual std::uint8_t GetTerritoryPercentage(player_id_t player)=0
Returns the percentage of the world controlled by a given player as defined by the number of territor...
static const int TERRITORY_CONNECTED_MASK
Definition: ICmpTerritoryManager.h:54
virtual bool IsVisible() const =0
Whether the territory lines are visible.
virtual const Grid< std::uint8_t > & 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.
Definition: IComponent.h:33
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23