OBJECT.CPP 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239
  1. /*
  2. ** Command & Conquer Red Alert(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: /CounterStrike/OBJECT.CPP 1 3/03/97 10:25a 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 : October 6, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * ObjectClass::AI -- Handles generic object AI processing. *
  36. * ObjectClass::Active_Click_With -- Dispatches action on the object specified. *
  37. * ObjectClass::Active_Click_With -- Dispatches action on the specified cell. *
  38. * ObjectClass::Attach_Trigger -- Attach specified trigger to object. *
  39. * ObjectClass::Can_Demolish -- Queries whether this object can be sold back. *
  40. * ObjectClass::Can_Player_Fire -- Can the player give this object an attack mission? *
  41. * ObjectClass::Can_Player_Move -- Can the player give this object a movement mission? *
  42. * ObjectClass::Can_Repair -- Queries whether this object can be repaired. *
  43. * ObjectClass::Catch_Fire -- Called when animation is attached to this object. *
  44. * ObjectClass::Center_Coord -- Fetches the center coordinate for the object. *
  45. * ObjectClass::Clicked_As_Target -- Triggers target selection animation. *
  46. * ObjectClass::Debug_Dump -- Displays status of the object class to the mono monitor. *
  47. * ObjectClass::Detach -- Detach the specified target from this object. *
  48. * ObjectClass::Detach_All -- Removes the object from all tracking systems. *
  49. * ObjectClass::Do_Shimmer -- Shimmers this object if it is cloaked. *
  50. * ObjectClass::Docking_Coord -- Fetches the coordinate to dock at this object. *
  51. * ObjectClass::Exit_Coord -- Return with the exit coordinate for this object. *
  52. * ObjectClass::Exit_Object -- Causes the specified object to leave this object. *
  53. * ObjectClass::Fire_Coord -- Fetches the coordinate a projectile will launch from. *
  54. * ObjectClass::Fire_Out -- Informs object that attached animation has finished. *
  55. * ObjectClass::Get_Mission -- Fetches the current mission of this object. *
  56. * ObjectClass::Get_Ownable -- Fetches the house owner legality options for this object. *
  57. * ObjectClass::Hidden -- Called when this object becomes hidden from the player. *
  58. * ObjectClass::In_Range -- Determines if the coordinate is within weapon range. *
  59. * ObjectClass::In_Which_Layer -- Fetches what layer this object is located in. *
  60. * ObjectClass::Init -- Initializes the basic object system. *
  61. * ObjectClass::Limbo -- Brings the object into a state of limbo. *
  62. * ObjectClass::Look -- Called when this object needs to reveal terrain. *
  63. * ObjectClass::Mark -- Handles basic marking logic. *
  64. * ObjectClass::Mark_For_Redraw -- Marks object and system for redraw. *
  65. * ObjectClass::Move -- Moves (by force) the object in the desired direction. *
  66. * ObjectClass::Name -- Fetches the identification name of this object. *
  67. * ObjectClass::ObjectClass -- Default constructor for objects. *
  68. * ObjectClass::Paradrop -- Unlimbos object in paradrop mode. *
  69. * ObjectClass::Passive_Click_With -- Right mouse button click process. *
  70. * ObjectClass::Receive_Message -- Processes an incoming radio message. *
  71. * ObjectClass::Record_The_Kill -- Records this object as killed by the specified object. *
  72. * ObjectClass::Render -- Displays the object onto the map. *
  73. * ObjectClass::Render_Coord -- Fetches the coordinate to draw this object at. *
  74. * ObjectClass::Repair -- Handles object repair control. *
  75. * ObjectClass::Revealed -- Reveals this object to the house specified. *
  76. * ObjectClass::Scatter -- Tries to scatter this object. *
  77. * ObjectClass::Select -- Try to make this object the "selected" object. *
  78. * ObjectClass::Sell_Back -- Sells the object -- if possible. *
  79. * ObjectClass::Sort_Y -- Returns the coordinate used for display order sorting. *
  80. * ObjectClass::Take_Damage -- Applies damage to the object. *
  81. * ObjectClass::Target_Coord -- Fetches the coordinate if this object is a target. *
  82. * ObjectClass::Unlimbo -- Brings the object into the game system. *
  83. * ObjectClass::Unselect -- This will un-select the object if it was selected. *
  84. * ObjectClass::Value -- Fetches the target value of this object. *
  85. * ObjectClass::Weapon_Range -- Returns the weapon range for the weapon specified. *
  86. * ObjectClass::What_Action -- Determines what action to perform on specified object. *
  87. * ObjectClass::What_Action -- Returns with the action to perform for this object. *
  88. * ObjectTypeClass::Cost_Of -- Returns the cost to buy this unit. *
  89. * ObjectTypeClass::Dimensions -- Gets the dimensions of the object in pixels. *
  90. * ObjectTypeClass::Get_Cameo_Data -- Fetches pointer to cameo data for this object type. *
  91. * ObjectTypeClass::Max_Pips -- Fetches the maximum pips allowed for this object. *
  92. * ObjectTypeClass::ObjectTypeClass -- Normal constructor for object type class objects. *
  93. * ObjectTypeClass::Occupy_List -- Returns with simple occupation list for object. *
  94. * ObjectTypeClass::One_Time -- Handles one time processing for object types. *
  95. * ObjectTypeClass::Overlap_List -- Returns a pointer to a simple overlap list. *
  96. * ObjectTypeClass::Time_To_Build -- Fetches the time to construct this object. *
  97. * ObjectTypeClass::Who_Can_Build_Me -- Determine what building can build this object type. *
  98. * ObjectTypeClass::Who_Can_Build_Me -- Finds the factory building that can build this object*
  99. * ObjectClass::Get_Image_Data -- Fetches the image data to use for this object. *
  100. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  101. #include "function.h"
  102. /*
  103. ** Selected objects have a special marking box around them. This is the shapes that are
  104. ** used for this purpose.
  105. */
  106. void const * ObjectTypeClass::SelectShapes = 0;
  107. void const * ObjectTypeClass::PipShapes = 0;
  108. /***********************************************************************************************
  109. * ObjectClass::ObjectClass -- Default constructor for objects. *
  110. * *
  111. * This is the default constructor for objects. It is called as an inherent part of the *
  112. * construction process for all the normal game objects instantiated. It serves merely to *
  113. * initialize the object values to a common (default) state. *
  114. * *
  115. * INPUT: none *
  116. * *
  117. * OUTPUT: none *
  118. * *
  119. * WARNINGS: Objects always start in a state of limbo. They must be Unlimbo()ed before they *
  120. * can be used. *
  121. * *
  122. * HISTORY: *
  123. * 09/24/1994 JLB : Created. *
  124. *=============================================================================================*/
  125. ObjectClass::ObjectClass(RTTIType rtti, int id) :
  126. AbstractClass(rtti, id),
  127. IsDown(false),
  128. IsToDamage(false),
  129. IsToDisplay(false),
  130. IsInLimbo(true),
  131. IsSelected(false),
  132. IsAnimAttached(false),
  133. IsFalling(false),
  134. Riser(0),
  135. Next(0),
  136. Trigger(NULL),
  137. Strength(255)
  138. {
  139. }
  140. /***********************************************************************************************
  141. * ObjectClass::Get_Image_Data -- Fetches the image data to use for this object. *
  142. * *
  143. * This routine will return with a pointer to the image data that should be used when *
  144. * this object is drawn. *
  145. * *
  146. * INPUT: none *
  147. * *
  148. * OUTPUT: Returns with a pointer to the shape data for this object. *
  149. * *
  150. * WARNINGS: none *
  151. * *
  152. * HISTORY: *
  153. * 08/06/1996 JLB : Created. *
  154. *=============================================================================================*/
  155. void const * ObjectClass::Get_Image_Data(void) const
  156. {
  157. return(Class_Of().Get_Image_Data());
  158. }
  159. /***********************************************************************************************
  160. * ObjectClass::Name -- Fetches the identification name of this object. *
  161. * *
  162. * This routine will return a pointer to the identifier name for this object. This name *
  163. * is usually short and is used in the INI files to identify this object. *
  164. * *
  165. * INPUT: none *
  166. * *
  167. * OUTPUT: Returns with a pointer to the text identifier name of this object. *
  168. * *
  169. * WARNINGS: none *
  170. * *
  171. * HISTORY: *
  172. * 07/29/1996 JLB : Created. *
  173. *=============================================================================================*/
  174. char const * ObjectClass::Name(void) const
  175. {
  176. return(Class_Of().Name());
  177. }
  178. /***********************************************************************************************
  179. * ObjectClass::Exit_Coord -- Return with the exit coordinate for this object. *
  180. * *
  181. * Ths exit coordinate is the location that a piggy back or newly produced object will *
  182. * appear at when it exits this object. Transports and factory buildings will utilize this *
  183. * routine. *
  184. * *
  185. * INPUT: none *
  186. * *
  187. * OUTPUT: Returns with the coordinate that an object will appear at when exiting this *
  188. * object. *
  189. * *
  190. * WARNINGS: none *
  191. * *
  192. * HISTORY: *
  193. * 07/29/1996 JLB : Created. *
  194. *=============================================================================================*/
  195. COORDINATE ObjectClass::Exit_Coord(void) const
  196. {
  197. return(Center_Coord());
  198. }
  199. /***********************************************************************************************
  200. * ObjectClass::AI -- Handles generic object AI processing. *
  201. * *
  202. * This routine is used to handle the AI processing that occurs for all object types. *
  203. * Typically, this isn't much, but there is the concept of falling that all objects can *
  204. * be subjected to (e.g., grenades). *
  205. * *
  206. * INPUT: none *
  207. * *
  208. * OUTPUT: none *
  209. * *
  210. * WARNINGS: none *
  211. * *
  212. * HISTORY: *
  213. * 02/07/1996 JLB : Created. *
  214. *=============================================================================================*/
  215. void ObjectClass::AI(void)
  216. {
  217. assert(this != 0);
  218. assert(IsActive);
  219. /*
  220. ** Falling logic is handled here.
  221. */
  222. if (IsFalling) {
  223. LayerType layer = In_Which_Layer();
  224. Height += Riser;
  225. if (Height <= 0) {
  226. Height = 0;
  227. IsFalling = false;
  228. Per_Cell_Process(PCP_END);
  229. Shorten_Attached_Anims(this);
  230. }
  231. if (IsAnimAttached) {
  232. Riser -= 1;
  233. Riser = max(Riser, -3);
  234. } else {
  235. Riser -= Rule.Gravity;
  236. // Riser -= GRAVITY;
  237. Riser = max(Riser, -100);
  238. }
  239. if (layer != In_Which_Layer()) {
  240. Map.Remove(this, layer);
  241. Map.Submit(this, In_Which_Layer());
  242. if (Class_Of().IsFootprint) {
  243. if (In_Which_Layer() == LAYER_GROUND) {
  244. Map.Place_Down(Coord_Cell(Center_Coord()), this);
  245. } else {
  246. Map.Pick_Up(Coord_Cell(Center_Coord()), this);
  247. }
  248. }
  249. }
  250. }
  251. }
  252. /***********************************************************************************************
  253. * ObjectClass::What_Action -- Determines what action to perform on specified object. *
  254. * *
  255. * This routine will return that action that this object could perform if the mouse were *
  256. * clicked over the object specified. *
  257. * *
  258. * INPUT: object -- Pointer to the object to check this object against when determining *
  259. * the action to perform. *
  260. * *
  261. * OUTPUT: It returns that action that will be performed if the mouse were clicked over the *
  262. * object. Since non-derived objects cannot do anything, and cannot even be *
  263. * instantiated, this routine will always return ACTION_NONE. *
  264. * *
  265. * WARNINGS: none *
  266. * *
  267. * HISTORY: *
  268. * 07/19/1995 JLB : Created. *
  269. *=============================================================================================*/
  270. ActionType ObjectClass::What_Action(ObjectClass const *) const
  271. {
  272. assert(this != 0);
  273. assert(IsActive);
  274. return(ACTION_NONE);
  275. }
  276. /***********************************************************************************************
  277. * ObjectClass::What_Action -- Returns with the action to perform for this object. *
  278. * *
  279. * This routine is called when information on a potential action if the mouse were clicked *
  280. * on the cell specified. This routine merely serves as a virtual placeholder so that *
  281. * object types that can actually perform some action will override this routine to provide *
  282. * true functionality. *
  283. * *
  284. * INPUT: cell -- The cell that the mouse is over and might be clicked on. *
  285. * *
  286. * OUTPUT: Returns with the action that this object would try to perform if the mouse were *
  287. * clicked. Since objects at this level have no ability to do anything, this routine *
  288. * will always returns ACTION_NONE unless it is overridden. *
  289. * *
  290. * WARNINGS: none *
  291. * *
  292. * HISTORY: *
  293. * 08/13/1995 JLB : Created. *
  294. *=============================================================================================*/
  295. ActionType ObjectClass::What_Action(CELL) const
  296. {
  297. assert(this != 0);
  298. assert(IsActive);
  299. return(ACTION_NONE);
  300. }
  301. /***********************************************************************************************
  302. * ObjectClass::In_Which_Layer -- Fetches what layer this object is located in. *
  303. * *
  304. * The default layer for object location is the LAYER_GROUND. Aircraft will override this *
  305. * routine and make adjustments as necessary according to the aircraft's altitude. *
  306. * *
  307. * INPUT: none *
  308. * *
  309. * OUTPUT: Returns with the layer that this object is located in. *
  310. * *
  311. * WARNINGS: none *
  312. * *
  313. * HISTORY: *
  314. * 08/13/1995 JLB : Created. *
  315. *=============================================================================================*/
  316. LayerType ObjectClass::In_Which_Layer(void) const
  317. {
  318. assert(this != 0);
  319. assert(IsActive);
  320. if (Height < (FLIGHT_LEVEL - (FLIGHT_LEVEL/3))) {
  321. return(LAYER_GROUND);
  322. }
  323. return(LAYER_TOP);
  324. }
  325. /***********************************************************************************************
  326. * ObjectClass::Get_Ownable -- Fetches the house owner legality options for this object. *
  327. * *
  328. * This routine will return the ownable bits for this object. Objects at this level can't *
  329. * really be owned by anyone, but return the full spectrum of legality just to be safe. *
  330. * *
  331. * INPUT: none *
  332. * *
  333. * OUTPUT: Returns with the ownable flags (as a combined bitfield) for this object. *
  334. * *
  335. * WARNINGS: none *
  336. * *
  337. * HISTORY: *
  338. * 08/13/1995 JLB : Created. *
  339. *=============================================================================================*/
  340. int ObjectClass::Get_Ownable(void) const
  341. {
  342. assert(this != 0);
  343. assert(IsActive);
  344. return(HOUSEF_ALLIES | HOUSEF_SOVIET | HOUSEF_OTHERS);
  345. }
  346. /***********************************************************************************************
  347. * ObjectClass::Can_Repair -- Queries whether this object can be repaired. *
  348. * *
  349. * Most objects cannot be repaired. This routine defaults to returning "false", but is *
  350. * overridden by derived functions defined by object types that can support repair. *
  351. * *
  352. * INPUT: none *
  353. * *
  354. * OUTPUT: Can this object be repaired? *
  355. * *
  356. * WARNINGS: none *
  357. * *
  358. * HISTORY: *
  359. * 08/13/1995 JLB : Created. *
  360. *=============================================================================================*/
  361. bool ObjectClass::Can_Repair(void) const
  362. {
  363. assert(this != 0);
  364. assert(IsActive);
  365. return(false);
  366. }
  367. /***********************************************************************************************
  368. * ObjectClass::Can_Demolish -- Queries whether this object can be sold back. *
  369. * *
  370. * This routine is used to determine if this object can be sold. Most objects cannot be *
  371. * but for those objects that can, this routine will be overridden as necessary. *
  372. * *
  373. * INPUT: none *
  374. * *
  375. * OUTPUT: Can this object be sold back? Typically, the answer is no. *
  376. * *
  377. * WARNINGS: none *
  378. * *
  379. * HISTORY: *
  380. * 08/13/1995 JLB : Created. *
  381. *=============================================================================================*/
  382. bool ObjectClass::Can_Demolish(void) const
  383. {
  384. assert(this != 0);
  385. assert(IsActive);
  386. return(false);
  387. }
  388. /***********************************************************************************************
  389. * ObjectClass::Can_Player_Fire -- Can the player give this object an attack mission? *
  390. * *
  391. * This routine is used to determine if attacking is an option under player control with *
  392. * respect to this unit. This routine will be overridden as necessary for those objects *
  393. * that have the ability to attack. *
  394. * *
  395. * INPUT: none *
  396. * *
  397. * OUTPUT: Can this object be given an attack order by the player? *
  398. * *
  399. * WARNINGS: none *
  400. * *
  401. * HISTORY: *
  402. * 08/13/1995 JLB : Created. *
  403. *=============================================================================================*/
  404. bool ObjectClass::Can_Player_Fire(void) const
  405. {
  406. assert(this != 0);
  407. assert(IsActive);
  408. return(false);
  409. }
  410. /***********************************************************************************************
  411. * ObjectClass::Can_Player_Move -- Can the player give this object a movement mission? *
  412. * *
  413. * This routine is used to determine if the player has the ability to command this object *
  414. * with a movement mission. This routine will be overridden as necessary to support this *
  415. * ability. *
  416. * *
  417. * INPUT: none *
  418. * *
  419. * OUTPUT: Can this object be given a movement mission by the player? *
  420. * *
  421. * WARNINGS: none *
  422. * *
  423. * HISTORY: *
  424. * 08/13/1995 JLB : Created. *
  425. *=============================================================================================*/
  426. bool ObjectClass::Can_Player_Move(void) const
  427. {
  428. assert(this != 0);
  429. assert(IsActive);
  430. return(false);
  431. }
  432. /***********************************************************************************************
  433. * ObjectClass::Target_Coord -- Fetches the coordinate if this object is a target. *
  434. * *
  435. * When the coordinate to use when firing at this object is needed, this routine will *
  436. * provide it. Normal objects just use the center of the object for this, but there are *
  437. * some more sophisticated objects that are not fired upon the center. *
  438. * *
  439. * INPUT: none *
  440. * *
  441. * OUTPUT: Returns with the coordinate to fire at if this object is a target. *
  442. * *
  443. * WARNINGS: none *
  444. * *
  445. * HISTORY: *
  446. * 08/13/1995 JLB : Created. *
  447. *=============================================================================================*/
  448. COORDINATE ObjectClass::Target_Coord(void) const
  449. {
  450. assert(this != 0);
  451. assert(IsActive);
  452. return(Coord_Add(XY_Coord(0, -Height), Center_Coord()));
  453. // return(Center_Coord());
  454. }
  455. /***********************************************************************************************
  456. * ObjectClass::Center_Coord -- Fetches the center coordinate for the object. *
  457. * *
  458. * This routine will return the center coordinate for the object. The center coordinate is *
  459. * typically the coordinate recorded in the object structure. Exceptions to this include *
  460. * the trees and other terrain elements. *
  461. * *
  462. * INPUT: none *
  463. * *
  464. * OUTPUT: Returns the coordinate that is considered the center point of this object. *
  465. * *
  466. * WARNINGS: none *
  467. * *
  468. * HISTORY: *
  469. * 09/21/1995 JLB : Created. *
  470. *=============================================================================================*/
  471. COORDINATE ObjectClass::Center_Coord(void) const
  472. {
  473. assert(this != 0);
  474. assert(IsActive);
  475. return(Coord);
  476. }
  477. /***********************************************************************************************
  478. * ObjectClass::Render_Coord -- Fetches the coordinate to draw this object at. *
  479. * *
  480. * This routine will return the coordinate to base the drawing of this object's graphic *
  481. * at. This is adjusted according to the nature of the graphic associated with this *
  482. * object. *
  483. * *
  484. * INPUT: none *
  485. * *
  486. * OUTPUT: Returns the coordinate to draw the graphic of this object at. *
  487. * *
  488. * WARNINGS: none *
  489. * *
  490. * HISTORY: *
  491. * 09/21/1995 JLB : Created. *
  492. *=============================================================================================*/
  493. COORDINATE ObjectClass::Render_Coord(void) const
  494. {
  495. assert(this != 0);
  496. assert(IsActive);
  497. return(Center_Coord());
  498. }
  499. /***********************************************************************************************
  500. * ObjectClass::Docking_Coord -- Fetches the coordinate to dock at this object. *
  501. * *
  502. * This routine returns the coordinate that a potential docking object should home in on. *
  503. * Typically, this the center of the object, but in certain cases it is adjusted off center *
  504. * according to the object type. An example of this would be the airfield. *
  505. * *
  506. * INPUT: none *
  507. * *
  508. * OUTPUT: Returns with the coordinate that a docking object should head for. *
  509. * *
  510. * WARNINGS: none *
  511. * *
  512. * HISTORY: *
  513. * 09/21/1995 JLB : Created. *
  514. *=============================================================================================*/
  515. COORDINATE ObjectClass::Docking_Coord(void) const
  516. {
  517. assert(this != 0);
  518. assert(IsActive);
  519. return(Center_Coord());
  520. }
  521. /***********************************************************************************************
  522. * ObjectClass::Sort_Y -- Returns the coordinate used for display order sorting. *
  523. * *
  524. * This routine will return the value to be used for object sorting. The sorting ensures *
  525. * that the object are rendered from a top to bottom order. Certain object use a sorting *
  526. * value different from their center coordinate. This is true if the object "touches the *
  527. * ground" at a point that is different from the object's center point. *
  528. * *
  529. * INPUT: none *
  530. * *
  531. * OUTPUT: Returns with the value to use as the Y sorting value. *
  532. * *
  533. * WARNINGS: none *
  534. * *
  535. * HISTORY: *
  536. * 09/21/1995 JLB : Created. *
  537. *=============================================================================================*/
  538. COORDINATE ObjectClass::Sort_Y(void) const
  539. {
  540. assert(this != 0);
  541. assert(IsActive);
  542. return(Coord);
  543. }
  544. /***********************************************************************************************
  545. * ObjectClass::Fire_Coord -- Fetches the coordinate a projectile will launch from. *
  546. * *
  547. * For those objects that fire, the coordinate that the projectile it launches will appear *
  548. * at the location specified by the return value from this function. *
  549. * *
  550. * INPUT: which -- Which weapon to consider when determining fire coordinate? *
  551. * 0: primary weapon *
  552. * 1: secondary weapon *
  553. * *
  554. * OUTPUT: Returns with the coordinate that a launched projectile will appear at if this *
  555. * object were to fire the weapon specified. *
  556. * *
  557. * WARNINGS: none *
  558. * *
  559. * HISTORY: *
  560. * 09/21/1995 JLB : Created. *
  561. *=============================================================================================*/
  562. COORDINATE ObjectClass::Fire_Coord(int ) const
  563. {
  564. assert(this != 0);
  565. assert(IsActive);
  566. return(Coord);
  567. }
  568. /***********************************************************************************************
  569. * ObjectClass::Record_The_Kill -- Records this object as killed by the specified object. *
  570. * *
  571. * This routine is called when this object is killed. If the source of the death is known, *
  572. * then a pointer to the responsible object is provided as a parameter. *
  573. * *
  574. * INPUT: source -- Pointer to the cause of this unit's death. *
  575. * *
  576. * OUTPUT: none *
  577. * *
  578. * WARNINGS: none *
  579. * *
  580. * HISTORY: *
  581. * 09/21/1995 JLB : Created. *
  582. *=============================================================================================*/
  583. void ObjectClass::Record_The_Kill(TechnoClass * )
  584. {
  585. assert(this != 0);
  586. assert(IsActive);
  587. }
  588. /***********************************************************************************************
  589. * ObjectClass::Do_Shimmer -- Shimmers this object if it is cloaked. *
  590. * *
  591. * When an object is cloaked, there are several conditions that would cause it to shimmer *
  592. * and thus reveal itself. When such a condition arrises, this function is called. If the *
  593. * object is cloaked, then it will shimmer. At this derivation level, cloaking is *
  594. * undefined. Objects that can cloak will override this function as necessary. *
  595. * *
  596. * INPUT: none *
  597. * *
  598. * OUTPUT: none *
  599. * *
  600. * WARNINGS: none *
  601. * *
  602. * HISTORY: *
  603. * 09/21/1995 JLB : Created. *
  604. *=============================================================================================*/
  605. void ObjectClass::Do_Shimmer(void)
  606. {
  607. assert(this != 0);
  608. assert(IsActive);
  609. }
  610. /***********************************************************************************************
  611. * ObjectClass::Exit_Object -- Causes the specified object to leave this object. *
  612. * *
  613. * This routine is called, typically, by a transport building type that requires an object *
  614. * to leave it. This routine will place the object at a suitable location or return *
  615. * a value indicating why not. *
  616. * *
  617. * INPUT: object -- Pointer to the object that wishes to leave this object. *
  618. * *
  619. * OUTPUT: Returns the success value of the attempt: *
  620. * 0: Object could not be placed -- ever *
  621. * 1: Object placement is temporarily delayed -- try again later. *
  622. * 2: Object placement proceeded normally *
  623. * *
  624. * WARNINGS: none *
  625. * *
  626. * HISTORY: *
  627. * 09/21/1995 JLB : Created. *
  628. *=============================================================================================*/
  629. int ObjectClass::Exit_Object(TechnoClass *)
  630. {
  631. assert(this != 0);
  632. assert(IsActive);
  633. return(0);
  634. }
  635. /***********************************************************************************************
  636. * ObjectClass::Hidden -- Called when this object becomes hidden from the player. *
  637. * *
  638. * This routine is called when the object becomes hidden from the player. It can result in *
  639. * lost targeting and tracking abilities with respect to the hidden object. *
  640. * *
  641. * INPUT: none *
  642. * *
  643. * OUTPUT: none *
  644. * *
  645. * WARNINGS: none *
  646. * *
  647. * HISTORY: *
  648. * 09/21/1995 JLB : Created. *
  649. *=============================================================================================*/
  650. void ObjectClass::Hidden(void)
  651. {
  652. assert(this != 0);
  653. assert(IsActive);
  654. }
  655. /***********************************************************************************************
  656. * ObjectClass::Look -- Called when this object needs to reveal terrain. *
  657. * *
  658. * This routine is called when the object needs to look around the terrain. For player *
  659. * owned objects, the terrain is revealed. For non-player objects, not effect occurs. *
  660. * *
  661. * INPUT: incremental -- If true, then the looking algorithm will only examine the edges *
  662. * of the sight range. This is more efficient and work well if the *
  663. * object has only moved one cell since the last time it has performed *
  664. * the look operation. *
  665. * *
  666. * OUTPUT: none *
  667. * *
  668. * WARNINGS: This can be a time consuming operation. Call only when necessary. *
  669. * *
  670. * HISTORY: *
  671. * 09/21/1995 JLB : Created. *
  672. *=============================================================================================*/
  673. void ObjectClass::Look(bool )
  674. {
  675. assert(this != 0);
  676. assert(IsActive);
  677. }
  678. /***********************************************************************************************
  679. * ObjectClass::Active_Click_With -- Dispatches action on the object specified. *
  680. * *
  681. * This routine is called when this object is selected and the mouse was clicked on the *
  682. * tactical map. An action is required from the object. The object that the mouse was *
  683. * over and the tentative action to perform are provided as parameters. *
  684. * *
  685. * INPUT: action -- The requested action to perform with the object specified. *
  686. * *
  687. * object -- The object that the action should be performed on. This object is *
  688. * what the mouse was over when the click occurred. *
  689. * *
  690. * OUTPUT: none *
  691. * *
  692. * WARNINGS: none *
  693. * *
  694. * HISTORY: *
  695. * 09/21/1995 JLB : Created. *
  696. *=============================================================================================*/
  697. void ObjectClass::Active_Click_With(ActionType , ObjectClass *)
  698. {
  699. assert(this != 0);
  700. assert(IsActive);
  701. }
  702. /***********************************************************************************************
  703. * ObjectClass::Active_Click_With -- Dispatches action on the specified cell. *
  704. * *
  705. * This routine will dispatch the action requested upon the cell specified. It is called *
  706. * when the mouse is clicked over a cell while this object is selected. *
  707. * *
  708. * INPUT: action -- The action to perform. *
  709. * *
  710. * cell -- The location (cell) to perform this action upon. *
  711. * *
  712. * OUTPUT: none *
  713. * *
  714. * WARNINGS: none *
  715. * *
  716. * HISTORY: *
  717. * 09/21/1995 JLB : Created. *
  718. *=============================================================================================*/
  719. void ObjectClass::Active_Click_With(ActionType , CELL )
  720. {
  721. assert(this != 0);
  722. assert(IsActive);
  723. }
  724. /***********************************************************************************************
  725. * ObjectClass::Clicked_As_Target -- Triggers target selection animation. *
  726. * *
  727. * This routine is called when this object is the target of some player click action. *
  728. * For more sophisticated object, this will trigger the object to begin flashing a few *
  729. * times. At this level, no action is performed. *
  730. * *
  731. * INPUT: flashes -- The requested number of times to flash this object. *
  732. * *
  733. * OUTPUT: none *
  734. * *
  735. * WARNINGS: none *
  736. * *
  737. * HISTORY: *
  738. * 09/21/1995 JLB : Created. *
  739. *=============================================================================================*/
  740. void ObjectClass::Clicked_As_Target(int)
  741. {
  742. assert(this != 0);
  743. assert(IsActive);
  744. }
  745. /***********************************************************************************************
  746. * ObjectClass::In_Range -- Determines if the coordinate is within weapon range. *
  747. * *
  748. * This routine will determine if the specified coordinate is within weapon range. *
  749. * *
  750. * INPUT: coord -- The coordinate to check to see if it is within weapon range. *
  751. * *
  752. * which -- The weapon to check against. *
  753. * 0: primary weapon *
  754. * 1: secondary weapon *
  755. * *
  756. * OUTPUT: bool; Is the specified coordinate within weapon range for the weapon type *
  757. * specified? *
  758. * *
  759. * WARNINGS: none *
  760. * *
  761. * HISTORY: *
  762. * 09/21/1995 JLB : Created. *
  763. *=============================================================================================*/
  764. bool ObjectClass::In_Range(COORDINATE , int) const
  765. {
  766. assert(this != 0);
  767. assert(IsActive);
  768. return(false);
  769. }
  770. /***********************************************************************************************
  771. * ObjectClass::Weapon_Range -- Returns the weapon range for the weapon specified. *
  772. * *
  773. * This routine will return the weapon range according to the type of weapon specified. *
  774. * *
  775. * INPUT: which -- The weapon to fetch the range from. *
  776. * 0: primary weapon *
  777. * 1: secondary weapon *
  778. * *
  779. * OUTPUT: Returns with the range (in leptons) of the weapon specified. *
  780. * *
  781. * WARNINGS: none *
  782. * *
  783. * HISTORY: *
  784. * 09/21/1995 JLB : Created. *
  785. *=============================================================================================*/
  786. int ObjectClass::Weapon_Range(int) const
  787. {
  788. assert(this != 0);
  789. assert(IsActive);
  790. return(0);
  791. }
  792. /***********************************************************************************************
  793. * ObjectClass::Scatter -- Tries to scatter this object. *
  794. * *
  795. * This routine is used when the object should scatter from its current location. It *
  796. * applies to units that have the ability to move. *
  797. * *
  798. * INPUT: coord -- The source of the threat that is causing the scatter. *
  799. * *
  800. * forced-- Whether this scatter attempt is serious and scattering should occur *
  801. * regardless of what is doing now. *
  802. * *
  803. * OUTPUT: none *
  804. * *
  805. * WARNINGS: This may or may not cause the object to scatter. It is merely a request to the *
  806. * object that it would be good if it were to scatter. *
  807. * *
  808. * HISTORY: *
  809. * 09/21/1995 JLB : Created. *
  810. *=============================================================================================*/
  811. void ObjectClass::Scatter(COORDINATE , bool, bool)
  812. {
  813. assert(this != 0);
  814. assert(IsActive);
  815. }
  816. /***********************************************************************************************
  817. * ObjectClass::Catch_Fire -- Called when animation is attached to this object. *
  818. * *
  819. * This routine is called when an animation is attached to this object. It might be a *
  820. * fire animation (hence the name), but it might also be smoke or any other animation *
  821. * as well. *
  822. * *
  823. * INPUT: none *
  824. * *
  825. * OUTPUT: bool; Was the object caught on fire by this routine? Actually, this is really *
  826. * the answer to this question; "Is this animation attaching to this object *
  827. * that doesn't already have an animation attached?" *
  828. * *
  829. * WARNINGS: none *
  830. * *
  831. * HISTORY: *
  832. * 09/21/1995 JLB : Created. *
  833. *=============================================================================================*/
  834. bool ObjectClass::Catch_Fire(void)
  835. {
  836. assert(this != 0);
  837. assert(IsActive);
  838. return false;
  839. }
  840. /***********************************************************************************************
  841. * ObjectClass::Fire_Out -- Informs object that attached animation has finished. *
  842. * *
  843. * This routine is called if there is an attached animation on this object and that *
  844. * animation has finished. Typically, this is necessary for when trees are on fire. *
  845. * *
  846. * INPUT: none *
  847. * *
  848. * OUTPUT: none *
  849. * *
  850. * WARNINGS: none *
  851. * *
  852. * HISTORY: *
  853. * 07/24/1995 JLB : Created. *
  854. *=============================================================================================*/
  855. void ObjectClass::Fire_Out(void)
  856. {
  857. assert(this != 0);
  858. assert(IsActive);
  859. }
  860. /***********************************************************************************************
  861. * ObjectClass::Value -- Fetches the target value of this object. *
  862. * *
  863. * This routine will return the target value of this object. The higher the number, the *
  864. * better the object will be as a target. This routine is called when searching for *
  865. * targets. Generic objects have no target potential, and this routine returns zero to *
  866. * reflect that. Other object types will override this routine to return the appropriate *
  867. * target value. *
  868. * *
  869. * INPUT: none *
  870. * *
  871. * OUTPUT: Returns with the value of this object as a target. Higher values mean better *
  872. * target. *
  873. * *
  874. * WARNINGS: none *
  875. * *
  876. * HISTORY: *
  877. * 07/24/1995 JLB : Created. *
  878. *=============================================================================================*/
  879. int ObjectClass::Value(void) const
  880. {
  881. assert(this != 0);
  882. assert(IsActive);
  883. return(0);
  884. }
  885. /***********************************************************************************************
  886. * ObjectClass::Get_Mission -- Fetches the current mission of this object. *
  887. * *
  888. * Generic objects don't have a mission, so this routine will just return MISSION_NONE. *
  889. * However, techno objects do have a mission and this routine is overloaded to handle *
  890. * those objects in order to return the correct mission value. *
  891. * *
  892. * INPUT: none *
  893. * *
  894. * OUTPUT: Returns with the current mission being followed by this object. *
  895. * *
  896. * WARNINGS: none *
  897. * *
  898. * HISTORY: *
  899. * 07/24/1995 JLB : Created. *
  900. *=============================================================================================*/
  901. MissionType ObjectClass::Get_Mission(void) const
  902. {
  903. assert(this != 0);
  904. assert(IsActive);
  905. return(MISSION_NONE);
  906. }
  907. /***********************************************************************************************
  908. * ObjectClass::Repair -- Handles object repair control. *
  909. * *
  910. * This routine will control object repair mode. At the object level, no repair is *
  911. * possible, so it is expected that any object that can repair will override this function *
  912. * as necessary. *
  913. * *
  914. * INPUT: control -- The repair control parameter. *
  915. * 0 = turn repair off *
  916. * 1 = turn repair on *
  917. * -1 = toggle repair state *
  918. * *
  919. * OUTPUT: none *
  920. * *
  921. * WARNINGS: none *
  922. * *
  923. * HISTORY: *
  924. * 07/24/1995 JLB : Created. *
  925. *=============================================================================================*/
  926. void ObjectClass::Repair(int )
  927. {
  928. assert(this != 0);
  929. assert(IsActive);
  930. }
  931. /***********************************************************************************************
  932. * ObjectClass::Sell_Back -- Sells the object -- if possible. *
  933. * *
  934. * This routine is called to sell back the object. Override this routine for the more *
  935. * sophisticated objects that can actually be sold back. Normal objects can't be sold and *
  936. * this routine does nothing as a consequence. *
  937. * *
  938. * INPUT: control -- How to control the sell state of this object. *
  939. * 0 = stop selling. *
  940. * 1 = start selling. *
  941. * -1 = toggle selling state. *
  942. * *
  943. * OUTPUT: none *
  944. * *
  945. * WARNINGS: none *
  946. * *
  947. * HISTORY: *
  948. * 07/19/1995 JLB : Created. *
  949. *=============================================================================================*/
  950. void ObjectClass::Sell_Back(int )
  951. {
  952. assert(this != 0);
  953. assert(IsActive);
  954. }
  955. /***********************************************************************************************
  956. * ObjectClass::Move -- Moves (by force) the object in the desired direction. *
  957. * *
  958. * This routine will instantly move the object one cell in the specified direction. It *
  959. * moves the object by force. This is typically ONLY used by the scenario editor *
  960. * process. *
  961. * *
  962. * INPUT: facing -- The direction to move the object. *
  963. * *
  964. * OUTPUT: none *
  965. * *
  966. * WARNINGS: Naturally, this can cause illegal placement situations -- use with caution. *
  967. * *
  968. * HISTORY: *
  969. * 06/19/1994 JLB : Created. *
  970. *=============================================================================================*/
  971. void ObjectClass::Move(FacingType facing)
  972. {
  973. assert(this != 0);
  974. assert(IsActive);
  975. COORDINATE coord;
  976. Mark(MARK_UP);
  977. coord = Adjacent_Cell(Coord, facing);
  978. if (Can_Enter_Cell(Coord_Cell(coord)) == MOVE_OK) {
  979. Coord = coord;
  980. }
  981. Mark(MARK_DOWN);
  982. }
  983. /***********************************************************************************************
  984. * ObjectClass::Unselect -- This will un-select the object if it was selected. *
  985. * *
  986. * This routine brings a currently selected object into an unselected state. This is *
  987. * needed when another object becomes selected as well as if the object is destroyed. *
  988. * *
  989. * INPUT: none *
  990. * *
  991. * OUTPUT: none *
  992. * *
  993. * WARNINGS: none *
  994. * *
  995. * HISTORY: *
  996. * 06/19/1994 JLB : Created. *
  997. *=============================================================================================*/
  998. void ObjectClass::Unselect(void)
  999. {
  1000. assert(this != 0);
  1001. assert(IsActive);
  1002. if (IsSelected) {
  1003. CurrentObject.Delete(this);
  1004. if (In_Which_Layer() == LAYER_GROUND) Mark(MARK_OVERLAP_UP);
  1005. IsSelected = false;
  1006. if (In_Which_Layer() == LAYER_GROUND) Mark(MARK_OVERLAP_DOWN);
  1007. }
  1008. }
  1009. /***********************************************************************************************
  1010. * ObjectClass::Select -- Try to make this object the "selected" object. *
  1011. * *
  1012. * This routine is used to make this object into the one that is "selected". A selected *
  1013. * object usually displays a floating bar graph and is available to be given orders from *
  1014. * the player's I/O. *
  1015. * *
  1016. * INPUT: none *
  1017. * *
  1018. * OUTPUT: none *
  1019. * *
  1020. * WARNINGS: none *
  1021. * *
  1022. * HISTORY: *
  1023. * 06/19/1994 JLB : Created. *
  1024. * 06/12/1995 JLB : Cannot select a loaner object. *
  1025. * 07/23/1995 JLB : Adds to head or tail depending on leader type flag. *
  1026. *=============================================================================================*/
  1027. bool ObjectClass::Select(void)
  1028. {
  1029. assert(this != 0);
  1030. assert(IsActive);
  1031. if (!Debug_Map && (IsSelected || !Class_Of().IsSelectable)) {
  1032. return(false);
  1033. }
  1034. if (!Debug_Map && Can_Player_Move() && Is_Techno() && ((TechnoClass *)this)->IsALoaner) {
  1035. return(false);
  1036. }
  1037. /*
  1038. ** Don't allow selection if the object is still in the air.
  1039. */
  1040. if (Height > 0 && (What_Am_I() == RTTI_UNIT || What_Am_I() == RTTI_VESSEL || What_Am_I() == RTTI_INFANTRY)) {
  1041. return(false);
  1042. }
  1043. /*
  1044. ** Don't allow selection of object when in building placement mode.
  1045. */
  1046. if (Map.PendingObject) {
  1047. return(false);
  1048. }
  1049. /*
  1050. ** If selecting an object of a different house than the player's, make sure that
  1051. ** the entire selection list is cleared.
  1052. */
  1053. if (CurrentObject.Count() > 0) {
  1054. HouseClass * tryhptr = HouseClass::As_Pointer(Owner());
  1055. HouseClass * oldhptr = HouseClass::As_Pointer(CurrentObject[0]->Owner());
  1056. // if (Owner() != CurrentObject[0]->Owner() || CurrentObject[0]->Owner() != PlayerPtr->Class->House) {
  1057. if (oldhptr->IsPlayerControl != tryhptr->IsPlayerControl || !oldhptr->IsPlayerControl) {
  1058. Unselect_All();
  1059. }
  1060. }
  1061. if (((TechnoTypeClass const &)Class_Of()).IsLeader) {
  1062. CurrentObject.Add_Head(this);
  1063. } else {
  1064. CurrentObject.Add(this);
  1065. }
  1066. if (In_Which_Layer() == LAYER_GROUND) Mark(MARK_OVERLAP_UP);
  1067. IsSelected = true;
  1068. if (In_Which_Layer() == LAYER_GROUND) Mark(MARK_OVERLAP_DOWN);
  1069. return(true);
  1070. }
  1071. /***********************************************************************************************
  1072. * ObjectClass::Render -- Displays the object onto the map. *
  1073. * *
  1074. * This routine will determine the location of the object and if it is roughly on the *
  1075. * visible screen, it will display it. Not displaying objects that are not on the screen *
  1076. * will save valuable time. *
  1077. * *
  1078. * INPUT: bool; Should the render be forced regardless of whether the object is flagged to *
  1079. * be redrawn? *
  1080. * *
  1081. * OUTPUT: bool; Was the draw code called for this object? *
  1082. * *
  1083. * WARNINGS: none *
  1084. * *
  1085. * HISTORY: *
  1086. * 06/19/1994 JLB : Created. *
  1087. *=============================================================================================*/
  1088. bool ObjectClass::Render(bool forced) const
  1089. {
  1090. assert(this != 0);
  1091. assert(IsActive);
  1092. int x, y;
  1093. COORDINATE coord = Render_Coord();
  1094. CELL cell = Coord_Cell(coord);
  1095. if (Debug_Map || Debug_Unshroud || ((forced || IsToDisplay) && IsDown && !IsInLimbo)) {
  1096. IsToDisplay = false;
  1097. if (Map.Coord_To_Pixel(coord, x, y)) {
  1098. /*
  1099. ** Draw the object itself
  1100. */
  1101. Draw_It(x, y, WINDOW_TACTICAL);
  1102. #ifdef SCENARIO_EDITOR
  1103. /*
  1104. ** Draw the trigger attached to the object. Draw_It is window-
  1105. ** relative, so add the window's x-coord to 'x'.
  1106. */
  1107. if (Debug_Map && Trigger.Is_Valid()) {
  1108. Fancy_Text_Print(Trigger->Class->IniName,
  1109. x + (WinX), y,
  1110. &ColorRemaps[PCOLOR_RED], TBLACK,
  1111. TPF_CENTER | TPF_NOSHADOW | TPF_6POINT);
  1112. }
  1113. #endif
  1114. return(true);
  1115. }
  1116. }
  1117. return(false);
  1118. }
  1119. #ifdef CHEAT_KEYS
  1120. /***********************************************************************************************
  1121. * ObjectClass::Debug_Dump -- Displays status of the object class to the mono monitor. *
  1122. * *
  1123. * This routine is used to display the current status of the object class to the mono *
  1124. * monitor. *
  1125. * *
  1126. * INPUT: none *
  1127. * *
  1128. * OUTPUT: none *
  1129. * *
  1130. * WARNINGS: none *
  1131. * *
  1132. * HISTORY: *
  1133. * 06/02/1994 JLB : Created. *
  1134. *=============================================================================================*/
  1135. void ObjectClass::Debug_Dump(MonoClass * mono) const
  1136. {
  1137. mono->Set_Cursor(1, 1);mono->Printf("%-18.18s", Text_String(Full_Name()));
  1138. if (Next != NULL) {
  1139. mono->Set_Cursor(20, 5);mono->Printf("%08X", Next->As_Target());
  1140. }
  1141. if (Trigger.Is_Valid()) {
  1142. mono->Text_Print(Trigger->Class->IniName, 11, 3);
  1143. }
  1144. mono->Set_Cursor(34, 1);mono->Printf("%3d", Strength);
  1145. mono->Fill_Attrib(1, 13, 12, 1, IsDown ? MonoClass::INVERSE : MonoClass::NORMAL);
  1146. mono->Fill_Attrib(1, 14, 12, 1, IsToDamage ? MonoClass::INVERSE : MonoClass::NORMAL);
  1147. mono->Fill_Attrib(1, 15, 12, 1, IsToDisplay ? MonoClass::INVERSE : MonoClass::NORMAL);
  1148. mono->Fill_Attrib(1, 16, 12, 1, IsInLimbo ? MonoClass::INVERSE : MonoClass::NORMAL);
  1149. mono->Fill_Attrib(1, 17, 12, 1, IsSelected ? MonoClass::INVERSE : MonoClass::NORMAL);
  1150. mono->Fill_Attrib(14, 13, 12, 1, IsAnimAttached ? MonoClass::INVERSE : MonoClass::NORMAL);
  1151. mono->Set_Cursor(23, 14);mono->Printf("%d", Riser);
  1152. mono->Fill_Attrib(14, 12, 14, 1, IsFalling ? MonoClass::INVERSE : MonoClass::NORMAL);
  1153. AbstractClass::Debug_Dump(mono);
  1154. }
  1155. #endif
  1156. /***********************************************************************************************
  1157. * ObjectClass::Mark_For_Redraw -- Marks object and system for redraw. *
  1158. * *
  1159. * This routine will mark the object and inform the display system *
  1160. * that appropriate rendering is needed. Whenever it is determined *
  1161. * that an object needs to be redrawn, call this routine. *
  1162. * *
  1163. * INPUT: none *
  1164. * *
  1165. * OUTPUT: none *
  1166. * *
  1167. * WARNINGS: This is a subordinate function to the function Mark(). If an object needs to *
  1168. * be redrawn it is probably better to call the function Mark(MARK_CHANGE) rather *
  1169. * than this function. This function does not inform the map system that *
  1170. * overlapping objects are to be redrawn and thus unless you are really sure that *
  1171. * this routine should be called, don't. *
  1172. * *
  1173. * HISTORY: *
  1174. * 05/08/1994 JLB : Created. *
  1175. * 12/23/1994 JLB : Flags map and flags unit only. *
  1176. *=============================================================================================*/
  1177. void ObjectClass::Mark_For_Redraw(void)
  1178. {
  1179. assert(this != 0);
  1180. assert(IsActive);
  1181. if (!IsToDisplay) {
  1182. IsToDisplay = true;
  1183. /*
  1184. ** This tells the map rendering logic to "go through the motions" and call the
  1185. ** rendering function. In the rendering function, it will sort out what gets
  1186. ** rendered and what doesn't.
  1187. */
  1188. Map.Flag_To_Redraw(false);
  1189. }
  1190. }
  1191. /***********************************************************************************************
  1192. * ObjectClass::Limbo -- Brings the object into a state of limbo. *
  1193. * *
  1194. * An object brought into a state of limbo by this routine can be safely deleted. This *
  1195. * routine will remove the object from all game lists and tracking systems. It is called *
  1196. * prior to deleting the object or placing the object "on ice". *
  1197. * *
  1198. * INPUT: none *
  1199. * *
  1200. * OUTPUT: bool; Was the object successfully placed in limbo? *
  1201. * *
  1202. * WARNINGS: none *
  1203. * *
  1204. * HISTORY: *
  1205. * 09/24/1994 JLB : Created. *
  1206. *=============================================================================================*/
  1207. bool ObjectClass::Limbo(void)
  1208. {
  1209. assert(this != 0);
  1210. assert(IsActive);
  1211. if (GameActive && !IsInLimbo) {
  1212. Unselect();
  1213. Detach_All();
  1214. Mark(MARK_UP);
  1215. /*
  1216. ** Remove the object from the appropriate display list.
  1217. */
  1218. Map.Remove(this, In_Which_Layer());
  1219. /*
  1220. ** Remove the object from the logic processing list.
  1221. */
  1222. if (Class_Of().IsSentient) {
  1223. Logic.Delete(this);
  1224. }
  1225. Hidden();
  1226. IsInLimbo = true;
  1227. IsToDisplay = false;
  1228. return(true);
  1229. }
  1230. return(false);
  1231. }
  1232. /***********************************************************************************************
  1233. * ObjectClass::Unlimbo -- Brings the object into the game system. *
  1234. * *
  1235. * This routine will place the object into the game tracking and display systems. It is *
  1236. * called as a consequence of creating the object. Every game object must be unlimboed at *
  1237. * some point. *
  1238. * *
  1239. * INPUT: coord -- The coordinate to place the object into the game system. *
  1240. * *
  1241. * dir (optional) -- initial facing direction for this object *
  1242. * *
  1243. * OUTPUT: bool; Was the game object successfully unlimboed? *
  1244. * *
  1245. * WARNINGS: none *
  1246. * *
  1247. * HISTORY: *
  1248. * 09/24/1994 JLB : Created. *
  1249. * 12/23/1994 JLB : Sets object strength. *
  1250. *=============================================================================================*/
  1251. bool ObjectClass::Unlimbo(COORDINATE coord, DirType )
  1252. {
  1253. assert(this != 0);
  1254. assert(IsActive);
  1255. if (GameActive && IsInLimbo && !IsDown) {
  1256. if (ScenarioInit || Can_Enter_Cell(Coord_Cell(coord), FACING_NONE) == MOVE_OK) {
  1257. IsInLimbo = false;
  1258. IsToDisplay = false;
  1259. Coord = Class_Of().Coord_Fixup(coord);
  1260. if (Mark(MARK_DOWN)) {
  1261. if (IsActive) {
  1262. /*
  1263. ** Add the object to the appropriate map layer. This layer is used
  1264. ** for rendering purposes.
  1265. */
  1266. if (In_Which_Layer() != LAYER_NONE) {
  1267. Map.Submit(this, In_Which_Layer());
  1268. }
  1269. if (Class_Of().IsSentient) {
  1270. Logic.Submit(this);
  1271. }
  1272. }
  1273. return(true);
  1274. }
  1275. }
  1276. }
  1277. return(false);
  1278. }
  1279. /***********************************************************************************************
  1280. * ObjectClass::Detach -- Detach the specified target from this object. *
  1281. * *
  1282. * This routine is called when the object (as specified) is to be removed from the game *
  1283. * engine and thus, all references to it must be severed. Typically, the only thing *
  1284. * checked for at this level is the attached trigger. *
  1285. * *
  1286. * INPUT: target -- The target that will be removed from the game system. *
  1287. * *
  1288. * OUTPUT: none *
  1289. * *
  1290. * WARNINGS: none *
  1291. * *
  1292. * HISTORY: *
  1293. * 07/29/1996 JLB : Created. *
  1294. *=============================================================================================*/
  1295. void ObjectClass::Detach(TARGET target, bool )
  1296. {
  1297. if (Trigger.Is_Valid() && Is_Target_Trigger(target) && Trigger->As_Target() == target) {
  1298. Attach_Trigger(NULL);
  1299. }
  1300. }
  1301. /***********************************************************************************************
  1302. * ObjectClass::Detach_All -- Removes the object from all tracking systems. *
  1303. * *
  1304. * This routine will take the object and see that it is removed from all miscellaneous *
  1305. * tracking systems in the game. This operation is vital when deleting an object. It is *
  1306. * necessary so that when the object is removed from the game, existing game objects won't *
  1307. * be referencing a now invalid game object. This typically affects the targeting *
  1308. * and navigation computers of other game objects. *
  1309. * *
  1310. * INPUT: none *
  1311. * *
  1312. * OUTPUT: none *
  1313. * *
  1314. * WARNINGS: none *
  1315. * *
  1316. * HISTORY: *
  1317. * 09/24/1994 JLB : Created. *
  1318. *=============================================================================================*/
  1319. void ObjectClass::Detach_All(bool all)
  1320. {
  1321. assert(this != 0);
  1322. assert(IsActive);
  1323. /*
  1324. ** Unselect this object if it was selected.
  1325. */
  1326. if (all || Owner() != PlayerPtr->Class->House) {
  1327. Unselect();
  1328. }
  1329. Map.Detach(this);
  1330. /*
  1331. ** Remove from targeting computers.
  1332. */
  1333. Detach_This_From_All(As_Target(), all);
  1334. }
  1335. /***********************************************************************************************
  1336. * ObjectClass::Receive_Message -- Processes an incoming radio message. *
  1337. * *
  1338. * Any radio message received that applies to objects in general are handled by this *
  1339. * routine. Typically, this is the "redraw" message, which occurs when another object is *
  1340. * loading or unloading and thus overlapping. *
  1341. * *
  1342. * INPUT: message -- The message received. *
  1343. * *
  1344. * OUTPUT: Returns with the appropriate radio response. If the message was recognized, then *
  1345. * RADIO_ROGER is returned, otherwise, just RADIO_STATIC is returned. *
  1346. * *
  1347. * WARNINGS: none *
  1348. * *
  1349. * HISTORY: *
  1350. * 09/24/1994 JLB : Created. *
  1351. *=============================================================================================*/
  1352. RadioMessageType ObjectClass::Receive_Message(RadioClass *, RadioMessageType message, long & )
  1353. {
  1354. assert(this != 0);
  1355. assert(IsActive);
  1356. switch (message) {
  1357. /*
  1358. ** This message serves as a rendering convenience. It lets the system
  1359. ** know that there might be a visual conflict and the unit in radio
  1360. ** contact should be redrawn. This typically occurs when a vehicle
  1361. ** is being unloaded from a hover lander.
  1362. */
  1363. case RADIO_REDRAW:
  1364. Mark(MARK_CHANGE);
  1365. return(RADIO_ROGER);
  1366. default:
  1367. break;
  1368. }
  1369. return(RADIO_STATIC);
  1370. }
  1371. /***********************************************************************************************
  1372. * ObjectClass::Take_Damage -- Applies damage to the object. *
  1373. * *
  1374. * This routine applies damage to the object according to the damage parameters. It handles *
  1375. * reducing the strength of the object and also returns the result of that damage. The *
  1376. * result value can be examined to determine if the object was destroyed, greatly damaged, *
  1377. * or other results. *
  1378. * *
  1379. * INPUT: damage -- Reference to the damage number to apply. This number will be adjusted *
  1380. * according to defensive armor and distance. Examine this value after *
  1381. * the call to determine the actual amount of damage applied. *
  1382. * *
  1383. * distance -- The distance (in leptons) from the center of the damage causing *
  1384. * explosion to the object itself. *
  1385. * *
  1386. * warhead -- The warhead type that is causing the damage. *
  1387. * *
  1388. * source -- The perpetrator of this damage. *
  1389. * *
  1390. * forced -- Is the damage forced upon the object regardless of whether it *
  1391. * is normally immune? *
  1392. * *
  1393. * OUTPUT: Returns the ResultType that indicates what the affect of the damage was. *
  1394. * *
  1395. * WARNINGS: none *
  1396. * *
  1397. * HISTORY: *
  1398. * 11/29/1994 JLB : Created. *
  1399. * 12/27/1994 JLB : Trigger event processing for attacked or destroyed. *
  1400. * 01/01/1995 JLB : Reduces damage greatly depending on range. *
  1401. *=============================================================================================*/
  1402. ResultType ObjectClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, int forced)
  1403. {
  1404. assert(this != 0);
  1405. assert(IsActive);
  1406. ResultType result = RESULT_NONE;
  1407. int oldstrength = Strength;
  1408. if (oldstrength && damage != 0 && (forced || !Class_Of().IsImmune)) {
  1409. int maxstrength = Class_Of().MaxStrength;
  1410. /*
  1411. ** Modify damage based on the warhead type and the armor of the object. This results
  1412. ** in a reduced damage value, but never below 1 damage point. Unless
  1413. ** it's forced damage, in which case we want full damage.
  1414. */
  1415. if (!forced /*&& damage > 0*/) {
  1416. damage = Modify_Damage(damage, warhead, Class_Of().Armor, distance);
  1417. /*
  1418. ** Special hack to ensure that dogs only do damage to intended victim and no
  1419. ** damage to others.
  1420. */
  1421. if (source && source->What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)source)->Class->IsDog) {
  1422. if (source->TarCom == As_Target()) {
  1423. damage = Strength;
  1424. } else {
  1425. damage = 0;
  1426. }
  1427. }
  1428. }
  1429. if (damage == 0) return(RESULT_NONE);
  1430. /*
  1431. ** Are we healing/repairing? If so, add strength, but in
  1432. ** any case, return that no damage was done.
  1433. */
  1434. if (damage < 0) {
  1435. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1436. if (What_Am_I() == RTTI_INFANTRY || What_Am_I() == RTTI_UNIT || What_Am_I() == RTTI_AIRCRAFT) {
  1437. #else
  1438. if (What_Am_I() == RTTI_INFANTRY) {
  1439. #endif
  1440. Clicked_As_Target(7);
  1441. Strength -= damage;
  1442. if (Strength > maxstrength) {
  1443. Strength = maxstrength;
  1444. }
  1445. }
  1446. return(RESULT_NONE);
  1447. }
  1448. /*
  1449. ** At this point, we KNOW that at least light damage has occurred.
  1450. */
  1451. result = RESULT_LIGHT;
  1452. /*
  1453. ** A non-fatal blow has occurred. Check to see if the object transitioned to below
  1454. ** half strength or if it is now down to one hit point.
  1455. */
  1456. if (oldstrength > damage) {
  1457. if (oldstrength >= (maxstrength >> 1) && (oldstrength-damage) < (maxstrength >> 1)) {
  1458. result = RESULT_HALF;
  1459. }
  1460. } else {
  1461. /*
  1462. ** When an object is damaged to destruction, it will instead stop at one
  1463. ** damage point. This will prolong the damage state as well as
  1464. ** give greater satisfaction when it is finally destroyed.
  1465. */
  1466. damage = oldstrength;
  1467. }
  1468. /*
  1469. ** Apply the damage to the object.
  1470. */
  1471. Strength = oldstrength - damage;
  1472. /*
  1473. ** Check to see if the object is majorly damaged or destroyed.
  1474. */
  1475. switch (Strength) {
  1476. case 0:
  1477. Record_The_Kill(source);
  1478. result = RESULT_DESTROYED;
  1479. if (this->Is_Techno()) {
  1480. if (this == ::As_Object(((TechnoClass *)this)->House->UnitToTeleport)) ((TechnoClass *)this)->House->UnitToTeleport = 0;
  1481. }
  1482. Detach_All();
  1483. break;
  1484. case 1:
  1485. result = RESULT_MAJOR;
  1486. break;
  1487. default:
  1488. break;
  1489. }
  1490. /*
  1491. ** Handle any trigger event associated with this object.
  1492. */
  1493. if (source && Trigger.Is_Valid() && result != RESULT_DESTROYED) {
  1494. Trigger->Spring(TEVENT_ATTACKED, this);
  1495. }
  1496. /*
  1497. ** If any damage was assessed and this object is selected, then flag
  1498. ** the object to be redrawn so that the health bar will be updated.
  1499. */
  1500. if (result != RESULT_NONE && IsSelected) {
  1501. Mark(MARK_CHANGE);
  1502. }
  1503. }
  1504. /*
  1505. ** Return with the result of the damage taken.
  1506. */
  1507. return(result);
  1508. }
  1509. /***********************************************************************************************
  1510. * ObjectClass::Mark -- Handles basic marking logic. *
  1511. * *
  1512. * This routine handles the base logic for marking an object up or down on the map. It *
  1513. * manages the IsDown flag as well as flagging the object to be redrawn if necessary. *
  1514. * Whenever an object is to be marked, it should call this base class function first. If *
  1515. * this function returns true, then the higher level function should proceed with its own *
  1516. * logic. *
  1517. * *
  1518. * INPUT: mark -- The marking method to use for this object. It can be either MARK_DOWN, *
  1519. * MARK_UP, or MARK_CHANGE. *
  1520. * *
  1521. * OUTPUT: bool; Was the object marked successfully? *
  1522. * *
  1523. * WARNINGS: none *
  1524. * *
  1525. * HISTORY: *
  1526. * 01/23/1995 JLB : Created. *
  1527. *=============================================================================================*/
  1528. bool ObjectClass::Mark(MarkType mark)
  1529. {
  1530. assert(this != 0);
  1531. assert(IsActive);
  1532. if (!IsInLimbo && IsActive) {
  1533. /*
  1534. ** A mark for change is always successful UNLESS the object
  1535. ** is not placed down or has already been flagged as changed
  1536. ** this game frame.
  1537. */
  1538. if (mark == MARK_CHANGE || mark == MARK_CHANGE_REDRAW) {
  1539. if (IsToDisplay && mark != MARK_CHANGE_REDRAW) return(false);
  1540. if (IsDown) {
  1541. Mark_For_Redraw();
  1542. return(true);
  1543. }
  1544. return(false);
  1545. }
  1546. /*
  1547. ** Handle adding or removing the object in the cells' overlap lists
  1548. */
  1549. if (mark == MARK_OVERLAP_UP) {
  1550. if (IsDown == true) {
  1551. if (Class_Of().IsFootprint) {
  1552. Map.Overlap_Up(Coord_Cell(Coord), this);
  1553. }
  1554. Mark_For_Redraw();
  1555. return(true);
  1556. }
  1557. }
  1558. if (mark == MARK_OVERLAP_DOWN) {
  1559. if (IsDown == true) {
  1560. if (Class_Of().IsFootprint) {
  1561. Map.Overlap_Down(Coord_Cell(Coord), this);
  1562. }
  1563. Mark_For_Redraw();
  1564. return(true);
  1565. }
  1566. }
  1567. /*
  1568. ** It is important to know whether the object is a techno class
  1569. ** or not to see if we have to adjust the regional threat ratings
  1570. */
  1571. int threat = 0;
  1572. HousesType house = HOUSE_NONE;
  1573. CELL cell = 0;
  1574. TechnoClass * tech;
  1575. if (Is_Techno()) {
  1576. tech = (TechnoClass *)this;
  1577. threat = tech->Risk();
  1578. house = tech->Owner();
  1579. cell = Coord_Cell(Coord);
  1580. } else {
  1581. tech = NULL;
  1582. }
  1583. /*
  1584. ** Marking down is only successful if the object isn't already
  1585. ** placed down.
  1586. */
  1587. if (mark == MARK_DOWN && !IsDown) {
  1588. if (tech && Session.Type == GAME_NORMAL && In_Which_Layer() == LAYER_GROUND) {
  1589. Map[cell].Adjust_Threat(house, threat);
  1590. }
  1591. IsDown = true;
  1592. Mark_For_Redraw();
  1593. return(true);
  1594. }
  1595. /*
  1596. ** Lifting up is only successful if the object isn't already
  1597. ** lifted up from the map.
  1598. */
  1599. if (mark == MARK_UP && IsDown) {
  1600. if (tech && Session.Type == GAME_NORMAL && In_Which_Layer() == LAYER_GROUND) {
  1601. Map[cell].Adjust_Threat(house, -threat);
  1602. }
  1603. IsDown = false;
  1604. return(true);
  1605. }
  1606. }
  1607. return(false);
  1608. }
  1609. /***********************************************************************************************
  1610. * ObjectClass::Init -- Initializes the basic object system. *
  1611. * *
  1612. * This routine should be called when the basic object system needs to be initialized. This *
  1613. * occurs when the scenario is about to be loaded. *
  1614. * *
  1615. * INPUT: none *
  1616. * *
  1617. * OUTPUT: none *
  1618. * *
  1619. * WARNINGS: none *
  1620. * *
  1621. * HISTORY: *
  1622. * 01/23/1995 JLB : Created. *
  1623. *=============================================================================================*/
  1624. void ObjectClass::Init(void)
  1625. {
  1626. CurrentObject.Clear();
  1627. }
  1628. /***********************************************************************************************
  1629. * ObjectClass::Revealed -- Reveals this object to the house specified. *
  1630. * *
  1631. * This routine is called when this object gets revealed to the house specified. *
  1632. * *
  1633. * INPUT: house -- Pointer to the house that this object is being revealed to. *
  1634. * *
  1635. * OUTPUT: Was this object revealed for the first time to this house? Generic objects always *
  1636. * return true unless an invalid house pointer was specified. *
  1637. * *
  1638. * WARNINGS: none *
  1639. * *
  1640. * HISTORY: *
  1641. * 07/19/1995 JLB : Created. *
  1642. *=============================================================================================*/
  1643. bool ObjectClass::Revealed(HouseClass * house)
  1644. {
  1645. assert(this != 0);
  1646. assert(IsActive);
  1647. return(house != NULL);
  1648. }
  1649. /***********************************************************************************************
  1650. * ObjectClass::Paradrop -- Unlimbos object in paradrop mode. *
  1651. * *
  1652. * Call this routine as a replacement for Unlimbo() if the object is to be paradropped onto *
  1653. * the playing field. *
  1654. * *
  1655. * INPUT: coord -- The desired landing coordinate to give the dropping unit. *
  1656. * *
  1657. * OUTPUT: bool; Was the object successfully unlimboed and has begun paradropping? *
  1658. * *
  1659. * WARNINGS: The unit may not be successful in paradropping if the desired destination *
  1660. * location cannot be occupied by the object. *
  1661. * *
  1662. * HISTORY: *
  1663. * 02/07/1996 JLB : Created. *
  1664. *=============================================================================================*/
  1665. bool ObjectClass::Paradrop(COORDINATE coord)
  1666. {
  1667. assert(this != 0);
  1668. assert(IsActive);
  1669. Height = FLIGHT_LEVEL;
  1670. IsFalling = true;
  1671. if (Unlimbo(coord, DIR_S)) {
  1672. AnimClass * anim = NULL;
  1673. if (What_Am_I() == RTTI_BULLET) {
  1674. anim = new AnimClass(ANIM_PARA_BOMB, Coord_Move(Center_Coord(), DIR_N, 0x0030 + Height));
  1675. } else {
  1676. anim = new AnimClass(ANIM_PARACHUTE, Coord_Move(Center_Coord(), DIR_N, 0x0030 + Height));
  1677. }
  1678. /*
  1679. ** If the animation was created, then attach it to this object.
  1680. */
  1681. if (anim != NULL) {
  1682. anim->Attach_To(this);
  1683. }
  1684. return(true);
  1685. }
  1686. return(false);
  1687. }
  1688. /***********************************************************************************************
  1689. * ObjectClass::Attach_Trigger -- Attach specified trigger to object. *
  1690. * *
  1691. * This routine is used to attach the specified trigger to the object. *
  1692. * *
  1693. * INPUT: trigger -- Pointer to the trigger to attach. If any existing trigger is desired *
  1694. * to be detached, then pass NULL to this routine. *
  1695. * *
  1696. * OUTPUT: bool; Was the trigger attached? *
  1697. * *
  1698. * WARNINGS: none *
  1699. * *
  1700. * HISTORY: *
  1701. * 05/06/1996 JLB : Created. *
  1702. *=============================================================================================*/
  1703. bool ObjectClass::Attach_Trigger(TriggerClass * trigger)
  1704. {
  1705. if (Trigger.Is_Valid()) {
  1706. TriggerClass * tptr = Trigger;
  1707. tptr->AttachCount--;
  1708. Trigger = NULL;
  1709. }
  1710. if (trigger) {
  1711. Trigger = trigger;
  1712. trigger->AttachCount++;
  1713. return(true);
  1714. }
  1715. return(false);
  1716. }
  1717. // These can't be made inline (for various reasons).
  1718. short const * ObjectClass::Occupy_List(bool placement) const {return(Class_Of().Occupy_List(placement));};
  1719. short const * ObjectClass::Overlap_List(bool ) const {return(Class_Of().Overlap_List());};
  1720. BuildingClass * ObjectClass::Who_Can_Build_Me(bool intheory, bool legal) const {return(Class_Of().Who_Can_Build_Me(intheory, legal, Owner()));};
  1721. fixed ObjectClass::Health_Ratio(void) const {return(fixed(Strength, Class_Of().MaxStrength));};
  1722. int ObjectClass::Full_Name(void) const {return Class_Of().Full_Name();};
  1723. //**********************************************************************************************
  1724. // MODULE SEPARATION -- ObjectTypeClass member functions follow.
  1725. //**********************************************************************************************
  1726. /***********************************************************************************************
  1727. * ObjectTypeClass::ObjectTypeClass -- Normal constructor for object type class objects. *
  1728. * *
  1729. * This is the base constructor that is used when constructing the object type classes. *
  1730. * Every tangible game piece type calls this constructor for the ObjectTypeClass. This *
  1731. * class holds static information that is common to objects in general. *
  1732. * *
  1733. * INPUT: see below... *
  1734. * *
  1735. * OUTPUT: none *
  1736. * *
  1737. * WARNINGS: none *
  1738. * *
  1739. * HISTORY: *
  1740. * 03/23/1995 JLB : Created. *
  1741. *=============================================================================================*/
  1742. ObjectTypeClass::ObjectTypeClass(
  1743. RTTIType rtti,
  1744. int id,
  1745. bool is_sentient,
  1746. bool is_stealthy,
  1747. bool is_selectable,
  1748. bool is_legal_target,
  1749. bool is_insignificant,
  1750. bool is_immune,
  1751. bool is_footprint,
  1752. int name,
  1753. char const * ini) :
  1754. AbstractTypeClass(rtti, id, name, ini),
  1755. IsCrushable(false),
  1756. IsStealthy(is_stealthy),
  1757. IsSelectable(is_selectable),
  1758. IsLegalTarget(is_legal_target),
  1759. IsInsignificant(is_insignificant),
  1760. IsImmune(is_immune),
  1761. IsSentient(is_sentient),
  1762. IsFootprint(is_footprint),
  1763. Armor(ARMOR_NONE),
  1764. MaxStrength(0),
  1765. ImageData(0),
  1766. RadarIcon(0)
  1767. {
  1768. }
  1769. /***********************************************************************************************
  1770. * ObjectTypeClass::Max_Pips -- Fetches the maximum pips allowed for this object. *
  1771. * *
  1772. * This routine will return the maximum number of pips that can be displayed for this *
  1773. * object. When dealing with generic objects, this value is always zero. *
  1774. * *
  1775. * INPUT: none *
  1776. * *
  1777. * OUTPUT: Returns with the number of pip boxes (empty or otherwise) to display. *
  1778. * *
  1779. * WARNINGS: none *
  1780. * *
  1781. * HISTORY: *
  1782. * 07/19/1995 JLB : Created. *
  1783. *=============================================================================================*/
  1784. int ObjectTypeClass::Max_Pips(void) const
  1785. {
  1786. return(0);
  1787. }
  1788. /***********************************************************************************************
  1789. * ObjectTypeClass::Dimensions -- Gets the dimensions of the object in pixels. *
  1790. * *
  1791. * This routine will fetch the dimensions of this object expressed as pixels width and *
  1792. * pixels height. This information can be used to intelligently update the clipping *
  1793. * rectangles. *
  1794. * *
  1795. * INPUT: width -- Reference to the width variable that will be filled in. *
  1796. * *
  1797. * height -- Reference to the height variable that will be filled in. *
  1798. * *
  1799. * OUTPUT: none *
  1800. * *
  1801. * WARNINGS: none *
  1802. * *
  1803. * HISTORY: *
  1804. * 07/19/1995 JLB : Created. *
  1805. *=============================================================================================*/
  1806. void ObjectTypeClass::Dimensions(int &width, int &height) const
  1807. {
  1808. width = 10;
  1809. height = 10;
  1810. }
  1811. /***********************************************************************************************
  1812. * ObjectTypeClass::Cost_Of -- Returns the cost to buy this unit. *
  1813. * *
  1814. * This routine will return the cost to purchase this unit. This routine is expected to be *
  1815. * overridden by the objects that can actually be purchased. All other object types can *
  1816. * simply return zero since this value won't be used. *
  1817. * *
  1818. * INPUT: none *
  1819. * *
  1820. * OUTPUT: Returns the cost of the object. *
  1821. * *
  1822. * WARNINGS: none *
  1823. * *
  1824. * HISTORY: *
  1825. * 07/19/1995 JLB : Created. *
  1826. *=============================================================================================*/
  1827. int ObjectTypeClass::Cost_Of(void) const
  1828. {
  1829. return(0);
  1830. }
  1831. /***********************************************************************************************
  1832. * ObjectTypeClass::Time_To_Build -- Fetches the time to construct this object. *
  1833. * *
  1834. * This routine will fetch the time in takes to construct this object. Objects that can *
  1835. * be constructed will override this routine in order to return a useful value. *
  1836. * *
  1837. * INPUT: none *
  1838. * *
  1839. * OUTPUT: Returns with the time units (arbitrary) that it takes to construct this object. *
  1840. * *
  1841. * WARNINGS: none *
  1842. * *
  1843. * HISTORY: *
  1844. * 07/19/1995 JLB : Created. *
  1845. *=============================================================================================*/
  1846. int ObjectTypeClass::Time_To_Build(void) const
  1847. {
  1848. return(0);
  1849. }
  1850. /***********************************************************************************************
  1851. * ObjectTypeClass::Get_Cameo_Data -- Fetches pointer to cameo data for this object type. *
  1852. * *
  1853. * This routine will return with the cameo data pointer for this object type. It is *
  1854. * expected that objects that can appear on the sidebar will override this routine in order *
  1855. * to provide proper cameo data pointer. *
  1856. * *
  1857. * INPUT: none *
  1858. * *
  1859. * OUTPUT: Returns with a pointer to the cameo shape data. *
  1860. * *
  1861. * WARNINGS: none *
  1862. * *
  1863. * HISTORY: *
  1864. * 07/19/1995 JLB : Created. *
  1865. *=============================================================================================*/
  1866. void const * ObjectTypeClass::Get_Cameo_Data(void) const
  1867. {
  1868. return(NULL);
  1869. }
  1870. /***********************************************************************************************
  1871. * ObjectTypeClass::Occupy_List -- Returns with simple occupation list for object. *
  1872. * *
  1873. * This routine returns a pointer to a simple occupation list for this object. Since at *
  1874. * this tier of the object class chain, the exact shape of the object is indeterminate, *
  1875. * this function merely returns a single cell occupation list. This actually works for *
  1876. * most vehicles. *
  1877. * *
  1878. * INPUT: none *
  1879. * *
  1880. * OUTPUT: Returns a pointer to a simple occupation list. *
  1881. * *
  1882. * WARNINGS: none *
  1883. * *
  1884. * HISTORY: *
  1885. * 05/28/1994 JLB : Created. *
  1886. *=============================================================================================*/
  1887. short const * ObjectTypeClass::Occupy_List(bool) const
  1888. {
  1889. static short const _list[] = {0, REFRESH_EOL};
  1890. return(_list);
  1891. }
  1892. /***********************************************************************************************
  1893. * ObjectTypeClass::Overlap_List -- Returns a pointer to a simple overlap list. *
  1894. * *
  1895. * This function returns a pointer to an overlap list for the object. An overlap list is *
  1896. * the offsets from the object's cell to get the cells the imagery overlaps, but is object *
  1897. * is not considered to occupy. Since at this stage, the overlap information is not *
  1898. * available, this function merely returns a pointer to an empty list. *
  1899. * *
  1900. * INPUT: none *
  1901. * *
  1902. * OUTPUT: Returns a pointer to the generic overlap list. *
  1903. * *
  1904. * WARNINGS: none *
  1905. * *
  1906. * HISTORY: *
  1907. * 05/28/1994 JLB : Created. *
  1908. *=============================================================================================*/
  1909. short const * ObjectTypeClass::Overlap_List(void) const
  1910. {
  1911. static short const _list[] = {REFRESH_EOL};
  1912. return(_list);
  1913. }
  1914. /***********************************************************************************************
  1915. * ObjectTypeClass::One_Time -- Handles one time processing for object types. *
  1916. * *
  1917. * This routine is used to handle the once per game processing required for object types. *
  1918. * This consists of loading any data and initializing any data tables the game requires. *
  1919. * *
  1920. * INPUT: none *
  1921. * *
  1922. * OUTPUT: none *
  1923. * *
  1924. * WARNINGS: This routine goes to disk. *
  1925. * *
  1926. * HISTORY: *
  1927. * 11/01/1994 JLB : Created. *
  1928. *=============================================================================================*/
  1929. void ObjectTypeClass::One_Time(void)
  1930. {
  1931. SelectShapes = MFCD::Retrieve("SELECT.SHP");
  1932. #ifndef NDEBUG
  1933. RawFileClass file("PIPS.SHP");
  1934. if (file.Is_Available()) {
  1935. PipShapes = Load_Alloc_Data(file);
  1936. } else {
  1937. PipShapes = MFCD::Retrieve("PIPS.SHP");
  1938. }
  1939. #else
  1940. PipShapes = MFCD::Retrieve("PIPS.SHP");
  1941. #endif
  1942. }
  1943. /***********************************************************************************************
  1944. * ObjectTypeClass::Who_Can_Build_Me -- Determine what building can build this object type. *
  1945. * *
  1946. * This routine will scan through all available factory buildings and determine which *
  1947. * is capable of building this object type. The scan can be controlled to scan for only *
  1948. * factory buildings that are free to produce now or those that could produce this *
  1949. * object type if conditions permit. *
  1950. * *
  1951. * INPUT: intheory -- Should the general (when conditions permit) case be examined to see *
  1952. * if a building could build this object type "in theory" even though it *
  1953. * might currently be otherwise occupied? *
  1954. * *
  1955. * legal -- Check for building prerequisite and technology level rules? Usually *
  1956. * this would be 'true' for human controlled requests and 'false' for *
  1957. * the computer. This is because the computer is usually not under *
  1958. * the normal restrictions that the player is under. *
  1959. * *
  1960. * OUTPUT: Returns with a pointer to the building that can produce the object of this *
  1961. * type. If no suitable factory building could be found, then NULL is returned. *
  1962. * *
  1963. * WARNINGS: none *
  1964. * *
  1965. * HISTORY: *
  1966. * 07/29/1996 JLB : Created. *
  1967. *=============================================================================================*/
  1968. BuildingClass * ObjectTypeClass::Who_Can_Build_Me(bool intheory, bool legal, HousesType house) const
  1969. {
  1970. BuildingClass * anybuilding = NULL;
  1971. for (int index = 0; index < Buildings.Count(); index++) {
  1972. BuildingClass * building = Buildings.Ptr(index);
  1973. assert(building != NULL);
  1974. if ( !building->IsInLimbo &&
  1975. building->House->Class->House == house &&
  1976. building->Class->ToBuild == RTTI &&
  1977. building->Mission != MISSION_DECONSTRUCTION && building->MissionQueue != MISSION_DECONSTRUCTION &&
  1978. ((1L << building->ActLike) & Get_Ownable()) &&
  1979. (!legal || building->House->Can_Build(this, building->ActLike)) &&
  1980. (intheory || !building->In_Radio_Contact())) {
  1981. // BG: Hack so only kennels can build dogs, and no other, and barracks can
  1982. // only build humans and no other.
  1983. if (What_Am_I() == RTTI_INFANTRYTYPE) {
  1984. InfantryTypeClass * me = (InfantryTypeClass *)this;
  1985. if (me->IsDog) {
  1986. if (*building == STRUCT_KENNEL) {
  1987. if (building->IsLeader) return(building);
  1988. anybuilding = building;
  1989. }
  1990. } else {
  1991. if (*building != STRUCT_KENNEL) {
  1992. if (building->IsLeader) return(building);
  1993. anybuilding = building;
  1994. }
  1995. }
  1996. } else {
  1997. /*
  1998. ** HACK ALERT: Helipads can build aircraft and airstrips can build
  1999. ** fixed wing craft only.
  2000. */
  2001. if (What_Am_I() == RTTI_AIRCRAFTTYPE) {
  2002. AircraftTypeClass * air = (AircraftTypeClass *)this;
  2003. if ((*building == STRUCT_HELIPAD && !air->IsFixedWing) || (*building == STRUCT_AIRSTRIP && air->IsFixedWing)) {
  2004. if (building->IsLeader) return(building);
  2005. anybuilding = building;
  2006. }
  2007. } else {
  2008. if (building->IsLeader) return(building);
  2009. anybuilding = building;
  2010. }
  2011. }
  2012. }
  2013. }
  2014. return(anybuilding);
  2015. }