Refactored object creation
parent
a0f0a53d59
commit
57646c0c7b
|
@ -67,7 +67,6 @@
|
||||||
#include "object/object_manager.h"
|
#include "object/object_manager.h"
|
||||||
|
|
||||||
#include "object/auto/auto.h"
|
#include "object/auto/auto.h"
|
||||||
#include "object/auto/autobase.h"
|
|
||||||
|
|
||||||
#include "object/motion/motion.h"
|
#include "object/motion/motion.h"
|
||||||
#include "object/motion/motionhuman.h"
|
#include "object/motion/motionhuman.h"
|
||||||
|
@ -1589,8 +1588,11 @@ void CRobotMain::StartDisplayVisit(EventType event)
|
||||||
m_visitArrow = nullptr;
|
m_visitArrow = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Vector goal = m_displayText->GetVisitGoal(event);
|
ObjectCreateParams params;
|
||||||
m_visitArrow = m_objMan->CreateObject(goal, 0.0f, OBJECT_SHOW, -1.0f, 1.0f, 10.0f);
|
params.pos = m_displayText->GetVisitGoal(event);
|
||||||
|
params.type = OBJECT_SHOW;
|
||||||
|
params.height = 10.0f;
|
||||||
|
m_visitArrow = m_objMan->CreateObject(params);
|
||||||
|
|
||||||
m_visitPos = m_visitArrow->GetPosition();
|
m_visitPos = m_visitArrow->GetPosition();
|
||||||
m_visitPosArrow = m_visitPos;
|
m_visitPosArrow = m_visitPos;
|
||||||
|
@ -3289,7 +3291,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
|
|
||||||
if (line->GetCommand() == "LevelController" && m_sceneReadPath.empty())
|
if (line->GetCommand() == "LevelController" && m_sceneReadPath.empty())
|
||||||
{
|
{
|
||||||
m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f);
|
m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER);
|
||||||
if (m_controller->Implements(ObjectInterfaceType::Programmable))
|
if (m_controller->Implements(ObjectInterfaceType::Programmable))
|
||||||
{
|
{
|
||||||
CProgrammableObject* programmable = dynamic_cast<CProgrammableObject*>(m_controller);
|
CProgrammableObject* programmable = dynamic_cast<CProgrammableObject*>(m_controller);
|
||||||
|
@ -3306,137 +3308,49 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
|
|
||||||
if (line->GetCommand() == "CreateObject" && m_sceneReadPath.empty())
|
if (line->GetCommand() == "CreateObject" && m_sceneReadPath.empty())
|
||||||
{
|
{
|
||||||
ObjectType type = line->GetParam("type")->AsObjectType();
|
ObjectCreateParams params = CObject::ReadCreateParams(line.get());
|
||||||
|
|
||||||
float objectProgress = static_cast<float>(rankObj) / static_cast<float>(numObjects);
|
float objectProgress = static_cast<float>(rankObj) / static_cast<float>(numObjects);
|
||||||
std::string details = StrUtils::ToString<int>(rankObj+1)+" / "+StrUtils::ToString<int>(numObjects);
|
std::string details = StrUtils::ToString<int>(rankObj+1)+" / "+StrUtils::ToString<int>(numObjects);
|
||||||
#if DEV_BUILD
|
#if DEV_BUILD
|
||||||
// Object categories may spoil the level a bit, so hide them in release builds
|
// Object categories may spoil the level a bit, so hide them in release builds
|
||||||
details += ": "+CLevelParserParam::FromObjectType(type);
|
details += ": "+CLevelParserParam::FromObjectType(params.type);
|
||||||
#endif
|
#endif
|
||||||
m_ui->GetLoadingScreen()->SetProgress(0.25f+objectProgress*0.5f, RT_LOADING_OBJECTS, details);
|
m_ui->GetLoadingScreen()->SetProgress(0.25f+objectProgress*0.5f, RT_LOADING_OBJECTS, details);
|
||||||
|
|
||||||
Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
|
|
||||||
float dirAngle = line->GetParam("dir")->AsFloat(0.0f)*Math::PI;
|
|
||||||
bool trainer;
|
|
||||||
CObject* obj = nullptr;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
obj = m_objMan->CreateObject(
|
CObject* obj = m_objMan->CreateObject(params);
|
||||||
pos, dirAngle,
|
obj->Read(line.get());
|
||||||
type,
|
|
||||||
line->GetParam("power")->AsFloat(1.0f),
|
|
||||||
line->GetParam("z")->AsFloat(1.0f),
|
|
||||||
line->GetParam("h")->AsFloat(0.0f),
|
|
||||||
trainer = line->GetParam("trainer")->AsBool(false),
|
|
||||||
line->GetParam("toy")->AsBool(false),
|
|
||||||
line->GetParam("option")->AsInt(0),
|
|
||||||
line->GetParam("team")->AsInt(0)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (const CObjectCreateException& e)
|
|
||||||
{
|
|
||||||
GetLogger()->Error("Error loading level object: %s\n", e.what());
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_fixScene && type == OBJECT_HUMAN)
|
if (m_fixScene && obj->GetType() == OBJECT_HUMAN)
|
||||||
{
|
|
||||||
assert(obj->Implements(ObjectInterfaceType::Movable));
|
|
||||||
CMotion* motion = dynamic_cast<CMovableObject*>(obj)->GetMotion();
|
|
||||||
if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f);
|
|
||||||
if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->Implements(ObjectInterfaceType::Old)) // TODO: temporary hack
|
|
||||||
{
|
|
||||||
COldObject* oldObj = dynamic_cast<COldObject*>(obj);
|
|
||||||
|
|
||||||
oldObj->SetDefRank(rankObj); // TODO: do we really need this?
|
|
||||||
|
|
||||||
if (type == OBJECT_BASE)
|
|
||||||
m_base = oldObj;
|
|
||||||
|
|
||||||
if (line->GetParam("select")->AsBool(false))
|
|
||||||
sel = oldObj;
|
|
||||||
|
|
||||||
// TODO: everything below should go to CObject::Read() function
|
|
||||||
// In fact, we could give CLevelParserLine as parameter to CreateObject() in the first place
|
|
||||||
|
|
||||||
Gfx::CameraType cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL);
|
|
||||||
if (cType != Gfx::CAM_TYPE_NULL)
|
|
||||||
oldObj->SetCameraType(cType);
|
|
||||||
|
|
||||||
oldObj->SetCameraDist(line->GetParam("cameraDist")->AsFloat(50.0f));
|
|
||||||
oldObj->SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
|
|
||||||
|
|
||||||
Gfx::PyroType pType = line->GetParam("pyro")->AsPyroType(Gfx::PT_NULL);
|
|
||||||
if (pType != Gfx::PT_NULL)
|
|
||||||
{
|
{
|
||||||
m_engine->GetPyroManager()->Create(pType, oldObj);
|
assert(obj->Implements(ObjectInterfaceType::Movable));
|
||||||
|
CMotion* motion = dynamic_cast<CMovableObject*>(obj)->GetMotion();
|
||||||
|
if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f);
|
||||||
|
if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == OBJECT_INFO)
|
if (obj->Implements(ObjectInterfaceType::Controllable) && line->GetParam("select")->AsBool(false))
|
||||||
|
sel = obj;
|
||||||
|
|
||||||
|
if (obj->GetType() == OBJECT_BASE)
|
||||||
|
m_base = obj;
|
||||||
|
|
||||||
|
if (obj->Implements(ObjectInterfaceType::Old))
|
||||||
|
dynamic_cast<COldObject*>(obj)->SetDefRank(rankObj); // TODO: do we really need this?
|
||||||
|
|
||||||
|
if (obj->Implements(ObjectInterfaceType::Programmable))
|
||||||
{
|
{
|
||||||
CExchangePost* exchangePost = static_cast<CExchangePost*>(oldObj);
|
CProgrammableObject* programmable = dynamic_cast<CProgrammableObject*>(obj);
|
||||||
exchangePost->ReadInfo(line.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets the parameters of the command line.
|
|
||||||
if (line->GetParam("cmdline")->IsDefined())
|
|
||||||
{
|
|
||||||
const auto& cmdline = line->GetParam("cmdline")->AsArray();
|
|
||||||
for (unsigned int i = 0; i < cmdline.size(); i++)
|
|
||||||
{
|
|
||||||
oldObj->SetCmdLine(i, cmdline[i]->AsFloat());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool selectable = line->GetParam("selectable")->AsBool(true);
|
|
||||||
oldObj->SetSelectable(selectable);
|
|
||||||
oldObj->SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
|
|
||||||
oldObj->SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
|
|
||||||
oldObj->SetRange(line->GetParam("range")->AsFloat(30.0f));
|
|
||||||
oldObj->SetShield(line->GetParam("shield")->AsFloat(1.0f));
|
|
||||||
oldObj->SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f));
|
|
||||||
oldObj->SetCollisions(line->GetParam("clip")->AsBool(true));
|
|
||||||
oldObj->SetCheckToken(!line->GetParam("checkToken")->IsDefined() ? trainer || !selectable : line->GetParam("checkToken")->AsBool(true));
|
|
||||||
// SetManual will affect bot speed
|
|
||||||
if (type == OBJECT_MOBILEdr)
|
|
||||||
{
|
|
||||||
oldObj->SetManual(!trainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Math::Vector zoom = line->GetParam("zoom")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f));
|
|
||||||
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
|
|
||||||
oldObj->SetScale(zoom);
|
|
||||||
|
|
||||||
// only used in AlienWorm lines
|
|
||||||
if (type == OBJECT_WORM)
|
|
||||||
{
|
|
||||||
CMotion* motion = oldObj->GetMotion();
|
|
||||||
if (motion != nullptr && line->GetParam("param")->IsDefined())
|
|
||||||
{
|
|
||||||
const auto& p = line->GetParam("param")->AsArray();
|
|
||||||
for (unsigned int i = 0; i < 10 && i < p.size(); i++)
|
|
||||||
{
|
|
||||||
motion->SetParam(i, p[i]->AsFloat());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int run = -1;
|
|
||||||
std::map<int, Program*> loadedPrograms;
|
|
||||||
if (oldObj->Implements(ObjectInterfaceType::Programmable))
|
|
||||||
{
|
|
||||||
CProgrammableObject* programmable = dynamic_cast<CProgrammableObject*>(oldObj);
|
|
||||||
|
|
||||||
|
std::map<int, Program*> loadedPrograms;
|
||||||
bool allFilled = true;
|
bool allFilled = true;
|
||||||
for (int i = 0; i < 10 || allFilled; i++)
|
for (int i = 0; i < 10 || allFilled; i++)
|
||||||
{
|
{
|
||||||
std::string op = "script" + boost::lexical_cast<std::string>(i+1); // script1..script10
|
std::string op = "script" + StrUtils::ToString<int>(i+1); // script1..script10
|
||||||
std::string opReadOnly = "scriptReadOnly" + boost::lexical_cast<std::string>(i+1); // scriptReadOnly1..scriptReadOnly10
|
std::string opReadOnly = "scriptReadOnly" + StrUtils::ToString<int>(i+1); // scriptReadOnly1..scriptReadOnly10
|
||||||
std::string opRunnable = "scriptRunnable" + boost::lexical_cast<std::string>(i+1); // scriptRunnable1..scriptRunnable10
|
std::string opRunnable = "scriptRunnable" + StrUtils::ToString<int>(i+1); // scriptRunnable1..scriptRunnable10
|
||||||
if (line->GetParam(op)->IsDefined())
|
if (line->GetParam(op)->IsDefined())
|
||||||
{
|
{
|
||||||
Program* program = programmable->AddProgram();
|
Program* program = programmable->AddProgram();
|
||||||
|
@ -3454,37 +3368,17 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
int i = line->GetParam("run")->AsInt(0);
|
int i = line->GetParam("run")->AsInt(0);
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
{
|
{
|
||||||
run = i-1;
|
programmable->SetScriptRun(loadedPrograms[i-1]);
|
||||||
programmable->SetScriptRun(loadedPrograms[run]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CAuto* automat = oldObj->GetAuto();
|
|
||||||
if (automat != nullptr)
|
|
||||||
{
|
|
||||||
type = line->GetParam("autoType")->AsObjectType(OBJECT_NULL);
|
|
||||||
automat->SetType(type);
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
std::string op = "autoValue" + boost::lexical_cast<std::string>(i+1); // autoValue1..autoValue5
|
|
||||||
automat->SetValue(i, line->GetParam(op)->AsFloat(0.0f));
|
|
||||||
}
|
|
||||||
automat->SetString(const_cast<char*>(line->GetParam("autoString")->AsPath("ai", "").c_str()));
|
|
||||||
|
|
||||||
int i = line->GetParam("run")->AsInt(-1);
|
|
||||||
if (i != -1)
|
|
||||||
{
|
|
||||||
if (i != PARAM_FIXSCENE &&
|
|
||||||
!m_settings->GetMovies()) i = 0;
|
|
||||||
automat->Start(i); // starts the film
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soluce && oldObj->Implements(ObjectInterfaceType::Programmable) && line->GetParam("soluce")->IsDefined())
|
if (soluce && obj->Implements(ObjectInterfaceType::Programmable) && line->GetParam("soluce")->IsDefined())
|
||||||
dynamic_cast<CProgrammableObject*>(oldObj)
|
dynamic_cast<CProgrammableObject*>(obj)->SetSoluceName(line->GetParam("soluce")->AsPath("ai"));
|
||||||
->SetSoluceName(line->GetParam("soluce")->AsPath("ai"));
|
}
|
||||||
|
catch (const CObjectCreateException& e)
|
||||||
if (line->GetParam("reset")->AsBool(false))
|
{
|
||||||
oldObj->SetAnimateOnReset(true);
|
GetLogger()->Error("Error loading level object: %s\n", e.what());
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
rankObj ++;
|
rankObj ++;
|
||||||
|
@ -3764,11 +3658,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
if (m_base == nullptr && // no main base?
|
if (m_base == nullptr && // no main base?
|
||||||
!m_fixScene) // interractive scene?
|
!m_fixScene) // interractive scene?
|
||||||
{
|
{
|
||||||
CObject* obj;
|
CObject* obj = sel;
|
||||||
if (sel == nullptr)
|
if (sel == nullptr)
|
||||||
obj = SearchHuman();
|
obj = SearchHuman();
|
||||||
else
|
|
||||||
obj = sel;
|
|
||||||
|
|
||||||
if (obj != nullptr)
|
if (obj != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -3810,6 +3702,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
|
|
||||||
void CRobotMain::LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase)
|
void CRobotMain::LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase)
|
||||||
{
|
{
|
||||||
|
m_ui->ShowLoadingScreen(false);
|
||||||
|
|
||||||
GetLogger()->Error("%s\n", error.c_str());
|
GetLogger()->Error("%s\n", error.c_str());
|
||||||
GetLogger()->Error("%s\n", exception.what());
|
GetLogger()->Error("%s\n", exception.what());
|
||||||
ChangePhase(exitPhase);
|
ChangePhase(exitPhase);
|
||||||
|
@ -4947,55 +4841,45 @@ void CRobotMain::IOWriteSceneFinished()
|
||||||
//! Resumes the game
|
//! Resumes the game
|
||||||
CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, const std::string& objCounterText, float objectProgress, int objRank)
|
CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename, const std::string& objCounterText, float objectProgress, int objRank)
|
||||||
{
|
{
|
||||||
Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
|
ObjectCreateParams params = CObject::ReadCreateParams(line);
|
||||||
Math::Vector dir = line->GetParam("angle")->AsPoint()*(Math::PI/180.0f);
|
params.power = -1.0f;
|
||||||
Math::Vector zoom = line->GetParam("zoom")->AsPoint();
|
params.id = line->GetParam("id")->AsInt();
|
||||||
|
|
||||||
ObjectType type = line->GetParam("type")->AsObjectType();
|
|
||||||
int id = line->GetParam("id")->AsInt();
|
|
||||||
|
|
||||||
std::string details = objCounterText;
|
std::string details = objCounterText;
|
||||||
#if DEV_BUILD
|
#if DEV_BUILD
|
||||||
// Object categories may spoil the level a bit, so hide them in release builds
|
// Object categories may spoil the level a bit, so hide them in release builds
|
||||||
details += ": "+CLevelParserParam::FromObjectType(type);
|
details += ": "+CLevelParserParam::FromObjectType(params.type);
|
||||||
#endif
|
#endif
|
||||||
m_ui->GetLoadingScreen()->SetProgress(0.25f+objectProgress*0.5f, RT_LOADING_OBJECTS_SAVED, details);
|
m_ui->GetLoadingScreen()->SetProgress(0.25f+objectProgress*0.5f, RT_LOADING_OBJECTS_SAVED, details);
|
||||||
|
|
||||||
bool trainer = line->GetParam("trainer")->AsBool(false);
|
CObject* obj = m_objMan->CreateObject(params);
|
||||||
bool toy = line->GetParam("toy")->AsBool(false);
|
|
||||||
int option = line->GetParam("option")->AsInt(0);
|
|
||||||
int team = line->GetParam("team")->AsInt(0);
|
|
||||||
|
|
||||||
CObject* obj = m_objMan->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option, team, id);
|
|
||||||
|
|
||||||
if (obj->Implements(ObjectInterfaceType::Old))
|
if (obj->Implements(ObjectInterfaceType::Old))
|
||||||
{
|
{
|
||||||
COldObject* oldObj = dynamic_cast<COldObject*>(obj);
|
COldObject* oldObj = dynamic_cast<COldObject*>(obj);
|
||||||
|
|
||||||
oldObj->SetDefRank(objRank);
|
oldObj->SetRotation(line->GetParam("angle")->AsPoint() * Math::DEG_TO_RAD); // Who decided to call this argument differently than in main scene files? :/
|
||||||
oldObj->SetPosition(pos);
|
// TODO: Also, why doesn't CStaticObject implement SetRotation?
|
||||||
oldObj->SetRotation(dir);
|
|
||||||
|
|
||||||
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
|
oldObj->SetDefRank(objRank);
|
||||||
oldObj->SetScale(zoom);
|
|
||||||
|
|
||||||
for (int i = 1; i < OBJECTMAXPART; i++)
|
for (int i = 1; i < OBJECTMAXPART; i++)
|
||||||
{
|
{
|
||||||
if (oldObj->GetObjectRank(i) == -1) continue;
|
if (oldObj->GetObjectRank(i) == -1) continue;
|
||||||
|
|
||||||
pos = line->GetParam(std::string("p")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
|
Math::Vector pos = line->GetParam(std::string("p")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
|
||||||
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
|
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
|
||||||
{
|
{
|
||||||
oldObj->SetPartPosition(i, pos*g_unit);
|
oldObj->SetPartPosition(i, pos*g_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = line->GetParam(std::string("a")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
|
Math::Vector dir = line->GetParam(std::string("a")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
|
||||||
if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f)
|
if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f)
|
||||||
{
|
{
|
||||||
oldObj->SetPartRotation(i, dir*(Math::PI/180.0f));
|
oldObj->SetPartRotation(i, dir*(Math::PI/180.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
zoom = line->GetParam(std::string("z")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
|
Math::Vector zoom = line->GetParam(std::string("z")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
|
||||||
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
|
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
|
||||||
{
|
{
|
||||||
oldObj->SetPartScale(i, zoom);
|
oldObj->SetPartScale(i, zoom);
|
||||||
|
@ -5003,7 +4887,7 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == OBJECT_BASE) m_base = obj;
|
if (obj->GetType() == OBJECT_BASE) m_base = obj;
|
||||||
|
|
||||||
obj->Read(line);
|
obj->Read(line);
|
||||||
|
|
||||||
|
|
|
@ -417,11 +417,11 @@ bool CAuto::Write(CLevelParserLine* line)
|
||||||
|
|
||||||
bool CAuto::Read(CLevelParserLine* line)
|
bool CAuto::Read(CLevelParserLine* line)
|
||||||
{
|
{
|
||||||
m_type = line->GetParam("aType")->AsObjectType();
|
m_type = line->GetParam("aType")->AsObjectType(m_type);
|
||||||
m_bBusy = line->GetParam("aBusy")->AsBool();
|
m_bBusy = line->GetParam("aBusy")->AsBool(m_bBusy);
|
||||||
m_time = line->GetParam("aTime")->AsFloat();
|
m_time = line->GetParam("aTime")->AsFloat(m_time);
|
||||||
m_progressTime = line->GetParam("aProgressTime")->AsFloat();
|
m_progressTime = line->GetParam("aProgressTime")->AsFloat(m_progressTime);
|
||||||
m_progressTotal = line->GetParam("aProgressTotal")->AsFloat();
|
m_progressTotal = line->GetParam("aProgressTotal")->AsFloat(m_progressTotal);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
#include "level/robotmain.h"
|
#include "level/robotmain.h"
|
||||||
|
|
||||||
|
#include "level/parser/parserline.h"
|
||||||
|
#include "level/parser/parserparam.h"
|
||||||
|
|
||||||
#include "graphics/model/model_crash_sphere.h"
|
#include "graphics/model/model_crash_sphere.h"
|
||||||
|
|
||||||
#include "script/scriptfunc.h"
|
#include "script/scriptfunc.h"
|
||||||
|
@ -51,6 +54,22 @@ CObject::~CObject()
|
||||||
CScriptFunctions::DestroyObjectVar(m_botVar, true);
|
CScriptFunctions::DestroyObjectVar(m_botVar, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectCreateParams CObject::ReadCreateParams(CLevelParserLine* line)
|
||||||
|
{
|
||||||
|
ObjectCreateParams params;
|
||||||
|
params.pos = line->GetParam("pos")->AsPoint()*g_unit;
|
||||||
|
params.angle = line->GetParam("dir")->AsFloat(0.0f)*Math::PI;
|
||||||
|
params.type = line->GetParam("type")->AsObjectType();
|
||||||
|
params.power = line->GetParam("power")->AsFloat(1.0f);
|
||||||
|
params.height = line->GetParam("h")->AsFloat(0.0f);
|
||||||
|
params.trainer = line->GetParam("trainer")->AsBool(false);
|
||||||
|
params.toy = line->GetParam("toy")->AsBool(false); // TODO: Remove
|
||||||
|
params.option = line->GetParam("option")->AsInt(0);
|
||||||
|
params.team = line->GetParam("team")->AsInt(0);
|
||||||
|
//params.id = line->GetParam("id")->AsInt(-1);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
void CObject::SetCrashSpheres(const std::vector<Gfx::ModelCrashSphere>& crashSpheres)
|
void CObject::SetCrashSpheres(const std::vector<Gfx::ModelCrashSphere>& crashSpheres)
|
||||||
{
|
{
|
||||||
for (const auto& crashSphere : crashSpheres)
|
for (const auto& crashSphere : crashSpheres)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "object/crash_sphere.h"
|
#include "object/crash_sphere.h"
|
||||||
#include "object/object_interface_type.h"
|
#include "object/object_interface_type.h"
|
||||||
#include "object/old_object_interface.h"
|
#include "object/old_object_interface.h"
|
||||||
|
#include "object/object_create_params.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -82,6 +83,8 @@ public:
|
||||||
virtual void Write(CLevelParserLine* line) = 0;
|
virtual void Write(CLevelParserLine* line) = 0;
|
||||||
//! Reads object properties from line in level file
|
//! Reads object properties from line in level file
|
||||||
virtual void Read(CLevelParserLine* line) = 0;
|
virtual void Read(CLevelParserLine* line) = 0;
|
||||||
|
//! Reads params required for object creation
|
||||||
|
static ObjectCreateParams ReadCreateParams(CLevelParserLine* line);
|
||||||
|
|
||||||
//! Updates all interface controls
|
//! Updates all interface controls
|
||||||
virtual void UpdateInterface() {};
|
virtual void UpdateInterface() {};
|
||||||
|
|
|
@ -29,7 +29,6 @@ struct ObjectCreateParams
|
||||||
float angle;
|
float angle;
|
||||||
ObjectType type;
|
ObjectType type;
|
||||||
float power;
|
float power;
|
||||||
float zoom;
|
|
||||||
float height;
|
float height;
|
||||||
bool trainer;
|
bool trainer;
|
||||||
bool toy;
|
bool toy;
|
||||||
|
@ -43,7 +42,6 @@ struct ObjectCreateParams
|
||||||
angle = 0.0f;
|
angle = 0.0f;
|
||||||
type = OBJECT_NULL;
|
type = OBJECT_NULL;
|
||||||
power = -1.0f;
|
power = -1.0f;
|
||||||
zoom = 1.0f;
|
|
||||||
height = 0.0f;
|
height = 0.0f;
|
||||||
trainer = false;
|
trainer = false;
|
||||||
toy = false;
|
toy = false;
|
||||||
|
|
|
@ -139,30 +139,13 @@ CObject* CObjectManager::CreateObject(ObjectCreateParams params)
|
||||||
return objectPtr;
|
return objectPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CObject* CObjectManager::CreateObject(Math::Vector pos,
|
CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type, float power)
|
||||||
float angle,
|
|
||||||
ObjectType type,
|
|
||||||
float power,
|
|
||||||
float zoom,
|
|
||||||
float height,
|
|
||||||
bool trainer,
|
|
||||||
bool toy,
|
|
||||||
int option,
|
|
||||||
int team,
|
|
||||||
int id)
|
|
||||||
{
|
{
|
||||||
ObjectCreateParams params;
|
ObjectCreateParams params;
|
||||||
params.pos = pos;
|
params.pos = pos;
|
||||||
params.angle = angle;
|
params.angle = angle;
|
||||||
params.type = type;
|
params.type = type;
|
||||||
params.power = power;
|
params.power = power;
|
||||||
params.zoom = zoom;
|
|
||||||
params.height = height;
|
|
||||||
params.trainer = trainer;
|
|
||||||
params.toy = toy;
|
|
||||||
params.option = option;
|
|
||||||
params.team = team;
|
|
||||||
params.id = id;
|
|
||||||
|
|
||||||
return CreateObject(params);
|
return CreateObject(params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,17 +139,7 @@ public:
|
||||||
//! Creates an object
|
//! Creates an object
|
||||||
//@{
|
//@{
|
||||||
CObject* CreateObject(ObjectCreateParams params);
|
CObject* CreateObject(ObjectCreateParams params);
|
||||||
CObject* CreateObject(Math::Vector pos,
|
CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.0f);
|
||||||
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 team = 0,
|
|
||||||
int id = -1);
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
//! Deletes the object
|
//! Deletes the object
|
||||||
|
|
|
@ -45,11 +45,14 @@
|
||||||
#include "object/object_manager.h"
|
#include "object/object_manager.h"
|
||||||
|
|
||||||
#include "object/auto/auto.h"
|
#include "object/auto/auto.h"
|
||||||
|
#include "object/auto/autobase.h"
|
||||||
#include "object/auto/autojostle.h"
|
#include "object/auto/autojostle.h"
|
||||||
|
|
||||||
#include "object/motion/motion.h"
|
#include "object/motion/motion.h"
|
||||||
#include "object/motion/motionvehicle.h"
|
#include "object/motion/motionvehicle.h"
|
||||||
|
|
||||||
|
#include "object/subclass/exchange_post.h"
|
||||||
|
|
||||||
#include "object/task/taskmanager.h"
|
#include "object/task/taskmanager.h"
|
||||||
|
|
||||||
#include "physics/physics.h"
|
#include "physics/physics.h"
|
||||||
|
@ -979,7 +982,7 @@ void COldObject::Write(CLevelParserLine* line)
|
||||||
|
|
||||||
if ( GetAnimateOnReset() )
|
if ( GetAnimateOnReset() )
|
||||||
{
|
{
|
||||||
line->AddParam("resetCap", MakeUnique<CLevelParserParam>(GetAnimateOnReset()));
|
line->AddParam("reset", MakeUnique<CLevelParserParam>(GetAnimateOnReset()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_bVirusMode )
|
if ( m_bVirusMode )
|
||||||
|
@ -1030,43 +1033,111 @@ void COldObject::Write(CLevelParserLine* line)
|
||||||
|
|
||||||
void COldObject::Read(CLevelParserLine* line)
|
void COldObject::Read(CLevelParserLine* line)
|
||||||
{
|
{
|
||||||
Gfx::CameraType cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL);
|
Math::Vector zoom = line->GetParam("zoom")->AsPoint(Math::Vector(1.0f, 1.0f, 1.0f));
|
||||||
if ( cType != Gfx::CAM_TYPE_NULL )
|
if (zoom.x != 1.0f || zoom.y != 1.0f || zoom.z != 1.0f)
|
||||||
{
|
SetScale(zoom);
|
||||||
SetCameraType(cType);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (line->GetParam("camera")->IsDefined())
|
||||||
|
SetCameraType(line->GetParam("camera")->AsCameraType());
|
||||||
SetCameraDist(line->GetParam("cameraDist")->AsFloat(50.0f));
|
SetCameraDist(line->GetParam("cameraDist")->AsFloat(50.0f));
|
||||||
SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
|
SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
|
||||||
SetEnergyLevel(line->GetParam("energy")->AsFloat(0.0f));
|
|
||||||
SetShield(line->GetParam("shield")->AsFloat(1.0f));
|
if (line->GetParam("pyro")->IsDefined())
|
||||||
SetSelectable(line->GetParam("selectable")->AsBool(true));
|
m_engine->GetPyroManager()->Create(line->GetParam("pyro")->AsPyroType(), this);
|
||||||
SetFixed(line->GetParam("fixed")->AsBool(false));
|
|
||||||
SetCollisions(line->GetParam("clip")->AsBool(true));
|
|
||||||
SetLock(line->GetParam("lock")->AsBool(false));
|
|
||||||
SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
|
SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
|
||||||
SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
|
SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
|
||||||
SetRange(line->GetParam("range")->AsFloat(30.0f));
|
SetCollisions(line->GetParam("clip")->AsBool(true));
|
||||||
SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f));
|
SetAnimateOnReset(line->GetParam("reset")->AsBool(false));
|
||||||
|
if (Implements(ObjectInterfaceType::Controllable))
|
||||||
|
{
|
||||||
|
SetSelectable(line->GetParam("selectable")->AsBool(true));
|
||||||
|
}
|
||||||
|
if (Implements(ObjectInterfaceType::JetFlying))
|
||||||
|
{
|
||||||
|
SetRange(line->GetParam("range")->AsFloat(30.0f));
|
||||||
|
}
|
||||||
|
if (Implements(ObjectInterfaceType::Shielded))
|
||||||
|
{
|
||||||
|
SetShield(line->GetParam("shield")->AsFloat(1.0f));
|
||||||
|
SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f));
|
||||||
|
}
|
||||||
|
if (Implements(ObjectInterfaceType::Programmable))
|
||||||
|
{
|
||||||
|
SetCheckToken(!line->GetParam("checkToken")->IsDefined() ? GetSelectable() : line->GetParam("checkToken")->AsBool(true));
|
||||||
|
|
||||||
|
if (line->GetParam("cmdline")->IsDefined())
|
||||||
|
{
|
||||||
|
const auto& cmdline = line->GetParam("cmdline")->AsArray();
|
||||||
|
for (unsigned int i = 0; i < cmdline.size(); i++)
|
||||||
|
{
|
||||||
|
SetCmdLine(i, cmdline[i]->AsFloat());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_type == OBJECT_INFO)
|
||||||
|
{
|
||||||
|
CExchangePost* exchangePost = dynamic_cast<CExchangePost*>(this);
|
||||||
|
assert(exchangePost != nullptr);
|
||||||
|
exchangePost->ReadInfo(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetManual will affect bot speed
|
||||||
|
if (m_type == OBJECT_MOBILEdr)
|
||||||
|
{
|
||||||
|
// TODO: Merge these two settings?
|
||||||
|
SetManual(!GetTrainer());
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlienWorm time up/down
|
||||||
|
// TODO: Refactor function names
|
||||||
|
if (m_type == OBJECT_WORM)
|
||||||
|
{
|
||||||
|
assert(Implements(ObjectInterfaceType::Movable));
|
||||||
|
CMotion* motion = GetMotion();
|
||||||
|
if (line->GetParam("param")->IsDefined())
|
||||||
|
{
|
||||||
|
const auto& p = line->GetParam("param")->AsArray();
|
||||||
|
for (unsigned int i = 0; i < 10 && i < p.size(); i++)
|
||||||
|
{
|
||||||
|
motion->SetParam(i, p[i]->AsFloat());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_auto != nullptr)
|
||||||
|
{
|
||||||
|
// TODO: Is it used for anything else than AlienEggs?
|
||||||
|
m_auto->SetType(line->GetParam("autoType")->AsObjectType(OBJECT_NULL));
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
std::string op = "autoValue" + boost::lexical_cast<std::string>(i+1); // autoValue1..autoValue5
|
||||||
|
m_auto->SetValue(i, line->GetParam(op)->AsFloat(0.0f));
|
||||||
|
}
|
||||||
|
m_auto->SetString(const_cast<char*>(line->GetParam("autoString")->AsPath("ai", "").c_str()));
|
||||||
|
|
||||||
|
int i = line->GetParam("run")->AsInt(-1);
|
||||||
|
if (i != -1)
|
||||||
|
{
|
||||||
|
if (i != PARAM_FIXSCENE && !m_main->GetMovies()) i = 0;
|
||||||
|
m_auto->Start(i); // starts the film
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Everthing below is for use only by saved scenes
|
||||||
|
if (line->GetParam("energy")->IsDefined())
|
||||||
|
SetEnergyLevel(line->GetParam("energy")->AsFloat());
|
||||||
|
SetFixed(line->GetParam("fixed")->AsBool(false));
|
||||||
|
SetLock(line->GetParam("lock")->AsBool(false));
|
||||||
SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f));
|
SetGunGoalV(line->GetParam("aimV")->AsFloat(0.0f));
|
||||||
SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f));
|
SetGunGoalH(line->GetParam("aimH")->AsFloat(0.0f));
|
||||||
|
|
||||||
SetAnimateOnReset(line->GetParam("resetCap")->AsBool(false));
|
|
||||||
m_bBurn = line->GetParam("burnMode")->AsBool(false);
|
m_bBurn = line->GetParam("burnMode")->AsBool(false);
|
||||||
m_bVirusMode = line->GetParam("virusMode")->AsBool(false);
|
m_bVirusMode = line->GetParam("virusMode")->AsBool(false);
|
||||||
m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f);
|
m_virusTime = line->GetParam("virusTime")->AsFloat(0.0f);
|
||||||
|
|
||||||
// Sets the parameters of the command line.
|
|
||||||
if (line->GetParam("cmdline")->IsDefined())
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
for (auto& p : line->GetParam("cmdline")->AsArray())
|
|
||||||
{
|
|
||||||
SetCmdLine(i, p->AsFloat());
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_motion != nullptr )
|
if ( m_motion != nullptr )
|
||||||
{
|
{
|
||||||
m_motion->Read(line);
|
m_motion->Read(line);
|
||||||
|
|
|
@ -176,15 +176,15 @@ bool CPhysics::Write(CLevelParserLine* line)
|
||||||
|
|
||||||
bool CPhysics::Read(CLevelParserLine* line)
|
bool CPhysics::Read(CLevelParserLine* line)
|
||||||
{
|
{
|
||||||
m_motorSpeed = line->GetParam("motor")->AsPoint();
|
m_motorSpeed = line->GetParam("motor")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
if ( m_object->Implements(ObjectInterfaceType::Flying) )
|
if ( m_object->Implements(ObjectInterfaceType::Flying) )
|
||||||
{
|
{
|
||||||
if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
|
if ( m_object->Implements(ObjectInterfaceType::JetFlying) )
|
||||||
{
|
{
|
||||||
m_object->SetReactorRange(line->GetParam("reactorRange")->AsFloat());
|
m_object->SetReactorRange(line->GetParam("reactorRange")->AsFloat(1.0f));
|
||||||
}
|
}
|
||||||
SetLand(line->GetParam("land")->AsBool());
|
SetLand(line->GetParam("land")->AsBool(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1557,7 +1557,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
|
||||||
type == OBJECT_WORM )
|
type == OBJECT_WORM )
|
||||||
{
|
{
|
||||||
object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type);
|
object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type);
|
||||||
CObjectManager::GetInstancePointer()->CreateObject(pos, angle, OBJECT_EGG, 0.0f);
|
CObjectManager::GetInstancePointer()->CreateObject(pos, angle, OBJECT_EGG);
|
||||||
if (object->Implements(ObjectInterfaceType::Programmable))
|
if (object->Implements(ObjectInterfaceType::Programmable))
|
||||||
{
|
{
|
||||||
dynamic_cast<CProgrammableObject*>(object)->SetActivity(false);
|
dynamic_cast<CProgrammableObject*>(object)->SetActivity(false);
|
||||||
|
|
Loading…
Reference in New Issue