LCOV - code coverage report
Current view: top level - source/graphics - Unit.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 4 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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_UNIT
      19             : #define INCLUDED_UNIT
      20             : 
      21             : #include <map>
      22             : #include <set>
      23             : 
      24             : #include "ps/CStr.h"
      25             : #include "simulation2/system/Entity.h"    // entity_id_t
      26             : 
      27             : class CActorDef;
      28             : class CModelAbstract;
      29             : class CObjectEntry;
      30             : class CObjectManager;
      31             : class CUnitAnimation;
      32             : 
      33             : 
      34             : /////////////////////////////////////////////////////////////////////////////////////////////
      35             : // CUnit: simple "actor" definition - defines a sole object within the world
      36             : class CUnit
      37             : {
      38             :     NONCOPYABLE(CUnit);
      39             : private:
      40             :     // Private constructor. Needs complete list of selections for the variation.
      41             :     CUnit(CObjectManager& objectManager, const CActorDef& actor, uint32_t seed);
      42             : 
      43             : public:
      44             :     // Attempt to create a unit with the given actor.
      45             :     // If specific selections are wanted, call SetEntitySelection or SetActorSelections after creation.
      46             :     // Returns NULL on failure.
      47             :     static CUnit* Create(const CStrW& actorName, uint32_t seed, CObjectManager& objectManager);
      48             : 
      49             :     // destructor
      50             :     ~CUnit();
      51             : 
      52             :     // get unit's template object
      53           0 :     const CObjectEntry& GetObject() const { return *m_Object; }
      54             :     // get unit's model data
      55           0 :     CModelAbstract& GetModel() const { return *m_Model; }
      56             : 
      57           0 :     CUnitAnimation* GetAnimation() { return m_Animation; }
      58             : 
      59             :     /**
      60             :      * Update the model's animation.
      61             :      * @param frameTime time in seconds
      62             :      */
      63             :     void UpdateModel(float frameTime);
      64             : 
      65             :     // Sets the entity-selection, and updates the unit to use the new
      66             :     // actor variation. Either set one key at a time, or a complete map.
      67             :     void SetEntitySelection(const CStr& key, const CStr& selection);
      68             :     void SetEntitySelection(const std::map<CStr, CStr>& selections);
      69             : 
      70             :     // Most units have a hopefully-unique ID number, so they can be referred to
      71             :     // persistently despite saving/loading maps. Default for new units is -1; should
      72             :     // usually be set to CUnitManager::GetNewID() after creation.
      73           0 :     entity_id_t GetID() const { return m_ID; }
      74             :     void SetID(entity_id_t id);
      75             : 
      76             :     const std::set<CStr>& GetActorSelections() const { return m_ActorSelections; }
      77             : 
      78             :     /**
      79             :      * Overwrite the seed-selected actor selections. Likely only useful for Atlas or debugging.
      80             :      */
      81             :     void SetActorSelections(const std::set<CStr>& selections);
      82             : 
      83             : private:
      84             :     // Actor for the unit
      85             :     const CActorDef& m_Actor;
      86             :     // object from which unit was created; never NULL once fully created.
      87             :     CObjectEntry* m_Object = nullptr;
      88             :     // object model representation; never NULL once fully created.
      89             :     CModelAbstract* m_Model = nullptr;
      90             : 
      91             :     CUnitAnimation* m_Animation = nullptr;
      92             : 
      93             :     // unique (per map) ID number for units created in the editor, as a
      94             :     // permanent way of referencing them.
      95             :     entity_id_t m_ID;
      96             : 
      97             :     // seed used when creating unit
      98             :     uint32_t m_Seed;
      99             : 
     100             :     // Actor-level selections for this unit. This is normally set at init time,
     101             :     // so that we always re-use the same aesthetic variants.
     102             :     // These have lower priority than entity-level selections.
     103             :     std::set<CStr> m_ActorSelections;
     104             :     // Entity-level selections for this unit (used for e.g. animation variants).
     105             :     std::map<CStr, CStr> m_EntitySelections;
     106             : 
     107             :     // object manager which looks after this unit's objectentry
     108             :     CObjectManager& m_ObjectManager;
     109             : 
     110             :     void ReloadObject();
     111             : 
     112             :     friend class CUnitAnimation;
     113             : };
     114             : 
     115             : #endif

Generated by: LCOV version 1.13