CnC_Remastered_Collection

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

DISPLAY.H (12696B)


      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\display.h_v   2.15   16 Oct 1995 16:47:42   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 : DISPLAY.H                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : May 1, 1994                                                  *
     28  *                                                                                             *
     29  *                  Last Update : May 1, 1994   [JLB]                                          *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #ifndef DISPLAY_H
     36 #define DISPLAY_H
     37 
     38 #include	"map.h"
     39 #include	"layer.h"
     40 
     41 
     42 #define	ICON_PIXEL_W	 		24
     43 #define	ICON_PIXEL_H			24
     44 #define	ICON_LEPTON_W			256
     45 #define	ICON_LEPTON_H			256
     46 #define	CELL_PIXEL_W	 		ICON_PIXEL_W
     47 #define	CELL_PIXEL_H			ICON_PIXEL_H
     48 #define	CELL_LEPTON_W			ICON_LEPTON_W
     49 #define	CELL_LEPTON_H			ICON_LEPTON_H
     50 
     51 //	-----------------------------------------------------------
     52 #define	PIXEL_LEPTON_W			(ICON_LEPTON_W/ICON_PIXEL_W)
     53 #define	PIXEL_LEPTON_H			(ICON_LEPTON_H/ICON_PIXEL_H)
     54 
     55 
     56 extern COORDINATE Coord_Add(COORDINATE coord1, COORDINATE coord2);
     57 
     58 class DisplayClass: public MapClass
     59 {
     60 	// Need access to shadow shapes
     61 	friend class DLLExportClass;
     62 	
     63 	public:
     64 
     65 		/*
     66 		**	This indicates the theater that the display is to represent.
     67 		*/
     68 		TheaterType Theater;
     69 
     70 		/*
     71 		** The tactical map display position is indicated by the cell of the
     72 		**	upper left hand corner. These should not be altered directly. Use
     73 		**	the Set_Tactical_Position function instead.
     74 		*/
     75 		COORDINATE TacticalCoord;
     76 
     77 		/*
     78 		**	The dimensions (in cells) of the visible window onto the game map. This tactical
     79 		**	map is how the player interacts and views the game world.
     80 		*/
     81 		int TacLeptonWidth;
     82 		int TacLeptonHeight;
     83 
     84 		/*
     85 		**	These layer control elements are used to group the displayable objects
     86 		**	so that proper overlap can be obtained.
     87 		*/
     88 		static LayerClass Layer[LAYER_COUNT];
     89 
     90 		/*
     91 		**	This records the position and shape of a placement cursor to display
     92 		**	over the map. This cursor is used when placing buildings and also used
     93 		**	extensively by the scenario editor.
     94 		*/
     95 		CELL ZoneCell;
     96 		short ZoneOffset;
     97 		short const *CursorSize;
     98 		short CursorShapeSave[256];	// For save/load
     99 		bool ProximityCheck;				// Is proximity check ok?
    100 
    101 		/*
    102 		** This holds the building type that is about to be placed upon the map.
    103 		**	It is only valid during the building placement state. The PendingLegal
    104 		**	flag is updated as the cursor moves and it reflects the legality of
    105 		**	placing the building at the desired location.
    106 		*/
    107 		ObjectClass * PendingObjectPtr;
    108 		ObjectTypeClass const * PendingObject;
    109 		HousesType PendingHouse;
    110 
    111 		static unsigned char FadingBrighten[256];
    112 		static unsigned char FadingShade[256];
    113 		static unsigned char FadingLight[256];
    114 		static unsigned char RemapTables[HOUSE_COUNT][3][256];
    115 		static unsigned char FadingGreen[256];
    116 		static unsigned char FadingYellow[256];
    117 		static unsigned char FadingRed[256];
    118 		static unsigned char TranslucentTable[(MAGIC_COL_COUNT+1)*256];
    119 		static unsigned char WhiteTranslucentTable[(1+1)*256];
    120 		static unsigned char MouseTranslucentTable[(4+1)*256];
    121 		static void const *TransIconset;
    122 		static unsigned char UnitShadow[(USHADOW_COL_COUNT+1)*256];
    123 		static unsigned char SpecialGhost[2*256];
    124 
    125 		//-------------------------------------------------------------------------
    126 		DisplayClass(void);
    127 
    128 		virtual void Read_INI(char *buffer);
    129 		void Write_INI(char *buffer);
    130 
    131 		/*
    132 		** Initialization
    133 		*/
    134 		virtual void One_Time(void);							// One-time inits
    135 		virtual void Init_Clear(void);						// Clears all to known state
    136 		virtual void Init_IO(void);							// Inits button list
    137 		virtual void Init_Theater(TheaterType theater);	// Theater-specific inits
    138 
    139 		/*
    140 		**	General display/map/interface support functionality.
    141 		*/
    142 		virtual void AI(KeyNumType &input, int x, int y);
    143 		virtual void Draw_It(bool complete=false);
    144 
    145 		/*
    146 		**	Added functionality.
    147 		*/
    148 		COORDINATE  Center_Map(void);
    149 		virtual bool Map_Cell(CELL cell, HouseClass *house, bool and_for_allies);
    150 
    151 		virtual CELL Click_Cell_Calc(int x, int y);
    152 		virtual void Help_Text(int , int =-1, int =-1, int =YELLOW, bool =false, int =0) {};
    153 		virtual MouseType Get_Mouse_Shape(void) const = 0;
    154 		virtual bool Scroll_Map(DirType facing, int & distance, bool really);
    155 		virtual void Refresh_Cells(CELL cell, short const *list);
    156 		virtual void Set_View_Dimensions(int x, int y, int width=-1, int height=-1);
    157 
    158 		/*
    159 		**	Pending object placement control.
    160 		*/
    161 		virtual void Put_Place_Back(TechnoClass * ) {}; // Affects 'pending' system.
    162 		void  Cursor_Mark(CELL pos, bool on);
    163 		void  Set_Cursor_Shape(short const * list);
    164 		CELL  Set_Cursor_Pos(CELL pos = -1);
    165 		void  Get_Occupy_Dimensions(int & w, int & h, short const *list);
    166 
    167 		/*
    168 		**	Tactical map only functionality.
    169 		*/
    170 		virtual void Set_Tactical_Position(COORDINATE coord);
    171 		void  Refresh_Band(void);
    172 		void  Select_These(COORDINATE coord1, COORDINATE coord2, bool additive = false);
    173 		COORDINATE  Pixel_To_Coord(int x, int y);
    174 		bool  Coord_To_Pixel(COORDINATE coord, int &x, int &y);
    175 		bool  Push_Onto_TacMap(COORDINATE &source, COORDINATE &dest);
    176 		void  Remove(ObjectClass const *object, LayerType layer);
    177 		void  Submit(ObjectClass const *object, LayerType layer);
    178 		CELL  Calculated_Cell(SourceType dir, HousesType house);
    179 		bool  In_View(register CELL cell);
    180 		bool  Passes_Proximity_Check(ObjectTypeClass const *object);
    181 #ifdef USE_RA_AI
    182 		bool Passes_Proximity_Check(ObjectTypeClass const * object, HousesType house, short const * list, CELL trycell) const;
    183 #endif
    184 		ObjectClass *  Cell_Object(CELL cell, int x=0, int y=0);
    185 		ObjectClass *  Next_Object(ObjectClass * object);
    186 		ObjectClass *  Prev_Object(ObjectClass * object);
    187 		int  Cell_Shadow(CELL cell, HouseClass *house);
    188 		short const *  Text_Overlap_List(char const * text, int x, int y, int lines = 1);
    189 		bool  Is_Spot_Free(COORDINATE coord) const;
    190 		COORDINATE  Closest_Free_Spot(COORDINATE coord, bool any=false) const;
    191 		void  Sell_Mode_Control(int control);
    192 		void  Repair_Mode_Control(int control);
    193 
    194 		void Flag_Cell(CELL cell) {
    195 			Flag_To_Redraw(false);
    196 			IsToRedraw = true;
    197 			CellRedraw[cell] = true;
    198 		};
    199 		bool  Is_Cell_Flagged(CELL cell) const {return CellRedraw.Is_True(cell);};
    200 
    201 		/*
    202 		** Computes starting position based on player's units' Coords.
    203 		*/
    204 		void Compute_Start_Pos(long& x, long& y);
    205 
    206 		/*
    207 		**	File I/O.
    208 		*/
    209 		virtual void Code_Pointers(void);
    210 		virtual void Decode_Pointers(void);
    211 
    212 	protected:
    213 		virtual void Mouse_Right_Press(void);
    214 		virtual void Mouse_Left_Press(int x, int y);
    215 		virtual void Mouse_Left_Up(bool shadow, ObjectClass * object, ActionType action, bool wwsmall = false);
    216 		virtual void Mouse_Left_Held(int x, int y);
    217 		virtual void Mouse_Left_Release(CELL cell, int x, int y, ObjectClass * object, ActionType action, bool wwsmall = false);
    218 
    219 	public:
    220 		/*
    221 		**	This is the pixel offset for the upper left corner of the tactical map.
    222 		*/
    223 		int TacPixelX;
    224 		int TacPixelY;
    225 
    226 		/*
    227 		**	This is the coordinate that the tactical map should be in at next available opportunity.
    228 		*/
    229 		COORDINATE DesiredTacticalCoord;
    230 
    231 		/*
    232 		**	If something in the tactical map is to be redrawn, this flag is set to true.
    233 		*/
    234 		unsigned IsToRedraw:1;
    235 
    236 		/*
    237 		**	If the player is currently wielding a wrench (to select buildings for repair),
    238 		**	then this flag is true. In such a state, normal movement and combat orders
    239 		**	are preempted.
    240 		*/
    241 		unsigned IsRepairMode:1;
    242 
    243 		/*
    244 		**	If the player is currently in "sell back" mode, then this flag will be
    245 		**	true. While in this mode, anything clicked on will be sold back to the
    246 		**	"factory".
    247 		*/
    248 		unsigned IsSellMode:1;
    249 
    250 		/*
    251 		**	If the player is currently in ion cannon targetting mode, then this
    252 		** flag will be true.  While in this mode, anything clicked on will be
    253 		** be destroyed by the ION cannon.
    254 		*/
    255 		unsigned IsTargettingMode:2;
    256 
    257 	protected:
    258 
    259 		/*
    260 		**	If it is currently in rubber band mode (multi unit selection), then this
    261 		**	flag will be true. While in such a mode, normal input is prempted while
    262 		**	the extended selection is in progress.
    263 		*/
    264 		unsigned IsRubberBand:1;
    265 
    266 		/*
    267 		**	The moment the mouse is held down, this flag gets set. If the mouse is dragged
    268 		**	a sufficient distance while held down, then true rubber band mode selection
    269 		**	can begin. Using a minimum distance prevents accidental rubber band selection
    270 		**	mode from being initiated.
    271 		*/
    272 		unsigned IsTentative:1;
    273 
    274 		/*
    275 		**	This gadget class is used for capturing input to the tactical map. All mouse input
    276 		**	will be routed through this gadget.
    277 		*/
    278 		class TacticalClass : public GadgetClass {
    279 			public:
    280 				TacticalClass(void) : GadgetClass(0,0,0,0,LEFTPRESS|LEFTRELEASE|LEFTHELD|LEFTUP|RIGHTPRESS,true) {};
    281 
    282 				int Selection_At_Mouse(unsigned flags, KeyNumType & key);
    283 				int Command_Object(unsigned flags, KeyNumType & key);
    284 
    285 			protected:
    286 				virtual int Action(unsigned flags, KeyNumType & key);
    287 		};
    288 		friend class TacticalClass;
    289 
    290 		/*
    291 		**	This is the "button" that tracks all input to the tactical map.
    292 		** It must be available to derived classes, for Save/Load purposes.
    293 		*/
    294 public:		//ST - 1/21/2019 11:59AM
    295 		static TacticalClass TacButton;
    296 
    297 	private:
    298 
    299 		/*
    300 		**	This is a utility flag that is set during the icon draw process only if there
    301 		**	was at least one shadow icon detected that should be redrawn. When the shadow
    302 		**	drawing logic is to take place, but this flag is false, then the shadow drawing
    303 		**	will be skipped since it would perform no function.
    304 		*/
    305 		unsigned IsShadowPresent:1;
    306 
    307 		/*
    308 		**	Rubber band mode consists of stretching a box from the anchor point (specified
    309 		**	here) to the current cursor position.
    310 		*/
    311 		int BandX,BandY;
    312 		int NewX,NewY;
    313 
    314 		static void const *ShadowShapes;
    315 		static unsigned char ShadowTrans[(SHADOW_COL_COUNT+1)*256];
    316 
    317 		void Redraw_Icons(int draw_flags=0);
    318 		void Redraw_Shadow(void);
    319 		void Redraw_Shadow_Rects(void);
    320 
    321 		/*
    322 		**	This bit array is used to flag cells to be redrawn. If the icon needs to
    323 		**	be redrawn for a cell, then the corresponding flag will be true.
    324 		*/
    325 		static BooleanVectorClass CellRedraw;
    326 
    327 		//
    328 		// We need a way to bypass visible view checks when we are running in the context of GlyphX without using the
    329 		// internal C&C renderer. We shouldn't know or care what the user is actually looking at
    330 		// ST - 4/17/2019 9:01AM
    331 		//
    332 		static bool IgnoreViewConstraints;
    333 
    334 		/*
    335 		** Some additional padding in case we need to add data to the class and maintain backwards compatibility for save/load
    336 		*/
    337 		unsigned char SaveLoadPadding[1024];
    338 };
    339 
    340 
    341 #endif