/
p_telept.c
290 lines (238 loc) · 7.79 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2009 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1999 Activision
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* p_telept.c:
*/
// HEADER FILES ------------------------------------------------------------
#include "jhexen.h"
#include "dmu_lib.h"
#include "p_map.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
void P_ArtiTeleportOther(player_t *plr)
{
mobj_t *mo;
mo = P_SpawnPlayerMissile(MT_TELOTHER_FX1, plr->plr->mo);
if(mo)
mo->target = plr->plr->mo;
}
void P_TeleportToPlayerStarts(mobj_t *victim)
{
int i, selections = 0;
float destPos[3];
angle_t destAngle;
spawnspot_t *start;
for(i = 0; i < MAXPLAYERS; ++i)
{
if(!players[i].plr->inGame)
continue;
selections++;
}
i = P_Random() % selections;
start = P_GetPlayerStart(0, i);
destPos[VX] = start->pos[VX];
destPos[VY] = start->pos[VY];
destAngle = playerStarts[i].angle;
P_Teleport(victim, destPos[VX], destPos[VY], destAngle, true);
}
void P_TeleportToDeathmatchStarts(mobj_t *victim)
{
int i, selections;
float destPos[3];
angle_t destAngle;
selections = deathmatchP - deathmatchStarts;
if(selections)
{
i = P_Random() % selections;
destPos[VX] = deathmatchStarts[i].pos[VX];
destPos[VY] = deathmatchStarts[i].pos[VY];
destAngle = deathmatchStarts[i].angle;
P_Teleport(victim, destPos[VX], destPos[VY], destAngle, true);
}
else
{
P_TeleportToPlayerStarts(victim);
}
}
mobj_t *P_SpawnTeleFog(float x, float y, angle_t angle)
{
return P_SpawnMobj3f(MT_TFOG, x, y, TELEFOGHEIGHT, angle, MTF_Z_FLOOR);
}
boolean P_Teleport(mobj_t *mo, float x, float y, angle_t angle,
boolean useFog)
{
float oldpos[3], aboveFloor, fogDelta;
player_t* player;
unsigned int an;
angle_t oldAngle;
mobj_t* fog;
memcpy(oldpos, mo->pos, sizeof(oldpos));
oldAngle = mo->angle;
aboveFloor = mo->pos[VZ] - mo->floorZ;
if(!P_TeleportMove(mo, x, y, false))
return false;
if(mo->player)
{
player = mo->player;
player->plr->flags |= DDPF_FIXANGLES | DDPF_FIXPOS | DDPF_FIXMOM;
if(player->powers[PT_FLIGHT] && aboveFloor)
{
mo->pos[VZ] = mo->floorZ + aboveFloor;
if(mo->pos[VZ] + mo->height > mo->ceilingZ)
{
mo->pos[VZ] = mo->ceilingZ - mo->height;
}
player->plr->viewZ = mo->pos[VZ] + player->plr->viewHeight;
}
else
{
mo->pos[VZ] = mo->floorZ;
player->plr->viewZ = mo->pos[VZ] + player->plr->viewHeight;
if(useFog)
{
player->plr->lookDir = 0;
}
}
}
else if(mo->flags & MF_MISSILE)
{
mo->pos[VZ] = mo->floorZ + aboveFloor;
if(mo->pos[VZ] + mo->height > mo->ceilingZ)
{
mo->pos[VZ] = mo->ceilingZ - mo->height;
}
}
else
{
mo->pos[VZ] = mo->floorZ;
}
// Spawn teleport fog at source and destination
if(useFog)
{
fogDelta = (mo->flags & MF_MISSILE ? 0 : TELEFOGHEIGHT);
fog = P_SpawnMobj3f(MT_TFOG, oldpos[VX], oldpos[VY],
oldpos[VZ] + fogDelta, oldAngle + ANG180, 0);
S_StartSound(SFX_TELEPORT, fog);
an = angle >> ANGLETOFINESHIFT;
fog = P_SpawnMobj3f(MT_TFOG,
x + 20 * FIX2FLT(finecosine[an]),
y + 20 * FIX2FLT(finesine[an]),
mo->pos[VZ] + fogDelta, angle + ANG180, 0);
S_StartSound(SFX_TELEPORT, fog);
if(mo->player && !mo->player->powers[PT_SPEED])
{ // Freeze player for about .5 sec
mo->reactionTime = 18;
}
mo->angle = angle;
}
if(mo->flags2 & MF2_FLOORCLIP)
{
mo->floorClip = 0;
if(mo->pos[VZ] == P_GetFloatp(mo->subsector, DMU_FLOOR_HEIGHT))
{
const terraintype_t* tt = P_MobjGetFloorTerrainType(mo);
if(tt->flags & TTF_FLOORCLIP)
{
mo->floorClip = 10;
}
}
}
if(mo->flags & MF_MISSILE)
{
angle >>= ANGLETOFINESHIFT;
mo->mom[MX] = mo->info->speed * FIX2FLT(finecosine[angle]);
mo->mom[MY] = mo->info->speed * FIX2FLT(finesine[angle]);
}
else if(useFog) // No fog doesn't alter the player's momentums.
{
mo->mom[MX] = mo->mom[MY] = mo->mom[MZ] = 0;
}
P_MobjClearSRVO(mo);
return true;
}
boolean EV_Teleport(int tid, mobj_t* thing, boolean fog)
{
int i, count, searcher;
mobj_t* mo = 0;
if(!thing)
return false;
if(thing->flags2 & MF2_NOTELEPORT)
return false;
count = 0;
searcher = -1;
while(P_FindMobjFromTID(tid, &searcher) != NULL)
count++;
if(count == 0)
return false;
count = 1 + (P_Random() % count);
searcher = -1;
for(i = 0; i < count; ++i)
{
mo = P_FindMobjFromTID(tid, &searcher);
}
if(!mo)
Con_Error("Can't find teleport mapspot\n");
return P_Teleport(thing, mo->pos[VX], mo->pos[VY], mo->angle, fog);
}
#if __JHERETIC__ || __JHEXEN__
void P_ArtiTele(player_t* player)
{
int i, selections;
float destPos[3];
angle_t destAngle;
if(deathmatch)
{
selections = deathmatchP - deathmatchStarts;
i = P_Random() % selections;
destPos[VX] = deathmatchStarts[i].pos[VX];
destPos[VY] = deathmatchStarts[i].pos[VY];
destAngle = deathmatchStarts[i].angle;
}
else
{
//// \fixme DJS - this doesn't seem right... why always player 0?
destPos[VX] = playerStarts[0].pos[VX];
destPos[VY] = playerStarts[0].pos[VY];
destAngle = playerStarts[0].angle;
}
# if __JHEXEN__
P_Teleport(player->plr->mo, destPos[VX], destPos[VY], destAngle, true);
if(player->morphTics)
{ // Teleporting away will undo any morph effects (pig)
P_UndoPlayerMorph(player);
}
# else
P_Teleport(player->plr->mo, destPos[VX], destPos[VY], destAngle);
S_StartSound(SFX_WPNUP, NULL);
# endif
}
#endif