corpsedata.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. class CorpseData
  2. {
  3. const int GET_LIFETIME_TRIES_MAX = 3;
  4. bool m_bUpdate;
  5. int m_iLastUpdateTime;
  6. int m_iTimeOfDeath;
  7. int m_iMaxLifetime;
  8. int m_iCorpseState;
  9. int m_iTriesToGetLifetime;
  10. float m_LifetimeAdjusted = float.MIN;
  11. float m_LastLifetime = float.MIN;
  12. PlayerBase m_Player;
  13. void CorpseData(notnull PlayerBase player,int time_of_death)
  14. {
  15. m_bUpdate = true;
  16. m_iLastUpdateTime = time_of_death;
  17. m_iTimeOfDeath = time_of_death;
  18. m_iMaxLifetime = -1;
  19. m_iCorpseState = PlayerConstants.CORPSE_STATE_FRESH;
  20. m_Player = player;
  21. m_iTriesToGetLifetime = 0;
  22. }
  23. void UpdateCorpseState(bool force_check = false)
  24. {
  25. if (m_iMaxLifetime <= 0 )
  26. {
  27. if ( m_iCorpseState == PlayerConstants.CORPSE_STATE_DECAYED && !force_check )
  28. {
  29. m_bUpdate = false;
  30. return;
  31. }
  32. else
  33. {
  34. m_iMaxLifetime = m_Player.GetLifetime();
  35. if (m_iMaxLifetime <= 0) //cleanup time not initialized yet!
  36. {
  37. m_iTriesToGetLifetime++;
  38. m_iMaxLifetime = -1;
  39. if (m_iTriesToGetLifetime >= GET_LIFETIME_TRIES_MAX)
  40. {
  41. m_bUpdate = false;
  42. }
  43. return;
  44. }
  45. m_iMaxLifetime -= 30 * m_iTriesToGetLifetime; //adjusts for failed init attempts
  46. m_Player.SetLifetime(m_iMaxLifetime);
  47. }
  48. }
  49. if (m_LifetimeAdjusted == float.MIN)
  50. m_LifetimeAdjusted = m_iMaxLifetime;
  51. if (m_LastLifetime == float.MIN)
  52. m_LastLifetime = m_iMaxLifetime;
  53. float lifetime = m_Player.GetLifetime();
  54. if (!CanProgressDecay())
  55. {
  56. m_LastLifetime = lifetime;
  57. return;
  58. }
  59. int corpseStateOld = m_iCorpseState;
  60. float delta = lifetime - m_LastLifetime;
  61. #ifdef DIAG_DEVELOPER
  62. if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.FOOD_DECAY))
  63. {
  64. float timeAccel = 1;
  65. timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
  66. delta *= timeAccel;
  67. }
  68. #endif
  69. m_LifetimeAdjusted += delta;
  70. float corpseFreshness = m_LifetimeAdjusted/m_iMaxLifetime;
  71. if (corpseFreshness > PlayerConstants.CORPSE_THRESHOLD_MEDIUM)
  72. {
  73. m_iCorpseState = PlayerConstants.CORPSE_STATE_FRESH;
  74. }
  75. else if (corpseFreshness <= PlayerConstants.CORPSE_THRESHOLD_MEDIUM && corpseFreshness > PlayerConstants.CORPSE_THRESHOLD_DECAYED)
  76. {
  77. m_iCorpseState = PlayerConstants.CORPSE_STATE_MEDIUM;
  78. }
  79. else
  80. {
  81. m_iCorpseState = PlayerConstants.CORPSE_STATE_DECAYED;
  82. m_bUpdate = false;
  83. }
  84. if (corpseStateOld != m_iCorpseState)
  85. {
  86. m_Player.m_CorpseState = m_iCorpseState;
  87. m_Player.SetSynchDirty();
  88. }
  89. m_LastLifetime = lifetime;
  90. }
  91. protected bool CanProgressDecay()
  92. {
  93. return !m_Player.GetIsFrozen();
  94. }
  95. }