summaryrefslogtreecommitdiff
path: root/src/core/Radar.h
blob: 3e61f8db29d2f97cfe948ccc590281174abb1d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#pragma once
#include "Sprite2d.h"

#define CARBLIP_MARKER_COLOR_R 252
#define CARBLIP_MARKER_COLOR_G 138
#define CARBLIP_MARKER_COLOR_B 242
#define CARBLIP_MARKER_COLOR_A 255

#define CHARBLIP_MARKER_COLOR_R 252
#define CHARBLIP_MARKER_COLOR_G 138
#define CHARBLIP_MARKER_COLOR_B 242
#define CHARBLIP_MARKER_COLOR_A 255

#define OBJECTBLIP_MARKER_COLOR_R 252
#define OBJECTBLIP_MARKER_COLOR_G 138
#define OBJECTBLIP_MARKER_COLOR_B 242
#define OBJECTBLIP_MARKER_COLOR_A 255

#define COORDBLIP_MARKER_COLOR_R 255
#define COORDBLIP_MARKER_COLOR_G 255
#define COORDBLIP_MARKER_COLOR_B 128
#define COORDBLIP_MARKER_COLOR_A 228

#define NUM_MAP_LEGENDS 75

#define MENU_MAP_LENGTH_UNIT 1190.0f // in game unit
#define MENU_MAP_WIDTH_SCALE 1.112f // in game unit (originally 1.112494151260504f)
#define MENU_MAP_HEIGHT_SCALE 1.119f // in game unit (originally 1.118714268907563f)
#define MENU_MAP_TOP_OFFSET 0.28f // in length unit defined above - ~333 game unit
#define MENU_MAP_LEFT_OFFSET 0.185f // in length unit defined above - ~220 game unit
#define MENU_MAP_LENGTH (4000.f / MENU_MAP_LENGTH_UNIT)

enum eBlipType
{
	BLIP_NONE,
	BLIP_CAR,
	BLIP_CHAR,
	BLIP_OBJECT,
	BLIP_COORD,
	BLIP_CONTACT_POINT
};

enum eBlipDisplay
{
	BLIP_DISPLAY_NEITHER = 0,
	BLIP_DISPLAY_MARKER_ONLY = 1,
	BLIP_DISPLAY_BLIP_ONLY = 2,
	BLIP_DISPLAY_BOTH = 3,
};

enum eRadarSprite
{
	RADAR_SPRITE_ENTITY_BLIP = -2,
	RADAR_SPRITE_COORD_BLIP = -1,
	RADAR_SPRITE_NONE = 0,
	RADAR_SPRITE_CENTRE,
	RADAR_SPRITE_MAP_HERE,
	RADAR_SPRITE_NORTH,
	RADAR_SPRITE_AVERY,
	RADAR_SPRITE_BIKER,
	RADAR_SPRITE_CORTEZ,
	RADAR_SPRITE_DIAZ,
	RADAR_SPRITE_KENT,
	RADAR_SPRITE_LAWYER,
	RADAR_SPRITE_PHIL,
	RADAR_SPRITE_BIKERS,
	RADAR_SPRITE_BOATYARD,
	RADAR_SPRITE_MALIBU_CLUB,
	RADAR_SPRITE_CUBANS,
	RADAR_SPRITE_FILM,
	RADAR_SPRITE_GUN,
	RADAR_SPRITE_HAITIANS,
	RADAR_SPRITE_HARDWARE,
	RADAR_SPRITE_SAVE,
	RADAR_SPRITE_STRIP,
	RADAR_SPRITE_ICE,
	RADAR_SPRITE_KCABS,
	RADAR_SPRITE_LOVEFIST,
	RADAR_SPRITE_PRINTWORKS,
	RADAR_SPRITE_PROPERTY,
	RADAR_SPRITE_SUNYARD,
	RADAR_SPRITE_SPRAY,
	RADAR_SPRITE_TSHIRT,
	RADAR_SPRITE_TOMMY,
	RADAR_SPRITE_PHONE,
	RADAR_SPRITE_EIGHTBALL,
	RADAR_SPRITE_BURNER,
	RADAR_SPRITE_CIPRIANI,
	RADAR_SPRITE_DONALD,
	RADAR_SPRITE_JOSEPH,
	RADAR_SPRITE_LEONE,
	RADAR_SPRITE_MARIA,
	RADAR_SPRITE_MCRAY,
	RADAR_SPRITE_TOSHIKO,
	RADAR_SPRITE_VINCENZO, // tmp
	RADAR_SPRITE_BOMB,
	RADAR_SPRITE_CLOTHES,
	RADAR_SPRITE_PROPERTY_RED,
	RADAR_SPRITE_PHIL_CASSIDY,
	RADAR_SPRITE_POWERUP,
	RADAR_SPRITE_MPBASE,
	RADAR_SPRITE_MPCHECKPOINT,
	RADAR_SPRITE_MPPLAYER,
	RADAR_SPRITE_MPOBJECTIVE,
	RADAR_SPRITE_MPCAR,
	RADAR_SPRITE_MPTANK,
	RADAR_SPRITE_MPCARLOCKUP,
	RADAR_SPRITE_MPTARGETPLAYER,
	RADAR_SPRITE_MAPHERE0,
	RADAR_SPRITE_MAPHERE1,
	RADAR_SPRITE_MAPHERE2,
	RADAR_SPRITE_MAPHERE3,
	RADAR_SPRITE_MAPHERE4,
	RADAR_SPRITE_MAPHERE5,
	RADAR_SPRITE_MAPHERE6,
	RADAR_SPRITE_MAPHERE7,
	RADAR_SPRITE_MAPWAYPOINT,

