summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cbottoken.cpp12
-rw-r--r--src/script/cmdtoken.cpp255
-rw-r--r--src/script/cmdtoken.h7
-rw-r--r--src/script/script.cpp377
-rw-r--r--src/script/script.h11
5 files changed, 347 insertions, 315 deletions
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index 505228e..81219df 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -253,10 +253,11 @@ std::string GetHelpFilename(const char *token)
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, "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, "takeoff" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/takeoff.txt");
if ( strcmp(token, "research" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/research.txt");
+ if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.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");
@@ -333,6 +334,7 @@ std::string GetHelpFilename(const char *token)
if ( strcmp(token, "penup" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penup.txt");
if ( strcmp(token, "pencolor" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/pencolor.txt");
if ( strcmp(token, "penwidth" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/penwidth.txt");
+ if ( strcmp(token, "camerafocus" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/camerafocus.txt");
if ( strcmp(token, "extern" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/extern.txt");
if ( strcmp(token, "class" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/class.txt");
if ( strcmp(token, "static" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/static.txt");
@@ -384,6 +386,7 @@ bool IsFunction(const char *token)
if ( strcmp(token, "busy" ) == 0 ) return true;
if ( strcmp(token, "factory" ) == 0 ) return true;
if ( strcmp(token, "research" ) == 0 ) return true;
+ if ( strcmp(token, "takeoff" ) == 0 ) return true;
if ( strcmp(token, "destroy" ) == 0 ) return true;
if ( strcmp(token, "search" ) == 0 ) return true;
if ( strcmp(token, "radar" ) == 0 ) return true;
@@ -439,6 +442,7 @@ bool IsFunction(const char *token)
if ( strcmp(token, "penup" ) == 0 ) return true;
if ( strcmp(token, "pencolor" ) == 0 ) return true;
if ( strcmp(token, "penwidth" ) == 0 ) return true;
+ if ( strcmp(token, "camerafocus" ) == 0 ) return true;
if ( strcmp(token, "sizeof" ) == 0 ) return true;
return false;
}
@@ -477,6 +481,7 @@ const char* GetHelpText(const char *token)
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, "search" ) == 0 ) return "search ( );";
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );";
@@ -532,6 +537,7 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "penup" ) == 0 ) return "penup ( );";
if ( strcmp(token, "pencolor" ) == 0 ) return "pencolor ( color );";
if ( strcmp(token, "penwidth" ) == 0 ) return "penwidth ( width );";
+ if ( strcmp(token, "camerafocus") == 0 ) return "camerafocus ( object );";
return "";
}
diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp
index 69df68b..6393505 100644
--- a/src/script/cmdtoken.cpp
+++ b/src/script/cmdtoken.cpp
@@ -35,6 +35,16 @@ char* SkipSpace(char *line)
return line;
}
+std::string GetCmd(char* line)
+{
+ line = SkipSpace(line);
+
+ int len = 0;
+ for(char* x = line; *x != 0 && *x != ' ' && *x != '\t' && *x != '\n'; x++, len++);
+
+ return std::string(line, len);
+}
+
// Checks if a line contains a command.
bool Cmd(char *line, const char *token)
@@ -42,8 +52,15 @@ bool Cmd(char *line, const char *token)
char* p;
line = SkipSpace(line);
+
p = strstr(line, token);
- return ( p == line ); // command at the beginning?
+ if(p != line) return false; // command at the beginning?
+
+ unsigned int len = 0;
+ for(char* x = p; *x != 0 && *x != ' ' && *x != '\t' && *x != '\n'; x++, len++);
+ if(len != strlen(token)) return false; // ends with space?
+
+ return true;
}
// Seeking an operator.
@@ -238,16 +255,6 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def)
if ( Cmd(p, "Mine" ) ) return OBJECT_BOMB;
if ( Cmd(p, "Firework" ) ) return OBJECT_WINFIRE;
if ( Cmd(p, "Bag" ) ) return OBJECT_BAG;
- if ( Cmd(p, "Greenery10" ) ) return OBJECT_PLANT10;
- if ( Cmd(p, "Greenery11" ) ) return OBJECT_PLANT11;
- if ( Cmd(p, "Greenery12" ) ) return OBJECT_PLANT12;
- if ( Cmd(p, "Greenery13" ) ) return OBJECT_PLANT13;
- if ( Cmd(p, "Greenery14" ) ) return OBJECT_PLANT14;
- if ( Cmd(p, "Greenery15" ) ) return OBJECT_PLANT15;
- if ( Cmd(p, "Greenery16" ) ) return OBJECT_PLANT16;
- if ( Cmd(p, "Greenery17" ) ) return OBJECT_PLANT17;
- if ( Cmd(p, "Greenery18" ) ) return OBJECT_PLANT18;
- if ( Cmd(p, "Greenery19" ) ) return OBJECT_PLANT19;
if ( Cmd(p, "Greenery0" ) ) return OBJECT_PLANT0;
if ( Cmd(p, "Greenery1" ) ) return OBJECT_PLANT1;
if ( Cmd(p, "Greenery2" ) ) return OBJECT_PLANT2;
@@ -258,26 +265,24 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def)
if ( Cmd(p, "Greenery7" ) ) return OBJECT_PLANT7;
if ( Cmd(p, "Greenery8" ) ) return OBJECT_PLANT8;
if ( Cmd(p, "Greenery9" ) ) return OBJECT_PLANT9;
+ if ( Cmd(p, "Greenery10" ) ) return OBJECT_PLANT10;
+ if ( Cmd(p, "Greenery11" ) ) return OBJECT_PLANT11;
+ if ( Cmd(p, "Greenery12" ) ) return OBJECT_PLANT12;
+ if ( Cmd(p, "Greenery13" ) ) return OBJECT_PLANT13;
+ if ( Cmd(p, "Greenery14" ) ) return OBJECT_PLANT14;
+ if ( Cmd(p, "Greenery15" ) ) return OBJECT_PLANT15;
+ if ( Cmd(p, "Greenery16" ) ) return OBJECT_PLANT16;
+ if ( Cmd(p, "Greenery17" ) ) return OBJECT_PLANT17;
+ if ( Cmd(p, "Greenery18" ) ) return OBJECT_PLANT18;
+ if ( Cmd(p, "Greenery19" ) ) return OBJECT_PLANT19;
if ( Cmd(p, "Tree0" ) ) return OBJECT_TREE0;
if ( Cmd(p, "Tree1" ) ) return OBJECT_TREE1;
if ( Cmd(p, "Tree2" ) ) return OBJECT_TREE2;
if ( Cmd(p, "Tree3" ) ) return OBJECT_TREE3;
if ( Cmd(p, "Tree4" ) ) return OBJECT_TREE4;
if ( Cmd(p, "Tree5" ) ) return OBJECT_TREE5;
- if ( Cmd(p, "Tree6" ) ) return OBJECT_TREE6;
- if ( Cmd(p, "Tree7" ) ) return OBJECT_TREE7;
- if ( Cmd(p, "Tree8" ) ) return OBJECT_TREE8;
- if ( Cmd(p, "Tree9" ) ) return OBJECT_TREE9;
- if ( Cmd(p, "Mushroom0" ) ) return OBJECT_MUSHROOM0;
if ( Cmd(p, "Mushroom1" ) ) return OBJECT_MUSHROOM1;
if ( Cmd(p, "Mushroom2" ) ) return OBJECT_MUSHROOM2;
- if ( Cmd(p, "Mushroom3" ) ) return OBJECT_MUSHROOM3;
- if ( Cmd(p, "Mushroom4" ) ) return OBJECT_MUSHROOM4;
- if ( Cmd(p, "Mushroom5" ) ) return OBJECT_MUSHROOM5;
- if ( Cmd(p, "Mushroom6" ) ) return OBJECT_MUSHROOM6;
- if ( Cmd(p, "Mushroom7" ) ) return OBJECT_MUSHROOM7;
- if ( Cmd(p, "Mushroom8" ) ) return OBJECT_MUSHROOM8;
- if ( Cmd(p, "Mushroom9" ) ) return OBJECT_MUSHROOM9;
if ( Cmd(p, "Home" ) ) return OBJECT_HOME1;
if ( Cmd(p, "Derrick" ) ) return OBJECT_DERRICK;
if ( Cmd(p, "BotFactory" ) ) return OBJECT_FACTORY;
@@ -323,47 +328,6 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def)
if ( Cmd(p, "Barrier1" ) ) return OBJECT_BARRIER1;
if ( Cmd(p, "Barrier2" ) ) return OBJECT_BARRIER2;
if ( Cmd(p, "Barrier3" ) ) return OBJECT_BARRIER3;
- if ( Cmd(p, "Barrier4" ) ) return OBJECT_BARRIER4;
- if ( Cmd(p, "Teen40" ) ) return OBJECT_TEEN40;
- if ( Cmd(p, "Teen41" ) ) return OBJECT_TEEN41;
- if ( Cmd(p, "Teen42" ) ) return OBJECT_TEEN42;
- if ( Cmd(p, "Teen43" ) ) return OBJECT_TEEN43;
- if ( Cmd(p, "Teen44" ) ) return OBJECT_TEEN44;
- if ( Cmd(p, "Teen45" ) ) return OBJECT_TEEN45;
- if ( Cmd(p, "Teen46" ) ) return OBJECT_TEEN46;
- if ( Cmd(p, "Teen47" ) ) return OBJECT_TEEN47;
- if ( Cmd(p, "Teen48" ) ) return OBJECT_TEEN48;
- if ( Cmd(p, "Teen49" ) ) return OBJECT_TEEN49;
- if ( Cmd(p, "Teen30" ) ) return OBJECT_TEEN30;
- if ( Cmd(p, "Teen31" ) ) return OBJECT_TEEN31;
- if ( Cmd(p, "Teen32" ) ) return OBJECT_TEEN32;
- if ( Cmd(p, "Teen33" ) ) return OBJECT_TEEN33;
- if ( Cmd(p, "Stone" ) ) return OBJECT_TEEN34;
- if ( Cmd(p, "Teen35" ) ) return OBJECT_TEEN35;
- if ( Cmd(p, "Teen36" ) ) return OBJECT_TEEN36;
- if ( Cmd(p, "Teen37" ) ) return OBJECT_TEEN37;
- if ( Cmd(p, "Teen38" ) ) return OBJECT_TEEN38;
- if ( Cmd(p, "Teen39" ) ) return OBJECT_TEEN39;
- if ( Cmd(p, "Teen20" ) ) return OBJECT_TEEN20;
- if ( Cmd(p, "Teen21" ) ) return OBJECT_TEEN21;
- if ( Cmd(p, "Teen22" ) ) return OBJECT_TEEN22;
- if ( Cmd(p, "Teen23" ) ) return OBJECT_TEEN23;
- if ( Cmd(p, "Teen24" ) ) return OBJECT_TEEN24;
- if ( Cmd(p, "Teen25" ) ) return OBJECT_TEEN25;
- if ( Cmd(p, "Teen26" ) ) return OBJECT_TEEN26;
- if ( Cmd(p, "Teen27" ) ) return OBJECT_TEEN27;
- if ( Cmd(p, "Teen28" ) ) return OBJECT_TEEN28;
- if ( Cmd(p, "Teen29" ) ) return OBJECT_TEEN29;
- if ( Cmd(p, "Teen10" ) ) return OBJECT_TEEN10;
- if ( Cmd(p, "Teen11" ) ) return OBJECT_TEEN11;
- if ( Cmd(p, "Teen12" ) ) return OBJECT_TEEN12;
- if ( Cmd(p, "Teen13" ) ) return OBJECT_TEEN13;
- if ( Cmd(p, "Teen14" ) ) return OBJECT_TEEN14;
- if ( Cmd(p, "Teen15" ) ) return OBJECT_TEEN15;
- if ( Cmd(p, "Teen16" ) ) return OBJECT_TEEN16;
- if ( Cmd(p, "Teen17" ) ) return OBJECT_TEEN17;
- if ( Cmd(p, "Teen18" ) ) return OBJECT_TEEN18;
- if ( Cmd(p, "Teen19" ) ) return OBJECT_TEEN19;
if ( Cmd(p, "Teen0" ) ) return OBJECT_TEEN0;
if ( Cmd(p, "Teen1" ) ) return OBJECT_TEEN1;
if ( Cmd(p, "Teen2" ) ) return OBJECT_TEEN2;
@@ -374,26 +338,51 @@ ObjectType GetTypeObject(char *line, int rank, ObjectType def)
if ( Cmd(p, "Teen7" ) ) return OBJECT_TEEN7;
if ( Cmd(p, "Teen8" ) ) return OBJECT_TEEN8;
if ( Cmd(p, "Teen9" ) ) return OBJECT_TEEN9;
+ if ( Cmd(p, "Teen10" ) ) return OBJECT_TEEN10;
+ if ( Cmd(p, "Teen11" ) ) return OBJECT_TEEN11;
+ if ( Cmd(p, "Teen12" ) ) return OBJECT_TEEN12;
+ if ( Cmd(p, "Teen13" ) ) return OBJECT_TEEN13;
+ if ( Cmd(p, "Teen14" ) ) return OBJECT_TEEN14;
+ if ( Cmd(p, "Teen15" ) ) return OBJECT_TEEN15;
+ if ( Cmd(p, "Teen16" ) ) return OBJECT_TEEN16;
+ if ( Cmd(p, "Teen17" ) ) return OBJECT_TEEN17;
+ if ( Cmd(p, "Teen18" ) ) return OBJECT_TEEN18;
+ if ( Cmd(p, "Teen19" ) ) return OBJECT_TEEN19;
+ if ( Cmd(p, "Teen20" ) ) return OBJECT_TEEN20;
+ if ( Cmd(p, "Teen21" ) ) return OBJECT_TEEN21;
+ if ( Cmd(p, "Teen22" ) ) return OBJECT_TEEN22;
+ if ( Cmd(p, "Teen23" ) ) return OBJECT_TEEN23;
+ if ( Cmd(p, "Teen24" ) ) return OBJECT_TEEN24;
+ if ( Cmd(p, "Teen25" ) ) return OBJECT_TEEN25;
+ if ( Cmd(p, "Teen26" ) ) return OBJECT_TEEN26;
+ if ( Cmd(p, "Teen27" ) ) return OBJECT_TEEN27;
+ if ( Cmd(p, "Teen28" ) ) return OBJECT_TEEN28;
+ if ( Cmd(p, "Teen29" ) ) return OBJECT_TEEN29;
+ if ( Cmd(p, "Teen30" ) ) return OBJECT_TEEN30;
+ if ( Cmd(p, "Teen31" ) ) return OBJECT_TEEN31;
+ if ( Cmd(p, "Teen32" ) ) return OBJECT_TEEN32;
+ if ( Cmd(p, "Teen33" ) ) return OBJECT_TEEN33;
+ if ( Cmd(p, "Stone" ) ) return OBJECT_TEEN34;
+ if ( Cmd(p, "Teen35" ) ) return OBJECT_TEEN35;
+ if ( Cmd(p, "Teen36" ) ) return OBJECT_TEEN36;
+ if ( Cmd(p, "Teen37" ) ) return OBJECT_TEEN37;
+ if ( Cmd(p, "Teen38" ) ) return OBJECT_TEEN38;
+ if ( Cmd(p, "Teen39" ) ) return OBJECT_TEEN39;
+ if ( Cmd(p, "Teen40" ) ) return OBJECT_TEEN40;
+ if ( Cmd(p, "Teen41" ) ) return OBJECT_TEEN41;
+ if ( Cmd(p, "Teen42" ) ) return OBJECT_TEEN42;
+ if ( Cmd(p, "Teen43" ) ) return OBJECT_TEEN43;
+ if ( Cmd(p, "Teen44" ) ) return OBJECT_TEEN44;
if ( Cmd(p, "Quartz0" ) ) return OBJECT_QUARTZ0;
if ( Cmd(p, "Quartz1" ) ) return OBJECT_QUARTZ1;
if ( Cmd(p, "Quartz2" ) ) return OBJECT_QUARTZ2;
if ( Cmd(p, "Quartz3" ) ) return OBJECT_QUARTZ3;
- if ( Cmd(p, "Quartz4" ) ) return OBJECT_QUARTZ4;
- if ( Cmd(p, "Quartz5" ) ) return OBJECT_QUARTZ5;
- if ( Cmd(p, "Quartz6" ) ) return OBJECT_QUARTZ6;
- if ( Cmd(p, "Quartz7" ) ) return OBJECT_QUARTZ7;
- if ( Cmd(p, "Quartz8" ) ) return OBJECT_QUARTZ8;
- if ( Cmd(p, "Quartz9" ) ) return OBJECT_QUARTZ9;
if ( Cmd(p, "MegaStalk0" ) ) return OBJECT_ROOT0;
if ( Cmd(p, "MegaStalk1" ) ) return OBJECT_ROOT1;
if ( Cmd(p, "MegaStalk2" ) ) return OBJECT_ROOT2;
if ( Cmd(p, "MegaStalk3" ) ) return OBJECT_ROOT3;
if ( Cmd(p, "MegaStalk4" ) ) return OBJECT_ROOT4;
if ( Cmd(p, "MegaStalk5" ) ) return OBJECT_ROOT5;
- if ( Cmd(p, "MegaStalk6" ) ) return OBJECT_ROOT6;
- if ( Cmd(p, "MegaStalk7" ) ) return OBJECT_ROOT7;
- if ( Cmd(p, "MegaStalk8" ) ) return OBJECT_ROOT8;
- if ( Cmd(p, "MegaStalk9" ) ) return OBJECT_ROOT9;
if ( Cmd(p, "ApolloLEM" ) ) return OBJECT_APOLLO1;
if ( Cmd(p, "ApolloJeep" ) ) return OBJECT_APOLLO2;
if ( Cmd(p, "ApolloFlag" ) ) return OBJECT_APOLLO3;
@@ -438,11 +427,7 @@ const char* GetTypeObject(ObjectType type)
if ( type == OBJECT_MOBILEdr ) return "Scribbler";
if ( type == OBJECT_MARKPOWER ) return "PowerSpot";
if ( type == OBJECT_MARKSTONE ) return "TitaniumSpot";
-#if _GERMAN | _WG
- if ( type == OBJECT_MARKURANIUM ) return "PlatinumSpot";
-#else
if ( type == OBJECT_MARKURANIUM ) return "UraniumSpot";
-#endif
if ( type == OBJECT_MARKKEYa ) return "KeyASpot";
if ( type == OBJECT_MARKKEYb ) return "KeyBSpot";
if ( type == OBJECT_MARKKEYc ) return "KeyCSpot";
@@ -454,17 +439,9 @@ const char* GetTypeObject(ObjectType type)
if ( type == OBJECT_FLAGy ) return "YellowFlag";
if ( type == OBJECT_FLAGv ) return "VioletFlag";
if ( type == OBJECT_POWER ) return "PowerCell";
-#if _GERMAN | _WG
- if ( type == OBJECT_ATOMIC ) return "FuelCell";
-#else
if ( type == OBJECT_ATOMIC ) return "NuclearCell";
-#endif
if ( type == OBJECT_STONE ) return "TitaniumOre";
-#if _GERMAN | _WG
- if ( type == OBJECT_URANIUM ) return "PlatinumOre";
-#else
if ( type == OBJECT_URANIUM ) return "UraniumOre";
-#endif
if ( type == OBJECT_METAL ) return "Titanium";
if ( type == OBJECT_BULLET ) return "OrgaMatter";
if ( type == OBJECT_BBOX ) return "BlackBox";
@@ -507,20 +484,8 @@ const char* GetTypeObject(ObjectType type)
if ( type == OBJECT_TREE3 ) return "Tree3";
if ( type == OBJECT_TREE4 ) return "Tree4";
if ( type == OBJECT_TREE5 ) return "Tree5";
- if ( type == OBJECT_TREE6 ) return "Tree6";
- if ( type == OBJECT_TREE7 ) return "Tree7";
- if ( type == OBJECT_TREE8 ) return "Tree8";
- if ( type == OBJECT_TREE9 ) return "Tree9";
- if ( type == OBJECT_MUSHROOM0 ) return "Mushroom0";
if ( type == OBJECT_MUSHROOM1 ) return "Mushroom1";
if ( type == OBJECT_MUSHROOM2 ) return "Mushroom2";
- if ( type == OBJECT_MUSHROOM3 ) return "Mushroom3";
- if ( type == OBJECT_MUSHROOM4 ) return "Mushroom4";
- if ( type == OBJECT_MUSHROOM5 ) return "Mushroom5";
- if ( type == OBJECT_MUSHROOM6 ) return "Mushroom6";
- if ( type == OBJECT_MUSHROOM7 ) return "Mushroom7";
- if ( type == OBJECT_MUSHROOM8 ) return "Mushroom8";
- if ( type == OBJECT_MUSHROOM9 ) return "Mushroom9";
if ( type == OBJECT_HOME1 ) return "Home";
if ( type == OBJECT_DERRICK ) return "Derrick";
if ( type == OBJECT_FACTORY ) return "BotFactory";
@@ -535,11 +500,7 @@ const char* GetTypeObject(ObjectType type)
if ( type == OBJECT_INFO ) return "ExchangePost";
if ( type == OBJECT_ENERGY ) return "PowerPlant";
if ( type == OBJECT_LABO ) return "AutoLab";
-#if _GERMAN | _WG
- if ( type == OBJECT_NUCLEAR ) return "FuelCellPlant";
-#else
if ( type == OBJECT_NUCLEAR ) return "NuclearPlant";
-#endif
if ( type == OBJECT_PARA ) return "PowerCaptor";
if ( type == OBJECT_SAFE ) return "Vault";
if ( type == OBJECT_HUSTON ) return "Houston";
@@ -570,7 +531,6 @@ const char* GetTypeObject(ObjectType type)
if ( type == OBJECT_BARRIER1 ) return "Barrier1";
if ( type == OBJECT_BARRIER2 ) return "Barrier2";
if ( type == OBJECT_BARRIER3 ) return "Barrier3";
- if ( type == OBJECT_BARRIER4 ) return "Barrier4";
if ( type == OBJECT_TEEN0 ) return "Teen0";
if ( type == OBJECT_TEEN1 ) return "Teen1";
if ( type == OBJECT_TEEN2 ) return "Teen2";
@@ -616,31 +576,16 @@ const char* GetTypeObject(ObjectType type)
if ( type == OBJECT_TEEN42 ) return "Teen42";
if ( type == OBJECT_TEEN43 ) return "Teen43";
if ( type == OBJECT_TEEN44 ) return "Teen44";
- if ( type == OBJECT_TEEN45 ) return "Teen45";
- if ( type == OBJECT_TEEN46 ) return "Teen46";
- if ( type == OBJECT_TEEN47 ) return "Teen47";
- if ( type == OBJECT_TEEN48 ) return "Teen48";
- if ( type == OBJECT_TEEN49 ) return "Teen49";
if ( type == OBJECT_QUARTZ0 ) return "Quartz0";
if ( type == OBJECT_QUARTZ1 ) return "Quartz1";
if ( type == OBJECT_QUARTZ2 ) return "Quartz2";
if ( type == OBJECT_QUARTZ3 ) return "Quartz3";
- if ( type == OBJECT_QUARTZ4 ) return "Quartz4";
- if ( type == OBJECT_QUARTZ5 ) return "Quartz5";
- if ( type == OBJECT_QUARTZ6 ) return "Quartz6";
- if ( type == OBJECT_QUARTZ7 ) return "Quartz7";
- if ( type == OBJECT_QUARTZ8 ) return "Quartz8";
- if ( type == OBJECT_QUARTZ9 ) return "Quartz9";
if ( type == OBJECT_ROOT0 ) return "MegaStalk0";
if ( type == OBJECT_ROOT1 ) return "MegaStalk1";
if ( type == OBJECT_ROOT2 ) return "MegaStalk2";
if ( type == OBJECT_ROOT3 ) return "MegaStalk3";
if ( type == OBJECT_ROOT4 ) return "MegaStalk4";
if ( type == OBJECT_ROOT5 ) return "MegaStalk5";
- if ( type == OBJECT_ROOT6 ) return "MegaStalk6";
- if ( type == OBJECT_ROOT7 ) return "MegaStalk7";
- if ( type == OBJECT_ROOT8 ) return "MegaStalk8";
- if ( type == OBJECT_ROOT9 ) return "MegaStalk9";
if ( type == OBJECT_APOLLO1 ) return "ApolloLEM";
if ( type == OBJECT_APOLLO2 ) return "ApolloJeep";
if ( type == OBJECT_APOLLO3 ) return "ApolloFlag";
@@ -800,6 +745,62 @@ const char* GetCamera(Gfx::CameraType type)
return "BACK";
}
+// Returns the type of drive.
+
+DriveType GetDrive(char *line, int rank)
+{
+ char* p;
+
+ p = SearchArg(line, rank);
+ if ( *p == 0 ) return DRIVE_OTHER;
+
+ if ( Cmd(p, "Wheeled" ) ) return DRIVE_WHEELED;
+ if ( Cmd(p, "Tracked" ) ) return DRIVE_TRACKED;
+ if ( Cmd(p, "Winged" ) ) return DRIVE_WINGED;
+ if ( Cmd(p, "Legged" ) ) return DRIVE_LEGGED;
+
+ return DRIVE_OTHER;
+}
+
+// Returns the name of a drive.
+
+const char* GetDrive(DriveType type)
+{
+ if ( type == DRIVE_WHEELED ) return "Wheeled";
+ if ( type == DRIVE_TRACKED ) return "Tracked";
+ if ( type == DRIVE_WINGED ) return "Winged";
+ if ( type == DRIVE_LEGGED ) return "Legged";
+ return "Other";
+}
+
+// Returns the type of tool.
+
+ToolType GetTool(char *line, int rank)
+{
+ char* p;
+
+ p = SearchArg(line, rank);
+ if ( *p == 0 ) return TOOL_OTHER;
+
+ if ( Cmd(p, "Grabber" ) ) return TOOL_GRABBER;
+ if ( Cmd(p, "Sniffer" ) ) return TOOL_SNIFFER;
+ if ( Cmd(p, "Shooter" ) ) return TOOL_SHOOTER;
+ if ( Cmd(p, "OrgaShooter" ) ) return TOOL_ORGASHOOTER;
+
+ return TOOL_OTHER;
+}
+
+// Returns the name of a tool.
+
+const char* GetTool(ToolType type)
+{
+ if ( type == TOOL_GRABBER ) return "Grabber";
+ if ( type == TOOL_SNIFFER ) return "Sniffer";
+ if ( type == TOOL_SHOOTER ) return "Shooter";
+ if ( type == TOOL_ORGASHOOTER ) return "OrgaShooter";
+ return "Other";
+}
+
// Returns an integer.
int OpInt(char *line, const char *op, int def)
@@ -887,6 +888,24 @@ Gfx::CameraType OpCamera(char *line, const char *op)
return GetCamera(line, 0);
}
+// Returns the type of drive.
+
+DriveType OpDrive(char *line, const char *op)
+{
+ line = SearchOp(line, op);
+ if ( *line == 0 ) return DRIVE_OTHER;
+ return GetDrive(line, 0);
+}
+
+// Returns the type of tool.
+
+ToolType OpTool(char *line, const char *op)
+{
+ line = SearchOp(line, op);
+ if ( *line == 0 ) return TOOL_OTHER;
+ return GetTool(line, 0);
+}
+
// Returns the type of a building.
int OpBuild(char *line, const char *op)
diff --git a/src/script/cmdtoken.h b/src/script/cmdtoken.h
index fe831f1..8a423c5 100644
--- a/src/script/cmdtoken.h
+++ b/src/script/cmdtoken.h
@@ -30,6 +30,7 @@
// Procedures.
+extern std::string GetCmd(char* line);
extern bool Cmd(char *line, const char *token);
extern char* SearchOp(char *line, const char *op);
@@ -45,6 +46,10 @@ extern int GetResearch(char *line, int rank);
extern Gfx::PyroType GetPyro(char *line, int rank);
extern Gfx::CameraType GetCamera(char *line, int rank);
extern const char* GetCamera(Gfx::CameraType type);
+extern DriveType GetDrive(char *line, int rank);
+extern const char* GetDrive(DriveType type);
+extern ToolType GetTool(char *line, int rank);
+extern const char* GetTool(ToolType type);
extern int OpInt(char *line, const char *op, int def);
extern float OpFloat(char *line, const char *op, float def);
@@ -55,6 +60,8 @@ extern Gfx::EngineObjectType OpTypeTerrain(char *line, const char *op, Gfx::Engi
extern int OpResearch(char *line, const char *op);
extern Gfx::PyroType OpPyro(char *line, const char *op);
extern Gfx::CameraType OpCamera(char *line, const char *op);
+extern DriveType OpDrive(char *line, const char *op);
+extern ToolType OpTool(char *line, const char *op);
extern int OpBuild(char *line, const char *op);
extern Math::Vector OpPos(char *line, const char *op);
extern Math::Vector OpDir(char *line, const char *op);
diff --git a/src/script/script.cpp b/src/script/script.cpp
index ca6ce25..2299fbf 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -18,10 +18,12 @@
#include "script/script.h"
#include "app/app.h"
+#include "app/gamedata.h"
#include "common/global.h"
#include "common/iman.h"
#include "common/restext.h"
+#include "common/stringutils.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
@@ -37,6 +39,7 @@
#include "object/auto/auto.h"
#include "object/auto/autofactory.h"
+#include "object/auto/autobase.h"
#include "physics/physics.h"
@@ -678,10 +681,23 @@ 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);
- CAutoFactory* automat = static_cast<CAutoFactory*>(factory->GetAuto());
+ if (factory == nullptr) {
+ exception = ERR_GENERIC;
+ result->SetValInt(ERR_GENERIC);
+ CLogger::GetInstancePointer()->Error("in object.factory() - factory is nullptr");
+ return false;
+ }
if ( thisType == OBJECT_FACTORY )
{
+ CAutoFactory* automat = static_cast<CAutoFactory*>(factory->GetAuto());
+ if(automat == nullptr) {
+ exception = ERR_GENERIC;
+ result->SetValInt(ERR_GENERIC);
+ CLogger::GetInstancePointer()->Error("in object.factory() - automat is nullptr");
+ return false;
+ }
+
bool bEnable = false;
if ( type == OBJECT_MOBILEwa )
@@ -900,6 +916,54 @@ bool CScript::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int&
return true;
}
+// Instruction "object.takeoff()"
+
+bool CScript::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
+{
+ Error err;
+
+ exception = 0;
+
+ 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_BASE )
+ {
+ err = (static_cast<CAutoBase*>(automat))->TakeOff(false);
+ } 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)
@@ -1330,7 +1394,7 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception)
if ( err == ERR_STOP ) err = ERR_OK;
result->SetValInt(err); // indicates the error or ok
- if ( err != ERR_OK && script->m_errMode == ERM_STOP )
+ if ( ShouldProcessStop(err, script->m_errMode) )
{
exception = err;
return false;
@@ -1344,6 +1408,21 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception)
}
+// Returns true if error code means real error and exception must be thrown
+
+bool CScript::ShouldProcessStop(Error err, int errMode)
+{
+ // aim impossible - not a real error
+ if ( err == ERR_AIM_IMPOSSIBLE )
+ return false;
+
+ if ( err != ERR_OK && errMode == ERM_STOP )
+ return true;
+
+ return false;
+}
+
+
// Compilation of the instruction "detect(type)".
CBotTypResult CScript::cDetect(CBotVar* &var, void* user)
@@ -1576,7 +1655,7 @@ CBotTypResult CScript::cCanBuild(CBotVar* &var, void* user)
return CBotTypResult(CBotTypBoolean);
}
-// Instruction "canbuid ( category );"
+// Instruction "canbuild ( category );"
// returns true if this building can be built
bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
@@ -1602,7 +1681,7 @@ bool CScript::rCanBuild(CBotVar* var, CBotVar* result, int& exception, void* use
(category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER)))
{
- //if we want to build not researched one
+ // if we want to build not researched one
if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
(category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC))
)
@@ -1646,7 +1725,7 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
}
else
{
- category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
+ 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)) ||
@@ -1663,7 +1742,7 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
(category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER)))
{
- //if we want to build not researched one
+ // if we want to build not researched one
if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
(category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC))
)
@@ -1676,8 +1755,11 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
}
}
+
+ if (pThis->GetIgnoreBuildCheck())
+ err = ERR_OK;
- if (err == ERR_OK && script->m_primaryTask == 0) //if we can build and no task is present
+ 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);
@@ -1688,9 +1770,9 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
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
+ // 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 )
@@ -1820,52 +1902,10 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user
}
}
- if ( type == OBJECT_FRET ||
- type == OBJECT_STONE ||
- type == OBJECT_URANIUM ||
- type == OBJECT_METAL ||
- type == OBJECT_POWER ||
- type == OBJECT_ATOMIC ||
- type == OBJECT_BULLET ||
- type == OBJECT_BBOX ||
- type == OBJECT_KEYa ||
- type == OBJECT_KEYb ||
- type == OBJECT_KEYc ||
- type == OBJECT_KEYd ||
- type == OBJECT_TNT ||
- type == OBJECT_SCRAP1 ||
- type == OBJECT_SCRAP2 ||
- type == OBJECT_SCRAP3 ||
- type == OBJECT_SCRAP4 ||
- type == OBJECT_SCRAP5 ||
- type == OBJECT_BOMB ||
- type == OBJECT_WAYPOINT ||
- type == OBJECT_SHOW ||
- type == OBJECT_WINFIRE ||
- type == OBJECT_BAG ||
- type == OBJECT_MARKPOWER ||
- type == OBJECT_MARKSTONE ||
- type == OBJECT_MARKURANIUM ||
- type == OBJECT_MARKKEYa ||
- type == OBJECT_MARKKEYb ||
- type == OBJECT_MARKKEYc ||
- type == OBJECT_MARKKEYd ||
- type == OBJECT_EGG )
- {
- object = new CObject();
- if ( !object->CreateResource(pos, angle, type) )
- {
- delete object;
- result->SetValInt(1); // error
- return true;
- }
- object->SetActivity(false);
- }
- else if ( type == OBJECT_MOTHER ||
- type == OBJECT_ANT ||
- type == OBJECT_SPIDER ||
- type == OBJECT_BEE ||
- type == OBJECT_WORM )
+ if ( type == OBJECT_ANT ||
+ type == OBJECT_SPIDER ||
+ type == OBJECT_BEE ||
+ type == OBJECT_WORM )
{
CObject* egg;
@@ -1883,117 +1923,16 @@ bool CScript::rProduce(CBotVar* var, CBotVar* result, int& exception, void* user
delete egg;
}
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 )
- {
- object = new CObject();
- if ( !object->CreateBuilding(pos, angle, 0, type) )
- {
- delete object;
- result->SetValInt(1); // error
- return true;
- }
- object->SetActivity(false);
- script->m_main->CreateShortcuts();
- }
- 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) )
+ } else {
+ if ((type == OBJECT_POWER || type == OBJECT_ATOMIC) && power == -1.0f) power = 1.0f;
+ object = CObjectManager::GetInstancePointer()->CreateObject(pos, angle, type, power);
+ if ( object == nullptr )
{
- delete object;
result->SetValInt(1); // error
return true;
}
- 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 )
- {
- object = new CObject();
- if ( !object->CreateVehicle(pos, angle, type, power, false, false) )
- {
- delete object;
- result->SetValInt(1); // error
- return true;
- }
- object->UpdateMapping();
- object->SetRange(30.0f);
- object->SetZoom(0, 1.0f);
- CPhysics* physics = object->GetPhysics();
- if ( physics != 0 )
- {
- physics->SetFreeze(false); // can move
- }
- object->SetLock(false); // vehicle useable
- // SetManual will affect bot speed
- if (type == OBJECT_MOBILEdr)
- {
- object->SetManual(true);
- }
- object->SetActivity(true);
script->m_main->CreateShortcuts();
}
- else
- {
- result->SetValInt(1); // impossible
- return true;
- }
if (name[0] != 0)
{
@@ -2923,7 +2862,6 @@ bool CScript::rShield(CBotVar* var, CBotVar* result, int& exception, void* user)
CBotTypResult CScript::cFire(CBotVar* &var, void* user)
{
-#if 0
CObject* pThis = static_cast<CObject *>(user);
ObjectType type;
@@ -2931,23 +2869,25 @@ CBotTypResult CScript::cFire(CBotVar* &var, void* user)
if ( type == OBJECT_ANT )
{
- return cOnePoint(var, user);
+ if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
+ CBotTypResult ret = cPoint(var, user);
+ if ( ret.GetType() != 0 ) return ret;
+ if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
}
else if ( type == OBJECT_SPIDER )
{
- return cNull(var, user);
+ if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
}
else
{
- if ( var == 0 ) return CBotTypResult(CBotTypFloat);
- if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
- var = var->GetNext();
- if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
- return CBotTypResult(CBotTypFloat);
+ if ( var != 0 )
+ {
+ if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
+ var = var->GetNext();
+ if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
+ }
}
-#else
return CBotTypResult(CBotTypFloat);
-#endif
}
// Instruction "fire(delay)".
@@ -2983,6 +2923,7 @@ bool CScript::rFire(CBotVar* var, CBotVar* result, int& exception, void* user)
{
if ( var == 0 ) delay = 0.0f;
else delay = var->GetValFloat();
+ if ( delay < 0.0f ) delay = -delay;
err = script->m_primaryTask->StartTaskFire(delay);
}
@@ -3031,7 +2972,11 @@ bool CScript::rAim(CBotVar* var, CBotVar* result, int& exception, void* user)
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 )
+ if ( err == ERR_AIM_IMPOSSIBLE )
+ {
+ result->SetValInt(err); // shows the error
+ }
+ else if ( err != ERR_OK )
{
delete script->m_primaryTask;
script->m_primaryTask = 0;
@@ -3488,6 +3433,47 @@ bool CScript::rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* use
return true;
}
+// Compilation of the instruction with one object parameter
+
+CBotTypResult CScript::cOneObject(CBotVar* &var, void* user)
+{
+ if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
+ var = var->GetNext();
+ if ( var == 0 ) return CBotTypResult(CBotTypFloat);
+
+ return CBotTypResult(CBotErrOverParam);
+}
+
+// Instruction "camerafocus(object)".
+
+bool CScript::rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ CScript* script = (static_cast<CObject *>(user))->GetRunScript();
+
+ CBotVar* classVars = var->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* object = CObjectManager::GetInstancePointer()->SearchInstance(rank);
+
+ script->m_main->SelectObject(object, false);
+
+ result->SetValInt(ERR_OK);
+ exception = ERR_OK;
+ return true;
+}
+
// Object's constructor.
@@ -3504,6 +3490,7 @@ CScript::CScript(CObject* object, CTaskManager** secondaryTask)
m_secondaryTask = secondaryTask;
m_interface = m_main->GetInterface();
+ m_pause = CPauseManager::GetInstancePointer();
m_ipf = CBOT_IPF;
m_errMode = ERM_STOP;
@@ -3587,6 +3574,8 @@ void CScript::InitFonctions()
CBotProgram::AddFunction("penup", rPenUp, CScript::cNull);
CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat);
CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat);
+
+ CBotProgram::AddFunction("camerafocus", rCameraFocus, CScript::cOneObject);
CBotProgram::AddFunction("canbuild", rCanBuild, CScript::cCanBuild);
CBotProgram::AddFunction("build", rBuild, CScript::cOneFloat);
@@ -3898,16 +3887,16 @@ bool CScript::Continue(const Event &event)
if ( m_error != 0 && m_errMode == ERM_STOP )
{
- char s[100];
+ std::string s;
GetError(s);
- m_main->GetDisplayText()->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR);
+ m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR);
}
- m_engine->SetPause(true); // gives pause
+ m_pause->SetPause(PAUSE_EDITOR); // gives pause
return true;
}
if ( !m_bContinue )
{
- m_engine->SetPause(true); // gives pause
+ m_pause->SetPause(PAUSE_EDITOR); // gives pause
}
}
@@ -3931,9 +3920,9 @@ bool CScript::Continue(const Event &event)
if ( m_error != 0 && m_errMode == ERM_STOP )
{
- char s[100];
+ std::string s;
GetError(s);
- m_main->GetDisplayText()->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR);
+ m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR);
}
return true;
}
@@ -3950,9 +3939,9 @@ bool CScript::Step(const Event &event)
if ( !m_bRun ) return true;
if ( !m_bStepMode ) return false;
- m_engine->SetPause(false);
+ // ??? m_engine->SetPause(false);
// TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms
- m_engine->SetPause(true);
+ // ??? m_engine->SetPause(true);
m_event = event;
@@ -3973,16 +3962,16 @@ bool CScript::Step(const Event &event)
if ( m_error != 0 && m_errMode == ERM_STOP )
{
- char s[100];
+ std::string s;
GetError(s);
- m_main->GetDisplayText()->DisplayText(s, m_object, 10.0f, Ui::TT_ERROR);
+ m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR);
}
return true;
}
if ( m_bContinue ) // instuction "move", "goto", etc. ?
{
- m_engine->SetPause(false); // removes the pause
+ m_pause->ClearPause(); // removes the pause
}
return false;
}
@@ -4347,27 +4336,27 @@ int CScript::GetError()
// Returns the text of the error.
-void CScript::GetError(char* buffer)
+void CScript::GetError(std::string& error)
{
if ( m_error == 0 )
{
- buffer[0] = 0;
+ error.clear();
}
else
{
if ( m_error == ERR_OBLIGATORYTOKEN )
{
- char s[100];
+ std::string s;
GetResource(RES_ERR, m_error, s);
- sprintf(buffer, s, m_token);
+ error = StrUtils::Format(s.c_str(), m_token);
}
else if ( m_error < 1000 )
{
- GetResource(RES_ERR, m_error, buffer);
+ GetResource(RES_ERR, m_error, error);
}
else
{
- GetResource(RES_CBOT, m_error, buffer);
+ GetResource(RES_CBOT, m_error, error);
}
}
}
@@ -4385,7 +4374,9 @@ void CScript::New(Ui::CEdit* edit, const char* name)
char *sf;
int cursor1, cursor2, len, i, j;
- GetResource(RES_TEXT, RT_SCRIPT_NEW, res);
+ std::string resStr;
+ GetResource(RES_TEXT, RT_SCRIPT_NEW, resStr);
+ strcpy(res, resStr.c_str());
if ( name[0] == 0 ) strcpy(text, res);
else strcpy(text, name);
@@ -4418,7 +4409,7 @@ void CScript::New(Ui::CEdit* edit, const char* name)
sf = m_main->GetScriptFile();
if ( sf[0] != 0 ) // Load an empty program specific?
{
- std::string filename = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, sf);
+ std::string filename = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, sf);
file = fopen(filename.c_str(), "rb");
if ( file != NULL )
{
@@ -4512,7 +4503,7 @@ bool CScript::ReadScript(const char* filename)
if ( strchr(filename, '/') == 0 ) //we're reading non user script
{
- name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename);
+ name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename);
}
else
{
@@ -4546,7 +4537,7 @@ bool CScript::WriteScript(const char* filename)
if ( strchr(filename, '/') == 0 ) //we're writing non user script
{
- name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename);
+ name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename);
}
else
{
diff --git a/src/script/script.h b/src/script/script.h
index 7fd5555..fb44342 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -24,6 +24,10 @@
#include "common/event.h"
+#include "common/global.h"
+
+#include "app/pausemanager.h"
+
#include "CBot/CBotDll.h"
#include <stdio.h>
@@ -74,7 +78,7 @@ public:
bool IntroduceVirus();
int GetError();
- void GetError(char* buffer);
+ void GetError(std::string& error);
void New(Ui::CEdit* edit, const char* name);
bool SendScript(const char* text);
@@ -126,6 +130,7 @@ private:
static CBotTypResult cPenDown(CBotVar* &var, void* user);
static CBotTypResult cOnePoint(CBotVar* &var, void* user);
static CBotTypResult cPoint(CBotVar* &var, void* user);
+ static CBotTypResult cOneObject(CBotVar* &var, void* user);
static bool rSin(CBotVar* var, CBotVar* result, int& exception, void* user);
@@ -190,6 +195,7 @@ private:
static bool rPenUp(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rPenColor(CBotVar* var, CBotVar* result, int& exception, void* user);
static bool rPenWidth(CBotVar* var, CBotVar* result, int& exception, void* user);
+ static bool rCameraFocus(CBotVar* var, CBotVar* result, int& exception, void* user);
public:
static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var);
@@ -200,10 +206,12 @@ public:
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 rTakeOff(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 bool ShouldProcessStop(Error err, int errMode);
static CObject* SearchInfo(CScript* script, CObject* object, float power);
protected:
@@ -216,6 +224,7 @@ protected:
CTaskManager* m_primaryTask;
CTaskManager** m_secondaryTask;
CObject* m_object;
+ CPauseManager* m_pause;
int m_ipf; // number of instructions/second
int m_errMode; // what to do in case of error