0ad/source/graphics/UnitManager.h
Ykkrosh ec69bccb2c # Tidied up some code.
- Made some classes not be singletons, since there's no reason why they
should be.
 - Made them non-global too (because globals have unclear lifetimes, and
make it harder to test things, etc). They're now owned by CGameView and
CWorld, and mostly accessed via g_Game or arguments (vaguely trying to
avoid the graphics code calling into the game code).
 - Moved CGameView implementation into pimpl, so the header file isn't
so heavy.
 - Changed a few pointers into references, to indicate that they're
never NULL.

This was SVN commit r4756.
2007-01-08 01:56:46 +00:00

68 lines
1.8 KiB
C++

///////////////////////////////////////////////////////////////////////////////
//
// Name: UnitManager.h
// Author: Rich Cross
// Contact: rich@wildfiregames.com
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _UNITMANAGER_H
#define _UNITMANAGER_H
#include <vector>
#include <set>
class CUnit;
class CModel;
class CVector3D;
class CEntity;
class CStr;
class CObjectManager;
///////////////////////////////////////////////////////////////////////////////
// CUnitManager: simple container class holding all units within the world
class CUnitManager
{
public:
// constructor, destructor
CUnitManager();
~CUnitManager();
// add given unit to world
void AddUnit(CUnit* unit);
// remove given unit from world, but don't delete it
void RemoveUnit(CUnit* unit);
// remove given unit from world and delete it
void DeleteUnit(CUnit* unit);
// remove and delete all units
void DeleteAll();
// creates a new unit and adds it to the world
CUnit* CreateUnit(const CStr& actorName, CEntity* entity, const std::set<CStr>& selections);
// return the units
const std::vector<CUnit*>& GetUnits() const { return m_Units; }
// iterate through units testing given ray against bounds of each unit;
// return the closest unit, or null if everything missed
CUnit* PickUnit(const CVector3D& origin, const CVector3D& dir, bool entitiesOnly) const;
CUnit* FindByID(int id) const;
int GetNewID() { return m_NextID++; }
void SetNextID(int n) { m_NextID = n; }
void SetObjectManager(CObjectManager& objectManager) { m_ObjectManager = &objectManager; }
private:
// list of all known units
std::vector<CUnit*> m_Units;
// next ID number to be assigned to a unit created in the editor
int m_NextID;
// graphical object manager; may be NULL if not set up
CObjectManager* m_ObjectManager;
};
#endif