Added object.destroy()
parent
d0de6a88ba
commit
796cb92ffc
|
@ -106,6 +106,7 @@ enum Error
|
||||||
ERR_INFO_NULL = 390, //! < no information terminal
|
ERR_INFO_NULL = 390, //! < no information terminal
|
||||||
ERR_VEH_VIRUS = 400, //! < vehicle infected by a virus
|
ERR_VEH_VIRUS = 400, //! < vehicle infected by a virus
|
||||||
ERR_BAT_VIRUS = 401, //! < building 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_POWER = 500, //! < no battery
|
||||||
ERR_VEH_ENERGY = 501, //! < more energy
|
ERR_VEH_ENERGY = 501, //! < more energy
|
||||||
ERR_FLAG_FLY = 510, //! < impossible in flight
|
ERR_FLAG_FLY = 510, //! < impossible in flight
|
||||||
|
|
|
@ -623,6 +623,7 @@ void InitializeRestext()
|
||||||
stringsErr[ERR_FLAG_CREATE] = "Too many flags of this color (maximum 5)";
|
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_PROXY] = "Too close to an existing flag";
|
||||||
stringsErr[ERR_FLAG_DELETE] = "No flag nearby";
|
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_MISSION_NOTERM] = "The mission is not accomplished yet (press \\key help; for more details)";
|
||||||
stringsErr[ERR_DELETEMOBILE] = "Bot destroyed";
|
stringsErr[ERR_DELETEMOBILE] = "Bot destroyed";
|
||||||
stringsErr[ERR_DELETEBUILDING] = "Building destroyed";
|
stringsErr[ERR_DELETEBUILDING] = "Building destroyed";
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "ui/interface.h"
|
#include "ui/interface.h"
|
||||||
#include "ui/window.h"
|
#include "ui/window.h"
|
||||||
|
#include "ui/displaytext.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.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.
|
// Management of an event.
|
||||||
|
|
||||||
bool CAutoDestroyer::EventProcess(const Event &event)
|
bool CAutoDestroyer::EventProcess(const Event &event)
|
||||||
|
@ -86,21 +117,11 @@ bool CAutoDestroyer::EventProcess(const Event &event)
|
||||||
{
|
{
|
||||||
if ( event.type == EVENT_OBJECT_BDESTROY )
|
if ( event.type == EVENT_OBJECT_BDESTROY )
|
||||||
{
|
{
|
||||||
if ( m_object->GetVirusMode() ) // contaminated by a virus?
|
Error err = StartAction(0);
|
||||||
{
|
if ( err != ERR_OK )
|
||||||
return true; // Don't do anything. TODO: Error?
|
m_displayText->DisplayError(err, m_object);
|
||||||
}
|
|
||||||
|
|
||||||
scrap = SearchPlastic();
|
return false;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,4 +402,4 @@ void CAutoDestroyer::EnableInterface(Ui::CWindow *pw, EventType event, bool bSta
|
||||||
if ( control == 0 ) return;
|
if ( control == 0 ) return;
|
||||||
|
|
||||||
control->SetState(Ui::STATE_ENABLE, bState);
|
control->SetState(Ui::STATE_ENABLE, bState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ public:
|
||||||
bool EventProcess(const Event &event);
|
bool EventProcess(const Event &event);
|
||||||
Error GetError();
|
Error GetError();
|
||||||
|
|
||||||
|
Error StartAction(int param);
|
||||||
|
|
||||||
bool CreateInterface(bool bSelect);
|
bool CreateInterface(bool bSelect);
|
||||||
|
|
||||||
bool Write(char *line);
|
bool Write(char *line);
|
||||||
|
|
|
@ -875,6 +875,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
|
||||||
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
|
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
|
||||||
bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
|
bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
|
||||||
bc->AddFunction("factory", CScript::rFactory, CScript::cClassOneFloat);
|
bc->AddFunction("factory", CScript::rFactory, CScript::cClassOneFloat);
|
||||||
|
bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
|
||||||
|
|
||||||
// Initializes the class FILE.
|
// Initializes the class FILE.
|
||||||
InitClassFILE();
|
InitClassFILE();
|
||||||
|
|
|
@ -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, "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, "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, "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, "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, "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");
|
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, "retobject" ) == 0 ) return true;
|
||||||
if ( strcmp(token, "busy" ) == 0 ) return true;
|
if ( strcmp(token, "busy" ) == 0 ) return true;
|
||||||
if ( strcmp(token, "factory" ) == 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, "search" ) == 0 ) return true;
|
||||||
if ( strcmp(token, "radar" ) == 0 ) return true;
|
if ( strcmp(token, "radar" ) == 0 ) return true;
|
||||||
if ( strcmp(token, "detect" ) == 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, "getresearchdone" ) == 0 ) return "getresearchdone ( );";
|
||||||
if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( rank );";
|
if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( rank );";
|
||||||
if ( strcmp(token, "retobjectbyid") == 0 ) return "retobjectbyid ( 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, "factory" ) == 0 ) return "object.factory ( cat );";
|
||||||
|
if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );";
|
||||||
if ( strcmp(token, "search" ) == 0 ) return "search ( );";
|
if ( strcmp(token, "search" ) == 0 ) return "search ( );";
|
||||||
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );";
|
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );";
|
||||||
if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );";
|
if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );";
|
||||||
|
|
|
@ -70,6 +70,11 @@ CBotTypResult CScript::cNull(CBotVar* &var, void* user)
|
||||||
return CBotTypResult(CBotTypFloat);
|
return CBotTypResult(CBotTypFloat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CBotTypResult CScript::cClassNull(CBotVar* thisclass, CBotVar* &var)
|
||||||
|
{
|
||||||
|
return CScript::cNull(var, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// Compiling a procedure with a single real number.
|
// Compiling a procedure with a single real number.
|
||||||
|
|
||||||
CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
|
CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
|
||||||
|
@ -538,6 +543,51 @@ bool CScript::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exce
|
||||||
return true;
|
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)"
|
// Instruction "object.factory(cat)"
|
||||||
|
|
||||||
bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
|
bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
|
||||||
|
|
|
@ -193,9 +193,11 @@ private:
|
||||||
public:
|
public:
|
||||||
static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var);
|
static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var);
|
||||||
static CBotTypResult cClassOneFloat(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 rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
|
||||||
static bool rFactory(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:
|
private:
|
||||||
static bool Process(CScript* script, CBotVar* result, int &exception);
|
static bool Process(CScript* script, CBotVar* result, int &exception);
|
||||||
|
|
Loading…
Reference in New Issue