Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpDecay.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 9 Lines | |||||
#include "simulation2/system/Component.h" | #include "simulation2/system/Component.h" | ||||
#include "ICmpDecay.h" | #include "ICmpDecay.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "ICmpPosition.h" | #include "ICmpPosition.h" | ||||
#include "ICmpTerrain.h" | #include "ICmpTerrain.h" | ||||
#include "ICmpUnitRenderer.h" | |||||
#include "ICmpVisual.h" | #include "ICmpVisual.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
/** | /** | ||||
* Fairly basic decay implementation, for units and buildings etc. | * Fairly basic decay implementation, for units and buildings etc. | ||||
* The decaying entity remains stationary for some time period, then falls downwards | * The decaying entity remains stationary for some time period, then falls downwards | ||||
* with some initial speed and some acceleration, until it has fully sunk. | * with some initial speed and some acceleration, until it has fully sunk. | ||||
Show All 15 Lines | public: | ||||
static void ClassInit(CComponentManager& UNUSED(componentManager)) | static void ClassInit(CComponentManager& UNUSED(componentManager)) | ||||
{ | { | ||||
} | } | ||||
DEFAULT_COMPONENT_ALLOCATOR(Decay) | DEFAULT_COMPONENT_ALLOCATOR(Decay) | ||||
bool m_Active; | bool m_Active; | ||||
bool m_ShipSink; | bool m_ShipSink; | ||||
bool m_CreatesCorpse; | |||||
float m_DelayTime; | float m_DelayTime; | ||||
float m_SinkRate; | float m_SinkRate; | ||||
float m_SinkAccel; | float m_SinkAccel; | ||||
entity_pos_t m_InitialXRotation; | entity_pos_t m_InitialXRotation; | ||||
entity_pos_t m_InitialZRotation; | entity_pos_t m_InitialZRotation; | ||||
// Used to randomize ship-like sinking | // Used to randomize ship-like sinking | ||||
float m_SinkingAngleX; | float m_SinkingAngleX; | ||||
float m_SinkingAngleZ; | float m_SinkingAngleZ; | ||||
float m_CurrentTime; | float m_CurrentTime; | ||||
float m_TotalSinkDepth; // distance we need to sink (derived from bounding box), or -1 if undetermined | float m_TotalSinkDepth; // distance we need to sink (derived from bounding box), or -1 if undetermined | ||||
static std::string GetSchema() | static std::string GetSchema() | ||||
{ | { | ||||
return | return | ||||
"<element name='Active' a:help='If false, the entity will not do any decaying'>" | "<element name='Active' a:help='If false, the entity will not do any decaying'>" | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<optional>" | |||||
"<element name='CreatesCorpse'>" | |||||
"<empty/>" | |||||
"</element>" | |||||
"</optional>" | |||||
"<element name='SinkingAnim' a:help='If true, the entity will decay in a ship-like manner'>" | "<element name='SinkingAnim' a:help='If true, the entity will decay in a ship-like manner'>" | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<element name='DelayTime' a:help='Time to wait before starting to sink, in seconds'>" | "<element name='DelayTime' a:help='Time to wait before starting to sink, in seconds'>" | ||||
"<ref name='nonNegativeDecimal'/>" | "<ref name='nonNegativeDecimal'/>" | ||||
"</element>" | "</element>" | ||||
"<element name='SinkRate' a:help='Initial rate of sinking, in metres per second'>" | "<element name='SinkRate' a:help='Initial rate of sinking, in metres per second'>" | ||||
"<ref name='nonNegativeDecimal'/>" | "<ref name='nonNegativeDecimal'/>" | ||||
"</element>" | "</element>" | ||||
"<element name='SinkAccel' a:help='Acceleration rate of sinking, in metres per second per second'>" | "<element name='SinkAccel' a:help='Acceleration rate of sinking, in metres per second per second'>" | ||||
"<ref name='nonNegativeDecimal'/>" | "<ref name='nonNegativeDecimal'/>" | ||||
"</element>"; | "</element>"; | ||||
} | } | ||||
virtual void Init(const CParamNode& paramNode) | virtual void Init(const CParamNode& paramNode) | ||||
{ | { | ||||
m_Active = paramNode.GetChild("Active").ToBool(); | m_Active = paramNode.GetChild("Active").ToBool(); | ||||
m_ShipSink = paramNode.GetChild("SinkingAnim").ToBool(); | m_ShipSink = paramNode.GetChild("SinkingAnim").ToBool(); | ||||
m_CreatesCorpse = paramNode.GetChild("CreatesCorpse").IsOk(); | |||||
m_DelayTime = paramNode.GetChild("DelayTime").ToFixed().ToFloat(); | m_DelayTime = paramNode.GetChild("DelayTime").ToFixed().ToFloat(); | ||||
m_SinkRate = paramNode.GetChild("SinkRate").ToFixed().ToFloat(); | m_SinkRate = paramNode.GetChild("SinkRate").ToFixed().ToFloat(); | ||||
m_SinkAccel = paramNode.GetChild("SinkAccel").ToFixed().ToFloat(); | m_SinkAccel = paramNode.GetChild("SinkAccel").ToFixed().ToFloat(); | ||||
m_CurrentTime = 0.f; | m_CurrentTime = 0.f; | ||||
m_TotalSinkDepth = -1.f; | m_TotalSinkDepth = -1.f; | ||||
// Detect unsafe misconfiguration | // Detect unsafe misconfiguration | ||||
if (m_Active && !ENTITY_IS_LOCAL(GetEntityId())) | if (m_Active && !ENTITY_IS_LOCAL(GetEntityId())) | ||||
{ | { | ||||
debug_warn(L"CCmpDecay must not be used on non-local (network-synchronised) entities"); | debug_warn(L"CCmpDecay must not be used on non-local (network-synchronised) entities"); | ||||
m_Active = false; | m_Active = false; | ||||
} | } | ||||
if (m_Active) | if (m_Active) | ||||
GetSimContext().GetComponentManager().DynamicSubscriptionNonsync(MT_Interpolate, this, true); | GetSimContext().GetComponentManager().DynamicSubscriptionNonsync(MT_Interpolate, this, true); | ||||
if (m_Active && m_CreatesCorpse) | |||||
{ | |||||
CmpPtr<ICmpUnitRenderer> cmpUnitRenderer(GetSystemEntity()); | |||||
if (cmpUnitRenderer) | |||||
{ | |||||
cmpUnitRenderer->AddRagDoll(); | |||||
} | |||||
} | |||||
} | } | ||||
virtual void Deinit() | virtual void Deinit() | ||||
{ | { | ||||
if (m_Active && m_CreatesCorpse) | |||||
{ | |||||
CmpPtr<ICmpUnitRenderer> cmpUnitRenderer(GetSystemEntity()); | |||||
if (cmpUnitRenderer) | |||||
cmpUnitRenderer->RemoveRagDoll(); | |||||
} | |||||
} | } | ||||
virtual void Serialize(ISerializer& UNUSED(serialize)) | virtual void Serialize(ISerializer& UNUSED(serialize)) | ||||
{ | { | ||||
// This component isn't network-synchronised, so don't serialize anything | // This component isn't network-synchronised, so don't serialize anything | ||||
} | } | ||||
virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) | virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator