summaryrefslogtreecommitdiff
path: root/apps/plugins/doom/p_user.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-03-28 15:44:01 +0000
committerDave Chapman <dave@dchapman.com>2006-03-28 15:44:01 +0000
commit47f4a458d636a889e955e68f896708f1276febc0 (patch)
tree99f770c02ef606f0abbdcd332ac39e69830d8007 /apps/plugins/doom/p_user.c
parentfff7d6157d56f233cad5c2003475e47a5ff809a7 (diff)
downloadrockbox-47f4a458d636a889e955e68f896708f1276febc0.tar.gz
rockbox-47f4a458d636a889e955e68f896708f1276febc0.zip
Patch #2969 - Doom! Currently only working on the H300.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9312 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/doom/p_user.c')
-rw-r--r--apps/plugins/doom/p_user.c420
1 files changed, 420 insertions, 0 deletions
diff --git a/apps/plugins/doom/p_user.c b/apps/plugins/doom/p_user.c
new file mode 100644
index 0000000000..abbe36b12c
--- /dev/null
+++ b/apps/plugins/doom/p_user.c
@@ -0,0 +1,420 @@
1/* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 * 02111-1307, USA.
26 *
27 * DESCRIPTION:
28 * Player related stuff.
29 * Bobbing POV/weapon, movement.
30 * Pending weapon.
31 *
32 *-----------------------------------------------------------------------------*/
33
34#include "doomstat.h"
35#include "d_event.h"
36#include "r_main.h"
37#include "p_map.h"
38#include "p_spec.h"
39#include "p_user.h"
40#include "rockmacros.h"
41// Index of the special effects (INVUL inverse) map.
42
43#define INVERSECOLORMAP 32
44
45//
46// Movement.
47//
48
49// 16 pixels of bob
50
51#define MAXBOB 0x100000
52
53boolean onground; // whether player is on ground or in air
54
55//
56// P_Thrust
57// Moves the given origin along a given angle.
58//
59
60void P_Thrust(player_t* player,angle_t angle,fixed_t move)
61{
62 angle >>= ANGLETOFINESHIFT;
63 player->mo->momx += FixedMul(move,finecosine[angle]);
64 player->mo->momy += FixedMul(move,finesine[angle]);
65}
66
67
68/*
69 * P_Bob
70 * Same as P_Thrust, but only affects bobbing.
71 *
72 * killough 10/98: We apply thrust separately between the real physical player
73 * and the part which affects bobbing. This way, bobbing only comes from player
74 * motion, nothing external, avoiding many problems, e.g. bobbing should not
75 * occur on conveyors, unless the player walks on one, and bobbing should be
76 * reduced at a regular rate, even on ice (where the player coasts).
77 */
78
79void P_Bob(player_t *player, angle_t angle, fixed_t move)
80{
81 player->momx += FixedMul(move,finecosine[angle >>= ANGLETOFINESHIFT]);
82 player->momy += FixedMul(move,finesine[angle]);
83}
84
85//
86// P_CalcHeight
87// Calculate the walking / running height adjustment
88//
89
90void P_CalcHeight (player_t* player)
91{
92 int angle;
93 fixed_t bob;
94
95 // Regular movement bobbing
96 // (needs to be calculated for gun swing
97 // even if not on ground)
98 // OPTIMIZE: tablify angle
99 // Note: a LUT allows for effects
100 // like a ramp with low health.
101
102
103 /* killough 10/98: Make bobbing depend only on player-applied motion.
104 *
105 * Note: don't reduce bobbing here if on ice: if you reduce bobbing here,
106 * it causes bobbing jerkiness when the player moves from ice to non-ice,
107 * and vice-versa.
108 */
109 player->bob = !mbf_features ?
110 (FixedMul (player->mo->momx, player->mo->momx)
111 + FixedMul (player->mo->momy,player->mo->momy))>>2 :
112 player_bobbing ? (FixedMul(player->momx,player->momx) +
113 FixedMul(player->momy,player->momy))>>2 : 0;
114
115 if (player->bob > MAXBOB)
116 player->bob = MAXBOB;
117
118 if (!onground || player->cheats & CF_NOMOMENTUM)
119 {
120 player->viewz = player->mo->z + VIEWHEIGHT;
121
122 if (player->viewz > player->mo->ceilingz-4*FRACUNIT)
123 player->viewz = player->mo->ceilingz-4*FRACUNIT;
124
125 // The following line was in the Id source and appears // phares 2/25/98
126 // to be a bug. player->viewz is checked in a similar
127 // manner at a different exit below.
128
129 // player->viewz = player->mo->z + player->viewheight;
130 return;
131 }
132
133 angle = (FINEANGLES/20*leveltime)&FINEMASK;
134 bob = FixedMul(player->bob/2,finesine[angle]);
135
136 // move viewheight
137
138 if (player->playerstate == PST_LIVE)
139 {
140 player->viewheight += player->deltaviewheight;
141
142 if (player->viewheight > VIEWHEIGHT)
143 {
144 player->viewheight = VIEWHEIGHT;
145 player->deltaviewheight = 0;
146 }
147
148 if (player->viewheight < VIEWHEIGHT/2)
149 {
150 player->viewheight = VIEWHEIGHT/2;
151 if (player->deltaviewheight <= 0)
152 player->deltaviewheight = 1;
153 }
154
155 if (player->deltaviewheight)
156 {
157 player->deltaviewheight += FRACUNIT/4;
158 if (!player->deltaviewheight)
159 player->deltaviewheight = 1;
160 }
161 }
162
163 player->viewz = player->mo->z + player->viewheight + bob;
164
165 if (player->viewz > player->mo->ceilingz-4*FRACUNIT)
166 player->viewz = player->mo->ceilingz-4*FRACUNIT;
167}
168
169
170//
171// P_MovePlayer
172//
173// Adds momentum if the player is not in the air
174//
175// killough 10/98: simplified
176
177void P_MovePlayer (player_t* player)
178{
179 ticcmd_t *cmd = &player->cmd;
180 mobj_t *mo = player->mo;
181
182 mo->angle += cmd->angleturn << 16;
183 onground = mo->z <= mo->floorz;
184
185 // killough 10/98:
186 //
187 // We must apply thrust to the player and bobbing separately, to avoid
188 // anomalies. The thrust applied to bobbing is always the same strength on
189 // ice, because the player still "works just as hard" to move, while the
190 // thrust applied to the movement varies with 'movefactor'.
191
192 if (cmd->forwardmove | cmd->sidemove) // killough 10/98
193 {
194 if (onground || mo->flags & MF_BOUNCES) // killough 8/9/98
195 {
196 int friction, movefactor = P_GetMoveFactor(mo, &friction);
197
198 // killough 11/98:
199 // On sludge, make bobbing depend on efficiency.
200 // On ice, make it depend on effort.
201
202 int bobfactor =
203 friction < ORIG_FRICTION ? movefactor : ORIG_FRICTION_FACTOR;
204
205 if (cmd->forwardmove)
206 {
207 P_Bob(player,mo->angle,cmd->forwardmove*bobfactor);
208 P_Thrust(player,mo->angle,cmd->forwardmove*movefactor);
209 }
210
211 if (cmd->sidemove)
212 {
213 P_Bob(player,mo->angle-ANG90,cmd->sidemove*bobfactor);
214 P_Thrust(player,mo->angle-ANG90,cmd->sidemove*movefactor);
215 }
216 }
217 if (mo->state == states+S_PLAY)
218 P_SetMobjState(mo,S_PLAY_RUN1);
219 }
220}
221
222#define ANG5 (ANG90/18)
223
224//
225// P_DeathThink
226// Fall on your face when dying.
227// Decrease POV height to floor height.
228//
229
230void P_DeathThink (player_t* player)
231{
232 angle_t angle;
233 angle_t delta;
234
235 P_MovePsprites (player);
236
237 // fall to the ground
238
239 if (player->viewheight > 6*FRACUNIT)
240 player->viewheight -= FRACUNIT;
241
242 if (player->viewheight < 6*FRACUNIT)
243 player->viewheight = 6*FRACUNIT;
244
245 player->deltaviewheight = 0;
246 onground = (player->mo->z <= player->mo->floorz);
247 P_CalcHeight (player);
248
249 if (player->attacker && player->attacker != player->mo)
250 {
251 angle = R_PointToAngle2 (player->mo->x,
252 player->mo->y,
253 player->attacker->x,
254 player->attacker->y);
255
256 delta = angle - player->mo->angle;
257
258 if (delta < ANG5 || delta > (unsigned)-ANG5)
259 {
260 // Looking at killer,
261 // so fade damage flash down.
262
263 player->mo->angle = angle;
264
265 if (player->damagecount)
266 player->damagecount--;
267 }
268 else if (delta < ANG180)
269 player->mo->angle += ANG5;
270 else
271 player->mo->angle -= ANG5;
272 }
273 else if (player->damagecount)
274 player->damagecount--;
275
276 if (player->cmd.buttons & BT_USE)
277 player->playerstate = PST_REBORN;
278}
279
280
281//
282// P_PlayerThink
283//
284
285void P_PlayerThink (player_t* player)
286{
287 ticcmd_t* cmd;
288 weapontype_t newweapon;
289
290 // killough 2/8/98, 3/21/98:
291 if (player->cheats & CF_NOCLIP)
292 player->mo->flags |= MF_NOCLIP;
293 else
294 player->mo->flags &= ~MF_NOCLIP;
295
296 // chain saw run forward
297
298 cmd = &player->cmd;
299 if (player->mo->flags & MF_JUSTATTACKED)
300 {
301 cmd->angleturn = 0;
302 cmd->forwardmove = 0xc800/512;
303 cmd->sidemove = 0;
304 player->mo->flags &= ~MF_JUSTATTACKED;
305 }
306
307 if (player->playerstate == PST_DEAD)
308 {
309 P_DeathThink (player);
310 return;
311 }
312
313 // Move around.
314 // Reactiontime is used to prevent movement
315 // for a bit after a teleport.
316
317 if (player->mo->reactiontime)
318 player->mo->reactiontime--;
319 else
320 P_MovePlayer (player);
321
322 P_CalcHeight (player); // Determines view height and bobbing
323
324 // Determine if there's anything about the sector you're in that's
325 // going to affect you, like painful floors.
326
327 if (player->mo->subsector->sector->special)
328 P_PlayerInSpecialSector (player);
329
330 // Check for weapon change.
331
332 if (cmd->buttons & BT_CHANGE)
333 {
334 // The actual changing of the weapon is done
335 // when the weapon psprite can do it
336 // (read: not in the middle of an attack).
337
338 newweapon = (cmd->buttons & BT_WEAPONMASK)>>BT_WEAPONSHIFT;
339
340 // killough 3/22/98: For demo compatibility we must perform the fist
341 // and SSG weapons switches here, rather than in G_BuildTiccmd(). For
342 // other games which rely on user preferences, we must use the latter.
343
344 if (demo_compatibility)
345 { // compatibility mode -- required for old demos -- killough
346 if (newweapon == wp_fist && player->weaponowned[wp_chainsaw] &&
347 (player->readyweapon != wp_chainsaw ||
348 !player->powers[pw_strength]))
349 newweapon = wp_chainsaw;
350 if (gamemode == commercial &&
351 newweapon == wp_shotgun &&
352 player->weaponowned[wp_supershotgun] &&
353 player->readyweapon != wp_supershotgun)
354 newweapon = wp_supershotgun;
355 }
356
357 // killough 2/8/98, 3/22/98 -- end of weapon selection changes
358
359 if (player->weaponowned[newweapon] && newweapon != player->readyweapon)
360
361 // Do not go to plasma or BFG in shareware,
362 // even if cheated.
363
364 if ((newweapon != wp_plasma && newweapon != wp_bfg)
365 || (gamemode != shareware) )
366 player->pendingweapon = newweapon;
367 }
368
369 // check for use
370
371 if (cmd->buttons & BT_USE)
372 {
373 if (!player->usedown)
374 {
375 P_UseLines (player);
376 player->usedown = true;
377 }
378 }
379 else
380 player->usedown = false;
381
382 // cycle psprites
383
384 P_MovePsprites (player);
385
386 // Counters, time dependent power ups.
387
388 // Strength counts up to diminish fade.
389
390 if (player->powers[pw_strength])
391 player->powers[pw_strength]++;
392
393 // killough 1/98: Make idbeholdx toggle:
394
395 if (player->powers[pw_invulnerability] > 0) // killough
396 player->powers[pw_invulnerability]--;
397
398 if (player->powers[pw_invisibility] > 0) // killough
399 if (! --player->powers[pw_invisibility] )
400 player->mo->flags &= ~MF_SHADOW;
401
402 if (player->powers[pw_infrared] > 0) // killough
403 player->powers[pw_infrared]--;
404
405 if (player->powers[pw_ironfeet] > 0) // killough
406 player->powers[pw_ironfeet]--;
407
408 if (player->damagecount)
409 player->damagecount--;
410
411 if (player->bonuscount)
412 player->bonuscount--;
413
414 // Handling colormaps.
415 // killough 3/20/98: reformat to terse C syntax
416
417 player->fixedcolormap = player->powers[pw_invulnerability] > 4*32 ||
418 player->powers[pw_invulnerability] & 8 ? INVERSECOLORMAP :
419 player->powers[pw_infrared] > 4*32 || player->powers[pw_infrared] & 8;
420}