2015-07-26 21:39:49 +00:00
|
|
|
#include "CScriptObject.h"
|
|
|
|
#include "../CAnimSet.h"
|
|
|
|
#include "CMasterTemplate.h"
|
|
|
|
|
|
|
|
CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemplate *pTemplate)
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
mpTemplate = pTemplate;
|
2015-07-26 21:39:49 +00:00
|
|
|
mpArea = pArea;
|
|
|
|
mpLayer = pLayer;
|
|
|
|
mpProperties = nullptr;
|
|
|
|
mpTemplate->AddObject(this);
|
2015-09-26 22:55:14 +00:00
|
|
|
mpDisplayModel = nullptr;
|
2015-11-24 15:43:26 +00:00
|
|
|
mpBillboard = nullptr;
|
2015-09-26 22:55:14 +00:00
|
|
|
mpCollision = nullptr;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CScriptObject::~CScriptObject()
|
|
|
|
{
|
|
|
|
if (mpProperties) delete mpProperties;
|
|
|
|
mpTemplate->RemoveObject(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ************ DATA MANIPULATION ************
|
2015-09-18 05:53:53 +00:00
|
|
|
void CScriptObject::CopyFromTemplate(CScriptTemplate *pTemp, u32 propCount)
|
|
|
|
{
|
|
|
|
CStructTemplate *pBaseStruct = pTemp->BaseStructByCount(propCount);
|
|
|
|
delete mpProperties;
|
|
|
|
mpProperties = CPropertyStruct::CopyFromTemplate(pBaseStruct);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptObject::EvaluateProperties()
|
|
|
|
{
|
|
|
|
mpInstanceName = mpTemplate->FindInstanceName(mpProperties);
|
|
|
|
mpPosition = mpTemplate->FindPosition(mpProperties);
|
|
|
|
mpRotation = mpTemplate->FindRotation(mpProperties);
|
|
|
|
mpScale = mpTemplate->FindScale(mpProperties);
|
|
|
|
mpActive = mpTemplate->FindActive(mpProperties);
|
|
|
|
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
|
|
|
mVolumeShape = mpTemplate->VolumeShape(this);
|
|
|
|
EvaluateDisplayModel();
|
2015-11-24 15:43:26 +00:00
|
|
|
EvaluateBillboard();
|
2015-09-26 22:55:14 +00:00
|
|
|
EvaluateCollisionModel();
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptObject::EvaluateDisplayModel()
|
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
mpDisplayModel = mpTemplate->FindDisplayModel(mpProperties);
|
|
|
|
mModelToken = CToken(mpDisplayModel);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 15:43:26 +00:00
|
|
|
void CScriptObject::EvaluateBillboard()
|
|
|
|
{
|
|
|
|
mpBillboard = mpTemplate->FindBillboardTexture(mpProperties);
|
|
|
|
mBillboardToken = CToken(mpBillboard);
|
|
|
|
}
|
|
|
|
|
2015-09-26 22:55:14 +00:00
|
|
|
void CScriptObject::EvaluateCollisionModel()
|
|
|
|
{
|
|
|
|
mpCollision = mpTemplate->FindCollision(mpProperties);
|
|
|
|
mCollisionToken = CToken(mpCollision);
|
|
|
|
}
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
// ************ GETTERS ************
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyBase* CScriptObject::PropertyByIndex(u32 index) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mpProperties->PropertyByIndex(index);
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
CPropertyBase* CScriptObject::PropertyByIDString(const TString& str) const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
return mpProperties->PropertyByIDString(str);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CScriptTemplate* CScriptObject::Template() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mpTemplate;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CMasterTemplate* CScriptObject::MasterTemplate() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mpTemplate->MasterTemplate();
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CGameArea* CScriptObject::Area() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mpArea;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CScriptLayer* CScriptObject::Layer() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mpLayer;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyStruct* CScriptObject::Properties() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
return mpProperties;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
u32 CScriptObject::NumProperties() const
|
|
|
|
{
|
|
|
|
return mpProperties->Count();
|
|
|
|
}
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
u32 CScriptObject::ObjectTypeID() const
|
|
|
|
{
|
|
|
|
return mpTemplate->ObjectID();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CScriptObject::InstanceID() const
|
|
|
|
{
|
|
|
|
return mInstanceID;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CScriptObject::NumInLinks() const
|
|
|
|
{
|
|
|
|
return mInConnections.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 CScriptObject::NumOutLinks() const
|
|
|
|
{
|
|
|
|
return mOutConnections.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const SLink& CScriptObject::InLink(u32 index) const
|
|
|
|
{
|
|
|
|
return mInConnections[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const SLink& CScriptObject::OutLink(u32 index) const
|
|
|
|
{
|
|
|
|
return mOutConnections[index];
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
TString CScriptObject::InstanceName() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpInstanceName)
|
|
|
|
return mpInstanceName->Get();
|
|
|
|
else
|
|
|
|
return "";
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CVector3f CScriptObject::Position() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpPosition)
|
|
|
|
return mpPosition->Get();
|
|
|
|
else
|
|
|
|
return CVector3f::skZero;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CVector3f CScriptObject::Rotation() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpRotation)
|
|
|
|
return mpRotation->Get();
|
|
|
|
else
|
|
|
|
return CVector3f::skZero;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CVector3f CScriptObject::Scale() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpScale)
|
|
|
|
return mpScale->Get();
|
|
|
|
else
|
|
|
|
return CVector3f::skOne;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
bool CScriptObject::IsActive() const
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpActive)
|
|
|
|
return mpActive->Get();
|
|
|
|
else
|
|
|
|
return true;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
void CScriptObject::SetPosition(const CVector3f& newPos)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpPosition) mpPosition->Set(newPos);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
void CScriptObject::SetRotation(const CVector3f& newRot)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpRotation) mpRotation->Set(newRot);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
void CScriptObject::SetScale(const CVector3f& newScale)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpScale) mpScale->Set(newScale);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void CScriptObject::SetName(const TString& newName)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpInstanceName) mpInstanceName->Set(newName);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
void CScriptObject::SetActive(bool isActive)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-09-18 05:53:53 +00:00
|
|
|
if (mpActive) mpActive->Set(isActive);
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CPropertyStruct* CScriptObject::LightParameters() const
|
|
|
|
{
|
|
|
|
return mpLightParameters;
|
|
|
|
}
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
CModel* CScriptObject::GetDisplayModel() const
|
|
|
|
{
|
|
|
|
return mpDisplayModel;
|
|
|
|
}
|
|
|
|
|
2015-11-24 15:43:26 +00:00
|
|
|
CTexture* CScriptObject::GetBillboard() const
|
|
|
|
{
|
|
|
|
return mpBillboard;
|
|
|
|
}
|
|
|
|
|
2015-09-26 22:55:14 +00:00
|
|
|
CCollisionMeshGroup* CScriptObject::GetCollision() const
|
|
|
|
{
|
|
|
|
return mpCollision;
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:53:53 +00:00
|
|
|
EVolumeShape CScriptObject::VolumeShape() const
|
|
|
|
{
|
|
|
|
return mVolumeShape;
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|