Fixes #295
When cannon cannot turn at specified angle, it will still reach the edge angle, but return the error codedev-ui
parent
2cf84ad214
commit
7485ed790c
|
@ -123,6 +123,7 @@ enum Error
|
||||||
ERR_TOOMANY = 702, //! < too many objects
|
ERR_TOOMANY = 702, //! < too many objects
|
||||||
ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing
|
ERR_OBLIGATORYTOKEN = 800, //! < compulsory instruction missing
|
||||||
ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited
|
ERR_PROHIBITEDTOKEN = 801, //! < instruction prohibited
|
||||||
|
ERR_AIM_IMPOSSIBLE = 900, //! < cannot aim at specified angle(s)
|
||||||
|
|
||||||
INFO_FIRST = 10000, //! < first information
|
INFO_FIRST = 10000, //! < first information
|
||||||
INFO_BUILD = 10001, //! < construction builded
|
INFO_BUILD = 10001, //! < construction builded
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
CTaskGunGoal::CTaskGunGoal(CObject* object) : CTask(object)
|
CTaskGunGoal::CTaskGunGoal(CObject* object) : CTask(object)
|
||||||
{
|
{
|
||||||
|
m_aimImpossible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object's destructor.
|
// Object's destructor.
|
||||||
|
@ -116,6 +117,12 @@ Error CTaskGunGoal::Start(float dirV, float dirH)
|
||||||
|
|
||||||
m_progress = 0.0f;
|
m_progress = 0.0f;
|
||||||
|
|
||||||
|
// direction was constrainted, hence resulting in impossible move
|
||||||
|
if (dirV != m_finalDirV || dirH != m_finalDirH)
|
||||||
|
{
|
||||||
|
m_aimImpossible = true;
|
||||||
|
}
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,12 +133,25 @@ Error CTaskGunGoal::IsEnded()
|
||||||
if ( m_engine->GetPause() ) return ERR_CONTINUE;
|
if ( m_engine->GetPause() ) return ERR_CONTINUE;
|
||||||
|
|
||||||
if ( m_initialDirV == m_finalDirV &&
|
if ( m_initialDirV == m_finalDirV &&
|
||||||
m_initialDirH == m_finalDirH ) return ERR_STOP;
|
m_initialDirH == m_finalDirH )
|
||||||
if ( m_progress < 1.0f ) return ERR_CONTINUE;
|
{
|
||||||
|
if ( m_aimImpossible )
|
||||||
|
return ERR_AIM_IMPOSSIBLE;
|
||||||
|
else
|
||||||
|
return ERR_STOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_progress < 1.0f ) return ERR_CONTINUE;
|
||||||
|
|
||||||
m_object->SetGunGoalV(m_finalDirV);
|
m_object->SetGunGoalV(m_finalDirV);
|
||||||
m_object->SetGunGoalH(m_finalDirH);
|
m_object->SetGunGoalH(m_finalDirH);
|
||||||
Abort();
|
Abort();
|
||||||
|
|
||||||
|
if ( m_aimImpossible )
|
||||||
|
{
|
||||||
|
return ERR_AIM_IMPOSSIBLE;
|
||||||
|
}
|
||||||
|
|
||||||
return ERR_STOP;
|
return ERR_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,5 +44,7 @@ protected:
|
||||||
float m_finalDirV; // direction to reach
|
float m_finalDirV; // direction to reach
|
||||||
float m_initialDirH; // initial direction
|
float m_initialDirH; // initial direction
|
||||||
float m_finalDirH; // direction to reach
|
float m_finalDirH; // direction to reach
|
||||||
|
|
||||||
|
bool m_aimImpossible; // set to true if impossible aim was set
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1393,7 +1393,7 @@ bool CScript::Process(CScript* script, CBotVar* result, int &exception)
|
||||||
|
|
||||||
if ( err == ERR_STOP ) err = ERR_OK;
|
if ( err == ERR_STOP ) err = ERR_OK;
|
||||||
result->SetValInt(err); // indicates the error or 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;
|
exception = err;
|
||||||
return false;
|
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)".
|
// Compilation of the instruction "detect(type)".
|
||||||
|
|
||||||
CBotTypResult CScript::cDetect(CBotVar* &var, void* user)
|
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 = var->GetNext();
|
||||||
var == 0 ? y=0.0f : y=var->GetValFloat();
|
var == 0 ? y=0.0f : y=var->GetValFloat();
|
||||||
err = script->m_primaryTask->StartTaskGunGoal(x*Math::PI/180.0f, y*Math::PI/180.0f);
|
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;
|
delete script->m_primaryTask;
|
||||||
script->m_primaryTask = 0;
|
script->m_primaryTask = 0;
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include "common/event.h"
|
#include "common/event.h"
|
||||||
|
|
||||||
|
#include "common/global.h"
|
||||||
|
|
||||||
#include "app/pausemanager.h"
|
#include "app/pausemanager.h"
|
||||||
|
|
||||||
#include "CBot/CBotDll.h"
|
#include "CBot/CBotDll.h"
|
||||||
|
@ -209,6 +211,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool Process(CScript* script, CBotVar* result, int &exception);
|
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);
|
static CObject* SearchInfo(CScript* script, CObject* object, float power);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue