Reverted factory() to its original design; reworked syntax of other object.functions() accordingly; improved compatibility with CeeBot4 SCHOOL
parent
adda82819c
commit
9a33551a03
|
@ -99,6 +99,10 @@ const char* GetObjectName(ObjectType type)
|
|||
if ( type == OBJECT_MOBILEts ) return "TrackedSniffer";
|
||||
if ( type == OBJECT_MOBILEfs ) return "WingedSniffer";
|
||||
if ( type == OBJECT_MOBILEis ) return "LeggedSniffer";
|
||||
if ( type == OBJECT_MOBILEwb ) return "WheeledBuilder";
|
||||
if ( type == OBJECT_MOBILEtb ) return "TrackedBuilder";
|
||||
if ( type == OBJECT_MOBILEfb ) return "WingedBuilder";
|
||||
if ( type == OBJECT_MOBILEib ) return "LeggedBuilder";
|
||||
if ( type == OBJECT_MOBILErt ) return "Thumper";
|
||||
if ( type == OBJECT_MOBILErc ) return "PhazerShooter";
|
||||
if ( type == OBJECT_MOBILErr ) return "Recycler";
|
||||
|
@ -519,11 +523,11 @@ const char* GetHelpText(const char *token)
|
|||
if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( rank );";
|
||||
if ( strcmp(token, "retobjectbyid") == 0 ) return "retobjectbyid ( rank );";
|
||||
if ( strcmp(token, "progfunc" ) == 0 ) return "progfunc ( funcname );";
|
||||
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, "busy" ) == 0 ) return "busy ( );";
|
||||
if ( strcmp(token, "factory" ) == 0 ) return "factory ( cat, program, object );";
|
||||
if ( strcmp(token, "research" ) == 0 ) return "research ( type );";
|
||||
if ( strcmp(token, "takeoff" ) == 0 ) return "takeoff ( );";
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return "destroy ( );";
|
||||
if ( strcmp(token, "search" ) == 0 ) return "search ( cat, pos, min, max, sens, filter );";
|
||||
if ( strcmp(token, "searchall" ) == 0 ) return "searchall ( cat, pos, min, max, sens, filter );";
|
||||
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens, filter );";
|
||||
|
|
|
@ -428,25 +428,30 @@ bool CScriptFunctions::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* resul
|
|||
}
|
||||
|
||||
|
||||
// Compilation of instruction "object.factory(cat, program)"
|
||||
// Compilation of instruction "factory(cat, program [, object])"
|
||||
|
||||
CBotTypResult CScriptFunctions::cFactory(CBotVar* thisclass, CBotVar* &var)
|
||||
CBotTypResult CScriptFunctions::cFactory(CBotVar* &var, void* user)
|
||||
{
|
||||
if ( var == nullptr ) return CBotTypResult(CBotErrLowParam);
|
||||
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
var = var->GetNext();
|
||||
if ( var != nullptr )
|
||||
{
|
||||
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadNum);
|
||||
if ( var->GetType() != CBotTypPointer ) return CBotTypResult(CBotErrBadParam);
|
||||
var = var->GetNext();
|
||||
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
||||
if ( var != nullptr )
|
||||
{
|
||||
if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadParam);
|
||||
var = var->GetNext();
|
||||
if ( var != nullptr ) return CBotTypResult(CBotErrOverParam);
|
||||
}
|
||||
}
|
||||
return CBotTypResult(CBotTypFloat);
|
||||
}
|
||||
|
||||
// Instruction "object.factory(cat, program)"
|
||||
// Instruction "factory(cat, program [, object])"
|
||||
|
||||
bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
bool CScriptFunctions::rFactory(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
CScript* script = static_cast<CScript*>(user);
|
||||
CObject* pThis = script->m_object;
|
||||
|
@ -457,21 +462,24 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
|
|||
|
||||
ObjectType type = static_cast<ObjectType>(var->GetValInt());
|
||||
var = var->GetNext();
|
||||
std::string program;
|
||||
if ( var != nullptr )
|
||||
program = var->GetValString();
|
||||
else
|
||||
program = "";
|
||||
|
||||
CObject* factory = static_cast<CObject*>(thisclass->GetUserPtr());
|
||||
CObject* factory = static_cast<CObject*>(var->GetUserPtr());
|
||||
if (factory == nullptr)
|
||||
{
|
||||
exception = ERR_UNKNOWN;
|
||||
result->SetValInt(ERR_UNKNOWN);
|
||||
GetLogger()->Error("in object.factory() - factory is nullptr");
|
||||
GetLogger()->Error("in factory() - factory is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
var = var->GetNext();
|
||||
std::string program;
|
||||
if ( var != nullptr )
|
||||
program = var->GetValString();
|
||||
|
||||
else
|
||||
program = "";
|
||||
|
||||
if ( pThis->GetTeam() != factory->GetTeam() && factory->GetTeam() != 0 )
|
||||
{
|
||||
exception = ERR_ENEMY_OBJECT;
|
||||
|
@ -486,7 +494,7 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
|
|||
{
|
||||
exception = ERR_UNKNOWN;
|
||||
result->SetValInt(ERR_UNKNOWN);
|
||||
GetLogger()->Error("in object.factory() - automat is nullptr");
|
||||
GetLogger()->Error("in factory() - automat is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -597,7 +605,7 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu
|
|||
|
||||
// Instruction "object.takeoff()"
|
||||
|
||||
bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
bool CScriptFunctions::rTakeOff(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
CScript* script = static_cast<CScript*>(user);
|
||||
CObject* pThis = script->m_object;
|
||||
|
@ -605,8 +613,7 @@ bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* resul
|
|||
Error err;
|
||||
|
||||
exception = 0;
|
||||
|
||||
CObject* base = static_cast<CObject*>(thisclass->GetUserPtr());
|
||||
CObject* base = static_cast<CObject*>(var->GetUserPtr());
|
||||
CAuto* automat = base->GetAuto();
|
||||
|
||||
if ( pThis->GetTeam() != base->GetTeam() && base->GetTeam() != 0 )
|
||||
|
@ -1291,10 +1298,10 @@ bool CScriptFunctions::rBuild(CBotVar* var, CBotVar* result, int& exception, voi
|
|||
|
||||
oType = pThis->GetType();
|
||||
|
||||
if ( oType != OBJECT_MOBILEfa && // allowed only for grabber bots && humans
|
||||
oType != OBJECT_MOBILEta &&
|
||||
oType != OBJECT_MOBILEwa &&
|
||||
oType != OBJECT_MOBILEia &&
|
||||
if ( oType != OBJECT_MOBILEfb && // allowed only for builder bots && humans
|
||||
oType != OBJECT_MOBILEtb &&
|
||||
oType != OBJECT_MOBILEwb &&
|
||||
oType != OBJECT_MOBILEib &&
|
||||
oType != OBJECT_HUMAN &&
|
||||
oType != OBJECT_TECH )
|
||||
{
|
||||
|
@ -3298,9 +3305,9 @@ void CScriptFunctions::Init()
|
|||
bc->AddItem("team", CBotTypResult(CBotTypInt), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddItem("velocity", CBotTypResult(CBotTypClass, "point"), CBotVar::ProtectionLevel::ReadOnly);
|
||||
bc->AddFunction("busy", rBusy, cBusy);
|
||||
bc->AddFunction("factory", rFactory, cFactory);
|
||||
//bc->AddFunction("factory", rFactory, cFactory);
|
||||
bc->AddFunction("research", rResearch, cClassOneFloat);
|
||||
bc->AddFunction("takeoff", rTakeOff, cClassNull);
|
||||
//bc->AddFunction("takeoff", rTakeOff);
|
||||
bc->AddFunction("destroy", rDestroy, cClassNull);
|
||||
|
||||
CBotProgram::AddFunction("endmission",rEndMission,cEndMission);
|
||||
|
@ -3365,8 +3372,10 @@ void CScriptFunctions::Init()
|
|||
CBotProgram::AddFunction("penup", rPenUp, cNull);
|
||||
CBotProgram::AddFunction("pencolor", rPenColor, cOneFloat);
|
||||
CBotProgram::AddFunction("penwidth", rPenWidth, cOneFloat);
|
||||
CBotProgram::AddFunction("factory", rFactory, cFactory);
|
||||
|
||||
CBotProgram::AddFunction("camerafocus", rCameraFocus, cOneObject);
|
||||
CBotProgram::AddFunction("takeoff", rTakeOff, cOneObject);
|
||||
|
||||
SetFileAccessHandler(MakeUnique<CBotFileAccessHandlerColobot>());
|
||||
}
|
||||
|
|
|
@ -81,6 +81,10 @@ private:
|
|||
static CBot::CBotTypResult cMessage(CBot::CBotVar* &var, void* user);
|
||||
static CBot::CBotTypResult cPenDown(CBot::CBotVar* &var, void* user);
|
||||
|
||||
static CBot::CBotTypResult cFactory(CBot::CBotVar* &var, void* user);
|
||||
//static CBot::CBotTypResult cTakeOff(CBot::CBotVar* &var, void* user);
|
||||
|
||||
|
||||
static CBot::CBotTypResult cOnePoint(CBot::CBotVar* &var, void* user);
|
||||
static CBot::CBotTypResult cOneObject(CBot::CBotVar* &var, void* user);
|
||||
|
||||
|
@ -144,16 +148,15 @@ private:
|
|||
static bool rPenWidth(CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
static bool rCameraFocus(CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
|
||||
static bool rTakeOff(CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
static bool rFactory(CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
|
||||
static CBot::CBotTypResult cBusy(CBot::CBotVar* thisclass, CBot::CBotVar* &var);
|
||||
static CBot::CBotTypResult cFactory(CBot::CBotVar* thisclass, CBot::CBotVar* &var);
|
||||
static CBot::CBotTypResult cClassNull(CBot::CBotVar* thisclass, CBot::CBotVar* &var);
|
||||
static CBot::CBotTypResult cClassOneFloat(CBot::CBotVar* thisclass, CBot::CBotVar* &var);
|
||||
|
||||
static bool rBusy(CBot::CBotVar* thisclass, CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
static bool rFactory(CBot::CBotVar* thisclass, CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
static bool rResearch(CBot::CBotVar* thisclass, CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
static bool rTakeOff(CBot::CBotVar* thisclass, CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
static bool rDestroy(CBot::CBotVar* thisclass, CBot::CBotVar* var, CBot::CBotVar* result, int& exception, void* user);
|
||||
|
||||
static CBot::CBotTypResult cPointConstructor(CBot::CBotVar* pThis, CBot::CBotVar* &var);
|
||||
|
|
Loading…
Reference in New Issue