/
p_pillar.c
225 lines (190 loc) · 7.43 KB
/
p_pillar.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
/**\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_pillar.c:
*/
// HEADER FILES ------------------------------------------------------------
#include "jhexen.h"
#include "dmu_lib.h"
#include "p_mapspec.h"
#include "p_iterlist.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
void T_BuildPillar(pillar_t *pillar)
{
result_e res1;
result_e res2;
// First, raise the floor
res1 = T_MovePlane(pillar->sector, pillar->floorSpeed, pillar->floorDest, pillar->crush, 0, pillar->direction); // floorOrCeiling, direction
// Then, lower the ceiling
res2 =
T_MovePlane(pillar->sector, pillar->ceilingSpeed, pillar->ceilingDest,
pillar->crush, 1, -pillar->direction);
if(res1 == pastdest && res2 == pastdest)
{
P_ToXSector(pillar->sector)->specialData = NULL;
SN_StopSequence(P_GetPtrp(pillar->sector, DMU_SOUND_ORIGIN));
P_TagFinished(P_ToXSector(pillar->sector)->tag);
DD_ThinkerRemove(&pillar->thinker);
}
}
int EV_BuildPillar(linedef_t *line, byte *args, boolean crush)
{
int rtn = 0;
float newHeight;
sector_t *sec = NULL;
pillar_t *pillar;
iterlist_t *list;
list = P_GetSectorIterListForTag((int) args[0], false);
if(!list)
return rtn;
P_IterListResetIterator(list, true);
while((sec = P_IterListIterator(list)) != NULL)
{
if(P_ToXSector(sec)->specialData)
continue; // Already moving, so keep going.
if(P_GetFloatp(sec, DMU_FLOOR_HEIGHT) ==
P_GetFloatp(sec, DMU_CEILING_HEIGHT))
continue; // Pillar is already closed.
rtn = 1;
if(!args[2])
{
newHeight =
P_GetFloatp(sec, DMU_FLOOR_HEIGHT) +
((P_GetFloatp(sec, DMU_CEILING_HEIGHT) -
P_GetFloatp(sec, DMU_FLOOR_HEIGHT)) * .5f);
}
else
{
newHeight =
P_GetFloatp(sec, DMU_FLOOR_HEIGHT) + (float) args[2];
}
pillar = Z_Calloc(sizeof(*pillar), PU_MAP, 0);
pillar->thinker.function = T_BuildPillar;
DD_ThinkerAdd(&pillar->thinker);
P_ToXSector(sec)->specialData = pillar;
pillar->sector = sec;
if(!args[2])
{
pillar->ceilingSpeed = pillar->floorSpeed =
(float) args[1] * (1.0f / 8);
}
else if(newHeight - P_GetFloatp(sec, DMU_FLOOR_HEIGHT) >
P_GetFloatp(sec, DMU_CEILING_HEIGHT) - newHeight)
{
pillar->floorSpeed = (float) args[1] * (1.0f / 8);
pillar->ceilingSpeed =
(P_GetFloatp(sec, DMU_CEILING_HEIGHT) - newHeight) *
(pillar->floorSpeed / (newHeight - P_GetFloatp(sec, DMU_FLOOR_HEIGHT)));
}
else
{
pillar->ceilingSpeed = (float) args[1] * (1.0f / 8);
pillar->floorSpeed =
(newHeight - P_GetFloatp(sec, DMU_FLOOR_HEIGHT)) *
(pillar->ceilingSpeed /
(P_GetFloatp(sec, DMU_CEILING_HEIGHT) - newHeight));
}
pillar->floorDest = newHeight;
pillar->ceilingDest = newHeight;
pillar->direction = 1;
pillar->crush = crush * (int) args[3];
SN_StartSequence(P_GetPtrp(pillar->sector, DMU_SOUND_ORIGIN),
SEQ_PLATFORM + P_ToXSector(pillar->sector)->seqType);
}
return rtn;
}
int EV_OpenPillar(linedef_t *line, byte *args)
{
int rtn = 0;
sector_t *sec = NULL;
pillar_t *pillar;
iterlist_t *list;
list = P_GetSectorIterListForTag((int) args[0], false);
if(!list)
return rtn;
P_IterListResetIterator(list, true);
while((sec = P_IterListIterator(list)) != NULL)
{
if(P_ToXSector(sec)->specialData)
continue; // Already moving, so keep going...
if(P_GetFloatp(sec, DMU_FLOOR_HEIGHT) !=
P_GetFloatp(sec, DMU_CEILING_HEIGHT))
continue; // Pillar isn't closed.
rtn = 1;
pillar = Z_Calloc(sizeof(*pillar), PU_MAP, 0);
pillar->thinker.function = T_BuildPillar;
DD_ThinkerAdd(&pillar->thinker);
P_ToXSector(sec)->specialData = pillar;
pillar->sector = sec;
if(!args[2])
{
P_FindSectorSurroundingLowestFloor(sec,
P_GetFloatp(sec, DMU_FLOOR_HEIGHT), &pillar->floorDest);
}
else
{
pillar->floorDest =
P_GetFloatp(sec, DMU_FLOOR_HEIGHT) - (float) args[2];
}
if(!args[3])
{
P_FindSectorSurroundingHighestCeiling(sec, 0, &pillar->ceilingDest);
}
else
{
pillar->ceilingDest =
P_GetFloatp(sec, DMU_CEILING_HEIGHT) + (float) args[3];
}
if(P_GetFloatp(sec, DMU_FLOOR_HEIGHT) - pillar->floorDest >=
pillar->ceilingDest - P_GetFloatp(sec, DMU_CEILING_HEIGHT))
{
pillar->floorSpeed = (float) args[1] * (1.0f / 8);
pillar->ceilingSpeed =
(P_GetFloatp(sec, DMU_CEILING_HEIGHT) - pillar->ceilingDest) *
(pillar->floorSpeed /
(pillar->floorDest - P_GetFloatp(sec, DMU_FLOOR_HEIGHT)));
}
else
{
pillar->ceilingSpeed = (float) args[1] * (1.0f / 8);
pillar->floorSpeed =
(pillar->floorDest - P_GetFloatp(sec, DMU_FLOOR_HEIGHT)) *
(pillar->ceilingSpeed /
(P_GetFloatp(sec, DMU_CEILING_HEIGHT) - pillar->ceilingDest));
}
pillar->direction = -1; // Open the pillar.
SN_StartSequence(P_GetPtrp(pillar->sector, DMU_SOUND_ORIGIN),
SEQ_PLATFORM + P_ToXSector(pillar->sector)->seqType);
}
return rtn;
}