TARCOM.CPP 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/TARCOM.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 : 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::AI -- Handles the logical AI for the tarcom class. *
  36. * TarComClass::Debug_Dump -- Displays the status of the tarcom class to the mono screen. *
  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. assert(IsActive);
  94. TurretClass::AI();
  95. if (!IsActive) return;
  96. if (Class->Primary != WEAPON_NONE) {
  97. /*
  98. ** Determine which weapon can fire. First check for the primary weapon. If that weapon
  99. ** cannot fire, then check any secondary weapon. If neither weapon can fire, then the
  100. ** failure code returned is that from the primary weapon.
  101. */
  102. WeaponTypeClass const * weapon = &Weapons[Class->Primary];
  103. int primary = 0;
  104. FireErrorType ok = Can_Fire(TarCom, 0);
  105. if (ok != FIRE_OK) {
  106. if (Can_Fire(TarCom, 1) == FIRE_OK) {
  107. ok = FIRE_OK;
  108. primary = 1;
  109. weapon = &Weapons[Class->Secondary];
  110. }
  111. }
  112. switch (ok) {
  113. case FIRE_OK:
  114. // if (What_Am_I() != RTTI_UNIT) {
  115. // IsFiring = false;
  116. // } else {
  117. if (!((UnitClass *)this)->Class->IsFireAnim) {
  118. Mark(MARK_OVERLAP_UP);
  119. IsFiring = false;
  120. Mark(MARK_OVERLAP_DOWN);
  121. }
  122. // }
  123. if (TurretClass::Fire_At(TarCom, primary)) {
  124. // Sound_Effect(weapon->Sound, Coord);
  125. }
  126. break;
  127. case FIRE_FACING:
  128. if (Class->IsLockTurret) {
  129. if (!Target_Legal(NavCom) && !IsDriving) {
  130. PrimaryFacing.Set_Desired(Direction(TarCom));
  131. SecondaryFacing.Set_Desired(PrimaryFacing.Desired());
  132. }
  133. } else {
  134. #ifdef OLD
  135. if (*this == UNIT_FTANK) {
  136. SecondaryFacing.Set_Desired(Facing_Dir(Dir_Facing(Direction(TarCom))));
  137. } else {
  138. SecondaryFacing.Set_Desired(Direction(TarCom));
  139. }
  140. #else
  141. SecondaryFacing.Set_Desired(Direction(TarCom));
  142. #endif
  143. // SecondaryFacing.Set_Desired(Direction256(Center_Coord(), As_Coord(TarCom)));
  144. }
  145. break;
  146. case FIRE_CLOAKED:
  147. Mark(MARK_OVERLAP_UP);
  148. IsFiring = false;
  149. Mark(MARK_OVERLAP_DOWN);
  150. Do_Uncloak();
  151. break;
  152. }
  153. }
  154. if (Target_Legal(TarCom) && !IsRotating) {
  155. DirType dir = Direction(TarCom);
  156. if (Class->IsTurretEquipped) {
  157. SecondaryFacing.Set_Desired(dir);
  158. } else {
  159. /*
  160. ** Non turret equipped vehicles will rotate their body to face the target only
  161. ** if the vehicle isn't currently moving or facing the correct direction. This
  162. ** applies only to tracked vehicles. Wheeled vehicles never rotate to face the
  163. ** target, since they aren't maneuverable enough.
  164. */
  165. if ((Class->Speed == SPEED_TRACK /* || *this == UNIT_BIKE */ ) && !Target_Legal(NavCom) && !IsDriving && PrimaryFacing.Difference(dir)) {
  166. #ifdef OLD
  167. if (*this == UNIT_FTANK) {
  168. PrimaryFacing.Set_Desired(Facing_Dir(Dir_Facing(dir)));
  169. } else {
  170. PrimaryFacing.Set_Desired(dir);
  171. }
  172. #else
  173. PrimaryFacing.Set_Desired(dir);
  174. #endif
  175. }
  176. }
  177. }
  178. }