diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-06-24 21:37:15 +0200 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-06-24 21:37:15 +0200 |
commit | 7c2e955e1552a9c4e412ea2c936be61fc78ba010 (patch) | |
tree | ee506dfbec54f998d10c385bde3a1c3fa04e66b2 /src/object | |
parent | e218dcfdf2c58f8841e7ebd220527d08e870a6d5 (diff) | |
parent | b376486fd74fa02b0297ceef6d0f977b32358e5e (diff) | |
download | colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.tar.gz colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.tar.bz2 colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.zip |
Colobot Gold 0.1.0-alpha
Diffstat (limited to 'src/object')
60 files changed, 1663 insertions, 536 deletions
diff --git a/src/object/README.txt b/src/object/README.txt index fe946db..4e21620 100644 --- a/src/object/README.txt +++ b/src/object/README.txt @@ -5,3 +5,4 @@ * Contains the main class of game engine - CRobotMain and the various in-game objects: * CObject and related auto, motion and task subclasses. */ + diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index 3d88012..8dc1d94 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -107,6 +107,12 @@ void CAuto::Start(int param) { } +// Starts an action + +Error CAuto::StartAction(int param) +{ + return ERR_GENERIC; +} // Gete a type. diff --git a/src/object/auto/auto.h b/src/object/auto/auto.h index 53ccdf9..4a430ce 100644 --- a/src/object/auto/auto.h +++ b/src/object/auto/auto.h @@ -31,7 +31,7 @@ namespace Ui { class CDisplayText; class CInterface; class CWindow; -} /* Ui */ +} /* Ui */ namespace Gfx { @@ -44,7 +44,7 @@ class CCloud; class CCamera; class CPlanet; class CLightning; -} /* Gfx */ +} /* Gfx */ class CAuto @@ -61,6 +61,8 @@ public: virtual Error IsEnded(); virtual bool Abort(); + virtual Error StartAction(int param); + virtual bool SetType(ObjectType type); virtual bool SetValue(int rank, float value); virtual bool SetString(char *string); diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index cb7f04c..d0bd87b 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -1412,9 +1412,8 @@ void CAutoBase::BeginTransit() m_engine->SetDeepView(2000.0f); // we see very far m_engine->ApplyChange(); - Math::Point scale; bool full; - m_engine->GetBackground(m_bgName, m_bgUp, m_bgDown, m_bgCloudUp, m_bgCloudDown, full, scale); + m_engine->GetBackground(m_bgName, m_bgUp, m_bgDown, m_bgCloudUp, m_bgCloudDown, full); m_engine->DeleteTexture(m_bgName); m_engine->SetBackground(m_bgBack, Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index 260edcb..b613406 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -589,4 +589,3 @@ Error CAutoDerrick::GetError() return ERR_OK; } - diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index b62a45a..fdaebc0 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,18 +69,65 @@ 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) { - 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 (m_main->GetSelect() == m_object) + { + if ( event.type == EVENT_OBJECT_BDESTROY ) + { + Error err = StartAction(0); + if ( err != ERR_OK ) + m_displayText->DisplayError(err, m_object); + + return false; + } + } + if ( event.type != EVENT_FRAME ) return true; m_progress += event.rTime*m_speed; @@ -94,61 +142,21 @@ bool CAutoDestroyer::EventProcess(const Event &event) return true; } + pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0)); if ( m_phase == ADEP_WAIT ) { if ( m_progress >= 1.0f ) { - scrap = SearchPlastic(); - if ( scrap == 0 ) - { - m_phase = ADEP_WAIT; // still waiting ... - m_progress = 0.0f; - m_speed = 1.0f/0.5f; - } - else + m_phase = ADEP_WAIT; // still waiting ... + m_progress = 0.0f; + m_speed = 1.0f/0.5f; + if (m_main->GetSelect() == m_object) { - 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; - } - } + scrap = SearchPlastic(); + if ( pw != 0 ) EnableInterface(pw, EVENT_OBJECT_BDESTROY, (scrap != 0)); } } - } + } else if ( pw != 0 ) EnableInterface(pw, EVENT_OBJECT_BDESTROY, false); if ( m_phase == ADEP_DOWN ) { @@ -224,6 +232,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 +252,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 +341,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 +396,15 @@ 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); +} diff --git a/src/object/auto/autodestroyer.h b/src/object/auto/autodestroyer.h index 26981c3..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); @@ -53,7 +55,7 @@ public: protected: CObject* SearchPlastic(); - bool SearchVehicle(); + void EnableInterface(Ui::CWindow *pw, EventType event, bool bState); protected: AutoDestroyerPhase m_phase; diff --git a/src/object/auto/autoenergy.cpp b/src/object/auto/autoenergy.cpp index a0b4d85..6a8672b 100644 --- a/src/object/auto/autoenergy.cpp +++ b/src/object/auto/autoenergy.cpp @@ -649,3 +649,4 @@ bool CAutoEnergy::Read(char *line) return true; } + diff --git a/src/object/auto/autofactory.cpp b/src/object/auto/autofactory.cpp index 82877c6..a648656 100644 --- a/src/object/auto/autofactory.cpp +++ b/src/object/auto/autofactory.cpp @@ -24,6 +24,7 @@ #include "math/geometry.h" #include "object/robotmain.h" +#include "object/brain.h" #include "physics/physics.h" @@ -103,21 +104,74 @@ void CAutoFactory::Init() m_fretPos = m_object->GetPosition(0); + m_program = nullptr; + CAuto::Init(); } +// Starts an action + +Error CAutoFactory::StartAction(int param) +{ + CObject* fret; + ObjectType type = static_cast<ObjectType>(param); + + if ( type != OBJECT_NULL ) + { + if ( m_phase != AFP_WAIT ) + { + return ERR_OK; + } + + m_type = type; + + fret = SearchFret(); // transform metal? + if ( fret == 0 ) + { + return ERR_FACTORY_NULL; + } + if ( NearestVehicle() ) + { + return ERR_FACTORY_NEAR; + } + + SetBusy(true); + InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f); + UpdateInterface(); + + fret->SetLock(true); // usable metal + SoundManip(3.0f, 1.0f, 0.5f); + + m_phase = AFP_CLOSE_S; + m_progress = 0.0f; + m_speed = 1.0f/3.0f; + return ERR_OK; + } + return ERR_GENERIC; +} + + +// Sets program for created robot + +void CAutoFactory::SetProgram(const char* program) +{ + m_program = new char[strlen(program)+1]; + strcpy(m_program, program); +} + + // Management of an event. bool CAutoFactory::EventProcess(const Event &event) { + ObjectType type; CObject* fret; CObject* vehicle; Math::Matrix* mat; CPhysics* physics; Math::Vector pos, speed; Math::Point dim; - ObjectType type; float zoom, angle, prog; int i; @@ -155,39 +209,12 @@ bool CAutoFactory::EventProcess(const Event &event) if ( event.type == EVENT_OBJECT_FACTORYrs ) type = OBJECT_MOBILErs; if ( event.type == EVENT_OBJECT_FACTORYsa ) type = OBJECT_MOBILEsa; - if ( type != OBJECT_NULL ) - { - m_type = type; + Error err = StartAction(type); + if( err != ERR_OK && err != ERR_GENERIC ) + m_displayText->DisplayError(err, m_object); - if ( m_phase != AFP_WAIT ) - { - return false; - } - - fret = SearchFret(); // transform metal? - if ( fret == 0 ) - { - m_displayText->DisplayError(ERR_FACTORY_NULL, m_object); - return false; - } - if ( NearestVehicle() ) - { - m_displayText->DisplayError(ERR_FACTORY_NEAR, m_object); - return false; - } - - SetBusy(true); - InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f); - UpdateInterface(); - - fret->SetLock(true); // usable metal - SoundManip(3.0f, 1.0f, 0.5f); - - m_phase = AFP_CLOSE_S; - m_progress = 0.0f; - m_speed = 1.0f/3.0f; - return true; - } + if( err != ERR_GENERIC ) + return false; } if ( event.type != EVENT_FRAME ) return true; @@ -362,7 +389,7 @@ bool CAutoFactory::EventProcess(const Event &event) delete fret; } - vehicle = SearchVehicle(); + m_vehicle = vehicle = SearchVehicle(); if ( vehicle != 0 ) { physics = vehicle->GetPhysics(); @@ -461,6 +488,17 @@ bool CAutoFactory::EventProcess(const Event &event) m_object->SetZoomZ(10+i, 0.30f); } + if ( m_program != nullptr ) + { + CBrain* brain = m_vehicle->GetBrain(); + if ( brain != nullptr ) + { + brain->SendProgram(0, const_cast<const char*>(m_program)); + brain->SetScriptRun(0); + brain->RunProgram(0); + } + } + SetBusy(false); UpdateInterface(); diff --git a/src/object/auto/autofactory.h b/src/object/auto/autofactory.h index 7c5013d..d9350e6 100644 --- a/src/object/auto/autofactory.h +++ b/src/object/auto/autofactory.h @@ -48,6 +48,9 @@ public: void Init(); bool EventProcess(const Event &event); + Error StartAction(int param); + void SetProgram(const char* program); + bool CreateInterface(bool bSelect); bool Write(char *line); @@ -69,7 +72,10 @@ protected: float m_progress; float m_speed; float m_lastParticle; - Math::Vector m_fretPos; + Math::Vector m_fretPos; int m_channelSound; + + CObject* m_vehicle; + char* m_program; }; diff --git a/src/object/auto/autoflag.cpp b/src/object/auto/autoflag.cpp index 936546d..cc00db0 100644 --- a/src/object/auto/autoflag.cpp +++ b/src/object/auto/autoflag.cpp @@ -159,4 +159,3 @@ Error CAutoFlag::GetError() return ERR_OK; } - diff --git a/src/object/auto/autoinfo.cpp b/src/object/auto/autoinfo.cpp index 56c21d2..6d4a484 100644 --- a/src/object/auto/autoinfo.cpp +++ b/src/object/auto/autoinfo.cpp @@ -428,7 +428,7 @@ void CAutoInfo::UpdateList() { info = m_object->GetInfo(i); sprintf(text, "%s = %.2f", info.name, info.value); - pl->SetName(i, text); + pl->SetItemName(i, text); } } @@ -466,7 +466,7 @@ void CAutoInfo::UpdateListVirus() } text[j] = 0; - pl->SetName(i, text); + pl->SetItemName(i, text); } } @@ -513,4 +513,3 @@ bool CAutoInfo::Read(char *line) return true; } - diff --git a/src/object/auto/autojostle.cpp b/src/object/auto/autojostle.cpp index 11952c2..5ce01c2 100644 --- a/src/object/auto/autojostle.cpp +++ b/src/object/auto/autojostle.cpp @@ -77,6 +77,11 @@ void CAutoJostle::Start(int param, float force) } } +// Should never be called +void CAutoJostle::Start(int param) +{ +} + // Management of an event. @@ -137,4 +142,3 @@ Error CAutoJostle::IsEnded() return m_error; } - diff --git a/src/object/auto/autojostle.h b/src/object/auto/autojostle.h index 7b700ad..3822421 100644 --- a/src/object/auto/autojostle.h +++ b/src/object/auto/autojostle.h @@ -37,7 +37,9 @@ public: bool EventProcess(const Event &event); Error IsEnded(); -protected: +private: + // Overriden to avoid warning about hiding virtual function + virtual void Start(int param) override; protected: float m_force; diff --git a/src/object/auto/autokid.cpp b/src/object/auto/autokid.cpp index a9f86b0..7d61d64 100644 --- a/src/object/auto/autokid.cpp +++ b/src/object/auto/autokid.cpp @@ -197,4 +197,3 @@ Error CAutoKid::GetError() return ERR_OK; } - diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index 6984fd6..172a618 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; - } + Error err = ERR_GENERIC; + if ( event.type == EVENT_OBJECT_RiPAW ) err = StartAction(RESEARCH_iPAW); + if ( event.type == EVENT_OBJECT_RiGUN ) err = StartAction(RESEARCH_iGUN); - m_research = event.type; + if( err != ERR_OK && err != ERR_GENERIC ) + m_displayText->DisplayError(err, m_object); - if ( TestResearch(m_research) ) - { - m_displayText->DisplayError(ERR_LABO_ALREADY, m_object); + if( err != ERR_GENERIC ) return false; - } - - power = m_object->GetPower(); - if ( power == 0 ) - { - m_displayText->DisplayError(ERR_LABO_NULL, m_object); - 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,11 +625,10 @@ 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; return true; } - 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/automush.cpp b/src/object/auto/automush.cpp index e97e2a1..1e4796d 100644 --- a/src/object/auto/automush.cpp +++ b/src/object/auto/automush.cpp @@ -342,4 +342,3 @@ bool CAutoMush::Read(char *line) return true; } - diff --git a/src/object/auto/autonest.cpp b/src/object/auto/autonest.cpp index 1cf13d6..8a2d644 100644 --- a/src/object/auto/autonest.cpp +++ b/src/object/auto/autonest.cpp @@ -273,4 +273,3 @@ bool CAutoNest::Read(char *line) return true; } - diff --git a/src/object/auto/autonuclear.cpp b/src/object/auto/autonuclear.cpp index 75bfb45..224776d 100644 --- a/src/object/auto/autonuclear.cpp +++ b/src/object/auto/autonuclear.cpp @@ -484,4 +484,3 @@ bool CAutoNuclear::Read(char *line) return true; } - diff --git a/src/object/auto/autopara.cpp b/src/object/auto/autopara.cpp index ad6517b..24bc119 100644 --- a/src/object/auto/autopara.cpp +++ b/src/object/auto/autopara.cpp @@ -327,4 +327,3 @@ bool CAutoPara::Read(char *line) return true; } - diff --git a/src/object/auto/autoradar.cpp b/src/object/auto/autoradar.cpp index 1a10aa7..4afd3fe 100644 --- a/src/object/auto/autoradar.cpp +++ b/src/object/auto/autoradar.cpp @@ -305,4 +305,3 @@ bool CAutoRadar::SearchEnemy(Math::Vector &pos) return true; } - diff --git a/src/object/auto/autorepair.cpp b/src/object/auto/autorepair.cpp index 95b6cc8..2f813f8 100644 --- a/src/object/auto/autorepair.cpp +++ b/src/object/auto/autorepair.cpp @@ -74,7 +74,7 @@ void CAutoRepair::Init() bool CAutoRepair::EventProcess(const Event &event) { - CObject* vehicule; + CObject* vehicle; Math::Vector pos, speed; Math::Point dim; float angle, shield; @@ -137,16 +137,16 @@ bool CAutoRepair::EventProcess(const Event &event) if ( m_phase == ARP_REPAIR ) { - vehicule = SearchVehicle(); + vehicle = SearchVehicle(); if ( m_progress < 1.0f || - (vehicule != 0 && vehicule->GetShield() < 1.0f) ) + (vehicle != 0 && vehicle->GetShield() < 1.0f) ) { - if ( vehicule != 0 ) + if ( vehicle != 0 ) { - shield = vehicule->GetShield(); + shield = vehicle->GetShield(); shield += event.rTime*0.2f; if ( shield > 1.0f ) shield = 1.0f; - vehicule->SetShield(shield); + vehicle->SetShield(shield); } if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time ) @@ -340,4 +340,3 @@ bool CAutoRepair::Read(char *line) return true; } - diff --git a/src/object/auto/autorepair.h b/src/object/auto/autorepair.h index 31a3c65..f522a55 100644 --- a/src/object/auto/autorepair.h +++ b/src/object/auto/autorepair.h @@ -63,4 +63,3 @@ protected: float m_lastParticle; }; - diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index 3c32307..8308ebe 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 ) - { + 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; - } - - 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); - 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; @@ -608,4 +607,3 @@ bool CAutoResearch::Read(char *line) return true; } - 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/auto/autoroot.cpp b/src/object/auto/autoroot.cpp index a390e90..7e5c5e7 100644 --- a/src/object/auto/autoroot.cpp +++ b/src/object/auto/autoroot.cpp @@ -115,4 +115,3 @@ Error CAutoRoot::GetError() return ERR_OK; } - diff --git a/src/object/auto/autosafe.cpp b/src/object/auto/autosafe.cpp index fc83400..2871a70 100644 --- a/src/object/auto/autosafe.cpp +++ b/src/object/auto/autosafe.cpp @@ -400,7 +400,7 @@ int CAutoSafe::CountKeys() Math::Vector cPos, oPos; Math::Point rot; ObjectType oType; - float dist, angle, limit, cAngle, oAngle; + float dist, angle, limit = 0.0f, cAngle, oAngle = 0.0f; int i, index; cPos = m_object->GetPosition(0); @@ -611,5 +611,3 @@ CObject* CAutoSafe::SearchVehicle() return 0; } - - diff --git a/src/object/auto/autostation.cpp b/src/object/auto/autostation.cpp index a2f5b6b..2c0aa02 100644 --- a/src/object/auto/autostation.cpp +++ b/src/object/auto/autostation.cpp @@ -82,7 +82,7 @@ bool CAutoStation::EventProcess(const Event &event) Math::Matrix* mat; Math::Vector pos, ppos, speed; Math::Point dim; - CObject* vehicule; + CObject* vehicle; CObject* power; Gfx::TerrainRes res; float big, energy, used, add, freq; @@ -133,10 +133,10 @@ bool CAutoStation::EventProcess(const Event &event) freq = 1.0f; if ( big > 0.0f ) { - vehicule = SearchVehicle(); - if ( vehicule != 0 ) + vehicle = SearchVehicle(); + if ( vehicle != 0 ) { - power = vehicule->GetPower(); + power = vehicle->GetPower(); if ( power != 0 && power->GetCapacity() == 1.0f ) { energy = power->GetEnergy(); @@ -149,7 +149,7 @@ bool CAutoStation::EventProcess(const Event &event) big -= add/4.0f; // discharge the large battery } - power = vehicule->GetFret(); + power = vehicle->GetFret(); if ( power != 0 && power->GetType() == OBJECT_POWER ) { energy = power->GetEnergy(); @@ -368,4 +368,3 @@ void CAutoStation::UpdateInterface(float rTime) } } - diff --git a/src/object/auto/autotower.cpp b/src/object/auto/autotower.cpp index e3b06cf..17a41f4 100644 --- a/src/object/auto/autotower.cpp +++ b/src/object/auto/autotower.cpp @@ -397,7 +397,7 @@ void CAutoTower::FireStopUpdate(float progress, bool bLightOn) pos.y = 18.0f; pos.z = listpos[i*2+1]; pos = Transform(*mat, pos); - + m_partiStop[i] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISELR, 1.0f, 0.0f, 0.0f); @@ -544,4 +544,3 @@ bool CAutoTower::Read(char *line) return true; } - diff --git a/src/object/brain.cpp b/src/object/brain.cpp index fa3e425..9e5149e 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -1309,14 +1309,17 @@ bool CBrain::CreateInterface(bool bSelect) type == OBJECT_ANT || type == OBJECT_SPIDER || type == OBJECT_BEE || - type == OBJECT_WORM ) // vehicle? + type == OBJECT_WORM || + type == OBJECT_CONTROLLER) // vehicle? { - if (!(m_main->GetRetroMode())) { + if (!(m_main->GetRetroMode())) + { ddim.x = dim.x*5.1f; - ddim.y = dim.y*2.0f; + ddim.y = dim.y*2.0f; // default => 2 pos.x = ox+sx*0.0f; pos.y = oy+sy*0.0f; - pw->CreateList(pos, ddim, -1, EVENT_OBJECT_PROGLIST, 1.10f); + + pw->CreateList(pos, ddim, -1, EVENT_OBJECT_PROGLIST, -1.10f); UpdateScript(pw); pos.x = ox+sx*5.2f; @@ -1333,7 +1336,8 @@ bool CBrain::CreateInterface(bool bSelect) type == OBJECT_MOBILEfi || type == OBJECT_MOBILEfs || type == OBJECT_MOBILEft || - type == OBJECT_BEE ) // driving? + type == OBJECT_BEE || + type == OBJECT_CONTROLLER) // driving? { pos.x = ox+sx*6.4f; pos.y = oy+sy*0; @@ -1345,8 +1349,9 @@ bool CBrain::CreateInterface(bool bSelect) pb = pw->CreateButton(pos, dim, 28, EVENT_OBJECT_GASUP); pb->SetImmediat(true); - if ( type != OBJECT_HUMAN || - m_object->GetOption() != 2 ) + if ( (type != OBJECT_HUMAN && + type != OBJECT_CONTROLLER) || + m_object->GetOption() != 2 ) { pos.x = ox+sx*15.3f; pos.y = oy+sy*0; @@ -2056,7 +2061,7 @@ void CBrain::UpdateInterface(float rTime) pc->SetState(Ui::STATE_VISIBLE, m_main->GetShowMap()); } - pb = (Ui::CButton*)pw->SearchControl(EVENT_OBJECT_REC); + pb = static_cast<Ui::CButton*>(pw->SearchControl(EVENT_OBJECT_REC)); if ( pb != 0 ) { if ( m_bTraceRecord && Math::Mod(m_time, 0.4f) >= 0.2f ) @@ -2304,7 +2309,8 @@ void CBrain::UpdateInterface() type == OBJECT_ANT || type == OBJECT_SPIDER || type == OBJECT_BEE || - type == OBJECT_WORM ) // vehicle? + type == OBJECT_WORM || + type == OBJECT_CONTROLLER) // vehicle? { bRun = false; if ( m_script[m_selScript] != 0 ) @@ -2481,7 +2487,7 @@ void CBrain::UpdateScript(Ui::CWindow *pw) } } - pl->SetName(i, name); + pl->SetItemName(i, name); } if ( !bSoluce ) @@ -2715,6 +2721,23 @@ bool CBrain::ReadSoluce(char* filename) return true; } +// Load a script from text buffer. + +bool CBrain::SendProgram(int rank, const char* buffer) +{ + if ( m_script[rank] == 0 ) + { + m_script[rank] = new CScript(m_object, &m_secondaryTask); + } + + if ( m_script[rank]->SendScript(buffer) ) return true; + + delete m_script[rank]; + m_script[rank] = 0; + + return false; +} + // Load a script with a text file. bool CBrain::ReadProgram(int rank, const char* filename) diff --git a/src/object/brain.h b/src/object/brain.h index eba8004..dcf07a4 100644 --- a/src/object/brain.h +++ b/src/object/brain.h @@ -52,7 +52,7 @@ class CTerrain; class CWater; class CCamera; class CParticle; -} /* Gfx */ +} /* Gfx */ const int BRAINMAXSCRIPT = 10; @@ -114,6 +114,7 @@ public: char* GetScriptName(int rank); void SetSoluceName(char *name); char* GetSoluceName(); + bool SendProgram(int rank, const char* buffer); bool ReadSoluce(char* filename); bool ReadProgram(int rank, const char* filename); diff --git a/src/object/mainmovie.cpp b/src/object/mainmovie.cpp index 04c0d56..85abee2 100644 --- a/src/object/mainmovie.cpp +++ b/src/object/mainmovie.cpp @@ -228,4 +228,3 @@ MainMovieType CMainMovie::GetStopType() return m_stopType; } - diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp index 384d683..16e53aa 100644 --- a/src/object/motion/motionant.cpp +++ b/src/object/motion/motionant.cpp @@ -75,7 +75,7 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type, // Creates the main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); modelManager->AddModelReference("ant1.mod", false, rank); m_object->SetPosition(0, pos); @@ -425,7 +425,7 @@ bool CMotionAnt::EventFrame(const Event &event) { Math::Vector dir, pos, speed; Math::Point dim; - float s, a, prog, time; + float s, a, prog = 0.0f, time; float tSt[9], tNd[9]; int i, ii, st, nd, action; bool bStop; @@ -831,4 +831,3 @@ bool CMotionAnt::EventFrame(const Event &event) return true; } - diff --git a/src/object/motion/motionbee.cpp b/src/object/motion/motionbee.cpp index 8f69945..2a052b2 100644 --- a/src/object/motion/motionbee.cpp +++ b/src/object/motion/motionbee.cpp @@ -73,7 +73,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type, // Creates main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); modelManager->AddModelReference("bee1.mod", false, rank); m_object->SetPosition(0, pos); @@ -406,7 +406,7 @@ bool CMotionBee::EventProcess(const Event &event) bool CMotionBee::EventFrame(const Event &event) { Math::Vector dir; - float s, a, prog; + float s, a, prog = 0.0f; int action, i, st, nd; bool bStop; @@ -610,4 +610,3 @@ bool CMotionBee::EventFrame(const Event &event) return true; } - diff --git a/src/object/motion/motiondummy.cpp b/src/object/motion/motiondummy.cpp new file mode 100644 index 0000000..86e389e --- /dev/null +++ b/src/object/motion/motiondummy.cpp @@ -0,0 +1,85 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2013 Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + + +#include "object/motion/motiondummy.h" +#include "physics/physics.h" +#include "graphics/engine/modelmanager.h" + +#include <stdio.h> +#include <string.h> + +// Object's constructor. + +CMotionDummy::CMotionDummy(CObject* object) : CMotion(object) +{ +} + +// Object's destructor. + +CMotionDummy::~CMotionDummy() +{ +} + + +// Removes an object. + +void CMotionDummy::DeleteObject(bool bAll) +{ +} + + +// Creates a Dummy traveling any lands on the ground. + +bool CMotionDummy::Create(Math::Vector pos, float angle, ObjectType type, + float power) +{ + m_object->SetType(type); + + // Creates the main base. + int rank = m_engine->CreateObject(); + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object + m_object->SetObjectRank(0, rank); + + // Movement + m_physics->SetType(TYPE_FLYING); + + m_physics->SetLinMotionX(MO_ADVSPEED, 50.0f); + m_physics->SetLinMotionX(MO_RECSPEED, 50.0f); + m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f); + m_physics->SetLinMotionX(MO_RECACCEL, 20.0f); + m_physics->SetLinMotionX(MO_STOACCEL, 20.0f); + m_physics->SetLinMotionX(MO_TERSLIDE, 0.0f); + m_physics->SetLinMotionZ(MO_TERSLIDE, 0.0f); + m_physics->SetLinMotionX(MO_TERFORCE, 0.0f); + m_physics->SetLinMotionZ(MO_TERFORCE, 0.0f); + m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f); + m_physics->SetLinMotionY(MO_ADVSPEED, 60.0f); + m_physics->SetLinMotionY(MO_RECSPEED, 60.0f); + m_physics->SetLinMotionY(MO_ADVACCEL, 20.0f); + m_physics->SetLinMotionY(MO_RECACCEL, 50.0f); + m_physics->SetLinMotionY(MO_STOACCEL, 50.0f); + + m_physics->SetCirMotionY(MO_ADVSPEED, 0.4f*Math::PI); + m_physics->SetCirMotionY(MO_RECSPEED, 0.4f*Math::PI); + m_physics->SetCirMotionY(MO_ADVACCEL, 2.0f); + m_physics->SetCirMotionY(MO_RECACCEL, 2.0f); + m_physics->SetCirMotionY(MO_STOACCEL, 2.0f); + + return true; +} + diff --git a/src/object/motion/motiondummy.h b/src/object/motion/motiondummy.h new file mode 100644 index 0000000..2cb3a88 --- /dev/null +++ b/src/object/motion/motiondummy.h @@ -0,0 +1,34 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2013 Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +// motiondummy.h + +#pragma once + + +#include "object/motion/motion.h" + +class CMotionDummy : public CMotion +{ +public: + CMotionDummy(CObject* object); + ~CMotionDummy(); + + void DeleteObject(bool bAll=false); + bool Create(Math::Vector pos, float angle, ObjectType type, float power); +}; + diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp index dc5ff34..edee260 100644 --- a/src/object/motion/motionhuman.cpp +++ b/src/object/motion/motionhuman.cpp @@ -107,7 +107,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, if ( m_main->GetGamerOnlyHead() ) { rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); face = m_main->GetGamerFace(); sprintf(filename, "human2h%d.mod", face+1); @@ -134,7 +134,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type, // Creates the main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); if (option == 0) // head in helmet? @@ -677,7 +677,7 @@ bool CMotionHuman::EventFrame(const Event &event) float s, a, prog, rTime[2], lTime[2], time, rot, hr, hl; float al, ar, af; float tSt[9], tNd[9]; - float aa, bb, shield, deadFactor, level; + float aa, bb, shield, deadFactor = 0.0f, level; int i, ii, st, nd, action, legAction, armAction; bool bOnBoard, bSwim; @@ -1617,18 +1617,18 @@ bool CMotionHuman::EventFrame(const Event &event) legAction == MH_MARCHTAKE ) { Sound sound[2]; - float speed, synchro, volume[2], freq[2], hard, level; + float synchro, volume[2], freq[2], hard; - speed = m_physics->GetLinMotionX(MO_REASPEED); + float speedX = m_physics->GetLinMotionX(MO_REASPEED); if ( m_object->GetFret() == 0 ) { - if ( speed > 0.0f ) synchro = 0.21f; // synchro forward + if ( speedX > 0.0f ) synchro = 0.21f; // synchro forward else synchro = 0.29f; // synchro backward } else { - if ( speed > 0.0f ) synchro = 0.15f; // synchro forward + if ( speedX > 0.0f ) synchro = 0.15f; // synchro forward else synchro = 0.35f; // synchro backward } time = rTime[1]+synchro; @@ -1735,4 +1735,3 @@ void CMotionHuman::StopDisplayPerso() m_bDisplayPerso = false; } - diff --git a/src/object/motion/motionmother.cpp b/src/object/motion/motionmother.cpp index 573a2e4..03e7c21 100644 --- a/src/object/motion/motionmother.cpp +++ b/src/object/motion/motionmother.cpp @@ -74,7 +74,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type, // Creates main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); modelManager->AddModelReference("mother1.mod", false, rank); m_object->SetPosition(0, pos); @@ -493,4 +493,3 @@ bool CMotionMother::EventFrame(const Event &event) return true; } - diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp index 59bc6e0..8d339b6 100644 --- a/src/object/motion/motionspider.cpp +++ b/src/object/motion/motionspider.cpp @@ -101,7 +101,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type, // Creates the main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); // This is an "empty" object, without triangles m_object->SetPosition(0, pos); @@ -363,7 +363,7 @@ bool CMotionSpider::EventFrame(const Event &event) { Math::Vector dir, pos, speed; Math::Point dim; - float s, a, prog, time; + float s, a, prog = 0.0f, time; float tSt[12], tNd[12]; int i, ii, st, nd, action; bool bStop; @@ -743,4 +743,3 @@ bool CMotionSpider::EventFrame(const Event &event) return true; } - diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index ddb1867..b4ed89d 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -88,7 +88,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type, // Creates the head. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); modelManager->AddModelReference("toto1.mod", false, rank); m_object->SetPosition(0, pos); @@ -853,4 +853,3 @@ void CMotionToto::SetLinkType(ObjectType type) m_type = type; } - diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp index 44b8fdd..a67ae24 100644 --- a/src/object/motion/motionvehicle.cpp +++ b/src/object/motion/motionvehicle.cpp @@ -102,7 +102,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, // Creates the main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); if (type == OBJECT_MOBILEfa || @@ -931,6 +931,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type, rank = m_engine->CreateObject(); m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); pPower->SetObjectRank(0, rank); + pPower->CreateShadowCircle(1.5f, 1.0f); //create a shadow for battary if ( power <= 1.0f ) modelManager->AddModelCopy("power.mod", false, rank); else modelManager->AddModelCopy("atomic.mod", false, rank); @@ -1649,7 +1650,7 @@ bool CMotionVehicle::EventFrameFly(const Event &event) bool CMotionVehicle::EventFrameInsect(const Event &event) { Math::Vector dir; - float s, a, prog, time; + float s, a, prog = 0.0f, time; int i, st, nd, action; bool bStop, bOnBoard; @@ -1943,4 +1944,3 @@ void CMotionVehicle::SetTraceWidth(float width) m_traceWidth = width; } - diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp index ee555a8..80bf7fc 100644 --- a/src/object/motion/motionworm.cpp +++ b/src/object/motion/motionworm.cpp @@ -89,9 +89,9 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type, // Creates the main base. rank = m_engine->CreateObject(); - m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object + m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICLE); // this is a moving object m_object->SetObjectRank(0, rank); - // This is an "empty" object, without triangles + // This is an "empty" object, without triangles m_object->SetPosition(0, pos); m_object->SetAngleY(0, angle); @@ -356,4 +356,3 @@ bool CMotionWorm::EventFrame(const Event &event) return true; } - diff --git a/src/object/object.cpp b/src/object/object.cpp index 23a757a..4cf0688 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -64,6 +64,7 @@ #include "object/motion/motion.h" #include "object/motion/motionant.h" #include "object/motion/motionbee.h" +#include "object/motion/motiondummy.h" #include "object/motion/motionhuman.h" #include "object/motion/motionmother.h" #include "object/motion/motionspider.h" @@ -71,6 +72,7 @@ #include "object/motion/motionvehicle.h" #include "object/motion/motionworm.h" #include "object/robotmain.h" +#include "object/objman.h" #include "physics/physics.h" @@ -202,6 +204,10 @@ void uObject(CBotVar* botThis, void* user) fret = object->GetFret(); if ( fret == 0 ) pVar->SetPointer(0); else pVar->SetPointer(fret->GetBotVar()); + + pVar = pVar->GetNext(); // "id" + value = object->GetID(); + pVar->SetValInt(value); } @@ -337,6 +343,8 @@ CObject::CObject() m_botVar = CBotVar::Create("", CBotTypResult(CBotTypClass, "object")); m_botVar->SetUserPtr(this); m_botVar->SetIdent(m_id); + + CObjectManager::GetInstancePointer()->AddInstance(this); } // Object's destructor. @@ -360,6 +368,7 @@ CObject::~CObject() m_auto = nullptr; CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_OBJECT, this); + CObjectManager::GetInstancePointer()->DeleteInstance(this); m_app = nullptr; } @@ -592,7 +601,7 @@ bool CObject::ExploObject(ExploType type, float force, float decay) } } - if ( EXPLO_BOUM ) + if ( type == EXPLO_BOUM ) { if ( m_shotTime < 0.5f ) return false; m_shotTime = 0.0f; @@ -2137,6 +2146,10 @@ bool CObject::CreateVehicle(Math::Vector pos, float angle, ObjectType type, { m_motion = new CMotionHuman(this); } + else if ( type == OBJECT_CONTROLLER ) + { + m_motion = new CMotionDummy(this); //dummy object + } else { m_motion = new CMotionVehicle(this); @@ -7314,7 +7327,7 @@ bool CObject::GetTraceDown() CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Debug("GetTraceDown() invalid m_motion class!\n"); + GetLogger()->Trace("GetTraceDown() invalid m_motion class!\n"); return false; } return mv->GetTraceDown(); @@ -7326,7 +7339,7 @@ void CObject::SetTraceDown(bool bDown) CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Debug("SetTraceDown() invalid m_motion class!\n"); + GetLogger()->Trace("SetTraceDown() invalid m_motion class!\n"); return; } mv->SetTraceDown(bDown); @@ -7338,7 +7351,7 @@ int CObject::GetTraceColor() CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Debug("GetTraceColor() invalid m_motion class!\n"); + GetLogger()->Trace("GetTraceColor() invalid m_motion class!\n"); return 0; } return mv->GetTraceColor(); @@ -7350,7 +7363,7 @@ void CObject::SetTraceColor(int color) CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Debug("SetTraceColor() invalid m_motion class!\n"); + GetLogger()->Trace("SetTraceColor() invalid m_motion class!\n"); return; } mv->SetTraceColor(color); @@ -7362,7 +7375,7 @@ float CObject::GetTraceWidth() CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Debug("GetTraceWidth() invalid m_motion class!\n"); + GetLogger()->Trace("GetTraceWidth() invalid m_motion class!\n"); return 0.0f; } return mv->GetTraceWidth(); @@ -7374,10 +7387,9 @@ void CObject::SetTraceWidth(float width) CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Debug("SetTraceWidth() invalid m_motion class!\n"); + GetLogger()->Trace("SetTraceWidth() invalid m_motion class!\n"); return; } mv->SetTraceWidth(width); } - diff --git a/src/object/object.h b/src/object/object.h index 4d8cc02..25ea708 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -156,6 +156,7 @@ enum ObjectType OBJECT_MOBILEsa = 210, //! < submarine OBJECT_MOBILEtg = 211, //! < training target OBJECT_MOBILEdr = 212, //! < robot drawing + OBJECT_CONTROLLER = 213, //! < mission controller OBJECT_WAYPOINT = 250, //! < waypoint OBJECT_FLAGb = 260, //! < blue flag OBJECT_FLAGr = 261, //! < red flag diff --git a/src/object/objman.cpp b/src/object/objman.cpp new file mode 100644 index 0000000..e4102b8 --- /dev/null +++ b/src/object/objman.cpp @@ -0,0 +1,389 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + + +#include "object/object.h" +#include "object/auto/auto.h" + +#include "object/objman.h" + + +template<> CObjectManager* CSingleton<CObjectManager>::m_instance = nullptr; + + +CObjectManager::CObjectManager() +{ + for (int i = 0; i < MAX_OBJECTS; i++) + { + m_table[i] = nullptr; + } + usedCount = 0; +} + +CObjectManager::~CObjectManager() +{ +} + +bool CObjectManager::AddInstance(CObject* instance) +{ + if (usedCount >= MAX_OBJECTS) return false; + + m_table[instance->GetID()] = instance; + usedCount++; + return true; +} + +bool CObjectManager::DeleteInstance(CObject* instance) +{ + for (int i = 0; i < usedCount; i++) + { + if (m_table[i] == instance) + m_table[i] = nullptr; + } + + return true; +} + +CObject* CObjectManager::SearchInstance(int id) +{ + if (id >= MAX_OBJECTS) return nullptr; + return m_table[id]; +} + +CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, float zoom, float height, + ObjectType type, float power, + bool trainer, bool toy, + int option) +{ + CObject* object = nullptr; + + if ( type == OBJECT_NULL ) return nullptr; + + if ( type == OBJECT_HUMAN || + type == OBJECT_TECH ) + { + trainer = false; // necessarily + } + + if ( type == OBJECT_PORTICO || + type == OBJECT_BASE || + type == OBJECT_DERRICK || + type == OBJECT_FACTORY || + type == OBJECT_STATION || + type == OBJECT_CONVERT || + type == OBJECT_REPAIR || + type == OBJECT_DESTROYER|| + type == OBJECT_TOWER || + type == OBJECT_NEST || + type == OBJECT_RESEARCH || + type == OBJECT_RADAR || + type == OBJECT_INFO || + type == OBJECT_ENERGY || + type == OBJECT_LABO || + type == OBJECT_NUCLEAR || + type == OBJECT_PARA || + type == OBJECT_SAFE || + type == OBJECT_HUSTON || + type == OBJECT_TARGET1 || + type == OBJECT_TARGET2 || + type == OBJECT_START || + type == OBJECT_END ) + { + object = new CObject(); + object->CreateBuilding(pos, angle, height, type, power); + + CAuto* automat = object->GetAuto(); + if (automat != nullptr) + { + automat->Init(); + } + } + else + if ( type == OBJECT_FRET || + type == OBJECT_STONE || + type == OBJECT_URANIUM || + type == OBJECT_METAL || + type == OBJECT_POWER || + type == OBJECT_ATOMIC || + type == OBJECT_BULLET || + type == OBJECT_BBOX || + type == OBJECT_KEYa || + type == OBJECT_KEYb || + type == OBJECT_KEYc || + type == OBJECT_KEYd || + type == OBJECT_TNT || + type == OBJECT_SCRAP1 || + type == OBJECT_SCRAP2 || + type == OBJECT_SCRAP3 || + type == OBJECT_SCRAP4 || + type == OBJECT_SCRAP5 || + type == OBJECT_BOMB || + type == OBJECT_WAYPOINT || + type == OBJECT_SHOW || + type == OBJECT_WINFIRE || + type == OBJECT_BAG || + type == OBJECT_MARKPOWER || + type == OBJECT_MARKSTONE || + type == OBJECT_MARKURANIUM || + type == OBJECT_MARKKEYa || + type == OBJECT_MARKKEYb || + type == OBJECT_MARKKEYc || + type == OBJECT_MARKKEYd || + type == OBJECT_EGG ) + { + object = new CObject(); + object->CreateResource(pos, angle, type, power); + } + else + if ( type == OBJECT_FLAGb || + type == OBJECT_FLAGr || + type == OBJECT_FLAGg || + type == OBJECT_FLAGy || + type == OBJECT_FLAGv ) + { + object = new CObject(); + object->CreateFlag(pos, angle, type); + } + else + if ( type == OBJECT_BARRIER0 || + type == OBJECT_BARRIER1 || + type == OBJECT_BARRIER2 || + type == OBJECT_BARRIER3 || + type == OBJECT_BARRIER4 ) + { + object = new CObject(); + object->CreateBarrier(pos, angle, height, type); + } + else + if ( type == OBJECT_PLANT0 || + type == OBJECT_PLANT1 || + type == OBJECT_PLANT2 || + type == OBJECT_PLANT3 || + type == OBJECT_PLANT4 || + type == OBJECT_PLANT5 || + type == OBJECT_PLANT6 || + type == OBJECT_PLANT7 || + type == OBJECT_PLANT8 || + type == OBJECT_PLANT9 || + type == OBJECT_PLANT10 || + type == OBJECT_PLANT11 || + type == OBJECT_PLANT12 || + type == OBJECT_PLANT13 || + type == OBJECT_PLANT14 || + type == OBJECT_PLANT15 || + type == OBJECT_PLANT16 || + type == OBJECT_PLANT17 || + type == OBJECT_PLANT18 || + type == OBJECT_PLANT19 || + type == OBJECT_TREE0 || + type == OBJECT_TREE1 || + type == OBJECT_TREE2 || + type == OBJECT_TREE3 || + type == OBJECT_TREE4 || + type == OBJECT_TREE5 || + type == OBJECT_TREE6 || + type == OBJECT_TREE7 || + type == OBJECT_TREE8 || + type == OBJECT_TREE9 ) + { + object = new CObject(); + object->CreatePlant(pos, angle, height, type); + } + else + if ( type == OBJECT_MUSHROOM0 || + type == OBJECT_MUSHROOM1 || + type == OBJECT_MUSHROOM2 || + type == OBJECT_MUSHROOM3 || + type == OBJECT_MUSHROOM4 || + type == OBJECT_MUSHROOM5 || + type == OBJECT_MUSHROOM6 || + type == OBJECT_MUSHROOM7 || + type == OBJECT_MUSHROOM8 || + type == OBJECT_MUSHROOM9 ) + { + object = new CObject(); + object->CreateMushroom(pos, angle, height, type); + } + else + if ( type == OBJECT_TEEN0 || + type == OBJECT_TEEN1 || + type == OBJECT_TEEN2 || + type == OBJECT_TEEN3 || + type == OBJECT_TEEN4 || + type == OBJECT_TEEN5 || + type == OBJECT_TEEN6 || + type == OBJECT_TEEN7 || + type == OBJECT_TEEN8 || + type == OBJECT_TEEN9 || + type == OBJECT_TEEN10 || + type == OBJECT_TEEN11 || + type == OBJECT_TEEN12 || + type == OBJECT_TEEN13 || + type == OBJECT_TEEN14 || + type == OBJECT_TEEN15 || + type == OBJECT_TEEN16 || + type == OBJECT_TEEN17 || + type == OBJECT_TEEN18 || + type == OBJECT_TEEN19 || + type == OBJECT_TEEN20 || + type == OBJECT_TEEN21 || + type == OBJECT_TEEN22 || + type == OBJECT_TEEN23 || + type == OBJECT_TEEN24 || + type == OBJECT_TEEN25 || + type == OBJECT_TEEN26 || + type == OBJECT_TEEN27 || + type == OBJECT_TEEN28 || + type == OBJECT_TEEN29 || + type == OBJECT_TEEN30 || + type == OBJECT_TEEN31 || + type == OBJECT_TEEN32 || + type == OBJECT_TEEN33 || + type == OBJECT_TEEN34 || + type == OBJECT_TEEN35 || + type == OBJECT_TEEN36 || + type == OBJECT_TEEN37 || + type == OBJECT_TEEN38 || + type == OBJECT_TEEN39 || + type == OBJECT_TEEN40 || + type == OBJECT_TEEN41 || + type == OBJECT_TEEN42 || + type == OBJECT_TEEN43 || + type == OBJECT_TEEN44 || + type == OBJECT_TEEN45 || + type == OBJECT_TEEN46 || + type == OBJECT_TEEN47 || + type == OBJECT_TEEN48 || + type == OBJECT_TEEN49 ) + { + object = new CObject(); + object->SetOption(option); + object->CreateTeen(pos, angle, zoom, height, type); + } + else + if ( type == OBJECT_QUARTZ0 || + type == OBJECT_QUARTZ1 || + type == OBJECT_QUARTZ2 || + type == OBJECT_QUARTZ3 || + type == OBJECT_QUARTZ4 || + type == OBJECT_QUARTZ5 || + type == OBJECT_QUARTZ6 || + type == OBJECT_QUARTZ7 || + type == OBJECT_QUARTZ8 || + type == OBJECT_QUARTZ9 ) + { + object = new CObject(); + object->CreateQuartz(pos, angle, height, type); + } + else + if ( type == OBJECT_ROOT0 || + type == OBJECT_ROOT1 || + type == OBJECT_ROOT2 || + type == OBJECT_ROOT3 || + type == OBJECT_ROOT4 || + type == OBJECT_ROOT5 || + type == OBJECT_ROOT6 || + type == OBJECT_ROOT7 || + type == OBJECT_ROOT8 || + type == OBJECT_ROOT9 ) + { + object = new CObject(); + object->CreateRoot(pos, angle, height, type); + } + else + if ( type == OBJECT_HOME1 ) + { + object = new CObject(); + object->CreateHome(pos, angle, height, type); + } + else + if ( type == OBJECT_RUINmobilew1 || + type == OBJECT_RUINmobilew2 || + type == OBJECT_RUINmobilet1 || + type == OBJECT_RUINmobilet2 || + type == OBJECT_RUINmobiler1 || + type == OBJECT_RUINmobiler2 || + type == OBJECT_RUINfactory || + type == OBJECT_RUINdoor || + type == OBJECT_RUINsupport || + type == OBJECT_RUINradar || + type == OBJECT_RUINconvert || + type == OBJECT_RUINbase || + type == OBJECT_RUINhead ) + { + object = new CObject(); + object->CreateRuin(pos, angle, height, type); + } + else + if ( type == OBJECT_APOLLO1 || + type == OBJECT_APOLLO3 || + type == OBJECT_APOLLO4 || + type == OBJECT_APOLLO5 ) + { + object = new CObject(); + object->CreateApollo(pos, angle, type); + } + else + if ( type == OBJECT_MOTHER || + type == OBJECT_ANT || + type == OBJECT_SPIDER || + type == OBJECT_BEE || + type == OBJECT_WORM ) + { + object = new CObject(); + object->CreateInsect(pos, angle, type); // no eggs + } + else + if ( type == OBJECT_HUMAN || + type == OBJECT_TECH || + type == OBJECT_TOTO || + 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_APOLLO2 ) + { + object = new CObject(); + object->SetOption(option); + object->CreateVehicle(pos, angle, type, power, trainer, toy); + } + + return object; +} + diff --git a/src/object/objman.h b/src/object/objman.h new file mode 100644 index 0000000..3087383 --- /dev/null +++ b/src/object/objman.h @@ -0,0 +1,53 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +/** + * \file object/objman.h + * \brief Instance manager for objects + */ + +#pragma once + +#include "object/object.h" + +#include "common/singleton.h" + +const int MAX_OBJECTS = 500; + +/** + * \class ObjectManager + * \brief Manager for objects + */ +class CObjectManager : public CSingleton<CObjectManager> +{ +public: + CObjectManager(); + virtual ~CObjectManager(); + + //! Registers new object + bool AddInstance(CObject* instance); + //! Deletes the registered object + bool DeleteInstance(CObject* instance); + //! Seeks for an object + CObject* SearchInstance(int id); + //! Creates an object + CObject* CreateObject(Math::Vector pos, float angle, float zoom, float height, ObjectType type, float power, bool trainer, bool toy, int option); + +protected: + CObject* m_table[MAX_OBJECTS]; + int usedCount; +}; + diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index c1e4140..b58e5f8 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -34,7 +34,7 @@ #include "graphics/engine/engine.h" #include "graphics/engine/lightman.h" #include "graphics/engine/lightning.h" -#include "graphics/engine/modelfile.h" +#include "graphics/engine/modelmanager.h" #include "graphics/engine/particle.h" #include "graphics/engine/planet.h" #include "graphics/engine/pyro.h" @@ -79,6 +79,7 @@ #include "ui/slider.h" #include "ui/window.h" +#include <iomanip> template<> CRobotMain* CSingleton<CRobotMain>::m_instance = nullptr; @@ -602,11 +603,8 @@ bool rPoint(CBotVar* pThis, CBotVar* var, CBotVar* pResult, int& Exception) return true; // no interruption } - - - //! Constructor of robot application -CRobotMain::CRobotMain(CApplication* app) +CRobotMain::CRobotMain(CApplication* app, bool loadProfile) { m_app = app; @@ -643,7 +641,7 @@ CRobotMain::CRobotMain(CApplication* app) m_visitLast = EVENT_NULL; m_visitObject = 0; m_visitArrow = 0; - m_audioTrack = 0; + m_audioTrack = ""; m_audioRepeat = true; m_delayWriteMessage = 0; m_selectObject = 0; @@ -656,6 +654,7 @@ CRobotMain::CRobotMain(CApplication* app) m_terrainCreate = false; m_version = 1; + m_controller = nullptr; m_retroStyle = false; m_immediatSatCom = false; m_beginSatCom = false; @@ -670,11 +669,13 @@ CRobotMain::CRobotMain(CApplication* app) m_showPos = false; m_selectInsect = false; m_showSoluce = false; - #ifdef NDEBUG - m_showAll = false; - #else + + #if DEV_BUILD m_showAll = true; // for development + #else + m_showAll = false; #endif + m_cheatRadar = false; m_fixScene = false; m_trainerPilot = false; @@ -705,27 +706,31 @@ CRobotMain::CRobotMain(CApplication* app) m_windowPos = Math::Point(0.15f, 0.17f); m_windowDim = Math::Point(0.70f, 0.66f); - // TODO: profile - // float fValue; - // int iValue; + float fValue; + int iValue; - // if (GetLocalProfileFloat("Edit", "FontSize", fValue)) m_fontSize = fValue; - // if (GetLocalProfileFloat("Edit", "WindowPos.x", fValue)) m_windowPos.x = fValue; - // if (GetLocalProfileFloat("Edit", "WindowPos.y", fValue)) m_windowPos.y = fValue; - // if (GetLocalProfileFloat("Edit", "WindowDim.x", fValue)) m_windowDim.x = fValue; - // if (GetLocalProfileFloat("Edit", "WindowDim.y", fValue)) m_windowDim.y = fValue; + if (loadProfile) + { + if (GetProfile().GetLocalProfileFloat("Edit", "FontSize", fValue)) m_fontSize = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosX", fValue)) m_windowPos.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowPosY", fValue)) m_windowPos.y = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue; + } m_IOPublic = false; m_IODim = Math::Point(320.0f/640.0f, (121.0f+18.0f*8)/480.0f); m_IOPos.x = (1.0f-m_IODim.x)/2.0f; // in the middle m_IOPos.y = (1.0f-m_IODim.y)/2.0f; - /* TODO: profile - if (GetLocalProfileInt ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; - if (GetLocalProfileFloat("Edit", "IOPos.x", fValue)) m_IOPos.x = fValue; - if (GetLocalProfileFloat("Edit", "IOPos.y", fValue)) m_IOPos.y = fValue; - if (GetLocalProfileFloat("Edit", "IODim.x", fValue)) m_IODim.x = fValue; - if (GetLocalProfileFloat("Edit", "IODim.y", fValue)) m_IODim.y = fValue; */ + if (loadProfile) + { + if (GetProfile().GetLocalProfileInt ("Edit", "IOPublic", iValue)) m_IOPublic = iValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IOPosX", fValue)) m_IOPos.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IOPosY", fValue)) m_IOPos.y = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IODimX", fValue)) m_IODim.x = fValue; + if (GetProfile().GetLocalProfileFloat("Edit", "IODimY", fValue)) m_IODim.y = fValue; + } m_short->FlushShortcuts(); InitEye(); @@ -741,12 +746,11 @@ CRobotMain::CRobotMain(CApplication* app) g_researchEnable = 0; g_unit = UNIT; - m_gamerName[0] = 0; - /* TODO: profile - GetLocalProfileString("Gamer", "LastName", m_gamerName, 100); */ + m_gamerName = ""; + if (loadProfile) GetProfile().GetLocalProfileString("Gamer", "LastName", m_gamerName); SetGlobalGamerName(m_gamerName); ReadFreeParam(); - m_dialog->SetupRecall(); + if (loadProfile) m_dialog->SetupRecall(); for (int i = 0; i < MAXSHOWLIMIT; i++) { @@ -805,6 +809,48 @@ CRobotMain::CRobotMain(CApplication* app) CBotProgram::DefineNum("FilterOnlyLanding", FILTER_ONLYLANDING); CBotProgram::DefineNum("FilterOnlyFliying", FILTER_ONLYFLYING); + CBotProgram::DefineNum("ExploNone", 0); + CBotProgram::DefineNum("ExploBoum", EXPLO_BOUM); + CBotProgram::DefineNum("ExploBurn", EXPLO_BURN); + CBotProgram::DefineNum("ExploWater", EXPLO_WATER); + + CBotProgram::DefineNum("ResultNotEnded", ERR_MISSION_NOTERM); + CBotProgram::DefineNum("ResultLost", INFO_LOST); + CBotProgram::DefineNum("ResultLostQuick", INFO_LOSTq); + CBotProgram::DefineNum("ResultWin", ERR_OK); + + CBotProgram::DefineNum("BuildBotFactory", BUILD_FACTORY); + CBotProgram::DefineNum("BuildDerrick", BUILD_DERRICK); + CBotProgram::DefineNum("BuildConverter", BUILD_CONVERT); + CBotProgram::DefineNum("BuildRadarStation", BUILD_RADAR); + CBotProgram::DefineNum("BuildPowerPlant", BUILD_ENERGY); + CBotProgram::DefineNum("BuildNuclearPlant", BUILD_NUCLEAR); + CBotProgram::DefineNum("BuildPowerStation", BUILD_STATION); + CBotProgram::DefineNum("BuildRepairCenter", BUILD_REPAIR); + CBotProgram::DefineNum("BuildDefenseTower", BUILD_TOWER); + CBotProgram::DefineNum("BuildResearchCenter", BUILD_RESEARCH); + CBotProgram::DefineNum("BuildAutoLab", BUILD_LABO); + CBotProgram::DefineNum("BuildPowerCaptor", BUILD_PARA); + CBotProgram::DefineNum("BuildExchangePost", BUILD_INFO); + CBotProgram::DefineNum("BuildDestroyer", BUILD_DESTROYER); + CBotProgram::DefineNum("FlatGround", BUILD_GFLAT); + CBotProgram::DefineNum("UseFlags", BUILD_FLAG); + CBotProgram::DefineNum("ResearchTracked", RESEARCH_TANK); + CBotProgram::DefineNum("ResearchWinged", RESEARCH_FLY); + CBotProgram::DefineNum("ResearchShooter", RESEARCH_CANON); + CBotProgram::DefineNum("ResearchDefenseTower", RESEARCH_TOWER); + CBotProgram::DefineNum("ResearchNuclearPlant", RESEARCH_ATOMIC); + CBotProgram::DefineNum("ResearchThumper", RESEARCH_THUMP); + CBotProgram::DefineNum("ResearchShielder", RESEARCH_SHIELD); + CBotProgram::DefineNum("ResearchPhazerShooter", RESEARCH_PHAZER); + CBotProgram::DefineNum("ResearchLegged", RESEARCH_iPAW); + CBotProgram::DefineNum("ResearchOrgaShooter", RESEARCH_iGUN); + CBotProgram::DefineNum("ResearchRecycler", RESEARCH_RECYCLER); + CBotProgram::DefineNum("ResearchSubber", RESEARCH_SUBM); + CBotProgram::DefineNum("ResearchSniffer", RESEARCH_SNIFFER); + +//? CBotProgram:: + CBotProgram::DefineNum("PolskiPortalColobota", 1337); CBotClass* bc; @@ -831,6 +877,11 @@ CRobotMain::CRobotMain(CApplication* app) bc->AddItem("material", CBotTypResult(CBotTypInt), PR_READ); 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("research", CScript::rResearch, CScript::cClassOneFloat); + bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull); // Initializes the class FILE. InitClassFILE(); @@ -891,15 +942,32 @@ Ui::CDisplayText* CRobotMain::GetDisplayText() return m_displayText; } +void CRobotMain::LoadSceneOnStart(const std::string& name, int rank) +{ + // TODO: fix this ugly dependency :( + m_dialog->SetSceneName(name.c_str()); + m_dialog->SetSceneRank(rank); + ChangePhase(PHASE_LOADING); +} + //! Creates the file colobot.ini at the first time void CRobotMain::CreateIni() { - /* TODO: profile - int iValue; - // colobot.ini doesn't exist? - if (!GetLocalProfileInt("Setup", "TotoMode", iValue)) - m_dialog->SetupMemorize();*/ + m_dialog->SetupMemorize(); + + GetProfile().SetLocalProfileFloat("Edit", "FontSize", m_fontSize); + GetProfile().SetLocalProfileFloat("Edit", "WindowPosX", m_windowPos.x); + GetProfile().SetLocalProfileFloat("Edit", "WindowPosY", m_windowPos.y); + GetProfile().SetLocalProfileFloat("Edit", "WindowDimX", m_windowDim.x); + GetProfile().SetLocalProfileFloat("Edit", "WindowDimY", m_windowDim.y); + GetProfile().SetLocalProfileInt("Edit", "IOPublic", m_IOPublic); + GetProfile().SetLocalProfileFloat("Edit", "IOPosX", m_IOPos.x); + GetProfile().SetLocalProfileFloat("Edit", "IOPosY", m_IOPos.y); + GetProfile().SetLocalProfileFloat("Edit", "IODimX", m_IODim.x); + GetProfile().SetLocalProfileFloat("Edit", "IODimY", m_IODim.y); + + GetProfile().SaveCurrentDirectory(); } void CRobotMain::SetDefaultInputBindings() @@ -952,28 +1020,24 @@ void CRobotMain::SetDefaultInputBindings() void CRobotMain::SetInputBinding(InputSlot slot, InputBinding binding) { unsigned int index = static_cast<unsigned int>(slot); - assert(index >= 0 && index < INPUT_SLOT_MAX); m_inputBindings[index] = binding; } const InputBinding& CRobotMain::GetInputBinding(InputSlot slot) { unsigned int index = static_cast<unsigned int>(slot); - assert(index >= 0 && index < INPUT_SLOT_MAX); return m_inputBindings[index]; } void CRobotMain::SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding) { unsigned int index = static_cast<unsigned int>(slot); - assert(index >= 0 && index < JOY_AXIS_SLOT_MAX); m_joyAxisBindings[index] = binding; } const JoyAxisBinding& CRobotMain::GetJoyAxisBinding(JoyAxisSlot slot) { unsigned int index = static_cast<unsigned int>(slot); - assert(index >= 0 && index < JOY_AXIS_SLOT_MAX); return m_joyAxisBindings[index]; } @@ -1041,6 +1105,7 @@ void CRobotMain::ChangePhase(Phase phase) FlushDisplayInfo(); m_engine->SetRankView(0); m_engine->DeleteAllObjects(); + Gfx::CModelManager::GetInstancePointer()->DeleteAllModelCopies(); m_engine->SetWaterAddColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); m_engine->SetBackground(""); m_engine->SetBackForce(false); @@ -1137,6 +1202,8 @@ void CRobotMain::ChangePhase(Phase phase) if (m_mapImage) m_map->SetFixImage(m_mapFilename); + m_app->ResetTimeAfterLoading(); + /*Math::Point ddim; pos.x = 620.0f/640.0f; @@ -1225,7 +1292,7 @@ void CRobotMain::ChangePhase(Phase phase) ddim.x = dim.x*2; ddim.y = dim.y*2; m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK); m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); - + StartMusic(); } } @@ -1239,7 +1306,7 @@ void CRobotMain::ChangePhase(Phase phase) } //! Processes an event -bool CRobotMain::EventProcess(Event &event) +bool CRobotMain::ProcessEvent(Event &event) { /* Motion vector management */ @@ -1332,7 +1399,7 @@ bool CRobotMain::EventProcess(Event &event) // Management of the console. if (m_phase != PHASE_NAME && !m_movie->IsExist() && - !m_movieLock && !m_editLock && + !m_movieLock && !m_editLock && !m_engine->GetPause() && event.type == EVENT_KEY_DOWN && event.key.key == KEY(PAUSE)) // Pause ? { @@ -1474,7 +1541,7 @@ bool CRobotMain::EventProcess(Event &event) ChangePhase(PHASE_WIN); else if (m_lostDelay > 0.0f) ChangePhase(PHASE_LOST); - else + else if (!m_cmdEdit) m_dialog->StartAbort(); // do you want to leave? } if (event.key.key == KEY(PAUSE)) @@ -1760,12 +1827,47 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } + if (strcmp(cmd, "allbuildings") == 0) + { + g_build = -1; // all buildings are available + + m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); + return; + } + + if (strcmp(cmd, "all") == 0) + { + g_researchDone = -1; // all research are done + g_build = -1; // all buildings are available + + m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); + return; + } + if (strcmp(cmd, "nolimit") == 0) { m_terrain->SetFlyingMaxHeight(280.0f); return; } + if (strcmp(cmd, "controller") == 0) + { + if (m_controller != nullptr) + { + // Don't use SelectObject because it checks if the object is selectable + if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) + StopDisplayVisit(); + + CObject* prev = DeselectAll(); + if (prev != nullptr && prev != m_controller) + m_controller->AddDeselList(prev); + + SelectOneObject(m_controller, true); + m_short->UpdateShortcuts(); + } + return; + } + if (strcmp(cmd, "photo1") == 0) { m_freePhoto = !m_freePhoto; @@ -1834,7 +1936,7 @@ void CRobotMain::ExecuteCmd(char *cmd) object->SetRange(object->GetRange()*10.0f); return; } - + if (strcmp(cmd, "\155\157\157") == 0) { // VGhpcyBpcyBlYXN0ZXItZWdnIGFuZCBzbyBpdCBzaG91bGQgYmUgb2JmdXNjYXRlZCEgRG8gbm90 @@ -1901,7 +2003,14 @@ void CRobotMain::ExecuteCmd(char *cmd) if (strcmp(cmd, "debugmode") == 0) { - m_app->SetDebugMode(!m_app->GetDebugMode()); + if (m_app->IsDebugModeActive(DEBUG_ALL)) + { + m_app->SetDebugModeActive(DEBUG_ALL, false); + } + else + { + m_app->SetDebugModeActive(DEBUG_ALL, true); + } return; } @@ -1988,15 +2097,23 @@ void CRobotMain::ExecuteCmd(char *cmd) return; } - if (strcmp(cmd, "speed4") == 0) { + if (strcmp(cmd, "speed4") == 0) + { SetSpeed(4.0f); UpdateSpeedLabel(); - return; + return; } - if (strcmp(cmd, "speed8") == 0) { + if (strcmp(cmd, "speed8") == 0) + { SetSpeed(8.0f); UpdateSpeedLabel(); - return; + return; + } + if (strcmp(cmd, "crazy") == 0) + { + SetSpeed(1000.0f); + UpdateSpeedLabel(); + return; } if (m_phase == PHASE_SIMUL) @@ -2020,7 +2137,7 @@ void CRobotMain::FlushDisplayInfo() m_infoFilename[i][0] = 0; m_infoPos[i] = 0; } - strcpy(m_infoFilename[SATCOM_OBJECT], "help/") + m_app->GetLanguageChar() + std::string("/objects.txt"); + strcpy(m_infoFilename[SATCOM_OBJECT], "objects.txt"); m_infoIndex = 0; } @@ -2093,7 +2210,7 @@ void CRobotMain::StartDisplayInfo(const char *filename, int index) void CRobotMain::StopDisplayInfo() { if (m_cmdEdit) return; - + if (m_movieInfoIndex != -1) // film to read the SatCom? m_movie->Start(MM_SATCOMclose, 2.0f); @@ -2182,8 +2299,7 @@ float CRobotMain::GetGameTime() void CRobotMain::SetFontSize(float size) { m_fontSize = size; - /* TODO: profile - SetLocalProfileFloat("Edit", "FontSize", m_fontSize); */ + GetProfile().SetLocalProfileFloat("Edit", "FontSize", m_fontSize); } float CRobotMain::GetFontSize() @@ -2195,9 +2311,8 @@ float CRobotMain::GetFontSize() void CRobotMain::SetWindowPos(Math::Point pos) { m_windowPos = pos; - /* TODO: profile - SetLocalProfileFloat("Edit", "WindowPos.x", m_windowPos.x); - SetLocalProfileFloat("Edit", "WindowPos.y", m_windowPos.y); */ + GetProfile().SetLocalProfileFloat("Edit", "WindowPosX", m_windowPos.x); + GetProfile().SetLocalProfileFloat("Edit", "WindowPosY", m_windowPos.y); } Math::Point CRobotMain::GetWindowPos() @@ -2208,9 +2323,8 @@ Math::Point CRobotMain::GetWindowPos() void CRobotMain::SetWindowDim(Math::Point dim) { m_windowDim = dim; - /* TODO: profile - SetLocalProfileFloat("Edit", "WindowDim.x", m_windowDim.x); - SetLocalProfileFloat("Edit", "WindowDim.y", m_windowDim.y); */ + GetProfile().SetLocalProfileFloat("Edit", "WindowDimX", m_windowDim.x); + GetProfile().SetLocalProfileFloat("Edit", "WindowDimY", m_windowDim.y); } Math::Point CRobotMain::GetWindowDim() @@ -2223,8 +2337,7 @@ Math::Point CRobotMain::GetWindowDim() void CRobotMain::SetIOPublic(bool mode) { m_IOPublic = mode; - /* TODO: profile - SetLocalProfileInt("Edit", "IOPublic", m_IOPublic); */ + GetProfile().SetLocalProfileInt("Edit", "IOPublic", m_IOPublic); } bool CRobotMain::GetIOPublic() @@ -2235,9 +2348,8 @@ bool CRobotMain::GetIOPublic() void CRobotMain::SetIOPos(Math::Point pos) { m_IOPos = pos; - /* TODO: profile - SetLocalProfileFloat("Edit", "IOPos.x", m_IOPos.x); - SetLocalProfileFloat("Edit", "IOPos.y", m_IOPos.y); */ + GetProfile().SetLocalProfileFloat("Edit", "IOPosX", m_IOPos.x); + GetProfile().SetLocalProfileFloat("Edit", "IOPosY", m_IOPos.y); } Math::Point CRobotMain::GetIOPos() @@ -2248,9 +2360,8 @@ Math::Point CRobotMain::GetIOPos() void CRobotMain::SetIODim(Math::Point dim) { m_IODim = dim; - /* TODO: profile - SetLocalProfileFloat("Edit", "IODim.x", m_IODim.x); - SetLocalProfileFloat("Edit", "IODim.y", m_IODim.y); */ + GetProfile().SetLocalProfileFloat("Edit", "IODimX", m_IODim.x); + GetProfile().SetLocalProfileFloat("Edit", "IODimY", m_IODim.y); } Math::Point CRobotMain::GetIODim() @@ -2680,6 +2791,8 @@ CObject* CRobotMain::DetectObject(Math::Point pos) if (obj == nullptr) break; if (!obj->GetActif()) continue; + CObject* truck = obj->GetTruck(); + if (truck != nullptr) if (!truck->GetActif()) continue; if (obj->GetProxyActivate()) continue; CObject* target = nullptr; @@ -3446,6 +3559,7 @@ bool CRobotMain::EventFrame(const Event &event) { m_checkEndTime = m_time; CheckEndMission(true); + UpdateAudio(true); } if (m_winDelay > 0.0f && !m_editLock) @@ -3635,7 +3749,7 @@ void CRobotMain::Convert() } } - if (Cmd(line, "EndMissionTake")) + if (Cmd(line, "EndMissionTake") || Cmd(line, "AudioChange")) { char* p = strstr(line, "pos="); if (p != 0) @@ -3729,6 +3843,7 @@ void CRobotMain::ScenePerso() { DeleteAllObjects(); // removes all the current 3D Scene m_engine->DeleteAllObjects(); + Gfx::CModelManager::GetInstancePointer()->DeleteAllModelCopies(); m_terrain->FlushRelief(); // all flat m_terrain->FlushBuildingLevel(); m_terrain->FlushFlyingLimit(); @@ -3785,7 +3900,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) FlushDisplayInfo(); m_terrain->FlushMaterials(); - m_audioTrack = 0; + m_audioTrack = ""; m_audioRepeat = true; m_displayText->SetDelay(1.0f); m_displayText->SetEnable(true); @@ -3793,8 +3908,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_lockedSatCom = false; m_endingWinRank = 0; m_endingLostRank = 0; + m_audioChangeTotal = 0; m_endTakeTotal = 0; m_endTakeResearch = 0; + m_endTakeNever = false; m_endTakeWinDelay = 2.0f; m_endTakeLostDelay = 2.0f; m_obligatoryTotal = 0; @@ -3803,6 +3920,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_mapImage = false; m_mapFilename[0] = 0; + m_controller = nullptr; + m_colorRefBot.r = 10.0f/256.0f; m_colorRefBot.g = 166.0f/256.0f; m_colorRefBot.b = 254.0f/256.0f; // blue @@ -3840,6 +3959,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_version = 1; m_retroStyle = false; + + m_missionResult = ERR_MISSION_NOTERM; } char line[500]; @@ -3864,12 +3985,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rankGadget = 0; CObject* sel = 0; - std::string oldLocale; - char *locale = setlocale(LC_NUMERIC, nullptr); - if (locale != nullptr) - oldLocale = locale; + SetNumericLocale(); - setlocale(LC_NUMERIC, "C"); + /* + * NOTE: Moving frequently used lines to the top + * may speed up loading + */ while (fgets(line, 500, file) != NULL) { @@ -3890,18 +4011,34 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) // TODO: Fallback to an non-localized entry sprintf(op, "Title.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) + { OpString(line, "text", m_title); + continue; + } sprintf(op, "Resume.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) + { OpString(line, "text", m_resume); + continue; + } sprintf(op, "ScriptName.%c", m_app->GetLanguageChar()); if (Cmd(line, op) && !resetObject) + { OpString(line, "text", m_scriptName); + continue; + } + + if (Cmd(line, "Title")) continue; // Ignore + if (Cmd(line, "Resume")) continue; // Ignore + if (Cmd(line, "ScriptName")) continue; // Ignore if (Cmd(line, "ScriptFile") && !resetObject) + { OpString(line, "name", m_scriptFile); + continue; + } if (Cmd(line, "Instructions") && !resetObject) { @@ -3910,7 +4047,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str()); m_immediatSatCom = OpInt(line, "immediat", 0); - if(m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0); + if (m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0); + continue; } if (Cmd(line, "Satellite") && !resetObject) @@ -3918,6 +4056,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpString(line, "name", name); std::string path = m_app->GetDataFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_SAT], path.c_str()); + continue; } if (Cmd(line, "Loading") && !resetObject) @@ -3925,6 +4064,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpString(line, "name", name); std::string path = m_app->GetDataFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_LOADING], path.c_str()); + continue; } if (Cmd(line, "HelpFile") && !resetObject) @@ -3932,66 +4072,131 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpString(line, "name", name); std::string path = m_app->GetDataFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_PROG], path.c_str()); + continue; } if (Cmd(line, "SoluceFile") && !resetObject) { OpString(line, "name", name); std::string path = m_app->GetDataFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str()); + continue; } if (Cmd(line, "EndingFile") && !resetObject) { m_endingWinRank = OpInt(line, "win", 0); m_endingLostRank = OpInt(line, "lost", 0); + continue; } if (Cmd(line, "MessageDelay") && !resetObject) { m_displayText->SetDelay(OpFloat(line, "factor", 1.0f)); + continue; + } + + if (Cmd(line, "CacheAudio") && !resetObject && m_version >= 2) + { + OpString(line, "filename", name); + m_sound->CacheMusic(name); + continue; + } + + if (Cmd(line, "AudioChange") && !resetObject && m_version >= 2 && m_controller == nullptr) + { + int i = m_audioChangeTotal; + if (i < 10) + { + m_audioChange[i].pos = OpPos(line, "pos")*g_unit; + m_audioChange[i].dist = OpFloat(line, "dist", 8.0f)*g_unit; + m_audioChange[i].type = OpTypeObject(line, "type", OBJECT_NULL); + m_audioChange[i].min = OpInt(line, "min", 1); + m_audioChange[i].max = OpInt(line, "max", 9999); + m_audioChange[i].powermin = OpInt(line, "powermin", -1); + m_audioChange[i].powermax = OpInt(line, "powermax", 100); + OpString(line, "filename", m_audioChange[i].music); + m_audioChange[i].repeat = OpInt(line, "repeat", 1); + m_audioChange[i].changed = false; + m_sound->CacheMusic(m_audioChange[i].music); + m_audioChangeTotal ++; + } + continue; } - if (Cmd(line, "Audio") && !resetObject) + if (Cmd(line, "Audio") && !resetObject && m_controller == nullptr) { - m_audioTrack = OpInt(line, "track", 0); + if (m_version < 2) + { + int trackid = OpInt(line, "track", 0); + if (trackid != 0) + { + std::stringstream filenameStr; + filenameStr << "music" << std::setfill('0') << std::setw(3) << trackid << ".ogg"; + m_audioTrack = filenameStr.str(); + } + } + else + { + char trackname[100]; + OpString(line, "filename", trackname); + m_audioTrack = trackname; + } m_audioRepeat = OpInt(line, "repeat", 1); + if (m_audioTrack != "") m_sound->CacheMusic(m_audioTrack); + continue; } if (Cmd(line, "AmbientColor") && !resetObject) { m_engine->SetAmbientColor(OpColor(line, "air", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0); m_engine->SetAmbientColor(OpColor(line, "water", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1); + continue; } if (Cmd(line, "FogColor") && !resetObject) { m_engine->SetFogColor(OpColor(line, "air", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0); m_engine->SetFogColor(OpColor(line, "water", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1); + continue; } if (Cmd(line, "VehicleColor") && !resetObject) + { m_colorNewBot = OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)); + continue; + } if (Cmd(line, "InsectColor") && !resetObject) + { m_colorNewAlien = OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)); + continue; + } if (Cmd(line, "GreeneryColor") && !resetObject) + { m_colorNewGreen = OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)); + continue; + } if (Cmd(line, "DeepView") && !resetObject) { m_engine->SetDeepView(OpFloat(line, "air", 500.0f)*g_unit, 0, true); m_engine->SetDeepView(OpFloat(line, "water", 100.0f)*g_unit, 1, true); + continue; } if (Cmd(line, "FogStart") && !resetObject) { m_engine->SetFogStart(OpFloat(line, "air", 0.5f), 0); m_engine->SetFogStart(OpFloat(line, "water", 0.5f), 1); + continue; } if (Cmd(line, "SecondTexture") && !resetObject) + { m_engine->SetSecondTexture(OpInt(line, "rank", 1)); + continue; + } if (Cmd(line, "Background") && !resetObject) { @@ -4002,6 +4207,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpColor(line, "cloudUp", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)), OpColor(line, "cloudDown", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)), OpInt(line, "full", 0)); + continue; } if (Cmd(line, "Planet") && !resetObject) @@ -4022,12 +4228,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) Math::Point(uv2.x, uv2.z), strstr(name, "planet") != nullptr // TODO: add transparent op or modify textures ); + continue; } if (Cmd(line, "ForegroundName") && !resetObject) { OpString(line, "image", name); m_engine->SetForegroundName(name); + continue; } if (((m_version == 1 && Cmd(line, "Global")) || (m_version >= 2 && Cmd(line, "Mission"))) && !resetObject) @@ -4035,20 +4243,24 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) g_unit = OpFloat(line, "unitScale", 4.0f); m_engine->SetTracePrecision(OpFloat(line, "traceQuality", 1.0f)); m_shortCut = OpInt(line, "shortcut", 1); - if(m_version >= 2) { + if (m_version >= 2) + { m_retroStyle = OpInt(line, "retro", 0); - if(m_retroStyle) GetLogger()->Info("Retro mode enabled.\n"); + if (m_retroStyle) GetLogger()->Info("Retro mode enabled.\n"); } + continue; } if (Cmd(line, "TerrainGenerate") && !resetObject) { - if(m_terrainCreate) { + if (m_terrainCreate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainGenerate after TerrainCreate\n", filename, lineNum); continue; } - if(m_terrainInit) { + if (m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainGenerate after TerrainInit\n", filename, lineNum); continue; } @@ -4061,67 +4273,81 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpFloat(line, "hard", 0.5f)); m_terrainGenerate = true; + continue; } - if (Cmd(line, "TerrainWind") && !resetObject) { - if(m_terrainCreate) { + if (Cmd(line, "TerrainWind") && !resetObject) + { + if (m_terrainCreate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind after TerrainCreate\n", filename, lineNum); continue; } - if(m_terrainInit) { + if (m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind after TerrainInit\n", filename, lineNum); continue; } - if(!m_terrainGenerate) { + if (!m_terrainGenerate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind before TerrainGenerate\n", filename, lineNum); continue; } m_terrain->SetWind(OpPos(line, "speed")); + continue; } if (Cmd(line, "TerrainRelief") && !resetObject) { - if(m_terrainCreate) { + if (m_terrainCreate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief after TerrainCreate\n", filename, lineNum); continue; } - if(m_terrainInit) { + if (m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief after TerrainInit\n", filename, lineNum); continue; } - if(!m_terrainGenerate) { + if (!m_terrainGenerate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief before TerrainGenerate\n", filename, lineNum); continue; } OpString(line, "image", name); m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1)); + continue; } if (Cmd(line, "TerrainResource") && !resetObject) { - if(m_terrainCreate) { + if (m_terrainCreate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource after TerrainCreate\n", filename, lineNum); continue; } - if(m_terrainInit) { + if (m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource after TerrainInit\n", filename, lineNum); continue; } - if(!m_terrainGenerate) { + if (!m_terrainGenerate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource before TerrainGenerate\n", filename, lineNum); continue; } OpString(line, "image", name); m_terrain->LoadResources(name); + continue; } if (Cmd(line, "TerrainWater") && !resetObject) @@ -4141,10 +4367,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) pos); m_colorNewWater = OpColor(line, "color", m_colorRefWater); m_colorShiftWater = OpFloat(line, "brightness", 0.0f); + continue; } if (Cmd(line, "TerrainLava") && !resetObject) + { m_water->SetLava(OpInt(line, "mode", 0)); + continue; + } if (Cmd(line, "TerrainCloud") && !resetObject) { @@ -4153,6 +4383,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpColor(line, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), OpColor(line, "ambient", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)), OpFloat(line, "level", 500.0f) * g_unit); + continue; } if (Cmd(line, "TerrainBlitz") && !resetObject) @@ -4160,11 +4391,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_lightning->Create(OpFloat(line, "sleep", 0.0f), OpFloat(line, "delay", 3.0f), OpFloat(line, "magnetic", 50.0f) * g_unit); + continue; } if (Cmd(line, "TerrainInitTextures") && !resetObject) { - if(m_terrainInit) { + if (m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainInitTextures and TerrainInit at same time\n", filename, lineNum); continue; } @@ -4173,10 +4406,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) AddExt(name, ".png"); int dx = OpInt(line, "dx", 1); int dy = OpInt(line, "dy", 1); - char* op = SearchOp(line, "table"); + char* opTable = SearchOp(line, "table"); int tt[100]; for (int i = 0; i < dx*dy; i++) - tt[i] = GetInt(op, i, 0); + tt[i] = GetInt(opTable, i, 0); if (strstr(name, "%user%") != 0) CopyFileListToTemp(name, tt, dx*dy); @@ -4184,38 +4417,46 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_terrain->InitTextures(name, tt, dx, dy); m_terrainInitTextures = true; + continue; } - if (Cmd(line, "TerrainInit") && !resetObject) { - if(m_terrainInitTextures) { + if (Cmd(line, "TerrainInit") && !resetObject) + { + if (m_terrainInitTextures) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainInit and TerrainInitTextures at same time\n", filename, lineNum); continue; } m_terrain->InitMaterials(OpInt(line, "id", 1)); m_terrainInit = true; + continue; } if (Cmd(line, "TerrainMaterial") && !resetObject) { - if(m_terrainCreate) { + if (m_terrainCreate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial after TerrainCreate\n", filename, lineNum); continue; } - if(m_terrainInit) { + if (m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial after TerrainInit\n", filename, lineNum); continue; } - if(m_terrainInitTextures) { + if (m_terrainInitTextures) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial and TerrainInitTextures at same time\n", filename, lineNum); continue; } OpString(line, "image", name); AddExt(name, ".png"); - if (strstr(name, "%user%") != 0) { + if (strstr(name, "%user%") != 0) + { GetProfile().CopyFileToTemp(std::string(name)); } @@ -4228,36 +4469,41 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpInt(line, "down", 1), OpInt(line, "left", 1), OpFloat(line, "hard", 0.5f)); + continue; } if (Cmd(line, "TerrainLevel") && !resetObject) { - if(m_terrainCreate) { + if (m_terrainCreate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel after TerrainCreate\n", filename, lineNum); continue; } - if(!m_terrainInit) { + if (!m_terrainInit) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel before TerrainInit\n", filename, lineNum); continue; } - if(m_terrainInitTextures) { + if (m_terrainInitTextures) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel and TerrainInitTextures at same time\n", filename, lineNum); continue; } - if(!m_terrainGenerate) { + if (!m_terrainGenerate) + { GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel before TerrainGenerate\n", filename, lineNum); continue; } - char* op = SearchOp(line, "id"); + char* opId = SearchOp(line, "id"); int id[50]; int i = 0; while (i < 50) { - id[i] = GetInt(op, i, 0); + id[i] = GetInt(opId, i, 0); if (id[i++] == 0) break; } @@ -4268,11 +4514,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpFloat(line, "freq", 100.0f), OpPos(line, "center")*g_unit, OpFloat(line, "radius", 0.0f)*g_unit); + continue; } - if (Cmd(line, "TerrainCreate") && !resetObject) { + if (Cmd(line, "TerrainCreate") && !resetObject) + { m_terrain->CreateObjects(); m_terrainCreate = true; + continue; } if (Cmd(line, "BeginObject")) @@ -4284,11 +4533,35 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) sel = IOReadScene(read, stack); m_beginObject = true; + continue; + } + + if (Cmd(line, "MissionController") && read[0] == 0 && m_version >= 2) + { + /* TODO: ??? + if (!m_beginObject) + { + GetLogger()->Error("Syntax error in file '%s' (line %d): MissionController before BeginObject\n", filename, lineNum); + continue; + }*/ + + m_controller = CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, 1.0f, 0.0f, OBJECT_CONTROLLER, 100.0f, false, false, 0); + m_controller->SetMagnifyDamage(100.0f); + CBrain* brain = m_controller->GetBrain(); + if (brain != nullptr) + { + OpString(line, "script", name); + if (name[0] != 0) + brain->SetScriptName(0, name); + brain->SetScriptRun(0); + } + continue; } if (Cmd(line, "CreateObject") && read[0] == 0) { - if (!m_beginObject) { + if (!m_beginObject) + { GetLogger()->Error("Syntax error in file '%s' (line %d): CreateObject before BeginObject\n", filename, lineNum); continue; } @@ -4330,9 +4603,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } Math::Vector pos = OpPos(line, "pos")*g_unit; - float dir = OpFloat(line, "dir", 0.0f)*Math::PI; + float dirAngle = OpFloat(line, "dir", 0.0f)*Math::PI; bool trainer = OpInt(line, "trainer", 0); - CObject* obj = CreateObject(pos, dir, + CObject* obj = CreateObject(pos, dirAngle, OpFloat(line, "z", 1.0f), OpFloat(line, "h", 0.0f), type, @@ -4391,7 +4664,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) sel = obj; } - obj->SetSelectable(OpInt(line, "selectable", 1)); + bool selectable = OpInt(line, "selectable", 1); + obj->SetSelectable(selectable); obj->SetEnable(OpInt(line, "enable", 1)); obj->SetProxyActivate(OpInt(line, "proxyActivate", 0)); obj->SetProxyDistance(OpFloat(line, "proxyDistance", 15.0f)*g_unit); @@ -4399,10 +4673,15 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) obj->SetShield(OpFloat(line, "shield", 1.0f)); obj->SetMagnifyDamage(OpFloat(line, "magnifyDamage", 1.0f)); obj->SetClip(OpInt(line, "clip", 1)); - obj->SetCheckToken(m_version >= 2 ? trainer : OpInt(line, "manual", 1)); - obj->SetManual(m_version >= 2 ? !trainer : OpInt(line, "manual", 0)); + obj->SetCheckToken(m_version >= 2 ? trainer || !selectable : OpInt(line, "checkToken", 1)); + // SetManual will affect bot speed + if (type == OBJECT_MOBILEdr) + { + obj->SetManual(m_version >= 2 ? !trainer : OpInt(line, "manual", 0)); + } - if(m_version >= 2) { + if (m_version >= 2) + { Math::Vector zoom = OpDir(line, "zoom"); if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f) obj->SetZoom(0, zoom); @@ -4479,6 +4758,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) } rankObj ++; + continue; } if (Cmd(line, "CreateFog") && !resetObject) @@ -4494,6 +4774,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) dim.x = ddim; dim.y = dim.x; m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f); + continue; } if (Cmd(line, "CreateLight") && !resetObject) @@ -4505,7 +4786,10 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) type = OpTypeTerrain(line, "type", Gfx::ENG_OBJTYPE_NULL); if (type == Gfx::ENG_OBJTYPE_TERRAIN) + { + m_lightMan->SetLightPriority(lightRank, Gfx::LIGHT_PRI_HIGHEST); m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_TERRAIN); + } if (type == Gfx::ENG_OBJTYPE_QUARTZ) m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_QUARTZ); @@ -4515,6 +4799,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (type == Gfx::ENG_OBJTYPE_FIX) m_lightMan->SetLightExcludeType(lightRank, Gfx::ENG_OBJTYPE_TERRAIN); + + continue; } if (Cmd(line, "CreateSpot") && !resetObject) { @@ -4535,6 +4821,8 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (type == Gfx::ENG_OBJTYPE_FIX) m_lightMan->SetLightExcludeType(rankLight, Gfx::ENG_OBJTYPE_TERRAIN); + + continue; } if (Cmd(line, "GroundSpot") && !resetObject) @@ -4549,10 +4837,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_engine->SetObjectGroundSpotMinMax(rank, OpFloat(line, "min", 0.0f)*g_unit, OpFloat(line, "max", 0.0f)*g_unit); } + continue; } if (Cmd(line, "WaterColor") && !resetObject) + { m_engine->SetWaterAddColor(OpColor(line, "color", Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f))); + continue; + } if (Cmd(line, "MapColor") && !resetObject) { @@ -4573,23 +4865,29 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpInt(line, "mode", 0), OpInt(line, "debug", 0)); } + continue; } + if (Cmd(line, "MapZoom") && !resetObject) { m_map->ZoomMap(OpFloat(line, "factor", 2.0f)); m_map->MapEnable(OpInt(line, "enable", 1)); + continue; } if (Cmd(line, "MaxFlyingHeight") && !resetObject) { m_terrain->SetFlyingMaxHeight(OpFloat(line, "max", 280.0f)*g_unit); + continue; } + if (Cmd(line, "AddFlyingHeight") && !resetObject) { m_terrain->AddFlyingLimit(OpPos(line, "center")*g_unit, OpFloat(line, "extRadius", 20.0f)*g_unit, OpFloat(line, "intRadius", 10.0f)*g_unit, OpFloat(line, "maxHeight", 200.0f)); + continue; } if (Cmd(line, "Camera")) @@ -4602,32 +4900,51 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); m_camera->SetFixDirection(OpFloat(line, "fixDirection", 0.25f)*Math::PI); + continue; } - if (Cmd(line, "EndMissionTake") && !resetObject) + if (Cmd(line, "EndMissionTake") && !resetObject && m_controller == nullptr) { int i = m_endTakeTotal; if (i < 10) { - m_endTake[i].pos = OpPos(line, "pos")*g_unit; - m_endTake[i].dist = OpFloat(line, "dist", 8.0f)*g_unit; - m_endTake[i].type = OpTypeObject(line, "type", OBJECT_NULL); - m_endTake[i].min = OpInt(line, "min", 1); - m_endTake[i].max = OpInt(line, "max", 9999); - m_endTake[i].lost = OpInt(line, "lost", -1); + m_endTake[i].pos = OpPos(line, "pos")*g_unit; + m_endTake[i].dist = OpFloat(line, "dist", 8.0f)*g_unit; + m_endTake[i].type = OpTypeObject(line, "type", OBJECT_NULL); + m_endTake[i].min = OpInt(line, "min", 1); + m_endTake[i].max = OpInt(line, "max", 9999); + if (m_version >= 2) + { + m_endTake[i].powermin = OpInt(line, "powermin", -1); + m_endTake[i].powermax = OpInt(line, "powermax", 100); + } + else + { + m_endTake[i].powermin = -1; + m_endTake[i].powermax = 100; + } + m_endTake[i].lost = OpInt(line, "lost", -1); m_endTake[i].immediat = OpInt(line, "immediat", 0); OpString(line, "message", m_endTake[i].message); m_endTakeTotal ++; } + continue; } - if (Cmd(line, "EndMissionDelay") && !resetObject) + if (Cmd(line, "EndMissionDelay") && !resetObject && m_controller == nullptr) { m_endTakeWinDelay = OpFloat(line, "win", 2.0f); m_endTakeLostDelay = OpFloat(line, "lost", 2.0f); + continue; } - if (Cmd(line, "EndMissionResearch") && !resetObject) + if (Cmd(line, "EndMissionResearch") && !resetObject && m_controller == nullptr) { m_endTakeResearch |= OpResearch(line, "type"); + continue; + } + if (Cmd(line, "EndMissionNever") && !resetObject && m_controller == nullptr) + { + m_endTakeNever = true; + continue; } if (Cmd(line, "ObligatoryToken") && !resetObject) @@ -4638,6 +4955,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpString(line, "text", m_obligatoryToken[i]); m_obligatoryTotal ++; } + continue; } if (Cmd(line, "ProhibitedToken") && !resetObject) @@ -4648,22 +4966,39 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) OpString(line, "text", m_prohibitedToken[i]); m_prohibitedTotal ++; } + continue; } if (Cmd(line, "EnableBuild") && !resetObject) + { g_build |= OpBuild(line, "type"); + continue; + } if (Cmd(line, "EnableResearch") && !resetObject) + { g_researchEnable |= OpResearch(line, "type"); + continue; + } - if (Cmd(line, "DoneResearch") && read[0] == 0 && !resetObject) // not loading file? + if (Cmd(line, "DoneResearch") && read[0] == 0 && !resetObject) // not loading file? + { g_researchDone |= OpResearch(line, "type"); + continue; + } if (Cmd(line, "NewScript") && !resetObject) { OpString(line, "name", name); AddNewScriptName(OpTypeObject(line, "type", OBJECT_NULL), name); + continue; } + + if (line[0] == '\n') continue; // Ignore empty lines + if (line[0] == '\0') continue; // Ignore empty lines + if (read[0] != 0) continue; // Ignore when loading saved game + + GetLogger()->Error("Syntax error in file '%s' (line %d): Unknown command: %s", filename, lineNum, line); // Don't add \n at the end of log message - it's included in line variable } fclose(file); @@ -4737,7 +5072,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) m_dialog->SetSceneRead(""); m_dialog->SetStackRead(""); - setlocale(LC_NUMERIC, oldLocale.c_str()); + RestoreNumericLocale(); } //! Creates an object of decoration mobile or stationary @@ -5055,7 +5390,8 @@ CObject* CRobotMain::CreateObject(Math::Vector pos, float angle, float zoom, flo type == OBJECT_MOBILEwt || type == OBJECT_MOBILEit || type == OBJECT_MOBILEdr || - type == OBJECT_APOLLO2 ) + type == OBJECT_APOLLO2 || + type == OBJECT_CONTROLLER ) { object = new CObject(); object->SetOption(option); @@ -5643,7 +5979,7 @@ char* SearchLastDir(char *filename) while (p != filename) { - if (*(--p) == '/') return p; + if (*(--p) == '/' || *p == '\\') return p; } return 0; } @@ -5748,7 +6084,7 @@ void CRobotMain::LoadOneScript(CObject *obj, int &nbError) char filename[MAX_FNAME]; sprintf(filename, "%s/%s/%c%.3d%.3d%.1d.txt", - GetSavegameDir(), m_gamerName, name[0], rank, objRank, i); + GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i); brain->ReadProgram(i, filename); if (!brain->GetCompile(i)) nbError++; } @@ -5818,7 +6154,7 @@ void CRobotMain::SaveOneScript(CObject *obj) { char filename[MAX_FNAME]; sprintf(filename, "%s/%s/%c%.3d%.3d%.1d.txt", - GetSavegameDir(), m_gamerName, name[0], rank, objRank, i); + GetSavegameDir(), m_gamerName.c_str(), name[0], rank, objRank, i); brain->WriteProgram(i, filename); } } @@ -5945,6 +6281,8 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) { if (obj->GetType() == OBJECT_FIX) return; + SetNumericLocale(); + char line[3000]; char name[100]; @@ -6031,6 +6369,8 @@ void CRobotMain::IOWriteObject(FILE *file, CObject* obj, const char *cmd) strcat(line, "\n"); fputs(line, file); + + RestoreNumericLocale(); } //! Saves the current game @@ -6039,6 +6379,8 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * FILE* file = fopen(filename, "w"); if (file == NULL) return false; + SetNumericLocale(); + char line[500]; sprintf(line, "Title text=\"%s\"\n", info); @@ -6101,6 +6443,8 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char * } fclose(file); + RestoreNumericLocale(); + #if CBOT_STACK // Writes the file of stacks of execution. file = fOpen(filecbot, "wb"); @@ -6145,6 +6489,8 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) if (type == OBJECT_NULL) return nullptr; + SetNumericLocale(); + int trainer = OpInt(line, "trainer", 0); int toy = OpInt(line, "toy", 0); int option = OpInt(line, "option", 0); @@ -6210,6 +6556,8 @@ CObject* CRobotMain::IOReadObject(char *line, const char* filename, int objRank) automat->Start(run); // starts the film } + RestoreNumericLocale(); + return obj; } @@ -6221,6 +6569,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) FILE* file = fopen(filename, "r"); if (file == NULL) return 0; + SetNumericLocale(); + CObject* fret = nullptr; CObject* power = nullptr; CObject* sel = nullptr; @@ -6342,6 +6692,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot) } #endif + RestoreNumericLocale(); + return sel; } @@ -6352,10 +6704,10 @@ void CRobotMain::WriteFreeParam() m_freeResearch |= g_researchDone; m_freeBuild |= g_build; - if (m_gamerName[0] == 0) return; + if (m_gamerName == "") return; char filename[MAX_FNAME]; - sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName); + sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName.c_str()); FILE* file = fopen(filename, "w"); if (file == NULL) return; @@ -6371,10 +6723,10 @@ void CRobotMain::ReadFreeParam() m_freeResearch = 0; m_freeBuild = 0; - if (m_gamerName[0] == 0) return; + if (m_gamerName == "") return; char filename[MAX_FNAME]; - sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName); + sprintf(filename, "%s/%s/research.gam", GetSavegameDir(), m_gamerName.c_str()); FILE* file = fopen(filename, "r"); if (file == NULL) return; @@ -6525,9 +6877,113 @@ void CRobotMain::ResetCreate() } } +//! Updates the audiotracks +void CRobotMain::UpdateAudio(bool frame) +{ + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); + + for (int t = 0; t < m_audioChangeTotal; t++) + { + if (m_audioChange[t].changed) continue; + + Math::Vector bPos = m_audioChange[t].pos; + bPos.y = 0.0f; + + Math::Vector oPos; + + int nb = 0; + for (int i = 0; i < 1000000; i++) + { + CObject* obj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i)); + if (obj == nullptr) break; + + // Do not use GetActif () because an invisible worm (underground) + // should be regarded as existing here! + if (obj->GetLock()) continue; + if (obj->GetRuin()) continue; + if (!obj->GetEnable()) continue; + + ObjectType type = obj->GetType(); + if (type == OBJECT_SCRAP2 || + type == OBJECT_SCRAP3 || + type == OBJECT_SCRAP4 || + type == OBJECT_SCRAP5) // wastes? + { + type = OBJECT_SCRAP1; + } + + if (type != m_audioChange[t].type) continue; + + float energyLevel = -1; + CObject* power = obj->GetPower(); + if (power != nullptr) + { + energyLevel = power->GetEnergy(); + if (power->GetType() == OBJECT_ATOMIC) energyLevel *= 100; + } + if (energyLevel < m_audioChange[t].powermin || energyLevel > m_audioChange[t].powermax) continue; + + if (obj->GetTruck() == 0) + oPos = obj->GetPosition(0); + else + oPos = obj->GetTruck()->GetPosition(0); + + oPos.y = 0.0f; + + if (Math::DistanceProjected(oPos, bPos) <= m_audioChange[t].dist) + nb ++; + } + + if (nb >= m_audioChange[t].min && + nb <= m_audioChange[t].max) + { + CLogger::GetInstancePointer()->Debug("Changing music...\n"); + m_sound->StopMusic(); + m_sound->PlayMusic(std::string(m_audioChange[t].music), m_audioChange[t].repeat); + m_audioChange[t].changed = true; + } + } +} + +void CRobotMain::SetEndMission(Error result, float delay) +{ + if (m_controller != nullptr) + { + m_endTakeWinDelay = delay; + m_endTakeLostDelay = delay; + m_missionResult = result; + } +} + //! Checks if the mission is over Error CRobotMain::CheckEndMission(bool frame) { + if (m_controller != nullptr) + { + if (m_missionResult == INFO_LOST) //mission lost? + { + m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f)); + m_winDelay = 0.0f; + if (m_lostDelay == 0) m_lostDelay = m_endTakeLostDelay; + m_displayText->SetEnable(false); + } + if (m_missionResult == INFO_LOSTq) //mission lost? + { + m_winDelay = 0.0f; + if (m_lostDelay == 0) m_lostDelay = 0.1f; + m_displayText->SetEnable(false); + } + if (frame && m_base) return ERR_MISSION_NOTERM; + if (m_missionResult == ERR_OK) { //mission win? + m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f)); + if (m_winDelay == 0) m_winDelay = m_endTakeWinDelay; + m_lostDelay = 0.0f; + m_displayText->SetEnable(false); + } + if (m_missionResult == ERR_MISSION_NOTERM) m_displayText->SetEnable(true); + return m_missionResult; + } + CInstanceManager* iMan = CInstanceManager::GetInstancePointer(); for (int t = 0; t < m_endTakeTotal; t++) @@ -6562,6 +7018,15 @@ Error CRobotMain::CheckEndMission(bool frame) if (type != m_endTake[t].type) continue; + float energyLevel = -1; + CObject* power = obj->GetPower(); + if (power != nullptr) + { + energyLevel = power->GetEnergy(); + if (power->GetType() == OBJECT_ATOMIC) energyLevel *= 100; + } + if (energyLevel < m_endTake[t].powermin || energyLevel > m_endTake[t].powermax) continue; + if (obj->GetTruck() == 0) oPos = obj->GetPosition(0); else @@ -6598,7 +7063,8 @@ Error CRobotMain::CheckEndMission(bool frame) } } if (nb < m_endTake[t].min || - nb > m_endTake[t].max) + nb > m_endTake[t].max || + m_endTakeNever ) { m_displayText->SetEnable(true); return ERR_MISSION_NOTERM; @@ -6781,10 +7247,10 @@ bool CRobotMain::GetRadar() for (int i = 0; i < 1000000; i++) { CObject* obj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i)); - if (obj == 0) break; + if (obj == nullptr) break; ObjectType type = obj->GetType(); - if (type == OBJECT_RADAR) + if (type == OBJECT_RADAR && !obj->GetLock()) return true; } return false; @@ -6813,15 +7279,15 @@ bool CRobotMain::GetRetroMode() //! Change the player's name void CRobotMain::SetGamerName(const char *name) { - strcpy(m_gamerName, name); + m_gamerName = std::string(name); SetGlobalGamerName(m_gamerName); ReadFreeParam(); } -//! Getes the player's name +//! Gets the player's name char* CRobotMain::GetGamerName() { - return m_gamerName; + return const_cast<char*>(m_gamerName.c_str()); } @@ -7025,7 +7491,8 @@ float CRobotMain::GetTracePrecision() //! Starts music with a mission void CRobotMain::StartMusic() { - if (m_audioTrack != 0) + CLogger::GetInstancePointer()->Debug("Starting music...\n"); + if (m_audioTrack != "") { m_sound->StopMusic(); m_sound->PlayMusic(m_audioTrack, m_audioRepeat); @@ -7038,3 +7505,18 @@ void CRobotMain::ClearInterface() HiliteClear(); // removes setting evidence m_tooltipName[0] = 0; // really removes the tooltip } + +void CRobotMain::SetNumericLocale() +{ + char *locale = setlocale(LC_NUMERIC, nullptr); + if (locale != nullptr) + m_oldLocale = locale; + + setlocale(LC_NUMERIC, "C"); +} + +void CRobotMain::RestoreNumericLocale() +{ + setlocale(LC_NUMERIC, m_oldLocale.c_str()); +} + diff --git a/src/object/robotmain.h b/src/object/robotmain.h index fe5fbd5..525e5df 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -99,13 +99,29 @@ struct EndTake Math::Vector pos; float dist; ObjectType type; - int min; // wins if> + int min; // wins if > int max; // wins if < int lost; // lost if <= + float powermin; // wins if energy cell >= + float powermax; // wins if energy cell <= bool immediat; char message[100]; }; +struct AudioChange +{ + Math::Vector pos; + float dist; + ObjectType type; + int min; // change if > + int max; // change if < + float powermin; // change if energy cell >= + float powermax; // change if energy cell <= + char music[100]; + bool repeat; + bool changed; +}; + const int MAXNEWSCRIPTNAME = 20; @@ -175,14 +191,17 @@ const int AXIS_INVALID = -1; class CRobotMain : public CSingleton<CRobotMain> { public: - CRobotMain(CApplication* app); - ~CRobotMain(); + CRobotMain(CApplication* app, bool loadProfile); + virtual ~CRobotMain(); Gfx::CCamera* GetCamera(); Gfx::CTerrain* GetTerrain(); Ui::CInterface* GetInterface(); Ui::CDisplayText* GetDisplayText(); + //! Caused the given mission to be loaded immediately after start + void LoadSceneOnStart(const std::string& name, int rank); + void CreateIni(); //! Sets the default input bindings (key and axes) @@ -210,7 +229,7 @@ public: void ResetKeyStates(); void ChangePhase(Phase phase); - bool EventProcess(Event &event); + bool ProcessEvent(Event &event); bool CreateShortcuts(); void ScenePerso(); @@ -248,6 +267,8 @@ public: void ResetObject(); void ResetCreate(); + void UpdateAudio(bool frame); + void SetEndMission(Error result, float delay); Error CheckEndMission(bool frame); void CheckEndMessage(const char* message); int GetObligatoryToken(); @@ -353,6 +374,11 @@ public: int CreateSpot(Math::Vector pos, Gfx::Color color); + void SetNumericLocale(); + void RestoreNumericLocale(); + + CObject* GetSelect(); + protected: bool EventFrame(const Event &event); bool EventObject(const Event &event); @@ -383,7 +409,6 @@ protected: void DeleteAllObjects(); void UpdateInfoText(); CObject* SearchObject(ObjectType type); - CObject* GetSelect(); void StartDisplayVisit(EventType event); void FrameVisit(float rTime); void StopDisplayVisit(); @@ -391,6 +416,7 @@ protected: bool TestGadgetQuantity(int rank); void UpdateSpeedLabel(); + protected: CApplication* m_app; CEventQueue* m_eventQueue; @@ -444,10 +470,12 @@ protected: bool m_cheatRadar; bool m_audioRepeat; bool m_shortCut; - int m_audioTrack; + std::string m_audioTrack; int m_delayWriteMessage; int m_movieInfoIndex; + CObject* m_controller; + //Level Checker flags bool m_beginObject; bool m_terrainGenerate; @@ -516,19 +544,25 @@ protected: int m_endTakeTotal; EndTake m_endTake[10]; long m_endTakeResearch; + bool m_endTakeNever; float m_endTakeWinDelay; float m_endTakeLostDelay; + int m_audioChangeTotal; + AudioChange m_audioChange[10]; + int m_obligatoryTotal; char m_obligatoryToken[100][20]; int m_prohibitedTotal; char m_prohibitedToken[100][20]; - char m_gamerName[100]; + std::string m_gamerName; int m_freeBuild; // constructible buildings int m_freeResearch; // researches possible + Error m_missionResult; + ShowLimit m_showLimit[MAXSHOWLIMIT]; Gfx::Color m_colorRefBot; @@ -540,5 +574,7 @@ protected: Gfx::Color m_colorRefWater; Gfx::Color m_colorNewWater; float m_colorShiftWater; + + std::string m_oldLocale; }; diff --git a/src/object/task/task.cpp b/src/object/task/task.cpp index 39fdccf..5ec6f8a 100644 --- a/src/object/task/task.cpp +++ b/src/object/task/task.cpp @@ -81,4 +81,3 @@ bool CTask::Abort() return true; } - diff --git a/src/object/task/task.h b/src/object/task/task.h index 12961ef..41b3d3b 100644 --- a/src/object/task/task.h +++ b/src/object/task/task.h @@ -34,7 +34,7 @@ class CSoundInterface; namespace Ui { class CDisplayText; -} /* Ui */ +} /* Ui */ namespace Gfx { class CEngine; @@ -43,7 +43,7 @@ class CParticle; class CTerrain; class CWater; class CCamera; -} /* Gfx */ +} /* Gfx */ const float TAKE_DIST = 6.0f; // distance to an object to pick it diff --git a/src/object/task/taskadvance.cpp b/src/object/task/taskadvance.cpp index 58eb939..885e100 100644 --- a/src/object/task/taskadvance.cpp +++ b/src/object/task/taskadvance.cpp @@ -139,4 +139,3 @@ Error CTaskAdvance::IsEnded() return ERR_CONTINUE; } - diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index b9af475..39479a6 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -557,7 +557,7 @@ Error CTaskBuild::FlatFloor() ObjectType type; Math::Vector center, pos, oPos, bPos; Math::Point c, p; - float radius, max, oRadius, bRadius, angle, dist; + float radius, max, oRadius, bRadius = 0.0f, angle, dist; int i, j; bool bLittleFlat, bBase; diff --git a/src/object/task/taskgoto.cpp b/src/object/task/taskgoto.cpp index c4a2939..01ff38b 100644 --- a/src/object/task/taskgoto.cpp +++ b/src/object/task/taskgoto.cpp @@ -90,8 +90,11 @@ bool CTaskGoto::EventProcess(const Event &event) rot.x = m_leakPos.x-pos.x; rot.y = m_leakPos.z-pos.z; dist = Math::Point(rot.x, rot.y).Length(); - rot.x /= dist; - rot.y /= dist; + if (dist != 0) + { + rot.x /= dist; + rot.y /= dist; + } a = m_object->GetAngleY(0); g = Math::RotateAngle(rot.x, -rot.y); // CW ! @@ -754,7 +757,7 @@ Error CTaskGoto::Start(Math::Vector goal, float altitude, Error CTaskGoto::IsEnded() { Math::Vector pos; - float limit, angle, dist, h, level; + float limit, angle = 0.0f, dist, h, level; if ( m_engine->GetPause() ) return ERR_CONTINUE; if ( m_error != ERR_OK ) return m_error; @@ -1308,16 +1311,6 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, Math::Vector &pos, return true; } - if ( type == OBJECT_DESTROYER ) - { - mat = pObj->GetWorldMatrix(0); - pos.x += 0.0f; - if ( bTake && distance != 0.0f ) suppl = 4.0f; - if ( bTake ) pos.x += TAKE_DIST+distance+suppl; - pos = Transform(*mat, pos); - return true; - } - if ( type == OBJECT_PARA && m_physics->GetType() == TYPE_FLYING ) { mat = pObj->GetWorldMatrix(0); @@ -1336,7 +1329,7 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, Math::Vector &pos, bool CTaskGoto::LeakSearch(Math::Vector &pos, float &delay) { - CObject *pObj, *pObstacle; + CObject *pObj, *pObstacle = nullptr; Math::Vector iPos, oPos, bPos; float iRadius, oRadius, bRadius, dist, min, dir; int i, j; @@ -1453,7 +1446,7 @@ void CTaskGoto::ComputeRepulse(Math::Point &dir) // The worm goes everywhere and through everything! iType = m_object->GetType(); - if ( iType == OBJECT_WORM ) return; + if ( iType == OBJECT_WORM || iType == OBJECT_CONTROLLER ) return; m_object->GetCrashSphere(0, iPos, iRadius); gDist = Math::Distance(iPos, m_goal); @@ -2239,4 +2232,3 @@ bool CTaskGoto::BitmapTestDot(int rank, int x, int y) return m_bmArray[rank*m_bmLine*m_bmSize + m_bmLine*y + x/8] & (1<<x%8); } - diff --git a/src/object/task/taskmanager.cpp b/src/object/task/taskmanager.cpp index a2ce8b8..11fba6c 100644 --- a/src/object/task/taskmanager.cpp +++ b/src/object/task/taskmanager.cpp @@ -271,4 +271,3 @@ bool CTaskManager::Abort() return m_task->Abort(); } - diff --git a/src/object/task/tasksearch.cpp b/src/object/task/tasksearch.cpp index b219185..974a53d 100644 --- a/src/object/task/tasksearch.cpp +++ b/src/object/task/tasksearch.cpp @@ -218,6 +218,13 @@ Error CTaskSearch::IsEnded() bool CTaskSearch::Abort() { + m_hand = TSH_UP; + InitAngle(); + for (int i = 0; i < 3; i++) + { + m_object->SetAngleZ(i+1, m_finalAngle[i]); + } + m_camera->StopCentering(m_object, 2.0f); m_physics->SetFreeze(false); // is moving again return true; @@ -319,4 +326,3 @@ void CTaskSearch::DeleteMark(ObjectType type) } } - diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp index 929dd5c..fe6eaeb 100644 --- a/src/object/task/taskshield.cpp +++ b/src/object/task/taskshield.cpp @@ -552,5 +552,3 @@ float CTaskShield::GetRadius() return RADIUS_SHIELD_MIN + (RADIUS_SHIELD_MAX-RADIUS_SHIELD_MIN)*m_object->GetParam(); } - - diff --git a/src/object/task/tasktake.cpp b/src/object/task/tasktake.cpp index 0037f85..c7f0530 100644 --- a/src/object/task/tasktake.cpp +++ b/src/object/task/tasktake.cpp @@ -598,4 +598,3 @@ bool CTaskTake::IsFreeDeposeObject(Math::Vector pos) return true; // location free } - diff --git a/src/object/task/taskturn.cpp b/src/object/task/taskturn.cpp index 7a924cb..bf9d593 100644 --- a/src/object/task/taskturn.cpp +++ b/src/object/task/taskturn.cpp @@ -126,4 +126,3 @@ Error CTaskTurn::IsEnded() return ERR_CONTINUE; } - diff --git a/src/object/task/taskwait.cpp b/src/object/task/taskwait.cpp index 3e201e0..5b9fdb3 100644 --- a/src/object/task/taskwait.cpp +++ b/src/object/task/taskwait.cpp @@ -64,4 +64,3 @@ Error CTaskWait::IsEnded() return ERR_CONTINUE; } - |