Added object.factory(cat)

dev-ui
krzys-h 2013-05-18 16:44:22 +02:00
parent 07839a561f
commit 47d7b80507
8 changed files with 233 additions and 38 deletions

View File

@ -107,6 +107,12 @@ void CAuto::Start(int param)
{
}
// Starts an action
Error CAuto::StartAction(int param)
{
return ERR_GENERIC;
}
// Gete a type.

View File

@ -61,6 +61,8 @@ public:
virtual Error IsEnded();
virtual bool Abort();
virtual Error StartAction(int param);
virtual bool SetType(ObjectType type);
virtual bool SetValue(int rank, float value);
virtual bool SetString(char *string);

View File

@ -107,17 +107,59 @@ void CAutoFactory::Init()
}
// Starts an action
Error CAutoFactory::StartAction(int param)
{
CObject* fret;
ObjectType type = static_cast<ObjectType>(param);
if ( type != OBJECT_NULL )
{
if ( m_phase != AFP_WAIT )
{
return ERR_OK;
}
m_type = type;
fret = SearchFret(); // transform metal?
if ( fret == 0 )
{
return ERR_FACTORY_NULL;
}
if ( NearestVehicle() )
{
return ERR_FACTORY_NEAR;
}
SetBusy(true);
InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f);
UpdateInterface();
fret->SetLock(true); // usable metal
SoundManip(3.0f, 1.0f, 0.5f);
m_phase = AFP_CLOSE_S;
m_progress = 0.0f;
m_speed = 1.0f/3.0f;
return ERR_OK;
}
return ERR_GENERIC;
}
// Management of an event.
bool CAutoFactory::EventProcess(const Event &event)
{
ObjectType type;
CObject* fret;
CObject* vehicle;
Math::Matrix* mat;
CPhysics* physics;
Math::Vector pos, speed;
Math::Point dim;
ObjectType type;
float zoom, angle, prog;
int i;
@ -155,39 +197,12 @@ bool CAutoFactory::EventProcess(const Event &event)
if ( event.type == EVENT_OBJECT_FACTORYrs ) type = OBJECT_MOBILErs;
if ( event.type == EVENT_OBJECT_FACTORYsa ) type = OBJECT_MOBILEsa;
if ( type != OBJECT_NULL )
{
m_type = type;
Error err = StartAction(type);
if( err != ERR_OK && err != ERR_GENERIC )
m_displayText->DisplayError(err, m_object);
if ( m_phase != AFP_WAIT )
{
return false;
}
fret = SearchFret(); // transform metal?
if ( fret == 0 )
{
m_displayText->DisplayError(ERR_FACTORY_NULL, m_object);
return false;
}
if ( NearestVehicle() )
{
m_displayText->DisplayError(ERR_FACTORY_NEAR, m_object);
return false;
}
SetBusy(true);
InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f);
UpdateInterface();
fret->SetLock(true); // usable metal
SoundManip(3.0f, 1.0f, 0.5f);
m_phase = AFP_CLOSE_S;
m_progress = 0.0f;
m_speed = 1.0f/3.0f;
return true;
}
if( err != ERR_GENERIC )
return false;
}
if ( event.type != EVENT_FRAME ) return true;

View File

@ -48,6 +48,8 @@ public:
void Init();
bool EventProcess(const Event &event);
Error StartAction(int param);
bool CreateInterface(bool bSelect);
bool Write(char *line);

View File

@ -602,9 +602,6 @@ bool rPoint(CBotVar* pThis, CBotVar* var, CBotVar* pResult, int& Exception)
return true; // no interruption
}
//! Constructor of robot application
CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
{
@ -847,7 +844,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
CBotProgram::DefineNum("ResearchSubber", RESEARCH_SUBM);
CBotProgram::DefineNum("ResearchSniffer", RESEARCH_SNIFFER);
CBotProgram::
//? CBotProgram::
CBotProgram::DefineNum("PolskiPortalColobota", 1337);
@ -876,6 +873,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), PR_READ);
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), PR_READ);
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
bc->AddFunction("factory", CScript::rFactory, CScript::cClassOneFloat);
// Initializes the class FILE.
InitClassFILE();

View File

