ModelState.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. ** Command & Conquer Generals(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // ModelState.h
  24. // Basic data types needed for the game engine. This is an extension of BaseType.h.
  25. // Author: Michael S. Booth, April 2001
  26. #pragma once
  27. #ifndef _ModelState_H_
  28. #define _ModelState_H_
  29. #include "Lib/BaseType.h"
  30. #include "Common/INI.h"
  31. #include "Common/BitFlags.h"
  32. //-------------------------------------------------------------------------------------------------
  33. /**
  34. THE PROBLEM
  35. -----------
  36. -- there are lots of different states. (consider that structures can be: day/night, snow/nosnow,
  37. powered/not, garrisoned/empty, damaged/not... you do the math.)
  38. -- some states are mutually exclusive (idle vs. moving), others are not (snow/nosnow, day/night).
  39. generally, humanoid units have mostly the former, while structure units have mostly the latter.
  40. The current ModelState system really only supports the mutually-exclusive states well.
  41. -- we'd rather not have to specify every state in the INI files, BUT we do want to be able
  42. to intelligently choose the best model for a given state, whether or not a "real" state exists for it.
  43. -- it would be desirable to have a unified way of representing "ModelState" so that we don't
  44. have multiple similar-yet-different systems.
  45. YUCK, WHAT NOW
  46. --------------
  47. Let's represent the Model State with two dictinct pieces:
  48. -- an "ActionState" piece, representing the mutually-exclusive states, which are almost
  49. always an action of some sort
  50. -- and a "ConditionState" piece, which is a set of bitflags to indicate the static "condition"
  51. of the model.
  52. Note that these are usually set independently in code, but they are lumped together in order to
  53. determine the actual model to be used.
  54. (Let's require all objects would be required to have an "Idle" ActionState, which is the
  55. normal, just-sitting there condition.)
  56. From a code point of view, this becomes an issue of requesting a certain state, and
  57. finding the best-fit match for it. So, what are the rules for finding a good match?
  58. -- Action states must match exactly. If the desired action state is not found, then the
  59. IDLE state is substituted (but this should generally be considered an error condition).
  60. -- Condition states choose the match with the closest match among the "Condition" bits in the
  61. INI file, based on satisfying the most of the "required" conditions and the fewest of the
  62. "forbidden" conditions.
  63. */
  64. //-------------------------------------------------------------------------------------------------
  65. // IMPORTANT NOTE: you should endeavor to set up states such that the most "normal"
  66. // state is defined by the bit being off. That is, the typical "normal" condition
  67. // has all condition flags set to zero.
  68. enum ModelConditionFlagType
  69. {
  70. MODELCONDITION_INVALID = -1,
  71. MODELCONDITION_FIRST = 0,
  72. //
  73. // Note: these values are saved in save files, so you MUST NOT REMOVE OR CHANGE
  74. // existing values!
  75. //
  76. MODELCONDITION_TOPPLED = MODELCONDITION_FIRST,
  77. MODELCONDITION_FRONTCRUSHED,
  78. MODELCONDITION_BACKCRUSHED,
  79. MODELCONDITION_DAMAGED,
  80. MODELCONDITION_REALLY_DAMAGED,
  81. MODELCONDITION_RUBBLE,
  82. MODELCONDITION_SPECIAL_DAMAGED,
  83. MODELCONDITION_NIGHT,
  84. MODELCONDITION_SNOW,
  85. MODELCONDITION_PARACHUTING,
  86. MODELCONDITION_GARRISONED,
  87. MODELCONDITION_ENEMYNEAR,
  88. MODELCONDITION_WEAPONSET_VETERAN,
  89. MODELCONDITION_WEAPONSET_ELITE,
  90. MODELCONDITION_WEAPONSET_HERO,
  91. MODELCONDITION_WEAPONSET_CRATEUPGRADE_ONE,
  92. MODELCONDITION_WEAPONSET_CRATEUPGRADE_TWO,
  93. MODELCONDITION_WEAPONSET_PLAYER_UPGRADE,
  94. MODELCONDITION_DOOR_1_OPENING,
  95. MODELCONDITION_DOOR_1_CLOSING,
  96. MODELCONDITION_DOOR_1_WAITING_OPEN,
  97. MODELCONDITION_DOOR_1_WAITING_TO_CLOSE,
  98. MODELCONDITION_DOOR_2_OPENING,
  99. MODELCONDITION_DOOR_2_CLOSING,
  100. MODELCONDITION_DOOR_2_WAITING_OPEN,
  101. MODELCONDITION_DOOR_2_WAITING_TO_CLOSE,
  102. MODELCONDITION_DOOR_3_OPENING,
  103. MODELCONDITION_DOOR_3_CLOSING,
  104. MODELCONDITION_DOOR_3_WAITING_OPEN,
  105. MODELCONDITION_DOOR_3_WAITING_TO_CLOSE,
  106. MODELCONDITION_DOOR_4_OPENING,
  107. MODELCONDITION_DOOR_4_CLOSING,
  108. MODELCONDITION_DOOR_4_WAITING_OPEN,
  109. MODELCONDITION_DOOR_4_WAITING_TO_CLOSE,
  110. MODELCONDITION_ATTACKING, //Simply set when a unit is fighting -- terrorist moving with a target will flail arms like a psycho.
  111. MODELCONDITION_PREATTACK_A, //Use for pre-attack animations (like aiming, pulling out a knife, or detonating explosives).
  112. MODELCONDITION_FIRING_A,
  113. MODELCONDITION_BETWEEN_FIRING_SHOTS_A,
  114. MODELCONDITION_RELOADING_A,
  115. MODELCONDITION_PREATTACK_B, //Use for pre-attack animations (like aiming, pulling out a knife, or detonating explosives).
  116. MODELCONDITION_FIRING_B,
  117. MODELCONDITION_BETWEEN_FIRING_SHOTS_B,
  118. MODELCONDITION_RELOADING_B,
  119. MODELCONDITION_PREATTACK_C, //Use for pre-attack animations (like aiming, pulling out a knife, or detonating explosives).
  120. MODELCONDITION_FIRING_C,
  121. MODELCONDITION_BETWEEN_FIRING_SHOTS_C,
  122. MODELCONDITION_RELOADING_C,
  123. MODELCONDITION_TURRET_ROTATE,
  124. MODELCONDITION_POST_COLLAPSE,
  125. MODELCONDITION_MOVING,
  126. MODELCONDITION_DYING,
  127. MODELCONDITION_AWAITING_CONSTRUCTION,
  128. MODELCONDITION_PARTIALLY_CONSTRUCTED,
  129. MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED,
  130. MODELCONDITION_PRONE,
  131. MODELCONDITION_FREEFALL,
  132. MODELCONDITION_ACTIVELY_CONSTRUCTING,
  133. MODELCONDITION_CONSTRUCTION_COMPLETE,
  134. MODELCONDITION_RADAR_EXTENDING,
  135. MODELCONDITION_RADAR_UPGRADED,
  136. MODELCONDITION_PANICKING, // yes, it's spelled with a "k". look it up.
  137. MODELCONDITION_AFLAME,
  138. MODELCONDITION_SMOLDERING,
  139. MODELCONDITION_BURNED,
  140. MODELCONDITION_DOCKING, ///< This encloses the whole time you are Entering, Actioning, and Exiting a dock
  141. MODELCONDITION_DOCKING_BEGINNING, ///< From Enter to Action
  142. MODELCONDITION_DOCKING_ACTIVE, ///< From Action to Exit
  143. MODELCONDITION_DOCKING_ENDING, ///< Exit all the way to next enter (use only animations that end with this)
  144. MODELCONDITION_CARRYING,
  145. MODELCONDITION_FLOODED,
  146. MODELCONDITION_LOADED, // loaded woot! ... like a transport is loaded
  147. MODELCONDITION_JETAFTERBURNER,// shows "flames" for extra motive force (eg, when taking off)
  148. MODELCONDITION_JETEXHAUST, // shows "exhaust" for motive force
  149. MODELCONDITION_PACKING, // packs an object
  150. MODELCONDITION_UNPACKING, // unpacks an object
  151. MODELCONDITION_DEPLOYED, // a deployed object state
  152. MODELCONDITION_OVER_WATER, // Units that can go over water want cool effects for doing so
  153. MODELCONDITION_POWER_PLANT_UPGRADED, // to show special control rods on the cold fusion plant
  154. MODELCONDITION_CLIMBING, //For units climbing up or down cliffs.
  155. MODELCONDITION_SOLD, // object is being sold
  156. #ifdef ALLOW_SURRENDER
  157. MODELCONDITION_SURRENDER, //When units surrender...
  158. #endif
  159. MODELCONDITION_RAPPELLING,
  160. MODELCONDITION_ARMED, // armed like a mine or bomb is armed (not like a human is armed)
  161. MODELCONDITION_POWER_PLANT_UPGRADING, // while special control rods on the cold fusion plant are extending
  162. //Special model conditions work as following:
  163. //Something turns it on... but a timer in the object will turn them off after a given
  164. //amount of time. If you add any more special animations, then you'll need to add the
  165. //code to turn off the state.
  166. MODELCONDITION_SPECIAL_CHEERING, //When units do a victory cheer (or player initiated cheer).
  167. MODELCONDITION_CONTINUOUS_FIRE_SLOW,
  168. MODELCONDITION_CONTINUOUS_FIRE_MEAN,
  169. MODELCONDITION_CONTINUOUS_FIRE_FAST,
  170. MODELCONDITION_RAISING_FLAG,
  171. MODELCONDITION_CAPTURED,
  172. MODELCONDITION_EXPLODED_FLAILING,
  173. MODELCONDITION_EXPLODED_BOUNCING,
  174. MODELCONDITION_SPLATTED,
  175. // this is an easier-to-use variant on the whole FIRING_A deal...
  176. // these bits are set if firing, reloading, between shots, or preattack.
  177. MODELCONDITION_USING_WEAPON_A,
  178. MODELCONDITION_USING_WEAPON_B,
  179. MODELCONDITION_USING_WEAPON_C,
  180. MODELCONDITION_PREORDER,
  181. //
  182. // Note: these values are saved in save files, so you MUST NOT REMOVE OR CHANGE
  183. // existing values!
  184. //
  185. MODELCONDITION_COUNT // keep last!
  186. };
  187. //-------------------------------------------------------------------------------------------------
  188. typedef BitFlags<MODELCONDITION_COUNT> ModelConditionFlags;
  189. #define MAKE_MODELCONDITION_MASK(k) ModelConditionFlags(ModelConditionFlags::kInit, (k))
  190. #define MAKE_MODELCONDITION_MASK2(k,a) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a))
  191. #define MAKE_MODELCONDITION_MASK3(k,a,b) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b))
  192. #define MAKE_MODELCONDITION_MASK4(k,a,b,c) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b), (c))
  193. #define MAKE_MODELCONDITION_MASK5(k,a,b,c,d) ModelConditionFlags(ModelConditionFlags::kInit, (k), (a), (b), (c), (d))
  194. #define MAKE_MODELCONDITION_MASK12(a,b,c,d,e,f,g,h,i,j,k,l) ModelConditionFlags(ModelConditionFlags::kInit, (a), (b), (c), (d), (e), (f), (g), (h), (i), (j), (k), (l))
  195. //-------------------------------------------------------------------------------------------------
  196. //-------------------------------------------------------------------------------------------------
  197. //-------------------------------------------------------------------------------------------------
  198. #endif // _ModelState_H_