-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathp_change.c
More file actions
217 lines (177 loc) · 5.03 KB
/
Copy pathp_change.c
File metadata and controls
217 lines (177 loc) · 5.03 KB
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
/* p_change.c */
#include "doomdef.h"
#include "p_local.h"
/*
==============================================================================
SECTOR HEIGHT CHANGING
= After modifying a sectors floor or ceiling height, call this
= routine to adjust the positions of all things that touch the
= sector.
=
= If anything doesn't fit anymore, true will be returned.
= If crunch is true, they will take damage as they are being crushed
= If Crunch is false, you should set the sector height back the way it
= was and call P_ChangeSector again to undo the changes
==============================================================================
*/
typedef struct
{
boolean crushchange;
boolean nofit;
fixed_t bbox[4];
} changetest_t;
/*
==================
=
= P_ThingHeightClip
=
= Takes a valid thing and adjusts the thing->floorz, thing->ceilingz,
= anf possibly thing->z
=
= This is called for all nearby monsters whenever a sector changes height
=
= If the thing doesn't fit, the z will be set to the lowest value and
= false will be returned
==================
*/
boolean P_ThingHeightClip (mobj_t *thing)
{
boolean onfloor;
pmovework_t tm;
fixed_t height;
onfloor = (thing->z == thing->floorz);
P_CheckPosition (&tm, thing, thing->x, thing->y);
/* what about stranding a monster partially off an edge? */
thing->floorz = tm.tmfloorz;
thing->ceilingz = tm.tmceilingz;
height = thing->height*FRACUNIT;
if (onfloor)
/* walking monsters rise and fall with the floor */
thing->z = thing->floorz;
else
{ /* don't adjust a floating monster unless forced to */
if (thing->z+height > thing->ceilingz)
thing->z = thing->ceilingz - height;
}
if (thing->ceilingz - thing->floorz < height)
return false;
return true;
}
/*
===============
=
= PIT_ChangeSector
=
===============
*/
boolean PIT_ChangeSector (mobj_t *thing, changetest_t *ct)
{
mobj_t *mo;
fixed_t thbbox[4];
thbbox[BOXTOP ] = thing->y + (thing->radius*FRACUNIT);
thbbox[BOXBOTTOM] = thing->y - (thing->radius*FRACUNIT);
thbbox[BOXRIGHT ] = thing->x + (thing->radius*FRACUNIT);
thbbox[BOXLEFT ] = thing->x - (thing->radius*FRACUNIT);
if (thbbox[BOXTOP] < ct->bbox[BOXBOTTOM])
return true;
if (thbbox[BOXBOTTOM] > ct->bbox[BOXTOP])
return true;
if (thbbox[BOXRIGHT] < ct->bbox[BOXLEFT])
return true;
if (thbbox[BOXLEFT] > ct->bbox[BOXRIGHT])
return true;
if (P_ThingHeightClip (thing))
return true; /* keep checking */
if (thing->flags & MF_STATIC)
return true; /* do not attempt to gib static objects */
/* crunch bodies to giblets */
if (thing->health <= 0)
{
P_SetMobjState (thing, S_GIBS);
thing->height = 0;
thing->radius = 0;
return true; /* keep checking */
}
/* crunch dropped items */
if (thing->flags & MF_DROPPED)
{
P_RemoveMobj (thing);
return true; /* keep checking */
}
if (! (thing->flags & MF_SHOOTABLE) )
return true; /* assume it is bloody gibs or something */
ct->nofit = true;
if (ct->crushchange && !(gametic&3) && (gametic!=prevgametic) )
{
P_DamageMobj(thing,NULL,NULL,10);
/* spray blood in a random direction */
mo = P_SpawnMobj2 (thing->x, thing->y, thing->z + (thing->height*FRACUNIT)/2, MT_BLOOD, thing->subsector);
mo->momx = (P_Random() - P_Random ())<<12;
mo->momy = (P_Random() - P_Random ())<<12;
}
return true; /* keep checking (crush other things) */
}
/*
===============
=
= P_ChangeSector
=
===============
*/
static boolean P_ChangeSector (sector_t *sector, boolean crunch, fixed_t *secbbox)
{
int x,y;
int i;
changetest_t ct;
fixed_t block;
VINT blockbox[4];
/* force next sound to reflood */
for (i=0 ; i<MAXPLAYERS ; i++)
players[i].lastsoundsector = NULL;
ct.nofit = false;
ct.crushchange = crunch;
/* adjust bounding box to map blocks */
block = secbbox[BOXTOP];
ct.bbox[BOXTOP] = block;
block = (unsigned)(block-bmaporgy+MAXRADIUS)>>MAPBLOCKSHIFT;
block = block >= bmapheight ? bmapheight-1 : block;
blockbox[BOXTOP]=block;
block = secbbox[BOXBOTTOM];
ct.bbox[BOXBOTTOM] = block;
block = (block-bmaporgy-MAXRADIUS);
block = block < 0 ? 0 : (unsigned)block>>MAPBLOCKSHIFT;
blockbox[BOXBOTTOM]=block;
block = secbbox[BOXRIGHT];
ct.bbox[BOXRIGHT] = block;
block = (unsigned)(block-bmaporgx+MAXRADIUS)>>MAPBLOCKSHIFT;
block = block >= bmapwidth ? bmapwidth-1 : block;
blockbox[BOXRIGHT]=block;
block = secbbox[BOXLEFT];
ct.bbox[BOXLEFT] = block;
block = (block-bmaporgx-MAXRADIUS);
block = block < 0 ? 0 : (unsigned)block>>MAPBLOCKSHIFT;
blockbox[BOXLEFT]=block;
/* recheck heights for all things near the moving sector */
if (blocklinksadjust)
{
blockbox[BOXLEFT] /= 2;
blockbox[BOXRIGHT] /= 2;
blockbox[BOXBOTTOM] /= 2;
blockbox[BOXTOP] /= 2;
}
for (x=blockbox[BOXLEFT] ; x<= blockbox[BOXRIGHT] ; x++)
for (y=blockbox[BOXBOTTOM];y<= blockbox[BOXTOP] ; y++)
P_BlockThingsIterator (x, y, (blockthingsiter_t)PIT_ChangeSector, &ct);
return ct.nofit;
}
/*
===============
=
= P_ChangeMover
=
===============
*/
boolean P_ChangeMover (mover_t *mover, boolean crunch)
{
return P_ChangeSector(mover->sector, crunch, mover->secbbox);
}