Colobot
objman.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "object/object.h"
28 
29 #include "common/singleton.h"
30 
31 #include <map>
32 
37 class CObjectManager : public CSingleton<CObjectManager>
38 {
39 public:
41  virtual ~CObjectManager();
42 
44  bool AddObject(CObject* instance);
46  bool DeleteObject(CObject* instance);
48  CObject* GetObjectById(unsigned int id);
50  CObject* GetObjectByRank(unsigned int id);
52  const std::map<unsigned int, CObject*>& GetAllObjects();
54  void Flush();
55 
56 
58  CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.f, float zoom = 1.f, float height = 0.f, bool trainer = false, bool toy = false, int option = 0);
60  bool DestroyObject(int id);
62 
63  CObject* Radar(CObject* pThis, ObjectType type = OBJECT_NULL, float angle = 0.0f, float focus = Math::PI*2.0f, float minDist = 0.0f, float maxDist = 1000.0f, bool furthest = false, RadarFilter filter = FILTER_NONE, bool cbotTypes = false);
64  CObject* Radar(CObject* pThis, std::vector<ObjectType> type = std::vector<ObjectType>(), float angle = 0.0f, float focus = Math::PI*2.0f, float minDist = 0.0f, float maxDist = 1000.0f, bool furthest = false, RadarFilter filter = FILTER_NONE, bool cbotTypes = false);
65  CObject* Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type = OBJECT_NULL, float angle = 0.0f, float focus = Math::PI*2.0f, float minDist = 0.0f, float maxDist = 1000.0f, bool furthest = false, RadarFilter filter = FILTER_NONE, bool cbotTypes = false);
66  CObject* Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector<ObjectType> type = std::vector<ObjectType>(), float angle = 0.0f, float focus = Math::PI*2.0f, float minDist = 0.0f, float maxDist = 1000.0f, bool furthest = false, RadarFilter filter = FILTER_NONE, bool cbotTypes = false);
68 
70  CObject* FindNearest(CObject* pThis, ObjectType type = OBJECT_NULL, float maxDist = 1000.0f, bool cbotTypes = false);
71  CObject* FindNearest(CObject* pThis, std::vector<ObjectType> type = std::vector<ObjectType>(), float maxDist = 1000.0f, bool cbotTypes = false);
72  CObject* FindNearest(CObject* pThis, Math::Vector thisPosition, ObjectType type = OBJECT_NULL, float maxDist = 1000.0f, bool cbotTypes = false);
73  CObject* FindNearest(CObject* pThis, Math::Vector thisPosition, std::vector<ObjectType> type = std::vector<ObjectType>(), float maxDist = 1000.0f, bool cbotTypes = false);
75 
76 protected:
77  std::map<unsigned int, CObject*> m_table;
78 };
79 
CSingleton base class for singletons.
bool DeleteObject(CObject *instance)
Unregisters the object.
Definition: objman.cpp:52
CObject * FindNearest(CObject *pThis, ObjectType type=OBJECT_NULL, float maxDist=1000.0f, bool cbotTypes=false)
Returns nearest object that's closer than maxDist.
Definition: objman.cpp:515
Definition: singleton.h:30
bool AddObject(CObject *instance)
Registers new object.
Definition: objman.cpp:44
const float PI
PI.
Definition: const.h:47
CObject * GetObjectByRank(unsigned int id)
Gets object by id in range <0; m_table.size())
Definition: objman.cpp:73
ObjectType
Type of game object.
Definition: object.h:51
CObject * CreateObject(Math::Vector pos, float angle, ObjectType type, float power=-1.f, float zoom=1.f, float height=0.f, bool trainer=false, bool toy=false, int option=0)
Creates an object.
Definition: objman.cpp:91
CObject - base class for all game objects.
bool DestroyObject(int id)
Destroys an object.
Definition: objman.cpp:386
CObject * Radar(CObject *pThis, ObjectType type=OBJECT_NULL, float angle=0.0f, float focus=Math::PI *2.0f, float minDist=0.0f, float maxDist=1000.0f, bool furthest=false, RadarFilter filter=FILTER_NONE, bool cbotTypes=false)
Finds an object, like radar() in CBot.
Definition: objman.cpp:394
3D (3x1) vector
Definition: vector.h:52
void Flush()
Removes all objects.
Definition: objman.cpp:86
Definition: objman.h:37
const std::map< unsigned int, CObject * > & GetAllObjects()
Returns all objects.
Definition: objman.cpp:81
CObject * GetObjectById(unsigned int id)
Finds object by id (CObject::GetID())
Definition: objman.cpp:67
Definition: object.h:357