@ -253,6 +253,7 @@ 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, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.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");
@ -375,6 +376,7 @@ bool IsFunction(const char *token)
if ( strcmp(token, "getresearchdone" ) == 0 ) return true;
if ( strcmp(token, "retobjectbyid") == 0 ) return true;
if ( strcmp(token, "retobject" ) == 0 ) return true;
if ( strcmp(token, "factory" ) == 0 ) return true;
if ( strcmp(token, "search" ) == 0 ) return true;
if ( strcmp(token, "radar" ) == 0 ) return true;
if ( strcmp(token, "detect" ) == 0 ) return true;
@ -463,6 +465,7 @@ 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, "factory" ) == 0 ) return "object.factory ( cat );";
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 );";

View File

@ -35,6 +35,9 @@
#include "object/task/taskmanager.h"
#include "object/objman.h"
#include "object/auto/auto.h"
#include "object/auto/autofactory.h"
#include "physics/physics.h"
#include "script/cbottoken.h"
@ -78,6 +81,11 @@ CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
return CBotTypResult(CBotTypFloat);
}
CBotTypResult CScript::cClassOneFloat(CBotVar* thisclass, CBotVar* &var)
{
return CScript::cOneFloat(var, nullptr);
}
// Compiling a procedure with two real numbers.
CBotTypResult CScript::cTwoFloat(CBotVar* &var, void* user)
@ -491,6 +499,163 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us
return true;
}
// Instruction "object.factory(cat)"
bool CScript::rFactory(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* factory = CObjectManager::GetInstancePointer()->SearchInstance(rank);
CAuto* automat = factory->GetAuto();
if ( thisType == OBJECT_FACTORY )
{
ObjectType type = static_cast<ObjectType>(var->GetValInt());
bool bEnable = false;
if ( type == OBJECT_MOBILEwa )
{
bEnable = true;
}
if ( type == OBJECT_MOBILEta )
{
bEnable = g_researchDone&RESEARCH_TANK;
}
if ( type == OBJECT_MOBILEfa )
{
bEnable = g_researchDone&RESEARCH_FLY;
}
if ( type == OBJECT_MOBILEia )
{
bEnable = g_researchDone&RESEARCH_iPAW;
}
if ( type == OBJECT_MOBILEws )
{
bEnable = g_researchDone&RESEARCH_SNIFFER;
}
if ( type == OBJECT_MOBILEts )
{
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILEfs )
{
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
(g_researchDone&RESEARCH_FLY) );
}
if ( type == OBJECT_MOBILEis )
{
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
(g_researchDone&RESEARCH_iPAW) );
}
if ( type == OBJECT_MOBILEwc )
{
bEnable = g_researchDone&RESEARCH_CANON;
}
if ( type == OBJECT_MOBILEtc )
{
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILEfc )
{
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
(g_researchDone&RESEARCH_FLY) );
}
if ( type == OBJECT_MOBILEic )
{
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
(g_researchDone&RESEARCH_iPAW) );
}
if ( type == OBJECT_MOBILEwi )
{
bEnable = g_researchDone&RESEARCH_iGUN;
}
if ( type == OBJECT_MOBILEti )
{
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILEfi )
{
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
(g_researchDone&RESEARCH_FLY) );
}
if ( type == OBJECT_MOBILEii )
{
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
(g_researchDone&RESEARCH_iPAW) );
}
if ( type == OBJECT_MOBILErt )
{
bEnable = ( (g_researchDone&RESEARCH_THUMP) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILErc )
{
bEnable = ( (g_researchDone&RESEARCH_PHAZER) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILErr )
{
bEnable = ( (g_researchDone&RESEARCH_RECYCLER) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILErs )
{
bEnable = ( (g_researchDone&RESEARCH_SHIELD) &&
(g_researchDone&RESEARCH_TANK) );
}
if ( type == OBJECT_MOBILEsa )
{
bEnable = g_researchDone&RESEARCH_SUBM;
}
if ( bEnable )
err = automat->StartAction(type);
else
err = ERR_BUILD_DISABLED;
} 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;
}
// Compilation of the instruction "destroy(rank[, exploType[, force]])".
CBotTypResult CScript::cDestroy(CBotVar* &var, void* user)

View File

@ -94,7 +94,6 @@ protected:
bool Compile();
private:
static CBotTypResult cNull(CBotVar* &var, void* user);
static CBotTypResult cOneFloat(CBotVar* &var, void* user);
static CBotTypResult cTwoFloat(CBotVar* &var, void* user);
@ -191,6 +190,11 @@ private:
static bool rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user);
public:
static CBotTypResult cClassOneFloat(CBotVar* thisclass, CBotVar* &var);
static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
private:
static bool Process(CScript* script, CBotVar* result, int &exception);
static CObject* SearchInfo(CScript* script, CObject* object, float power);