SDATA.CPP 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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: F:\projects\c&c\vcs\code\sdata.cpv 2.17 16 Oct 1995 16:52:10 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 : August 12, 1994 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified. *
  32. * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type. *
  33. * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object. *
  34. * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. *
  35. * SmudgeTypeClass::Init -- Performs theater specific initializations. *
  36. * SmudgeTypeClass::Display -- Draws a generic version of this smudge type. *
  37. * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object. *
  38. * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type. *
  39. * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects. *
  40. * SmudgeTypeClass::One_Time -- Performs one-time initialization *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "function.h"
  43. #include "type.h"
  44. static SmudgeTypeClass const Crater1 (
  45. SMUDGE_CRATER1,
  46. "CR1",
  47. TXT_CRATER,
  48. 1,1, // Width and height of smudge (in icons).
  49. false, // Is this a building bib?
  50. true // Is this a crater smudge?
  51. );
  52. static SmudgeTypeClass const Crater2 (
  53. SMUDGE_CRATER2,
  54. "CR2",
  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 Crater3 (
  61. SMUDGE_CRATER3,
  62. "CR3",
  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 Crater4 (
  69. SMUDGE_CRATER4,
  70. "CR4",
  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 Crater5 (
  77. SMUDGE_CRATER5,
  78. "CR5",
  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 Crater6 (
  85. SMUDGE_CRATER6,
  86. "CR6",
  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 Scorch1 (
  93. SMUDGE_SCORCH1,
  94. "SC1",
  95. TXT_SCORCH,
  96. 1,1, // Width and height of smudge (in icons).
  97. false, // Is this a building bib?
  98. false // Is this a crater smudge?
  99. );
  100. static SmudgeTypeClass const Scorch2 (
  101. SMUDGE_SCORCH2,
  102. "SC2",
  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 Scorch3 (
  109. SMUDGE_SCORCH3,
  110. "SC3",
  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 Scorch4 (
  117. SMUDGE_SCORCH4,
  118. "SC4",
  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 Scorch5 (
  125. SMUDGE_SCORCH5,
  126. "SC5",
  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 Scorch6 (
  133. SMUDGE_SCORCH6,
  134. "SC6",
  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 Bibx1 (
  141. SMUDGE_BIB1,
  142. "BIB1",
  143. TXT_BIB,
  144. 4,2, // Width and height of smudge (in icons).
  145. true, // Is this a building bib?
  146. false // Is this a crater smudge?
  147. );
  148. static SmudgeTypeClass const Bibx2 (
  149. SMUDGE_BIB2,
  150. "BIB2",
  151. TXT_BIB,
  152. 3,2, // Width and height of smudge (in icons).
  153. true, // Is this a building bib?
  154. false // Is this a crater smudge?
  155. );
  156. /*
  157. ** The watcom code optimiser screws up the last constructor call. Making it 'volatile' reduces the
  158. ** level of optimisation enough for the problem not to manifest.
  159. */
  160. volatile 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. ** Working array to the smudge control objects types. This routine is
  170. ** used for quick conversion from a SmudgeType number into an actual
  171. ** smudge type object pointer.
  172. */
  173. SmudgeTypeClass const * const SmudgeTypeClass::Pointers[SMUDGE_COUNT] = {
  174. &Crater1, // SMUDGE_CRATER1
  175. &Crater2, // SMUDGE_CRATER2
  176. &Crater3, // SMUDGE_CRATER3
  177. &Crater4, // SMUDGE_CRATER4
  178. &Crater5, // SMUDGE_CRATER5
  179. &Crater6, // SMUDGE_CRATER6
  180. &Scorch1, // SMUDGE_SCORCH1
  181. &Scorch2, // SMUDGE_SCORCH2
  182. &Scorch3, // SMUDGE_SCORCH3
  183. &Scorch4, // SMUDGE_SCORCH4
  184. &Scorch5, // SMUDGE_SCORCH5
  185. &Scorch6, // SMUDGE_SCORCH6
  186. &Bibx1, // SMUDGE_BIB1
  187. &Bibx2, // SMUDGE_BIB2
  188. (SmudgeTypeClass const * const)&Bibx3 // SMUDGE_BIB3
  189. };
  190. /***********************************************************************************************
  191. * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects. *
  192. * *
  193. * This constructor is used to create the smudge type objects. These type objects contain *
  194. * static information about the various smudge types supported in the game. *
  195. * *
  196. * INPUT: see below... *
  197. * *
  198. * OUTPUT: none *
  199. * *
  200. * WARNINGS: none *
  201. * *
  202. * HISTORY: *
  203. * 08/12/1994 JLB : Created. *
  204. *=============================================================================================*/
  205. SmudgeTypeClass::SmudgeTypeClass(SmudgeType smudge, char const *ininame, int fullname, int width, int height, bool isbib, bool iscrater) :
  206. ObjectTypeClass(false, false, false, true, false, false, true, true, fullname, ininame, ARMOR_NONE, 0)
  207. {
  208. IsBib = isbib;
  209. Width = width;
  210. Height = height;
  211. IsCrater = iscrater;
  212. Type = smudge;
  213. }
  214. /***********************************************************************************************
  215. * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type. *
  216. * *
  217. * This converts an ASCII name into a smudge type number. This is typically necessary *
  218. * when processing scenario INI files and not used otherwise. *
  219. * *
  220. * INPUT: name -- Pointer to the name to convert. *
  221. * *
  222. * OUTPUT: Returns with the SmudgeType number that matches the name supplied. If no match *
  223. * was found, then SMUDGE_NONE is returned. *
  224. * *
  225. * WARNINGS: none *
  226. * *
  227. * HISTORY: *
  228. * 08/12/1994 JLB : Created. *
  229. *=============================================================================================*/
  230. SmudgeType SmudgeTypeClass::From_Name(char const *name)
  231. {
  232. if (name) {
  233. for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
  234. if (stricmp(As_Reference(index).IniName, name) == 0) {
  235. return(index);
  236. }
  237. }
  238. }
  239. return(SMUDGE_NONE);
  240. }
  241. /***********************************************************************************************
  242. * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object. *
  243. * *
  244. * Smudges are always only one icon in dimension, so this routine always returns a cell *
  245. * occupation offset list of the center cell. *
  246. * *
  247. * INPUT: placement -- Is this for placement legality checking only? The normal condition *
  248. * is for marking occupation flags. *
  249. * *
  250. * OUTPUT: Returns occupation list specifying all the cells that the overlay occupies. This *
  251. * is just the center cell. *
  252. * *
  253. * WARNINGS: none *
  254. * *
  255. * HISTORY: *
  256. * 08/12/1994 JLB : Created. *
  257. *=============================================================================================*/
  258. short const * SmudgeTypeClass::Occupy_List(bool) const
  259. {
  260. static short _occupy[4*4];
  261. short * ptr = &_occupy[0];
  262. for (int x = 0; x < Width; x++) {
  263. for (int y = 0; y < Height; y++) {
  264. *ptr++ = x + (y*MAP_CELL_W);
  265. }
  266. }
  267. *ptr = REFRESH_EOL;
  268. return(_occupy);
  269. }
  270. /***********************************************************************************************
  271. * SmudgeTypeClass::Init -- Performs theater specific initializations. *
  272. * *
  273. * Smudge object imagery varies between theaters. This routine will load the appropriate *
  274. * imagery for the theater specified. *
  275. * *
  276. * INPUT: theater -- The theater to prepare for. *
  277. * *
  278. * OUTPUT: none *
  279. * *
  280. * WARNINGS: none *
  281. * *
  282. * HISTORY: *
  283. * 08/12/1994 JLB : Created. *
  284. *=============================================================================================*/
  285. void SmudgeTypeClass::Init(TheaterType theater)
  286. {
  287. if (theater != LastTheater){
  288. for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
  289. SmudgeTypeClass const & smudge = As_Reference(index);
  290. char fullname[_MAX_FNAME+_MAX_EXT]; // Fully constructed smudge data set name.
  291. _makepath(fullname, NULL, NULL, smudge.IniName, Theaters[theater].Suffix);
  292. ((void const *&)smudge.ImageData) = MixFileClass::Retrieve(fullname);
  293. }
  294. }
  295. }
  296. #ifdef SCENARIO_EDITOR
  297. /***********************************************************************************************
  298. * SmudgeTypeClass::Display -- Draws a generic version of this smudge type. *
  299. * *
  300. * The scenario object editor will call this routine to display a typical imagery of this *
  301. * smudge object for graphical identification purposes. *
  302. * *
  303. * INPUT: x,y -- Coordinate to render the smudge at. *
  304. * *
  305. * window-- The window to base the coordinate rendering upon. *
  306. * *
  307. * OUTPUT: none *
  308. * *
  309. * WARNINGS: none *
  310. * *
  311. * HISTORY: *
  312. * 08/12/1994 JLB : Created. *
  313. *=============================================================================================*/
  314. void SmudgeTypeClass::Display(int x, int y, WindowNumberType window, HousesType ) const
  315. {
  316. void const *ptr = Get_Image_Data();
  317. x += WindowList[window][WINDOWX] << 3;
  318. y += WindowList[window][WINDOWY];
  319. if (ptr) {
  320. for (int w = 0; w < Width; w++) {
  321. for (int h = 0; h < Height; h++) {
  322. CC_Draw_Shape(ptr, 0, x + w*ICON_PIXEL_W, y + h*ICON_PIXEL_H, WINDOW_TACTICAL, SHAPE_WIN_REL);
  323. //LogicPage->Draw_Stamp(ptr, w + (h*Width), x + w*ICON_PIXEL_W, y + h*ICON_PIXEL_H, NULL, WINDOW_TACTICAL);
  324. }
  325. }
  326. }
  327. }
  328. /***********************************************************************************************
  329. * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. *
  330. * *
  331. * This routine adds smudge objects to the list of objects that the scenario editor can *
  332. * place upon the ground. It is only called from the scenario editor. *
  333. * *
  334. * INPUT: none *
  335. * *
  336. * OUTPUT: none *
  337. * *
  338. * WARNINGS: none *
  339. * *
  340. * HISTORY: *
  341. * 08/12/1994 JLB : Created. *
  342. *=============================================================================================*/
  343. void SmudgeTypeClass::Prep_For_Add(void)
  344. {
  345. for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
  346. if (As_Reference(index).Get_Image_Data()) {
  347. Map.Add_To_List(&As_Reference(index));
  348. }
  349. }
  350. }
  351. #endif
  352. /***********************************************************************************************
  353. * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object. *
  354. * *
  355. * This routine will, in one motion, create a smudge object and place it upon the map. *
  356. * Since placing a smudge on the map will destroy the object, this routine will leave the *
  357. * smudge object count unchanged. Typically, this routine is used by the scenario editor *
  358. * for creating smudges and placing them on the map. *
  359. * *
  360. * INPUT: cell -- The cell to place the smudge object. *
  361. * *
  362. * OUTPUT: bool; Was the placement successful? *
  363. * *
  364. * WARNINGS: none *
  365. * *
  366. * HISTORY: *
  367. * 08/12/1994 JLB : Created. *
  368. *=============================================================================================*/
  369. bool SmudgeTypeClass::Create_And_Place(CELL cell, HousesType ) const
  370. {
  371. if (new SmudgeClass(Type, Cell_Coord(cell))) {
  372. return(true);
  373. }
  374. return(false);
  375. }
  376. /***********************************************************************************************
  377. * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type. *
  378. * *
  379. * This routine will create a smudge object of the appropriate type. Smudge objects are *
  380. * transitory in nature. They exist only from the point of creation until they are given *
  381. * a spot on the map to reside. At that time the map data is updated and the smudge *
  382. * object is destroyed. *
  383. * *
  384. * INPUT: none *
  385. * *
  386. * OUTPUT: Returns with a pointer to a created smudge object. If none could be created, then *
  387. * NULL is returned. *
  388. * *
  389. * WARNINGS: none *
  390. * *
  391. * HISTORY: *
  392. * 08/12/1994 JLB : Created. *
  393. *=============================================================================================*/
  394. ObjectClass * SmudgeTypeClass::Create_One_Of(HouseClass *) const
  395. {
  396. return(new SmudgeClass(Type, -1));
  397. }
  398. /***********************************************************************************************
  399. * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified. *
  400. * *
  401. * This routine will draw the smudge overlay image at the coordinate (upper left) *
  402. * specified. The underlying terrain icon is presumed to have already been rendered. *
  403. * *
  404. * INPUT: x,y -- Coordinate of the upper left corner of icon to render the smudge object. *
  405. * *
  406. * OUTPUT: none *
  407. * *
  408. * WARNINGS: none *
  409. * *
  410. * HISTORY: *
  411. * 08/12/1994 JLB : Created. *
  412. *=============================================================================================*/
  413. void SmudgeTypeClass::Draw_It(int x, int y, int data) const
  414. {
  415. void const * ptr = Get_Image_Data();
  416. if (ptr) {
  417. IsTheaterShape = true; // Smudges are theater specific
  418. CC_Draw_Shape(ptr, data, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  419. IsTheaterShape = false;
  420. // LogicPage->Draw_Stamp(ptr, data, x, y, NULL, WINDOW_TACTICAL);
  421. }
  422. }
  423. /***********************************************************************************************
  424. * SmudgeTypeClass::One_Time -- Performs one-time initialization *
  425. * *
  426. * INPUT: none *
  427. * *
  428. * OUTPUT: none *
  429. * *
  430. * WARNINGS: none *
  431. * *
  432. * HISTORY: *
  433. * 08/12/1994 JLB : Created. *
  434. *=============================================================================================*/
  435. void SmudgeTypeClass::One_Time(void)
  436. {
  437. }