2012-03-19 13:37:59 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
2012-03-09 16:08:05 +00:00
|
|
|
// * 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
|
2012-03-11 19:49:33 +00:00
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-06-20 15:00:16 +00:00
|
|
|
#include "object/auto/autolabo.h"
|
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "common/global.h"
|
|
|
|
#include "common/misc.h"
|
2012-06-20 15:00:16 +00:00
|
|
|
#include "math/geometry.h"
|
|
|
|
#include "object/robotmain.h"
|
|
|
|
#include "script/cmdtoken.h"
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "ui/interface.h"
|
|
|
|
#include "ui/window.h"
|
|
|
|
#include "ui/displaytext.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-11 15:28:27 +00:00
|
|
|
const float LABO_DELAY = 20.0f; // duration of the analysis
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAutoLabo::CAutoLabo(CInstanceManager* iMan, CObject* object)
|
|
|
|
: CAuto(iMan, object)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i=0 ; i<3 ; i++ )
|
|
|
|
{
|
|
|
|
m_partiRank[i] = -1;
|
|
|
|
}
|
|
|
|
m_partiSphere = -1;
|
|
|
|
|
|
|
|
m_soundChannel = -1;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Object's destructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAutoLabo::~CAutoLabo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Destroys the object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
void CAutoLabo::DeleteObject(bool bAll)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i=0 ; i<3 ; i++ )
|
|
|
|
{
|
|
|
|
if ( m_partiRank[i] != -1 )
|
|
|
|
{
|
|
|
|
m_particule->DeleteParticule(m_partiRank[i]);
|
|
|
|
m_partiRank[i] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_partiSphere != -1 )
|
|
|
|
{
|
|
|
|
m_particule->DeleteParticule(m_partiSphere);
|
|
|
|
m_partiSphere = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_soundChannel != -1 )
|
|
|
|
{
|
|
|
|
m_sound->FlushEnvelope(m_soundChannel);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.0f, 1.0f, SOPER_STOP);
|
|
|
|
m_soundChannel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAuto::DeleteObject(bAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Initialize the object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoLabo::Init()
|
|
|
|
{
|
|
|
|
m_time = 0.0f;
|
|
|
|
m_timeVirus = 0.0f;
|
|
|
|
m_lastParticule = 0.0f;
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
m_phase = ALAP_WAIT; // waiting ...
|
2012-03-08 18:32:05 +00:00
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
|
|
|
CAuto::Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Management of an event.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoLabo::EventProcess(const Event &event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CObject* power;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector pos, goal, speed;
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point dim, rot;
|
2012-03-08 18:32:05 +00:00
|
|
|
float angle;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
CAuto::EventProcess(event);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_engine->RetPause() ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
if ( event.event == EVENT_UPDINTERFACE )
|
|
|
|
{
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_object->RetSelect() ) CreateInterface(true);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
if ( m_object->RetSelect() && // center selected?
|
2012-03-08 18:32:05 +00:00
|
|
|
(event.event == EVENT_OBJECT_RiPAW ||
|
|
|
|
event.event == EVENT_OBJECT_RiGUN) )
|
|
|
|
{
|
|
|
|
if ( m_phase != ALAP_WAIT )
|
|
|
|
{
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_research = event.event;
|
|
|
|
|
|
|
|
if ( TestResearch(m_research) )
|
|
|
|
{
|
|
|
|
m_displayText->DisplayError(ERR_LABO_ALREADY, m_object);
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
power = m_object->RetPower();
|
|
|
|
if ( power == 0 )
|
|
|
|
{
|
|
|
|
m_displayText->DisplayError(ERR_LABO_NULL, m_object);
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
if ( power->RetType() != OBJECT_BULLET )
|
|
|
|
{
|
|
|
|
m_displayText->DisplayError(ERR_LABO_BAD, m_object);
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
SetBusy(true);
|
2012-03-08 18:32:05 +00:00
|
|
|
InitProgressTotal(1.0f+1.5f+1.5f+LABO_DELAY+1.5f+1.5f+1.0f);
|
|
|
|
UpdateInterface();
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
power->SetLock(true); // ball longer usable
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
SoundManip(1.0f, 1.0f, 1.0f);
|
|
|
|
m_phase = ALAP_OPEN1;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.0f;
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( event.event != EVENT_FRAME ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
m_progress += event.rTime*m_speed;
|
|
|
|
m_timeVirus -= event.rTime;
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
if ( m_object->RetVirusMode() ) // contaminated by a virus?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
if ( m_timeVirus <= 0.0f )
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
m_timeVirus = 0.1f+Math::Rand()*0.3f;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EventProgress(event.rTime);
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_WAIT )
|
|
|
|
{
|
|
|
|
if ( m_progress >= 1.0f )
|
|
|
|
{
|
2012-03-15 16:34:49 +00:00
|
|
|
m_phase = ALAP_WAIT; // still waiting ...
|
2012-03-08 18:32:05 +00:00
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_OPEN1 )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
angle = 80.0f-(35.0f*m_progress);
|
2012-06-13 20:48:35 +00:00
|
|
|
m_object->SetAngleZ(3, angle*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(4, angle*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(5, angle*Math::PI/180.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
m_object->SetAngleZ(3, 45.0f*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(4, 45.0f*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(5, 45.0f*Math::PI/180.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
SoundManip(1.5f, 1.0f, 0.7f);
|
|
|
|
m_phase = ALAP_OPEN2;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_OPEN2 )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
pos.x = -9.0f;
|
|
|
|
pos.y = 3.0f+m_progress*10.0f;
|
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(1, pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
m_object->SetPosition(1, Math::Vector(-9.0f, 13.0f, 0.0f));
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
SoundManip(1.5f, 1.0f, 0.5f);
|
|
|
|
m_phase = ALAP_OPEN3;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_OPEN3 )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
angle = (1.0f-m_progress)*Math::PI/2.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
m_object->SetAngleZ(1, angle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_object->SetAngleZ(1, 0.0f);
|
|
|
|
|
|
|
|
goal = m_object->RetPosition(0);
|
|
|
|
goal.y += 3.0f;
|
|
|
|
pos = goal;
|
|
|
|
pos.x -= 4.0f;
|
|
|
|
pos.y += 4.0f;
|
|
|
|
for ( i=0 ; i<3 ; i++ )
|
|
|
|
{
|
|
|
|
m_partiRank[i] = m_particule->CreateRay(pos, goal,
|
|
|
|
PARTIRAY2,
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point(2.9f, 2.9f),
|
2012-03-08 18:32:05 +00:00
|
|
|
LABO_DELAY);
|
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
m_soundChannel = m_sound->Play(SOUND_LABO, m_object->RetPosition(0), 0.0f, 0.25f, true);
|
2012-03-08 18:32:05 +00:00
|
|
|
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.60f, 2.0f, SOPER_CONTINUE);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 1.0f, 2.00f, 8.0f, SOPER_CONTINUE);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.60f, 8.0f, SOPER_CONTINUE);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.25f, 2.0f, SOPER_STOP);
|
|
|
|
|
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.y += 4.0f;
|
2012-06-19 18:11:47 +00:00
|
|
|
speed = Math::Vector(0.0f, 0.0f, 0.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
dim.x = 4.0f;
|
|
|
|
dim.y = dim.x;
|
|
|
|
m_partiSphere = m_particule->CreateParticule(pos, speed, dim, PARTISPHERE2, LABO_DELAY, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
m_phase = ALAP_ANALYSE;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/LABO_DELAY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_ANALYSE )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
power = m_object->RetPower();
|
|
|
|
if ( power != 0 )
|
|
|
|
{
|
|
|
|
power->SetZoom(0, 1.0f-m_progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
angle = m_object->RetAngleY(2);
|
|
|
|
if ( m_progress < 0.5f )
|
|
|
|
{
|
|
|
|
angle -= event.rTime*m_progress*20.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
angle -= event.rTime*(20.0f-m_progress*20.0f);
|
|
|
|
}
|
2012-03-15 16:34:49 +00:00
|
|
|
m_object->SetAngleY(2, angle); // rotates the analyzer
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
angle += m_object->RetAngleY(0);
|
|
|
|
for ( i=0 ; i<3 ; i++ )
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
rot = Math::RotatePoint(-angle, -4.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.x += rot.x;
|
|
|
|
pos.z += rot.y;
|
|
|
|
pos.y += 3.0f+4.0f;;
|
2012-03-15 16:34:49 +00:00
|
|
|
m_particule->SetPosition(m_partiRank[i], pos); // adjusts ray
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-13 20:48:35 +00:00
|
|
|
angle += Math::PI*2.0f/3.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
if ( m_progress > 0.25f &&
|
|
|
|
m_progress < 0.80f )
|
|
|
|
{
|
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.y += 3.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.x += (Math::Rand()-0.5f)*2.0f;
|
|
|
|
pos.z += (Math::Rand()-0.5f)*2.0f;
|
|
|
|
speed.y = Math::Rand()*5.0f+5.0f;
|
|
|
|
speed.x = (Math::Rand()-0.5f)*10.0f;
|
|
|
|
speed.z = (Math::Rand()-0.5f)*10.0f;
|
|
|
|
dim.x = Math::Rand()*0.4f*m_progress+1.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->CreateTrack(pos, speed, dim, PARTITRACK2,
|
|
|
|
2.0f+2.0f*m_progress, 10.0f, 1.5f, 1.4f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-15 16:34:49 +00:00
|
|
|
SetResearch(m_research); // research done
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
power = m_object->RetPower();
|
|
|
|
if ( power != 0 )
|
|
|
|
{
|
|
|
|
m_object->SetPower(0);
|
2012-03-15 16:34:49 +00:00
|
|
|
power->DeleteObject(); // destroys the ball
|
2012-03-08 18:32:05 +00:00
|
|
|
delete power;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_displayText->DisplayError(INFO_LABO, m_object);
|
|
|
|
|
|
|
|
SoundManip(1.5f, 1.0f, 0.5f);
|
|
|
|
m_phase = ALAP_CLOSE1;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_CLOSE1 )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
angle = m_progress*Math::PI/2.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
m_object->SetAngleZ(1, angle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
m_object->SetAngleZ(1, Math::PI/2.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
SoundManip(1.5f, 1.0f, 0.7f);
|
|
|
|
m_phase = ALAP_CLOSE2;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_CLOSE2 )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
pos.x = -9.0f;
|
|
|
|
pos.y = 3.0f+(1.0f-m_progress)*10.0f;;
|
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(1, pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
m_object->SetPosition(1, Math::Vector(-9.0f, 3.0f, 0.0f));
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
SoundManip(1.0f, 1.0f, 1.0f);
|
|
|
|
m_phase = ALAP_CLOSE3;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == ALAP_CLOSE3 )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
angle = 45.0f+(35.0f*m_progress);
|
2012-06-13 20:48:35 +00:00
|
|
|
m_object->SetAngleZ(3, angle*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(4, angle*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(5, angle*Math::PI/180.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
m_object->SetAngleZ(3, 80.0f*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(4, 80.0f*Math::PI/180.0f);
|
|
|
|
m_object->SetAngleZ(5, 80.0f*Math::PI/180.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
SetBusy(false);
|
2012-03-08 18:32:05 +00:00
|
|
|
UpdateInterface();
|
|
|
|
|
|
|
|
m_phase = ALAP_WAIT;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Returns an error due the state of the automation.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error CAutoLabo::RetError()
|
|
|
|
{
|
|
|
|
CObject* pObj;
|
|
|
|
ObjectType type;
|
|
|
|
|
|
|
|
if ( m_object->RetVirusMode() )
|
|
|
|
{
|
|
|
|
return ERR_BAT_VIRUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
pObj = m_object->RetPower();
|
|
|
|
if ( pObj == 0 ) return ERR_LABO_NULL;
|
|
|
|
type = pObj->RetType();
|
|
|
|
if ( type != OBJECT_BULLET ) return ERR_LABO_BAD;
|
|
|
|
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Creates all the interface when the object is selected.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoLabo::CreateInterface(bool bSelect)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CWindow* pw;
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point pos, dim, ddim;
|
2012-03-08 18:32:05 +00:00
|
|
|
float ox, oy, sx, sy;
|
|
|
|
|
|
|
|
CAuto::CreateInterface(bSelect);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( !bSelect ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( pw == 0 ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
dim.x = 33.0f/640.0f;
|
|
|
|
dim.y = 33.0f/480.0f;
|
|
|
|
ox = 3.0f/640.0f;
|
|
|
|
oy = 3.0f/480.0f;
|
|
|
|
sx = 33.0f/640.0f;
|
|
|
|
sy = 33.0f/480.0f;
|
|
|
|
|
|
|
|
pos.x = ox+sx*7.0f;
|
|
|
|
pos.y = oy+sy*0.5f;
|
|
|
|
pw->CreateButton(pos, dim, 64+45, EVENT_OBJECT_RiPAW);
|
|
|
|
|
|
|
|
pos.x = ox+sx*8.0f;
|
|
|
|
pos.y = oy+sy*0.5f;
|
|
|
|
pw->CreateButton(pos, dim, 64+46, EVENT_OBJECT_RiGUN);
|
|
|
|
|
|
|
|
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, 111, EVENT_OBJECT_TYPE);
|
|
|
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Updates the status of all interface buttons.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoLabo::UpdateInterface()
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
|
|
|
|
if ( !m_object->RetSelect() ) return;
|
|
|
|
|
|
|
|
CAuto::UpdateInterface();
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
DeadInterface(pw, EVENT_OBJECT_RiPAW, g_researchEnable&RESEARCH_iPAW);
|
|
|
|
DeadInterface(pw, EVENT_OBJECT_RiGUN, g_researchEnable&RESEARCH_iGUN);
|
|
|
|
|
|
|
|
OkayButton(pw, EVENT_OBJECT_RiPAW);
|
|
|
|
OkayButton(pw, EVENT_OBJECT_RiGUN);
|
|
|
|
|
|
|
|
VisibleInterface(pw, EVENT_OBJECT_RiPAW, !m_bBusy);
|
|
|
|
VisibleInterface(pw, EVENT_OBJECT_RiGUN, !m_bBusy);
|
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Indicates the research conducted for a button.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoLabo::OkayButton(CWindow *pw, EventMsg event)
|
|
|
|
{
|
|
|
|
CControl* control;
|
|
|
|
|
|
|
|
control = pw->SearchControl(event);
|
|
|
|
if ( control == 0 ) return;
|
|
|
|
|
|
|
|
control->SetState(STATE_OKAY, TestResearch(event));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Test whether a search has already been done.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoLabo::TestResearch(EventMsg event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
if ( event == EVENT_OBJECT_RiPAW ) return (g_researchDone & RESEARCH_iPAW);
|
|
|
|
if ( event == EVENT_OBJECT_RiGUN ) return (g_researchDone & RESEARCH_iGUN);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Indicates a search as made.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoLabo::SetResearch(EventMsg event)
|
|
|
|
{
|
|
|
|
Event newEvent;
|
|
|
|
|
|
|
|
if ( event == EVENT_OBJECT_RiPAW ) g_researchDone |= RESEARCH_iPAW;
|
|
|
|
if ( event == EVENT_OBJECT_RiGUN ) g_researchDone |= RESEARCH_iGUN;
|
|
|
|
|
|
|
|
m_main->WriteFreeParam();
|
|
|
|
|
|
|
|
m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE);
|
|
|
|
m_event->AddEvent(newEvent);
|
|
|
|
UpdateInterface();
|
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Plays the sound of the manipulator arm.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoLabo::SoundManip(float time, float amplitude, float frequency)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
i = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 0.0f, 0.3f*frequency, true);
|
2012-03-08 18:32:05 +00:00
|
|
|
m_sound->AddEnvelope(i, 0.5f*amplitude, 1.0f*frequency, 0.1f, SOPER_CONTINUE);
|
|
|
|
m_sound->AddEnvelope(i, 0.5f*amplitude, 1.0f*frequency, time-0.1f, SOPER_CONTINUE);
|
|
|
|
m_sound->AddEnvelope(i, 0.0f, 0.3f*frequency, 0.1f, SOPER_STOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Saves all parameters of the controller.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoLabo::Write(char *line)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector pos;
|
2012-03-08 18:32:05 +00:00
|
|
|
char name[100];
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_phase == ALAP_WAIT ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
sprintf(name, " aExist=%d", 1);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
CAuto::Write(line);
|
|
|
|
|
|
|
|
sprintf(name, " aPhase=%d", m_phase);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
sprintf(name, " aProgress=%.2f", m_progress);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
sprintf(name, " aSpeed=%.2f", m_speed);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
sprintf(name, " aResearch=%d", m_research);
|
|
|
|
strcat(line, name);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 16:34:49 +00:00
|
|
|
// Restores all parameters of the controller.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoLabo::Read(char *line)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector pos;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( OpInt(line, "aExist", 0) == 0 ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAuto::Read(line);
|
|
|
|
|
|
|
|
m_phase = (AutoLaboPhase)OpInt(line, "aPhase", ALAP_WAIT);
|
|
|
|
m_progress = OpFloat(line, "aProgress", 0.0f);
|
|
|
|
m_speed = OpFloat(line, "aSpeed", 1.0f);
|
|
|
|
m_research = (EventMsg)OpInt(line, "aResearch", 0);
|
|
|
|
|
|
|
|
m_lastParticule = 0.0f;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|