Create CObjectFactory

* move functions creating objects to new class CObjectFactory
 * replace calls to CObject::Create*() with CObjectManager::Create()
 * move creation/deletion of some objects to better places
 * make CModelManager non-singleton
 * clean up some code in changed functions
master
Piotr Dziwinski 2015-06-20 19:27:43 +02:00
parent 74a31c9fb4
commit f9b09d08f0
48 changed files with 4233 additions and 4283 deletions

View File

@ -158,6 +158,7 @@ set(BASE_SOURCES
object/motion/motionvehicle.cpp
object/motion/motionworm.cpp
object/object.cpp
object/object_factory.cpp
object/robotmain.cpp
object/objman.cpp
object/task/task.cpp

View File

@ -105,14 +105,12 @@ CApplication::CApplication()
m_private = new ApplicationPrivate();
m_iMan = new CInstanceManager();
m_pathManager = new CPathManager();
m_objMan = new CObjectManager();
m_eventQueue = new CEventQueue();
m_profile = new CProfile();
m_input = new CInput();
m_engine = nullptr;
m_device = nullptr;
m_modelManager = nullptr;
m_controller = nullptr;
m_sound = nullptr;
@ -174,9 +172,6 @@ CApplication::~CApplication()
delete m_input;
m_input = nullptr;
delete m_objMan;
m_objMan = nullptr;
delete m_eventQueue;
m_eventQueue = nullptr;
@ -572,9 +567,6 @@ bool CApplication::Create()
return false;
}
// Create model manager
m_modelManager = new Gfx::CModelManager(m_engine);
// Create the robot application.
m_controller = new CController(this, !defaultValues);
@ -650,9 +642,6 @@ void CApplication::Destroy()
delete m_sound;
m_sound = nullptr;
delete m_modelManager;
m_modelManager = nullptr;
if (m_engine != nullptr)
{
m_engine->Destroy();

View File

@ -359,16 +359,12 @@ protected:
//! Instance manager
// TODO: to be removed
CInstanceManager* m_iMan;
//! Object manager
CObjectManager* m_objMan;
//! Global event queue
CEventQueue* m_eventQueue;
//! Graphics engine
Gfx::CEngine* m_engine;
//! Graphics device
Gfx::CDevice* m_device;
//! 3D models manager
Gfx::CModelManager* m_modelManager;
//! Sound subsystem
CSoundInterface* m_sound;
//! Game controller - game engine and UI

View File

@ -32,6 +32,7 @@
#include "graphics/engine/cloud.h"
#include "graphics/engine/lightman.h"
#include "graphics/engine/lightning.h"
#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/planet.h"
#include "graphics/engine/pyro.h"
@ -229,6 +230,11 @@ CDevice* CEngine::GetDevice()
return m_device;
}
CModelManager* CEngine::GetModelManager()
{
return m_modelManager.get();
}
CText* CEngine::GetText()
{
return m_text;
@ -278,6 +284,7 @@ bool CEngine::Create()
{
m_size = m_app->GetVideoConfig().size;
m_modelManager.reset(new CModelManager(this));
m_lightMan = new CLightManager(this);
m_text = new CText(this);
m_particle = new CParticle(this);
@ -324,7 +331,7 @@ bool CEngine::Create()
void CEngine::Destroy()
{
m_text->Destroy();
delete m_pause;
m_pause = nullptr;

View File

@ -48,6 +48,7 @@
#include <vector>
#include <map>
#include <set>
#include <memory>
class CApplication;
@ -61,6 +62,7 @@ namespace Gfx {
class CDevice;
class CModelManager;
class CLightManager;
class CText;
class CParticle;
@ -694,6 +696,7 @@ public:
//! Returns the text rendering engine
CText* GetText();
CModelManager* GetModelManager();
//! Returns the light manager
CLightManager* GetLightManager();
//! Returns the particle manager
@ -1328,6 +1331,7 @@ protected:
CApplication* m_app;
CSoundInterface* m_sound;
CDevice* m_device;
std::unique_ptr<CModelManager> m_modelManager;
CText* m_text;
CLightManager* m_lightMan;
CParticle* m_particle;

View File

@ -27,8 +27,6 @@
#include <cstdio>
template<> Gfx::CModelManager* CSingleton<Gfx::CModelManager>::m_instance = nullptr;
namespace Gfx {
CModelManager::CModelManager(CEngine* engine)

View File

@ -51,7 +51,7 @@ class CModelFile;
* its own and unique base engine object. This is especially useful
* for models where the geometry must be altered.
*/
class CModelManager : public CSingleton<CModelManager>
class CModelManager
{
public:
CModelManager(CEngine* engine);

View File

@ -492,20 +492,10 @@ bool CAutoConvert::SearchVehicle()
void CAutoConvert::CreateMetal()
{
Math::Vector pos;
float angle;
CObject* fret;
Math::Vector pos = m_object->GetPosition(0);
float angle = m_object->GetAngleY(0);
pos = m_object->GetPosition(0);
angle = m_object->GetAngleY(0);
fret = new CObject();
if ( !fret->CreateResource(pos, angle, OBJECT_METAL) )
{
delete fret;
m_main->DisplayError(ERR_TOOMANY, m_object);
return;
}
CObject* fret = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, OBJECT_METAL);
if ( m_bResetDelete )
{

View File

@ -518,15 +518,7 @@ bool CAutoDerrick::SearchFree(Math::Vector pos)
void CAutoDerrick::CreateFret(Math::Vector pos, float angle, ObjectType type,
float height)
{
CObject* fret;
fret = new CObject();
if ( !fret->CreateResource(pos, angle, type) )
{
delete fret;
m_main->DisplayError(ERR_TOOMANY, m_object);
return;
}
CObject* fret = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type);
fret->SetLock(true); // object not yet usable
if ( m_object->GetResetCap() == RESET_MOVE )

View File

@ -166,8 +166,6 @@ void CAutoEgg::Start(int param)
bool CAutoEgg::EventProcess(const Event &event)
{
CObject* alien;
CAuto::EventProcess(event);
if ( m_engine->GetPause() ) return true;
@ -180,15 +178,10 @@ bool CAutoEgg::EventProcess(const Event &event)
m_progress += event.rTime*m_speed;
if ( m_progress < 1.0f ) return true;
alien = new CObject();
if ( !alien->CreateInsect(m_object->GetPosition(0), m_object->GetAngleY(0), m_type) )
{
delete alien;
m_phase = AEP_DELAY;
m_progress = 0.0f;
m_speed = 1.0f/2.0f;
return true;
}
Math::Vector pos = m_object->GetPosition(0);
float angle = m_object->GetAngleY(0);
CObject* alien = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, m_type);
alien->SetActivity(false);
CBrain* brain = alien->GetBrain();
if(brain != nullptr)
@ -200,8 +193,8 @@ bool CAutoEgg::EventProcess(const Event &event)
Init();
}
alien = SearchAlien();
if ( alien == 0 ) return true;
CObject* alien = SearchAlien();
if ( alien == nullptr ) return true;
alien->SetActivity(false);
m_progress += event.rTime*m_speed;

View File

@ -458,20 +458,10 @@ bool CAutoEnergy::SearchVehicle()
void CAutoEnergy::CreatePower()
{
CObject* power;
Math::Vector pos;
float angle;
pos = m_object->GetPosition(0);
angle = m_object->GetAngleY(0);
power = new CObject();
if ( !power->CreateResource(pos, angle, OBJECT_POWER) )
{
delete power;
m_main->DisplayError(ERR_TOOMANY, m_object);
return;
}
Math::Vector pos = m_object->GetPosition(0);
float angle = m_object->GetAngleY(0);
float powerLevel = 1.0f;
CObject* power = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, OBJECT_POWER, powerLevel);
power->SetLock(true); // battery not yet usable
pos = power->GetPosition(0);

View File

@ -639,16 +639,9 @@ bool CAutoFactory::NearestVehicle()
bool CAutoFactory::CreateVehicle()
{
CObject* vehicle;
Math::Matrix* mat;
CPhysics* physics;
Math::Vector pos;
float angle;
char* name;
float angle = m_object->GetAngleY(0);
angle = m_object->GetAngleY(0);
mat = m_object->GetWorldMatrix(0);
Math::Vector pos;
if ( m_type == OBJECT_MOBILErt ||
m_type == OBJECT_MOBILErc ||
m_type == OBJECT_MOBILErr ||
@ -660,21 +653,16 @@ bool CAutoFactory::CreateVehicle()
{
pos = Math::Vector(4.0f, 0.0f, 0.0f);
}
Math::Matrix* mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, pos);
vehicle = new CObject();
if ( !vehicle->CreateVehicle(pos, angle, m_type, -1.0f, false, false) )
{
delete vehicle;
m_main->DisplayError(ERR_TOOMANY, m_object);
return false;
}
CObject* vehicle = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, m_type);
vehicle->UpdateMapping();
vehicle->SetLock(true); // not usable
vehicle->SetRange(30.0f);
physics = vehicle->GetPhysics();
if ( physics != 0 )
CPhysics* physics = vehicle->GetPhysics();
if ( physics != nullptr )
{
physics->SetFreeze(true); // it doesn't move
}
@ -684,7 +672,7 @@ bool CAutoFactory::CreateVehicle()
{
for ( int i=0 ; ; i++ )
{
name = m_main->GetNewScriptName(m_type, i);
char* name = m_main->GetNewScriptName(m_type, i);
if ( name == nullptr ) break;
Program* prog = brain->GetOrAddProgram(i);
vehicle->ReadProgram(prog, name);

View File

@ -180,14 +180,7 @@ bool CAutoNest::SearchFree(Math::Vector pos)
void CAutoNest::CreateFret(Math::Vector pos, float angle, ObjectType type)
{
CObject* fret;
fret = new CObject();
if ( !fret->CreateResource(pos, angle, type) )
{
delete fret;
return;
}
CObject* fret = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type);
fret->SetLock(true); // not usable
fret->SetZoom(0, 0.0f);
}

View File

@ -392,20 +392,11 @@ bool CAutoNuclear::SearchVehicle()
void CAutoNuclear::CreatePower()
{
CObject* power;
Math::Vector pos;
float angle;
Math::Vector pos = m_object->GetPosition(0);
float angle = m_object->GetAngleY(0);
pos = m_object->GetPosition(0);
angle = m_object->GetAngleY(0);
power = new CObject();
if ( !power->CreateResource(pos, angle, OBJECT_ATOMIC) )
{
delete power;
m_main->DisplayError(ERR_TOOMANY, m_object);
return;
}
float powerLevel = 1.0f;
CObject* power = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, OBJECT_ATOMIC, powerLevel);
power->SetTruck(m_object);
power->SetPosition(0, Math::Vector(22.0f, 3.0f, 0.0f));

View File

@ -65,13 +65,6 @@ CMotion::~CMotion()
{
}
// Deletes the object.
void CMotion::DeleteObject(bool bAll)
{
}
void CMotion::SetPhysics(CPhysics* physics)
{
m_physics = physics;
@ -82,14 +75,6 @@ void CMotion::SetBrain(CBrain* brain)
m_brain = brain;
}
// Creates.
bool CMotion::Create(Math::Vector pos, float angle, ObjectType type, float power)
{
return true;
}
// Management of an event.
bool CMotion::EventProcess(const Event &event)

View File

@ -54,8 +54,8 @@ public:
void SetPhysics(CPhysics* physics);
void SetBrain(CBrain* brain);
virtual void DeleteObject(bool bAll=false);
virtual bool Create(Math::Vector pos, float angle, ObjectType type, float power);
virtual void DeleteObject(bool bAll=false) = 0;
virtual void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager) = 0;
virtual bool EventProcess(const Event &event);
virtual Error SetAction(int action, float time=0.2f);
virtual int GetAction();

View File

@ -68,10 +68,9 @@ void CMotionAnt::DeleteObject(bool bAll)
// Creates a vehicle poses some rolling on the floor.
bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
int rank;
m_object->SetType(type);
@ -258,8 +257,6 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physics of the object.

View File

@ -53,7 +53,7 @@ public:
~CMotionAnt();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
protected:

View File

@ -66,10 +66,9 @@ void CMotionBee::DeleteObject(bool bAll)
// Creates a vehicle traveling any lands on the ground.
bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
int rank;
m_object->SetType(type);
@ -275,8 +274,6 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physical object.

View File

@ -47,7 +47,7 @@ public:
~CMotionBee();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
protected:

View File

@ -47,8 +47,8 @@ void CMotionDummy::DeleteObject(bool bAll)
// Creates a Dummy traveling any lands on the ground.
bool CMotionDummy::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionDummy::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager*)
{
m_object->SetType(type);
@ -81,7 +81,5 @@ bool CMotionDummy::Create(Math::Vector pos, float angle, ObjectType type,
m_physics->SetCirMotionY(MO_ADVACCEL, 2.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 2.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 2.0f);
return true;
}

View File

@ -31,6 +31,6 @@ public:
~CMotionDummy();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
};

View File

@ -96,14 +96,12 @@ Error CMotionHuman::SetAction(int action, float time)
// Creates cosmonaut on the ground.
bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
char filename[100];
int rank, option, face, glasses;
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
option = m_object->GetOption();
@ -132,7 +130,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
return true;
return;
}
// Creates the main base.
@ -327,8 +325,6 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physical object.

View File

@ -65,7 +65,7 @@ public:
~CMotionHuman();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
Error SetAction(int action, float time=0.2f);

View File

@ -67,10 +67,9 @@ void CMotionMother::DeleteObject(bool bAll)
// Creates a vehicle traveling any lands on the ground.
bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
int rank;
m_object->SetType(type);
@ -252,8 +251,6 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physics of the object.

View File

@ -33,7 +33,7 @@ public:
~CMotionMother();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
protected:

View File

@ -68,8 +68,8 @@ void CMotionSpider::DeleteObject(bool bAll)
// Creates a vehicle traveling any lands on the ground.
bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
int rank, i, j, parent;
char name[50];
@ -98,8 +98,6 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
0.0f, 0.0f, -2.0f,
};
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
// Creates the main base.
@ -191,8 +189,6 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physics of the object.

View File

@ -51,7 +51,7 @@ public:
~CMotionSpider();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
protected:

View File

@ -80,10 +80,9 @@ void CMotionToto::DeleteObject(bool bAll)
// Creates a vehicle traveling any lands on the ground.
bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
int rank;
@ -180,8 +179,6 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}

View File

@ -42,7 +42,7 @@ public:
~CMotionToto();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
Error SetAction(int action, float time=0.2f);
void SetLinkType(ObjectType type);

View File

@ -91,16 +91,14 @@ void CMotionVehicle::DeleteObject(bool bAll)
// Creates a vehicle traveling any lands on the ground.
bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
CObject* pPower;
int rank, i, j, parent;
Gfx::Color color;
char name[50];
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
// Creates the main base.
@ -954,8 +952,6 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); //to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physics of the object.

View File

@ -33,7 +33,7 @@ public:
~CMotionVehicle();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
bool GetTraceDown();

View File

@ -80,14 +80,12 @@ void CMotionWorm::DeleteObject(bool bAll)
// Creates a vehicle traveling any lands on the ground.
bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
float power)
void CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
float power, Gfx::CModelManager* modelManager)
{
int rank, i;
float px;
Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
// Creates the main base.
@ -142,8 +140,6 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetPosition(0, pos); // to display the shadows immediately
m_engine->LoadAllTextures();
return true;
}
// Creates the physics of the object.

