SDATA.CPP 32 KB

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