Added researched(), canresearch() and buildingenabled()

closes #524
master
krzys-h 2015-07-22 17:08:51 +02:00
parent d5d8c0b29f
commit 393317fa48
3 changed files with 83 additions and 37 deletions

View File

@ -263,9 +263,6 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "ceil" ) == 0 ) helpfile = "cbot/expr";
if ( strcmp(token, "round" ) == 0 ) helpfile = "cbot/expr";
if ( strcmp(token, "trunc" ) == 0 ) helpfile = "cbot/expr";
if ( strcmp(token, "getbuild" ) == 0 ) helpfile = "cbot/getbuild";
if ( strcmp(token, "getresearchenable" ) == 0 ) helpfile = "cbot/getresen";
if ( strcmp(token, "getresearchdone" ) == 0 ) helpfile = "cbot/getresdo";
if ( strcmp(token, "retobject" ) == 0 ) helpfile = "cbot/retobj";
if ( strcmp(token, "errmode" ) == 0 ) helpfile = "cbot/errmode";
if ( strcmp(token, "busy" ) == 0 ) helpfile = "cbot/busy";
@ -280,13 +277,16 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "distance2d" ) == 0 ) helpfile = "cbot/dist2d";
if ( strcmp(token, "space" ) == 0 ) helpfile = "cbot/space";
if ( strcmp(token, "flatground" ) == 0 ) helpfile = "cbot/flatgrnd";
if ( strcmp(token, "canbuild" ) == 0 ) helpfile = "cbot/canbuild";
if ( strcmp(token, "canresearch" ) == 0 ) helpfile = "cbot/canresearch";
if ( strcmp(token, "researched" ) == 0 ) helpfile = "cbot/researched";
if ( strcmp(token, "buildingenabled") == 0 ) helpfile = "cbot/buildingenabled";
if ( strcmp(token, "build" ) == 0 ) helpfile = "cbot/build";
if ( strcmp(token, "wait" ) == 0 ) helpfile = "cbot/wait";
if ( strcmp(token, "move" ) == 0 ) helpfile = "cbot/move";
if ( strcmp(token, "turn" ) == 0 ) helpfile = "cbot/turn";
if ( strcmp(token, "goto" ) == 0 ) helpfile = "cbot/goto";
if ( strcmp(token, "grab" ) == 0 ) helpfile = "cbot/grab";
if ( strcmp(token, "canbuild" ) == 0 ) helpfile = "cbot/canbuild";
if ( strcmp(token, "build" ) == 0 ) helpfile = "cbot/build";
if ( strcmp(token, "drop" ) == 0 ) helpfile = "cbot/drop";
if ( strcmp(token, "sniff" ) == 0 ) helpfile = "cbot/sniff";
if ( strcmp(token, "receive" ) == 0 ) helpfile = "cbot/receive";
@ -348,7 +348,6 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "penup" ) == 0 ) helpfile = "cbot/penup";
if ( strcmp(token, "pencolor" ) == 0 ) helpfile = "cbot/pencolor";
if ( strcmp(token, "penwidth" ) == 0 ) helpfile = "cbot/penwidth";
if ( strcmp(token, "camerafocus" ) == 0 ) helpfile = "cbot/camerafocus";
if ( strcmp(token, "extern" ) == 0 ) helpfile = "cbot/extern";
if ( strcmp(token, "class" ) == 0 ) helpfile = "cbot/class";
if ( strcmp(token, "static" ) == 0 ) helpfile = "cbot/static";
@ -400,9 +399,6 @@ bool IsFunction(const char *token)
if ( strcmp(token, "ceil" ) == 0 ) return true;
if ( strcmp(token, "round" ) == 0 ) return true;
if ( strcmp(token, "trunc" ) == 0 ) return true;
if ( strcmp(token, "getbuild" ) == 0 ) return true;
if ( strcmp(token, "getresearchenable" ) == 0 ) return true;
if ( strcmp(token, "getresearchdone" ) == 0 ) return true;
if ( strcmp(token, "retobjectbyid") == 0 ) return true;
if ( strcmp(token, "retobject" ) == 0 ) return true;
if ( strcmp(token, "busy" ) == 0 ) return true;
@ -418,13 +414,16 @@ bool IsFunction(const char *token)
if ( strcmp(token, "distance2d" ) == 0 ) return true;
if ( strcmp(token, "space" ) == 0 ) return true;
if ( strcmp(token, "flatground" ) == 0 ) return true;
if ( strcmp(token, "canbuild" ) == 0 ) return true;
if ( strcmp(token, "canresearch" ) == 0 ) return true;
if ( strcmp(token, "researched" ) == 0 ) return true;
if ( strcmp(token, "buildingenabled") == 0 ) return true;
if ( strcmp(token, "build" ) == 0 ) return true;
if ( strcmp(token, "wait" ) == 0 ) return true;
if ( strcmp(token, "move" ) == 0 ) return true;
if ( strcmp(token, "turn" ) == 0 ) return true;
if ( strcmp(token, "goto" ) == 0 ) return true;
if ( strcmp(token, "grab" ) == 0 ) return true;
if ( strcmp(token, "canbuild" ) == 0 ) return true;
if ( strcmp(token, "build" ) == 0 ) return true;
if ( strcmp(token, "drop" ) == 0 ) return true;
if ( strcmp(token, "sniff" ) == 0 ) return true;
if ( strcmp(token, "receive" ) == 0 ) return true;
@ -499,9 +498,6 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "ceil" ) == 0 ) return "ceil ( value );";
if ( strcmp(token, "round" ) == 0 ) return "round ( value );";
if ( strcmp(token, "trunc" ) == 0 ) return "trunc ( value );";
if ( strcmp(token, "getbuild" ) == 0 ) return "getbuild ( );";
if ( strcmp(token, "getresearchenable" ) == 0 ) return "getresearchenable ( );";
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, "progfunc" ) == 0 ) return "progfunc ( funcname );";
@ -510,7 +506,7 @@ const char* GetHelpText(const char *token)
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, "search" ) == 0 ) return "search ( cat, pos );";
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );";
if ( strcmp(token, "detect" ) == 0 ) return "detect ( cat );";
if ( strcmp(token, "direction" ) == 0 ) return "direction ( position );";
@ -518,13 +514,16 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "distance" ) == 0 ) return "distance ( p1, p2 );";
if ( strcmp(token, "space" ) == 0 ) return "space ( center, rmin, rmax, dist );";
if ( strcmp(token, "flatground") == 0 ) return "flatground ( center, rmax );";
if ( strcmp(token, "canbuild" ) == 0 ) return "canbuild ( category );";
if ( strcmp(token, "canresearch" ) == 0 ) return "canresearch ( research );";
if ( strcmp(token, "researched" ) == 0 ) return "researched ( research );";
if ( strcmp(token, "buildingenabled") == 0 ) return "buildingenabled ( category );";
if ( strcmp(token, "build" ) == 0 ) return "build ( category );";
if ( strcmp(token, "wait" ) == 0 ) return "wait ( time );";
if ( strcmp(token, "move" ) == 0 ) return "move ( distance );";
if ( strcmp(token, "turn" ) == 0 ) return "turn ( angle );";
if ( strcmp(token, "goto" ) == 0 ) return "goto ( position, altitude );";
if ( strcmp(token, "grab" ) == 0 ) return "grab ( order );";
if ( strcmp(token, "canbuild" ) == 0 ) return "canbuild ( category );";
if ( strcmp(token, "build" ) == 0 ) return "build ( category );";
if ( strcmp(token, "drop" ) == 0 ) return "drop ( order );";
if ( strcmp(token, "sniff" ) == 0 ) return "sniff ( );";
if ( strcmp(token, "receive" ) == 0 ) return "receive ( name, power );";
@ -535,7 +534,7 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "recycle" ) == 0 ) return "recycle ( );";
if ( strcmp(token, "shield" ) == 0 ) return "shield ( oper, radius );";
if ( strcmp(token, "fire" ) == 0 ) return "fire ( time );";
if ( strcmp(token, "aim" ) == 0 ) return "aim ( x, y );";
if ( strcmp(token, "aim" ) == 0 ) return "aim ( y, x );";
if ( strcmp(token, "motor" ) == 0 ) return "motor ( left, right );";
if ( strcmp(token, "jet" ) == 0 ) return "jet ( power );";
if ( strcmp(token, "topo" ) == 0 ) return "topo ( position );";

