TARGET.CPP 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/TARGET.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : TARGET.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : September 10, 1993 *
  26. * *
  27. * Last Update : July 16, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * As_Aircraft -- Converts the target value into an aircraft pointer. *
  32. * As_Animation -- Converts target value into animation pointer. *
  33. * As_Building -- Converts a target value into a building object pointer. *
  34. * As_Bullet -- Converts the target into a bullet pointer. *
  35. * As_Cell -- Converts a target value into a cell number. *
  36. * As_Coord -- Converts a target value into a coordinate value. *
  37. * As_Infantry -- If the target is infantry, return a pointer to it. *
  38. * As_Movement_Coord -- Fetches coordinate if trying to move to this target. *
  39. * As_Object -- Converts a target value into an object pointer. *
  40. * As_Target -- Converts a cell into a target value. *
  41. * As_Target -- Converts a coordinate into a target value. *
  42. * As_Team -- Converts a target number into a team pointer. *
  43. * As_TeamType -- Converts a target into a team type pointer. *
  44. * As_Techno -- Converts a target value into a TechnoClass pointer. *
  45. * As_TechnoType -- Convert the target number into a techno type class pointer. *
  46. * As_Trigger -- Converts specified target into a trigger pointer. *
  47. * As_TriggerType -- Convert the specified target into a trigger type. *
  48. * As_Unit -- Converts a target value into a unit pointer. *
  49. * As_Vessel -- Converts a target number into a vessel pointer. *
  50. * TClass::TClass -- Constructor for target from object pointer. *
  51. * TargetClass::As_Object -- Converts a target into an object pointer. *
  52. * TargetClass::As_Techno -- Converts a target into a techno object pointer. *
  53. * Target_Legal -- Determines if the specified target is legal. *
  54. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  55. #include "function.h"
  56. #include "target.h"
  57. TargetClass::TargetClass(TARGET target)
  58. {
  59. Target.Target = target;
  60. }
  61. TargetClass::TargetClass(AbstractClass const * ptr) {
  62. if (ptr != NULL) {
  63. Target.Sub.Exponent = ptr->RTTI;
  64. Target.Sub.Mantissa = ptr->ID;
  65. } else {
  66. Target.Sub.Exponent = RTTI_NONE;
  67. }
  68. }
  69. TargetClass::TargetClass(AbstractTypeClass const * ptr) {
  70. if (ptr != NULL) {
  71. Target.Sub.Exponent = ptr->RTTI;
  72. Target.Sub.Mantissa = ptr->ID;
  73. } else {
  74. Target.Sub.Exponent = RTTI_NONE;
  75. }
  76. }
  77. TargetClass::TargetClass(CellClass const * ptr) {
  78. if (ptr != NULL) {
  79. Target.Sub.Exponent = RTTI_CELL;
  80. Target.Sub.Mantissa = ptr->ID;
  81. } else {
  82. Target.Sub.Exponent = RTTI_NONE;
  83. }
  84. }
  85. CellClass * xTargetClass::As_Cell(void) const
  86. {
  87. if (Target.Sub.Exponent == RTTI_CELL) {
  88. return(&Map[(CELL)Target.Sub.Mantissa]);
  89. }
  90. return(NULL);
  91. }
  92. /***********************************************************************************************
  93. * As_Trigger -- Converts specified target into a trigger pointer. *
  94. * *
  95. * This routine will convert the specified target number into a trigger pointer. *
  96. * *
  97. * INPUT: target -- The target number to convert. *
  98. * *
  99. * OUTPUT: Returns with the trigger pointer that the specified target number represents. If *
  100. * it doesn't represent a legal trigger object, then NULL is returned. *
  101. * *
  102. * WARNINGS: none *
  103. * *
  104. * HISTORY: *
  105. * 07/08/1995 JLB : Created. *
  106. *=============================================================================================*/
  107. TriggerClass * As_Trigger(TARGET target, bool check_active)
  108. {
  109. TriggerClass* trigger = Is_Target_Trigger(target) ? Triggers.Raw_Ptr(Target_Value(target)) : NULL;
  110. if (check_active && trigger != NULL && !trigger->IsActive) {
  111. trigger = NULL;
  112. }
  113. return(trigger);
  114. }
  115. /***********************************************************************************************
  116. * As_Team -- Converts a target number into a team pointer. *
  117. * *
  118. * This routine will convert the specified target number into a team pointer. *
  119. * *
  120. * INPUT: target -- The target number to convert. *
  121. * *
  122. * OUTPUT: Returns with the team object that the specified target number represents. If it *
  123. * doesn't represent a legal team then NULL is returned. *
  124. * *
  125. * WARNINGS: none *
  126. * *
  127. * HISTORY: *
  128. * 07/08/1995 JLB : Created. *
  129. *=============================================================================================*/
  130. TeamClass * As_Team(TARGET target, bool check_active)
  131. {
  132. TeamClass* team = Is_Target_Team(target) ? Teams.Raw_Ptr(Target_Value(target)) : NULL;
  133. if (check_active && team != NULL && !team->IsActive) {
  134. team = NULL;
  135. }
  136. return(team);
  137. }
  138. /***********************************************************************************************
  139. * As_TeamType -- Converts a target into a team type pointer. *
  140. * *
  141. * This routine will convert the specified target number into a team type pointer. *
  142. * *
  143. * INPUT: target -- The target number to convert. *
  144. * *
  145. * OUTPUT: Returns with a pointer to the team type represented by the target number. If the *
  146. * target number doesn't represent a legal team type, then NULL is returned. *
  147. * *
  148. * WARNINGS: none *
  149. * *
  150. * HISTORY: *
  151. * 07/08/1995 JLB : Created. *
  152. *=============================================================================================*/
  153. TeamTypeClass * As_TeamType(TARGET target)
  154. {
  155. return(Is_Target_TeamType(target) ? TeamTypes.Raw_Ptr(Target_Value(target)) : NULL);
  156. }
  157. /***********************************************************************************************
  158. * As_Animation -- Converts target value into animation pointer. *
  159. * *
  160. * This routine will convert the specified target number into an animation pointer. *
  161. * *
  162. * INPUT: target -- The target number to convert into an animation pointer. *
  163. * *
  164. * OUTPUT: Returns with a pointer to the legal animation that this target represents. If it *
  165. * doesn't represent a legal animation, then NULL is returned. *
  166. * *
  167. * WARNINGS: none *
  168. * *
  169. * HISTORY: *
  170. * 07/08/1995 JLB : Created. *
  171. *=============================================================================================*/
  172. AnimClass * As_Animation(TARGET target, bool check_active)
  173. {
  174. AnimClass* anim = Is_Target_Animation(target) ? Anims.Raw_Ptr(Target_Value(target)) : NULL;
  175. if (check_active && anim != NULL && !anim->IsActive) {
  176. anim = NULL;
  177. }
  178. return(anim);
  179. }
  180. /***********************************************************************************************
  181. * As_Bullet -- Converts the target into a bullet pointer. *
  182. * *
  183. * This routine will convert the specified target number into a bullet pointer. *
  184. * *
  185. * INPUT: target -- The target number to convert. *
  186. * *
  187. * OUTPUT: Returns with a pointer to the bullet it specifies. If the target doesn't refer to *
  188. * a legal bullet, then NULL is returned. *
  189. * *
  190. * WARNINGS: none *
  191. * *
  192. * HISTORY: *
  193. * 07/08/1995 JLB : Created. *
  194. *=============================================================================================*/
  195. BulletClass * As_Bullet(TARGET target, bool check_active)
  196. {
  197. BulletClass* bullet = Is_Target_Bullet(target) ? Bullets.Raw_Ptr(Target_Value(target)) : NULL;
  198. if (check_active && bullet != NULL && !bullet->IsActive) {
  199. bullet = NULL;
  200. }
  201. return(bullet);
  202. }
  203. /***********************************************************************************************
  204. * As_Aircraft -- Converts the target value into an aircraft pointer. *
  205. * *
  206. * This routine will convert the specified target value into an aircraft object pointer. *
  207. * *
  208. * INPUT: target -- The target value to convert. *
  209. * *
  210. * OUTPUT: Returns with a pointer to the aircraft that this target value represents. If the *
  211. * specified target value doesn't represent an aircraft, then NULL is returned. *
  212. * *
  213. * WARNINGS: none *
  214. * *
  215. * HISTORY: *
  216. * 08/27/1995 JLB : Created. *
  217. *=============================================================================================*/
  218. AircraftClass * As_Aircraft(TARGET target, bool check_active)
  219. {
  220. AircraftClass* aircraft = Is_Target_Aircraft(target) ? Aircraft.Raw_Ptr(Target_Value(target)) : NULL;
  221. if (check_active && aircraft != NULL && !aircraft->IsActive) {
  222. aircraft = NULL;
  223. }
  224. return(aircraft);
  225. }
  226. /***********************************************************************************************
  227. * As_Techno -- Converts a target value into a TechnoClass pointer. *
  228. * *
  229. * This routine will take the target value specified and convert it into a TechnoClass *
  230. * pointer if the target represents an object that has a TechnoClass. *
  231. * *
  232. * INPUT: target -- The target value to convert into a TechnoClass pointer. *
  233. * *
  234. * OUTPUT: Returns with a pointer to the associated object's TechnoClass. If the target *
  235. * cannot be converted into a TechnoClass pointer, then NULL is returned. *
  236. * *
  237. * WARNINGS: none *
  238. * *
  239. * HISTORY: *
  240. * 06/02/1994 JLB : Created. *
  241. *=============================================================================================*/
  242. TechnoClass * As_Techno(TARGET target, bool check_active)
  243. {
  244. ObjectClass * obj = As_Object(target, check_active);
  245. if (obj && obj->Is_Techno()) {
  246. return(TechnoClass *)obj;
  247. }
  248. return(NULL);
  249. }
  250. /***********************************************************************************************
  251. * As_Object -- Converts a target value into an object pointer. *
  252. * *
  253. * This routine is used to convert the target value specified into an object pointer. If *
  254. * the target doesn't represent an object or the target value is illegal, then NULL is *
  255. * returned. *
  256. * *
  257. * INPUT: target -- The target value to convert from. *
  258. * *
  259. * OUTPUT: Returns with a pointer to the object it represent, or NULL if not an object. *
  260. * *
  261. * WARNINGS: none *
  262. * *
  263. * HISTORY: *
  264. * 05/27/1994 JLB : Created. *
  265. *=============================================================================================*/
  266. ObjectClass * As_Object(TARGET target, bool check_active)
  267. {
  268. int val = Target_Value(target);
  269. ObjectClass * object = NULL;
  270. switch (Target_Kind(target)) {
  271. case RTTI_INFANTRY:
  272. object = Infantry.Raw_Ptr(val);
  273. break;
  274. case RTTI_UNIT:
  275. object = Units.Raw_Ptr(val);
  276. break;
  277. case RTTI_VESSEL:
  278. object = Vessels.Raw_Ptr(val);
  279. break;
  280. case RTTI_BUILDING:
  281. object = Buildings.Raw_Ptr(val);
  282. break;
  283. case RTTI_AIRCRAFT:
  284. object = Aircraft.Raw_Ptr(val);
  285. break;
  286. case RTTI_TERRAIN:
  287. object = Terrains.Raw_Ptr(val);
  288. break;
  289. case RTTI_BULLET:
  290. object = Bullets.Raw_Ptr(val);
  291. break;
  292. case RTTI_ANIM:
  293. object = Anims.Raw_Ptr(val);
  294. break;
  295. default:
  296. break;
  297. }
  298. /*
  299. ** Special check to ensure that a target value that references an
  300. ** invalid object will not be converted back into an object pointer.
  301. ** This condition is rare, but could occur in a network game if the
  302. ** object it refers to is destroyed between the time an event message
  303. ** is sent and when it is received.
  304. */
  305. if (check_active && object != NULL && !object->IsActive) {
  306. object = NULL;
  307. }
  308. return(object);
  309. }
  310. /***********************************************************************************************
  311. * As_Unit -- Converts a target value into a unit pointer. *
  312. * *
  313. * This routine is used to convert the target value specified into a pointer to a unit *
  314. * object. *
  315. * *
  316. * INPUT: target -- The target value to convert into a unit pointer. *
  317. * *
  318. * OUTPUT: Returns with a pointer to the unit the target value represents or NULL if not *
  319. * a unit. *
  320. * *
  321. * WARNINGS: none *
  322. * *
  323. * HISTORY: *
  324. * 05/27/1994 JLB : Created. *
  325. *=============================================================================================*/
  326. UnitClass * As_Unit(TARGET target, bool check_active)
  327. {
  328. UnitClass* unit = Is_Target_Unit(target) ? Units.Raw_Ptr(Target_Value(target)) : NULL;
  329. if (check_active && unit != NULL && !unit->IsActive) {
  330. unit = NULL;
  331. }
  332. return(unit);
  333. }
  334. /***********************************************************************************************
  335. * As_Vessel -- Converts a target number into a vessel pointer. *
  336. * *
  337. * Use this routine to conver the specified target number into a pointer to a vessel object *
  338. * that it represents. *
  339. * *
  340. * INPUT: target -- The target number to convert to a vessel pointer. *
  341. * *
  342. * OUTPUT: Returns with a pointer to the vessel object that this target value represents. If *
  343. * the target number does not represent a vessel, then null is returned. *
  344. * *
  345. * WARNINGS: none *
  346. * *
  347. * HISTORY: *
  348. * 07/16/1996 JLB : Created. *
  349. *=============================================================================================*/
  350. VesselClass * As_Vessel(TARGET target, bool check_active)
  351. {
  352. VesselClass* vessel = Is_Target_Vessel(target) ? Vessels.Raw_Ptr(Target_Value(target)) : NULL;
  353. if (check_active && vessel != NULL && !vessel->IsActive) {
  354. vessel = NULL;
  355. }
  356. return(vessel);
  357. }
  358. /***********************************************************************************************
  359. * As_Infantry -- If the target is infantry, return a pointer to it. *
  360. * *
  361. * This routine will translate the specified target value into an infantry pointer if the *
  362. * target actually represents an infantry object. *
  363. * *
  364. * INPUT: target -- The target to convert to a pointer. *
  365. * *
  366. * OUTPUT: Returns a pointer to the infantry object that this target value represents. If *
  367. * the target doesn't represent an infantry object, then return NULL. *
  368. * *
  369. * WARNINGS: none *
  370. * *
  371. * HISTORY: *
  372. * 10/17/1994 JLB : Created. *
  373. *=============================================================================================*/
  374. InfantryClass * As_Infantry(TARGET target, bool check_active)
  375. {
  376. InfantryClass* infantry = Is_Target_Infantry(target) ? Infantry.Raw_Ptr(Target_Value(target)) : NULL;
  377. if (check_active && infantry != NULL && !infantry->IsActive) {
  378. infantry = NULL;
  379. }
  380. return(infantry);
  381. }
  382. /***********************************************************************************************
  383. * As_Building -- Converts a target value into a building object pointer. *
  384. * *
  385. * This routine is used to convert the target value specified into a building pointer. *
  386. * *
  387. * INPUT: target -- The target value to convert from. *
  388. * *
  389. * OUTPUT: Returns with a pointer to the building object that the target value represents. *
  390. * If it doesn't represent a building, then return NULL. *
  391. * *
  392. * WARNINGS: none *
  393. * *
  394. * HISTORY: *
  395. * 05/27/1994 JLB : Created. *
  396. *=============================================================================================*/
  397. BuildingClass * As_Building(TARGET target, bool check_active)
  398. {
  399. BuildingClass* building = Is_Target_Building(target) ? Buildings.Raw_Ptr(Target_Value(target)) : NULL;
  400. if (check_active && building != NULL && !building->IsActive) {
  401. building = NULL;
  402. }
  403. return(building);
  404. }
  405. /***********************************************************************************************
  406. * Target_Legal -- Determines if the specified target is legal. *
  407. * *
  408. * This routine is used to check for the legality of the target value specified. It is *
  409. * necessary to call this routine if there is doubt about the the legality of the target. *
  410. * It is possible for the unit that a target value represents to be eliminated and thus *
  411. * rendering the target value invalid. *
  412. * *
  413. * INPUT: target -- The target value to check. *
  414. * *
  415. * OUTPUT: bool; Is the target value legal? *
  416. * *
  417. * WARNINGS: none *
  418. * *
  419. * HISTORY: *
  420. * 05/27/1994 JLB : Created. *
  421. *=============================================================================================*/
  422. bool Target_Legal(TARGET target)
  423. {
  424. if (target == TARGET_NONE) return(false);
  425. ObjectClass * obj = As_Object(target, false);
  426. if (obj) {
  427. return(obj->IsActive);
  428. }
  429. return(true);
  430. }
  431. /***********************************************************************************************
  432. * As_Cell -- Converts a target value into a cell number. *
  433. * *
  434. * This routine is used to convert the target value specified, into a cell value. This is *
  435. * necessary for find path and other procedures that need a cell value. *
  436. * *
  437. * INPUT: target -- The target value to convert to a cell value. *
  438. * *
  439. * OUTPUT: Returns with the target value expressed as a cell location. *
  440. * *
  441. * WARNINGS: none *
  442. * *
  443. * HISTORY: *
  444. * 05/27/1994 JLB : Created. *
  445. *=============================================================================================*/
  446. CELL As_Cell(TARGET target)
  447. {
  448. return(Coord_Cell(As_Coord(target)));
  449. }
  450. /***********************************************************************************************
  451. * As_Coord -- Converts a target value into a coordinate value. *
  452. * *
  453. * This routine is used to convert the target value specified into a coordinate value. It *
  454. * is necessary for those procedures that require a coordinate value. *
  455. * *
  456. * INPUT: target -- The target value to convert. *
  457. * *
  458. * OUTPUT: Returns with the target expressed as a COORDINATE value. *
  459. * *
  460. * WARNINGS: none *
  461. * *
  462. * HISTORY: *
  463. * 05/27/1994 JLB : Created. *
  464. * 11/16/1994 JLB : Simplified. *
  465. *=============================================================================================*/
  466. COORDINATE As_Coord(TARGET target)
  467. {
  468. if (Target_Legal(target)) {
  469. /*
  470. ** Cell target values are handled as a special case. The value of the target number is
  471. ** actually the cell index number.
  472. */
  473. if (Is_Target_Cell(target)) {
  474. int v = Target_Value(target);
  475. int x = ((v & 0x0FFF) << 4) + 0x0008;
  476. int y = (((v>>12) & 0x0FFF) << 4) + 0x0008;
  477. return(XY_Coord(x, y));
  478. // return(Cell_Coord((CELL)Target_Value(target)));
  479. }
  480. /*
  481. ** Normal targets correspond to game objects. Fetch the object pointer and then ask it
  482. ** for the center coordinate. Return the center coordinate as the target's coordinate.
  483. */
  484. ObjectClass * obj = As_Object(target);
  485. if (obj != NULL) {
  486. assert(obj->IsActive);
  487. return(obj->Target_Coord());
  488. }
  489. }
  490. /*
  491. ** An unrecognized target value results in a null coordinate value.
  492. */
  493. return(0x00000000L);
  494. }
  495. /***********************************************************************************************
  496. * As_Movement_Coord -- Fetches coordinate if trying to move to this target. *
  497. * *
  498. * This routine will convert the specified target into a coordinate location. This location *
  499. * is used when moving to the target specified. For cells, this is the center of the cell. *
  500. * For special buildings that allow docking, it is the center location of the docking *
  501. * bay. *
  502. * *
  503. * INPUT: target -- The target to convert into a coordinate value. *
  504. * *
  505. * OUTPUT: Returns with the docking coordinate of the target value specified. *
  506. * *
  507. * WARNINGS: none *
  508. * *
  509. * HISTORY: *
  510. * 08/27/1995 JLB : Created. *
  511. *=============================================================================================*/
  512. COORDINATE As_Movement_Coord(TARGET target)
  513. {
  514. if (Target_Legal(target)) {
  515. /*
  516. ** Cell target values are handled as a special case. The value of the target number is
  517. ** actually the cell index number.
  518. */
  519. if (Is_Target_Cell(target)) {
  520. return(Cell_Coord((CELL)Target_Value(target)));
  521. }
  522. /*
  523. ** Normal targets correspond to game objects. Fetch the object pointer and then ask it
  524. ** for the center coordinate. Return the center coordinate as the target's coordinate.
  525. */
  526. ObjectClass * obj = As_Object(target);
  527. if (obj) {
  528. return(obj->Docking_Coord());
  529. }
  530. }
  531. /*
  532. ** An unrecognized target value results in a null coordinate value.
  533. */
  534. return(0x00000000L);
  535. }
  536. /***********************************************************************************************
  537. * TargetClass::As_Object -- Converts a target into an object pointer. *
  538. * *
  539. * If the target represents an object of some type, then this routine will return a *
  540. * pointer to the object. Otherwise it will return NULL. *
  541. * *
  542. * INPUT: none *
  543. * *
  544. * OUTPUT: Returns with a pointer to the object that this target represents or NULL if it *
  545. * doesn't represent a target. *
  546. * *
  547. * WARNINGS: none *
  548. * *
  549. * HISTORY: *
  550. * 03/05/1996 JLB : Created. *
  551. *=============================================================================================*/
  552. AbstractClass * xTargetClass::As_Abstract(bool check_active) const
  553. {
  554. AbstractClass* abst = NULL;
  555. switch ((RTTIType)*this) {
  556. case RTTI_TEAM:
  557. abst = Teams.Raw_Ptr(Value());
  558. break;
  559. case RTTI_BULLET:
  560. abst = Bullets.Raw_Ptr(Value());
  561. break;
  562. case RTTI_OVERLAY:
  563. abst = Overlays.Raw_Ptr(Value());
  564. break;
  565. case RTTI_SMUDGE:
  566. abst = Smudges.Raw_Ptr(Value());
  567. break;
  568. case RTTI_UNIT:
  569. abst = Units.Raw_Ptr(Value());
  570. break;
  571. case RTTI_VESSEL:
  572. abst = Vessels.Raw_Ptr(Value());
  573. break;
  574. case RTTI_BUILDING:
  575. abst = Buildings.Raw_Ptr(Value());
  576. break;
  577. case RTTI_INFANTRY:
  578. abst = Infantry.Raw_Ptr(Value());
  579. break;
  580. case RTTI_AIRCRAFT:
  581. abst = Aircraft.Raw_Ptr(Value());
  582. break;
  583. case RTTI_TERRAIN:
  584. abst = Terrains.Raw_Ptr(Value());
  585. break;
  586. case RTTI_ANIM:
  587. abst = Anims.Raw_Ptr(Value());
  588. break;
  589. default:
  590. break;
  591. }
  592. if (check_active && abst != NULL && !abst->IsActive) {
  593. abst = NULL;
  594. }
  595. return(abst);
  596. }
  597. AbstractTypeClass * xTargetClass::As_TypeClass(void) const
  598. {
  599. switch ((RTTIType)*this) {
  600. case RTTI_TEAMTYPE:
  601. return(TeamTypes.Raw_Ptr(Value()));
  602. case RTTI_TRIGGERTYPE:
  603. return(TriggerTypes.Raw_Ptr(Value()));
  604. case RTTI_BULLETTYPE:
  605. return((BulletTypeClass *)&BulletTypeClass::As_Reference(BulletType(Value())));
  606. case RTTI_OVERLAY:
  607. return((OverlayTypeClass *)&OverlayTypeClass::As_Reference(OverlayType(Value())));
  608. case RTTI_SMUDGE:
  609. return((SmudgeTypeClass *)&SmudgeTypeClass::As_Reference(SmudgeType(Value())));
  610. case RTTI_UNIT:
  611. return((UnitTypeClass *)&UnitTypeClass::As_Reference(UnitType(Value())));
  612. case RTTI_VESSEL:
  613. return((VesselTypeClass *)&VesselTypeClass::As_Reference(VesselType(Value())));
  614. case RTTI_BUILDING:
  615. return((BuildingTypeClass *)&BuildingTypeClass::As_Reference(StructType(Value())));
  616. case RTTI_INFANTRY:
  617. return((InfantryTypeClass *)&InfantryTypeClass::As_Reference(InfantryType(Value())));
  618. case RTTI_AIRCRAFT:
  619. return((AircraftTypeClass *)&AircraftTypeClass::As_Reference(AircraftType(Value())));
  620. case RTTI_TERRAIN:
  621. return((TerrainTypeClass *)&TerrainTypeClass::As_Reference(TerrainType(Value())));
  622. case RTTI_ANIM:
  623. return((AnimTypeClass *)&AnimTypeClass::As_Reference(AnimType(Value())));
  624. default:
  625. break;
  626. }
  627. return(0);
  628. }
  629. /***********************************************************************************************
  630. * TargetClass::As_Techno -- Converts a target into a techno object pointer. *
  631. * *
  632. * This routine is used to convert the target object into a pointer to a techno class *
  633. * object. If the target doesn't specify a techno class object, then NULL is returned. *
  634. * *
  635. * INPUT: none *
  636. * *
  637. * OUTPUT: Returns with a pointer to the techno class object that this target represents or *
  638. * else it returns NULL. *
  639. * *
  640. * WARNINGS: none *
  641. * *
  642. * HISTORY: *
  643. * 03/05/1996 JLB : Created. *
  644. *=============================================================================================*/
  645. TechnoClass * xTargetClass::As_Techno(bool check_active) const
  646. {
  647. TechnoClass* techno = NULL;
  648. switch ((RTTIType)*this) {
  649. case RTTI_UNIT:
  650. techno = Units.Raw_Ptr(Value());
  651. break;
  652. case RTTI_VESSEL:
  653. techno = Vessels.Raw_Ptr(Value());
  654. break;
  655. case RTTI_BUILDING:
  656. techno = Buildings.Raw_Ptr(Value());
  657. break;
  658. case RTTI_INFANTRY:
  659. techno = Infantry.Raw_Ptr(Value());
  660. break;
  661. case RTTI_AIRCRAFT:
  662. techno = Aircraft.Raw_Ptr(Value());
  663. break;
  664. default:
  665. break;
  666. }
  667. if (check_active && techno != NULL && !techno->IsActive) {
  668. techno = NULL;
  669. }
  670. return(techno);
  671. }
  672. ObjectClass * xTargetClass::As_Object(bool check_active) const
  673. {
  674. ObjectClass* object = NULL;
  675. switch ((RTTIType)*this) {
  676. case RTTI_TERRAIN:
  677. object = Terrains.Raw_Ptr(Value());
  678. break;
  679. case RTTI_SMUDGE:
  680. object = Smudges.Raw_Ptr(Value());
  681. break;
  682. case RTTI_OVERLAY:
  683. object = Overlays.Raw_Ptr(Value());
  684. break;
  685. case RTTI_BULLET:
  686. object = Bullets.Raw_Ptr(Value());
  687. break;
  688. case RTTI_ANIM:
  689. object = Anims.Raw_Ptr(Value());
  690. break;
  691. case RTTI_UNIT:
  692. object = Units.Raw_Ptr(Value());
  693. break;
  694. case RTTI_VESSEL:
  695. object = Vessels.Raw_Ptr(Value());
  696. break;
  697. case RTTI_BUILDING:
  698. object = Buildings.Raw_Ptr(Value());
  699. break;
  700. case RTTI_INFANTRY:
  701. object = Infantry.Raw_Ptr(Value());
  702. break;
  703. case RTTI_AIRCRAFT:
  704. object = Aircraft.Raw_Ptr(Value());
  705. break;
  706. default:
  707. break;
  708. }
  709. if (check_active && object != NULL && !object->IsActive) {
  710. object = NULL;
  711. }
  712. return(object);
  713. }
  714. /***********************************************************************************************
  715. * As_Target -- Converts a cell into a target value. *
  716. * *
  717. * This routine will convert a cell into a target value. *
  718. * *
  719. * INPUT: cell -- The cell number that will be coerced into a target value. *
  720. * *
  721. * OUTPUT: Returns with the target value that this cell represents. *
  722. * *
  723. * WARNINGS: none *
  724. * *
  725. * HISTORY: *
  726. * 03/05/1996 JLB : Created. *
  727. *=============================================================================================*/
  728. TARGET As_Target(CELL cell)
  729. {
  730. int x = Cell_X(cell);
  731. int y = Cell_Y(cell);
  732. x <<= 4;
  733. y <<= 4;
  734. x += 0x0008;
  735. y += 0x0008;
  736. return(Build_Target(RTTI_CELL, ((y << 12) | x) ));
  737. }
  738. /***********************************************************************************************
  739. * As_Target -- Converts a coordinate into a target value. *
  740. * *
  741. * This routine is used to convert the specified coordinate into a target value. *
  742. * *
  743. * INPUT: coord -- The coordinate that is to be converted into a target value. *
  744. * *
  745. * OUTPUT: Returns with the target value that represents the coordinate. *
  746. * *
  747. * WARNINGS: none *
  748. * *
  749. * HISTORY: *
  750. * 03/05/1996 JLB : Created. *
  751. *=============================================================================================*/
  752. TARGET As_Target(COORDINATE coord)
  753. {
  754. int x = Coord_X(coord);
  755. int y = Coord_Y(coord);
  756. x >>= 4;
  757. y >>= 4;
  758. return(Build_Target(RTTI_CELL, ((y << 12) | x) ));
  759. }
  760. /***********************************************************************************************
  761. * As_TechnoType -- Convert the target number into a techno type class pointer. *
  762. * *
  763. * This routine will conver the specified target number into a pointer to the techno *
  764. * type class that it represents. *
  765. * *
  766. * INPUT: target -- The target number to convert. *
  767. * *
  768. * OUTPUT: Returns with a pointer to the TechnoTypeClass object that the target number *
  769. * represents. If it doesn't represent that kind of object, then NULL is returned. *
  770. * *
  771. * WARNINGS: none *
  772. * *
  773. * HISTORY: *
  774. * 07/16/1996 JLB : Created. *
  775. *=============================================================================================*/
  776. TechnoTypeClass const * As_TechnoType(TARGET target)
  777. {
  778. int val = Target_Value(target);
  779. switch (Target_Kind(target)) {
  780. case RTTI_INFANTRYTYPE:
  781. return(&InfantryTypeClass::As_Reference(InfantryType(val)));
  782. case RTTI_UNITTYPE:
  783. return(&UnitTypeClass::As_Reference(UnitType(val)));
  784. case RTTI_VESSELTYPE:
  785. return(&VesselTypeClass::As_Reference(VesselType(val)));
  786. case RTTI_AIRCRAFTTYPE:
  787. return(&AircraftTypeClass::As_Reference(AircraftType(val)));
  788. case RTTI_BUILDINGTYPE:
  789. return(&BuildingTypeClass::As_Reference(StructType(val)));
  790. }
  791. return(NULL);
  792. }
  793. /***********************************************************************************************
  794. * As_TriggerType -- Convert the specified target into a trigger type. *
  795. * *
  796. * This routine will conver the target number into a pointer to the trigger type it *
  797. * represents. *
  798. * *
  799. * INPUT: target -- The target value to convert into a trigger type pointer. *
  800. * *
  801. * OUTPUT: Returns with a pointer to the trigger type object that the specified target value *
  802. * represents. If it doesn't represent a trigger type, then NULL is returned. *
  803. * *
  804. * WARNINGS: none *
  805. * *
  806. * HISTORY: *
  807. * 07/16/1996 JLB : Created. *
  808. *=============================================================================================*/
  809. TriggerTypeClass * As_TriggerType(TARGET target)
  810. {
  811. if (Target_Kind(target) == RTTI_TRIGGERTYPE) {
  812. return(TriggerTypes.Raw_Ptr(Target_Value(target)));
  813. }
  814. return(NULL);
  815. }