View File

@ -33,7 +33,7 @@ public:
~CMotionWorm();
void DeleteObject(bool bAll=false);
bool Create(Math::Vector pos, float angle, ObjectType type, float power);
void Create(Math::Vector pos, float angle, ObjectType type, float power, Gfx::CModelManager* modelManager);
bool EventProcess(const Event &event);
bool SetParam(int rank, float value);

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,8 @@
#include "graphics/engine/engine.h"
#include "graphics/engine/camera.h"
#include "object/object_type.h"
#include "sound/sound.h"
@ -43,222 +45,6 @@ class CScript;
class CLevelParserLine;
struct Program;
/**
* \enum ObjectType
* \brief Type of game object
*/
enum ObjectType
{
OBJECT_NULL = 0, //! < object destroyed
OBJECT_FIX = 1, //! < stationary scenery
OBJECT_PORTICO = 2, //! < Portico
OBJECT_BASE = 3, //! < SpaceShip
OBJECT_DERRICK = 4, //! < Derrick
OBJECT_FACTORY = 5, //! < BotFactory
OBJECT_STATION = 6, //! < PowerStation
OBJECT_CONVERT = 7, //! < Converter
OBJECT_REPAIR = 8, //! < RepairStation
OBJECT_TOWER = 9, //! < DefenseTower
OBJECT_NEST = 10, //! < AlienNest
OBJECT_RESEARCH = 11, //! < ResearchCenter
OBJECT_RADAR = 12, //! < RadarStation
OBJECT_ENERGY = 13, //! < PowerPlant
OBJECT_LABO = 14, //! < AutoLab
OBJECT_NUCLEAR = 15, //! < NuclearPlant
OBJECT_START = 16, //! < StartArea
OBJECT_END = 17, //! < EndArea
OBJECT_INFO = 18, //! < ExchangePost
OBJECT_PARA = 19, //! < PowerCaptor
OBJECT_TARGET1 = 20, //! < Target1 (gate)
OBJECT_TARGET2 = 21, //! < Target2 (center)
OBJECT_SAFE = 22, //! < Vault
OBJECT_HUSTON = 23, //! < Houston
OBJECT_DESTROYER = 24, //! < Destroyer
OBJECT_FRET = 30, //! < transportable (unused)
OBJECT_STONE = 31, //! < TitaniumOre
OBJECT_URANIUM = 32, //! < UraniumOre
OBJECT_METAL = 33, //! < Titanium
OBJECT_POWER = 34, //! < PowerCell
OBJECT_ATOMIC = 35, //! < NuclearCell
OBJECT_BULLET = 36, //! < OrgaMatter
OBJECT_BBOX = 37, //! < BlackBox
OBJECT_TNT = 38, //! < TNT
OBJECT_SCRAP1 = 40, //! < Scrap1 (metal)
OBJECT_SCRAP2 = 41, //! < Scrap2 (metal)
OBJECT_SCRAP3 = 42, //! < Scrap3 (metal)
OBJECT_SCRAP4 = 43, //! < Scrap4 (plastic)
OBJECT_SCRAP5 = 44, //! < Scrap5 (plastic)
OBJECT_MARKPOWER = 50, //! < PowerSpot
OBJECT_MARKSTONE = 51, //! < TitaniumSpot
OBJECT_MARKURANIUM = 52, //! < UraniumSpot
OBJECT_MARKKEYa = 53, //! < KeyASpot
OBJECT_MARKKEYb = 54, //! < KeyBSpot
OBJECT_MARKKEYc = 55, //! < KeyCSpot
OBJECT_MARKKEYd = 56, //! < KeyDSpot
OBJECT_BOMB = 60, //! < Mine
OBJECT_WINFIRE = 61, //! < Firework
OBJECT_SHOW = 62, //! < arrow above object (Visit)
OBJECT_BAG = 63, //! < Bag
OBJECT_PLANT0 = 70, //! < Greenery0
OBJECT_PLANT1 = 71, //! < Greenery1
OBJECT_PLANT2 = 72, //! < Greenery2
OBJECT_PLANT3 = 73, //! < Greenery3
OBJECT_PLANT4 = 74, //! < Greenery4
OBJECT_PLANT5 = 75, //! < Greenery5
OBJECT_PLANT6 = 76, //! < Greenery6
OBJECT_PLANT7 = 77, //! < Greenery7
OBJECT_PLANT8 = 78, //! < Greenery8
OBJECT_PLANT9 = 79, //! < Greenery9
OBJECT_PLANT10 = 80, //! < Greenery10
OBJECT_PLANT11 = 81, //! < Greenery11
OBJECT_PLANT12 = 82, //! < Greenery12
OBJECT_PLANT13 = 83, //! < Greenery13
OBJECT_PLANT14 = 84, //! < Greenery14
OBJECT_PLANT15 = 85, //! < Greenery15
OBJECT_PLANT16 = 86, //! < Greenery16
OBJECT_PLANT17 = 87, //! < Greenery17
OBJECT_PLANT18 = 88, //! < Greenery18
OBJECT_PLANT19 = 89, //! < Greenery19
OBJECT_TREE0 = 90, //! < Tree0
OBJECT_TREE1 = 91, //! < Tree1
OBJECT_TREE2 = 92, //! < Tree2
OBJECT_TREE3 = 93, //! < Tree3
OBJECT_TREE4 = 94, //! < Tree4
OBJECT_TREE5 = 95, //! < Tree5
OBJECT_MOBILEwt = 100, //! < PracticeBot
OBJECT_MOBILEtt = 101, //! < track-trainer (unused)
OBJECT_MOBILEft = 102, //! < fly-trainer (unused)
OBJECT_MOBILEit = 103, //! < insect-trainer (unused)
OBJECT_MOBILEwa = 110, //! < WheeledGrabber
OBJECT_MOBILEta = 111, //! < TrackedGrabber
OBJECT_MOBILEfa = 112, //! < WingedGrabber
OBJECT_MOBILEia = 113, //! < LeggedGrabber
OBJECT_MOBILEwc = 120, //! < WheeledShooter
OBJECT_MOBILEtc = 121, //! < TrackedShooter
OBJECT_MOBILEfc = 122, //! < WingedShooter
OBJECT_MOBILEic = 123, //! < LeggedShooter
OBJECT_MOBILEwi = 130, //! < WheeledOrgaShooter
OBJECT_MOBILEti = 131, //! < TrackedOrgaShooter
OBJECT_MOBILEfi = 132, //! < WingedOrgaShooter
OBJECT_MOBILEii = 133, //! < LeggedOrgaShooter
OBJECT_MOBILEws = 140, //! < WheeledSniffer
OBJECT_MOBILEts = 141, //! < TrackedSniffer
OBJECT_MOBILEfs = 142, //! < WingedSniffer
OBJECT_MOBILEis = 143, //! < LeggedSniffer
OBJECT_MOBILErt = 200, //! < Thumper
OBJECT_MOBILErc = 201, //! < PhazerShooter
OBJECT_MOBILErr = 202, //! < Recycler
OBJECT_MOBILErs = 203, //! < Shielder
OBJECT_MOBILEsa = 210, //! < Subber
OBJECT_MOBILEtg = 211, //! < TargetBot
OBJECT_MOBILEdr = 212, //! < Scribbler
OBJECT_CONTROLLER = 213, //! < MissionController
OBJECT_WAYPOINT = 250, //! < WayPoint
OBJECT_FLAGb = 260, //! < BlueFlag
OBJECT_FLAGr = 261, //! < RedFlag
OBJECT_FLAGg = 262, //! < GreenFlag
OBJECT_FLAGy = 263, //! < YellowFlag
OBJECT_FLAGv = 264, //! < VioletFlag
OBJECT_KEYa = 270, //! < KeyA
OBJECT_KEYb = 271, //! < KeyB
OBJECT_KEYc = 272, //! < KeyC
OBJECT_KEYd = 273, //! < KeyD
OBJECT_HUMAN = 300, //! < Me
OBJECT_TOTO = 301, //! < Robby (toto)
OBJECT_TECH = 302, //! < Tech
OBJECT_BARRIER0 = 400, //! < Barrier0
OBJECT_BARRIER1 = 401, //! < Barrier1
OBJECT_BARRIER2 = 402, //! < Barrier2
OBJECT_BARRIER3 = 403, //! < Barrier3
OBJECT_MOTHER = 500, //! < AlienQueen
OBJECT_EGG = 501, //! < AlienEgg
OBJECT_ANT = 502, //! < AlienAnt
OBJECT_SPIDER = 503, //! < AlienSpider
OBJECT_BEE = 504, //! < AlienWasp
OBJECT_WORM = 505, //! < AlienWorm
OBJECT_RUINmobilew1 = 600, //! < WreckBotw1
OBJECT_RUINmobilew2 = 601, //! < WreckBotw2
OBJECT_RUINmobilet1 = 602, //! < WreckBott1
OBJECT_RUINmobilet2 = 603, //! < WreckBott2
OBJECT_RUINmobiler1 = 604, //! < WreckBotr1
OBJECT_RUINmobiler2 = 605, //! < WreckBotr2
OBJECT_RUINfactory = 606, //! < RuinBotFactory
OBJECT_RUINdoor = 607, //! < RuinDoor
OBJECT_RUINsupport = 608, //! < RuinSupport
OBJECT_RUINradar = 609, //! < RuinRadar
OBJECT_RUINconvert = 610, //! < RuinConvert
OBJECT_RUINbase = 611, //! < RuinBaseCamp
OBJECT_RUINhead = 612, //! < RuinHeadCamp
OBJECT_TEEN0 = 620, //! < Teen0
OBJECT_TEEN1 = 621, //! < Teen1
OBJECT_TEEN2 = 622, //! < Teen2
OBJECT_TEEN3 = 623, //! < Teen3
OBJECT_TEEN4 = 624, //! < Teen4
OBJECT_TEEN5 = 625, //! < Teen5
OBJECT_TEEN6 = 626, //! < Teen6
OBJECT_TEEN7 = 627, //! < Teen7
OBJECT_TEEN8 = 628, //! < Teen8
OBJECT_TEEN9 = 629, //! < Teen9
OBJECT_TEEN10 = 630, //! < Teen10
OBJECT_TEEN11 = 631, //! < Teen11
OBJECT_TEEN12 = 632, //! < Teen12
OBJECT_TEEN13 = 633, //! < Teen13
OBJECT_TEEN14 = 634, //! < Teen14
OBJECT_TEEN15 = 635, //! < Teen15
OBJECT_TEEN16 = 636, //! < Teen16
OBJECT_TEEN17 = 637, //! < Teen17
OBJECT_TEEN18 = 638, //! < Teen18
OBJECT_TEEN19 = 639, //! < Teen19
OBJECT_TEEN20 = 640, //! < Teen20
OBJECT_TEEN21 = 641, //! < Teen21
OBJECT_TEEN22 = 642, //! < Teen22
OBJECT_TEEN23 = 643, //! < Teen23
OBJECT_TEEN24 = 644, //! < Teen24
OBJECT_TEEN25 = 645, //! < Teen25
OBJECT_TEEN26 = 646, //! < Teen26
OBJECT_TEEN27 = 647, //! < Teen27
OBJECT_TEEN28 = 648, //! < Teen28
OBJECT_TEEN29 = 649, //! < Teen29
OBJECT_TEEN30 = 650, //! < Teen30
OBJECT_TEEN31 = 651, //! < Teen31
OBJECT_TEEN32 = 652, //! < Teen32
OBJECT_TEEN33 = 653, //! < Teen33
OBJECT_TEEN34 = 654, //! < Stone (Teen34)
OBJECT_TEEN35 = 655, //! < Teen35
OBJECT_TEEN36 = 656, //! < Teen36
OBJECT_TEEN37 = 657, //! < Teen37
OBJECT_TEEN38 = 658, //! < Teen38
OBJECT_TEEN39 = 659, //! < Teen39
OBJECT_TEEN40 = 660, //! < Teen40
OBJECT_TEEN41 = 661, //! < Teen41
OBJECT_TEEN42 = 662, //! < Teen42
OBJECT_TEEN43 = 663, //! < Teen43
OBJECT_TEEN44 = 664, //! < Teen44
OBJECT_QUARTZ0 = 700, //! < Quartz0
OBJECT_QUARTZ1 = 701, //! < Quartz1
OBJECT_QUARTZ2 = 702, //! < Quartz2
OBJECT_QUARTZ3 = 703, //! < Quartz3
OBJECT_ROOT0 = 710, //! < MegaStalk0
OBJECT_ROOT1 = 711, //! < MegaStalk1
OBJECT_ROOT2 = 712, //! < MegaStalk2
OBJECT_ROOT3 = 713, //! < MegaStalk3
OBJECT_ROOT4 = 714, //! < MegaStalk4
OBJECT_ROOT5 = 715, //! < MegaStalk5
OBJECT_MUSHROOM1 = 731, //! < Mushroom1
OBJECT_MUSHROOM2 = 732, //! < Mushroom2
OBJECT_APOLLO1 = 900, //! < ApolloLEM
OBJECT_APOLLO2 = 901, //! < ApolloJeep
OBJECT_APOLLO3 = 902, //! < ApolloFlag
OBJECT_APOLLO4 = 903, //! < ApolloModule
OBJECT_APOLLO5 = 904, //! < ApolloAntenna
OBJECT_HOME1 = 910, //! < Home
OBJECT_MAX = 1000 //! < number of values
};
// The father of all parts must always be the part number zero!
const int OBJECTMAXPART = 40;
@ -344,13 +130,6 @@ enum ResetCap
RESET_DELETE = 2,
};
enum RadarFilter
{
FILTER_NONE = 0,
FILTER_ONLYLANDING = 1,
FILTER_ONLYFLYING = 2,
};
@ -387,21 +166,6 @@ public:
void SetDrawWorld(bool bDraw);
void SetDrawFront(bool bDraw);
bool CreateVehicle(Math::Vector pos, float angle, ObjectType type, float power, bool bTrainer, bool bToy);
bool CreateInsect(Math::Vector pos, float angle, ObjectType type);
bool CreateBuilding(Math::Vector pos, float angle, float height, ObjectType type, float power=1.0f);
bool CreateResource(Math::Vector pos, float angle, ObjectType type, float power=1.0f);
bool CreateFlag(Math::Vector pos, float angle, ObjectType type);
bool CreateBarrier(Math::Vector pos, float angle, float height, ObjectType type);
bool CreatePlant(Math::Vector pos, float angle, float height, ObjectType type);
bool CreateMushroom(Math::Vector pos, float angle, float height, ObjectType type);
bool CreateTeen(Math::Vector pos, float angle, float zoom, float height, ObjectType type);
bool CreateQuartz(Math::Vector pos, float angle, float height, ObjectType type);
bool CreateRoot(Math::Vector pos, float angle, float height, ObjectType type);
bool CreateHome(Math::Vector pos, float angle, float height, ObjectType type);
bool CreateRuin(Math::Vector pos, float angle, float height, ObjectType type);
bool CreateApollo(Math::Vector pos, float angle, ObjectType type);
bool ReadProgram(Program* program, const char* filename);
bool WriteProgram(Program* program, char* filename);
@ -610,6 +374,7 @@ public:
bool StartShowLimit();
void StopShowLimit();
void SetShowLimitRadius(float radius);
bool IsProgram();
void CreateSelectParticle();
@ -618,8 +383,11 @@ public:
CScript* GetRunScript();
CBotVar* GetBotVar();
CPhysics* GetPhysics();
void SetPhysics(CPhysics* physics);
CBrain* GetBrain();
void SetBrain(CBrain* brain);
CMotion* GetMotion();
void SetMotion(CMotion* motion);
CAuto* GetAuto();
void SetAuto(CAuto* automat);
@ -645,8 +413,6 @@ public:
float GetTraceWidth();
void SetTraceWidth(float width);
std::string GetModelDirName();
static DriveType GetDriveFromObject(ObjectType type);
static ToolType GetToolFromObject(ObjectType type);
@ -654,7 +420,6 @@ protected:
bool EventFrame(const Event &event);
void VirusFrame(float rTime);
void PartiFrame(float rTime);
void CreateOtherObject(ObjectType type);
void InitPart(int part);
void UpdateTotalPart();
int SearchDescendant(int parent, int n);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,80 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file object/object_factory.h
* \brief CObjectFactory - factory for game objects
*/
#pragma once
#include "math/vector.h"
#include "object/object_type.h"
#include <memory>
namespace Gfx {
class CEngine;
class CModelManager;
class CParticle;
class CTerrain;
} // namespace Gfx
class CObject;
class CRobotMain;
class CObjectFactory
{
public:
CObjectFactory(Gfx::CEngine* engine,
Gfx::CTerrain* terrain,
Gfx::CModelManager* modelManager,
Gfx::CParticle* particle,
CRobotMain* main);
CObject* CreateObject(Math::Vector pos, float angle, ObjectType type,
float power, float zoom, float height,
bool trainer, bool toy, int option);
CObject* CreateBuilding(Math::Vector pos, float angle, float height, ObjectType type, float power=1.0f);
CObject* CreateResource(Math::Vector pos, float angle, ObjectType type, float power=1.0f);
CObject* CreateVehicle(Math::Vector pos, float angle, ObjectType type, float power, bool trainer, bool toy, int option);
CObject* CreateInsect(Math::Vector pos, float angle, ObjectType type);
CObject* CreateFlag(Math::Vector pos, float angle, ObjectType type);
CObject* CreateBarrier(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreatePlant(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreateMushroom(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreateTeen(Math::Vector pos, float angle, float zoom, float height, ObjectType type, int option);
CObject* CreateQuartz(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreateRoot(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreateHome(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreateRuin(Math::Vector pos, float angle, float height, ObjectType type);
CObject* CreateApollo(Math::Vector pos, float angle, ObjectType type);
private:
void AddObjectAuto(CObject* obj);
private:
Gfx::CEngine* m_engine;
Gfx::CTerrain* m_terrain;
Gfx::CModelManager* m_modelManager;
Gfx::CParticle* m_particle;
CRobotMain* m_main;
};

238
src/object/object_type.h Normal file
View File

@ -0,0 +1,238 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file object/object_type.h
* \brief ObjectType enum
*/
#pragma once
/**
* \enum ObjectType
* \brief Type of game object
*/
enum ObjectType
{
OBJECT_NULL = 0, //! < object destroyed
OBJECT_FIX = 1, //! < stationary scenery
OBJECT_PORTICO = 2, //! < Portico
OBJECT_BASE = 3, //! < SpaceShip
OBJECT_DERRICK = 4, //! < Derrick
OBJECT_FACTORY = 5, //! < BotFactory
OBJECT_STATION = 6, //! < PowerStation
OBJECT_CONVERT = 7, //! < Converter
OBJECT_REPAIR = 8, //! < RepairStation
OBJECT_TOWER = 9, //! < DefenseTower
OBJECT_NEST = 10, //! < AlienNest
OBJECT_RESEARCH = 11, //! < ResearchCenter
OBJECT_RADAR = 12, //! < RadarStation
OBJECT_ENERGY = 13, //! < PowerPlant
OBJECT_LABO = 14, //! < AutoLab
OBJECT_NUCLEAR = 15, //! < NuclearPlant
OBJECT_START = 16, //! < StartArea
OBJECT_END = 17, //! < EndArea
OBJECT_INFO = 18, //! < ExchangePost
OBJECT_PARA = 19, //! < PowerCaptor
OBJECT_TARGET1 = 20, //! < Target1 (gate)
OBJECT_TARGET2 = 21, //! < Target2 (center)
OBJECT_SAFE = 22, //! < Vault
OBJECT_HUSTON = 23, //! < Houston
OBJECT_DESTROYER = 24, //! < Destroyer
OBJECT_FRET = 30, //! < transportable (unused)
OBJECT_STONE = 31, //! < TitaniumOre
OBJECT_URANIUM = 32, //! < UraniumOre
OBJECT_METAL = 33, //! < Titanium
OBJECT_POWER = 34, //! < PowerCell
OBJECT_ATOMIC = 35, //! < NuclearCell
OBJECT_BULLET = 36, //! < OrgaMatter
OBJECT_BBOX = 37, //! < BlackBox
OBJECT_TNT = 38, //! < TNT
OBJECT_SCRAP1 = 40, //! < Scrap1 (metal)
OBJECT_SCRAP2 = 41, //! < Scrap2 (metal)
OBJECT_SCRAP3 = 42, //! < Scrap3 (metal)
OBJECT_SCRAP4 = 43, //! < Scrap4 (plastic)
OBJECT_SCRAP5 = 44, //! < Scrap5 (plastic)
OBJECT_MARKPOWER = 50, //! < PowerSpot
OBJECT_MARKSTONE = 51, //! < TitaniumSpot
OBJECT_MARKURANIUM = 52, //! < UraniumSpot
OBJECT_MARKKEYa = 53, //! < KeyASpot
OBJECT_MARKKEYb = 54, //! < KeyBSpot
OBJECT_MARKKEYc = 55, //! < KeyCSpot
OBJECT_MARKKEYd = 56, //! < KeyDSpot
OBJECT_BOMB = 60, //! < Mine
OBJECT_WINFIRE = 61, //! < Firework
OBJECT_SHOW = 62, //! < arrow above object (Visit)
OBJECT_BAG = 63, //! < Bag
OBJECT_PLANT0 = 70, //! < Greenery0
OBJECT_PLANT1 = 71, //! < Greenery1
OBJECT_PLANT2 = 72, //! < Greenery2
OBJECT_PLANT3 = 73, //! < Greenery3
OBJECT_PLANT4 = 74, //! < Greenery4
OBJECT_PLANT5 = 75, //! < Greenery5
OBJECT_PLANT6 = 76, //! < Greenery6
OBJECT_PLANT7 = 77, //! < Greenery7
OBJECT_PLANT8 = 78, //! < Greenery8
OBJECT_PLANT9 = 79, //! < Greenery9
OBJECT_PLANT10 = 80, //! < Greenery10
OBJECT_PLANT11 = 81, //! < Greenery11
OBJECT_PLANT12 = 82, //! < Greenery12
OBJECT_PLANT13 = 83, //! < Greenery13
OBJECT_PLANT14 = 84, //! < Greenery14
OBJECT_PLANT15 = 85, //! < Greenery15
OBJECT_PLANT16 = 86, //! < Greenery16
OBJECT_PLANT17 = 87, //! < Greenery17
OBJECT_PLANT18 = 88, //! < Greenery18
OBJECT_PLANT19 = 89, //! < Greenery19
OBJECT_TREE0 = 90, //! < Tree0
OBJECT_TREE1 = 91, //! < Tree1
OBJECT_TREE2 = 92, //! < Tree2
OBJECT_TREE3 = 93, //! < Tree3
OBJECT_TREE4 = 94, //! < Tree4
OBJECT_TREE5 = 95, //! < Tree5
OBJECT_MOBILEwt = 100, //! < PracticeBot
OBJECT_MOBILEtt = 101, //! < track-trainer (unused)
OBJECT_MOBILEft = 102, //! < fly-trainer (unused)
OBJECT_MOBILEit = 103, //! < insect-trainer (unused)
OBJECT_MOBILEwa = 110, //! < WheeledGrabber
OBJECT_MOBILEta = 111, //! < TrackedGrabber
OBJECT_MOBILEfa = 112, //! < WingedGrabber
OBJECT_MOBILEia = 113, //! < LeggedGrabber
OBJECT_MOBILEwc = 120, //! < WheeledShooter
OBJECT_MOBILEtc = 121, //! < TrackedShooter
OBJECT_MOBILEfc = 122, //! < WingedShooter
OBJECT_MOBILEic = 123, //! < LeggedShooter
OBJECT_MOBILEwi = 130, //! < WheeledOrgaShooter
OBJECT_MOBILEti = 131, //! < TrackedOrgaShooter
OBJECT_MOBILEfi = 132, //! < WingedOrgaShooter
OBJECT_MOBILEii = 133, //! < LeggedOrgaShooter
OBJECT_MOBILEws = 140, //! < WheeledSniffer
OBJECT_MOBILEts = 141, //! < TrackedSniffer
OBJECT_MOBILEfs = 142, //! < WingedSniffer
OBJECT_MOBILEis = 143, //! < LeggedSniffer
OBJECT_MOBILErt = 200, //! < Thumper
OBJECT_MOBILErc = 201, //! < PhazerShooter
OBJECT_MOBILErr = 202, //! < Recycler
OBJECT_MOBILErs = 203, //! < Shielder
OBJECT_MOBILEsa = 210, //! < Subber
OBJECT_MOBILEtg = 211, //! < TargetBot
OBJECT_MOBILEdr = 212, //! < Scribbler
OBJECT_CONTROLLER = 213, //! < MissionController
OBJECT_WAYPOINT = 250, //! < WayPoint
OBJECT_FLAGb = 260, //! < BlueFlag
OBJECT_FLAGr = 261, //! < RedFlag
OBJECT_FLAGg = 262, //! < GreenFlag
OBJECT_FLAGy = 263, //! < YellowFlag
OBJECT_FLAGv = 264, //! < VioletFlag
OBJECT_KEYa = 270, //! < KeyA
OBJECT_KEYb = 271, //! < KeyB
OBJECT_KEYc = 272, //! < KeyC
OBJECT_KEYd = 273, //! < KeyD
OBJECT_HUMAN = 300, //! < Me
OBJECT_TOTO = 301, //! < Robby (toto)
OBJECT_TECH = 302, //! < Tech
OBJECT_BARRIER0 = 400, //! < Barrier0
OBJECT_BARRIER1 = 401, //! < Barrier1
OBJECT_BARRIER2 = 402, //! < Barrier2
OBJECT_BARRIER3 = 403, //! < Barrier3
OBJECT_MOTHER = 500, //! < AlienQueen
OBJECT_EGG = 501, //! < AlienEgg
OBJECT_ANT = 502, //! < AlienAnt
OBJECT_SPIDER = 503, //! < AlienSpider
OBJECT_BEE = 504, //! < AlienWasp
OBJECT_WORM = 505, //! < AlienWorm
OBJECT_RUINmobilew1 = 600, //! < WreckBotw1
OBJECT_RUINmobilew2 = 601, //! < WreckBotw2
OBJECT_RUINmobilet1 = 602, //! < WreckBott1
OBJECT_RUINmobilet2 = 603, //! < WreckBott2
OBJECT_RUINmobiler1 = 604, //! < WreckBotr1
OBJECT_RUINmobiler2 = 605, //! < WreckBotr2
OBJECT_RUINfactory = 606, //! < RuinBotFactory
OBJECT_RUINdoor = 607, //! < RuinDoor
OBJECT_RUINsupport = 608, //! < RuinSupport
OBJECT_RUINradar = 609, //! < RuinRadar
OBJECT_RUINconvert = 610, //! < RuinConvert
OBJECT_RUINbase = 611, //! < RuinBaseCamp
OBJECT_RUINhead = 612, //! < RuinHeadCamp
OBJECT_TEEN0 = 620, //! < Teen0
OBJECT_TEEN1 = 621, //! < Teen1
OBJECT_TEEN2 = 622, //! < Teen2
OBJECT_TEEN3 = 623, //! < Teen3
OBJECT_TEEN4 = 624, //! < Teen4
OBJECT_TEEN5 = 625, //! < Teen5
OBJECT_TEEN6 = 626, //! < Teen6
OBJECT_TEEN7 = 627, //! < Teen7
OBJECT_TEEN8 = 628, //! < Teen8
OBJECT_TEEN9 = 629, //! < Teen9
OBJECT_TEEN10 = 630, //! < Teen10
OBJECT_TEEN11 = 631, //! < Teen11
OBJECT_TEEN12 = 632, //! < Teen12
OBJECT_TEEN13 = 633, //! < Teen13
OBJECT_TEEN14 = 634, //! < Teen14
OBJECT_TEEN15 = 635, //! < Teen15
OBJECT_TEEN16 = 636, //! < Teen16
OBJECT_TEEN17 = 637, //! < Teen17
OBJECT_TEEN18 = 638, //! < Teen18
OBJECT_TEEN19 = 639, //! < Teen19
OBJECT_TEEN20 = 640, //! < Teen20
OBJECT_TEEN21 = 641, //! < Teen21
OBJECT_TEEN22 = 642, //! < Teen22
OBJECT_TEEN23 = 643, //! < Teen23
OBJECT_TEEN24 = 644, //! < Teen24
OBJECT_TEEN25 = 645, //! < Teen25
OBJECT_TEEN26 = 646, //! < Teen26
OBJECT_TEEN27 = 647, //! < Teen27
OBJECT_TEEN28 = 648, //! < Teen28
OBJECT_TEEN29 = 649, //! < Teen29
OBJECT_TEEN30 = 650, //! < Teen30
OBJECT_TEEN31 = 651, //! < Teen31
OBJECT_TEEN32 = 652, //! < Teen32
OBJECT_TEEN33 = 653, //! < Teen33
OBJECT_TEEN34 = 654, //! < Stone (Teen34)
OBJECT_TEEN35 = 655, //! < Teen35
OBJECT_TEEN36 = 656, //! < Teen36
OBJECT_TEEN37 = 657, //! < Teen37
OBJECT_TEEN38 = 658, //! < Teen38
OBJECT_TEEN39 = 659, //! < Teen39
OBJECT_TEEN40 = 660, //! < Teen40
OBJECT_TEEN41 = 661, //! < Teen41
OBJECT_TEEN42 = 662, //! < Teen42
OBJECT_TEEN43 = 663, //! < Teen43
OBJECT_TEEN44 = 664, //! < Teen44
OBJECT_QUARTZ0 = 700, //! < Quartz0
OBJECT_QUARTZ1 = 701, //! < Quartz1
OBJECT_QUARTZ2 = 702, //! < Quartz2
OBJECT_QUARTZ3 = 703, //! < Quartz3
OBJECT_ROOT0 = 710, //! < MegaStalk0
OBJECT_ROOT1 = 711, //! < MegaStalk1
OBJECT_ROOT2 = 712, //! < MegaStalk2
OBJECT_ROOT3 = 713, //! < MegaStalk3
OBJECT_ROOT4 = 714, //! < MegaStalk4
OBJECT_ROOT5 = 715, //! < MegaStalk5
OBJECT_MUSHROOM1 = 731, //! < Mushroom1
OBJECT_MUSHROOM2 = 732, //! < Mushroom2
OBJECT_APOLLO1 = 900, //! < ApolloLEM
OBJECT_APOLLO2 = 901, //! < ApolloJeep
OBJECT_APOLLO3 = 902, //! < ApolloFlag
OBJECT_APOLLO4 = 903, //! < ApolloModule
OBJECT_APOLLO5 = 904, //! < ApolloAntenna
OBJECT_HOME1 = 910, //! < Home
OBJECT_MAX = 1000 //! < number of values
};

View File

@ -23,6 +23,7 @@
#include "math/all.h"
#include "object/object.h"
#include "object/object_factory.h"
#include "object/auto/auto.h"
#include "physics/physics.h"
@ -33,7 +34,12 @@
template<> CObjectManager* CSingleton<CObjectManager>::m_instance = nullptr;
CObjectManager::CObjectManager()
CObjectManager::CObjectManager(Gfx::CEngine* engine,
Gfx::CTerrain* terrain,
Gfx::CModelManager* modelManager,
Gfx::CParticle* particle,
CRobotMain* main)
: m_objectFactory(new CObjectFactory(engine, terrain, modelManager, particle, main))
{
}
@ -92,295 +98,7 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType
float power, float zoom, float height,
bool trainer, bool toy, int option)
{
CObject* object = nullptr;
if ( type == OBJECT_NULL ) return nullptr;
if ( type == OBJECT_HUMAN ||
type == OBJECT_TECH )
{
trainer = false; // necessarily
}
if ( type == OBJECT_PORTICO ||
type == OBJECT_BASE ||
type == OBJECT_DERRICK ||
type == OBJECT_FACTORY ||
type == OBJECT_STATION ||
type == OBJECT_CONVERT ||
type == OBJECT_REPAIR ||
type == OBJECT_DESTROYER||
type == OBJECT_TOWER ||
type == OBJECT_NEST ||
type == OBJECT_RESEARCH ||
type == OBJECT_RADAR ||
type == OBJECT_INFO ||
type == OBJECT_ENERGY ||
type == OBJECT_LABO ||
type == OBJECT_NUCLEAR ||
type == OBJECT_PARA ||
type == OBJECT_SAFE ||
type == OBJECT_HUSTON ||
type == OBJECT_TARGET1 ||
type == OBJECT_TARGET2 ||
type == OBJECT_START ||
type == OBJECT_END )
{
object = new CObject();
object->CreateBuilding(pos, angle, height, type, power);
CAuto* automat = object->GetAuto();
if (automat != nullptr)
{
automat->Init();
}
}
else
if ( type == OBJECT_FRET ||
type == OBJECT_STONE ||
type == OBJECT_URANIUM ||
type == OBJECT_METAL ||
type == OBJECT_POWER ||
type == OBJECT_ATOMIC ||
type == OBJECT_BULLET ||
type == OBJECT_BBOX ||
type == OBJECT_KEYa ||
type == OBJECT_KEYb ||
type == OBJECT_KEYc ||
type == OBJECT_KEYd ||
type == OBJECT_TNT ||
type == OBJECT_SCRAP1 ||
type == OBJECT_SCRAP2 ||
type == OBJECT_SCRAP3 ||
type == OBJECT_SCRAP4 ||
type == OBJECT_SCRAP5 ||
type == OBJECT_BOMB ||
type == OBJECT_WAYPOINT ||
type == OBJECT_SHOW ||
type == OBJECT_WINFIRE ||
type == OBJECT_BAG ||
type == OBJECT_MARKPOWER ||
type == OBJECT_MARKSTONE ||
type == OBJECT_MARKURANIUM ||
type == OBJECT_MARKKEYa ||
type == OBJECT_MARKKEYb ||
type == OBJECT_MARKKEYc ||
type == OBJECT_MARKKEYd ||
type == OBJECT_EGG )
{
object = new CObject();
object->CreateResource(pos, angle, type, power);
}
else
if ( type == OBJECT_FLAGb ||
type == OBJECT_FLAGr ||
type == OBJECT_FLAGg ||
type == OBJECT_FLAGy ||
type == OBJECT_FLAGv )
{
object = new CObject();
object->CreateFlag(pos, angle, type);
}
else
if ( type == OBJECT_BARRIER0 ||
type == OBJECT_BARRIER1 ||
type == OBJECT_BARRIER2 ||
type == OBJECT_BARRIER3 )
{
object = new CObject();
object->CreateBarrier(pos, angle, height, type);
}
else
if ( type == OBJECT_PLANT0 ||
type == OBJECT_PLANT1 ||
type == OBJECT_PLANT2 ||
type == OBJECT_PLANT3 ||
type == OBJECT_PLANT4 ||
type == OBJECT_PLANT5 ||
type == OBJECT_PLANT6 ||
type == OBJECT_PLANT7 ||
type == OBJECT_PLANT8 ||
type == OBJECT_PLANT9 ||
type == OBJECT_PLANT10 ||
type == OBJECT_PLANT11 ||
type == OBJECT_PLANT12 ||
type == OBJECT_PLANT13 ||
type == OBJECT_PLANT14 ||
type == OBJECT_PLANT15 ||
type == OBJECT_PLANT16 ||
type == OBJECT_PLANT17 ||
type == OBJECT_PLANT18 ||
type == OBJECT_PLANT19 ||
type == OBJECT_TREE0 ||
type == OBJECT_TREE1 ||
type == OBJECT_TREE2 ||
type == OBJECT_TREE3 ||
type == OBJECT_TREE4 ||
type == OBJECT_TREE5 )
{
object = new CObject();
object->CreatePlant(pos, angle, height, type);
}
else
if ( type == OBJECT_MUSHROOM1 ||
type == OBJECT_MUSHROOM2 )
{
object = new CObject();
object->CreateMushroom(pos, angle, height, type);
}
else
if ( type == OBJECT_TEEN0 ||
type == OBJECT_TEEN1 ||
type == OBJECT_TEEN2 ||
type == OBJECT_TEEN3 ||
type == OBJECT_TEEN4 ||
type == OBJECT_TEEN5 ||
type == OBJECT_TEEN6 ||
type == OBJECT_TEEN7 ||
type == OBJECT_TEEN8 ||
type == OBJECT_TEEN9 ||
type == OBJECT_TEEN10 ||
type == OBJECT_TEEN11 ||
type == OBJECT_TEEN12 ||
type == OBJECT_TEEN13 ||
type == OBJECT_TEEN14 ||
type == OBJECT_TEEN15 ||
type == OBJECT_TEEN16 ||
type == OBJECT_TEEN17 ||
type == OBJECT_TEEN18 ||
type == OBJECT_TEEN19 ||
type == OBJECT_TEEN20 ||
type == OBJECT_TEEN21 ||
type == OBJECT_TEEN22 ||
type == OBJECT_TEEN23 ||
type == OBJECT_TEEN24 ||
type == OBJECT_TEEN25 ||
type == OBJECT_TEEN26 ||
type == OBJECT_TEEN27 ||
type == OBJECT_TEEN28 ||
type == OBJECT_TEEN29 ||
type == OBJECT_TEEN30 ||
type == OBJECT_TEEN31 ||
type == OBJECT_TEEN32 ||
type == OBJECT_TEEN33 ||
type == OBJECT_TEEN34 ||
type == OBJECT_TEEN35 ||
type == OBJECT_TEEN36 ||
type == OBJECT_TEEN37 ||
type == OBJECT_TEEN38 ||
type == OBJECT_TEEN39 ||
type == OBJECT_TEEN40 ||
type == OBJECT_TEEN41 ||
type == OBJECT_TEEN42 ||
type == OBJECT_TEEN43 ||
type == OBJECT_TEEN44 )
{
object = new CObject();
object->SetOption(option);
object->CreateTeen(pos, angle, zoom, height, type);
}
else
if ( type == OBJECT_QUARTZ0 ||
type == OBJECT_QUARTZ1 ||
type == OBJECT_QUARTZ2 ||
type == OBJECT_QUARTZ3 )
{
object = new CObject();
object->CreateQuartz(pos, angle, height, type);
}
else
if ( type == OBJECT_ROOT0 ||
type == OBJECT_ROOT1 ||
type == OBJECT_ROOT2 ||
type == OBJECT_ROOT3 ||
type == OBJECT_ROOT4 ||
type == OBJECT_ROOT5 )
{
object = new CObject();
object->CreateRoot(pos, angle, height, type);
}
else
if ( type == OBJECT_HOME1 )
{
object = new CObject();
object->CreateHome(pos, angle, height, type);
}
else
if ( type == OBJECT_RUINmobilew1 ||
type == OBJECT_RUINmobilew2 ||
type == OBJECT_RUINmobilet1 ||
type == OBJECT_RUINmobilet2 ||
type == OBJECT_RUINmobiler1 ||
type == OBJECT_RUINmobiler2 ||
type == OBJECT_RUINfactory ||
type == OBJECT_RUINdoor ||
type == OBJECT_RUINsupport ||
type == OBJECT_RUINradar ||
type == OBJECT_RUINconvert ||
type == OBJECT_RUINbase ||
type == OBJECT_RUINhead )
{
object = new CObject();
object->CreateRuin(pos, angle, height, type);
}
else
if ( type == OBJECT_APOLLO1 ||
type == OBJECT_APOLLO3 ||
type == OBJECT_APOLLO4 ||
type == OBJECT_APOLLO5 )
{
object = new CObject();
object->CreateApollo(pos, angle, type);
}
else
if ( type == OBJECT_MOTHER ||
type == OBJECT_ANT ||
type == OBJECT_SPIDER ||
type == OBJECT_BEE ||
type == OBJECT_WORM )
{
object = new CObject();
object->CreateInsect(pos, angle, type); // no eggs
}
else
if ( type == OBJECT_HUMAN ||
type == OBJECT_TECH ||
type == OBJECT_TOTO ||
type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEia ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEic ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEii ||
type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEts ||
type == OBJECT_MOBILEws ||
type == OBJECT_MOBILEis ||
type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs ||
type == OBJECT_MOBILEsa ||
type == OBJECT_MOBILEtg ||
type == OBJECT_MOBILEft ||
type == OBJECT_MOBILEtt ||
type == OBJECT_MOBILEwt ||
type == OBJECT_MOBILEit ||
type == OBJECT_MOBILEdr ||
type == OBJECT_APOLLO2 )
{
object = new CObject();
object->SetOption(option);
object->CreateVehicle(pos, angle, type, power, trainer, toy);
}
return object;
return m_objectFactory->CreateObject(pos, angle, type, power, zoom, height, trainer, toy, option);
}
bool CObjectManager::DestroyObject(int id)

View File

@ -24,11 +24,35 @@
#pragma once
#include "object/object.h"
#include "common/singleton.h"
#include "math/const.h"
#include "math/vector.h"
#include "object/object_type.h"
#include <map>
#include <vector>
#include <memory>
namespace Gfx {
class CEngine;
class CModelManager;
class CParticle;
class CTerrain;
} // namespace Gfx
class CObject;
class CRobotMain;
class CObjectFactory;
enum RadarFilter
{
FILTER_NONE = 0,
FILTER_ONLYLANDING = 1,
FILTER_ONLYFLYING = 2,
};
/**
* \class ObjectManager
@ -37,7 +61,11 @@
class CObjectManager : public CSingleton<CObjectManager>
{
public:
CObjectManager();
CObjectManager(Gfx::CEngine* engine,
Gfx::CTerrain* terrain,
Gfx::CModelManager* modelManager,
Gfx::CParticle* particle,
CRobotMain* main);
virtual ~CObjectManager();
//! Registers new object
@ -52,8 +80,7 @@ public:
const std::map<unsigned int, CObject*>& GetAllObjects();
//! Removes all objects
void Flush();
//! Creates an object
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);
//! Destroys an object
@ -75,5 +102,6 @@ public:
protected:
std::map<unsigned int, CObject*> m_table;
std::unique_ptr<CObjectFactory> m_objectFactory;
};

View File

@ -128,10 +128,13 @@ CRobotMain::CRobotMain(CController* controller)
m_ctrl = controller;
m_app = nullptr;
m_objMan = nullptr;
m_eventQueue = nullptr;
m_sound = nullptr;
m_engine = nullptr;
m_modelManager = nullptr;
m_lightMan = nullptr;
m_particle = nullptr;
m_water = nullptr;
@ -153,7 +156,7 @@ CRobotMain::CRobotMain(CController* controller)
m_time = 0.0f;
m_gameTime = 0.0f;
m_missionTimerEnabled = false;
m_missionTimerStarted = false;
m_missionTimer = 0.0f;
@ -245,6 +248,7 @@ void CRobotMain::Create(bool loadProfile)
m_sound = m_app->GetSound();
m_engine = Gfx::CEngine::GetInstancePointer();
m_modelManager = m_engine->GetModelManager();
m_lightMan = m_engine->GetLightManager();
m_particle = m_engine->GetParticle();
m_water = m_engine->GetWater();
@ -263,7 +267,13 @@ void CRobotMain::Create(bool loadProfile)
m_short = new Ui::CMainShort();
m_map = new Ui::CMainMap();
m_displayInfo = nullptr;
m_objMan = new CObjectManager(m_engine,
m_terrain,
m_modelManager,
m_particle,
this);
m_engine->SetTerrain(m_terrain);
m_engine->SetMovieLock(m_movieLock);
@ -341,7 +351,10 @@ CRobotMain::~CRobotMain()
delete m_map;
m_map = nullptr;
delete m_objMan;
m_objMan = nullptr;
m_dialog = nullptr;
m_input = nullptr;
m_pause = nullptr;
@ -457,7 +470,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_engine->SetRankView(0);
m_terrain->FlushRelief();
m_engine->DeleteAllObjects();
Gfx::CModelManager::GetInstancePointer()->DeleteAllModelCopies();
m_modelManager->DeleteAllModelCopies();
m_engine->SetWaterAddColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f));
m_engine->SetBackground("");
m_engine->SetBackForce(false);
@ -489,8 +502,8 @@ void CRobotMain::ChangePhase(Phase phase)
iMan->Flush(CLASS_PHYSICS);
iMan->Flush(CLASS_BRAIN);
iMan->Flush(CLASS_PYRO);
CObjectManager::GetInstancePointer()->Flush();
m_objMan->Flush();
Math::Point dim, pos;
@ -1703,7 +1716,7 @@ void CRobotMain::StartDisplayVisit(EventType event)
}
Math::Vector goal = m_displayText->GetVisitGoal(event);
m_visitArrow = CObjectManager::GetInstancePointer()->CreateObject(goal, 0.0f, OBJECT_SHOW, -1.0f, 1.0f, 10.0f);
m_visitArrow = m_objMan->CreateObject(goal, 0.0f, OBJECT_SHOW, -1.0f, 1.0f, 10.0f);
m_visitPos = m_visitArrow->GetPosition(0);
m_visitPosArrow = m_visitPos;
@ -1799,7 +1812,7 @@ CObject* CRobotMain::GetSelectObject()
CObject* CRobotMain::DeselectAll()
{
CObject* prev = nullptr;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -1931,9 +1944,9 @@ void CRobotMain::DeleteAllObjects()
for (int i = 0; i < MAXSHOWLIMIT; i++)
FlushShowLimit(i);
while(CObjectManager::GetInstancePointer()->GetAllObjects().size() > 0)
while(m_objMan->GetAllObjects().size() > 0)
{
CObject* obj = CObjectManager::GetInstancePointer()->GetAllObjects().begin()->second;
CObject* obj = m_objMan->GetAllObjects().begin()->second;
obj->DeleteObject(true); // destroys rapidly
delete obj;
@ -1949,13 +1962,13 @@ void CRobotMain::SelectHuman()
//! Returns the object human
CObject* CRobotMain::SearchHuman()
{
return CObjectManager::GetInstancePointer()->FindNearest(nullptr, OBJECT_HUMAN);
return m_objMan->FindNearest(nullptr, OBJECT_HUMAN);
}
//! Returns the object toto
CObject* CRobotMain::SearchToto()
{
return CObjectManager::GetInstancePointer()->FindNearest(nullptr, OBJECT_TOTO);
return m_objMan->FindNearest(nullptr, OBJECT_TOTO);
}
//! Returns the nearest selectable object from a given position
@ -1963,7 +1976,7 @@ CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu)
{
float min = 100000.0f;
CObject* best = 0;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -1987,7 +2000,7 @@ CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu)
//! Returns the selected object
CObject* CRobotMain::GetSelect()
{
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -1999,7 +2012,7 @@ CObject* CRobotMain::GetSelect()
CObject* CRobotMain::SearchObject(ObjectType type)
{
return CObjectManager::GetInstancePointer()->FindNearest(nullptr, type);
return m_objMan->FindNearest(nullptr, type);
}
//! Detects the object aimed by the mouse
@ -2007,7 +2020,7 @@ CObject* CRobotMain::DetectObject(Math::Point pos)
{
int objRank = m_engine->DetectObject(pos);
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -2247,7 +2260,7 @@ void CRobotMain::HiliteClear()
int rank = -1;
m_engine->SetHighlightRank(&rank); // nothing more selected
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -2407,7 +2420,7 @@ void CRobotMain::HelpObject()
//! Change the mode of the camera
void CRobotMain::ChangeCamera()
{
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -2552,7 +2565,7 @@ void CRobotMain::RemoteCamera(float pan, float zoom, float rTime)
//! Cancels the current movie
void CRobotMain::AbortMovie()
{
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -2812,7 +2825,7 @@ bool CRobotMain::EventObject(const Event &event)
m_resetCreate = false;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -2843,7 +2856,7 @@ void CRobotMain::ScenePerso()
DeleteAllObjects(); // removes all the current 3D Scene
m_terrain->FlushRelief();
m_engine->DeleteAllObjects();
Gfx::CModelManager::GetInstancePointer()->DeleteAllModelCopies();
m_modelManager->DeleteAllModelCopies();
m_terrain->FlushBuildingLevel();
m_terrain->FlushFlyingLimit();
m_lightMan->FlushLights();
@ -2854,7 +2867,7 @@ void CRobotMain::ScenePerso()
iMan->Flush(CLASS_BRAIN);
iMan->Flush(CLASS_PYRO);
CObjectManager::GetInstancePointer()->Flush();
m_objMan->Flush();
ChangeColor();
@ -3468,7 +3481,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (line->GetCommand() == "MissionController" && read[0] == 0)
{
m_controller = CObjectManager::GetInstancePointer()->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f);
m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f);
m_controller->SetMagnifyDamage(100.0f);
m_controller->SetIgnoreBuildCheck(true);
CBrain* brain = m_controller->GetBrain();
@ -3523,7 +3536,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
float dirAngle = line->GetParam("dir")->AsFloat(0.0f)*Math::PI;
bool trainer;
CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(
CObject* obj = m_objMan->CreateObject(
pos, dirAngle,
type,
line->GetParam("power")->AsFloat(1.0f),
@ -4211,7 +4224,7 @@ bool CRobotMain::TestGadgetQuantity(int rank)
float CRobotMain::SearchNearestObject(Math::Vector center, CObject *exclu)
{
float min = 100000.0f;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -4361,7 +4374,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* truck)
// Calculates the maximum radius possible depending on other items.
float oMax = 30.0f; // radius to build the biggest building
float tMax;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -4695,7 +4708,7 @@ void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank,
//! Saves all programs of all the robots
void CRobotMain::SaveAllScript()
{
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -4848,7 +4861,7 @@ bool CRobotMain::IsBusy()
{
if (CScriptFunctions::m_CompteurFileOpen > 0) return true;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -4979,7 +4992,7 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
}
int objRank = 0;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -5030,7 +5043,7 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
fWrite(&version, sizeof(long), 1, file); // version of CBOT
objRank = 0;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -5063,7 +5076,7 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename,
bool toy = line->GetParam("toy")->AsBool(false);
int option = line->GetParam("option")->AsInt(0);
CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option);
CObject* obj = m_objMan->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option);
obj->SetDefRank(objRank);
obj->SetPosition(0, pos);
obj->SetAngle(0, dir);
@ -5433,7 +5446,7 @@ void CRobotMain::ResetCreate()
iMan->Flush(CLASS_BRAIN);
iMan->Flush(CLASS_PYRO);
CObjectManager::GetInstancePointer()->Flush();
m_objMan->Flush();
m_camera->SetType(Gfx::CAM_TYPE_DIALOG);
@ -5442,7 +5455,7 @@ void CRobotMain::ResetCreate()
if (!GetNiceReset()) return;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -5474,7 +5487,7 @@ void CRobotMain::UpdateAudio(bool frame)
Math::Vector oPos;
int nb = 0;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -5599,7 +5612,7 @@ Error CRobotMain::CheckEndMission(bool frame)
Math::Vector oPos;
int nb = 0;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;
@ -5879,7 +5892,7 @@ bool CRobotMain::GetRadar()
if (m_cheatRadar)
return true;
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
for(auto it : m_objMan->GetAllObjects())
{
CObject* obj = it.second;

View File

@ -79,6 +79,7 @@ class CEventQueue;
class CSoundInterface;
class CLevelParserLine;
class CInput;
class CObjectManager;
namespace Gfx {
class CEngine;
@ -395,6 +396,7 @@ protected:
protected:
CController* m_ctrl;
CApplication* m_app;
CObjectManager* m_objMan;
CEventQueue* m_eventQueue;
CMainMovie* m_movie;
Gfx::CEngine* m_engine;
@ -403,6 +405,7 @@ protected:
Gfx::CCloud* m_cloud;
Gfx::CLightning* m_lightning;
Gfx::CPlanet* m_planet;
Gfx::CModelManager* m_modelManager;
Gfx::CLightManager* m_lightMan;
Gfx::CTerrain* m_terrain;
Gfx::CCamera* m_camera;

View File

@ -78,13 +78,8 @@ CTaskBuild::~CTaskBuild()
bool CTaskBuild::CreateBuilding(Math::Vector pos, float angle)
{
m_building = new CObject();
if ( !m_building->CreateBuilding(pos, angle, 0.0f, m_type, 0.0f) )
{
delete m_building;
m_building = 0;
return false;
}
float power = 0.0f;
m_building = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, m_type, power);
m_building->UpdateMapping();
m_building->SetLock(true); // not yet usable

View File

@ -185,15 +185,7 @@ int CTaskFlag::CountObject(ObjectType type)
Error CTaskFlag::CreateFlag(int rank)
{
CObject* pObj;
CObject* pNew;
Gfx::CPyro* pyro;
Math::Matrix* mat;
Math::Vector pos;
float dist;
int i;
ObjectType table[5] =
ObjectType table[5] =
{
OBJECT_FLAGb,
OBJECT_FLAGr,
@ -202,35 +194,31 @@ Error CTaskFlag::CreateFlag(int rank)
OBJECT_FLAGv,
};
mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, Math::Vector(4.0f, 0.0f, 0.0f));
Math::Matrix* mat = m_object->GetWorldMatrix(0);
Math::Vector pos = Transform(*mat, Math::Vector(4.0f, 0.0f, 0.0f));
pObj = SearchNearest(pos, OBJECT_NULL);
if ( pObj != 0 )
CObject* pObj = SearchNearest(pos, OBJECT_NULL);
if ( pObj != nullptr )
{
dist = Math::Distance(pos, pObj->GetPosition(0));
float dist = Math::Distance(pos, pObj->GetPosition(0));
if ( dist < 10.0f )
{
return ERR_FLAG_PROXY;
}
}
i = rank;
if ( CountObject(table[i]) >= 5 )
ObjectType type = table[rank];
if ( CountObject(type) >= 5 )
{
return ERR_FLAG_CREATE;
}
pNew = new CObject();
if ( !pNew->CreateFlag(pos, 0.0f, table[i]) )
{
delete pNew;
return ERR_TOOMANY;
}
float angle = 0.0f;
CObject* pNew = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type);
//pNew->SetZoom(0, 0.0f);
m_sound->Play(SOUND_WAYPOINT, pos);
pyro = new Gfx::CPyro();
Gfx::CPyro* pyro = new Gfx::CPyro();
pyro->Create(Gfx::PT_FLCREATE, pNew);
return ERR_OK;

View File

@ -302,16 +302,7 @@ Error CTaskRecover::IsEnded()
if ( m_phase == TRP_DOWN )
{
m_metal = new CObject();
if ( !m_metal->CreateResource(m_recoverPos, 0.0f, OBJECT_METAL) )
{
delete m_metal;
m_metal = 0;
Abort();
m_bError = true;
m_main->DisplayError(ERR_TOOMANY, m_object);
return ERR_STOP;
}
m_metal = CObjectManager::GetInstancePointer()->CreateObject(m_recoverPos, 0.0f, OBJECT_METAL);
m_metal->SetLock(true); // metal not yet usable
m_metal->SetZoom(0, 0.0f);

View File

@ -25,11 +25,11 @@
#include "math/geometry.h"
#include "physics/physics.h"
#include "object/objman.h"
#include "object/robotmain.h"
#include "physics/physics.h"
// Object's constructor.
@ -235,21 +235,15 @@ bool CTaskSearch::Abort()
bool CTaskSearch::CreateMark()
{
CObject* fret;
ObjectType type;
Math::Matrix* mat;
Math::Vector pos;
Gfx::TerrainRes res;
Error info;
mat = m_object->GetWorldMatrix(0);
pos = Math::Vector(7.5f, 0.0f, 0.0f);
Math::Matrix* mat = m_object->GetWorldMatrix(0);
Math::Vector pos = Math::Vector(7.5f, 0.0f, 0.0f);
pos = Math::Transform(*mat, pos); // sensor position
res = m_terrain->GetResource(pos);
Gfx::TerrainRes res = m_terrain->GetResource(pos);
if ( res == Gfx::TR_NULL ) return false;
type = OBJECT_NULL;
ObjectType type = OBJECT_NULL;
Error info = ERR_OK;
if ( res == Gfx::TR_STONE )
{
type = OBJECT_MARKSTONE;
@ -289,13 +283,7 @@ bool CTaskSearch::CreateMark()
//? DeleteMark(type);
fret = new CObject();
if ( !fret->CreateResource(pos, 0.0f, type) )
{
delete fret;
m_main->DisplayError(ERR_TOOMANY, m_object);
return false;
}
CObjectManager::GetInstancePointer()->CreateObject(pos, 0.0f, type);
m_main->DisplayError(info, pos, 5.0f, 50.0f); // displays the message

View File

@ -1675,48 +1675,46 @@ CBotTypResult CScriptFunctions::cProduce(CBotVar* &var, void* user)
bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
CObject* object;
CObject* me = (static_cast<CObject *>(user));
CBotString cbs;
const char* name;
Math::Vector pos;
float angle;
ObjectType type;
float power;
const char* name = "";
Math::Vector pos;
float angle = 0.0f;
ObjectType type = OBJECT_NULL;
float power = 0.0f;
if ( var->GetType() <= CBotTypDouble )
{
type = static_cast<ObjectType>(var->GetValInt());
var = var->GetNext();
pos = me->GetPosition(0);
Math::Vector rotation = me->GetAngle(0) + me->GetInclinaison();
angle = rotation.y;
if( var != 0 )
if( var != nullptr )
power = var->GetValFloat();
else
power = -1.0f;
name = "";
}
else
{
if ( !GetPoint(var, exception, pos) ) return true;
angle = var->GetValFloat()*Math::PI/180.0f;
var = var->GetNext();
type = static_cast<ObjectType>(var->GetValInt());
var = var->GetNext();
if ( var != 0 )
if ( var != nullptr )
{
cbs = var->GetValString();
CBotString cbs = var->GetValString();
name = cbs;
var = var->GetNext();
if ( var != 0 )
if ( var != nullptr )
{
power = var->GetValFloat();
}
@ -1731,30 +1729,24 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
power = -1.0f;
}
}
CObject* object = nullptr;
if ( type == OBJECT_ANT ||
type == OBJECT_SPIDER ||
type == OBJECT_BEE ||
type == OBJECT_WORM )
{
CObject* egg;
object = new CObject();
if ( !object->CreateInsect(pos, angle, type) )
{
delete object;
result->SetValInt(1); // error
return true;
}
egg = new CObject();
if ( !egg->CreateResource(pos, angle, OBJECT_EGG, 0.0f) )
{
delete egg;
}
CObject* object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type);
CObjectManager::GetInstancePointer()->CreateObject(pos, angle, OBJECT_EGG, 0.0f);
object->SetActivity(false);
} else {
if ((type == OBJECT_POWER || type == OBJECT_ATOMIC) && power == -1.0f) power = 1.0f;
}
else
{
if ((type == OBJECT_POWER || type == OBJECT_ATOMIC) && power == -1.0f)
{
power = 1.0f;
}
object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power);
if ( object == nullptr )
{
@ -1763,7 +1755,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
}
script->m_main->CreateShortcuts();
}
if (name[0] != 0)
{
std::string name2 = CPathManager::InjectLevelDir(name, "ai");
@ -1775,7 +1767,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
brain->RunProgram(program);
}
}
result->SetValInt(0); // no error
return true;
}