2012-03-19 11:44:39 +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-04-10 17:44:49 +00:00
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
// taskshield.cpp
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-06-20 15:00:16 +00:00
|
|
|
#include "object/task/taskshield.h"
|
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "common/iman.h"
|
2012-06-22 14:31:55 +00:00
|
|
|
#include "old/light.h"
|
|
|
|
#include "old/particule.h"
|
2012-06-20 15:00:16 +00:00
|
|
|
#include "math/geometry.h"
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "object/brain.h"
|
2012-06-20 15:00:16 +00:00
|
|
|
#include "physics/physics.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
2012-06-11 15:28:27 +00:00
|
|
|
const float ENERGY_TIME = 20.0f; // maximum duration if full battery
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CTaskShield::CTaskShield(CInstanceManager* iMan, CObject* object)
|
|
|
|
: CTask(iMan, object)
|
|
|
|
{
|
|
|
|
m_rankSphere = -1;
|
|
|
|
m_soundChannel = -1;
|
|
|
|
m_effectLight = -1;
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Object's destructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CTaskShield::~CTaskShield()
|
|
|
|
{
|
|
|
|
Abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Management of an event.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CTaskShield::EventProcess(const Event &event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CObject* power;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Matrix* mat;
|
|
|
|
Math::Matrix matrix;
|
|
|
|
Math::Vector pos, speed, goal, angle;
|
2012-03-08 18:32:05 +00:00
|
|
|
D3DCOLORVALUE color;
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point dim;
|
2012-03-08 18:32:05 +00:00
|
|
|
float energy;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_engine->RetPause() ) return true;
|
|
|
|
if ( event.event != EVENT_FRAME ) return true;
|
|
|
|
if ( m_bError ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
m_progress += event.rTime*m_speed; // others advance
|
2012-03-08 18:32:05 +00:00
|
|
|
m_time += event.rTime;
|
|
|
|
m_delay -= event.rTime;
|
|
|
|
|
|
|
|
mat = m_object->RetWorldMatrix(0);
|
2012-06-19 18:11:47 +00:00
|
|
|
pos = Math::Vector(7.0f, 15.0f, 0.0f);
|
|
|
|
pos = Math::Transform(*mat, pos); // sphere position
|
2012-03-08 18:32:05 +00:00
|
|
|
m_shieldPos = pos;
|
|
|
|
|
|
|
|
if ( m_rankSphere != -1 )
|
|
|
|
{
|
|
|
|
m_particule->SetPosition(m_rankSphere, m_shieldPos);
|
|
|
|
dim.x = RetRadius();
|
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->SetDimension(m_rankSphere, dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_UP1 )
|
|
|
|
{
|
|
|
|
pos.x = 7.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.y = 4.5f+Math::Bounce(m_progress)*3.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(2, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_UP2 )
|
|
|
|
{
|
|
|
|
pos.x = 0.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.y = 1.0f+Math::Bounce(m_progress)*3.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(3, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_SHIELD )
|
|
|
|
{
|
|
|
|
energy = (1.0f/ENERGY_TIME)*event.rTime;
|
|
|
|
energy *= RetRadius()/RADIUS_SHIELD_MAX;
|
|
|
|
power = m_object->RetPower();
|
|
|
|
if ( power != 0 )
|
|
|
|
{
|
|
|
|
power->SetEnergy(power->RetEnergy()-energy/power->RetCapacity());
|
|
|
|
}
|
|
|
|
m_energyUsed += energy;
|
|
|
|
|
|
|
|
if ( m_soundChannel == -1 )
|
|
|
|
{
|
2012-06-10 13:28:12 +00:00
|
|
|
m_soundChannel = m_sound->Play(SOUND_SHIELD, m_shieldPos, 0.5f, 0.5f, true);
|
2012-03-08 18:32:05 +00:00
|
|
|
m_sound->AddEnvelope(m_soundChannel, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 1.0f, 1.0f, 1.0f, SOPER_LOOP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sound->Position(m_soundChannel, m_shieldPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = m_shieldPos;
|
|
|
|
pos.y += RetRadius()*(2.0f+sinf(m_time*9.0f)*0.2f);
|
|
|
|
if ( m_effectLight == -1 )
|
|
|
|
{
|
|
|
|
CreateLight(pos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_light->SetLightPos(m_effectLight, pos);
|
|
|
|
|
|
|
|
color.r = 0.0f+sinf(m_time*33.2f)*0.2f;
|
|
|
|
color.g = 0.5f+sinf(m_time*20.0f)*0.5f;
|
|
|
|
color.b = 0.5f+sinf(m_time*21.3f)*1.0f;
|
|
|
|
color.a = 0.0f;
|
|
|
|
m_light->SetLightColor(m_effectLight, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
pos = m_shieldPos;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.x += (Math::Rand()-0.5f)*5.0f;
|
|
|
|
pos.z += (Math::Rand()-0.5f)*5.0f;
|
|
|
|
speed.x = (Math::Rand()-0.5f)*0.0f;
|
|
|
|
speed.z = (Math::Rand()-0.5f)*0.0f;
|
|
|
|
speed.y = Math::Rand()*15.0f;
|
|
|
|
dim.x = Math::Rand()*6.0f+4.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->CreateParticule(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_lastRay+m_engine->ParticuleAdapt(0.05f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastRay = m_time;
|
|
|
|
|
|
|
|
pos = m_shieldPos;
|
|
|
|
dim.x = RetRadius()/20.0f;
|
|
|
|
dim.y = dim.x;
|
2012-06-13 20:48:35 +00:00
|
|
|
angle.x = (Math::Rand()-0.5f)*Math::PI*1.2f;
|
2012-03-08 18:32:05 +00:00
|
|
|
angle.y = 0.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
angle.z = (Math::Rand()-0.5f)*Math::PI*1.2f;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::LoadRotationXZYMatrix(matrix, angle);
|
|
|
|
goal = Math::Transform(matrix, Math::Vector(0.0f, RetRadius()-dim.x, 0.0f));
|
2012-03-08 18:32:05 +00:00
|
|
|
goal += pos;
|
|
|
|
m_particule->CreateRay(pos, goal, PARTIRAY2, dim, 0.3f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_lastIncrease+0.2f <= m_time )
|
|
|
|
{
|
|
|
|
m_lastIncrease = m_time;
|
|
|
|
IncreaseShield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_SMOKE )
|
|
|
|
{
|
|
|
|
if ( m_soundChannel != -1 )
|
|
|
|
{
|
|
|
|
m_sound->FlushEnvelope(m_soundChannel);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 0.5f, 0.5f, 2.0f, SOPER_STOP);
|
|
|
|
m_soundChannel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
pos = m_shieldPos;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.x += (Math::Rand()-0.5f)*5.0f;
|
|
|
|
pos.z += (Math::Rand()-0.5f)*5.0f;
|
|
|
|
speed.x = (Math::Rand()-0.5f)*3.0f;
|
|
|
|
speed.z = (Math::Rand()-0.5f)*3.0f;
|
|
|
|
speed.y = (Math::Rand()-0.5f)*3.0f;
|
|
|
|
dim.x = Math::Rand()*1.5f+2.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_DOWN1 )
|
|
|
|
{
|
|
|
|
pos.x = 0.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.y = 1.0f+(1.0f-Math::Bounce(m_progress))*3.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(3, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_DOWN2 )
|
|
|
|
{
|
|
|
|
pos.x = 7.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
pos.y = 4.5f+(1.0f-Math::Bounce(m_progress))*3.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(2, pos);
|
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Deploys the shield.
|
|
|
|
// The period is only useful with TSM_UP!
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error CTaskShield::Start(TaskShieldMode mode, float delay)
|
|
|
|
{
|
|
|
|
CObject* power;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Matrix* mat;
|
|
|
|
Math::Vector pos, iPos, oPos, speed;
|
2012-03-08 18:32:05 +00:00
|
|
|
ObjectType type;
|
|
|
|
float energy;
|
|
|
|
|
|
|
|
if ( mode == TSM_DOWN )
|
|
|
|
{
|
|
|
|
return Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mode == TSM_UPDATE )
|
|
|
|
{
|
|
|
|
if ( m_object->RetSelect() )
|
|
|
|
{
|
|
|
|
m_brain->UpdateInterface();
|
|
|
|
}
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = m_object->RetType();
|
|
|
|
if ( type != OBJECT_MOBILErs ) return ERR_SHIELD_VEH;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
m_bError = true; // operation impossible
|
2012-03-08 18:32:05 +00:00
|
|
|
if ( !m_physics->RetLand() ) return ERR_SHIELD_VEH;
|
|
|
|
|
|
|
|
power = m_object->RetPower();
|
|
|
|
if ( power == 0 ) return ERR_SHIELD_ENERGY;
|
|
|
|
energy = power->RetEnergy();
|
|
|
|
if ( energy == 0.0f ) return ERR_SHIELD_ENERGY;
|
|
|
|
|
|
|
|
mat = m_object->RetWorldMatrix(0);
|
2012-06-19 18:11:47 +00:00
|
|
|
pos = Math::Vector(7.0f, 15.0f, 0.0f);
|
2012-04-10 17:44:49 +00:00
|
|
|
pos = Transform(*mat, pos); // sphere position
|
2012-03-08 18:32:05 +00:00
|
|
|
m_shieldPos = pos;
|
|
|
|
|
|
|
|
m_sound->Play(SOUND_PSHHH2, m_shieldPos, 1.0f, 0.7f);
|
|
|
|
|
|
|
|
m_phase = TS_UP1;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
m_time = 0.0f;
|
|
|
|
m_delay = delay;
|
|
|
|
m_lastParticule = 0.0f;
|
|
|
|
m_lastRay = 0.0f;
|
|
|
|
m_lastIncrease = 0.0f;
|
|
|
|
m_energyUsed = 0.0f;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
m_bError = false; // ok
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
if ( m_object->RetSelect() )
|
|
|
|
{
|
|
|
|
m_brain->UpdateInterface();
|
|
|
|
}
|
2012-06-13 20:48:35 +00:00
|
|
|
//? m_camera->StartCentering(m_object, Math::PI*0.85f, -Math::PI*0.15f, RetRadius()+40.0f, 3.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Returns the shield.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error CTaskShield::Stop()
|
|
|
|
{
|
|
|
|
float time;
|
|
|
|
|
|
|
|
if ( m_phase == TS_SHIELD )
|
|
|
|
{
|
|
|
|
m_object->SetShieldRadius(0.0f);
|
|
|
|
|
|
|
|
if ( m_rankSphere != -1 )
|
|
|
|
{
|
|
|
|
m_particule->SetPhase(m_rankSphere, PARPHEND, 3.0f);
|
|
|
|
m_rankSphere = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_effectLight != -1 )
|
|
|
|
{
|
|
|
|
m_light->DeleteLight(m_effectLight);
|
|
|
|
m_effectLight = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
time = m_energyUsed*4.0f;
|
|
|
|
if ( time < 1.0f ) time = 1.0f;
|
|
|
|
if ( time > 4.0f ) time = 4.0f;
|
|
|
|
|
|
|
|
m_phase = TS_SMOKE;
|
|
|
|
m_speed = 1.0f/time;
|
|
|
|
|
|
|
|
m_camera->StopCentering(m_object, 4.0f);
|
|
|
|
|
|
|
|
if ( m_object->RetSelect() )
|
|
|
|
{
|
|
|
|
m_brain->UpdateInterface();
|
|
|
|
}
|
|
|
|
return ERR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Indicates whether the action is finished.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error CTaskShield::IsEnded()
|
|
|
|
{
|
|
|
|
CObject* power;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector pos, speed;
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point dim;
|
2012-03-08 18:32:05 +00:00
|
|
|
float energy;
|
|
|
|
|
|
|
|
if ( m_engine->RetPause() ) return ERR_CONTINUE;
|
|
|
|
if ( m_bError ) return ERR_STOP;
|
|
|
|
|
|
|
|
if ( m_phase == TS_SHIELD )
|
|
|
|
{
|
|
|
|
m_object->SetShieldRadius(RetRadius());
|
|
|
|
|
|
|
|
power = m_object->RetPower();
|
|
|
|
if ( power == 0 )
|
|
|
|
{
|
|
|
|
energy = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
energy = power->RetEnergy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( energy == 0.0f || m_delay <= 0.0f )
|
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
return ERR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_progress < 1.0f ) return ERR_CONTINUE;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
|
|
|
if ( m_phase == TS_UP1 )
|
|
|
|
{
|
|
|
|
pos.x = 7.0f;
|
|
|
|
pos.y = 4.5f+3.0f;
|
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(2, pos);
|
|
|
|
|
|
|
|
m_sound->Play(SOUND_PSHHH2, m_shieldPos, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
m_phase = TS_UP2;
|
|
|
|
m_speed = 1.0f/0.8f;
|
|
|
|
return ERR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_UP2 )
|
|
|
|
{
|
|
|
|
pos.x = 0.0f;
|
|
|
|
pos.y = 1.0f+3.0f;
|
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(3, pos);
|
|
|
|
|
|
|
|
m_object->SetShieldRadius(RetRadius());
|
|
|
|
|
|
|
|
pos = m_shieldPos;
|
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 = RetRadius();
|
|
|
|
dim.y = dim.x;
|
|
|
|
m_rankSphere = m_particule->CreateParticule(pos, speed, dim, PARTISPHERE3, 2.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
m_phase = TS_SHIELD;
|
|
|
|
m_speed = 1.0f/999.9f;
|
|
|
|
|
|
|
|
if ( m_object->RetSelect() )
|
|
|
|
{
|
|
|
|
m_brain->UpdateInterface();
|
|
|
|
}
|
|
|
|
return ERR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_SMOKE )
|
|
|
|
{
|
|
|
|
m_sound->Play(SOUND_PSHHH2, m_shieldPos, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
m_phase = TS_DOWN1;
|
|
|
|
m_speed = 1.0f/0.8f;
|
|
|
|
return ERR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == TS_DOWN1 )
|
|
|
|
{
|
|
|
|
m_sound->Play(SOUND_PSHHH2, m_shieldPos, 1.0f, 0.7f);
|
|
|
|
|
|
|
|
m_phase = TS_DOWN2;
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
return ERR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Abort();
|
|
|
|
return ERR_STOP;
|
|
|
|
}
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Indicates whether the action is pending.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CTaskShield::IsBusy()
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
if ( m_phase == TS_SHIELD )
|
|
|
|
{
|
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
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Suddenly ends the current action.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CTaskShield::Abort()
|
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
|
|
|
|
|
|
|
m_object->SetShieldRadius(0.0f);
|
|
|
|
|
|
|
|
pos.x = 7.0f;
|
|
|
|
pos.y = 4.5f;
|
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(2, pos);
|
|
|
|
|
|
|
|
pos.x = 0.0f;
|
|
|
|
pos.y = 1.0f;
|
|
|
|
pos.z = 0.0f;
|
|
|
|
m_object->SetPosition(3, pos);
|
|
|
|
|
|
|
|
if ( m_soundChannel != -1 )
|
|
|
|
{
|
|
|
|
m_sound->FlushEnvelope(m_soundChannel);
|
|
|
|
m_sound->AddEnvelope(m_soundChannel, 0.5f, 0.5f, 2.0f, SOPER_STOP);
|
|
|
|
m_soundChannel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_rankSphere != -1 )
|
|
|
|
{
|
|
|
|
m_particule->SetPhase(m_rankSphere, PARPHEND, 3.0f);
|
|
|
|
m_rankSphere = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_effectLight != -1 )
|
|
|
|
{
|
|
|
|
m_light->DeleteLight(m_effectLight);
|
|
|
|
m_effectLight = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_camera->StopCentering(m_object, 2.0f);
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Creates the light to accompany a pyrotechnic effect.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-19 18:11:47 +00:00
|
|
|
bool CTaskShield::CreateLight(Math::Vector pos)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
D3DLIGHT7 light;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( !m_engine->RetLightMode() ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
ZeroMemory( &light, sizeof(light) );
|
|
|
|
light.dltType = D3DLIGHT_SPOT;
|
|
|
|
light.dcvDiffuse.r = 0.0f;
|
|
|
|
light.dcvDiffuse.g = 1.0f;
|
|
|
|
light.dcvDiffuse.b = 2.0f;
|
|
|
|
light.dvPosition.x = pos.x;
|
|
|
|
light.dvPosition.y = pos.y;
|
|
|
|
light.dvPosition.z = pos.z;
|
|
|
|
light.dvDirection.x = 0.0f;
|
2012-04-10 17:44:49 +00:00
|
|
|
light.dvDirection.y = -1.0f; // against the bottom
|
2012-03-08 18:32:05 +00:00
|
|
|
light.dvDirection.z = 0.0f;
|
|
|
|
light.dvRange = D3DLIGHT_RANGE_MAX;
|
|
|
|
light.dvFalloff = 1.0f;
|
|
|
|
light.dvAttenuation0 = 1.0f;
|
|
|
|
light.dvAttenuation1 = 0.0f;
|
|
|
|
light.dvAttenuation2 = 0.0f;
|
|
|
|
light.dvTheta = 0.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
light.dvPhi = Math::PI/4.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
m_effectLight = m_light->CreateLight();
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( m_effectLight == -1 ) return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
m_light->SetLight(m_effectLight, light);
|
|
|
|
m_light->SetLightIntensity(m_effectLight, 1.0f);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Repaired the shielded objects within the sphere of the shield.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CTaskShield::IncreaseShield()
|
|
|
|
{
|
|
|
|
ObjectType type;
|
|
|
|
CObject* pObj;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector oPos;
|
2012-03-08 18:32:05 +00:00
|
|
|
float dist, shield;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
|
|
|
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
|
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
|
|
|
|
type = pObj->RetType();
|
|
|
|
if ( type == OBJECT_MOTHER ||
|
|
|
|
type == OBJECT_ANT ||
|
|
|
|
type == OBJECT_SPIDER ||
|
|
|
|
type == OBJECT_BEE ||
|
|
|
|
type == OBJECT_WORM ) continue;
|
|
|
|
|
|
|
|
oPos = pObj->RetPosition(0);
|
2012-06-19 18:11:47 +00:00
|
|
|
dist = Math::Distance(oPos, m_shieldPos);
|
2012-03-08 18:32:05 +00:00
|
|
|
if ( dist <= RetRadius()+10.0f )
|
|
|
|
{
|
|
|
|
shield = pObj->RetShield();
|
|
|
|
shield += 0.1f;
|
|
|
|
if ( shield > 1.0f ) shield = 1.0f;
|
|
|
|
pObj->SetShield(shield);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-10 17:44:49 +00:00
|
|
|
// Returns the radius of the shield.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
float CTaskShield::RetRadius()
|
|
|
|
{
|
|
|
|
return RADIUS_SHIELD_MIN + (RADIUS_SHIELD_MAX-RADIUS_SHIELD_MIN)*m_object->RetParam();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|