	RADAR_SPRITE_COUNT
};

enum
{
	RADAR_TRACE_RED,
	RADAR_TRACE_GREEN,
	RADAR_TRACE_LIGHT_BLUE,
	RADAR_TRACE_GRAY,
	RADAR_TRACE_YELLOW,
	RADAR_TRACE_MAGENTA,
	RADAR_TRACE_CYAN
};

enum
{
	BLIP_MODE_TRIANGULAR_UP = 0,
	BLIP_MODE_TRIANGULAR_DOWN,
	BLIP_MODE_SQUARE,
};

struct sRadarTrace
{
	uint32 m_nColor;
	uint32 m_eBlipType; // eBlipType
	int32 m_nEntityHandle;
	CVector m_vec2DPos;
	CVector m_vecPos;
	uint16 m_BlipIndex;
	bool m_bDim;
	bool m_bInUse;
	bool m_bShortRange;
	bool m_unused;
	float m_Radius;
	int16 m_wScale;
	uint16 m_eBlipDisplay; // eBlipDisplay
	uint16 m_eRadarSprite; // eRadarSprite
};

// Either that was a thing while saving/loading blips, or they added sizes of each field one by one. I want to do the former.
#pragma pack(push,1)
struct sRadarTraceSave
{
	uint32 m_nColor;
	float m_Radius;
	uint32 m_eBlipType; // eBlipType
	int32 m_nEntityHandle;
	CVector2D m_vec2DPos;
	CVector m_vecPos;
	uint16 m_BlipIndex;
	bool m_bDim;
	bool m_bInUse;
	bool m_bShortRange;
	bool m_unused;
	int16 m_wScale;
	uint16 m_eBlipDisplay; // eBlipDisplay
	uint16 m_eRadarSprite; // eRadarSprite
};
#pragma pack(pop)

// Values for screen space
#define RADAR_LEFT (40.0f)
#define RADAR_BOTTOM (40.0f)

#ifdef FIX_RADAR
/*
	The values are from an early screenshot taken before R* broke radar
		#define RADAR_WIDTH (82.0f)
		#define RADAR_HEIGHT (82.0f)
*/
#define RADAR_WIDTH ((CDraw::ms_bFixRadar)  ? (82.0f) : (94.0f))	
#define RADAR_HEIGHT ((CDraw::ms_bFixRadar) ? (82.0f) : (76.0f))
#else
/*
	broken since forever, someone tried to fix size for 640x512(PAL)
		http://aap.rockstarvision.com/pics/gta3/ps2screens/gta3_interface.jpg
	but failed:
		http://aap.rockstarvision.com/pics/gta3/artwork/gta3_artwork_16.jpg
	most likely the guy used something like this:
		int y = 82 * (640.0/512.0)/(640.0/480.0);
		int x = y * (640.0/512.0);
*/
#define RADAR_WIDTH (94.0f)
#define RADAR_HEIGHT (76.0f)
#endif