View File

@ -174,6 +174,28 @@ CBotTypResult CScriptFunctions::cStringString(CBotVar* &var, void* user)
return CBotTypResult(CBotTypString);
}
// compilation of instruction with one int returning int
CBotTypResult CScriptFunctions::cOneInt(CBotVar* &var, void* user)
{
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum);
var = var->GetNext();
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
return CBotTypResult(CBotTypInt);
}
// compilation of instruction with one int returning boolean
CBotTypResult CScriptFunctions::cOneIntReturnBool(CBotVar* &var, void* user)
{
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum);
var = var->GetNext();
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
return CBotTypResult(CBotTypBoolean);
}
// Seeking value in an array of integers.
@ -1342,30 +1364,47 @@ bool CScriptFunctions::rDirection(CBotVar* var, CBotVar* result, int& exception,
return true;
}
// compilation of instruction "canbuild ( category );"
CBotTypResult CScriptFunctions::cCanBuild(CBotVar* &var, void* user)
{
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
var = var->GetNext();
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
return CBotTypResult(CBotTypBoolean);
}
// Instruction "canbuild ( category );"
// returns true if this building can be built
bool CScriptFunctions::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CObject* pThis = static_cast<CObject *>(user);
ObjectType category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
ObjectType category = static_cast<ObjectType>(var->GetValInt());
exception = 0;
result->SetValInt(CRobotMain::GetInstancePointer()->CanBuild(category, pThis->GetTeam()));
return true;
}
bool CScriptFunctions::rCanResearch(CBotVar* var, CBotVar* result, int& exception, void* user)
{
ResearchType research = static_cast<ResearchType>(var->GetValInt());
exception = 0;
result->SetValInt(CRobotMain::GetInstancePointer()->IsResearchEnabled(research));
return true;
}
bool CScriptFunctions::rResearched(CBotVar* var, CBotVar* result, int& exception, void* user)
{
CObject* pThis = static_cast<CObject *>(user);
ResearchType research = static_cast<ResearchType>(var->GetValInt());
exception = 0;
result->SetValInt(CRobotMain::GetInstancePointer()->IsResearchDone(research, pThis->GetTeam()));
return true;
}
bool CScriptFunctions::rBuildingEnabled(CBotVar* var, CBotVar* result, int& exception, void* user)
{
ObjectType category = static_cast<ObjectType>(var->GetValInt());
exception = 0;
result->SetValInt(CRobotMain::GetInstancePointer()->IsBuildingEnabled(category));
return true;
}
// Instruction "build(type)"
// draws error if can not build (wher errormode stop), otherwise 0 <- error
@ -3648,9 +3687,16 @@ void CScriptFunctions::Init()
CBotProgram::AddFunction("getbuild", rGetBuild, CScriptFunctions::cNull);
CBotProgram::AddFunction("getresearchenable", rGetResearchEnable, CScriptFunctions::cNull);
CBotProgram::AddFunction("getresearchdone", rGetResearchDone, CScriptFunctions::cNull);
CBotProgram::AddFunction("setbuild", rSetBuild, CScriptFunctions::cOneFloat);
CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScriptFunctions::cOneFloat);
CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScriptFunctions::cOneFloat);
CBotProgram::AddFunction("setbuild", rSetBuild, CScriptFunctions::cOneInt);
CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScriptFunctions::cOneInt);
CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScriptFunctions::cOneInt);
CBotProgram::AddFunction("canbuild", rCanBuild, CScriptFunctions::cOneIntReturnBool);
CBotProgram::AddFunction("canresearch", rCanResearch, CScriptFunctions::cOneIntReturnBool);
CBotProgram::AddFunction("researched", rResearched, CScriptFunctions::cOneIntReturnBool);
CBotProgram::AddFunction("buildingenabled", rBuildingEnabled, CScriptFunctions::cOneIntReturnBool);
CBotProgram::AddFunction("build", rBuild, CScriptFunctions::cOneInt);
CBotProgram::AddFunction("retobject", rGetObject, CScriptFunctions::cGetObject);
CBotProgram::AddFunction("retobjectbyid", rGetObjectById, CScriptFunctions::cGetObject);
@ -3696,9 +3742,6 @@ void CScriptFunctions::Init()
CBotProgram::AddFunction("penwidth", rPenWidth, CScriptFunctions::cOneFloat);
CBotProgram::AddFunction("camerafocus", rCameraFocus, CScriptFunctions::cOneObject);
CBotProgram::AddFunction("canbuild", rCanBuild, CScriptFunctions::cCanBuild);
CBotProgram::AddFunction("build", rBuild, CScriptFunctions::cOneFloat);
}

