summaryrefslogtreecommitdiffstats
path: root/src/object
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2013-05-19 21:48:29 +0200
committerkrzys-h <krzys_h@interia.pl>2013-05-19 21:48:29 +0200
commitf90a4b48f5ecdc498c32b1b4a35d57f107f36fd5 (patch)
treea44f5a61c7729db9fd0e37aafce2140e88d7991f /src/object
parent6798641a71e18e1e3ea798617deb38f557b3c497 (diff)
downloadcolobot-f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5.tar.gz
colobot-f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5.tar.bz2
colobot-f90a4b48f5ecdc498c32b1b4a35d57f107f36fd5.zip
Added object.research(type)
Diffstat (limited to 'src/object')
-rw-r--r--src/object/auto/autolabo.cpp101
-rw-r--r--src/object/auto/autolabo.h3
-rw-r--r--src/object/auto/autoresearch.cpp175
-rw-r--r--src/object/auto/autoresearch.h4
-rw-r--r--src/object/robotmain.cpp7
5 files changed, 155 insertions, 135 deletions
diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp
index 6984fd6..8424b93 100644
--- a/src/object/auto/autolabo.cpp
+++ b/src/object/auto/autolabo.cpp
@@ -42,7 +42,7 @@ const float LABO_DELAY = 20.0f; // duration of the analysis
// Object's constructor.
- CAutoLabo::CAutoLabo(CObject* object) : CAuto(object)
+CAutoLabo::CAutoLabo(CObject* object) : CAuto(object)
{
int i;
@@ -111,6 +111,48 @@ void CAutoLabo::Init()
}
+// Starts an action
+
+Error CAutoLabo::StartAction(int param)
+{
+ CObject* power;
+
+ if ( m_phase != ALAP_WAIT )
+ {
+ return ERR_GENERIC;
+ }
+
+ m_research = static_cast<ResearchType>(param);
+
+ if ( g_researchDone & m_research )
+ {
+ return ERR_LABO_ALREADY;
+ }
+
+ power = m_object->GetPower();
+ if ( power == 0 )
+ {
+ return ERR_LABO_NULL;
+ }
+ if ( power->GetType() != OBJECT_BULLET )
+ {
+ return ERR_LABO_BAD;
+ }
+
+ SetBusy(true);
+ InitProgressTotal(1.0f+1.5f+1.5f+LABO_DELAY+1.5f+1.5f+1.0f);
+ UpdateInterface();
+
+ power->SetLock(true); // ball longer usable
+
+ SoundManip(1.0f, 1.0f, 1.0f);
+ m_phase = ALAP_OPEN1;
+ m_progress = 0.0f;
+ m_speed = 1.0f/1.0f;
+ return ERR_OK;
+}
+
+
// Management of an event.
bool CAutoLabo::EventProcess(const Event &event)
@@ -130,46 +172,17 @@ bool CAutoLabo::EventProcess(const Event &event)
if ( m_object->GetSelect() ) CreateInterface(true);
}
- if ( m_object->GetSelect() && // center selected?
- (event.type == EVENT_OBJECT_RiPAW ||
- event.type == EVENT_OBJECT_RiGUN) )
+ if ( m_object->GetSelect() ) // center selected?
{
- if ( m_phase != ALAP_WAIT )
- {
- return false;
- }
-
- m_research = event.type;
-
- if ( TestResearch(m_research) )
- {
- m_displayText->DisplayError(ERR_LABO_ALREADY, m_object);
- return false;
- }
-
- power = m_object->GetPower();
- if ( power == 0 )
- {
- m_displayText->DisplayError(ERR_LABO_NULL, m_object);
+ Error err = ERR_GENERIC;
+ if ( event.type == EVENT_OBJECT_RiPAW ) err = StartAction(RESEARCH_iPAW);
+ if ( event.type == EVENT_OBJECT_RiGUN ) err = StartAction(RESEARCH_iGUN);
+
+ if( err != ERR_OK && err != ERR_GENERIC )
+ m_displayText->DisplayError(err, m_object);
+
+ if( err != ERR_GENERIC )
return false;
- }
- if ( power->GetType() != OBJECT_BULLET )
- {
- m_displayText->DisplayError(ERR_LABO_BAD, m_object);
- return false;
- }
-
- SetBusy(true);
- InitProgressTotal(1.0f+1.5f+1.5f+LABO_DELAY+1.5f+1.5f+1.0f);
- UpdateInterface();
-
- power->SetLock(true); // ball longer usable
-
- SoundManip(1.0f, 1.0f, 1.0f);
- m_phase = ALAP_OPEN1;
- m_progress = 0.0f;
- m_speed = 1.0f/1.0f;
- return true;
}
if ( event.type != EVENT_FRAME ) return true;
@@ -341,7 +354,13 @@ bool CAutoLabo::EventProcess(const Event &event)
}
else
{
- SetResearch(m_research); // research done
+ g_researchDone |= m_research; // research done
+
+ m_main->WriteFreeParam();
+
+ Event newEvent(EVENT_UPDINTERFACE);
+ m_eventQueue->AddEvent(newEvent);
+ UpdateInterface();
power = m_object->GetPower();
if ( power != 0 )
@@ -606,7 +625,7 @@ bool CAutoLabo::Read(char *line)
m_phase = static_cast< AutoLaboPhase >(OpInt(line, "aPhase", ALAP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
- m_research = static_cast< EventType >(OpInt(line, "aResearch", 0));
+ m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
m_lastParticle = 0.0f;
diff --git a/src/object/auto/autolabo.h b/src/object/auto/autolabo.h
index b61e8e3..b3b08bb 100644
--- a/src/object/auto/autolabo.h
+++ b/src/object/auto/autolabo.h
@@ -47,6 +47,7 @@ public:
void DeleteObject(bool bAll=false);
void Init();
+ Error StartAction(int param);
bool EventProcess(const Event &event);
Error GetError();
@@ -68,7 +69,7 @@ protected:
float m_speed;
float m_timeVirus;
float m_lastParticle;
- EventType m_research;
+ ResearchType m_research;
int m_partiRank[3];
int m_partiSphere;
int m_soundChannel;
diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp
index 3c32307..7564bb8 100644
--- a/src/object/auto/autoresearch.cpp
+++ b/src/object/auto/autoresearch.cpp
@@ -92,6 +92,60 @@ void CAutoResearch::Init()
}
+// Starts an action
+
+Error CAutoResearch::StartAction(int param)
+{
+ CObject* power;
+ float time;
+
+ if ( m_phase != ALP_WAIT )
+ {
+ return ERR_GENERIC;
+ }
+
+ m_research = static_cast<ResearchType>(param);
+
+ if ( g_researchDone & m_research )
+ {
+ return ERR_RESEARCH_ALREADY;
+ }
+
+ power = m_object->GetPower();
+ if ( power == 0 )
+ {
+ return ERR_RESEARCH_POWER;
+ }
+ if ( power->GetCapacity() > 1.0f )
+ {
+ return ERR_RESEARCH_TYPE;
+ }
+ if ( power->GetEnergy() < 1.0f )
+ {
+ return ERR_RESEARCH_ENERGY;
+ }
+
+ time = SEARCH_TIME;
+ if ( m_research == RESEARCH_TANK ) time *= 0.3f;
+ if ( m_research == RESEARCH_FLY ) time *= 0.3f;
+ if ( m_research == RESEARCH_ATOMIC ) time *= 2.0f;
+
+ SetBusy(true);
+ InitProgressTotal(time);
+ UpdateInterface();
+
+ m_channelSound = m_sound->Play(SOUND_RESEARCH, m_object->GetPosition(0), 0.0f, 1.0f, true);
+ m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE);
+ m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, time-4.0f, SOPER_CONTINUE);
+ m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
+
+ m_phase = ALP_SEARCH;
+ m_progress = 0.0f;
+ m_speed = 1.0f/time;
+ return ERR_OK;
+}
+
+
// Management of an event.
bool CAutoResearch::EventProcess(const Event &event)
@@ -100,7 +154,7 @@ bool CAutoResearch::EventProcess(const Event &event)
Math::Vector pos, speed;
Error message;
Math::Point dim;
- float angle, time;
+ float angle;
CAuto::EventProcess(event);
@@ -111,64 +165,23 @@ bool CAutoResearch::EventProcess(const Event &event)
if ( m_object->GetSelect() ) CreateInterface(true);
}
- if ( m_object->GetSelect() && // center selected?
- (event.type == EVENT_OBJECT_RTANK ||
- event.type == EVENT_OBJECT_RFLY ||
- event.type == EVENT_OBJECT_RTHUMP ||
- event.type == EVENT_OBJECT_RCANON ||
- event.type == EVENT_OBJECT_RTOWER ||
- event.type == EVENT_OBJECT_RPHAZER ||
- event.type == EVENT_OBJECT_RSHIELD ||
- event.type == EVENT_OBJECT_RATOMIC ) )
+ if ( m_object->GetSelect() ) // center selected?
{
- if ( m_phase != ALP_WAIT )
- {
- return false;
- }
-
- m_research = event.type;
-
- if ( TestResearch(m_research) )
- {
- m_displayText->DisplayError(ERR_RESEARCH_ALREADY, m_object);
- return false;
- }
-
- power = m_object->GetPower();
- if ( power == 0 )
- {
- m_displayText->DisplayError(ERR_RESEARCH_POWER, m_object);
+ Error err = ERR_GENERIC;
+ if ( event.type == EVENT_OBJECT_RTANK ) err = StartAction(RESEARCH_TANK);
+ if ( event.type == EVENT_OBJECT_RFLY ) err = StartAction(RESEARCH_FLY);
+ if ( event.type == EVENT_OBJECT_RTHUMP ) err = StartAction(RESEARCH_THUMP);
+ if ( event.type == EVENT_OBJECT_RCANON ) err = StartAction(RESEARCH_CANON);
+ if ( event.type == EVENT_OBJECT_RTOWER ) err = StartAction(RESEARCH_TOWER);
+ if ( event.type == EVENT_OBJECT_RPHAZER ) err = StartAction(RESEARCH_PHAZER);
+ if ( event.type == EVENT_OBJECT_RSHIELD ) err = StartAction(RESEARCH_SHIELD);
+ if ( event.type == EVENT_OBJECT_RATOMIC ) err = StartAction(RESEARCH_ATOMIC);
+
+ if( err != ERR_OK && err != ERR_GENERIC )
+ m_displayText->DisplayError(err, m_object);
+
+ if( err != ERR_GENERIC )
return false;
- }
- if ( power->GetCapacity() > 1.0f )
- {
- m_displayText->DisplayError(ERR_RESEARCH_TYPE, m_object);
- return false;
- }
- if ( power->GetEnergy() < 1.0f )
- {
- m_displayText->DisplayError(ERR_RESEARCH_ENERGY, m_object);
- return false;
- }
-
- time = SEARCH_TIME;
- if ( event.type == EVENT_OBJECT_RTANK ) time *= 0.3f;
- if ( event.type == EVENT_OBJECT_RFLY ) time *= 0.3f;
- if ( event.type == EVENT_OBJECT_RATOMIC ) time *= 2.0f;
-
- SetBusy(true);
- InitProgressTotal(time);
- UpdateInterface();
-
- m_channelSound = m_sound->Play(SOUND_RESEARCH, m_object->GetPosition(0), 0.0f, 1.0f, true);
- m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE);
- m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, time-4.0f, SOPER_CONTINUE);
- m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
-
- m_phase = ALP_SEARCH;
- m_progress = 0.0f;
- m_speed = 1.0f/time;
- return true;
}
if ( event.type != EVENT_FRAME ) return true;
@@ -236,18 +249,25 @@ bool CAutoResearch::EventProcess(const Event &event)
}
else
{
- SetResearch(m_research); // research done
+ g_researchDone |= m_research; // research done
+
+ m_main->WriteFreeParam();
+
+ Event newEvent(EVENT_UPDINTERFACE);
+ m_eventQueue->AddEvent(newEvent);
+ UpdateInterface();
+
m_displayText->DisplayError(INFO_RESEARCH, m_object);
message = ERR_OK;
- if ( m_research == EVENT_OBJECT_RTANK ) message = INFO_RESEARCHTANK;
- if ( m_research == EVENT_OBJECT_RFLY ) message = INFO_RESEARCHFLY;
- if ( m_research == EVENT_OBJECT_RTHUMP ) message = INFO_RESEARCHTHUMP;
- if ( m_research == EVENT_OBJECT_RCANON ) message = INFO_RESEARCHCANON;
- if ( m_research == EVENT_OBJECT_RTOWER ) message = INFO_RESEARCHTOWER;
- if ( m_research == EVENT_OBJECT_RPHAZER ) message = INFO_RESEARCHPHAZER;
- if ( m_research == EVENT_OBJECT_RSHIELD ) message = INFO_RESEARCHSHIELD;
- if ( m_research == EVENT_OBJECT_RATOMIC ) message = INFO_RESEARCHATOMIC;
+ if ( m_research == RESEARCH_TANK ) message = INFO_RESEARCHTANK;
+ if ( m_research == RESEARCH_FLY ) message = INFO_RESEARCHFLY;
+ if ( m_research == RESEARCH_THUMP ) message = INFO_RESEARCHTHUMP;
+ if ( m_research == RESEARCH_CANON ) message = INFO_RESEARCHCANON;
+ if ( m_research == RESEARCH_TOWER ) message = INFO_RESEARCHTOWER;
+ if ( m_research == RESEARCH_PHAZER ) message = INFO_RESEARCHPHAZER;
+ if ( m_research == RESEARCH_SHIELD ) message = INFO_RESEARCHSHIELD;
+ if ( m_research == RESEARCH_ATOMIC ) message = INFO_RESEARCHATOMIC;
if ( message != ERR_OK )
{
m_displayText->DisplayError(message, m_object);
@@ -474,27 +494,6 @@ bool CAutoResearch::TestResearch(EventType event)
return false;
}
-// Indicates a search as made.
-
-void CAutoResearch::SetResearch(EventType event)
-{
-
- if ( event == EVENT_OBJECT_RTANK ) g_researchDone |= RESEARCH_TANK;
- if ( event == EVENT_OBJECT_RFLY ) g_researchDone |= RESEARCH_FLY;
- if ( event == EVENT_OBJECT_RTHUMP ) g_researchDone |= RESEARCH_THUMP;
- if ( event == EVENT_OBJECT_RCANON ) g_researchDone |= RESEARCH_CANON;
- if ( event == EVENT_OBJECT_RTOWER ) g_researchDone |= RESEARCH_TOWER;
- if ( event == EVENT_OBJECT_RPHAZER ) g_researchDone |= RESEARCH_PHAZER;
- if ( event == EVENT_OBJECT_RSHIELD ) g_researchDone |= RESEARCH_SHIELD;
- if ( event == EVENT_OBJECT_RATOMIC ) g_researchDone |= RESEARCH_ATOMIC;
-
- m_main->WriteFreeParam();
-
- Event newEvent(EVENT_UPDINTERFACE);
- m_eventQueue->AddEvent(newEvent);
- UpdateInterface();
-}
-
// Updates the stop lights.
@@ -600,7 +599,7 @@ bool CAutoResearch::Read(char *line)
m_phase = static_cast< AutoResearchPhase >(OpInt(line, "aPhase", ALP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
- m_research = static_cast< EventType >(OpInt(line, "aResearch", 0));
+ m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
m_lastUpdateTime = 0.0f;
m_lastParticle = 0.0f;
diff --git a/src/object/auto/autoresearch.h b/src/object/auto/autoresearch.h
index 6c804ef..dcb9f7b 100644
--- a/src/object/auto/autoresearch.h
+++ b/src/object/auto/autoresearch.h
@@ -41,6 +41,7 @@ public:
void DeleteObject(bool bAll=false);
void Init();
+ Error StartAction(int result);
bool EventProcess(const Event &event);
Error GetError();
@@ -54,7 +55,6 @@ protected:
void UpdateInterface(float rTime);
void OkayButton(Ui::CWindow *pw, EventType event);
bool TestResearch(EventType event);
- void SetResearch(EventType event);
void FireStopUpdate(float progress, bool bLightOn);
protected:
@@ -64,7 +64,7 @@ protected:
float m_timeVirus;
float m_lastUpdateTime;
float m_lastParticle;
- EventType m_research;
+ ResearchType m_research;
int m_partiStop[6];
int m_channelSound;
};
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index b959d44..15250c6 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -873,9 +873,10 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), PR_READ);
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), PR_READ);
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
- bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
- bc->AddFunction("factory", CScript::rFactory, CScript::cFactory);
- bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
+ bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
+ bc->AddFunction("factory", CScript::rFactory, CScript::cFactory);
+ bc->AddFunction("research", CScript::rResearch, CScript::cClassOneFloat);
+ bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
// Initializes the class FILE.
InitClassFILE();