CnC_Remastered_Collection

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

BUILDING.H (11289B)


      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\building.h_v   2.20   16 Oct 1995 16:47:54   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 : BUILDING.H                                                   *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : April 14, 1994                                               *
     28  *                                                                                             *
     29  *                  Last Update : April 14, 1994   [JLB]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #ifndef BUILDING_H
     36 #define BUILDING_H
     37 
     38 #include	"tarcom.h"
     39 #include	"radio.h"
     40 #include	"cargo.h"
     41 #include	"mission.h"
     42 #include	"bullet.h"
     43 #include	"target.h"
     44 #include	"factory.h"
     45 
     46 #define	MAX_DOOR_STAGE	18	// # of frames of door opening on weapons factory
     47 #define	DOOR_OPEN_STAGE 9	// frame on which the door is entirely open
     48 #define	MAX_REPAIR_ANIM_STAGE	5	// # of stages of anim for repair center cycling
     49 
     50 /****************************************************************************
     51 **	For each instance of a building in the game, there is one of
     52 **	these structures. This structure holds information that is specific
     53 **	and dynamic for a particular building.
     54 */
     55 class BuildingClass : public TechnoClass
     56 {
     57 	public:
     58 		BuildingTypeClass const * const Class;
     59 		operator StructType(void) const {return Class->Type;};
     60 
     61 		/*
     62 		**	If this building is in the process of producing something, then this
     63 		**	will point to the factory manager.
     64 		*/
     65 		FactoryClass * Factory;
     66 
     67 		/*
     68 		**	This is the house that originally owned this factory. Objects buildable
     69 		**	by this house type will be produced from this factory regardless of who
     70 		**	the current owner is.
     71 		*/
     72 		HousesType ActLike;
     73 
     74 		/*
     75 		**	If the building is at a good point to change orders, then this
     76 		**	flag will be set to true.
     77 		*/
     78 		unsigned IsReadyToCommence:1;
     79 
     80 		/*
     81 		**	If this building is currently spending money to repair itself, then
     82 		**	this flag is true. It will automatically be set to false when the building
     83 		**	has reached full strength, when money is exhausted, or if the player
     84 		**	specifically stops the repair process.
     85 		*/
     86 		unsigned IsRepairing:1;
     87 
     88 		/*
     89 		**	If repair is currently in progress and this flag is true, then a wrench graphic
     90 		**	will be overlaid on the building to give visual feedback for the repair process.
     91 		*/
     92 		unsigned IsWrenchVisible:1;
     93 
     94 		/*
     95 		** This flag is set when a commando has raided the building and planted
     96 		** plastic explosives.  When the CommandoCountDown timer expires, the
     97 		** building takes massive damage.
     98 		*/
     99 		unsigned IsGoingToBlow:1;
    100 
    101 		/*
    102 		**	If this building was destroyed by some method that would prevent
    103 		**	survivors, then this flag will be true.
    104 		*/
    105 		unsigned IsSurvivorless:1;
    106 
    107 		/*
    108 		**	These state control variables are used by the oblisk for the charging
    109 		**	animation.
    110 		*/
    111 		unsigned IsCharging:1;
    112 		unsigned IsCharged:1;
    113 
    114 		/*
    115 		**	A building that has been captured will not contain the full compliment
    116 		**	of crew. This is true even if it subsiquently gets captured back.
    117 		*/
    118 		unsigned IsCaptured:1;
    119 
    120 		/*
    121 		**	Special countdown to destruction value. If the building is destroyed,
    122 		**	it won't actually be removed from the map until this value reaches
    123 		**	zero. This delay is for cosmetic reasons.
    124 		*/
    125 		TCountDownTimerClass CountDown;
    126 
    127 		/*
    128 		**	This is the current animation processing state that the building is
    129 		**	in.
    130 		*/
    131 		BStateType BState;
    132 		BStateType QueueBState;
    133 
    134 		/*
    135 		** For multiplayer games, this keeps track of the last house to damage
    136 		** this building, so if it burns to death or otherwise gradually dies,
    137 		** proper credit can be given for the kill.
    138 		*/
    139 		HousesType WhoLastHurtMe;
    140 
    141 		/*
    142 		**	This is the saboteur responsible for this building's destruction.
    143 		*/
    144 		TARGET WhomToRepay;
    145 
    146 		/*
    147 		**	This is a record of the last strength of the building. Every so often,
    148 		**	it will compare this strength to the current strength. If there is a
    149 		**	discrepency, then the owner power is adjusted accordingly.
    150 		*/
    151 		int LastStrength;
    152 
    153 		/*
    154 		**	This is the countdown timer that regulates placement retry logic
    155 		**	for factory type buildings.
    156 		*/
    157 		TCountDownTimerClass PlacementDelay;
    158 
    159 		/*---------------------------------------------------------------------
    160 		**	Constructors, Destructors, and overloaded operators.
    161 		*/
    162 		static void * BuildingClass::operator new(size_t size);
    163 		static void BuildingClass::operator delete(void *ptr);
    164 		BuildingClass(void) : Class(0) {};
    165 		BuildingClass(StructType type, HousesType house);
    166 		virtual ~BuildingClass(void);
    167 		virtual RTTIType What_Am_I(void) const {return RTTI_BUILDING;};
    168 
    169 		/*---------------------------------------------------------------------
    170 		**	Member function prototypes.
    171 		*/
    172 		static void Init(void);
    173 
    174 		TARGET  Target_Scan(void);
    175 		BuildingTypeClass::AnimControlType const *  Fetch_Anim_Control(void) {return (&Class->Anims[BState]);};
    176 
    177 		/*
    178 		**	Query functions.
    179 		*/
    180 		virtual CELL Find_Exit_Cell(TechnoClass const * techno) const;
    181 		virtual InfantryType Crew_Type(void) const;
    182 		virtual int Pip_Count(void) const;
    183 		virtual bool Can_Player_Move(void) const;
    184 		virtual ActionType What_Action(ObjectClass * target) const;
    185 		virtual ActionType What_Action(CELL cell) const;
    186 		virtual bool Can_Demolish(void) const;
    187 		virtual bool Can_Demolish_Unit(void) const;
    188 		virtual bool Can_Capture(void) const;
    189 		virtual ObjectTypeClass const & Class_Of(void) const {return *Class;};
    190 		virtual int Refund_Amount(void) const;
    191 		virtual DirType Fire_Direction(void) const;
    192 		int  Power_Output(void) const;
    193 
    194 		/*
    195 		**	Coordinate inquiry functions. These are used for both display and
    196 		**	combat purposes.
    197 		*/
    198 		virtual COORDINATE Docking_Coord(void) const;
    199 		virtual FireDataType Fire_Data(int which) const;
    200 		virtual COORDINATE Fire_Coord(int which) const;
    201 		virtual COORDINATE Center_Coord(void) const;
    202 		virtual COORDINATE Sort_Y(void) const;
    203 		virtual COORDINATE Target_Coord(void) const;
    204 
    205 		/*
    206 		**	Object entry and exit from the game system.
    207 		*/
    208 		virtual void Detach(TARGET target, bool all);
    209 		virtual void Detach_All(bool all=true);
    210 		virtual void Grand_Opening(bool captured = false);
    211 		virtual void Update_Buildables(void);
    212 		virtual MoveType Can_Enter_Cell(CELL cell, FacingType = FACING_NONE) const;
    213 		virtual bool Unlimbo(COORDINATE , DirType dir = DIR_N);
    214 		virtual bool Limbo(void);
    215 		bool Passes_Proximity_Check(CELL homecell);
    216 
    217 		/*
    218 		**	Display and rendering support functionality. Supports imagery and how
    219 		**	object interacts with the map and thus indirectly controls rendering.
    220 		*/
    221 		virtual void const * Remap_Table(void);
    222 		virtual int Exit_Object(TechnoClass * base);
    223 		virtual void Draw_It(int x, int y, WindowNumberType window);
    224 		virtual bool Mark(MarkType mark);
    225 		virtual void Look(bool incremental=false);
    226 		virtual void Fire_Out(void);
    227 		void  Begin_Mode(BStateType bstate);
    228 
    229 		/*
    230 		**	User I/O.
    231 		*/
    232 		virtual void Active_Click_With(ActionType action, ObjectClass * object);
    233 		virtual void Active_Click_With(ActionType action, CELL cell);
    234 
    235 		/*
    236 		**	Combat related.
    237 		*/
    238 		virtual void Death_Announcement(TechnoClass const * source=0) const;
    239 		virtual FireErrorType Can_Fire(TARGET, int which) const;
    240 		virtual TARGET Greatest_Threat(ThreatType threat) const;
    241 		virtual ResultType Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source=0);
    242 		virtual TARGET As_Target(void) const;
    243 		virtual bool Captured(HouseClass * newowner);
    244 
    245 		/*
    246 		**	AI.
    247 		*/
    248 		virtual void Hidden(void);
    249 		virtual bool Revealed(HouseClass * house);
    250 		virtual void Repair(int control);
    251 		virtual void Sell_Back(int control);
    252 		virtual RadioMessageType Receive_Message(RadioClass * from, RadioMessageType message, long & param);
    253 		virtual void AI(void);
    254 		virtual void Assign_Target(TARGET target);
    255 		virtual bool Toggle_Primary(void);
    256 		bool  Flush_For_Placement(TechnoClass * techno, CELL cell);
    257 
    258 		virtual int Mission_Unload(void);
    259 		virtual int Mission_Repair(void);
    260 		virtual int Mission_Attack(void);
    261 		virtual int Mission_Harvest(void);
    262 		virtual int Mission_Guard(void);
    263 		virtual int Mission_Construction(void);
    264 		virtual int Mission_Deconstruction(void);
    265 		virtual int Mission_Missile(void);
    266 		virtual void Enter_Idle_Mode(bool initial=false);
    267 
    268 		/*
    269 		**	Scenario and debug support.
    270 		*/
    271 		#ifdef CHEAT_KEYS
    272 		virtual void Debug_Dump(MonoClass *mono) const;
    273 		#endif
    274 
    275 		/*
    276 		**	File I/O.
    277 		*/
    278 		static void  Read_INI(char *buffer);
    279 		static void  Write_INI(char *buffer);
    280 		static char *INI_Name(void) {return "STRUCTURES";};
    281 		bool  Load(FileClass & file);
    282 		bool  Save(FileClass & file);
    283 		virtual void Code_Pointers(void);
    284 		virtual void Decode_Pointers(void);
    285 		void  Update_Specials(void);
    286 
    287 		/*
    288 		**	Dee-buggin' support.
    289 		*/
    290 		int Validate(void) const;
    291 
    292 	private:
    293 		void  Drop_Debris(TARGET source = TARGET_NONE);
    294 		virtual BulletClass * Fire_At(TARGET target, int which);
    295 
    296 		/*
    297 		** Some additional padding in case we need to add data to the class and maintain backwards compatibility for save/load
    298 		*/
    299 		unsigned char SaveLoadPadding[32];
    300 
    301 		static COORDINATE const CenterOffset[BSIZE_COUNT];
    302 
    303 		/*
    304 		** This contains the value of the Virtual Function Table Pointer
    305 		*/
    306 		static void * VTable;
    307 };
    308 
    309 #endif