TDATA.CPP 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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/TDATA.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 : TDATA.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : May 2, 1994 *
  26. * *
  27. * Last Update : July 19, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * TerrainTypeClass::As_Reference -- Fetches a reference to the terrain type object specified*
  32. * TerrainTypeClass::Create_And_Place -- Creates and places terrain object on map. *
  33. * TerrainTypeClass::Create_On_Of -- Creates a terrain object from type. *
  34. * TerrainTypeClass::Display -- Display a generic terrain object. *
  35. * TerrainTypeClass::From_Name -- Convert name to terrain type. *
  36. * TerrainTypeClass::Init -- Loads terrain object shape files. *
  37. * TerrainTypeClass::Init_Heap -- Initialize the terrain object heap. *
  38. * TerrainTypeClass::Occupy_List -- Returns with the occupy list for the terrain object type.*
  39. * TerrainTypeClass::One_Time -- Performs any special one time processing for terrain types. *
  40. * TerrainTypeClass::Overlap_List -- Fetches the overlap list for the terrain type. *
  41. * TerrainTypeClass::Prep_For_Add -- Prepares to add terrain object. *
  42. * TerrainTypeClass::TerrainTypeClass -- The general constructor for the terrain type objects*
  43. * TerrainTypeClass::operator delete -- Returns a terrain type object back to the mem pool. *
  44. * TerrainTypeClass::operator new -- Allocates a terrain type object from special pool. *
  45. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  46. #include "function.h"
  47. #include "terrain.h"
  48. #include "type.h"
  49. static short const _List000011101000[] = {MAP_CELL_W, MAP_CELL_W+1, MAP_CELL_W+2, MAP_CELL_W*2, REFRESH_EOL};
  50. static short const _List000110[] = {MAP_CELL_W, MAP_CELL_W+1, REFRESH_EOL};
  51. static short const _List001011100110[] = {2, MAP_CELL_W, MAP_CELL_W+1, MAP_CELL_W+2, MAP_CELL_W*2+1, MAP_CELL_W*2+2, REFRESH_EOL};
  52. static short const _List0010[] = {MAP_CELL_W, REFRESH_EOL};
  53. static short const _List0011[] = {MAP_CELL_W, MAP_CELL_W+1, REFRESH_EOL};
  54. static short const _List001[] = {2, REFRESH_EOL};
  55. static short const _List010110[] = {1, MAP_CELL_W, MAP_CELL_W+1, REFRESH_EOL};
  56. static short const _List01[] = {1, REFRESH_EOL};
  57. static short const _List11[] = {0, 1, REFRESH_EOL};
  58. static short const _List1001[] = {0, MAP_CELL_W+1, REFRESH_EOL};
  59. static short const _List1010[] = {0, MAP_CELL_W, REFRESH_EOL};
  60. static short const _List101001[] = {0, 2, MAP_CELL_W+2, REFRESH_EOL};
  61. static short const _List10[] = {0, REFRESH_EOL};
  62. static short const _List110000011001[] = {0, 1, MAP_CELL_W+3, MAP_CELL_W*2, MAP_CELL_W*2+3, REFRESH_EOL};
  63. static short const _List110001[] = {0, 1, MAP_CELL_W+2, REFRESH_EOL};
  64. static short const _List1100[] = {0, 1, REFRESH_EOL};
  65. static short const _List110110[] = {0, 1, MAP_CELL_W, MAP_CELL_W+1, REFRESH_EOL};
  66. static short const _List1101[] = {0, 1, MAP_CELL_W+1, REFRESH_EOL};
  67. static short const _List1111[] = {0, 1, MAP_CELL_W, MAP_CELL_W+1, REFRESH_EOL};
  68. static short const _List111000010110[] = {0, 1, 2, MAP_CELL_W+3, MAP_CELL_W*2+1, MAP_CELL_W*2+2, REFRESH_EOL};
  69. static TerrainTypeClass const Mine(
  70. TERRAIN_MINE,
  71. THEATERF_TEMPERATE|THEATERF_SNOW,
  72. XYP_COORD(12,24), // Center base coordinate offset.
  73. true, // Is it immune to normal combat damage?
  74. false, // Is based on the water?
  75. "MINE",
  76. TXT_ORE_MINE,
  77. (short const *)_List10,
  78. NULL
  79. );
  80. static TerrainTypeClass const Boxes01(
  81. TERRAIN_BOXES01,
  82. THEATERF_INTERIOR,
  83. XYP_COORD(12,24), // Center base coordinate offset.
  84. true, // Is it immune to normal combat damage?
  85. false, // Is based on the water?
  86. "BOXES01",
  87. TXT_CRATES,
  88. (short const *)_List10,
  89. NULL
  90. );
  91. static TerrainTypeClass const Boxes02(
  92. TERRAIN_BOXES02,
  93. THEATERF_INTERIOR,
  94. XYP_COORD(12,24), // Center base coordinate offset.
  95. true, // Is it immune to normal combat damage?
  96. false, // Is based on the water?
  97. "BOXES02",
  98. TXT_CRATES,
  99. (short const *)_List10,
  100. NULL
  101. );
  102. static TerrainTypeClass const Boxes03(
  103. TERRAIN_BOXES03,
  104. THEATERF_INTERIOR,
  105. XYP_COORD(12,24), // Center base coordinate offset.
  106. true, // Is it immune to normal combat damage?
  107. false, // Is based on the water?
  108. "BOXES03",
  109. TXT_CRATES,
  110. (short const *)_List10,
  111. NULL
  112. );
  113. static TerrainTypeClass const Boxes04(
  114. TERRAIN_BOXES04,
  115. THEATERF_INTERIOR,
  116. XYP_COORD(12,24), // Center base coordinate offset.
  117. true, // Is it immune to normal combat damage?
  118. false, // Is based on the water?
  119. "BOXES04",
  120. TXT_CRATES,
  121. (short const *)_List10,
  122. NULL
  123. );
  124. static TerrainTypeClass const Boxes05(
  125. TERRAIN_BOXES05,
  126. THEATERF_INTERIOR,
  127. XYP_COORD(12,24), // Center base coordinate offset.
  128. true, // Is it immune to normal combat damage?
  129. false, // Is based on the water?
  130. "BOXES05",
  131. TXT_CRATES,
  132. (short const *)_List10,
  133. NULL
  134. );
  135. static TerrainTypeClass const Boxes06(
  136. TERRAIN_BOXES06,
  137. THEATERF_INTERIOR,
  138. XYP_COORD(12,24), // Center base coordinate offset.
  139. true, // Is it immune to normal combat damage?
  140. false, // Is based on the water?
  141. "BOXES06",
  142. TXT_CRATES,
  143. (short const *)_List10,
  144. NULL
  145. );
  146. static TerrainTypeClass const Boxes07(
  147. TERRAIN_BOXES07,
  148. THEATERF_INTERIOR,
  149. XYP_COORD(12,24), // Center base coordinate offset.
  150. true, // Is it immune to normal combat damage?
  151. false, // Is based on the water?
  152. "BOXES07",
  153. TXT_CRATES,
  154. (short const *)_List10,
  155. NULL
  156. );
  157. static TerrainTypeClass const Boxes08(
  158. TERRAIN_BOXES08,
  159. THEATERF_INTERIOR,
  160. XYP_COORD(12,24), // Center base coordinate offset.
  161. true, // Is it immune to normal combat damage?
  162. false, // Is based on the water?
  163. "BOXES08",
  164. TXT_CRATES,
  165. (short const *)_List10,
  166. NULL
  167. );
  168. static TerrainTypeClass const Boxes09(
  169. TERRAIN_BOXES09,
  170. THEATERF_INTERIOR,
  171. XYP_COORD(12,24), // Center base coordinate offset.
  172. true, // Is it immune to normal combat damage?
  173. false, // Is based on the water?
  174. "BOXES09",
  175. TXT_CRATES,
  176. (short const *)_List10,
  177. NULL
  178. );
  179. static TerrainTypeClass const Ice01(
  180. TERRAIN_ICE01,
  181. THEATERF_SNOW,
  182. XYP_COORD(24,24), // Center base coordinate offset.
  183. true, // Is it immune to normal combat damage?
  184. true, // Is based on the water?
  185. "ICE01",
  186. TXT_ICE,
  187. (short const *)_List1111,
  188. NULL
  189. );
  190. static TerrainTypeClass const Ice02(
  191. TERRAIN_ICE02,
  192. THEATERF_SNOW,
  193. XYP_COORD(12,24), // Center base coordinate offset.
  194. true, // Is it immune to normal combat damage?
  195. true, // Is based on the water?
  196. "ICE02",
  197. TXT_ICE,
  198. (short const *)_List1010,
  199. NULL
  200. );
  201. static TerrainTypeClass const Ice03(
  202. TERRAIN_ICE03,
  203. THEATERF_SNOW,
  204. XYP_COORD(24,12), // Center base coordinate offset.
  205. true, // Is it immune to normal combat damage?
  206. true, // Is based on the water?
  207. "ICE03",
  208. TXT_ICE,
  209. (short const *)_List11,
  210. NULL
  211. );
  212. static TerrainTypeClass const Ice04(
  213. TERRAIN_ICE04,
  214. THEATERF_SNOW,
  215. XYP_COORD(12,12), // Center base coordinate offset.
  216. true, // Is it immune to normal combat damage?
  217. true, // Is based on the water?
  218. "ICE04",
  219. TXT_ICE,
  220. (short const *)_List10,
  221. NULL
  222. );
  223. static TerrainTypeClass const Ice05(
  224. TERRAIN_ICE05,
  225. THEATERF_SNOW,
  226. XYP_COORD(12,12), // Center base coordinate offset.
  227. true, // Is it immune to normal combat damage?
  228. true, // Is based on the water?
  229. "ICE05",
  230. TXT_ICE,
  231. (short const *)_List10,
  232. NULL
  233. );
  234. static TerrainTypeClass const Tree1Class(
  235. TERRAIN_TREE1,
  236. THEATERF_TEMPERATE|THEATERF_SNOW,
  237. XYP_COORD(11,41), // Center base coordinate offset.
  238. false, // Is it immune to normal combat damage?
  239. false, // Is based on the water?
  240. "T01",
  241. TXT_TREE,
  242. (short const *)_List0010,
  243. (short const *)_List1001
  244. );
  245. static TerrainTypeClass const Tree2Class(
  246. TERRAIN_TREE2,
  247. THEATERF_TEMPERATE|THEATERF_SNOW,
  248. XYP_COORD(11,44), // Center base coordinate offset.
  249. false, // Is it immune to normal combat damage?
  250. false, // Is based on the water?
  251. "T02",
  252. TXT_TREE,
  253. (short const *)_List0010,
  254. (short const *)_List1001
  255. );
  256. static TerrainTypeClass const Tree3Class(
  257. TERRAIN_TREE3,
  258. THEATERF_TEMPERATE|THEATERF_SNOW,
  259. XYP_COORD(12,45), // Center base coordinate offset.
  260. false, // Is it immune to normal combat damage?
  261. false, // Is based on the water?
  262. "T03",
  263. TXT_TREE,
  264. (short const *)_List0010,
  265. (short const *)_List1001
  266. );
  267. static TerrainTypeClass const Tree5Class(
  268. TERRAIN_TREE5,
  269. THEATERF_TEMPERATE|THEATERF_SNOW,
  270. XYP_COORD(15,41), // Center base coordinate offset.
  271. false, // Is it immune to normal combat damage?
  272. false, // Is based on the water?
  273. "T05",
  274. TXT_TREE,
  275. (short const *)_List0010,
  276. (short const *)_List1001
  277. );
  278. static TerrainTypeClass const Tree6Class(
  279. TERRAIN_TREE6,
  280. THEATERF_TEMPERATE|THEATERF_SNOW,
  281. XYP_COORD(16,37), // Center base coordinate offset.
  282. false, // Is it immune to normal combat damage?
  283. false, // Is based on the water?
  284. "T06",
  285. TXT_TREE,
  286. (short const *)_List0010,
  287. (short const *)_List1001
  288. );
  289. static TerrainTypeClass const Tree7Class(
  290. TERRAIN_TREE7,
  291. THEATERF_TEMPERATE|THEATERF_SNOW,
  292. XYP_COORD(15,41), // Center base coordinate offset.
  293. false, // Is it immune to normal combat damage?
  294. false, // Is based on the water?
  295. "T07",
  296. TXT_TREE,
  297. (short const *)_List0010,
  298. (short const *)_List1001
  299. );
  300. static TerrainTypeClass const Tree8Class(
  301. TERRAIN_TREE8,
  302. THEATERF_TEMPERATE|THEATERF_SNOW,
  303. XYP_COORD(14,22), // Center base coordinate offset.
  304. false, // Is it immune to normal combat damage?
  305. false, // Is based on the water?
  306. "T08",
  307. TXT_TREE,
  308. (short const *)_List10,
  309. (short const *)_List01
  310. );
  311. static TerrainTypeClass const Tree10Class(
  312. TERRAIN_TREE10,
  313. THEATERF_TEMPERATE|THEATERF_SNOW,
  314. XYP_COORD(25,43), // Center base coordinate offset.
  315. false, // Is it immune to normal combat damage?
  316. false, // Is based on the water?
  317. "T10",
  318. TXT_TREE,
  319. (short const *)_List0011,
  320. (short const *)_List1100
  321. );
  322. static TerrainTypeClass const Tree11Class(
  323. TERRAIN_TREE11,
  324. THEATERF_TEMPERATE|THEATERF_SNOW,
  325. XYP_COORD(23,44), // Center base coordinate offset.
  326. false, // Is it immune to normal combat damage?
  327. false, // Is based on the water?
  328. "T11",
  329. TXT_TREE,
  330. (short const *)_List0011,
  331. (short const *)_List1100
  332. );
  333. static TerrainTypeClass const Tree12Class(
  334. TERRAIN_TREE12,
  335. THEATERF_TEMPERATE|THEATERF_SNOW,
  336. XYP_COORD(14,36), // Center base coordinate offset.
  337. false, // Is it immune to normal combat damage?
  338. false, // Is based on the water?
  339. "T12",
  340. TXT_TREE,
  341. (short const *)_List0010,
  342. (short const *)_List1001
  343. );
  344. static TerrainTypeClass const Tree13Class(
  345. TERRAIN_TREE13,
  346. THEATERF_TEMPERATE|THEATERF_SNOW,
  347. XYP_COORD(19,40), // Center base coordinate offset.
  348. false, // Is it immune to normal combat damage?
  349. false, // Is based on the water?
  350. "T13",
  351. TXT_TREE,
  352. (short const *)_List0010,
  353. (short const *)_List1101
  354. );
  355. static TerrainTypeClass const Tree14Class(
  356. TERRAIN_TREE14,
  357. THEATERF_TEMPERATE|THEATERF_SNOW,
  358. XYP_COORD(19,40), // Center base coordinate offset.
  359. false, // Is it immune to normal combat damage?
  360. false, // Is based on the water?
  361. "T14",
  362. TXT_TREE,
  363. (short const *)_List0011,
  364. (short const *)_List1100
  365. );
  366. static TerrainTypeClass const Tree15Class(
  367. TERRAIN_TREE15,
  368. THEATERF_TEMPERATE|THEATERF_SNOW,
  369. XYP_COORD(19,40), // Center base coordinate offset.
  370. false, // Is it immune to normal combat damage?
  371. false, // Is based on the water?
  372. "T15",
  373. TXT_TREE,
  374. (short const *)_List0011,
  375. (short const *)_List1100
  376. );
  377. static TerrainTypeClass const Tree16Class(
  378. TERRAIN_TREE16,
  379. THEATERF_TEMPERATE|THEATERF_SNOW,
  380. XYP_COORD(13,36), // Center base coordinate offset.
  381. false, // Is it immune to normal combat damage?
  382. false, // Is based on the water?
  383. "T16",
  384. TXT_TREE,
  385. (short const *)_List0010,
  386. (short const *)_List1001
  387. );
  388. static TerrainTypeClass const Tree17Class(
  389. TERRAIN_TREE17,
  390. THEATERF_TEMPERATE|THEATERF_SNOW,
  391. XYP_COORD(18,44), // Center base coordinate offset.
  392. false, // Is it immune to normal combat damage?
  393. false, // Is based on the water?
  394. "T17",
  395. TXT_TREE,
  396. (short const *)_List0010,
  397. (short const *)_List1001
  398. );
  399. static TerrainTypeClass const Clump1Class(
  400. TERRAIN_CLUMP1,
  401. THEATERF_TEMPERATE|THEATERF_SNOW,
  402. XYP_COORD(28,41), // Center base coordinate offset.
  403. true, // Is it immune to normal combat damage?
  404. false, // Is based on the water?
  405. "TC01",
  406. TXT_TREE,
  407. (short const *)_List000110,
  408. (short const *)_List110001
  409. );
  410. static TerrainTypeClass const Clump2Class(
  411. TERRAIN_CLUMP2,
  412. THEATERF_TEMPERATE|THEATERF_SNOW,
  413. XYP_COORD(38,41), // Center base coordinate offset.
  414. true, // Is it immune to normal combat damage?
  415. false, // Is based on the water?
  416. "TC02",
  417. TXT_TREE,
  418. (short const *)_List010110,
  419. (short const *)_List101001
  420. );
  421. static TerrainTypeClass const Clump3Class(
  422. TERRAIN_CLUMP3,
  423. THEATERF_TEMPERATE|THEATERF_SNOW,
  424. XYP_COORD(33,35), // Center base coordinate offset.
  425. true, // Is it immune to normal combat damage?
  426. false, // Is based on the water?
  427. "TC03",
  428. TXT_TREE,
  429. (short const *)_List110110,
  430. (short const *)_List001
  431. );
  432. static TerrainTypeClass const Clump4Class(
  433. TERRAIN_CLUMP4,
  434. THEATERF_TEMPERATE|THEATERF_SNOW,
  435. XYP_COORD(44,49), // Center base coordinate offset.
  436. true, // Is it immune to normal combat damage?
  437. false, // Is based on the water?
  438. "TC04",
  439. TXT_TREE,
  440. (short const *)_List000011101000,
  441. (short const *)_List111000010110
  442. );
  443. static TerrainTypeClass const Clump5Class(
  444. TERRAIN_CLUMP5,
  445. THEATERF_TEMPERATE|THEATERF_SNOW,
  446. XYP_COORD(49,58), // Center base coordinate offset.
  447. true, // Is it immune to normal combat damage?
  448. false, // Is based on the water?
  449. "TC05",
  450. TXT_TREE,
  451. (short const *)_List001011100110,
  452. (short const *)_List110000011001
  453. );
  454. /***********************************************************************************************
  455. * TerrainTypeClass::TerrainTypeClass -- The general constructor for the terrain type objects. *
  456. * *
  457. * This is the constructor for terrain type objects. It is only used to construct the *
  458. * static (constant) terrain type objects. *
  459. * *
  460. * INPUT: see below.. *
  461. * *
  462. * OUTPUT: none *
  463. * *
  464. * WARNINGS: none *
  465. * *
  466. * HISTORY: *
  467. * 07/19/1994 JLB : Created. *
  468. *=============================================================================================*/
  469. TerrainTypeClass::TerrainTypeClass(
  470. TerrainType terrain,
  471. int theater,
  472. COORDINATE centerbase,
  473. bool is_immune,
  474. bool is_water,
  475. char const * ininame,
  476. int fullname,
  477. short const * occupy,
  478. short const * overlap) :
  479. ObjectTypeClass(RTTI_TERRAINTYPE,
  480. int(terrain),
  481. true,
  482. true,
  483. false,
  484. false,
  485. true,
  486. is_immune,
  487. true,
  488. fullname,
  489. ininame),
  490. Type(terrain),
  491. CenterBase(centerbase),
  492. Theater(theater),
  493. IsWaterBased(is_water),
  494. Occupy(occupy),
  495. Overlap(overlap)
  496. {
  497. MaxStrength = 800;
  498. Armor = ARMOR_WOOD;
  499. }
  500. /***********************************************************************************************
  501. * TerrainTypeClass::operator new -- Allocates a terrain type object from special pool. *
  502. * *
  503. * This routine will allocated a terrain type class object from the memory pool set up *
  504. * for that purpose. *
  505. * *
  506. * INPUT: none *
  507. * *
  508. * OUTPUT: Returns with a pointer to the freshly allocated terrain type object block. If *
  509. * there was insufficient memory, then NULL is returned. *
  510. * *
  511. * WARNINGS: none *
  512. * *
  513. * HISTORY: *
  514. * 07/19/1996 JLB : Created. *
  515. *=============================================================================================*/
  516. void * TerrainTypeClass::operator new(size_t)
  517. {
  518. return(TerrainTypes.Alloc());
  519. }
  520. /***********************************************************************************************
  521. * TerrainTypeClass::operator delete -- Returns a terrain type object back to the mem pool. *
  522. * *
  523. * This routine will return the supplied terrain type object back to the special memory *
  524. * pool for whence it was originally allocated. *
  525. * *
  526. * INPUT: pointer -- Pointer to the terrain type object to return to the memory pool. *
  527. * *
  528. * OUTPUT: none *
  529. * *
  530. * WARNINGS: none *
  531. * *
  532. * HISTORY: *
  533. * 07/19/1996 JLB : Created. *
  534. *=============================================================================================*/
  535. void TerrainTypeClass::operator delete(void * pointer)
  536. {
  537. TerrainTypes.Free((TerrainTypeClass *)pointer);
  538. }
  539. /***********************************************************************************************
  540. * TerrainTypeClass::Init_Heap -- Initialize the terrain object heap. *
  541. * *
  542. * This routine preallocates the terrain type objects in the memory pool. It must be called *
  543. * before the terrain type object data can be filled in. *
  544. * *
  545. * INPUT: none *
  546. * *
  547. * OUTPUT: none *
  548. * *
  549. * WARNINGS: This must be called only once and before the rules.ini file is processed. *
  550. * *
  551. * HISTORY: *
  552. * 07/19/1996 JLB : Created. *
  553. *=============================================================================================*/
  554. void TerrainTypeClass::Init_Heap(void)
  555. {
  556. /*
  557. ** These terrain type class objects must be allocated in the exact order that they
  558. ** are specified in the TerrainType enumeration. This is necessary because the heap
  559. ** allocation block index serves double duty as the type number index.
  560. */
  561. new TerrainTypeClass(Tree1Class); // TERRAIN_TREE1
  562. new TerrainTypeClass(Tree2Class); // TERRAIN_TREE2
  563. new TerrainTypeClass(Tree3Class); // TERRAIN_TREE3
  564. new TerrainTypeClass(Tree5Class); // TERRAIN_TREE5
  565. new TerrainTypeClass(Tree6Class); // TERRAIN_TREE6
  566. new TerrainTypeClass(Tree7Class); // TERRAIN_TREE7
  567. new TerrainTypeClass(Tree8Class); // TERRAIN_TREE8
  568. new TerrainTypeClass(Tree10Class); // TERRAIN_TREE10
  569. new TerrainTypeClass(Tree11Class); // TERRAIN_TREE11
  570. new TerrainTypeClass(Tree12Class); // TERRAIN_TREE12
  571. new TerrainTypeClass(Tree13Class); // TERRAIN_TREE13
  572. new TerrainTypeClass(Tree14Class); // TERRAIN_TREE14
  573. new TerrainTypeClass(Tree15Class); // TERRAIN_TREE15
  574. new TerrainTypeClass(Tree16Class); // TERRAIN_TREE16
  575. new TerrainTypeClass(Tree17Class); // TERRAIN_TREE17
  576. new TerrainTypeClass(Clump1Class); // TERRAIN_CLUMP1
  577. new TerrainTypeClass(Clump2Class); // TERRAIN_CLUMP2
  578. new TerrainTypeClass(Clump3Class); // TERRAIN_CLUMP3
  579. new TerrainTypeClass(Clump4Class); // TERRAIN_CLUMP4
  580. new TerrainTypeClass(Clump5Class); // TERRAIN_CLUMP5
  581. new TerrainTypeClass(Ice01); // TERRAIN_ICE01
  582. new TerrainTypeClass(Ice02); // TERRAIN_ICE02
  583. new TerrainTypeClass(Ice03); // TERRAIN_ICE03
  584. new TerrainTypeClass(Ice04); // TERRAIN_ICE04
  585. new TerrainTypeClass(Ice05); // TERRAIN_ICE05
  586. new TerrainTypeClass(Boxes01); // TERRAIN_BOXES01
  587. new TerrainTypeClass(Boxes02); // TERRAIN_BOXES02
  588. new TerrainTypeClass(Boxes03); // TERRAIN_BOXES03
  589. new TerrainTypeClass(Boxes04); // TERRAIN_BOXES04
  590. new TerrainTypeClass(Boxes05); // TERRAIN_BOXES05
  591. new TerrainTypeClass(Boxes06); // TERRAIN_BOXES06
  592. new TerrainTypeClass(Boxes07); // TERRAIN_BOXES07
  593. new TerrainTypeClass(Boxes08); // TERRAIN_BOXES08
  594. new TerrainTypeClass(Boxes09); // TERRAIN_BOXES09
  595. new TerrainTypeClass(Mine); // TERRAIN_MINE
  596. }
  597. /***********************************************************************************************
  598. * TerrainTypeClass::One_Time -- Performs any special one time processing for terrain types. *
  599. * *
  600. * This routine will perform any special one time processing needed for the terrain *
  601. * object types. Typically, this would load up artwork for terrain objects that have *
  602. * artwork independant of the theater they appear in. *
  603. * *
  604. * INPUT: none *
  605. * *
  606. * OUTPUT: none *
  607. * *
  608. * WARNINGS: none *
  609. * *
  610. * HISTORY: *
  611. * 07/19/1996 JLB : Created. *
  612. *=============================================================================================*/
  613. void TerrainTypeClass::One_Time(void)
  614. {
  615. }
  616. /***********************************************************************************************
  617. * TerrainTypeClass::Init -- Loads terrain object shape files. *
  618. * *
  619. * This routine is used to load up the terrain object shape files. *
  620. * The shape files loaded depends on theater. *
  621. * *
  622. * INPUT: theater -- The theater to load the terrain shape data for. *
  623. * *
  624. * OUTPUT: none *
  625. * *
  626. * WARNINGS: none *
  627. * *
  628. * HISTORY: *
  629. * 05/16/1994 JLB : Created. *
  630. *=============================================================================================*/
  631. void TerrainTypeClass::Init(TheaterType theater)
  632. {
  633. if (theater != LastTheater) {
  634. for (TerrainType index = TERRAIN_FIRST; index < TERRAIN_COUNT; index++) {
  635. TerrainTypeClass const & terrain = As_Reference(index);
  636. char fullname[_MAX_FNAME+_MAX_EXT];
  637. /*
  638. ** Clear any existing shape pointer. All terrain is theater specific, thus if
  639. ** it isn't loaded in this routine, it shouldn't exist at all.
  640. */
  641. ((void const *&)terrain.ImageData) = NULL;
  642. if (terrain.Theater & (1 << theater)) {
  643. /*
  644. ** Load in the appropriate object shape data.
  645. */
  646. _makepath(fullname, NULL, NULL, terrain.IniName, Theaters[theater].Suffix);
  647. ((void const *&)terrain.ImageData) = MFCD::Retrieve(fullname);
  648. IsTheaterShape = true; //Let Build_Frame know that this is a theater specific shape
  649. if (terrain.RadarIcon != NULL) delete[] (char *)terrain.RadarIcon;
  650. ((void const *&)terrain.RadarIcon) = Get_Radar_Icon(terrain.Get_Image_Data(), 0, 1, 3);
  651. IsTheaterShape = false;
  652. }
  653. }
  654. }
  655. }
  656. /***********************************************************************************************
  657. * TerrainTypeClass::From_Name -- Convert name to terrain type. *
  658. * *
  659. * This routine is used to convert a text name into the matching *
  660. * terrain type number. This is used during scenario initialization. *
  661. * *
  662. * INPUT: name -- The name to convert. *
  663. * *
  664. * OUTPUT: Returns the TerrainType that matches the name specified. If *
  665. * no match was found, then TERRAIN_NONE is returned. *
  666. * *
  667. * WARNINGS: none *
  668. * *
  669. * HISTORY: *
  670. * 05/16/1994 JLB : Created. *
  671. *=============================================================================================*/
  672. TerrainType TerrainTypeClass::From_Name(char const * name)
  673. {
  674. TerrainType index;
  675. if (name != NULL) {
  676. for (index = TERRAIN_FIRST; index < TERRAIN_COUNT; index++) {
  677. if (stricmp(name, As_Reference(index).IniName) == 0) {
  678. return(index);
  679. }
  680. }
  681. }
  682. return(TERRAIN_NONE);
  683. }
  684. #ifdef SCENARIO_EDITOR
  685. /***********************************************************************************************
  686. * TerrainTypeClass::Display -- Display a generic terrain object. *
  687. * *
  688. * This routine is used to display a generic terrain object. Typical *
  689. * use is during scenario editing. *
  690. * *
  691. * INPUT: x,y -- Pixel coordinates to display object at (centered). *
  692. * *
  693. * window-- The window to display the object within. *
  694. * *
  695. * OUTPUT: none *
  696. * *
  697. * WARNINGS: none *
  698. * *
  699. * HISTORY: *
  700. * 05/16/1994 JLB : Created. *
  701. *=============================================================================================*/
  702. void TerrainTypeClass::Display(int x, int y, WindowNumberType window, HousesType) const
  703. {
  704. IsTheaterShape = true;
  705. CC_Draw_Shape(Get_Image_Data(), 0, x, y, window, SHAPE_NORMAL|SHAPE_CENTER|SHAPE_WIN_REL);
  706. IsTheaterShape = false;
  707. }
  708. /***********************************************************************************************
  709. * TerrainTypeClass::Prep_For_Add -- Prepares to add terrain object. *
  710. * *
  711. * Submits all of the valid terrain objects to the scenario editor for possible selection *
  712. * and subsequent placement on the map. All terrain objects, that have a valid shape *
  713. * file available, are added. *
  714. * *
  715. * INPUT: none *
  716. * *
  717. * OUTPUT: none *
  718. * *
  719. * WARNINGS: none *
  720. * *
  721. * HISTORY: *
  722. * 05/23/1994 JLB : Created. *
  723. *=============================================================================================*/
  724. void TerrainTypeClass::Prep_For_Add(void)
  725. {
  726. for (TerrainType index = TERRAIN_FIRST; index < TERRAIN_COUNT; index++) {
  727. if (As_Reference(index).Get_Image_Data()) {
  728. Map.Add_To_List(&As_Reference(index));
  729. }
  730. }
  731. }
  732. #endif
  733. /***********************************************************************************************
  734. * TerrainTypeClass::Create_And_Place -- Creates and places terrain object on map. *
  735. * *
  736. * This support routine is used by the scenario editor to add a terrain object to the map. *
  737. * *
  738. * INPUT: cell -- The cell to place the terrain object in. *
  739. * *
  740. * OUTPUT: bool; Was the placement successful? *
  741. * *
  742. * WARNINGS: none *
  743. * *
  744. * HISTORY: *
  745. * 05/28/1994 JLB : Created. *
  746. *=============================================================================================*/
  747. bool TerrainTypeClass::Create_And_Place(CELL cell, HousesType ) const
  748. {
  749. if (new TerrainClass(Type, cell)) {
  750. return(true);
  751. }
  752. return(false);
  753. }
  754. /***********************************************************************************************
  755. * TerrainTypeClass::Create_On_Of -- Creates a terrain object from type. *
  756. * *
  757. * This is used to create a terrain object by using the terrain type as a guide. This *
  758. * routine is typically used by the scenario editor in order to place a terrain object *
  759. * onto the map. *
  760. * *
  761. * INPUT: none *
  762. * *
  763. * OUTPUT: Returns with a pointer to the created terrain object or NULL if one couldn't be *
  764. * created. *
  765. * *
  766. * WARNINGS: none *
  767. * *
  768. * HISTORY: *
  769. * 07/19/1994 JLB : Created. *
  770. *=============================================================================================*/
  771. ObjectClass * TerrainTypeClass::Create_One_Of(HouseClass *) const
  772. {
  773. return(new TerrainClass(Type, -1));
  774. }
  775. /***********************************************************************************************
  776. * TerrainTypeClass::Occupy_List -- Returns with the occupy list for the terrain object type. *
  777. * *
  778. * This routine will return with the occupy list for the terrain object type. If there is *
  779. * no occupy list for this terrain object type, then a special zero length occupy list *
  780. * pointer is returned. *
  781. * *
  782. * INPUT: none *
  783. * *
  784. * OUTPUT: Returns with a pointer to the terrain object's occupy list. A zero length list is *
  785. * returned in the case of no occupy list. *
  786. * *
  787. * WARNINGS: none *
  788. * *
  789. * HISTORY: *
  790. * 09/20/1995 JLB : Created. *
  791. *=============================================================================================*/
  792. short const * TerrainTypeClass::Occupy_List(bool ) const
  793. {
  794. if (Occupy != NULL) return(Occupy);
  795. static short const _simple[1] = {
  796. REFRESH_EOL
  797. };
  798. return(&_simple[0]);
  799. }
  800. /***********************************************************************************************
  801. * TerrainTypeClass::Overlap_List -- Fetches the overlap list for the terrain type. *
  802. * *
  803. * This routine will return with the overlap list for the terrain object type. If there *
  804. * is no overlap list for the terrain object, then a null length list is returned in order *
  805. * to ensure that a non-null pointer is returned. *
  806. * *
  807. * INPUT: none *
  808. * *
  809. * OUTPUT: Returns with a pointer to the overlap list for this object type. A special zero *
  810. * length list pointer is returned if there is no overlap list associated with the *
  811. * object type. *
  812. * *
  813. * WARNINGS: none *
  814. * *
  815. * HISTORY: *
  816. * 09/20/1995 JLB : Created. *
  817. *=============================================================================================*/
  818. short const * TerrainTypeClass::Overlap_List(void) const
  819. {
  820. if (Overlap != NULL) return(Overlap);
  821. static short const _simple[1] = {
  822. REFRESH_EOL
  823. };
  824. return(&_simple[0]);
  825. }
  826. /***********************************************************************************************
  827. * TerrainTypeClass::As_Reference -- Fetches a reference to the terrain type object specified. *
  828. * *
  829. * Use this routine to convert the terrain type number into a reference to a terrain *
  830. * type class object. *
  831. * *
  832. * INPUT: type -- The terrain type number to convert. *
  833. * *
  834. * OUTPUT: Returns with a reference to the terrain type class object that is referred to by *
  835. * the terrain type number. *
  836. * *
  837. * WARNINGS: Be sure that the terrain type number is valid. Using an invalid value causes *
  838. * undefined behavior. *
  839. * *
  840. * HISTORY: *
  841. * 07/19/1996 JLB : Created. *
  842. *=============================================================================================*/
  843. TerrainTypeClass & TerrainTypeClass::As_Reference(TerrainType type)
  844. {
  845. return(*TerrainTypes.Ptr(type));
  846. }
  847. COORDINATE TerrainTypeClass::Coord_Fixup(COORDINATE coord) const
  848. {
  849. return Coord_Whole(coord);
  850. }