-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_telept.c
216 lines (145 loc) · 5.06 KB
/
p_telept.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <stdlib.h>
#include <string.h>
#include "doomdef.h"
#include "d_think.h"
#include "p_pspr.h"
#include "doomstat.h"
#include "p_spec.h"
#include "p_maputl.h"
#include "p_map.h"
#include "r_main.h"
#include "p_tick.h"
#include "s_sound.h"
#include "p_user.h"
static mobj_t* P_TeleportDestination(line_t* line)
{
int i;
for (i = -1; (i = P_FindSectorFromLineTag(line, i)) >= 0;) {
register thinker_t* th = NULL;
while ((th = P_NextThinker(th,th_misc)) != NULL)
if (th->function == P_MobjThinker) {
register mobj_t* m = (mobj_t*)th;
if (m->type == MT_TELEPORTMAN &&
m->subsector->sector-sectors == i)
return m;
}
}
return NULL;
}
int EV_Teleport(line_t *line, int side, mobj_t *thing)
{
mobj_t *m;
if (side || thing->flags & MF_MISSILE)
return 0;
if ((m = P_TeleportDestination(line)) != NULL)
{
int oldx = thing->x, oldy = thing->y, oldz = thing->z;
player_t *player = thing->player;
if (player && player->mo != thing)
player = NULL;
if (!P_TeleportMove(thing, m->x, m->y, false))
return 0;
thing->z = thing->floorz;
if (player)
player->viewz = thing->z + player->viewheight;
S_StartSound(P_SpawnMobj(oldx, oldy, oldz, MT_TFOG), sfx_telept);
S_StartSound(P_SpawnMobj(m->x +
20*finecosine[m->angle>>ANGLETOFINESHIFT],
m->y +
20*finesine[m->angle>>ANGLETOFINESHIFT],
thing->z, MT_TFOG),
sfx_telept);
if (thing->player)
thing->reactiontime = 18;
thing->angle = m->angle;
thing->momx = thing->momy = thing->momz = 0;
if (player)
player->momx = player->momy = 0;
return 1;
}
return 0;
}
int EV_SilentTeleport(line_t *line, int side, mobj_t *thing)
{
mobj_t *m;
if (side || thing->flags & MF_MISSILE)
return 0;
if ((m = P_TeleportDestination(line)) != NULL)
{
int z = thing->z - thing->floorz;
angle_t angle =
R_PointToAngle2(0, 0, line->dx, line->dy) - m->angle + ANG90;
int s = finesine[angle>>ANGLETOFINESHIFT];
int c = finecosine[angle>>ANGLETOFINESHIFT];
int momx = thing->momx;
int momy = thing->momy;
player_t *player = thing->player;
if (!P_TeleportMove(thing, m->x, m->y, false)) /* killough 8/9/98 */
return 0;
thing->angle += angle;
thing->z = z + thing->floorz;
thing->momx = FixedMul(momx, c) - FixedMul(momy, s);
thing->momy = FixedMul(momy, c) + FixedMul(momx, s);
if (player && player->mo == thing)
{
int deltaviewheight = player->deltaviewheight;
player->deltaviewheight = 0;
P_CalcHeight(player);
player->deltaviewheight = deltaviewheight;
}
return 1;
}
return 0;
}
#define FUDGEFACTOR 10
int EV_SilentLineTeleport(line_t *line, int side, mobj_t *thing,
boolean reverse)
{
int i;
line_t *l;
if (side || thing->flags & MF_MISSILE)
return 0;
for (i = -1; (i = P_FindLineFromLineTag(line, i)) >= 0;)
if ((l=lines+i) != line && l->backsector)
{
int pos = D_abs(line->dx) > D_abs(line->dy) ?
FixedDiv(thing->x - line->v1->x, line->dx) :
FixedDiv(thing->y - line->v1->y, line->dy) ;
angle_t angle = (reverse ? pos = FRACUNIT-pos, 0 : ANG180) +
R_PointToAngle2(0, 0, l->dx, l->dy) -
R_PointToAngle2(0, 0, line->dx, line->dy);
int x = l->v2->x - FixedMul(pos, l->dx);
int y = l->v2->y - FixedMul(pos, l->dy);
int s = finesine[angle>>ANGLETOFINESHIFT];
int c = finecosine[angle>>ANGLETOFINESHIFT];
int fudge = FUDGEFACTOR;
player_t *player = thing->player && thing->player->mo == thing ?
thing->player : NULL;
int stepdown =
l->frontsector->floorheight < l->backsector->floorheight;
int z = thing->z - thing->floorz;
int side = reverse || (player && stepdown);
while (P_PointOnLineSide(x, y, l) != side && --fudge>=0)
if (D_abs(l->dx) > D_abs(l->dy))
y -= l->dx < 0 != side ? -1 : 1;
else
x += l->dy < 0 != side ? -1 : 1;
if (!P_TeleportMove(thing, x, y, false))
return 0;
thing->z = z + sides[l->sidenum[stepdown]].sector->floorheight;
thing->angle += angle;
x = thing->momx;
y = thing->momy;
thing->momx = FixedMul(x, c) - FixedMul(y, s);
thing->momy = FixedMul(y, c) + FixedMul(x, s);
if (player)
{
int deltaviewheight = player->deltaviewheight;
player->deltaviewheight = 0;
P_CalcHeight(player);
player->deltaviewheight = deltaviewheight;
}
return 1;
}
return 0;
}