class CRadar
{
public:
	static float m_radarRange;
	static sRadarTrace ms_RadarTrace[NUMRADARBLIPS];
	static CSprite2d CentreSprite;
	static CSprite2d MapHereSprite;
	static CSprite2d NorthSprite;
	static CSprite2d AverySprite;
	static CSprite2d BikerSprite;
	static CSprite2d CortezSprite;
	static CSprite2d DiazSprite;
	static CSprite2d KentSprite;
	static CSprite2d LawyerSprite;
	static CSprite2d PhilSprite;
	static CSprite2d BikersSprite;
	static CSprite2d BoatyardSprite;
	static CSprite2d MalibuClubSprite;
	static CSprite2d CubansSprite;
	static CSprite2d FilmSprite;
	static CSprite2d GunSprite;
	static CSprite2d HaitiansSprite;
	static CSprite2d HardwareSprite;
	static CSprite2d SaveHouseSprite;
	static CSprite2d StripSprite;
	static CSprite2d IceSprite;
	static CSprite2d KCabsSprite;
	static CSprite2d LovefistSprite;
	static CSprite2d PrintworksSprite;
	static CSprite2d PropertySprite;
	static CSprite2d SunYardSprite;
	static CSprite2d SpraySprite;
	static CSprite2d TShirtSprite;
	static CSprite2d TommySprite;
	static CSprite2d PhoneSprite;
/*	static CSprite2d RadioWildstyleSprite;
	static CSprite2d RadioFlashSprite;
	static CSprite2d RadioKChatSprite;
	static CSprite2d RadioFeverSprite;
	static CSprite2d RadioVRockSprite;
	static CSprite2d RadioVCPRSprite;
	static CSprite2d RadioEspantosoSprite;
	static CSprite2d RadioEmotionSprite;
	static CSprite2d RadioWaveSprite;*/
	static CSprite2d EightBallSprite;
	static CSprite2d BurnerSprite;
	static CSprite2d CiprianiSprite;
	static CSprite2d DonaldSprite;
	static CSprite2d JosephSprite;
	static CSprite2d LeoneSprite;
	static CSprite2d MariaSprite;
	static CSprite2d McraySprite;
	static CSprite2d ToshikoSprite;
	static CSprite2d VincenzoSprite;
	static CSprite2d BombSprite;
	static CSprite2d ClothesShopSprite;
	static CSprite2d PropertyRedSprite;
	static CSprite2d PhilCassidySprite;
	static CSprite2d PowerupSprite;
	static CSprite2d MPBase;
	static CSprite2d MPCheckPoint;
	static CSprite2d MPPlayer;
	static CSprite2d MPObjective;
	static CSprite2d MPCar;
	static CSprite2d MPTank;
	static CSprite2d MPCarLockup;
	static CSprite2d MPTargetPlayer;
	static CSprite2d MapHereSprite0;
	static CSprite2d MapHereSprite1;
	static CSprite2d MapHereSprite2;
	static CSprite2d MapHereSprite3;
	static CSprite2d MapHereSprite4;
	static CSprite2d MapHereSprite5;
	static CSprite2d MapHereSprite6;
	static CSprite2d MapHereSprite7;
	static CSprite2d MapWayPoint;
	static CSprite2d *RadarSprites[RADAR_SPRITE_COUNT];
	static float cachedCos;
	static float cachedSin;
	static CRGBA ArrowBlipColour1;
	static CRGBA ArrowBlipColour2;
	static int16 MapLegendList[NUM_MAP_LEGENDS];
	static int16 MapLegendCounter;

#ifdef MAP_ENHANCEMENTS
	static int TargetMarkerId;
	static CVector TargetMarkerPos;
#endif

	static void InitFrontEndMap();
	static void DrawYouAreHereSprite(float, float);
#ifdef MAP_ENHANCEMENTS
	static void ToggleTargetMarker(float, float);
#endif
	static uint8 CalculateBlipAlpha(float dist);
	static void ChangeBlipBrightness(int32 i, int32 bright);
	static void ChangeBlipColour(int32 i, int32);
	static void ChangeBlipDisplay(int32 i, eBlipDisplay display);
	static void ChangeBlipScale(int32 i, int32 scale);
	static void ClearBlip(int32 i);
	static void ClearBlipForEntity(eBlipType type, int32 id);
	static int ClipRadarPoly(CVector2D *out, const CVector2D *in);
	static bool DisplayThisBlip(int32 i);
	static void Draw3dMarkers();
	static void DrawBlips();
	static void DrawMap();
	static void DrawRadarMap();
	static void DrawRadarMask();
	static void DrawRadarSection(int32 x, int32 y);
	static void DrawRadarSprite(uint16 sprite, float x, float y, uint8 alpha);
	static void DrawRotatingRadarSprite(CSprite2d* sprite, float x, float y, float angle, int32 alpha);
	static int32 GetActualBlipArrayIndex(int32 i);
	static int32 GetNewUniqueBlipIndex(int32 i);
	static uint32 GetRadarTraceColour(uint32 color, bool bright);
	static void Initialise();
	static float LimitRadarPoint(CVector2D &point);
	static void LoadAllRadarBlips(uint8 *buf, uint32 size);
	static void LoadTextures();
	static void RemoveRadarSections();
	static void SaveAllRadarBlips(uint8*, uint32*);
	static void SetBlipSprite(int32 i, int32 icon);
	static int32 SetCoordBlip(eBlipType type, CVector pos, uint32, eBlipDisplay);
	static int32 SetEntityBlip(eBlipType type, int32, uint32, eBlipDisplay);
	static int32 SetShortRangeCoordBlip(eBlipType type, CVector pos, uint32, eBlipDisplay);
	static void SetRadarMarkerState(int32 i, bool flag);
	static void ShowRadarMarker(CVector pos, uint32 color, float radius);
	static void ShowRadarTrace(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha);
	static void ShowRadarTraceWithHeight(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha, uint8 mode);
	static void Shutdown();
	static void StreamRadarSections(const CVector &posn);
	static void StreamRadarSections(int32 x, int32 y);
	static void TransformRealWorldToTexCoordSpace(CVector2D &out, const CVector2D &in, int32 x, int32 y);
	static void TransformRadarPointToRealWorldSpace(CVector2D &out, const CVector2D &in);
	static void TransformRadarPointToScreenSpace(CVector2D &out, const CVector2D &in);
	static void TransformRealWorldPointToRadarSpace(CVector2D &out, const CVector2D &in);
	static void CalculateCachedSinCos();
	static void DrawEntityBlip(int32 blipId);
	static void DrawCoordBlip(int32 blipId);
	static void DrawLegend(int32, int32, int32);
};