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 "inv.h"
27 #include "namesdyn.h"
28 #include "fix16.h"
29 #include "net.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 extern int32_t g_mostConcurrentPlayers;
36
37 #define MOVEFIFOSIZ 256
38
39 #define NAM_GRENADE_LIFETIME 120
40 #define NAM_GRENADE_LIFETIME_VAR 30
41
42 #define HORIZ_MIN -99
43 #define HORIZ_MAX 299
44 #define AUTO_AIM_ANGLE 48
45 #define PHEIGHT_DUKE (38<<8)
46 #define PHEIGHT_RR (40<<8);
47 extern int32_t PHEIGHT;
48
49 #define TRIPBOMB_TRIPWIRE 0x00000001
50 #define TRIPBOMB_TIMER 0x00000002
51
52 #define PIPEBOMB_REMOTE 0x00000001
53 #define PIPEBOMB_TIMER 0x00000002
54
55 #define WEAPON_POS_LOWER -9
56 #define WEAPON_POS_RAISE 10
57 #define WEAPON_POS_START 6
58
59 #define MAX_WEAPON_RECS 256
60
61 enum weaponflags_t {
62 WEAPON_SPAWNTYPE1 = 0x00000000, // just spawn
63 WEAPON_HOLSTER_CLEARS_CLIP = 0x00000001, // 'holstering' clears the current clip
64 WEAPON_GLOWS = 0x00000002, // weapon 'glows' (shrinker and grower)
65 WEAPON_AUTOMATIC = 0x00000004, // automatic fire (continues while 'fire' is held down
66 WEAPON_FIREEVERYOTHER = 0x00000008, // during 'hold time' fire every frame
67 WEAPON_FIREEVERYTHIRD = 0x00000010, // during 'hold time' fire every third frame
68 WEAPON_RANDOMRESTART = 0x00000020, // restart for automatic is 'randomized' by RND 3
69 WEAPON_AMMOPERSHOT = 0x00000040, // uses ammo for each shot (for automatic)
70 WEAPON_BOMB_TRIGGER = 0x00000080, // weapon is the 'bomb' trigger
71 WEAPON_NOVISIBLE = 0x00000100, // weapon use does not cause user to become 'visible'
72 WEAPON_THROWIT = 0x00000200, // weapon 'throws' the 'shoots' item...
73 WEAPON_CHECKATRELOAD = 0x00000400, // check weapon availability at 'reload' time
74 WEAPON_STANDSTILL = 0x00000800, // player stops jumping before actual fire (like tripbomb in duke)
75 WEAPON_SPAWNTYPE2 = 0x00001000, // spawn like shotgun shells
76 WEAPON_SPAWNTYPE3 = 0x00002000, // spawn like chaingun shells
77 };
78
79 enum gamemode_t {
80 MODE_MENU = 0x00000001,
81 MODE_DEMO = 0x00000002,
82 MODE_GAME = 0x00000004,
83 MODE_EOL = 0x00000008,
84 MODE_TYPE = 0x00000010,
85 MODE_RESTART = 0x00000020,
86 MODE_SENDTOWHOM = 0x00000040,
87 };
88
89 // Player Actions.
90 enum playeraction_t {
91 pstanding = 0x00000001,
92 pwalking = 0x00000002,
93 prunning = 0x00000004,
94 pducking = 0x00000008,
95 pfalling = 0x00000010,
96 pjumping = 0x00000020,
97 phigher = 0x00000040,
98 pwalkingback = 0x00000080,
99 prunningback = 0x00000100,
100 pkicking = 0x00000200,
101 pshrunk = 0x00000400,
102 pjetpack = 0x00000800,
103 ponsteroids = 0x00001000,
104 ponground = 0x00002000,
105 palive = 0x00004000,
106 pdead = 0x00008000,
107 pfacing = 0x00010000
108 };
109
110 typedef struct {
111 vec3_t pos;
112 int16_t ang, sect;
113 } playerspawn_t;
114
115 typedef struct {
116 int16_t got_access, last_extra, inv_amount[GET_MAX], curr_weapon, holoduke_on;
117 int16_t last_weapon, weapon_pos, kickback_pic;
118 int16_t ammo_amount[MAX_WEAPONS], frag[MAXPLAYERS];
119 uint32_t gotweapon;
120 char inven_icon, jetpack_on, heat_on;
121 } DukeStatus_t;
122
123 typedef struct {
124 uint32_t bits;
125 int16_t fvel, svel;
126 fix16_t q16avel, q16horz;
127 int8_t extbits;
128 } input_t;
129
130 #pragma pack(push,1)
131 // XXX: r1625 changed a lot types here, among others
132 // * int32_t --> int16_t
133 // * int16_t --> int8_t
134 // * char --> int8_t
135 // Need to carefully think about implications!
136 // TODO: rearrange this if the opportunity arises!
137 // KEEPINSYNC lunatic/_defs_game.lua
138 typedef struct {
139 vec3_t pos, opos, vel, npos;
140 vec2_t bobpos, fric;
141
142 fix16_t q16horiz, q16horizoff, oq16horiz, oq16horizoff;
143 fix16_t q16ang, oq16ang, q16angvel;
144
145 int32_t truefz, truecz, player_par;
146 int32_t randomflamex, exitx, exity;
147 int32_t runspeed, max_player_health, max_shield_amount;
148 int32_t autostep, autostep_sbw;
149
150 int32_t interface_toggle_flag;
151 uint16_t max_actors_killed, actors_killed;
152 uint32_t gotweapon;
153 uint16_t zoom;
154
155 int16_t loogiex[64], loogiey[64], sbs, sound_pitch;
156
157 int16_t cursectnum, look_ang, last_extra, subweapon;
158 int16_t max_ammo_amount[MAX_WEAPONS], ammo_amount[MAX_WEAPONS], inv_amount[GET_MAX];
159 int16_t wackedbyactor, pyoff, opyoff;
160
161 int16_t newowner, jumping_counter, airleft;
162 int16_t fta, ftq, access_wallnum, access_spritenum;
163 int16_t kickback_pic, got_access, weapon_ang, visibility;
164 int16_t somethingonplayer, on_crane, i, one_parallax_sectnum;
165 int16_t random_club_frame, one_eighty_count;
166 int16_t dummyplayersprite, extra_extra8;
167 int16_t actorsqu, timebeforeexit, customexitsound, last_pissed_time;
168
169 int16_t weaprecs[MAX_WEAPON_RECS], weapon_sway, crack_time, bobcounter;
170
171 int16_t orotscrnang, rotscrnang, dead_flag; // JBF 20031220: added orotscrnang
172 int16_t holoduke_on, pycount;
173 int16_t transporter_hold/*, clipdist*/;
174
175 uint8_t max_secret_rooms, secret_rooms;
176 // XXX: 255 values for frag(gedself) seems too small.
177 uint8_t frag, fraggedself, quick_kick, last_quick_kick;
178 uint8_t return_to_center, reloading, weapreccnt;
179 uint8_t aim_mode, auto_aim, weaponswitch, movement_lock, team;
180 uint8_t tipincs, hbomb_hold_delay, frag_ps;
181
182 uint8_t gm, on_warping_sector, footprintcount, hurt_delay;
183 uint8_t hbomb_on, jumping_toggle, rapid_fire_hold, on_ground;
184 uint8_t inven_icon, buttonpalette, over_shoulder_on, show_empty_weapon;
185
186 uint8_t jetpack_on, spritebridge, lastrandomspot;
187 uint8_t scuba_on, footprintpal, heat_on, invdisptime;
188
189 uint8_t holster_weapon, falling_counter, footprintshade;
190 uint8_t refresh_inventory, last_full_weapon;
191
192 uint8_t toggle_key_flag, knuckle_incs, knee_incs, access_incs;
193 uint8_t walking_snd_toggle, palookup, hard_landing, fist_incs;
194
195 int8_t numloogs, loogcnt, scream_voice;
196 int8_t last_weapon, cheat_phase, weapon_pos, wantweaponfire, curr_weapon;
197
198 uint8_t palette;
199 palette_t pals;
200
201 int8_t last_used_weapon;
202
203 int16_t recoil;
204 int32_t stairs;
205 int32_t hbomb_offset;
206 int16_t hbomb_time;
207 uint8_t shotgun_state[2];
208 uint8_t make_noise;
209 int32_t noise_x, noise_y, noise_radius;
210 uint8_t keys[5];
211 int16_t yehaa_timer;
212 int16_t drink_amt, eat_amt, drink_ang, eat_ang;
213 int32_t drink_timer, eat_timer;
214 int16_t level_end_timer;
215 int16_t moto_speed, tilt_status, moto_drink;
216 uint8_t on_motorcycle, on_boat, moto_underwater, not_on_water, moto_on_ground;
217 uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud;
218 int16_t moto_bump, moto_bump_target, moto_turb;
219 int16_t drug_stat[3];
220 int32_t drug_aspect;
221 uint8_t drug_mode, lotag800kill, sea_sick_stat;
222 int32_t drug_timer;
223 int32_t sea_sick;
224 uint8_t hurt_delay2, nocheat;
225
226 int32_t dhat60f, dhat613, dhat617, dhat61b, dhat61f;
227
228 uint8_t dn64_36d, dn64_36e;
229
230 int16_t dn64_370, dn64_372, dn64_374, dn64_376, dn64_378;
231
232 uint8_t dn64_385;
233
234 int32_t dn_388;
235
236 int8_t crouch_toggle;
237 int8_t padding_[1];
238 } DukePlayer_t;
239
240 // KEEPINSYNC lunatic/_defs_game.lua
241 typedef struct {
242 DukePlayer_t *ps;
243 input_t *inputBits;
244
245 int32_t movefifoend, syncvalhead, myminlag;
246 int32_t pcolor, pteam;
247 // NOTE: wchoice[HANDREMOTE_WEAPON .. MAX_WEAPONS-1] unused
248 uint8_t frags[MAXPLAYERS], wchoice[MAX_WEAPONS];
249
250 char vote, gotvote, playerreadyflag, playerquitflag, connected;
251 char user_name[32];
252 char syncval[SYNCFIFOSIZ][MAXSYNCBYTES];
253 } playerdata_t;
254 #pragma pack(pop)
255
256 // KEEPINSYNC lunatic/con_lang.lua
257 typedef struct
258 {
259 // NOTE: the member names must be identical to aplWeapon* suffixes.
260 int32_t WorksLike; // What the original works like
261 int32_t Clip; // number of items in magazine
262 int32_t Reload; // delay to reload (include fire)
263 int32_t FireDelay; // delay to fire
264 int32_t TotalTime; // The total time the weapon is cycling before next fire.
265 int32_t HoldDelay; // delay after release fire button to fire (0 for none)
266 int32_t Flags; // Flags for weapon
267 int32_t Shoots; // what the weapon shoots
268 int32_t SpawnTime; // the frame at which to spawn an item
269 int32_t Spawn; // the item to spawn
270 int32_t ShotsPerBurst; // number of shots per 'burst' (one ammo per 'burst')
271 int32_t InitialSound; // Sound made when weapon starts firing. zero for no sound
272 int32_t FireSound; // Sound made when firing (each time for automatic)
273 int32_t Sound2Time; // Alternate sound time
274 int32_t Sound2Sound; // Alternate sound sound ID
275 int32_t FlashColor; // Muzzle flash color
276 } weapondata_t;
277
278 #ifdef LUNATIC
279 # define PWEAPON(Player, Weapon, Wmember) (g_playerWeapon[Player][Weapon].Wmember)
280 extern weapondata_t g_playerWeapon[MAXPLAYERS][MAX_WEAPONS];
281 #else
282 # define PWEAPON(Player, Weapon, Wmember) (aplWeapon ## Wmember [Weapon][Player])
283 extern intptr_t *aplWeaponClip[MAX_WEAPONS]; // number of items in clip
284 extern intptr_t *aplWeaponReload[MAX_WEAPONS]; // delay to reload (include fire)
285 extern intptr_t *aplWeaponFireDelay[MAX_WEAPONS]; // delay to fire
286 extern intptr_t *aplWeaponHoldDelay[MAX_WEAPONS]; // delay after release fire button to fire (0 for none)
287 extern intptr_t *aplWeaponTotalTime[MAX_WEAPONS]; // The total time the weapon is cycling before next fire.
288 extern intptr_t *aplWeaponFlags[MAX_WEAPONS]; // Flags for weapon
289 extern intptr_t *aplWeaponShoots[MAX_WEAPONS]; // what the weapon shoots
290 extern intptr_t *aplWeaponSpawnTime[MAX_WEAPONS]; // the frame at which to spawn an item
291 extern intptr_t *aplWeaponSpawn[MAX_WEAPONS]; // the item to spawn
292 extern intptr_t *aplWeaponShotsPerBurst[MAX_WEAPONS]; // number of shots per 'burst' (one ammo per 'burst'
293 extern intptr_t *aplWeaponWorksLike[MAX_WEAPONS]; // What original the weapon works like
294 extern intptr_t *aplWeaponInitialSound[MAX_WEAPONS]; // Sound made when initialy firing. zero for no sound
295 extern intptr_t *aplWeaponFireSound[MAX_WEAPONS]; // Sound made when firing (each time for automatic)
296 extern intptr_t *aplWeaponSound2Time[MAX_WEAPONS]; // Alternate sound time
297 extern intptr_t *aplWeaponSound2Sound[MAX_WEAPONS]; // Alternate sound sound ID
298 extern intptr_t *aplWeaponFlashColor[MAX_WEAPONS]; // Color for polymer muzzle flash
299 #endif
300
301 // KEEPINSYNC lunatic/_defs_game.lua
302 typedef struct {
303 int32_t cur, count; // "cur" is the only member that is *used*
304 int32_t gunposx, lookhalfang; // weapon_xoffset, ps->look_ang>>1
305 int32_t gunposy, lookhoriz; // gun_pos, looking_arc
306 int32_t shade;
307 } hudweapon_t;
308
309 extern input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS];
310 extern playerspawn_t g_playerSpawnPoints[MAXPLAYERS];
311 extern playerdata_t *const g_player;
312 extern int16_t WeaponPickupSprites[MAX_WEAPONS];
313 extern hudweapon_t hudweap;
314 extern int32_t g_levelTextTime;
315 extern int32_t g_myAimMode;
316 extern int32_t g_numObituaries;
317 extern int32_t g_numSelfObituaries;
318 extern int32_t mouseyaxismode;
319 extern int32_t ticrandomseed;
320
321 #define SHOOT_HARDCODED_ZVEL INT32_MIN
322
323 int A_Shoot(int spriteNum, int projecTile);
324
P_PalFrom(DukePlayer_t * pPlayer,uint8_t f,uint8_t r,uint8_t g,uint8_t b)325 static inline void P_PalFrom(DukePlayer_t *pPlayer, uint8_t f, uint8_t r, uint8_t g, uint8_t b)
326 {
327 pPlayer->pals.f = f;
328 pPlayer->pals.r = r;
329 pPlayer->pals.g = g;
330 pPlayer->pals.b = b;
331 }
332
333 void P_AddKills(DukePlayer_t * pPlayer, uint16_t kills);
334 int32_t A_GetHitscanRange(int spriteNum);
335 void P_GetInput(int playerNum);
336 void P_GetInputMotorcycle(int playerNum);
337 void P_GetInputBoat(int playerNum);
338 void sub_299C0(void);
339 void P_DHGetInput(int const playerNum);
340 void P_AddAmmo(DukePlayer_t * pPlayer, int weaponNum, int addAmount);
341 void P_AddWeapon(DukePlayer_t *pPlayer, int weaponNum);
342 void P_CheckWeapon(DukePlayer_t *pPlayer);
343 void P_DisplayScuba(void);
344 void P_DisplayWeapon(void);
345 void P_DropWeapon(int playerNum);
346 int P_FindOtherPlayer(int playerNum, int32_t *pDist);
347 void P_FragPlayer(int playerNum);
348 #ifdef YAX_ENABLE
349 void getzsofslope_player(int sectNum, int playerX, int playerY, int32_t *pCeilZ, int32_t *pFloorZ);
350 #endif
351 void P_UpdatePosWhenViewingCam(DukePlayer_t *pPlayer);
352 void P_ProcessInput(int playerNum);
353 void P_DHProcessInput(int playerNum);
354 void P_QuickKill(DukePlayer_t *pPlayer);
355 void P_SelectNextInvItem(DukePlayer_t *pPlayer);
356 void P_UpdateScreenPal(DukePlayer_t *pPlayer);
357 void P_EndLevel(void);
358 void P_CheckWeaponI(int playerNum);
359 int P_GetHudPal(const DukePlayer_t *pPlayer);
360 int P_GetKneePal(const DukePlayer_t *pPlayer);
361 #ifdef __cplusplus
362 }
363 int P_GetKneePal(const DukePlayer_t *pPlayer, int hudPal);
364 extern "C" {
365 #endif
366 int P_GetOverheadPal(const DukePlayer_t *pPlayer);
367 void P_MadeNoise(int playerNum);
368 int P_HasKey(int sectNum, int playerNum);
369 int P_NextWeapon(DukePlayer_t* p, int k, int j);
370
371 // Get the player index given an APLAYER sprite pointer.
P_GetP(const void * pSprite)372 static inline int P_GetP(const void *pSprite)
373 {
374 #if 0 // unprotected player index retrieval
375 return spr->yvel;
376 #elif defined NETCODE_DISABLE
377 UNREFERENCED_PARAMETER(pSprite); // for NDEBUG build
378 // NOTE: In the no-netcode build, there's no point to pass player indices
379 // at all since there is ever only one player. However, merely returning 0
380 // would mean making this build less strict than the normal one.
381 Bassert(((const uspritetype *)pSprite)->yvel == 0);
382 return 0;
383 #else
384 int playerNum = ((const uspritetype *)pSprite)->yvel;
385 // [JM] Check against MAXPLAYERS as opposed to g_mostConcurrentPlayers
386 // to prevent CON for disconnected/fake players from executing as playernum 0.
387 if ((unsigned)playerNum >= MAXPLAYERS)
388 playerNum = 0;
389 return playerNum;
390 #endif
391 }
392
393 // Get the player index given an APLAYER sprite index.
P_Get(int32_t spriteNum)394 static inline int P_Get(int32_t spriteNum) { return P_GetP((const uspritetype *)&sprite[spriteNum]); }
395
396 #ifdef __cplusplus
397 }
398 #endif
399
400 #endif
401