DOOR.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/DOOR.CPP 1 3/03/97 10:24a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** 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 ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : DOOR.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 06/11/95 *
  30. * *
  31. * Last Update : June 14, 1995 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * DoorClass::AI -- Handles the door processing logic. *
  36. * DoorClass::Close_Door -- Try to close the unit's door. *
  37. * DoorClass::DoorClass -- Constructor for the DoorClass object. *
  38. * DoorClass::Door_Stage -- Fetches the current door animation frame. *
  39. * DoorClass::Open_Door -- Opens the door for this unit. *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "function.h"
  42. /***********************************************************************************************
  43. * DoorClass::DoorClass -- Constructor for the DoorClass object. *
  44. * *
  45. * This constructor sets the door to an initial closed state. *
  46. * *
  47. * INPUT: none *
  48. * *
  49. * OUTPUT: none *
  50. * *
  51. * WARNINGS: none *
  52. * *
  53. * HISTORY: *
  54. * 06/14/1995 JLB : Created. *
  55. *=============================================================================================*/
  56. DoorClass::DoorClass(void)
  57. {
  58. State = IS_CLOSED;
  59. IsToRedraw = false;
  60. Stages = 0;
  61. }
  62. /***********************************************************************************************
  63. * DoorClass::AI -- Handles the door processing logic. *
  64. * *
  65. * This routine should be called every game frame. It handles the door closing and opening *
  66. * logic. *
  67. * *
  68. * INPUT: none *
  69. * *
  70. * OUTPUT: none *
  71. * *
  72. * WARNINGS: none *
  73. * *
  74. * HISTORY: *
  75. * 06/13/1995 JLB : Created. *
  76. *=============================================================================================*/
  77. void DoorClass::AI(void)
  78. {
  79. if (Control.Graphic_Logic()) {
  80. if (Control.Fetch_Stage() >= Stages) {
  81. Control.Set_Rate(0);
  82. switch (State) {
  83. case IS_OPENING:
  84. State = IS_OPEN;
  85. break;
  86. case IS_CLOSING:
  87. State = IS_CLOSED;
  88. break;
  89. }
  90. }
  91. IsToRedraw = true;
  92. }
  93. }
  94. /***********************************************************************************************
  95. * DoorClass::Open_Door -- Opens the door for this unit. *
  96. * *
  97. * This routine will perform the door open operation for this unit. It will control vehicle *
  98. * rotation if necessary. *
  99. * *
  100. * INPUT: rate -- The animation rate (delay) to use for the door animation logic. *
  101. * *
  102. * stages -- The number of animations stages that this door must pass through. *
  103. * *
  104. * OUTPUT: Was action initiated to open the door? *
  105. * *
  106. * WARNINGS: none *
  107. * *
  108. * HISTORY: *
  109. * 05/08/1995 JLB : Created. *
  110. *=============================================================================================*/
  111. bool DoorClass::Open_Door(int rate, int stages)
  112. {
  113. switch (State) {
  114. case IS_CLOSED:
  115. case IS_CLOSING:
  116. State = IS_OPENING;
  117. Stages = stages-1;
  118. Control.Set_Stage(0);
  119. Control.Set_Rate(rate);
  120. return(true);
  121. }
  122. return(false);
  123. }
  124. /***********************************************************************************************
  125. * DoorClass::Close_Door -- Try to close the unit's door. *
  126. * *
  127. * This routine will attempt to close the unit's door. If the door is already closed or *
  128. * in the process of closing, then no action is performed. *
  129. * *
  130. * INPUT: rate -- The animation rate (delay) to use for the door animation logic. *
  131. * *
  132. * stages -- The number of animations stages that this door must pass through. *
  133. * *
  134. * OUTPUT: Action was initiated to close the door? *
  135. * *
  136. * WARNINGS: none *
  137. * *
  138. * HISTORY: *
  139. * 05/08/1995 JLB : Created. *
  140. *=============================================================================================*/
  141. bool DoorClass::Close_Door(int rate, int stages)
  142. {
  143. switch (State) {
  144. case IS_OPEN:
  145. case IS_OPENING:
  146. State = IS_CLOSING;
  147. Stages = stages-1;
  148. Control.Set_Stage(0);
  149. Control.Set_Rate(rate);
  150. return(true);
  151. }
  152. return(false);
  153. }
  154. /***********************************************************************************************
  155. * DoorClass::Door_Stage -- Fetches the current door animation frame. *
  156. * *
  157. * Use this routine to fetch the current door animation frame number. Frame zero is the *
  158. * closed frame and frame 'N' is the open frame. If the door is in the process of opening *
  159. * or closing, the appropriate frame number is used. 'N' is defined as the number of *
  160. * stages in the animation minus 1 (e.g., a four frame animation will return a door stage *
  161. * number between 0 and 3, inclusive). *
  162. * *
  163. * INPUT: none *
  164. * *
  165. * OUTPUT: Returns with the door animation frame number. *
  166. * *
  167. * WARNINGS: none *
  168. * *
  169. * HISTORY: *
  170. * 06/14/1995 JLB : Created. *
  171. *=============================================================================================*/
  172. int DoorClass::Door_Stage(void) const
  173. {
  174. switch (State) {
  175. case IS_CLOSING:
  176. return((Stages-1) - Control.Fetch_Stage());
  177. case IS_CLOSED:
  178. return(0);
  179. case IS_OPENING:
  180. return(Control.Fetch_Stage());
  181. case IS_OPEN:
  182. return(Stages-1);
  183. }
  184. return(0);
  185. }