-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathp_generic.c
173 lines (161 loc) · 3.91 KB
/
p_generic.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
// generic floor / ceiling movement
// by kgsws
#include "z_zone.h"
#include "doomdef.h"
#include "p_local.h"
#include "s_sound.h"
#include "doomstat.h"
#include "r_state.h"
#include "p_generic.h"
//
// Ceiling
//
void T_GenericCeiling(generic_plane_t *gp)
{
fixed_t speed;
sector_t *sec = gp->info.sector;
if(gp->info.startz < gp->info.stopz)
{
// raise
if(sec->ceilingheight + gp->speed > gp->info.stopz)
speed = gp->info.stopz - sec->ceilingheight;
else
speed = gp->speed;
sec->ceilingheight += speed;
P_ChangeSector(sec, !!gp->info.crushspeed);
} else
if(gp->info.startz > gp->info.stopz)
{
// lower
if(sec->ceilingheight - gp->speed < gp->info.stopz)
speed = sec->ceilingheight - gp->info.stopz;
else
speed = gp->speed;
sec->ceilingheight -= speed;
if(P_ChangeSector(sec, !!gp->info.crushspeed))
{
// move blocked
if(gp->info.crushspeed)
{
// change speed and continue;
gp->speed = gp->info.crushspeed;
} else
{
// return back
sec->ceilingheight += speed;
P_ChangeSector(sec, false);
}
}
}
// finished ?
if(sec->ceilingheight == gp->info.stopz)
{
if(gp->info.stopsound)
S_StartSound((mobj_t *)&sec->soundorg, gp->info.stopsound, SOUND_BODY);
sec->specialdata = NULL;
sec->ceilingpic = gp->info.stoppic;
P_RemoveThinker(&gp->thinker);
} else
{
if(!(leveltime&7) && gp->info.movesound)
S_StartSound((mobj_t *)&sec->soundorg, gp->info.movesound, SOUND_BODY);
}
}
void P_GenericSectorCeiling(sector_t *sec, generic_info_t *info)
{
generic_plane_t *gp;
// remove old one
if(sec->specialdata)
P_RemoveThinker(sec->specialdata);
// check speed
if(!info->speed)
return;
// add new one
gp = Z_Malloc(sizeof(generic_plane_t), PU_LEVSPEC, 0);
P_AddThinker(&gp->thinker);
gp->info = *info;
gp->thinker.function.acp1 = (actionf_p1)T_GenericCeiling;
sec->specialdata = gp;
// set starting parameters
gp->speed = gp->info.speed;
sec->ceilingheight = info->startz;
sec->ceilingpic = info->startpic;
if(info->startsound)
S_StartSound((mobj_t *)&sec->soundorg, info->startsound, SOUND_BODY);
}
//
// Floor
//
void T_GenericFloor(generic_plane_t *gp)
{
fixed_t speed;
sector_t *sec = gp->info.sector;
if(gp->info.startz > gp->info.stopz)
{
// lower
if(sec->floorheight - gp->speed < gp->info.stopz)
speed = sec->floorheight - gp->info.stopz;
else
speed = gp->speed;
sec->floorheight -= speed;
P_ChangeSector(sec, !!gp->info.crushspeed);
} else
if(gp->info.startz < gp->info.stopz)
{
// raise
if(sec->floorheight + gp->speed > gp->info.stopz)
speed = gp->info.stopz - sec->floorheight;
else
speed = gp->speed;
sec->floorheight += speed;
if(P_ChangeSector(sec, !!gp->info.crushspeed))
{
// move blocked
if(gp->info.crushspeed)
{
// change speed and continue;
gp->speed = gp->info.crushspeed;
} else
{
// return back
sec->floorheight -= speed;
P_ChangeSector(sec, false);
}
}
}
// finished ?
if(sec->floorheight == gp->info.stopz)
{
if(gp->info.stopsound)
S_StartSound((mobj_t *)&sec->soundorg, gp->info.stopsound, SOUND_BODY);
sec->specialdata = NULL;
sec->floorpic = gp->info.stoppic;
P_RemoveThinker(&gp->thinker);
} else
{
if(!(leveltime&7) && gp->info.movesound)
S_StartSound((mobj_t *)&sec->soundorg, gp->info.movesound, SOUND_BODY);
}
}
void P_GenericSectorFloor(sector_t *sec, generic_info_t *info)
{
generic_plane_t *gp;
// remove old one
if(sec->specialdata)
P_RemoveThinker(sec->specialdata);
// check speed
if(!info->speed)
return;
// add new one
gp = Z_Malloc(sizeof(generic_plane_t), PU_LEVSPEC, 0);
P_AddThinker(&gp->thinker);
gp->info = *info;
gp->thinker.function.acp1 = (actionf_p1)T_GenericFloor;
sec->specialdata = gp;
// set starting parameters
gp->speed = gp->info.speed;
sec->floorheight = info->startz;
sec->floorpic = info->startpic;
if(info->startsound)
S_StartSound((mobj_t *)&sec->soundorg, info->startsound, SOUND_BODY);
}