TARCOM.CPP (9442B)
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: F:\projects\c&c\vcs\code\tarcom.cpv 2.17 16 Oct 1995 16:52:20 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 : TARCOM.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : April 16, 1994 * 28 * * 29 * Last Update : July 19, 1995 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * TarComClass::Debug_Dump -- Displays the status of the tarcom class to the mono screen. * 34 * TarComClass::AI -- Handles the logical AI for the tarcom class. * 35 * TarComClass::~TarComClass -- Destructor for turret object. * 36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 37 38 #include "function.h" 39 40 41 /*********************************************************************************************** 42 * TarComClass::~TarComClass -- Destructor for turret object. * 43 * * 44 * This is the destructor for turret objects. * 45 * * 46 * INPUT: none * 47 * * 48 * OUTPUT: none * 49 * * 50 * WARNINGS: none * 51 * * 52 * HISTORY: * 53 * 07/19/1995 JLB : Created. * 54 *=============================================================================================*/ 55 TarComClass::~TarComClass(void) 56 { 57 } 58 59 60 #ifdef CHEAT_KEYS 61 /*********************************************************************************************** 62 * TarComClass::Debug_Dump -- Displays the status of the tarcom class to the mono screen. * 63 * * 64 * This routine is used to display the tarcom class status to the monochrome monitor. * 65 * * 66 * INPUT: none * 67 * * 68 * OUTPUT: none * 69 * * 70 * WARNINGS: none * 71 * * 72 * HISTORY: * 73 * 06/02/1994 JLB : Created. * 74 *=============================================================================================*/ 75 void TarComClass::Debug_Dump(MonoClass *mono) const 76 { 77 TurretClass::Debug_Dump(mono); 78 } 79 #endif 80 81 82 /*********************************************************************************************** 83 * TarComClass::AI -- Handles the logical AI for the tarcom class. * 84 * * 85 * This handles the AI logic for the targeting computer. * 86 * * 87 * INPUT: none * 88 * * 89 * OUTPUT: none * 90 * * 91 * WARNINGS: none * 92 * * 93 * HISTORY: * 94 * 06/02/1994 JLB : Created. * 95 *=============================================================================================*/ 96 void TarComClass::AI(void) 97 { 98 TurretClass::AI(); 99 100 if (Class->Primary != WEAPON_NONE) { 101 102 /* 103 ** Determine which weapon can fire. First check for the primary weapon. If that weapon 104 ** cannot fire, then check any secondary weapon. If neither weapon can fire, then the 105 ** failure code returned is that from the primary weapon. 106 */ 107 WeaponTypeClass const * weapon = &Weapons[Class->Primary]; 108 int primary = 0; 109 FireErrorType ok = Can_Fire(TarCom, 0); 110 if (ok != FIRE_OK) { 111 if (Can_Fire(TarCom, 1) == FIRE_OK) { 112 ok = FIRE_OK; 113 primary = 1; 114 weapon = &Weapons[Class->Secondary]; 115 } 116 } 117 118 switch (ok) { 119 case FIRE_OK: 120 if (What_Am_I() != RTTI_UNIT) { 121 IsFiring = false; 122 } else { 123 if (!((UnitClass *)this)->Class->IsFireAnim) { 124 IsFiring = false; 125 } 126 } 127 128 if (TurretClass::Fire_At(TarCom, primary)) { 129 Sound_Effect(weapon->Sound, Coord); 130 } 131 break; 132 133 case FIRE_FACING: 134 if (Class->IsLockTurret) { 135 if (!Target_Legal(NavCom) && !IsDriving) { 136 PrimaryFacing.Set_Desired(Direction(TarCom)); 137 SecondaryFacing.Set_Desired(PrimaryFacing.Desired()); 138 } 139 } else { 140 if (*this == UNIT_FTANK) { 141 SecondaryFacing.Set_Desired(Facing_Dir(Dir_Facing(Direction(TarCom)))); 142 } else { 143 SecondaryFacing.Set_Desired(Direction(TarCom)); 144 } 145 // SecondaryFacing.Set_Desired(Direction256(Center_Coord(), As_Coord(TarCom))); 146 } 147 break; 148 149 case FIRE_CLOAKED: 150 IsFiring = false; 151 Do_Uncloak(); 152 break; 153 } 154 } 155 156 if (Target_Legal(TarCom) && !IsRotating) { 157 DirType dir = Direction(TarCom); 158 159 if (Class->IsTurretEquipped) { 160 SecondaryFacing.Set_Desired(dir); 161 } else { 162 163 /* 164 ** Non turret equipped vehicles will rotate their body to face the target only 165 ** if the vehicle isn't currently moving or facing the correct direction. This 166 ** applies only to tracked vehicles. Wheeled vehicles never rotate to face the 167 ** target, since they aren't maneuverable enough. 168 */ 169 if ((Class->Speed == SPEED_TRACK || *this == UNIT_BIKE) && !Target_Legal(NavCom) && !IsDriving && PrimaryFacing.Difference(dir)) { 170 if (*this == UNIT_FTANK) { 171 PrimaryFacing.Set_Desired(Facing_Dir(Dir_Facing(dir))); 172 } else { 173 PrimaryFacing.Set_Desired(dir); 174 } 175 } 176 } 177 } 178 } 179 180