DOOR.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: F:\projects\c&c\vcs\code\door.cpv 1.4 16 Oct 1995 16:49:16 JOE_BOSTIC $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : DOOR.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 06/11/95 *
  26. * *
  27. * Last Update : June 14, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * DoorClass::AI -- Handles the door processing logic. *
  32. * DoorClass::Close_Door -- Try to close the unit's door. *
  33. * DoorClass::DoorClass -- Constructor for the DoorClass object. *
  34. * DoorClass::Door_Stage -- Fetches the current door animation frame. *
  35. * DoorClass::Open_Door -- Opens the door for this unit. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "function.h"
  38. /***********************************************************************************************
  39. * DoorClass::DoorClass -- Constructor for the DoorClass object. *
  40. * *
  41. * This constructor sets the door to an initial closed state. *
  42. * *
  43. * INPUT: none *
  44. * *
  45. * OUTPUT: none *
  46. * *
  47. * WARNINGS: none *
  48. * *
  49. * HISTORY: *
  50. * 06/14/1995 JLB : Created. *
  51. *=============================================================================================*/
  52. DoorClass::DoorClass(void)
  53. {
  54. State = IS_CLOSED;
  55. IsToRedraw = false;
  56. Stages = 0;
  57. }
  58. /***********************************************************************************************
  59. * DoorClass::AI -- Handles the door processing logic. *
  60. * *
  61. * This routine should be called every game frame. It handles the door closing and opening *
  62. * logic. *
  63. * *
  64. * INPUT: none *
  65. * *
  66. * OUTPUT: none *
  67. * *
  68. * WARNINGS: none *
  69. * *
  70. * HISTORY: *
  71. * 06/13/1995 JLB : Created. *
  72. *=============================================================================================*/
  73. void DoorClass::AI(void)
  74. {
  75. if (Control.Graphic_Logic()) {
  76. if (Control.Fetch_Stage() >= Stages) {
  77. Control.Set_Rate(0);
  78. switch (State) {
  79. case IS_OPENING:
  80. State = IS_OPEN;
  81. break;
  82. case IS_CLOSING:
  83. State = IS_CLOSED;
  84. break;
  85. }
  86. }
  87. IsToRedraw = true;
  88. }
  89. }
  90. /***********************************************************************************************
  91. * DoorClass::Open_Door -- Opens the door for this unit. *
  92. * *
  93. * This routine will perform the door open operation for this unit. It will control vehicle *
  94. * rotation if necessary. *
  95. * *
  96. * INPUT: rate -- The animation rate (delay) to use for the door animation logic. *
  97. * *
  98. * stages -- The number of animations stages that this door must pass through. *
  99. * *
  100. * OUTPUT: Was action initiated to open the door? *
  101. * *
  102. * WARNINGS: none *
  103. * *
  104. * HISTORY: *
  105. * 05/08/1995 JLB : Created. *
  106. *=============================================================================================*/
  107. bool DoorClass::Open_Door(int rate, int stages)
  108. {
  109. switch (State) {
  110. case IS_CLOSED:
  111. case IS_CLOSING:
  112. State = IS_OPENING;
  113. Stages = stages-1;
  114. Control.Set_Stage(0);
  115. Control.Set_Rate(rate);
  116. return(true);
  117. }
  118. return(false);
  119. }
  120. /***********************************************************************************************
  121. * DoorClass::Close_Door -- Try to close the unit's door. *
  122. * *
  123. * This routine will attempt to close the unit's door. If the door is already closed or *
  124. * in the process of closing, then no action is performed. *
  125. * *
  126. * INPUT: rate -- The animation rate (delay) to use for the door animation logic. *
  127. * *
  128. * stages -- The number of animations stages that this door must pass through. *
  129. * *
  130. * OUTPUT: Action was initiated to close the door? *
  131. * *
  132. * WARNINGS: none *
  133. * *
  134. * HISTORY: *
  135. * 05/08/1995 JLB : Created. *
  136. *=============================================================================================*/
  137. bool DoorClass::Close_Door(int rate, int stages)
  138. {
  139. switch (State) {
  140. case IS_OPEN:
  141. case IS_OPENING:
  142. State = IS_CLOSING;
  143. Stages = stages-1;
  144. Control.Set_Stage(0);
  145. Control.Set_Rate(rate);
  146. return(true);
  147. }
  148. return(false);
  149. }
  150. /***********************************************************************************************
  151. * DoorClass::Door_Stage -- Fetches the current door animation frame. *
  152. * *
  153. * Use this routine to fetch the current door animation frame number. Frame zero is the *
  154. * closed frame and frame 'N' is the open frame. If the door is in the process of opening *
  155. * or closing, the appropriate frame number is used. 'N' is defined as the number of *
  156. * stages in the animation minus 1 (e.g., a four frame animation will return a door stage *
  157. * number between 0 and 3, inclusive). *
  158. * *
  159. * INPUT: none *
  160. * *
  161. * OUTPUT: Returns with the door animation frame number. *
  162. * *
  163. * WARNINGS: none *
  164. * *
  165. * HISTORY: *
  166. * 06/14/1995 JLB : Created. *
  167. *=============================================================================================*/
  168. int DoorClass::Door_Stage(void) const
  169. {
  170. switch (State) {
  171. case IS_CLOSING:
  172. return((Stages-1) - Control.Fetch_Stage());
  173. case IS_CLOSED:
  174. return(0);
  175. case IS_OPENING:
  176. return(Control.Fetch_Stage());
  177. case IS_OPEN:
  178. return(Stages-1);
  179. }
  180. return(0);
  181. }