TARGET.H 8.5 KB

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