SDATA.CPP 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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/SDATA.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 : SDATA.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : August 9, 1994 *
  30. * *
  31. * Last Update : July 9, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * SmudgeTypeClass::As_Reference -- Fetches a reference to the smudge type specified. *
  36. * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object. *
  37. * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type. *
  38. * SmudgeTypeClass::Display -- Draws a generic version of this smudge type. *
  39. * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified. *
  40. * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type. *
  41. * SmudgeTypeClass::Init -- Performs theater specific initializations. *
  42. * SmudgeTypeClass::Init_Heap -- Initialize the smudge type class object heap. *
  43. * SmudgeTypeClass::One_Time -- Performs one-time initialization *
  44. * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. *
  45. * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects. *
  46. * SmudgeTypeClass::operator delete -- Returns a smudge type class object to the pool. *
  47. * SmudgeTypeClass::operator new -- Allocate a smudge type object from the memory pool. *
  48. * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object. *
  49. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  50. #include "function.h"
  51. #include "type.h"
  52. static SmudgeTypeClass const Crater1 (
  53. SMUDGE_CRATER1,
  54. "CR1",
  55. TXT_CRATER,
  56. 1,1, // Width and height of smudge (in icons).
  57. false, // Is this a building bib?
  58. true // Is this a crater smudge?
  59. );
  60. static SmudgeTypeClass const Crater2 (
  61. SMUDGE_CRATER2,
  62. "CR2",
  63. TXT_CRATER,
  64. 1,1, // Width and height of smudge (in icons).
  65. false, // Is this a building bib?
  66. true // Is this a crater smudge?
  67. );
  68. static SmudgeTypeClass const Crater3 (
  69. SMUDGE_CRATER3,
  70. "CR3",
  71. TXT_CRATER,
  72. 1,1, // Width and height of smudge (in icons).
  73. false, // Is this a building bib?
  74. true // Is this a crater smudge?
  75. );
  76. static SmudgeTypeClass const Crater4 (
  77. SMUDGE_CRATER4,
  78. "CR4",
  79. TXT_CRATER,
  80. 1,1, // Width and height of smudge (in icons).
  81. false, // Is this a building bib?
  82. true // Is this a crater smudge?
  83. );
  84. static SmudgeTypeClass const Crater5 (
  85. SMUDGE_CRATER5,
  86. "CR5",
  87. TXT_CRATER,
  88. 1,1, // Width and height of smudge (in icons).
  89. false, // Is this a building bib?
  90. true // Is this a crater smudge?
  91. );
  92. static SmudgeTypeClass const Crater6 (
  93. SMUDGE_CRATER6,
  94. "CR6",
  95. TXT_CRATER,
  96. 1,1, // Width and height of smudge (in icons).
  97. false, // Is this a building bib?
  98. true // Is this a crater smudge?
  99. );
  100. static SmudgeTypeClass const Scorch1 (
  101. SMUDGE_SCORCH1,
  102. "SC1",
  103. TXT_SCORCH,
  104. 1,1, // Width and height of smudge (in icons).
  105. false, // Is this a building bib?
  106. false // Is this a crater smudge?
  107. );
  108. static SmudgeTypeClass const Scorch2 (
  109. SMUDGE_SCORCH2,
  110. "SC2",
  111. TXT_SCORCH,
  112. 1,1, // Width and height of smudge (in icons).
  113. false, // Is this a building bib?
  114. false // Is this a crater smudge?
  115. );
  116. static SmudgeTypeClass const Scorch3 (
  117. SMUDGE_SCORCH3,
  118. "SC3",
  119. TXT_SCORCH,
  120. 1,1, // Width and height of smudge (in icons).
  121. false, // Is this a building bib?
  122. false // Is this a crater smudge?
  123. );
  124. static SmudgeTypeClass const Scorch4 (
  125. SMUDGE_SCORCH4,
  126. "SC4",
  127. TXT_SCORCH,
  128. 1,1, // Width and height of smudge (in icons).
  129. false, // Is this a building bib?
  130. false // Is this a crater smudge?
  131. );
  132. static SmudgeTypeClass const Scorch5 (
  133. SMUDGE_SCORCH5,
  134. "SC5",
  135. TXT_SCORCH,
  136. 1,1, // Width and height of smudge (in icons).
  137. false, // Is this a building bib?
  138. false // Is this a crater smudge?
  139. );
  140. static SmudgeTypeClass const Scorch6 (
  141. SMUDGE_SCORCH6,
  142. "SC6",
  143. TXT_SCORCH,
  144. 1,1, // Width and height of smudge (in icons).
  145. false, // Is this a building bib?
  146. false // Is this a crater smudge?
  147. );
  148. static SmudgeTypeClass const Bibx1 (
  149. SMUDGE_BIB1,
  150. "BIB1",
  151. TXT_BIB,
  152. 4,2, // Width and height of smudge (in icons).
  153. true, // Is this a building bib?
  154. false // Is this a crater smudge?
  155. );
  156. static SmudgeTypeClass const Bibx2 (
  157. SMUDGE_BIB2,
  158. "BIB2",
  159. TXT_BIB,
  160. 3,2, // Width and height of smudge (in icons).
  161. true, // Is this a building bib?
  162. false // Is this a crater smudge?
  163. );
  164. static SmudgeTypeClass const Bibx3 (
  165. SMUDGE_BIB3,
  166. "BIB3",
  167. TXT_BIB,
  168. 2,2, // Width and height of smudge (in icons).
  169. true, // Is this a building bib?
  170. false // Is this a crater smudge?
  171. );
  172. /***********************************************************************************************
  173. * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects. *
  174. * *
  175. * This constructor is used to create the smudge type objects. These type objects contain *
  176. * static information about the various smudge types supported in the game. *
  177. * *
  178. * INPUT: see below... *
  179. * *
  180. * OUTPUT: none *
  181. * *
  182. * WARNINGS: none *
  183. * *
  184. * HISTORY: *
  185. * 08/12/1994 JLB : Created. *
  186. *=============================================================================================*/
  187. SmudgeTypeClass::SmudgeTypeClass(
  188. SmudgeType smudge,
  189. char const * ininame,
  190. int fullname,
  191. int width,
  192. int height,
  193. bool isbib,
  194. bool iscrater) :
  195. ObjectTypeClass(
  196. RTTI_SMUDGETYPE,
  197. int(smudge),
  198. false,
  199. true,
  200. false,
  201. false,
  202. true,
  203. true,
  204. false,
  205. fullname,
  206. ininame),
  207. Type(smudge),
  208. Width(width),
  209. Height(height),
  210. IsCrater(iscrater),
  211. IsBib(isbib)
  212. {
  213. }
  214. /***********************************************************************************************
  215. * SmudgeTypeClass::operator new -- Allocate a smudge type object from the memory pool. *
  216. * *
  217. * This will allocate a smudge type class object from the special memory pool for that *
  218. * purpose. *
  219. * *
  220. * INPUT: none *
  221. * *
  222. * OUTPUT: Returns with the newly allocated smudge type class object. If there is insufficient*
  223. * memory in the pool to fulfill the request, then NULL is returned. *
  224. * *
  225. * WARNINGS: none *
  226. * *
  227. * HISTORY: *
  228. * 07/09/1996 JLB : Created. *
  229. *=============================================================================================*/
  230. void * SmudgeTypeClass::operator new(size_t)
  231. {
  232. return(SmudgeTypes.Alloc());
  233. }
  234. /***********************************************************************************************
  235. * SmudgeTypeClass::operator delete -- Returns a smudge type class object to the pool. *
  236. * *
  237. * This will return the smudge type class object back to the memory pool from whence it *
  238. * was originally allocated. *
  239. * *
  240. * INPUT: pointer -- Pointer to the smudge type class object to return the pool. *
  241. * *
  242. * OUTPUT: none *
  243. * *
  244. * WARNINGS: none *
  245. * *
  246. * HISTORY: *
  247. * 07/09/1996 JLB : Created. *
  248. *=============================================================================================*/
  249. void SmudgeTypeClass::operator delete(void * pointer)
  250. {
  251. SmudgeTypes.Free((SmudgeTypeClass *)pointer);
  252. }
  253. /***********************************************************************************************
  254. * SmudgeTypeClass::Init_Heap -- Initialize the smudge type class object heap. *
  255. * *
  256. * This will initialize the special heap for smudge type class objects, by pre-allocated *
  257. * all known smudge types. *
  258. * *
  259. * INPUT: none *
  260. * *
  261. * OUTPUT: none *
  262. * *
  263. * WARNINGS: Call this routine only once and before the rules.ini file is processed. *
  264. * *
  265. * HISTORY: *
  266. * 07/09/1996 JLB : Created. *
  267. *=============================================================================================*/
  268. void SmudgeTypeClass::Init_Heap(void)
  269. {
  270. /*
  271. ** These smudge type class objects must be allocated in the exact order that they
  272. ** are specified in the SmudgeType enumeration. This is necessary because the heap
  273. ** allocation block index serves double duty as the type number index.
  274. */
  275. new SmudgeTypeClass(Crater1); // SMUDGE_CRATER1
  276. new SmudgeTypeClass(Crater2); // SMUDGE_CRATER2
  277. new SmudgeTypeClass(Crater3); // SMUDGE_CRATER3
  278. new SmudgeTypeClass(Crater4); // SMUDGE_CRATER4
  279. new SmudgeTypeClass(Crater5); // SMUDGE_CRATER5
  280. new SmudgeTypeClass(Crater6); // SMUDGE_CRATER6
  281. new SmudgeTypeClass(Scorch1); // SMUDGE_SCORCH1
  282. new SmudgeTypeClass(Scorch2); // SMUDGE_SCORCH2
  283. new SmudgeTypeClass(Scorch3); // SMUDGE_SCORCH3
  284. new SmudgeTypeClass(Scorch4); // SMUDGE_SCORCH4
  285. new SmudgeTypeClass(Scorch5); // SMUDGE_SCORCH5
  286. new SmudgeTypeClass(Scorch6); // SMUDGE_SCORCH6
  287. new SmudgeTypeClass(Bibx1); // SMUDGE_BIB1
  288. new SmudgeTypeClass(Bibx2); // SMUDGE_BIB2
  289. new SmudgeTypeClass(Bibx3); // SMUDGE_BIB3
  290. }
  291. /***********************************************************************************************
  292. * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type. *
  293. * *
  294. * This converts an ASCII name into a smudge type number. This is typically necessary *
  295. * when processing scenario INI files and not used otherwise. *
  296. * *
  297. * INPUT: name -- Pointer to the name to convert. *
  298. * *
  299. * OUTPUT: Returns with the SmudgeType number that matches the name supplied. If no match *
  300. * was found, then SMUDGE_NONE is returned. *
  301. * *
  302. * WARNINGS: none *
  303. * *
  304. * HISTORY: *
  305. * 08/12/1994 JLB : Created. *
  306. *=============================================================================================*/
  307. SmudgeType SmudgeTypeClass::From_Name(char const * name)
  308. {
  309. if (name != NULL) {
  310. for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
  311. if (stricmp(As_Reference(index).IniName, name) == 0) {
  312. return(index);
  313. }
  314. }
  315. }
  316. return(SMUDGE_NONE);
  317. }
  318. /***********************************************************************************************
  319. * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object. *
  320. * *
  321. * Smudges are always only one icon in dimension, so this routine always returns a cell *
  322. * occupation offset list of the center cell. *
  323. * *
  324. * INPUT: placement -- Is this for placement legality checking only? The normal condition *
  325. * is for marking occupation flags. *
  326. * *
  327. * OUTPUT: Returns occupation list specifying all the cells that the overlay occupies. This *
  328. * is just the center cell. *
  329. * *
  330. * WARNINGS: none *
  331. * *
  332. * HISTORY: *
  333. * 08/12/1994 JLB : Created. *
  334. *=============================================================================================*/
  335. short const * SmudgeTypeClass::Occupy_List(bool) const
  336. {
  337. static short _occupy[4*4];
  338. short * ptr = &_occupy[0];
  339. for (int x = 0; x < Width; x++) {
  340. for (int y = 0; y < Height; y++) {
  341. *ptr++ = x + (y*MAP_CELL_W);
  342. }
  343. }
  344. *ptr = REFRESH_EOL;
  345. return(_occupy);
  346. }
  347. /***********************************************************************************************
  348. * SmudgeTypeClass::Init -- Performs theater specific initializations. *
  349. * *
  350. * Smudge object imagery varies between theaters. This routine will load the appropriate *
  351. * imagery for the theater specified. *
  352. * *
  353. * INPUT: theater -- The theater to prepare for. *
  354. * *
  355. * OUTPUT: none *
  356. * *
  357. * WARNINGS: none *
  358. * *
  359. * HISTORY: *
  360. * 08/12/1994 JLB : Created. *
  361. *=============================================================================================*/
  362. void SmudgeTypeClass::Init(TheaterType theater)
  363. {
  364. if (theater != LastTheater) {
  365. for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
  366. SmudgeTypeClass const & smudge = As_Reference(index);
  367. char fullname[_MAX_FNAME+_MAX_EXT]; // Fully constructed smudge data set name.
  368. _makepath(fullname, NULL, NULL, smudge.IniName, Theaters[theater].Suffix);
  369. ((void const *&)smudge.ImageData) = MFCD::Retrieve(fullname);
  370. }
  371. }
  372. }
  373. #ifdef SCENARIO_EDITOR
  374. /***********************************************************************************************
  375. * SmudgeTypeClass::Display -- Draws a generic version of this smudge type. *
  376. * *
  377. * The scenario object editor will call this routine to display a typical imagery of this *
  378. * smudge object for graphical identification purposes. *
  379. * *
  380. * INPUT: x,y -- Coordinate to render the smudge at. *
  381. * *
  382. * window-- The window to base the coordinate rendering upon. *
  383. * *
  384. * OUTPUT: none *
  385. * *
  386. * WARNINGS: none *
  387. * *
  388. * HISTORY: *
  389. * 08/12/1994 JLB : Created. *
  390. *=============================================================================================*/
  391. void SmudgeTypeClass::Display(int x, int y, WindowNumberType window, HousesType ) const
  392. {
  393. void const * ptr = Get_Image_Data();
  394. x += WindowList[window][WINDOWX];
  395. y += WindowList[window][WINDOWY];
  396. IsTheaterShape = true; // Smudges are theater specific
  397. if (ptr != NULL) {
  398. for (int w = 0; w < Width; w++) {
  399. for (int h = 0; h < Height; h++) {
  400. CC_Draw_Shape(ptr, w + (h*Width), x + w*ICON_PIXEL_W, y + h*ICON_PIXEL_H, WINDOW_TACTICAL, SHAPE_WIN_REL);
  401. }
  402. }
  403. }
  404. IsTheaterShape = false;
  405. }
  406. /***********************************************************************************************
  407. * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. *
  408. * *
  409. * This routine adds smudge objects to the list of objects that the scenario editor can *
  410. * place upon the ground. It is only called from the scenario editor. *
  411. * *
  412. * INPUT: none *
  413. * *
  414. * OUTPUT: none *
  415. * *
  416. * WARNINGS: none *
  417. * *
  418. * HISTORY: *
  419. * 08/12/1994 JLB : Created. *
  420. *=============================================================================================*/
  421. void SmudgeTypeClass::Prep_For_Add(void)
  422. {
  423. for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
  424. if (As_Reference(index).Get_Image_Data()) {
  425. Map.Add_To_List(&As_Reference(index));
  426. }
  427. }
  428. }
  429. #endif
  430. /***********************************************************************************************
  431. * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object. *
  432. * *
  433. * This routine will, in one motion, create a smudge object and place it upon the map. *
  434. * Since placing a smudge on the map will destroy the object, this routine will leave the *
  435. * smudge object count unchanged. Typically, this routine is used by the scenario editor *
  436. * for creating smudges and placing them on the map. *
  437. * *
  438. * INPUT: cell -- The cell to place the smudge object. *
  439. * *
  440. * OUTPUT: bool; Was the placement successful? *
  441. * *
  442. * WARNINGS: none *
  443. * *
  444. * HISTORY: *
  445. * 08/12/1994 JLB : Created. *
  446. *=============================================================================================*/
  447. bool SmudgeTypeClass::Create_And_Place(CELL cell, HousesType ) const
  448. {
  449. if (new SmudgeClass(Type, Cell_Coord(cell))) {
  450. return(true);
  451. }
  452. return(false);
  453. }
  454. /***********************************************************************************************
  455. * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type. *
  456. * *
  457. * This routine will create a smudge object of the appropriate type. Smudge objects are *
  458. * transitory in nature. They exist only from the point of creation until they are given *
  459. * a spot on the map to reside. At that time the map data is updated and the smudge *
  460. * object is destroyed. *
  461. * *
  462. * INPUT: none *
  463. * *
  464. * OUTPUT: Returns with a pointer to a created smudge object. If none could be created, then *
  465. * NULL is returned. *
  466. * *
  467. * WARNINGS: none *
  468. * *
  469. * HISTORY: *
  470. * 08/12/1994 JLB : Created. *
  471. *=============================================================================================*/
  472. ObjectClass * SmudgeTypeClass::Create_One_Of(HouseClass *) const
  473. {
  474. return(new SmudgeClass(Type, -1));
  475. }
  476. /***********************************************************************************************
  477. * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified. *
  478. * *
  479. * This routine will draw the smudge overlay image at the coordinate (upper left) *
  480. * specified. The underlying terrain icon is presumed to have already been rendered. *
  481. * *
  482. * INPUT: x,y -- Coordinate of the upper left corner of icon to render the smudge object. *
  483. * *
  484. * OUTPUT: none *
  485. * *
  486. * WARNINGS: none *
  487. * *
  488. * HISTORY: *
  489. * 08/12/1994 JLB : Created. *
  490. *=============================================================================================*/
  491. void SmudgeTypeClass::Draw_It(int x, int y, int data) const
  492. {
  493. void const * ptr = Get_Image_Data();
  494. if (ptr != NULL) {
  495. IsTheaterShape = true; // Smudges are theater specific
  496. CC_Draw_Shape(ptr, data, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  497. IsTheaterShape = false;
  498. }
  499. }
  500. /***********************************************************************************************
  501. * SmudgeTypeClass::One_Time -- Performs one-time initialization *
  502. * *
  503. * INPUT: none *
  504. * *
  505. * OUTPUT: none *
  506. * *
  507. * WARNINGS: none *
  508. * *
  509. * HISTORY: *
  510. * 08/12/1994 JLB : Created. *
  511. *=============================================================================================*/
  512. void SmudgeTypeClass::One_Time(void)
  513. {
  514. }
  515. /***********************************************************************************************
  516. * SmudgeTypeClass::As_Reference -- Fetches a reference to the smudge type specified. *
  517. * *
  518. * Use this routine to get a reference to the smudge type class object when given just *
  519. * the smudge type identifier. *
  520. * *
  521. * INPUT: type -- The smudge type identifier to convert into a reference. *
  522. * *
  523. * OUTPUT: Returns with a reference to the smudge type class object. *
  524. * *
  525. * WARNINGS: Be sure that the smudge type specified is legal. An illegal type value will *
  526. * produce undefined results. *
  527. * *
  528. * HISTORY: *
  529. * 07/09/1996 JLB : Created. *
  530. *=============================================================================================*/
  531. SmudgeTypeClass & SmudgeTypeClass::As_Reference(SmudgeType type)
  532. {
  533. return(*SmudgeTypes.Ptr(type));
  534. }