1 /*
2 	C-Dogs SDL
3 	A port of the legendary (and fun) action/arcade cdogs.
4 	Copyright (c) 2014-2016, 2018-2020 Cong Xu
5 	All rights reserved.
6 
7 	Redistribution and use in source and binary forms, with or without
8 	modification, are permitted provided that the following conditions are met:
9 
10 	Redistributions of source code must retain the above copyright notice, this
11 	list of conditions and the following disclaimer.
12 	Redistributions in binary form must reproduce the above copyright notice,
13 	this list of conditions and the following disclaimer in the documentation
14 	and/or other materials provided with the distribution.
15 
16 	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 	POSSIBILITY OF SUCH DAMAGE.
27 */
28 #pragma once
29 
30 #include "character.h"
31 
32 #define MAX_GUNS 2
33 #define MAX_GRENADES 1
34 #define MAX_WEAPONS (MAX_GUNS + MAX_GRENADES)
35 // TODO: track accuracy
36 // this requires sending the bullet type with the ActorHit event,
37 // since we want to exclude melee and explosives from accuracy calcuation
38 typedef struct
39 {
40 	int ActorUID; // -1 if dead
41 	bool IsLocal; // whether this is a local-machine player
42 	// Whether this player is ready to start, for remote players
43 	bool Ready;
44 	Character Char;
45 	char name[20];
46 	const WeaponClass *guns[MAX_WEAPONS];
47 	CArray ammo; // of int
48 	int Lives;
49 
50 	NPlayerStats Stats;
51 	NPlayerStats Totals;
52 
53 	// Used for end-of-game score tallying
54 	int survived;
55 	int hp;
56 	int missions;
57 	int lastMission;
58 	int allTime, today;
59 
60 	input_device_e inputDevice;
61 	int deviceIndex;
62 	int UID;
63 } PlayerData;
64 
65 extern CArray gPlayerDatas; // of PlayerData
66 
67 #define MAX_LOCAL_PLAYERS 4
68 
69 void PlayerDataInit(CArray *p);
70 void PlayerDataAddOrUpdate(const NPlayerData pd);
71 void PlayerRemove(const int uid);
72 NPlayerData PlayerDataDefault(const int idx);
73 NPlayerData PlayerDataMissionReset(const PlayerData *p);
74 void PlayerDataTerminate(CArray *p);
75 
76 PlayerData *PlayerDataGetByUID(const int uid);
77 int FindLocalPlayerIndex(const int uid);
78 
79 typedef enum
80 {
81 	PLAYER_ANY,
82 	PLAYER_ALIVE,
83 	PLAYER_ALIVE_OR_DYING
84 } PlayerAliveOptions;
85 int GetNumPlayers(
86 	const PlayerAliveOptions alive, const bool human, const bool local);
87 bool AreAllPlayersDeadAndNoLives(void);
88 const PlayerData *GetFirstPlayer(
89 	const bool alive, const bool human, const bool local);
90 bool IsPlayerAlive(const PlayerData *player);
91 bool IsPlayerHuman(const PlayerData *player);
92 bool IsPlayerHumanAndAlive(const PlayerData *player);
93 bool IsPlayerAliveOrDying(const PlayerData *player);
94 bool IsPlayerScreen(const PlayerData *p);
95 struct vec2 PlayersGetMidpoint(void);
96 void PlayersGetBoundingRectangle(struct vec2 *min, struct vec2 *max);
97 int PlayersNumUseAmmo(const int ammoId);
98 bool PlayerIsLocal(const int uid);
99 
100 void PlayerScore(PlayerData *p, const int points);
101 // Return false if player already assigned this input device
102 bool PlayerTrySetInputDevice(
103 	PlayerData *p, const input_device_e d, const int idx);
104 // Return false if player already assigned a device,
105 // or this device/index is already used by another player
106 bool PlayerTrySetUnusedInputDevice(
107 	PlayerData *p, const input_device_e d, const int idx);
108 
109 int PlayerGetNumWeapons(const PlayerData *p);
110 bool PlayerHasGrenadeButton(const PlayerData *p);
111