1 #ifndef __ISOMETRIC_UTILSH
2 #define __ISOMETRIC_UTILSH
3
4 #include "JA2Types.h"
5 #include "Overhead_Types.h"
6 #include "Types.h"
7 #include "WorldDef.h"
8 struct SOLDIERTYPE;
9
10
11 #define MAXCOL WORLD_COLS
12 #define MAXROW WORLD_ROWS
13 #define GRIDSIZE (MAXCOL * MAXROW)
14 #define RIGHTMOSTGRID (MAXCOL - 1)
15 #define LASTROWSTART (GRIDSIZE - MAXCOL)
16 #define NOWHERE (GRIDSIZE + 1)
17 #define MAPWIDTH (WORLD_COLS)
18 #define MAPHEIGHT (WORLD_ROWS)
19 #define MAPLENGTH (MAPHEIGHT*MAPWIDTH)
20
21
OppositeDirection(UINT dir)22 static inline UINT8 OppositeDirection(UINT dir) { return (dir + 4) % NUM_WORLD_DIRECTIONS; }
TwoCCDirection(UINT dir)23 static inline UINT8 TwoCCDirection(UINT dir) { return (dir + 6) % NUM_WORLD_DIRECTIONS; }
TwoCDirection(UINT dir)24 static inline UINT8 TwoCDirection(UINT dir) { return (dir + 2) % NUM_WORLD_DIRECTIONS; }
OneCCDirection(UINT dir)25 static inline UINT8 OneCCDirection(UINT dir) { return (dir + 7) % NUM_WORLD_DIRECTIONS; }
OneCDirection(UINT dir)26 static inline UINT8 OneCDirection(UINT dir) { return (dir + 1) % NUM_WORLD_DIRECTIONS; }
27
28 extern const UINT8 gPurpendicularDirection[NUM_WORLD_DIRECTIONS][NUM_WORLD_DIRECTIONS];
29
30 // Macros
31
32
33 // |Check for map bounds------------------------------------------| |Invalid-| |Valid-------------------|
34 #define MAPROWCOLTOPOS( r, c ) ( ( (r < 0) || (r >= WORLD_ROWS) || (c < 0) || (c >= WORLD_COLS) ) ? ( 0xffff ) : ( (r) * WORLD_COLS + (c) ) )
35
36 #define GETWORLDINDEXFROMWORLDCOORDS( r, c ) ( (INT16) ( r / CELL_X_SIZE ) ) * WORLD_COLS + ( (INT16) ( c / CELL_Y_SIZE ) )
37
38 void ConvertGridNoToXY( INT16 sGridNo, INT16 *sXPos, INT16 *sYPos );
39 void ConvertGridNoToCellXY( INT16 sGridNo, INT16 *sXPos, INT16 *sYPos );
40 void ConvertGridNoToCenterCellXY( INT16 sGridNo, INT16 *sXPos, INT16 *sYPos );
41
42
43 // GRID NO MANIPULATION FUNCTIONS
44 INT16 NewGridNo(INT16 sGridno, INT16 sDirInc);
45 INT16 DirectionInc(UINT8 sDirection);
46 INT32 OutOfBounds(INT16 sGridno, INT16 sProposedGridno);
47
48
49 BOOLEAN GetMouseXY( INT16 *psMouseX, INT16 *psMouseY );
50 BOOLEAN GetMouseWorldCoords( INT16 *psMouseX, INT16 *psMouseY );
51
52 /* Returns the GridNo of the tile the mouse cursor is currently over or NOWHERE
53 * if the cursor is not over any tile. */
54 GridNo GetMouseMapPos(void);
55
56
57 void GetAbsoluteScreenXYFromMapPos(GridNo pos, INT16* psWorldScreenX, INT16* psWorldScreenY);
58 GridNo GetMapPosFromAbsoluteScreenXY(INT16 sWorldScreenX, INT16 sWorldScreenY);
59
60
61 void FromCellToScreenCoordinates( INT16 sCellX, INT16 sCellY, INT16 *psScreenX, INT16 *psScreenY );
62 void FromScreenToCellCoordinates( INT16 sScreenX, INT16 sScreenY, INT16 *psCellX, INT16 *psCellY );
63
64 // Higher resolution convertion functions
65 void FloatFromCellToScreenCoordinates( FLOAT dCellX, FLOAT dCellY, FLOAT *pdScreenX, FLOAT *pdScreenY );
66
67 BOOLEAN GridNoOnVisibleWorldTile( INT16 sGridNo );
68 BOOLEAN GridNoOnEdgeOfMap( INT16 sGridNo, INT8 * pbDirection );
69
70 void CellXYToScreenXY(INT16 sCellX, INT16 sCellY, INT16* sScreenX, INT16* sScreenY);
71
72 INT32 GetRangeFromGridNoDiff( INT16 sGridNo1, INT16 sGridNo2 );
73 INT32 GetRangeInCellCoordsFromGridNoDiff( INT16 sGridNo1, INT16 sGridNo2 );
74
75 bool IsPointInScreenRect(INT16 x, INT16 y, SGPRect const&);
76 BOOLEAN IsPointInScreenRectWithRelative( INT16 sXPos, INT16 sYPos, SGPRect *pRect, INT16 *sXRel, INT16 *sRelY );
77
78
79 INT16 PythSpacesAway(INT16 sOrigin, INT16 sDest);
80 INT16 SpacesAway(INT16 sOrigin, INT16 sDest);
81 INT16 CardinalSpacesAway(INT16 sOrigin, INT16 sDest);
82 bool FindHigherLevel(SOLDIERTYPE const*, UINT8* out_direction = 0);
83 bool FindLowerLevel(SOLDIERTYPE const*, UINT8* out_direction = 0);
84
85 INT16 QuickestDirection(INT16 origin, INT16 dest);
86 INT16 ExtQuickestDirection(INT16 origin, INT16 dest);
87
88
89 // Returns the (center ) cell coordinates in X
90 INT16 CenterX( INT16 sGridno );
91
92 // Returns the (center ) cell coordinates in Y
93 INT16 CenterY( INT16 sGridno );
94
95 BOOLEAN FindFenceJumpDirection(SOLDIERTYPE const*, UINT8* out_direction = 0);
96 BOOLEAN IsFacingClimableWindow(SOLDIERTYPE const*);
97
98 //Simply chooses a random gridno within valid boundaries (for dropping things in unloaded sectors)
99 INT16 RandomGridNo(void);
100
101 extern UINT32 guiForceRefreshMousePositionCalculation;
102
103 extern const INT16 DirIncrementer[8];
104
105 #endif
106