TARGET.H 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.H 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.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 25, 1994 *
  30. * *
  31. * Last Update : April 25, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef TARGET_H
  37. #define TARGET_H
  38. inline RTTIType Target_Kind(TARGET a)
  39. {
  40. return(RTTIType(((TARGET_COMPOSITE &)a).Sub.Exponent));
  41. }
  42. inline unsigned Target_Value(TARGET a)
  43. {
  44. return(((TARGET_COMPOSITE &)a).Sub.Mantissa);
  45. }
  46. inline bool Is_Target_Team(TARGET a) {return (Target_Kind(a) == RTTI_TEAM);}
  47. inline bool Is_Target_TeamType(TARGET a) {return (Target_Kind(a) == RTTI_TEAMTYPE);}
  48. inline bool Is_Target_Trigger(TARGET a) {return (Target_Kind(a) == RTTI_TRIGGER);}
  49. inline bool Is_Target_TriggerType(TARGET a) {return (Target_Kind(a) == RTTI_TRIGGERTYPE);}
  50. inline bool Is_Target_Infantry(TARGET a) {return (Target_Kind(a) == RTTI_INFANTRY);}
  51. inline bool Is_Target_Bullet(TARGET a) {return (Target_Kind(a) == RTTI_BULLET);}
  52. inline bool Is_Target_Terrain(TARGET a) {return (Target_Kind(a) == RTTI_TERRAIN);}
  53. inline bool Is_Target_Cell(TARGET a) {return (Target_Kind(a) == RTTI_CELL);}
  54. inline bool Is_Target_Unit(TARGET a) {return (Target_Kind(a) == RTTI_UNIT);}
  55. inline bool Is_Target_Vessel(TARGET a) {return (Target_Kind(a) == RTTI_VESSEL);}
  56. inline bool Is_Target_Building(TARGET a) {return (Target_Kind(a) == RTTI_BUILDING);}
  57. inline bool Is_Target_Template(TARGET a) {return (Target_Kind(a) == RTTI_TEMPLATE);}
  58. inline bool Is_Target_Aircraft(TARGET a) {return (Target_Kind(a) == RTTI_AIRCRAFT);}
  59. inline bool Is_Target_Animation(TARGET a) {return (Target_Kind(a) == RTTI_ANIM);}
  60. inline bool Is_Target_Object(TARGET a)
  61. {
  62. return (Target_Kind(a) == RTTI_TERRAIN ||
  63. Target_Kind(a) == RTTI_UNIT ||
  64. Target_Kind(a) == RTTI_VESSEL ||
  65. Target_Kind(a) == RTTI_INFANTRY ||
  66. Target_Kind(a) == RTTI_BUILDING ||
  67. Target_Kind(a) == RTTI_AIRCRAFT);
  68. }
  69. TARGET As_Target(CELL cell);
  70. TARGET As_Target(COORDINATE coord);
  71. //inline TARGET As_Target(CELL cell) {return (TARGET)(((unsigned)RTTI_CELL << TARGET_MANTISSA) | cell);}
  72. class UnitClass;
  73. class BuildingClass;
  74. class TechnoClass;
  75. class TerrainClass;
  76. class ObjectClass;
  77. class InfantryClass;
  78. class BulletClass;
  79. class TriggerClass;
  80. class TeamClass;
  81. class TeamTypeClass;
  82. class AnimClass;
  83. class AircraftClass;
  84. class VesselClass;
  85. class CellClass;
  86. class TriggerTypeClass;
  87. /*
  88. ** Must not have a constructor since Watcom cannot handle a class that has a constructor if
  89. ** that class object is in a union. Don't use this class for normal purposes. Use the TargetClass
  90. ** instead. The xTargetClass is only used in one module for a special reason -- keep it that way.
  91. */
  92. class xTargetClass
  93. {
  94. protected:
  95. TARGET_COMPOSITE Target;
  96. public:
  97. // conversion operator to RTTIType
  98. operator RTTIType (void) const {return(RTTIType(Target.Sub.Exponent));}
  99. // comparison operator
  100. int operator == (xTargetClass & tgt) {return (tgt.Target.Target==Target.Target ? 1 : 0);}
  101. // conversion operator to regular TARGET type
  102. TARGET As_TARGET(void) const {return(Target.Target);}
  103. unsigned Value(void) const {return(Target.Sub.Mantissa);};
  104. void Invalidate(void) {Target.Sub.Exponent = RTTI_NONE;Target.Sub.Mantissa = -1;}
  105. bool Is_Valid(void) const {return (Target.Sub.Exponent != RTTI_NONE);}
  106. TARGET As_Target(void) const {return(Target.Target);}
  107. AbstractTypeClass * As_TypeClass(void) const;
  108. AbstractClass * As_Abstract(void) const;
  109. TechnoClass * As_Techno(void) const;
  110. ObjectClass * As_Object(void) const;
  111. CellClass * As_Cell(void) const;
  112. /*
  113. ** Helper routines to combine testing for, and fetching a pointer to, the
  114. ** type of object indicated.
  115. */
  116. TriggerTypeClass * As_TriggerType(void) const {if (*this == RTTI_TRIGGERTYPE) return((TriggerTypeClass *)As_TypeClass());return(0);}
  117. TeamTypeClass * As_TeamType(void) const {if (*this == RTTI_TEAMTYPE) return((TeamTypeClass *)As_TypeClass());return(0);}
  118. TerrainClass * As_Terrain(void) const {if (*this == RTTI_TERRAIN) return((TerrainClass *)As_Abstract());return(0);}
  119. BulletClass * As_Bullet(void) const {if (*this == RTTI_BULLET) return((BulletClass *)As_Abstract());return(0);}
  120. AnimClass * As_Anim(void) const {if (*this == RTTI_ANIM) return((AnimClass *)As_Abstract());return(0);}
  121. TeamClass * As_Team(void) const {if (*this == RTTI_TEAM) return((TeamClass *)As_Abstract());return(0);}
  122. InfantryClass * As_Infantry(void) const {if (*this == RTTI_INFANTRY) return((InfantryClass *)As_Techno());return(0);}
  123. UnitClass * As_Unit(void) const {if (*this == RTTI_UNIT) return((UnitClass *)As_Techno());return(0);}
  124. BuildingClass * As_Building(void) const {if (*this == RTTI_BUILDING) return((BuildingClass *)As_Techno());return(0);}
  125. AircraftClass * As_Aircraft(void) const {if (*this == RTTI_AIRCRAFT) return((AircraftClass *)As_Techno());return(0);}
  126. VesselClass * As_Vessel(void) const {if (*this == RTTI_VESSEL) return((VesselClass *)As_Techno());return(0);}
  127. };
  128. /*
  129. ** This class only serves as a wrapper to the xTargetClass. This class must not define any members except
  130. ** for the constructors. This is because the xTargetClass is used in a union and this target object is
  131. ** used as its initializer. If this class had any extra members they would not be properly copied and
  132. ** communicated to the other machines in a network/modem game. Combining this class with xTargetClass would
  133. ** be more efficient, but Watcom doesn't allow class objects that have a constructor to be part of a union [even
  134. ** if the class object has a default constructor!].
  135. */
  136. class TargetClass : public xTargetClass
  137. {
  138. public:
  139. TargetClass(void) {Invalidate();}
  140. TargetClass(NoInitClass const &) {}
  141. TargetClass(RTTIType rtti, int id) {
  142. Target.Sub.Exponent = rtti;
  143. Target.Sub.Mantissa = id;
  144. }
  145. TargetClass(CELL cell) {
  146. Target.Sub.Exponent = RTTI_CELL;
  147. Target.Sub.Mantissa = cell;
  148. }
  149. TargetClass(TARGET target);
  150. TargetClass(AbstractClass const * ptr);
  151. TargetClass(AbstractTypeClass const * ptr);
  152. TargetClass(CellClass const * ptr);
  153. };
  154. #endif