summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-02 17:55:53 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-02 17:55:53 +0200
commit8a1e4b1e5f9a321aaa10b120881c52706c48c68a (patch)
treefffc79ba27152598a9369fa574ca847176c434cf
parent4dde10e9a58af33a64bc0292e4a8ad07fd38cd90 (diff)
downloadcolobot-8a1e4b1e5f9a321aaa10b120881c52706c48c68a.tar.gz
colobot-8a1e4b1e5f9a321aaa10b120881c52706c48c68a.tar.bz2
colobot-8a1e4b1e5f9a321aaa10b120881c52706c48c68a.zip
Added button for Destroyer
Issue #142
-rw-r--r--src/common/event.h1
-rw-r--r--src/common/restext.cpp1
-rw-r--r--src/object/auto/autodestroyer.cpp161
-rw-r--r--src/object/auto/autodestroyer.h2
4 files changed, 52 insertions, 113 deletions
diff --git a/src/common/event.h b/src/common/event.h
index 153b732..b9c6623 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -396,6 +396,7 @@ enum EventType
EVENT_OBJECT_MPOWER = 1024,
EVENT_OBJECT_BHELP = 1040,
EVENT_OBJECT_BTAKEOFF = 1041,
+ EVENT_OBJECT_BDESTROY = 1042,
EVENT_OBJECT_BDERRICK = 1050,
EVENT_OBJECT_BSTATION = 1051,
EVENT_OBJECT_BFACTORY = 1052,
diff --git a/src/common/restext.cpp b/src/common/restext.cpp
index b610d7f..7fdcdbd 100644
--- a/src/common/restext.cpp
+++ b/src/common/restext.cpp
@@ -295,6 +295,7 @@ void InitializeRestext()
stringsEvent[EVENT_OBJECT_MPOWER] = "..power cell";
stringsEvent[EVENT_OBJECT_BHELP] = "Instructions for the mission (\\key help;)";
stringsEvent[EVENT_OBJECT_BTAKEOFF] = "Take off to finish the mission";
+ stringsEvent[EVENT_OBJECT_BDESTROY] = "Destroy";
stringsEvent[EVENT_OBJECT_BDERRICK] = "Build a derrick";
stringsEvent[EVENT_OBJECT_BSTATION] = "Build a power station";
stringsEvent[EVENT_OBJECT_BFACTORY] = "Build a bot factory";
diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp
index b62a45a..2d64fb1 100644
--- a/src/object/auto/autodestroyer.cpp
+++ b/src/object/auto/autodestroyer.cpp
@@ -72,14 +72,35 @@ void CAutoDestroyer::Init()
bool CAutoDestroyer::EventProcess(const Event &event)
{
- CObject* scrap;
- Gfx::CPyro* pyro;
+ CObject* scrap;
+ Gfx::CPyro* pyro;
Math::Vector pos, speed;
Math::Point dim;
+ Ui::CWindow* pw;
CAuto::EventProcess(event);
if ( m_engine->GetPause() ) return true;
+
+ if ( event.type == EVENT_OBJECT_BDESTROY )
+ {
+ if ( m_object->GetVirusMode() ) // contaminated by a virus?
+ {
+ return true; // Don't do anything. TODO: Error?
+ }
+
+ 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;
+ }
+
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
@@ -98,55 +119,13 @@ bool CAutoDestroyer::EventProcess(const Event &event)
{
if ( m_progress >= 1.0f )
{
+ m_phase = ADEP_WAIT; // still waiting ...
+ m_progress = 0.0f;
+ m_speed = 1.0f/0.5f;
scrap = SearchPlastic();
- if ( scrap == 0 )
- {
- m_phase = ADEP_WAIT; // still waiting ...
- m_progress = 0.0f;
- m_speed = 1.0f/0.5f;
- }
- else
- {
- scrap->SetLock(true); // usable waste
-//? scrap->SetTruck(m_object); // usable waste
-
- if ( SearchVehicle() )
- {
- if ( m_progress < 20.0f ) {
- m_phase = ADEP_WAIT; // still waiting ...
- //m_progress = 0.0f;
- m_speed = 1.0f/0.5f;
- } else {
- if ( m_object->GetLock() ) { // If still building...
- m_phase = ADEP_WAIT; // still waiting ...
- m_progress = 0.0f;
- m_speed = 1.0f/0.5f;
- } else {
- 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
- {
- if ( m_object->GetLock() ) { // If still building...
- m_phase = ADEP_WAIT; // still waiting ...
- m_progress = 0.0f;
- m_speed = 1.0f/0.5f;
- } else {
- 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;
- }
- }
- }
+ pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
+ if ( pw == 0 ) return true;
+ EnableInterface(pw, EVENT_OBJECT_BDESTROY, (scrap != 0));
}
}
@@ -224,6 +203,7 @@ bool CAutoDestroyer::CreateInterface(bool bSelect)
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
+ CObject* scrap;
CAuto::CreateInterface(bSelect);
@@ -243,6 +223,15 @@ bool CAutoDestroyer::CreateInterface(bool bSelect)
ddim.y = 66.0f/480.0f;
pw->CreateGroup(pos, ddim, 106, EVENT_OBJECT_TYPE);
+ pos.x = ox+sx*8.00f;
+ pos.y = oy+sy*0.25f;
+ ddim.x = (33.0f/640.0f)*1.5f;
+ ddim.y = (33.0f/480.0f)*1.5f;
+ pw->CreateButton(pos, ddim, 12, EVENT_OBJECT_BDESTROY);
+
+ scrap = SearchPlastic();
+ EnableInterface(pw, EVENT_OBJECT_BDESTROY, (scrap != 0));
+
return true;
}
@@ -323,68 +312,6 @@ CObject* CAutoDestroyer::SearchPlastic()
return nullptr;
}
-// Seeks if one vehicle is too close.
-
-bool CAutoDestroyer::SearchVehicle()
-{
- CObject* pObj;
- Math::Vector cPos, oPos;
- ObjectType type;
- float oRadius, dist;
- int i;
-
- cPos = m_object->GetPosition(0);
-
- for ( i=0 ; i<1000000 ; i++ )
- {
- pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
- if ( pObj == nullptr ) break;
-
- type = pObj->GetType();
- if ( type != OBJECT_HUMAN &&
- type != OBJECT_MOBILEfa &&
- type != OBJECT_MOBILEta &&
- type != OBJECT_MOBILEwa &&
- type != OBJECT_MOBILEia &&
- type != OBJECT_MOBILEfc &&
- type != OBJECT_MOBILEtc &&
- type != OBJECT_MOBILEwc &&
- type != OBJECT_MOBILEic &&
- type != OBJECT_MOBILEfi &&
- type != OBJECT_MOBILEti &&
- type != OBJECT_MOBILEwi &&
- type != OBJECT_MOBILEii &&
- type != OBJECT_MOBILEfs &&
- type != OBJECT_MOBILEts &&
- type != OBJECT_MOBILEws &&
- type != OBJECT_MOBILEis &&
- type != OBJECT_MOBILErt &&
- type != OBJECT_MOBILErc &&
- type != OBJECT_MOBILErr &&
- type != OBJECT_MOBILErs &&
- type != OBJECT_MOBILEsa &&
- type != OBJECT_MOBILEtg &&
- type != OBJECT_MOBILEft &&
- type != OBJECT_MOBILEtt &&
- type != OBJECT_MOBILEwt &&
- type != OBJECT_MOBILEit &&
- type != OBJECT_MOBILEdr &&
- type != OBJECT_MOTHER &&
- type != OBJECT_ANT &&
- type != OBJECT_SPIDER &&
- type != OBJECT_BEE &&
- type != OBJECT_WORM ) continue;
-
- if ( !pObj->GetCrashSphere(0, oPos, oRadius) ) continue;
- dist = Math::Distance(oPos, cPos)-oRadius;
-
- if ( dist < 20.0f ) return true;
- }
-
- return false;
-}
-
-
// Returns an error due the state of the automation.
Error CAutoDestroyer::GetError()
@@ -440,4 +367,14 @@ bool CAutoDestroyer::Read(char *line)
return true;
}
+// Changes the state of a button interface.
+
+void CAutoDestroyer::EnableInterface(Ui::CWindow *pw, EventType event, bool bState)
+{
+ Ui::CControl* control;
+
+ control = pw->SearchControl(event);
+ 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 26981c3..4ab1118 100644
--- a/src/object/auto/autodestroyer.h
+++ b/src/object/auto/autodestroyer.h
@@ -53,7 +53,7 @@ public:
protected:
CObject* SearchPlastic();
- bool SearchVehicle();
+ void EnableInterface(Ui::CWindow *pw, EventType event, bool bState);
protected:
AutoDestroyerPhase m_phase;