summaryrefslogtreecommitdiffstats
path: root/src/object/auto
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-18 17:38:44 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-18 18:04:48 +0200
commit796cb92ffc7dc03f9cc7107cac5ddb81795d0549 (patch)
treec53eddc06665e251956773f290fdb89440b52ac2 /src/object/auto
parentd0de6a88ba5095c4d485e281e6fb3e804b0c21b6 (diff)
downloadcolobot-796cb92ffc7dc03f9cc7107cac5ddb81795d0549.tar.gz
colobot-796cb92ffc7dc03f9cc7107cac5ddb81795d0549.tar.bz2
colobot-796cb92ffc7dc03f9cc7107cac5ddb81795d0549.zip
Added object.destroy()
Diffstat (limited to 'src/object/auto')
-rw-r--r--src/object/auto/autodestroyer.cpp51
-rw-r--r--src/object/auto/autodestroyer.h2
2 files changed, 38 insertions, 15 deletions
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 <stdio.h>
#include <string.h>
@@ -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);