diff options
-rw-r--r-- | src/object/auto/autobase.cpp | 99 | ||||
-rw-r--r-- | src/object/auto/autobase.h | 2 | ||||
-rw-r--r-- | src/object/robotmain.cpp | 1 | ||||
-rw-r--r-- | src/script/cbottoken.cpp | 9 | ||||
-rw-r--r-- | src/script/script.cpp | 49 | ||||
-rw-r--r-- | src/script/script.h | 1 |
6 files changed, 113 insertions, 48 deletions
diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 6d61bc2..06b5dbb 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -121,7 +121,6 @@ bool CAutoBase::EventProcess(const Event &event) CObject* pObj; Math::Vector pos, speed, vibCir, iPos; Math::Point dim, p; - Error err; float angle, dist, time, h, len, vSpeed; int i, max; @@ -313,50 +312,7 @@ begin: if ( event.type == EVENT_OBJECT_BTAKEOFF ) { - err = CheckCloseDoor(); - if ( err != ERR_OK ) - { - m_main->DisplayError(err, m_object); - return false; - } - - err = m_main->CheckEndMission(false); - if ( err != ERR_OK ) - { - m_main->DisplayError(err, m_object); - return false; - } - - FreezeCargo(true); // freeze whole cargo - m_main->SetMovieLock(true); // blocks everything until the end - m_main->DeselectAll(); - - newEvent.type = EVENT_UPDINTERFACE; - m_eventQueue->AddEvent(newEvent); - - m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); - - pos = m_pos; - pos.x -= 110.0f; - m_terrain->AdjustToFloor(pos); - pos.y += 10.0f; - m_camera->SetScriptEye(pos); - m_posSound = pos; - - pos = m_object->GetPosition(0); - pos.y += 50.0f; - m_camera->SetScriptLookat(pos); - - m_engine->SetFocus(1.0f); - - m_soundChannel = m_sound->Play(SOUND_MANIP, m_posSound, 0.3f, 1.5f, true); - m_sound->AddEnvelope(m_soundChannel, 0.3f, 1.5f, BASE_DOOR_TIME2, SOPER_CONTINUE); - m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.5f, 0.5f, SOPER_STOP); - - m_phase = ABP_CLOSE2; - m_progress = 0.0f; - m_speed = 1.0f/BASE_DOOR_TIME2; - return true; + return TakeOff(true); } if ( event.type != EVENT_FRAME ) return true; @@ -1444,3 +1400,56 @@ void CAutoBase::EndTransit() m_main->StartMusic(); } +Error CAutoBase::TakeOff(bool printMsg) +{ + + Event newEvent; + Math::Vector pos; + Error err; + + err = CheckCloseDoor(); + if ( err != ERR_OK ) + { + if(printMsg) m_main->DisplayError(err, m_object); + return err; + } + + err = m_main->CheckEndMission(false); + if ( err != ERR_OK ) + { + if(printMsg) m_main->DisplayError(err, m_object); + return err; + } + + FreezeCargo(true); // freeze whole cargo + m_main->SetMovieLock(true); // blocks everything until the end + m_main->DeselectAll(); + + newEvent.type = EVENT_UPDINTERFACE; + m_eventQueue->AddEvent(newEvent); + + m_camera->SetType(Gfx::CAM_TYPE_SCRIPT); + + pos = m_pos; + pos.x -= 110.0f; + m_terrain->AdjustToFloor(pos); + pos.y += 10.0f; + m_camera->SetScriptEye(pos); + m_posSound = pos; + + pos = m_object->GetPosition(0); + pos.y += 50.0f; + m_camera->SetScriptLookat(pos); + + m_engine->SetFocus(1.0f); + + m_soundChannel = m_sound->Play(SOUND_MANIP, m_posSound, 0.3f, 1.5f, true); + m_sound->AddEnvelope(m_soundChannel, 0.3f, 1.5f, BASE_DOOR_TIME2, SOPER_CONTINUE); + m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.5f, 0.5f, SOPER_STOP); + + m_phase = ABP_CLOSE2; + m_progress = 0.0f; + m_speed = 1.0f/BASE_DOOR_TIME2; + return ERR_OK; +} + diff --git a/src/object/auto/autobase.h b/src/object/auto/autobase.h index 422f340..967e43d 100644 --- a/src/object/auto/autobase.h +++ b/src/object/auto/autobase.h @@ -77,6 +77,8 @@ public: Error GetError(); bool CreateInterface(bool bSelect); + + Error TakeOff(bool printMsg); protected: void UpdateInterface(); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 22e8152..47f06b3 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -881,6 +881,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile) bc->AddFunction("busy", CScript::rBusy, CScript::cBusy); bc->AddFunction("factory", CScript::rFactory, CScript::cFactory); bc->AddFunction("research", CScript::rResearch, CScript::cClassOneFloat); + bc->AddFunction("takeoff", CScript::rTakeOff, CScript::cClassNull); bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull); // Initializes the class FILE. diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 505228e..9f99752 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -253,10 +253,11 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "getresearchenable" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresen.txt"); if ( strcmp(token, "getresearchdone" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getresdo.txt"); if ( strcmp(token, "retobject" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/retobj.txt"); - if ( strcmp(token, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); - if ( strcmp(token, "busy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/busy.txt"); - if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); + if ( strcmp(token, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); + if ( strcmp(token, "busy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/busy.txt"); + if ( strcmp(token, "takeoff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/takeoff.txt"); if ( strcmp(token, "research" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/research.txt"); + if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt"); if ( strcmp(token, "destroy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/destroy.txt"); if ( strcmp(token, "search" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/search.txt"); if ( strcmp(token, "radar" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/radar.txt"); @@ -384,6 +385,7 @@ bool IsFunction(const char *token) if ( strcmp(token, "busy" ) == 0 ) return true; if ( strcmp(token, "factory" ) == 0 ) return true; if ( strcmp(token, "research" ) == 0 ) return true; + if ( strcmp(token, "takeoff" ) == 0 ) return true; if ( strcmp(token, "destroy" ) == 0 ) return true; if ( strcmp(token, "search" ) == 0 ) return true; if ( strcmp(token, "radar" ) == 0 ) return true; @@ -477,6 +479,7 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "busy" ) == 0 ) return "object.busy ( );"; if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat, program );"; if ( strcmp(token, "research" ) == 0 ) return "object.research ( type );"; + if ( strcmp(token, "takeoff" ) == 0 ) return "object.takeoff ( );"; if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );"; if ( strcmp(token, "search" ) == 0 ) return "search ( );"; if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 1a70699..05e2626 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -38,6 +38,7 @@ #include "object/auto/auto.h" #include "object/auto/autofactory.h" +#include "object/auto/autobase.h" #include "physics/physics.h" @@ -901,6 +902,54 @@ bool CScript::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& return true; } +// Instruction "object.takeoff()" + +bool CScript::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + Error err; + + exception = 0; + + CBotVar* classVars = thisclass->GetItemList(); // "category" + ObjectType thisType = static_cast<ObjectType>(classVars->GetValInt()); + classVars = classVars->GetNext(); // "position" + classVars = classVars->GetNext(); // "orientation" + classVars = classVars->GetNext(); // "pitch" + classVars = classVars->GetNext(); // "roll" + classVars = classVars->GetNext(); // "energyLevel" + classVars = classVars->GetNext(); // "shieldLevel" + classVars = classVars->GetNext(); // "temperature" + classVars = classVars->GetNext(); // "altitude" + classVars = classVars->GetNext(); // "lifeTime" + classVars = classVars->GetNext(); // "material" + classVars = classVars->GetNext(); // "energyCell" + classVars = classVars->GetNext(); // "load" + classVars = classVars->GetNext(); // "id" + int rank = classVars->GetValInt(); + CObject* center = CObjectManager::GetInstancePointer()->SearchInstance(rank); + CAuto* automat = center->GetAuto(); + + if ( thisType == OBJECT_BASE ) + { + err = (static_cast<CAutoBase*>(automat))->TakeOff(false); + } else + err = ERR_WRONG_OBJ; + + if ( err != ERR_OK ) + { + result->SetValInt(err); // return error +//TODO: if ( script->m_errMode == ERM_STOP ) + if( true ) + { + exception = err; + return false; + } + return true; + } + + return true; +} + // Compilation of the instruction "delete(rank[, exploType[, force]])". CBotTypResult CScript::cDelete(CBotVar* &var, void* user) diff --git a/src/script/script.h b/src/script/script.h index 3641dd9..9d8d372 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -200,6 +200,7 @@ public: static bool rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); + static bool rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); static bool rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); private: |