Add an ability to cancel making a building (fixes #509)

master
MrSimbax 2015-07-30 17:47:26 +02:00
parent 119bc62a7c
commit a18d195cfd
2 changed files with 42 additions and 0 deletions

View File

@ -208,6 +208,22 @@ bool CTaskBuild::EventProcess(const Event &event)
m_progress += event.rTime*m_speed; // other advance
// Cancel if the player try to move
float axeX = event.motionInput.x;
float axeY = event.motionInput.y;
float axeZ = event.motionInput.z;
if ( m_object->GetType() == OBJECT_HUMAN &&
(axeX != 0.0f || axeY != 0.0f || axeZ != 0.0f) &&
(m_phase == TBP_TURN || m_phase == TBP_MOVE || m_phase == TBP_TAKE || m_phase == TBP_PREP) )
{
m_phase = TBP_STOP;
}
if ( m_phase == TBP_STOP ) // stops?
{
return true;
}
if ( m_phase == TBP_TURN ) // preliminary rotation?
{
a = m_object->GetRotationY();
@ -554,6 +570,31 @@ Error CTaskBuild::IsEnded()
m_physics->SetMotorSpeedX(0.0f);
}
if ( m_phase == TBP_STOP ) // canceled?
{
if ( m_progress < 1.0f && m_motion->GetAction() == MHS_GUN ) return ERR_CONTINUE;
if ( m_motion->GetAction() == MHS_FIRE )
{
m_motion->SetAction(MHS_GUN);
m_speed = 1.0f/1.0f;
m_progress = 0.0f;
return ERR_CONTINUE;
}
m_motion->SetAction(-1);
// Place gun back
m_object->SetObjectParent(14, 0);
m_object->SetPartPosition(14, Math::Vector(-1.5f, 0.3f, -1.35f));
m_object->SetPartRotationZ(14, Math::PI);
m_physics->SetMotorSpeedX(0.0f);
m_physics->SetMotorSpeedZ(0.0f);
m_metal->SetLock(false); // make titanium usable
}
Abort();
return ERR_STOP;
}

View File

@ -37,6 +37,7 @@ const int TBMAXLIGHT = 4;
enum TaskBuildPhase
{
TBP_STOP = 0, // cancels task
TBP_TURN = 1, // turns
TBP_MOVE = 2, // forward/backward
TBP_TAKE = 3, // takes gun