summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerihel <erihel@gmail.com>2013-04-28 20:09:41 +0200
committererihel <erihel@gmail.com>2013-04-28 20:09:41 +0200
commit919b0e8114368132c88d95768b43fc17c70b699d (patch)
tree50da6747d6e3dad7e2236a01c6c7a40c910e4a30
parent5669053de08bac9726902e96f89aa85b99909399 (diff)
parentc7d289c00bc60d366f8c5c1016fb30717a228495 (diff)
downloadcolobot-919b0e8114368132c88d95768b43fc17c70b699d.tar.gz
colobot-919b0e8114368132c88d95768b43fc17c70b699d.tar.bz2
colobot-919b0e8114368132c88d95768b43fc17c70b699d.zip
Merge branch 'dev' of github:colobot/colobot into dev
m---------data0
-rw-r--r--src/object/object.cpp6
-rw-r--r--src/object/object.h1
-rw-r--r--src/object/robotmain.cpp37
-rw-r--r--src/object/robotmain.h1
-rw-r--r--src/script/cbottoken.cpp10
-rw-r--r--src/script/script.cpp135
-rw-r--r--src/script/script.h5
8 files changed, 145 insertions, 50 deletions
diff --git a/data b/data
-Subproject 01900b30c0bdb51e800971e67e6e863fe4ac2a3
+Subproject fcb194a2d35f72658138d237b27f2cdda7cd6b9
diff --git a/src/object/object.cpp b/src/object/object.cpp
index b621ef2..ce79e34 100644
--- a/src/object/object.cpp
+++ b/src/object/object.cpp
@@ -2145,8 +2145,10 @@ bool CObject::CreateVehicle(Math::Vector pos, float angle, ObjectType type,
{
m_motion = new CMotionHuman(this);
}
- else
- {
+ else if ( type == OBJECT_CONTROLLER ) {
+ m_motion = new CMotion(this); //dummy object
+ }
+ else {
m_motion = new CMotionVehicle(this);
}
if ( m_motion == 0 ) return false;
diff --git a/src/object/object.h b/src/object/object.h
index 4d8cc02..25ea708 100644
--- a/src/object/object.h
+++ b/src/object/object.h
@@ -156,6 +156,7 @@ enum ObjectType
OBJECT_MOBILEsa = 210, //! < submarine
OBJECT_MOBILEtg = 211, //! < training target
OBJECT_MOBILEdr = 212, //! < robot drawing
+ OBJECT_CONTROLLER = 213, //! < mission controller
OBJECT_WAYPOINT = 250, //! < waypoint
OBJECT_FLAGb = 260, //! < blue flag
OBJECT_FLAGr = 261, //! < red flag
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 6ba09a5..ddd6545 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -3830,6 +3830,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_audioChangeTotal = 0;
m_endTakeTotal = 0;
m_endTakeResearch = 0;
+ m_endTakeNever = false;
m_endTakeWinDelay = 2.0f;
m_endTakeLostDelay = 2.0f;
m_obligatoryTotal = 0;
@@ -4350,6 +4351,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_beginObject = true;
}
+ if (Cmd(line, "MissionController") && read[0] == 0 && m_version == 3)
+ {
+ if (!m_beginObject) {
+ GetLogger()->Error("Syntax error in file '%s' (line %d): MissionController before BeginObject\n", filename, lineNum);
+ continue;
+ }
+
+ CObject* obj = CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, 1.0f, 0.0f, OBJECT_CONTROLLER, 100.0f, false, false, 0);
+ CBrain* brain = obj->GetBrain();
+ if (brain != nullptr)
+ {
+ OpString(line, "script", name);
+ if (name[0] != 0)
+ brain->SetScriptName(1, name);
+ brain->SetScriptRun(1);
+ }
+ }
+
if (Cmd(line, "CreateObject") && read[0] == 0)
{
if (!m_beginObject) {
@@ -4671,7 +4690,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_camera->SetFixDirection(OpFloat(line, "fixDirection", 0.25f)*Math::PI);
}
- if (Cmd(line, "EndMissionTake") && !resetObject)
+ if (Cmd(line, "EndMissionTake") && !resetObject && m_version<3)
{
int i = m_endTakeTotal;
if (i < 10)
@@ -4694,15 +4713,19 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_endTakeTotal ++;
}
}
- if (Cmd(line, "EndMissionDelay") && !resetObject)
+ if (Cmd(line, "EndMissionDelay") && !resetObject && m_version<3)
{
m_endTakeWinDelay = OpFloat(line, "win", 2.0f);
m_endTakeLostDelay = OpFloat(line, "lost", 2.0f);
}
- if (Cmd(line, "EndMissionResearch") && !resetObject)
+ if (Cmd(line, "EndMissionResearch") && !resetObject && m_version<3)
{
m_endTakeResearch |= OpResearch(line, "type");
}
+ if (Cmd(line, "EndMissionNever") && !resetObject && m_version == 2)
+ {
+ m_endTakeNever = true;
+ }
if (Cmd(line, "ObligatoryToken") && !resetObject)
{
@@ -5129,7 +5152,8 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo
type == OBJECT_MOBILEwt ||
type == OBJECT_MOBILEit ||
type == OBJECT_MOBILEdr ||
- type == OBJECT_APOLLO2 )
+ type == OBJECT_APOLLO2 ||
+ type == OBJECT_CONTROLLER )
{
object = new CObject();
object->SetOption(option);
@@ -6685,6 +6709,8 @@ void CRobotMain::UpdateAudio(bool frame)
//! Checks if the mission is over
Error CRobotMain::CheckEndMission(bool frame)
{
+ if (m_version >= 3) return ERR_MISSION_NOTERM; //disabled. TODO: Control from program
+
CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
for (int t = 0; t < m_endTakeTotal; t++)
@@ -6763,7 +6789,8 @@ Error CRobotMain::CheckEndMission(bool frame)
}
}
if (nb < m_endTake[t].min ||
- nb > m_endTake[t].max)
+ nb > m_endTake[t].max ||
+ m_endTakeNever )
{
m_displayText->SetEnable(true);
return ERR_MISSION_NOTERM;
diff --git a/src/object/robotmain.h b/src/object/robotmain.h
index 7ed84c5..73315af 100644
--- a/src/object/robotmain.h
+++ b/src/object/robotmain.h
@@ -537,6 +537,7 @@ protected:
int m_endTakeTotal;
EndTake m_endTake[10];
long m_endTakeResearch;
+ bool m_endTakeNever;
float m_endTakeWinDelay;
float m_endTakeLostDelay;
diff --git a/src/script/cbottoken.cpp b/src/script/cbottoken.cpp
index 0bd52da..6eb6592 100644
--- a/src/script/cbottoken.cpp
+++ b/src/script/cbottoken.cpp
@@ -262,6 +262,8 @@ std::string GetHelpFilename(const char *token)
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, "grab" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/grab.txt");
+ if ( strcmp(token, "buildinfo" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/buildinfo.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");
@@ -380,7 +382,9 @@ bool IsFunction(const char *token)
if ( strcmp(token, "turn" ) == 0 ) return true;
if ( strcmp(token, "goto" ) == 0 ) return true;
if ( strcmp(token, "grab" ) == 0 ) return true;
- if ( strcmp(token, "build" ) == 0 ) return true;
+ if ( strcmp(token, "buildinfo" ) == 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;
@@ -463,7 +467,9 @@ const char* GetHelpText(const char *token)
if ( strcmp(token, "turn" ) == 0 ) return "turn ( angle );";
if ( strcmp(token, "goto" ) == 0 ) return "goto ( position, altitude );";
if ( strcmp(token, "grab" ) == 0 ) return "grab ( order );";
- if ( strcmp(token, "build" ) == 0 ) return "build ( category );";
+ if ( strcmp(token, "buildinfo" ) == 0 ) return "buildinfo ( category );";
+ 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 );";
diff --git a/src/script/script.cpp b/src/script/script.cpp
index c95cd4b..c9e3c66 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -1003,8 +1003,83 @@ 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)
+{
+ exception = 0;
+
+ CScript::rBuildInfo(var, result, exception, user);
+ Error err = static_cast<Error>(result->GetValInt());
+
+ if (err == ERR_OK)
+ result->SetValInt(true);
+ else
+ result->SetValInt(false);
+
+ return true;
+}
+
+// Instruction "buildinfo ( category );"
+// This function indicates if this building can be built, and returns a specific value
+//
+// returns 0(ERR_OK) if this building can be built
+// returns 132(ERR_BUILD_DISABLED) if can not build in a current mission
+// returns 133(ERR_BUILD_RESEARCH) if this building needs to be researched
+
+bool CScript::rBuildInfo(CBotVar* var, CBotVar* result, int& exception, void* user)
+{
+ ObjectType category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
+ exception = 0;
+ int value = ERR_BUILD_DISABLED;
+
+ 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 )))
+ {
+
+ //if we want to build not researched one
+ if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
+ (category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC))
+ )
+ {
+ value = ERR_BUILD_RESEARCH;
+ }
+ else
+ {
+ value = ERR_OK;
+ }
+
+ }
+
+ result->SetValInt(value);
+ return true;
+}
+
// Instruction "build(type)"
-// draws error if can not build (wher errormode stop), otherwise 0 <- 1
+// draws error if can not build (wher errormode stop), otherwise 0 <- error
bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
{
@@ -1027,48 +1102,26 @@ bool CScript::rBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
}
else
{
- category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
-
- //if we want to produce one of these buildings
- 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 )))
- {
-
- //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 if (script->m_primaryTask == 0) //if we have no other tasks
- {
- script->m_primaryTask = new CTaskManager(script->m_object);
- err = script->m_primaryTask->StartTaskBuild(category);
+ //Let's check is building this object is possible
+ CScript::rBuildInfo(var, result, exception, user);
+ err = static_cast<Error>(result->GetValInt());
- if (err != ERR_OK)
- {
- delete script->m_primaryTask;
- script->m_primaryTask = 0;
- }
- }
-
- }
- else //if we can't build this object
+ if (err == ERR_OK && script->m_primaryTask == 0) //if we can build and no task is present
{
- err = ERR_BUILD_DISABLED;
+ category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
+
+ 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 )
@@ -2939,6 +2992,8 @@ void CScript::InitFonctions()
CBotProgram::AddFunction("pencolor", rPenColor, CScript::cOneFloat);
CBotProgram::AddFunction("penwidth", rPenWidth, CScript::cOneFloat);
+ CBotProgram::AddFunction("buildinfo", rBuildInfo, CScript::cOneFloat);
+ CBotProgram::AddFunction("canbuild", rCanBuild, CScript::cCanBuild);
CBotProgram::AddFunction("build", rBuild, CScript::cOneFloat);
}
diff --git a/src/script/script.h b/src/script/script.h
index 597486b..702138b 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -104,7 +104,8 @@ private:
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 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);
@@ -139,6 +140,8 @@ private:
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 rBuildInfo(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);