2014-10-14 13:11:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
|
|
|
|
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
|
|
|
|
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
|
|
|
|
*
|
|
|
|
|
* 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://gnu.org/licenses
|
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "object/auto/autosafe.h"
|
|
|
|
|
|
|
|
|
|
#include "math/geometry.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2015-06-20 18:02:40 +00:00
|
|
|
|
#include "object/object_manager.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "object/robotmain.h"
|
2014-11-10 13:16:32 +00:00
|
|
|
|
#include "object/level/parserline.h"
|
|
|
|
|
#include "object/level/parserparam.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "ui/interface.h"
|
|
|
|
|
#include "ui/window.h"
|
|
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
const float OPEN_DELAY = 8.0f; // duration of opening
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Object's constructor.
|
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
|
CAutoSafe::CAutoSafe(CObject* object) : CAuto(object)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<4 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
m_bKey[i] = false;
|
|
|
|
|
m_keyParti[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_bLock = false;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_lastParticle = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_channelSound = -1;
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
|
|
CAutoSafe::~CAutoSafe()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Destroys the object.
|
|
|
|
|
|
|
|
|
|
void CAutoSafe::DeleteObject(bool bAll)
|
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObject* obj = SearchVehicle();
|
|
|
|
|
if ( obj != nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_channelSound != -1 )
|
|
|
|
|
{
|
|
|
|
|
m_sound->FlushEnvelope(m_channelSound);
|
|
|
|
|
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 1.0f, SOPER_STOP);
|
|
|
|
|
m_channelSound = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CAuto::DeleteObject(bAll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the object.
|
|
|
|
|
|
|
|
|
|
void CAutoSafe::Init()
|
|
|
|
|
{
|
|
|
|
|
m_time = 0.0f;
|
|
|
|
|
m_timeVirus = 0.0f;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_lastParticle = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_countKeys = 0;
|
|
|
|
|
m_actualAngle = 0.0f;
|
|
|
|
|
m_finalAngle = 0.0f;
|
|
|
|
|
|
|
|
|
|
m_phase = ASAP_WAIT; // waiting ...
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
|
|
|
|
|
|
CAuto::Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
|
|
bool CAutoSafe::EventProcess(const Event &event)
|
|
|
|
|
{
|
|
|
|
|
CObject* pObj;
|
|
|
|
|
Math::Vector pos, speed;
|
|
|
|
|
Math::Point dim;
|
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
|
|
CAuto::EventProcess(event);
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_engine->GetPause() ) return true;
|
|
|
|
|
if ( event.type != EVENT_FRAME ) return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_progress += event.rTime*m_speed;
|
|
|
|
|
m_timeVirus -= event.rTime;
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_object->GetVirusMode() ) // contaminated by a virus?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_timeVirus <= 0.0f )
|
|
|
|
|
{
|
|
|
|
|
m_timeVirus = 0.1f+Math::Rand()*0.3f;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventProgress(event.rTime);
|
|
|
|
|
|
2015-06-26 18:19:16 +00:00
|
|
|
|
if ( !m_bLock && CRobotMain::GetInstancePointer()->GetGameTime() < 1.0f )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
pObj = SearchVehicle();
|
|
|
|
|
if ( pObj != 0 )
|
|
|
|
|
{
|
|
|
|
|
pObj->SetLock(true); // object not yet usable
|
|
|
|
|
m_main->CreateShortcuts();
|
|
|
|
|
m_bLock = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == ASAP_WAIT )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress >= 1.0f )
|
|
|
|
|
{
|
|
|
|
|
count = CountKeys(); // count these key
|
|
|
|
|
if ( count != m_countKeys )
|
|
|
|
|
{
|
|
|
|
|
m_countKeys = count;
|
|
|
|
|
|
|
|
|
|
if ( count == 0 ) m_finalAngle = 0.0f*Math::PI/180.0f;
|
|
|
|
|
if ( count == 1 ) m_finalAngle = 5.0f*Math::PI/180.0f;
|
|
|
|
|
if ( count == 2 ) m_finalAngle = 10.0f*Math::PI/180.0f;
|
|
|
|
|
if ( count == 3 ) m_finalAngle = 15.0f*Math::PI/180.0f;
|
|
|
|
|
if ( count == 4 ) m_finalAngle = 120.0f*Math::PI/180.0f;
|
|
|
|
|
|
|
|
|
|
if ( count == 4 ) // all the keys?
|
|
|
|
|
{
|
|
|
|
|
LockKeys();
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_channelSound = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 1.0f, 0.25f, true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_sound->AddEnvelope(m_channelSound, 1.0f, 2.00f, OPEN_DELAY, SOPER_STOP);
|
|
|
|
|
|
|
|
|
|
m_phase = ASAP_OPEN;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/OPEN_DELAY;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_channelSound = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 1.0f, 0.25f, true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_sound->AddEnvelope(m_channelSound, 1.0f, 0.35f, 0.5f, SOPER_STOP);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_phase = ASAP_WAIT;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == ASAP_OPEN )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
|
{
|
|
|
|
|
DownKeys(m_progress);
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_lastParticle = m_time;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<10 ; i++ )
|
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
pos = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.x += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
pos.z += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
speed.x = (Math::Rand()-0.5f)*4.0f;
|
|
|
|
|
speed.z = (Math::Rand()-0.5f)*4.0f;
|
|
|
|
|
speed.y = Math::Rand()*15.0f;
|
|
|
|
|
dim.x = Math::Rand()*6.0f+4.0f;
|
|
|
|
|
dim.y = dim.x;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, 1.0f, 0.0f, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
pos = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.x += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
pos.z += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
speed.x = (Math::Rand()-0.5f)*4.0f;
|
|
|
|
|
speed.z = (Math::Rand()-0.5f)*4.0f;
|
|
|
|
|
speed.y = Math::Rand()*10.0f;
|
|
|
|
|
dim.x = Math::Rand()*3.0f+2.0f;
|
|
|
|
|
dim.y = dim.x;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 1.0f, 0.0f, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
for ( i=0 ; i<4 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
pos = m_keyPos[i];
|
|
|
|
|
speed.x = (Math::Rand()-0.5f)*2.0f;
|
|
|
|
|
speed.z = (Math::Rand()-0.5f)*2.0f;
|
|
|
|
|
speed.y = 1.0f+Math::Rand()*1.0f;
|
|
|
|
|
dim.x = Math::Rand()*1.5f+1.5f;
|
|
|
|
|
dim.y = dim.x;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f, 0.0f, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DeleteKeys();
|
|
|
|
|
|
|
|
|
|
pObj = SearchVehicle();
|
|
|
|
|
if ( pObj != 0 )
|
|
|
|
|
{
|
|
|
|
|
pObj->SetLock(false); // object usable
|
|
|
|
|
m_main->CreateShortcuts();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-10 07:26:38 +00:00
|
|
|
|
m_object->DeleteAllCrashSpheres();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_object->SetGlobalSphere(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f);
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_sound->Play(SOUND_FINDING, m_object->GetPosition(0));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_phase = ASAP_FINISH;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/100.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == ASAP_FINISH )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress >= 1.0f )
|
|
|
|
|
{
|
|
|
|
|
m_phase = ASAP_FINISH;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/100.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Opens or closes the doors.
|
|
|
|
|
if ( m_actualAngle != m_finalAngle )
|
|
|
|
|
{
|
|
|
|
|
if ( m_actualAngle < m_finalAngle )
|
|
|
|
|
{
|
|
|
|
|
m_actualAngle += (105.0f*Math::PI/180.0f)*event.rTime/OPEN_DELAY;
|
|
|
|
|
if ( m_actualAngle > m_finalAngle ) m_actualAngle = m_finalAngle;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_actualAngle -= (105.0f*Math::PI/180.0f)*event.rTime/OPEN_DELAY;
|
|
|
|
|
if ( m_actualAngle < m_finalAngle ) m_actualAngle = m_finalAngle;
|
|
|
|
|
}
|
|
|
|
|
m_object->SetAngleZ(1, m_actualAngle);
|
|
|
|
|
m_object->SetAngleZ(2, -m_actualAngle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Blinks the keys.
|
|
|
|
|
speed = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
|
dim.x = 2.0f;
|
|
|
|
|
dim.y = dim.x;
|
|
|
|
|
for ( i=0 ; i<4 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( m_phase != ASAP_WAIT || !m_bKey[i] || Math::Mod(m_time, 1.0f) < 0.4f )
|
|
|
|
|
{
|
|
|
|
|
if ( m_keyParti[i] != -1 )
|
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->DeleteParticle(m_keyParti[i]);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_keyParti[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( m_keyParti[i] == -1 )
|
|
|
|
|
{
|
|
|
|
|
pos = m_keyPos[i];
|
|
|
|
|
pos.y += 2.2f;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_keyParti[i] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISELY, 1.0f, 0.0f, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Creates all the interface when the object is selected.
|
|
|
|
|
|
|
|
|
|
bool CAutoSafe::CreateInterface(bool bSelect)
|
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
Ui::CWindow* pw;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
Math::Point pos, ddim;
|
|
|
|
|
float ox, oy, sx, sy;
|
|
|
|
|
|
|
|
|
|
CAuto::CreateInterface(bSelect);
|
|
|
|
|
|
|
|
|
|
if ( !bSelect ) return true;
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( pw == 0 ) return false;
|
|
|
|
|
|
|
|
|
|
ox = 3.0f/640.0f;
|
|
|
|
|
oy = 3.0f/480.0f;
|
|
|
|
|
sx = 33.0f/640.0f;
|
|
|
|
|
sy = 33.0f/480.0f;
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*0;
|
|
|
|
|
ddim.x = 66.0f/640.0f;
|
|
|
|
|
ddim.y = 66.0f/480.0f;
|
|
|
|
|
pw->CreateGroup(pos, ddim, 114, EVENT_OBJECT_TYPE);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-17 19:55:45 +00:00
|
|
|
|
// Returns an error due the state of the automation.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
Error CAutoSafe::GetError()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_object->GetVirusMode() )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
return ERR_BAT_VIRUS;
|
|
|
|
|
}
|
|
|
|
|
return ERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Saves all parameters of the controller.
|
|
|
|
|
|
2014-11-10 13:16:32 +00:00
|
|
|
|
bool CAutoSafe::Write(CLevelParserLine* line)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_phase == ASAP_WAIT ) return false;
|
2015-06-21 18:59:23 +00:00
|
|
|
|
|
|
|
|
|
line->AddParam("aExist", CLevelParserParamUPtr{new CLevelParserParam(true)});
|
2012-06-26 20:23:05 +00:00
|
|
|
|
CAuto::Write(line);
|
2015-06-21 18:59:23 +00:00
|
|
|
|
line->AddParam("aPhase", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_phase))});
|
|
|
|
|
line->AddParam("aProgress", CLevelParserParamUPtr{new CLevelParserParam(m_progress)});
|
|
|
|
|
line->AddParam("aSpeed", CLevelParserParamUPtr{new CLevelParserParam(m_speed)});
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Restores all parameters of the controller.
|
|
|
|
|
|
2014-11-10 16:15:34 +00:00
|
|
|
|
bool CAutoSafe::Read(CLevelParserLine* line)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2014-11-10 16:15:34 +00:00
|
|
|
|
if ( !line->GetParam("aExist")->AsBool(false) ) return false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
CAuto::Read(line);
|
2014-11-10 16:15:34 +00:00
|
|
|
|
m_phase = static_cast< AutoSafePhase >(line->GetParam("aPhase")->AsInt(ASAP_WAIT));
|
|
|
|
|
m_progress = line->GetParam("aProgress")->AsFloat(0.0f);
|
|
|
|
|
m_speed = line->GetParam("aSpeed")->AsFloat(1.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_lastParticle = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Counts the number of keys
|
|
|
|
|
|
|
|
|
|
int CAutoSafe::CountKeys()
|
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector cPos = m_object->GetPosition(0);
|
|
|
|
|
float cAngle = m_object->GetAngleY(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (int index = 0; index < 4; index++)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
m_bKey[index] = false;
|
|
|
|
|
m_keyPos[index] = cPos;
|
|
|
|
|
}
|
2015-06-21 09:16:09 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
if ( obj->GetTransporter() != nullptr ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
ObjectType oType = obj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( oType != OBJECT_KEYa &&
|
|
|
|
|
oType != OBJECT_KEYb &&
|
|
|
|
|
oType != OBJECT_KEYc &&
|
|
|
|
|
oType != OBJECT_KEYd ) continue;
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition(0);
|
|
|
|
|
float dist = Math::DistanceProjected(oPos, cPos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( dist > 20.0f ) continue;
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
float limit = 0.0f;
|
|
|
|
|
float oAngle = 0.0f;
|
|
|
|
|
int index = 0;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( oType == OBJECT_KEYa )
|
|
|
|
|
{
|
|
|
|
|
limit = Math::PI*1.0f;
|
|
|
|
|
oAngle = Math::PI*0.0f;
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
|
|
|
|
if ( oType == OBJECT_KEYb )
|
|
|
|
|
{
|
|
|
|
|
limit = Math::PI*0.0f;
|
|
|
|
|
oAngle = Math::PI*1.0f;
|
|
|
|
|
index = 1;
|
|
|
|
|
}
|
|
|
|
|
if ( oType == OBJECT_KEYc )
|
|
|
|
|
{
|
|
|
|
|
limit = Math::PI*1.5f;
|
|
|
|
|
oAngle = Math::PI*0.5f;
|
|
|
|
|
index = 2;
|
|
|
|
|
}
|
|
|
|
|
if ( oType == OBJECT_KEYd )
|
|
|
|
|
{
|
|
|
|
|
limit = Math::PI*0.5f;
|
|
|
|
|
oAngle = Math::PI*0.0f;
|
|
|
|
|
index = 3;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
float angle = Math::RotateAngle(oPos.x-cPos.x, oPos.z-cPos.z)+cAngle;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( !Math::TestAngle(angle, limit-8.0f*Math::PI/180.0f, limit+8.0f*Math::PI/180.0f) ) continue;
|
|
|
|
|
|
|
|
|
|
// Key changes the shape of the base.
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Point rot = Math::RotatePoint(Math::Point(cPos.x, cPos.z), limit-cAngle, Math::Point(cPos.x+16.0f, cPos.z));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
oPos.x = rot.x;
|
|
|
|
|
oPos.z = rot.y;
|
|
|
|
|
oPos.y = cPos.y+1.0f;
|
2015-06-21 14:22:09 +00:00
|
|
|
|
obj->SetPosition(0, oPos);
|
|
|
|
|
obj->SetAngleY(0, oAngle+cAngle);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_keyPos[index] = oPos;
|
|
|
|
|
|
|
|
|
|
m_bKey[index] = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
for (int index = 0; index < 4; index++)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_bKey[index] ) i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Blocks all keys.
|
|
|
|
|
|
|
|
|
|
void CAutoSafe::LockKeys()
|
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector cPos = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
ObjectType oType = obj->GetType();
|
2015-06-29 21:05:31 +00:00
|
|
|
|
if ( obj->GetTransporter() != nullptr ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( oType != OBJECT_KEYa &&
|
|
|
|
|
oType != OBJECT_KEYb &&
|
|
|
|
|
oType != OBJECT_KEYc &&
|
|
|
|
|
oType != OBJECT_KEYd ) continue;
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition(0);
|
|
|
|
|
float dist = Math::DistanceProjected(oPos, cPos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( dist > 20.0f ) continue;
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
obj->SetLock(true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sent down all the keys.
|
|
|
|
|
|
|
|
|
|
void CAutoSafe::DownKeys(float progress)
|
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector cPos = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
ObjectType oType = obj->GetType();
|
2015-06-29 21:05:31 +00:00
|
|
|
|
if ( obj->GetTransporter() != nullptr ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( oType != OBJECT_KEYa &&
|
|
|
|
|
oType != OBJECT_KEYb &&
|
|
|
|
|
oType != OBJECT_KEYc &&
|
|
|
|
|
oType != OBJECT_KEYd ) continue;
|
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition(0);
|
|
|
|
|
float dist = Math::DistanceProjected(oPos, cPos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( dist > 20.0f ) continue;
|
|
|
|
|
|
|
|
|
|
oPos.y = cPos.y+1.0f-progress*2.2f;
|
2015-06-21 14:22:09 +00:00
|
|
|
|
obj->SetPosition(0, oPos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete all the keys.
|
|
|
|
|
|
|
|
|
|
void CAutoSafe::DeleteKeys()
|
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
Math::Vector cPos = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
bool haveDeleted = false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
haveDeleted = false;
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
ObjectType oType = obj->GetType();
|
2015-06-29 21:05:31 +00:00
|
|
|
|
if ( obj->GetTransporter() != nullptr ) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
if ( oType != OBJECT_KEYa &&
|
|
|
|
|
oType != OBJECT_KEYb &&
|
|
|
|
|
oType != OBJECT_KEYc &&
|
|
|
|
|
oType != OBJECT_KEYd ) continue;
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition(0);
|
|
|
|
|
float dist = Math::DistanceProjected(oPos, cPos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( dist > 20.0f ) continue;
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(obj);
|
|
|
|
|
|
|
|
|
|
haveDeleted = true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-21 09:16:09 +00:00
|
|
|
|
while ( haveDeleted );
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Seeking a vehicle in the safe.
|
|
|
|
|
|
|
|
|
|
CObject* CAutoSafe::SearchVehicle()
|
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector cPos = m_object->GetPosition(0);
|
2015-04-17 19:28:30 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2015-04-17 19:28:30 +00:00
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
if ( obj == m_object ) continue;
|
2015-06-29 21:05:31 +00:00
|
|
|
|
if ( obj->GetTransporter() != nullptr ) continue;
|
2015-04-17 19:28:30 +00:00
|
|
|
|
|
2015-06-21 14:22:09 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition(0);
|
|
|
|
|
float dist = Math::DistanceProjected(oPos, cPos);
|
|
|
|
|
if ( dist <= 4.0f ) return obj;
|
2015-04-17 19:28:30 +00:00
|
|
|
|
}
|
2015-06-21 14:22:09 +00:00
|
|
|
|
return nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|