LCOV - code coverage report
Current view: top level - source/simulation2/components - ICmpUnitMotion.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 2 50.0 %
Date: 2022-06-14 00:41:00 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2022 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_ICMPUNITMOTION
      19             : #define INCLUDED_ICMPUNITMOTION
      20             : 
      21             : #include "simulation2/system/Interface.h"
      22             : 
      23             : #include "simulation2/components/ICmpPathfinder.h" // for pass_class_t
      24             : #include "simulation2/components/ICmpPosition.h" // for entity_pos_t
      25             : 
      26             : /**
      27             :  * Motion interface for entities with complex movement capabilities.
      28             :  * (Simpler motion is handled by ICmpMotion instead.)
      29             :  *
      30             :  * It should eventually support different movement speeds, moving to areas
      31             :  * instead of points, moving as part of a group, moving as part of a formation,
      32             :  * etc.
      33             :  */
      34           0 : class ICmpUnitMotion : public IComponent
      35             : {
      36             : public:
      37             : 
      38             :     /**
      39             :      * Attempt to walk into range of a to a given point, or as close as possible.
      40             :      * The range is measured from the center of the unit.
      41             :      * If cannot move anywhere at all, or if there is some other error, then returns false.
      42             :      * Otherwise, returns true.
      43             :      * If maxRange is negative, then the maximum range is treated as infinity.
      44             :      */
      45             :     virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) = 0;
      46             : 
      47             :     /**
      48             :      * Attempt to walk into range of a given target entity, or as close as possible.
      49             :      * The range is measured between approximately the edges of the unit and the target, so that
      50             :      * maxRange=0 is not unreachably close to the target.
      51             :      * If the unit cannot move anywhere at all, or if there is some other error, then returns false.
      52             :      * Otherwise, returns true.
      53             :      * If maxRange is negative, then the maximum range is treated as infinity.
      54             :      */
      55             :     virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) = 0;
      56             : 
      57             :     /**
      58             :      * Join a formation, and move towards a given offset relative to the formation controller entity.
      59             :      * The unit will remain 'in formation' fromthe perspective of UnitMotion
      60             :      * until SetMemberOfFormation(INVALID_ENTITY) is passed.
      61             :      */
      62             :     virtual void MoveToFormationOffset(entity_id_t controller, entity_pos_t x, entity_pos_t z) = 0;
      63             : 
      64             :     /**
      65             :      * Set/unset the unit as a formation member.
      66             :      * @param controller - if INVALID_ENTITY, the unit is no longer a formation member. Otherwise it is and this is the controller.
      67             :      */
      68             :     virtual void SetMemberOfFormation(entity_id_t controller) = 0;
      69             : 
      70             :     /**
      71             :      * Check if the target is reachable.
      72             :      * Don't take this as absolute gospel since there are things that the pathfinder may not detect, such as
      73             :      * entity obstructions in the way, but in general it should return satisfactory results.
      74             :      * The interface is similar to MoveToTargetRange but the move is not attempted.
      75             :      * @return true if the target is assumed reachable, false otherwise.
      76             :      */
      77             :     virtual bool IsTargetRangeReachable(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) = 0;
      78             : 
      79             :     /**
      80             :      * Turn to look towards the given point.
      81             :      */
      82             :     virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) = 0;
      83             : 
      84             :     /**
      85             :      * Stop moving immediately.
      86             :      */
      87             :     virtual void StopMoving() = 0;
      88             : 
      89             :     /**
      90             :      * Get the speed at the end of the current turn.
      91             :      */
      92             :     virtual fixed GetCurrentSpeed() const = 0;
      93             : 
      94             :     /**
      95             :      * @returns true if the unit has a destination.
      96             :      */
      97             :     virtual bool IsMoveRequested() const = 0;
      98             : 
      99             :     /**
     100             :      * Get the unit template walk speed after modifications.
     101             :      */
     102             :     virtual fixed GetWalkSpeed() const = 0;
     103             : 
     104             :     /**
     105             :      * Get the unit template running (i.e. max) speed after modifications.
     106             :      */
     107             :     virtual fixed GetRunMultiplier() const = 0;
     108             : 
     109             :     /**
     110             :      * Returns the ratio of GetSpeed() / GetWalkSpeed().
     111             :      */
     112             :     virtual fixed GetSpeedMultiplier() const = 0;
     113             : 
     114             :     /**
     115             :      * Set the current movement speed.
     116             :      * @param speed A multiplier of GetWalkSpeed().
     117             :      */
     118             :     virtual void SetSpeedMultiplier(fixed multiplier) = 0;
     119             : 
     120             :     /**
     121             :      * Get the speed at which the unit intends to move.
     122             :      * (regardless of whether the unit is moving or not right now).
     123             :      */
     124             :     virtual fixed GetSpeed() const = 0;
     125             : 
     126             :     /**
     127             :      * @return the estimated position of the unit in @param dt seconds,
     128             :      * following current paths. This is allowed to 'look into the future'.
     129             :      */
     130             :     virtual CFixedVector2D EstimateFuturePosition(const fixed dt) const = 0;
     131             : 
     132             :     /**
     133             :      * Get the current acceleration.
     134             :      */
     135             :     virtual fixed GetAcceleration() const = 0;
     136             : 
     137             :     /**
     138             :      * Set the current acceleration.
     139             :      * @param acceleration The acceleration.
     140             :      */
     141             :     virtual void SetAcceleration(fixed acceleration) = 0;
     142             : 
     143             :     /**
     144             :      * Set whether the unit will turn to face the target point after finishing moving.
     145             :      */
     146             :     virtual void SetFacePointAfterMove(bool facePointAfterMove) = 0;
     147             : 
     148             :     virtual bool GetFacePointAfterMove() const = 0;
     149             : 
     150             :     /**
     151             :      * Get the unit's passability class.
     152             :      */
     153             :     virtual pass_class_t GetPassabilityClass() const = 0;
     154             : 
     155             :     /**
     156             :      * Get the passability class name (as defined in pathfinder.xml)
     157             :      */
     158             :     virtual std::string GetPassabilityClassName() const = 0;
     159             : 
     160             :     /**
     161             :      * Sets the passability class name (as defined in pathfinder.xml)
     162             :      */
     163             :     virtual void SetPassabilityClassName(const std::string& passClassName) = 0;
     164             : 
     165             :     /**
     166             :      * Get the unit clearance (used by the Obstruction component)
     167             :      */
     168             :     virtual entity_pos_t GetUnitClearance() const = 0;
     169             : 
     170             :     /**
     171             :      * Toggle the rendering of debug info.
     172             :      */
     173             :     virtual void SetDebugOverlay(bool enabled) = 0;
     174             : 
     175         230 :     DECLARE_INTERFACE_TYPE(UnitMotion)
     176             : };
     177             : 
     178             : #endif // INCLUDED_ICMPUNITMOTION

Generated by: LCOV version 1.13