summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-18 17:38:44 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-18 18:04:48 +0200
commit796cb92ffc7dc03f9cc7107cac5ddb81795d0549 (patch)
treec53eddc06665e251956773f290fdb89440b52ac2
parentd0de6a88ba5095c4d485e281e6fb3e804b0c21b6 (diff)
downloadcolobot-796cb92ffc7dc03f9cc7107cac5ddb81795d0549.tar.gz
colobot-796cb92ffc7dc03f9cc7107cac5ddb81795d0549.tar.bz2
colobot-796cb92ffc7dc03f9cc7107cac5ddb81795d0549.zip
Added object.destroy()
-rw-r--r--src/common/global.h1
-rw-r--r--src/common/restext.cpp1
-rw-r--r--src/object/auto/autodestroyer.cpp51
-rw-r--r--src/object/auto/autodestroyer.h2
-rw-r--r--src/object/robotmain.cpp1
-rw-r--r--src/script/cbottoken.cpp5
-rw-r--r--src/script/script.cpp50
-rw-r--r--src/script/script.h2
8 files changed, 97 insertions, 16 deletions
diff --git a/src/common/global.h b/src/common/global.h
index db601df..5e03536 100644
--- a/src/common/global.h
+++ b/src/common/global.h
@@ -106,6 +106,7 @@ enum Error
ERR_INFO_NULL = 390, //! < no information terminal
ERR_VEH_VIRUS = 400, //! < vehicle infected by a virus
ERR_BAT_VIRUS = 401, //! < building infected by a virus
+ ERR_DESTROY_NOTFOUND = 410, //! < not found anything to destroy
ERR_VEH_POWER = 500, //! < no battery
ERR_VEH_ENERGY = 501, //! < more energy
ERR_FLAG_FLY = 510, //! < impossible in flight
diff --git a/src/common/restext.cpp b/src/common/restext.cpp
index 7fdcdbd..663a82e 100644
--- a/src/common/restext.cpp
+++ b/src/common/restext.cpp
@@ -623,6 +623,7 @@ void InitializeRestext()
stringsErr[ERR_FLAG_CREATE] = "Too many flags of this color (maximum 5)";
stringsErr[ERR_FLAG_PROXY] = "Too close to an existing flag";
stringsErr[ERR_FLAG_DELETE] = "No flag nearby";
+ stringsErr[ERR_DESTROY_NOTFOUND]= "Not found anything to destroy";
stringsErr[ERR_MISSION_NOTERM] = "The mission is not accomplished yet (press \\key help; for more details)";
stringsErr[ERR_DELETEMOBILE] = "Bot destroyed";
stringsErr[ERR_DELETEBUILDING] = "Building destroyed";
diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp
index e33c317..8e3fa98 100644
--- a/src/object/auto/autodestroyer.cpp
+++ b/src/object/auto/autodestroyer.cpp
@@ -24,6 +24,7 @@
#include "ui/interface.h"
#include "ui/window.h"
+#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
@@ -68,6 +69,36 @@ void CAutoDestroyer::Init()
}
+// Starts an action
+Error CAutoDestroyer::StartAction(int param)
+{
+ CObject* scrap;
+
+ if ( m_object->GetVirusMode() ) // contaminated by a virus?
+ {
+ return ERR_BAT_VIRUS;
+ }
+
+ scrap = SearchPlastic();
+ if ( scrap == nullptr )
+ return ERR_DESTROY_NOTFOUND;
+ else {
+ if ( m_phase == ADEP_WAIT ) {
+ scrap->SetLock(true); // usable waste
+//? scrap->SetTruck(m_object); // usable waste
+
+ m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f);
+
+ m_phase = ADEP_DOWN;
+ m_progress = 0.0f;
+ m_speed = 1.0f/1.0f;
+ m_bExplo = false;
+ } else
+ return ERR_GENERIC;
+ }
+ return ERR_OK;
+}
+
// Management of an event.
bool CAutoDestroyer::EventProcess(const Event &event)
@@ -86,21 +117,11 @@ bool CAutoDestroyer::EventProcess(const Event &event)
{
if ( event.type == EVENT_OBJECT_BDESTROY )
{
- if ( m_object->GetVirusMode() ) // contaminated by a virus?
- {
- return true; // Don't do anything. TODO: Error?
- }
+ Error err = StartAction(0);
+ if ( err != ERR_OK )
+ m_displayText->DisplayError(err, m_object);
- scrap = SearchPlastic();
- scrap->SetLock(true); // usable waste
-//? scrap->SetTruck(m_object); // usable waste
-
- m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f);
-
- m_phase = ADEP_DOWN;
- m_progress = 0.0f;
- m_speed = 1.0f/1.0f;
- m_bExplo = false;
+ return false;
}
}
@@ -381,4 +402,4 @@ void CAutoDestroyer::EnableInterface(Ui::CWindow *pw, EventType event, bool bSta
if ( control == 0 ) return;
control->SetState(Ui::STATE_ENABLE, bState);
-} \ No newline at end of file
+}
diff --git a/src/object/auto/autodestroyer.h b/src/object/auto/autodestroyer.h
index 4ab1118..ef3d5ae 100644
--- a/src/object/auto/autodestroyer.h
+++ b/src/object/auto/autodestroyer.h
@@ -46,6 +46,8 @@ public:
bool EventProcess(const Event &event);
Error GetError();
+ Error StartAction(int param);
+
bool CreateInterface(bool bSelect);
bool Write(char *line);
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 52387f8..2957799 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -875,6 +875,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
bc->AddFunction("factory", CScript::rFactory, CScript::cClassOneFloat);
+ bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
// Initializes the class FILE.
InitClassFILE();
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index c56482f..b5e99f5 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -255,6 +255,7 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "retobject" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/retobj.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, "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");
if ( strcmp(token, "direction" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/direct.txt");
@@ -379,6 +380,7 @@ bool IsFunction(const char *token)
if ( strcmp(token, "retobject" ) == 0 ) return true;
if ( strcmp(token, "busy" ) == 0 ) return true;
if ( strcmp(token, "factory" ) == 0 ) return true;
+ if ( strcmp(token, "destroy" ) == 0 ) return true;
if ( strcmp(token, "search" ) == 0 ) return true;
if ( strcmp(token, "radar" ) == 0 ) return true;
if ( strcmp(token, "detect" ) == 0 ) return true;
@@ -467,8 +469,9 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "getresearchdone" ) == 0 ) return "getresearchdone ( );";
if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( rank );";
if ( strcmp(token, "retobjectbyid") == 0 ) return "retobjectbyid ( rank );";
- if ( strcmp(token, "busy" ) == 0 ) return "object.busy ( cat );";
+ if ( strcmp(token, "busy" ) == 0 ) return "object.busy ( );";
if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat );";
+ 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 );";
if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );";
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 0271eb6..527da93 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -70,6 +70,11 @@ CBotTypResult CScript::cNull(CBotVar* &var, void* user)
return CBotTypResult(CBotTypFloat);
}
+CBotTypResult CScript::cClassNull(CBotVar* thisclass, CBotVar* &var)
+{
+ return CScript::cNull(var, nullptr);
+}
+
// Compiling a procedure with a single real number.
CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
@@ -538,6 +543,51 @@ bool CScript::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exce
return true;
}
+bool CScript::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
+{
+ exception = 0;
+ Error err;
+
+ 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* obj = CObjectManager::GetInstancePointer()->SearchInstance(rank);
+ CAuto* automat = obj->GetAuto();
+
+ if ( thisType == OBJECT_DESTROYER )
+ {
+ err = automat->StartAction(0);
+ } else
+ err = ERR_MANIP_VEH;
+
+ 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;
+}
+
// Instruction "object.factory(cat)"
bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
diff --git a/src/script/script.h b/src/script/script.h
index ae9011b..75f0d72 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -193,9 +193,11 @@ private:
public:
static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var);
static CBotTypResult cClassOneFloat(CBotVar* thisclass, CBotVar* &var);
+ static CBotTypResult cClassNull(CBotVar* thisclass, CBotVar* &var);
static bool rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
+ static bool rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
private:
static bool Process(CScript* script, CBotVar* result, int &exception);