2014-10-14 13:11:37 +00:00
/*
* This file is part of the Colobot : Gold Edition source code
2023-08-06 21:15:48 +00:00
* Copyright ( C ) 2001 - 2023 , Daniel Roux , EPSITEC SA & TerranovaTeam
2015-08-22 14:40:02 +00:00
* http : //epsitec.ch; http://colobot.info; http://github.com/colobot
2014-10-14 13:11:37 +00:00
*
* 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
2012-09-22 12:40:13 +00:00
2015-07-02 21:48:30 +00:00
# include "object/old_object.h"
2012-06-26 20:23:05 +00:00
2012-09-22 12:40:13 +00:00
# include "app/app.h"
2012-06-26 20:23:05 +00:00
# include "common/global.h"
2015-10-01 17:19:40 +00:00
# include "common/settings.h"
2015-07-22 10:45:50 +00:00
# include "common/stringutils.h"
2012-09-10 21:29:38 +00:00
2022-02-26 02:53:39 +00:00
# include "graphics/engine/engine.h"
2012-09-10 21:29:38 +00:00
# include "graphics/engine/lightman.h"
# include "graphics/engine/lightning.h"
# include "graphics/engine/particle.h"
2015-06-22 19:58:58 +00:00
# include "graphics/engine/pyro_manager.h"
2012-09-10 21:29:38 +00:00
# include "graphics/engine/terrain.h"
2015-08-13 09:47:32 +00:00
# include "level/robotmain.h"
2017-05-17 16:22:27 +00:00
# include "level/scoreboard.h"
2015-08-13 09:47:32 +00:00
# include "level/parser/parserexceptions.h"
# include "level/parser/parserline.h"
# include "level/parser/parserparam.h"
2012-09-10 21:29:38 +00:00
# include "math/geometry.h"
2015-06-20 18:02:40 +00:00
# include "object/object_manager.h"
2015-08-02 11:09:48 +00:00
# include "object/auto/auto.h"
2015-08-14 16:19:58 +00:00
# include "object/auto/autobase.h"
2015-08-02 11:09:48 +00:00
# include "object/auto/autojostle.h"
# include "object/motion/motion.h"
# include "object/motion/motionvehicle.h"
2012-09-10 21:29:38 +00:00
2015-08-17 11:19:21 +00:00
# include "object/subclass/base_alien.h"
2015-08-14 16:19:58 +00:00
# include "object/subclass/exchange_post.h"
2012-09-10 21:29:38 +00:00
# include "physics/physics.h"
# include "script/cbottoken.h"
2015-08-10 16:16:00 +00:00
# include "script/script.h"
2015-07-22 11:24:16 +00:00
# include "script/scriptfunc.h"
2012-09-10 21:29:38 +00:00
2015-08-10 14:37:03 +00:00
# include "ui/object_interface.h"
2015-08-10 16:16:00 +00:00
# include "ui/studio.h"
# include "ui/controls/edit.h"
2015-08-10 14:37:03 +00:00
2015-08-10 16:16:00 +00:00
# include <iomanip>
2014-11-10 13:16:32 +00:00
2012-06-26 20:23:05 +00:00
const float VIRUS_DELAY = 60.0f ; // duration of virus infection
// Object's constructor.
2015-07-02 21:48:30 +00:00
COldObject : : COldObject ( int id )
2015-08-14 21:11:24 +00:00
: CObject ( id , OBJECT_NULL ) ,
CInteractiveObject ( m_implementedInterfaces ) ,
CTransportableObject ( m_implementedInterfaces ) ,
CTaskExecutorObjectImpl ( m_implementedInterfaces , this ) ,
2015-08-15 19:29:08 +00:00
CProgramStorageObjectImpl ( m_implementedInterfaces , this ) ,
2015-08-14 21:11:24 +00:00
CProgrammableObjectImpl ( m_implementedInterfaces , this ) ,
CJostleableObject ( m_implementedInterfaces ) ,
2022-01-29 16:16:57 +00:00
CSlottedObject ( m_implementedInterfaces ) ,
2015-08-14 21:11:24 +00:00
CJetFlyingObject ( m_implementedInterfaces ) ,
CControllableObject ( m_implementedInterfaces ) ,
CPowerContainerObjectImpl ( m_implementedInterfaces ) ,
CRangedObject ( m_implementedInterfaces ) ,
CTraceDrawingObject ( m_implementedInterfaces ) ,
CShieldedAutoRegenObject ( m_implementedInterfaces ) ,
m_partiSel ( )
2012-06-26 20:23:05 +00:00
{
2015-08-10 16:16:00 +00:00
// A bit of a hack since we don't have subclasses yet, set externally in SetProgrammable()
2015-08-15 19:29:08 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : ProgramStorage ) ] = false ;
2015-07-10 18:38:44 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Programmable ) ] = false ;
2015-08-13 08:49:26 +00:00
// Another hack, see SetMovable()
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Movable ) ] = false ;
2015-07-10 20:11:22 +00:00
// Another hack
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Jostleable ) ] = false ;
2015-07-10 18:38:44 +00:00
2015-07-11 17:48:37 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Old ) ] = true ;
2015-06-29 20:45:38 +00:00
m_sound = CApplication : : GetInstancePointer ( ) - > GetSound ( ) ;
2013-02-16 21:37:43 +00:00
m_engine = Gfx : : CEngine : : GetInstancePointer ( ) ;
m_lightMan = m_engine - > GetLightManager ( ) ;
m_particle = m_engine - > GetParticle ( ) ;
m_main = CRobotMain : : GetInstancePointer ( ) ;
m_terrain = m_main - > GetTerrain ( ) ;
m_camera = m_main - > GetCamera ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-18 09:42:55 +00:00
m_type = OBJECT_NULL ;
2012-06-26 20:23:05 +00:00
m_option = 0 ;
2015-06-25 17:05:56 +00:00
m_name = " " ;
2012-06-26 20:23:05 +00:00
m_shadowLight = - 1 ;
2015-08-14 21:11:24 +00:00
m_shadowHeight = 0.0f ;
2022-01-03 21:51:36 +00:00
m_linVibration = glm : : vec3 ( 0.0f , 0.0f , 0.0f ) ;
m_cirVibration = glm : : vec3 ( 0.0f , 0.0f , 0.0f ) ;
m_tilt = glm : : vec3 ( 0.0f , 0.0f , 0.0f ) ;
2012-06-26 20:23:05 +00:00
2015-08-17 20:40:52 +00:00
m_power = nullptr ;
m_cargo = nullptr ;
m_transporter = nullptr ;
2015-06-29 21:05:31 +00:00
m_transporterLink = 0 ;
2012-06-26 20:23:05 +00:00
m_shield = 1.0f ;
2015-08-12 17:09:35 +00:00
m_range = 30.0f ;
2012-06-26 20:23:05 +00:00
m_lastEnergy = 999.9f ;
m_bSelect = false ;
m_bSelectable = true ;
m_bCheckToken = true ;
2015-08-16 18:24:48 +00:00
m_underground = false ;
2012-06-26 20:23:05 +00:00
m_bTrainer = false ;
m_bToy = false ;
m_bManual = false ;
m_aTime = 0.0f ;
m_shotTime = 0.0f ;
m_bVirusMode = false ;
m_virusTime = 0.0f ;
2012-09-10 21:29:38 +00:00
m_lastVirusParticle = 0.0f ;
2017-06-20 21:35:33 +00:00
m_damaging = false ;
2018-04-19 23:31:11 +00:00
m_damageTime = 0.0f ;
2015-08-16 18:24:48 +00:00
m_dying = DeathType : : Alive ;
2012-06-26 20:23:05 +00:00
m_bFlat = false ;
m_gunGoalV = 0.0f ;
m_gunGoalH = 0.0f ;
m_shieldRadius = 0.0f ;
m_magnifyDamage = 1.0f ;
2022-01-29 16:16:57 +00:00
m_hasPowerSlot = false ;
m_hasCargoSlot = false ;
2012-06-26 20:23:05 +00:00
2015-08-06 07:33:37 +00:00
m_character = Character ( ) ;
2012-06-26 20:23:05 +00:00
m_character . wheelFront = 1.0f ;
m_character . wheelBack = 1.0f ;
m_character . wheelLeft = 1.0f ;
m_character . wheelRight = 1.0f ;
2012-09-10 21:29:38 +00:00
m_cameraType = Gfx : : CAM_TYPE_BACK ;
2012-06-26 20:23:05 +00:00
m_bCameraLock = false ;
2013-02-16 21:37:43 +00:00
for ( int i = 0 ; i < OBJECTMAXPART ; i + + )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ i ] . bUsed = false ;
}
m_totalPart = 0 ;
2013-02-16 21:37:43 +00:00
for ( int i = 0 ; i < 4 ; i + + )
2012-06-26 20:23:05 +00:00
{
m_partiSel [ i ] = - 1 ;
}
2015-08-10 16:16:00 +00:00
m_time = 0.0f ;
m_burnTime = 0.0f ;
m_buttonAxe = EVENT_NULL ;
2015-08-13 08:49:26 +00:00
m_reactorRange = 1.0f ;
m_traceDown = false ;
m_traceColor = TraceColor : : Black ;
m_traceWidth = 0.5f ;
2015-07-10 07:26:38 +00:00
DeleteAllCrashSpheres ( ) ;
2012-06-26 20:23:05 +00:00
}
// Object's destructor.
2015-07-02 21:48:30 +00:00
COldObject : : ~ COldObject ( )
2012-06-26 20:23:05 +00:00
{
2016-01-30 17:01:09 +00:00
m_main - > HideDropZone ( this ) ;
2012-06-26 20:23:05 +00:00
}
// Removes an object.
// If bAll = true, it does not help,
// because all objects in the scene are quickly destroyed!
2015-07-02 21:48:30 +00:00
void COldObject : : DeleteObject ( bool bAll )
2012-06-26 20:23:05 +00:00
{
2015-07-22 11:24:16 +00:00
CScriptFunctions : : DestroyObjectVar ( m_botVar , false ) ;
2012-06-26 20:23:05 +00:00
2012-09-17 18:47:27 +00:00
if ( m_camera - > GetControllingObject ( ) = = this )
2012-06-26 20:23:05 +00:00
{
2015-08-17 20:40:52 +00:00
m_camera - > SetControllingObject ( nullptr ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-14 20:05:12 +00:00
m_main - > RemoveFromSelectionHistory ( this ) ;
2012-06-26 20:23:05 +00:00
if ( ! bAll )
{
2015-06-22 19:58:58 +00:00
m_engine - > GetPyroManager ( ) - > CutObjectLink ( this ) ;
2017-05-23 18:31:55 +00:00
m_particle - > CutObjectLink ( this ) ;
2012-06-26 20:23:05 +00:00
if ( m_bSelect )
{
SetSelect ( false ) ;
}
if ( m_type = = OBJECT_BASE | |
m_type = = OBJECT_FACTORY | |
m_type = = OBJECT_REPAIR | |
m_type = = OBJECT_DESTROYER | |
m_type = = OBJECT_DERRICK | |
m_type = = OBJECT_STATION | |
m_type = = OBJECT_CONVERT | |
m_type = = OBJECT_TOWER | |
m_type = = OBJECT_RESEARCH | |
m_type = = OBJECT_RADAR | |
m_type = = OBJECT_INFO | |
m_type = = OBJECT_ENERGY | |
m_type = = OBJECT_LABO | |
m_type = = OBJECT_NUCLEAR | |
m_type = = OBJECT_PARA | |
m_type = = OBJECT_SAFE | |
m_type = = OBJECT_HUSTON | |
m_type = = OBJECT_START | |
m_type = = OBJECT_END ) // building?
{
2015-07-12 09:01:16 +00:00
m_terrain - > DeleteBuildingLevel ( GetPosition ( ) ) ; // flattens the field
2012-06-26 20:23:05 +00:00
}
}
m_type = OBJECT_NULL ; // invalid object until complete destruction
if ( m_shadowLight ! = - 1 )
{
2012-09-10 21:29:38 +00:00
m_lightMan - > DeleteLight ( m_shadowLight ) ;
2012-06-26 20:23:05 +00:00
m_shadowLight = - 1 ;
}
2015-06-22 19:58:58 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_physics - > DeleteObject ( bAll ) ;
}
2015-08-10 14:37:03 +00:00
if ( m_objectInterface ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-08-10 14:37:03 +00:00
m_objectInterface - > DeleteObject ( bAll ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-22 19:58:58 +00:00
if ( m_motion ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_motion - > DeleteObject ( bAll ) ;
}
2015-06-22 19:58:58 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_auto - > DeleteObject ( bAll ) ;
}
2013-02-16 21:37:43 +00:00
for ( int i = 0 ; i < OBJECTMAXPART ; i + + )
2012-06-26 20:23:05 +00:00
{
if ( m_objectPart [ i ] . bUsed )
{
m_objectPart [ i ] . bUsed = false ;
m_engine - > DeleteObject ( m_objectPart [ i ] . object ) ;
if ( m_objectPart [ i ] . masterParti ! = - 1 )
{
2012-09-10 21:29:38 +00:00
m_particle - > DeleteParticle ( m_objectPart [ i ] . masterParti ) ;
2012-06-26 20:23:05 +00:00
m_objectPart [ i ] . masterParti = - 1 ;
}
}
}
2015-09-30 18:54:36 +00:00
if ( ! bAll )
{
if ( m_power ! = nullptr )
{
if ( m_power - > Implements ( ObjectInterfaceType : : Old ) )
2018-10-10 17:14:23 +00:00
{
2020-09-14 19:19:16 +00:00
dynamic_cast < COldObject & > ( * m_power ) . SetTransporter ( nullptr ) ;
2018-10-10 17:14:23 +00:00
}
2023-11-18 18:46:25 +00:00
CObjectManager : : GetInstance ( ) . DeleteObject ( m_power ) ;
2015-09-30 18:54:36 +00:00
m_power = nullptr ;
}
if ( m_cargo ! = nullptr )
{
if ( m_cargo - > Implements ( ObjectInterfaceType : : Old ) )
2018-10-10 17:14:23 +00:00
{
2020-09-14 19:19:16 +00:00
dynamic_cast < COldObject & > ( * m_cargo ) . SetTransporter ( nullptr ) ;
2018-10-10 17:14:23 +00:00
}
2023-11-18 18:46:25 +00:00
CObjectManager : : GetInstance ( ) . DeleteObject ( m_cargo ) ;
2015-09-30 18:54:36 +00:00
m_cargo = nullptr ;
}
}
2012-06-26 20:23:05 +00:00
if ( ! bAll ) m_main - > CreateShortcuts ( ) ;
}
2015-08-13 11:41:25 +00:00
// Simplifies a object (destroys all logic classes, making it a static object)
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
void COldObject : : Simplify ( )
2012-06-26 20:23:05 +00:00
{
2015-08-10 16:16:00 +00:00
if ( Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2015-08-10 16:16:00 +00:00
StopProgram ( ) ;
2012-06-26 20:23:05 +00:00
}
m_main - > SaveOneScript ( this ) ;
2015-08-15 19:29:08 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : ProgramStorage ) ] = false ;
2015-08-10 16:16:00 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Programmable ) ] = false ;
2015-06-22 19:58:58 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_physics - > DeleteObject ( ) ;
2015-06-22 19:58:58 +00:00
m_physics . reset ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 11:41:25 +00:00
if ( m_motion ! = nullptr )
{
m_motion - > DeleteObject ( ) ;
m_motion . reset ( ) ;
}
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Movable ) ] = false ;
2012-06-26 20:23:05 +00:00
2015-08-10 14:37:03 +00:00
if ( m_objectInterface ! = nullptr )
{
m_objectInterface - > DeleteObject ( ) ;
m_objectInterface . reset ( ) ;
}
2015-06-22 19:58:58 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_auto - > DeleteObject ( ) ;
2015-06-22 19:58:58 +00:00
m_auto . reset ( ) ;
2012-06-26 20:23:05 +00:00
}
m_main - > CreateShortcuts ( ) ;
}
2017-05-17 16:22:27 +00:00
bool COldObject : : DamageObject ( DamageType type , float force , CObject * killer )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
assert ( Implements ( ObjectInterfaceType : : Damageable ) ) ;
assert ( ! Implements ( ObjectInterfaceType : : Destroyable ) | | Implements ( ObjectInterfaceType : : Shielded ) | | Implements ( ObjectInterfaceType : : Fragile ) ) ;
2015-08-16 18:24:48 +00:00
if ( IsDying ( ) ) return false ;
2020-07-13 17:44:50 +00:00
if ( Implements ( ObjectInterfaceType : : Jostleable ) ) return false ;
2012-06-26 20:23:05 +00:00
2015-08-13 16:54:44 +00:00
if ( m_type = = OBJECT_ANT | |
m_type = = OBJECT_WORM | |
m_type = = OBJECT_SPIDER | |
m_type = = OBJECT_BEE )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
// Fragile, but can have fire effect
// TODO: IsBurnable()
force = - 1.0f ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 16:54:44 +00:00
else if ( Implements ( ObjectInterfaceType : : Fragile ) )
{
2019-07-17 00:57:47 +00:00
if ( ( m_type = = OBJECT_BOMB | |
m_type = = OBJECT_RUINmobilew1 | |
m_type = = OBJECT_RUINmobilew2 | |
m_type = = OBJECT_RUINmobilet1 | |
m_type = = OBJECT_RUINmobilet2 | |
m_type = = OBJECT_RUINmobiler1 | |
m_type = = OBJECT_RUINmobiler2 | |
m_type = = OBJECT_RUINfactory | |
m_type = = OBJECT_RUINdoor | |
m_type = = OBJECT_RUINsupport | |
m_type = = OBJECT_RUINradar | |
m_type = = OBJECT_RUINconvert ) & & type ! = DamageType : : Explosive ) return false ; // Mines and ruins can't be destroyed by shooting
2018-05-07 18:21:57 +00:00
if ( m_type = = OBJECT_URANIUM & & ( type = = DamageType : : Fire | | type = = DamageType : : Organic ) ) return false ; // UraniumOre is not destroyable by shooting or aliens (see #777)
if ( m_type = = OBJECT_STONE & & ( type = = DamageType : : Fire | | type = = DamageType : : Organic ) ) return false ; // TitaniumOre is not destroyable either
// PowerCell, NuclearCell and Titanium are destroyable by shooting, but not by collisions!
if ( m_type = = OBJECT_METAL & & type = = DamageType : : Collision ) return false ;
if ( m_type = = OBJECT_POWER & & type = = DamageType : : Collision ) return false ;
if ( m_type = = OBJECT_NUCLEAR & & type = = DamageType : : Collision ) return false ;
2015-08-13 16:54:44 +00:00
2018-05-07 18:23:53 +00:00
if ( m_magnifyDamage * m_main - > GetGlobalMagnifyDamage ( ) = = 0 ) return false ; // Don't destroy if magnifyDamage=0
2015-08-13 16:54:44 +00:00
2017-05-17 16:22:27 +00:00
DestroyObject ( DestructionType : : Explosion , killer ) ;
2015-08-13 16:54:44 +00:00
return true ;
}
if ( type ! = DamageType : : Phazer & & m_type = = OBJECT_MOTHER ) return false ; // AlienQueen can be destroyed only by PhazerShooter
2012-06-26 20:23:05 +00:00
2015-08-13 16:54:44 +00:00
if ( type = = DamageType : : Organic )
2012-06-26 20:23:05 +00:00
{
2015-08-13 11:41:25 +00:00
// TODO: I don't understand, why does it apply damage only once every 0.5 second?
2012-06-26 20:23:05 +00:00
if ( m_shotTime < 0.5f ) return false ;
m_shotTime = 0.0f ;
}
2015-08-13 11:41:25 +00:00
float loss = 1.0f ;
2015-08-13 16:54:44 +00:00
bool dead = true ;
if ( Implements ( ObjectInterfaceType : : Shielded ) )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
float magnifyDamage = m_magnifyDamage * m_main - > GetGlobalMagnifyDamage ( ) ;
2015-08-13 17:46:30 +00:00
if ( force ! = std : : numeric_limits < float > : : infinity ( ) )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
// Calculate the shield lost by the explosion
2015-08-17 20:05:26 +00:00
loss = force * magnifyDamage ;
2015-08-25 15:03:18 +00:00
if ( m_type = = OBJECT_HUMAN ) loss / = 2.5f ; // Me is more resistant
2015-08-13 16:54:44 +00:00
if ( loss > 1.0f ) loss = 1.0f ;
// Decreases the the shield
float shield = GetShield ( ) ;
shield - = loss ;
SetShield ( shield ) ;
2017-06-20 21:35:33 +00:00
// Sending info about taking damage
2017-10-17 00:33:05 +00:00
if ( ! m_damaging )
{
SetDamaging ( true ) ;
m_main - > UpdateShortcuts ( ) ;
}
m_damageTime = m_time ;
2015-08-13 16:54:44 +00:00
}
else
{
if ( magnifyDamage ! = 0.0f )
2015-08-13 11:41:25 +00:00
{
2015-08-13 16:54:44 +00:00
// Dead immediately
SetShield ( 0.0f ) ;
2017-06-20 21:35:33 +00:00
SetDamaging ( false ) ;
2015-08-13 11:41:25 +00:00
}
2012-06-26 20:23:05 +00:00
}
2015-08-13 16:54:44 +00:00
dead = ( GetShield ( ) < = 0.0f ) ;
}
2012-06-26 20:23:05 +00:00
2015-08-13 16:54:44 +00:00
if ( dead & & Implements ( ObjectInterfaceType : : Destroyable ) )
{
if ( type = = DamageType : : Fire )
{
2017-05-17 16:22:27 +00:00
DestroyObject ( DestructionType : : Burn , killer ) ;
2015-08-13 16:54:44 +00:00
}
else
{
2017-05-17 16:22:27 +00:00
DestroyObject ( DestructionType : : Explosion , killer ) ;
2015-08-13 16:54:44 +00:00
}
return true ;
}
2012-06-26 20:23:05 +00:00
2015-08-13 16:54:44 +00:00
if ( m_type = = OBJECT_HUMAN )
{
m_engine - > GetPyroManager ( ) - > Create ( Gfx : : PT_SHOTH , this , loss ) ;
}
else if ( m_type = = OBJECT_MOTHER )
{
m_engine - > GetPyroManager ( ) - > Create ( Gfx : : PT_SHOTM , this , loss ) ;
}
else
{
m_engine - > GetPyroManager ( ) - > Create ( Gfx : : PT_SHOTT , this , loss ) ;
2015-08-13 11:41:25 +00:00
}
2015-08-13 16:54:44 +00:00
return false ;
}
2017-05-17 16:22:27 +00:00
void COldObject : : DestroyObject ( DestructionType type , CObject * killer )
2015-08-13 16:54:44 +00:00
{
assert ( Implements ( ObjectInterfaceType : : Destroyable ) ) ;
if ( type = = DestructionType : : NoEffect ) assert ( ! ! " DestructionType::NoEffect should not be passed to DestroyObject()! " ) ;
assert ( type ! = DestructionType : : Drowned | | m_type = = OBJECT_HUMAN ) ;
2015-08-16 18:24:48 +00:00
if ( IsDying ( ) ) return ;
2015-08-13 16:54:44 +00:00
if ( Implements ( ObjectInterfaceType : : Shielded ) )
{
SetShield ( 0.0f ) ;
2017-06-20 21:35:33 +00:00
SetDamaging ( false ) ;
2015-08-13 16:54:44 +00:00
}
2015-08-14 17:08:26 +00:00
Gfx : : PyroType pyroType = Gfx : : PT_NULL ;
2015-08-13 16:54:44 +00:00
if ( type = = DestructionType : : Explosion ) // explosion?
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
if ( m_type = = OBJECT_ANT | |
m_type = = OBJECT_SPIDER | |
m_type = = OBJECT_BEE | |
m_type = = OBJECT_WORM )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
pyroType = Gfx : : PT_EXPLOO ;
}
else if ( m_type = = OBJECT_MOTHER | |
m_type = = OBJECT_NEST | |
m_type = = OBJECT_BULLET )
{
pyroType = Gfx : : PT_FRAGO ;
}
else if ( m_type = = OBJECT_HUMAN )
{
pyroType = Gfx : : PT_DEADG ;
}
else if ( m_type = = OBJECT_BASE | |
m_type = = OBJECT_DERRICK | |
m_type = = OBJECT_FACTORY | |
m_type = = OBJECT_STATION | |
m_type = = OBJECT_CONVERT | |
m_type = = OBJECT_REPAIR | |
m_type = = OBJECT_DESTROYER | |
m_type = = OBJECT_TOWER | |
m_type = = OBJECT_NEST | |
m_type = = OBJECT_RESEARCH | |
m_type = = OBJECT_RADAR | |
m_type = = OBJECT_INFO | |
m_type = = OBJECT_ENERGY | |
m_type = = OBJECT_LABO | |
m_type = = OBJECT_NUCLEAR | |
m_type = = OBJECT_PARA | |
m_type = = OBJECT_SAFE | |
m_type = = OBJECT_HUSTON | |
m_type = = OBJECT_START | |
2018-07-13 11:16:30 +00:00
m_type = = OBJECT_END | |
m_type = = OBJECT_RUINfactory | |
m_type = = OBJECT_RUINdoor | |
m_type = = OBJECT_RUINsupport | |
m_type = = OBJECT_RUINradar | |
m_type = = OBJECT_RUINconvert ) // building?
2015-08-13 16:54:44 +00:00
{
pyroType = Gfx : : PT_FRAGT ;
}
else if ( m_type = = OBJECT_MOBILEtg )
{
pyroType = Gfx : : PT_FRAGT ;
2012-06-26 20:23:05 +00:00
}
else
{
2015-08-13 16:54:44 +00:00
pyroType = Gfx : : PT_EXPLOT ;
2012-06-26 20:23:05 +00:00
}
}
2015-08-13 16:54:44 +00:00
else if ( type = = DestructionType : : ExplosionWater )
{
pyroType = Gfx : : PT_FRAGW ;
}
else if ( type = = DestructionType : : Burn ) // burning?
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
if ( m_type = = OBJECT_MOTHER | |
m_type = = OBJECT_ANT | |
m_type = = OBJECT_SPIDER | |
m_type = = OBJECT_BEE | |
m_type = = OBJECT_WORM | |
m_type = = OBJECT_BULLET )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
pyroType = Gfx : : PT_BURNO ;
2015-08-16 18:24:48 +00:00
SetDying ( DeathType : : Burning ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 16:54:44 +00:00
else if ( m_type = = OBJECT_HUMAN )
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
pyroType = Gfx : : PT_DEADG ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 16:54:44 +00:00
else
2012-06-26 20:23:05 +00:00
{
2015-08-13 16:54:44 +00:00
pyroType = Gfx : : PT_BURNT ;
2015-08-16 18:24:48 +00:00
SetDying ( DeathType : : Burning ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 16:54:44 +00:00
SetVirusMode ( false ) ;
2015-08-13 11:41:25 +00:00
}
2015-08-13 16:54:44 +00:00
else if ( type = = DestructionType : : Drowned )
2015-08-13 11:41:25 +00:00
{
2015-08-13 16:54:44 +00:00
pyroType = Gfx : : PT_DEADW ;
2012-06-26 20:23:05 +00:00
}
2017-05-17 16:22:27 +00:00
else if ( type = = DestructionType : : Win )
{
pyroType = Gfx : : PT_WPCHECK ;
}
2020-07-13 17:44:50 +00:00
else if ( type = = DestructionType : : Squash )
{
pyroType = Gfx : : PT_SQUASH ;
DeleteAllCrashSpheres ( ) ;
}
2015-08-14 17:08:26 +00:00
assert ( pyroType ! = Gfx : : PT_NULL ) ;
2017-05-24 08:45:31 +00:00
if ( pyroType = = Gfx : : PT_FRAGT | |
pyroType = = Gfx : : PT_FRAGO | |
pyroType = = Gfx : : PT_FRAGW )
{
SetDying ( DeathType : : Exploding ) ;
}
2015-08-13 16:54:44 +00:00
m_engine - > GetPyroManager ( ) - > Create ( pyroType , this ) ;
2012-06-26 20:23:05 +00:00
2015-08-13 11:41:25 +00:00
if ( Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2015-08-13 11:41:25 +00:00
StopProgram ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 11:41:25 +00:00
m_main - > SaveOneScript ( this ) ;
2012-06-26 20:23:05 +00:00
2012-09-10 21:29:38 +00:00
if ( GetSelect ( ) )
2012-06-26 20:23:05 +00:00
{
SetSelect ( false ) ; // deselects the object
2012-09-10 21:29:38 +00:00
m_camera - > SetType ( Gfx : : CAM_TYPE_EXPLO ) ;
2012-06-26 20:23:05 +00:00
m_main - > DeselectAll ( ) ;
}
2015-07-14 20:05:12 +00:00
m_main - > RemoveFromSelectionHistory ( this ) ;
2012-06-26 21:01:17 +00:00
2017-05-17 16:22:27 +00:00
CScoreboard * scoreboard = m_main - > GetScoreboard ( ) ;
if ( scoreboard )
scoreboard - > ProcessKill ( this , killer ) ;
2015-07-22 10:45:50 +00:00
m_team = 0 ; // Back to neutral on destruction
2015-07-15 16:49:15 +00:00
2015-08-11 15:51:39 +00:00
if ( m_botVar ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-08-18 10:29:41 +00:00
if ( Implements ( ObjectInterfaceType : : Transportable ) ) // (*)
2012-06-26 20:23:05 +00:00
{
2015-07-22 11:24:16 +00:00
CScriptFunctions : : DestroyObjectVar ( m_botVar , false ) ;
2012-06-26 20:23:05 +00:00
}
}
}
// (*) If a robot or cosmonaut dies, the subject must continue to exist,
// so that programs of the ants continue to operate as usual.
// Initializes a new part.
2015-07-02 21:48:30 +00:00
void COldObject : : InitPart ( int part )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bUsed = true ;
m_objectPart [ part ] . object = - 1 ;
m_objectPart [ part ] . parentPart = - 1 ;
2022-01-03 21:51:36 +00:00
m_objectPart [ part ] . position = glm : : vec3 ( 0.0f , 0.0f , 0.0f ) ;
2012-06-26 20:23:05 +00:00
m_objectPart [ part ] . angle . y = 0.0f ;
m_objectPart [ part ] . angle . x = 0.0f ;
m_objectPart [ part ] . angle . z = 0.0f ;
2022-01-03 21:51:36 +00:00
m_objectPart [ part ] . zoom = glm : : vec3 ( 1.0f , 1.0f , 1.0f ) ;
2012-06-26 20:23:05 +00:00
m_objectPart [ part ] . bTranslate = true ;
m_objectPart [ part ] . bRotate = true ;
m_objectPart [ part ] . bZoom = false ;
2022-01-04 23:35:41 +00:00
m_objectPart [ part ] . matTranslate = glm : : mat4 ( 1.0f ) ;
m_objectPart [ part ] . matRotate = glm : : mat4 ( 1.0f ) ;
m_objectPart [ part ] . matTransform = glm : : mat4 ( 1.0f ) ;
m_objectPart [ part ] . matWorld = glm : : mat4 ( 1.0f ) ;
2012-06-26 20:23:05 +00:00
m_objectPart [ part ] . masterParti = - 1 ;
}
// Removes part.
2015-07-02 21:48:30 +00:00
void COldObject : : DeletePart ( int part )
2012-06-26 20:23:05 +00:00
{
if ( ! m_objectPart [ part ] . bUsed ) return ;
if ( m_objectPart [ part ] . masterParti ! = - 1 )
{
2012-09-10 21:29:38 +00:00
m_particle - > DeleteParticle ( m_objectPart [ part ] . masterParti ) ;
2012-06-26 20:23:05 +00:00
m_objectPart [ part ] . masterParti = - 1 ;
}
m_objectPart [ part ] . bUsed = false ;
m_engine - > DeleteObject ( m_objectPart [ part ] . object ) ;
UpdateTotalPart ( ) ;
}
2015-07-02 21:48:30 +00:00
void COldObject : : UpdateTotalPart ( )
2012-06-26 20:23:05 +00:00
{
int i ;
m_totalPart = 0 ;
for ( i = 0 ; i < OBJECTMAXPART ; i + + )
{
if ( m_objectPart [ i ] . bUsed )
{
m_totalPart = i + 1 ;
}
}
}
// Specifies the number of the object of a part.
2015-07-02 21:48:30 +00:00
void COldObject : : SetObjectRank ( int part , int objRank )
2012-06-26 20:23:05 +00:00
{
if ( ! m_objectPart [ part ] . bUsed ) // object not created?
{
InitPart ( part ) ;
UpdateTotalPart ( ) ;
}
m_objectPart [ part ] . object = objRank ;
}
2012-10-17 19:55:45 +00:00
// Returns the number of part.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
int COldObject : : GetObjectRank ( int part )
2012-06-26 20:23:05 +00:00
{
if ( ! m_objectPart [ part ] . bUsed ) return - 1 ;
return m_objectPart [ part ] . object ;
}
// Specifies what is the parent of a part.
// Reminder: Part 0 is always the father of all
// and therefore the main part (eg the chassis of a car).
2015-07-02 21:48:30 +00:00
void COldObject : : SetObjectParent ( int part , int parent )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . parentPart = parent ;
}
// Specifies the type of the object.
2015-07-02 21:48:30 +00:00
void COldObject : : SetType ( ObjectType type )
2012-06-26 20:23:05 +00:00
{
m_type = type ;
2015-06-25 17:05:56 +00:00
m_name = GetObjectName ( m_type ) ;
2012-06-26 20:23:05 +00:00
2018-05-09 21:25:52 +00:00
SetSelectable ( IsSelectableByDefault ( m_type ) ) ;
2015-08-12 17:09:35 +00:00
// TODO: Temporary hack
if ( m_type = = OBJECT_MOBILEfa | | // WingedGrabber
2017-11-16 17:43:45 +00:00
m_type = = OBJECT_MOBILEfb | | // WingedBuilder
2015-08-12 17:09:35 +00:00
m_type = = OBJECT_MOBILEfs | | // WingedSniffer
m_type = = OBJECT_MOBILEfc | | // WingedShooter
m_type = = OBJECT_MOBILEfi | | // WingedOrgaShooter
2017-12-21 00:49:56 +00:00
m_type = = OBJECT_MOBILEft | | // WingedTrainer
2015-08-12 17:09:35 +00:00
m_type = = OBJECT_HUMAN | | // Me
2016-01-30 16:24:02 +00:00
m_type = = OBJECT_TECH | | // Tech
m_type = = OBJECT_CONTROLLER )
2015-08-12 17:09:35 +00:00
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Flying ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : JetFlying ) ] = true ;
}
else if ( m_type = = OBJECT_BEE )
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Flying ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : JetFlying ) ] = false ;
}
else
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Flying ) ] = false ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : JetFlying ) ] = false ;
}
// TODO: Another temporary hack
2015-08-13 17:41:21 +00:00
if ( m_type = = OBJECT_MOBILEfa | |
m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEia | |
2017-11-16 17:43:45 +00:00
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib | |
2015-08-13 17:41:21 +00:00
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILEfs | |
m_type = = OBJECT_MOBILEts | |
m_type = = OBJECT_MOBILEws | |
m_type = = OBJECT_MOBILEis | |
m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEtg | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEit | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErp | |
m_type = = OBJECT_MOBILEst | |
2015-08-13 17:41:21 +00:00
m_type = = OBJECT_TOWER | |
m_type = = OBJECT_RESEARCH | |
2022-01-29 16:16:57 +00:00
m_type = = OBJECT_ENERGY | | // TODO not actually a power cell slot
m_type = = OBJECT_LABO | | // TODO not actually a power cell slot
m_type = = OBJECT_NUCLEAR ) // TODO not actually a power cell slot
{
m_hasPowerSlot = true ;
}
else
{
m_hasPowerSlot = false ;
}
if ( m_type = = OBJECT_HUMAN | |
m_type = = OBJECT_TECH | |
m_type = = OBJECT_MOBILEfa | | // Grabbers
m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEia | |
2023-05-07 18:43:43 +00:00
m_type = = OBJECT_MOBILEsa | | // subber
m_type = = OBJECT_BEE )
2015-08-12 17:09:35 +00:00
{
2022-01-29 16:16:57 +00:00
m_hasCargoSlot = true ;
2015-08-12 17:09:35 +00:00
}
else
{
2022-01-29 16:16:57 +00:00
m_hasCargoSlot = false ;
2015-08-12 17:09:35 +00:00
}
2022-01-29 16:16:57 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Slotted ) ] = ( m_hasPowerSlot | | m_hasCargoSlot ) ;
2015-08-13 11:41:25 +00:00
// TODO: Hacking some more
if ( m_type = = OBJECT_MOBILEtg | |
2016-02-13 20:15:15 +00:00
m_type = = OBJECT_STONE | |
2015-08-13 11:41:25 +00:00
m_type = = OBJECT_METAL | |
2016-02-13 20:15:15 +00:00
m_type = = OBJECT_URANIUM | |
2015-08-13 11:41:25 +00:00
m_type = = OBJECT_POWER | |
m_type = = OBJECT_ATOMIC | |
m_type = = OBJECT_TNT | |
m_type = = OBJECT_BULLET | |
2015-08-13 16:54:44 +00:00
m_type = = OBJECT_EGG | |
m_type = = OBJECT_BOMB | |
m_type = = OBJECT_ANT | |
m_type = = OBJECT_WORM | |
m_type = = OBJECT_SPIDER | |
2015-09-28 20:08:04 +00:00
m_type = = OBJECT_BEE | |
m_type = = OBJECT_TEEN28 )
2015-08-13 11:41:25 +00:00
{
2015-08-13 16:54:44 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Damageable ) ] = true ;
2015-08-13 11:41:25 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Destroyable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Fragile ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Shielded ) ] = false ;
}
2015-08-13 16:54:44 +00:00
else if ( m_type = = OBJECT_HUMAN | |
2015-08-13 11:41:25 +00:00
m_type = = OBJECT_MOBILEfa | |
m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEia | |
2017-11-16 17:43:45 +00:00
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib | |
2015-08-13 11:41:25 +00:00
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILEfs | |
m_type = = OBJECT_MOBILEts | |
m_type = = OBJECT_MOBILEws | |
m_type = = OBJECT_MOBILEis | |
m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEit | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErp | |
m_type = = OBJECT_MOBILEst | |
2015-08-13 11:41:25 +00:00
m_type = = OBJECT_FACTORY | |
m_type = = OBJECT_REPAIR | |
m_type = = OBJECT_DESTROYER | |
m_type = = OBJECT_DERRICK | |
m_type = = OBJECT_STATION | |
m_type = = OBJECT_CONVERT | |
m_type = = OBJECT_TOWER | |
m_type = = OBJECT_RESEARCH | |
m_type = = OBJECT_RADAR | |
m_type = = OBJECT_INFO | |
m_type = = OBJECT_ENERGY | |
m_type = = OBJECT_LABO | |
m_type = = OBJECT_NUCLEAR | |
2015-08-13 16:54:44 +00:00
m_type = = OBJECT_PARA | |
m_type = = OBJECT_MOTHER )
2015-08-13 11:41:25 +00:00
{
2015-08-13 16:54:44 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Damageable ) ] = true ;
2015-08-13 11:41:25 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Destroyable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Fragile ) ] = false ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Shielded ) ] = true ;
}
2015-08-13 16:54:44 +00:00
else if ( m_type = = OBJECT_HUSTON | |
m_type = = OBJECT_BASE )
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Damageable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Destroyable ) ] = false ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Fragile ) ] = false ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Shielded ) ] = false ;
}
2019-07-17 00:57:47 +00:00
else if ( m_type = = OBJECT_RUINmobilew1 | |
m_type = = OBJECT_RUINmobilew2 | |
m_type = = OBJECT_RUINmobilet1 | |
m_type = = OBJECT_RUINmobilet2 | |
m_type = = OBJECT_RUINmobiler1 | |
m_type = = OBJECT_RUINmobiler2 | |
m_type = = OBJECT_RUINfactory | |
m_type = = OBJECT_RUINdoor | |
m_type = = OBJECT_RUINsupport | |
m_type = = OBJECT_RUINradar | |
m_type = = OBJECT_RUINconvert )
2018-07-13 11:16:30 +00:00
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Damageable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Destroyable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Fragile ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Shielded ) ] = false ;
}
2020-07-13 17:44:50 +00:00
else if ( m_type = = OBJECT_PLANT0 | |
m_type = = OBJECT_PLANT1 | |
m_type = = OBJECT_PLANT2 | |
m_type = = OBJECT_PLANT3 | |
m_type = = OBJECT_PLANT4 | |
m_type = = OBJECT_PLANT15 | |
m_type = = OBJECT_PLANT16 | |
m_type = = OBJECT_PLANT17 | |
m_type = = OBJECT_PLANT18 )
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Damageable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Destroyable ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Fragile ) ] = true ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Shielded ) ] = false ;
}
2015-08-13 11:41:25 +00:00
else
{
2015-08-14 11:50:05 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Damageable ) ] = false ;
2015-08-13 11:41:25 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Destroyable ) ] = false ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Fragile ) ] = false ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Shielded ) ] = false ;
}
// TODO: #TooMuchHacking
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : ShieldedAutoRegen ) ] = ( m_type = = OBJECT_HUMAN ) ;
2015-08-13 17:41:21 +00:00
// TODO: Hacking in progress...
2015-08-18 09:42:55 +00:00
if ( m_type = = OBJECT_STONE | |
2015-08-13 17:41:21 +00:00
m_type = = OBJECT_URANIUM | |
m_type = = OBJECT_BULLET | |
m_type = = OBJECT_METAL | |
m_type = = OBJECT_POWER | |
m_type = = OBJECT_ATOMIC | |
m_type = = OBJECT_BBOX | |
m_type = = OBJECT_KEYa | |
m_type = = OBJECT_KEYb | |
m_type = = OBJECT_KEYc | |
m_type = = OBJECT_KEYd | |
m_type = = OBJECT_TNT )
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Transportable ) ] = true ;
}
else
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Transportable ) ] = false ;
}
// TODO: You have been hacked!
if ( m_type = = OBJECT_HUMAN | |
m_type = = OBJECT_TOTO | |
m_type = = OBJECT_MOBILEfa | |
m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEia | |
2017-11-16 17:43:45 +00:00
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib | |
2015-08-13 17:41:21 +00:00
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILEfs | |
m_type = = OBJECT_MOBILEts | |
m_type = = OBJECT_MOBILEws | |
m_type = = OBJECT_MOBILEis | |
m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEit | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErp | |
m_type = = OBJECT_MOBILEst | |
2018-07-12 22:03:20 +00:00
m_type = = OBJECT_MOBILEtg | |
2015-08-13 17:41:21 +00:00
m_type = = OBJECT_MOBILEdr | |
m_type = = OBJECT_APOLLO2 | |
m_type = = OBJECT_BASE | |
m_type = = OBJECT_DERRICK | |
m_type = = OBJECT_FACTORY | |
m_type = = OBJECT_REPAIR | |
m_type = = OBJECT_DESTROYER | |
m_type = = OBJECT_STATION | |
m_type = = OBJECT_CONVERT | |
m_type = = OBJECT_TOWER | |
m_type = = OBJECT_RESEARCH | |
m_type = = OBJECT_RADAR | |
m_type = = OBJECT_INFO | |
m_type = = OBJECT_ENERGY | |
m_type = = OBJECT_LABO | |
m_type = = OBJECT_NUCLEAR | |
m_type = = OBJECT_PARA | |
m_type = = OBJECT_SAFE | |
2015-08-16 16:03:04 +00:00
m_type = = OBJECT_HUSTON | |
m_type = = OBJECT_ANT | |
m_type = = OBJECT_WORM | |
m_type = = OBJECT_SPIDER | |
m_type = = OBJECT_BEE | |
2016-01-30 16:24:02 +00:00
m_type = = OBJECT_MOTHER | |
m_type = = OBJECT_CONTROLLER )
2015-08-13 17:41:21 +00:00
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Controllable ) ] = true ;
}
else
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Controllable ) ] = false ;
}
2015-08-16 14:06:51 +00:00
// TODO: Another one? :/
2015-08-18 10:29:41 +00:00
if ( m_type = = OBJECT_POWER | | // PowerCell
m_type = = OBJECT_ATOMIC | | // NuclearCell
m_type = = OBJECT_STATION | | // PowerStation
m_type = = OBJECT_ENERGY ) // PowerPlant
2015-08-16 14:06:51 +00:00
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : PowerContainer ) ] = true ;
}
else
{
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : PowerContainer ) ] = false ;
}
2015-08-13 11:41:25 +00:00
2012-06-26 20:23:05 +00:00
if ( m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILErc ) // cannon vehicle?
{
2012-09-10 21:29:38 +00:00
m_cameraType = Gfx : : CAM_TYPE_ONBOARD ;
2012-06-26 20:23:05 +00:00
}
}
2015-07-02 21:48:30 +00:00
const char * COldObject : : GetName ( )
2012-06-26 20:23:05 +00:00
{
2015-06-25 17:05:56 +00:00
return m_name . c_str ( ) ;
2012-06-26 20:23:05 +00:00
}
// Choosing the option to use.
2015-07-02 21:48:30 +00:00
void COldObject : : SetOption ( int option )
2012-06-26 20:23:05 +00:00
{
m_option = option ;
}
2015-07-02 21:48:30 +00:00
int COldObject : : GetOption ( )
2012-06-26 20:23:05 +00:00
{
return m_option ;
}
// Saves all the parameters of the object.
2015-07-02 21:48:30 +00:00
void COldObject : : Write ( CLevelParserLine * line )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 pos ;
2012-06-26 20:23:05 +00:00
2022-02-26 17:48:51 +00:00
line - > AddParam ( " camera " , std : : make_unique < CLevelParserParam > ( GetCameraType ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 13:16:32 +00:00
if ( GetCameraLock ( ) )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " cameraLock " , std : : make_unique < CLevelParserParam > ( GetCameraLock ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2017-04-29 11:05:11 +00:00
if ( IsBulletWall ( ) )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " bulletWall " , std : : make_unique < CLevelParserParam > ( IsBulletWall ( ) ) ) ;
2017-04-29 11:05:11 +00:00
2015-08-11 20:51:09 +00:00
if ( GetEnergyLevel ( ) ! = 0.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " energy " , std : : make_unique < CLevelParserParam > ( GetEnergyLevel ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-10 21:29:38 +00:00
if ( GetShield ( ) ! = 1.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " shield " , std : : make_unique < CLevelParserParam > ( GetShield ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2012-09-10 21:29:38 +00:00
if ( GetRange ( ) ! = 1.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " range " , std : : make_unique < CLevelParserParam > ( GetRange ( ) ) ) ;
2015-06-21 18:59:23 +00:00
2014-11-10 13:16:32 +00:00
if ( ! GetSelectable ( ) )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " selectable " , std : : make_unique < CLevelParserParam > ( GetSelectable ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2015-08-11 15:51:39 +00:00
if ( ! GetCollisions ( ) )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " clip " , std : : make_unique < CLevelParserParam > ( GetCollisions ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 13:16:32 +00:00
if ( GetLock ( ) )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " lock " , std : : make_unique < CLevelParserParam > ( GetLock ( ) ) ) ;
2015-08-30 20:18:49 +00:00
2015-08-29 14:29:41 +00:00
if ( ! GetActivity ( ) )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " activity " , std : : make_unique < CLevelParserParam > ( GetActivity ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2014-11-10 13:16:32 +00:00
if ( GetProxyActivate ( ) )
2012-06-26 20:23:05 +00:00
{
2022-02-26 17:48:51 +00:00
line - > AddParam ( " proxyActivate " , std : : make_unique < CLevelParserParam > ( GetProxyActivate ( ) ) ) ;
line - > AddParam ( " proxyDistance " , std : : make_unique < CLevelParserParam > ( GetProxyDistance ( ) / g_unit ) ) ;
2012-06-26 20:23:05 +00:00
}
2012-09-10 21:29:38 +00:00
if ( GetMagnifyDamage ( ) ! = 1.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " magnifyDamage " , std : : make_unique < CLevelParserParam > ( GetMagnifyDamage ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2015-06-26 20:07:55 +00:00
if ( GetTeam ( ) ! = 0 )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " team " , std : : make_unique < CLevelParserParam > ( GetTeam ( ) ) ) ;
2015-06-26 20:07:55 +00:00
2012-09-10 21:29:38 +00:00
if ( GetGunGoalV ( ) ! = 0.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " aimV " , std : : make_unique < CLevelParserParam > ( GetGunGoalV ( ) ) ) ;
2015-06-21 18:59:23 +00:00
2012-09-10 21:29:38 +00:00
if ( GetGunGoalH ( ) ! = 0.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " aimH " , std : : make_unique < CLevelParserParam > ( GetGunGoalH ( ) ) ) ;
2012-06-26 20:23:05 +00:00
2015-07-13 21:04:11 +00:00
if ( GetAnimateOnReset ( ) )
2012-06-26 20:23:05 +00:00
{
2022-02-26 17:48:51 +00:00
line - > AddParam ( " reset " , std : : make_unique < CLevelParserParam > ( GetAnimateOnReset ( ) ) ) ;
2012-06-26 20:23:05 +00:00
}
2014-11-10 13:16:32 +00:00
if ( m_bVirusMode )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " virusMode " , std : : make_unique < CLevelParserParam > ( m_bVirusMode ) ) ;
2012-06-26 20:23:05 +00:00
if ( m_virusTime ! = 0.0f )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " virusTime " , std : : make_unique < CLevelParserParam > ( m_virusTime ) ) ;
2012-06-26 20:23:05 +00:00
2022-02-26 17:48:51 +00:00
line - > AddParam ( " lifetime " , std : : make_unique < CLevelParserParam > ( m_aTime ) ) ;
2017-10-24 09:12:19 +00:00
2012-06-26 20:23:05 +00:00
// Sets the parameters of the command line.
2015-06-21 18:59:23 +00:00
CLevelParserParamVec cmdline ;
2015-08-12 14:54:44 +00:00
for ( float value : GetCmdLine ( ) )
2012-06-26 20:23:05 +00:00
{
2022-02-26 17:48:51 +00:00
cmdline . push_back ( std : : make_unique < CLevelParserParam > ( value ) ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-21 18:59:23 +00:00
if ( cmdline . size ( ) > 0 )
2022-02-26 17:48:51 +00:00
line - > AddParam ( " cmdline " , std : : make_unique < CLevelParserParam > ( std : : move ( cmdline ) ) ) ;
2012-06-26 21:01:17 +00:00
2014-11-10 16:15:34 +00:00
if ( m_motion ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_motion - > Write ( line ) ;
}
2015-08-10 16:16:00 +00:00
if ( Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2022-02-26 17:48:51 +00:00
line - > AddParam ( " bVirusActive " , std : : make_unique < CLevelParserParam > ( GetActiveVirus ( ) ) ) ;
2015-08-10 21:20:36 +00:00
}
2015-08-10 16:16:00 +00:00
2014-11-10 16:15:34 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_physics - > Write ( line ) ;
}
2014-11-10 16:15:34 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_auto - > Write ( line ) ;
}
}
2012-10-17 19:55:45 +00:00
// Returns all parameters of the object.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
void COldObject : : Read ( CLevelParserLine * line )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 zoom = line - > GetParam ( " zoom " ) - > AsPoint ( glm : : vec3 ( 1.0f , 1.0f , 1.0f ) ) ;
2015-08-14 16:19:58 +00:00
if ( zoom . x ! = 1.0f | | zoom . y ! = 1.0f | | zoom . z ! = 1.0f )
SetScale ( zoom ) ;
2012-06-26 20:23:05 +00:00
2015-08-14 16:19:58 +00:00
if ( line - > GetParam ( " camera " ) - > IsDefined ( ) )
SetCameraType ( line - > GetParam ( " camera " ) - > AsCameraType ( ) ) ;
2014-11-10 16:15:34 +00:00
SetCameraLock ( line - > GetParam ( " cameraLock " ) - > AsBool ( false ) ) ;
2015-08-14 16:19:58 +00:00
if ( line - > GetParam ( " pyro " ) - > IsDefined ( ) )
m_engine - > GetPyroManager ( ) - > Create ( line - > GetParam ( " pyro " ) - > AsPyroType ( ) , this ) ;
2017-05-19 13:33:44 +00:00
SetBulletWall ( line - > GetParam ( " bulletWall " ) - > AsBool ( IsBulletWallByDefault ( m_type ) ) ) ;
2017-04-29 11:05:11 +00:00
2014-11-10 16:15:34 +00:00
SetProxyActivate ( line - > GetParam ( " proxyActivate " ) - > AsBool ( false ) ) ;
SetProxyDistance ( line - > GetParam ( " proxyDistance " ) - > AsFloat ( 15.0f ) * g_unit ) ;
2015-08-14 16:19:58 +00:00
SetCollisions ( line - > GetParam ( " clip " ) - > AsBool ( true ) ) ;
SetAnimateOnReset ( line - > GetParam ( " reset " ) - > AsBool ( false ) ) ;
if ( Implements ( ObjectInterfaceType : : Controllable ) )
{
2017-01-28 11:53:28 +00:00
SetSelectable ( line - > GetParam ( " selectable " ) - > AsBool ( IsSelectableByDefault ( m_type ) ) ) ;
2015-08-14 16:19:58 +00:00
}
if ( Implements ( ObjectInterfaceType : : JetFlying ) )
{
SetRange ( line - > GetParam ( " range " ) - > AsFloat ( 30.0f ) ) ;
}
2018-05-08 17:54:25 +00:00
if ( Implements ( ObjectInterfaceType : : Fragile ) )
{
SetMagnifyDamage ( line - > GetParam ( " magnifyDamage " ) - > AsFloat ( 1.0f ) ) ; // TODO: This is a temporary hack for now - CFragileObject doesn't have SetMagnifyDamage ~krzys_h
}
2015-08-14 16:19:58 +00:00
if ( Implements ( ObjectInterfaceType : : Shielded ) )
{
SetShield ( line - > GetParam ( " shield " ) - > AsFloat ( 1.0f ) ) ;
SetMagnifyDamage ( line - > GetParam ( " magnifyDamage " ) - > AsFloat ( 1.0f ) ) ;
}
if ( Implements ( ObjectInterfaceType : : Programmable ) )
{
SetCheckToken ( ! line - > GetParam ( " checkToken " ) - > IsDefined ( ) ? GetSelectable ( ) : line - > GetParam ( " checkToken " ) - > AsBool ( true ) ) ;
2015-07-11 17:48:37 +00:00
2015-08-14 16:19:58 +00:00
if ( line - > GetParam ( " cmdline " ) - > IsDefined ( ) )
{
const auto & cmdline = line - > GetParam ( " cmdline " ) - > AsArray ( ) ;
for ( unsigned int i = 0 ; i < cmdline . size ( ) ; i + + )
{
SetCmdLine ( i , cmdline [ i ] - > AsFloat ( ) ) ;
}
}
}
2012-06-26 20:23:05 +00:00
2015-08-14 16:19:58 +00:00
// SetManual will affect bot speed
if ( m_type = = OBJECT_MOBILEdr )
{
// TODO: Merge these two settings?
SetManual ( ! GetTrainer ( ) ) ;
}
// AlienWorm time up/down
// TODO: Refactor function names
if ( m_type = = OBJECT_WORM )
2015-06-21 18:59:23 +00:00
{
2015-08-14 16:19:58 +00:00
assert ( Implements ( ObjectInterfaceType : : Movable ) ) ;
CMotion * motion = GetMotion ( ) ;
if ( line - > GetParam ( " param " ) - > IsDefined ( ) )
2015-06-21 18:59:23 +00:00
{
2015-08-14 16:19:58 +00:00
const auto & p = line - > GetParam ( " param " ) - > AsArray ( ) ;
for ( unsigned int i = 0 ; i < 10 & & i < p . size ( ) ; i + + )
{
motion - > SetParam ( i , p [ i ] - > AsFloat ( ) ) ;
}
2014-11-10 16:15:34 +00:00
}
2012-06-26 20:23:05 +00:00
}
2012-06-26 21:01:17 +00:00
2015-08-14 16:19:58 +00:00
if ( m_auto ! = nullptr )
{
// TODO: Is it used for anything else than AlienEggs?
m_auto - > SetType ( line - > GetParam ( " autoType " ) - > AsObjectType ( OBJECT_NULL ) ) ;
for ( int i = 0 ; i < 5 ; i + + )
{
2023-08-09 17:32:59 +00:00
std : : string op = " autoValue " + StrUtils : : ToString ( i + 1 ) ; // autoValue1..autoValue5
2015-08-14 16:19:58 +00:00
m_auto - > SetValue ( i , line - > GetParam ( op ) - > AsFloat ( 0.0f ) ) ;
}
2021-06-25 22:47:25 +00:00
m_auto - > SetString ( const_cast < char * > ( line - > GetParam ( " autoString " ) - > AsString ( " " ) . c_str ( ) ) ) ;
2015-08-14 16:19:58 +00:00
int i = line - > GetParam ( " run " ) - > AsInt ( - 1 ) ;
if ( i ! = - 1 )
{
2015-10-01 17:19:40 +00:00
if ( i ! = PARAM_FIXSCENE & & ! CSettings : : GetInstancePointer ( ) - > GetMovies ( ) ) i = 0 ;
2015-08-14 16:19:58 +00:00
m_auto - > Start ( i ) ; // starts the film
}
}
// Everthing below is for use only by saved scenes
if ( line - > GetParam ( " energy " ) - > IsDefined ( ) )
SetEnergyLevel ( line - > GetParam ( " energy " ) - > AsFloat ( ) ) ;
SetLock ( line - > GetParam ( " lock " ) - > AsBool ( false ) ) ;
2015-08-29 14:29:41 +00:00
SetActivity ( line - > GetParam ( " activity " ) - > AsBool ( true ) ) ;
2015-08-14 16:19:58 +00:00
SetGunGoalV ( line - > GetParam ( " aimV " ) - > AsFloat ( 0.0f ) ) ;
SetGunGoalH ( line - > GetParam ( " aimH " ) - > AsFloat ( 0.0f ) ) ;
2015-08-16 18:24:48 +00:00
if ( line - > GetParam ( " burnMode " ) - > AsBool ( false ) )
SetDying ( DeathType : : Burning ) ;
2015-08-14 16:19:58 +00:00
m_bVirusMode = line - > GetParam ( " virusMode " ) - > AsBool ( false ) ;
m_virusTime = line - > GetParam ( " virusTime " ) - > AsFloat ( 0.0f ) ;
2017-10-24 09:12:19 +00:00
m_aTime = line - > GetParam ( " lifetime " ) - > AsFloat ( 0.0f ) ;
2014-11-10 16:15:34 +00:00
if ( m_motion ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_motion - > Read ( line ) ;
}
2015-08-10 21:20:36 +00:00
if ( Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2015-08-12 14:54:44 +00:00
SetActiveVirus ( line - > GetParam ( " bVirusActive " ) - > AsBool ( false ) ) ;
2015-08-10 21:20:36 +00:00
}
2014-11-10 16:15:34 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_physics - > Read ( line ) ;
}
2014-11-10 16:15:34 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_auto - > Read ( line ) ;
}
}
// Seeking the nth son of a father.
2015-07-02 21:48:30 +00:00
int COldObject : : SearchDescendant ( int parent , int n )
2012-06-26 20:23:05 +00:00
{
int i ;
for ( i = 0 ; i < m_totalPart ; i + + )
{
if ( ! m_objectPart [ i ] . bUsed ) continue ;
if ( parent = = m_objectPart [ i ] . parentPart )
{
if ( n - - = = 0 ) return i ;
}
}
return - 1 ;
}
2015-07-10 07:26:38 +00:00
void COldObject : : TransformCrashSphere ( Math : : Sphere & crashSphere )
2012-06-26 20:23:05 +00:00
{
2020-07-08 12:17:08 +00:00
if ( ! Implements ( ObjectInterfaceType : : Jostleable ) ) crashSphere . radius * = GetScaleX ( ) ;
2012-06-26 20:23:05 +00:00
2012-10-17 19:55:45 +00:00
// Returns to the sphere collisions,
2015-07-10 07:26:38 +00:00
// which ignores the tilt of the vehicle.
2012-06-26 20:23:05 +00:00
// This is necessary to collisions with vehicles,
2015-06-25 17:05:56 +00:00
// so as not to reflect SetTilt, for example.
2012-06-26 20:23:05 +00:00
// The sphere must necessarily have a center (0, y, 0).
2015-07-10 07:26:38 +00:00
if ( m_crashSpheres . size ( ) = = 1 & &
crashSphere . pos . x = = 0.0f & &
crashSphere . pos . z = = 0.0f )
2012-06-26 20:23:05 +00:00
{
2015-07-10 07:26:38 +00:00
crashSphere . pos + = m_objectPart [ 0 ] . position ;
return ;
2012-06-26 20:23:05 +00:00
}
2015-07-10 07:26:38 +00:00
if ( m_objectPart [ 0 ] . bTranslate | |
m_objectPart [ 0 ] . bRotate )
2012-06-26 20:23:05 +00:00
{
UpdateTransformObject ( ) ;
}
2015-07-10 07:26:38 +00:00
crashSphere . pos = Math : : Transform ( m_objectPart [ 0 ] . matWorld , crashSphere . pos ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-11 09:35:20 +00:00
void COldObject : : TransformCameraCollisionSphere ( Math : : Sphere & collisionSphere )
2012-06-26 20:23:05 +00:00
{
2015-07-11 09:35:20 +00:00
collisionSphere . pos = Math : : Transform ( m_objectPart [ 0 ] . matWorld , collisionSphere . pos ) ;
2015-07-14 19:29:13 +00:00
collisionSphere . radius * = GetScaleX ( ) ;
2012-06-26 20:23:05 +00:00
}
// Specifies the sphere of jostling, relative to the object.
2015-07-10 20:11:22 +00:00
void COldObject : : SetJostlingSphere ( const Math : : Sphere & jostlingSphere )
2012-06-26 20:23:05 +00:00
{
2015-07-10 20:11:22 +00:00
m_jostlingSphere = jostlingSphere ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Jostleable ) ] = true ;
2012-06-26 20:23:05 +00:00
}
// Specifies the sphere of jostling, in the world.
2015-07-10 20:11:22 +00:00
Math : : Sphere COldObject : : GetJostlingSphere ( ) const
2012-06-26 20:23:05 +00:00
{
2015-07-10 20:11:22 +00:00
Math : : Sphere transformedJostlingSphere = m_jostlingSphere ;
transformedJostlingSphere . pos = Math : : Transform ( m_objectPart [ 0 ] . matWorld , transformedJostlingSphere . pos ) ;
return transformedJostlingSphere ;
2012-06-26 20:23:05 +00:00
}
// Positioning an object on a certain height, above the ground.
2015-07-02 21:48:30 +00:00
void COldObject : : SetFloorHeight ( float height )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 pos ;
2012-06-26 20:23:05 +00:00
pos = m_objectPart [ 0 ] . position ;
2012-09-10 21:29:38 +00:00
m_terrain - > AdjustToFloor ( pos ) ;
2012-06-26 20:23:05 +00:00
2015-06-22 19:58:58 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_physics - > SetLand ( height = = 0.0f ) ;
m_physics - > SetMotor ( height ! = 0.0f ) ;
}
m_objectPart [ 0 ] . position . y = pos . y + height + m_character . height ;
m_objectPart [ 0 ] . bTranslate = true ; // it will recalculate the matrices
}
// Adjust the inclination of an object laying on the ground.
2015-07-02 21:48:30 +00:00
void COldObject : : FloorAdjust ( )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 pos , n ;
2021-12-24 19:08:04 +00:00
glm : : vec2 nn ;
2012-06-26 20:23:05 +00:00
float a ;
2015-07-12 09:01:16 +00:00
pos = GetPosition ( ) ;
2012-06-26 20:23:05 +00:00
if ( m_terrain - > GetNormal ( n , pos ) )
{
2015-07-14 19:29:13 +00:00
a = GetRotationY ( ) ;
2021-12-24 19:08:04 +00:00
nn = Math : : RotatePoint ( - a , { n . z , n . x } ) ;
2015-07-14 19:29:13 +00:00
SetRotationX ( sinf ( nn . x ) ) ;
SetRotationZ ( - sinf ( nn . y ) ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-08-11 18:59:35 +00:00
// Getes the linear vibration.
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
void COldObject : : SetLinVibration ( glm : : vec3 dir )
2012-06-26 20:23:05 +00:00
{
if ( m_linVibration . x ! = dir . x | |
m_linVibration . y ! = dir . y | |
m_linVibration . z ! = dir . z )
{
m_linVibration = dir ;
m_objectPart [ 0 ] . bTranslate = true ;
}
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetLinVibration ( )
2012-06-26 20:23:05 +00:00
{
return m_linVibration ;
}
2012-08-11 18:59:35 +00:00
// Getes the circular vibration.
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
void COldObject : : SetCirVibration ( glm : : vec3 dir )
2012-06-26 20:23:05 +00:00
{
if ( m_cirVibration . x ! = dir . x | |
m_cirVibration . y ! = dir . y | |
m_cirVibration . z ! = dir . z )
{
m_cirVibration = dir ;
m_objectPart [ 0 ] . bRotate = true ;
}
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetCirVibration ( )
2012-06-26 20:23:05 +00:00
{
return m_cirVibration ;
}
2012-08-11 18:59:35 +00:00
// Getes the inclination.
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
void COldObject : : SetTilt ( glm : : vec3 dir )
2012-06-26 20:23:05 +00:00
{
2015-06-29 20:45:38 +00:00
if ( m_tilt . x ! = dir . x | |
m_tilt . y ! = dir . y | |
m_tilt . z ! = dir . z )
2012-06-26 20:23:05 +00:00
{
2015-06-29 20:45:38 +00:00
m_tilt = dir ;
2012-06-26 20:23:05 +00:00
m_objectPart [ 0 ] . bRotate = true ;
}
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetTilt ( )
2012-06-26 20:23:05 +00:00
{
2015-06-29 20:45:38 +00:00
return m_tilt ;
2012-06-26 20:23:05 +00:00
}
2012-08-11 18:59:35 +00:00
// Getes the position of center of the object.
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
void COldObject : : SetPartPosition ( int part , const glm : : vec3 & pos )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . position = pos ;
m_objectPart [ part ] . bTranslate = true ; // it will recalculate the matrices
if ( part = = 0 & & ! m_bFlat ) // main part?
{
2015-07-11 17:48:37 +00:00
int rank = m_objectPart [ 0 ] . object ;
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
glm : : vec3 shPos = pos ;
2012-09-10 21:29:38 +00:00
m_terrain - > AdjustToFloor ( shPos , true ) ;
2015-08-14 11:37:40 +00:00
m_engine - > SetObjectShadowSpotPos ( rank , shPos ) ;
2012-06-26 20:23:05 +00:00
2015-07-11 17:48:37 +00:00
float height = 0.0f ;
2015-08-12 17:09:35 +00:00
if ( Implements ( ObjectInterfaceType : : Flying ) )
2012-06-26 20:23:05 +00:00
{
height = pos . y - shPos . y ;
}
2015-08-14 11:37:40 +00:00
m_engine - > SetObjectShadowSpotHeight ( rank , height ) ;
2012-06-26 20:23:05 +00:00
2015-08-14 11:37:40 +00:00
m_engine - > UpdateObjectShadowSpotNormal ( rank ) ;
2012-06-26 20:23:05 +00:00
if ( m_shadowLight ! = - 1 )
{
2022-01-03 21:51:36 +00:00
glm : : vec3 lightPos = pos ;
2015-07-11 17:48:37 +00:00
lightPos . y + = m_shadowHeight ;
m_lightMan - > SetLightPos ( m_shadowLight , lightPos ) ;
2012-06-26 20:23:05 +00:00
}
}
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetPartPosition ( int part ) const
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . position ;
}
2012-08-11 18:59:35 +00:00
// Getes the rotation around three axis.
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
void COldObject : : SetPartRotation ( int part , const glm : : vec3 & angle )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . angle = angle ;
m_objectPart [ part ] . bRotate = true ; // it will recalculate the matrices
if ( part = = 0 & & ! m_bFlat ) // main part?
{
2015-08-14 11:37:40 +00:00
m_engine - > SetObjectShadowSpotAngle ( m_objectPart [ 0 ] . object , m_objectPart [ 0 ] . angle . y ) ;
2012-06-26 20:23:05 +00:00
}
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetPartRotation ( int part ) const
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . angle ;
}
2012-08-11 18:59:35 +00:00
// Getes the rotation about the axis Y.
2012-06-26 20:23:05 +00:00
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartRotationY ( int part , float angle )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . angle . y = angle ;
m_objectPart [ part ] . bRotate = true ; // it will recalculate the matrices
if ( part = = 0 & & ! m_bFlat ) // main part?
{
2015-08-14 11:37:40 +00:00
m_engine - > SetObjectShadowSpotAngle ( m_objectPart [ 0 ] . object , m_objectPart [ 0 ] . angle . y ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-08-11 18:59:35 +00:00
// Getes the rotation about the axis X.
2012-06-26 20:23:05 +00:00
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartRotationX ( int part , float angle )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . angle . x = angle ;
m_objectPart [ part ] . bRotate = true ; // it will recalculate the matrices
}
2012-08-11 18:59:35 +00:00
// Getes the rotation about the axis Z.
2012-06-26 20:23:05 +00:00
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartRotationZ ( int part , float angle )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . angle . z = angle ;
m_objectPart [ part ] . bRotate = true ; //it will recalculate the matrices
}
2015-07-14 19:29:13 +00:00
float COldObject : : GetPartRotationY ( int part )
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . angle . y ;
}
2015-07-14 19:29:13 +00:00
float COldObject : : GetPartRotationX ( int part )
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . angle . x ;
}
2015-07-14 19:29:13 +00:00
float COldObject : : GetPartRotationZ ( int part )
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . angle . z ;
}
2012-08-11 18:59:35 +00:00
// Getes the global zoom.
2012-06-26 20:23:05 +00:00
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartScale ( int part , float zoom )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bTranslate = true ; // it will recalculate the matrices
m_objectPart [ part ] . zoom . x = zoom ;
m_objectPart [ part ] . zoom . y = zoom ;
m_objectPart [ part ] . zoom . z = zoom ;
m_objectPart [ part ] . bZoom = ( m_objectPart [ part ] . zoom . x ! = 1.0f | |
m_objectPart [ part ] . zoom . y ! = 1.0f | |
m_objectPart [ part ] . zoom . z ! = 1.0f ) ;
}
2022-01-03 21:51:36 +00:00
void COldObject : : SetPartScale ( int part , glm : : vec3 zoom )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bTranslate = true ; // it will recalculate the matrices
m_objectPart [ part ] . zoom = zoom ;
m_objectPart [ part ] . bZoom = ( m_objectPart [ part ] . zoom . x ! = 1.0f | |
m_objectPart [ part ] . zoom . y ! = 1.0f | |
m_objectPart [ part ] . zoom . z ! = 1.0f ) ;
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetPartScale ( int part ) const
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . zoom ;
}
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartScaleX ( int part , float zoom )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bTranslate = true ; // it will recalculate the matrices
m_objectPart [ part ] . zoom . x = zoom ;
m_objectPart [ part ] . bZoom = ( m_objectPart [ part ] . zoom . x ! = 1.0f | |
m_objectPart [ part ] . zoom . y ! = 1.0f | |
m_objectPart [ part ] . zoom . z ! = 1.0f ) ;
}
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartScaleY ( int part , float zoom )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bTranslate = true ; // it will recalculate the matrices
m_objectPart [ part ] . zoom . y = zoom ;
m_objectPart [ part ] . bZoom = ( m_objectPart [ part ] . zoom . x ! = 1.0f | |
m_objectPart [ part ] . zoom . y ! = 1.0f | |
m_objectPart [ part ] . zoom . z ! = 1.0f ) ;
}
2015-07-14 19:29:13 +00:00
void COldObject : : SetPartScaleZ ( int part , float zoom )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bTranslate = true ; // it will recalculate the matrices
m_objectPart [ part ] . zoom . z = zoom ;
m_objectPart [ part ] . bZoom = ( m_objectPart [ part ] . zoom . x ! = 1.0f | |
m_objectPart [ part ] . zoom . y ! = 1.0f | |
m_objectPart [ part ] . zoom . z ! = 1.0f ) ;
}
2015-07-14 19:29:13 +00:00
float COldObject : : GetPartScaleX ( int part )
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . zoom . x ;
}
2015-07-14 19:29:13 +00:00
float COldObject : : GetPartScaleY ( int part )
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . zoom . y ;
}
2015-07-14 19:29:13 +00:00
float COldObject : : GetPartScaleZ ( int part )
2012-06-26 20:23:05 +00:00
{
return m_objectPart [ part ] . zoom . z ;
}
2015-07-02 21:48:30 +00:00
void COldObject : : SetTrainer ( bool bEnable )
2012-06-26 20:23:05 +00:00
{
m_bTrainer = bEnable ;
if ( m_bTrainer ) // training?
{
2012-09-10 21:29:38 +00:00
m_cameraType = Gfx : : CAM_TYPE_FIX ;
2012-06-26 20:23:05 +00:00
}
}
2015-07-02 21:48:30 +00:00
bool COldObject : : GetTrainer ( )
2012-06-26 20:23:05 +00:00
{
return m_bTrainer ;
}
2020-07-20 16:35:31 +00:00
bool COldObject : : GetPlusTrainer ( )
{
return m_main - > GetPlusTrainer ( ) ;
}
2015-07-02 21:48:30 +00:00
void COldObject : : SetToy ( bool bEnable )
2012-06-26 20:23:05 +00:00
{
m_bToy = bEnable ;
}
2015-07-02 21:48:30 +00:00
bool COldObject : : GetToy ( )
2012-06-26 20:23:05 +00:00
{
return m_bToy ;
}
2015-07-02 21:48:30 +00:00
void COldObject : : SetManual ( bool bManual )
2012-06-26 20:23:05 +00:00
{
m_bManual = bManual ;
}
2015-07-02 21:48:30 +00:00
bool COldObject : : GetManual ( )
2012-06-26 20:23:05 +00:00
{
return m_bManual ;
}
// Management of the particle master.
2015-07-02 21:48:30 +00:00
void COldObject : : SetMasterParticle ( int part , int parti )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . masterParti = parti ;
}
// Management of the stack transport.
2022-01-29 16:16:57 +00:00
int COldObject : : GetNumSlots ( )
2012-06-26 20:23:05 +00:00
{
2022-01-29 16:16:57 +00:00
assert ( m_hasPowerSlot | | m_hasCargoSlot ) ; // otherwise implemented[CSlottedObject] is false
return ( m_hasPowerSlot ? 1 : 0 ) + ( m_hasCargoSlot ? 1 : 0 ) ;
2012-06-26 20:23:05 +00:00
}
2022-01-29 16:16:57 +00:00
int COldObject : : MapPseudoSlot ( Pseudoslot pseudoslot )
2012-06-26 20:23:05 +00:00
{
2022-01-29 16:16:57 +00:00
switch ( pseudoslot )
{
case Pseudoslot : : POWER :
return m_hasPowerSlot ? 0 : - 1 ;
case Pseudoslot : : CARRYING :
return m_hasCargoSlot ? ( m_hasPowerSlot ? 1 : 0 ) : - 1 ;
default :
return - 1 ;
}
2012-06-26 20:23:05 +00:00
}
2022-02-02 14:45:56 +00:00
glm : : vec3 COldObject : : GetSlotPosition ( int slotNum )
2022-01-29 16:16:57 +00:00
{
if ( slotNum = = 0 & & m_hasPowerSlot )
return m_powerPosition ;
else
{
assert ( m_hasCargoSlot & & slotNum = = ( m_hasPowerSlot ? 1 : 0 ) ) ;
int grabPartNum ;
2022-02-02 14:45:56 +00:00
glm : : vec3 grabRelPos ;
2022-01-29 16:16:57 +00:00
// See CTaskManip::TransporterTakeObject call to SetTransporterPart and SetPosition
switch ( m_type )
{
case OBJECT_HUMAN :
case OBJECT_TECH :
grabPartNum = 4 ;
2022-02-02 14:45:56 +00:00
grabRelPos = glm : : vec3 ( 1.7f , - 0.5f , 1.1f ) ;
2022-01-29 16:16:57 +00:00
break ;
case OBJECT_MOBILEsa : // subber
grabPartNum = 2 ;
2022-02-02 14:45:56 +00:00
grabRelPos = glm : : vec3 ( 1.1f , - 1.0f , 1.0f ) ;
2022-01-29 16:16:57 +00:00
break ;
case OBJECT_MOBILEfa : // Grabbers
case OBJECT_MOBILEta :
case OBJECT_MOBILEwa :
case OBJECT_MOBILEia :
grabPartNum = 3 ;
2022-02-02 14:45:56 +00:00
grabRelPos = glm : : vec3 ( 4.7f , 0.0f , 0.0f ) ;
2022-01-29 16:16:57 +00:00
break ;
2023-06-18 22:31:15 +00:00
case OBJECT_BEE :
2023-06-22 21:32:02 +00:00
grabPartNum = 0 ;
2023-07-04 18:34:37 +00:00
grabRelPos = glm : : vec3 ( 0.0f , - 3.0f , 0.0f ) ;
2023-06-18 22:31:15 +00:00
break ;
2022-01-29 16:16:57 +00:00
default : // unreachable, only the above objects have cargo slots
assert ( ! m_hasCargoSlot ) ;
return m_powerPosition ;
}
2012-06-26 20:23:05 +00:00
2022-02-02 14:45:56 +00:00
return Math : : Transform ( glm : : inverse ( GetWorldMatrix ( 0 ) ) , Math : : Transform ( GetWorldMatrix ( grabPartNum ) , grabRelPos ) ) ;
2022-01-29 16:16:57 +00:00
}
}
float COldObject : : GetSlotAngle ( int slotNum )
2015-08-17 19:23:07 +00:00
{
2022-01-29 16:16:57 +00:00
if ( slotNum = = 0 & & m_hasPowerSlot )
{
switch ( m_type )
{
case OBJECT_TOWER :
case OBJECT_RESEARCH :
case OBJECT_ENERGY :
case OBJECT_LABO :
case OBJECT_NUCLEAR :
return 0 ;
default : // robots
return Math : : PI ;
}
}
else
{
assert ( m_hasCargoSlot & & slotNum = = ( m_hasPowerSlot ? 1 : 0 ) ) ;
return 0 ;
}
2015-08-17 19:23:07 +00:00
}
2022-01-29 16:16:57 +00:00
float COldObject : : GetSlotAcceptanceAngle ( int slotNum )
2015-08-17 19:23:07 +00:00
{
2022-01-29 16:16:57 +00:00
if ( slotNum = = 0 & & m_hasPowerSlot )
{
switch ( m_type )
{
case OBJECT_TOWER :
case OBJECT_RESEARCH :
return 45.0f * Math : : PI / 180.0f ;
case OBJECT_ENERGY :
return 90.0f * Math : : PI / 180.0f ;
case OBJECT_LABO :
return 120.0f * Math : : PI / 180.0f ;
case OBJECT_NUCLEAR :
return 45.0f * Math : : PI / 180.0f ;
default :
return 45.0f * Math : : PI / 180.0f ;
}
}
else
{
assert ( m_hasCargoSlot & & slotNum = = ( m_hasPowerSlot ? 1 : 0 ) ) ;
return 0 ; // no acceptance angle for cargo slot
}
2015-08-17 19:23:07 +00:00
}
2022-01-29 16:16:57 +00:00
CObject * COldObject : : GetSlotContainedObject ( int slotNum )
2012-06-26 20:23:05 +00:00
{
2022-01-29 16:16:57 +00:00
if ( slotNum = = 0 & & m_hasPowerSlot )
return m_power ;
else
{
assert ( m_hasCargoSlot & & slotNum = = ( m_hasPowerSlot ? 1 : 0 ) ) ;
return m_cargo ;
}
2012-06-26 20:23:05 +00:00
}
2022-01-29 16:16:57 +00:00
void COldObject : : SetSlotContainedObject ( int slotNum , CObject * object )
{
if ( slotNum = = 0 & & m_hasPowerSlot )
m_power = object ;
else
{
assert ( m_hasCargoSlot & & slotNum = = ( m_hasPowerSlot ? 1 : 0 ) ) ;
m_cargo = object ;
}
}
// not part of CSlottedObject; just used for initialization
2022-02-02 14:45:56 +00:00
void COldObject : : SetPowerPosition ( const glm : : vec3 & powerPosition )
2012-06-26 20:23:05 +00:00
{
2022-01-29 16:16:57 +00:00
m_powerPosition = powerPosition ;
2012-06-26 20:23:05 +00:00
}
2022-01-29 16:16:57 +00:00
2015-06-29 21:05:31 +00:00
// Management of the object "transporter" that transports it.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
void COldObject : : SetTransporter ( CObject * transporter )
2012-06-26 20:23:05 +00:00
{
2015-06-29 21:05:31 +00:00
m_transporter = transporter ;
2012-06-26 20:23:05 +00:00
// Invisible shadow if the object is transported.
2015-08-17 20:40:52 +00:00
m_engine - > SetObjectShadowSpotHide ( m_objectPart [ 0 ] . object , ( m_transporter ! = nullptr ) ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-02 21:48:30 +00:00
CObject * COldObject : : GetTransporter ( )
2012-06-26 20:23:05 +00:00
{
2015-06-29 21:05:31 +00:00
return m_transporter ;
2012-06-26 20:23:05 +00:00
}
// Management of the conveying portion.
2015-07-02 21:48:30 +00:00
void COldObject : : SetTransporterPart ( int part )
2012-06-26 20:23:05 +00:00
{
2015-06-29 21:05:31 +00:00
m_transporterLink = part ;
2012-06-26 20:23:05 +00:00
}
2012-10-17 19:55:45 +00:00
// Returns matrices of an object portion.
2012-06-26 20:23:05 +00:00
2022-01-05 18:12:35 +00:00
glm : : mat4 COldObject : : GetRotateMatrix ( int part )
2012-06-26 20:23:05 +00:00
{
2022-01-04 23:35:41 +00:00
return m_objectPart [ part ] . matRotate ;
2012-06-26 20:23:05 +00:00
}
2022-01-05 18:12:35 +00:00
glm : : mat4 COldObject : : GetWorldMatrix ( int part )
2012-06-26 20:23:05 +00:00
{
if ( m_objectPart [ 0 ] . bTranslate | |
m_objectPart [ 0 ] . bRotate )
{
UpdateTransformObject ( ) ;
}
2022-01-04 23:35:41 +00:00
return m_objectPart [ part ] . matWorld ;
2012-06-26 20:23:05 +00:00
}
2015-06-20 17:27:43 +00:00
// Creates shade under a vehicle as a negative light.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
bool COldObject : : CreateShadowLight ( float height , Gfx : : Color color )
2015-06-20 17:27:43 +00:00
{
if ( ! m_engine - > GetLightMode ( ) ) return true ;
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
glm : : vec3 pos = GetPosition ( ) ;
2015-06-20 17:27:43 +00:00
m_shadowHeight = height ;
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
Gfx : : Light light ;
light . type = Gfx : : LIGHT_SPOT ;
light . diffuse = color ;
light . ambient = color * 0.1f ;
2022-01-03 21:51:36 +00:00
light . position = glm : : vec3 ( pos . x , pos . y + height , pos . z ) ;
light . direction = glm : : vec3 ( 0.0f , - 1.0f , 0.0f ) ; // against the bottom
2015-06-20 17:27:43 +00:00
light . spotIntensity = 128 ;
light . attenuation0 = 1.0f ;
light . attenuation1 = 0.0f ;
light . attenuation2 = 0.0f ;
light . spotAngle = 90.0f * Math : : PI / 180.0f ;
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
m_shadowLight = m_lightMan - > CreateLight ( ) ;
if ( m_shadowLight = = - 1 ) return false ;
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
m_lightMan - > SetLight ( m_shadowLight , light ) ;
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
// Only illuminates the objects on the ground.
m_lightMan - > SetLightIncludeType ( m_shadowLight , Gfx : : ENG_OBJTYPE_TERRAIN ) ;
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
return true ;
}
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
// Returns the number of negative light shade.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
int COldObject : : GetShadowLight ( )
2015-06-20 17:27:43 +00:00
{
return m_shadowLight ;
}
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
// Creates the circular shadow underneath a vehicle.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
bool COldObject : : CreateShadowCircle ( float radius , float intensity ,
2015-06-20 17:27:43 +00:00
Gfx : : EngineShadowType type )
{
float zoom ;
2012-06-26 20:23:05 +00:00
2015-06-20 17:27:43 +00:00
if ( intensity = = 0.0f ) return true ;
2012-06-26 20:23:05 +00:00
2015-07-14 19:29:13 +00:00
zoom = GetScaleX ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-14 11:37:40 +00:00
m_engine - > CreateShadowSpot ( m_objectPart [ 0 ] . object ) ;
2012-06-26 20:23:05 +00:00
2015-08-14 11:37:40 +00:00
m_engine - > SetObjectShadowSpotRadius ( m_objectPart [ 0 ] . object , radius * zoom ) ;
m_engine - > SetObjectShadowSpotIntensity ( m_objectPart [ 0 ] . object , intensity ) ;
m_engine - > SetObjectShadowSpotHeight ( m_objectPart [ 0 ] . object , 0.0f ) ;
m_engine - > SetObjectShadowSpotAngle ( m_objectPart [ 0 ] . object , m_objectPart [ 0 ] . angle . y ) ;
m_engine - > SetObjectShadowSpotType ( m_objectPart [ 0 ] . object , type ) ;
2012-06-26 20:23:05 +00:00
return true ;
}
// Calculates the matrix for transforming the object.
2012-10-17 19:55:45 +00:00
// Returns true if the matrix has changed.
2012-06-26 20:23:05 +00:00
// The rotations occur in the order Y, Z and X.
2015-07-02 21:48:30 +00:00
bool COldObject : : UpdateTransformObject ( int part , bool bForceUpdate )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 position , angle , eye ;
2012-06-26 20:23:05 +00:00
bool bModif = false ;
int parent ;
2015-08-17 20:40:52 +00:00
if ( m_transporter ! = nullptr ) // transported by transporter?
2012-06-26 20:23:05 +00:00
{
m_objectPart [ part ] . bTranslate = true ;
m_objectPart [ part ] . bRotate = true ;
}
if ( ! bForceUpdate & &
! m_objectPart [ part ] . bTranslate & &
! m_objectPart [ part ] . bRotate ) return false ;
position = m_objectPart [ part ] . position ;
angle = m_objectPart [ part ] . angle ;
if ( part = = 0 ) // main part?
{
position + = m_linVibration ;
2015-06-29 20:45:38 +00:00
angle + = m_cirVibration + m_tilt ;
2012-06-26 20:23:05 +00:00
}
if ( m_objectPart [ part ] . bTranslate | |
m_objectPart [ part ] . bRotate )
{
if ( m_objectPart [ part ] . bTranslate )
{
2022-01-04 23:35:41 +00:00
m_objectPart [ part ] . matTranslate = glm : : mat4 ( 1.0f ) ;
m_objectPart [ part ] . matTranslate [ 3 ] [ 0 ] = position . x ;
m_objectPart [ part ] . matTranslate [ 3 ] [ 1 ] = position . y ;
m_objectPart [ part ] . matTranslate [ 3 ] [ 2 ] = position . z ;
2012-06-26 20:23:05 +00:00
}
if ( m_objectPart [ part ] . bRotate )
{
Math : : LoadRotationZXYMatrix ( m_objectPart [ part ] . matRotate , angle ) ;
}
if ( m_objectPart [ part ] . bZoom )
{
2022-01-04 23:35:41 +00:00
glm : : mat4 mz = glm : : mat4 ( 1.0f ) ;
mz [ 0 ] [ 0 ] = m_objectPart [ part ] . zoom . x ;
mz [ 1 ] [ 1 ] = m_objectPart [ part ] . zoom . y ;
mz [ 2 ] [ 2 ] = m_objectPart [ part ] . zoom . z ;
m_objectPart [ part ] . matTransform = m_objectPart [ part ] . matTranslate * m_objectPart [ part ] . matRotate * mz ;
2012-06-26 20:23:05 +00:00
}
else
{
2022-01-04 23:35:41 +00:00
m_objectPart [ part ] . matTransform = m_objectPart [ part ] . matTranslate * m_objectPart [ part ] . matRotate ;
2012-06-26 20:23:05 +00:00
}
bModif = true ;
}
if ( bForceUpdate | |
m_objectPart [ part ] . bTranslate | |
m_objectPart [ part ] . bRotate )
{
parent = m_objectPart [ part ] . parentPart ;
2015-08-17 20:40:52 +00:00
if ( part = = 0 & & m_transporter ! = nullptr ) // transported by a transporter?
2012-06-26 20:23:05 +00:00
{
2022-01-04 23:35:41 +00:00
glm : : mat4 matWorldTransporter = m_transporter - > GetWorldMatrix ( m_transporterLink ) ;
m_objectPart [ part ] . matWorld = matWorldTransporter * m_objectPart [ part ] . matTransform ;
2012-06-26 20:23:05 +00:00
}
else
{
if ( parent = = - 1 ) // no parent?
{
m_objectPart [ part ] . matWorld = m_objectPart [ part ] . matTransform ;
}
else
{
2022-01-04 23:35:41 +00:00
m_objectPart [ part ] . matWorld = m_objectPart [ parent ] . matWorld * m_objectPart [ part ] . matTransform ;
2012-06-26 20:23:05 +00:00
}
}
bModif = true ;
}
if ( bModif )
{
m_engine - > SetObjectTransform ( m_objectPart [ part ] . object ,
m_objectPart [ part ] . matWorld ) ;
}
m_objectPart [ part ] . bTranslate = false ;
m_objectPart [ part ] . bRotate = false ;
return bModif ;
}
// Updates all matrices to transform the object father and all his sons.
// Assume a maximum of 4 degrees of freedom.
// Appropriate, for example, to a body, an arm, forearm, hand and fingers.
2015-07-02 21:48:30 +00:00
bool COldObject : : UpdateTransformObject ( )
2012-06-26 20:23:05 +00:00
{
bool bUpdate1 , bUpdate2 , bUpdate3 , bUpdate4 ;
int level1 , level2 , level3 , level4 , rank ;
int parent1 , parent2 , parent3 , parent4 ;
if ( m_bFlat )
{
for ( level1 = 0 ; level1 < m_totalPart ; level1 + + )
{
if ( ! m_objectPart [ level1 ] . bUsed ) continue ;
UpdateTransformObject ( level1 , false ) ;
}
}
else
{
parent1 = 0 ;
bUpdate1 = UpdateTransformObject ( parent1 , false ) ;
for ( level1 = 0 ; level1 < m_totalPart ; level1 + + )
{
rank = SearchDescendant ( parent1 , level1 ) ;
if ( rank = = - 1 ) break ;
parent2 = rank ;
bUpdate2 = UpdateTransformObject ( rank , bUpdate1 ) ;
for ( level2 = 0 ; level2 < m_totalPart ; level2 + + )
{
rank = SearchDescendant ( parent2 , level2 ) ;
if ( rank = = - 1 ) break ;
parent3 = rank ;
bUpdate3 = UpdateTransformObject ( rank , bUpdate2 ) ;
for ( level3 = 0 ; level3 < m_totalPart ; level3 + + )
{
rank = SearchDescendant ( parent3 , level3 ) ;
if ( rank = = - 1 ) break ;
parent4 = rank ;
bUpdate4 = UpdateTransformObject ( rank , bUpdate3 ) ;
for ( level4 = 0 ; level4 < m_totalPart ; level4 + + )
{
rank = SearchDescendant ( parent4 , level4 ) ;
if ( rank = = - 1 ) break ;
UpdateTransformObject ( rank , bUpdate4 ) ;
}
}
}
}
}
return true ;
}
// Puts all the progeny flat (there is more than fathers).
// This allows for debris independently from each other in all directions.
2015-07-02 21:48:30 +00:00
void COldObject : : FlatParent ( )
2012-06-26 20:23:05 +00:00
{
int i ;
for ( i = 0 ; i < m_totalPart ; i + + )
{
2022-01-04 23:35:41 +00:00
m_objectPart [ i ] . position . x = m_objectPart [ i ] . matWorld [ 3 ] [ 0 ] ;
m_objectPart [ i ] . position . y = m_objectPart [ i ] . matWorld [ 3 ] [ 1 ] ;
m_objectPart [ i ] . position . z = m_objectPart [ i ] . matWorld [ 3 ] [ 2 ] ;
2012-06-26 20:23:05 +00:00
2022-01-04 23:35:41 +00:00
m_objectPart [ i ] . matWorld [ 3 ] [ 0 ] = 0.0f ;
m_objectPart [ i ] . matWorld [ 3 ] [ 1 ] = 0.0f ;
m_objectPart [ i ] . matWorld [ 3 ] [ 2 ] = 0.0f ;
2012-06-26 20:23:05 +00:00
2022-01-04 23:35:41 +00:00
m_objectPart [ i ] . matTranslate [ 3 ] [ 0 ] = 0.0f ;
m_objectPart [ i ] . matTranslate [ 3 ] [ 1 ] = 0.0f ;
m_objectPart [ i ] . matTranslate [ 3 ] [ 2 ] = 0.0f ;
2012-06-26 20:23:05 +00:00
m_objectPart [ i ] . parentPart = - 1 ; // more parents
}
m_bFlat = true ;
}
// Updates the mapping of the texture of the pile.
2015-07-02 21:48:30 +00:00
void COldObject : : UpdateEnergyMapping ( )
2012-06-26 20:23:05 +00:00
{
2022-02-02 17:13:21 +00:00
if ( m_lastEnergy = = GetEnergyLevel ( ) )
2013-01-27 10:43:53 +00:00
return ;
2012-06-26 20:23:05 +00:00
2015-08-12 14:54:44 +00:00
m_lastEnergy = GetEnergyLevel ( ) ;
2012-06-26 20:23:05 +00:00
2013-01-27 10:43:53 +00:00
float a = 0.0f , b = 0.0f ;
2012-06-26 20:23:05 +00:00
if ( m_type = = OBJECT_POWER | |
m_type = = OBJECT_ATOMIC )
{
a = 2.0f ;
b = 0.0f ; // dimensions of the battery (according to y)
}
2013-01-27 10:43:53 +00:00
else if ( m_type = = OBJECT_STATION )
2012-06-26 20:23:05 +00:00
{
a = 10.0f ;
b = 4.0f ; // dimensions of the battery (according to y)
}
2013-01-27 10:43:53 +00:00
else if ( m_type = = OBJECT_ENERGY )
2012-06-26 20:23:05 +00:00
{
a = 9.0f ;
b = 3.0f ; // dimensions of the battery (according to y)
}
2015-08-12 14:54:44 +00:00
float i = 0.50f + 0.25f * GetEnergyLevel ( ) ; // origin
2013-01-27 10:43:53 +00:00
float s = i + 0.25f ; // width
2012-06-26 20:23:05 +00:00
2013-01-27 10:43:53 +00:00
float au = ( s - i ) / ( b - a ) ;
float bu = s - b * ( s - i ) / ( b - a ) ;
2012-06-26 20:23:05 +00:00
2015-07-22 15:38:16 +00:00
std : : string teamStr = StrUtils : : ToString < int > ( GetTeam ( ) ) ;
if ( GetTeam ( ) = = 0 ) teamStr = " " ;
2022-02-02 17:13:21 +00:00
2022-02-12 23:03:46 +00:00
m_engine - > SetUVTransform ( m_objectPart [ 0 ] . object , " energy " ,
2022-02-02 17:13:21 +00:00
{ 0.0f , 0.25f * ( GetEnergyLevel ( ) - 1.0f ) } , { 1.0f , 1.0f } ) ;
2012-06-26 20:23:05 +00:00
}
// Manual action.
2015-07-02 21:48:30 +00:00
bool COldObject : : EventProcess ( const Event & event )
2012-06-26 20:23:05 +00:00
{
2015-08-12 14:54:44 +00:00
// NOTE: This should be called befoce CProgrammableObjectImpl::EventProcess, see the other note inside this function
2015-08-13 20:27:10 +00:00
if ( ! CTaskExecutorObjectImpl : : EventProcess ( event ) ) return false ;
2015-08-10 11:46:39 +00:00
2015-06-22 19:58:58 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
if ( ! m_physics - > EventProcess ( event ) ) // object destroyed?
{
2012-09-10 21:29:38 +00:00
if ( GetSelect ( ) & &
2012-06-26 20:23:05 +00:00
m_type ! = OBJECT_ANT & &
m_type ! = OBJECT_SPIDER & &
m_type ! = OBJECT_BEE )
{
2015-08-16 18:24:48 +00:00
if ( ! IsDying ( ) ) m_camera - > SetType ( Gfx : : CAM_TYPE_EXPLO ) ;
2012-06-26 20:23:05 +00:00
m_main - > DeselectAll ( ) ;
}
return false ;
}
}
2015-08-10 21:20:36 +00:00
if ( Implements ( ObjectInterfaceType : : Movable ) & & m_physics ! = nullptr )
{
bool deselectedStop = ! GetSelect ( ) ;
if ( Implements ( ObjectInterfaceType : : Programmable ) )
{
deselectedStop = deselectedStop & & ! IsProgram ( ) ;
}
if ( Implements ( ObjectInterfaceType : : TaskExecutor ) )
{
deselectedStop = deselectedStop & & ! IsForegroundTask ( ) ;
}
if ( deselectedStop )
2015-08-10 16:16:00 +00:00
{
float axeX = 0.0f ;
float axeY = 0.0f ;
float axeZ = 0.0f ;
2015-08-16 18:24:48 +00:00
if ( GetDying ( ) = = DeathType : : Burning ) // Burning?
2015-08-10 16:16:00 +00:00
{
axeZ = - 1.0f ; // tomb
2015-08-17 11:19:21 +00:00
if ( ( m_type = = OBJECT_ANT | |
2015-08-10 16:16:00 +00:00
m_type = = OBJECT_SPIDER | |
m_type = = OBJECT_WORM ) )
{
2015-08-17 11:19:21 +00:00
// TODO: Move to CBaseAlien?
CBaseAlien * alien = dynamic_cast < CBaseAlien * > ( this ) ;
assert ( alien ! = nullptr ) ;
if ( ! alien - > GetFixed ( ) )
{
axeY = 2.0f ; // zigzag disorganized fast
if ( m_type = = OBJECT_WORM ) axeY = 5.0f ;
axeX = 0.5f + sinf ( m_time * 1.0f ) * 0.5f +
sinf ( m_time * 6.0f ) * 2.0f +
sinf ( m_time * 21.0f ) * 0.2f ;
float factor = 1.0f - m_burnTime / 15.0f ; // slow motion
if ( factor < 0.0f ) factor = 0.0f ;
axeY * = factor ;
axeX * = factor ;
}
2015-08-10 16:16:00 +00:00
}
}
m_physics - > SetMotorSpeedX ( axeY ) ; // move forward/move back
m_physics - > SetMotorSpeedY ( axeZ ) ; // up / down
m_physics - > SetMotorSpeedZ ( axeX ) ; // rotate
}
else if ( GetSelect ( ) )
{
2015-08-10 21:20:36 +00:00
bool canMove = true ;
if ( Implements ( ObjectInterfaceType : : TaskExecutor ) )
{
2015-08-25 15:21:25 +00:00
canMove = canMove & & ( ! IsForegroundTask ( ) | | GetForegroundTask ( ) - > IsPilot ( ) ) ;
2015-08-10 21:20:36 +00:00
}
2015-08-17 16:26:09 +00:00
if ( Implements ( ObjectInterfaceType : : Programmable ) )
{
canMove = canMove & & ! IsProgram ( ) ;
}
2015-08-10 21:20:36 +00:00
if ( canMove )
2015-08-10 16:16:00 +00:00
{
if ( event . type = = EVENT_OBJECT_LEFT | |
event . type = = EVENT_OBJECT_RIGHT | |
event . type = = EVENT_OBJECT_UP | |
event . type = = EVENT_OBJECT_DOWN | |
event . type = = EVENT_OBJECT_GASUP | |
event . type = = EVENT_OBJECT_GASDOWN )
{
m_buttonAxe = event . type ;
}
if ( event . type = = EVENT_MOUSE_BUTTON_UP )
{
m_buttonAxe = EVENT_NULL ;
}
float axeX = event . motionInput . x ;
float axeY = event . motionInput . y ;
float axeZ = event . motionInput . z ;
if ( ( ! m_main - > GetTrainerPilot ( ) & &
GetTrainer ( ) ) | |
! m_main - > CanPlayerInteract ( ) ) // drive vehicle?
{
axeX = 0.0f ;
axeY = 0.0f ;
axeZ = 0.0f ; // Remote control impossible!
}
if ( m_buttonAxe = = EVENT_OBJECT_LEFT ) axeX = - 1.0f ;
if ( m_buttonAxe = = EVENT_OBJECT_RIGHT ) axeX = 1.0f ;
if ( m_buttonAxe = = EVENT_OBJECT_UP ) axeY = 1.0f ;
if ( m_buttonAxe = = EVENT_OBJECT_DOWN ) axeY = - 1.0f ;
if ( m_buttonAxe = = EVENT_OBJECT_GASUP ) axeZ = 1.0f ;
if ( m_buttonAxe = = EVENT_OBJECT_GASDOWN ) axeZ = - 1.0f ;
if ( m_type = = OBJECT_MOBILEdr & & GetManual ( ) ) // scribbler in manual mode?
{
if ( axeX ! = 0.0f ) axeY = 0.0f ; // if running -> not moving!
axeX * = 0.5f ;
axeY * = 0.5f ;
}
if ( ! m_main - > IsResearchDone ( RESEARCH_FLY , GetTeam ( ) ) )
{
axeZ = - 1.0f ; // tomb
}
if ( axeX > 1.0f ) axeX = 1.0f ;
if ( axeX < - 1.0f ) axeX = - 1.0f ;
m_physics - > SetMotorSpeedX ( axeY ) ; // move forward/move back
m_physics - > SetMotorSpeedY ( axeZ ) ; // up/down
m_physics - > SetMotorSpeedZ ( axeX ) ; // rotate
}
}
2015-08-10 11:46:39 +00:00
}
2015-08-10 14:37:03 +00:00
if ( m_objectInterface ! = nullptr )
{
m_objectInterface - > EventProcess ( event ) ;
}
2015-06-22 19:58:58 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-08-25 08:57:36 +00:00
if ( ! GetLock ( ) )
{
m_auto - > EventProcess ( event ) ;
}
2012-06-26 20:23:05 +00:00
2012-09-10 21:29:38 +00:00
if ( event . type = = EVENT_FRAME & &
2012-06-26 20:23:05 +00:00
m_auto - > IsEnded ( ) ! = ERR_CONTINUE )
{
m_auto - > DeleteObject ( ) ;
2015-06-22 19:58:58 +00:00
m_auto . reset ( ) ;
2012-06-26 20:23:05 +00:00
}
}
2015-06-22 19:58:58 +00:00
if ( m_motion ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2015-08-11 22:12:37 +00:00
if ( ! m_motion - > EventProcess ( event ) ) return false ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 20:27:10 +00:00
if ( ! CProgrammableObjectImpl : : EventProcess ( event ) ) return false ;
2015-08-12 14:54:44 +00:00
2012-09-10 21:29:38 +00:00
if ( event . type = = EVENT_FRAME )
2012-06-26 20:23:05 +00:00
{
return EventFrame ( event ) ;
}
return true ;
}
// Animates the object.
2015-07-02 21:48:30 +00:00
bool COldObject : : EventFrame ( const Event & event )
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
if ( m_type = = OBJECT_HUMAN & & m_main - > GetMainMovie ( ) = = MM_SATCOMopen )
2012-06-26 20:23:05 +00:00
{
UpdateTransformObject ( ) ;
return true ;
}
2015-08-10 16:16:00 +00:00
m_time + = event . rTime ;
2015-08-10 11:46:39 +00:00
if ( m_engine - > GetPause ( ) & & m_type ! = OBJECT_SHOW ) return true ;
2012-06-26 20:23:05 +00:00
2015-08-16 18:24:48 +00:00
if ( GetDying ( ) = = DeathType : : Burning ) m_burnTime + = event . rTime ;
2015-08-10 16:16:00 +00:00
2012-06-26 20:23:05 +00:00
m_aTime + = event . rTime ;
m_shotTime + = event . rTime ;
VirusFrame ( event . rTime ) ;
PartiFrame ( event . rTime ) ;
UpdateMapping ( ) ;
UpdateTransformObject ( ) ;
2012-09-10 21:29:38 +00:00
UpdateSelectParticle ( ) ;
2012-06-26 20:23:05 +00:00
2015-08-13 11:41:25 +00:00
if ( Implements ( ObjectInterfaceType : : ShieldedAutoRegen ) )
{
SetShield ( GetShield ( ) + event . rTime * ( 1.0f / GetShieldFullRegenTime ( ) ) ) ;
}
2017-10-17 00:33:05 +00:00
if ( m_damaging & & m_time - m_damageTime > 2.0f )
{
SetDamaging ( false ) ;
m_main - > UpdateShortcuts ( ) ;
}
2012-06-26 20:23:05 +00:00
return true ;
}
// Updates the mapping of the object.
2015-07-02 21:48:30 +00:00
void COldObject : : UpdateMapping ( )
2012-06-26 20:23:05 +00:00
{
2015-08-18 10:29:41 +00:00
if ( Implements ( ObjectInterfaceType : : PowerContainer ) )
2012-06-26 20:23:05 +00:00
{
UpdateEnergyMapping ( ) ;
}
}
// Management of viruses.
2015-07-02 21:48:30 +00:00
void COldObject : : VirusFrame ( float rTime )
2012-06-26 20:23:05 +00:00
{
if ( ! m_bVirusMode ) return ; // healthy object?
m_virusTime + = rTime ;
if ( m_virusTime > = VIRUS_DELAY )
{
m_bVirusMode = false ; // the virus is no longer active
}
2012-09-10 21:29:38 +00:00
if ( m_lastVirusParticle + m_engine - > ParticleAdapt ( 0.2f ) < = m_aTime )
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
m_lastVirusParticle = m_aTime ;
2012-06-26 20:23:05 +00:00
2022-01-03 21:51:36 +00:00
glm : : vec3 pos = GetPosition ( ) ;
2012-06-26 20:23:05 +00:00
pos . x + = ( Math : : Rand ( ) - 0.5f ) * 10.0f ;
pos . z + = ( Math : : Rand ( ) - 0.5f ) * 10.0f ;
2022-01-03 21:51:36 +00:00
glm : : vec3 speed ;
2012-06-26 20:23:05 +00:00
speed . x = ( Math : : Rand ( ) - 0.5f ) * 2.0f ;
speed . z = ( Math : : Rand ( ) - 0.5f ) * 2.0f ;
speed . y = Math : : Rand ( ) * 4.0f + 4.0f ;
2021-12-24 19:08:04 +00:00
glm : : vec2 dim ;
2012-06-26 20:23:05 +00:00
dim . x = Math : : Rand ( ) * 0.3f + 0.3f ;
dim . y = dim . x ;
2015-08-07 13:18:04 +00:00
m_particle - > CreateParticle ( pos , speed , dim , Gfx : : PARTIVIRUS , 3.0f ) ;
2012-06-26 20:23:05 +00:00
}
}
// Management particles mistresses.
2015-07-02 21:48:30 +00:00
void COldObject : : PartiFrame ( float rTime )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 pos , angle , factor ;
2012-06-26 20:23:05 +00:00
int i , channel ;
for ( i = 0 ; i < OBJECTMAXPART ; i + + )
{
if ( ! m_objectPart [ i ] . bUsed ) continue ;
channel = m_objectPart [ i ] . masterParti ;
if ( channel = = - 1 ) continue ;
2016-09-27 16:32:21 +00:00
if ( ! m_particle - > GetPosition ( channel , pos ) )
2012-06-26 20:23:05 +00:00
{
m_objectPart [ i ] . masterParti = - 1 ; // particle no longer exists!
continue ;
}
2015-07-13 21:19:46 +00:00
SetPartPosition ( i , pos ) ;
2012-06-26 20:23:05 +00:00
2016-09-27 16:32:21 +00:00
// Each song spins differently.
2012-06-26 20:23:05 +00:00
switch ( i % 5 )
{
2022-01-03 21:51:36 +00:00
case 0 : factor = glm : : vec3 ( 0.5f , 0.3f , 0.6f ) ; break ;
case 1 : factor = glm : : vec3 ( - 0.3f , 0.4f , - 0.2f ) ; break ;
case 2 : factor = glm : : vec3 ( 0.4f , - 0.6f , - 0.3f ) ; break ;
case 3 : factor = glm : : vec3 ( - 0.6f , - 0.2f , 0.0f ) ; break ;
case 4 : factor = glm : : vec3 ( 0.4f , 0.1f , - 0.7f ) ; break ;
2012-06-26 20:23:05 +00:00
}
2015-07-14 19:29:13 +00:00
angle = GetPartRotation ( i ) ;
2012-06-26 20:23:05 +00:00
angle + = rTime * Math : : PI * factor ;
2015-07-14 19:29:13 +00:00
SetPartRotation ( i , angle ) ;
2012-06-26 20:23:05 +00:00
}
}
// Changes the perspective to view if it was like in the vehicle,
// or behind the vehicle.
2022-01-03 21:51:36 +00:00
void COldObject : : AdjustCamera ( glm : : vec3 & eye , float & dirH , float & dirV ,
glm : : vec3 & lookat , glm : : vec3 & upVec ,
2012-09-10 21:29:38 +00:00
Gfx : : CameraType type )
2012-06-26 20:23:05 +00:00
{
float speed ;
int part ;
UpdateTransformObject ( ) ;
part = 0 ;
if ( m_type = = OBJECT_HUMAN | |
m_type = = OBJECT_TECH )
{
eye . x = - 0.2f ;
eye . y = 3.3f ;
eye . z = 0.0f ;
//? eye.x = 1.0f;
//? eye.y = 3.3f;
//? eye.z = 0.0f;
}
else if ( m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErr | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILErp )
2012-06-26 20:23:05 +00:00
{
eye . x = - 1.1f ; // on the cap
eye . y = 7.9f ;
eye . z = 0.0f ;
}
else if ( m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEic ) // fireball?
{
//? eye.x = -0.9f; // on the cannon
//? eye.y = 3.0f;
//? eye.z = 0.0f;
//? part = 1;
eye . x = - 0.9f ; // on the cannon
eye . y = 8.3f ;
eye . z = 0.0f ;
}
else if ( m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEii ) // orgaball ?
{
//? eye.x = -3.5f; // on the cannon
//? eye.y = 5.1f;
//? eye.z = 0.0f;
//? part = 1;
eye . x = - 2.5f ; // on the cannon
eye . y = 10.4f ;
eye . z = 0.0f ;
}
else if ( m_type = = OBJECT_MOBILErc )
{
//? eye.x = 2.0f; // in the cannon
//? eye.y = 0.0f;
//? eye.z = 0.0f;
//? part = 2;
eye . x = 4.0f ; // on the cannon
eye . y = 11.0f ;
eye . z = 0.0f ;
}
2018-12-23 06:04:06 +00:00
else if ( m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEst )
2012-06-26 20:23:05 +00:00
{
eye . x = 3.0f ;
eye . y = 4.5f ;
eye . z = 0.0f ;
}
else if ( m_type = = OBJECT_MOBILEdr )
{
eye . x = 1.0f ;
eye . y = 6.5f ;
eye . z = 0.0f ;
}
else if ( m_type = = OBJECT_APOLLO2 )
{
eye . x = - 3.0f ;
eye . y = 6.0f ;
eye . z = - 2.0f ;
}
else
{
eye . x = 0.7f ; // between the brackets
eye . y = 4.8f ;
eye . z = 0.0f ;
}
2012-09-10 21:29:38 +00:00
if ( type = = Gfx : : CAM_TYPE_BACK )
2012-06-26 20:23:05 +00:00
{
eye . x - = 20.0f ;
eye . y + = 1.0f ;
}
lookat . x = eye . x + 1.0f ;
lookat . y = eye . y + 0.0f ;
lookat . z = eye . z + 0.0f ;
eye = Math : : Transform ( m_objectPart [ part ] . matWorld , eye ) ;
lookat = Math : : Transform ( m_objectPart [ part ] . matWorld , lookat ) ;
// Camera tilts when turning.
2022-01-03 21:51:36 +00:00
upVec = glm : : vec3 ( 0.0f , 1.0f , 0.0f ) ;
2015-06-22 19:58:58 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
if ( m_physics - > GetLand ( ) ) // on ground?
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
speed = m_physics - > GetLinMotionX ( MO_REASPEED ) ;
2012-06-26 20:23:05 +00:00
lookat . y - = speed * 0.002f ;
2012-09-10 21:29:38 +00:00
speed = m_physics - > GetCirMotionY ( MO_REASPEED ) ;
2012-06-26 20:23:05 +00:00
upVec . z - = speed * 0.04f ;
}
else // in flight?
{
2012-09-10 21:29:38 +00:00
speed = m_physics - > GetLinMotionX ( MO_REASPEED ) ;
2012-06-26 20:23:05 +00:00
lookat . y + = speed * 0.002f ;
2012-09-10 21:29:38 +00:00
speed = m_physics - > GetCirMotionY ( MO_REASPEED ) ;
2012-06-26 20:23:05 +00:00
upVec . z + = speed * 0.08f ;
}
}
upVec = Math : : Transform ( m_objectPart [ 0 ] . matRotate , upVec ) ;
dirH = - ( m_objectPart [ part ] . angle . y + Math : : PI / 2.0f ) ;
dirV = 0.0f ;
}
// Management of features.
2015-07-02 21:48:30 +00:00
Character * COldObject : : GetCharacter ( )
2012-06-26 20:23:05 +00:00
{
return & m_character ;
}
2012-10-17 19:55:45 +00:00
// Returns the absolute time.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
float COldObject : : GetAbsTime ( )
2012-06-26 20:23:05 +00:00
{
return m_aTime ;
}
2015-07-02 21:48:30 +00:00
float COldObject : : GetCapacity ( )
2012-06-26 20:23:05 +00:00
{
2020-08-31 11:37:45 +00:00
return m_type = = OBJECT_ATOMIC ? m_main - > GetGlobalNuclearCapacity ( ) : m_main - > GetGlobalCellCapacity ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-11 20:51:09 +00:00
bool COldObject : : IsRechargeable ( )
{
return m_type = = OBJECT_POWER ;
}
2012-06-26 20:23:05 +00:00
// Management of the shield.
2015-07-02 21:48:30 +00:00
void COldObject : : SetShield ( float level )
2012-06-26 20:23:05 +00:00
{
2015-08-13 11:41:25 +00:00
if ( level > 1.0f ) level = 1.0f ;
if ( level < 0.0f ) level = 0.0f ;
2012-06-26 20:23:05 +00:00
m_shield = level ;
}
2015-07-02 21:48:30 +00:00
float COldObject : : GetShield ( )
2012-06-26 20:23:05 +00:00
{
2015-08-18 09:42:55 +00:00
if ( Implements ( ObjectInterfaceType : : Fragile ) ) return 0.0f ;
2012-06-26 20:23:05 +00:00
return m_shield ;
}
// Management of flight range (zero = infinity).
2015-07-02 21:48:30 +00:00
void COldObject : : SetRange ( float delay )
2012-06-26 20:23:05 +00:00
{
m_range = delay ;
}
2015-07-02 21:48:30 +00:00
float COldObject : : GetRange ( )
2012-06-26 20:23:05 +00:00
{
return m_range ;
}
2015-08-13 08:49:26 +00:00
void COldObject : : SetReactorRange ( float reactorRange )
{
if ( reactorRange > 1.0f ) reactorRange = 1.0f ;
if ( reactorRange < 0.0f ) reactorRange = 0.0f ;
m_reactorRange = reactorRange ;
}
float COldObject : : GetReactorRange ( )
{
return m_reactorRange ;
}
2012-06-26 20:23:05 +00:00
// Pushes an object.
2015-07-02 21:48:30 +00:00
bool COldObject : : JostleObject ( float force )
2012-06-26 20:23:05 +00:00
{
if ( m_type = = OBJECT_FLAGb | |
m_type = = OBJECT_FLAGr | |
m_type = = OBJECT_FLAGg | |
m_type = = OBJECT_FLAGy | |
m_type = = OBJECT_FLAGv ) // flag?
{
2015-06-22 19:58:58 +00:00
if ( m_auto = = nullptr ) return false ;
2012-06-26 20:23:05 +00:00
m_auto - > Start ( 1 ) ;
}
else
{
2015-06-22 19:58:58 +00:00
if ( m_auto ! = nullptr ) return false ;
2012-06-26 20:23:05 +00:00
2022-02-26 17:48:51 +00:00
auto autoJostle = std : : make_unique < CAutoJostle > ( this ) ;
2015-06-22 19:58:58 +00:00
autoJostle - > Start ( 0 , force ) ;
m_auto = std : : move ( autoJostle ) ;
2012-06-26 20:23:05 +00:00
}
return true ;
}
// Management of time from which a virus is active.
2015-07-02 21:48:30 +00:00
void COldObject : : SetVirusMode ( bool bEnable )
2012-06-26 20:23:05 +00:00
{
m_bVirusMode = bEnable ;
m_virusTime = 0.0f ;
2015-08-10 16:16:00 +00:00
if ( m_bVirusMode & & Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2015-08-10 16:16:00 +00:00
if ( ! IntroduceVirus ( ) ) // tries to infect
2012-06-26 20:23:05 +00:00
{
m_bVirusMode = false ; // program was not contaminated!
}
}
}
2015-07-02 21:48:30 +00:00
bool COldObject : : GetVirusMode ( )
2012-06-26 20:23:05 +00:00
{
return m_bVirusMode ;
}
// Management mode of the camera.
2015-07-02 21:48:30 +00:00
void COldObject : : SetCameraType ( Gfx : : CameraType type )
2012-06-26 20:23:05 +00:00
{
m_cameraType = type ;
}
2015-07-02 21:48:30 +00:00
Gfx : : CameraType COldObject : : GetCameraType ( )
2012-06-26 20:23:05 +00:00
{
return m_cameraType ;
}
2015-08-10 21:20:36 +00:00
void COldObject : : SetCameraLock ( bool lock )
2012-06-26 20:23:05 +00:00
{
2015-08-10 21:20:36 +00:00
m_bCameraLock = lock ;
2012-06-26 20:23:05 +00:00
}
2015-07-02 21:48:30 +00:00
bool COldObject : : GetCameraLock ( )
2012-06-26 20:23:05 +00:00
{
return m_bCameraLock ;
}
// Management of the demonstration of the object.
2015-08-11 21:37:44 +00:00
void COldObject : : SetHighlight ( bool highlight )
2012-06-26 20:23:05 +00:00
{
2015-08-11 21:37:44 +00:00
if ( highlight )
2012-06-26 20:23:05 +00:00
{
2015-06-29 20:45:38 +00:00
int list [ OBJECTMAXPART + 1 ] ;
int j = 0 ;
for ( int i = 0 ; i < m_totalPart ; i + + )
2012-06-26 20:23:05 +00:00
{
if ( m_objectPart [ i ] . bUsed )
{
list [ j + + ] = m_objectPart [ i ] . object ;
}
}
list [ j ] = - 1 ; // terminate
2012-09-10 21:29:38 +00:00
m_engine - > SetHighlightRank ( list ) ; // gives the list of selected parts
2012-06-26 20:23:05 +00:00
}
}
// Indicates whether the object is selected or not.
2015-08-10 21:20:36 +00:00
void COldObject : : SetSelect ( bool select , bool bDisplayError )
2012-06-26 20:23:05 +00:00
{
2015-08-10 21:20:36 +00:00
m_bSelect = select ;
2012-06-26 20:23:05 +00:00
2015-08-10 14:37:03 +00:00
// NOTE: Right now, Ui::CObjectInterface is only for programmable objects. Right now all selectable objects are programmable anyway.
// TODO: All UI-related stuff should be moved out of CObject classes
if ( Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2015-08-10 14:37:03 +00:00
if ( m_objectInterface = = nullptr )
{
2022-02-26 17:48:51 +00:00
m_objectInterface = std : : make_unique < Ui : : CObjectInterface > ( this ) ;
2015-08-10 14:37:03 +00:00
}
m_objectInterface - > CreateInterface ( m_bSelect ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-22 19:58:58 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
m_auto - > CreateInterface ( m_bSelect ) ;
}
2012-09-10 21:29:38 +00:00
CreateSelectParticle ( ) ; // creates / removes particles
2012-06-26 20:23:05 +00:00
if ( ! m_bSelect )
2015-08-10 21:20:36 +00:00
return ; // if not selected, we're done
2012-06-26 20:23:05 +00:00
2015-08-10 21:20:36 +00:00
Error err = ERR_OK ;
2015-06-22 19:58:58 +00:00
if ( m_physics ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
err = m_physics - > GetError ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-06-22 19:58:58 +00:00
if ( m_auto ! = nullptr )
2012-06-26 20:23:05 +00:00
{
2012-09-10 21:29:38 +00:00
err = m_auto - > GetError ( ) ;
2012-06-26 20:23:05 +00:00
}
if ( err ! = ERR_OK & & bDisplayError )
{
2013-06-24 20:09:39 +00:00
m_main - > DisplayError ( err , this ) ;
2012-06-26 20:23:05 +00:00
}
}
// Indicates whether the object is selected or not.
2015-08-10 21:20:36 +00:00
bool COldObject : : GetSelect ( )
2012-06-26 20:23:05 +00:00
{
return m_bSelect ;
}
// Indicates whether the object is selectable or not.
2015-07-02 21:48:30 +00:00
void COldObject : : SetSelectable ( bool bMode )
2012-06-26 20:23:05 +00:00
{
m_bSelectable = bMode ;
}
// Indicates whether the object is selecionnable or not.
2015-07-02 21:48:30 +00:00
bool COldObject : : GetSelectable ( )
2012-06-26 20:23:05 +00:00
{
return m_bSelectable ;
}
// Indicates if necessary to check the tokens of the object.
2015-07-02 21:48:30 +00:00
void COldObject : : SetCheckToken ( bool bMode )
2012-06-26 20:23:05 +00:00
{
m_bCheckToken = bMode ;
}
// Indicates if necessary to check the tokens of the object.
2015-07-02 21:48:30 +00:00
bool COldObject : : GetCheckToken ( )
2012-06-26 20:23:05 +00:00
{
return m_bCheckToken ;
}
2015-08-16 18:24:48 +00:00
// Sets if this object is underground or not. Underground objects are not detectable. Used by AlienWorm
2012-06-26 20:23:05 +00:00
2015-08-16 18:24:48 +00:00
void COldObject : : SetUnderground ( bool underground )
2012-06-26 20:23:05 +00:00
{
2015-08-16 18:24:48 +00:00
m_underground = underground ;
2012-06-26 20:23:05 +00:00
}
// Management of the method of increasing damage.
2015-07-02 21:48:30 +00:00
void COldObject : : SetMagnifyDamage ( float factor )
2012-06-26 20:23:05 +00:00
{
m_magnifyDamage = factor ;
}
2015-07-02 21:48:30 +00:00
float COldObject : : GetMagnifyDamage ( )
2012-06-26 20:23:05 +00:00
{
return m_magnifyDamage ;
}
2017-06-20 21:35:33 +00:00
void COldObject : : SetDamaging ( bool damaging )
{
m_damaging = damaging ;
}
bool COldObject : : IsDamaging ( )
{
return m_damaging ;
}
2012-06-26 20:23:05 +00:00
2015-08-16 18:24:48 +00:00
void COldObject : : SetDying ( DeathType deathType )
2012-06-26 20:23:05 +00:00
{
2015-08-16 18:24:48 +00:00
m_dying = deathType ;
2015-08-10 16:16:00 +00:00
m_burnTime = 0.0f ;
2012-06-26 20:23:05 +00:00
2015-08-16 18:24:48 +00:00
if ( IsDying ( ) & & Implements ( ObjectInterfaceType : : Programmable ) )
2012-06-26 20:23:05 +00:00
{
2015-08-10 16:16:00 +00:00
StopProgram ( ) ; // stops the current task
2012-06-26 20:23:05 +00:00
}
}
2015-08-16 18:24:48 +00:00
DeathType COldObject : : GetDying ( )
2012-06-26 20:23:05 +00:00
{
2015-08-16 18:24:48 +00:00
return m_dying ;
2012-06-26 20:23:05 +00:00
}
2015-08-16 18:24:48 +00:00
bool COldObject : : IsDying ( )
2012-06-26 20:23:05 +00:00
{
2015-08-16 18:24:48 +00:00
return m_dying ! = DeathType : : Alive ;
2012-06-26 20:23:05 +00:00
}
2015-07-02 21:48:30 +00:00
bool COldObject : : GetActive ( )
2012-06-26 20:23:05 +00:00
{
2016-12-27 14:32:38 +00:00
// Dying astronaut (m_dying == DeathType::Dead) should be treated as active
// This is for EndMissionTake to not detect him as actually dead until the animation is finished
return ! GetLock ( ) & & ! ( Implements ( ObjectInterfaceType : : Destroyable ) & & IsDying ( ) & & GetDying ( ) ! = DeathType : : Dead ) & & ! m_bFlat ;
2015-08-16 18:24:48 +00:00
}
bool COldObject : : GetDetectable ( )
{
return GetActive ( ) & & ! m_underground ;
2012-06-26 20:23:05 +00:00
}
// Management of the point of aim.
2015-07-02 21:48:30 +00:00
void COldObject : : SetGunGoalV ( float gunGoal )
2012-06-26 20:23:05 +00:00
{
if ( m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
2017-11-17 18:57:08 +00:00
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib ) // fireball?
2012-06-26 20:23:05 +00:00
{
if ( gunGoal > 10.0f * Math : : PI / 180.0f ) gunGoal = 10.0f * Math : : PI / 180.0f ;
if ( gunGoal < - 20.0f * Math : : PI / 180.0f ) gunGoal = - 20.0f * Math : : PI / 180.0f ;
2015-07-14 19:29:13 +00:00
SetPartRotationZ ( 1 , gunGoal ) ;
2012-06-26 20:23:05 +00:00
}
else if ( m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii ) // orgaball?
{
if ( gunGoal > 20.0f * Math : : PI / 180.0f ) gunGoal = 20.0f * Math : : PI / 180.0f ;
if ( gunGoal < - 20.0f * Math : : PI / 180.0f ) gunGoal = - 20.0f * Math : : PI / 180.0f ;
2015-07-14 19:29:13 +00:00
SetPartRotationZ ( 1 , gunGoal ) ;
2012-06-26 20:23:05 +00:00
}
else if ( m_type = = OBJECT_MOBILErc ) // phazer?
{
if ( gunGoal > 45.0f * Math : : PI / 180.0f ) gunGoal = 45.0f * Math : : PI / 180.0f ;
if ( gunGoal < - 20.0f * Math : : PI / 180.0f ) gunGoal = - 20.0f * Math : : PI / 180.0f ;
2015-07-14 19:29:13 +00:00
SetPartRotationZ ( 2 , gunGoal ) ;
2012-06-26 20:23:05 +00:00
}
else
{
gunGoal = 0.0f ;
}
m_gunGoalV = gunGoal ;
}
2015-07-02 21:48:30 +00:00
void COldObject : : SetGunGoalH ( float gunGoal )
2012-06-26 20:23:05 +00:00
{
if ( m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
2017-11-17 18:57:08 +00:00
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib ) // fireball?
2012-06-26 20:23:05 +00:00
{
if ( gunGoal > 40.0f * Math : : PI / 180.0f ) gunGoal = 40.0f * Math : : PI / 180.0f ;
if ( gunGoal < - 40.0f * Math : : PI / 180.0f ) gunGoal = - 40.0f * Math : : PI / 180.0f ;
2015-07-14 19:29:13 +00:00
SetPartRotationY ( 1 , gunGoal ) ;
2012-06-26 20:23:05 +00:00
}
else if ( m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii ) // orgaball?
{
if ( gunGoal > 40.0f * Math : : PI / 180.0f ) gunGoal = 40.0f * Math : : PI / 180.0f ;
if ( gunGoal < - 40.0f * Math : : PI / 180.0f ) gunGoal = - 40.0f * Math : : PI / 180.0f ;
2015-07-14 19:29:13 +00:00
SetPartRotationY ( 1 , gunGoal ) ;
2012-06-26 20:23:05 +00:00
}
else if ( m_type = = OBJECT_MOBILErc ) // phazer?
{
if ( gunGoal > 40.0f * Math : : PI / 180.0f ) gunGoal = 40.0f * Math : : PI / 180.0f ;
if ( gunGoal < - 40.0f * Math : : PI / 180.0f ) gunGoal = - 40.0f * Math : : PI / 180.0f ;
2015-07-14 19:29:13 +00:00
SetPartRotationY ( 2 , gunGoal ) ;
2012-06-26 20:23:05 +00:00
}
else
{
gunGoal = 0.0f ;
}
m_gunGoalH = gunGoal ;
}
2015-07-02 21:48:30 +00:00
float COldObject : : GetGunGoalV ( )
2012-06-26 20:23:05 +00:00
{
return m_gunGoalV ;
}
2015-07-02 21:48:30 +00:00
float COldObject : : GetGunGoalH ( )
2012-06-26 20:23:05 +00:00
{
return m_gunGoalH ;
}
2015-08-11 15:51:39 +00:00
float COldObject : : GetShowLimitRadius ( )
2015-06-20 17:27:43 +00:00
{
2015-08-12 15:48:58 +00:00
if ( m_type = = OBJECT_BASE ) return 200.0f ; // SpaceShip
if ( m_type = = OBJECT_MOBILErt ) return 400.0f ; // Thumper
if ( m_type = = OBJECT_TOWER ) return Gfx : : LTNG_PROTECTION_RADIUS ; // DefenseTower
if ( m_type = = OBJECT_PARA ) return Gfx : : LTNG_PROTECTION_RADIUS ; // PowerCaptor
return 0.0f ;
2015-06-20 17:27:43 +00:00
}
2012-06-26 20:23:05 +00:00
// Creates or removes particles associated to the object.
2015-07-02 21:48:30 +00:00
void COldObject : : CreateSelectParticle ( )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 pos , speed ;
2021-12-24 19:08:04 +00:00
glm : : vec2 dim ;
2012-06-26 20:23:05 +00:00
int i ;
// Removes particles preceding.
for ( i = 0 ; i < 4 ; i + + )
{
if ( m_partiSel [ i ] ! = - 1 )
{
2012-09-10 21:29:38 +00:00
m_particle - > DeleteParticle ( m_partiSel [ i ] ) ;
2012-06-26 20:23:05 +00:00
m_partiSel [ i ] = - 1 ;
}
}
2015-06-26 20:07:55 +00:00
if ( m_bSelect | | IsProgram ( ) | | m_main - > GetMissionType ( ) = = MISSION_RETRO )
2012-06-26 20:23:05 +00:00
{
// Creates particles lens for the headlights.
if ( m_type = = OBJECT_MOBILEfa | |
m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEia | |
2017-11-16 17:43:45 +00:00
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib | |
2012-06-26 20:23:05 +00:00
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILEfs | |
m_type = = OBJECT_MOBILEts | |
m_type = = OBJECT_MOBILEws | |
m_type = = OBJECT_MOBILEis | |
m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEtg | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEit | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErp | |
m_type = = OBJECT_MOBILEst | |
2012-06-26 20:23:05 +00:00
m_type = = OBJECT_MOBILEdr ) // vehicle?
{
2022-01-03 21:51:36 +00:00
pos = glm : : vec3 ( 0.0f , 0.0f , 0.0f ) ;
speed = glm : : vec3 ( 0.0f , 0.0f , 0.0f ) ;
2012-06-26 20:23:05 +00:00
dim . x = 0.0f ;
dim . y = 0.0f ;
2012-09-10 21:29:38 +00:00
m_partiSel [ 0 ] = m_particle - > CreateParticle ( pos , speed , dim , Gfx : : PARTISELY , 1.0f , 0.0f , 0.0f ) ;
m_partiSel [ 1 ] = m_particle - > CreateParticle ( pos , speed , dim , Gfx : : PARTISELY , 1.0f , 0.0f , 0.0f ) ;
m_partiSel [ 2 ] = m_particle - > CreateParticle ( pos , speed , dim , Gfx : : PARTISELR , 1.0f , 0.0f , 0.0f ) ;
m_partiSel [ 3 ] = m_particle - > CreateParticle ( pos , speed , dim , Gfx : : PARTISELR , 1.0f , 0.0f , 0.0f ) ;
UpdateSelectParticle ( ) ;
2012-06-26 20:23:05 +00:00
}
}
}
// Updates the particles associated to the object.
2015-07-02 21:48:30 +00:00
void COldObject : : UpdateSelectParticle ( )
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
glm : : vec3 pos [ 4 ] ;
2021-12-24 19:08:04 +00:00
glm : : vec2 dim [ 4 ] ;
2012-06-26 20:23:05 +00:00
float zoom [ 4 ] ;
float angle ;
int i ;
2015-06-26 20:07:55 +00:00
if ( ! m_bSelect & & ! IsProgram ( ) & & m_main - > GetMissionType ( ) ! = MISSION_RETRO ) return ;
2012-06-26 20:23:05 +00:00
dim [ 0 ] . x = 1.0f ;
dim [ 1 ] . x = 1.0f ;
dim [ 2 ] . x = 1.2f ;
dim [ 3 ] . x = 1.2f ;
// Lens front yellow.
if ( m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILErp ) // large caterpillars?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 0 ] = glm : : vec3 ( 4.2f , 2.8f , 1.5f ) ;
pos [ 1 ] = glm : : vec3 ( 4.2f , 2.8f , - 1.5f ) ;
2012-06-26 20:23:05 +00:00
dim [ 0 ] . x = 1.5f ;
dim [ 1 ] . x = 1.5f ;
}
2018-12-23 06:04:06 +00:00
else if ( m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEst ) // submarine?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 0 ] = glm : : vec3 ( 3.6f , 4.0f , 2.0f ) ;
pos [ 1 ] = glm : : vec3 ( 3.6f , 4.0f , - 2.0f ) ;
2012-06-26 20:23:05 +00:00
}
else if ( m_type = = OBJECT_MOBILEtg ) // target?
{
2022-01-03 21:51:36 +00:00
pos [ 0 ] = glm : : vec3 ( 3.4f , 6.5f , 2.0f ) ;
pos [ 1 ] = glm : : vec3 ( 3.4f , 6.5f , - 2.0f ) ;
2012-06-26 20:23:05 +00:00
}
else if ( m_type = = OBJECT_MOBILEdr ) // designer?
{
2022-01-03 21:51:36 +00:00
pos [ 0 ] = glm : : vec3 ( 4.9f , 3.5f , 2.5f ) ;
pos [ 1 ] = glm : : vec3 ( 4.9f , 3.5f , - 2.5f ) ;
2012-06-26 20:23:05 +00:00
}
2017-12-21 00:49:56 +00:00
else if ( m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEit | |
GetTrainer ( ) ) // trainer ?
{
2022-01-03 21:51:36 +00:00
pos [ 0 ] = glm : : vec3 ( 4.2f , 2.5f , 1.2f ) ;
pos [ 1 ] = glm : : vec3 ( 4.2f , 2.5f , - 1.2f ) ;
2017-12-21 00:49:56 +00:00
dim [ 0 ] . x = 1.5f ;
dim [ 1 ] . x = 1.5f ;
}
2012-06-26 20:23:05 +00:00
else
{
2022-01-03 21:51:36 +00:00
pos [ 0 ] = glm : : vec3 ( 4.2f , 2.5f , 1.5f ) ;
pos [ 1 ] = glm : : vec3 ( 4.2f , 2.5f , - 1.5f ) ;
2012-06-26 20:23:05 +00:00
}
// Red back lens
2017-12-21 00:49:56 +00:00
if ( m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEit | |
GetTrainer ( ) ) // trainer?
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 4.0f , 2.5f , 2.2f ) ;
pos [ 3 ] = glm : : vec3 ( - 4.0f , 2.5f , - 2.2f ) ;
2017-12-21 00:49:56 +00:00
}
else if ( m_type = = OBJECT_MOBILEfa | |
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEfs ) // flying?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 4.0f , 3.1f , 4.5f ) ;
pos [ 3 ] = glm : : vec3 ( - 4.0f , 3.1f , - 4.5f ) ;
2012-06-26 20:23:05 +00:00
dim [ 2 ] . x = 0.6f ;
dim [ 3 ] . x = 0.6f ;
}
2017-12-21 00:49:56 +00:00
else if ( m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEws ) // wheels?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 4.5f , 2.7f , 2.8f ) ;
pos [ 3 ] = glm : : vec3 ( - 4.5f , 2.7f , - 2.8f ) ;
2012-06-26 20:23:05 +00:00
}
2017-12-21 00:49:56 +00:00
else if ( m_type = = OBJECT_MOBILEia | |
m_type = = OBJECT_MOBILEib | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILEis ) // legs?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 4.5f , 2.7f , 2.8f ) ;
pos [ 3 ] = glm : : vec3 ( - 4.5f , 2.7f , - 2.8f ) ;
2012-06-26 20:23:05 +00:00
}
2017-12-21 00:49:56 +00:00
else if ( m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEts ) // caterpillars?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 3.6f , 4.2f , 3.0f ) ;
pos [ 3 ] = glm : : vec3 ( - 3.6f , 4.2f , - 3.0f ) ;
2012-06-26 20:23:05 +00:00
}
2020-01-11 17:39:44 +00:00
else if ( m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs ) // large caterpillars?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 5.0f , 5.2f , 2.5f ) ;
pos [ 3 ] = glm : : vec3 ( - 5.0f , 5.2f , - 2.5f ) ;
2012-06-26 20:23:05 +00:00
}
2020-01-11 17:39:44 +00:00
if ( m_type = = OBJECT_MOBILErp | | ( GetTrainer ( ) & &
( m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs ) ) ) // large caterpillars (trainer)?
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 4.6f , 5.2f , 2.6f ) ;
pos [ 3 ] = glm : : vec3 ( - 4.6f , 5.2f , - 2.6f ) ;
2020-01-11 17:39:44 +00:00
}
2018-12-23 06:04:06 +00:00
if ( m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEst ) // submarine?
2012-06-26 20:23:05 +00:00
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 3.6f , 4.0f , 2.0f ) ;
pos [ 3 ] = glm : : vec3 ( - 3.6f , 4.0f , - 2.0f ) ;
2012-06-26 20:23:05 +00:00
}
if ( m_type = = OBJECT_MOBILEtg ) // target?
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 2.4f , 6.5f , 2.0f ) ;
pos [ 3 ] = glm : : vec3 ( - 2.4f , 6.5f , - 2.0f ) ;
2012-06-26 20:23:05 +00:00
}
if ( m_type = = OBJECT_MOBILEdr ) // designer?
{
2022-01-03 21:51:36 +00:00
pos [ 2 ] = glm : : vec3 ( - 5.3f , 2.7f , 1.8f ) ;
pos [ 3 ] = glm : : vec3 ( - 5.3f , 2.7f , - 1.8f ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-14 19:29:13 +00:00
angle = GetRotationY ( ) / Math : : PI ;
2012-06-26 20:23:05 +00:00
zoom [ 0 ] = 1.0f ;
zoom [ 1 ] = 1.0f ;
zoom [ 2 ] = 1.0f ;
zoom [ 3 ] = 1.0f ;
2013-03-24 20:31:31 +00:00
if ( ( IsProgram ( ) | | // current program?
2015-06-26 20:07:55 +00:00
m_main - > GetMissionType ( ) = = MISSION_RETRO ) & & // Retro mode?
2012-06-26 20:23:05 +00:00
Math : : Mod ( m_aTime , 0.7f ) < 0.3f )
{
zoom [ 0 ] = 0.0f ; // blinks
zoom [ 1 ] = 0.0f ;
zoom [ 2 ] = 0.0f ;
zoom [ 3 ] = 0.0f ;
}
// Updates lens.
for ( i = 0 ; i < 4 ; i + + )
{
2016-05-28 14:16:48 +00:00
if ( m_partiSel [ i ] = = - 1 ) continue ;
2012-06-26 20:23:05 +00:00
pos [ i ] = Math : : Transform ( m_objectPart [ 0 ] . matWorld , pos [ i ] ) ;
dim [ i ] . y = dim [ i ] . x ;
2012-09-10 21:29:38 +00:00
m_particle - > SetParam ( m_partiSel [ i ] , pos [ i ] , dim [ i ] , zoom [ i ] , angle , 1.0f ) ;
2012-06-26 20:23:05 +00:00
}
}
2012-10-17 19:55:45 +00:00
// Returns the physics associated to the object.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
CPhysics * COldObject : : GetPhysics ( )
2012-06-26 20:23:05 +00:00
{
2015-06-22 19:58:58 +00:00
return m_physics . get ( ) ;
2012-06-26 20:23:05 +00:00
}
2012-10-17 19:55:45 +00:00
// Returns the movement associated to the object.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
CMotion * COldObject : : GetMotion ( )
2012-06-26 20:23:05 +00:00
{
2015-06-22 19:58:58 +00:00
return m_motion . get ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-08-13 08:49:26 +00:00
// TODO: Temporary hack until we'll have subclasses for objects
void COldObject : : SetProgrammable ( )
{
2015-08-15 19:29:08 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : ProgramStorage ) ] = true ;
2015-08-13 08:49:26 +00:00
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Programmable ) ] = true ;
}
// TODO: Another hack
void COldObject : : SetMovable ( std : : unique_ptr < CMotion > motion , std : : unique_ptr < CPhysics > physics )
2015-06-20 17:27:43 +00:00
{
2015-06-22 19:58:58 +00:00
m_motion = std : : move ( motion ) ;
2015-08-13 08:49:26 +00:00
m_physics = std : : move ( physics ) ;
m_implementedInterfaces [ static_cast < int > ( ObjectInterfaceType : : Movable ) ] = true ;
2015-06-20 17:27:43 +00:00
}
2012-10-17 19:55:45 +00:00
// Returns the controller associated to the object.
2012-06-26 20:23:05 +00:00
2015-07-02 21:48:30 +00:00
CAuto * COldObject : : GetAuto ( )
2012-06-26 20:23:05 +00:00
{
2015-06-22 19:58:58 +00:00
return m_auto . get ( ) ;
2012-06-26 20:23:05 +00:00
}
2015-07-02 21:48:30 +00:00
void COldObject : : SetAuto ( std : : unique_ptr < CAuto > automat )
2012-06-26 20:23:05 +00:00
{
2015-06-22 19:58:58 +00:00
m_auto = std : : move ( automat ) ;
2012-06-26 20:23:05 +00:00
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetPosition ( ) const
2015-07-11 21:41:41 +00:00
{
2015-07-13 21:19:46 +00:00
return GetPartPosition ( 0 ) ;
}
2022-01-03 21:51:36 +00:00
void COldObject : : SetPosition ( const glm : : vec3 & pos )
2015-07-13 21:19:46 +00:00
{
SetPartPosition ( 0 , pos ) ;
2015-07-11 21:41:41 +00:00
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetRotation ( ) const
2015-07-11 21:41:41 +00:00
{
2015-07-14 19:29:13 +00:00
return GetPartRotation ( 0 ) ;
}
2022-01-03 21:51:36 +00:00
void COldObject : : SetRotation ( const glm : : vec3 & rotation )
2015-07-14 19:29:13 +00:00
{
SetPartRotation ( 0 , rotation ) ;
2015-07-11 21:41:41 +00:00
}
2022-01-03 21:51:36 +00:00
glm : : vec3 COldObject : : GetScale ( ) const
2015-07-11 21:41:41 +00:00
{
2015-07-14 19:29:13 +00:00
return GetPartScale ( 0 ) ;
2015-07-11 21:41:41 +00:00
}
2022-01-03 21:51:36 +00:00
void COldObject : : SetScale ( const glm : : vec3 & scale )
2015-07-14 19:29:13 +00:00
{
SetPartScale ( 0 , scale ) ;
}
2015-08-10 11:46:39 +00:00
2015-08-10 14:37:03 +00:00
void COldObject : : UpdateInterface ( )
{
if ( m_objectInterface ! = nullptr & & GetSelect ( ) )
{
m_objectInterface - > UpdateInterface ( ) ;
}
2015-08-10 16:16:00 +00:00
2015-08-12 14:54:44 +00:00
CreateSelectParticle ( ) ;
m_main - > UpdateShortcuts ( ) ;
}
2015-08-10 16:16:00 +00:00
void COldObject : : StopProgram ( )
{
2015-08-12 14:54:44 +00:00
CProgrammableObjectImpl : : StopProgram ( ) ;
2015-08-10 16:16:00 +00:00
2015-08-12 14:54:44 +00:00
//TODO: I don't want CProgrammableObjectImpl to depend on motion and physics, refactor this somehow
2015-08-10 16:16:00 +00:00
m_physics - > SetMotorSpeedX ( 0.0f ) ;
m_physics - > SetMotorSpeedY ( 0.0f ) ;
m_physics - > SetMotorSpeedZ ( 0.0f ) ;
2015-08-13 20:27:10 +00:00
if ( m_type ! = OBJECT_HUMAN ) // Be sure not to stop the death animation!
{
m_motion - > SetAction ( - 1 ) ;
}
2015-08-10 16:16:00 +00:00
}
2015-08-13 08:49:26 +00:00
// State management of the pencil drawing robot.
bool COldObject : : GetTraceDown ( )
{
return m_traceDown ;
}
void COldObject : : SetTraceDown ( bool down )
{
m_traceDown = down ;
}
TraceColor COldObject : : GetTraceColor ( )
{
return m_traceColor ;
}
void COldObject : : SetTraceColor ( TraceColor color )
{
m_traceColor = color ;
}
float COldObject : : GetTraceWidth ( )
{
return m_traceWidth ;
}
void COldObject : : SetTraceWidth ( float width )
{
m_traceWidth = width ;
}
2015-08-13 11:41:25 +00:00
bool COldObject : : IsRepairable ( )
{
if ( m_type = = OBJECT_HUMAN ) return false ;
return true ;
}
float COldObject : : GetShieldFullRegenTime ( )
{
if ( m_type = = OBJECT_HUMAN ) return 120.0f ;
assert ( false ) ;
return 0.0f ;
}
2015-08-13 16:54:44 +00:00
float COldObject : : GetLightningHitProbability ( )
{
if ( m_type = = OBJECT_BASE | |
m_type = = OBJECT_DERRICK | |
m_type = = OBJECT_FACTORY | |
m_type = = OBJECT_REPAIR | |
m_type = = OBJECT_DESTROYER | |
m_type = = OBJECT_STATION | |
m_type = = OBJECT_CONVERT | |
m_type = = OBJECT_TOWER | |
m_type = = OBJECT_RESEARCH | |
m_type = = OBJECT_RADAR | |
m_type = = OBJECT_INFO | |
m_type = = OBJECT_ENERGY | |
m_type = = OBJECT_LABO | |
m_type = = OBJECT_NUCLEAR | |
m_type = = OBJECT_PARA | |
m_type = = OBJECT_SAFE | |
m_type = = OBJECT_HUSTON ) // building?
{
return 1.0f ;
}
if ( m_type = = OBJECT_METAL | |
m_type = = OBJECT_POWER | |
m_type = = OBJECT_ATOMIC ) // resource?
{
return 0.3f ;
}
if ( m_type = = OBJECT_MOBILEfa | |
m_type = = OBJECT_MOBILEta | |
m_type = = OBJECT_MOBILEwa | |
m_type = = OBJECT_MOBILEia | |
2017-11-16 17:43:45 +00:00
m_type = = OBJECT_MOBILEfb | |
m_type = = OBJECT_MOBILEtb | |
m_type = = OBJECT_MOBILEwb | |
m_type = = OBJECT_MOBILEib | |
2015-08-13 16:54:44 +00:00
m_type = = OBJECT_MOBILEfc | |
m_type = = OBJECT_MOBILEtc | |
m_type = = OBJECT_MOBILEwc | |
m_type = = OBJECT_MOBILEic | |
m_type = = OBJECT_MOBILEfi | |
m_type = = OBJECT_MOBILEti | |
m_type = = OBJECT_MOBILEwi | |
m_type = = OBJECT_MOBILEii | |
m_type = = OBJECT_MOBILEfs | |
m_type = = OBJECT_MOBILEts | |
m_type = = OBJECT_MOBILEws | |
m_type = = OBJECT_MOBILEis | |
m_type = = OBJECT_MOBILErt | |
m_type = = OBJECT_MOBILErc | |
m_type = = OBJECT_MOBILErr | |
m_type = = OBJECT_MOBILErs | |
m_type = = OBJECT_MOBILEsa | |
m_type = = OBJECT_MOBILEft | |
m_type = = OBJECT_MOBILEtt | |
m_type = = OBJECT_MOBILEwt | |
m_type = = OBJECT_MOBILEit | |
2018-12-23 06:04:06 +00:00
m_type = = OBJECT_MOBILErp | |
m_type = = OBJECT_MOBILEst | |
2018-07-12 22:03:20 +00:00
m_type = = OBJECT_MOBILEtg | |
2015-08-13 16:54:44 +00:00
m_type = = OBJECT_MOBILEdr ) // robot?
{
return 0.5f ;
}
return 0.0f ;
}
2017-01-28 11:53:28 +00:00
bool COldObject : : IsSelectableByDefault ( ObjectType type )
{
if ( type = = OBJECT_MOTHER | |
type = = OBJECT_ANT | |
type = = OBJECT_SPIDER | |
type = = OBJECT_BEE | |
2018-07-12 22:03:20 +00:00
type = = OBJECT_WORM )
2017-01-28 11:53:28 +00:00
{
return false ;
}
return true ;
}
2017-04-29 11:05:11 +00:00
void COldObject : : SetBulletWall ( bool bulletWall )
{
m_bulletWall = bulletWall ;
}
bool COldObject : : IsBulletWall ( )
{
return m_bulletWall ;
}
2017-05-19 13:33:44 +00:00
bool COldObject : : IsBulletWallByDefault ( ObjectType type )
{
if ( type = = OBJECT_BARRICADE0 | |
type = = OBJECT_BARRICADE1 )
{
return true ;
}
return false ;
}