summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorOleg Kosmakov <kosmakoff@gmail.com>2014-03-21 13:08:36 +0200
committerOleg Kosmakov <kosmakoff@gmail.com>2014-03-21 13:08:36 +0200
commit7485ed790caeaa76efab0e9df48224cf1943ec27 (patch)
tree79fa3c6532bdcfe67967687c6438a60d37ce6dc9 /src/script
parent2cf84ad2148c8f88a1153771b357cc8b3208e38a (diff)
downloadcolobot-7485ed790caeaa76efab0e9df48224cf1943ec27.tar.gz
colobot-7485ed790caeaa76efab0e9df48224cf1943ec27.tar.bz2
colobot-7485ed790caeaa76efab0e9df48224cf1943ec27.zip
Fixes #295
When cannon cannot turn at specified angle, it will still reach the edge angle, but return the error code
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script.cpp23
-rw-r--r--src/script/script.h3
2 files changed, 24 insertions, 2 deletions
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 3a4d2d1..d55c4d1 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -1393,7 +1393,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 ( ShouldExecutionStop(err, script->m_errMode) )
{
exception = err;
return false;
@@ -1407,6 +1407,21 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception)
}
+// Returns true if error code means rela error and exception must be thrown
+
+bool CScript::ShouldExecutionStop(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)
@@ -2954,7 +2969,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;
diff --git a/src/script/script.h b/src/script/script.h
index afb89c8..694228a 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -24,6 +24,8 @@
#include "common/event.h"
+#include "common/global.h"
+
#include "app/pausemanager.h"
#include "CBot/CBotDll.h"
@@ -209,6 +211,7 @@ public:
private:
static bool Process(CScript* script, CBotVar* result, int &exception);
+ static bool ShouldExecutionStop(Error err, int errMode);
static CObject* SearchInfo(CScript* script, CObject* object, float power);
protected: