OBJECT.CPP 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\object.cpv 2.17 16 Oct 1995 16:49:22 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : OBJECT.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 29, 1994 *
  30. * *
  31. * Last Update : August 13, 1995 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * ObjectClass::Debug_Dump -- Displays status of the object class to the mono monitor. *
  36. * ObjectClass::Detach_All -- Removes the object from all tracking systems. *
  37. * ObjectClass::Detach_This_From_All -- Detatches this object from all others. *
  38. * ObjectClass::Fire_Out -- Informs object that attached animation has finished. *
  39. * ObjectClass::Get_Mission -- Fetches the current mission of this object. *
  40. * ObjectClass::Init -- Initializes the basic object system. *
  41. * ObjectClass::Limbo -- Brings the object into a state of limbo. *
  42. * ObjectClass::Mark -- Handles basic marking logic. *
  43. * ObjectClass::Mark_For_Redraw -- Marks object and system for redraw. *
  44. * ObjectClass::Move -- Moves (by force) the object in the desired direction. *
  45. * ObjectClass::ObjectClass -- Default constructor for objects. *
  46. * ObjectClass::Passive_Click_With -- Right mouse button click process. *
  47. * ObjectClass::Receive_Message -- Processes an incoming radio message. *
  48. * ObjectClass::Render -- Displays the object onto the map. *
  49. * ObjectClass::Repair -- Handles object repair control. *
  50. * ObjectClass::Revealed -- Reveals this object to the house specified. *
  51. * ObjectClass::Select -- Try to make this object the "selected" object. *
  52. * ObjectClass::Sell_Back -- Sells the object -- if possible. *
  53. * ObjectClass::Take_Damage -- Applies damage to the object. *
  54. * ObjectClass::Unlimbo -- Brings the object into the game system. *
  55. * ObjectClass::Unselect -- This will un-select the object if it was selected. *
  56. * ObjectClass::Value -- Fetches the target value of this object. *
  57. * ObjectClass::What_Action -- Deteremines what action to perform on specified object. *
  58. * ObjectClass::What_Am_I -- RTTI query of this object type. *
  59. * ObjectTypeClass::Cost_Of -- Returns the cost to buy this unit. *
  60. * ObjectTypeClass::Dimensions -- Gets the dimensions of the object in pixels. *
  61. * ObjectTypeClass::Get_Cameo_Data -- Fetches pointer to cameo data for this object type. *
  62. * ObjectTypeClass::Max_Pips -- Fetches the maximum pips allowed for this object. *
  63. * ObjectTypeClass::ObjectTypeClass -- Normal constructor for object type class objects. *
  64. * ObjectTypeClass::Occupy_List -- Returns with simple occupation list for object. *
  65. * ObjectTypeClass::One_Time -- Handles one time processing for object types. *
  66. * ObjectTypeClass::Overlap_List -- Returns a pointer to a simple overlap list. *
  67. * ObjectTypeClass::Time_To_Build -- Fetches the time to construct this object. *
  68. * ObjectTypeClass::Who_Can_Build_Me -- Finds the factory building that can build this object*
  69. * ObjectClass::What_Action -- Returns with the action to perform for this object. *
  70. * ObjectClass::In_Which_Layer -- Fetches what layer this object is located in. *
  71. * ObjectClass::Is_Techno -- Checks to see if this object is a techno type. *
  72. * ObjectClass::Get_Ownable -- Fetches the house owner legality options for this object. *
  73. * ObjectClass::Can_Repair -- Queries whether this object can be repaired. *
  74. * ObjectClass::Can_Demolish -- Queries whether this object can be sold back. *
  75. * ObjectClass::Can_Player_Fire -- Can the player give this object an attack mission? *
  76. * ObjectClass::Can_Player_Move -- Can the player give this object a movement mission? *
  77. * ObjectClass::Target_Coord -- Fetches the coordinate if this object is a target. *
  78. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  79. #include "function.h"
  80. /*
  81. ** Selected objects have a special marking box around them. This is the shapes that are
  82. ** used for this purpose.
  83. */
  84. void const * ObjectTypeClass::SelectShapes = 0;
  85. void const * ObjectTypeClass::PipShapes = 0;
  86. bool ObjectClass::Is_Infantry(void) const
  87. {
  88. return(false);
  89. }
  90. /***********************************************************************************************
  91. * ObjectTypeClass::ObjectTypeClass -- Normal constructor for object type class objects. *
  92. * *
  93. * This is the base constructor that is used when constructing the object type classes. *
  94. * Every tangible game piece type calls this constructor for the ObjectTypeClass. This *
  95. * class holds static information that is common to objects in general. *
  96. * *
  97. * INPUT: see below... *
  98. * *
  99. * OUTPUT: none *
  100. * *
  101. * WARNINGS: none *
  102. * *
  103. * HISTORY: *
  104. * 03/23/1995 JLB : Created. *
  105. *=============================================================================================*/
  106. ObjectTypeClass::ObjectTypeClass(
  107. bool is_sentient,
  108. bool is_flammable,
  109. bool is_crushable,
  110. bool is_stealthy,
  111. bool is_selectable,
  112. bool is_legal_target,
  113. bool is_insignificant,
  114. bool is_immune,
  115. int name,
  116. char const *ini,
  117. ArmorType armor,
  118. unsigned short strength) :
  119. AbstractTypeClass(name, ini)
  120. {
  121. IsSentient = is_sentient;
  122. IsFlammable = is_flammable;
  123. IsCrushable = is_crushable;
  124. IsStealthy = is_stealthy;
  125. IsSelectable = is_selectable;
  126. IsLegalTarget = is_legal_target;
  127. IsInsignificant = is_insignificant;
  128. IsImmune = is_immune;
  129. Armor = armor;
  130. MaxStrength = strength;
  131. ImageData = NULL;
  132. //RadarIcon = NULL;
  133. }
  134. /***********************************************************************************************
  135. * ObjectTypeClass::Max_Pips -- Fetches the maximum pips allowed for this object. *
  136. * *
  137. * This routine will return the maximum number of pips that can be displayed for this *
  138. * object. When dealing with generic objects, this value is always zero. *
  139. * *
  140. * INPUT: none *
  141. * *
  142. * OUTPUT: Returns with the number of pip boxes (empty or otherwise) to display. *
  143. * *
  144. * WARNINGS: none *
  145. * *
  146. * HISTORY: *
  147. * 07/19/1995 JLB : Created. *
  148. *=============================================================================================*/
  149. int ObjectTypeClass::Max_Pips(void) const
  150. {
  151. return(0);
  152. }
  153. /***********************************************************************************************
  154. * ObjectTypeClass::Dimensions -- Gets the dimensions of the object in pixels. *
  155. * *
  156. * This routine will fetch the dimensions of this object expressed as pixels width and *
  157. * pixels height. This information can be used to intelligently update the clipping *
  158. * rectangles. *
  159. * *
  160. * INPUT: width -- Reference to the width variable that will be filled in. *
  161. * *
  162. * height -- Reference to the height variable that will be filled in. *
  163. * *
  164. * OUTPUT: none *
  165. * *
  166. * WARNINGS: none *
  167. * *
  168. * HISTORY: *
  169. * 07/19/1995 JLB : Created. *
  170. *=============================================================================================*/
  171. void ObjectTypeClass::Dimensions(int &width, int &height) const
  172. {
  173. width = 10;
  174. height = 10;
  175. }
  176. /***********************************************************************************************
  177. * ObjectTypeClass::Cost_Of -- Returns the cost to buy this unit. *
  178. * *
  179. * This routine will return the cost to purchase this unit. This routine is expected to be *
  180. * overridden by the objects that can actually be purchased. All other object types can *
  181. * simply return zero since this value won't be used. *
  182. * *
  183. * INPUT: none *
  184. * *
  185. * OUTPUT: Returns the cost of the object. *
  186. * *
  187. * WARNINGS: none *
  188. * *
  189. * HISTORY: *
  190. * 07/19/1995 JLB : Created. *
  191. *=============================================================================================*/
  192. int ObjectTypeClass::Cost_Of(void) const
  193. {
  194. return(0);
  195. }
  196. /***********************************************************************************************
  197. * ObjectTypeClass::Time_To_Build -- Fetches the time to construct this object. *
  198. * *
  199. * This routine will fetch the time in takes to construct this object. Objects that can *
  200. * be constructed will override this routine in order to return a useful value. *
  201. * *
  202. * INPUT: none *
  203. * *
  204. * OUTPUT: Returns with the time units (arbitrary) that it takes to construct this object. *
  205. * *
  206. * WARNINGS: none *
  207. * *
  208. * HISTORY: *
  209. * 07/19/1995 JLB : Created. *
  210. *=============================================================================================*/
  211. int ObjectTypeClass::Time_To_Build(HousesType ) const
  212. {
  213. return(0);
  214. }
  215. /***********************************************************************************************
  216. * ObjectTypeClass::Who_Can_Build_Me -- Finds the factory building that can build this object. *
  217. * *
  218. * This routine will search for a factory building that can build this object type. *
  219. * *
  220. * INPUT: <NA> this routine is just here to be overridden by other classes. *
  221. * *
  222. * OUTPUT: Returns with a pointer to the building that can construct the object specified. *
  223. * *
  224. * WARNINGS: none *
  225. * *
  226. * HISTORY: *
  227. * 07/19/1995 JLB : Created. *
  228. *=============================================================================================*/
  229. BuildingClass * ObjectTypeClass::Who_Can_Build_Me(bool, bool, HousesType) const
  230. {
  231. return(NULL);
  232. }
  233. /***********************************************************************************************
  234. * ObjectTypeClass::Get_Cameo_Data -- Fetches pointer to cameo data for this object type. *
  235. * *
  236. * This routine will return with the cameo data pointer for this object type. It is *
  237. * expected that objects that can appear on the sidebar will override this routine in order *
  238. * to provide proper cameo data pointer. *
  239. * *
  240. * INPUT: none *
  241. * *
  242. * OUTPUT: Returns with a pointer to the cameo shape data. *
  243. * *
  244. * WARNINGS: none *
  245. * *
  246. * HISTORY: *
  247. * 07/19/1995 JLB : Created. *
  248. *=============================================================================================*/
  249. void const * ObjectTypeClass::Get_Cameo_Data(void) const
  250. {
  251. return(NULL);
  252. }
  253. /***********************************************************************************************
  254. * ObjectClass::ObjectClass -- Default constructor for objects. *
  255. * *
  256. * This is the default constructor for objects. It is called as an inherent part of the *
  257. * construction process for all the normal game objects instantiated. It serves merely to *
  258. * initialize the object values to a common (default) state. *
  259. * *
  260. * INPUT: none *
  261. * *
  262. * OUTPUT: none *
  263. * *
  264. * WARNINGS: Objects always start in a state of limbo. They must be Unlimbo()ed before they *
  265. * can be used. *
  266. * *
  267. * HISTORY: *
  268. * 09/24/1994 JLB : Created. *
  269. *=============================================================================================*/
  270. ObjectClass::ObjectClass(void)
  271. {
  272. Coord = 0xFFFFFFFFL; // Some bogus illegal value.
  273. Next = 0; // Not part of any object list.
  274. Trigger = 0; // No associated trigger.
  275. IsToDamage = false;
  276. IsToDisplay = false; // Redraw is presumed unnecessary.
  277. IsInLimbo = true; // Always presumed to start in limbo state.
  278. IsSelected = false; // Limboed units cannot be selected.
  279. IsDown = false; // Limboed units cannot be on the map.
  280. IsAnimAttached = false; // Anim is not attached.
  281. Strength = 255; // nominal strength value
  282. }
  283. /***********************************************************************************************
  284. * ObjectClass::What_Am_I -- RTTI query of this object type. *
  285. * *
  286. * This routine will never be called, but is here for completeness. Every object that *
  287. * is derived from object class must overload this function and return their own proper *
  288. * object RTTI value. *
  289. * *
  290. * INPUT: none *
  291. * *
  292. * OUTPUT: Returns with the RTTI value that coresponds to the object's type. *
  293. * *
  294. * WARNINGS: none *
  295. * *
  296. * HISTORY: *
  297. * 07/19/1995 JLB : Created. *
  298. *=============================================================================================*/
  299. RTTIType ObjectClass::What_Am_I(void) const
  300. {
  301. return(RTTI_OBJECT);
  302. }
  303. /***********************************************************************************************
  304. * ObjectClass::What_Action -- Deteremines what action to perform on specified object. *
  305. * *
  306. * This routine will return that action that this object could perform if the mouse were *
  307. * clicked over the object specified. *
  308. * *
  309. * INPUT: object -- Pointer to the object to check this object against when determining *
  310. * the action to perform. *
  311. * *
  312. * OUTPUT: It returns that action that will be performed if the mouse were clicked over the *
  313. * object. Since non-derived objects cannot do anything, and cannot even be *
  314. * instantiated, this routine will always return ACTION_NONE. *
  315. * *
  316. * WARNINGS: none *
  317. * *
  318. * HISTORY: *
  319. * 07/19/1995 JLB : Created. *
  320. *=============================================================================================*/
  321. ActionType ObjectClass::What_Action(ObjectClass *) const
  322. {
  323. return(ACTION_NONE);
  324. }
  325. /***********************************************************************************************
  326. * ObjectClass::What_Action -- Returns with the action to perform for this object. *
  327. * *
  328. * This routine is called when information on a potential action if the mouse were clicked *
  329. * on the cell specified. This routine merely serves as a virtual placeholder so that *
  330. * object types that can actually perform some action will override this routine to provide *
  331. * true functionality. *
  332. * *
  333. * INPUT: cell -- The cell that the mouse is over and might be clicked on. *
  334. * *
  335. * OUTPUT: Returns with the action that this object would try to perform if the mouse were *
  336. * clicked. Since objects at this level have no ability to do anything, this routine *
  337. * will always returns ACTION_NONE unless it is overridden. *
  338. * *
  339. * WARNINGS: none *
  340. * *
  341. * HISTORY: *
  342. * 08/13/1995 JLB : Created. *
  343. *=============================================================================================*/
  344. ActionType ObjectClass::What_Action(CELL) const
  345. {
  346. return(ACTION_NONE);
  347. }
  348. /***********************************************************************************************
  349. * ObjectClass::In_Which_Layer -- Fetches what layer this object is located in. *
  350. * *
  351. * The default layer for object location is the LAYER_GROUND. Aircraft will override this *
  352. * routine and make adjustments as necessary according to the aircraft's altitude. *
  353. * *
  354. * INPUT: none *
  355. * *
  356. * OUTPUT: Returns with the layer that this object is located in. *
  357. * *
  358. * WARNINGS: none *
  359. * *
  360. * HISTORY: *
  361. * 08/13/1995 JLB : Created. *
  362. *=============================================================================================*/
  363. LayerType ObjectClass::In_Which_Layer(void) const
  364. {
  365. return(LAYER_GROUND);
  366. }
  367. /***********************************************************************************************
  368. * ObjectClass::Is_Techno -- Checks to see if this object is a techno type. *
  369. * *
  370. * Most active objects in the game are of the techno type. This routine will return true *
  371. * if called on an object that is derived from TechnoClass. The RTTI interface is *
  372. * insufficient for this purpose -- hence the existence of this routine. *
  373. * *
  374. * INPUT: none *
  375. * *
  376. * OUTPUT: Is this object derived from the TechnoClass object? This is true for units, *
  377. * infantry, aircraft, and buildings. *
  378. * *
  379. * WARNINGS: none *
  380. * *
  381. * HISTORY: *
  382. * 08/13/1995 JLB : Created. *
  383. *=============================================================================================*/
  384. bool ObjectClass::Is_Techno(void) const
  385. {
  386. return(false);
  387. }
  388. /***********************************************************************************************
  389. * ObjectClass::Get_Ownable -- Fetches the house owner legality options for this object. *
  390. * *
  391. * This routine will return the ownable bits for this object. Objects at this level can't *
  392. * really be owned by anyone, but return the full spectrum of legality just to be safe. *
  393. * *
  394. * INPUT: none *
  395. * *
  396. * OUTPUT: Returns with the ownable flags (as a combined bitfield) for this object. *
  397. * *
  398. * WARNINGS: none *
  399. * *
  400. * HISTORY: *
  401. * 08/13/1995 JLB : Created. *
  402. *=============================================================================================*/
  403. unsigned char ObjectClass::Get_Ownable(void) const
  404. {
  405. return(0xff);
  406. }
  407. /***********************************************************************************************
  408. * ObjectClass::Can_Repair -- Queries whether this object can be repaired. *
  409. * *
  410. * Most objects cannot be repaired. This routine defaults to returning "false", but is *
  411. * overridden by derived functions defined by object types that can support repair. *
  412. * *
  413. * INPUT: none *
  414. * *
  415. * OUTPUT: Can this object be repaired? *
  416. * *
  417. * WARNINGS: none *
  418. * *
  419. * HISTORY: *
  420. * 08/13/1995 JLB : Created. *
  421. *=============================================================================================*/
  422. bool ObjectClass::Can_Repair(void) const
  423. {
  424. return(false);
  425. }
  426. /***********************************************************************************************
  427. * ObjectClass::Can_Demolish -- Queries whether this object can be sold back. *
  428. * *
  429. * This routine is used to determine if this object can be sold. Most objects cannot be *
  430. * but for those objects that can, this routine will be overridden as necessary. *
  431. * *
  432. * INPUT: none *
  433. * *
  434. * OUTPUT: Can this object be sold back? Typically, the answer is no. *
  435. * *
  436. * WARNINGS: none *
  437. * *
  438. * HISTORY: *
  439. * 08/13/1995 JLB : Created. *
  440. *=============================================================================================*/
  441. bool ObjectClass::Can_Demolish(void) const
  442. {
  443. return(false);
  444. }
  445. /***********************************************************************************************
  446. * ObjectClass::Can_Player_Fire -- Can the player give this object an attack mission? *
  447. * *
  448. * This routine is used to determine if attacking is an option under player control with *
  449. * respect to this unit. This routine will be overridden as necessary for those objects *
  450. * that have the ability to attack. *
  451. * *
  452. * INPUT: none *
  453. * *
  454. * OUTPUT: Can this object be given an attack order by the player? *
  455. * *
  456. * WARNINGS: none *
  457. * *
  458. * HISTORY: *
  459. * 08/13/1995 JLB : Created. *
  460. *=============================================================================================*/
  461. bool ObjectClass::Can_Player_Fire(void) const
  462. {
  463. return(false);
  464. }
  465. /***********************************************************************************************
  466. * ObjectClass::Can_Player_Move -- Can the player give this object a movement mission? *
  467. * *
  468. * This routine is used to determine if the player has the ability to command this object *
  469. * with a movement mission. This routine will be overridden as necessary to support this *
  470. * ability. *
  471. * *
  472. * INPUT: none *
  473. * *
  474. * OUTPUT: Can this object be given a movement mission by the player? *
  475. * *
  476. * WARNINGS: none *
  477. * *
  478. * HISTORY: *
  479. * 08/13/1995 JLB : Created. *
  480. *=============================================================================================*/
  481. bool ObjectClass::Can_Player_Move(void) const
  482. {
  483. return(false);
  484. }
  485. /***********************************************************************************************
  486. * ObjectClass::Target_Coord -- Fetches the coordinate if this object is a target. *
  487. * *
  488. * When the coordinate to use when firing at this object is needed, this routine will *
  489. * provide it. Normal objects just use the center of the object for this, but there are *
  490. * some more sophisticated objects that are not fired upon the center. *
  491. * *
  492. * INPUT: none *
  493. * *
  494. * OUTPUT: Returns with the coordinate to fire at if this object is a target. *
  495. * *
  496. * WARNINGS: none *
  497. * *
  498. * HISTORY: *
  499. * 08/13/1995 JLB : Created. *
  500. *=============================================================================================*/
  501. COORDINATE ObjectClass::Target_Coord(void) const
  502. {
  503. return(Center_Coord());
  504. }
  505. COORDINATE ObjectClass::Center_Coord(void) const {return Coord;};
  506. COORDINATE ObjectClass::Render_Coord(void) const {return(Center_Coord());}
  507. COORDINATE ObjectClass::Docking_Coord(void) const {return(Center_Coord());}
  508. COORDINATE ObjectClass::Sort_Y(void) const {return Coord;};
  509. COORDINATE ObjectClass::Fire_Coord(int ) const {return Coord;};
  510. void ObjectClass::Record_The_Kill(TechnoClass * ) {};
  511. void ObjectClass::Do_Shimmer(void) {};
  512. int ObjectClass::Exit_Object(TechnoClass *) {return 0;};
  513. void ObjectClass::Hidden(void) {};
  514. void ObjectClass::Look(bool ) {};
  515. void ObjectClass::Active_Click_With(ActionType , ObjectClass *) {};
  516. void ObjectClass::Active_Click_With(ActionType , CELL ) {};
  517. void ObjectClass::Clicked_As_Target(int) {};
  518. bool ObjectClass::In_Range(COORDINATE , int) const {return false;};
  519. int ObjectClass::Weapon_Range(int) const {return 0x0000;};
  520. TARGET ObjectClass::As_Target(void) const {return TARGET_NONE;};
  521. void ObjectClass::Scatter(COORDINATE , bool) {};
  522. bool ObjectClass::Catch_Fire(void) {return false;};
  523. /***********************************************************************************************
  524. * ObjectClass::Fire_Out -- Informs object that attached animation has finished. *
  525. * *
  526. * This routine is called if there is an attached animation on this object and that *
  527. * animation has finished. Typically, this is necessary for when trees are on fire. *
  528. * *
  529. * INPUT: none *
  530. * *
  531. * OUTPUT: none *
  532. * *
  533. * WARNINGS: none *
  534. * *
  535. * HISTORY: *
  536. * 07/24/1995 JLB : Created. *
  537. *=============================================================================================*/
  538. void ObjectClass::Fire_Out(void)
  539. {
  540. }
  541. /***********************************************************************************************
  542. * ObjectClass::Value -- Fetches the target value of this object. *
  543. * *
  544. * This routine will return the target value of this object. The higher the number, the *
  545. * better the object will be as a target. This routine is called when searching for *
  546. * targets. Generic objects have no target potential, and this routine returns zero to *
  547. * reflect that. Other object types will override this routine to return the appropriate *
  548. * target value. *
  549. * *
  550. * INPUT: none *
  551. * *
  552. * OUTPUT: Returns with the value of this object as a target. Higher values mean better *
  553. * target. *
  554. * *
  555. * WARNINGS: none *
  556. * *
  557. * HISTORY: *
  558. * 07/24/1995 JLB : Created. *
  559. *=============================================================================================*/
  560. int ObjectClass::Value(void) const
  561. {
  562. return(0);
  563. }
  564. /***********************************************************************************************
  565. * ObjectClass::Get_Mission -- Fetches the current mission of this object. *
  566. * *
  567. * Generic objects don't have a mission, so this routine will just return MISSION_NONE. *
  568. * However, techno objects do have a mission and this routine is overloaded to handle *
  569. * those objects in order to return the correct mission value. *
  570. * *
  571. * INPUT: none *
  572. * *
  573. * OUTPUT: Returns with the current mission being followed by this object. *
  574. * *
  575. * WARNINGS: none *
  576. * *
  577. * HISTORY: *
  578. * 07/24/1995 JLB : Created. *
  579. *=============================================================================================*/
  580. MissionType ObjectClass::Get_Mission(void) const
  581. {
  582. return(MISSION_NONE);
  583. }
  584. /***********************************************************************************************
  585. * ObjectClass::Repair -- Handles object repair control. *
  586. * *
  587. * This routine will control object repair mode. At the object level, no repair is *
  588. * possible, so it is expected that any object that can repair will override this function *
  589. * as necessary. *
  590. * *
  591. * INPUT: control -- The repair control parameter. *
  592. * 0 = turn repair off *
  593. * 1 = turn repair on *
  594. * -1 = toggle repair state *
  595. * *
  596. * OUTPUT: none *
  597. * *
  598. * WARNINGS: none *
  599. * *
  600. * HISTORY: *
  601. * 07/24/1995 JLB : Created. *
  602. *=============================================================================================*/
  603. void ObjectClass::Repair(int )
  604. {
  605. }
  606. /***********************************************************************************************
  607. * ObjectClass::Sell_Back -- Sells the object -- if possible. *
  608. * *
  609. * This routine is called to sell back the object. Override this routine for the more *
  610. * sophisticated objects that can actually be sold back. Normal objects can't be sold and *
  611. * this routine does nothing as a consequence. *
  612. * *
  613. * INPUT: control -- How to control the sell state of this object. *
  614. * 0 = stop selling. *
  615. * 1 = start selling. *
  616. * -1 = toggle selling state. *
  617. * *
  618. * OUTPUT: none *
  619. * *
  620. * WARNINGS: none *
  621. * *
  622. * HISTORY: *
  623. * 07/19/1995 JLB : Created. *
  624. *=============================================================================================*/
  625. void ObjectClass::Sell_Back(int )
  626. {
  627. }
  628. /***********************************************************************************************
  629. * ObjectClass::Move -- Moves (by force) the object in the desired direction. *
  630. * *
  631. * This routine will instantly move the object one cell in the specified direction. It *
  632. * moves the object by force. This is typically ONLY used by the scenario editor *
  633. * process. *
  634. * *
  635. * INPUT: facing -- The direction to move the object. *
  636. * *
  637. * OUTPUT: none *
  638. * *
  639. * WARNINGS: Naturally, this can cause illegal placement situations -- use with caution. *
  640. * *
  641. * HISTORY: *
  642. * 06/19/1994 JLB : Created. *
  643. *=============================================================================================*/
  644. void ObjectClass::Move(FacingType facing)
  645. {
  646. COORDINATE coord;
  647. Mark(MARK_UP);
  648. coord = Adjacent_Cell(Coord, facing);
  649. if (Can_Enter_Cell(Coord_Cell(coord)) == MOVE_OK) {
  650. Coord = coord;
  651. }
  652. Mark(MARK_DOWN);
  653. }
  654. /***********************************************************************************************
  655. * ObjectClass::Unselect -- This will un-select the object if it was selected. *
  656. * *
  657. * This routine brings a currently selected object into an unselected state. This is *
  658. * needed when another object becomes selected as well as if the object is destroyed. *
  659. * *
  660. * INPUT: none *
  661. * *
  662. * OUTPUT: none *
  663. * *
  664. * WARNINGS: none *
  665. * *
  666. * HISTORY: *
  667. * 06/19/1994 JLB : Created. *
  668. *=============================================================================================*/
  669. void ObjectClass::Unselect(void)
  670. {
  671. if (IsSelected) {
  672. CurrentObject.Delete(this);
  673. if (In_Which_Layer()==LAYER_GROUND){
  674. Mark(MARK_OVERLAP_UP);
  675. }
  676. IsSelected = false;
  677. if (In_Which_Layer()==LAYER_GROUND){
  678. Mark(MARK_OVERLAP_DOWN);
  679. }
  680. }
  681. }
  682. /***********************************************************************************************
  683. * ObjectClass::Select -- Try to make this object the "selected" object. *
  684. * *
  685. * This routine is used to make this object into the one that is "selected". A selected *
  686. * object usually displays a floating bar graph and is available to be given orders from *
  687. * the player's I/O. *
  688. * *
  689. * INPUT: none *
  690. * *
  691. * OUTPUT: none *
  692. * *
  693. * WARNINGS: none *
  694. * *
  695. * HISTORY: *
  696. * 06/19/1994 JLB : Created. *
  697. * 06/12/1995 JLB : Cannot select a loaner object. *
  698. * 07/23/1995 JLB : Adds to head or tail depending on leader type flag. *
  699. *=============================================================================================*/
  700. bool ObjectClass::Select(void)
  701. {
  702. if (!Debug_Map && (IsSelected || !Class_Of().IsSelectable)) return(false);
  703. if (Can_Player_Move() && Is_Techno() && ((TechnoClass *)this)->IsALoaner) return(false);
  704. /*
  705. ** Don't allow selection of object when in building placement mode.
  706. */
  707. if (Map.PendingObject) return(false);
  708. /*
  709. ** If selecting an object of a different house than the player's, make sure that
  710. ** the entire selection list is cleared.
  711. */
  712. if (CurrentObject.Count() > 0) {
  713. if (Owner() != CurrentObject[0]->Owner() || CurrentObject[0]->Owner() != PlayerPtr->Class->House) {
  714. Unselect_All();
  715. }
  716. }
  717. if (((TechnoTypeClass const &)Class_Of()).IsLeader) {
  718. CurrentObject.Add_Head(this);
  719. } else {
  720. CurrentObject.Add(this);
  721. }
  722. if (In_Which_Layer()==LAYER_GROUND){
  723. Mark(MARK_OVERLAP_UP);
  724. }
  725. IsSelected = true;
  726. if (In_Which_Layer()==LAYER_GROUND){
  727. Mark(MARK_OVERLAP_DOWN);
  728. }
  729. return(true);
  730. }
  731. /***********************************************************************************************
  732. * ObjectClass::Render -- Displays the object onto the map. *
  733. * *
  734. * This routine will determine the location of the object and if it is roughly on the *
  735. * visible screen, it will display it. Not displaying objects that are not on the screen *
  736. * will save valuable time. *
  737. * *
  738. * INPUT: bool; Should the render be forced regardless of whether the object is flagged to *
  739. * be redrawn? *
  740. * *
  741. * OUTPUT: bool; Was the draw code called for this object? *
  742. * *
  743. * WARNINGS: none *
  744. * *
  745. * HISTORY: *
  746. * 06/19/1994 JLB : Created. *
  747. *=============================================================================================*/
  748. bool ObjectClass::Render(bool forced)
  749. {
  750. int x,y;
  751. COORDINATE coord = Render_Coord();
  752. CELL cell = Coord_Cell(coord);
  753. if (Debug_Map || Debug_Unshroud || ((forced || IsToDisplay) && IsDown && !IsInLimbo)) {
  754. IsToDisplay = false;
  755. /*
  756. ** Draw the path as lines on the map if so directed and the object is one that
  757. ** contains a path.
  758. */
  759. if (Special.IsShowPath && IsSelected) {
  760. switch (What_Am_I()) {
  761. case RTTI_INFANTRY:
  762. case RTTI_UNIT:
  763. FootClass * foot = (FootClass *)this;
  764. CELL cell;
  765. int oldx, oldy;
  766. if (foot->Head_To_Coord() && foot->Path[0] != FACING_NONE) {
  767. cell = Adjacent_Cell(Coord_Cell(foot->Head_To_Coord()), (FacingType)((foot->Path[0] + FACING_S) & FACING_NW));
  768. Map.Coord_To_Pixel(Cell_Coord(cell), oldx, oldy);
  769. for (int index = 0; index < PATH_MAX; index++) {
  770. if (foot->Path[index] == FACING_NONE) break;
  771. cell = Adjacent_Cell(cell, foot->Path[index]);
  772. if (Map.Coord_To_Pixel(Cell_Coord(cell), x, y)) {
  773. LogicPage->Draw_Line(oldx, 8+oldy, x, 8+y, BLACK);
  774. }
  775. oldx = x;
  776. oldy = y;
  777. }
  778. }
  779. break;
  780. }
  781. }
  782. if (Map.Coord_To_Pixel(coord, x, y)) {
  783. /*
  784. ** Draw the object itself
  785. */
  786. Draw_It(x, y, WINDOW_TACTICAL);
  787. #ifdef SCENARIO_EDITOR
  788. /*
  789. ** Draw the trigger attached to the object. Draw_It is window-
  790. ** relative, so add the window's x-coord to 'x'.
  791. */
  792. if (Debug_Map && Trigger) {
  793. Fancy_Text_Print(Trigger->Get_Name(), x + (WinX<<3), y, PINK, TBLACK, TPF_CENTER | TPF_NOSHADOW | TPF_6POINT);
  794. }
  795. #endif
  796. return(true);
  797. }
  798. }
  799. return(false);
  800. }
  801. #ifdef CHEAT_KEYS
  802. /***********************************************************************************************
  803. * ObjectClass::Debug_Dump -- Displays status of the object class to the mono monitor. *
  804. * *
  805. * This routine is used to display the current status of the object class to the mono *
  806. * monitor. *
  807. * *
  808. * INPUT: none *
  809. * *
  810. * OUTPUT: none *
  811. * *
  812. * WARNINGS: none *
  813. * *
  814. * HISTORY: *
  815. * 06/02/1994 JLB : Created. *
  816. *=============================================================================================*/
  817. void ObjectClass::Debug_Dump(MonoClass *mono) const
  818. {
  819. mono->Text_Print("X", 16 + (IsToDisplay?2:0), 18);
  820. mono->Text_Print("X", 16 + (IsActive?2:0), 3);
  821. mono->Text_Print("X", 16 + (IsInLimbo?2:0), 4);
  822. mono->Text_Print("X", 16 + (IsSelected?2:0), 7);
  823. mono->Set_Cursor(56, 1);
  824. mono->Printf("%08lX", Coord);
  825. mono->Set_Cursor(14, 1);mono->Printf("[%04X]", As_Target());
  826. mono->Set_Cursor(20, 3);mono->Printf("%2d[%d]", Strength, Class_Of().MaxStrength);
  827. }
  828. #endif
  829. /***********************************************************************************************
  830. * ObjectTypeClass::Occupy_List -- Returns with simple occupation list for object. *
  831. * *
  832. * This routine returns a pointer to a simple occupation list for this object. Since at *
  833. * this tier of the object class chain, the exact shape of the object is indeterminate, *
  834. * this function merely returns a single cell occupation list. This actually works for *
  835. * most vehicles. *
  836. * *
  837. * INPUT: none *
  838. * *
  839. * OUTPUT: Returns a pointer to a simple occupation list. *
  840. * *
  841. * WARNINGS: none *
  842. * *
  843. * HISTORY: *
  844. * 05/28/1994 JLB : Created. *
  845. *=============================================================================================*/
  846. short const * ObjectTypeClass::Occupy_List(bool) const
  847. {
  848. static short const _list[] = {0, REFRESH_EOL};
  849. return(_list);
  850. }
  851. /***********************************************************************************************
  852. * ObjectTypeClass::Overlap_List -- Returns a pointer to a simple overlap list. *
  853. * *
  854. * This function returns a pointer to an overlap list for the object. An overlap list is *
  855. * the offsets from the object's cell to get the cells the imagery overlaps, but is object *
  856. * is not considered to occupy. Since at this stage, the overlap information is not *
  857. * available, this function merely returns a pointer to an empty list. *
  858. * *
  859. * INPUT: none *
  860. * *
  861. * OUTPUT: Returns a pointer to the generic overlap list. *
  862. * *
  863. * WARNINGS: none *
  864. * *
  865. * HISTORY: *
  866. * 05/28/1994 JLB : Created. *
  867. *=============================================================================================*/
  868. short const * ObjectTypeClass::Overlap_List(void) const
  869. {
  870. static short const _list[] = {REFRESH_EOL};
  871. return(_list);
  872. }
  873. /***********************************************************************************************
  874. * ObjectTypeClass::One_Time -- Handles one time processing for object types. *
  875. * *
  876. * This routine is used to handle the once per game processing required for object types. *
  877. * This consists of loading any data and initializing any data tables the game requires. *
  878. * *
  879. * INPUT: none *
  880. * *
  881. * OUTPUT: none *
  882. * *
  883. * WARNINGS: This routine goes to disk. *
  884. * *
  885. * HISTORY: *
  886. * 11/01/1994 JLB : Created. *
  887. *=============================================================================================*/
  888. void ObjectTypeClass::One_Time(void)
  889. {
  890. SelectShapes = MixFileClass::Retrieve("SELECT.SHP");
  891. #if (FRENCH)
  892. PipShapes = Hires_Retrieve("PIPS_F.SHP");
  893. #else
  894. #if (GERMAN)
  895. PipShapes = Hires_Retrieve("PIPS_G.SHP");
  896. #else
  897. PipShapes = Hires_Retrieve("PIPS.SHP");
  898. #endif
  899. #endif
  900. }
  901. /***********************************************************************************************
  902. * ObjectClass::Mark_For_Redraw -- Marks object and system for redraw. *
  903. * *
  904. * This routine will mark the object and inform the display system *
  905. * that appropriate rendering is needed. Whenever it is determined *
  906. * that an object needs to be redrawn, call this routine. *
  907. * *
  908. * INPUT: none *
  909. * *
  910. * OUTPUT: none *
  911. * *
  912. * WARNINGS: This is a subordinate function to the function Mark(). If an object needs to *
  913. * be redrawn it is probably better to call the function Mark(MARK_CHANGE) rather *
  914. * than this function. This function does not inform the map system that *
  915. * overlapping objects are to be redrawn and thus unless you are really sure that *
  916. * this routine should be called, don't. *
  917. * *
  918. * HISTORY: *
  919. * 05/08/1994 JLB : Created. *
  920. * 12/23/1994 JLB : Flags map and flags unit only. *
  921. *=============================================================================================*/
  922. void ObjectClass::Mark_For_Redraw(void)
  923. {
  924. if (!IsToDisplay) {
  925. IsToDisplay = true;
  926. /*
  927. ** This tells the map rendering logic to "go through the motions" and call the
  928. ** rendering function. In the rendering function, it will sort out what gets
  929. ** rendered and what doesn't.
  930. */
  931. Map.Flag_To_Redraw(false);
  932. }
  933. }
  934. /***********************************************************************************************
  935. * ObjectClass::Limbo -- Brings the object into a state of limbo. *
  936. * *
  937. * An object brought into a state of limbo by this routine can be safely deleted. This *
  938. * routine will remove the object from all game lists and tracking systems. It is called *
  939. * prior to deleting the object or placing the object "on ice". *
  940. * *
  941. * INPUT: none *
  942. * *
  943. * OUTPUT: bool; Was the object successfully placed in limbo? *
  944. * *
  945. * WARNINGS: none *
  946. * *
  947. * HISTORY: *
  948. * 09/24/1994 JLB : Created. *
  949. *=============================================================================================*/
  950. bool ObjectClass::Limbo(void)
  951. {
  952. if (GameActive && !IsInLimbo) {
  953. Unselect();
  954. Detach_All();
  955. Mark(MARK_UP);
  956. /*
  957. ** Remove the object from the appropriate display list.
  958. */
  959. Map.Remove(this, In_Which_Layer());
  960. /*
  961. ** Remove the object from the logic processing list.
  962. */
  963. if (Class_Of().IsSentient) {
  964. Logic.Delete(this);
  965. }
  966. Hidden();
  967. IsInLimbo = true;
  968. IsToDisplay = false;
  969. return(true);
  970. }
  971. return(false);
  972. }
  973. /***********************************************************************************************
  974. * ObjectClass::Unlimbo -- Brings the object into the game system. *
  975. * *
  976. * This routine will place the object into the game tracking and display systems. It is *
  977. * called as a consequence of creating the object. Every game object must be unlimboed at *
  978. * some point. *
  979. * *
  980. * INPUT: coord -- The coordinate to place the object into the game system. *
  981. * *
  982. * dir (optional) -- initial facing direction for this object *
  983. * *
  984. * OUTPUT: bool; Was the game object successfully unlimboed? *
  985. * *
  986. * WARNINGS: none *
  987. * *
  988. * HISTORY: *
  989. * 09/24/1994 JLB : Created. *
  990. * 12/23/1994 JLB : Sets object strength. *
  991. *=============================================================================================*/
  992. bool ObjectClass::Unlimbo(COORDINATE coord, DirType )
  993. {
  994. if (GameActive && IsInLimbo && !IsDown) {
  995. if (ScenarioInit || Can_Enter_Cell(Coord_Cell(coord), FACING_NONE) == MOVE_OK) {
  996. IsInLimbo = false;
  997. IsToDisplay = false;
  998. Coord = Class_Of().Coord_Fixup(coord);
  999. if (Mark(MARK_DOWN)) {
  1000. if (IsActive) {
  1001. /*
  1002. ** Add the object to the appropriate map layer. This layer is used
  1003. ** for rendering purposes.
  1004. */
  1005. if (In_Which_Layer() != LAYER_NONE) {
  1006. Map.Submit(this, In_Which_Layer());
  1007. }
  1008. if (Class_Of().IsSentient) {
  1009. Logic.Submit(this);
  1010. }
  1011. }
  1012. return(true);
  1013. }
  1014. }
  1015. }
  1016. return(false);
  1017. }
  1018. /***********************************************************************************************
  1019. * ObjectClass::Detach_All -- Removes the object from all tracking systems. *
  1020. * *
  1021. * This routine will take the object and see that it is removed from all miscellaneous *
  1022. * tracking systems in the game. This operation is vital when deleting an object. It is *
  1023. * necessary so that when the object is removed from the game, existing game objects won't *
  1024. * be referencing a now invalid game object. This typically affects the targeting *
  1025. * and navigation computers of other game objects. *
  1026. * *
  1027. * INPUT: none *
  1028. * *
  1029. * OUTPUT: none *
  1030. * *
  1031. * WARNINGS: none *
  1032. * *
  1033. * HISTORY: *
  1034. * 09/24/1994 JLB : Created. *
  1035. *=============================================================================================*/
  1036. void ObjectClass::Detach_All(bool all)
  1037. {
  1038. /*
  1039. ** Unselect this object if it was selected.
  1040. */
  1041. if (all || Owner() != PlayerPtr->Class->House) {
  1042. Unselect();
  1043. }
  1044. Map.Detach(this);
  1045. /*
  1046. ** Remove from targeting computers.
  1047. */
  1048. Detach_This_From_All(As_Target(), all);
  1049. }
  1050. /***********************************************************************************************
  1051. * ObjectClass::Detach_This_From_All -- Detatches this object from all others. *
  1052. * *
  1053. * This routine sweeps through all game objects and makes sure that it is no longer *
  1054. * referenced by them. Typically, this is called in preparation for the object's death *
  1055. * or limbo state. *
  1056. * *
  1057. * INPUT: target -- This object expressed as a target number. *
  1058. * *
  1059. * OUTPUT: none *
  1060. * *
  1061. * WARNINGS: none *
  1062. * *
  1063. * HISTORY: *
  1064. * 05/08/1995 JLB : Created. *
  1065. *=============================================================================================*/
  1066. void ObjectClass::Detach_This_From_All(TARGET target, bool all)
  1067. {
  1068. int index;
  1069. if (Target_Legal(target)) {
  1070. for (index = 0; index < Houses.Count(); index++) {
  1071. Houses.Ptr(index)->Detach(target, all);
  1072. }
  1073. for (index = 0; index < Teams.Count(); index++) {
  1074. Teams.Ptr(index)->Detach(target, all);
  1075. }
  1076. for (index = 0; index < Units.Count(); index++) {
  1077. Units.Ptr(index)->Detach(target, all);
  1078. }
  1079. for (index = 0; index < Infantry.Count(); index++) {
  1080. Infantry.Ptr(index)->Detach(target, all);
  1081. }
  1082. for (index = 0; index < Aircraft.Count(); index++) {
  1083. Aircraft.Ptr(index)->Detach(target, all);
  1084. }
  1085. for (index = 0; index < Buildings.Count(); index++) {
  1086. Buildings.Ptr(index)->Detach(target, all);
  1087. }
  1088. for (index = 0; index < Bullets.Count(); index++) {
  1089. Bullets.Ptr(index)->Detach(target, all);
  1090. }
  1091. for (index = 0; index < Anims.Count(); index++) {
  1092. Anims.Ptr(index)->Detach(target, all);
  1093. }
  1094. }
  1095. }
  1096. /***********************************************************************************************
  1097. * ObjectClass::Receive_Message -- Processes an incoming radio message. *
  1098. * *
  1099. * Any radio message received that applies to objects in general are handled by this *
  1100. * routine. Typically, this is the "redraw" message, which occurs when another object is *
  1101. * loading or unloading and thus overlapping. *
  1102. * *
  1103. * INPUT: message -- The message received. *
  1104. * *
  1105. * OUTPUT: Returns with the appropriate radio response. If the message was recognized, then *
  1106. * RADIO_ROGER is returned, otherwise, just RADIO_STATIC is returned. *
  1107. * *
  1108. * WARNINGS: none *
  1109. * *
  1110. * HISTORY: *
  1111. * 09/24/1994 JLB : Created. *
  1112. *=============================================================================================*/
  1113. RadioMessageType ObjectClass::Receive_Message(RadioClass *, RadioMessageType message, long & )
  1114. {
  1115. switch (message) {
  1116. /*
  1117. ** This message serves as a rendering convenience. It lets the system
  1118. ** know that there might be a visual conflict and the unit in radio
  1119. ** contact should be redrawn. This typically occurs when a vehicle
  1120. ** is being unloaded from a hover lander.
  1121. */
  1122. case RADIO_REDRAW:
  1123. Mark(MARK_CHANGE);
  1124. return(RADIO_ROGER);
  1125. default:
  1126. break;
  1127. }
  1128. return(RADIO_STATIC);
  1129. }
  1130. /***********************************************************************************************
  1131. * ObjectClass::Take_Damage -- Applies damage to the object. *
  1132. * *
  1133. * This routine applies damage to the object according to the damage parameters. It handles *
  1134. * reducing the strength of the object and also returns the result of that damage. The *
  1135. * result value can be examined to determine if the object was destroyed, greatly damaged, *
  1136. * or other results. *
  1137. * *
  1138. * INPUT: damage -- Reference to the damage number to apply. This number will be adjusted *
  1139. * according to defensive armor and distance. Examine this value after *
  1140. * the call to determine the actual amount of damage applied. *
  1141. * *
  1142. * distance -- The distance (in leptons) from the center of the damage causing *
  1143. * explosion to the object itself. *
  1144. * *
  1145. * warhead -- The warhead type that is causing the damage. *
  1146. * *
  1147. * OUTPUT: Returns the ResultType that indicates what the affect of the damage was. *
  1148. * *
  1149. * WARNINGS: none *
  1150. * *
  1151. * HISTORY: *
  1152. * 11/29/1994 JLB : Created. *
  1153. * 12/27/1994 JLB : Trigger event processing for attacked or destroyed. *
  1154. * 01/01/1995 JLB : Reduces damage greatly depending on range. *
  1155. *=============================================================================================*/
  1156. ResultType ObjectClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source)
  1157. {
  1158. ResultType result = RESULT_NONE;
  1159. int oldstrength = Strength;
  1160. if (oldstrength && damage && !Class_Of().IsImmune) {
  1161. int maxstrength = Class_Of().MaxStrength;
  1162. /*
  1163. ** Modify damage based on the warhead type and the armor of the object. This results
  1164. ** in a reduced damage value, but never below 1 damage point.
  1165. */
  1166. damage = Modify_Damage(damage, warhead, Class_Of().Armor, distance);
  1167. if (!damage) return(RESULT_NONE);
  1168. /*
  1169. ** At this point, we KNOW that at least light damage has occurred.
  1170. */
  1171. result = RESULT_LIGHT;
  1172. /*
  1173. ** A non-fatal blow has occurred. Check to see if the object transitioned to below
  1174. ** half strength or if it is now down to one hit point.
  1175. */
  1176. if (oldstrength > damage) {
  1177. if (oldstrength >= (maxstrength >> 1) && (oldstrength-damage) < (maxstrength >> 1)) {
  1178. result = RESULT_HALF;
  1179. }
  1180. } else {
  1181. /*
  1182. ** When an object is damaged to destruction, it will instead stop at one
  1183. ** damage point. This will prolong the damage state as well as
  1184. ** give greater satisfaction when it is finally destroyed.
  1185. */
  1186. damage = oldstrength;
  1187. }
  1188. /*
  1189. ** Apply the damage to the object.
  1190. */
  1191. Strength = oldstrength - damage;
  1192. /*
  1193. ** Check to see if the object is majorly damaged or destroyed.
  1194. */
  1195. switch (Strength) {
  1196. case 0:
  1197. Record_The_Kill(source);
  1198. result = RESULT_DESTROYED;
  1199. Detach_All();
  1200. break;
  1201. case 1:
  1202. result = RESULT_MAJOR;
  1203. break;
  1204. default:
  1205. break;
  1206. }
  1207. /*
  1208. ** Handle any trigger event associated with this object.
  1209. */
  1210. if (source && Trigger && result != RESULT_DESTROYED) {
  1211. Trigger->Spring(EVENT_ATTACKED, this);
  1212. }
  1213. /*
  1214. ** If any damage was assessed and this object is selected, then flag
  1215. ** the object to be redrawn so that the health bar will be updated.
  1216. */
  1217. if (result != RESULT_NONE && IsSelected) {
  1218. Mark(MARK_CHANGE);
  1219. }
  1220. }
  1221. /*
  1222. ** Return with the result of the damage taken.
  1223. */
  1224. return(result);
  1225. }
  1226. /***********************************************************************************************
  1227. * ObjectClass::Mark -- Handles basic marking logic. *
  1228. * *
  1229. * This routine handles the base logic for marking an object up or down on the map. It *
  1230. * manages the IsDown flag as well as flagging the object to be redrawn if necessary. *
  1231. * Whenever an object is to be marked, it should call this base class function first. If *
  1232. * this function returns true, then the higher level function should proceed with its own *
  1233. * logic. *
  1234. * *
  1235. * INPUT: mark -- The marking method to use for this object. It can be either MARK_DOWN, *
  1236. * MARK_UP, or MARK_CHANGE. *
  1237. * *
  1238. * OUTPUT: bool; Was the object marked successfully? *
  1239. * *
  1240. * WARNINGS: none *
  1241. * *
  1242. * HISTORY: *
  1243. * 01/23/1995 JLB : Created. *
  1244. *=============================================================================================*/
  1245. bool ObjectClass::Mark(MarkType mark)
  1246. {
  1247. TechnoClass *tech;
  1248. CELL cell;
  1249. int threat;
  1250. HousesType house;
  1251. if (!IsInLimbo && IsActive) {
  1252. /*
  1253. ** A mark for change is always successful UNLESS the object
  1254. ** is not placed down or has already been flagged as changed
  1255. ** this game frame.
  1256. */
  1257. if (mark == MARK_CHANGE) {
  1258. if (IsToDisplay) return(false);
  1259. if (IsDown == true) {
  1260. Mark_For_Redraw();
  1261. return(true);
  1262. }
  1263. return(false);
  1264. }
  1265. /*
  1266. ** Handle adding or removing the object in the cells' overlap lists
  1267. */
  1268. if (mark == MARK_OVERLAP_UP) {
  1269. if (IsDown == true) {
  1270. Map.Overlap_Up(Coord_Cell(Coord),this);
  1271. Mark_For_Redraw();
  1272. return(true);
  1273. }
  1274. }
  1275. if (mark == MARK_OVERLAP_DOWN) {
  1276. if (IsDown == true) {
  1277. Map.Overlap_Down(Coord_Cell(Coord),this);
  1278. Mark_For_Redraw();
  1279. return(true);
  1280. }
  1281. }
  1282. /*
  1283. ** It is important to know whether the object is a techno class
  1284. ** or not to see if we have to adjust the regional threat ratings
  1285. */
  1286. if (Is_Techno()) {
  1287. tech = (TechnoClass *)this;
  1288. threat = tech->Risk();
  1289. house = tech->Owner();
  1290. cell = Coord_Cell(Coord);
  1291. } else
  1292. tech = NULL;
  1293. /*
  1294. ** Marking down is only successful if the object isn't already
  1295. ** placed down.
  1296. */
  1297. if (mark == MARK_DOWN && !IsDown) {
  1298. if (tech && GameToPlay == GAME_NORMAL) {
  1299. Map[cell].Adjust_Threat(house, threat);
  1300. }
  1301. IsDown = true;
  1302. Mark_For_Redraw();
  1303. return(true);
  1304. }
  1305. /*
  1306. ** Lifting up is only successful if the object isn't already
  1307. ** lifted up from the map.
  1308. */
  1309. if (mark == MARK_UP && IsDown) {
  1310. if (tech && GameToPlay == GAME_NORMAL) {
  1311. Map[cell].Adjust_Threat(house, -threat);
  1312. }
  1313. IsDown = false;
  1314. return(true);
  1315. }
  1316. }
  1317. return(false);
  1318. }
  1319. /***********************************************************************************************
  1320. * ObjectClass::Init -- Initializes the basic object system. *
  1321. * *
  1322. * This routine should be called when the basic object system needs to be initialized. This *
  1323. * occurs when the scenario is about to be loaded. *
  1324. * *
  1325. * INPUT: none *
  1326. * *
  1327. * OUTPUT: none *
  1328. * *
  1329. * WARNINGS: none *
  1330. * *
  1331. * HISTORY: *
  1332. * 01/23/1995 JLB : Created. *
  1333. *=============================================================================================*/
  1334. void ObjectClass::Init(void)
  1335. {
  1336. CurrentObject.Clear();
  1337. }
  1338. /***********************************************************************************************
  1339. * ObjectClass::Revealed -- Reveals this object to the house specified. *
  1340. * *
  1341. * This routine is called when this object gets revealed to the house specified. *
  1342. * *
  1343. * INPUT: house -- Pointer to the house that this object is being revealed to. *
  1344. * *
  1345. * OUTPUT: Was this object revealed for the first time to this house? Generic objects always *
  1346. * return true unless an invalid house pointer was specified. *
  1347. * *
  1348. * WARNINGS: none *
  1349. * *
  1350. * HISTORY: *
  1351. * 07/19/1995 JLB : Created. *
  1352. *=============================================================================================*/
  1353. bool ObjectClass::Revealed(HouseClass * house)
  1354. {
  1355. return(house != NULL);
  1356. }
  1357. // These can't be made inline (for various reasons).
  1358. short const * ObjectClass::Occupy_List(bool placement) const {return(Class_Of().Occupy_List(placement));};
  1359. short const * ObjectClass::Overlap_List(void) const {return(Class_Of().Overlap_List());};
  1360. BuildingClass * ObjectClass::Who_Can_Build_Me(bool intheory, bool legal) const {return(Class_Of().Who_Can_Build_Me(intheory, legal, Owner()));};
  1361. unsigned ObjectClass::Health_Ratio(void) const {return(Cardinal_To_Fixed(Class_Of().MaxStrength, Strength));};
  1362. int ObjectClass::Full_Name(void) const {return Class_Of().Full_Name();};