TARGET.CPP 46 KB

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