MCPcopy Create free account
hub / github.com/carbonengine/trinity / UpdateState

Method UpdateState

trinity/Eve/SpaceObject/EveMissileWarhead.cpp:355–418  ·  view source on GitHub ↗

-------------------------------------------------------------------------------- Description: Handles the warhead's state managment. Makes sure we are in the corrct state by checking certain conditions like timings or distances etc. Arguments: deltaT - time since last frame in seconds estimatedTotalAliveTime - up-to-date estimate of the total alive time target - what are we hitting Return value: R

Source from the content-addressed store, hash-verified

353// Returns an enum to trigger explosions etc. due to state changes
354// --------------------------------------------------------------------------------
355EveMissileWarhead::StateChangeEvent EveMissileWarhead::UpdateState( float deltaT, float estimatedTotalAliveTime, ITriTargetable* target )
356{
357 // NB: target may be null (bombs)
358 m_bombFlightpath = !target;
359
360 StateChangeEvent evt = EVT_NONE;
361 Vector3 position;
362 const float estimatedTotalFlyingTime = ( estimatedTotalAliveTime + 0.1f ) * m_speedModifier;
363
364 // calc a value from 0 to 1 across the whole (estimated) flying time, (excluding eject-phase time and delay time)
365 const float flight01 = TriClamp( m_flyingTime / estimatedTotalFlyingTime, 0.f, 1.f );
366 switch( m_state )
367 {
368 case STATE_DELAYED:
369 // wait for valid start data then we are ready to launch
370 if( m_startDataValid )
371 {
372 m_state = STATE_LAUNCH;
373 }
374 break;
375 case STATE_LAUNCH:
376 // turn on particle emitting
377 EnableParticleEmitting( true );
378 m_state = STATE_EJECTING;
379 break;
380 case STATE_EJECTING:
381 m_currentDurationEjectPhase -= deltaT;
382 if( m_currentDurationEjectPhase <= 0.f )
383 {
384 m_currentDurationEjectPhase = 0.f;
385 m_state = STATE_START_TRACKING;
386 }
387 break;
388 case STATE_START_TRACKING:
389 // get target locator from target
390 m_targetLocator = target ? target->GetGoodDamageLocatorIndex( GetWorldPosition() ) : -1;
391 if( estimatedTotalAliveTime >= 5.f && m_doSpread )
392 {
393 m_state = STATE_TRACKING_SPREAD;
394 }
395 else
396 {
397 m_state = STATE_TRACKING_FINAL;
398 }
399 break;
400 case STATE_TRACKING_SPREAD:
401 if( flight01 >= m_finalTargetTime )
402 {
403 m_targetLocator = target ? target->GetGoodDamageLocatorIndex( GetWorldPosition() ) : -1;
404 evt = EVT_SWITCH_TARGET;
405 m_state = STATE_TRACKING_FINAL;
406 }
407 break;
408 case STATE_TRACKING_FINAL:
409 break;
410 case STATE_EXPLODED:
411 m_state = STATE_DEAD;
412 break;

Callers 1

UpdateSyncronousMethod · 0.45

Calls 2

TriClampFunction · 0.85

Tested by

no test coverage detected