diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/object/objman.cpp | 7 | ||||
-rw-r--r-- | src/object/objman.h | 2 | ||||
-rw-r--r-- | src/object/robotmain.cpp | 350 | ||||
-rw-r--r-- | src/object/robotmain.h | 3 | ||||
-rw-r--r-- | src/script/script.cpp | 165 |
5 files changed, 20 insertions, 507 deletions
diff --git a/src/object/objman.cpp b/src/object/objman.cpp index e4102b8..0471ebf 100644 --- a/src/object/objman.cpp +++ b/src/object/objman.cpp @@ -63,10 +63,9 @@ CObject* CObjectManager::SearchInstance(int id) return m_table[id]; } -CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, float zoom, float height, - ObjectType type, float power, - bool trainer, bool toy, - int option) +CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type, + float power, float zoom, float height, + bool trainer, bool toy, int option) { CObject* object = nullptr; diff --git a/src/object/objman.h b/src/object/objman.h index 3087383..1d67468 100644 --- a/src/object/objman.h +++ b/src/object/objman.h @@ -44,7 +44,7 @@ public: //! Seeks for an object CObject* SearchInstance(int id); //! Creates an object - CObject* CreateObject(Math::Vector pos, float angle, float zoom, float height, ObjectType type, float power, bool trainer, bool toy, int option); + 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); protected: CObject* m_table[MAX_OBJECTS]; diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 1fa3058..af463c7 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -2459,7 +2459,7 @@ void CRobotMain::StartDisplayVisit(EventType event) } Math::Vector goal = m_displayText->GetVisitGoal(event); - m_visitArrow = CreateObject(goal, 0.0f, 1.0f, 10.0f, OBJECT_SHOW, false, false, 0); + m_visitArrow = CObjectManager::GetInstancePointer()->CreateObject(goal, 0.0f, OBJECT_SHOW, -1.0f, 1.0f, 10.0f); m_visitPos = m_visitArrow->GetPosition(0); m_visitPosArrow = m_visitPos; @@ -4555,7 +4555,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "MissionController") && read[0] == 0 && m_version >= 2) { - m_controller = CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, 1.0f, 0.0f, OBJECT_CONTROLLER, 100.0f, false, false, 0); + m_controller = CObjectManager::GetInstancePointer()->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f); m_controller->SetMagnifyDamage(100.0f); CBrain* brain = m_controller->GetBrain(); if (brain != nullptr) @@ -4614,13 +4614,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) Math::Vector pos = OpPos(line, "pos")*g_unit; float dirAngle = OpFloat(line, "dir", 0.0f)*Math::PI; - bool trainer = OpInt(line, "trainer", 0); - CObject* obj = CreateObject(pos, dirAngle, - OpFloat(line, "z", 1.0f), - OpFloat(line, "h", 0.0f), + bool trainer; + CObject* obj = CObjectManager::GetInstancePointer()->CreateObject( + pos, dirAngle, type, OpFloat(line, "power", 1.0f), - trainer, + OpFloat(line, "z", 1.0f), + OpFloat(line, "h", 0.0f), + trainer = OpInt(line, "trainer", 0), OpInt(line, "toy", 0), OpInt(line, "option", 0)); @@ -5088,339 +5089,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_eventQueue->AddEvent(Event(EVENT_WIN)); } -//! Creates an object of decoration mobile or stationary -CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, float height, - ObjectType type, float power, - bool trainer, bool toy, - int option) -{ - CObject* object = nullptr; - - if ( type == OBJECT_NULL ) return nullptr; - - if ( type == OBJECT_HUMAN || - type == OBJECT_TECH ) - { - trainer = false; // necessarily - } - - if ( type == OBJECT_PORTICO || - type == OBJECT_BASE || - type == OBJECT_DERRICK || - type == OBJECT_FACTORY || - type == OBJECT_STATION || - type == OBJECT_CONVERT || - type == OBJECT_REPAIR || - type == OBJECT_DESTROYER|| - type == OBJECT_TOWER || - type == OBJECT_NEST || - type == OBJECT_RESEARCH || - type == OBJECT_RADAR || - type == OBJECT_INFO || - type == OBJECT_ENERGY || - type == OBJECT_LABO || - type == OBJECT_NUCLEAR || - type == OBJECT_PARA || - type == OBJECT_SAFE || - type == OBJECT_HUSTON || - type == OBJECT_TARGET1 || - type == OBJECT_TARGET2 || - type == OBJECT_START || - type == OBJECT_END ) - { - object = new CObject(); - object->CreateBuilding(pos, angle, height, type, power); - - CAuto* automat = object->GetAuto(); - if (automat != nullptr) - { - automat->Init(); - } - } - else - if ( type == OBJECT_FRET || - type == OBJECT_STONE || - type == OBJECT_URANIUM || - type == OBJECT_METAL || - type == OBJECT_POWER || - type == OBJECT_ATOMIC || - type == OBJECT_BULLET || - type == OBJECT_BBOX || - type == OBJECT_KEYa || - type == OBJECT_KEYb || - type == OBJECT_KEYc || - type == OBJECT_KEYd || - type == OBJECT_TNT || - type == OBJECT_SCRAP1 || - type == OBJECT_SCRAP2 || - type == OBJECT_SCRAP3 || - type == OBJECT_SCRAP4 || - type == OBJECT_SCRAP5 || - type == OBJECT_BOMB || - type == OBJECT_WAYPOINT || - type == OBJECT_SHOW || - type == OBJECT_WINFIRE || - type == OBJECT_BAG || - type == OBJECT_MARKPOWER || - type == OBJECT_MARKSTONE || - type == OBJECT_MARKURANIUM || - type == OBJECT_MARKKEYa || - type == OBJECT_MARKKEYb || - type == OBJECT_MARKKEYc || - type == OBJECT_MARKKEYd || - type == OBJECT_EGG ) - { - object = new CObject(); - object->CreateResource(pos, angle, type, power); - } - else - if ( type == OBJECT_FLAGb || - type == OBJECT_FLAGr || - type == OBJECT_FLAGg || - type == OBJECT_FLAGy || - type == OBJECT_FLAGv ) - { - object = new CObject(); - object->CreateFlag(pos, angle, type); - } - else - if ( type == OBJECT_BARRIER0 || - type == OBJECT_BARRIER1 || - type == OBJECT_BARRIER2 || - type == OBJECT_BARRIER3 || - type == OBJECT_BARRIER4 ) - { - object = new CObject(); - object->CreateBarrier(pos, angle, height, type); - } - else - if ( type == OBJECT_PLANT0 || - type == OBJECT_PLANT1 || - type == OBJECT_PLANT2 || - type == OBJECT_PLANT3 || - type == OBJECT_PLANT4 || - type == OBJECT_PLANT5 || - type == OBJECT_PLANT6 || - type == OBJECT_PLANT7 || - type == OBJECT_PLANT8 || - type == OBJECT_PLANT9 || - type == OBJECT_PLANT10 || - type == OBJECT_PLANT11 || - type == OBJECT_PLANT12 || - type == OBJECT_PLANT13 || - type == OBJECT_PLANT14 || - type == OBJECT_PLANT15 || - type == OBJECT_PLANT16 || - type == OBJECT_PLANT17 || - type == OBJECT_PLANT18 || - type == OBJECT_PLANT19 || - type == OBJECT_TREE0 || - type == OBJECT_TREE1 || - type == OBJECT_TREE2 || - type == OBJECT_TREE3 || - type == OBJECT_TREE4 || - type == OBJECT_TREE5 || - type == OBJECT_TREE6 || - type == OBJECT_TREE7 || - type == OBJECT_TREE8 || - type == OBJECT_TREE9 ) - { - object = new CObject(); - object->CreatePlant(pos, angle, height, type); - } - else - if ( type == OBJECT_MUSHROOM0 || - type == OBJECT_MUSHROOM1 || - type == OBJECT_MUSHROOM2 || - type == OBJECT_MUSHROOM3 || - type == OBJECT_MUSHROOM4 || - type == OBJECT_MUSHROOM5 || - type == OBJECT_MUSHROOM6 || - type == OBJECT_MUSHROOM7 || - type == OBJECT_MUSHROOM8 || - type == OBJECT_MUSHROOM9 ) - { - object = new CObject(); - object->CreateMushroom(pos, angle, height, type); - } - else - if ( type == OBJECT_TEEN0 || - type == OBJECT_TEEN1 || - type == OBJECT_TEEN2 || - type == OBJECT_TEEN3 || - type == OBJECT_TEEN4 || - type == OBJECT_TEEN5 || - type == OBJECT_TEEN6 || - type == OBJECT_TEEN7 || - type == OBJECT_TEEN8 || - type == OBJECT_TEEN9 || - type == OBJECT_TEEN10 || - type == OBJECT_TEEN11 || - type == OBJECT_TEEN12 || - type == OBJECT_TEEN13 || - type == OBJECT_TEEN14 || - type == OBJECT_TEEN15 || - type == OBJECT_TEEN16 || - type == OBJECT_TEEN17 || - type == OBJECT_TEEN18 || - type == OBJECT_TEEN19 || - type == OBJECT_TEEN20 || - type == OBJECT_TEEN21 || - type == OBJECT_TEEN22 || - type == OBJECT_TEEN23 || - type == OBJECT_TEEN24 || - type == OBJECT_TEEN25 || - type == OBJECT_TEEN26 || - type == OBJECT_TEEN27 || - type == OBJECT_TEEN28 || - type == OBJECT_TEEN29 || - type == OBJECT_TEEN30 || - type == OBJECT_TEEN31 || - type == OBJECT_TEEN32 || - type == OBJECT_TEEN33 || - type == OBJECT_TEEN34 || - type == OBJECT_TEEN35 || - type == OBJECT_TEEN36 || - type == OBJECT_TEEN37 || - type == OBJECT_TEEN38 || - type == OBJECT_TEEN39 || - type == OBJECT_TEEN40 || - type == OBJECT_TEEN41 || - type == OBJECT_TEEN42 || - type == OBJECT_TEEN43 || - type == OBJECT_TEEN44 || - type == OBJECT_TEEN45 || - type == OBJECT_TEEN46 || - type == OBJECT_TEEN47 || - type == OBJECT_TEEN48 || - type == OBJECT_TEEN49 ) - { - object = new CObject(); - object->SetOption(option); - object->CreateTeen(pos, angle, zoom, height, type); - } - else - if ( type == OBJECT_QUARTZ0 || - type == OBJECT_QUARTZ1 || - type == OBJECT_QUARTZ2 || - type == OBJECT_QUARTZ3 || - type == OBJECT_QUARTZ4 || - type == OBJECT_QUARTZ5 || - type == OBJECT_QUARTZ6 || - type == OBJECT_QUARTZ7 || - type == OBJECT_QUARTZ8 || - type == OBJECT_QUARTZ9 ) - { - object = new CObject(); - object->CreateQuartz(pos, angle, height, type); - } - else - if ( type == OBJECT_ROOT0 || - type == OBJECT_ROOT1 || - type == OBJECT_ROOT2 || - type == OBJECT_ROOT3 || - type == OBJECT_ROOT4 || - type == OBJECT_ROOT5 || - type == OBJECT_ROOT6 || - type == OBJECT_ROOT7 || - type == OBJECT_ROOT8 || - type == OBJECT_ROOT9 ) - { - object = new CObject(); - object->CreateRoot(pos, angle, height, type); - } - else - if ( type == OBJECT_HOME1 ) - { - object = new CObject(); - object->CreateHome(pos, angle, height, type); - } - else - if ( type == OBJECT_RUINmobilew1 || - type == OBJECT_RUINmobilew2 || - type == OBJECT_RUINmobilet1 || - type == OBJECT_RUINmobilet2 || - type == OBJECT_RUINmobiler1 || - type == OBJECT_RUINmobiler2 || - type == OBJECT_RUINfactory || - type == OBJECT_RUINdoor || - type == OBJECT_RUINsupport || - type == OBJECT_RUINradar || - type == OBJECT_RUINconvert || - type == OBJECT_RUINbase || - type == OBJECT_RUINhead ) - { - object = new CObject(); - object->CreateRuin(pos, angle, height, type); - } - else - if ( type == OBJECT_APOLLO1 || - type == OBJECT_APOLLO3 || - type == OBJECT_APOLLO4 || - type == OBJECT_APOLLO5 ) - { - object = new CObject(); - object->CreateApollo(pos, angle, type); - } - else - if ( type == OBJECT_MOTHER || - type == OBJECT_ANT || - type == OBJECT_SPIDER || - type == OBJECT_BEE || - type == OBJECT_WORM ) - { - object = new CObject(); - object->CreateInsect(pos, angle, type); // no eggs - } - else - if ( type == OBJECT_HUMAN || - type == OBJECT_TECH || - type == OBJECT_TOTO || - type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEta || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEia || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEii || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEis || - type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs || - type == OBJECT_MOBILEsa || - type == OBJECT_MOBILEtg || - type == OBJECT_MOBILEft || - type == OBJECT_MOBILEtt || - type == OBJECT_MOBILEwt || - type == OBJECT_MOBILEit || - type == OBJECT_MOBILEdr || - type == OBJECT_APOLLO2 || - type == OBJECT_CONTROLLER ) - { - object = new CObject(); - object->SetOption(option); - object->CreateVehicle(pos, angle, type, power, trainer, toy); - } - - if (m_fixScene && type == OBJECT_HUMAN) - { - CMotion* motion = object->GetMotion(); - if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f); - if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f); - } - - return object; -} - //! Creates a directional light int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) { @@ -6510,7 +6178,7 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) int toy = OpInt(line, "toy", 0); int option = OpInt(line, "option", 0); - CObject* obj = CreateObject(pos, dir.y, 1.0f, 0.0f, type, 0.0f, trainer, toy, option); + CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option); obj->SetDefRank(objRank); obj->SetPosition(0, pos); obj->SetAngle(0, dir); diff --git a/src/object/robotmain.h b/src/object/robotmain.h index b25a0a4..c300b5a 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -390,9 +390,6 @@ protected: void CreateScene(bool soluce, bool fixScene, bool resetObject); Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length); - CObject* CreateObject(Math::Vector pos, float angle, float zoom, - float height, ObjectType type, float power=1.0f, - bool trainer=false, bool toy=false, int option=0); int CreateLight(Math::Vector direction, Gfx::Color color); void HiliteClear(); void HiliteObject(Math::Point pos); diff --git a/src/script/script.cpp b/src/script/script.cpp index 05e2626..fbf7276 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1870,52 +1870,10 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } } - if ( type == OBJECT_FRET || - type == OBJECT_STONE || - type == OBJECT_URANIUM || - type == OBJECT_METAL || - type == OBJECT_POWER || - type == OBJECT_ATOMIC || - type == OBJECT_BULLET || - type == OBJECT_BBOX || - type == OBJECT_KEYa || - type == OBJECT_KEYb || - type == OBJECT_KEYc || - type == OBJECT_KEYd || - type == OBJECT_TNT || - type == OBJECT_SCRAP1 || - type == OBJECT_SCRAP2 || - type == OBJECT_SCRAP3 || - type == OBJECT_SCRAP4 || - type == OBJECT_SCRAP5 || - type == OBJECT_BOMB || - type == OBJECT_WAYPOINT || - type == OBJECT_SHOW || - type == OBJECT_WINFIRE || - type == OBJECT_BAG || - type == OBJECT_MARKPOWER || - type == OBJECT_MARKSTONE || - type == OBJECT_MARKURANIUM || - type == OBJECT_MARKKEYa || - type == OBJECT_MARKKEYb || - type == OBJECT_MARKKEYc || - type == OBJECT_MARKKEYd || - type == OBJECT_EGG ) - { - object = new CObject(); - if ( !object->CreateResource(pos, angle, type) ) - { - delete object; - result->SetValInt(1); // error - return true; - } - object->SetActivity(false); - } - else if ( type == OBJECT_MOTHER || - type == OBJECT_ANT || - type == OBJECT_SPIDER || - type == OBJECT_BEE || - type == OBJECT_WORM ) + if ( type == OBJECT_ANT || + type == OBJECT_SPIDER || + type == OBJECT_BEE || + type == OBJECT_WORM ) { CObject* egg; @@ -1933,124 +1891,15 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user delete egg; } object->SetActivity(false); - } - else if ( type == OBJECT_PORTICO || - type == OBJECT_BASE || - type == OBJECT_DERRICK || - type == OBJECT_FACTORY || - type == OBJECT_STATION || - type == OBJECT_CONVERT || - type == OBJECT_REPAIR || - type == OBJECT_DESTROYER|| - type == OBJECT_TOWER || - type == OBJECT_NEST || - type == OBJECT_RESEARCH || - type == OBJECT_RADAR || - type == OBJECT_INFO || - type == OBJECT_ENERGY || - type == OBJECT_LABO || - type == OBJECT_NUCLEAR || - type == OBJECT_PARA || - type == OBJECT_SAFE || - type == OBJECT_HUSTON || - type == OBJECT_TARGET1 || - type == OBJECT_TARGET2 || - type == OBJECT_START || - type == OBJECT_END ) - { - object = new CObject(); - if ( !object->CreateBuilding(pos, angle, 0, type) ) + } else { + object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power); + if ( object == nullptr ) { - delete object; result->SetValInt(1); // error return true; } - object->SetActivity(true); - - CAuto* automat = object->GetAuto(); - if (automat != nullptr) - { - automat->Init(); - } - script->m_main->CreateShortcuts(); } - else if ( type == OBJECT_FLAGb || - type == OBJECT_FLAGr || - type == OBJECT_FLAGg || - type == OBJECT_FLAGy || - type == OBJECT_FLAGv ) - { - object = new CObject(); - if ( !object->CreateFlag(pos, angle, type) ) - { - delete object; - result->SetValInt(1); // error - return true; - } - object->SetActivity(false); - } - else if ( type == OBJECT_HUMAN || - type == OBJECT_TECH || - type == OBJECT_TOTO || - type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEta || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEia || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEii || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEis || - type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs || - type == OBJECT_MOBILEsa || - type == OBJECT_MOBILEtg || - type == OBJECT_MOBILEft || - type == OBJECT_MOBILEtt || - type == OBJECT_MOBILEwt || - type == OBJECT_MOBILEit || - type == OBJECT_MOBILEdr || - type == OBJECT_APOLLO2 ) - { - object = new CObject(); - if ( !object->CreateVehicle(pos, angle, type, power, false, false) ) - { - delete object; - result->SetValInt(1); // error - return true; - } - object->UpdateMapping(); - object->SetRange(30.0f); - object->SetZoom(0, 1.0f); - CPhysics* physics = object->GetPhysics(); - if ( physics != 0 ) - { - physics->SetFreeze(false); // can move - } - object->SetLock(false); // vehicle useable - // SetManual will affect bot speed - if (type == OBJECT_MOBILEdr) - { - object->SetManual(true); - } - object->SetActivity(true); - script->m_main->CreateShortcuts(); - } - else - { - result->SetValInt(1); // impossible - return true; - } if (name[0] != 0) { |