LCOV - code coverage report
Current view: top level - source/simulation2/components - ICmpTerritoryManager.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 2 100.0 %
Date: 2026-12-02 01:21:50 Functions: 0 0 -

          Line data    Source code
       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             : 
      21             : #include "simulation2/helpers/Player.h"
      22             : #include "simulation2/helpers/Position.h"
      23             : #include "simulation2/system/Component.h"
      24             : #include "simulation2/system/Interface.h"
      25             : 
      26             : #include <cstddef>
      27             : #include <js/Value.h>
      28             : #include <vector>
      29             : 
      30             : template<typename T> class Grid;
      31             : 
      32           8 : class ICmpTerritoryManager : public IComponent
      33             : {
      34             : public:
      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             :      */
      63             :     virtual const Grid<std::uint8_t>& GetTerritoryGrid() = 0;
      64             : 
      65             :     /**
      66             :      * Get owner of territory at given position.
      67             :      * @return player ID of owner; 0 if neutral territory
      68             :      */
      69             :     virtual player_id_t GetOwner(entity_pos_t x, entity_pos_t z) = 0;
      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             :      */
      91             :     virtual bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0;
      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           6 :     DECLARE_INTERFACE_TYPE(TerritoryManager)
     115             : };
     116             : 
     117             : #endif // INCLUDED_ICMPTERRITORYMANAGER

Generated by: LCOV version 1.16