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
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "object/auto/autokid.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-22 14:31:55 +00:00
|
|
|
#include "old/particule.h"
|
|
|
|
#include "old/water.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAutoKid::CAutoKid(CInstanceManager* iMan, CObject* object)
|
|
|
|
: CAuto(iMan, object)
|
|
|
|
{
|
|
|
|
m_soundChannel = -1;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAutoKid::~CAutoKid()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
// Destroys the object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
void CAutoKid::DeleteObject(bool bAll)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CAuto::DeleteObject(bAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
// Initialize the object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoKid::Init()
|
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector pos;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_lastParticule = 0.0f;
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
if ( m_type == OBJECT_TEEN36 ) // trunk ?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
pos = m_object->RetPosition(0);
|
2012-06-13 20:48:35 +00:00
|
|
|
m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f));
|
|
|
|
m_progress = Math::Mod(pos.x/10.0f, 1.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
if ( m_type == OBJECT_TEEN37 ) // boat?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
pos = m_object->RetPosition(0);
|
2012-06-13 20:48:35 +00:00
|
|
|
m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f))*2.5f;
|
|
|
|
m_progress = Math::Mod(pos.x/10.0f, 1.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
if ( m_type == OBJECT_TEEN38 ) // fan?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
if ( m_soundChannel == -1 )
|
|
|
|
{
|
2012-06-10 13:28:12 +00:00
|
|
|
//? m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 1.0f, 0.5f, true);
|
|
|
|
m_bSilent = false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
// Management of an event.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoKid::EventProcess(const Event &event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector vib, pos, speed;
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point dim;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAuto::EventProcess(event);
|
|
|
|
|
|
|
|
if ( m_soundChannel != -1 )
|
|
|
|
{
|
|
|
|
if ( m_engine->RetPause() )
|
|
|
|
{
|
|
|
|
if ( !m_bSilent )
|
|
|
|
{
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.5f, 0.1f, SOPER_CONTINUE);
|
2012-06-10 13:28:12 +00:00
|
|
|
m_bSilent = true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( m_bSilent )
|
|
|
|
{
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 0.1f, SOPER_CONTINUE);
|
2012-06-10 13:28:12 +00:00
|
|
|
m_bSilent = false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_engine->RetPause() ) return true;
|
|
|
|
if ( event.event != EVENT_FRAME ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
m_progress += event.rTime*m_speed;
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
if ( m_type == OBJECT_TEEN36 ) // trunk?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
vib.x = 0.0f;
|
|
|
|
vib.y = sinf(m_progress)*1.0f;
|
|
|
|
vib.z = 0.0f;
|
|
|
|
m_object->SetLinVibration(vib);
|
|
|
|
|
|
|
|
vib.x = 0.0f;
|
|
|
|
vib.y = 0.0f;
|
|
|
|
vib.z = sinf(m_progress*0.5f)*0.05f;
|
|
|
|
m_object->SetCirVibration(vib);
|
|
|
|
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.15f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.y = m_water->RetLevel()+1.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.x += (Math::Rand()-0.5f)*50.0f;
|
|
|
|
pos.z += (Math::Rand()-0.5f)*50.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
speed.y = 0.0f;
|
|
|
|
speed.x = 0.0f;
|
|
|
|
speed.z = 0.0f;
|
|
|
|
dim.x = 50.0f;
|
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->CreateParticule(pos, speed, dim, PARTIFLIC, 3.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
if ( m_type == OBJECT_TEEN37 ) // boat?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
vib.x = 0.0f;
|
|
|
|
vib.y = sinf(m_progress)*1.0f;
|
|
|
|
vib.z = 0.0f;
|
|
|
|
m_object->SetLinVibration(vib);
|
|
|
|
|
|
|
|
vib.x = 0.0f;
|
|
|
|
vib.y = 0.0f;
|
|
|
|
vib.z = sinf(m_progress*0.5f)*0.15f;
|
|
|
|
m_object->SetCirVibration(vib);
|
|
|
|
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.15f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.y = m_water->RetLevel()+1.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.x += (Math::Rand()-0.5f)*20.0f;
|
|
|
|
pos.z += (Math::Rand()-0.5f)*20.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
speed.y = 0.0f;
|
|
|
|
speed.x = 0.0f;
|
|
|
|
speed.z = 0.0f;
|
|
|
|
dim.x = 20.0f;
|
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->CreateParticule(pos, speed, dim, PARTIFLIC, 3.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
if ( m_type == OBJECT_TEEN38 ) // fan?
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
m_object->SetAngleY(1, sinf(m_progress*0.6f)*0.4f);
|
|
|
|
m_object->SetAngleX(2, m_progress*5.0f);
|
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-14 18:17:01 +00:00
|
|
|
// Returns an error due the state of the automation.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error CAutoKid::RetError()
|
|
|
|
{
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|