TARGET.H 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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\target.h_v 2.16 16 Oct 1995 16:45:04 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. /**************************************************************************
  39. ** When a unit proceeds with carrying out its mission, it can have several
  40. ** intermediate goals. Each goal (or target if you will) can be one of the
  41. ** following kinds.
  42. */
  43. typedef enum KindType {
  44. KIND_NONE,
  45. KIND_CELL,
  46. KIND_UNIT,
  47. KIND_INFANTRY,
  48. KIND_BUILDING,
  49. KIND_TERRAIN,
  50. KIND_AIRCRAFT,
  51. KIND_TEMPLATE,
  52. KIND_BULLET,
  53. KIND_ANIMATION,
  54. KIND_TRIGGER,
  55. KIND_TEAM,
  56. KIND_TEAMTYPE
  57. } KindType;
  58. #define TARGET_MANTISSA 12 // Bits of value precision.
  59. #define TARGET_MANTISSA_MASK (~((~0)<<TARGET_MANTISSA))
  60. #define TARGET_EXPONENT ((sizeof(TARGET)*8)-TARGET_MANTISSA)
  61. #define TARGET_EXPONENT_MASK (~(((unsigned)(~0))>>TARGET_EXPONENT))
  62. inline KindType Target_Kind(TARGET a){return (KindType)(((unsigned)a)>>TARGET_MANTISSA);}
  63. inline unsigned Target_Value(TARGET a){return (((unsigned)a) & TARGET_MANTISSA_MASK);}
  64. inline bool Is_Target_Team(TARGET a) {return (Target_Kind(a) == KIND_TEAM);}
  65. inline bool Is_Target_TeamType(TARGET a) {return (Target_Kind(a) == KIND_TEAMTYPE);}
  66. inline bool Is_Target_Trigger(TARGET a) {return (Target_Kind(a) == KIND_TRIGGER);}
  67. inline bool Is_Target_Infantry(TARGET a) {return (Target_Kind(a) == KIND_INFANTRY);}
  68. inline bool Is_Target_Bullet(TARGET a){return (Target_Kind(a) == KIND_BULLET);}
  69. inline bool Is_Target_Terrain(TARGET a){return (Target_Kind(a) == KIND_TERRAIN);}
  70. inline bool Is_Target_Cell(TARGET a){return (Target_Kind(a) == KIND_CELL);}
  71. inline bool Is_Target_Unit(TARGET a){return (Target_Kind(a) == KIND_UNIT);}
  72. inline bool Is_Target_Building(TARGET a){return (Target_Kind(a) == KIND_BUILDING);}
  73. inline bool Is_Target_Template(TARGET a){return (Target_Kind(a) == KIND_TEMPLATE);}
  74. inline bool Is_Target_Aircraft(TARGET a){return (Target_Kind(a) == KIND_AIRCRAFT);}
  75. inline bool Is_Target_Animation(TARGET a) {return (Target_Kind(a) == KIND_ANIMATION);}
  76. inline TARGET Build_Target(KindType kind, int value) {return (TARGET)((((unsigned)kind) << TARGET_MANTISSA) | (unsigned)value);}
  77. inline TARGET As_Target(CELL cell){return (TARGET)(((unsigned)KIND_CELL << TARGET_MANTISSA) | cell);}
  78. class UnitClass;
  79. class BuildingClass;
  80. class TechnoClass;
  81. class TerrainClass;
  82. class ObjectClass;
  83. class InfantryClass;
  84. class BulletClass;
  85. class TriggerClass;
  86. class TeamClass;
  87. class TeamTypeClass;
  88. class AnimClass;
  89. class AircraftClass;
  90. #ifdef NEVER
  91. class TargetClass
  92. {
  93. public:
  94. TargetClass(void) {Target.Raw = 0;};
  95. /*
  96. ** This handles assignment from an integer and conversion
  97. ** to an integer.
  98. */
  99. inline TargetClass(int val, KindType kind) {Target.Component.Value=val; Target.Component.Kind=kind;};
  100. inline TargetClass(int val) {Target.Raw = val;};
  101. inline operator int () {return Target.Raw;};
  102. //inline TargetClass & operator = (const int &val) {*((int*)this)=val; return *this;};
  103. inline bool Is_Filled(void) {return Target.Component.Kind != KIND_NONE;};
  104. inline void Invalidate(void) {Target.Component.Kind = 0;};
  105. inline bool Is_Cell(void) {return Target.Component.Kind == KIND_CELL;};
  106. inline bool Is_Unit(void) {return Target.Component.Kind == KIND_UNIT;};
  107. inline bool Is_Building(void) {return Target.Component.Kind == KIND_BUILDING;};
  108. inline bool Is_Aircraft(void) {return Target.Component.Kind == KIND_AIRCRAFT;};
  109. inline int As_Value(void) {return Target.Component.Value;};
  110. inline KindType As_Kind(void) {return Target.Component.Kind;};
  111. // Allows comparing one target to another (for equality).
  112. inline bool operator == (TargetClass t1) {
  113. return (Target.Raw == t1.Target.Raw);
  114. };
  115. UnitClass * As_Unit(void);
  116. BuildingClass * As_Building(void);
  117. bool Legal(void);
  118. CELL As_Cell(void);
  119. COORDINATE As_Coord(void);
  120. int Distance(TechnoClass *base);
  121. static int As_Target(UnitClass *unit);
  122. static int As_Target(BuildingClass *building);
  123. static int As_Target(CELL cell);
  124. private:
  125. /*
  126. ** This is the special encoded target value.
  127. */
  128. union {
  129. struct {
  130. unsigned Value:TARGET_MANTISSA;
  131. KindType Kind:TARGET_EXPONENT;
  132. } Component;
  133. int Raw;
  134. } Target;
  135. static int Build(int value, KindType kind);
  136. };
  137. #endif
  138. #endif