Proper CObject lifetime management
CObjectManager is now the only class responsible for storing CObjectsmaster
parent
fed67e6640
commit
0c9a9bce98
|
@ -231,7 +231,6 @@ enum ResearchType
|
|||
|
||||
|
||||
// TODO: move to CRobotMain
|
||||
extern long g_id; // unique identifier
|
||||
extern int g_build; // constructible buildings
|
||||
extern int g_researchDone; // research done
|
||||
extern long g_researchEnable; // research available
|
||||
|
|
|
@ -243,10 +243,9 @@ void CCamera::SetType(CameraType type)
|
|||
|
||||
if ( (m_type == CAM_TYPE_BACK) && m_transparency )
|
||||
{
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck())
|
||||
continue; // battery or cargo?
|
||||
|
||||
|
@ -890,9 +889,9 @@ bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat)
|
|||
|
||||
m_transparency = false;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
if (obj->GetTruck()) continue; // battery or cargo?
|
||||
|
||||
|
@ -966,10 +965,9 @@ bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat)
|
|||
|
||||
bool CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
|
||||
{
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj == m_cameraObj) continue;
|
||||
|
||||
ObjectType type = obj->GetType();
|
||||
|
|
|
@ -317,10 +317,9 @@ CObject* CLightning::SearchObject(Math::Vector pos)
|
|||
// Seeking the object closest to the point of impact of lightning.
|
||||
CObject* bestObj = 0;
|
||||
float min = 100000.0f;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (!obj->GetActif()) continue; // inactive object?
|
||||
if (obj->GetTruck() != nullptr) continue; // object transported?
|
||||
|
||||
|
|
|
@ -3658,10 +3658,9 @@ CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos,
|
|||
|
||||
CObject* best = 0;
|
||||
bool shield = false;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (!obj->GetActif()) continue; // inactive?
|
||||
if (obj == father) continue;
|
||||
|
||||
|
@ -3783,9 +3782,9 @@ CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal,
|
|||
box2.y += min;
|
||||
box2.z += min;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
if (!obj->GetActif()) continue; // inactive?
|
||||
if (obj == father) continue;
|
||||
|
|
|
@ -1372,18 +1372,16 @@ void CPyro::DeleteObject(bool primary, bool secondary)
|
|||
type != OBJECT_ENERGY )
|
||||
{
|
||||
CObject* sub = m_object->GetPower();
|
||||
if ( sub != 0 )
|
||||
if ( sub != nullptr )
|
||||
{
|
||||
sub->DeleteObject(); // removes the battery
|
||||
delete sub;
|
||||
m_object->SetPower(0);
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(sub);
|
||||
m_object->SetPower(nullptr);
|
||||
}
|
||||
|
||||
sub = m_object->GetFret();
|
||||
if ( sub != 0 )
|
||||
if ( sub != nullptr )
|
||||
{
|
||||
sub->DeleteObject(); // removes the object transported
|
||||
delete sub;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(sub);
|
||||
m_object->SetFret(nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -1391,7 +1389,7 @@ void CPyro::DeleteObject(bool primary, bool secondary)
|
|||
if (primary)
|
||||
{
|
||||
CObject* truck = m_object->GetTruck();
|
||||
if ( truck != 0 ) // object carries?
|
||||
if ( truck != nullptr ) // object carries?
|
||||
{
|
||||
if (truck->GetPower() == m_object)
|
||||
truck->SetPower(nullptr);
|
||||
|
@ -1400,9 +1398,7 @@ void CPyro::DeleteObject(bool primary, bool secondary)
|
|||
truck->SetFret(nullptr);
|
||||
}
|
||||
|
||||
CObject* sub = m_object;
|
||||
sub->DeleteObject(); // removes the object (*)
|
||||
delete sub;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_object);
|
||||
m_object = nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -2218,9 +2214,9 @@ CObject* CPyro::FallSearchBeeExplo()
|
|||
float iRadius;
|
||||
m_object->GetCrashSphere(0, iPos, iRadius);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* pObj = it.second;
|
||||
CObject* pObj = it.second.get();
|
||||
|
||||
ObjectType oType = pObj->GetType();
|
||||
if ( oType != OBJECT_HUMAN &&
|
||||
|
|
|
@ -1244,9 +1244,9 @@ void CAutoBase::FreezeCargo(bool bFreeze)
|
|||
Math::Vector oPos;
|
||||
float dist;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
pObj->SetCargo(false);
|
||||
|
||||
|
@ -1280,9 +1280,9 @@ void CAutoBase::MoveCargo()
|
|||
|
||||
sPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetCargo() ) continue;
|
||||
|
||||
|
@ -1308,9 +1308,9 @@ Error CAutoBase::CheckCloseDoor()
|
|||
float oRad, dist;
|
||||
int j;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue; // yourself?
|
||||
if ( !pObj->GetActif() ) continue; // inactive?
|
||||
|
|
|
@ -54,17 +54,14 @@ CAutoConvert::~CAutoConvert()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoConvert::DeleteObject(bool bAll)
|
||||
void CAutoConvert::DeleteObject(bool all)
|
||||
{
|
||||
CObject* fret;
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
fret = SearchStone(OBJECT_STONE);
|
||||
if ( fret != 0 )
|
||||
CObject* fret = SearchStone(OBJECT_STONE);
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // destroy the stone
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +72,7 @@ void CAutoConvert::DeleteObject(bool bAll)
|
|||
m_soundChannel = -1;
|
||||
}
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
CAuto::DeleteObject(all);
|
||||
}
|
||||
|
||||
|
||||
|
@ -233,11 +230,11 @@ bool CAutoConvert::EventProcess(const Event &event)
|
|||
m_object->SetAngleY(3, Math::PI);
|
||||
|
||||
fret = SearchStone(OBJECT_STONE);
|
||||
if ( fret != 0 )
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
m_bResetDelete = ( fret->GetResetCap() != RESET_NONE );
|
||||
fret->DeleteObject(); // destroy the stone
|
||||
delete fret;
|
||||
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
|
||||
CreateMetal(); // Create the metal
|
||||
|
@ -405,9 +402,9 @@ CObject* CAutoConvert::SearchStone(ObjectType type)
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
oType = pObj->GetType();
|
||||
if ( oType != type ) continue;
|
||||
|
@ -433,9 +430,9 @@ bool CAutoConvert::SearchVehicle()
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_HUMAN &&
|
||||
|
|
|
@ -61,17 +61,14 @@ CAutoDerrick::~CAutoDerrick()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoDerrick::DeleteObject(bool bAll)
|
||||
void CAutoDerrick::DeleteObject(bool all)
|
||||
{
|
||||
CObject* fret;
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
fret = SearchFret();
|
||||
if ( fret != 0 && fret->GetLock() )
|
||||
CObject* fret = SearchFret();
|
||||
if ( fret != nullptr && fret->GetLock() )
|
||||
{
|
||||
fret->DeleteObject();
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +79,7 @@ void CAutoDerrick::DeleteObject(bool bAll)
|
|||
m_soundChannel = -1;
|
||||
}
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
CAuto::DeleteObject(all);
|
||||
}
|
||||
|
||||
|
||||
|
@ -468,9 +465,9 @@ CObject* CAutoDerrick::SearchFret()
|
|||
Math::Vector oPos;
|
||||
ObjectType type;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type == OBJECT_DERRICK ) continue;
|
||||
|
@ -494,9 +491,9 @@ bool CAutoDerrick::SearchFree(Math::Vector pos)
|
|||
float sRadius, distance;
|
||||
int j;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type == OBJECT_DERRICK ) continue;
|
||||
|
|
|
@ -279,9 +279,9 @@ CObject* CAutoDestroyer::SearchPlastic()
|
|||
|
||||
sPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
//if ( type != OBJECT_SCRAP4 &&
|
||||
|
|
|
@ -55,16 +55,14 @@ CAutoEgg::~CAutoEgg()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoEgg::DeleteObject(bool bAll)
|
||||
void CAutoEgg::DeleteObject(bool all)
|
||||
{
|
||||
CObject* alien;
|
||||
CAuto::DeleteObject(all);
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
alien = SearchAlien();
|
||||
if ( alien != 0 )
|
||||
CObject* alien = SearchAlien();
|
||||
if ( alien != nullptr )
|
||||
{
|
||||
// Probably the intended action
|
||||
// Original code: ( alien->GetZoom(0) == 1.0f )
|
||||
|
@ -75,8 +73,7 @@ void CAutoEgg::DeleteObject(bool bAll)
|
|||
}
|
||||
else
|
||||
{
|
||||
alien->DeleteObject();
|
||||
delete alien;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(alien);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -283,9 +280,9 @@ CObject* CAutoEgg::SearchAlien()
|
|||
cPos = m_object->GetPosition(0);
|
||||
min = 100000.0f;
|
||||
pBest = 0;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
||||
|
|
|
@ -61,34 +61,30 @@ CAutoEnergy::~CAutoEnergy()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoEnergy::DeleteObject(bool bAll)
|
||||
void CAutoEnergy::DeleteObject(bool all)
|
||||
{
|
||||
CObject* fret;
|
||||
|
||||
if ( m_partiSphere != -1 )
|
||||
{
|
||||
m_particle->DeleteParticle(m_partiSphere);
|
||||
m_partiSphere = -1;
|
||||
}
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
fret = SearchMetal();
|
||||
if ( fret != 0 )
|
||||
CObject* fret = SearchMetal();
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // destroys the metal
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
|
||||
fret = SearchPower();
|
||||
if ( fret != 0 )
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // destroys the cell
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
}
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
CAuto::DeleteObject(all);
|
||||
}
|
||||
|
||||
|
||||
|
@ -312,11 +308,10 @@ bool CAutoEnergy::EventProcess(const Event &event)
|
|||
else
|
||||
{
|
||||
fret = SearchMetal();
|
||||
if ( fret != 0 )
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
m_object->SetPower(0);
|
||||
fret->DeleteObject(); // destroys the metal
|
||||
delete fret;
|
||||
m_object->SetPower(nullptr);
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
|
||||
fret = SearchPower();
|
||||
|
@ -406,9 +401,9 @@ bool CAutoEnergy::SearchVehicle()
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_HUMAN &&
|
||||
|
@ -479,9 +474,9 @@ CObject* CAutoEnergy::SearchPower()
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetLock() ) continue;
|
||||
|
||||
|
|
|
@ -62,25 +62,20 @@ CAutoFactory::~CAutoFactory()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoFactory::DeleteObject(bool bAll)
|
||||
void CAutoFactory::DeleteObject(bool all)
|
||||
{
|
||||
CObject* fret;
|
||||
CObject* vehicle;
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
fret = SearchFret(); // transform metal?
|
||||
if ( fret != 0 )
|
||||
CObject* fret = SearchFret(); // transform metal?
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // destroys the metal
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
|
||||
vehicle = SearchVehicle();
|
||||
if ( vehicle != 0 )
|
||||
CObject* vehicle = SearchVehicle();
|
||||
if ( vehicle != nullptr )
|
||||
{
|
||||
vehicle->DeleteObject(); // destroys the vehicle
|
||||
delete vehicle;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(vehicle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +86,7 @@ void CAutoFactory::DeleteObject(bool bAll)
|
|||
m_channelSound = -1;
|
||||
}
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
CAuto::DeleteObject(all);
|
||||
}
|
||||
|
||||
|
||||
|
@ -387,10 +382,9 @@ bool CAutoFactory::EventProcess(const Event &event)
|
|||
SoundManip(2.0f, 1.0f, 1.2f);
|
||||
|
||||
fret = SearchFret(); // transform metal?
|
||||
if ( fret != 0 )
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // removes the metal
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
|
||||
m_vehicle = vehicle = SearchVehicle();
|
||||
|
@ -558,9 +552,9 @@ CObject* CAutoFactory::SearchFret()
|
|||
ObjectType type;
|
||||
float dist;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_METAL ) continue;
|
||||
|
@ -586,9 +580,9 @@ bool CAutoFactory::NearestVehicle()
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_HUMAN &&
|
||||
|
@ -692,9 +686,9 @@ CObject* CAutoFactory::SearchVehicle()
|
|||
ObjectType type;
|
||||
float dist;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetLock() ) continue;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "math/geometry.h"
|
||||
|
||||
#include "object/object_manager.h"
|
||||
#include "object/robotmain.h"
|
||||
#include "object/level/parserline.h"
|
||||
#include "object/level/parserparam.h"
|
||||
|
@ -366,11 +367,10 @@ bool CAutoLabo::EventProcess(const Event &event)
|
|||
UpdateInterface();
|
||||
|
||||
power = m_object->GetPower();
|
||||
if ( power != 0 )
|
||||
if ( power != nullptr )
|
||||
{
|
||||
m_object->SetPower(0);
|
||||
power->DeleteObject(); // destroys the ball
|
||||
delete power;
|
||||
m_object->SetPower(nullptr);
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(power);
|
||||
}
|
||||
|
||||
m_main->DisplayError(INFO_LABO, m_object);
|
||||
|
|
|
@ -232,9 +232,9 @@ bool CAutoMush::SearchTarget()
|
|||
|
||||
iPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj->GetLock() ) continue;
|
||||
|
||||
|
|
|
@ -48,21 +48,18 @@ CAutoNest::~CAutoNest()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoNest::DeleteObject(bool bAll)
|
||||
void CAutoNest::DeleteObject(bool all)
|
||||
{
|
||||
CObject* fret;
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
fret = SearchFret();
|
||||
if ( fret != 0 )
|
||||
CObject* fret = SearchFret();
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject();
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
}
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
CAuto::DeleteObject(all);
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,9 +154,9 @@ bool CAutoNest::SearchFree(Math::Vector pos)
|
|||
float sRadius, distance;
|
||||
int j;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type == OBJECT_NEST ) continue;
|
||||
|
@ -193,9 +190,9 @@ CObject* CAutoNest::SearchFret()
|
|||
Math::Vector oPos;
|
||||
ObjectType type;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetLock() ) continue;
|
||||
|
||||
|
|
|
@ -57,17 +57,14 @@ CAutoNuclear::~CAutoNuclear()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CAutoNuclear::DeleteObject(bool bAll)
|
||||
void CAutoNuclear::DeleteObject(bool all)
|
||||
{
|
||||
CObject* fret;
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
fret = SearchUranium();
|
||||
if ( fret != 0 )
|
||||
CObject* fret = SearchUranium();
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // destroys the metal
|
||||
delete fret;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +75,7 @@ void CAutoNuclear::DeleteObject(bool bAll)
|
|||
m_channelSound = -1;
|
||||
}
|
||||
|
||||
CAuto::DeleteObject(bAll);
|
||||
CAuto::DeleteObject(all);
|
||||
}
|
||||
|
||||
|
||||
|
@ -231,11 +228,10 @@ bool CAutoNuclear::EventProcess(const Event &event)
|
|||
else
|
||||
{
|
||||
fret = SearchUranium();
|
||||
if ( fret != 0 )
|
||||
if ( fret != nullptr )
|
||||
{
|
||||
fret->DeleteObject(); // destroyed uranium
|
||||
delete fret;
|
||||
m_object->SetPower(0);
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(fret);
|
||||
m_object->SetPower(nullptr);
|
||||
}
|
||||
|
||||
CreatePower(); // creates the atomic cell
|
||||
|
@ -340,9 +336,9 @@ bool CAutoNuclear::SearchVehicle()
|
|||
ObjectType type;
|
||||
float oRadius, dist;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_HUMAN &&
|
||||
|
|
|
@ -250,9 +250,9 @@ void CAutoPara::ChargeObject(float rTime)
|
|||
|
||||
sPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
oPos = pObj->GetPosition(0);
|
||||
dist = Math::Distance(oPos, sPos);
|
||||
|
|
|
@ -274,9 +274,9 @@ bool CAutoRadar::SearchEnemy(Math::Vector &pos)
|
|||
min = 1000000.0f;
|
||||
m_totalDetect = 0;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetActif() ) continue;
|
||||
|
||||
|
|
|
@ -242,9 +242,9 @@ CObject* CAutoRepair::SearchVehicle()
|
|||
|
||||
sPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_MOBILEfa &&
|
||||
|
|
|
@ -68,13 +68,10 @@ CAutoSafe::~CAutoSafe()
|
|||
|
||||
void CAutoSafe::DeleteObject(bool bAll)
|
||||
{
|
||||
CObject* pObj;
|
||||
|
||||
pObj = SearchVehicle();
|
||||
if ( pObj != 0 )
|
||||
CObject* obj = SearchVehicle();
|
||||
if ( obj != nullptr )
|
||||
{
|
||||
pObj->DeleteObject();
|
||||
delete pObj;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
||||
}
|
||||
|
||||
if ( m_channelSound != -1 )
|
||||
|
@ -403,10 +400,10 @@ int CAutoSafe::CountKeys()
|
|||
m_bKey[index] = false;
|
||||
m_keyPos[index] = cPos;
|
||||
}
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
||||
|
@ -479,9 +476,9 @@ void CAutoSafe::LockKeys()
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
oType = pObj->GetType();
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
@ -510,9 +507,9 @@ void CAutoSafe::DownKeys(float progress)
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
oType = pObj->GetType();
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
@ -535,39 +532,34 @@ void CAutoSafe::DownKeys(float progress)
|
|||
|
||||
void CAutoSafe::DeleteKeys()
|
||||
{
|
||||
CObject* pObj;
|
||||
Math::Vector cPos, oPos;
|
||||
ObjectType oType;
|
||||
float dist;
|
||||
bool bDelete;
|
||||
|
||||
cPos = m_object->GetPosition(0);
|
||||
Math::Vector cPos = m_object->GetPosition(0);
|
||||
|
||||
bool haveDeleted = false;
|
||||
do
|
||||
{
|
||||
bDelete = false;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
haveDeleted = false;
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
oType = pObj->GetType();
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
ObjectType oType = obj->GetType();
|
||||
if ( obj->GetTruck() != nullptr ) continue;
|
||||
|
||||
if ( oType != OBJECT_KEYa &&
|
||||
oType != OBJECT_KEYb &&
|
||||
oType != OBJECT_KEYc &&
|
||||
oType != OBJECT_KEYd ) continue;
|
||||
|
||||
oPos = pObj->GetPosition(0);
|
||||
dist = Math::DistanceProjected(oPos, cPos);
|
||||
Math::Vector oPos = obj->GetPosition(0);
|
||||
float dist = Math::DistanceProjected(oPos, cPos);
|
||||
if ( dist > 20.0f ) continue;
|
||||
|
||||
pObj->DeleteObject();
|
||||
delete pObj;
|
||||
bDelete = true;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
||||
|
||||
haveDeleted = true;
|
||||
}
|
||||
}
|
||||
while ( bDelete );
|
||||
while ( haveDeleted );
|
||||
}
|
||||
|
||||
// Seeking a vehicle in the safe.
|
||||
|
@ -580,9 +572,9 @@ CObject* CAutoSafe::SearchVehicle()
|
|||
|
||||
cPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue;
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
|
|
@ -247,10 +247,10 @@ CObject* CAutoStation::SearchVehicle()
|
|||
float dist;
|
||||
|
||||
sPos = m_object->GetPosition(0);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type != OBJECT_HUMAN &&
|
||||
|
|
|
@ -277,9 +277,9 @@ CObject* CAutoTower::SearchTarget(Math::Vector &impact)
|
|||
iPos = m_object->GetPosition(0);
|
||||
min = 1000000.0f;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
oType = pObj->GetType();
|
||||
if ( oType != OBJECT_MOTHER &&
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "graphics/core/color.h"
|
||||
#include "graphics/engine/terrain.h"
|
||||
|
||||
#include "object/object_manager.h"
|
||||
#include "object/motion/motion.h"
|
||||
#include "object/task/taskmanager.h"
|
||||
#include "object/level/parserline.h"
|
||||
|
@ -130,7 +131,7 @@ CBrain::~CBrain()
|
|||
|
||||
// Destroys the object.
|
||||
|
||||
void CBrain::DeleteObject(bool bAll)
|
||||
void CBrain::DeleteObject(bool all)
|
||||
{
|
||||
if ( m_soundChannelAlarm != -1 )
|
||||
{
|
||||
|
@ -139,13 +140,12 @@ void CBrain::DeleteObject(bool bAll)
|
|||
m_soundChannelAlarm = -1;
|
||||
}
|
||||
|
||||
if ( !bAll )
|
||||
if ( !all )
|
||||
{
|
||||
if ( m_beeBullet != 0 )
|
||||
if ( m_beeBullet != nullptr )
|
||||
{
|
||||
m_beeBullet->DeleteObject();
|
||||
delete m_beeBullet;
|
||||
m_beeBullet = 0;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_beeBullet);
|
||||
m_beeBullet = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "math/geometry.h"
|
||||
|
||||
#include "object/brain.h"
|
||||
#include "object/object_manager.h"
|
||||
|
||||
#include "physics/physics.h"
|
||||
|
||||
|
@ -94,7 +95,6 @@ void CMotionVehicle::DeleteObject(bool bAll)
|
|||
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];
|
||||
|
@ -925,27 +925,20 @@ void CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
|
|||
color.a = 0.0f;
|
||||
m_object->CreateEffectLight(20.0f, color);
|
||||
|
||||
// Creates the battery.
|
||||
pPower = new CObject();
|
||||
pPower->SetType(power<=1.0f?OBJECT_POWER:OBJECT_ATOMIC);
|
||||
CObject* powerCell = nullptr;
|
||||
Math::Vector powerCellPos = m_object->GetCharacter()->posPower;
|
||||
float powerCellAngle = 0.0f;
|
||||
if (power <= 1.0f)
|
||||
{
|
||||
powerCell = CObjectManager::GetInstancePointer()->CreateObject(powerCellPos, powerCellAngle, OBJECT_POWER, power);
|
||||
}
|
||||
else
|
||||
{
|
||||
powerCell = CObjectManager::GetInstancePointer()->CreateObject(powerCellPos, powerCellAngle, OBJECT_ATOMIC, power / 100.0f);
|
||||
}
|
||||
|
||||
rank = m_engine->CreateObject();
|
||||
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
|
||||
pPower->SetObjectRank(0, rank);
|
||||
pPower->CreateShadowCircle(1.5f, 1.0f); //create a shadow for battary
|
||||
|
||||
if ( power <= 1.0f ) modelManager->AddModelCopy("power.mod", false, rank);
|
||||
else modelManager->AddModelCopy("atomic.mod", false, rank);
|
||||
|
||||
pPower->SetPosition(0, m_object->GetCharacter()->posPower);
|
||||
pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f);
|
||||
pPower->SetGlobalSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.5f);
|
||||
|
||||
pPower->SetTruck(m_object);
|
||||
m_object->SetPower(pPower);
|
||||
|
||||
if ( power <= 1.0f ) pPower->SetEnergy(power);
|
||||
else pPower->SetEnergy(power/100.0f);
|
||||
powerCell->SetTruck(m_object);
|
||||
m_object->SetPower(powerCell);
|
||||
}
|
||||
|
||||
pos = m_object->GetPosition(0);
|
||||
|
|
|
@ -189,7 +189,8 @@ void uObject(CBotVar* botThis, void* user)
|
|||
|
||||
// Object's constructor.
|
||||
|
||||
CObject::CObject()
|
||||
CObject::CObject(int id)
|
||||
: m_id(id)
|
||||
{
|
||||
m_app = CApplication::GetInstancePointer();
|
||||
m_sound = m_app->GetSound();
|
||||
|
@ -207,7 +208,6 @@ CObject::CObject()
|
|||
m_runScript = nullptr;
|
||||
|
||||
m_type = OBJECT_FIX;
|
||||
m_id = ++g_id;
|
||||
m_option = 0;
|
||||
m_name[0] = 0;
|
||||
m_partiReactor = -1;
|
||||
|
@ -315,8 +315,6 @@ CObject::CObject()
|
|||
m_botVar = CBotVar::Create("", CBotTypResult(CBotTypClass, "object"));
|
||||
m_botVar->SetUserPtr(this);
|
||||
m_botVar->SetIdent(m_id);
|
||||
|
||||
CObjectManager::GetInstancePointer()->AddObject(this);
|
||||
}
|
||||
|
||||
// Object's destructor.
|
||||
|
@ -338,8 +336,6 @@ CObject::~CObject()
|
|||
m_motion = nullptr;
|
||||
delete m_auto;
|
||||
m_auto = nullptr;
|
||||
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(this);
|
||||
|
||||
m_app = nullptr;
|
||||
}
|
||||
|
@ -353,7 +349,6 @@ void CObject::DeleteObject(bool bAll)
|
|||
{
|
||||
CObject* pObj;
|
||||
Gfx::CPyro* pPyro;
|
||||
|
||||
if ( m_botVar != 0 )
|
||||
{
|
||||
m_botVar->SetUserPtr(OBJECTDELETED);
|
||||
|
@ -363,12 +358,13 @@ void CObject::DeleteObject(bool bAll)
|
|||
{
|
||||
m_camera->SetControllingObject(0);
|
||||
}
|
||||
|
||||
|
||||
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
pObj->DeleteDeselList(this);
|
||||
}
|
||||
|
@ -943,19 +939,6 @@ int CObject::GetOption()
|
|||
return m_option;
|
||||
}
|
||||
|
||||
|
||||
// Management of the unique identifier of an object.
|
||||
|
||||
void CObject::SetID(int id)
|
||||
{
|
||||
m_id = id;
|
||||
|
||||
if ( m_botVar != 0 )
|
||||
{
|
||||
m_botVar->SetIdent(m_id);
|
||||
}
|
||||
}
|
||||
|
||||
int CObject::GetID()
|
||||
{
|
||||
return m_id;
|
||||
|
|
|
@ -135,11 +135,18 @@ enum ResetCap
|
|||
|
||||
class CObject
|
||||
{
|
||||
friend class CObjectFactory;
|
||||
friend class CObjectManager;
|
||||
protected:
|
||||
CObject(int id);
|
||||
void DeleteObject(bool bAll=false);
|
||||
|
||||
public:
|
||||
CObject();
|
||||
CObject(const CObject&) = delete;
|
||||
CObject& operator=(const CObject&) = delete;
|
||||
|
||||
~CObject();
|
||||
|
||||
void DeleteObject(bool bAll=false);
|
||||
void Simplify();
|
||||
bool ExploObject(ExploType type, float force, float decay=1.0f);
|
||||
|
||||
|
@ -157,7 +164,6 @@ public:
|
|||
void SetOption(int option);
|
||||
int GetOption();
|
||||
|
||||
void SetID(int id);
|
||||
int GetID();
|
||||
|
||||
bool Write(CLevelParserLine* line);
|
||||
|
@ -446,7 +452,7 @@ protected:
|
|||
CScript* m_runScript;
|
||||
|
||||
ObjectType m_type; // OBJECT_*
|
||||
int m_id; // unique identifier
|
||||
const int m_id; // unique identifier
|
||||
char m_name[50]; // name of the object
|
||||
Character m_character; // characteristic
|
||||
int m_option; // option
|
||||
|
|
|
@ -77,11 +77,9 @@ CObjectFactory::CObjectFactory(Gfx::CEngine* engine,
|
|||
, m_main(main)
|
||||
{}
|
||||
|
||||
CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType type,
|
||||
float power, float zoom, float height,
|
||||
bool trainer, bool toy, int option)
|
||||
CObjectUPtr CObjectFactory::CreateObject(const ObjectCreateParams& params)
|
||||
{
|
||||
switch (type)
|
||||
switch (params.type)
|
||||
{
|
||||
case OBJECT_NULL:
|
||||
return nullptr;
|
||||
|
@ -109,7 +107,7 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_TARGET2:
|
||||
case OBJECT_START:
|
||||
case OBJECT_END:
|
||||
return CreateBuilding(pos, angle, height, type, power);
|
||||
return CreateBuilding(params);
|
||||
|
||||
case OBJECT_FRET:
|
||||
case OBJECT_STONE:
|
||||
|
@ -142,20 +140,20 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_MARKKEYc:
|
||||
case OBJECT_MARKKEYd:
|
||||
case OBJECT_EGG:
|
||||
return CreateResource(pos, angle, type, power);
|
||||
return CreateResource(params);
|
||||
|
||||
case OBJECT_FLAGb:
|
||||
case OBJECT_FLAGr:
|
||||
case OBJECT_FLAGg:
|
||||
case OBJECT_FLAGy:
|
||||
case OBJECT_FLAGv:
|
||||
return CreateFlag(pos, angle, type);
|
||||
return CreateFlag(params);
|
||||
|
||||
case OBJECT_BARRIER0:
|
||||
case OBJECT_BARRIER1:
|
||||
case OBJECT_BARRIER2:
|
||||
case OBJECT_BARRIER3:
|
||||
return CreateBarrier(pos, angle, height, type);
|
||||
return CreateBarrier(params);
|
||||
|
||||
case OBJECT_PLANT0:
|
||||
case OBJECT_PLANT1:
|
||||
|
@ -183,11 +181,11 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_TREE3:
|
||||
case OBJECT_TREE4:
|
||||
case OBJECT_TREE5:
|
||||
return CreatePlant(pos, angle, height, type);
|
||||
return CreatePlant(params);
|
||||
|
||||
case OBJECT_MUSHROOM1:
|
||||
case OBJECT_MUSHROOM2:
|
||||
return CreateMushroom(pos, angle, height, type);
|
||||
return CreateMushroom(params);
|
||||
|
||||
case OBJECT_TEEN0:
|
||||
case OBJECT_TEEN1:
|
||||
|
@ -234,13 +232,13 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_TEEN42:
|
||||
case OBJECT_TEEN43:
|
||||
case OBJECT_TEEN44:
|
||||
return CreateTeen(pos, angle, zoom, height, type, option);
|
||||
return CreateTeen(params);
|
||||
|
||||
case OBJECT_QUARTZ0:
|
||||
case OBJECT_QUARTZ1:
|
||||
case OBJECT_QUARTZ2:
|
||||
case OBJECT_QUARTZ3:
|
||||
return CreateQuartz(pos, angle, height, type);
|
||||
return CreateQuartz(params);
|
||||
|
||||
case OBJECT_ROOT0:
|
||||
case OBJECT_ROOT1:
|
||||
|
@ -248,10 +246,10 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_ROOT3:
|
||||
case OBJECT_ROOT4:
|
||||
case OBJECT_ROOT5:
|
||||
return CreateRoot(pos, angle, height, type);
|
||||
return CreateRoot(params);
|
||||
|
||||
case OBJECT_HOME1:
|
||||
return CreateHome(pos, angle, height, type);
|
||||
return CreateHome(params);
|
||||
|
||||
case OBJECT_RUINmobilew1:
|
||||
case OBJECT_RUINmobilew2:
|
||||
|
@ -266,20 +264,20 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_RUINconvert:
|
||||
case OBJECT_RUINbase:
|
||||
case OBJECT_RUINhead:
|
||||
return CreateRuin(pos, angle, height, type);
|
||||
return CreateRuin(params);
|
||||
|
||||
case OBJECT_APOLLO1:
|
||||
case OBJECT_APOLLO3:
|
||||
case OBJECT_APOLLO4:
|
||||
case OBJECT_APOLLO5:
|
||||
return CreateApollo(pos, angle, type);
|
||||
return CreateApollo(params);
|
||||
|
||||
case OBJECT_MOTHER:
|
||||
case OBJECT_ANT:
|
||||
case OBJECT_SPIDER:
|
||||
case OBJECT_BEE:
|
||||
case OBJECT_WORM:
|
||||
return CreateInsect(pos, angle, type); // no eggs
|
||||
return CreateInsect(params); // no eggs
|
||||
|
||||
case OBJECT_HUMAN:
|
||||
case OBJECT_TECH:
|
||||
|
@ -312,7 +310,7 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
case OBJECT_MOBILEit:
|
||||
case OBJECT_MOBILEdr:
|
||||
case OBJECT_APOLLO2:
|
||||
return CreateVehicle(pos, angle, type, power, trainer, toy, option);
|
||||
return CreateVehicle(params);
|
||||
|
||||
default:
|
||||
break;
|
||||
|
@ -323,9 +321,15 @@ CObject* CObjectFactory::CreateObject(Math::Vector pos, float angle, ObjectType
|
|||
|
||||
// Creates a building laying on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateBuilding(Math::Vector pos, float angle, float height, ObjectType type, float power)
|
||||
CObjectUPtr CObjectFactory::CreateBuilding(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
float power = params.power;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -1124,7 +1128,7 @@ CObject* CObjectFactory::CreateBuilding(Math::Vector pos, float angle, float hei
|
|||
pPower->obj->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f);
|
||||
pPower->obj->SetGlobalSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.5f);
|
||||
|
||||
pPower->SetTruck(obj);
|
||||
pPower->SetTruck(obj.get());
|
||||
SetPower(pPower);
|
||||
|
||||
if ( power <= 1.0f ) pPower->obj->SetEnergy(power);
|
||||
|
@ -1136,7 +1140,7 @@ CObject* CObjectFactory::CreateBuilding(Math::Vector pos, float angle, float hei
|
|||
pos.y += height;
|
||||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
m_engine->LoadAllTextures();
|
||||
|
||||
return obj;
|
||||
|
@ -1144,9 +1148,14 @@ CObject* CObjectFactory::CreateBuilding(Math::Vector pos, float angle, float hei
|
|||
|
||||
// Creates a small resource set on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateResource(Math::Vector pos, float angle, ObjectType type, float power)
|
||||
CObjectUPtr CObjectFactory::CreateResource(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
ObjectType type = params.type;
|
||||
float power = params.power;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -1242,10 +1251,11 @@ CObject* CObjectFactory::CreateResource(Math::Vector pos, float angle, ObjectTyp
|
|||
obj->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f);
|
||||
obj->SetGlobalSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.5f);
|
||||
}
|
||||
|
||||
obj->CreateShadowCircle(radius, 1.0f);
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
m_engine->LoadAllTextures();
|
||||
obj->FloorAdjust();
|
||||
|
||||
|
@ -1258,9 +1268,13 @@ CObject* CObjectFactory::CreateResource(Math::Vector pos, float angle, ObjectTyp
|
|||
|
||||
// Creates a flag placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateFlag(Math::Vector pos, float angle, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateFlag(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -1302,7 +1316,7 @@ CObject* CObjectFactory::CreateFlag(Math::Vector pos, float angle, ObjectType ty
|
|||
obj->CreateShadowCircle(2.0f, 0.3f);
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
m_engine->LoadAllTextures();
|
||||
obj->FloorAdjust();
|
||||
|
||||
|
@ -1314,9 +1328,14 @@ CObject* CObjectFactory::CreateFlag(Math::Vector pos, float angle, ObjectType ty
|
|||
|
||||
// Creates a barrier placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateBarrier(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateBarrier(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -1394,7 +1413,7 @@ CObject* CObjectFactory::CreateBarrier(Math::Vector pos, float angle, float heig
|
|||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
obj->FloorAdjust();
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
|
@ -1406,9 +1425,14 @@ CObject* CObjectFactory::CreateBarrier(Math::Vector pos, float angle, float heig
|
|||
|
||||
// Creates a plant placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreatePlant(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreatePlant(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -1631,7 +1655,7 @@ CObject* CObjectFactory::CreatePlant(Math::Vector pos, float angle, float height
|
|||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
pos.y += height;
|
||||
|
@ -1642,9 +1666,14 @@ CObject* CObjectFactory::CreatePlant(Math::Vector pos, float angle, float height
|
|||
|
||||
// Creates a mushroom placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateMushroom(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateMushroom(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -1684,7 +1713,7 @@ CObject* CObjectFactory::CreateMushroom(Math::Vector pos, float angle, float hei
|
|||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
pos.y += height;
|
||||
|
@ -1695,9 +1724,16 @@ CObject* CObjectFactory::CreateMushroom(Math::Vector pos, float angle, float hei
|
|||
|
||||
// Creates a toy placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateTeen(Math::Vector pos, float angle, float zoom, float height, ObjectType type, int option)
|
||||
CObjectUPtr CObjectFactory::CreateTeen(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float zoom = params.zoom;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
int option = params.option;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
obj->SetOption(option);
|
||||
|
@ -2511,7 +2547,7 @@ CObject* CObjectFactory::CreateTeen(Math::Vector pos, float angle, float zoom, f
|
|||
obj->FloorAdjust();
|
||||
}
|
||||
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
pos.y += height;
|
||||
|
@ -2522,9 +2558,14 @@ CObject* CObjectFactory::CreateTeen(Math::Vector pos, float angle, float zoom, f
|
|||
|
||||
// Creates a crystal placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateQuartz(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateQuartz(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -2589,7 +2630,7 @@ CObject* CObjectFactory::CreateQuartz(Math::Vector pos, float angle, float heigh
|
|||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
pos.y += height;
|
||||
|
@ -2623,10 +2664,14 @@ CObject* CObjectFactory::CreateQuartz(Math::Vector pos, float angle, float heigh
|
|||
}
|
||||
|
||||
// Creates a root placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateRoot(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateRoot(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -2776,7 +2821,7 @@ CObject* CObjectFactory::CreateRoot(Math::Vector pos, float angle, float height,
|
|||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
pos.y += height;
|
||||
|
@ -2786,10 +2831,14 @@ CObject* CObjectFactory::CreateRoot(Math::Vector pos, float angle, float height,
|
|||
}
|
||||
|
||||
// Creates a small home.
|
||||
|
||||
CObject* CObjectFactory::CreateHome(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateHome(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -2812,7 +2861,7 @@ CObject* CObjectFactory::CreateHome(Math::Vector pos, float angle, float height,
|
|||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
pos.y += height;
|
||||
|
@ -2822,10 +2871,14 @@ CObject* CObjectFactory::CreateHome(Math::Vector pos, float angle, float height,
|
|||
}
|
||||
|
||||
// Creates ruin placed on the ground.
|
||||
|
||||
CObject* CObjectFactory::CreateRuin(Math::Vector pos, float angle, float height, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateRuin(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
float height = params.height;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -3078,7 +3131,7 @@ CObject* CObjectFactory::CreateRuin(Math::Vector pos, float angle, float height,
|
|||
obj->SetPosition(0, pos); //to display the shadows immediately
|
||||
|
||||
obj->SetFloorHeight(0.0f);
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
if ( type != OBJECT_RUINfactory &&
|
||||
type != OBJECT_RUINconvert &&
|
||||
|
@ -3234,9 +3287,13 @@ CObject* CObjectFactory::CreateRuin(Math::Vector pos, float angle, float height,
|
|||
|
||||
// Creates a gadget apollo.
|
||||
|
||||
CObject* CObjectFactory::CreateApollo(Math::Vector pos, float angle, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateApollo(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
|
@ -3399,7 +3456,7 @@ CObject* CObjectFactory::CreateApollo(Math::Vector pos, float angle, ObjectType
|
|||
obj->CreateShadowCircle(3.0f, 0.7f);
|
||||
}
|
||||
|
||||
AddObjectAuto(obj);
|
||||
AddObjectAuto(obj.get());
|
||||
|
||||
pos = obj->GetPosition(0);
|
||||
obj->SetPosition(0, pos); // to display the shadows immediately
|
||||
|
@ -3409,16 +3466,24 @@ CObject* CObjectFactory::CreateApollo(Math::Vector pos, float angle, ObjectType
|
|||
|
||||
// Creates a vehicle traveling any pose on the floor.
|
||||
|
||||
CObject* CObjectFactory::CreateVehicle(Math::Vector pos, float angle, ObjectType type, float power, bool trainer, bool toy, int option)
|
||||
CObjectUPtr CObjectFactory::CreateVehicle(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
ObjectType type = params.type;
|
||||
float power = params.power;
|
||||
bool trainer = params.trainer;
|
||||
bool toy = params.toy;
|
||||
int option = params.option;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
obj->SetOption(option);
|
||||
|
||||
if ( type == OBJECT_TOTO )
|
||||
{
|
||||
CMotion* motion = new CMotionToto(obj);
|
||||
CMotion* motion = new CMotionToto(obj.get());
|
||||
motion->Create(pos, angle, type, 1.0f, m_modelManager);
|
||||
obj->SetMotion(motion);
|
||||
return obj;
|
||||
|
@ -3436,8 +3501,8 @@ CObject* CObjectFactory::CreateVehicle(Math::Vector pos, float angle, ObjectType
|
|||
|
||||
obj->SetToy(toy);
|
||||
|
||||
CPhysics* physics = new CPhysics(obj);
|
||||
CBrain* brain = new CBrain(obj);
|
||||
CPhysics* physics = new CPhysics(obj.get());
|
||||
CBrain* brain = new CBrain(obj.get());
|
||||
|
||||
physics->SetBrain(brain);
|
||||
brain->SetPhysics(physics);
|
||||
|
@ -3481,15 +3546,15 @@ CObject* CObjectFactory::CreateVehicle(Math::Vector pos, float angle, ObjectType
|
|||
if ( type == OBJECT_HUMAN ||
|
||||
type == OBJECT_TECH )
|
||||
{
|
||||
motion = new CMotionHuman(obj);
|
||||
motion = new CMotionHuman(obj.get());
|
||||
}
|
||||
else if ( type == OBJECT_CONTROLLER )
|
||||
{
|
||||
motion = new CMotionDummy(obj); //dummy object
|
||||
motion = new CMotionDummy(obj.get()); //dummy object
|
||||
}
|
||||
else
|
||||
{
|
||||
motion = new CMotionVehicle(obj);
|
||||
motion = new CMotionVehicle(obj.get());
|
||||
}
|
||||
|
||||
physics->SetMotion(motion);
|
||||
|
@ -3505,14 +3570,18 @@ CObject* CObjectFactory::CreateVehicle(Math::Vector pos, float angle, ObjectType
|
|||
|
||||
// Creates an insect lands on any ground.
|
||||
|
||||
CObject* CObjectFactory::CreateInsect(Math::Vector pos, float angle, ObjectType type)
|
||||
CObjectUPtr CObjectFactory::CreateInsect(const ObjectCreateParams& params)
|
||||
{
|
||||
CObject* obj = new CObject();
|
||||
Math::Vector pos = params.pos;
|
||||
float angle = params.angle;
|
||||
ObjectType type = params.type;
|
||||
|
||||
CObjectUPtr obj(new CObject(params.id));
|
||||
|
||||
obj->SetType(type);
|
||||
|
||||
CPhysics* physics = new CPhysics(obj);
|
||||
CBrain* brain = new CBrain(obj);
|
||||
CPhysics* physics = new CPhysics(obj.get());
|
||||
CBrain* brain = new CBrain(obj.get());
|
||||
|
||||
physics->SetBrain(brain);
|
||||
brain->SetPhysics(physics);
|
||||
|
@ -3523,23 +3592,23 @@ CObject* CObjectFactory::CreateInsect(Math::Vector pos, float angle, ObjectType
|
|||
CMotion* motion = nullptr;
|
||||
if ( type == OBJECT_MOTHER )
|
||||
{
|
||||
motion = new CMotionMother(obj);
|
||||
motion = new CMotionMother(obj.get());
|
||||
}
|
||||
if ( type == OBJECT_ANT )
|
||||
{
|
||||
motion = new CMotionAnt(obj);
|
||||
motion = new CMotionAnt(obj.get());
|
||||
}
|
||||
if ( type == OBJECT_SPIDER )
|
||||
{
|
||||
motion = new CMotionSpider(obj);
|
||||
motion = new CMotionSpider(obj.get());
|
||||
}
|
||||
if ( type == OBJECT_BEE )
|
||||
{
|
||||
motion = new CMotionBee(obj);
|
||||
motion = new CMotionBee(obj.get());
|
||||
}
|
||||
if ( type == OBJECT_WORM )
|
||||
{
|
||||
motion = new CMotionWorm(obj);
|
||||
motion = new CMotionWorm(obj.get());
|
||||
}
|
||||
|
||||
physics->SetMotion(motion);
|
||||
|
|
|
@ -40,6 +40,22 @@ class CTerrain;
|
|||
class CObject;
|
||||
class CRobotMain;
|
||||
|
||||
using CObjectUPtr = std::unique_ptr<CObject>;
|
||||
|
||||
struct ObjectCreateParams
|
||||
{
|
||||
Math::Vector pos;
|
||||
float angle;
|
||||
ObjectType type;
|
||||
float power;
|
||||
float zoom;
|
||||
float height;
|
||||
bool trainer;
|
||||
bool toy;
|
||||
int option;
|
||||
int id;
|
||||
};
|
||||
|
||||
class CObjectFactory
|
||||
{
|
||||
public:
|
||||
|
@ -49,26 +65,23 @@ public:
|
|||
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);
|
||||
CObjectUPtr CreateObject(const ObjectCreateParams& params);
|
||||
|
||||
private:
|
||||
CObjectUPtr CreateBuilding(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateResource(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateVehicle(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateInsect(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateFlag(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateBarrier(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreatePlant(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateMushroom(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateTeen(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateQuartz(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateRoot(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateHome(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateRuin(const ObjectCreateParams& params);
|
||||
CObjectUPtr CreateApollo(const ObjectCreateParams& params);
|
||||
void AddObjectAuto(CObject* obj);
|
||||
|
||||
private:
|
||||
|
|
|
@ -40,6 +40,7 @@ CObjectManager::CObjectManager(Gfx::CEngine* engine,
|
|||
Gfx::CParticle* particle,
|
||||
CRobotMain* main)
|
||||
: m_objectFactory(new CObjectFactory(engine, terrain, modelManager, particle, main))
|
||||
, m_nextId(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,33 +48,39 @@ CObjectManager::~CObjectManager()
|
|||
{
|
||||
}
|
||||
|
||||
bool CObjectManager::AddObject(CObject* instance)
|
||||
{
|
||||
assert(instance != nullptr);
|
||||
assert(m_table[instance->GetID()] == nullptr);
|
||||
m_table[instance->GetID()] = instance;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CObjectManager::DeleteObject(CObject* instance)
|
||||
{
|
||||
assert(instance != nullptr);
|
||||
for(auto it = m_table.begin(); it != m_table.end(); ++it)
|
||||
|
||||
instance->DeleteObject();
|
||||
|
||||
auto it = m_table.find(instance->GetID());
|
||||
if (it != m_table.end())
|
||||
{
|
||||
if(it->second == instance)
|
||||
{
|
||||
m_table.erase(it);
|
||||
return true;
|
||||
}
|
||||
m_table.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CObjectManager::DeleteAllObjects()
|
||||
{
|
||||
for (auto& it : m_table)
|
||||
{
|
||||
bool all = true;
|
||||
it.second->DeleteObject(all);
|
||||
}
|
||||
|
||||
m_table.clear();
|
||||
|
||||
m_nextId = 0;
|
||||
}
|
||||
|
||||
CObject* CObjectManager::GetObjectById(unsigned int id)
|
||||
{
|
||||
if(m_table.count(id) == 0) return nullptr;
|
||||
return m_table[id];
|
||||
return m_table[id].get();
|
||||
}
|
||||
|
||||
CObject* CObjectManager::GetObjectByRank(unsigned int id)
|
||||
|
@ -81,32 +88,46 @@ CObject* CObjectManager::GetObjectByRank(unsigned int id)
|
|||
if(id >= m_table.size()) return nullptr;
|
||||
auto it = m_table.begin();
|
||||
for(unsigned int i = 0; i < id; i++, ++it);
|
||||
return it->second;
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
const std::map<unsigned int, CObject*>& CObjectManager::GetAllObjects()
|
||||
CObject* CObjectManager::CreateObject(Math::Vector pos,
|
||||
float angle,
|
||||
ObjectType type,
|
||||
float power,
|
||||
float zoom,
|
||||
float height,
|
||||
bool trainer,
|
||||
bool toy,
|
||||
int option,
|
||||
int id)
|
||||
{
|
||||
return m_table;
|
||||
}
|
||||
if (id < 0)
|
||||
{
|
||||
id = m_nextId;
|
||||
m_nextId++;
|
||||
}
|
||||
|
||||
void CObjectManager::Flush()
|
||||
{
|
||||
m_table.clear();
|
||||
}
|
||||
assert(m_table.find(id) == m_table.end());
|
||||
|
||||
CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type,
|
||||
float power, float zoom, float height,
|
||||
bool trainer, bool toy, int option)
|
||||
{
|
||||
return m_objectFactory->CreateObject(pos, angle, type, power, zoom, height, trainer, toy, option);
|
||||
}
|
||||
ObjectCreateParams params;
|
||||
params.pos = pos;
|
||||
params.angle = angle;
|
||||
params.type = type;
|
||||
params.power = power;
|
||||
params.zoom = zoom;
|
||||
params.height = height;
|
||||
params.trainer = trainer;
|
||||
params.toy = toy;
|
||||
params.option = option;
|
||||
params.id = id;
|
||||
|
||||
bool CObjectManager::DestroyObject(int id)
|
||||
{
|
||||
CObject* obj = GetObjectById(id);
|
||||
if(obj == nullptr) return false;
|
||||
delete obj; // Destructor calls CObjectManager::DeleteObject
|
||||
return true;
|
||||
auto objectUPtr = m_objectFactory->CreateObject(params);
|
||||
CObject* objectPtr = objectUPtr.get();
|
||||
|
||||
m_table[id] = std::move(objectUPtr);
|
||||
|
||||
return objectPtr;
|
||||
}
|
||||
|
||||
CObject* CObjectManager::Radar(CObject* pThis, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
|
||||
|
@ -161,7 +182,7 @@ CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float
|
|||
pBest = nullptr;
|
||||
for ( auto it = m_table.begin() ; it != m_table.end() ; ++it )
|
||||
{
|
||||
pObj = it->second;
|
||||
pObj = it->second.get();
|
||||
if ( pObj == pThis ) continue; // pThis may be nullptr but it doesn't matter
|
||||
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
|
@ -248,4 +269,4 @@ CObject* CObjectManager::FindNearest(CObject* pThis, Math::Vector thisPosition,
|
|||
CObject* CObjectManager::FindNearest(CObject* pThis, Math::Vector thisPosition, std::vector<ObjectType> type, float maxDist, bool cbotTypes)
|
||||
{
|
||||
return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ enum RadarFilter
|
|||
FILTER_ONLYFLYING = 2,
|
||||
};
|
||||
|
||||
using CObjectMap = std::map<int, std::unique_ptr<CObject>>;
|
||||
|
||||
/**
|
||||
* \class ObjectManager
|
||||
|
@ -68,40 +69,102 @@ public:
|
|||
CRobotMain* main);
|
||||
virtual ~CObjectManager();
|
||||
|
||||
//! Registers new object
|
||||
bool AddObject(CObject* instance);
|
||||
//! Unregisters the object
|
||||
//! 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,
|
||||
int id = -1);
|
||||
|
||||
//! Deletes the object
|
||||
bool DeleteObject(CObject* instance);
|
||||
//! Deletes all objects
|
||||
void DeleteAllObjects();
|
||||
|
||||
//! Finds object by id (CObject::GetID())
|
||||
CObject* GetObjectById(unsigned int id);
|
||||
//! Gets object by id in range <0; m_table.size())
|
||||
CObject* GetObjectByRank(unsigned int id);
|
||||
//! Returns all objects
|
||||
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
|
||||
bool DestroyObject(int id);
|
||||
//! Gets object by id in range <0; number of objects - 1)
|
||||
CObject* GetObjectByRank(unsigned int id);
|
||||
|
||||
//! Returns all objects
|
||||
inline const CObjectMap& GetAllObjects()
|
||||
{
|
||||
return m_table;
|
||||
}
|
||||
|
||||
//! Finds an object, like radar() in CBot
|
||||
//@{
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
//@}
|
||||
//! Returns nearest object that's closer than maxDist
|
||||
//@{
|
||||
CObject* FindNearest(CObject* pThis, ObjectType type = OBJECT_NULL, float maxDist = 1000.0f, bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis, std::vector<ObjectType> type = std::vector<ObjectType>(), float maxDist = 1000.0f, bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis, Math::Vector thisPosition, ObjectType type = OBJECT_NULL, float maxDist = 1000.0f, bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis, Math::Vector thisPosition, std::vector<ObjectType> type = std::vector<ObjectType>(), float maxDist = 1000.0f, bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis,
|
||||
ObjectType type = OBJECT_NULL,
|
||||
float maxDist = 1000.0f,
|
||||
bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis,
|
||||
std::vector<ObjectType> type = std::vector<ObjectType>(),
|
||||
float maxDist = 1000.0f,
|
||||
bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis,
|
||||
Math::Vector thisPosition,
|
||||
ObjectType type = OBJECT_NULL,
|
||||
float maxDist = 1000.0f,
|
||||
bool cbotTypes = false);
|
||||
CObject* FindNearest(CObject* pThis,
|
||||
Math::Vector thisPosition,
|
||||
std::vector<ObjectType> type = std::vector<ObjectType>(),
|
||||
float maxDist = 1000.0f,
|
||||
bool cbotTypes = false);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
std::map<unsigned int, CObject*> m_table;
|
||||
CObjectMap m_table;
|
||||
std::unique_ptr<CObjectFactory> m_objectFactory;
|
||||
int m_nextId;
|
||||
};
|
||||
|
||||
|
|
|
@ -112,7 +112,6 @@ const float UNIT = 4.0f;
|
|||
|
||||
// Global variables.
|
||||
|
||||
long g_id; // unique identifier
|
||||
int g_build; // constructible buildings
|
||||
int g_researchDone; // research done
|
||||
long g_researchEnable; // research available
|
||||
|
@ -224,7 +223,6 @@ CRobotMain::CRobotMain(CController* controller)
|
|||
m_cameraPan = 0.0f;
|
||||
m_cameraZoom = 0.0f;
|
||||
|
||||
g_id = 0;
|
||||
g_build = 0;
|
||||
g_researchDone = 0; // no research done
|
||||
g_researchEnable = 0;
|
||||
|
@ -503,8 +501,6 @@ void CRobotMain::ChangePhase(Phase phase)
|
|||
iMan->Flush(CLASS_BRAIN);
|
||||
iMan->Flush(CLASS_PYRO);
|
||||
|
||||
m_objMan->Flush();
|
||||
|
||||
Math::Point dim, pos;
|
||||
|
||||
// Creates and hide the command console.
|
||||
|
@ -1710,9 +1706,8 @@ void CRobotMain::StartDisplayVisit(EventType event)
|
|||
// Creates the arrow to show the place.
|
||||
if (m_visitArrow != 0)
|
||||
{
|
||||
m_visitArrow->DeleteObject();
|
||||
delete m_visitArrow;
|
||||
m_visitArrow = 0;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_visitArrow);
|
||||
m_visitArrow = nullptr;
|
||||
}
|
||||
|
||||
Math::Vector goal = m_displayText->GetVisitGoal(event);
|
||||
|
@ -1775,8 +1770,7 @@ void CRobotMain::StopDisplayVisit()
|
|||
// Removes the arrow.
|
||||
if (m_visitArrow != nullptr)
|
||||
{
|
||||
m_visitArrow->DeleteObject();
|
||||
delete m_visitArrow;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_visitArrow);
|
||||
m_visitArrow = nullptr;
|
||||
}
|
||||
|
||||
|
@ -1812,10 +1806,9 @@ CObject* CRobotMain::GetSelectObject()
|
|||
CObject* CRobotMain::DeselectAll()
|
||||
{
|
||||
CObject* prev = nullptr;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetSelect()) prev = obj;
|
||||
obj->SetSelect(false);
|
||||
}
|
||||
|
@ -1936,21 +1929,14 @@ void CRobotMain::DeleteAllObjects()
|
|||
// Removes the arrow.
|
||||
if (m_visitArrow != nullptr)
|
||||
{
|
||||
m_visitArrow->DeleteObject();
|
||||
delete m_visitArrow;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_visitArrow);
|
||||
m_visitArrow = nullptr;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAXSHOWLIMIT; i++)
|
||||
FlushShowLimit(i);
|
||||
|
||||
while(m_objMan->GetAllObjects().size() > 0)
|
||||
{
|
||||
CObject* obj = m_objMan->GetAllObjects().begin()->second;
|
||||
|
||||
obj->DeleteObject(true); // destroys rapidly
|
||||
delete obj;
|
||||
}
|
||||
m_objMan->DeleteAllObjects();
|
||||
}
|
||||
|
||||
//! Selects the human
|
||||
|
@ -1976,10 +1962,9 @@ CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu)
|
|||
{
|
||||
float min = 100000.0f;
|
||||
CObject* best = 0;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj == exclu) continue;
|
||||
if (!IsSelectable(obj)) continue;
|
||||
|
||||
|
@ -2000,10 +1985,9 @@ CObject* CRobotMain::SearchNearest(Math::Vector pos, CObject* exclu)
|
|||
//! Returns the selected object
|
||||
CObject* CRobotMain::GetSelect()
|
||||
{
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetSelect())
|
||||
return obj;
|
||||
}
|
||||
|
@ -2020,9 +2004,9 @@ CObject* CRobotMain::DetectObject(Math::Point pos)
|
|||
{
|
||||
int objRank = m_engine->DetectObject(pos);
|
||||
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
if (!obj->GetActif()) continue;
|
||||
CObject* truck = obj->GetTruck();
|
||||
|
@ -2260,9 +2244,9 @@ void CRobotMain::HiliteClear()
|
|||
int rank = -1;
|
||||
m_engine->SetHighlightRank(&rank); // nothing more selected
|
||||
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
obj->SetHilite(false);
|
||||
m_map->SetHighlight(0);
|
||||
|
@ -2420,10 +2404,9 @@ void CRobotMain::HelpObject()
|
|||
//! Change the mode of the camera
|
||||
void CRobotMain::ChangeCamera()
|
||||
{
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetSelect())
|
||||
{
|
||||
if (obj->GetCameraLock()) return;
|
||||
|
@ -2565,10 +2548,9 @@ void CRobotMain::RemoteCamera(float pan, float zoom, float rTime)
|
|||
//! Cancels the current movie
|
||||
void CRobotMain::AbortMovie()
|
||||
{
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
CAuto* automat = obj->GetAuto();
|
||||
if (automat != 0)
|
||||
automat->Abort();
|
||||
|
@ -2645,17 +2627,17 @@ bool CRobotMain::EventFrame(const Event &event)
|
|||
pm = static_cast<Ui::CMap*>(pw->SearchControl(EVENT_OBJECT_MAP));
|
||||
if (pm != nullptr) pm->FlushObject();
|
||||
}
|
||||
|
||||
|
||||
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
|
||||
CObjectManager* objman = CObjectManager::GetInstancePointer();
|
||||
|
||||
CObject* toto = nullptr;
|
||||
if (!m_freePhoto)
|
||||
{
|
||||
// Advances all the robots, but not toto.
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (pm != nullptr) pm->UpdateObject(obj);
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
ObjectType type = obj->GetType();
|
||||
|
@ -2665,9 +2647,9 @@ bool CRobotMain::EventFrame(const Event &event)
|
|||
obj->EventProcess(event);
|
||||
}
|
||||
// Advances all objects transported by robots.
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck() == nullptr) continue;
|
||||
obj->EventProcess(event);
|
||||
}
|
||||
|
@ -2825,9 +2807,9 @@ bool CRobotMain::EventObject(const Event &event)
|
|||
|
||||
m_resetCreate = false;
|
||||
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
obj->EventProcess(event);
|
||||
}
|
||||
|
@ -2866,8 +2848,6 @@ void CRobotMain::ScenePerso()
|
|||
iMan->Flush(CLASS_PHYSICS);
|
||||
iMan->Flush(CLASS_BRAIN);
|
||||
iMan->Flush(CLASS_PYRO);
|
||||
|
||||
m_objMan->Flush();
|
||||
|
||||
|
||||
ChangeColor();
|
||||
|
@ -2907,7 +2887,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
|
||||
m_fixScene = fixScene;
|
||||
|
||||
g_id = 0;
|
||||
m_base = nullptr;
|
||||
|
||||
if (!resetObject)
|
||||
|
@ -4224,10 +4203,9 @@ bool CRobotMain::TestGadgetQuantity(int rank)
|
|||
float CRobotMain::SearchNearestObject(Math::Vector center, CObject *exclu)
|
||||
{
|
||||
float min = 100000.0f;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (!obj->GetActif()) continue; // inactive?
|
||||
if (obj->GetTruck() != nullptr) continue; // object carries?
|
||||
if (obj == exclu) continue;
|
||||
|
@ -4374,10 +4352,9 @@ 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 : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (!obj->GetActif()) continue; // inactive?
|
||||
if (obj->GetTruck() != nullptr) continue; // object carried?
|
||||
if (obj == metal) continue;
|
||||
|
@ -4575,16 +4552,14 @@ void CRobotMain::CompileScript(bool soluce)
|
|||
{
|
||||
int nbError = 0;
|
||||
int lastError = 0;
|
||||
|
||||
CObjectManager* objman = CObjectManager::GetInstancePointer();
|
||||
|
||||
do
|
||||
{
|
||||
lastError = nbError;
|
||||
nbError = 0;
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
|
||||
CBrain* brain = obj->GetBrain();
|
||||
|
@ -4610,9 +4585,9 @@ void CRobotMain::CompileScript(bool soluce)
|
|||
// Load all solutions.
|
||||
if (soluce)
|
||||
{
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck() != 0) continue;
|
||||
|
||||
CBrain* brain = obj->GetBrain();
|
||||
|
@ -4627,9 +4602,9 @@ void CRobotMain::CompileScript(bool soluce)
|
|||
}
|
||||
|
||||
// Start all programs according to the command "run".
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
|
||||
CBrain* brain = obj->GetBrain();
|
||||
|
@ -4708,10 +4683,9 @@ void CRobotMain::LoadFileScript(CObject *obj, const char* filename, int objRank,
|
|||
//! Saves all programs of all the robots
|
||||
void CRobotMain::SaveAllScript()
|
||||
{
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
SaveOneScript(obj);
|
||||
}
|
||||
}
|
||||
|
@ -4861,9 +4835,9 @@ bool CRobotMain::IsBusy()
|
|||
{
|
||||
if (CScriptFunctions::m_CompteurFileOpen > 0) return true;
|
||||
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
CBrain* brain = obj->GetBrain();
|
||||
if (brain != nullptr)
|
||||
|
@ -4952,12 +4926,14 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
|
|||
line->AddParam("text", new CLevelParserParam(std::string(info)));
|
||||
level->AddLine(line);
|
||||
|
||||
|
||||
//TODO: Do we need that? It's not used anyway
|
||||
line = new CLevelParserLine("Version");
|
||||
line->AddParam("maj", new CLevelParserParam(0));
|
||||
line->AddParam("min", new CLevelParserParam(1));
|
||||
level->AddLine(line);
|
||||
|
||||
|
||||
line = new CLevelParserLine("Created");
|
||||
line->AddParam("date", new CLevelParserParam(GetCurrentTimestamp()));
|
||||
level->AddLine(line);
|
||||
|
@ -4990,12 +4966,12 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
|
|||
line->AddParam("progress", new CLevelParserParam(progress));
|
||||
level->AddLine(line);
|
||||
}
|
||||
|
||||
|
||||
int objRank = 0;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetType() == OBJECT_TOTO) continue;
|
||||
if (obj->GetType() == OBJECT_FIX) continue;
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
|
@ -5017,6 +4993,7 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
|
|||
IOWriteObject(line, power);
|
||||
level->AddLine(line);
|
||||
}
|
||||
|
||||
|
||||
line = new CLevelParserLine("CreateObject");
|
||||
IOWriteObject(line, obj);
|
||||
|
@ -5043,10 +5020,9 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
|
|||
fWrite(&version, sizeof(long), 1, file); // version of CBOT
|
||||
|
||||
objRank = 0;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetType() == OBJECT_TOTO) continue;
|
||||
if (obj->GetType() == OBJECT_FIX) continue;
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
|
@ -5076,13 +5052,11 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename,
|
|||
bool toy = line->GetParam("toy")->AsBool(false);
|
||||
int option = line->GetParam("option")->AsInt(0);
|
||||
|
||||
CObject* obj = m_objMan->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, id);
|
||||
obj->SetDefRank(objRank);
|
||||
obj->SetPosition(0, pos);
|
||||
obj->SetAngle(0, dir);
|
||||
obj->SetIgnoreBuildCheck(line->GetParam("ignoreBuildCheck")->AsBool(false));
|
||||
obj->SetID(id);
|
||||
if (g_id < id) g_id = id;
|
||||
|
||||
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
|
||||
obj->SetZoom(0, zoom);
|
||||
|
@ -5205,8 +5179,6 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
|
|||
}
|
||||
delete level;
|
||||
|
||||
CObjectManager* objman = CObjectManager::GetInstancePointer();
|
||||
|
||||
// Compiles scripts.
|
||||
int nbError = 0;
|
||||
int lastError = 0;
|
||||
|
@ -5214,9 +5186,9 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
|
|||
{
|
||||
lastError = nbError;
|
||||
nbError = 0;
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
|
||||
objRank = obj->GetDefRank();
|
||||
|
@ -5228,9 +5200,9 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
|
|||
while (nbError > 0 && nbError != lastError);
|
||||
|
||||
// Starts scripts
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
if (obj->GetDefRank() == -1) continue;
|
||||
|
||||
|
@ -5256,10 +5228,9 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
|
|||
if (version == CBotProgram::GetVersion())
|
||||
{
|
||||
objRank = 0;
|
||||
for(auto it : objman->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
if (obj->GetType() == OBJECT_TOTO) continue;
|
||||
if (obj->GetType() == OBJECT_FIX) continue;
|
||||
if (obj->GetTruck() != nullptr) continue;
|
||||
|
@ -5445,8 +5416,6 @@ void CRobotMain::ResetCreate()
|
|||
iMan->Flush(CLASS_PHYSICS);
|
||||
iMan->Flush(CLASS_BRAIN);
|
||||
iMan->Flush(CLASS_PYRO);
|
||||
|
||||
m_objMan->Flush();
|
||||
|
||||
m_camera->SetType(Gfx::CAM_TYPE_DIALOG);
|
||||
|
||||
|
@ -5455,9 +5424,9 @@ void CRobotMain::ResetCreate()
|
|||
|
||||
if (!GetNiceReset()) return;
|
||||
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
ResetCap cap = obj->GetResetCap();
|
||||
if (cap == RESET_NONE) continue;
|
||||
|
@ -5487,10 +5456,9 @@ void CRobotMain::UpdateAudio(bool frame)
|
|||
Math::Vector oPos;
|
||||
|
||||
int nb = 0;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
// Do not use GetActif () because an invisible worm (underground)
|
||||
// should be regarded as existing here!
|
||||
if (obj->GetLock()) continue;
|
||||
|
@ -5612,10 +5580,9 @@ Error CRobotMain::CheckEndMission(bool frame)
|
|||
Math::Vector oPos;
|
||||
|
||||
int nb = 0;
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
|
||||
CObject* obj = it.second.get();
|
||||
// Do not use GetActif () because an invisible worm (underground)
|
||||
// should be regarded as existing here!
|
||||
if (obj->GetLock()) continue;
|
||||
|
@ -5892,9 +5859,9 @@ bool CRobotMain::GetRadar()
|
|||
if (m_cheatRadar)
|
||||
return true;
|
||||
|
||||
for(auto it : m_objMan->GetAllObjects())
|
||||
for(auto& it : m_objMan->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second;
|
||||
CObject* obj = it.second.get();
|
||||
|
||||
ObjectType type = obj->GetType();
|
||||
if (type == OBJECT_RADAR && !obj->GetLock())
|
||||
|
|
|
@ -474,9 +474,8 @@ Error CTaskBuild::IsEnded()
|
|||
|
||||
DeleteMark(m_metal->GetPosition(0), 20.0f);
|
||||
|
||||
m_metal->DeleteObject(); // removes the metal
|
||||
delete m_metal;
|
||||
m_metal = 0;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_metal);
|
||||
m_metal = nullptr;
|
||||
|
||||
m_building->SetZoom(0, 1.0f);
|
||||
m_building->SetCirVibration(Math::Vector(0.0f, 0.0f, 0.0f));
|
||||
|
@ -590,10 +589,9 @@ Error CTaskBuild::FlatFloor()
|
|||
|
||||
max = 100000.0f;
|
||||
bBase = false;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
if ( !pObj->GetActif() ) continue; // inactive?
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
if ( pObj == m_metal ) continue;
|
||||
|
@ -637,10 +635,9 @@ Error CTaskBuild::FlatFloor()
|
|||
}
|
||||
|
||||
max = 100000.0f;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
if ( !pObj->GetActif() ) continue; // inactive?
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
if ( pObj == m_metal ) continue;
|
||||
|
@ -707,10 +704,9 @@ CObject* CTaskBuild::SearchMetalObject(float &angle, float dMin, float dMax,
|
|||
min = 1000000.0f;
|
||||
pBest = 0;
|
||||
bMetal = false;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
if ( !pObj->GetActif() ) continue; // objet inactive?
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
|
||||
|
@ -761,16 +757,12 @@ CObject* CTaskBuild::SearchMetalObject(float &angle, float dMin, float dMax,
|
|||
|
||||
void CTaskBuild::DeleteMark(Math::Vector pos, float radius)
|
||||
{
|
||||
CObject* pObj;
|
||||
Math::Vector oPos;
|
||||
ObjectType type;
|
||||
float distance;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
std::vector<CObject*> objectsToDelete;
|
||||
|
||||
type = pObj->GetType();
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
CObject* obj = it.second.get();
|
||||
ObjectType type = obj->GetType();
|
||||
if ( type != OBJECT_MARKSTONE &&
|
||||
type != OBJECT_MARKURANIUM &&
|
||||
type != OBJECT_MARKKEYa &&
|
||||
|
@ -779,13 +771,17 @@ void CTaskBuild::DeleteMark(Math::Vector pos, float radius)
|
|||
type != OBJECT_MARKKEYd &&
|
||||
type != OBJECT_MARKPOWER ) continue;
|
||||
|
||||
oPos = pObj->GetPosition(0);
|
||||
distance = Math::Distance(oPos, pos);
|
||||
Math::Vector oPos = obj->GetPosition(0);
|
||||
float distance = Math::Distance(oPos, pos);
|
||||
if ( distance <= radius )
|
||||
{
|
||||
pObj->DeleteObject(); // removes the mark
|
||||
delete pObj;
|
||||
objectsToDelete.push_back(obj);
|
||||
}
|
||||
}
|
||||
|
||||
for (CObject* obj : objectsToDelete)
|
||||
{
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ bool CTaskDeleteMark::Abort()
|
|||
|
||||
void CTaskDeleteMark::DeleteMark()
|
||||
{
|
||||
CObject* pObj = CObjectManager::GetInstancePointer()->FindNearest(m_object, {
|
||||
CObject* obj = CObjectManager::GetInstancePointer()->FindNearest(m_object, {
|
||||
OBJECT_MARKPOWER,
|
||||
OBJECT_MARKSTONE,
|
||||
OBJECT_MARKURANIUM,
|
||||
|
@ -83,9 +83,8 @@ void CTaskDeleteMark::DeleteMark()
|
|||
OBJECT_MARKKEYd
|
||||
}, 8.0f/g_unit);
|
||||
|
||||
if(pObj != nullptr)
|
||||
if (obj != nullptr)
|
||||
{
|
||||
pObj->DeleteObject(); // removes the mark
|
||||
delete pObj;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
||||
}
|
||||
}
|
|
@ -156,10 +156,9 @@ int CTaskFlag::CountObject(ObjectType type)
|
|||
int count;
|
||||
|
||||
count = 0;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for (auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
if ( !pObj->GetEnable() ) continue;
|
||||
|
||||
oType = pObj->GetType();
|
||||
|
|
|
@ -508,9 +508,9 @@ CObject* CTaskGoto::WormSearch(Math::Vector &impact)
|
|||
iPos = m_object->GetPosition(0);
|
||||
min = 1000000.0f;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
oType = pObj->GetType();
|
||||
if ( oType != OBJECT_MOBILEfa &&
|
||||
|
@ -1154,9 +1154,9 @@ bool CTaskGoto::AdjustBuilding(Math::Vector &pos, float margin, float &distance)
|
|||
Math::Vector oPos;
|
||||
float dist, suppl;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetActif() ) continue;
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
|
@ -1314,10 +1314,9 @@ bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay)
|
|||
|
||||
min = 100000.0f;
|
||||
bRadius = 0.0f;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
if ( pObj == m_object ) continue;
|
||||
if ( !pObj->GetActif() ) continue;
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
|
@ -1494,9 +1493,9 @@ void CTaskGoto::ComputeRepulse(Math::Point &dir)
|
|||
bAlien = true;
|
||||
}
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue;
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
@ -1585,9 +1584,9 @@ void CTaskGoto::ComputeFlyingRepulse(float &dir)
|
|||
fac = 1.5f;
|
||||
dir = 0.0f;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue;
|
||||
if ( pObj->GetTruck() != 0 ) continue;
|
||||
|
@ -1898,9 +1897,9 @@ void CTaskGoto::BitmapObject()
|
|||
|
||||
m_object->GetCrashSphere(0, iPos, iRadius);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
|
||||
|
|
|
@ -733,10 +733,9 @@ CObject* CTaskManip::SearchTakeUnderObject(Math::Vector &pos, float dLimit)
|
|||
|
||||
min = 1000000.0f;
|
||||
pBest = 0;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
type = pObj->GetType();
|
||||
|
||||
if ( type != OBJECT_FRET &&
|
||||
|
@ -802,10 +801,9 @@ CObject* CTaskManip::SearchTakeFrontObject(bool bAdvance, Math::Vector &pos,
|
|||
min = 1000000.0f;
|
||||
pBest = 0;
|
||||
bAngle = 0.0f;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
type = pObj->GetType();
|
||||
|
||||
if ( type != OBJECT_FRET &&
|
||||
|
@ -891,10 +889,9 @@ CObject* CTaskManip::SearchTakeBackObject(bool bAdvance, Math::Vector &pos,
|
|||
min = 1000000.0f;
|
||||
pBest = 0;
|
||||
bAngle = 0.0f;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
type = pObj->GetType();
|
||||
|
||||
if ( type != OBJECT_FRET &&
|
||||
|
@ -986,9 +983,9 @@ CObject* CTaskManip::SearchOtherObject(bool bAdvance, Math::Vector &pos,
|
|||
dLimit = MARGIN_FRIEND;
|
||||
}
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue; // yourself?
|
||||
|
||||
|
@ -1341,9 +1338,9 @@ bool CTaskManip::IsFreeDeposeObject(Math::Vector pos)
|
|||
mat = m_object->GetWorldMatrix(0);
|
||||
iPos = Transform(*mat, pos);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue;
|
||||
if ( !pObj->GetActif() ) continue; // inactive?
|
||||
|
|
|
@ -328,9 +328,8 @@ Error CTaskRecover::IsEnded()
|
|||
{
|
||||
m_metal->SetZoom(0, 1.0f);
|
||||
|
||||
m_ruin->DeleteObject(); // destroys the ruin
|
||||
delete m_ruin;
|
||||
m_ruin = 0;
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(m_ruin);
|
||||
m_ruin = nullptr;
|
||||
|
||||
m_soundChannel = -1;
|
||||
|
||||
|
|
|
@ -283,9 +283,9 @@ bool CTaskReset::SearchVehicle()
|
|||
ObjectType type;
|
||||
float oRadius, dist;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for (auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue;
|
||||
|
||||
|
|
|
@ -294,9 +294,10 @@ bool CTaskSearch::CreateMark()
|
|||
|
||||
void CTaskSearch::DeleteMark(ObjectType type)
|
||||
{
|
||||
CObject* pObj;
|
||||
pObj = CObjectManager::GetInstancePointer()->FindNearest(nullptr, type);
|
||||
pObj->DeleteObject();
|
||||
delete pObj;
|
||||
CObject* obj = CObjectManager::GetInstancePointer()->FindNearest(nullptr, type);
|
||||
if (obj != nullptr)
|
||||
{
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -556,9 +556,9 @@ void CTaskShield::IncreaseShield()
|
|||
Math::Vector oPos;
|
||||
float dist, shield;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type == OBJECT_MOTHER ||
|
||||
|
|
|
@ -311,10 +311,9 @@ CObject* CTaskTake::SearchTakeObject(float &angle,
|
|||
min = 1000000.0f;
|
||||
pBest = 0;
|
||||
bAngle = 0.0f;
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
type = pObj->GetType();
|
||||
|
||||
if ( type != OBJECT_FRET &&
|
||||
|
@ -375,9 +374,9 @@ CObject* CTaskTake::SearchFriendObject(float &angle,
|
|||
iAngle = m_object->GetAngleY(0);
|
||||
iAngle = Math::NormAngle(iAngle); // 0..2*Math::PI
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue; // yourself?
|
||||
|
||||
|
@ -569,9 +568,9 @@ bool CTaskTake::IsFreeDeposeObject(Math::Vector pos)
|
|||
mat = m_object->GetWorldMatrix(0);
|
||||
iPos = Transform(*mat, pos);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( pObj == m_object ) continue;
|
||||
if ( !pObj->GetActif() ) continue; // inactive?
|
||||
|
|
|
@ -350,9 +350,9 @@ bool CTaskTerraform::Terraform()
|
|||
|
||||
m_sound->Play(SOUND_THUMP, m_terraPos);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
type = pObj->GetType();
|
||||
if ( type == OBJECT_NULL ) continue;
|
||||
|
|
|
@ -2527,10 +2527,9 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
|
|||
iType = m_object->GetType();
|
||||
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto &it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
|
||||
pObj = it.second.get();
|
||||
if ( pObj == m_object ) continue; // yourself?
|
||||
if ( pObj->GetTruck() != 0 ) continue; // object transported?
|
||||
if ( !pObj->GetEnable() ) continue; // inactive?
|
||||
|
|
|
@ -1041,12 +1041,10 @@ CBotTypResult CScriptFunctions::cDelete(CBotVar* &var, void* user)
|
|||
|
||||
bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
CObject* pObj;
|
||||
int rank;
|
||||
int exploType = 0;
|
||||
float force = 1.0f;
|
||||
|
||||
rank = var->GetValInt();
|
||||
|
||||
int rank = var->GetValInt();
|
||||
var->GetNext();
|
||||
if ( var != 0 )
|
||||
{
|
||||
|
@ -1057,9 +1055,9 @@ bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, vo
|
|||
force = var->GetValFloat();
|
||||
}
|
||||
}
|
||||
|
||||
pObj = static_cast<CObject*>(CObjectManager::GetInstancePointer()->GetObjectById(rank));
|
||||
if ( pObj == 0 )
|
||||
|
||||
CObject* obj = CObjectManager::GetInstancePointer()->GetObjectById(rank);
|
||||
if ( obj == nullptr )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -1067,11 +1065,11 @@ bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, vo
|
|||
{
|
||||
if ( exploType )
|
||||
{
|
||||
pObj->ExploObject(static_cast<ExploType>(exploType), force);
|
||||
obj->ExploObject(static_cast<ExploType>(exploType), force);
|
||||
}
|
||||
else
|
||||
{
|
||||
pObj->DeleteObject(false);
|
||||
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -138,9 +138,9 @@ bool CMainShort::CreateShortcuts()
|
|||
m_shortcuts[rank] = 0;
|
||||
rank ++;
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetActif() ) continue;
|
||||
if ( !pObj->GetSelectable() ) continue;
|
||||
|
|
|
@ -191,9 +191,9 @@ CObject* CTarget::DetectFriendObject(Math::Point pos)
|
|||
|
||||
objRank = m_engine->DetectObject(pos);
|
||||
|
||||
for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
for(auto& it : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
pObj = it.second;
|
||||
pObj = it.second.get();
|
||||
|
||||
if ( !pObj->GetActif() ) continue;
|
||||
if ( pObj->GetProxyActivate() ) continue;
|
||||
|
@ -268,6 +268,7 @@ CObject* CTarget::DetectFriendObject(Math::Point pos)
|
|||
return pTarget;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue