Debian Codegraph @

src/cdogs/player.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (c) 2014-2016, 2018-2020, 2022-2023, 2025 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 #include "weapon_usage.h"
32
33 #define MAX_GUNS 3
34 #define MELEE_SLOT 2
35 #define GRENADE_SLOT 3
36 #define MAX_GRENADES 1
37 #define MAX_WEAPONS (MAX_GUNS + MAX_GRENADES)
38 // TODO: track accuracy
39 // this requires sending the bullet type with the ActorHit event,
40 // since we want to exclude melee and explosives from accuracy calcuation
41 typedef struct
42 {
43 int ActorUID; // -1 if dead
44 bool IsLocal; // whether this is a local-machine player
45 // Whether this player is ready to start, for remote players
46 bool Ready;
47 Character Char;
48 char name[20];
49 const WeaponClass *guns[MAX_WEAPONS];
50 CArray ammo; // of int
51 int Lives;
52 int HP;
53
54 NPlayerStats Stats;
55 NPlayerStats Totals;
56 WeaponUsages WeaponUsages;
57
58 // Used for end-of-game score tallying
59 int hp;
60 int survived;
61 int missions;
62 int lastMission;
63
64 input_device_e inputDevice;
65 int deviceIndex;
66 int UID;
67 } PlayerData;
68
69 extern CArray gPlayerDatas; // of PlayerData
70
71 #define MAX_LOCAL_PLAYERS 4
72
73 void PlayerDataInit(CArray *p);
74 void PlayerDataAddOrUpdate(const NPlayerData pd);
75 void PlayerRemove(const int uid);
76 NPlayerData PlayerDataDefault(const int idx);
77 NPlayerData PlayerDataMissionReset(const PlayerData *p);
78 void PlayerDataTerminate(CArray *p);
79
80 PlayerData *PlayerDataGetByUID(const int uid);
81 int FindLocalPlayerIndex(const int uid);
82
83 typedef enum
84 {
85 PLAYER_ANY,
86 PLAYER_ALIVE,
87 PLAYER_ALIVE_OR_DYING
88 } PlayerAliveOptions;
89 int GetNumPlayers(
90 const PlayerAliveOptions alive, const bool human, const bool local);
91 bool AreAllPlayersDeadAndNoLives(void);
92 const PlayerData *GetFirstPlayer(
93 const bool alive, const bool human, const bool local);
94 bool IsPlayerAlive(const PlayerData *player);
95 bool IsPlayerHuman(const PlayerData *player);
96 bool IsPlayerHumanAndAlive(const PlayerData *player);
97 bool IsPlayerAliveOrDying(const PlayerData *player);
98 bool IsPlayerScreen(const PlayerData *p);
99 struct vec2 PlayersGetMidpoint(void);
100 void PlayersGetBoundingRectangle(struct vec2 *min, struct vec2 *max);
101 int PlayersNumUseAmmo(const int ammoId);
102 bool PlayerIsLocal(const int uid);
103
104 void PlayerScore(PlayerData *p, const int points);
105 // Return false if player already assigned this input device
106 bool PlayerTrySetInputDevice(
107 PlayerData *p, const input_device_e d, const int idx);
108 // Return false if player already assigned a device,
109 // or this device/index is already used by another player
110 bool PlayerTrySetUnusedInputDevice(
111 PlayerData *p, const input_device_e d, const int idx);
112
113 int PlayerGetNumWeapons(const PlayerData *p);
114 bool PlayerHasGrenadeButton(const PlayerData *p);
115 bool PlayerHasWeapon(const PlayerData *p, const WeaponClass *wc);
116 bool PlayerHasWeaponUpgrade(const PlayerData *p, const WeaponClass *wc);
117 void PlayerAddWeapon(PlayerData *p, const WeaponClass *wc);
118 void PlayerAddWeaponToSlot(
119 PlayerData *p, const WeaponClass *wc, const int slot);
120 void PlayerRemoveWeapon(PlayerData *p, const int slot);
121 void PlayerAddMinimalWeapons(PlayerData *p);
122 bool PlayerUsesAmmo(const PlayerData *p, const int ammoId);
123 bool PlayerUsesAnyAmmo(const PlayerData *p);
124 int PlayerGetAmmoAmount(const PlayerData *p, const int ammoId);
125 void PlayerAddAmmo(
126 PlayerData *p, const int ammoId, const int amount, const bool isFree);
127 void PlayerSetHP(PlayerData *p, const int hp);
128 void PlayerSetLives(PlayerData *p, const int lives);
129
130 int CharacterGetStartingHealth(const Character *c, const PlayerData *p);