diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cbottoken.cpp | 40 | ||||
-rw-r--r-- | src/script/cbottoken.h | 1 | ||||
-rw-r--r-- | src/script/cmdtoken.cpp | 3 | ||||
-rw-r--r-- | src/script/dd.cpp | 1 | ||||
-rw-r--r-- | src/script/script.cpp | 1149 | ||||
-rw-r--r-- | src/script/script.h | 39 |
6 files changed, 975 insertions, 258 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index 95b259b..505228e 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -220,7 +220,6 @@ std::string GetHelpFilename(const char *token) { if ( strcmp(token, "if" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/if.txt"); if ( strcmp(token, "else" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/if.txt"); - if ( strcmp(token, "repeat" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/repeat.txt"); if ( strcmp(token, "for" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/for.txt"); if ( strcmp(token, "while" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/while.txt"); if ( strcmp(token, "do" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/do.txt"); @@ -250,7 +249,15 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "pow" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); if ( strcmp(token, "rand" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); if ( strcmp(token, "abs" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/expr.txt"); + if ( strcmp(token, "getbuild" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/getbuild.txt"); + 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, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.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, "research" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/research.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"); @@ -262,8 +269,9 @@ std::string GetHelpFilename(const char *token) if ( strcmp(token, "move" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/move.txt"); if ( strcmp(token, "turn" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/turn.txt"); if ( strcmp(token, "goto" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/goto.txt"); - if ( strcmp(token, "find" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/find.txt"); if ( strcmp(token, "grab" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt"); + if ( strcmp(token, "canbuild" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/canbuild.txt"); + if ( strcmp(token, "build" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/build.txt"); if ( strcmp(token, "drop" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/drop.txt"); if ( strcmp(token, "sniff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/sniff.txt"); if ( strcmp(token, "receive" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/receive.txt"); @@ -367,7 +375,16 @@ bool IsFunction(const char *token) if ( strcmp(token, "pow" ) == 0 ) return true; if ( strcmp(token, "rand" ) == 0 ) return true; if ( strcmp(token, "abs" ) == 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, "progfunc" ) == 0 ) return true; + if ( strcmp(token, "busy" ) == 0 ) return true; + if ( strcmp(token, "factory" ) == 0 ) return true; + if ( strcmp(token, "research" ) == 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; @@ -380,8 +397,9 @@ bool IsFunction(const char *token) if ( strcmp(token, "move" ) == 0 ) return true; if ( strcmp(token, "turn" ) == 0 ) return true; if ( strcmp(token, "goto" ) == 0 ) return true; - if ( strcmp(token, "find" ) == 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; @@ -432,7 +450,6 @@ const char* GetHelpText(const char *token) { if ( strcmp(token, "if" ) == 0 ) return "if ( condition ) { bloc }"; if ( strcmp(token, "else" ) == 0 ) return "else { bloc }"; - if ( strcmp(token, "repeat" ) == 0 ) return "repeat ( number )"; if ( strcmp(token, "for" ) == 0 ) return "for ( before ; condition ; end )"; if ( strcmp(token, "while" ) == 0 ) return "while ( condition ) { bloc }"; if ( strcmp(token, "do" ) == 0 ) return "do { bloc } while ( condition );"; @@ -451,7 +468,16 @@ const char* GetHelpText(const char *token) if ( strcmp(token, "pow" ) == 0 ) return "pow ( x, y );"; if ( strcmp(token, "rand" ) == 0 ) return "rand ( );"; if ( strcmp(token, "abs" ) == 0 ) return "abs ( value );"; - if ( strcmp(token, "retobject" ) == 0 ) return "retobject ( );"; + 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 );"; + 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, "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 );"; @@ -464,8 +490,9 @@ const char* GetHelpText(const char *token) 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, "find" ) == 0 ) return "find ( cat );"; 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 );"; @@ -508,4 +535,3 @@ const char* GetHelpText(const char *token) return ""; } - diff --git a/src/script/cbottoken.h b/src/script/cbottoken.h index bc53f77..976d856 100644 --- a/src/script/cbottoken.h +++ b/src/script/cbottoken.h @@ -36,4 +36,3 @@ extern bool IsType(const char *token); extern bool IsFunction(const char *token); extern const char* GetHelpText(const char *token); - diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp index ab0528b..69df68b 100644 --- a/src/script/cmdtoken.cpp +++ b/src/script/cmdtoken.cpp @@ -401,6 +401,7 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def) if ( Cmd(p, "ApolloAntenna" ) ) return OBJECT_APOLLO5; if ( Cmd(p, "Me" ) ) return OBJECT_HUMAN; if ( Cmd(p, "Tech" ) ) return OBJECT_TECH; + if ( Cmd(p, "MissionController" ) ) return OBJECT_CONTROLLER; return def; } @@ -647,6 +648,7 @@ const char* GetTypeObject(ObjectType type) if ( type == OBJECT_APOLLO5 ) return "ApolloAntenna"; if ( type == OBJECT_HUMAN ) return "Me"; if ( type == OBJECT_TECH ) return "Tech"; + if ( type == OBJECT_CONTROLLER ) return "MissionController"; return ""; } @@ -945,4 +947,3 @@ Gfx::Color OpColor(char *line, const char *op, Gfx::Color def) return color; } - diff --git a/src/script/dd.cpp b/src/script/dd.cpp index 4110813..a7f5eb9 100644 --- a/src/script/dd.cpp +++ b/src/script/dd.cpp @@ -173,3 +173,4 @@ bool rSpace(CBotVar* var, CBotVar* result, int& exception, void* user) } return true; } + diff --git a/src/script/script.cpp b/src/script/script.cpp index d5fe2ce..b03702c 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -33,11 +33,17 @@ #include "object/object.h" #include "object/robotmain.h" #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" +#include "sound/sound.h" + #include "ui/interface.h" #include "ui/edit.h" #include "ui/list.h" @@ -64,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) @@ -75,6 +86,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) @@ -144,6 +160,18 @@ CBotTypResult CScript::cString(CBotVar* &var, void* user) return CBotTypResult(CBotTypFloat); } +// Compiling a procedure with a single string, returning string. + +CBotTypResult CScript::cStringString(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypString && + var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypString); +} + // Seeking value in an array of integers. @@ -312,6 +340,127 @@ bool CScript::rAbs(CBotVar* var, CBotVar* result, int& exception, void* user) return true; } +// Compilation of the instruction "endmission(result, delay)" + +CBotTypResult CScript::cEndMission(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(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypFloat); +} + +// Instruction "endmission(result, delay)" + +bool CScript::rEndMission(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + Error ended; + float delay; + + ended = static_cast<Error>(var->GetValFloat()); + var = var->GetNext(); + + delay = var->GetValFloat(); + + CRobotMain::GetInstancePointer()->SetEndMission(ended, delay); + return true; +} + +// Compilation of the instruction "playmusic(filename, repeat)" + +CBotTypResult CScript::cPlayMusic(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypFloat); +} + +// Instruction "playmusic(filename, repeat)" + +bool CScript::rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + std::string filename; + CBotString cbs; + bool repeat; + + cbs = var->GetValString(); + filename = std::string(cbs); + var = var->GetNext(); + + repeat = var->GetValInt(); + + CApplication::GetInstancePointer()->GetSound()->StopMusic(); + CApplication::GetInstancePointer()->GetSound()->PlayMusic(filename, repeat); + return true; +} + +// Instruction "stopmusic()" + +bool CScript::rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CApplication::GetInstancePointer()->GetSound()->StopMusic(); + return true; +} + +// Instruction "getbuild()" + +bool CScript::rGetBuild(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + result->SetValInt(g_build); + return true; +} + +// Instruction "getresearchenable()" + +bool CScript::rGetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + result->SetValInt(g_researchEnable); + return true; +} + +// Instruction "getresearchdone()" + +bool CScript::rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + result->SetValInt(g_researchDone); + return true; +} + +// Instruction "setbuild()" + +bool CScript::rSetBuild(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + g_build = var->GetValInt(); + CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE)); + return true; +} + +// Instruction "setresearchenable()" + +bool CScript::rSetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + g_researchEnable = var->GetValInt(); + CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE)); + return true; +} + +// Instruction "setresearchdone()" + +bool CScript::rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + g_researchDone = var->GetValInt(); + CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE)); + return true; +} // Compilation of the instruction "retobject(rank)". @@ -325,19 +474,37 @@ CBotTypResult CScript::cGetObject(CBotVar* &var, void* user) return CBotTypResult(CBotTypPointer, "object"); } +// Instruction "retobjectbyid(rank)". + +bool CScript::rGetObjectById(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CObject* pObj; + int rank; + + rank = var->GetValInt(); + + pObj = static_cast<CObject*>(CObjectManager::GetInstancePointer()->SearchInstance(rank)); + if ( pObj == 0 ) + { + result->SetPointer(0); + } + else + { + result->SetPointer(pObj->GetBotVar()); + } + return true; +} + // Instruction "retobject(rank)". bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast<CObject*>(user))->GetRunScript(); CObject* pObj; int rank; rank = var->GetValInt(); - CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); - - pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, rank)); + pObj = static_cast<CObject*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_OBJECT, rank)); if ( pObj == 0 ) { result->SetPointer(0); @@ -350,6 +517,457 @@ bool CScript::rGetObject(CBotVar* var, CBotVar* result, int& exception, void* us } +// Instruction "progfunc(funcname)". + +bool CScript::rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CBotString cbs; + const char* funcname; + std::string program; + + cbs = var->GetValString(); + funcname = cbs; + + //TODO: Translation :) + program = "extern void object::Auto()\n{\n\t\n\t//Automatically generated by progfunc(\""; + program += funcname; + program += "\");\n\t"; + program += funcname; + program += "();\n\t\n}\n"; + + result->SetValString(program.c_str()); + + return true; +} + +// Compilation of instruction "object.busy()" +CBotTypResult CScript::cBusy(CBotVar* thisclass, CBotVar* &var) +{ + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + return CBotTypResult(CBotTypBoolean); +} + +// Instruction "object.busy()" + +bool CScript::rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + exception = 0; + + CBotVar* classVars = thisclass->GetItemList(); // "category" + 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 ( automat != nullptr ) + result->SetValInt(automat->GetBusy()); + else + exception = ERR_WRONG_OBJ; + + 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_WRONG_OBJ; + + 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 instruction "object.factory(cat, program)" + +CBotTypResult CScript::cFactory(CBotVar* thisclass, CBotVar* &var) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) + { + if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + } + return CBotTypResult(CBotTypFloat); +} + +// Instruction "object.factory(cat, program)" + +bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + Error err; + + exception = 0; + + ObjectType type = static_cast<ObjectType>(var->GetValInt()); + var = var->GetNext(); + CBotString cbs; + const char* program; + if ( var != 0 ) + { + cbs = var->GetValString(); + program = cbs; + } + else + program = ""; + + 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); + CAutoFactory* automat = static_cast<CAutoFactory*>(factory->GetAuto()); + + if ( thisType == OBJECT_FACTORY ) + { + 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 ) + { + if ( automat != nullptr ) + { + err = automat->StartAction(type); + if ( err == ERR_OK ) automat->SetProgram(program); + } + else + err = ERR_GENERIC; + } + else + err = ERR_BUILD_DISABLED; + } + else + err = ERR_WRONG_OBJ; + + 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.research(type)" + +bool CScript::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) +{ + Error err; + + exception = 0; + + ResearchType type = static_cast<ResearchType>(var->GetValInt()); + + 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* center = CObjectManager::GetInstancePointer()->SearchInstance(rank); + CAuto* automat = center->GetAuto(); + + if ( thisType == OBJECT_RESEARCH || + thisType == OBJECT_LABO ) + { + bool ok = false; + if ( type == RESEARCH_iPAW || + type == RESEARCH_iGUN ) + { + if ( thisType != OBJECT_LABO ) + err = ERR_WRONG_OBJ; + else + ok = true; + } + else + { + if ( thisType != OBJECT_RESEARCH ) + err = ERR_WRONG_OBJ; + else + ok = true; + } + if ( ok ) + { + bool bEnable = ( g_researchEnable & type ); + if ( bEnable ) + { + if ( automat != nullptr ) + { + err = automat->StartAction(type); + } + else + err = ERR_GENERIC; + } + else + err = ERR_BUILD_DISABLED; + } + } + else + err = ERR_WRONG_OBJ; + + 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 "delete(rank[, exploType[, force]])". + +CBotTypResult CScript::cDelete(CBotVar* &var, void* user) +{ + if ( var == 0 ) return CBotTypResult(CBotErrLowParam); + + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + + if ( var != 0 ) + { + if ( var->GetType() != CBotTypInt ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + + if ( var != 0 ) + { + if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); + var = var->GetNext(); + } + } + + if ( var != 0 ) return CBotTypResult(CBotErrOverParam); + + return CBotTypResult(CBotTypFloat); +} + +// Instruction "delete(rank[, exploType[, force]])". + +bool CScript::rDelete(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CObject* pObj; + int rank; + int exploType = 0; + float force = 1.0f; + + rank = var->GetValInt(); + var->GetNext(); + if ( var != 0 ) + { + exploType = var->GetValInt(); + var->GetNext(); + if ( var != 0 ) + { + force = var->GetValFloat(); + } + } + + pObj = static_cast<CObject*>(CObjectManager::GetInstancePointer()->SearchInstance(rank)); + if ( pObj == 0 ) + { + return true; + } + else + { + if ( exploType ) + { + pObj->ExploObject(static_cast<ExploType>(exploType), force); + } + else + { + pObj->DeleteObject(false); + } + } + return true; +} + + + // Compilation of the instruction "search(type, pos)". CBotTypResult CScript::cSearch(CBotVar* &var, void* user) @@ -380,7 +998,6 @@ CBotTypResult CScript::cSearch(CBotVar* &var, void* user) bool CScript::rSearch(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast<CObject *>(user))->GetRunScript(); CObject *pObj, *pBest; CBotVar* array; Math::Vector pos, oPos; @@ -523,7 +1140,6 @@ CBotTypResult CScript::cRadar(CBotVar* &var, void* user) bool CScript::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) { - CScript* script = (static_cast<CObject *>(user))->GetRunScript(); CObject* pThis = static_cast<CObject *>(user); CObject *pObj, *pBest; CPhysics* physics; @@ -532,9 +1148,10 @@ bool CScript::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) RadarFilter filter; float best, minDist, maxDist, sens, iAngle, angle, focus, d, a; int type, oType, i; - bool bArray; + bool bArray = false; type = OBJECT_NULL; + array = 0; angle = 0.0f; focus = Math::PI*2.0f; minDist = 0.0f*g_unit; @@ -612,7 +1229,7 @@ bool CScript::rRadar(CBotVar* var, CBotVar* result, int& exception, void* user) if ( pObj->GetProxyActivate() ) continue; oType = pObj->GetType(); - if ( oType == OBJECT_TOTO ) continue; + if ( oType == OBJECT_TOTO || oType == OBJECT_CONTROLLER ) continue; if ( oType == OBJECT_RUINmobilew2 || oType == OBJECT_RUINmobilet1 || @@ -751,7 +1368,7 @@ bool CScript::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user) RadarFilter filter; float bGoal, best, minDist, maxDist, sens, iAngle, angle, focus, d, a; int type, oType, i; - bool bArray; + bool bArray = false; Error err; exception = 0; @@ -759,6 +1376,7 @@ bool CScript::rDetect(CBotVar* var, CBotVar* result, int& exception, void* user) if ( script->m_primaryTask == 0 ) // no task in progress? { type = OBJECT_NULL; + array = 0; angle = 0.0f; focus = 45.0f*Math::PI/180.0f; minDist = 0.0f*g_unit; @@ -947,6 +1565,148 @@ bool CScript::rDirection(CBotVar* var, CBotVar* result, int& exception, void* us return true; } +// compilation of instruction "canbuild ( category );" + +CBotTypResult CScript::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 "canbuid ( category );" +// returns true if this building can be built + +bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + ObjectType category = static_cast<ObjectType>(var->GetValInt()); //get category parameter + exception = 0; + + bool can = false; + + if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) || + (category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) || + (category == OBJECT_STATION && (g_build & BUILD_STATION)) || + (category == OBJECT_CONVERT && (g_build & BUILD_CONVERT)) || + (category == OBJECT_REPAIR && (g_build & BUILD_REPAIR)) || + (category == OBJECT_TOWER && (g_build & BUILD_TOWER)) || + (category == OBJECT_RESEARCH && (g_build & BUILD_RESEARCH)) || + (category == OBJECT_RADAR && (g_build & BUILD_RADAR)) || + (category == OBJECT_ENERGY && (g_build & BUILD_ENERGY)) || + (category == OBJECT_LABO && (g_build & BUILD_LABO)) || + (category == OBJECT_NUCLEAR && (g_build & BUILD_NUCLEAR)) || + (category == OBJECT_INFO && (g_build & BUILD_INFO)) || + (category == OBJECT_PARA && (g_build & BUILD_PARA)) || + (category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER))) + { + + //if we want to build not researched one + if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) || + (category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC)) + ) + { + can = false; + } + else + { + can = true; + } + + } + + result->SetValInt(can); + + + return true; +} + +// Instruction "build(type)" +// draws error if can not build (wher errormode stop), otherwise 0 <- error + +bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user) +{ + CScript* script = (static_cast<CObject *>(user))->GetRunScript(); + CObject* pThis = static_cast<CObject *>(user); + ObjectType oType; + ObjectType category; + Error err = ERR_BUILD_DISABLED; + + exception = 0; + + oType = pThis->GetType(); + + if ( oType != OBJECT_MOBILEfa && // allowed only for grabber bots + oType != OBJECT_MOBILEta && + oType != OBJECT_MOBILEwa && + oType != OBJECT_MOBILEia) + { + err = ERR_MANIP_VEH; //Wrong vehicle; + } + else + { + category = static_cast<ObjectType>(var->GetValInt()); //get category parameter + if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) || + (category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) || + (category == OBJECT_STATION && (g_build & BUILD_STATION)) || + (category == OBJECT_CONVERT && (g_build & BUILD_CONVERT)) || + (category == OBJECT_REPAIR && (g_build & BUILD_REPAIR)) || + (category == OBJECT_TOWER && (g_build & BUILD_TOWER)) || + (category == OBJECT_RESEARCH && (g_build & BUILD_RESEARCH)) || + (category == OBJECT_RADAR && (g_build & BUILD_RADAR)) || + (category == OBJECT_ENERGY && (g_build & BUILD_ENERGY)) || + (category == OBJECT_LABO && (g_build & BUILD_LABO)) || + (category == OBJECT_NUCLEAR && (g_build & BUILD_NUCLEAR)) || + (category == OBJECT_INFO && (g_build & BUILD_INFO)) || + (category == OBJECT_PARA && (g_build & BUILD_PARA)) || + (category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER))) + { + + //if we want to build not researched one + if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) || + (category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC)) + ) + { + err = ERR_BUILD_RESEARCH; + } + else + { + err = ERR_OK; + } + + } + + if (err == ERR_OK && script->m_primaryTask == 0) //if we can build and no task is present + { + script->m_primaryTask = new CTaskManager(script->m_object); + err = script->m_primaryTask->StartTaskBuild(category); + + if (err != ERR_OK) + { + delete script->m_primaryTask; + script->m_primaryTask = 0; + } + } + //When script is waiting for finishing this task, it sets ERR_OK, and continues executing Process + //without creating new task. I think, there was a problem with previous version in release configuration + //It did not init error variable in this situation, and code tried to use variable with trash inside + } + + if ( err != ERR_OK ) + { + result->SetValInt(err); // return error + if ( script->m_errMode == ERM_STOP ) + { + exception = err; + return false; + } + return true; + } + + return Process(script, result, exception); + +} // Compilation of the instruction "produce(pos, angle, type[, scriptName[, power]])" // or "produce(type[, power])". @@ -957,13 +1717,17 @@ CBotTypResult CScript::cProduce(CBotVar* &var, void* user) if ( var == 0 ) return CBotTypResult(CBotErrLowParam); - if ( var->GetType() <= CBotTypDouble ) { + if ( var->GetType() <= CBotTypDouble ) + { var = var->GetNext(); - if( var != 0 ) { + if( var != 0 ) + { if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); var = var->GetNext(); } - } else { + } + else + { ret = cPoint(var, user); if ( ret.GetType() != 0 ) return ret; @@ -975,11 +1739,13 @@ CBotTypResult CScript::cProduce(CBotVar* &var, void* user) if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); var = var->GetNext(); - if ( var != 0 ) { + if ( var != 0 ) + { if ( var->GetType() != CBotTypString ) return CBotTypResult(CBotErrBadString); var = var->GetNext(); - if ( var != 0 ) { + if ( var != 0 ) + { if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum); var = var->GetNext(); } @@ -1006,7 +1772,8 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user ObjectType type; float power; - if ( var->GetType() <= CBotTypDouble ) { + if ( var->GetType() <= CBotTypDouble ) + { type = static_cast<ObjectType>(var->GetValInt()); var = var->GetNext(); @@ -1021,7 +1788,9 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user power = -1.0f; name = ""; - } else { + } + else + { if ( !GetPoint(var, exception, pos) ) return true; angle = var->GetValFloat()*Math::PI/180.0f; @@ -1030,16 +1799,22 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user type = static_cast<ObjectType>(var->GetValInt()); var = var->GetNext(); - if ( var != 0 ) { + if ( var != 0 ) + { cbs = var->GetValString(); name = cbs; var = var->GetNext(); - if ( var != 0 ) { + if ( var != 0 ) + { power = var->GetValFloat(); - } else { + } + else + { power = -1.0f; } - } else { + } + else + { name = ""; power = -1.0f; } @@ -1086,12 +1861,11 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } object->SetActivity(false); } - else - if ( type == OBJECT_MOTHER || - type == OBJECT_ANT || - type == OBJECT_SPIDER || - type == OBJECT_BEE || - type == OBJECT_WORM ) + else if ( type == OBJECT_MOTHER || + type == OBJECT_ANT || + type == OBJECT_SPIDER || + type == OBJECT_BEE || + type == OBJECT_WORM ) { CObject* egg; @@ -1110,30 +1884,29 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } object->SetActivity(false); } - else - if ( type == OBJECT_PORTICO || - type == OBJECT_BASE || - type == OBJECT_DERRICK || - type == OBJECT_FACTORY || - type == OBJECT_STATION || - type == OBJECT_CONVERT || - type == OBJECT_REPAIR || - type == OBJECT_DESTROYER|| - type == OBJECT_TOWER || - type == OBJECT_NEST || - type == OBJECT_RESEARCH || - type == OBJECT_RADAR || - type == OBJECT_INFO || - type == OBJECT_ENERGY || - type == OBJECT_LABO || - type == OBJECT_NUCLEAR || - type == OBJECT_PARA || - type == OBJECT_SAFE || - type == OBJECT_HUSTON || - type == OBJECT_TARGET1 || - type == OBJECT_TARGET2 || - type == OBJECT_START || - type == OBJECT_END ) + else if ( type == OBJECT_PORTICO || + type == OBJECT_BASE || + type == OBJECT_DERRICK || + type == OBJECT_FACTORY || + type == OBJECT_STATION || + type == OBJECT_CONVERT || + type == OBJECT_REPAIR || + type == OBJECT_DESTROYER|| + type == OBJECT_TOWER || + type == OBJECT_NEST || + type == OBJECT_RESEARCH || + type == OBJECT_RADAR || + type == OBJECT_INFO || + type == OBJECT_ENERGY || + type == OBJECT_LABO || + type == OBJECT_NUCLEAR || + type == OBJECT_PARA || + type == OBJECT_SAFE || + type == OBJECT_HUSTON || + type == OBJECT_TARGET1 || + type == OBJECT_TARGET2 || + type == OBJECT_START || + type == OBJECT_END ) { object = new CObject(); if ( !object->CreateBuilding(pos, angle, 0, type) ) @@ -1145,12 +1918,11 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user object->SetActivity(false); script->m_main->CreateShortcuts(); } - else - if ( type == OBJECT_FLAGb || - type == OBJECT_FLAGr || - type == OBJECT_FLAGg || - type == OBJECT_FLAGy || - type == OBJECT_FLAGv ) + else if ( type == OBJECT_FLAGb || + type == OBJECT_FLAGr || + type == OBJECT_FLAGg || + type == OBJECT_FLAGy || + type == OBJECT_FLAGv ) { object = new CObject(); if ( !object->CreateFlag(pos, angle, type) ) @@ -1161,38 +1933,37 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user } object->SetActivity(false); } - else - if ( type == OBJECT_HUMAN || - type == OBJECT_TECH || - type == OBJECT_TOTO || - type == OBJECT_MOBILEfa || - type == OBJECT_MOBILEta || - type == OBJECT_MOBILEwa || - type == OBJECT_MOBILEia || - type == OBJECT_MOBILEfc || - type == OBJECT_MOBILEtc || - type == OBJECT_MOBILEwc || - type == OBJECT_MOBILEic || - type == OBJECT_MOBILEfi || - type == OBJECT_MOBILEti || - type == OBJECT_MOBILEwi || - type == OBJECT_MOBILEii || - type == OBJECT_MOBILEfs || - type == OBJECT_MOBILEts || - type == OBJECT_MOBILEws || - type == OBJECT_MOBILEis || - type == OBJECT_MOBILErt || - type == OBJECT_MOBILErc || - type == OBJECT_MOBILErr || - type == OBJECT_MOBILErs || - type == OBJECT_MOBILEsa || - type == OBJECT_MOBILEtg || - type == OBJECT_MOBILEft || - type == OBJECT_MOBILEtt || - type == OBJECT_MOBILEwt || - type == OBJECT_MOBILEit || - type == OBJECT_MOBILEdr || - type == OBJECT_APOLLO2 ) + else if ( type == OBJECT_HUMAN || + type == OBJECT_TECH || + type == OBJECT_TOTO || + type == OBJECT_MOBILEfa || + type == OBJECT_MOBILEta || + type == OBJECT_MOBILEwa || + type == OBJECT_MOBILEia || + type == OBJECT_MOBILEfc || + type == OBJECT_MOBILEtc || + type == OBJECT_MOBILEwc || + type == OBJECT_MOBILEic || + type == OBJECT_MOBILEfi || + type == OBJECT_MOBILEti || + type == OBJECT_MOBILEwi || + type == OBJECT_MOBILEii || + type == OBJECT_MOBILEfs || + type == OBJECT_MOBILEts || + type == OBJECT_MOBILEws || + type == OBJECT_MOBILEis || + type == OBJECT_MOBILErt || + type == OBJECT_MOBILErc || + type == OBJECT_MOBILErr || + type == OBJECT_MOBILErs || + type == OBJECT_MOBILEsa || + type == OBJECT_MOBILEtg || + type == OBJECT_MOBILEft || + type == OBJECT_MOBILEtt || + type == OBJECT_MOBILEwt || + type == OBJECT_MOBILEit || + type == OBJECT_MOBILEdr || + type == OBJECT_APOLLO2 ) { object = new CObject(); if ( !object->CreateVehicle(pos, angle, type, power, false, false) ) @@ -1210,7 +1981,11 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user physics->SetFreeze(false); // can move } object->SetLock(false); // vehicle useable - object->SetManual(true); + // SetManual will affect bot speed + if (type == OBJECT_MOBILEdr) + { + object->SetManual(true); + } object->SetActivity(true); script->m_main->CreateShortcuts(); } @@ -1220,8 +1995,11 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user return true; } - object->ReadProgram(0, static_cast<const char*>(name)); - object->RunProgram(0); + if (name[0] != 0) + { + object->ReadProgram(0, static_cast<const char*>(name)); + object->RunProgram(0); + } result->SetValInt(0); // no error return true; @@ -1576,147 +2354,6 @@ bool CScript::rGoto(CBotVar* var, CBotVar* result, int& exception, void* user) return Process(script, result, exception); } -// Instruction "find(type)". - -bool CScript::rFind(CBotVar* var, CBotVar* result, int& exception, void* user) -{ - CScript* script = (static_cast<CObject *>(user))->GetRunScript(); - Math::Vector pos; - TaskGotoGoal goal; - TaskGotoCrash crash; - float altitude; - Error err; - CObject* pThis = static_cast<CObject *>(user); - CObject *pObj, *pBest; - CBotVar* array; - Math::Vector iPos, oPos; - float best, minDist, maxDist, iAngle, focus, d, a; - int type, oType, i; - bool bArray; - - exception = 0; - - if ( script->m_primaryTask == 0 ) // no task in progress? - { - type = OBJECT_NULL; - focus = Math::PI*2.0f; - minDist = 0.0f*g_unit; - maxDist = 1000.0f*g_unit; - - if ( var->GetType() == CBotTypArrayPointer ) - { - array = var->GetItemList(); - bArray = true; - } - else - { - type = var->GetValInt(); - bArray = false; - } - - CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); - - best = 100000.0f; - pBest = 0; - for ( i=0 ; i<1000000 ; i++ ) - { - pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i)); - if ( pObj == 0 ) break; - if ( pObj == pThis ) continue; - - if ( pObj->GetTruck() != 0 ) continue; // object transported? - if ( !pObj->GetActif() ) continue; - if ( pObj->GetProxyActivate() ) continue; - - oType = pObj->GetType(); - if ( oType == OBJECT_TOTO ) continue; - - if ( oType == OBJECT_RUINmobilew2 || - oType == OBJECT_RUINmobilet1 || - oType == OBJECT_RUINmobilet2 || - oType == OBJECT_RUINmobiler1 || - oType == OBJECT_RUINmobiler2 ) - { - oType = OBJECT_RUINmobilew1; // any ruin - } - - if ( oType == OBJECT_SCRAP2 || - oType == OBJECT_SCRAP3 || - oType == OBJECT_SCRAP4 || - oType == OBJECT_SCRAP5 ) // wastes? - { - oType = OBJECT_SCRAP1; // any waste - } - - if ( oType == OBJECT_BARRIER2 || - oType == OBJECT_BARRIER3 ) // barriers? - { - oType = OBJECT_BARRIER1; // any barrier - } - - if ( bArray ) - { - if ( !FindList(array, oType) ) continue; - } - else - { - if ( type != oType && type != OBJECT_NULL ) continue; - } - - oPos = pObj->GetPosition(0); - d = Math::DistanceProjected(iPos, oPos); - if ( d < minDist || d > maxDist ) continue; // too close or too far? - - if ( focus >= Math::PI*2.0f ) - { - if ( d < best ) - { - best = d; - pBest = pObj; - } - continue; - } - - a = Math::RotateAngle(oPos.x-iPos.x, iPos.z-oPos.z); // CW ! - if ( Math::TestAngle(a, iAngle-focus/2.0f, iAngle+focus/2.0f) ) - { - if ( d < best ) - { - best = d; - pBest = pObj; - } - } - } - - if ( pBest == 0 ) - { - exception = ERR_FIND_IMPOSSIBLE; - return false; - } - - pos = pBest->GetPosition(0); - goal = TGG_DEFAULT; - crash = TGC_DEFAULT; - altitude = 0.0f*g_unit; - - script->m_primaryTask = new CTaskManager(script->m_object); - err = script->m_primaryTask->StartTaskGoto(pos, altitude, goal, crash); - if ( err != ERR_OK ) - { - delete script->m_primaryTask; - script->m_primaryTask = 0; - result->SetValInt(err); // shows the error - if ( script->m_errMode == ERM_STOP ) - { - exception = err; - return false; - } - return true; - } - } - return Process(script, result, exception); -} - // Compilation "grab/drop(oper)". CBotTypResult CScript::cGrabDrop(CBotVar* &var, void* user) @@ -2391,8 +3028,8 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user) { script->m_primaryTask = new CTaskManager(script->m_object); x = var->GetValFloat(); - var = var->GetNext(); - var == 0 ? y=0.0f : y=var->GetValFloat(); + var = var->GetNext(); + var == 0 ? y=0.0f : y=var->GetValFloat(); err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f); if ( err != ERR_OK ) { @@ -2897,7 +3534,21 @@ void CScript::InitFonctions() CBotProgram::AddFunction("rand", rRand, CScript::cNull); CBotProgram::AddFunction("abs", rAbs, CScript::cOneFloat); + CBotProgram::AddFunction("endmission",rEndMission,CScript::cEndMission); + CBotProgram::AddFunction("playmusic", rPlayMusic ,CScript::cPlayMusic); + CBotProgram::AddFunction("stopmusic", rStopMusic ,CScript::cNull); + + CBotProgram::AddFunction("getbuild", rGetBuild, CScript::cNull); + CBotProgram::AddFunction("getresearchenable", rGetResearchEnable, CScript::cNull); + CBotProgram::AddFunction("getresearchdone", rGetResearchDone, CScript::cNull); + CBotProgram::AddFunction("setbuild", rSetBuild, CScript::cOneFloat); + CBotProgram::AddFunction("setresearchenable", rSetResearchEnable, CScript::cOneFloat); + CBotProgram::AddFunction("setresearchdone", rSetResearchDone, CScript::cOneFloat); + + CBotProgram::AddFunction("progfunc", rProgFunc, CScript::cStringString); CBotProgram::AddFunction("retobject", rGetObject, CScript::cGetObject); + CBotProgram::AddFunction("retobjectbyid", rGetObjectById, CScript::cGetObject); + CBotProgram::AddFunction("delete", rDelete, CScript::cDelete); CBotProgram::AddFunction("search", rSearch, CScript::cSearch); CBotProgram::AddFunction("radar", rRadar, CScript::cRadar); CBotProgram::AddFunction("detect", rDetect, CScript::cDetect); @@ -2911,7 +3562,6 @@ void CScript::InitFonctions() CBotProgram::AddFunction("move", rMove, CScript::cOneFloat); CBotProgram::AddFunction("turn", rTurn, CScript::cOneFloat); CBotProgram::AddFunction("goto", rGoto, CScript::cGoto); - CBotProgram::AddFunction("find", rFind, CScript::cOneFloat); CBotProgram::AddFunction("grab", rGrab, CScript::cGrabDrop); CBotProgram::AddFunction("drop", rDrop, CScript::cGrabDrop); CBotProgram::AddFunction("sniff", rSniff, CScript::cNull); @@ -2938,6 +3588,10 @@ void CScript::InitFonctions() CBotProgram::AddFunction("penup", rPenUp, CScript::cNull); CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat); CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat); + + CBotProgram::AddFunction("canbuild", rCanBuild, CScript::cCanBuild); + CBotProgram::AddFunction("build", rBuild, CScript::cOneFloat); + } // Object's destructor. @@ -3128,7 +3782,7 @@ bool CScript::Compile() { if ( liste.GetSize() == 0 ) { - strcpy(m_title, "<sans nom>"); + strcpy(m_title, "<extern missing>"); } else { @@ -3165,7 +3819,7 @@ bool CScript::Compile() { m_cursor1 = m_cursor2 = 0; } - strcpy(m_title, "<erreur>"); + strcpy(m_title, "<error>"); return false; } } @@ -3404,7 +4058,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i if ( var == 0 && baseName[0] != 0 ) { sprintf(buffer, "%s = null;", baseName); - list->SetName(rankList++, buffer); + list->SetItemName(rankList++, buffer); return; } @@ -3446,7 +4100,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i value = pStatic->GetValString(); p = value; sprintf(buffer, "%s = %s;", varName, p); - list->SetName(rankList++, buffer); + list->SetItemName(rankList++, buffer); } else if ( type == CBotTypString ) { @@ -3454,7 +4108,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i value = pStatic->GetValString(); p = value; sprintf(buffer, "%s = \"%s\";", varName, p); - list->SetName(rankList++, buffer); + list->SetItemName(rankList++, buffer); } else if ( type == CBotTypArrayPointer ) { @@ -3470,7 +4124,7 @@ void PutList(const char *baseName, bool bArray, CBotVar *var, Ui::CList *list, i else { sprintf(buffer, "%s = ?;", varName); - list->SetName(rankList++, buffer); + list->SetItemName(rankList++, buffer); } index ++; @@ -3829,13 +4483,20 @@ void CScript::New(Ui::CEdit* edit, const char* name) // Provided a script for all parts. -bool CScript::SendScript(char* text) +bool CScript::SendScript(const char* text) { - m_len = strlen(text); + /*m_len = strlen(text); m_script = new char[m_len+1]; strcpy(m_script, text); if ( !CheckToken() ) return false; - if ( !Compile() ) return false; + if ( !Compile() ) return false;*/ + + Ui::CEdit* edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9); + edit->SetMaxChar(Ui::EDITSTUDIOMAX); + edit->SetAutoIndent(m_engine->GetEditIndentMode()); + edit->SetText(text, true); + GetScript(edit); + m_interface->DeleteControl(EVENT_EDIT9); return true; } diff --git a/src/script/script.h b/src/script/script.h index 982d12b..7a5d075 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -38,13 +38,13 @@ class CDisplayText; class CEdit; class CInterface; class CList; -} /* Ui */ +} /* Ui */ namespace Gfx { class CEngine; class CTerrain; class CWater; -} /* Gfx */ +} /* Gfx */ @@ -78,7 +78,7 @@ public: void GetError(char* buffer); void New(Ui::CEdit* edit, const char* name); - bool SendScript(char* text); + bool SendScript(const char* text); bool ReadScript(const char* filename); bool WriteScript(const char* filename); bool ReadStack(FILE *file); @@ -94,16 +94,20 @@ 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); static CBotTypResult cString(CBotVar* &var, void* user); + static CBotTypResult cStringString(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); + static CBotTypResult cDelete(CBotVar* &var, void* user); static CBotTypResult cSearch(CBotVar* &var, void* user); 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); @@ -132,11 +136,25 @@ private: static bool rPow(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rRand(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rAbs(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rEndMission(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rPlayMusic(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rStopMusic(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rGetBuild(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rGetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rSetBuild(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rSetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rGetObjectById(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rGetObject(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* user); + static bool rDelete(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rSearch(CBotVar* var, CBotVar* result, int& exception, void* user); static bool rRadar(CBotVar* var, CBotVar* result, int& exception, void* user); 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 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); static bool rDistance2d(CBotVar* var, CBotVar* result, int& exception, void* user); @@ -174,6 +192,18 @@ 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 cBusy(CBotVar* thisclass, CBotVar* &var); + static CBotTypResult cFactory(CBotVar* thisclass, CBotVar* &var); + static CBotTypResult cClassNull(CBotVar* thisclass, CBotVar* &var); + static CBotTypResult cClassOneFloat(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 rResearch(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); static CObject* SearchInfo(CScript* script, CObject* object, float power); @@ -207,4 +237,3 @@ protected: float m_returnValue; }; - |