CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

TARGET.H (8701B)


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