LCOV - code coverage report
Current view: top level - source/simulation2/components - ICmpObstruction.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_ICMPOBSTRUCTION
      19             : #define INCLUDED_ICMPOBSTRUCTION
      20             : 
      21             : #include "simulation2/components/ICmpObstructionManager.h"
      22             : #include "simulation2/helpers/Position.h"
      23             : #include "simulation2/system/Component.h"
      24             : #include "simulation2/system/Entity.h"
      25             : #include "simulation2/system/Interface.h"
      26             : 
      27             : #include <cstdint>
      28             : #include <js/Value.h>
      29             : #include <string>
      30             : #include <vector>
      31             : 
      32             : class CFixedVector2D;
      33             : 
      34             : /**
      35             :  * Flags an entity as obstructing movement for other units,
      36             :  * and handles the processing of collision queries.
      37             :  */
      38         199 : class ICmpObstruction : public IComponent
      39             : {
      40             : public:
      41             : 
      42             :     enum EFoundationCheck {
      43             :         FOUNDATION_CHECK_SUCCESS,
      44             :         FOUNDATION_CHECK_FAIL_ERROR,
      45             :         FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION,
      46             :         FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION,
      47             :         FOUNDATION_CHECK_FAIL_TERRAIN_CLASS
      48             :     };
      49             : 
      50             :     enum EObstructionType {
      51             :         STATIC,
      52             :         UNIT,
      53             :         CLUSTER
      54             :     };
      55             : 
      56             :     virtual ICmpObstructionManager::tag_t GetObstruction() const = 0;
      57             : 
      58             :     /**
      59             :      * Gets the square corresponding to this obstruction shape.
      60             :      * @return true and updates @p out on success;
      61             :      *         false on failure (e.g. object not in the world).
      62             :      */
      63             :     virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) const = 0;
      64             : 
      65             :     /**
      66             :      * Same as the method above, but returns an obstruction shape for the previous turn
      67             :      */
      68             :     virtual bool GetPreviousObstructionSquare(ICmpObstructionManager::ObstructionSquare& out) const = 0;
      69             : 
      70             :     /**
      71             :      * @return the size of the obstruction (either the clearance or a circumscribed circle).
      72             :      */
      73             :     virtual entity_pos_t GetSize() const = 0;
      74             : 
      75             :     /**
      76             :      * @return the size of the static obstruction or (0,0) for a unit shape.
      77             :      */
      78             :     virtual CFixedVector2D GetStaticSize() const = 0;
      79             : 
      80             :     virtual EObstructionType GetObstructionType() const = 0;
      81             : 
      82             :     virtual void SetUnitClearance(const entity_pos_t& clearance) = 0;
      83             : 
      84             :     virtual bool IsControlPersistent() const = 0;
      85             : 
      86             :     /**
      87             :      * Test whether the front of the obstruction square is in the water and the back is on the shore.
      88             :      */
      89             :     virtual bool CheckShorePlacement() const = 0;
      90             : 
      91             :     /**
      92             :      * Test whether this entity is colliding with any obstruction that are set to
      93             :      * block the creation of foundations.
      94             :      * @param ignoredEntities List of entities to ignore during the test.
      95             :      * @return FOUNDATION_CHECK_SUCCESS if check passes, else an EFoundationCheck
      96             :      *  value describing the type of failure.
      97             :      */
      98             :     virtual EFoundationCheck CheckFoundation(const std::string& className) const = 0;
      99             :     virtual EFoundationCheck CheckFoundation(const std::string& className, bool onlyCenterPoint) const = 0;
     100             : 
     101             :     /**
     102             :      * CheckFoundation wrapper for script calls, to return friendly strings instead of an EFoundationCheck.
     103             :      * @return "success" if check passes, else a string describing the type of failure.
     104             :      */
     105             :     virtual std::string CheckFoundation_wrapper(const std::string& className, bool onlyCenterPoint) const;
     106             : 
     107             :     /**
     108             :      * GetObstructionSquare wrapper for script calls.
     109             :      * @return [hw, hh] half-sizes of the obstruction square, or empty array on failure.
     110             :      */
     111             :     virtual CFixedVector2D GetObstructionHalfSizes_wrapper() const;
     112             : 
     113             :     /**
     114             :      * Test whether this entity is colliding with any obstructions that share its
     115             :      * control groups and block the creation of foundations.
     116             :      * @return true if foundation is valid (not obstructed)
     117             :      */
     118             :     virtual bool CheckDuplicateFoundation() const = 0;
     119             : 
     120             :     /**
     121             :      * Returns a list of entities that have an obstruction matching the given flag and intersect the current obstruction.
     122             :      * @return vector of blocking entities
     123             :      */
     124             :     virtual std::vector<entity_id_t> GetEntitiesByFlags(ICmpObstructionManager::flags_t flags) const = 0;
     125             : 
     126             :     /**
     127             :      * Returns a list of entities that are blocking movement.
     128             :      * @return vector of blocking entities
     129             :      */
     130             :     virtual std::vector<entity_id_t> GetEntitiesBlockingMovement() const = 0;
     131             : 
     132             :     /**
     133             :      * Returns a list of entities that are blocking construction of a foundation.
     134             :      * @return vector of blocking entities
     135             :      */
     136             :     virtual std::vector<entity_id_t> GetEntitiesBlockingConstruction() const = 0;
     137             : 
     138             :     /**
     139             :      * Returns a list of entities that shall be deleted when a construction on this obstruction starts,
     140             :      * for example sheep carcasses.
     141             :      */
     142             :     virtual std::vector<entity_id_t> GetEntitiesDeletedUponConstruction() const = 0;
     143             : 
     144             :     /**
     145             :      * Detects collisions between foundation-blocking entities and
     146             :      * tries to fix them by setting control groups, if appropriate.
     147             :      */
     148             :     virtual void ResolveFoundationCollisions() const = 0;
     149             : 
     150             :     virtual void SetActive(bool active) = 0;
     151             : 
     152             :     virtual void SetMovingFlag(bool enabled) = 0;
     153             : 
     154             :     virtual void SetDisableBlockMovementPathfinding(bool movementDisabled, bool pathfindingDisabled, int32_t shape) = 0;
     155             : 
     156             :     /**
     157             :      * @param templateOnly - whether to return the raw template value or the current value.
     158             :      */
     159             :     virtual bool GetBlockMovementFlag(bool templateOnly) const = 0;
     160             : 
     161             :     /**
     162             :      * Change the control group that the entity belongs to.
     163             :      * Control groups are used to let units ignore collisions with other units from
     164             :      * the same group. Default is the entity's own ID.
     165             :      */
     166             :     virtual void SetControlGroup(entity_id_t group) = 0;
     167             : 
     168             :     /// See SetControlGroup.
     169             :     virtual entity_id_t GetControlGroup() const = 0;
     170             : 
     171             :     virtual void SetControlGroup2(entity_id_t group2) = 0;
     172             :     virtual entity_id_t GetControlGroup2() const = 0;
     173             : 
     174       67407 :     DECLARE_INTERFACE_TYPE(Obstruction)
     175             : };
     176             : 
     177             : #endif // INCLUDED_ICMPOBSTRUCTION

Generated by: LCOV version 1.16