Debian Codegraph @

prboom2/src/dsda/scroll.c

raw
1 //
2 // Copyright(C) 2023 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Scroll
16 //
17
18 #include "p_tick.h"
19 #include "r_state.h"
20
21 #include "scroll.h"
22
23 static void dsda_UpdateSideScrollerPosition(scroll_t* s, fixed_t dx, fixed_t dy) {
24 side_t* side;
25
26 if (!dx && !dy)
27 return;
28
29 side = sides + s->affectee;
30 if (!s->flags)
31 {
32 side->textureoffset += dx;
33 side->rowoffset += dy;
34 }
35 else
36 {
37 if (s->flags & SCROLL_TOP)
38 {
39 side->textureoffset_top += dx;
40 side->rowoffset_top += dy;
41 }
42
43 if (s->flags & SCROLL_MID)
44 {
45 side->textureoffset_mid += dx;
46 side->rowoffset_mid += dy;
47 }
48
49 if (s->flags & SCROLL_BOTTOM)
50 {
51 side->textureoffset_bottom += dx;
52 side->rowoffset_bottom += dy;
53 }
54 }
55 }
56
57 static void dsda_UpdateFloorScrollerPosition(scroll_t* s, fixed_t dx, fixed_t dy) {
58 sector_t* sec;
59
60 if (!dx && !dy)
61 return;
62
63 sec = sectors + s->affectee;
64 sec->floor_xoffs += dx;
65 sec->floor_yoffs += dy;
66 }
67
68 static void dsda_UpdateCeilingScrollerPosition(scroll_t* s, fixed_t dx, fixed_t dy) {
69 sector_t* sec;
70
71 if (!dx && !dy)
72 return;
73
74 sec = sectors + s->affectee;
75 sec->ceiling_xoffs += dx;
76 sec->ceiling_yoffs += dy;
77 }
78
79 static void dsda_UpdateFloorCarryScrollerPosition(scroll_t* s, fixed_t dx, fixed_t dy) {
80 sector_t* sec;
81 fixed_t height;
82 fixed_t waterheight;
83 msecnode_t* node;
84 mobj_t* thing;
85
86 if (!dx && !dy)
87 return;
88
89 // killough 3/7/98: Carry things on floor
90 // killough 3/20/98: use new sector list which reflects true members
91 // killough 3/27/98: fix carrier bug
92 // killough 4/4/98: Underwater, carry things even w/o gravity
93
94 sec = sectors + s->affectee;
95 height = sec->floorheight;
96 waterheight = sec->heightsec != -1 &&
97 sectors[sec->heightsec].floorheight > height ?
98 sectors[sec->heightsec].floorheight : INT_MIN;
99
100 for (node = sec->touching_thinglist; node; node = node->m_snext) {
101 thing = node->m_thing;
102
103 // Move objects only if on floor or underwater, non-floating, and clipped
104 if (
105 !(thing->flags & MF_NOCLIP) && (
106 !(thing->flags & MF_NOGRAVITY || thing->z > height) ||
107 thing->z < waterheight
108 )
109 ) {
110 thing->momx += dx;
111 thing->momy += dy;
112 thing->intflags |= MIF_SCROLLING;
113 }
114 }
115 }
116
117 static void dsda_UpdateControlScroller(control_scroll_t* s) {
118 fixed_t dx;
119 fixed_t dy;
120 fixed_t height;
121 fixed_t delta;
122
123 dx = s->scroll.dx;
124 dy = s->scroll.dy;
125
126 if (s->control != -1) {
127 height = sectors[s->control].floorheight + sectors[s->control].ceilingheight;
128 delta = height - s->last_height;
129
130 s->last_height = height;
131
132 dx = FixedMul(dx, delta);
133 dy = FixedMul(dy, delta);
134 }
135
136 if (s->accel)
137 {
138 s->vdx += dx;
139 s->vdy += dy;
140 }
141 else {
142 s->vdx = dx;
143 s->vdy = dy;
144 }
145 }
146
147 void dsda_UpdateControlSideScroller(control_scroll_t* s) {
148 dsda_UpdateControlScroller(s);
149 dsda_UpdateSideScrollerPosition(&s->scroll, s->vdx, s->vdy);
150 }
151
152 void dsda_UpdateSideScroller(scroll_t* s) {
153 dsda_UpdateSideScrollerPosition(s, s->dx, s->dy);
154 }
155
156 void dsda_UpdateControlFloorScroller(control_scroll_t* s) {
157 dsda_UpdateControlScroller(s);
158 dsda_UpdateFloorScrollerPosition(&s->scroll, s->vdx, s->vdy);
159 }
160
161 void dsda_UpdateFloorScroller(scroll_t* s) {
162 dsda_UpdateFloorScrollerPosition(s, s->dx, s->dy);
163 }
164
165 void dsda_UpdateControlCeilingScroller(control_scroll_t* s) {
166 dsda_UpdateControlScroller(s);
167 dsda_UpdateCeilingScrollerPosition(&s->scroll, s->vdx, s->vdy);
168 }
169
170 void dsda_UpdateCeilingScroller(scroll_t* s) {
171 dsda_UpdateCeilingScrollerPosition(s, s->dx, s->dy);
172 }
173
174 void dsda_UpdateControlFloorCarryScroller(control_scroll_t* s) {
175 dsda_UpdateControlScroller(s);
176 dsda_UpdateFloorCarryScrollerPosition(&s->scroll, s->vdx, s->vdy);
177 }
178
179 void dsda_UpdateFloorCarryScroller(scroll_t* s) {
180 dsda_UpdateFloorScrollerPosition(s, s->dx, s->dy);
181 }
182
183 void dsda_UpdateZDoomFloorScroller(scroll_t* s) {
184 sector_t* sec;
185
186 if (!s->dx && !s->dy)
187 return;
188
189 sec = sectors + s->affectee;
190
191 if (s->flags & SCROLL_TEXTURE) {
192 sec->floor_xoffs -= s->dx;
193 sec->floor_yoffs += s->dy;
194 }
195
196 if (s->flags & (SCROLL_STATIC | SCROLL_PLAYER | SCROLL_MONSTER)) {
197 fixed_t height;
198 fixed_t waterheight;
199 msecnode_t* node;
200 mobj_t* thing;
201
202 height = sec->floorheight;
203 waterheight = sec->heightsec != -1 &&
204 sectors[sec->heightsec].floorheight > height ?
205 sectors[sec->heightsec].floorheight : INT_MIN;
206
207 for (node = sec->touching_thinglist; node; node = node->m_snext) {
208 thing = node->m_thing;
209
210 // Move objects only if on floor or underwater, non-floating, and clipped
211 if (
212 !(thing->flags & MF_NOCLIP) && (
213 !(thing->flags & MF_NOGRAVITY || thing->z > height) ||
214 thing->z < waterheight
215 )
216 ) {
217 dboolean scroll_it;
218
219 scroll_it = false;
220 if (thing->type == MT_SKULL || thing->flags & MF_COUNTKILL) {
221 if (s->flags & SCROLL_MONSTER)
222 scroll_it = true;
223 }
224 else if (thing->player) {
225 if (s->flags & SCROLL_PLAYER)
226 scroll_it = true;
227 }
228 else {
229 if (s->flags & SCROLL_STATIC)
230 scroll_it = true;
231 }
232
233 if (scroll_it) {
234 thing->momx += s->dx * 3 / 32;
235 thing->momy += s->dy * 3 / 32;
236 thing->intflags |= MIF_SCROLLING;
237 }
238 }
239 }
240 }
241 }
242
243 void dsda_UpdateZDoomCeilingScroller(scroll_t* s) {
244 sector_t* sec;
245
246 if (!s->dx && !s->dy)
247 return;
248
249 sec = sectors + s->affectee;
250
251 if (s->flags & SCROLL_TEXTURE) {
252 sec->ceiling_xoffs -= s->dx;
253 sec->ceiling_yoffs += s->dy;
254 }
255
256 if (s->flags & (SCROLL_STATIC | SCROLL_PLAYER | SCROLL_MONSTER)) {
257 msecnode_t* node;
258 mobj_t* thing;
259
260 for (node = sec->touching_thinglist; node; node = node->m_snext) {
261 thing = node->m_thing;
262
263 if (
264 !(thing->flags & MF_NOCLIP) &&
265 thing->flags & MF_SPAWNCEILING &&
266 thing->flags & MF_NOGRAVITY &&
267 thing->z + thing->height == sec->ceilingheight
268 ) {
269 dboolean scroll_it;
270
271 scroll_it = false;
272 if (thing->type == MT_SKULL || thing->flags & MF_COUNTKILL) {
273 if (s->flags & SCROLL_MONSTER)
274 scroll_it = true;
275 }
276 else if (thing->player) {
277 if (s->flags & SCROLL_PLAYER)
278 scroll_it = true;
279 }
280 else {
281 if (s->flags & SCROLL_STATIC)
282 scroll_it = true;
283 }
284
285 if (scroll_it) {
286 thing->momx = s->dx;
287 thing->momy = s->dy;
288 thing->intflags |= MIF_SCROLLING;
289 }
290 }
291 }
292 }
293 }
294
295 void dsda_UpdateThruster(scroll_t* s) {
296 sector_t* sec;
297 msecnode_t* node;
298 mobj_t* thing;
299
300 if (!s->dx && !s->dy)
301 return;
302
303 sec = sectors + s->affectee;
304
305 for (node = sec->touching_thinglist; node; node = node->m_snext) {
306 dboolean thrust_it;
307
308 thrust_it = false;
309 thing = node->m_thing;
310
311 if (thing->flags & MF_NOCLIP)
312 continue;
313
314 if (!(thing->flags & MF_NOGRAVITY) && thing->z <= thing->floorz) {
315 if (s->flags & THRUST_GROUNDED)
316 thrust_it = true;
317 }
318 else if (
319 thing->flags & MF_SPAWNCEILING &&
320 thing->flags & MF_NOGRAVITY &&
321 thing->z + thing->height == sec->ceilingheight
322 ) {
323 if (s->flags & THRUST_CEILING)
324 thrust_it = true;
325 }
326 else if (thing->flags & MF_NOGRAVITY || thing->z > thing->floorz) {
327 if (s->flags & THRUST_AIRBORNE)
328 thrust_it = true;
329 }
330
331 if (thrust_it) {
332 thrust_it = false;
333
334 if (thing->flags2 & MF2_WINDTHRUST && s->flags & THRUST_WINDTHRUST)
335 thrust_it = true;
336 else if (thing->type == MT_SKULL || thing->flags & MF_COUNTKILL) {
337 if (s->flags & THRUST_MONSTER)
338 thrust_it = true;
339 }
340 else if (thing->player) {
341 if (s->flags & THRUST_PLAYER)
342 thrust_it = true;
343 }
344 else if (thing->flags & MF_MISSILE) {
345 if (s->flags & THRUST_PROJECTILE)
346 thrust_it = true;
347 }
348 else {
349 if (s->flags & THRUST_STATIC)
350 thrust_it = true;
351 }
352
353 if (thrust_it) {
354 thing->momx += s->dx;
355 thing->momy += s->dy;
356 thing->intflags |= MIF_SCROLLING;
357 }
358 }
359 }
360 }
361
362 static void dsda_InitScroller(scroll_t* scroll, fixed_t dx, fixed_t dy, int affectee, int flags) {
363 scroll->dx = dx;
364 scroll->dy = dy;
365 scroll->flags = flags;
366 scroll->affectee = affectee;
367 }
368
369 static void dsda_InitControlScroller(control_scroll_t* scroll, int control, int accel) {
370 scroll->accel = accel;
371 scroll->vdx = 0;
372 scroll->vdy = 0;
373 scroll->control = control;
374 scroll->last_height = 0;
375
376 if (scroll->control != -1)
377 scroll->last_height = sectors[control].floorheight + sectors[control].ceilingheight;
378 }
379
380 void dsda_AddSideScroller(fixed_t dx, fixed_t dy, int affectee, int flags) {
381 scroll_t* scroll;
382
383 scroll = Z_MallocLevel(sizeof(*scroll));
384 scroll->thinker.function = dsda_UpdateSideScroller;
385 dsda_InitScroller(scroll, dx, dy, affectee, flags);
386 P_AddThinker(&scroll->thinker);
387 }
388
389 void dsda_AddControlSideScroller(fixed_t dx, fixed_t dy,
390 int control, int affectee, int accel, int flags) {
391 control_scroll_t* scroll;
392
393 scroll = Z_MallocLevel(sizeof(*scroll));
394 scroll->scroll.thinker.function = dsda_UpdateControlSideScroller;
395 dsda_InitScroller(&scroll->scroll, dx, dy, affectee, flags);
396 dsda_InitControlScroller(scroll, control, accel);
397 P_AddThinker(&scroll->scroll.thinker);
398 }
399
400 void dsda_AddFloorScroller(fixed_t dx, fixed_t dy, int affectee, int flags) {
401 scroll_t* scroll;
402
403 scroll = Z_MallocLevel(sizeof(*scroll));
404 scroll->thinker.function = dsda_UpdateFloorScroller;
405 dsda_InitScroller(scroll, dx, dy, affectee, flags);
406 P_AddThinker(&scroll->thinker);
407 }
408
409 void dsda_AddControlFloorScroller(fixed_t dx, fixed_t dy,
410 int control, int affectee, int accel, int flags) {
411 control_scroll_t* scroll;
412
413 scroll = Z_MallocLevel(sizeof(*scroll));
414 scroll->scroll.thinker.function = dsda_UpdateControlFloorScroller;
415 dsda_InitScroller(&scroll->scroll, dx, dy, affectee, flags);
416 dsda_InitControlScroller(scroll, control, accel);
417 P_AddThinker(&scroll->scroll.thinker);
418 }
419
420 void dsda_AddCeilingScroller(fixed_t dx, fixed_t dy, int affectee, int flags) {
421 scroll_t* scroll;
422
423 scroll = Z_MallocLevel(sizeof(*scroll));
424 scroll->thinker.function = dsda_UpdateCeilingScroller;
425 dsda_InitScroller(scroll, dx, dy, affectee, flags);
426 P_AddThinker(&scroll->thinker);
427 }
428
429 void dsda_AddControlCeilingScroller(fixed_t dx, fixed_t dy,
430 int control, int affectee, int accel, int flags) {
431 control_scroll_t* scroll;
432
433 scroll = Z_MallocLevel(sizeof(*scroll));
434 scroll->scroll.thinker.function = dsda_UpdateControlCeilingScroller;
435 dsda_InitScroller(&scroll->scroll, dx, dy, affectee, flags);
436 dsda_InitControlScroller(scroll, control, accel);
437 P_AddThinker(&scroll->scroll.thinker);
438 }
439
440 void dsda_AddFloorCarryScroller(fixed_t dx, fixed_t dy, int affectee, int flags) {
441 scroll_t* scroll;
442
443 scroll = Z_MallocLevel(sizeof(*scroll));
444 scroll->thinker.function = dsda_UpdateFloorCarryScroller;
445 dsda_InitScroller(scroll, dx, dy, affectee, flags);
446 P_AddThinker(&scroll->thinker);
447 }
448
449 void dsda_AddControlFloorCarryScroller(fixed_t dx, fixed_t dy,
450 int control, int affectee, int accel, int flags) {
451 control_scroll_t* scroll;
452
453 scroll = Z_MallocLevel(sizeof(*scroll));
454 scroll->scroll.thinker.function = dsda_UpdateControlFloorCarryScroller;
455 dsda_InitScroller(&scroll->scroll, dx, dy, affectee, flags);
456 dsda_InitControlScroller(scroll, control, accel);
457 P_AddThinker(&scroll->scroll.thinker);
458 }
459
460 void dsda_AddZDoomFloorScroller(fixed_t dx, fixed_t dy, int affectee, int flags) {
461 scroll_t* scroll;
462
463 scroll = Z_MallocLevel(sizeof(*scroll));
464 scroll->thinker.function = dsda_UpdateZDoomFloorScroller;
465 dsda_InitScroller(scroll, dx, dy, affectee, flags);
466 P_AddThinker(&scroll->thinker);
467 }
468
469 void dsda_AddZDoomCeilingScroller(fixed_t dx, fixed_t dy, int affectee, int flags) {
470 scroll_t* scroll;
471
472 scroll = Z_MallocLevel(sizeof(*scroll));
473 scroll->thinker.function = dsda_UpdateZDoomCeilingScroller;
474 dsda_InitScroller(scroll, dx, dy, affectee, flags);
475 P_AddThinker(&scroll->thinker);
476 }
477
478 void dsda_AddThruster(fixed_t dx, fixed_t dy, int affectee, int flags) {
479 scroll_t* scroll;
480
481 scroll = Z_MallocLevel(sizeof(*scroll));
482 scroll->thinker.function = dsda_UpdateThruster;
483 dsda_InitScroller(scroll, dx, dy, affectee, flags);
484 P_AddThinker(&scroll->thinker);
485 }