CRATE.CPP 10 KB

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