View File

@ -50,6 +50,8 @@ private:
static CBotTypResult cTwoFloat(CBotVar* &var, void* user);
static CBotTypResult cString(CBotVar* &var, void* user);
static CBotTypResult cStringString(CBotVar* &var, void* user);
static CBotTypResult cOneInt(CBotVar* &var, void* user);
static CBotTypResult cOneIntReturnBool(CBotVar* &var, void* user);
static CBotTypResult cEndMission(CBotVar* &var, void* user);
static CBotTypResult cPlayMusic(CBotVar* &var, void* user);
static CBotTypResult cGetObject(CBotVar* &var, void* user);
@ -58,7 +60,6 @@ private:
static CBotTypResult cRadar(CBotVar* &var, void* user);
static CBotTypResult cDetect(CBotVar* &var, void* user);
static CBotTypResult cDirection(CBotVar* &var, void* user);
static CBotTypResult cCanBuild(CBotVar* &var, void* user);
static CBotTypResult cProduce(CBotVar* &var, void* user);
static CBotTypResult cDistance(CBotVar* &var, void* user);
static CBotTypResult cSpace(CBotVar* &var, void* user);
@ -109,6 +110,9 @@ private:
static bool rDetect(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rDirection(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rCanResearch(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rResearched(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rBuildingEnabled(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rBuild(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rProduce(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rDistance(CBotVar* var, CBotVar* result, int& exception, void* user);