SDATA.CPP 25 KB

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