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 <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <d3d.h>
|
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "math/const.h"
|
|
|
|
#include "common/struct.h"
|
|
|
|
#include "graphics/d3d/d3dengine.h"
|
|
|
|
#include "math/old/d3dmath.h"
|
|
|
|
#include "common/event.h"
|
|
|
|
#include "common/misc.h"
|
|
|
|
#include "common/iman.h"
|
|
|
|
#include "math/old/math3d.h"
|
|
|
|
#include "graphics/common/particule.h"
|
|
|
|
#include "graphics/common/terrain.h"
|
|
|
|
#include "graphics/common/camera.h"
|
|
|
|
#include "object/object.h"
|
|
|
|
#include "script/cmdtoken.h"
|
|
|
|
#include "sound/sound.h"
|
|
|
|
#include "object/auto/auto.h"
|
|
|
|
#include "object/auto/automush.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-15 17:06:18 +00:00
|
|
|
// Object's constructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAutoMush::CAutoMush(CInstanceManager* iMan, CObject* object)
|
|
|
|
: CAuto(iMan, object)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2012-03-15 17:06:18 +00:00
|
|
|
// Object's destructor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CAutoMush::~CAutoMush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 17:06:18 +00:00
|
|
|
// Destroys the object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
void CAutoMush::DeleteObject(bool bAll)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CAuto::DeleteObject(bAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 17:06:18 +00:00
|
|
|
// Initialize the object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CAutoMush::Init()
|
|
|
|
{
|
|
|
|
m_phase = AMP_WAIT;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/4.0f;
|
|
|
|
|
|
|
|
m_time = 0.0f;
|
|
|
|
m_lastParticule = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 17:06:18 +00:00
|
|
|
// Management of an event.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoMush::EventProcess(const Event &event)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector pos, speed, dir;
|
2012-06-13 20:48:35 +00:00
|
|
|
Math::Point dim;
|
2012-03-08 18:32:05 +00:00
|
|
|
float factor, zoom, size, angle;
|
|
|
|
int i, channel;
|
|
|
|
|
|
|
|
CAuto::EventProcess(event);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
factor = 0.0f;
|
|
|
|
size = 1.0f;
|
|
|
|
|
|
|
|
if ( m_phase == AMP_WAIT )
|
|
|
|
{
|
|
|
|
if ( m_progress >= 1.0f )
|
|
|
|
{
|
|
|
|
if ( !SearchTarget() )
|
|
|
|
{
|
|
|
|
m_phase = AMP_WAIT;
|
|
|
|
m_progress = 0.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
m_speed = 1.0f/(2.0f+Math::Rand()*2.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_phase = AMP_SNIF;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == AMP_SNIF )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
factor = m_progress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_phase = AMP_ZOOM;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == AMP_ZOOM )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
factor = 1.0f;
|
|
|
|
size = 1.0f+m_progress*0.3f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sound->Play(SOUND_MUSHROOM, m_object->RetPosition(0));
|
|
|
|
|
|
|
|
m_phase = AMP_FIRE;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == AMP_FIRE )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
factor = 1.0f-m_progress;
|
|
|
|
size = 1.0f+(1.0f-m_progress)*0.3f;
|
|
|
|
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
for ( i=0 ; i<10 ; i++ )
|
|
|
|
{
|
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.y += 5.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
speed.x = (Math::Rand()-0.5f)*200.0f;
|
|
|
|
speed.z = (Math::Rand()-0.5f)*200.0f;
|
|
|
|
speed.y = -(20.0f+Math::Rand()*20.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
dim.x = 1.0f;
|
|
|
|
dim.y = dim.x;
|
|
|
|
channel = m_particule->CreateParticule(pos, speed, dim, PARTIGUN2, 2.0f, 100.0f, 0.0f);
|
|
|
|
m_particule->SetObjectFather(channel, m_object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_phase = AMP_SMOKE;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_phase == AMP_SMOKE )
|
|
|
|
{
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
{
|
|
|
|
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
|
|
|
|
{
|
|
|
|
m_lastParticule = m_time;
|
|
|
|
|
|
|
|
pos = m_object->RetPosition(0);
|
|
|
|
pos.y += 5.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
speed.x = (Math::Rand()-0.5f)*4.0f;
|
|
|
|
speed.z = (Math::Rand()-0.5f)*4.0f;
|
|
|
|
speed.y = -(0.5f+Math::Rand()*0.5f);
|
|
|
|
dim.x = Math::Rand()*2.5f+2.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
dim.y = dim.x;
|
|
|
|
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_phase = AMP_WAIT;
|
|
|
|
m_progress = 0.0f;
|
2012-06-13 20:48:35 +00:00
|
|
|
m_speed = 1.0f/(2.0f+Math::Rand()*2.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( factor != 0.0f || size != 1.0f )
|
|
|
|
{
|
2012-06-13 20:48:35 +00:00
|
|
|
dir.x = sinf(m_time*Math::PI*4.0f);
|
|
|
|
dir.z = cosf(m_time*Math::PI*4.0f);
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
angle = sinf(m_time*10.0f)*factor*0.04f;
|
|
|
|
m_object->SetAngleX(0, angle*dir.z);
|
|
|
|
m_object->SetAngleZ(0, angle*dir.x);
|
|
|
|
|
|
|
|
zoom = 1.0f+sinf(m_time*8.0f)*factor*0.06f;
|
|
|
|
m_object->SetZoomX(0, zoom*size);
|
|
|
|
zoom = 1.0f+sinf(m_time*5.0f)*factor*0.06f;
|
|
|
|
m_object->SetZoomY(0, zoom*size);
|
|
|
|
zoom = 1.0f+sinf(m_time*7.0f)*factor*0.06f;
|
|
|
|
m_object->SetZoomZ(0, zoom*size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_object->SetAngleX(0, 0.0f);
|
|
|
|
m_object->SetAngleZ(0, 0.0f);
|
2012-06-19 18:11:47 +00:00
|
|
|
m_object->SetZoom(0, Math::Vector(1.0f, 1.0f, 1.0f));
|
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-03-15 17:06:18 +00:00
|
|
|
// Seeking a nearby target.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CAutoMush::SearchTarget()
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CObject* pObj;
|
2012-06-19 18:11:47 +00:00
|
|
|
Math::Vector iPos, oPos;
|
2012-03-08 18:32:05 +00:00
|
|
|
ObjectType type;
|
|
|
|
float dist;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
iPos = m_object->RetPosition(0);
|
|
|
|
|
|
|
|
for ( i=0 ; i<1000000 ; i++ )
|
|
|
|
{
|
|
|
|
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
|
|
|
|
if ( pObj == 0 ) break;
|
|
|
|
|
|
|
|
if ( pObj->RetLock() ) continue;
|
|
|
|
|
|
|
|
type = pObj->RetType();
|
|
|
|
if ( 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_DERRICK &&
|
|
|
|
type != OBJECT_STATION &&
|
|
|
|
type != OBJECT_FACTORY &&
|
|
|
|
type != OBJECT_REPAIR &&
|
|
|
|
type != OBJECT_DESTROYER&&
|
|
|
|
type != OBJECT_CONVERT &&
|
|
|
|
type != OBJECT_TOWER &&
|
|
|
|
type != OBJECT_RESEARCH &&
|
|
|
|
type != OBJECT_RADAR &&
|
|
|
|
type != OBJECT_INFO &&
|
|
|
|
type != OBJECT_ENERGY &&
|
|
|
|
type != OBJECT_LABO &&
|
|
|
|
type != OBJECT_NUCLEAR &&
|
|
|
|
type != OBJECT_PARA &&
|
|
|
|
type != OBJECT_HUMAN ) continue;
|
|
|
|
|
|
|
|
oPos = pObj->RetPosition(0);
|
2012-06-19 18:11:47 +00:00
|
|
|
dist = Math::Distance(oPos, iPos);
|
2012-06-10 13:28:12 +00:00
|
|
|
if ( dist < 50.0f ) return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 17:06:18 +00:00
|
|
|
// Returns an error due the state of the automation.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
Error CAutoMush::RetError()
|
|
|
|
{
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 17:06:18 +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 CAutoMush::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 == AMP_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);
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 17:06:18 +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 CAutoMush::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 = (AutoMushPhase)OpInt(line, "aPhase", AMP_WAIT);
|
|
|
|
m_progress = OpFloat(line, "aProgress", 0.0f);
|
|
|
|
m_speed = OpFloat(line, "aSpeed", 1.0f);
|
|
|
|
|
|
|
|
m_lastParticule = 0.0f;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
return true;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|