buildingstate.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/buildingstate.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 9/08/00 10:37a $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "buildingstate.h"
  38. #include "wwdebug.h"
  39. /*
  40. ** Static data used by BuildingStateClass
  41. */
  42. static int _EquivalentPowerOnState[] =
  43. {
  44. BuildingStateClass::HEALTH100_POWERON,
  45. BuildingStateClass::HEALTH75_POWERON,
  46. BuildingStateClass::HEALTH50_POWERON,
  47. BuildingStateClass::HEALTH25_POWERON,
  48. BuildingStateClass::DESTROYED_POWERON,
  49. BuildingStateClass::HEALTH100_POWERON,
  50. BuildingStateClass::HEALTH75_POWERON,
  51. BuildingStateClass::HEALTH50_POWERON,
  52. BuildingStateClass::HEALTH25_POWERON,
  53. BuildingStateClass::DESTROYED_POWERON,
  54. };
  55. static int _EquivalentPowerOffState[] =
  56. {
  57. BuildingStateClass::HEALTH100_POWEROFF,
  58. BuildingStateClass::HEALTH75_POWEROFF,
  59. BuildingStateClass::HEALTH50_POWEROFF,
  60. BuildingStateClass::HEALTH25_POWEROFF,
  61. BuildingStateClass::DESTROYED_POWEROFF,
  62. BuildingStateClass::HEALTH100_POWEROFF,
  63. BuildingStateClass::HEALTH75_POWEROFF,
  64. BuildingStateClass::HEALTH50_POWEROFF,
  65. BuildingStateClass::HEALTH25_POWEROFF,
  66. BuildingStateClass::DESTROYED_POWEROFF,
  67. };
  68. static const char * _StateNames[] =
  69. {
  70. "Building State: Health 100%, Power ON",
  71. "Building State: Health 75%, Power ON",
  72. "Building State: Health 50%, Power ON",
  73. "Building State: Health 25%, Power ON",
  74. "Building State: Destroyed, Power ON",
  75. "Building State: Health 100%, Power OFF",
  76. "Building State: Health 75%, Power OFF",
  77. "Building State: Health 50%, Power OFF",
  78. "Building State: Health 25%, Power OFF",
  79. "Building State: Destroyed, Power OFF",
  80. };
  81. int BuildingStateClass::Get_Health_State(int building_state)
  82. {
  83. int state = building_state;
  84. if (state >= HEALTH100_POWEROFF) {
  85. state -= HEALTH100_POWEROFF;
  86. }
  87. return state;
  88. }
  89. int BuildingStateClass::Percentage_To_Health_State(float health)
  90. {
  91. if (health <= 0.0f) {
  92. return HEALTH_0;
  93. }
  94. if (health <= 25.0f) {
  95. return HEALTH_25;
  96. }
  97. if (health <= 50.0f) {
  98. return HEALTH_50;
  99. }
  100. if (health <= 75.0f) {
  101. return HEALTH_75;
  102. }
  103. return HEALTH_100;
  104. }
  105. bool BuildingStateClass::Is_Power_On(int building_state)
  106. {
  107. return (building_state < HEALTH100_POWEROFF);
  108. }
  109. int BuildingStateClass::Enable_Power(int input_state,bool onoff)
  110. {
  111. if (onoff) {
  112. return _EquivalentPowerOnState[input_state];
  113. } else {
  114. return _EquivalentPowerOffState[input_state];
  115. }
  116. }
  117. int BuildingStateClass::Compose_State(int health_state,bool power_onoff)
  118. {
  119. int state = health_state;
  120. if (power_onoff == false) {
  121. state += HEALTH100_POWEROFF;
  122. }
  123. return state;
  124. }
  125. const char * BuildingStateClass::Get_State_Name(int state)
  126. {
  127. WWASSERT(state >= 0);
  128. WWASSERT(state < STATE_COUNT);
  129. return _StateNames[state];
  130. }