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/autofactory.h"
|
|
|
|
|
|
|
|
|
|
#include "common/global.h"
|
2015-07-17 18:36:01 +00:00
|
|
|
|
#include "common/make_unique.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "math/geometry.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2015-07-22 10:45:50 +00:00
|
|
|
|
#include "object/object_create_params.h"
|
2015-06-20 18:02:40 +00:00
|
|
|
|
#include "object/object_manager.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
#include "object/old_object.h"
|
2014-12-21 16:06:55 +00:00
|
|
|
|
#include "object/robotmain.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
|
2015-07-10 18:38:44 +00:00
|
|
|
|
#include "object/interface/programmable_object.h"
|
2015-07-10 17:03:27 +00:00
|
|
|
|
#include "object/interface/transportable_object.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2015-08-02 11:09:48 +00:00
|
|
|
|
#include "object/level/parserline.h"
|
|
|
|
|
#include "object/level/parserparam.h"
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "physics/physics.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2015-03-29 12:21:02 +00:00
|
|
|
|
#include "script/script.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2015-08-06 11:25:24 +00:00
|
|
|
|
#include "ui/controls/interface.h"
|
|
|
|
|
#include "ui/controls/window.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
2015-07-25 07:10:11 +00:00
|
|
|
|
#include <boost/regex.hpp>
|
2015-07-22 14:16:16 +00:00
|
|
|
|
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
// Object's constructor.
|
|
|
|
|
|
2015-07-12 09:33:52 +00:00
|
|
|
|
CAutoFactory::CAutoFactory(COldObject* object) : CAuto(object)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
m_type = OBJECT_MOBILEws;
|
|
|
|
|
m_phase = AFP_WAIT; // paused until the first Init ()
|
|
|
|
|
m_channelSound = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
|
|
CAutoFactory::~CAutoFactory()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Destroys the object.
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
void CAutoFactory::DeleteObject(bool all)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
if ( !all )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
CObject* cargo = SearchCargo(); // transform metal?
|
|
|
|
|
if ( cargo != nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(cargo);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObject* vehicle = SearchVehicle();
|
|
|
|
|
if ( vehicle != nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(vehicle);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 09:16:09 +00:00
|
|
|
|
CAuto::DeleteObject(all);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the object.
|
|
|
|
|
|
|
|
|
|
void CAutoFactory::Init()
|
|
|
|
|
{
|
|
|
|
|
m_phase = AFP_WAIT;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
|
|
|
|
|
m_time = 0.0f;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_lastParticle = 0.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-07-12 09:01:16 +00:00
|
|
|
|
m_cargoPos = m_object->GetPosition();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-07-22 14:16:16 +00:00
|
|
|
|
m_program = "";
|
2013-05-19 14:25:53 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
CAuto::Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-18 14:44:22 +00:00
|
|
|
|
// Starts an action
|
|
|
|
|
|
|
|
|
|
Error CAutoFactory::StartAction(int param)
|
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
CObject* cargo;
|
2013-05-18 14:44:22 +00:00
|
|
|
|
ObjectType type = static_cast<ObjectType>(param);
|
|
|
|
|
|
|
|
|
|
if ( type != OBJECT_NULL )
|
|
|
|
|
{
|
|
|
|
|
if ( m_phase != AFP_WAIT )
|
|
|
|
|
{
|
|
|
|
|
return ERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_type = type;
|
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
cargo = SearchCargo(); // transform metal?
|
|
|
|
|
if ( cargo == 0 )
|
2013-05-18 14:44:22 +00:00
|
|
|
|
{
|
|
|
|
|
return ERR_FACTORY_NULL;
|
|
|
|
|
}
|
|
|
|
|
if ( NearestVehicle() )
|
|
|
|
|
{
|
|
|
|
|
return ERR_FACTORY_NEAR;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-03 18:33:45 +00:00
|
|
|
|
m_program = "";
|
2013-05-18 14:44:22 +00:00
|
|
|
|
SetBusy(true);
|
|
|
|
|
InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f);
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
cargo->SetLock(true); // usable metal
|
2013-05-18 14:44:22 +00:00
|
|
|
|
SoundManip(3.0f, 1.0f, 0.5f);
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_CLOSE_S;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/3.0f;
|
|
|
|
|
return ERR_OK;
|
|
|
|
|
}
|
2015-08-12 14:54:44 +00:00
|
|
|
|
return ERR_UNKNOWN;
|
2013-05-18 14:44:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-19 14:25:53 +00:00
|
|
|
|
// Sets program for created robot
|
|
|
|
|
|
2015-07-22 14:16:16 +00:00
|
|
|
|
void CAutoFactory::SetProgram(const std::string& program)
|
2013-05-19 14:25:53 +00:00
|
|
|
|
{
|
2015-07-22 14:16:16 +00:00
|
|
|
|
m_program = program;
|
2013-05-19 14:25:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 15:38:19 +00:00
|
|
|
|
ObjectType ObjectTypeFromFactoryButton(EventType eventType)
|
|
|
|
|
{
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYwa ) return OBJECT_MOBILEwa;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYta ) return OBJECT_MOBILEta;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYfa ) return OBJECT_MOBILEfa;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYia ) return OBJECT_MOBILEia;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYws ) return OBJECT_MOBILEws;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYts ) return OBJECT_MOBILEts;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYfs ) return OBJECT_MOBILEfs;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYis ) return OBJECT_MOBILEis;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYwc ) return OBJECT_MOBILEwc;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYtc ) return OBJECT_MOBILEtc;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYfc ) return OBJECT_MOBILEfc;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYic ) return OBJECT_MOBILEic;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYwi ) return OBJECT_MOBILEwi;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYti ) return OBJECT_MOBILEti;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYfi ) return OBJECT_MOBILEfi;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYii ) return OBJECT_MOBILEii;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYrt ) return OBJECT_MOBILErt;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYrc ) return OBJECT_MOBILErc;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYrr ) return OBJECT_MOBILErr;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYrs ) return OBJECT_MOBILErs;
|
|
|
|
|
if ( eventType == EVENT_OBJECT_FACTORYsa ) return OBJECT_MOBILEsa;
|
|
|
|
|
|
|
|
|
|
return OBJECT_NULL;
|
|
|
|
|
}
|
2013-05-19 14:25:53 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
|
|
bool CAutoFactory::EventProcess(const Event &event)
|
|
|
|
|
{
|
2013-05-18 14:44:22 +00:00
|
|
|
|
ObjectType type;
|
2015-06-29 21:05:31 +00:00
|
|
|
|
CObject* cargo;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
CObject* vehicle;
|
|
|
|
|
Math::Matrix* mat;
|
|
|
|
|
CPhysics* physics;
|
|
|
|
|
Math::Vector pos, speed;
|
|
|
|
|
Math::Point dim;
|
|
|
|
|
float zoom, angle, prog;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
CAuto::EventProcess(event);
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_engine->GetPause() ) return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_object->GetSelect() ) // factory selected?
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( event.type == EVENT_UPDINTERFACE )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
CreateInterface(true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 15:38:19 +00:00
|
|
|
|
type = ObjectTypeFromFactoryButton(event.type);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
|
Error err = StartAction(type);
|
2015-08-12 14:54:44 +00:00
|
|
|
|
if( err != ERR_OK && err != ERR_UNKNOWN )
|
2013-06-24 20:09:39 +00:00
|
|
|
|
m_main->DisplayError(err, m_object);
|
2013-05-18 14:44:22 +00:00
|
|
|
|
|
2015-08-12 14:54:44 +00:00
|
|
|
|
if( err != ERR_UNKNOWN )
|
2013-05-18 14:44:22 +00:00
|
|
|
|
return false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( event.type != EVENT_FRAME ) return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
m_progress += event.rTime*m_speed;
|
|
|
|
|
EventProgress(event.rTime);
|
|
|
|
|
|
|
|
|
|
if ( m_phase == AFP_WAIT )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress >= 1.0f )
|
|
|
|
|
{
|
|
|
|
|
m_phase = AFP_WAIT; // still waiting ...
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == AFP_CLOSE_S )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
zoom = 0.30f+(m_progress-0.5f+i/16.0f)*2.0f*0.70f;
|
|
|
|
|
if ( zoom < 0.30f ) zoom = 0.30f;
|
|
|
|
|
if ( zoom > 1.00f ) zoom = 1.00f;
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartScaleZ( 1+i, zoom);
|
|
|
|
|
m_object->SetPartScaleZ(10+i, zoom);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartScaleZ( 1+i, 1.0f);
|
|
|
|
|
m_object->SetPartScaleZ(10+i, 1.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SoundManip(2.0f, 1.0f, 1.2f);
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_CLOSE_T;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == AFP_CLOSE_T )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
angle = -m_progress*(Math::PI/2.0f)+Math::PI/2.0f;
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartRotationZ( 1+i, angle);
|
|
|
|
|
m_object->SetPartRotationZ(10+i, -angle);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartRotationZ( 1+i, 0.0f);
|
|
|
|
|
m_object->SetPartRotationZ(10+i, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 09:01:16 +00:00
|
|
|
|
m_channelSound = m_sound->Play(SOUND_FACTORY, m_object->GetPosition(), 0.0f, 1.0f, true);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE);
|
|
|
|
|
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 11.0f, SOPER_CONTINUE);
|
|
|
|
|
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_BUILD;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/15.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == AFP_BUILD )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress == 0.0f )
|
|
|
|
|
{
|
|
|
|
|
if ( !CreateVehicle() )
|
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
cargo = SearchCargo(); // transform metal?
|
|
|
|
|
if ( cargo != 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
cargo->SetLock(false); // metal usable again
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_OPEN_T;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
|
{
|
|
|
|
|
if ( m_type == OBJECT_MOBILErt ||
|
|
|
|
|
m_type == OBJECT_MOBILErc ||
|
|
|
|
|
m_type == OBJECT_MOBILErr ||
|
|
|
|
|
m_type == OBJECT_MOBILErs )
|
|
|
|
|
{
|
|
|
|
|
prog = 1.0f-m_progress*1.5f;
|
|
|
|
|
if ( prog < 0.0f ) prog = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
prog = 1.0f-m_progress;
|
|
|
|
|
}
|
2015-07-14 19:29:13 +00:00
|
|
|
|
angle = powf(prog*10.0f, 2.0f)+m_object->GetRotationY();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
vehicle = SearchVehicle();
|
|
|
|
|
if ( vehicle != 0 )
|
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
vehicle->SetRotationY(angle+Math::PI);
|
|
|
|
|
vehicle->SetScale(m_progress);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
cargo = SearchCargo(); // transform metal?
|
|
|
|
|
if ( cargo != 0 )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
cargo->SetScale(1.0f-m_progress);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
mat = m_object->GetWorldMatrix(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos = Math::Vector(-12.0f, 20.0f, -4.0f); // position of chimney
|
|
|
|
|
pos = Math::Transform(*mat, pos);
|
|
|
|
|
pos.y += 2.0f;
|
|
|
|
|
pos.x += (Math::Rand()-0.5f)*2.0f;
|
|
|
|
|
pos.z += (Math::Rand()-0.5f)*2.0f;
|
|
|
|
|
speed.x = 0.0f;
|
|
|
|
|
speed.z = 0.0f;
|
|
|
|
|
speed.y = 6.0f+Math::Rand()*6.0f;
|
|
|
|
|
dim.x = Math::Rand()*1.5f+1.0f;
|
|
|
|
|
dim.y = dim.x;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-24 20:09:39 +00:00
|
|
|
|
m_main->DisplayError(INFO_FACTORY, m_object);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
SoundManip(2.0f, 1.0f, 1.2f);
|
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
cargo = SearchCargo(); // transform metal?
|
|
|
|
|
if ( cargo != nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-29 21:05:31 +00:00
|
|
|
|
CObjectManager::GetInstancePointer()->DeleteObject(cargo);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 14:16:16 +00:00
|
|
|
|
vehicle = SearchVehicle();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( vehicle != 0 )
|
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
physics = vehicle->GetPhysics();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( physics != 0 )
|
|
|
|
|
{
|
|
|
|
|
physics->SetFreeze(false); // can move
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vehicle->SetLock(false); // vehicle useable
|
2015-07-14 19:29:13 +00:00
|
|
|
|
vehicle->SetRotationY(m_object->GetRotationY()+Math::PI);
|
|
|
|
|
vehicle->SetScale(1.0f);
|
2015-07-22 14:16:16 +00:00
|
|
|
|
|
|
|
|
|
if ( !m_program.empty() )
|
|
|
|
|
{
|
|
|
|
|
if (vehicle->Implements(ObjectInterfaceType::Programmable))
|
|
|
|
|
{
|
2015-08-10 16:16:00 +00:00
|
|
|
|
CProgrammableObject* programmable = dynamic_cast<CProgrammableObject*>(vehicle);
|
|
|
|
|
Program* program = programmable->AddProgram();
|
2015-07-22 14:16:16 +00:00
|
|
|
|
|
2015-07-25 07:10:11 +00:00
|
|
|
|
if (boost::regex_search(m_program, boost::regex("^[A-Za-z0-9_]+$"))) // Public function name?
|
2015-07-22 14:16:16 +00:00
|
|
|
|
{
|
|
|
|
|
std::string code = "extern void object::Start_"+m_program+"()\n{\n\t\n\t//Automatically generated by object.factory()\n\t"+m_program+"();\n\t\n}\n";
|
|
|
|
|
program->script->SendScript(code.c_str());
|
|
|
|
|
}
|
2015-07-25 07:10:11 +00:00
|
|
|
|
else if (boost::regex_search(m_program, boost::regex(".txt$"))) // File name (with .txt extension)?
|
2015-07-22 14:16:16 +00:00
|
|
|
|
{
|
|
|
|
|
program->script->ReadScript(m_program.c_str());
|
|
|
|
|
}
|
|
|
|
|
else // Program code?
|
|
|
|
|
{
|
|
|
|
|
program->script->SendScript(m_program.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 16:16:00 +00:00
|
|
|
|
programmable->RunProgram(program);
|
2015-07-22 14:16:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_main->CreateShortcuts();
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_OPEN_T;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == AFP_OPEN_T )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
angle = -(1.0f-m_progress)*(Math::PI/2.0f)+Math::PI/2.0f;
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartRotationZ( 1+i, angle);
|
|
|
|
|
m_object->SetPartRotationZ(10+i, -angle);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= 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
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
pos = m_cargoPos;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.x += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
pos.z += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
pos.y += Math::Rand()*10.0f;
|
|
|
|
|
speed = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
|
dim.x = 2.0f;
|
|
|
|
|
dim.y = dim.x;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartRotationZ( 1+i, Math::PI/2.0f);
|
|
|
|
|
m_object->SetPartRotationZ(10+i, -Math::PI/2.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SoundManip(3.0f, 1.0f, 0.5f);
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_OPEN_S;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/3.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( m_phase == AFP_OPEN_S )
|
|
|
|
|
{
|
|
|
|
|
if ( m_progress < 1.0f )
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
|
|
|
|
zoom = 0.30f+((1.0f-m_progress)-0.5f+i/16.0f)*2.0f*0.70f;
|
|
|
|
|
if ( zoom < 0.30f ) zoom = 0.30f;
|
|
|
|
|
if ( zoom > 1.00f ) zoom = 1.00f;
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartScaleZ( 1+i, zoom);
|
|
|
|
|
m_object->SetPartScaleZ(10+i, zoom);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= 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
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
pos = m_cargoPos;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.x += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
pos.z += (Math::Rand()-0.5f)*10.0f;
|
|
|
|
|
pos.y += Math::Rand()*10.0f;
|
|
|
|
|
speed = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
|
dim.x = 2.0f;
|
|
|
|
|
dim.y = dim.x;
|
2012-09-09 12:28:19 +00:00
|
|
|
|
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( i=0 ; i<9 ; i++ )
|
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
m_object->SetPartScaleZ( 1+i, 0.30f);
|
|
|
|
|
m_object->SetPartScaleZ(10+i, 0.30f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetBusy(false);
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
|
|
|
|
|
m_phase = AFP_WAIT;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/2.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Saves all parameters of the controller.
|
|
|
|
|
|
2014-11-10 13:16:32 +00:00
|
|
|
|
bool CAutoFactory::Write(CLevelParserLine* line)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
if ( m_phase == AFP_WAIT ) return false;
|
2015-06-21 18:59:23 +00:00
|
|
|
|
|
2015-07-17 18:36:01 +00:00
|
|
|
|
line->AddParam("aExist", MakeUnique<CLevelParserParam>(true));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
CAuto::Write(line);
|
2015-07-17 18:36:01 +00:00
|
|
|
|
line->AddParam("aPhase", MakeUnique<CLevelParserParam>(static_cast<int>(m_phase)));
|
|
|
|
|
line->AddParam("aProgress", MakeUnique<CLevelParserParam>(m_progress));
|
|
|
|
|
line->AddParam("aSpeed", MakeUnique<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 CAutoFactory::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< AutoFactoryPhase >(line->GetParam("aPhase")->AsInt(AFP_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;
|
2015-07-12 09:01:16 +00:00
|
|
|
|
m_cargoPos = m_object->GetPosition();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Seeks the cargo.
|
|
|
|
|
|
2015-06-29 21:05:31 +00:00
|
|
|
|
CObject* CAutoFactory::SearchCargo()
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2015-01-08 17:56:26 +00:00
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
ObjectType type = obj->GetType();
|
2015-01-08 17:56:26 +00:00
|
|
|
|
if ( type != OBJECT_METAL ) continue;
|
2015-07-10 17:03:27 +00:00
|
|
|
|
if (IsObjectBeingTransported(obj)) continue;
|
2015-06-21 14:22:09 +00:00
|
|
|
|
|
2015-07-12 09:01:16 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition();
|
2015-06-29 21:05:31 +00:00
|
|
|
|
float dist = Math::Distance(oPos, m_cargoPos);
|
2015-06-21 14:22:09 +00:00
|
|
|
|
|
|
|
|
|
if ( dist < 8.0f ) return obj;
|
2015-01-08 17:56:26 +00:00
|
|
|
|
}
|
2015-06-21 14:22:09 +00:00
|
|
|
|
|
2015-01-08 17:56:26 +00:00
|
|
|
|
return 0;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Search if a vehicle is too close.
|
|
|
|
|
|
|
|
|
|
bool CAutoFactory::NearestVehicle()
|
|
|
|
|
{
|
2015-07-12 09:01:16 +00:00
|
|
|
|
Math::Vector cPos = m_object->GetPosition();
|
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 type = obj->GetType();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( type != OBJECT_HUMAN &&
|
|
|
|
|
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_MOTHER &&
|
|
|
|
|
type != OBJECT_ANT &&
|
|
|
|
|
type != OBJECT_SPIDER &&
|
|
|
|
|
type != OBJECT_BEE &&
|
|
|
|
|
type != OBJECT_WORM ) continue;
|
|
|
|
|
|
2015-07-10 07:26:38 +00:00
|
|
|
|
if (obj->GetCrashSphereCount() == 0) continue;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-07-10 07:26:38 +00:00
|
|
|
|
auto crashSphere = obj->GetFirstCrashSphere();
|
|
|
|
|
if (Math::DistanceToSphere(cPos, crashSphere.sphere) < 10.0f)
|
|
|
|
|
return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Creates a vehicle.
|
|
|
|
|
|
|
|
|
|
bool CAutoFactory::CreateVehicle()
|
|
|
|
|
{
|
2015-07-14 19:29:13 +00:00
|
|
|
|
float angle = m_object->GetRotationY();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2015-06-20 17:27:43 +00:00
|
|
|
|
Math::Vector pos;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( m_type == OBJECT_MOBILErt ||
|
|
|
|
|
m_type == OBJECT_MOBILErc ||
|
|
|
|
|
m_type == OBJECT_MOBILErr ||
|
|
|
|
|
m_type == OBJECT_MOBILErs )
|
|
|
|
|
{
|
|
|
|
|
pos = Math::Vector(2.0f, 0.0f, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pos = Math::Vector(4.0f, 0.0f, 0.0f);
|
|
|
|
|
}
|
2015-06-20 17:27:43 +00:00
|
|
|
|
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos = Transform(*mat, pos);
|
|
|
|
|
|
2015-07-22 10:45:50 +00:00
|
|
|
|
ObjectCreateParams params;
|
|
|
|
|
params.pos = pos;
|
|
|
|
|
params.angle = angle;
|
|
|
|
|
params.type = m_type;
|
|
|
|
|
params.team = m_object->GetTeam();
|
|
|
|
|
CObject* vehicle = CObjectManager::GetInstancePointer()->CreateObject(params);
|
2015-07-12 13:09:32 +00:00
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
|
vehicle->SetLock(true); // not usable
|
|
|
|
|
|
2015-06-20 17:27:43 +00:00
|
|
|
|
CPhysics* physics = vehicle->GetPhysics();
|
|
|
|
|
if ( physics != nullptr )
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
physics->SetFreeze(true); // it doesn't move
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-10 18:38:44 +00:00
|
|
|
|
if (vehicle->Implements(ObjectInterfaceType::Programmable))
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
2015-08-10 16:16:00 +00:00
|
|
|
|
CProgrammableObject* programmable = dynamic_cast<CProgrammableObject*>(vehicle);
|
2015-04-06 14:41:05 +00:00
|
|
|
|
for ( int i=0 ; ; i++ )
|
|
|
|
|
{
|
2015-06-20 17:27:43 +00:00
|
|
|
|
char* name = m_main->GetNewScriptName(m_type, i);
|
2015-04-06 14:41:05 +00:00
|
|
|
|
if ( name == nullptr ) break;
|
2015-08-10 16:16:00 +00:00
|
|
|
|
Program* prog = programmable->GetOrAddProgram(i);
|
|
|
|
|
programmable->ReadProgram(prog, name);
|
2015-04-06 14:41:05 +00:00
|
|
|
|
prog->readOnly = true;
|
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Seeking the vehicle during manufacture.
|
|
|
|
|
|
|
|
|
|
CObject* CAutoFactory::SearchVehicle()
|
2015-06-21 14:22:09 +00:00
|
|
|
|
{
|
|
|
|
|
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
2015-01-08 17:56:26 +00:00
|
|
|
|
{
|
2015-06-21 14:22:09 +00:00
|
|
|
|
if ( !obj->GetLock() ) continue;
|
|
|
|
|
|
|
|
|
|
ObjectType type = obj->GetType();
|
2015-01-08 17:56:26 +00:00
|
|
|
|
if ( type != m_type ) continue;
|
2015-07-10 17:03:27 +00:00
|
|
|
|
if (IsObjectBeingTransported(obj)) continue;
|
2015-06-21 14:22:09 +00:00
|
|
|
|
|
2015-07-12 09:01:16 +00:00
|
|
|
|
Math::Vector oPos = obj->GetPosition();
|
2015-06-29 21:05:31 +00:00
|
|
|
|
float dist = Math::Distance(oPos, m_cargoPos);
|
2015-06-21 14:22:09 +00:00
|
|
|
|
|
|
|
|
|
if ( dist < 8.0f ) return obj;
|
2015-01-08 17:56:26 +00:00
|
|
|
|
}
|
2015-06-21 14:22:09 +00:00
|
|
|
|
|
|
|
|
|
return nullptr;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Creates all the interface when the object is selected.
|
|
|
|
|
|
|
|
|
|
bool CAutoFactory::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, dim, 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));
|
|
|
|
|
if ( pw == nullptr ) return false;
|
2012-06-26 20:23: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 = 0.0f;
|
|
|
|
|
pos.y = oy+sy*2.6f;
|
|
|
|
|
ddim.x = 138.0f/640.0f;
|
|
|
|
|
ddim.y = 222.0f/480.0f;
|
|
|
|
|
pw->CreateGroup(pos, ddim, 6, EVENT_WINDOW3);
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*8.2f;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+9, EVENT_OBJECT_FACTORYwa);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+10, EVENT_OBJECT_FACTORYta);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+11, EVENT_OBJECT_FACTORYfa);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+22, EVENT_OBJECT_FACTORYia);
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*7.1f;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+12, EVENT_OBJECT_FACTORYws);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+13, EVENT_OBJECT_FACTORYts);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+14, EVENT_OBJECT_FACTORYfs);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+24, EVENT_OBJECT_FACTORYis);
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*6.0f;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+15, EVENT_OBJECT_FACTORYwc);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+16, EVENT_OBJECT_FACTORYtc);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+17, EVENT_OBJECT_FACTORYfc);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+23, EVENT_OBJECT_FACTORYic);
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*4.9f;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+25, EVENT_OBJECT_FACTORYwi);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+26, EVENT_OBJECT_FACTORYti);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+27, EVENT_OBJECT_FACTORYfi);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+28, EVENT_OBJECT_FACTORYii);
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*3.8f;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+18, EVENT_OBJECT_FACTORYrt);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+19, EVENT_OBJECT_FACTORYrc);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+20, EVENT_OBJECT_FACTORYrr);
|
|
|
|
|
pos.x += dim.x;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+29, EVENT_OBJECT_FACTORYrs);
|
|
|
|
|
|
|
|
|
|
pos.x = ox+sx*0.0f;
|
|
|
|
|
pos.y = oy+sy*2.7f;
|
|
|
|
|
pw->CreateButton(pos, dim, 128+21, EVENT_OBJECT_FACTORYsa);
|
|
|
|
|
|
|
|
|
|
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, 101, EVENT_OBJECT_TYPE);
|
|
|
|
|
|
|
|
|
|
UpdateInterface();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Updates the status of all interface buttons.
|
|
|
|
|
|
|
|
|
|
void CAutoFactory::UpdateInterface()
|
|
|
|
|
{
|
2012-09-09 12:28:19 +00:00
|
|
|
|
Ui::CWindow* pw;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
if ( !m_object->GetSelect() ) return;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
CAuto::UpdateInterface();
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYwa, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYta, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYfa, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYia, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYws, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYts, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYfs, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYis, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYwc, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYtc, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYfc, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYic, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYwi, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYti, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYfi, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYii, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYrt, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYrc, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYrr, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYrs, m_bBusy);
|
|
|
|
|
UpdateButton(pw, EVENT_OBJECT_FACTORYsa, m_bBusy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Updates the status of one interface button.
|
|
|
|
|
|
2012-09-09 12:28:19 +00:00
|
|
|
|
void CAutoFactory::UpdateButton(Ui::CWindow *pw, EventType event, bool bBusy)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
EnableInterface(pw, event, !bBusy);
|
2015-07-13 16:13:28 +00:00
|
|
|
|
DeadInterface(pw, event, m_main->CanFactory(ObjectTypeFromFactoryButton(event), m_object->GetTeam()));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Plays the sound of the manipulator arm.
|
|
|
|
|
|
|
|
|
|
void CAutoFactory::SoundManip(float time, float amplitude, float frequency)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2015-07-12 09:01:16 +00:00
|
|
|
|
i = m_sound->Play(SOUND_MANIP, m_object->GetPosition(), 0.0f, 0.3f*frequency, true);
|
2012-06-26 20:23: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);
|
|
|
|
|
}
|