diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/cbottoken.cpp | 2 | ||||
-rw-r--r-- | src/script/script.cpp | 63 | ||||
-rw-r--r-- | src/script/script.h | 4 |
3 files changed, 54 insertions, 15 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp index b5e99f5..bf29e1d 100644 --- a/src/script/cbottoken.cpp +++ b/src/script/cbottoken.cpp @@ -470,7 +470,7 @@ 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, "busy" ) == 0 ) return "object.busy ( );"; - if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat );"; + if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat, program );"; 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 );"; diff --git a/src/script/script.cpp b/src/script/script.cpp index 250f052..1f86e71 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -86,11 +86,6 @@ 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) @@ -588,6 +583,23 @@ bool CScript::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e return true; } + +// Compilation of instruction "object.factory(cat)" + +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)" bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception) @@ -596,6 +608,18 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e 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" @@ -613,11 +637,10 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e classVars = classVars->GetNext(); // "id" int rank = classVars->GetValInt(); CObject* factory = CObjectManager::GetInstancePointer()->SearchInstance(rank); - CAuto* automat = factory->GetAuto(); + CAutoFactory* automat = static_cast<CAutoFactory*>(factory->GetAuto()); if ( thisType == OBJECT_FACTORY ) { - ObjectType type = static_cast<ObjectType>(var->GetValInt()); bool bEnable = false; if ( type == OBJECT_MOBILEwa ) @@ -724,10 +747,19 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e } if ( bEnable ) - err = automat->StartAction(type); + { + if ( automat != nullptr ) + { + err = automat->StartAction(type); + if ( err == ERR_OK ) automat->SetProgram(program); + } + else + err = ERR_GENERIC; + } else err = ERR_BUILD_DISABLED; - } else + } + else err = ERR_WRONG_OBJ; if ( err != ERR_OK ) @@ -4307,13 +4339,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 75f0d72..e3d3b7a 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -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); @@ -192,7 +192,7 @@ private: public: static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var); - static CBotTypResult cClassOneFloat(CBotVar* thisclass, CBotVar* &var); + static CBotTypResult cFactory(CBotVar* thisclass, CBotVar* &var); static CBotTypResult cClassNull(CBotVar* thisclass, CBotVar* &var); static bool rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception); |