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