1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010 EDuke32 developers and contributors
4
5 This file is part of EDuke32.
6
7 EDuke32 is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License version 2
9 as published by the Free Software Foundation.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 //-------------------------------------------------------------------------
22
23 #ifndef player_h_
24 #define player_h_
25
26 #include "build.h"
27 #include "inv.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 extern int32_t g_mostConcurrentPlayers;
34
35 #define MOVEFIFOSIZ 2
36
37 #define NAM_GRENADE_LIFETIME 120
38 #define NAM_GRENADE_LIFETIME_VAR 30
39
40 #define HORIZ_MIN (-99)
41 #define HORIZ_MAX 299
42 #define AUTO_AIM_ANGLE 48
43 #define PHEIGHT (38<<8)
44 #define PCROUCHHEIGHT (16<<8)
45 #define PCROUCHINCREMENT (2048+768)
46 #define PMINHEIGHT 1024 // this is NOT the value I wanted here, but Duke It Out in DC's shitty vents said otherwise
47
48 #define PCRACKTIME 777
49
50 #define PWATERSPEEDMODIFIER 0x1400
51 #define PCROUCHSPEEDMODIFIER 0x2000
52
53 #define TRIPBOMB_TRIPWIRE 0x00000001
54 #define TRIPBOMB_TIMER 0x00000002
55
56 #define PIPEBOMB_REMOTE 0x00000001
57 #define PIPEBOMB_TIMER 0x00000002
58
59 #define WEAPON_POS_LOWER (-9)
60 #define WEAPON_POS_RAISE 10
61 #define WEAPON_POS_START 6
62
63 enum weaponflags_t {
64 WEAPON_SPAWNTYPE1 = 0x00000000, // just spawn
65 WEAPON_HOLSTER_CLEARS_CLIP = 0x00000001, // 'holstering' clears the current clip
66 WEAPON_GLOWS = 0x00000002, // weapon 'glows' (shrinker and grower)
67 WEAPON_AUTOMATIC = 0x00000004, // automatic fire (continues while 'fire' is held down
68 WEAPON_FIREEVERYOTHER = 0x00000008, // during 'hold time' fire every frame
69 WEAPON_FIREEVERYTHIRD = 0x00000010, // during 'hold time' fire every third frame
70 WEAPON_RANDOMRESTART = 0x00000020, // restart for automatic is 'randomized' by RND 3
71 WEAPON_AMMOPERSHOT = 0x00000040, // uses ammo for each shot (for automatic)
72 WEAPON_BOMB_TRIGGER = 0x00000080, // weapon is the 'bomb' trigger
73 WEAPON_NOVISIBLE = 0x00000100, // weapon use does not cause user to become 'visible'
74 WEAPON_THROWIT = 0x00000200, // weapon 'throws' the 'shoots' item...
75 WEAPON_CHECKATRELOAD = 0x00000400, // check weapon availability at 'reload' time
76 WEAPON_STANDSTILL = 0x00000800, // player stops jumping before actual fire (like tripbomb in duke)
77 WEAPON_SPAWNTYPE2 = 0x00001000, // spawn like shotgun shells
78 WEAPON_SPAWNTYPE3 = 0x00002000, // spawn like chaingun shells
79 WEAPON_SEMIAUTO = 0x00004000, // cancel button press after each shot
80 WEAPON_RELOAD_TIMING = 0x00008000, // special casing for pistol reload sounds
81 WEAPON_RESET = 0x00010000 // cycle weapon back to frame 1 if fire is held, 0 if not
82 };
83
84 enum gamemode_t {
85 MODE_MENU = 0x00000001,
86 MODE_DEMO = 0x00000002,
87 MODE_GAME = 0x00000004,
88 MODE_EOL = 0x00000008,
89 MODE_TYPE = 0x00000010,
90 MODE_RESTART = 0x00000020,
91 MODE_SENDTOWHOM = 0x00000040,
92 };
93
94 // Player Actions.
95 enum playeraction_t {
96 pstanding = 0x00000001,
97 pwalking = 0x00000002,
98 prunning = 0x00000004,
99 pducking = 0x00000008,
100 pfalling = 0x00000010,
101 pjumping = 0x00000020,
102 phigher = 0x00000040,
103 pwalkingback = 0x00000080,
104 prunningback = 0x00000100,
105 pkicking = 0x00000200,
106 pshrunk = 0x00000400,
107 pjetpack = 0x00000800,
108 ponsteroids = 0x00001000,
109 ponground = 0x00002000,
110 palive = 0x00004000,
111 pdead = 0x00008000,
112 pfacing = 0x00010000
113 };
114
115 typedef struct {
116 vec3_t pos;
117 int16_t ang, sect;
118 } playerspawn_t;
119
120 typedef struct {
121 int16_t got_access, last_extra, inv_amount[GET_MAX], curr_weapon, holoduke_on;
122 int16_t last_weapon, weapon_pos, kickback_pic;
123 int16_t ammo_amount[MAX_WEAPONS];
124 uint16_t frag[MAXPLAYERS];
125 uint16_t gotweapon;
126 char inven_icon, jetpack_on, heat_on;
127 } DukeStatus_t;
128
129 typedef struct {
130 uint32_t bits;
131 int16_t fvel, svel;
132 fix16_t q16avel, q16horz;
133 uint8_t extbits;
134 } input_t;
135
136 #pragma pack(push,1)
137 // XXX: r1625 changed a lot types here, among others
138 // * int32_t --> int16_t
139 // * int16_t --> int8_t
140 // * char --> int8_t
141 // Need to carefully think about implications!
142 // TODO: rearrange this if the opportunity arises!
143 typedef struct {
144 vec3_t pos, opos;
145 vec3_t vel, npos;
146 vec2_t bobpos, fric;
147
148 fix16_t q16horiz, q16horizoff, oq16horiz, oq16horizoff;
149 fix16_t q16ang, oq16ang, q16angvel;
150
151 int32_t truefz, truecz, player_par;
152 int32_t runspeed, max_player_health, max_shield_amount;
153 int32_t autostep, autostep_sbw;
154
155 uint32_t interface_toggle;
156
157 palette_t pals;
158
159 uint16_t max_actors_killed, actors_killed;
160 uint16_t gotweapon, zoom;
161
162 uint16_t frag, fraggedself;
163
164 int16_t loogiex[64], loogiey[64], sbs, sound_pitch;
165
166 int16_t cursectnum, look_ang, last_extra, subweapon;
167 int16_t max_ammo_amount[MAX_WEAPONS], ammo_amount[MAX_WEAPONS], inv_amount[GET_MAX];
168 int16_t wackedbyactor, pyoff, opyoff;
169
170 int16_t newowner, jumping_counter, airleft;
171 int16_t fta, ftq, access_wallnum, access_spritenum;
172 int16_t got_access, weapon_ang, visibility;
173 int16_t somethingonplayer, on_crane, i, parallax_sectnum;
174 int16_t random_club_frame, one_eighty_count;
175 int16_t dummyplayersprite, extra_extra8;
176 int16_t actorsqu, timebeforeexit, customexitsound, last_pissed_time;
177
178 int16_t weaprecs[MAX_WEAPONS], weapon_sway, crack_time, bobcounter;
179
180 int16_t orotscrnang, rotscrnang, dead_flag; // JBF 20031220: added orotscrnang
181 int16_t holoduke_on, pycount;
182 int16_t transporter_hold, clipdist;
183
184 uint8_t max_secret_rooms, secret_rooms;
185 uint8_t quick_kick, last_quick_kick;
186 uint8_t return_to_center, reloading, weapreccnt;
187 uint8_t aim_mode, auto_aim, weaponswitch, movement_lock, team;
188 uint8_t tipincs, hbomb_hold_delay, frag_ps, kickback_pic;
189
190 uint8_t gm, on_warping_sector, footprintcount, hurt_delay;
191 uint8_t hbomb_on, jumping_toggle, rapid_fire_hold, on_ground;
192 uint8_t inven_icon, buttonpalette, over_shoulder_on, show_empty_weapon;
193
194 uint8_t jetpack_on, spritebridge;
195 uint8_t scuba_on, footprintpal, heat_on, invdisptime;
196
197 uint8_t holster_weapon, falling_counter, footprintshade;
198 uint8_t last_full_weapon;
199
200 uint8_t toggle_key_flag, knuckle_incs, knee_incs, access_incs;
201 uint8_t walking_snd_toggle, palookup, hard_landing, fist_incs;
202
203 int8_t numloogs, loogcnt, scream_voice;
204 int8_t last_weapon, cheat_phase, weapon_pos, wantweaponfire, curr_weapon;
205
206 uint8_t palette;
207 int8_t last_used_weapon;
208
209 int8_t crouch_toggle;
210 int8_t padding_[1];
211 } DukePlayer_t;
212
213 EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t) % 4 == 0);
214
215 typedef struct
216 {
217 DukePlayer_t *ps;
218 input_t input;
219
220 int horizRecenter;
221 int horizAngleAdjust;
222 int horizSkew;
223
224 int32_t netsynctime;
225 int32_t pcolor, pteam;
226 int16_t ping;
227 // NOTE: wchoice[HANDREMOTE_WEAPON .. MAX_WEAPONS-1] unused
228 uint8_t frags[MAXPLAYERS], wchoice[MAX_WEAPONS];
229
230 char smoothcamera;
231 char vote, gotvote, pingcnt, playerquitflag,
232 ready; // currently unused. May be used later to indicate that a player has pressed use on intermission to indicate they are ready to go on to the next map
233 char user_name[32];
234 uint32_t revision;
235 } playerdata_t;
236 #pragma pack(pop)
237
238 typedef struct
239 {
240 // NOTE: the member names must be identical to aplWeapon* suffixes.
241 int32_t WorksLike; // What the original works like
242 int32_t Clip; // number of items in magazine
243 int32_t Reload; // delay to reload (include fire)
244 int32_t FireDelay; // delay to fire
245 int32_t TotalTime; // The total time the weapon is cycling before next fire.
246 int32_t HoldDelay; // delay after release fire button to fire (0 for none)
247 int32_t Flags; // Flags for weapon
248 int32_t Shoots; // what the weapon shoots
249 int32_t SpawnTime; // the frame at which to spawn an item
250 int32_t Spawn; // the item to spawn
251 int32_t ShotsPerBurst; // number of shots per 'burst' (one ammo per 'burst')
252 int32_t InitialSound; // Sound made when weapon starts firing. zero for no sound
253 int32_t FireSound; // Sound made when firing (each time for automatic)
254 int32_t Sound2Time; // Alternate sound time
255 int32_t Sound2Sound; // Alternate sound sound ID
256 int32_t ReloadSound1; // Sound of magazine being removed
257 int32_t ReloadSound2; // Sound of magazine being inserted
258 int32_t SelectSound; // Sound of weapon being selected
259 int32_t FlashColor; // Muzzle flash color
260 } weapondata_t;
261
262 #define PWEAPON(Player, Weapon, Wmember) (aplWeapon ## Wmember [Weapon][Player])
263 extern intptr_t *aplWeaponClip[MAX_WEAPONS]; // number of items in clip
264 extern intptr_t *aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire)
265 extern intptr_t *aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire
266 extern intptr_t *aplWeaponHoldDelay[MAX_WEAPONS]; // delay after release fire button to fire (0 for none)
267 extern intptr_t *aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire.
268 extern intptr_t *aplWeaponFlags[MAX_WEAPONS]; // Flags for weapon
269 extern intptr_t *aplWeaponShoots[MAX_WEAPONS]; // what the weapon shoots
270 extern intptr_t *aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn an item
271 extern intptr_t *aplWeaponSpawn[MAX_WEAPONS]; // the item to spawn
272 extern intptr_t *aplWeaponShotsPerBurst[MAX_WEAPONS]; // number of shots per 'burst' (one ammo per 'burst'
273 extern intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like
274 extern intptr_t *aplWeaponInitialSound[MAX_WEAPONS]; // Sound made when initialy firing. zero for no sound
275 extern intptr_t *aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for automatic)
276 extern intptr_t *aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time
277 extern intptr_t *aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID
278 extern intptr_t *aplWeaponReloadSound1[MAX_WEAPONS]; // Sound of magazine being removed
279 extern intptr_t *aplWeaponReloadSound2[MAX_WEAPONS]; // Sound of magazine being inserted
280 extern intptr_t *aplWeaponSelectSound[MAX_WEAPONS]; // Sound for weapon selection
281 extern intptr_t *aplWeaponFlashColor[MAX_WEAPONS]; // Color for polymer muzzle flash
282
283 typedef struct {
284 int32_t workslike, cstat; // 8b
285 int32_t hitradius, range, flashcolor; // 12b
286 int16_t spawns, sound, isound, vel; // 8b
287 int16_t decal, trail, tnum, drop; // 8b
288 int16_t offset, bounces, bsound; // 6b
289 int16_t toffset; // 2b
290 int16_t extra, extra_rand; // 4b
291 int8_t sxrepeat, syrepeat, txrepeat, tyrepeat; // 4b
292 int8_t shade, xrepeat, yrepeat, pal; // 4b
293 int8_t movecnt; // 1b
294 uint8_t clipdist; // 1b
295 int8_t filler[2]; // 2b
296 int32_t userdata; // 4b
297 } projectile_t;
298
299 typedef struct {
300 int32_t cur, count; // "cur" is the only member that is *used*
301 int32_t gunposx, lookhalfang; // weapon_xoffset, ps->look_ang>>1
302 int32_t gunposy, lookhoriz; // gun_pos, looking_arc
303 int32_t shade;
304 } hudweapon_t;
305
306 extern input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS];
307 extern playerspawn_t g_playerSpawnPoints[MAXPLAYERS];
308 extern playerdata_t *const g_player;
309 extern int16_t WeaponPickupSprites[MAX_WEAPONS];
310 extern hudweapon_t hudweap;
311 extern int32_t g_levelTextTime;
312 extern int32_t g_myAimMode;
313 extern int32_t g_numObituaries;
314 extern int32_t g_numSelfObituaries;
315 extern int32_t mouseyaxismode;
316 extern int32_t ticrandomseed;
317 extern double g_lastInputTicks;
318
319 #define SHOOT_HARDCODED_ZVEL INT32_MIN
320
321 int A_ShootWithZvel(int spriteNum, int projecTile, int forceZvel);
A_Shoot(int spriteNum,int projecTile)322 static inline int A_Shoot(int spriteNum, int projecTile)
323 {
324 return A_ShootWithZvel(spriteNum, projecTile, SHOOT_HARDCODED_ZVEL);
325 }
326
P_PalFrom(DukePlayer_t * pPlayer,uint8_t f,uint8_t r,uint8_t g,uint8_t b)327 static inline void P_PalFrom(DukePlayer_t *pPlayer, uint8_t f, uint8_t r, uint8_t g, uint8_t b)
328 {
329 pPlayer->pals.f = f;
330 pPlayer->pals.r = r;
331 pPlayer->pals.g = g;
332 pPlayer->pals.b = b;
333 }
334
335 void P_AddKills(DukePlayer_t * pPlayer, uint16_t kills);
336 int32_t A_GetHitscanRange(int spriteNum);
337 void P_GetInput(int playerNum);
338 void P_AddAmmo(DukePlayer_t * pPlayer, int weaponNum, int addAmount);
339 void P_AddWeapon(DukePlayer_t *pPlayer, int weaponNum, int switchWeapon);
340 void P_CheckWeapon(DukePlayer_t *pPlayer);
341 void P_DisplayScuba(void);
342 void P_DisplayWeapon(void);
343 void P_DropWeapon(int playerNum);
344 int P_FindOtherPlayer(int playerNum, int32_t *pDist);
345 void P_FragPlayer(int playerNum);
346 void P_UpdatePosWhenViewingCam(DukePlayer_t *pPlayer);
347 void P_ProcessInput(int playerNum);
348 void P_QuickKill(DukePlayer_t *pPlayer);
349 void P_SelectNextInvItem(DukePlayer_t *pPlayer);
350 void P_UpdateScreenPal(DukePlayer_t *pPlayer);
351 void P_EndLevel(void);
352 int P_GetHudPal(const DukePlayer_t *pPlayer);
353 int P_GetKneePal(const DukePlayer_t *pPlayer);
354 #ifdef __cplusplus
355 }
356 int P_GetKneePal(const DukePlayer_t *pPlayer, int hudPal);
357 extern "C" {
358 #endif
359 int P_GetOverheadPal(const DukePlayer_t *pPlayer);
360
361 int Proj_GetDamage(projectile_t const *pProj);
362
363 void P_SetWeaponGamevars(int playerNum, const DukePlayer_t *pPlayer);
364
365 // Get the player index given an APLAYER sprite pointer.
P_GetP(const void * pSprite)366 static inline int P_GetP(const void *pSprite)
367 {
368 #if 0 // unprotected player index retrieval
369 return spr->yvel;
370 #elif defined NETCODE_DISABLE
371 UNREFERENCED_PARAMETER(pSprite); // for NDEBUG build
372 // NOTE: In the no-netcode build, there's no point to pass player indices
373 // at all since there is ever only one player. However, merely returning 0
374 // would mean making this build less strict than the normal one.
375 Bassert(((uspriteptr_t)pSprite)->yvel == 0);
376 return 0;
377 #else
378 int playerNum = ((uspriteptr_t)pSprite)->yvel;
379 // [JM] Check against MAXPLAYERS as opposed to g_mostConcurrentPlayers
380 // to prevent CON for disconnected/fake players from executing as playernum 0.
381 if ((unsigned)playerNum >= MAXPLAYERS)
382 playerNum = 0;
383 return playerNum;
384 #endif
385 }
386
387 // Get the player index given an APLAYER sprite index.
P_Get(int32_t spriteNum)388 static inline int P_Get(int32_t spriteNum) { return P_GetP((uspriteptr_t)&sprite[spriteNum]); }
389
390 #ifdef __cplusplus
391 }
392 #endif
393
394 extern int portableBackupSave(const char *, const char *, int, int);
395
396 #endif
397