CELL.CPP 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: F:\projects\c&c\vcs\code\cell.cpv 2.18 16 Oct 1995 16:49:20 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 : CELL.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : April 29, 1994 *
  26. * *
  27. * Last Update : August 17, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * CellClass::Adjacent_Cell -- Determines the adjacent cell according to facing. *
  32. * CellClass::Adjust_Threat -- Allows adjustment of threat at cell level *
  33. * CellClass::CellClass -- Constructor for cell objects. *
  34. * CellClass::Cell_Building -- Return with building at specified cell. *
  35. * CellClass::Cell_Color -- Determine what radar color to use for this cell. *
  36. * CellClass::Cell_Coord -- Returns the coordinate of this cell. *
  37. * CellClass::Cell_Find_Object -- Returns ptr to RTTI type occupying cell *
  38. * CellClass::Cell_Infantry -- Returns with pointer of first infantry unit. *
  39. * CellClass::Cell_Object -- Returns with clickable object in cell. *
  40. * CellClass::Cell_Techno -- Return with the unit/building at specified cell. *
  41. * CellClass::Cell_Terrain -- Determines terrain object in cell. *
  42. * CellClass::Cell_Unit -- Returns with pointer to unit occupying cell. *
  43. * CellClass::Clear_Icon -- Calculates what the clear icon number should be. *
  44. * CellClass::Closest_Free_Spot -- returns free spot closest to given coord *
  45. * CellClass::Concrete_Calc -- Calculates the concrete icon to use for the cell. *
  46. * CellClass::Draw_It -- Draws the cell imagery at the location specified. *
  47. * CellClass::Flag_Place -- Places a house flag down on the cell. *
  48. * CellClass::Flag_Remove -- Removes the house flag from the cell. *
  49. * CellClass::Cell_Occupier -- Fetches the occupier for the cell. *
  50. * CellClass::Get_Trigger -- retrieves reference to the cell's trigger *
  51. * CellClass::Goodie_Check -- Performs crate discovery logic. *
  52. * CellClass::Incoming -- Causes objects in cell to "run for cover". *
  53. * CellClass::Is_Generally_Clear -- Determines if cell can be built upon. *
  54. * CellClass::Occupy_Down -- Flag occupation of specified cell. *
  55. * CellClass::Occupy_Unit -- Marks cell as unit occupied. *
  56. * CellClass::Occupy_Up -- Removes occupation flag from the specified cell. *
  57. * CellClass::Overlap_Down -- This routine is used to mark a cell as being spilled over (overla*
  58. * CellClass::Overlap_Unit -- Marks cell as being overlapped by unit. *
  59. * CellClass::Overlap_Up -- Removes overlap flag for the cell. *
  60. * CellClass::Read -- Reads a particular cell value from a save game file. *
  61. * CellClass::Recalc_Attributes -- Recalculates the ground type attributes for the cell. *
  62. * CellClass::Redraw_Objects -- Redraws all objects overlapping this cell. *
  63. * CellClass::Reduce_Tiberium -- Reduces the tiberium in the cell by the amount specified. *
  64. * CellClass::Reduce_Wall -- Damages a wall, if damage is high enough. *
  65. * CellClass::Reserve_Cell -- Marks a cell as being occupied by the specified unit ID. *
  66. * CellClass::Shimmer -- Causes all objects in the cell to shimmer. *
  67. * CellClass::Spot_Index -- returns cell sub-coord index for given COORD *
  68. * CellClass::Tiberium_Adjust -- Adjust the look of the Tiberium for smooth. *
  69. * CellClass::Validate -- validates cell's number *
  70. * CellClass::Wall_Update -- Updates the imagery for wall objects in cell. *
  71. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  72. #include "function.h"
  73. /*
  74. ** New sidebar for GlyphX multiplayer. ST - 3/26/2019 12:24PM
  75. */
  76. #include "SidebarGlyphx.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. Overlay = OVERLAY_NONE;
  127. Smudge = SMUDGE_NONE;
  128. TType = TEMPLATE_NONE;
  129. Owner = HOUSE_NONE;
  130. InfType = HOUSE_NONE;
  131. OverrideLand = LAND_COUNT;
  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 && object->IsActive) {
  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 && object->IsActive) {
  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. if (optr->IsActive) {
  359. optr->Mark(MARK_CHANGE);
  360. }
  361. optr = optr->Next;
  362. }
  363. }
  364. /*
  365. ** Flag any overlapping object in this cell to be redrawn.
  366. */
  367. for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  368. if (Overlapper[index]) {
  369. if (!Overlapper[index]->IsActive) {
  370. Overlapper[index] = 0;
  371. } else {
  372. Overlapper[index]->Mark(MARK_CHANGE);
  373. }
  374. }
  375. }
  376. }
  377. }
  378. /***********************************************************************************************
  379. * CellClass::Is_Generally_Clear -- Determines if cell can be built upon. *
  380. * *
  381. * This determines if the cell can become a proper foundation for *
  382. * building placement. *
  383. * *
  384. * INPUT: none *
  385. * *
  386. * OUTPUT: bool; Can the cell be built upon? *
  387. * *
  388. * WARNINGS: none *
  389. * *
  390. * HISTORY: *
  391. * 05/18/1994 JLB : Created. *
  392. *=============================================================================================*/
  393. bool CellClass::Is_Generally_Clear(bool ignore_cloaked) const
  394. {
  395. Validate();
  396. if (ScenarioInit) return(true);
  397. if (Flag.Composite || IsFlagged || Cell_Occupier()) {
  398. if (!ignore_cloaked || (Cell_Occupier() && Cell_Occupier()->Is_Techno() && ((TechnoClass *)Cell_Occupier())->Cloak != CLOAKED)) {
  399. return(false);
  400. }
  401. }
  402. if (Smudge != SMUDGE_NONE && SmudgeTypeClass::As_Reference(Smudge).IsBib && Owner != HOUSE_NONE) {
  403. return(false);
  404. }
  405. if (Overlay != OVERLAY_NONE && (Overlay == OVERLAY_FLAG_SPOT || OverlayTypeClass::As_Reference(Overlay).IsWall)) {
  406. return(false);
  407. }
  408. #ifdef ADVANCED
  409. /*
  410. ** Building certain kinds of terrain is prohibited -- bridges in particular.
  411. */
  412. switch (TType) {
  413. case TEMPLATE_BRIDGE1:
  414. case TEMPLATE_BRIDGE1D:
  415. case TEMPLATE_BRIDGE2:
  416. case TEMPLATE_BRIDGE2D:
  417. case TEMPLATE_BRIDGE3:
  418. case TEMPLATE_BRIDGE3D:
  419. case TEMPLATE_BRIDGE4:
  420. case TEMPLATE_BRIDGE4D:
  421. case TEMPLATE_FORD1:
  422. case TEMPLATE_FORD2:
  423. return(false);
  424. default:
  425. break;
  426. }
  427. #endif
  428. return(::Ground[Land_Type()].Build);
  429. }
  430. /***********************************************************************************************
  431. * CellClass::Recalc_Attributes -- Recalculates the ground type attributes for the cell. *
  432. * *
  433. * This routine recalculates the ground type in the cell. The speeds the find path *
  434. * algorithm and other determinations of the cell type. *
  435. * *
  436. * INPUT: none *
  437. * *
  438. * OUTPUT: none *
  439. * *
  440. * WARNINGS: none *
  441. * *
  442. * HISTORY: *
  443. * 05/29/1994 JLB : Created. *
  444. * 06/20/1994 JLB : Knows about template pointer in cell object. *
  445. *=============================================================================================*/
  446. void CellClass::Recalc_Attributes(void)
  447. {
  448. Validate();
  449. /*
  450. ** Check for wall effects.
  451. */
  452. if (Overlay != OVERLAY_NONE) {
  453. Land = OverlayTypeClass::As_Reference(Overlay).Land;
  454. if (Land != LAND_CLEAR) return;
  455. }
  456. /*
  457. ** If there is a template associated with this cell, then scan
  458. ** through the template exception list checking to see if this cell
  459. ** is one of the exception types. If it is, then return that ground type,
  460. ** otherwise return the template's default type.
  461. */
  462. if (TType != TEMPLATE_NONE) {
  463. TemplateTypeClass const *ttype = &TemplateTypeClass::As_Reference(TType);
  464. /*
  465. ** If there is an exception type list for the icons of this template, then
  466. ** find out if the current icon is one of them. If so, apply the exception
  467. ** ground type to the cell.
  468. */
  469. char const *ptr = ttype->AltIcons;
  470. if (ptr) {
  471. int icon = TIcon;
  472. while (*ptr != -1) {
  473. if (icon == *ptr++) {
  474. Land = ttype->AltLand;
  475. return;
  476. }
  477. }
  478. }
  479. /*
  480. ** No exception found, so just return the default ground type for this template.
  481. */
  482. Land = ttype->Land;
  483. return;
  484. }
  485. /*
  486. ** No template is the same as clear terrain.
  487. */
  488. Land = TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1).Land;
  489. }
  490. /***********************************************************************************************
  491. * CellClass::Occupy_Down -- Flag occupation of specified cell. *
  492. * *
  493. * This routine is used to mark the cell as being occupied by the specified object. *
  494. * *
  495. * INPUT: object -- The object that is to occupy the cell *
  496. * *
  497. * OUTPUT: none *
  498. * *
  499. * WARNINGS: none *
  500. * *
  501. * HISTORY: *
  502. * 07/18/1994 JLB : Created. *
  503. * 11/29/1994 JLB : Simplified. *
  504. *=============================================================================================*/
  505. void CellClass::Occupy_Down(ObjectClass * object)
  506. {
  507. Validate();
  508. ObjectClass * optr;
  509. /*
  510. ** If the specified object is already part of the occupation list, then don't add
  511. ** it again -- bail instead.
  512. */
  513. if (Cell_Occupier()) {
  514. optr = Cell_Occupier();
  515. while (optr) {
  516. if (optr == object) {
  517. return;
  518. }
  519. if (!optr->Next) break;
  520. optr = optr->Next;
  521. }
  522. }
  523. optr = Cell_Occupier();
  524. object->Next = optr;
  525. OccupierPtr = object;
  526. Map.Radar_Pixel(Cell_Number());
  527. /*
  528. ** If being placed down on a visible square, then flag this
  529. ** techno object as being revealed to the player.
  530. */
  531. // Changes for GlyphX multiplayer. ST - 4/17/2019 3:02PM
  532. //if (IsVisible || GameToPlay != GAME_NORMAL) {
  533. // object->Revealed(PlayerPtr);
  534. //}
  535. if (GameToPlay != GAME_GLYPHX_MULTIPLAYER) {
  536. if (IsVisible || GameToPlay != GAME_NORMAL) {
  537. object->Revealed(PlayerPtr);
  538. }
  539. } else {
  540. for (int i = 0; i < MPlayerCount; i++) {
  541. HousesType house_type = MPlayerHouses[i];
  542. if (Is_Visible(house_type)) {
  543. HouseClass *house = HouseClass::As_Pointer(house_type);
  544. object->Revealed(house);
  545. }
  546. }
  547. }
  548. /*
  549. ** Special occupy bit set.
  550. */
  551. switch (object->What_Am_I()) {
  552. case RTTI_BUILDING:
  553. Flag.Occupy.Building = true;
  554. break;
  555. case RTTI_AIRCRAFT:
  556. case RTTI_UNIT:
  557. Flag.Occupy.Vehicle = true;
  558. break;
  559. case RTTI_TERRAIN:
  560. Flag.Occupy.Monolith = true;
  561. break;
  562. default:
  563. break;
  564. }
  565. }
  566. /***********************************************************************************************
  567. * CellClass::Occupy_Up -- Removes occupation flag from the specified cell. *
  568. * *
  569. * This routine will lift the object from the cell and free the cell to be occupied by *
  570. * another object. Only if the cell was previously marked with the object specified, will *
  571. * the object be lifted off. This routine is the counterpart to Occupy_Down(). *
  572. * *
  573. * INPUT: object -- The object that is being lifted off. *
  574. * *
  575. * OUTPUT: none *
  576. * *
  577. * WARNINGS: none *
  578. * *
  579. * HISTORY: *
  580. * 07/18/1994 JLB : Created. *
  581. * 11/29/1994 JLB : Fixed to handle next pointer in previous object. *
  582. *=============================================================================================*/
  583. void CellClass::Occupy_Up(ObjectClass * object)
  584. {
  585. Validate();
  586. ObjectClass * optr = NULL; // Working pointer to the objects in the chain.
  587. if (Cell_Occupier()) {
  588. optr = Cell_Occupier();
  589. }
  590. if (optr == object) {
  591. OccupierPtr = object->Next;
  592. object->Next = 0;
  593. } else {
  594. while (optr) {
  595. if (optr->Next == object) {
  596. optr->Next = object->Next;
  597. object->Next = 0;
  598. break;
  599. }
  600. if (!optr->Next) break;
  601. optr = optr->Next;
  602. }
  603. }
  604. Map.Radar_Pixel(Cell_Number());
  605. /*
  606. ** Special occupy bit clear.
  607. */
  608. switch (object->What_Am_I()) {
  609. case RTTI_BUILDING:
  610. Flag.Occupy.Building = false;
  611. break;
  612. case RTTI_AIRCRAFT:
  613. case RTTI_UNIT:
  614. Flag.Occupy.Vehicle = false;
  615. #ifdef NEVER
  616. int x,y;
  617. if (Map.Coord_To_Pixel(Cell_Coord(), x, y)) {
  618. SeenBuff.Put_Pixel(x, y, BLUE);
  619. }
  620. #endif
  621. break;
  622. case RTTI_TERRAIN:
  623. Flag.Occupy.Monolith = false;
  624. break;
  625. default:
  626. break;
  627. }
  628. }
  629. /***********************************************************************************************
  630. * CellClass::Overlap_Down -- This routine is used to mark a cell as being spilled over (overla*
  631. * *
  632. * Most game objects can often have their graphic imagery spill into more than one cell *
  633. * even though they are considered to "occupy" only one cell. All cells overlapped are *
  634. * flagged by this routine. Using this information it is possible to keep the tactical map *
  635. * display correct. *
  636. * *
  637. * INPUT: object -- The object to mark as overlapping this cell. *
  638. * *
  639. * OUTPUT: none *
  640. * *
  641. * WARNINGS: none *
  642. * *
  643. * HISTORY: *
  644. * 07/18/1994 JLB : Created. *
  645. * 07/04/1995 JLB : Ensures that buildings are always marked down. *
  646. *=============================================================================================*/
  647. void CellClass::Overlap_Down(ObjectClass * object)
  648. {
  649. Validate();
  650. ObjectClass **ptr = 0;
  651. if (!object) return;
  652. int index;
  653. for (index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  654. if (Overlapper[index] == object) return;
  655. if (!Overlapper[index]) ptr = &Overlapper[index];
  656. }
  657. /*
  658. ** Buildings must ALWAYS succeed in marking the cell as overlapped. Bump somebody
  659. ** else out in this case.
  660. */
  661. if (!ptr && object->What_Am_I() == RTTI_BUILDING) {
  662. for (index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  663. switch (Overlapper[index]->What_Am_I()) {
  664. case RTTI_BUILDING:
  665. case RTTI_TERRAIN:
  666. break;
  667. default:
  668. Overlapper[index] = object;
  669. index = sizeof(Overlapper)/sizeof(Overlapper[0]);
  670. break;
  671. }
  672. }
  673. }
  674. if (ptr) *ptr = object;
  675. /*
  676. ** If being placed down on a visible square, then flag this
  677. ** techno object as being revealed to the player.
  678. */
  679. // Changes for GlyphX multiplayer. ST - 4/18/2019 9:50AM
  680. //if (IsVisible) {
  681. // object->Revealed(PlayerPtr);
  682. //}
  683. if (GameToPlay != GAME_GLYPHX_MULTIPLAYER) {
  684. if (IsVisible) {
  685. object->Revealed(PlayerPtr);
  686. }
  687. } else {
  688. if (object->Is_Techno()) {
  689. TechnoClass *tech = static_cast<TechnoClass*>(object);
  690. object->Revealed(tech->House);
  691. } else {
  692. for (int i = 0; i < MPlayerCount; i++) {
  693. HousesType house_type = MPlayerHouses[i];
  694. HouseClass *house = HouseClass::As_Pointer(house_type);
  695. object->Revealed(house);
  696. }
  697. }
  698. }
  699. }
  700. /***********************************************************************************************
  701. * CellClass::Overlap_Up -- Removes overlap flag for the cell. *
  702. * *
  703. * This is the counterpart to Overlap_Down and is used to remove the overlap flag for the *
  704. * specified unit on the cell. *
  705. * *
  706. * INPUT: object -- The object to remove the overlap flag for. *
  707. * *
  708. * OUTPUT: none *
  709. * *
  710. * WARNINGS: none *
  711. * *
  712. * HISTORY: *
  713. * 07/18/1994 JLB : Created. *
  714. *=============================================================================================*/
  715. void CellClass::Overlap_Up(ObjectClass *object)
  716. {
  717. Validate();
  718. for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
  719. if (Overlapper[index] == object) {
  720. Overlapper[index] = 0;
  721. break;
  722. }
  723. }
  724. //Map.Validate();
  725. }
  726. /***********************************************************************************************
  727. * CellClass::Cell_Unit -- Returns with pointer to unit occupying cell. *
  728. * *
  729. * This routine will determine if a unit is occupying the cell and if so, return a pointer *
  730. * to it. If there is no unit occupying the cell, then NULL is returned. *
  731. * *
  732. * INPUT: none *
  733. * *
  734. * OUTPUT: Returns with pointer to unit occupying cell, else NULL. *
  735. * *
  736. * WARNINGS: none *
  737. * *
  738. * HISTORY: *
  739. * 07/18/1994 JLB : Created. *
  740. *=============================================================================================*/
  741. UnitClass * CellClass::Cell_Unit(void) const
  742. {
  743. Validate();
  744. return((UnitClass*)Cell_Find_Object(RTTI_UNIT));
  745. }
  746. /***********************************************************************************************
  747. * CellClass::Cell_Infantry -- Returns with pointer of first infantry unit occupying the cell. *
  748. * *
  749. * This routine examines the cell and returns a pointer to the first infantry unit *
  750. * that occupies it. If there is no infantry unit in the cell, then NULL is returned. *
  751. * *
  752. * INPUT: none *
  753. * *
  754. * OUTPUT: Returns with pointer to infantry unit occupying the cell or NULL if none are *
  755. * present. *
  756. * *
  757. * WARNINGS: none *
  758. * *
  759. * HISTORY: *
  760. * 12/21/1994 JLB : Created. *
  761. *=============================================================================================*/
  762. InfantryClass * CellClass::Cell_Infantry(void) const
  763. {
  764. Validate();
  765. return((InfantryClass*)Cell_Find_Object(RTTI_INFANTRY));
  766. }
  767. /***********************************************************************************************
  768. * CellClass::Get_Template_Info -- Get some info about a template for external use *
  769. * *
  770. * *
  771. * *
  772. * *
  773. * INPUT: Ref to info required *
  774. * *
  775. * OUTPUT: True if image info available *
  776. * *
  777. * *
  778. * WARNINGS: none *
  779. * *
  780. * HISTORY: *
  781. * 1/10/2019 5:57PM ST : Created. *
  782. *=============================================================================================*/
  783. bool CellClass::Get_Template_Info(char *template_name, int &icon, void *&image_data)
  784. {
  785. TemplateTypeClass const *ttype = NULL;
  786. if (TType != TEMPLATE_NONE) {
  787. ttype = &TemplateTypeClass::As_Reference(TType);
  788. icon = TIcon;
  789. } else {
  790. ttype = &TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1);
  791. icon = Clear_Icon();
  792. }
  793. if (ttype) {
  794. strcpy(template_name, ttype->IniName);
  795. image_data = (void*) ttype->ImageData;
  796. return true;
  797. }
  798. return false;
  799. }
  800. /***********************************************************************************************
  801. * CellClass::Draw_It -- Draws the cell imagery at the location specified. *
  802. * *
  803. * This is the gruntwork cell rendering code. It draws the cell at the screen location *
  804. * specified. This routine doesn't draw any overlapping or occupying units. It only *
  805. * deals with the ground (cell) layer -- icon level. *
  806. * *
  807. * INPUT: x,y -- The screen coordinates to render the cell imagery at. *
  808. * *
  809. * OUTPUT: none *
  810. * *
  811. * WARNINGS: none *
  812. * *
  813. * HISTORY: *
  814. * 07/18/1994 JLB : Created. *
  815. * 08/21/1994 JLB : Revised for simple template objects. *
  816. * 11/01/1994 BRR : Updated placement cursor; draws actual object *
  817. * 11/14/1994 BRR : Added remapping code to show passable areas *
  818. * 12/02/1994 BRR : Added trigger display *
  819. * 12/11/1994 JLB : Mixes up clear terrain through pseudo-random table. *
  820. * 04/25/1995 JLB : Smudges drawn BELOW overlays. *
  821. *=============================================================================================*/
  822. void CellClass::Draw_It(int x, int y, int draw_type) const
  823. {
  824. Validate();
  825. TemplateTypeClass const *ttype = 0;
  826. int icon; // The icon number to use from the template set.
  827. CELL cell = Cell_Number();
  828. void * remap = NULL;
  829. #ifdef SCENARIO_EDITOR
  830. TemplateTypeClass * tptr;
  831. TriggerClass * trig;
  832. int i;
  833. char waypt[2];
  834. #endif
  835. /*
  836. ** Fetch a pointer to the template type associated with this cell.
  837. */
  838. if (TType != TEMPLATE_NONE) {
  839. ttype = &TemplateTypeClass::As_Reference(TType);
  840. icon = TIcon;
  841. } else {
  842. ttype = &TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1);
  843. icon = Clear_Icon();
  844. }
  845. /*
  846. ** Draw the stamp of the template.
  847. */
  848. if (Debug_Icon) {
  849. 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));
  850. FontXSpacing -= 2;
  851. 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);
  852. FontXSpacing += 2;
  853. } else {
  854. if (!draw_type || draw_type == CELL_BLIT_ONLY){
  855. #ifdef SCENARIO_EDITOR
  856. /*
  857. ** Set up the remap table for this icon.
  858. */
  859. if (Debug_Map && Debug_Passable) {
  860. if (::Ground[Land].Cost[0] == 0 || (Cell_Occupier() != NULL &&
  861. Cell_Occupier()->What_Am_I() != RTTI_INFANTRY)) { // impassable
  862. remap = Map.FadingRed;
  863. } else {
  864. if (::Ground[Land].Cost[0] > 0x70) { // pretty passable
  865. remap = Map.FadingGreen;
  866. } else {
  867. remap = Map.FadingYellow; // moderately passable
  868. }
  869. }
  870. }
  871. #endif
  872. // ****** maybe this icon shouldn't be drawn if it is known that the cell will be covered
  873. // with shadow.
  874. /*
  875. ** This is the underlying terrain icon.
  876. */
  877. if (ttype->Get_Image_Data()) {
  878. LogicPage->Draw_Stamp(ttype->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
  879. if (remap) {
  880. LogicPage->Remap(x+Map.TacPixelX, y+Map.TacPixelY, ICON_PIXEL_W, ICON_PIXEL_H, remap);
  881. }
  882. }
  883. #ifdef SCENARIO_EDITOR
  884. /*
  885. ** Draw the map editor's "current" cell. This is the cell that can be
  886. ** assigned attributes such as tag labels.
  887. ** This must be draw before the placement cursor, but after drawing the
  888. ** objects in the cell.
  889. */
  890. if (Debug_Map && CurrentCell == Cell_Number()) {
  891. LogicPage->Draw_Rect(x+Map.TacPixelX, y+Map.TacPixelY, Map.TacPixelX + x + CELL_PIXEL_W - 1, Map.TacPixelY + y + CELL_PIXEL_H - 1, YELLOW);
  892. }
  893. #endif
  894. #ifdef NEVER
  895. /*
  896. ** Special concrete render. It always renders over the underlying
  897. ** terrain unless this concrete piece will cover the entire terrain
  898. ** piece.
  899. */
  900. if (Concrete) {
  901. LogicPage->Draw_Stamp(TemplateTypeClass::As_Pointer(TEMPLATE_CONCRETE_GDI)->Get_Image_Data(), Concrete-1, x, y, NULL, WINDOW_TACTICAL);
  902. }
  903. #endif
  904. }
  905. /*
  906. ** Redraw any smudge.
  907. */
  908. if (Smudge != SMUDGE_NONE) {
  909. #ifdef NEVER
  910. switch (Smudge) {
  911. case SMUDGE_BIB1:
  912. CC_Draw_Shape(Bib1, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  913. break;
  914. case SMUDGE_BIB2:
  915. CC_Draw_Shape(Bib2, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  916. break;
  917. case SMUDGE_BIB3:
  918. CC_Draw_Shape(Bib3, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
  919. break;
  920. }
  921. #endif
  922. SmudgeTypeClass::As_Reference(Smudge).Draw_It(x, y, SmudgeData);
  923. }
  924. if (!draw_type || draw_type == CELL_DRAW_ONLY){
  925. /*
  926. ** Draw the overlay object.
  927. */
  928. if (Overlay != OVERLAY_NONE) {
  929. OverlayTypeClass const & otype = OverlayTypeClass::As_Reference(Overlay);
  930. IsTheaterShape = (bool)otype.IsTheater;
  931. 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);
  932. IsTheaterShape = false;
  933. }
  934. #ifdef SCENARIO_EDITOR
  935. if (Debug_Map) {
  936. /*
  937. ** Draw the cell's Trigger mnemonic, if it has a trigger
  938. */
  939. if (IsTrigger) {
  940. trig = Get_Trigger();
  941. Fancy_Text_Print(trig->Get_Name(), x+Map.TacPixelX, y+Map.TacPixelY, PINK, TBLACK, TPF_NOSHADOW|TPF_6POINT);
  942. }
  943. /*
  944. ** Draw the cell's Waypoint designation if there is one.
  945. */
  946. if (IsWaypoint) {
  947. for (i = 0; i < 26; i++) {
  948. if (Waypoint[i]==Cell_Number()) {
  949. waypt[0] = 'A' + i;
  950. waypt[1] = 0;
  951. Fancy_Text_Print(waypt, Map.TacPixelX + x + CELL_PIXEL_W / 2,
  952. Map.TacPixelY + y + (CELL_PIXEL_H / 2) - 3, YELLOW, TBLACK,
  953. TPF_NOSHADOW | TPF_6POINT | TPF_CENTER);
  954. break;
  955. }
  956. }
  957. if (Waypoint[WAYPT_HOME] == Cell_Number()) {
  958. Fancy_Text_Print("Home", Map.TacPixelX + x, Map.TacPixelY + y + (CELL_PIXEL_H) - 7,
  959. WHITE, TBLACK, TPF_NOSHADOW | TPF_6POINT);
  960. }
  961. if (Waypoint[WAYPT_REINF] == Cell_Number()) {
  962. Fancy_Text_Print("Reinf", Map.TacPixelX + x, Map.TacPixelY + y + (CELL_PIXEL_H) - 7,
  963. WHITE, TBLACK, TPF_NOSHADOW | TPF_6POINT);
  964. }
  965. }
  966. }
  967. #endif
  968. /*
  969. ** Draw the placement cursor:
  970. ** - First, draw the hash-mark cursor, so it will appear underneath
  971. ** any cursor being drawn
  972. ** - If the PendingObject is a template, overlay, or smudge, draw it
  973. ** - Otherwise, it's up to the Display.Refresh_Map() routine to draw it
  974. */
  975. if (IsCursorHere) {
  976. /*
  977. ** Draw the hash-mark cursor:
  978. */
  979. if (Map.ProximityCheck && Is_Generally_Clear()) {
  980. LogicPage->Draw_Stamp(Map.TransIconset, 0, x, y, NULL, WINDOW_TACTICAL);
  981. } else {
  982. LogicPage->Draw_Stamp(Map.TransIconset, 2, x, y, NULL, WINDOW_TACTICAL);
  983. }
  984. #ifdef SCENARIO_EDITOR
  985. if (Debug_Map && Map.PendingObject) {
  986. switch (Map.PendingObject->What_Am_I()) {
  987. /*
  988. ** Draw a template:
  989. ** - Compute the icon offset of this cell for this template, using
  990. ** ZoneCell+ZoneOffset to get the upper-left corner of the placement
  991. ** cursor
  992. ** - Draw the icon
  993. */
  994. case RTTI_TEMPLATETYPE:
  995. tptr = (TemplateTypeClass *)Map.PendingObject;
  996. if (tptr->Get_Image_Data()) {
  997. icon = (Cell_X(cell) - Cell_X(Map.ZoneCell + Map.ZoneOffset)) +
  998. (Cell_Y(cell) - Cell_Y(Map.ZoneCell + Map.ZoneOffset)) *
  999. tptr->Width;
  1000. LogicPage->Draw_Stamp(tptr->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
  1001. }
  1002. break;
  1003. /*
  1004. ** Draw an overlay; just use the existing 'OverlayData' even though
  1005. ** it means nothing.
  1006. */
  1007. case RTTI_OVERLAYTYPE:
  1008. OverlayTypeClass::As_Reference(((OverlayTypeClass *)Map.PendingObject)->Type).Draw_It(x, y, OverlayData);
  1009. break;
  1010. /*
  1011. ** Draw a smudge
  1012. */
  1013. case RTTI_SMUDGETYPE:
  1014. SmudgeTypeClass::As_Reference(((SmudgeTypeClass *)Map.PendingObject)->Type).Draw_It(x, y, 0);
  1015. break;
  1016. }
  1017. }
  1018. #endif
  1019. }
  1020. }
  1021. }
  1022. }
  1023. /***********************************************************************************************
  1024. * CellClass::Concrete_Calc -- Calculates the concrete icon to use for the cell. *
  1025. * *
  1026. * This routine examines the cells around the current one and from this, determines what *
  1027. * concrete icon shape to use (if any). The cell data is adjusted and the cell is marked *
  1028. * for redraw if the icon changed. *
  1029. * *
  1030. * INPUT: none *
  1031. * *
  1032. * OUTPUT: none *
  1033. * *
  1034. * WARNINGS: none *
  1035. * *
  1036. * HISTORY: *
  1037. * 08/01/1994 JLB : Created. *
  1038. *=============================================================================================*/
  1039. void CellClass::Concrete_Calc(void)
  1040. {
  1041. Validate();
  1042. static FacingType _even[5] = {FACING_N, FACING_S, FACING_SW, FACING_W, FACING_NW};
  1043. static FacingType _odd[5] = {FACING_N, FACING_NE, FACING_E, FACING_SE, FACING_S};
  1044. FacingType *ptr; // Working pointer into adjacent cell list.
  1045. int index; // Constructed bit index.
  1046. int icon; // Icon number.
  1047. bool isodd; // Is this for the odd column?
  1048. #define OF_N 0x01
  1049. #define OF_NE 0x02
  1050. #define OF_E 0x04
  1051. #define OF_SE 0x08
  1052. #define OF_S 0x10
  1053. #define EF_N 0x01
  1054. #define EF_NW 0x10
  1055. #define EF_W 0x08
  1056. #define EF_SW 0x04
  1057. #define EF_S 0x02
  1058. /*
  1059. ** Determine if the even or odd row logic is necessary.
  1060. */
  1061. isodd = ((Cell_Number() & 0x01) != 0);
  1062. /*
  1063. ** Fetch correct pointer depending on whether this is for an
  1064. ** odd or even row.
  1065. */
  1066. ptr = (isodd) ? _odd : _even;
  1067. /*
  1068. ** Build an index according to the presence of concrete in the special
  1069. ** adjacent cells. This is a short list of adjacent cell flags since
  1070. ** only 5 adjacent cells need to be examined. The choice of which 5
  1071. ** depends on whether this is for an even or odd column.
  1072. */
  1073. index = 0;
  1074. for (int i = 0; i < (sizeof(_even)/sizeof(_even[0])); i++) {
  1075. CellClass * cellptr = Adjacent_Cell(*ptr++);
  1076. // if ((cellptr->IsConcrete) ||
  1077. // cellptr->Concrete == C_UPDOWN_RIGHT ||
  1078. // cellptr->Concrete == C_UPDOWN_LEFT) {
  1079. if (cellptr && cellptr->Overlay == OVERLAY_CONCRETE) {
  1080. index |= (1<<i);
  1081. }
  1082. }
  1083. /*
  1084. ** Special logic occurs for cells that are concrete filled.
  1085. */
  1086. if (Overlay == OVERLAY_CONCRETE) {
  1087. /*
  1088. ** Process the index value and place the appropriate concrete icon
  1089. ** in the cell.
  1090. */
  1091. if (isodd) {
  1092. switch (index) {
  1093. case OF_NE:
  1094. case OF_N|OF_NE:
  1095. case OF_E|OF_N:
  1096. case OF_E|OF_NE:
  1097. case OF_N|OF_NE|OF_E:
  1098. case OF_S|OF_N|OF_NE:
  1099. icon = C_RIGHT_UP; // right - up
  1100. break;
  1101. case OF_SE:
  1102. case OF_E|OF_SE:
  1103. case OF_S|OF_SE:
  1104. case OF_S|OF_E:
  1105. case OF_S|OF_SE|OF_E:
  1106. case OF_S|OF_SE|OF_N:
  1107. icon = C_RIGHT_DOWN; // right - down
  1108. break;
  1109. case OF_SE|OF_NE:
  1110. case OF_SE|OF_NE|OF_N:
  1111. case OF_SE|OF_NE|OF_S:
  1112. case OF_SE|OF_NE|OF_S|OF_N:
  1113. case OF_SE|OF_E|OF_N:
  1114. case OF_SE|OF_E|OF_NE|OF_N:
  1115. case OF_S|OF_E|OF_N:
  1116. case OF_S|OF_E|OF_NE:
  1117. case OF_S|OF_E|OF_NE|OF_N:
  1118. case OF_S|OF_SE|OF_E|OF_N:
  1119. case OF_S|OF_SE|OF_E|OF_NE|OF_N:
  1120. case OF_S|OF_SE|OF_E|OF_NE:
  1121. icon = C_RIGHT_UPDOWN; // right - up - down
  1122. break;
  1123. default:
  1124. icon = C_RIGHT; // right
  1125. break;
  1126. }
  1127. } else {
  1128. switch (index) {
  1129. case EF_NW:
  1130. case EF_NW|EF_N:
  1131. case EF_W|EF_N:
  1132. case EF_NW|EF_W|EF_N:
  1133. case EF_NW|EF_W:
  1134. case EF_NW|EF_S|EF_N:
  1135. icon = C_LEFT_UP; // left - up
  1136. break;
  1137. case EF_SW:
  1138. case EF_SW|EF_S:
  1139. case EF_W|EF_S:
  1140. case EF_W|EF_SW|EF_S:
  1141. case EF_W|EF_SW:
  1142. case EF_SW|EF_S|EF_N:
  1143. icon = C_LEFT_DOWN; // left - down
  1144. break;
  1145. case EF_NW|EF_SW:
  1146. case EF_NW|EF_SW|EF_N:
  1147. case EF_NW|EF_SW|EF_S:
  1148. case EF_NW|EF_SW|EF_S|EF_N:
  1149. case EF_W|EF_S|EF_N:
  1150. case EF_W|EF_SW|EF_N:
  1151. case EF_W|EF_SW|EF_S|EF_N:
  1152. case EF_NW|EF_W|EF_S:
  1153. case EF_NW|EF_W|EF_S|EF_N:
  1154. case EF_NW|EF_W|EF_SW|EF_S|EF_N:
  1155. case EF_NW|EF_W|EF_SW|EF_N:
  1156. case EF_NW|EF_W|EF_SW|EF_S:
  1157. icon = C_LEFT_UPDOWN; // left - up - down
  1158. break;
  1159. default:
  1160. icon = C_LEFT; // left
  1161. break;
  1162. }
  1163. }
  1164. } else {
  1165. // Presume that no concrete piece is needed.
  1166. icon = C_NONE;
  1167. if (isodd) {
  1168. index &= ~(OF_NE|OF_SE); // Ignore diagonals.
  1169. switch (index) {
  1170. case OF_N|OF_E:
  1171. icon = C_UP_RIGHT; // up right
  1172. break;
  1173. case OF_E|OF_S:
  1174. icon = C_DOWN_RIGHT; // down right
  1175. break;
  1176. case OF_N|OF_E|OF_S:
  1177. icon = C_UPDOWN_RIGHT; // up/down right
  1178. break;
  1179. default:
  1180. break;
  1181. }
  1182. } else {
  1183. index &= ~(EF_NW|EF_SW); // Ignore diagonals.
  1184. switch (index) {
  1185. case EF_N|EF_W:
  1186. icon = C_UP_LEFT; // up left
  1187. break;
  1188. case EF_W|EF_S:
  1189. icon = C_DOWN_LEFT; // down left
  1190. break;
  1191. case EF_N|EF_W|EF_S:
  1192. icon = C_UPDOWN_LEFT; // up/down left
  1193. break;
  1194. default:
  1195. break;
  1196. }
  1197. }
  1198. /*
  1199. ** If any kind of fixup piece is needed, then add concrete
  1200. ** to this location RECURSIVELY!
  1201. */
  1202. if (icon != C_NONE) {
  1203. OverlayTypeClass::As_Reference(OVERLAY_CONCRETE).Create_And_Place(Cell_Number());
  1204. icon = C_NONE;
  1205. }
  1206. }
  1207. /*
  1208. ** Update the icon on the map.
  1209. */
  1210. if (icon != C_NONE && OverlayData != icon) {
  1211. OverlayData = icon;
  1212. //Array[cell].Base = 0;
  1213. Redraw_Objects();
  1214. }
  1215. }
  1216. /***********************************************************************************************
  1217. * CellClass::Wall_Update -- Updates the imagery for wall objects in cell. *
  1218. * *
  1219. * This routine will examine the cell and the adjacent cells to determine what the wall *
  1220. * should look like with the cell. It will then update the wall's imagery value and flag *
  1221. * the cell to be redrawn if necessary. This routine should be called whenever the wall *
  1222. * or an adjacent wall is created or destroyed. *
  1223. * *
  1224. * INPUT: none *
  1225. * *
  1226. * OUTPUT: none *
  1227. * *
  1228. * WARNINGS: none *
  1229. * *
  1230. * HISTORY: *
  1231. * 09/19/1994 JLB : Created. *
  1232. * 09/19/1994 BWG : Updated to handle partially-damaged walls. *
  1233. *=============================================================================================*/
  1234. void CellClass::Wall_Update(void)
  1235. {
  1236. Validate();
  1237. static FacingType _offsets[5] = {FACING_N, FACING_E, FACING_S, FACING_W, FACING_NONE};
  1238. if (Overlay == OVERLAY_NONE) {
  1239. return;
  1240. }
  1241. OverlayTypeClass const & wall = OverlayTypeClass::As_Reference(Overlay);
  1242. if (!wall.IsWall) {
  1243. return;
  1244. }
  1245. for (unsigned index = 0; index < (sizeof(_offsets)/sizeof(_offsets[0])); index++) {
  1246. CellClass * newcell = Adjacent_Cell(_offsets[index]);
  1247. if (newcell && newcell->Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(newcell->Overlay).IsWall) {
  1248. int icon = 0;
  1249. /*
  1250. ** Build the icon number according to walls located in the adjacent
  1251. ** cells.
  1252. */
  1253. for (unsigned i = 0; i < 4; i++) {
  1254. CellClass * adjcell = newcell->Adjacent_Cell(_offsets[i]);
  1255. if (adjcell && adjcell->Overlay == newcell->Overlay) {
  1256. icon |= 1 << i;
  1257. }
  1258. }
  1259. newcell->OverlayData = (newcell->OverlayData & 0xFFF0) | icon;
  1260. // newcell->OverlayData = icon;
  1261. /*
  1262. ** Handle special cases for the incomplete damaged wall sets. If a damage stage
  1263. ** is calculated, but there is no artwork for it, then consider the wall to be
  1264. ** completely destroyed.
  1265. */
  1266. if (newcell->Overlay == OVERLAY_BRICK_WALL && newcell->OverlayData == 48) {
  1267. newcell->Overlay = OVERLAY_NONE;
  1268. newcell->OverlayData = 0;
  1269. ObjectClass::Detach_This_From_All(::As_Target(newcell->Cell_Number()), true);
  1270. }
  1271. if (newcell->Overlay == OVERLAY_SANDBAG_WALL && newcell->OverlayData == 16) {
  1272. newcell->Overlay = OVERLAY_NONE;
  1273. newcell->OverlayData = 0;
  1274. ObjectClass::Detach_This_From_All(::As_Target(newcell->Cell_Number()), true);
  1275. }
  1276. if (newcell->Overlay == OVERLAY_CYCLONE_WALL && newcell->OverlayData == 32) {
  1277. newcell->Overlay = OVERLAY_NONE;
  1278. newcell->OverlayData = 0;
  1279. ObjectClass::Detach_This_From_All(::As_Target(newcell->Cell_Number()), true);
  1280. }
  1281. if (newcell->Overlay == OVERLAY_BARBWIRE_WALL && newcell->OverlayData == 16) {
  1282. newcell->Overlay = OVERLAY_NONE;
  1283. newcell->OverlayData = 0;
  1284. ObjectClass::Detach_This_From_All(::As_Target(newcell->Cell_Number()), true);
  1285. }
  1286. newcell->Recalc_Attributes();
  1287. newcell->Redraw_Objects();
  1288. }
  1289. }
  1290. }
  1291. /***********************************************************************************************
  1292. * CellClass::Cell_Coord -- Returns the coordinate of this cell. *
  1293. * *
  1294. * This support function will determine the coordinate of this cell and return it. *
  1295. * *
  1296. * INPUT: none *
  1297. * *
  1298. * OUTPUT: Returns with coordinate value of cell. *
  1299. * *
  1300. * WARNINGS: none *
  1301. * *
  1302. * HISTORY: *
  1303. * 09/19/1994 JLB : Created. *
  1304. *=============================================================================================*/
  1305. COORDINATE CellClass::Cell_Coord(void) const
  1306. {
  1307. Validate();
  1308. return(::Cell_Coord(Cell_Number()));
  1309. }
  1310. /***********************************************************************************************
  1311. * CellClass::Reduce_Tiberium -- Reduces the tiberium in the cell by the amount specified. *
  1312. * *
  1313. * This routine will lower the tiberium level in the cell. It is used by the harvesting *
  1314. * process as well as by combat damage to the tiberium fields. *
  1315. * *
  1316. * INPUT: levels -- The number of levels to reduce the tiberium. *
  1317. * *
  1318. * OUTPUT: bool; Was the tiberium level reduced by at least one level? *
  1319. * *
  1320. * WARNINGS: none *
  1321. * *
  1322. * HISTORY: *
  1323. * 09/19/1994 JLB : Created. *
  1324. *=============================================================================================*/
  1325. int CellClass::Reduce_Tiberium(int levels)
  1326. {
  1327. Validate();
  1328. int reducer = 0;
  1329. if (levels && Land == LAND_TIBERIUM) {
  1330. if (OverlayData > levels) {
  1331. OverlayData -= levels;
  1332. reducer = levels;
  1333. } else {
  1334. Overlay = OVERLAY_NONE;
  1335. reducer = OverlayData;
  1336. OverlayData = 0;
  1337. Recalc_Attributes();
  1338. }
  1339. }
  1340. return(reducer);
  1341. }
  1342. /***********************************************************************************************
  1343. * CellClass::Reduce_Wall -- Damages a wall, if damage is high enough. *
  1344. * *
  1345. * This routine will change the wall shape used for a wall if it's damaged. *
  1346. * *
  1347. * *
  1348. * INPUT: damage -- The number of damage points the wall was hit with. *
  1349. * *
  1350. * OUTPUT: bool; Was the wall destroyed? *
  1351. * *
  1352. * WARNINGS: none *
  1353. * *
  1354. * HISTORY: *
  1355. * 03/15/1995 BWG : Created. *
  1356. * 03/19/1995 JLB : Updates cell information if wall was destroyed. *
  1357. *=============================================================================================*/
  1358. int CellClass::Reduce_Wall(int damage)
  1359. {
  1360. Validate();
  1361. if (Overlay != OVERLAY_NONE) {
  1362. bool destroyed = false;
  1363. OverlayTypeClass const & wall = OverlayTypeClass::As_Reference(Overlay);
  1364. if (wall.IsWall) {
  1365. /*
  1366. ** If the damage was great enough to ensure wall destruction, reduce the wall by one
  1367. ** level (no more). Otherwise determine wall reduction based on a percentage chance
  1368. ** proportional to the damage received and the wall's strength.
  1369. */
  1370. if (damage >= wall.DamagePoints) {
  1371. destroyed = true;
  1372. } else {
  1373. destroyed = Random_Pick(0, wall.DamagePoints) < damage;
  1374. }
  1375. if (destroyed) {
  1376. OverlayData+=16;
  1377. if ((OverlayData>>4) >= wall.DamageLevels) {
  1378. ObjectClass::Detach_This_From_All(As_Target());
  1379. Owner = HOUSE_NONE;
  1380. Overlay = OVERLAY_NONE;
  1381. OverlayData = 0;
  1382. Recalc_Attributes();
  1383. Redraw_Objects();
  1384. CellClass * ncell = Adjacent_Cell(FACING_N);
  1385. if (ncell) ncell->Wall_Update();
  1386. CellClass * wcell = Adjacent_Cell(FACING_W);
  1387. if (wcell) wcell->Wall_Update();
  1388. CellClass * scell = Adjacent_Cell(FACING_S);
  1389. if (scell) scell->Wall_Update();
  1390. CellClass * ecell = Adjacent_Cell(FACING_E);
  1391. if (ecell) ecell->Wall_Update();
  1392. return(true);
  1393. }
  1394. }
  1395. }
  1396. }
  1397. return(false);
  1398. }
  1399. /***********************************************************************************************
  1400. * CellClass::Get_Trigger -- retrieves reference to the cell's trigger *
  1401. * *
  1402. * INPUT: *
  1403. * none. *
  1404. * *
  1405. * OUTPUT: *
  1406. * TriggerClass reference *
  1407. * *
  1408. * WARNINGS: *
  1409. * Never call this function unless the IsTrigger flag is set for the cell! *
  1410. * *
  1411. * HISTORY: *
  1412. * 12/01/1994 BR : Created. *
  1413. *=============================================================================================*/
  1414. TriggerClass * CellClass::Get_Trigger(void) const
  1415. {
  1416. Validate();
  1417. if (IsTrigger) {
  1418. return(CellTriggers[Cell_Number()]);
  1419. }
  1420. return(NULL);
  1421. }
  1422. /***********************************************************************************************
  1423. * CellClass::Spot_Index -- returns cell sub-coord index for given COORD *
  1424. * *
  1425. * INPUT: *
  1426. * coord COORD to compute index for *
  1427. * *
  1428. * OUTPUT: *
  1429. * index into StoppingCoord that's closest to this coord *
  1430. * *
  1431. * WARNINGS: *
  1432. * none. *
  1433. * *
  1434. * HISTORY: *
  1435. * 11/21/1994 BR : Created. *
  1436. * 12/10/1994 JLB : Uses alternate sub-position algorithm. *
  1437. *=============================================================================================*/
  1438. int CellClass::Spot_Index(COORDINATE coord)
  1439. {
  1440. COORDINATE rel = coord & 0x00FF00FFL; // Sub coordinate value within cell.
  1441. /*
  1442. ** If the coordinate is close enough to the center of the cell, then return
  1443. ** the center position index.
  1444. */
  1445. if (Distance(rel, 0x00800080L) < 60) {
  1446. return(0);
  1447. }
  1448. /*
  1449. ** Since the center cell position has been eliminated, a simple comparison
  1450. ** as related to the center of the cell can be used to determine the sub
  1451. ** position. Take advantage of the fact that the sub positions are organized
  1452. ** from left to right, top to bottom.
  1453. */
  1454. int index = 0;
  1455. if (Coord_X(rel) > 0x80) index |= 0x01;
  1456. if (Coord_Y(rel) > 0x80) index |= 0x02;
  1457. return(index+1);
  1458. }
  1459. /***********************************************************************************************
  1460. * CellClass::Closest_Free_Spot -- returns free spot closest to given coord *
  1461. * *
  1462. * Similar to the CellClass::Free_Spot; this routine finds the spot in *
  1463. * the cell closest to the given coordinate, and returns the COORD of *
  1464. * that spot if it's available, NULL if it's not. *
  1465. * *
  1466. * INPUT: *
  1467. * coord coordinate to check (only sub cell position examined) *
  1468. * *
  1469. * any -- If only the closest spot is desired regardless of whether it is free or *
  1470. * not, then this parameter will be true. *
  1471. * *
  1472. * OUTPUT: *
  1473. * COORD of free spot, NULL if none. The coordinate return value does not alter the cell *
  1474. * coordinate data portions of the coordinate passed in. Only the lower sub-cell *
  1475. * data is altered. *
  1476. * *
  1477. * WARNINGS: *
  1478. * none. *
  1479. * *
  1480. * HISTORY: *
  1481. * 11/08/1994 BR : Created. *
  1482. * 12/10/1994 JLB : Picks best of closest stopping positions. *
  1483. * 12/21/1994 JLB : Adds a mix-up factor if center location is occupied. *
  1484. *=============================================================================================*/
  1485. COORDINATE CellClass::Closest_Free_Spot(COORDINATE coord, bool any) const
  1486. {
  1487. Validate();
  1488. int spot_index = Spot_Index(coord);
  1489. /*
  1490. ** This precalculated sequence table records the closest spots to any given spot. Sequential
  1491. ** examination of these spots for availability ensures that the closes available one is
  1492. ** discovered first.
  1493. */
  1494. static unsigned char _sequence[5][4] = {
  1495. {1,2,3,4},
  1496. {0,2,3,4},
  1497. {0,1,4,3},
  1498. {0,1,4,2},
  1499. {0,2,3,1}
  1500. };
  1501. /*
  1502. ** In the case of the center coordinate being requested, but is occupied, then all other
  1503. ** sublocations are equidistant. Instead of picking a static sequence of examination, the
  1504. ** order is mixed up by way of this table.
  1505. */
  1506. static unsigned char _alternate[4][4] = {
  1507. {1,2,3,4},
  1508. {2,3,4,1},
  1509. {3,4,1,2},
  1510. {4,1,2,3},
  1511. };
  1512. coord &= 0xFF00FF00L;
  1513. /*
  1514. ** Cells occupied by buildings or vehicles don't have any free spots.
  1515. */
  1516. if (!any && (Flag.Occupy.Vehicle || Flag.Occupy.Monolith)) {
  1517. return(NULL);
  1518. }
  1519. /*
  1520. ** If just the nearest position is desired regardless of whether occupied or not,
  1521. ** then just return with the stopping coordinate value.
  1522. */
  1523. if (any || Is_Spot_Free(spot_index)) {
  1524. return(Coord_Add(coord, StoppingCoordAbs[spot_index]));
  1525. }
  1526. /*
  1527. ** Scan through all available sub-locations in the cell in order to determine
  1528. ** the closest one to the coordinate requested. Use precalculated table so that
  1529. ** when the first free position is found, bail.
  1530. */
  1531. unsigned char *sequence;
  1532. if (spot_index == 0) {
  1533. sequence = &_alternate[Random_Pick(0,3)][0];
  1534. } else {
  1535. sequence = &_sequence[spot_index][0];
  1536. }
  1537. for (int index = 0; index < 4; index++) {
  1538. int pos = *sequence++;
  1539. if (Is_Spot_Free(pos)) {
  1540. return(Coord_Add(coord, StoppingCoordAbs[pos]));
  1541. }
  1542. }
  1543. /*
  1544. ** No free spot could be found so return a NULL coordinate.
  1545. */
  1546. return(0x00000000L);
  1547. }
  1548. /***********************************************************************************************
  1549. * CellClass::Clear_Icon -- Calculates what the clear icon number should be. *
  1550. * *
  1551. * This support routine will determine what the clear icon number would be for the cell. *
  1552. * The icon number is determined by converting the cell number into an index into a *
  1553. * lookup table. This yields what appears to be a randomized map without the necessity of *
  1554. * generating and recording randomized map numbers. *
  1555. * *
  1556. * INPUT: none *
  1557. * *
  1558. * OUTPUT: Returns with the icon number for clear terrain if it were displayed at the *
  1559. * cell. *
  1560. * *
  1561. * WARNINGS: none *
  1562. * *
  1563. * HISTORY: *
  1564. * 12/26/1994 JLB : Created. *
  1565. * 06/09/1995 JLB : Uses 16 entry scramble algorithm. *
  1566. *=============================================================================================*/
  1567. int CellClass::Clear_Icon(void) const
  1568. {
  1569. Validate();
  1570. CELL cell = Cell_Number();
  1571. return((cell & 0x03) | ((cell>>4) & 0x0C));
  1572. }
  1573. /***********************************************************************************************
  1574. * CellClass::Incoming -- Causes objects in cell to "run for cover". *
  1575. * *
  1576. * This routine is called whenever a great, but slow moving, threat is presented to the *
  1577. * occupants of a cell. The occupants will, in most cases, stop what they are doing and *
  1578. * try to get out of the way. *
  1579. * *
  1580. * INPUT: threat -- The coordinate source of the threat. *
  1581. * *
  1582. * forced -- If this threat is so major that the occupants should stop what *
  1583. * they are doing, then this parameter should be set to true. *
  1584. * *
  1585. * nokidding -- Override the scatter to also affect human controlled objects. *
  1586. * *
  1587. * OUTPUT: none *
  1588. * *
  1589. * WARNINGS: none *
  1590. * *
  1591. * HISTORY: *
  1592. * 01/10/1995 JLB : Created. *
  1593. *=============================================================================================*/
  1594. void CellClass::Incoming(COORDINATE threat, bool forced, bool nokidding)
  1595. {
  1596. Validate();
  1597. ObjectClass * object = NULL;
  1598. object = Cell_Occupier();
  1599. while (object) {
  1600. /*
  1601. ** Special check to make sure that friendly units never scatter.
  1602. */
  1603. if (nokidding || Special.IsScatter || (object->Is_Techno() && !((TechnoClass *)object)->House->IsHuman)) {
  1604. if (object->What_Am_I() == RTTI_INFANTRY) {
  1605. object->Scatter(threat, forced, nokidding);
  1606. } else {
  1607. object->Scatter(threat, forced, nokidding);
  1608. // object->Scatter(threat, false);
  1609. }
  1610. }
  1611. object = object->Next;
  1612. }
  1613. }
  1614. /***********************************************************************************************
  1615. * CellClass::Adjacent_Cell -- Determines the adjacent cell according to facing. *
  1616. * *
  1617. * Use this routine to return a reference to the adjacent cell in the direction specified. *
  1618. * *
  1619. * INPUT: face -- The direction to use when determining the adjacent cell. *
  1620. * *
  1621. * OUTPUT: Returns with a reference to the adjacent cell. *
  1622. * *
  1623. * WARNINGS: If the facing value is invalid, then a reference to the same cell is returned. *
  1624. * *
  1625. * HISTORY: *
  1626. * 03/19/1995 JLB : Created. *
  1627. *=============================================================================================*/
  1628. CellClass const * CellClass::Adjacent_Cell(FacingType face) const
  1629. {
  1630. Validate();
  1631. if (face == FACING_NONE) {
  1632. return(this);
  1633. }
  1634. if ((unsigned)face >= FACING_COUNT) {
  1635. return(NULL);
  1636. }
  1637. CELL newcell = ::Adjacent_Cell(Cell_Number(), face);
  1638. if ((unsigned)newcell >= MAP_CELL_TOTAL) {
  1639. return(NULL);
  1640. }
  1641. return &Map[newcell];
  1642. }
  1643. /***************************************************************************
  1644. * CellClass::Adjust_Threat -- Allows adjustment of threat at cell level *
  1645. * *
  1646. * INPUT: *
  1647. * *
  1648. * OUTPUT: *
  1649. * *
  1650. * WARNINGS: *
  1651. * *
  1652. * HISTORY: *
  1653. * 04/24/1995 PWG : Created. *
  1654. *=========================================================================*/
  1655. void CellClass::Adjust_Threat(HousesType house, int threat_value)
  1656. {
  1657. Validate();
  1658. int region = Map.Cell_Region(Cell_Number());
  1659. for (HousesType lp = HOUSE_FIRST; lp < HOUSE_COUNT; lp ++) {
  1660. if (lp == house) continue;
  1661. HouseClass *house_ptr = HouseClass::As_Pointer(lp);
  1662. if (house_ptr && (!house_ptr->IsHuman || !house_ptr->Is_Ally(house))) {
  1663. house_ptr->Adjust_Threat(region, threat_value);
  1664. }
  1665. }
  1666. if (Debug_Threat) {
  1667. Map.Flag_To_Redraw(true);
  1668. }
  1669. }
  1670. /***********************************************************************************************
  1671. * CellClass::Tiberium_Adjust -- Adjust the look of the Tiberium for smoothing purposes. *
  1672. * *
  1673. * This routine will adjust the level of the Tiberium in the cell so that it will *
  1674. * smoothly blend with the adjacent Tiberium. This routine should only be called for *
  1675. * new Tiberium cells. Existing cells that contain Tiberium follow a different growth *
  1676. * pattern. *
  1677. * *
  1678. * INPUT: pregame -- Is this a pregame call? Such a call will mixup the Tiberium overlay *
  1679. * used. *
  1680. * *
  1681. * OUTPUT: Returns with the added Tiberium value that is now available for harvesting. *
  1682. * *
  1683. * WARNINGS: The return value is only valid for the initial placement. Tiberium growth will *
  1684. * increase the net worth of the existing Tiberium. *
  1685. * *
  1686. * HISTORY: *
  1687. * 05/16/1995 JLB : Created. *
  1688. *=============================================================================================*/
  1689. long CellClass::Tiberium_Adjust(bool pregame)
  1690. {
  1691. Validate();
  1692. if (Overlay != OVERLAY_NONE) {
  1693. if (OverlayTypeClass::As_Reference(Overlay).Land == LAND_TIBERIUM) {
  1694. static int _adj[9] = {0,1,3,4,6,7,8,10,11};
  1695. int count = 0;
  1696. /*
  1697. ** Mixup the Tiberium overlays so that they don't look the same.
  1698. */
  1699. if (pregame) {
  1700. Overlay = Random_Pick(OVERLAY_TIBERIUM1, OVERLAY_TIBERIUM12);
  1701. }
  1702. /*
  1703. ** Add up all adjacent cells that contain tiberium.
  1704. ** (Skip those cells which aren't on the map)
  1705. */
  1706. for (FacingType face = FACING_FIRST; face < FACING_COUNT; face++) {
  1707. CELL cell = Cell_Number() + AdjacentCell[face];
  1708. if ((unsigned)cell >= MAP_CELL_TOTAL) continue;
  1709. CellClass * adj = Adjacent_Cell(face);
  1710. if (adj && adj->Overlay != OVERLAY_NONE &&
  1711. OverlayTypeClass::As_Reference(adj->Overlay).Land == LAND_TIBERIUM) {
  1712. count++;
  1713. }
  1714. }
  1715. OverlayData = _adj[count];
  1716. return((OverlayData+1) * UnitTypeClass::TIBERIUM_STEP);
  1717. }
  1718. }
  1719. return(0);
  1720. }
  1721. /***********************************************************************************************
  1722. * CellClass::Goodie_Check -- Performs crate discovery logic. *
  1723. * *
  1724. * Call this routine whenever an object enters a cell. It will check for the existance *
  1725. * of a crate and generate any "goodie" it might contain. *
  1726. * *
  1727. * INPUT: object -- Pointer to the object that is triggering this crate. *
  1728. * *
  1729. * OUTPUT: Can the object continue to enter this cell? A false return value means that the *
  1730. * cell is now occupied and must not be entered. *
  1731. * *
  1732. * WARNINGS: none *
  1733. * *
  1734. * HISTORY: *
  1735. * 05/22/1995 JLB : Created. *
  1736. * 07/08/1995 JLB : Added a bunch of goodies to the crates. *
  1737. *=============================================================================================*/
  1738. bool CellClass::Goodie_Check(FootClass * object, bool check_steel)
  1739. {
  1740. Validate();
  1741. enum {
  1742. MONEY, // Cash award.
  1743. UNIT, // A free unit.
  1744. NUKE, // A nuclear device that explodes.
  1745. ION, // Calls forth an ion blast on discoverer.
  1746. NUKE_MISSILE, // Gets a one time nuclear missile options.
  1747. ION_BLAST, // Gets a one time ion blast option.
  1748. AIR_STRIKE, // Gets a one time air strike option.
  1749. HEAL_BASE, // Heals the player's entire base.
  1750. CLOAK, // Units in region gain cloak ability.
  1751. EXPLOSION, // Conventional explosion.
  1752. NAPALM, // A napalm explosion.
  1753. SQUAD, // A mixed squad of friendly infantry appear.
  1754. VISCEROID, // A visceroid appears!
  1755. DARKNESS, // Shroud the entire map.
  1756. REVEAL, // Reveal the entire map.
  1757. TOTAL_CRATES,
  1758. };
  1759. static int _what[] = {
  1760. DARKNESS,DARKNESS,
  1761. REVEAL,REVEAL,
  1762. NUKE,
  1763. // ION,ION,
  1764. NUKE_MISSILE,
  1765. ION_BLAST,ION_BLAST,
  1766. AIR_STRIKE,AIR_STRIKE,AIR_STRIKE,AIR_STRIKE,
  1767. HEAL_BASE,HEAL_BASE,
  1768. CLOAK,CLOAK,
  1769. EXPLOSION,EXPLOSION,EXPLOSION,EXPLOSION,
  1770. NAPALM,NAPALM,NAPALM,
  1771. SQUAD,SQUAD,SQUAD,SQUAD,SQUAD,
  1772. UNIT,UNIT,UNIT,UNIT,UNIT,
  1773. VISCEROID
  1774. };
  1775. /*
  1776. ** Crate types are only defined here so it needs to match my new global crate total ST - 6/4/96 2:16PM
  1777. */
  1778. #if (TOTAL_CRATES) == (TOTAL_CRATE_TYPES)
  1779. #else
  1780. //Huge_Errrrror..... Oh NO!
  1781. #endif
  1782. if (object && Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(Overlay).IsCrate) {
  1783. bool steel = (Overlay == OVERLAY_STEEL_CRATE);
  1784. COORDINATE coord; // Temporary working coordinate value.
  1785. if (check_steel && steel) {
  1786. /*
  1787. ** A triggered crate is automatically destroyed regardless of who or how
  1788. ** it was triggered.
  1789. */
  1790. Redraw_Objects();
  1791. Overlay = OVERLAY_NONE;
  1792. OverlayData = 0;
  1793. if (object->Owner() == HOUSE_BAD) {
  1794. object->House->Add_Nuke_Piece();
  1795. new AnimClass(ANIM_CRATE_EMPULSE, Cell_Coord());
  1796. }
  1797. } else if(!check_steel && !steel) {
  1798. /*
  1799. ** A triggered crate is automatically destroyed regardless of who or how
  1800. ** it was triggered.
  1801. */
  1802. Redraw_Objects();
  1803. Overlay = OVERLAY_NONE;
  1804. OverlayData = 0;
  1805. int index;
  1806. UnitClass * unit = 0;
  1807. unsigned damage = 0;
  1808. int what = MONEY;
  1809. if (GameToPlay != GAME_NORMAL && (Random_Pick(1, 2) == 1 || !object->House->BScan)) {
  1810. what = -1;
  1811. /*
  1812. ** If the player has a construction yeard and practically no money and no legitmate means
  1813. ** to make any more money, then give money to build a refinery.
  1814. */
  1815. if ((object->House->BScan & (STRUCTF_CONST|STRUCTF_REFINERY)) == STRUCTF_CONST &&
  1816. object->House->Available_Money() < BuildingTypeClass::As_Reference(STRUCT_REFINERY).Cost) {
  1817. what = MONEY;
  1818. }
  1819. /*
  1820. ** If the player should get an MCV replacement, then give it now (probably).
  1821. */
  1822. if (Random_Pick(0, 1) == 0 &&
  1823. MPlayerBases &&
  1824. !(object->House->UScan & UNITF_MCV) &&
  1825. object->House->BScan == 0 &&
  1826. object->House->Available_Money() > ((BuildingTypeClass::As_Reference(STRUCT_REFINERY).Cost + BuildingTypeClass::As_Reference(STRUCT_POWER).Cost) * object->House->CostBias)) {
  1827. what = UNIT;
  1828. }
  1829. bool allow_super = true;
  1830. if (GameToPlay == GAME_GLYPHX_MULTIPLAYER && !Rule.AllowSuperWeapons) {
  1831. allow_super = false;
  1832. }
  1833. while (what == -1) {
  1834. what = _what[Random_Pick((unsigned)0, sizeof(_what)/sizeof(_what[0])-1)];
  1835. if (what == REVEAL && object->House->IsVisionary) what = -1;
  1836. if (what == AIR_STRIKE && (!allow_super || object->House->AirStrike.Is_Present())) what = -1;
  1837. if (what == NUKE_MISSILE && (!allow_super || object->House->NukeStrike.Is_Present())) what = -1;
  1838. if (what == ION_BLAST && (!allow_super || object->House->IonCannon.Is_Present())) what = -1;
  1839. if (what == CLOAK && object->IsCloakable) what = -1;
  1840. }
  1841. }
  1842. /*
  1843. ** Keep track of the number of each type of crate found
  1844. */
  1845. if (GameToPlay == GAME_INTERNET){
  1846. object->House->TotalCrates->Increment_Unit_Total(what);
  1847. }
  1848. /*
  1849. ** Update the crate count and when all the crates have been discovered, flag
  1850. ** to generate a new one.
  1851. */
  1852. CrateCount--;
  1853. if (!CrateMaker && CrateCount <= 0 && GameToPlay != GAME_NORMAL) {
  1854. CrateMaker = true;
  1855. CrateTimer = 1;
  1856. }
  1857. /*
  1858. ** Create the effect requested.
  1859. */
  1860. switch (what) {
  1861. default:
  1862. /*
  1863. ** Give the player money.
  1864. */
  1865. case MONEY:
  1866. new AnimClass(ANIM_CRATE_DOLLAR, Cell_Coord());
  1867. if (GameToPlay == GAME_NORMAL) {
  1868. HouseClass::As_Pointer(object->Owner())->Refund_Money(2000);
  1869. } else {
  1870. HouseClass::As_Pointer(object->Owner())->Refund_Money(100 + (Random_Pick(0,19)*100));
  1871. }
  1872. break;
  1873. /*
  1874. ** Shroud the world in blackness.
  1875. */
  1876. case DARKNESS:
  1877. {
  1878. new AnimClass(ANIM_CRATE_EMPULSE, Cell_Coord());
  1879. bool shroud = false;
  1880. if (GameToPlay != GAME_GLYPHX_MULTIPLAYER) {
  1881. if (object->House == PlayerPtr) {
  1882. shroud = true;
  1883. }
  1884. } else {
  1885. if (object->House->IsHuman) {
  1886. shroud = true;
  1887. }
  1888. }
  1889. if (shroud) {
  1890. for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  1891. CellClass * cellptr = &Map[cell];
  1892. if (cellptr->Is_Mapped(object->House) || cellptr->Is_Visible(object->House)) {
  1893. cellptr->Redraw_Objects();
  1894. cellptr->Set_Mapped(object->House, false);
  1895. cellptr->Set_Visible(object->House, false);
  1896. }
  1897. }
  1898. HouseClass *find_house = object->House;
  1899. for (int index = 0; index < Map.Layer[LAYER_GROUND].Count(); index++) {
  1900. ObjectClass * object = Map.Layer[LAYER_GROUND][index];
  1901. if (object && object->Is_Techno() && ((TechnoClass *)object)->House == find_house) {
  1902. object->Look();
  1903. }
  1904. }
  1905. Map.Flag_To_Redraw(true);
  1906. }
  1907. break;
  1908. }
  1909. /*
  1910. ** Reveal the entire map.
  1911. */
  1912. case REVEAL:
  1913. {
  1914. bool reveal = false;
  1915. if (GameToPlay != GAME_GLYPHX_MULTIPLAYER) {
  1916. if (object->House == PlayerPtr) {
  1917. reveal = true;
  1918. }
  1919. } else {
  1920. if (object->House->IsHuman) {
  1921. reveal = true;
  1922. }
  1923. }
  1924. new AnimClass(ANIM_CRATE_EMPULSE, Cell_Coord());
  1925. object->House->IsVisionary = true;
  1926. if (reveal) {
  1927. for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
  1928. Map.Map_Cell(cell, object->House, true);
  1929. }
  1930. }
  1931. break;
  1932. }
  1933. /*
  1934. ** Try to create a unit where the crate was.
  1935. */
  1936. case UNIT: {
  1937. UnitTypeClass const * utp = NULL;
  1938. /*
  1939. ** Give the player an MCV if he has no base left but does have more than enough
  1940. ** money to rebuild a new base. Of course, if he already has an MCV, then don't
  1941. ** give him another one.
  1942. */
  1943. if (MPlayerBases &&
  1944. !(object->House->UScan & UNITF_MCV) &&
  1945. object->House->BScan == 0 &&
  1946. object->House->Available_Money() > (BuildingTypeClass::As_Reference(STRUCT_REFINERY).Cost + BuildingTypeClass::As_Reference(STRUCT_POWER).Cost)) {
  1947. utp = &UnitTypeClass::As_Reference(UNIT_MCV);
  1948. }
  1949. /*
  1950. ** If the player has a base and a refinery, but no harvester, then give him
  1951. ** a free one.
  1952. */
  1953. if (!utp && (object->House->BScan & STRUCTF_REFINERY) && !(object->House->UScan & UNITF_HARVESTER)) {
  1954. utp = &UnitTypeClass::As_Reference(UNIT_HARVESTER);
  1955. }
  1956. while (!utp) {
  1957. UnitType utype = Random_Pick(UNIT_FIRST, (UnitType)(UNIT_COUNT-1));
  1958. if (utype != UNIT_MCV || MPlayerBases) {
  1959. utp = &UnitTypeClass::As_Reference(utype);
  1960. if (utp->IsCrateGoodie && (utp->Ownable & (1 << object->Owner())) && utp->Level <= BuildLevel+2) break;
  1961. utp = NULL;
  1962. }
  1963. }
  1964. UnitClass * unit = (UnitClass *)utp->Create_One_Of(object->House);
  1965. if (unit) {
  1966. if (unit->Unlimbo(Cell_Coord())) {
  1967. return(false);
  1968. }
  1969. delete unit;
  1970. }
  1971. }
  1972. break;
  1973. /*
  1974. ** Create a squad of miscellanous composition.
  1975. */
  1976. case SQUAD:
  1977. for (index = 0; index < 5; index++) {
  1978. static InfantryType _inf[] = {
  1979. INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,INFANTRY_E1,
  1980. INFANTRY_E2,
  1981. INFANTRY_E3,
  1982. INFANTRY_E4,
  1983. INFANTRY_E5,
  1984. INFANTRY_E7,
  1985. INFANTRY_RAMBO
  1986. };
  1987. InfantryTypeClass::As_Reference(_inf[Random_Pick((unsigned)0, sizeof(_inf)/sizeof(_inf[0])-1)]).Create_And_Place(Cell_Number(), object->Owner());
  1988. }
  1989. return(false);
  1990. /*
  1991. ** Sometimes an explosion of great magnitude occurs.
  1992. */
  1993. case NUKE:
  1994. new AnimClass(ANIM_ATOM_BLAST, Cell_Coord());
  1995. break;
  1996. /*
  1997. ** Sometimes an explosion of great magnitude occurs.
  1998. */
  1999. case ION:
  2000. new AnimClass(ANIM_ION_CANNON, Cell_Coord());
  2001. break;
  2002. /*
  2003. ** A nuclear missile was discovered. Add it to the sidebar.
  2004. */
  2005. case NUKE_MISSILE:
  2006. new AnimClass(ANIM_CRATE_MISSILE, Cell_Coord());
  2007. if (object->House->NukeStrike.Enable(true)) {
  2008. // Add to Glyphx multiplayer sidebar. ST - 3/22/2019 1:50PM
  2009. if (GameToPlay == GAME_GLYPHX_MULTIPLAYER) {
  2010. if (object->House->IsHuman) {
  2011. Sidebar_Glyphx_Add(RTTI_SPECIAL, SPC_NUCLEAR_BOMB, object->House);
  2012. }
  2013. } else {
  2014. if (object->IsOwnedByPlayer) {
  2015. Map.Add(RTTI_SPECIAL, SPC_NUCLEAR_BOMB);
  2016. Map.Column[1].Flag_To_Redraw();
  2017. }
  2018. }
  2019. }
  2020. break;
  2021. /*
  2022. ** A one time ion blast was discovered. Add it to the sidebar.
  2023. */
  2024. case ION_BLAST:
  2025. new AnimClass(ANIM_CRATE_EARTH, Cell_Coord());
  2026. if (object->House->IonCannon.Enable(true)) {
  2027. // Add to Glyphx multiplayer sidebar. ST - 3/22/2019 1:50PM
  2028. if (GameToPlay == GAME_GLYPHX_MULTIPLAYER) {
  2029. if (object->House->IsHuman) {
  2030. Sidebar_Glyphx_Add(RTTI_SPECIAL, SPC_ION_CANNON, object->House);
  2031. }
  2032. } else {
  2033. if (object->IsOwnedByPlayer) {
  2034. Map.Add(RTTI_SPECIAL, SPC_ION_CANNON);
  2035. Map.Column[1].Flag_To_Redraw();
  2036. }
  2037. }
  2038. }
  2039. break;
  2040. /*
  2041. ** A one time air strike can be called int. Add it to the sidebar.
  2042. */
  2043. case AIR_STRIKE:
  2044. new AnimClass(ANIM_CRATE_DEVIATOR, Cell_Coord());
  2045. if (object->House->AirStrike.Enable(true)) {
  2046. // Add to Glyphx multiplayer sidebar. ST - 3/22/2019 1:50PM
  2047. if (GameToPlay == GAME_GLYPHX_MULTIPLAYER) {
  2048. if (object->House->IsHuman) {
  2049. Sidebar_Glyphx_Add(RTTI_SPECIAL, SPC_AIR_STRIKE, object->House);
  2050. }
  2051. } else {
  2052. if (object->IsOwnedByPlayer) {
  2053. Map.Add(RTTI_SPECIAL, SPC_AIR_STRIKE);
  2054. Map.Column[1].Flag_To_Redraw();
  2055. }
  2056. }
  2057. }
  2058. break;
  2059. /*
  2060. ** A group of explosions are triggered around the crate.
  2061. */
  2062. case EXPLOSION:
  2063. damage = 400;
  2064. object->Take_Damage((int&)damage, 0, WARHEAD_HE);
  2065. for (index = 0; index < 5; index++) {
  2066. COORDINATE coord = Coord_Scatter(Cell_Coord(), Random_Pick(0, 0x0200));
  2067. new AnimClass(ANIM_FBALL1, coord);
  2068. damage = 400;
  2069. Explosion_Damage(coord, damage, NULL, WARHEAD_HE);
  2070. }
  2071. break;
  2072. /*
  2073. ** A napalm blast is triggered.
  2074. */
  2075. case NAPALM:
  2076. coord = Coord_Mid(Cell_Coord(), object->Center_Coord());
  2077. new AnimClass(ANIM_NAPALM3, coord);
  2078. damage = 600;
  2079. Explosion_Damage(coord, damage, NULL, WARHEAD_FIRE);
  2080. break;
  2081. /*
  2082. ** A visceroid appears and, boy, he's angry!
  2083. */
  2084. case VISCEROID:
  2085. unit = new UnitClass(UNIT_VICE, HOUSE_JP);
  2086. if (unit) {
  2087. if (unit->Unlimbo(Cell_Coord())) {
  2088. return(false);
  2089. }
  2090. delete unit;
  2091. }
  2092. break;
  2093. /*
  2094. ** All objects within a certain range will gain the ability to cloak.
  2095. */
  2096. case CLOAK:
  2097. new AnimClass(ANIM_CRATE_STEALTH, Cell_Coord());
  2098. for (index = 0; index < Map.Layer[LAYER_GROUND].Count(); index++) {
  2099. ObjectClass * obj = Map.Layer[LAYER_GROUND][index];
  2100. if (obj && obj->Is_Techno() && Distance(Cell_Coord(), obj->Center_Coord()) < 0x0300) {
  2101. ((TechnoClass *)obj)->IsCloakable = true;
  2102. }
  2103. }
  2104. break;
  2105. /*
  2106. ** All of the player's objects heal up.
  2107. */
  2108. case HEAL_BASE:
  2109. new AnimClass(ANIM_CRATE_INVUN, Cell_Coord());
  2110. for (index = 0; index < Logic.Count(); index++) {
  2111. ObjectClass * obj = Logic[index];
  2112. if (obj && object->Is_Techno() && object->House->Class->House == obj->Owner()) {
  2113. obj->Strength = obj->Class_Of().MaxStrength;
  2114. }
  2115. }
  2116. break;
  2117. }
  2118. }
  2119. }
  2120. return(true);
  2121. }
  2122. /***********************************************************************************************
  2123. * CellClass::Flag_Place -- Places a house flag down on the cell. *
  2124. * *
  2125. * This routine will place the house flag at this cell location. *
  2126. * *
  2127. * INPUT: house -- The house that is having its flag placed here. *
  2128. * *
  2129. * OUTPUT: Was the flag successfully placed here? *
  2130. * *
  2131. * WARNINGS: Failure to place means that the cell is impassable for some reason. *
  2132. * *
  2133. * HISTORY: *
  2134. * 05/23/1995 JLB : Created. *
  2135. *=============================================================================================*/
  2136. bool CellClass::Flag_Place(HousesType house)
  2137. {
  2138. Validate();
  2139. if (!IsFlagged && Is_Generally_Clear()) {
  2140. IsFlagged = true;
  2141. Owner = house;
  2142. Flag_Update();
  2143. Redraw_Objects();
  2144. return(true);
  2145. }
  2146. return(false);
  2147. }
  2148. /***********************************************************************************************
  2149. * CellClass::Flag_Remove -- Removes the house flag from the cell. *
  2150. * *
  2151. * This routine will free the cell of any house flag that may be located there. *
  2152. * *
  2153. * INPUT: none *
  2154. * *
  2155. * OUTPUT: Was there a flag here that was removed? *
  2156. * *
  2157. * WARNINGS: none *
  2158. * *
  2159. * HISTORY: *
  2160. * 05/23/1995 JLB : Created. *
  2161. *=============================================================================================*/
  2162. bool CellClass::Flag_Remove(void)
  2163. {
  2164. Validate();
  2165. if (IsFlagged) {
  2166. IsFlagged = false;
  2167. Owner = HOUSE_NONE;
  2168. Flag_Update();
  2169. Redraw_Objects();
  2170. return(true);
  2171. }
  2172. return(false);
  2173. }
  2174. void CellClass::Flag_Update(void)
  2175. {
  2176. if (IsFlagged && !CTFFlag) {
  2177. Flag_Create();
  2178. } else if (!IsFlagged && CTFFlag) {
  2179. Flag_Destroy();
  2180. }
  2181. }
  2182. void CellClass::Flag_Create(void)
  2183. {
  2184. if (!CTFFlag) {
  2185. CTFFlag = new AnimClass(ANIM_FLAG, Cell_Coord(), 0, 1, true);
  2186. if (CTFFlag == NULL) {
  2187. for (int i = 0; i < Anims.Count(); ++i) {
  2188. AnimClass* anim = Anims.Ptr(i);
  2189. if (*anim != ANIM_FLAG) {
  2190. anim->Delete_This();
  2191. break;
  2192. }
  2193. }
  2194. CTFFlag = new AnimClass(ANIM_FLAG, Cell_Coord(), 0, 1, true);
  2195. }
  2196. assert(CTFFlag != NULL);
  2197. CTFFlag->Set_Owner(Owner);
  2198. }
  2199. }
  2200. void CellClass::Flag_Destroy(void)
  2201. {
  2202. delete CTFFlag;
  2203. CTFFlag = NULL;
  2204. }
  2205. /***********************************************************************************************
  2206. * CellClass::Shimmer -- Causes all objects in the cell to shimmer. *
  2207. * *
  2208. * This routine is called when some event would cause a momentary disruption in the *
  2209. * cloaking device. All objects that are cloaked in the cell will have their cloaking *
  2210. * device shimmer. *
  2211. * *
  2212. * INPUT: none *
  2213. * *
  2214. * OUTPUT: none *
  2215. * *
  2216. * WARNINGS: none *
  2217. * *
  2218. * HISTORY: *
  2219. * 07/29/1995 JLB : Created. *
  2220. *=============================================================================================*/
  2221. void CellClass::Shimmer(void)
  2222. {
  2223. Validate();
  2224. ObjectClass * object = Cell_Occupier();
  2225. while (object) {
  2226. object->Do_Shimmer();
  2227. object = object->Next;
  2228. }
  2229. }
  2230. /***********************************************************************************************
  2231. * CellClass::Cell_Occupier -- Fetches the occupier for the cell. *
  2232. * *
  2233. * This routine returns with the first recorded occupier of this cell. A special validity *
  2234. * check is performed to ensure that there are no dead objects still marked on the *
  2235. * map. *
  2236. * *
  2237. * INPUT: none *
  2238. * *
  2239. * OUTPUT: Returns with a pointer to the first occupier object. *
  2240. * *
  2241. * WARNINGS: none *
  2242. * *
  2243. * HISTORY: *
  2244. * 08/17/1995 JLB : Created. *
  2245. *=============================================================================================*/
  2246. ObjectClass * CellClass::Cell_Occupier(void) const
  2247. {
  2248. ObjectClass * ptr = OccupierPtr;
  2249. while (ptr && !ptr->IsActive) {
  2250. ptr = ptr->Next;
  2251. ((ObjectClass *&)OccupierPtr) = 0;
  2252. }
  2253. return(ptr);
  2254. }
  2255. /*
  2256. ** Additions to CellClass to track visibility per-player. ST - 3/5/2019 3:08PM
  2257. **
  2258. **
  2259. **
  2260. **
  2261. **
  2262. */
  2263. /***********************************************************************************************
  2264. * CellClass::Set_Mapped -- Set the cell mapped for the given player *
  2265. * *
  2266. * *
  2267. * HISTORY: *
  2268. * 3/5/2019 3:09PM - ST *
  2269. *=============================================================================================*/
  2270. void CellClass::Set_Mapped(HousesType house, bool set)
  2271. {
  2272. int shift = (int) house;
  2273. if (set) {
  2274. IsMappedByPlayerMask |= (1 << shift);
  2275. } else {
  2276. IsMappedByPlayerMask &= ~(1 << shift);
  2277. }
  2278. }
  2279. /***********************************************************************************************
  2280. * CellClass::Set_Mapped -- Set the cell mapped for the given player *
  2281. * *
  2282. * *
  2283. * HISTORY: *
  2284. * 3/5/2019 3:09PM - ST *
  2285. *=============================================================================================*/
  2286. void CellClass::Set_Mapped(HouseClass *player, bool set)
  2287. {
  2288. if (player && player->Class) {
  2289. Set_Mapped(player->Class->House, set);
  2290. if (GameToPlay == GAME_NORMAL && player->IsHuman) {
  2291. IsMapped = set; // Also set the regular flag in single player
  2292. }
  2293. }
  2294. }
  2295. /***********************************************************************************************
  2296. * CellClass::Is_Mapped -- Is the cell mapped for the given player *
  2297. * *
  2298. * *
  2299. * HISTORY: *
  2300. * 3/5/2019 3:13PM - ST *
  2301. *=============================================================================================*/
  2302. bool CellClass::Is_Mapped(HousesType house) const
  2303. {
  2304. int shift = (int) house;
  2305. return (IsMappedByPlayerMask & (1 << shift)) ? true : false;
  2306. }
  2307. /***********************************************************************************************
  2308. * CellClass::Is_Mapped -- Is the cell mapped for the given player *
  2309. * *
  2310. * *
  2311. * HISTORY: *
  2312. * 3/5/2019 3:13PM - ST *
  2313. *=============================================================================================*/
  2314. bool CellClass::Is_Mapped(HouseClass *player) const
  2315. {
  2316. if (player && player->Class) {
  2317. return Is_Mapped(player->Class->House);
  2318. }
  2319. return false;
  2320. }
  2321. /***********************************************************************************************
  2322. * CellClass::Set_Visible -- Set the cell visible for the given player *
  2323. * *
  2324. * *
  2325. * HISTORY: *
  2326. * 3/5/2019 3:16PM - ST *
  2327. *=============================================================================================*/
  2328. void CellClass::Set_Visible(HousesType house, bool set)
  2329. {
  2330. int shift = (int) house;
  2331. if (set) {
  2332. IsVisibleByPlayerMask |= (1 << shift);
  2333. } else {
  2334. IsVisibleByPlayerMask &= ~(1 << shift);
  2335. }
  2336. }
  2337. /***********************************************************************************************
  2338. * CellClass::Set_Visible -- Set the cell visible for the given player *
  2339. * *
  2340. * *
  2341. * HISTORY: *
  2342. * 3/5/2019 3:16PM - ST *
  2343. *=============================================================================================*/
  2344. void CellClass::Set_Visible(HouseClass *player, bool set)
  2345. {
  2346. if (player && player->Class) {
  2347. Set_Visible(player->Class->House, set);
  2348. if (GameToPlay == GAME_NORMAL && player->IsHuman) {
  2349. IsVisible = set; // Also set the regular flag in single player. This is needed for rendering
  2350. }
  2351. }
  2352. }
  2353. /***********************************************************************************************
  2354. * CellClass::Is_Visible -- Is the cell visible for the given player *
  2355. * *
  2356. * *
  2357. * HISTORY: *
  2358. * 3/5/2019 3:16PM - ST *
  2359. *=============================================================================================*/
  2360. bool CellClass::Is_Visible(HousesType house) const
  2361. {
  2362. int shift = (int) house;
  2363. return (IsVisibleByPlayerMask & (1 << shift)) ? true : false;
  2364. }
  2365. /***********************************************************************************************
  2366. * CellClass::Is_Visible -- Is the cell visible for the given player *
  2367. * *
  2368. * *
  2369. * HISTORY: *
  2370. * 3/5/2019 3:16PM - ST *
  2371. *=============================================================================================*/
  2372. bool CellClass::Is_Visible(HouseClass *player) const
  2373. {
  2374. if (player && player->Class) {
  2375. return Is_Visible(player->Class->House);
  2376. }
  2377. return false;
  2378. }
  2379. void CellClass::Override_Land_Type(LandType type)
  2380. {
  2381. OverrideLand = type;
  2382. }
  2383. #ifdef USE_RA_AI
  2384. /*
  2385. ** Addition from Red Alert for AI. ST - 7/24/2019 5:33PM
  2386. */
  2387. /***********************************************************************************************
  2388. * CellClass::Is_Clear_To_Move -- Determines if the cell is generally clear for travel *
  2389. * *
  2390. * This routine is called when determining general passability for purposes of zone *
  2391. * calculation. Only blockages that cannot be circumvented are considered to make a cell *
  2392. * impassable. All other obstructions can either be destroyed or are temporary. *
  2393. * *
  2394. * INPUT: loco -- The locomotion type to use when determining passablility. *
  2395. * *
  2396. * ignoreinfantry -- Should infantry in the cell be ignored for movement purposes? *
  2397. * *
  2398. * ignorevehicles -- If vehicles should be ignored, then this flag will be true. *
  2399. * *
  2400. * zone -- If specified, the zone must match this value or else movement is *
  2401. * presumed disallowed. *
  2402. * *
  2403. * check -- This specifies the zone type that this check applies to. *
  2404. * *
  2405. * OUTPUT: Is the cell generally passable to ground targeting? *
  2406. * *
  2407. * WARNINGS: none *
  2408. * *
  2409. * HISTORY: *
  2410. * 09/25/1995 JLB : Created. *
  2411. * 06/25/1996 JLB : Uses tracked vehicles as a basis for zone check. *
  2412. * 10/05/1996 JLB : Allows checking for crushable blockages. *
  2413. *=============================================================================================*/
  2414. bool CellClass::Is_Clear_To_Move(bool ignoreinfantry, bool ignorevehicles) const
  2415. {
  2416. //assert((unsigned)Cell_Number() <= MAP_CELL_TOTAL);
  2417. /*
  2418. ** Flying objects always consider every cell passable since they can fly over everything.
  2419. */
  2420. //if (loco == SPEED_WINGED) {
  2421. // return(true);
  2422. //}
  2423. /*
  2424. ** If a zone was specified, then see if the cell is in a legal
  2425. ** zone to allow movement.
  2426. */
  2427. //if (zone != -1) {
  2428. // if (zone != Zones[check]) {
  2429. // return(false);
  2430. // }
  2431. //}
  2432. /*
  2433. ** Check the occupy bits for passable legality. If ignore infantry is true, then
  2434. ** don't consider infnatry.
  2435. */
  2436. int composite = Flag.Composite;
  2437. if (ignoreinfantry) {
  2438. composite &= 0xE0; // Drop the infantry occupation bits.
  2439. }
  2440. if (ignorevehicles) {
  2441. composite &= 0x5F; // Drop the vehicle/building bit.
  2442. }
  2443. if (composite != 0) {
  2444. return(false);
  2445. }
  2446. /*
  2447. ** Fetch the land type of the cell -- to be modified and used later.
  2448. */
  2449. //LandType land = Land_Type();
  2450. /*
  2451. ** Walls are always considered to block the terrain for general passability
  2452. ** purposes unless this is a wall crushing check or if the checking object
  2453. ** can destroy walls.
  2454. */
  2455. OverlayTypeClass const * overlay = NULL;
  2456. if (Overlay != OVERLAY_NONE) {
  2457. overlay = &OverlayTypeClass::As_Reference(Overlay);
  2458. }
  2459. if (overlay != NULL && overlay->IsWall) {
  2460. //if (check != MZONE_DESTROYER && (check != MZONE_CRUSHER || !overlay->IsCrushable)) {
  2461. return(false);
  2462. //}
  2463. /*
  2464. ** Crushing objects consider crushable walls as clear rather than the
  2465. ** typical LAND_WALL setting.
  2466. */
  2467. //land = LAND_CLEAR;
  2468. }
  2469. /*
  2470. ** See if the ground type is impassable to this locomotion type and if
  2471. ** so, return the error condition.
  2472. */
  2473. //if (::Ground[land].Cost[loco] == 0) {
  2474. // return(false);
  2475. //}
  2476. /*
  2477. ** All checks passed, so this cell must be passable.
  2478. */
  2479. return(true);
  2480. }
  2481. #endif //USE_RA_AI