summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/restext.cpp1
-rw-r--r--src/object/auto/autofactory.cpp25
-rw-r--r--src/object/auto/autofactory.h6
-rw-r--r--src/object/brain.cpp17
-rw-r--r--src/object/brain.h1
-rw-r--r--src/object/robotmain.cpp2
-rw-r--r--src/script/cbottoken.cpp2
-rw-r--r--src/script/script.cpp63
-rw-r--r--src/script/script.h4
9 files changed, 103 insertions, 18 deletions
diff --git a/src/common/restext.cpp b/src/common/restext.cpp
index bbec7ec..ac40dad 100644
--- a/src/common/restext.cpp
+++ b/src/common/restext.cpp
@@ -540,6 +540,7 @@ void InitializeRestext()
+ stringsErr[ERR_GENERIC] = "Internal error - tell the developers";
stringsErr[ERR_CMD] = "Unknown command";
stringsErr[ERR_MANIP_VEH] = "Inappropriate bot";
stringsErr[ERR_MANIP_FLY] = "Impossible when flying";
diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp
index 6aca426..fb82497 100644
--- a/src/object/auto/autofactory.cpp
+++ b/src/object/auto/autofactory.cpp
@@ -24,6 +24,7 @@
#include "math/geometry.h"
#include "object/robotmain.h"
+#include "object/brain.h"
#include "physics/physics.h"
@@ -103,6 +104,8 @@ void CAutoFactory::Init()
m_fretPos = m_object->GetPosition(0);
+ m_program = nullptr;
+
CAuto::Init();
}
@@ -149,6 +152,15 @@ Error CAutoFactory::StartAction(int param)
}
+// Sets program for created robot
+
+void CAutoFactory::SetProgram(const char* program)
+{
+ m_program = new char[strlen(program)+1];
+ strcpy(m_program, program);
+}
+
+
// Management of an event.
bool CAutoFactory::EventProcess(const Event &event)
@@ -377,7 +389,7 @@ bool CAutoFactory::EventProcess(const Event &event)
delete fret;
}
- vehicle = SearchVehicle();
+ m_vehicle = vehicle = SearchVehicle();
if ( vehicle != 0 )
{
physics = vehicle->GetPhysics();
@@ -476,6 +488,17 @@ bool CAutoFactory::EventProcess(const Event &event)
m_object->SetZoomZ(10+i, 0.30f);
}
+ if ( m_program != nullptr )
+ {
+ CBrain* brain = m_vehicle->GetBrain();
+ if ( brain != nullptr )
+ {
+ brain->SendProgram(0, const_cast<const char*>(m_program));
+ brain->SetScriptRun(0);
+ brain->RunProgram(0);
+ }
+ }
+
SetBusy(false);
UpdateInterface();
diff --git a/src/object/auto/autofactory.h b/src/object/auto/autofactory.h
index e5a415b..d9350e6 100644
--- a/src/object/auto/autofactory.h
+++ b/src/object/auto/autofactory.h
@@ -49,6 +49,7 @@ public:
bool EventProcess(const Event &event);
Error StartAction(int param);
+ void SetProgram(const char* program);
bool CreateInterface(bool bSelect);
@@ -71,7 +72,10 @@ protected:
float m_progress;
float m_speed;
float m_lastParticle;
- Math::Vector m_fretPos;
+ Math::Vector m_fretPos;
int m_channelSound;
+
+ CObject* m_vehicle;
+ char* m_program;
};
diff --git a/src/object/brain.cpp b/src/object/brain.cpp
index 266a8ac..56221b1 100644
--- a/src/object/brain.cpp
+++ b/src/object/brain.cpp
@@ -2720,6 +2720,23 @@ bool CBrain::ReadSoluce(char* filename)
return true;
}
+// Load a script from text buffer.
+
+bool CBrain::SendProgram(int rank, const char* buffer)
+{
+ if ( m_script[rank] == 0 )
+ {
+ m_script[rank] = new CScript(m_object, &m_secondaryTask);
+ }
+
+ if ( m_script[rank]->SendScript(buffer) ) return true;
+
+ delete m_script[rank];
+ m_script[rank] = 0;
+
+ return false;
+}
+
// Load a script with a text file.
bool CBrain::ReadProgram(int rank, const char* filename)
diff --git a/src/object/brain.h b/src/object/brain.h
index eba8004..38fb96f 100644
--- a/src/object/brain.h
+++ b/src/object/brain.h
@@ -114,6 +114,7 @@ public:
char* GetScriptName(int rank);
void SetSoluceName(char *name);
char* GetSoluceName();
+ bool SendProgram(int rank, const char* buffer);
bool ReadSoluce(char* filename);
bool ReadProgram(int rank, const char* filename);
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 2957799..b959d44 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -874,7 +874,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), PR_READ);
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
- bc->AddFunction("factory", CScript::rFactory, CScript::cClassOneFloat);
+ bc->AddFunction("factory", CScript::rFactory, CScript::cFactory);
bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
// Initializes the class FILE.
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);