CELL.CPP 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  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\cell.cpv 2.18 16 Oct 1995 16:49:20 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 : CELL.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 29, 1994 *
  30. * *
  31. * Last Update : August 17, 1995 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * CellClass::Adjacent_Cell -- Determines the adjacent cell according to facing. *
  36. * CellClass::Adjust_Threat -- Allows adjustment of threat at cell level *
  37. * CellClass::CellClass -- Constructor for cell objects. *
  38. * CellClass::Cell_Building -- Return with building at specified cell. *
  39. * CellClass::Cell_Color -- Determine what radar color to use for this cell. *
  40. * CellClass::Cell_Coord -- Returns the coordinate of this cell. *
  41. * CellClass::Cell_Find_Object -- Returns ptr to RTTI type occupying cell *
  42. * CellClass::Cell_Infantry -- Returns with pointer of first infantry unit. *
  43. * CellClass::Cell_Object -- Returns with clickable object in cell. *
  44. * CellClass::Cell_Techno -- Return with the unit/building at specified cell. *
  45. * CellClass::Cell_Terrain -- Determines terrain object in cell. *
  46. * CellClass::Cell_Unit -- Returns with pointer to unit occupying cell. *
  47. * CellClass::Clear_Icon -- Calculates what the clear icon number should be. *
  48. * CellClass::Closest_Free_Spot -- returns free spot closest to given coord *
  49. * CellClass::Concrete_Calc -- Calculates the concrete icon to use for the cell. *
  50. * CellClass::Draw_It -- Draws the cell imagery at the location specified. *
  51. * CellClass::Flag_Place -- Places a house flag down on the cell. *
  52. * CellClass::Flag_Remove -- Removes the house flag from the cell. *
  53. * CellClass::Cell_Occupier -- Fetches the occupier for the cell. *
  54. * CellClass::Get_Trigger -- retrieves reference to the cell's trigger *
  55. * CellClass::Goodie_Check -- Performs crate discovery logic. *
  56. * CellClass::Incoming -- Causes objects in cell to "run for cover". *
  57. * CellClass::Is_Generally_Clear -- Determines if cell can be built upon. *
  58. * CellClass::Occupy_Down -- Flag occupation of specified cell. *
  59. * CellClass::Occupy_Unit -- Marks cell as unit occupied. *
  60. * CellClass::Occupy_Up -- Removes occupation flag from the specified cell. *
  61. * CellClass::Overlap_Down -- This routine is used to mark a cell as being spilled over (overla*
  62. * CellClass::Overlap_Unit -- Marks cell as being overlapped by unit. *
  63. * CellClass::Overlap_Up -- Removes overlap flag for the cell. *
  64. * CellClass::Read -- Reads a particular cell value from a save game file. *
  65. * CellClass::Recalc_Attributes -- Recalculates the ground type attributes for the cell. *
  66. * CellClass::Redraw_Objects -- Redraws all objects overlapping this cell. *
  67. * CellClass::Reduce_Tiberium -- Reduces the tiberium in the cell by the amount specified. *
  68. * CellClass::Reduce_Wall -- Damages a wall, if damage is high enough. *
  69. * CellClass::Reserve_Cell -- Marks a cell as being occupied by the specified unit ID. *
  70. * CellClass::Shimmer -- Causes all objects in the cell to shimmer. *
  71. * CellClass::Spot_Index -- returns cell sub-coord index for given COORD *
  72. * CellClass::Tiberium_Adjust -- Adjust the look of the Tiberium for smooth. *
  73. * CellClass::Validate -- validates cell's number *
  74. * CellClass::Wall_Update -- Updates the imagery for wall objects in cell. *
  75. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  76. #include "function.h"
  77. #define FIXUP 0
  78. /***********************************************************************************************
  79. * CellClass::Validate -- validates cell's number *
  80. * *
  81. * INPUT: *
  82. * none. *
  83. * *
  84. * OUTPUT: *
  85. * 1 = ok, 0 = error *
  86. * *
  87. * WARNINGS: *
  88. * none. *
  89. * *
  90. * HISTORY: *
  91. * 08/09/1995 BRR : Created. *
  92. *=============================================================================================*/
  93. #ifdef CHEAT_KEYS
  94. int CellClass::Validate(void) const
  95. {
  96. int num;
  97. num = Cell_Number();
  98. if (num < 0 || num > 4095) {
  99. Validate_Error("CELL");
  100. return (0);
  101. }
  102. else
  103. return (1);
  104. }
  105. #else
  106. #define Validate()
  107. #endif
  108. /***********************************************************************************************
  109. * CellClass::CellClass -- Constructor for cell objects. *
  110. * *
  111. * A cell object is constructed into an empty state. It contains no specific objects, *
  112. * templates, or overlays. *
  113. * *
  114. * INPUT: none *
  115. * *
  116. * OUTPUT: none *
  117. * *
  118. * WARNINGS: none *
  119. * *
  120. * HISTORY: *
  121. * 08/09/1994 JLB : Created. *
  122. *=============================================================================================*/
  123. CellClass::CellClass(void)
  124. {
  125. memset(this, 0, sizeof(CellClass));
  126. Smudge = SMUDGE_NONE;
  127. Overlay = OVERLAY_NONE;
  128. Smudge = SMUDGE_NONE;
  129. TType = TEMPLATE_NONE;
  130. Owner = HOUSE_NONE;
  131. InfType = HOUSE_NONE;
  132. }
  133. /***********************************************************************************************
  134. * CellClass::Cell_Color -- Determine what radar color to use for this cell. *
  135. * *
  136. * Use this routine to determine what radar color to render a radar *
  137. * pixel with. This routine is called many many times to render the *
  138. * radar map, so it must be fast. *
  139. * *
  140. * INPUT: none *
  141. * *
  142. * OUTPUT: Returns with the color to display the radar pixel with. *
  143. * *
  144. * WARNINGS: none *
  145. * *
  146. * HISTORY: *
  147. * 03/01/1994 JLB : Created. *
  148. * 04/30/1994 JLB : Converted to member function. *
  149. * 05/31/1994 JLB : Takes into account any stealth characteristics of object. *
  150. *=============================================================================================*/
  151. int CellClass::Cell_Color(bool override) const
  152. {
  153. Validate();
  154. BuildingClass * object = Cell_Building();
  155. if (object) {
  156. return(object->House->Class->Color);
  157. }
  158. if (override) {
  159. return(TBLACK);
  160. }
  161. return(::Ground[Land_Type()].Color);
  162. }
  163. /***********************************************************************************************
  164. * CellClass::Cell_Techno -- Return with the unit/building at specified cell. *
  165. * *
  166. * Returns an object located in the cell. If there is a *
  167. * building present, it returns a pointer to that, otherwise it returns *
  168. * a pointer to one of the units there. If nothing is present in the *
  169. * specified cell, then it returns NULL. *
  170. * *
  171. * INPUT: x,y -- Coordinate offset (from upper left corner) to use as an aid in selecting *
  172. * the desired object within the cell. *
  173. * *
  174. * OUTPUT: Returns a pointer to a building or unit located in cell. If *
  175. * nothing present, just returns NULL. *
  176. * *
  177. * WARNINGS: none *
  178. * *
  179. * HISTORY: *
  180. * 08/05/1992 JLB : Created. *
  181. * 04/30/1994 JLB : Converted to member function. *
  182. *=============================================================================================*/
  183. TechnoClass * CellClass::Cell_Techno(int x, int y) const
  184. {
  185. Validate();
  186. ObjectClass * object;
  187. COORDINATE click; // Coordinate of click relative to cell corner.
  188. TechnoClass * close = NULL;
  189. long distance = 0; // Recorded closest distance.
  190. /*
  191. ** Create a coordinate value that represent the pixel location within the cell. This is
  192. ** actually the lower significant bits (leptons) of a regular coordinate value.
  193. */
  194. click = XY_Coord(Pixel_To_Lepton(x), Pixel_To_Lepton(y));
  195. if (Cell_Occupier()) {
  196. object = Cell_Occupier();
  197. while (object) {
  198. if (object->Is_Techno()) {
  199. COORDINATE coord; // Coordinate relative to cell corner.
  200. long dist;
  201. coord = object->Center_Coord() & 0x00FF00FFL;
  202. dist = Distance(coord, click);
  203. if (!close || dist < distance) {
  204. close = (TechnoClass *)object;
  205. distance = dist;
  206. }
  207. }
  208. object = object->Next;
  209. }
  210. }
  211. return(close);
  212. }
  213. /***************************************************************************
  214. * CellClass::Cell_Find_Object -- Returns ptr to RTTI type occupying cell *
  215. * *
  216. * INPUT: RTTIType the RTTI type we are searching for *
  217. * *
  218. * OUTPUT: none *
  219. * *
  220. * WARNINGS: none *
  221. * *
  222. * HISTORY: *
  223. * 03/17/1995 PWG : Created. *
  224. * 06/12/1995 JLB : Returns object class pointer. *
  225. *=========================================================================*/
  226. ObjectClass * CellClass::Cell_Find_Object(RTTIType rtti) const
  227. {
  228. Validate();
  229. ObjectClass * object = Cell_Occupier();
  230. while (object) {
  231. if (object->What_Am_I() == rtti) {
  232. return(object);
  233. }
  234. object = object->Next;
  235. }
  236. return(NULL);
  237. }
  238. /***********************************************************************************************
  239. * CellClass::Cell_Building -- Return with building at specified cell. *
  240. * *
  241. * Given a cell, determine if there is a building associated *
  242. * and return with a pointer to this building. *
  243. * *
  244. * INPUT: none *
  245. * *
  246. * OUTPUT: Returns with a pointer to the building associated with the *
  247. * cell. If there is no building associated, then NULL is *
  248. * returned. *
  249. * *
  250. * WARNINGS: none *
  251. * *
  252. * HISTORY: *
  253. * 08/05/1992 JLB : Created. *
  254. * 04/30/1994 JLB : Converted to member function. *
  255. *=============================================================================================*/
  256. BuildingClass * CellClass::Cell_Building(void) const
  257. {
  258. Validate();
  259. return((BuildingClass *)Cell_Find_Object(RTTI_BUILDING));
  260. }
  261. /***********************************************************************************************
  262. * CellClass::Cell_Terrain -- Determines terrain object in cell. *
  263. * *
  264. * This routine is used to determine the terrain object (if any) that *
  265. * overlaps this cell. *
  266. * *
  267. * INPUT: none *
  268. * *
  269. * OUTPUT: Returns with a pointer to the terrain object that overlaps *
  270. * this cell. If there is no terrain object present, then NULL *
  271. * is returned. *
  272. * *
  273. * WARNINGS: none *
  274. * *
  275. * HISTORY: *
  276. * 05/18/1994 JLB : Created. *
  277. *=============================================================================================*/
  278. TerrainClass * CellClass::Cell_Terrain(void) const
  279. {
  280. Validate();
  281. return((TerrainClass *)Cell_Find_Object(RTTI_TERRAIN));
  282. }
  283. /***********************************************************************************************
  284. * CellClass::Cell_Object -- Returns with clickable object in cell. *
  285. * *
  286. * This routine is used to determine which object is to be selected *
  287. * by a player click upon the cell. Not all objects that overlap the *
  288. * cell are selectable by the player. This routine sorts out which *
  289. * is which and returns with the appropriate object pointer. *
  290. * *
  291. * INPUT: x,y -- Coordinate (from upper left corner of cell) to use as a guide when *
  292. * selecting the object within the cell. This plays a role in those cases *
  293. * where several objects (such as infantry) exist within the same cell. *
  294. * *
  295. * OUTPUT: Returns with pointer to the object clickable within the *
  296. * cell. NULL is returned if there is no clickable object *
  297. * present. *
  298. * *
  299. * WARNINGS: none *
  300. * *
  301. * HISTORY: *
  302. * 05/13/1994 JLB : Created. *
  303. *=============================================================================================*/
  304. ObjectClass * CellClass::Cell_Object(int x, int y) const
  305. {
  306. Validate();
  307. ObjectClass * ptr;
  308. /*
  309. ** Hack so that aircraft landed on helipads can still be selected if directly
  310. ** clicked on.
  311. */
  312. ptr = (ObjectClass *)Cell_Find_Object(RTTI_AIRCRAFT);
  313. if (ptr) {
  314. return(ptr);
  315. }
  316. ptr = Cell_Techno(x, y);
  317. if (ptr) {
  318. return(ptr);
  319. }
  320. ptr = Cell_Terrain();
  321. if (ptr) return(ptr);
  322. return(ptr);
  323. }
  324. /***********************************************************************************************
  325. * CellClass::Redraw_Objects -- Redraws all objects overlapping this cell. *
  326. * *
  327. * This is a low level routine that marks all objects that overlap this *
  328. * cell to be redrawn. It is necessary to call this routine whenever *
  329. * the underlying icon has to be redrawn. *
  330. * *
  331. * INPUT: forced -- Should this redraw be forced even if flags *
  332. * indicate that it would be redundant? *
  333. * *
  334. * OUTPUT: none *
  335. * *
  336. * WARNINGS: none *
  337. * *
  338. * HISTORY: *
  339. * 05/18/1994 JLB : Created. *
  340. * 06/20/1994 JLB : Simplified to use object pointers. *
  341. * 12/24/1994 JLB : Only checks if cell is in view and not flagged already. *
  342. *=============================================================================================*/
  343. void CellClass::Redraw_Objects(bool forced)
  344. {
  345. Validate();
  346. CELL cell = Cell_Number();
  347. if (Map.In_View(cell) && (forced || !Map.Is_Cell_Flagged(cell))) {
  348. /*
  349. ** Flag the icon to be redrawn.
  350. */
  351. Map.Flag_Cell(cell);
  352. /*
  353. ** Flag the main object in the cell to be redrawn.
  354. */
  355. if (Cell_Occupier()) {
  356. ObjectClass * optr = Cell_Occupier();
  357. while (optr) {
  358. optr->Mark(MARK_CHANGE);
  359. optr = optr->Next;
  360. }
  361. }
  362. /*
  363. ** Flag any overlapping object in this cell to be redrawn.
  364. */
  365. for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  366. if (Overlapper[index]) {
  367. Overlapper[index]->Mark(MARK_CHANGE);
  368. }
  369. }
  370. }
  371. }
  372. /***********************************************************************************************
  373. * CellClass::Is_Generally_Clear -- Determines if cell can be built upon. *
  374. * *
  375. * This determines if the cell can become a proper foundation for *
  376. * building placement. *
  377. * *
  378. * INPUT: none *
  379. * *
  380. * OUTPUT: bool; Can the cell be built upon? *
  381. * *
  382. * WARNINGS: none *
  383. * *
  384. * HISTORY: *
  385. * 05/18/1994 JLB : Created. *
  386. *=============================================================================================*/
  387. bool CellClass::Is_Generally_Clear(void) const
  388. {
  389. Validate();
  390. if (ScenarioInit) return(true);
  391. if (Flag.Composite || IsFlagged || Cell_Occupier()) {
  392. return(false);
  393. }
  394. if (Smudge != SMUDGE_NONE && SmudgeTypeClass::As_Reference(Smudge).IsBib && Owner != HOUSE_NONE) {
  395. return(false);
  396. }
  397. if (Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(Overlay).IsWall) {
  398. return(false);
  399. }
  400. #ifdef ADVANCED
  401. /*
  402. ** Building certain kinds of terrain is prohibited -- bridges in particular.
  403. */
  404. switch (TType) {
  405. case TEMPLATE_BRIDGE1:
  406. case TEMPLATE_BRIDGE1D:
  407. case TEMPLATE_BRIDGE2:
  408. case TEMPLATE_BRIDGE2D:
  409. case TEMPLATE_BRIDGE3:
  410. case TEMPLATE_BRIDGE3D:
  411. case TEMPLATE_BRIDGE4:
  412. case TEMPLATE_BRIDGE4D:
  413. case TEMPLATE_FORD1:
  414. case TEMPLATE_FORD2:
  415. return(false);
  416. default:
  417. break;
  418. }
  419. #endif
  420. return(::Ground[Land_Type()].Build);
  421. }
  422. /***********************************************************************************************
  423. * CellClass::Recalc_Attributes -- Recalculates the ground type attributes for the cell. *
  424. * *
  425. * This routine recalculates the ground type in the cell. The speeds the find path *
  426. * algorithm and other determinations of the cell type. *
  427. * *
  428. * INPUT: none *
  429. * *
  430. * OUTPUT: none *
  431. * *
  432. * WARNINGS: none *
  433. * *
  434. * HISTORY: *
  435. * 05/29/1994 JLB : Created. *
  436. * 06/20/1994 JLB : Knows about template pointer in cell object. *
  437. *=============================================================================================*/
  438. void CellClass::Recalc_Attributes(void)
  439. {
  440. Validate();
  441. /*
  442. ** Check for wall effects.
  443. */
  444. if (Overlay != OVERLAY_NONE) {
  445. Land = OverlayTypeClass::As_Reference(Overlay).Land;
  446. if (Land != LAND_CLEAR) return;
  447. }
  448. /*
  449. ** If there is a template associated with this cell, then scan
  450. ** through the template exception list checking to see if this cell
  451. ** is one of the exception types. If it is, then return that ground type,
  452. ** otherwise return the template's default type.
  453. */
  454. if (TType != TEMPLATE_NONE) {
  455. TemplateTypeClass const *ttype = &TemplateTypeClass::As_Reference(TType);
  456. /*
  457. ** If there is an exception type list for the icons of this template, then
  458. ** find out if the current icon is one of them. If so, apply the exception
  459. ** ground type to the cell.
  460. */
  461. char const *ptr = ttype->AltIcons;
  462. if (ptr) {
  463. int icon = TIcon;
  464. while (*ptr != -1) {
  465. if (icon == *ptr++) {
  466. Land = ttype->AltLand;
  467. return;
  468. }
  469. }
  470. }
  471. /*
  472. ** No exception found, so just return the default ground type for this template.
  473. */
  474. Land = ttype->Land;
  475. return;
  476. }
  477. /*
  478. ** No template is the same as clear terrain.
  479. */
  480. Land = TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1).Land;
  481. }
  482. /***********************************************************************************************
  483. * CellClass::Occupy_Down -- Flag occupation of specified cell. *
  484. * *
  485. * This routine is used to mark the cell as being occupied by the specified object. *
  486. * *
  487. * INPUT: object -- The object that is to occupy the cell *
  488. * *
  489. * OUTPUT: none *
  490. * *
  491. * WARNINGS: none *
  492. * *
  493. * HISTORY: *
  494. * 07/18/1994 JLB : Created. *
  495. * 11/29/1994 JLB : Simplified. *
  496. *=============================================================================================*/
  497. void CellClass::Occupy_Down(ObjectClass * object)
  498. {
  499. Validate();
  500. ObjectClass * optr;
  501. /*
  502. ** If the specified object is already part of the occupation list, then don't add
  503. ** it again -- bail instead.
  504. */
  505. if (Cell_Occupier()) {
  506. optr = Cell_Occupier();
  507. while (optr) {
  508. if (optr == object) {
  509. return;
  510. }
  511. if (!optr->Next) break;
  512. optr = optr->Next;
  513. }
  514. }
  515. optr = Cell_Occupier();
  516. object->Next = optr;
  517. OccupierPtr = object;
  518. Map.Radar_Pixel(Cell_Number());
  519. /*
  520. ** If being placed down on a visible square, then flag this
  521. ** techno object as being revealed to the player.
  522. */
  523. if (IsVisible || GameToPlay != GAME_NORMAL) {
  524. object->Revealed(PlayerPtr);
  525. }
  526. /*
  527. ** Special occupy bit set.
  528. */
  529. switch (object->What_Am_I()) {
  530. case RTTI_BUILDING:
  531. Flag.Occupy.Building = true;
  532. break;
  533. case RTTI_AIRCRAFT:
  534. case RTTI_UNIT:
  535. Flag.Occupy.Vehicle = true;
  536. break;
  537. case RTTI_TERRAIN:
  538. Flag.Occupy.Monolith = true;
  539. break;
  540. default:
  541. break;
  542. }
  543. }
  544. /***********************************************************************************************
  545. * CellClass::Occupy_Up -- Removes occupation flag from the specified cell. *
  546. * *
  547. * This routine will lift the object from the cell and free the cell to be occupied by *
  548. * another object. Only if the cell was previously marked with the object specified, will *
  549. * the object be lifted off. This routine is the counterpart to Occupy_Down(). *
  550. * *
  551. * INPUT: object -- The object that is being lifted off. *
  552. * *
  553. * OUTPUT: none *
  554. * *
  555. * WARNINGS: none *
  556. * *
  557. * HISTORY: *
  558. * 07/18/1994 JLB : Created. *
  559. * 11/29/1994 JLB : Fixed to handle next pointer in previous object. *
  560. *=============================================================================================*/
  561. void CellClass::Occupy_Up(ObjectClass * object)
  562. {
  563. Validate();
  564. ObjectClass * optr = NULL; // Working pointer to the objects in the chain.
  565. if (Cell_Occupier()) {
  566. optr = Cell_Occupier();
  567. }
  568. if (optr == object) {
  569. OccupierPtr = object->Next;
  570. object->Next = 0;
  571. } else {
  572. while (optr) {
  573. if (optr->Next == object) {
  574. optr->Next = object->Next;
  575. object->Next = 0;
  576. break;
  577. }
  578. if (!optr->Next) break;
  579. optr = optr->Next;
  580. }
  581. }
  582. Map.Radar_Pixel(Cell_Number());
  583. /*
  584. ** Special occupy bit clear.
  585. */
  586. switch (object->What_Am_I()) {
  587. case RTTI_BUILDING:
  588. Flag.Occupy.Building = false;
  589. break;
  590. case RTTI_AIRCRAFT:
  591. case RTTI_UNIT:
  592. Flag.Occupy.Vehicle = false;
  593. #ifdef NEVER
  594. int x,y;
  595. if (Map.Coord_To_Pixel(Cell_Coord(), x, y)) {
  596. SeenBuff.Put_Pixel(x, y, BLUE);
  597. }
  598. #endif
  599. break;
  600. case RTTI_TERRAIN:
  601. Flag.Occupy.Monolith = false;
  602. break;
  603. default:
  604. break;
  605. }
  606. }
  607. /***********************************************************************************************
  608. * CellClass::Overlap_Down -- This routine is used to mark a cell as being spilled over (overla*
  609. * *
  610. * Most game objects can often have their graphic imagery spill into more than one cell *
  611. * even though they are considered to "occupy" only one cell. All cells overlapped are *
  612. * flagged by this routine. Using this information it is possible to keep the tactical map *
  613. * display correct. *
  614. * *
  615. * INPUT: object -- The object to mark as overlapping this cell. *
  616. * *
  617. * OUTPUT: none *
  618. * *
  619. * WARNINGS: none *
  620. * *
  621. * HISTORY: *
  622. * 07/18/1994 JLB : Created. *
  623. * 07/04/1995 JLB : Ensures that buildings are always marked down. *
  624. *=============================================================================================*/
  625. void CellClass::Overlap_Down(ObjectClass * object)
  626. {
  627. Validate();
  628. ObjectClass **ptr = 0;
  629. if (!object) return;
  630. for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  631. if (Overlapper[index] == object) return;
  632. if (!Overlapper[index]) ptr = &Overlapper[index];
  633. }
  634. /*
  635. ** Buildings must ALWAYS succeed in marking the cell as overlapped. Bump somebody
  636. ** else out in this case.
  637. */
  638. if (!ptr && object->What_Am_I() == RTTI_BUILDING) {
  639. for (index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  640. switch (Overlapper[index]->What_Am_I()) {
  641. case RTTI_BUILDING:
  642. case RTTI_TERRAIN:
  643. break;
  644. default:
  645. Overlapper[index] = object;
  646. index = sizeof(Overlapper)/sizeof(Overlapper[0]);
  647. break;
  648. }
  649. }
  650. }
  651. if (ptr) *ptr = object;
  652. /*
  653. ** If being placed down on a visible square, then flag this
  654. ** techno object as being revealed to the player.
  655. */
  656. if (IsVisible) {
  657. object->Revealed(PlayerPtr);
  658. }
  659. }
  660. /***********************************************************************************************
  661. * CellClass::Overlap_Up -- Removes overlap flag for the cell. *
  662. * *
  663. * This is the counterpart to Overlap_Down and is used to remove the overlap flag for the *
  664. * specified unit on the cell. *
  665. * *
  666. * INPUT: object -- The object to remove the overlap flag for. *
  667. * *
  668. * OUTPUT: none *
  669. * *
  670. * WARNINGS: none *
  671. * *
  672. * HISTORY: *
  673. * 07/18/1994 JLB : Created. *
  674. *=============================================================================================*/
  675. void CellClass::Overlap_Up(ObjectClass *object)
  676. {
  677. Validate();
  678. for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  679. if (Overlapper[index] == object) {
  680. Overlapper[index] = 0;
  681. break;
  682. }
  683. }
  684. }
  685. /***********************************************************************************************
  686. * CellClass::Cell_Unit -- Returns with pointer to unit occupying cell. *
  687. * *
  688. * This routine will determine if a unit is occupying the cell and if so, return a pointer *
  689. * to it. If there is no unit occupying the cell, then NULL is returned. *
  690. * *
  691. * INPUT: none *
  692. * *
  693. * OUTPUT: Returns with pointer to unit occupying cell, else NULL. *
  694. * *
  695. * WARNINGS: none *
  696. * *
  697. * HISTORY: *
  698. * 07/18/1994 JLB : Created. *
  699. *=============================================================================================*/
  700. UnitClass * CellClass::Cell_Unit(void) const
  701. {
  702. Validate();
  703. return((UnitClass*)Cell_Find_Object(RTTI_UNIT));
  704. }
  705. /***********************************************************************************************
  706. * CellClass::Cell_Infantry -- Returns with pointer of first infantry unit occupying the cell. *
  707. * *
  708. * This routine examines the cell and returns a pointer to the first infantry unit *
  709. * that occupies it. If there is no infantry unit in the cell, then NULL is returned. *
  710. * *
  711. * INPUT: none *
  712. * *
  713. * OUTPUT: Returns with pointer to infantry unit occupying the cell or NULL if none are *
  714. * present. *
  715. * *
  716. * WARNINGS: none *
  717. * *
  718. * HISTORY: *
  719. * 12/21/1994 JLB : Created. *
  720. *=============================================================================================*/
  721. InfantryClass * CellClass::Cell_Infantry(void) const
  722. {
  723. Validate();
  724. return((InfantryClass*)Cell_Find_Object(RTTI_INFANTRY));
  725. }
  726. /***********************************************************************************************
  727. * CellClass::Draw_It -- Draws the cell imagery at the location specified. *
  728. * *
  729. * This is the gruntwork cell rendering code. It draws the cell at the screen location *
  730. * specified. This routine doesn't draw any overlapping or occupying units. It only *
  731. * deals with the ground (cell) layer -- icon level. *
  732. * *
  733. * INPUT: x,y -- The screen coordinates to render the cell imagery at. *
  734. * *
  735. * OUTPUT: none *
  736. * *
  737. * WARNINGS: none *
  738. * *
  739. * HISTORY: *
  740. * 07/18/1994 JLB : Created. *
  741. * 08/21/1994 JLB : Revised for simple template objects. *
  742. * 11/01/1994 BRR : Updated placement cursor; draws actual object *
  743. * 11/14/1994 BRR : Added remapping code to show passable areas *
  744. * 12/02/1994 BRR : Added trigger display *
  745. * 12/11/1994 JLB : Mixes up clear terrain through pseudo-random table. *
  746. * 04/25/1995 JLB : Smudges drawn BELOW overlays. *
  747. *=============================================================================================*/
  748. void CellClass::Draw_It(int x, int y, int draw_type) const
  749. {
  750. Validate();
  751. TemplateTypeClass const *ttype = 0;
  752. int icon; // The icon number to use from the template set.
  753. CELL cell = Cell_Number();
  754. void * remap = NULL;
  755. #ifdef SCENARIO_EDITOR
  756. TemplateTypeClass * tptr;
  757. TriggerClass * trig;
  758. int i;
  759. char waypt[2];
  760. #endif
  761. /*
  762. ** Fetch a pointer to the template type associated with this cell.
  763. */
  764. if (TType != TEMPLATE_NONE) {
  765. ttype = &TemplateTypeClass::As_Reference(TType);
  766. icon = TIcon;
  767. } else {
  768. ttype = &TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1);
  769. icon = Clear_Icon();
  770. }
  771. /*
  772. ** Draw the stamp of the template.
  773. */
  774. if (Debug_Icon) {
  775. LogicPage->Fill_Rect(Map.TacPixelX+x, Map.TacPixelY+y, Map.TacPixelX+x+ICON_PIXEL_W-1, Map.TacPixelY+y+ICON_PIXEL_H-1, Sim_Random_Pick(1, 254));
  776. FontXSpacing -= 2;
  777. Fancy_Text_Print("%d\r%2X%c\r%02X.%02X", Map.TacPixelX+x+(ICON_PIXEL_W>>1), Map.TacPixelY+y, WHITE, TBLACK, TPF_6POINT|TPF_NOSHADOW|TPF_CENTER, cell, Flag.Composite, (Cell_Occupier() ? '*' : ' '), Overlay, OverlayData);
  778. FontXSpacing += 2;
  779. } else {
  780. if (!draw_type || draw_type == CELL_BLIT_ONLY){
  781. #ifdef SCENARIO_EDITOR
  782. /*
  783. ** Set up the remap table for this icon.
  784. */
  785. if (Debug_Map && Debug_Passable) {
  786. if (::Ground[Land].Cost[0] == 0 || (Cell_Occupier() != NULL &&
  787. Cell_Occupier()->What_Am_I() != RTTI_INFANTRY)) { // impassable
  788. remap = Map.FadingRed;
  789. } else {
  790. if (::Ground[Land].Cost[0] > 0x70) { // pretty passable
  791. remap = Map.FadingGreen;
  792. } else {
  793. remap = Map.FadingYellow; // moderately passable
  794. }
  795. }
  796. }
  797. #endif
  798. // ****** maybe this icon shouldn't be drawn if it is known that the cell will be covered
  799. // with shadow.
  800. /*
  801. ** This is the underlying terrain icon.
  802. */
  803. if (ttype->Get_Image_Data()) {
  804. LogicPage->Draw_Stamp(ttype->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
  805. if (remap) {
  806. LogicPage->Remap(x+Map.TacPixelX, y+Map.TacPixelY, ICON_PIXEL_W, ICON_PIXEL_H, remap);
  807. }
  808. }
  809. #ifdef SCENARIO_EDITOR
  810. /*
  811. ** Draw the map editor's "current" cell. This is the cell that can be
  812. ** assigned attributes such as tag labels.
  813. ** This must be draw before the placement cursor, but after drawing the
  814. ** objects in the cell.
  815. */
  816. if (Debug_Map && CurrentCell == Cell_Number()) {
  817. LogicPage->Draw_Rect(x+Map.TacPixelX, y+Map.TacPixelY, Map.TacPixelX + x + CELL_PIXEL_W - 1, Map.TacPixelY + y + CELL_PIXEL_H - 1, YELLOW);
  818. }
  819. #endif
  820. #ifdef NEVER
  821. /*
  822. ** Special concrete render. It always renders over the underlying
  823. ** terrain unless this concrete piece will cover the entire terrain
  824. ** piece.
  825. */
  826. if (Concrete) {
  827. LogicPage->Draw_Stamp(TemplateTypeClass::As_Pointer(TEMPLATE_CONCRETE_GDI)->Get_Image_Data(), Concrete-1, x, y, NULL, WINDOW_TACTICAL);
  828. }
  829. #endif
  830. }
  831. /*
  832. ** Redraw any smudge.
  833. */
  834. if (Smudge != SMUDGE_NONE) {
  835. #ifdef NEVER
  836. switch (Smudge) {
  837. case SMUDGE_BIB1:
  838. CC_Draw_Shape(Bib1, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  839. break;
  840. case SMUDGE_BIB2:
  841. CC_Draw_Shape(Bib2, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  842. break;
  843. case SMUDGE_BIB3:
  844. CC_Draw_Shape(Bib3, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  845. break;
  846. }
  847. #endif
  848. SmudgeTypeClass::As_Reference(Smudge).Draw_It(x, y, SmudgeData);
  849. }
  850. if (!draw_type || draw_type == CELL_DRAW_ONLY){
  851. /*
  852. ** Draw the overlay object.
  853. */
  854. if (Overlay != OVERLAY_NONE) {
  855. OverlayTypeClass const & otype = OverlayTypeClass::As_Reference(Overlay);
  856. IsTheaterShape = (bool)otype.IsTheater;
  857. CC_Draw_Shape(otype.Get_Image_Data(), OverlayData, (x+(CELL_PIXEL_W>>1)), (y+(CELL_PIXEL_H>>1)), WINDOW_TACTICAL, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_GHOST, NULL, Map.UnitShadow);
  858. IsTheaterShape = false;
  859. }
  860. #ifdef SCENARIO_EDITOR
  861. if (Debug_Map) {
  862. /*
  863. ** Draw the cell's Trigger mnemonic, if it has a trigger
  864. */
  865. if (IsTrigger) {
  866. trig = Get_Trigger();
  867. Fancy_Text_Print(trig->Get_Name(), x+Map.TacPixelX, y+Map.TacPixelY, PINK, TBLACK, TPF_NOSHADOW|TPF_6POINT);
  868. }
  869. /*
  870. ** Draw the cell's Waypoint designation if there is one.
  871. */
  872. if (IsWaypoint) {
  873. for (i = 0; i < 26; i++) {
  874. if (Waypoint[i]==Cell_Number()) {
  875. waypt[0] = 'A' + i;
  876. waypt[1] = 0;
  877. Fancy_Text_Print(waypt, Map.TacPixelX + x + CELL_PIXEL_W / 2,
  878. Map.TacPixelY + y + (CELL_PIXEL_H / 2) - 3, YELLOW, TBLACK,
  879. TPF_NOSHADOW | TPF_6POINT | TPF_CENTER);
  880. break;
  881. }
  882. }
  883. if (Waypoint[WAYPT_HOME] == Cell_Number()) {
  884. Fancy_Text_Print("Home", Map.TacPixelX + x, Map.TacPixelY + y + (CELL_PIXEL_H) - 7,
  885. WHITE, TBLACK, TPF_NOSHADOW | TPF_6POINT);
  886. }
  887. if (Waypoint[WAYPT_REINF] == Cell_Number()) {
  888. Fancy_Text_Print("Reinf", Map.TacPixelX + x, Map.TacPixelY + y + (CELL_PIXEL_H) - 7,
  889. WHITE, TBLACK, TPF_NOSHADOW | TPF_6POINT);
  890. }
  891. }
  892. }
  893. #endif
  894. /*
  895. ** Draw the placement cursor:
  896. ** - First, draw the hash-mark cursor, so it will appear underneath
  897. ** any cursor being drawn
  898. ** - If the PendingObject is a template, overlay, or smudge, draw it
  899. ** - Otherwise, it's up to the Display.Refresh_Map() routine to draw it
  900. */
  901. if (IsCursorHere) {
  902. /*
  903. ** Draw the hash-mark cursor:
  904. */
  905. if (Map.ProximityCheck && Is_Generally_Clear()) {
  906. LogicPage->Draw_Stamp(Map.TransIconset, 0, x, y, NULL, WINDOW_TACTICAL);
  907. } else {
  908. LogicPage->Draw_Stamp(Map.TransIconset, 2, x, y, NULL, WINDOW_TACTICAL);
  909. }
  910. #ifdef SCENARIO_EDITOR
  911. if (Debug_Map && Map.PendingObject) {
  912. switch (Map.PendingObject->What_Am_I()) {
  913. /*
  914. ** Draw a template:
  915. ** - Compute the icon offset of this cell for this template, using
  916. ** ZoneCell+ZoneOffset to get the upper-left corner of the placement
  917. ** cursor
  918. ** - Draw the icon
  919. */
  920. case RTTI_TEMPLATETYPE:
  921. tptr = (TemplateTypeClass *)Map.PendingObject;
  922. if (tptr->Get_Image_Data()) {
  923. icon = (Cell_X(cell) - Cell_X(Map.ZoneCell + Map.ZoneOffset)) +
  924. (Cell_Y(cell) - Cell_Y(Map.ZoneCell + Map.ZoneOffset)) *
  925. tptr->Width;
  926. LogicPage->Draw_Stamp(tptr->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
  927. }
  928. break;
  929. /*
  930. ** Draw an overlay; just use the existing 'OverlayData' even though
  931. ** it means nothing.
  932. */
  933. case RTTI_OVERLAYTYPE:
  934. OverlayTypeClass::As_Reference(((OverlayTypeClass *)Map.PendingObject)->Type).Draw_It(x, y, OverlayData);
  935. break;
  936. /*
  937. ** Draw a smudge
  938. */
  939. case RTTI_SMUDGETYPE:
  940. SmudgeTypeClass::As_Reference(((SmudgeTypeClass *)Map.PendingObject)->Type).Draw_It(x, y, 0);
  941. break;
  942. }
  943. }
  944. #endif
  945. }
  946. /*
  947. ** Draw the flag if there is one located at this cell.
  948. */
  949. if (IsFlagged) {
  950. void const * remap = HouseClass::As_Pointer(Owner)->Remap_Table(false, false);
  951. CC_Draw_Shape(MixFileClass::Retrieve("FLAGFLY.SHP"), Frame % 14, x+(ICON_PIXEL_W/2), y+(ICON_PIXEL_H/2), WINDOW_TACTICAL, SHAPE_CENTER|SHAPE_GHOST|SHAPE_FADING, remap, Map.UnitShadow);
  952. }
  953. }
  954. }
  955. }
  956. /***********************************************************************************************
  957. * CellClass::Concrete_Calc -- Calculates the concrete icon to use for the cell. *
  958. * *
  959. * This routine examines the cells around the current one and from this, determines what *
  960. * concrete icon shape to use (if any). The cell data is adjusted and the cell is marked *
  961. * for redraw if the icon changed. *
  962. * *
  963. * INPUT: none *
  964. * *
  965. * OUTPUT: none *
  966. * *
  967. * WARNINGS: none *
  968. * *
  969. * HISTORY: *
  970. * 08/01/1994 JLB : Created. *
  971. *=============================================================================================*/
  972. void CellClass::Concrete_Calc(void)
  973. {
  974. Validate();
  975. static FacingType _even[5] = {FACING_N, FACING_S, FACING_SW, FACING_W, FACING_NW};
  976. static FacingType _odd[5] = {FACING_N, FACING_NE, FACING_E, FACING_SE, FACING_S};
  977. FacingType *ptr; // Working pointer into adjacent cell list.
  978. int index; // Constructed bit index.
  979. int icon; // Icon number.
  980. bool isodd; // Is this for the odd column?
  981. #define OF_N 0x01
  982. #define OF_NE 0x02
  983. #define OF_E 0x04
  984. #define OF_SE 0x08
  985. #define OF_S 0x10
  986. #define EF_N 0x01
  987. #define EF_NW 0x10
  988. #define EF_W 0x08
  989. #define EF_SW 0x04
  990. #define EF_S 0x02
  991. /*
  992. ** Determine if the even or odd row logic is necessary.
  993. */
  994. isodd = ((Cell_Number() & 0x01) != 0);
  995. /*
  996. ** Fetch correct pointer depending on whether this is for an
  997. ** odd or even row.
  998. */
  999. ptr = (isodd) ? _odd : _even;
  1000. /*
  1001. ** Build an index according to the presence of concrete in the special
  1002. ** adjacent cells. This is a short list of adjacent cell flags since
  1003. ** only 5 adjacent cells need to be examined. The choice of which 5
  1004. ** depends on whether this is for an even or odd column.
  1005. */
  1006. index = 0;
  1007. for (int i = 0; i < (sizeof(_even)/sizeof(_even[0])); i++) {
  1008. CellClass & cellptr = Adjacent_Cell(*ptr++);
  1009. // if ((cellptr->IsConcrete) ||
  1010. // cellptr->Concrete == C_UPDOWN_RIGHT ||
  1011. // cellptr->Concrete == C_UPDOWN_LEFT) {
  1012. if (cellptr.Overlay == OVERLAY_CONCRETE) {
  1013. index |= (1<<i);
  1014. }
  1015. }
  1016. /*
  1017. ** Special logic occurs for cells that are concrete filled.
  1018. */
  1019. if (Overlay == OVERLAY_CONCRETE) {
  1020. /*
  1021. ** Process the index value and place the appropriate concrete icon
  1022. ** in the cell.
  1023. */
  1024. if (isodd) {
  1025. switch (index) {
  1026. case OF_NE:
  1027. case OF_N|OF_NE:
  1028. case OF_E|OF_N:
  1029. case OF_E|OF_NE:
  1030. case OF_N|OF_NE|OF_E:
  1031. case OF_S|OF_N|OF_NE:
  1032. icon = C_RIGHT_UP; // right - up
  1033. break;
  1034. case OF_SE:
  1035. case OF_E|OF_SE:
  1036. case OF_S|OF_SE:
  1037. case OF_S|OF_E:
  1038. case OF_S|OF_SE|OF_E:
  1039. case OF_S|OF_SE|OF_N:
  1040. icon = C_RIGHT_DOWN; // right - down
  1041. break;
  1042. case OF_SE|OF_NE:
  1043. case OF_SE|OF_NE|OF_N:
  1044. case OF_SE|OF_NE|OF_S:
  1045. case OF_SE|OF_NE|OF_S|OF_N:
  1046. case OF_SE|OF_E|OF_N:
  1047. case OF_SE|OF_E|OF_NE|OF_N:
  1048. case OF_S|OF_E|OF_N:
  1049. case OF_S|OF_E|OF_NE:
  1050. case OF_S|OF_E|OF_NE|OF_N:
  1051. case OF_S|OF_SE|OF_E|OF_N:
  1052. case OF_S|OF_SE|OF_E|OF_NE|OF_N:
  1053. case OF_S|OF_SE|OF_E|OF_NE:
  1054. icon = C_RIGHT_UPDOWN; // right - up - down
  1055. break;
  1056. default:
  1057. icon = C_RIGHT; // right
  1058. break;
  1059. }
  1060. } else {
  1061. switch (index) {
  1062. case EF_NW:
  1063. case EF_NW|EF_N:
  1064. case EF_W|EF_N:
  1065. case EF_NW|EF_W|EF_N:
  1066. case EF_NW|EF_W:
  1067. case EF_NW|EF_S|EF_N:
  1068. icon = C_LEFT_UP; // left - up
  1069. break;
  1070. case EF_SW:
  1071. case EF_SW|EF_S:
  1072. case EF_W|EF_S:
  1073. case EF_W|EF_SW|EF_S:
  1074. case EF_W|EF_SW:
  1075. case EF_SW|EF_S|EF_N:
  1076. icon = C_LEFT_DOWN; // left - down
  1077. break;
  1078. case EF_NW|EF_SW:
  1079. case EF_NW|EF_SW|EF_N:
  1080. case EF_NW|EF_SW|EF_S:
  1081. case EF_NW|EF_SW|EF_S|EF_N:
  1082. case EF_W|EF_S|EF_N:
  1083. case EF_W|EF_SW|EF_N:
  1084. case EF_W|EF_SW|EF_S|EF_N:
  1085. case EF_NW|EF_W|EF_S:
  1086. case EF_NW|EF_W|EF_S|EF_N:
  1087. case EF_NW|EF_W|EF_SW|EF_S|EF_N:
  1088. case EF_NW|EF_W|EF_SW|EF_N:
  1089. case EF_NW|EF_W|EF_SW|EF_S:
  1090. icon = C_LEFT_UPDOWN; // left - up - down
  1091. break;
  1092. default:
  1093. icon = C_LEFT; // left
  1094. break;
  1095. }
  1096. }
  1097. } else {
  1098. // Presume that no concrete piece is needed.
  1099. icon = C_NONE;
  1100. if (isodd) {
  1101. index &= ~(OF_NE|OF_SE); // Ignore diagonals.
  1102. switch (index) {
  1103. case OF_N|OF_E:
  1104. icon = C_UP_RIGHT; // up right
  1105. break;
  1106. case OF_E|OF_S:
  1107. icon = C_DOWN_RIGHT; // down right
  1108. break;
  1109. case OF_N|OF_E|OF_S:
  1110. icon = C_UPDOWN_RIGHT; // up/down right
  1111. break;
  1112. default:
  1113. break;
  1114. }
  1115. } else {
  1116. index &= ~(EF_NW|EF_SW); // Ignore diagonals.
  1117. switch (index) {
  1118. case EF_N|EF_W:
  1119. icon = C_UP_LEFT; // up left
  1120. break;
  1121. case EF_W|EF_S:
  1122. icon = C_DOWN_LEFT; // down left
  1123. break;
  1124. case EF_N|EF_W|EF_S:
  1125. icon = C_UPDOWN_LEFT; // up/down left
  1126. break;
  1127. default:
  1128. break;
  1129. }
  1130. }
  1131. /*
  1132. ** If any kind of fixup piece is needed, then add concrete
  1133. ** to this location RECURSIVELY!
  1134. */
  1135. if (icon != C_NONE) {
  1136. OverlayTypeClass::As_Reference(OVERLAY_CONCRETE).Create_And_Place(Cell_Number());
  1137. icon = C_NONE;
  1138. }
  1139. }
  1140. /*
  1141. ** Update the icon on the map.
  1142. */
  1143. if (icon != C_NONE && OverlayData != icon) {
  1144. OverlayData = icon;
  1145. //Array[cell].Base = 0;
  1146. Redraw_Objects();
  1147. }
  1148. }
  1149. /***********************************************************************************************
  1150. * CellClass::Wall_Update -- Updates the imagery for wall objects in cell. *
  1151. * *
  1152. * This routine will examine the cell and the adjacent cells to determine what the wall *
  1153. * should look like with the cell. It will then update the wall's imagery value and flag *
  1154. * the cell to be redrawn if necessary. This routine should be called whenever the wall *
  1155. * or an adjacent wall is created or destroyed. *
  1156. * *
  1157. * INPUT: none *
  1158. * *
  1159. * OUTPUT: none *
  1160. * *
  1161. * WARNINGS: none *
  1162. * *
  1163. * HISTORY: *
  1164. * 09/19/1994 JLB : Created. *
  1165. * 09/19/1994 BWG : Updated to handle partially-damaged walls. *
  1166. *=============================================================================================*/
  1167. void CellClass::Wall_Update(void)
  1168. {
  1169. Validate();
  1170. static FacingType _offsets[5] = {FACING_N, FACING_E, FACING_S, FACING_W, FACING_NONE};
  1171. for (unsigned index = 0; index < (sizeof(_offsets)/sizeof(_offsets[0])); index++) {
  1172. CellClass & newcell = Adjacent_Cell(_offsets[index]);
  1173. if (newcell.Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(newcell.Overlay).IsWall) {
  1174. int icon = 0;
  1175. /*
  1176. ** Build the icon number according to walls located in the adjacent
  1177. ** cells.
  1178. */
  1179. for (unsigned i = 0; i < 4; i++) {
  1180. if (newcell.Adjacent_Cell(_offsets[i]).Overlay == newcell.Overlay) {
  1181. icon |= 1 << i;
  1182. }
  1183. }
  1184. newcell.OverlayData = (newcell.OverlayData & 0xFFF0) | icon;
  1185. // newcell.OverlayData = icon;
  1186. /*
  1187. ** Handle special cases for the incomplete damaged wall sets. If a damage stage
  1188. ** is calculated, but there is no artwork for it, then consider the wall to be
  1189. ** completely destroyed.
  1190. */
  1191. if (newcell.Overlay == OVERLAY_BRICK_WALL && newcell.OverlayData == 48) {
  1192. newcell.Overlay = OVERLAY_NONE;
  1193. newcell.OverlayData = 0;
  1194. ObjectClass::Detach_This_From_All(::As_Target(newcell.Cell_Number()), true);
  1195. }
  1196. if (newcell.Overlay == OVERLAY_SANDBAG_WALL && newcell.OverlayData == 16) {
  1197. newcell.Overlay = OVERLAY_NONE;
  1198. newcell.OverlayData = 0;
  1199. ObjectClass::Detach_This_From_All(::As_Target(newcell.Cell_Number()), true);
  1200. }
  1201. if (newcell.Overlay == OVERLAY_CYCLONE_WALL && newcell.OverlayData == 32) {
  1202. newcell.Overlay = OVERLAY_NONE;
  1203. newcell.OverlayData = 0;
  1204. ObjectClass::Detach_This_From_All(::As_Target(newcell.Cell_Number()), true);
  1205. }
  1206. if (newcell.Overlay == OVERLAY_BARBWIRE_WALL && newcell.OverlayData == 16) {
  1207. newcell.Overlay = OVERLAY_NONE;
  1208. newcell.OverlayData = 0;
  1209. ObjectClass::Detach_This_From_All(::As_Target(newcell.Cell_Number()), true);
  1210. }
  1211. newcell.Recalc_Attributes();
  1212. newcell.Redraw_Objects();
  1213. }
  1214. }
  1215. }
  1216. /***********************************************************************************************
  1217. * CellClass::Cell_Coord -- Returns the coordinate of this cell. *
  1218. * *
  1219. * This support function will determine the coordinate of this cell and return it. *
  1220. * *
  1221. * INPUT: none *
  1222. * *
  1223. * OUTPUT: Returns with coordinate value of cell. *
  1224. * *
  1225. * WARNINGS: none *
  1226. * *
  1227. * HISTORY: *
  1228. * 09/19/1994 JLB : Created. *
  1229. *=============================================================================================*/
  1230. COORDINATE CellClass::Cell_Coord(void) const
  1231. {
  1232. Validate();
  1233. return(::Cell_Coord(Cell_Number()));
  1234. }
  1235. /***********************************************************************************************
  1236. * CellClass::Reduce_Tiberium -- Reduces the tiberium in the cell by the amount specified. *
  1237. * *
  1238. * This routine will lower the tiberium level in the cell. It is used by the harvesting *
  1239. * process as well as by combat damage to the tiberium fields. *
  1240. * *
  1241. * INPUT: levels -- The number of levels to reduce the tiberium. *
  1242. * *
  1243. * OUTPUT: bool; Was the tiberium level reduced by at least one level? *
  1244. * *
  1245. * WARNINGS: none *
  1246. * *
  1247. * HISTORY: *
  1248. * 09/19/1994 JLB : Created. *
  1249. *=============================================================================================*/
  1250. int CellClass::Reduce_Tiberium(int levels)
  1251. {
  1252. Validate();
  1253. int reducer = 0;
  1254. if (levels && Land == LAND_TIBERIUM) {
  1255. if (OverlayData > levels) {
  1256. OverlayData -= levels;
  1257. reducer = levels;
  1258. } else {
  1259. Overlay = OVERLAY_NONE;
  1260. reducer = OverlayData;
  1261. OverlayData = 0;
  1262. Recalc_Attributes();
  1263. }
  1264. }
  1265. return(reducer);
  1266. }
  1267. /***********************************************************************************************
  1268. * CellClass::Reduce_Wall -- Damages a wall, if damage is high enough. *
  1269. * *
  1270. * This routine will change the wall shape used for a wall if it's damaged. *
  1271. * *
  1272. * *
  1273. * INPUT: damage -- The number of damage points the wall was hit with. *
  1274. * *
  1275. * OUTPUT: bool; Was the wall destroyed? *
  1276. * *
  1277. * WARNINGS: none *
  1278. * *
  1279. * HISTORY: *
  1280. * 03/15/1995 BWG : Created. *
  1281. * 03/19/1995 JLB : Updates cell information if wall was destroyed. *
  1282. *=============================================================================================*/
  1283. int CellClass::Reduce_Wall(int damage)
  1284. {
  1285. Validate();
  1286. if (Overlay != OVERLAY_NONE) {
  1287. bool destroyed = false;
  1288. OverlayTypeClass const & wall = OverlayTypeClass::As_Reference(Overlay);
  1289. if (wall.IsWall) {
  1290. /*
  1291. ** If the damage was great enough to ensure wall destruction, reduce the wall by one
  1292. ** level (no more). Otherwise determine wall reduction based on a percentage chance
  1293. ** proportional to the damage received and the wall's strength.
  1294. */
  1295. if (damage >= wall.DamagePoints) {
  1296. destroyed = true;
  1297. } else {
  1298. destroyed = Random_Pick(0, wall.DamagePoints) < damage;
  1299. }
  1300. if (destroyed) {
  1301. OverlayData+=16;
  1302. if ((OverlayData>>4) >= wall.DamageLevels) {
  1303. ObjectClass::Detach_This_From_All(As_Target());
  1304. Owner = HOUSE_NONE;
  1305. Overlay = OVERLAY_NONE;
  1306. OverlayData = 0;
  1307. Recalc_Attributes();
  1308. Redraw_Objects();
  1309. Adjacent_Cell(FACING_N).Wall_Update();
  1310. Adjacent_Cell(FACING_W).Wall_Update();
  1311. Adjacent_Cell(FACING_S).Wall_Update();
  1312. Adjacent_Cell(FACING_E).Wall_Update();
  1313. return(true);
  1314. }
  1315. }
  1316. }
  1317. }
  1318. return(false);
  1319. }
  1320. /***********************************************************************************************
  1321. * CellClass::Get_Trigger -- retrieves reference to the cell's trigger *
  1322. * *
  1323. * INPUT: *
  1324. * none. *
  1325. * *
  1326. * OUTPUT: *
  1327. * TriggerClass reference *
  1328. * *
  1329. * WARNINGS: *
  1330. * Never call this function unless the IsTrigger flag is set for the cell! *
  1331. * *
  1332. * HISTORY: *
  1333. * 12/01/1994 BR : Created. *
  1334. *=============================================================================================*/
  1335. TriggerClass * CellClass::Get_Trigger(void) const
  1336. {
  1337. Validate();
  1338. if (IsTrigger) {
  1339. return(CellTriggers[Cell_Number()]);
  1340. }
  1341. return(NULL);
  1342. }
  1343. /***********************************************************************************************
  1344. * CellClass::Spot_Index -- returns cell sub-coord index for given COORD *
  1345. * *
  1346. * INPUT: *
  1347. * coord COORD to compute index for *
  1348. * *
  1349. * OUTPUT: *
  1350. * index into StoppingCoord that's closest to this coord *
  1351. * *
  1352. * WARNINGS: *
  1353. * none. *
  1354. * *
  1355. * HISTORY: *
  1356. * 11/21/1994 BR : Created. *
  1357. * 12/10/1994 JLB : Uses alternate sub-position algorithm. *
  1358. *=============================================================================================*/
  1359. int CellClass::Spot_Index(COORDINATE coord)
  1360. {
  1361. COORDINATE rel = coord & 0x00FF00FFL; // Sub coordinate value within cell.
  1362. /*
  1363. ** If the coordinate is close enough to the center of the cell, then return
  1364. ** the center position index.
  1365. */
  1366. if (Distance(rel, 0x00800080L) < 60) {
  1367. return(0);
  1368. }
  1369. /*
  1370. ** Since the center cell position has been eliminated, a simple comparison
  1371. ** as related to the center of the cell can be used to determine the sub
  1372. ** position. Take advantage of the fact that the sub positions are organized
  1373. ** from left to right, top to bottom.
  1374. */
  1375. int index = 0;
  1376. if (Coord_X(rel) > 0x80) index |= 0x01;
  1377. if (Coord_Y(rel) > 0x80) index |= 0x02;
  1378. return(index+1);
  1379. }
  1380. /***********************************************************************************************
  1381. * CellClass::Closest_Free_Spot -- returns free spot closest to given coord *
  1382. * *
  1383. * Similar to the CellClass::Free_Spot; this routine finds the spot in *
  1384. * the cell closest to the given coordinate, and returns the COORD of *
  1385. * that spot if it's available, NULL if it's not. *
  1386. * *
  1387. * INPUT: *
  1388. * coord coordinate to check (only sub cell position examined) *
  1389. * *
  1390. * any -- If only the closest spot is desired regardless of whether it is free or *
  1391. * not, then this parameter will be true. *
  1392. * *
  1393. * OUTPUT: *
  1394. * COORD of free spot, NULL if none. The coordinate return value does not alter the cell *
  1395. * coordinate data portions of the coordinate passed in. Only the lower sub-cell *
  1396. * data is altered. *
  1397. * *
  1398. * WARNINGS: *
  1399. * none. *
  1400. * *
  1401. * HISTORY: *
  1402. * 11/08/1994 BR : Created. *
  1403. * 12/10/1994 JLB : Picks best of closest stopping positions. *
  1404. * 12/21/1994 JLB : Adds a mix-up factor if center location is occupied. *
  1405. *=============================================================================================*/
  1406. COORDINATE CellClass::Closest_Free_Spot(COORDINATE coord, bool any) const
  1407. {
  1408. Validate();
  1409. int spot_index = Spot_Index(coord);
  1410. /*
  1411. ** This precalculated sequence table records the closest spots to any given spot. Sequential
  1412. ** examination of these spots for availability ensures that the closes available one is
  1413. ** discovered first.
  1414. */
  1415. static unsigned char _sequence[5][4] = {
  1416. {1,2,3,4},
  1417. {0,2,3,4},
  1418. {0,1,4,3},
  1419. {0,1,4,2},
  1420. {0,2,3,1}
  1421. };
  1422. /*
  1423. ** In the case of the center coordinate being requested, but is occupied, then all other
  1424. ** sublocations are equidistant. Instead of picking a static sequence of examination, the
  1425. ** order is mixed up by way of this table.
  1426. */
  1427. static unsigned char _alternate[4][4] = {
  1428. {1,2,3,4},
  1429. {2,3,4,1},
  1430. {3,4,1,2},
  1431. {4,1,2,3},
  1432. };
  1433. coord &= 0xFF00FF00L;
  1434. /*
  1435. ** Cells occupied by buildings or vehicles don't have any free spots.
  1436. */
  1437. if (!any && (Flag.Occupy.Vehicle || Flag.Occupy.Monolith)) {
  1438. return(NULL);
  1439. }
  1440. /*
  1441. ** If just the nearest position is desired regardless of whether occupied or not,
  1442. ** then just return with the stopping coordinate value.
  1443. */
  1444. if (any || Is_Spot_Free(spot_index)) {
  1445. return(Coord_Add(coord, StoppingCoordAbs[spot_index]));
  1446. }
  1447. /*
  1448. ** Scan through all available sub-locations in the cell in order to determine
  1449. ** the closest one to the coordinate requested. Use precalculated table so that
  1450. ** when the first free position is found, bail.
  1451. */
  1452. unsigned char *sequence;
  1453. if (spot_index == 0) {
  1454. sequence = &_alternate[Random_Pick(0,3)][0];
  1455. } else {
  1456. sequence = &_sequence[spot_index][0];
  1457. }
  1458. for (int index = 0; index < 4; index++) {
  1459. int pos = *sequence++;
  1460. if (Is_Spot_Free(pos)) {
  1461. return(Coord_Add(coord, StoppingCoordAbs[pos]));
  1462. }
  1463. }
  1464. /*
  1465. ** No free spot could be found so return a NULL coordinate.
  1466. */
  1467. return(0x00000000L);
  1468. }
  1469. /***********************************************************************************************
  1470. * CellClass::Clear_Icon -- Calculates what the clear icon number should be. *
  1471. * *
  1472. * This support routine will determine what the clear icon number would be for the cell. *
  1473. * The icon number is determined by converting the cell number into an index into a *
  1474. * lookup table. This yields what appears to be a randomized map without the necessity of *
  1475. * generating and recording randomized map numbers. *
  1476. * *
  1477. * INPUT: none *
  1478. * *
  1479. * OUTPUT: Returns with the icon number for clear terrain if it were displayed at the *
  1480. * cell. *
  1481. * *
  1482. * WARNINGS: none *
  1483. * *
  1484. * HISTORY: *
  1485. * 12/26/1994 JLB : Created. *
  1486. * 06/09/1995 JLB : Uses 16 entry scramble algorithm. *
  1487. *=============================================================================================*/
  1488. int CellClass::Clear_Icon(void) const
  1489. {
  1490. Validate();
  1491. CELL cell = Cell_Number();
  1492. return((cell & 0x03) | ((cell>>4) & 0x0C));
  1493. }
  1494. /***********************************************************************************************
  1495. * CellClass::Incoming -- Causes objects in cell to "run for cover". *
  1496. * *
  1497. * This routine is called whenever a great, but slow moving, threat is presented to the *
  1498. * occupants of a cell. The occupants will, in most cases, stop what they are doing and *
  1499. * try to get out of the way. *
  1500. * *
  1501. * INPUT: threat -- The coordinate source of the threat. *
  1502. * *
  1503. * forced -- If this threat is so major that the occupants should stop what *
  1504. * they are doing, then this parameter should be set to true. *
  1505. * *
  1506. * OUTPUT: none *
  1507. * *
  1508. * WARNINGS: none *
  1509. * *
  1510. * HISTORY: *
  1511. * 01/10/1995 JLB : Created. *
  1512. *=============================================================================================*/
  1513. void CellClass::Incoming(COORDINATE threat, bool forced)
  1514. {
  1515. Validate();
  1516. ObjectClass * object = NULL;
  1517. object = Cell_Occupier();
  1518. while (object) {
  1519. /*
  1520. ** Special check to make sure that friendly units never scatter.
  1521. */
  1522. if (Special.IsScatter || (object->Is_Techno() && !((TechnoClass *)object)->House->IsHuman)) {
  1523. if (object->What_Am_I() == RTTI_INFANTRY) {
  1524. object->Scatter(threat, forced);
  1525. } else {
  1526. object->Scatter(threat, forced);
  1527. // object->Scatter(threat, false);
  1528. }
  1529. }
  1530. object = object->Next;
  1531. }
  1532. }
  1533. /***********************************************************************************************
  1534. * CellClass::Adjacent_Cell -- Determines the adjacent cell according to facing. *
  1535. * *
  1536. * Use this routine to return a reference to the adjacent cell in the direction specified. *
  1537. * *
  1538. * INPUT: face -- The direction to use when determining the adjacent cell. *
  1539. * *
  1540. * OUTPUT: Returns with a reference to the adjacent cell. *
  1541. * *
  1542. * WARNINGS: If the facing value is invalid, then a reference to the same cell is returned. *
  1543. * *
  1544. * HISTORY: *
  1545. * 03/19/1995 JLB : Created. *
  1546. *=============================================================================================*/
  1547. CellClass const & CellClass::Adjacent_Cell(FacingType face) const
  1548. {
  1549. Validate();
  1550. if ((unsigned)face >= FACING_COUNT) {
  1551. return(*this);
  1552. }
  1553. CellClass const * ptr = this + AdjacentCell[face];
  1554. if (ptr->Cell_Number() & 0xF000) return(*this);
  1555. return(*ptr);
  1556. // return(*(this + AdjacentCell[face]));
  1557. }
  1558. /***************************************************************************
  1559. * CellClass::Adjust_Threat -- Allows adjustment of threat at cell level *
  1560. * *
  1561. * INPUT: *
  1562. * *
  1563. * OUTPUT: *
  1564. * *
  1565. * WARNINGS: *
  1566. * *
  1567. * HISTORY: *
  1568. * 04/24/1995 PWG : Created. *
  1569. *=========================================================================*/
  1570. void CellClass::Adjust_Threat(HousesType house, int threat_value)
  1571. {
  1572. Validate();
  1573. int region = Map.Cell_Region(Cell_Number());
  1574. for (HousesType lp = HOUSE_FIRST; lp < HOUSE_COUNT; lp ++) {
  1575. if (lp == house) continue;
  1576. HouseClass *house_ptr = HouseClass::As_Pointer(lp);
  1577. if (house_ptr && (!house_ptr->IsHuman || !house_ptr->Is_Ally(house))) {
  1578. house_ptr->Adjust_Threat(region, threat_value);
  1579. }
  1580. }
  1581. if (Debug_Threat) {
  1582. Map.Flag_To_Redraw(true);
  1583. }
  1584. }
  1585. /***********************************************************************************************
  1586. * CellClass::Tiberium_Adjust -- Adjust the look of the Tiberium for smoothing purposes. *
  1587. * *
  1588. * This routine will adjust the level of the Tiberium in the cell so that it will *
  1589. * smoothly blend with the adjacent Tiberium. This routine should only be called for *
  1590. * new Tiberium cells. Existing cells that contain Tiberium follow a different growth *
  1591. * pattern. *
  1592. * *
  1593. * INPUT: pregame -- Is this a pregame call? Such a call will mixup the Tiberium overlay *
  1594. * used. *
  1595. * *
  1596. * OUTPUT: Returns with the added Tiberium value that is now available for harvesting. *
  1597. * *
  1598. * WARNINGS: The return value is only valid for the initial placement. Tiberium growth will *
  1599. * increase the net worth of the existing Tiberium. *
  1600. * *
  1601. * HISTORY: *
  1602. * 05/16/1995 JLB : Created. *
  1603. *=============================================================================================*/
  1604. long CellClass::Tiberium_Adjust(bool pregame)
  1605. {
  1606. Validate();
  1607. if (Overlay != OVERLAY_NONE) {
  1608. if (OverlayTypeClass::As_Reference(Overlay).Land == LAND_TIBERIUM) {
  1609. static int _adj[9] = {0,1,3,4,6,7,8,10,11};
  1610. int count = 0;
  1611. /*
  1612. ** Mixup the Tiberium overlays so that they don't look the same.
  1613. */
  1614. if (pregame) {
  1615. Overlay = Random_Pick(OVERLAY_TIBERIUM1, OVERLAY_TIBERIUM12);
  1616. }
  1617. /*
  1618. ** Add up all adjacent cells that contain tiberium.
  1619. ** (Skip those cells which aren't on the map)
  1620. */
  1621. for (FacingType face = FACING_FIRST; face < FACING_COUNT; face++) {
  1622. CELL cell = Cell_Number() + AdjacentCell[face];
  1623. CellClass & adj = Adjacent_Cell(face);
  1624. if (adj.Overlay != OVERLAY_NONE &&
  1625. OverlayTypeClass::As_Reference(adj.Overlay).Land == LAND_TIBERIUM) {
  1626. count++;
  1627. }
  1628. }
  1629. OverlayData = _adj[count];
  1630. return((OverlayData+1) * UnitTypeClass::TIBERIUM_STEP);
  1631. }
  1632. }
  1633. return(0);
  1634. }
  1635. /***********************************************************************************************
  1636. * CellClass::Goodie_Check -- Performs crate discovery logic. *
  1637. * *
  1638. * Call this routine whenever an object enters a cell. It will check for the existance *
  1639. * of a crate and generate any "goodie" it might contain. *
  1640. * *
  1641. * INPUT: object -- Pointer to the object that is triggering this crate. *
  1642. * *
  1643. * OUTPUT: Can the object continue to enter this cell? A false return value means that the *
  1644. * cell is now occupied and must not be entered. *
  1645. * *
  1646. * WARNINGS: none *
  1647. * *
  1648. * HISTORY: *
  1649. * 05/22/1995 JLB : Created. *
  1650. * 07/08/1995 JLB : Added a bunch of goodies to the crates. *
  1651. *=============================================================================================*/
  1652. bool CellClass::Goodie_Check(FootClass * object)
  1653. {
  1654. Validate();
  1655. enum {
  1656. MONEY, // Cash award.
  1657. UNIT, // A free unit.
  1658. NUKE, // A nuclear device that explodes.
  1659. ION, // Calls forth an ion blast on discoverer.
  1660. NUKE_MISSILE, // Gets a one time nuclear missile options.
  1661. ION_BLAST, // Gets a one time ion blast option.
  1662. AIR_STRIKE, // Gets a one time air strike option.
  1663. HEAL_BASE, // Heals the player's entire base.
  1664. CLOAK, // Units in region gain cloak ability.
  1665. EXPLOSION, // Conventional explosion.
  1666. NAPALM, // A napalm explosion.
  1667. SQUAD, // A mixed squad of friendly infantry appear.
  1668. VISCEROID, // A visceroid appears!
  1669. DARKNESS, // Shroud the entire map.
  1670. REVEAL, // Reveal the entire map.
  1671. TOTAL_CRATES,
  1672. };
  1673. static int _what[] = {
  1674. DARKNESS,DARKNESS,
  1675. REVEAL,REVEAL,
  1676. NUKE,
  1677. // ION,ION,
  1678. NUKE_MISSILE,
  1679. ION_BLAST,ION_BLAST,
  1680. AIR_STRIKE,AIR_STRIKE,AIR_STRIKE,AIR_STRIKE,
  1681. HEAL_BASE,HEAL_BASE,
  1682. CLOAK,CLOAK,
  1683. EXPLOSION,EXPLOSION,EXPLOSION,EXPLOSION,
  1684. NAPALM,NAPALM,NAPALM,
  1685. SQUAD,SQUAD,SQUAD,SQUAD,SQUAD,
  1686. UNIT,UNIT,UNIT,UNIT,UNIT,
  1687. VISCEROID
  1688. };
  1689. /*
  1690. ** Crate types are only defined here so it needs to match my new global crate total ST - 6/4/96 2:16PM
  1691. */
  1692. #if (TOTAL_CRATES) == (TOTAL_CRATE_TYPES)
  1693. #else
  1694. //Huge_Errrrror..... Oh NO!
  1695. #endif
  1696. if (object && Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(Overlay).IsCrate) {
  1697. bool steel = (Overlay == OVERLAY_STEEL_CRATE);
  1698. COORDINATE coord; // Temporary working coordinate value.
  1699. /*
  1700. ** A triggered crate is automatically destroyed regardless of who or how
  1701. ** it was triggered.
  1702. */
  1703. Redraw_Objects();
  1704. Overlay = OVERLAY_NONE;
  1705. OverlayData = 0;
  1706. if (steel) {
  1707. if (object->Owner() == HOUSE_BAD) {
  1708. object->House->Add_Nuke_Piece();
  1709. new AnimClass(ANIM_CRATE_EMPULSE, Cell_Coord());
  1710. }
  1711. } else {
  1712. int index;
  1713. UnitClass * unit = 0;
  1714. unsigned damage = 0;
  1715. int what = MONEY;
  1716. if (GameToPlay != GAME_NORMAL && (Random_Pick(1, 2) == 1 || !object->House->BScan)) {
  1717. what = -1;
  1718. /*
  1719. ** If the player has a construction yeard and practically no money and no legitmate means
  1720. ** to make any more money, then give money to build a refinery.
  1721. */
  1722. if ((object->House->BScan & (STRUCTF_CONST|STRUCTF_REFINERY)) == STRUCTF_CONST &&
  1723. object->House->Available_Money() < BuildingTypeClass::As_Reference(STRUCT_REFINERY).Cost) {
  1724. what = MONEY;
  1725. }
  1726. /*
  1727. ** If the player should get an MCV replacement, then give it now (probably).
  1728. */
  1729. if (Random_Pick(0, 1) == 0 &&
  1730. MPlayerBases &&
  1731. !(object->House->UScan & UNITF_MCV) &&
  1732. object->House->BScan == 0 &&
  1733. object->House->Available_Money() > (BuildingTypeClass::As_Reference(STRUCT_REFINERY).Cost + BuildingTypeClass::As_Reference(STRUCT_POWER).Cost)) {
  1734. what = UNIT;
  1735. }
  1736. while (what == -1) {
  1737. what = _what[Random_Pick((unsigned)0, sizeof(_what)/sizeof(_what[0])-1)];
  1738. if (what == REVEAL && object->House->IsVisionary) what = -1;
  1739. if (what == AIR_STRIKE && object->House->AirStrike.Is_Present()) what = -1;
  1740. if (what == NUKE_MISSILE && object->House->NukeStrike.Is_Present()) what = -1;
  1741. if (what == ION_BLAST && object->House->IonCannon.Is_Present()) what = -1;
  1742. if (what == CLOAK && object->IsCloakable) what = -1;
  1743. }
  1744. }
  1745. /*
  1746. ** Keep track of the number of each type of crate found
  1747. */
  1748. if (GameToPlay == GAME_INTERNET){
  1749. object->House->TotalCrates->Increment_Unit_Total(what);
  1750. }
  1751. /*
  1752. ** Update the crate count and when all the crates have been discovered, flag
  1753. ** to generate a new one.
  1754. */
  1755. CrateCount--;
  1756. if (!CrateMaker && CrateCount <= 0 && GameToPlay != GAME_NORMAL) {
  1757. CrateMaker = true;
  1758. CrateTimer = 1;
  1759. }
  1760. /*
  1761. ** Create the effect requested.
  1762. */
  1763. switch (what) {
  1764. default:
  1765. /*
  1766. ** Give the player money.
  1767. */
  1768. case MONEY:
  1769. new AnimClass(ANIM_CRATE_DOLLAR, Cell_Coord());
  1770. if (GameToPlay == GAME_NORMAL) {
  1771. HouseClass::As_Pointer(object->Owner())->Refund_Money(2000);
  1772. } else {
  1773. HouseClass::As_Pointer(object->Owner())->Refund_Money(100 + (Random_Pick(0,19)*100));
  1774. }
  1775. break;
  1776. /*
  1777. ** Shroud the world in blackness.
  1778. */
  1779. case DARKNESS:
  1780. new AnimClass(ANIM_CRATE_EMPULSE, Cell_Coord());
  1781. if (object->House == PlayerPtr) {
  1782. for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  1783. CellClass * cellptr = &Map[cell];
  1784. if (cellptr->IsMapped || cellptr->IsVisible) {
  1785. cellptr->Redraw_Objects();
  1786. cellptr->IsMapped = false;
  1787. cellptr->IsVisible = false;
  1788. }
  1789. }
  1790. for (int index = 0; index < Map.Layer[LAYER_GROUND].Count(); index++) {
  1791. ObjectClass * object = Map.Layer[LAYER_GROUND][index];
  1792. if (object && object->Is_Techno() && ((TechnoClass *)object)->House == PlayerPtr) {
  1793. object->Look();
  1794. }
  1795. }
  1796. Map.Flag_To_Redraw(true);
  1797. }
  1798. break;
  1799. /*
  1800. ** Reveal the entire map.
  1801. */
  1802. case REVEAL:
  1803. new AnimClass(ANIM_CRATE_EMPULSE, Cell_Coord());
  1804. object->House->IsVisionary = true;
  1805. if (object->House == PlayerPtr) {
  1806. for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  1807. Map.Map_Cell(cell, PlayerPtr);
  1808. }
  1809. }
  1810. break;
  1811. /*
  1812. ** Try to create a unit where the crate was.
  1813. */
  1814. case UNIT: {
  1815. UnitTypeClass const * utp = NULL;
  1816. /*
  1817. ** Give the player an MCV if he has no base left but does have more than enough
  1818. ** money to rebuild a new base. Of course, if he already has an MCV, then don't
  1819. ** give him another one.
  1820. */
  1821. if (MPlayerBases &&
  1822. !(object->House->UScan & UNITF_MCV) &&
  1823. object->House->BScan == 0 &&
  1824. object->House->Available_Money() > (BuildingTypeClass::As_Reference(STRUCT_REFINERY).Cost + BuildingTypeClass::As_Reference(STRUCT_POWER).Cost)) {
  1825. utp = &UnitTypeClass::As_Reference(UNIT_MCV);
  1826. }
  1827. /*
  1828. ** If the player has a base and a refinery, but no harvester, then give him
  1829. ** a free one.
  1830. */
  1831. if (!utp && (object->House->BScan & STRUCTF_REFINERY) && !(object->House->UScan & UNITF_HARVESTER)) {
  1832. utp = &UnitTypeClass::As_Reference(UNIT_HARVESTER);
  1833. }
  1834. while (!utp) {
  1835. UnitType utype = Random_Pick(UNIT_FIRST, (UnitType)(UNIT_COUNT-1));
  1836. if (utype != UNIT_MCV || MPlayerBases) {
  1837. utp = &UnitTypeClass::As_Reference(utype);
  1838. if (utp->IsCrateGoodie && (utp->Ownable & (1 << object->Owner())) && utp->Level <= BuildLevel+2) break;
  1839. utp = NULL;
  1840. }
  1841. }
  1842. UnitClass * unit = (UnitClass *)utp->Create_One_Of(object->House);
  1843. if (unit) {
  1844. if (unit->Unlimbo(Cell_Coord())) {
  1845. return(false);
  1846. }
  1847. delete unit;
  1848. }
  1849. }
  1850. break;
  1851. /*
  1852. ** Create a squad of miscellanous composition.
  1853. */
  1854. case SQUAD:
  1855. for (index = 0; index < 5; index++) {
  1856. static InfantryType _inf[] = {
  1857. INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,
  1858. INFANTRY_E2,
  1859. INFANTRY_E3,
  1860. INFANTRY_E4,
  1861. INFANTRY_E5,
  1862. INFANTRY_E7,
  1863. INFANTRY_RAMBO
  1864. };
  1865. InfantryTypeClass::As_Reference(_inf[Random_Pick((unsigned)0, sizeof(_inf)/sizeof(_inf[0])-1)]).Create_And_Place(Cell_Number(), object->Owner());
  1866. }
  1867. return(false);
  1868. /*
  1869. ** Sometimes an explosion of great magnitude occurs.
  1870. */
  1871. case NUKE:
  1872. new AnimClass(ANIM_ATOM_BLAST, Cell_Coord());
  1873. break;
  1874. /*
  1875. ** Sometimes an explosion of great magnitude occurs.
  1876. */
  1877. case ION:
  1878. new AnimClass(ANIM_ION_CANNON, Cell_Coord());
  1879. break;
  1880. /*
  1881. ** A nuclear missile was discovered. Add it to the sidebar.
  1882. */
  1883. case NUKE_MISSILE:
  1884. new AnimClass(ANIM_CRATE_MISSILE, Cell_Coord());
  1885. if (object->House->NukeStrike.Enable(true)) {
  1886. if (object->IsOwnedByPlayer) {
  1887. Map.Add(RTTI_SPECIAL, SPC_NUCLEAR_BOMB);
  1888. Map.Column[1].Flag_To_Redraw();
  1889. }
  1890. }
  1891. break;
  1892. /*
  1893. ** A one time ion blast was discovered. Add it to the sidebar.
  1894. */
  1895. case ION_BLAST:
  1896. new AnimClass(ANIM_CRATE_EARTH, Cell_Coord());
  1897. if (object->House->IonCannon.Enable(true)) {
  1898. if (object->IsOwnedByPlayer) {
  1899. Map.Add(RTTI_SPECIAL, SPC_ION_CANNON);
  1900. Map.Column[1].Flag_To_Redraw();
  1901. }
  1902. }
  1903. break;
  1904. /*
  1905. ** A one time air strike can be called int. Add it to the sidebar.
  1906. */
  1907. case AIR_STRIKE:
  1908. new AnimClass(ANIM_CRATE_DEVIATOR, Cell_Coord());
  1909. if (object->House->AirStrike.Enable(true)) {
  1910. if (object->IsOwnedByPlayer) {
  1911. Map.Add(RTTI_SPECIAL, SPC_AIR_STRIKE);
  1912. Map.Column[1].Flag_To_Redraw();
  1913. }
  1914. }
  1915. break;
  1916. /*
  1917. ** A group of explosions are triggered around the crate.
  1918. */
  1919. case EXPLOSION:
  1920. damage = 400;
  1921. object->Take_Damage((int&)damage, 0, WARHEAD_HE);
  1922. for (index = 0; index < 5; index++) {
  1923. COORDINATE coord = Coord_Scatter(Cell_Coord(), Random_Pick(0, 0x0200));
  1924. new AnimClass(ANIM_FBALL1, coord);
  1925. damage = 400;
  1926. Explosion_Damage(coord, damage, NULL, WARHEAD_HE);
  1927. }
  1928. break;
  1929. /*
  1930. ** A napalm blast is triggered.
  1931. */
  1932. case NAPALM:
  1933. coord = Coord_Mid(Cell_Coord(), object->Center_Coord());
  1934. new AnimClass(ANIM_NAPALM3, coord);
  1935. damage = 600;
  1936. Explosion_Damage(coord, damage, NULL, WARHEAD_FIRE);
  1937. break;
  1938. /*
  1939. ** A visceroid appears and, boy, he's angry!
  1940. */
  1941. case VISCEROID:
  1942. unit = new UnitClass(UNIT_VICE, HOUSE_JP);
  1943. if (unit) {
  1944. if (unit->Unlimbo(Cell_Coord())) {
  1945. return(false);
  1946. }
  1947. delete unit;
  1948. }
  1949. break;
  1950. /*
  1951. ** All objects within a certain range will gain the ability to cloak.
  1952. */
  1953. case CLOAK:
  1954. new AnimClass(ANIM_CRATE_STEALTH, Cell_Coord());
  1955. for (index = 0; index < Map.Layer[LAYER_GROUND].Count(); index++) {
  1956. ObjectClass * obj = Map.Layer[LAYER_GROUND][index];
  1957. if (obj && obj->Is_Techno() && Distance(Cell_Coord(), obj->Center_Coord()) < 0x0300) {
  1958. ((TechnoClass *)obj)->IsCloakable = true;
  1959. }
  1960. }
  1961. break;
  1962. /*
  1963. ** All of the player's objects heal up.
  1964. */
  1965. case HEAL_BASE:
  1966. new AnimClass(ANIM_CRATE_INVUN, Cell_Coord());
  1967. for (index = 0; index < Logic.Count(); index++) {
  1968. ObjectClass * obj = Logic[index];
  1969. if (obj && object->Is_Techno() && object->House->Class->House == obj->Owner()) {
  1970. obj->Strength = obj->Class_Of().MaxStrength;
  1971. }
  1972. }
  1973. break;
  1974. }
  1975. }
  1976. }
  1977. return(true);
  1978. }
  1979. /***********************************************************************************************
  1980. * CellClass::Flag_Place -- Places a house flag down on the cell. *
  1981. * *
  1982. * This routine will place the house flag at this cell location. *
  1983. * *
  1984. * INPUT: house -- The house that is having its flag placed here. *
  1985. * *
  1986. * OUTPUT: Was the flag successfully placed here? *
  1987. * *
  1988. * WARNINGS: Failure to place means that the cell is impassable for some reason. *
  1989. * *
  1990. * HISTORY: *
  1991. * 05/23/1995 JLB : Created. *
  1992. *=============================================================================================*/
  1993. bool CellClass::Flag_Place(HousesType house)
  1994. {
  1995. Validate();
  1996. if (!IsFlagged && Is_Generally_Clear()) {
  1997. IsFlagged = true;
  1998. Owner = house;
  1999. Redraw_Objects();
  2000. return(true);
  2001. }
  2002. return(false);
  2003. }
  2004. /***********************************************************************************************
  2005. * CellClass::Flag_Remove -- Removes the house flag from the cell. *
  2006. * *
  2007. * This routine will free the cell of any house flag that may be located there. *
  2008. * *
  2009. * INPUT: none *
  2010. * *
  2011. * OUTPUT: Was there a flag here that was removed? *
  2012. * *
  2013. * WARNINGS: none *
  2014. * *
  2015. * HISTORY: *
  2016. * 05/23/1995 JLB : Created. *
  2017. *=============================================================================================*/
  2018. bool CellClass::Flag_Remove(void)
  2019. {
  2020. Validate();
  2021. if (IsFlagged) {
  2022. IsFlagged = false;
  2023. Owner = HOUSE_NONE;
  2024. Redraw_Objects();
  2025. return(true);
  2026. }
  2027. return(false);
  2028. }
  2029. /***********************************************************************************************
  2030. * CellClass::Shimmer -- Causes all objects in the cell to shimmer. *
  2031. * *
  2032. * This routine is called when some event would cause a momentary disruption in the *
  2033. * cloaking device. All objects that are cloaked in the cell will have their cloaking *
  2034. * device shimmer. *
  2035. * *
  2036. * INPUT: none *
  2037. * *
  2038. * OUTPUT: none *
  2039. * *
  2040. * WARNINGS: none *
  2041. * *
  2042. * HISTORY: *
  2043. * 07/29/1995 JLB : Created. *
  2044. *=============================================================================================*/
  2045. void CellClass::Shimmer(void)
  2046. {
  2047. Validate();
  2048. ObjectClass * object = Cell_Occupier();
  2049. while (object) {
  2050. object->Do_Shimmer();
  2051. object = object->Next;
  2052. }
  2053. }
  2054. /***********************************************************************************************
  2055. * CellClass::Cell_Occupier -- Fetches the occupier for the cell. *
  2056. * *
  2057. * This routine returns with the first recorded occupier of this cell. A special validity *
  2058. * check is performed to ensure that there are no dead objects still marked on the *
  2059. * map. *
  2060. * *
  2061. * INPUT: none *
  2062. * *
  2063. * OUTPUT: Returns with a pointer to the first occupier object. *
  2064. * *
  2065. * WARNINGS: none *
  2066. * *
  2067. * HISTORY: *
  2068. * 08/17/1995 JLB : Created. *
  2069. *=============================================================================================*/
  2070. ObjectClass * CellClass::Cell_Occupier(void) const
  2071. {
  2072. ObjectClass * ptr = OccupierPtr;
  2073. while (ptr && !ptr->IsActive) {
  2074. ptr = ptr->Next;
  2075. ((ObjectClass *&)OccupierPtr) = 0;
  2076. }
  2077. return(ptr);
  2078. }