TEMPLATE.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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/TEMPLATE.CPP 1 3/03/97 10:25a 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 : TEMPLATE.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : May 17, 1994 *
  30. * *
  31. * Last Update : January 23, 1995 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * TemplateClass::Init -- Resets the template object system. *
  36. * TemplateClass::Mark -- Lifts or drops a template object. *
  37. * TemplateClass::Select -- Select the template object. *
  38. * TemplateClass::TemplateClass -- Template object constructor. *
  39. * TemplateClass::Unlimbo -- Places a template object into the game/map system. *
  40. * TemplateClass::delete -- Returns a template object to the pool. *
  41. * TemplateClass::new -- Allocates a template object from pool *
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. #include "function.h"
  44. #include "template.h"
  45. /***********************************************************************************************
  46. * TemplateClass::Init -- Resets the template object system. *
  47. * *
  48. * This routine resets the template object system. It is called *
  49. * prior to loading a new scenario. *
  50. * *
  51. * INPUT: none *
  52. * *
  53. * OUTPUT: none *
  54. * *
  55. * WARNINGS: none *
  56. * *
  57. * HISTORY: *
  58. * 05/24/1994 JLB : Created. *
  59. *=============================================================================================*/
  60. void TemplateClass::Init(void)
  61. {
  62. Templates.Free_All();
  63. }
  64. /***********************************************************************************************
  65. * TemplateClass::Mark -- Lifts or drops a template object. *
  66. * *
  67. * This routine handles placing or removing a template object. This *
  68. * entails marking the map as appropriate and redisplaying affected *
  69. * cells. *
  70. * *
  71. * INPUT: mark -- The marking operation to perform. *
  72. * *
  73. * OUTPUT: bool; Was the template successfully marked? *
  74. * *
  75. * WARNINGS: none *
  76. * *
  77. * HISTORY: *
  78. * 05/17/1994 JLB : Created. *
  79. * 12/23/1994 JLB : Examines low level legality before processing. *
  80. *=============================================================================================*/
  81. bool TemplateClass::Mark(MarkType mark)
  82. {
  83. assert(Templates.ID(this) == ID);
  84. assert(IsActive);
  85. static bool noup = false;
  86. void const * iset = Get_Image_Data();
  87. if (iset && ObjectClass::Mark(mark)) {
  88. void * map = Get_Icon_Set_Map(iset);
  89. for (int y = 0; y < Class->Height; y++) {
  90. for (int x = 0; x < Class->Width; x++) {
  91. CELL cell = Coord_Cell(Coord) + y*MAP_CELL_W + x;
  92. if (Map.In_Radar(cell)) {
  93. CellClass * cellptr = &Map[cell];
  94. int number = y*Class->Width + x;
  95. /*
  96. ** Determine if this logical icon actually maps to a real icon. If no real
  97. ** icon is associated with this logical position, then don't do any action
  98. ** since none is required.
  99. */
  100. char * mapptr = (char*)map;
  101. bool real = (mapptr[number] != -1);
  102. if (real) {
  103. /*
  104. ** Lift the terrain object from the map.
  105. */
  106. if (mark == MARK_UP && !noup) {
  107. if (cellptr->TType == Class->Type && cellptr->TIcon == number) {
  108. cellptr->TType = TEMPLATE_NONE;
  109. cellptr->TIcon = 0;
  110. }
  111. }
  112. /*
  113. ** Place the terrain object down.
  114. */
  115. if (mark == MARK_DOWN) {
  116. if (*this == TEMPLATE_CLEAR1) {
  117. cellptr->TType = TEMPLATE_NONE;
  118. cellptr->TIcon = 0;
  119. } else {
  120. cellptr->TType = Class->Type;
  121. cellptr->TIcon = number;
  122. }
  123. /*
  124. ** Make sure that no overlays or smudges exist after
  125. ** placing the template down.
  126. */
  127. cellptr->Smudge = SMUDGE_NONE;
  128. cellptr->SmudgeData = 0;
  129. cellptr->Overlay = OVERLAY_NONE;
  130. cellptr->OverlayData = 0;
  131. }
  132. cellptr->Redraw_Objects();
  133. cellptr->Recalc_Attributes();
  134. }
  135. }
  136. }
  137. }
  138. /*
  139. ** When marking this template down onto the map, the map template numbers are update
  140. ** but the template is removed from existence. Make sure that the deletion of the
  141. ** template object doesn't also lift the template numbers up from the map.
  142. */
  143. if (mark == MARK_DOWN) {
  144. noup = true;
  145. delete this;
  146. noup = false;
  147. }
  148. return(true);
  149. }
  150. return(false);
  151. }
  152. /***********************************************************************************************
  153. * TemplateClass::new -- Allocates a template object from pool *
  154. * *
  155. * This routine is used to allocate a template object from the *
  156. * template object pool. *
  157. * *
  158. * INPUT: size -- The size of a template object (not used). *
  159. * *
  160. * OUTPUT: Returns with a pointer to an available template object. *
  161. * *
  162. * WARNINGS: none *
  163. * *
  164. * HISTORY: *
  165. * 05/17/1994 JLB : Created. *
  166. *=============================================================================================*/
  167. void * TemplateClass::operator new(size_t )
  168. {
  169. void * ptr = Templates.Allocate();
  170. if (ptr) {
  171. ((TemplateClass *)ptr)->IsActive = true;
  172. }
  173. return(ptr);
  174. }
  175. /***********************************************************************************************
  176. * TemplateClass::delete -- Returns a template object to the pool. *
  177. * *
  178. * This routine will return a template object to the template object *
  179. * pool. A template so returned is available for allocation again. *
  180. * *
  181. * INPUT: ptr -- Pointer to the object to be returned. *
  182. * *
  183. * OUTPUT: none *
  184. * *
  185. * WARNINGS: none *
  186. * *
  187. * HISTORY: *
  188. * 05/17/1994 JLB : Created. *
  189. *=============================================================================================*/
  190. void TemplateClass::operator delete(void * ptr)
  191. {
  192. if (ptr) {
  193. ((TemplateClass *)ptr)->IsActive = false;
  194. }
  195. Templates.Free((TemplateClass *)ptr);
  196. }
  197. /***********************************************************************************************
  198. * TemplateClass::TemplateClass -- Template object constructor. *
  199. * *
  200. * This is the constructor for a template object. *
  201. * *
  202. * INPUT: type -- The template object this is to become. *
  203. * *
  204. * pos -- The position on the map to place the object. *
  205. * *
  206. * OUTPUT: none *
  207. * *
  208. * WARNINGS: none *
  209. * *
  210. * HISTORY: *
  211. * 05/17/1994 JLB : Created. *
  212. *=============================================================================================*/
  213. TemplateClass::TemplateClass(TemplateType type, CELL pos) :
  214. ObjectClass(RTTI_TEMPLATE, Templates.ID(this)),
  215. Class(TemplateTypes.Ptr((int)type))
  216. {
  217. if (pos != -1) {
  218. Unlimbo(Cell_Coord(pos));
  219. }
  220. }