From 796cb92ffc7dc03f9cc7107cac5ddb81795d0549 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 18 May 2013 17:38:44 +0200 Subject: Added object.destroy() --- src/object/auto/autodestroyer.cpp | 51 +++++++++++++++++++++++++++------------ src/object/auto/autodestroyer.h | 2 ++ 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'src/object/auto') diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index e33c317..8e3fa98 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -24,6 +24,7 @@ #include "ui/interface.h" #include "ui/window.h" +#include "ui/displaytext.h" #include #include @@ -68,6 +69,36 @@ void CAutoDestroyer::Init() } +// Starts an action +Error CAutoDestroyer::StartAction(int param) +{ + CObject* scrap; + + if ( m_object->GetVirusMode() ) // contaminated by a virus? + { + return ERR_BAT_VIRUS; + } + + scrap = SearchPlastic(); + if ( scrap == nullptr ) + return ERR_DESTROY_NOTFOUND; + else { + if ( m_phase == ADEP_WAIT ) { + scrap->SetLock(true); // usable waste +//? scrap->SetTruck(m_object); // usable waste + + m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f); + + m_phase = ADEP_DOWN; + m_progress = 0.0f; + m_speed = 1.0f/1.0f; + m_bExplo = false; + } else + return ERR_GENERIC; + } + return ERR_OK; +} + // Management of an event. bool CAutoDestroyer::EventProcess(const Event &event) @@ -86,21 +117,11 @@ bool CAutoDestroyer::EventProcess(const Event &event) { if ( event.type == EVENT_OBJECT_BDESTROY ) { - if ( m_object->GetVirusMode() ) // contaminated by a virus? - { - return true; // Don't do anything. TODO: Error? - } + Error err = StartAction(0); + if ( err != ERR_OK ) + m_displayText->DisplayError(err, m_object); - scrap = SearchPlastic(); - scrap->SetLock(true); // usable waste -//? scrap->SetTruck(m_object); // usable waste - - m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f); - - m_phase = ADEP_DOWN; - m_progress = 0.0f; - m_speed = 1.0f/1.0f; - m_bExplo = false; + return false; } } @@ -381,4 +402,4 @@ void CAutoDestroyer::EnableInterface(Ui::CWindow *pw, EventType event, bool bSta if ( control == 0 ) return; control->SetState(Ui::STATE_ENABLE, bState); -} \ No newline at end of file +} diff --git a/src/object/auto/autodestroyer.h b/src/object/auto/autodestroyer.h index 4ab1118..ef3d5ae 100644 --- a/src/object/auto/autodestroyer.h +++ b/src/object/auto/autodestroyer.h @@ -46,6 +46,8 @@ public: bool EventProcess(const Event &event); Error GetError(); + Error StartAction(int param); + bool CreateInterface(bool bSelect); bool Write(char *line); -- cgit v1.2.3-1-g7c22