Line data Source code
1 : /* Copyright (C) 2025 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 : /* 19 : * Container that owns all units 20 : */ 21 : 22 : #ifndef INCLUDED_UNITMANAGER 23 : #define INCLUDED_UNITMANAGER 24 : 25 : #include "lib/posix/posix_types.h" 26 : #include "simulation2/system/Entity.h" 27 : 28 : #include <cstdint> 29 : #include <memory> 30 : #include <vector> 31 : 32 : class CObjectManager; 33 : class CStrW; 34 : class CUnit; 35 : 36 : /////////////////////////////////////////////////////////////////////////////// 37 : // CUnitManager: simple container class holding all units within the world 38 : class CUnitManager 39 : { 40 : public: 41 : // constructor, destructor 42 : CUnitManager(); 43 : ~CUnitManager(); 44 : 45 : // add given unit to world 46 : CUnit* AddUnit(std::unique_ptr<CUnit> unit); 47 : // remove given unit from world and delete it 48 : void DeleteUnit(CUnit* unit); 49 : 50 : // creates a new unit and adds it to the world 51 : CUnit* CreateUnit(const CStrW& actorName, const entity_id_t id, const uint32_t seed); 52 : 53 1 : void SetObjectManager(CObjectManager& objectManager) { m_ObjectManager = &objectManager; } 54 : 55 : /** 56 : * Mark a specific region of the terrain as dirty. 57 : * Coordinates are in terrain tiles, lower inclusive, upper exclusive. 58 : */ 59 : void MakeTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags); 60 : 61 : private: 62 : // list of all known units 63 : std::vector<std::unique_ptr<CUnit>> m_Units; 64 : // graphical object manager; may be NULL if not set up 65 : CObjectManager* m_ObjectManager; 66 : }; 67 : 68 : #endif // INCLUDED_UNITMANAGER