1 //**************************************************************************
2 //**
3 //**	##   ##    ##    ##   ##   ####     ####   ###     ###
4 //**	##   ##  ##  ##  ##   ##  ##  ##   ##  ##  ####   ####
5 //**	 ## ##  ##    ##  ## ##  ##    ## ##    ## ## ## ## ##
6 //**	 ## ##  ########  ## ##  ##    ## ##    ## ##  ###  ##
7 //**	  ###   ##    ##   ###    ##  ##   ##  ##  ##       ##
8 //**	   #    ##    ##    #      ####     ####   ##       ##
9 //**
10 //**	$Id: p_player.h 4336 2010-09-17 21:54:34Z firebrand_kh $
11 //**
12 //**	Copyright (C) 1999-2006 Jānis Legzdiņš
13 //**
14 //**	This program is free software; you can redistribute it and/or
15 //**  modify it under the terms of the GNU General Public License
16 //**  as published by the Free Software Foundation; either version 2
17 //**  of the License, or (at your option) any later version.
18 //**
19 //**	This program is distributed in the hope that it will be useful,
20 //**  but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //**  GNU General Public License for more details.
23 //**
24 //**************************************************************************
25 
26 // HEADER FILES ------------------------------------------------------------
27 
28 // MACROS ------------------------------------------------------------------
29 
30 // TYPES -------------------------------------------------------------------
31 
32 class VNetConnection;
33 class VClientGameBase;
34 
35 //
36 //	Constants for FixedColourmap
37 //
38 enum
39 {
40 	NUMCOLOURMAPS		= 32,
41 	INVERSECOLOURMAP	= 32,
42 	GOLDCOLOURMAP		= 33,
43 	REDCOLOURMAP		= 34,
44 	GREENCOLOURMAP		= 35,
45 };
46 
47 //
48 // Overlay psprites are scaled shapes
49 // drawn directly on the view screen,
50 // coordinates are given for a 320*200 view screen.
51 //
52 enum psprnum_t
53 {
54 	ps_weapon,
55 	ps_flash,	//	Only DOOM uses it
56 	NUMPSPRITES
57 };
58 
59 //
60 // Player states.
61 //
62 enum playerstate_t
63 {
64 	// Playing or camping.
65 	PST_LIVE,
66 	// Dead on the ground, view follows killer.
67 	PST_DEAD,
68 	// Ready to restart/respawn???
69 	PST_REBORN
70 };
71 
72 //
73 // Button/action code definitions.
74 //
75 enum
76 {
77 	BT_ATTACK		= 1,		// Press "Fire".
78 	BT_USE			= 2,		// Use button, to open doors, activate switches.
79 	BT_JUMP			= 4,
80 	BT_ALT_ATTACK	= 8,
81 };
82 
83 struct VViewState
84 {
85 	VState*			State;
86 	float			StateTime;
87 	float			SX;
88 	float			SY;
89 };
90 
91 //
92 // Extended player object info: player_t
93 //
94 class VBasePlayer : public VGameObject
95 {
96 	DECLARE_CLASS(VBasePlayer, VGameObject, 0)
97 
98 	enum { TOCENTRE = -128 };
99 
100 	VLevelInfo*		Level;
101 
102 	enum
103 	{
104 		PF_Active				= 0x0001,
105 		PF_Spawned				= 0x0002,
106 		PF_IsBot				= 0x0004,
107 		PF_FixAngle				= 0x0008,
108 		PF_AttackDown			= 0x0010,	// True if button down last tic.
109 		PF_UseDown				= 0x0020,
110 		PF_DidSecret			= 0x0040,	// True if secret level has been done.
111 		PF_Centreing			= 0x0080,
112 		PF_IsClient				= 0x0100,	// Player on client side
113 		PF_AutomapRevealed		= 0x0200,
114 		PF_AutomapShowThings	= 0x0400,
115 	};
116 	vuint32			PlayerFlags;
117 
118 	VNetConnection*	Net;
119 
120 	VStr			UserInfo;
121 
122 	VStr			PlayerName;
123 	vuint8			BaseClass;
124 	vuint8			PClass;			// player class type
125 	vuint8			TranslStart;
126 	vuint8			TranslEnd;
127 	vint32			Colour;
128 
129 	float			ClientForwardMove;	// *2048 for move
130 	float			ClientSideMove;		// *2048 for move
131 	float			ForwardMove;	// *2048 for move
132 	float			SideMove;		// *2048 for move
133 	float			FlyMove;		// fly up/down/centreing
134 	vuint8			Buttons;		// fire, use
135 	vuint8			Impulse;		// weapon changes, inventory, etc
136 	//	For ACS
137 	vuint8			OldButtons;
138 	TAVec			OldViewAngles;
139 
140 	VEntity*		MO;
141 	VEntity*		Camera;
142 	vint32			PlayerState;
143 
144 	// Determine POV,
145 	//  including viewpoint bobbing during movement.
146 	// Focal origin above r.z
147 	TVec			ViewOrg;
148 
149 	TAVec			ViewAngles;
150 
151 	// This is only used between levels,
152 	// mo->health is used during levels.
153 	vint32			Health;
154 
155 	// Frags, kills of other players.
156 	vint32			Frags;
157 	vint32			Deaths;
158 
159 	// For intermission stats.
160 	vint32			KillCount;
161 	vint32			ItemCount;
162 	vint32			SecretCount;
163 
164 	// So gun flashes light up areas.
165 	vuint8			ExtraLight;
166 
167 	// For lite-amp and invulnarability powers
168 	vuint8			FixedColourmap;
169 
170 	// Colour shifts for damage, powerups and content types
171 	vuint32			CShift;
172 
173 	// Overlay view sprites (gun, etc).
174 	VViewState		ViewStates[NUMPSPRITES];
175 	float			PSpriteSY;
176 
177 	float			WorldTimer;				// total time the player's been playing
178 
179 	vuint8			ClientNum;
180 
181 	vint32			SoundEnvironment;
182 
183 	VClientGameBase*	ClGame;
184 
185 	VPlayerReplicationInfo*	PlayerReplicationInfo;
186 
VBasePlayer()187 	VBasePlayer()
188 	: UserInfo(E_NoInit)
189 	, PlayerName(E_NoInit)
190 	{}
191 
192 	//	VObject interface
193 	bool ExecuteNetMethod(VMethod*);
194 
195 	void SpawnClient();
196 
197 	void Printf(const char*, ...);
198 	void CentrePrintf(const char*, ...);
199 
200 	void SetViewState(int, VState*);
201 	void AdvanceViewStates(float);
202 
203 	void SetUserInfo(const VStr&);
204 	void ReadFromUserInfo();
205 
206 	//	Handling of player input.
207 	void StartPitchDrift();
208 	void StopPitchDrift();
209 	void AdjustAngles();
210 	void HandleInput();
211 	bool Responder(event_t*);
212 	void ClearInput();
213 	int AcsGetInput(int);
214 
215 	//	Implementation of server to client events.
216 	void DoClientStartSound(int, TVec, int, int, float, float, bool);
217 	void DoClientStopSound(int, int);
218 	void DoClientStartSequence(TVec, int, VName, int);
219 	void DoClientAddSequenceChoice(int, VName);
220 	void DoClientStopSequence(int);
221 	void DoClientPrint(VStr);
222 	void DoClientCentrePrint(VStr);
223 	void DoClientSetAngles(TAVec);
224 	void DoClientIntermission(VName);
225 	void DoClientPause(bool);
226 	void DoClientSkipIntermission();
227 	void DoClientFinale(VStr);
228 	void DoClientChangeMusic(VName, int);
229 	void DoClientSetServerInfo(VStr, VStr);
230 	void DoClientHudMessage(const VStr&, VName, int, int, int, const VStr&,
231 		float, float, int, int, float, float, float);
232 
233 	void WriteViewData();
234 
235 	DECLARE_FUNCTION(cprint)
DECLARE_FUNCTION(centreprint)236 	DECLARE_FUNCTION(centreprint)
237 	DECLARE_FUNCTION(GetPlayerNum)
238 	DECLARE_FUNCTION(ClearPlayer)
239 	DECLARE_FUNCTION(SetViewState)
240 	DECLARE_FUNCTION(AdvanceViewStates)
241 	DECLARE_FUNCTION(DisconnectBot)
242 
243 	DECLARE_FUNCTION(ClientStartSound)
244 	DECLARE_FUNCTION(ClientStopSound)
245 	DECLARE_FUNCTION(ClientStartSequence)
246 	DECLARE_FUNCTION(ClientAddSequenceChoice)
247 	DECLARE_FUNCTION(ClientStopSequence)
248 	DECLARE_FUNCTION(ClientPrint)
249 	DECLARE_FUNCTION(ClientCentrePrint)
250 	DECLARE_FUNCTION(ClientSetAngles)
251 	DECLARE_FUNCTION(ClientIntermission)
252 	DECLARE_FUNCTION(ClientPause)
253 	DECLARE_FUNCTION(ClientSkipIntermission)
254 	DECLARE_FUNCTION(ClientFinale)
255 	DECLARE_FUNCTION(ClientChangeMusic)
256 	DECLARE_FUNCTION(ClientSetServerInfo)
257 	DECLARE_FUNCTION(ClientHudMessage)
258 
259 	DECLARE_FUNCTION(ServerSetUserInfo)
260 
261 	//	Player events.
262 	void eventPutClientIntoServer()
263 	{
264 		P_PASS_SELF;
265 		EV_RET_VOID(NAME_PutClientIntoServer);
266 	}
eventSpawnClient()267 	void eventSpawnClient()
268 	{
269 		P_PASS_SELF;
270 		EV_RET_VOID(NAME_SpawnClient);
271 	}
eventNetGameReborn()272 	void eventNetGameReborn()
273 	{
274 		P_PASS_SELF;
275 		EV_RET_VOID(NAME_NetGameReborn);
276 	}
eventDisconnectClient()277 	void eventDisconnectClient()
278 	{
279 		P_PASS_SELF;
280 		EV_RET_VOID(NAME_DisconnectClient);
281 	}
eventUserinfoChanged()282 	void eventUserinfoChanged()
283 	{
284 		P_PASS_SELF;
285 		EV_RET_VOID(NAME_UserinfoChanged);
286 	}
eventPlayerExitMap(bool clusterChange)287 	void eventPlayerExitMap(bool clusterChange)
288 	{
289 		P_PASS_SELF;
290 		P_PASS_BOOL(clusterChange);
291 		EV_RET_VOID(NAME_PlayerExitMap);
292 	}
eventPlayerTick(float deltaTime)293 	void eventPlayerTick(float deltaTime)
294 	{
295 		P_PASS_SELF;
296 		P_PASS_FLOAT(deltaTime);
297 		EV_RET_VOID(NAME_PlayerTick);
298 	}
eventClientTick(float DeltaTime)299 	void eventClientTick(float DeltaTime)
300 	{
301 		P_PASS_SELF;
302 		P_PASS_FLOAT(DeltaTime);
303 		EV_RET_VOID(NAME_ClientTick);
304 	}
eventSetViewPos()305 	void eventSetViewPos()
306 	{
307 		P_PASS_SELF;
308 		EV_RET_VOID(NAME_SetViewPos);
309 	}
eventPreTravel()310 	void eventPreTravel()
311 	{
312 		P_PASS_SELF;
313 		EV_RET_VOID(NAME_PreTravel);
314 	}
eventUseInventory(VStr Inv)315 	void eventUseInventory(VStr Inv)
316 	{
317 		P_PASS_SELF;
318 		P_PASS_STR(Inv);
319 		EV_RET_VOID(NAME_UseInventory);
320 	}
321 
322 	//	Cheats.
eventCheat_God()323 	void eventCheat_God()
324 	{
325 		P_PASS_SELF;
326 		EV_RET_VOID(NAME_Cheat_God);
327 	}
eventCheat_NoClip()328 	void eventCheat_NoClip()
329 	{
330 		P_PASS_SELF;
331 		EV_RET_VOID(NAME_Cheat_NoClip);
332 	}
eventCheat_Gimme()333 	void eventCheat_Gimme()
334 	{
335 		P_PASS_SELF;
336 		EV_RET_VOID(NAME_Cheat_Gimme);
337 	}
eventCheat_KillAll()338 	void eventCheat_KillAll()
339 	{
340 		P_PASS_SELF;
341 		EV_RET_VOID(NAME_Cheat_KillAll);
342 	}
eventCheat_Morph()343 	void eventCheat_Morph()
344 	{
345 		P_PASS_SELF;
346 		EV_RET_VOID(NAME_Cheat_Morph);
347 	}
eventCheat_NoWeapons()348 	void eventCheat_NoWeapons()
349 	{
350 		P_PASS_SELF;
351 		EV_RET_VOID(NAME_Cheat_NoWeapons);
352 	}
eventCheat_Class()353 	void eventCheat_Class()
354 	{
355 		P_PASS_SELF;
356 		EV_RET_VOID(NAME_Cheat_Class);
357 	}
eventCheat_Fly()358 	void eventCheat_Fly()
359 	{
360 		P_PASS_SELF;
361 		EV_RET_VOID(NAME_Cheat_Fly);
362 	}
eventCheat_NoTarget()363 	void eventCheat_NoTarget()
364 	{
365 		P_PASS_SELF;
366 		EV_RET_VOID(NAME_Cheat_NoTarget);
367 	}
eventCheat_Anubis()368 	void eventCheat_Anubis()
369 	{
370 		P_PASS_SELF;
371 		EV_RET_VOID(NAME_Cheat_Anubis);
372 	}
373 
374 	//	Server to client events.
eventClientStartSound(int SoundId,TVec Org,int OriginId,int Channel,float Volume,float Attenuation,bool Loop)375 	void eventClientStartSound(int SoundId, TVec Org, int OriginId,
376 		int Channel, float Volume, float Attenuation, bool Loop)
377 	{
378 		P_PASS_SELF;
379 		P_PASS_INT(SoundId);
380 		P_PASS_VEC(Org);
381 		P_PASS_INT(OriginId);
382 		P_PASS_INT(Channel);
383 		P_PASS_FLOAT(Volume);
384 		P_PASS_FLOAT(Attenuation);
385 		P_PASS_BOOL(Loop);
386 		EV_RET_VOID(NAME_ClientStartSound);
387 	}
eventClientStopSound(int OriginId,int Channel)388 	void eventClientStopSound(int OriginId, int Channel)
389 	{
390 		P_PASS_SELF;
391 		P_PASS_INT(OriginId);
392 		P_PASS_INT(Channel);
393 		EV_RET_VOID(NAME_ClientStopSound);
394 	}
eventClientStartSequence(TVec Origin,int OriginId,VName Name,int ModeNum)395 	void eventClientStartSequence(TVec Origin, int OriginId, VName Name,
396 		int ModeNum)
397 	{
398 		P_PASS_SELF;
399 		P_PASS_VEC(Origin);
400 		P_PASS_INT(OriginId);
401 		P_PASS_NAME(Name);
402 		P_PASS_INT(ModeNum);
403 		EV_RET_VOID(NAME_ClientStartSequence);
404 	}
eventClientAddSequenceChoice(int OriginId,VName Choice)405 	void eventClientAddSequenceChoice(int OriginId, VName Choice)
406 	{
407 		P_PASS_SELF;
408 		P_PASS_INT(OriginId);
409 		P_PASS_NAME(Choice);
410 		EV_RET_VOID(NAME_ClientAddSequenceChoice);
411 	}
eventClientStopSequence(int OriginId)412 	void eventClientStopSequence(int OriginId)
413 	{
414 		P_PASS_SELF;
415 		P_PASS_INT(OriginId);
416 		EV_RET_VOID(NAME_ClientStopSequence);
417 	}
eventClientPrint(VStr Str)418 	void eventClientPrint(VStr Str)
419 	{
420 		P_PASS_SELF;
421 		P_PASS_STR(Str);
422 		EV_RET_VOID(NAME_ClientPrint);
423 	}
eventClientCentrePrint(VStr Str)424 	void eventClientCentrePrint(VStr Str)
425 	{
426 		P_PASS_SELF;
427 		P_PASS_STR(Str);
428 		EV_RET_VOID(NAME_ClientCentrePrint);
429 	}
eventClientSetAngles(TAVec Angles)430 	void eventClientSetAngles(TAVec Angles)
431 	{
432 		P_PASS_SELF;
433 		P_PASS_AVEC(Angles);
434 		EV_RET_VOID(NAME_ClientSetAngles);
435 	}
eventClientIntermission(VName NextMap)436 	void eventClientIntermission(VName NextMap)
437 	{
438 		P_PASS_SELF;
439 		P_PASS_NAME(NextMap);
440 		EV_RET_VOID(NAME_ClientIntermission);
441 	}
eventClientPause(bool Paused)442 	void eventClientPause(bool Paused)
443 	{
444 		P_PASS_SELF;
445 		P_PASS_BOOL(Paused);
446 		EV_RET_VOID(NAME_ClientPause);
447 	}
eventClientSkipIntermission()448 	void eventClientSkipIntermission()
449 	{
450 		P_PASS_SELF;
451 		EV_RET_VOID(NAME_ClientSkipIntermission);
452 	}
eventClientFinale(VStr Type)453 	void eventClientFinale(VStr Type)
454 	{
455 		P_PASS_SELF;
456 		P_PASS_STR(Type);
457 		EV_RET_VOID(NAME_ClientFinale);
458 	}
eventClientChangeMusic(VName Song,int CDTrack)459 	void eventClientChangeMusic(VName Song, int CDTrack)
460 	{
461 		P_PASS_SELF;
462 		P_PASS_NAME(Song);
463 		P_PASS_INT(CDTrack);
464 		EV_RET_VOID(NAME_ClientChangeMusic);
465 	}
eventClientSetServerInfo(VStr Key,VStr Value)466 	void eventClientSetServerInfo(VStr Key, VStr Value)
467 	{
468 		P_PASS_SELF;
469 		P_PASS_STR(Key);
470 		P_PASS_STR(Value);
471 		EV_RET_VOID(NAME_ClientSetServerInfo);
472 	}
eventClientHudMessage(const VStr & Message,VName Font,int Type,int Id,int Colour,const VStr & ColourName,float x,float y,int HudWidth,int HudHeight,float HoldTime,float Time1,float Time2)473 	void eventClientHudMessage(const VStr& Message, VName Font, int Type,
474 		int Id, int Colour, const VStr& ColourName, float x, float y,
475 		int HudWidth, int HudHeight, float HoldTime, float Time1, float Time2)
476 	{
477 		P_PASS_SELF;
478 		P_PASS_STR(Message);
479 		P_PASS_NAME(Font);
480 		P_PASS_INT(Type);
481 		P_PASS_INT(Id);
482 		P_PASS_INT(Colour);
483 		P_PASS_STR(ColourName);
484 		P_PASS_FLOAT(x);
485 		P_PASS_FLOAT(y);
486 		P_PASS_INT(HudWidth);
487 		P_PASS_INT(HudHeight);
488 		P_PASS_FLOAT(HoldTime);
489 		P_PASS_FLOAT(Time1);
490 		P_PASS_FLOAT(Time2);
491 		EV_RET_VOID(NAME_ClientHudMessage);
492 	}
493 
494 	//	Client to server events.
eventServerImpulse(int AImpulse)495 	void eventServerImpulse(int AImpulse)
496 	{
497 		P_PASS_SELF;
498 		P_PASS_INT(AImpulse);
499 		EV_RET_VOID(NAME_ServerImpulse);
500 	}
eventServerSetUserInfo(VStr Info)501 	void eventServerSetUserInfo(VStr Info)
502 	{
503 		P_PASS_SELF;
504 		P_PASS_STR(Info);
505 		EV_RET_VOID(NAME_ServerSetUserInfo);
506 	}
507 };
508 
509 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
510 
511 // PUBLIC DATA DECLARATIONS ------------------------------------------------
512