Debian Codegraph @

prboom2/src/dsda/aim.c

raw
1 //
2 // Copyright(C) 2024 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Aim
16 //
17
18 #include "p_map.h"
19 #include "tables.h"
20
21 #include "dsda/excmd.h"
22
23 #include "aim.h"
24
25 angle_t dsda_PlayerPitch(player_t* player)
26 {
27 return dsda_FreeAim() ? player->mo->pitch : -(angle_t)(player->lookdir * ANG1 / M_PI);
28 }
29
30 fixed_t dsda_PlayerSlope(player_t* player)
31 {
32 return dsda_FreeAim() ? finetangent[(ANG90 - player->mo->pitch) >> ANGLETOFINESHIFT] :
33 raven ? ((player->lookdir) << FRACBITS) / 173 :
34 0;
35 }
36
37 int dsda_PitchToLookDir(angle_t pitch)
38 {
39 return -(int) ((((uint64_t) pitch * FIXED_PI) >> FRACBITS) / ANG1);
40 }
41
42 angle_t dsda_LookDirToPitch(int lookdir)
43 {
44 return (angle_t) -FixedDiv(lookdir * ANG1, FIXED_PI);
45 }
46
47 int dsda_PlayerLookDir(player_t* player)
48 {
49 return dsda_FreeAim() ? dsda_PitchToLookDir(player->mo->pitch) : player->lookdir;
50 }
51
52 void dsda_PlayerAim(mobj_t* source, angle_t angle, aim_t* aim, uint64_t target_mask)
53 {
54 aim->angle = angle;
55
56 if (dsda_FreeAim())
57 {
58 aim->slope = finetangent[(ANG90 - source->pitch) >> ANGLETOFINESHIFT];
59 aim->z_offset = 0;
60 }
61 else
62 {
63 do
64 {
65 aim->slope = P_AimLineAttack(source, aim->angle, 16 * 64 * FRACUNIT, target_mask);
66
67 if (!linetarget)
68 {
69 aim->angle += 1 << 26;
70 aim->slope = P_AimLineAttack(source, aim->angle, 16 * 64 * FRACUNIT, target_mask);
71 }
72
73 if (!linetarget)
74 {
75 aim->angle -= 2 << 26;
76 aim->slope = P_AimLineAttack(source, aim->angle, 16 * 64 * FRACUNIT, target_mask);
77 }
78
79 if (!linetarget) {
80 aim->angle = angle;
81 aim->slope = raven ? ((source->player->lookdir) << FRACBITS) / 173 : 0;
82 }
83 }
84 while (target_mask && (target_mask = 0, !linetarget)); // killough 8/2/98
85
86 aim->z_offset = raven ? ((source->player->lookdir) << FRACBITS) / 173 : 0;
87 }
88 }
89
90 void dsda_PlayerAimBad(mobj_t* source, angle_t angle, aim_t* aim, uint64_t target_mask)
91 {
92 aim->angle = angle;
93 aim->z_offset = 0;
94
95 if (dsda_FreeAim())
96 {
97 aim->slope = finetangent[(ANG90 - source->pitch) >> ANGLETOFINESHIFT];
98 aim->z_offset = 0;
99 }
100 else
101 {
102 do
103 {
104 aim->slope = P_AimLineAttack(source, aim->angle, 16 * 64 * FRACUNIT, target_mask);
105
106 if (!linetarget)
107 {
108 aim->angle += 1 << 26;
109 aim->slope = P_AimLineAttack(source, aim->angle, 16 * 64 * FRACUNIT, target_mask);
110 }
111
112 if (!linetarget)
113 {
114 aim->angle -= 2 << 26;
115 aim->slope = P_AimLineAttack(source, aim->angle, 16 * 64 * FRACUNIT, target_mask);
116 }
117
118 if (heretic && !linetarget)
119 aim->slope = ((source->player->lookdir) << FRACBITS) / 173;
120 }
121 while (target_mask && (target_mask = 0, !linetarget)); // killough 8/2/98
122 }
123 }