TARGET.H (6755B)
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 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\target.h_v 2.16 16 Oct 1995 16:45:04 JOE_BOSTIC $ */ 17 /*********************************************************************************************** 18 *** 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 *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : TARGET.H * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : April 25, 1994 * 28 * * 29 * Last Update : April 25, 1994 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 34 35 #ifndef TARGET_H 36 #define TARGET_H 37 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 : unsigned char { 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 59 60 #define TARGET_MANTISSA 12 // Bits of value precision. 61 #define TARGET_MANTISSA_MASK (~((~0)<<TARGET_MANTISSA)) 62 #define TARGET_EXPONENT ((sizeof(TARGET)*8)-TARGET_MANTISSA) 63 #define TARGET_EXPONENT_MASK (~(((unsigned)(~0))>>TARGET_EXPONENT)) 64 65 inline KindType Target_Kind(TARGET a){return (KindType)(((unsigned)a)>>TARGET_MANTISSA);} 66 inline unsigned Target_Value(TARGET a){return (((unsigned)a) & TARGET_MANTISSA_MASK);} 67 68 inline bool Is_Target_Team(TARGET a) {return (Target_Kind(a) == KIND_TEAM);} 69 inline bool Is_Target_TeamType(TARGET a) {return (Target_Kind(a) == KIND_TEAMTYPE);} 70 inline bool Is_Target_Trigger(TARGET a) {return (Target_Kind(a) == KIND_TRIGGER);} 71 inline bool Is_Target_Infantry(TARGET a) {return (Target_Kind(a) == KIND_INFANTRY);} 72 inline bool Is_Target_Bullet(TARGET a){return (Target_Kind(a) == KIND_BULLET);} 73 inline bool Is_Target_Terrain(TARGET a){return (Target_Kind(a) == KIND_TERRAIN);} 74 inline bool Is_Target_Cell(TARGET a){return (Target_Kind(a) == KIND_CELL);} 75 inline bool Is_Target_Unit(TARGET a){return (Target_Kind(a) == KIND_UNIT);} 76 inline bool Is_Target_Building(TARGET a){return (Target_Kind(a) == KIND_BUILDING);} 77 inline bool Is_Target_Template(TARGET a){return (Target_Kind(a) == KIND_TEMPLATE);} 78 inline bool Is_Target_Aircraft(TARGET a){return (Target_Kind(a) == KIND_AIRCRAFT);} 79 inline bool Is_Target_Animation(TARGET a) {return (Target_Kind(a) == KIND_ANIMATION);} 80 81 inline TARGET Build_Target(KindType kind, int value) {return (TARGET)((((unsigned)kind) << TARGET_MANTISSA) | (unsigned)value);} 82 inline TARGET As_Target(CELL cell){return (TARGET)(((unsigned)KIND_CELL << TARGET_MANTISSA) | cell);} 83 84 class UnitClass; 85 class BuildingClass; 86 class TechnoClass; 87 class TerrainClass; 88 class ObjectClass; 89 class InfantryClass; 90 class BulletClass; 91 class TriggerClass; 92 class TeamClass; 93 class TeamTypeClass; 94 class AnimClass; 95 class AircraftClass; 96 97 #ifdef NEVER 98 class TargetClass 99 { 100 public: 101 TargetClass(void) {Target.Raw = 0;}; 102 103 /* 104 ** This handles assignment from an integer and conversion 105 ** to an integer. 106 */ 107 inline TargetClass(int val, KindType kind) {Target.Component.Value=val; Target.Component.Kind=kind;}; 108 inline TargetClass(int val) {Target.Raw = val;}; 109 inline operator int () {return Target.Raw;}; 110 //inline TargetClass & operator = (const int &val) {*((int*)this)=val; return *this;}; 111 112 inline bool Is_Filled(void) {return Target.Component.Kind != KIND_NONE;}; 113 inline void Invalidate(void) {Target.Component.Kind = 0;}; 114 inline bool Is_Cell(void) {return Target.Component.Kind == KIND_CELL;}; 115 inline bool Is_Unit(void) {return Target.Component.Kind == KIND_UNIT;}; 116 inline bool Is_Building(void) {return Target.Component.Kind == KIND_BUILDING;}; 117 inline bool Is_Aircraft(void) {return Target.Component.Kind == KIND_AIRCRAFT;}; 118 inline int As_Value(void) {return Target.Component.Value;}; 119 inline KindType As_Kind(void) {return Target.Component.Kind;}; 120 121 // Allows comparing one target to another (for equality). 122 inline bool operator == (TargetClass t1) { 123 return (Target.Raw == t1.Target.Raw); 124 }; 125 126 UnitClass * As_Unit(void); 127 BuildingClass * As_Building(void); 128 bool Legal(void); 129 CELL As_Cell(void); 130 COORDINATE As_Coord(void); 131 int Distance(TechnoClass *base); 132 static int As_Target(UnitClass *unit); 133 static int As_Target(BuildingClass *building); 134 static int As_Target(CELL cell); 135 136 private: 137 138 /* 139 ** This is the special encoded target value. 140 */ 141 union { 142 struct { 143 unsigned Value:TARGET_MANTISSA; 144 KindType Kind:TARGET_EXPONENT; 145 } Component; 146 int Raw; 147 } Target; 148 149 150 static int Build(int value, KindType kind); 151 }; 152 #endif 153 154 #endif