Ticket #1921: ShipSinking.patch
File ShipSinking.patch, 3.2 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship.xml
12 12 </Cost> 13 13 <Decay> 14 14 <Inactive/> 15 <SinkingAnim/> 15 16 <DelayTime>0.0</DelayTime> 16 17 <SinkRate>0.5</SinkRate> 17 18 <SinkAccel>7.0</SinkAccel> -
source/simulation2/components/CCmpDecay.cpp
53 53 DEFAULT_COMPONENT_ALLOCATOR(Decay) 54 54 55 55 bool m_Active; 56 bool m_ShipSink; 56 57 float m_DelayTime; 57 58 float m_SinkRate; 58 59 float m_SinkAccel; 59 60 61 entity_pos_t m_InitialXRotation; 62 entity_pos_t m_InitialZRotation; 63 60 64 float m_CurrentTime; 61 65 float m_TotalSinkDepth; // distance we need to sink (derived from bounding box), or -1 if undetermined 62 66 … … 76 80 "<element name='Inactive' a:help='If this element is present, the entity will not do any decaying'>" 77 81 "<empty/>" 78 82 "</element>" 83 "</optional>" 84 "<optional>" 85 "<element name='SinkingAnim' a:help='If this element is present, the entity will decay in a ship-like manner'>" 86 "<empty/>" 87 "</element>" 79 88 "</optional>"; 80 89 } 81 90 82 91 virtual void Init(const CParamNode& paramNode) 83 92 { 84 93 m_Active = !paramNode.GetChild("Inactive").IsOk(); 94 m_ShipSink = paramNode.GetChild("SinkingAnim").IsOk(); 85 95 m_DelayTime = paramNode.GetChild("DelayTime").ToFixed().ToFloat(); 86 96 m_SinkRate = paramNode.GetChild("SinkRate").ToFixed().ToFloat(); 87 97 m_SinkAccel = paramNode.GetChild("SinkAccel").ToFixed().ToFloat(); … … 155 165 fixed ground = cmpTerrain->GetGroundLevel(pos.X, pos.Z); 156 166 m_TotalSinkDepth += std::max(0.f, (pos.Y - ground).ToFloat()); 157 167 } 168 169 // Sink it further down if it sinks like a ship, as it will rotate. 170 if (m_ShipSink) 171 m_TotalSinkDepth += 10.0f; 172 173 // probably 0 in both cases but we'll remember it anyway. 174 m_InitialXRotation = cmpPosition->GetRotation().X; 175 m_InitialZRotation = cmpPosition->GetRotation().Z; 158 176 } 159 177 160 178 m_CurrentTime += msgData.deltaSimTime; 161 179 162 if (m_CurrentTime > m_DelayTime)180 if (m_CurrentTime >= m_DelayTime) 163 181 { 164 182 float t = m_CurrentTime - m_DelayTime; 165 183 float depth = (m_SinkRate * t) + (m_SinkAccel * t * t); 166 184 185 if (m_ShipSink) 186 { 187 // exponential sinking with tilting. 188 float tilt_time = t > 5 ? 5 : t; 189 float tiltSink = (tilt_time/5)*(tilt_time/5)*5; 190 entity_pos_t RotX = entity_pos_t::FromFloat(((m_InitialXRotation.ToFloat() * (5 - tiltSink)) + (1.5 * tiltSink))/5); 191 entity_pos_t RotZ = entity_pos_t::FromFloat(((m_InitialZRotation.ToFloat() * (3 - tilt_time)) + (-0.3 * tilt_time))/3); 192 cmpPosition->SetXZRotation(RotX,RotZ); 193 194 depth = m_SinkRate * (exp(t-1)-exp(-0.6)) + (m_SinkAccel * exp(t-4)-exp(-4)); 195 if (depth < 0) 196 depth = 0; 197 } 198 167 199 cmpPosition->SetHeightOffset(entity_pos_t::FromFloat(-depth)); 168 200 169 201 if (depth > m_TotalSinkDepth)