TARCOM.CPP 9.1 KB

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