CRATE.CPP 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/CRATE.CPP 3 3/04/97 3:12p 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 : CRATE.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 08/26/96 *
  30. * *
  31. * Last Update : October 14, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * CrateClass::Create_Crate -- Create a crate in the cell specified. *
  36. * CrateClass::Get_Crate -- Pick up a crate from the cell specified. *
  37. * CrateClass::Put_Crate -- Generates crate overlay at cell specified. *
  38. * CrateClass::Remove_It -- Removes the crate from wherever it is. *
  39. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  40. #include "function.h"
  41. /***********************************************************************************************
  42. * CrateClass::Remove_It -- Removes the crate from wherever it is. *
  43. * *
  44. * This routine will remove the crate from whereever it happens to be. *
  45. * *
  46. * INPUT: none *
  47. * *
  48. * OUTPUT: bool; Was the crate found and removed? *
  49. * *
  50. * WARNINGS: none *
  51. * *
  52. * HISTORY: *
  53. * 08/26/1996 JLB : Created. *
  54. *=============================================================================================*/
  55. bool CrateClass::Remove_It(void)
  56. {
  57. if (Is_Valid()) {
  58. Get_Crate(Cell);
  59. Make_Invalid();
  60. return(true);
  61. }
  62. return(false);
  63. }
  64. /***********************************************************************************************
  65. * CrateClass::Create_Crate -- Create a crate in the cell specified. *
  66. * *
  67. * This will create a crate in the cell specified. If the crate could not be crated there *
  68. * then 'false' will be returned. *
  69. * *
  70. * INPUT: cell -- The desired cell to place the crate in. *
  71. * *
  72. * OUTPUT: bool; Was the crate created and placed in the cell? *
  73. * *
  74. * WARNINGS: It is quite possible for the crate not to have been placed. Only the most clear *
  75. * locations are valid for crate placement. *
  76. * *
  77. * HISTORY: *
  78. * 08/26/1996 JLB : Created. *
  79. *=============================================================================================*/
  80. bool CrateClass::Create_Crate(CELL cell)
  81. {
  82. /*
  83. ** Remove any existing crate that this crate class is tracking.
  84. */
  85. Remove_It();
  86. /*
  87. ** Try to place a new crate at the cell specified.
  88. */
  89. if (Put_Crate(cell)) {
  90. Cell = cell;
  91. Timer = Random_Pick(Rule.CrateTime * (TICKS_PER_MINUTE/2), Rule.CrateTime * (TICKS_PER_MINUTE*2));
  92. Timer.Start();
  93. return(true);
  94. }
  95. return(false);
  96. }
  97. /***********************************************************************************************
  98. * CrateClass::Put_Crate -- Generates crate overlay at cell specified. *
  99. * *
  100. * This helpter routine will examine the cell and place the appropriate crate type into *
  101. * the cell specified. If the overlay could not be generated, then 'false' is returned. *
  102. * *
  103. * INPUT: cell -- The cell to generate the crate overlay in. *
  104. * *
  105. * OUTPUT: bool; Was the crate overlay generated? *
  106. * *
  107. * WARNINGS: none *
  108. * *
  109. * HISTORY: *
  110. * 08/26/1996 JLB : Created. *
  111. * 10/14/1996 JLB : Takes reference to cell so that tracking can occur. *
  112. *=============================================================================================*/
  113. bool CrateClass::Put_Crate(CELL & cell)
  114. {
  115. int old = ScenarioInit;
  116. ScenarioInit = 0;
  117. if (Map.In_Radar(cell)) {
  118. CellClass * cellptr = &Map[cell];
  119. while (cellptr->Overlay != OVERLAY_NONE && !cellptr->Is_Clear_To_Build(SPEED_FLOAT) && !cellptr->Is_Clear_To_Build(SPEED_FOOT)) {
  120. cell = Map.Pick_Random_Location();
  121. if (Percent_Chance(100 * Rule.WaterCrateChance)) {
  122. cell = Map.Nearby_Location(cell, SPEED_FLOAT);
  123. } else {
  124. cell = Map.Nearby_Location(cell, SPEED_TRACK);
  125. }
  126. cellptr = &Map[cell];
  127. }
  128. if (cellptr->Is_Clear_To_Build(SPEED_FLOAT)) {
  129. new OverlayClass(OVERLAY_WATER_CRATE, cell);
  130. } else {
  131. new OverlayClass(OVERLAY_WOOD_CRATE, cell);
  132. }
  133. ScenarioInit = old;
  134. return(true);
  135. }
  136. ScenarioInit = old;
  137. return(false);
  138. }
  139. /***********************************************************************************************
  140. * CrateClass::Get_Crate -- Pick up a crate from the cell specified. *
  141. * *
  142. * This will remove the crate from the cell specified. *
  143. * *
  144. * INPUT: cell -- The cell to examine and remove any crate overlays present. *
  145. * *
  146. * OUTPUT: bool; Was a crate overlay found and removed? *
  147. * *
  148. * WARNINGS: none *
  149. * *
  150. * HISTORY: *
  151. * 08/26/1996 JLB : Created. *
  152. *=============================================================================================*/
  153. bool CrateClass::Get_Crate(CELL cell)
  154. {
  155. if (Map.In_Radar(cell)) {
  156. CellClass * cellptr = &Map[cell];
  157. if (cellptr->Overlay == OVERLAY_WOOD_CRATE ||
  158. cellptr->Overlay == OVERLAY_STEEL_CRATE ||
  159. cellptr->Overlay == OVERLAY_WATER_CRATE) {
  160. cellptr->Overlay = OVERLAY_NONE;
  161. cellptr->OverlayData = 0;
  162. cellptr->Redraw_Objects();
  163. return(true);
  164. }
  165. }
  166. return(false);
  167. }