/
p_setup.cpp
730 lines (639 loc) · 19.4 KB
/
p_setup.cpp
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
//-----------------------------------------------------------------------------
//
// Copyright 1993-1996 id Software
// Copyright 1994-1996 Raven Software
// Copyright 1999-2016 Randy Heit
// Copyright 2002-2018 Christoph Oelckers
//
// 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 3 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, see http://www.gnu.org/licenses/
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
//
//-----------------------------------------------------------------------------
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h> // for alloca()
#endif
#include "templates.h"
#include "d_player.h"
#include "m_argv.h"
#include "g_game.h"
#include "filesystem.h"
#include "p_local.h"
#include "p_effect.h"
#include "p_terrain.h"
#include "nodebuild.h"
#include "p_lnspec.h"
#include "c_console.h"
#include "p_acs.h"
#include "announcer.h"
#include "wi_stuff.h"
#include "engineerrors.h"
#include "gi.h"
#include "p_conversation.h"
#include "a_keys.h"
#include "s_sndseq.h"
#include "sbar.h"
#include "p_setup.h"
#include "r_data/r_interpolate.h"
#include "r_sky.h"
#include "cmdlib.h"
#include "md5.h"
#include "po_man.h"
#include "swrenderer/r_renderer.h"
#include "p_blockmap.h"
#include "r_utility.h"
#include "p_spec.h"
#include "g_levellocals.h"
#include "c_dispatch.h"
#include "a_dynlight.h"
#include "events.h"
#include "p_destructible.h"
#include "types.h"
#include "i_time.h"
#include "vm.h"
#include "a_specialspot.h"
#include "maploader/maploader.h"
#include "p_acs.h"
#include "am_map.h"
#include "i_system.h"
#include "v_video.h"
#include "fragglescript/t_script.h"
#include "s_music.h"
#include "animations.h"
#include "texturemanager.h"
#include "p_lnspec.h"
#include "d_main.h"
extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position);
extern unsigned int R_OldBlend;
//===========================================================================
//
// P_PrecacheLevel
//
// Preloads all relevant graphics for the Level->
//
//===========================================================================
void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitlist);
static void AddToList(uint8_t *hitlist, FTextureID texid, int bitmask)
{
if (hitlist[texid.GetIndex()] & bitmask) return; // already done, no need to process everything again.
hitlist[texid.GetIndex()] |= (uint8_t)bitmask;
const auto addAnimations = [hitlist, bitmask](const FTextureID texid)
{
for (auto anim : TexAnim.GetAnimations())
{
if (texid == anim->BasePic || (!anim->bDiscrete && anim->BasePic < texid && texid < anim->BasePic + anim->NumFrames))
{
for (int i = anim->BasePic.GetIndex(); i < anim->BasePic.GetIndex() + anim->NumFrames; i++)
{
hitlist[i] |= (uint8_t)bitmask;
}
}
}
};
addAnimations(texid);
auto switchdef = TexAnim.FindSwitch(texid);
if (switchdef)
{
const FSwitchDef *const pair = switchdef->PairDef;
const uint16_t numFrames = switchdef->NumFrames;
const uint16_t pairNumFrames = pair->NumFrames;
for (int i = 0; i < numFrames; i++)
{
hitlist[switchdef->frames[i].Texture.GetIndex()] |= (uint8_t)bitmask;
}
for (int i = 0; i < pairNumFrames; i++)
{
hitlist[pair->frames[i].Texture.GetIndex()] |= (uint8_t)bitmask;
}
if (numFrames == 1 && pairNumFrames == 1)
{
// Switch can still be animated via BOOM binary definition from ANIMATED lump
addAnimations(switchdef->frames[0].Texture);
addAnimations(pair->frames[0].Texture);
}
}
auto adoor = TexAnim.FindAnimatedDoor(texid);
if (adoor)
{
for (int i = 0; i < adoor->NumTextureFrames; i++)
{
hitlist[adoor->TextureFrames[i].GetIndex()] |= (uint8_t)bitmask;
}
}
}
static void PrecacheLevel(FLevelLocals *Level)
{
if (demoplayback)
return;
int i;
TMap<PClassActor *, bool> actorhitlist;
int cnt = TexMan.NumTextures();
TArray<uint8_t> hitlist(cnt, true);
memset(hitlist.Data(), 0, cnt);
AActor *actor;
auto iterator = Level->GetThinkerIterator<AActor>();
while ((actor = iterator.Next()))
{
actorhitlist[actor->GetClass()] = true;
}
for (auto n : gameinfo.PrecachedClasses)
{
PClassActor *cls = PClass::FindActor(n);
if (cls != nullptr) actorhitlist[cls] = true;
}
for (unsigned i = 0; i < Level->info->PrecacheClasses.Size(); i++)
{
// Level->info can only store names, no class pointers.
PClassActor *cls = PClass::FindActor(Level->info->PrecacheClasses[i]);
if (cls != nullptr) actorhitlist[cls] = true;
}
for (i = Level->sectors.Size() - 1; i >= 0; i--)
{
AddToList(hitlist.Data(), Level->sectors[i].GetTexture(sector_t::floor), FTextureManager::HIT_Flat);
AddToList(hitlist.Data(), Level->sectors[i].GetTexture(sector_t::ceiling), FTextureManager::HIT_Flat);
}
for (i = Level->sides.Size() - 1; i >= 0; i--)
{
auto &sd = Level->sides[i];
int hitflag = FTextureManager::HIT_Wall;
// Only precache skyboxes when this is actually used as a sky transfer.
if (sd.linedef->sidedef[0] == &sd && sd.linedef->special == Static_Init && sd.linedef->args[1] == Init_TransferSky) hitflag |= FTextureManager::HIT_Sky;
AddToList(hitlist.Data(), sd.GetTexture(side_t::top), hitflag);
AddToList(hitlist.Data(), sd.GetTexture(side_t::mid), FTextureManager::HIT_Wall);
AddToList(hitlist.Data(), sd.GetTexture(side_t::bottom), hitflag);
}
if (Level->skytexture1.isValid())
{
AddToList(hitlist.Data(), Level->skytexture1, FTextureManager::HIT_Sky);
}
if (Level->skytexture2.isValid())
{
AddToList(hitlist.Data(), Level->skytexture2, FTextureManager::HIT_Sky);
}
for (auto n : gameinfo.PrecachedTextures)
{
FTextureID tex = TexMan.CheckForTexture(n, ETextureType::Wall, FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ReturnFirst);
if (tex.Exists()) AddToList(hitlist.Data(), tex, FTextureManager::HIT_Wall);
}
for (unsigned i = 0; i < Level->info->PrecacheTextures.Size(); i++)
{
FTextureID tex = TexMan.CheckForTexture(Level->info->PrecacheTextures[i], ETextureType::Wall, FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ReturnFirst);
if (tex.Exists()) AddToList(hitlist.Data(), tex, FTextureManager::HIT_Wall);
}
// This is just a temporary solution, until the hardware renderer's texture manager is in a better state.
if (!V_IsHardwareRenderer())
SWRenderer->Precache(hitlist.Data(), actorhitlist);
else
hw_PrecacheTexture(hitlist.Data(), actorhitlist);
}
//============================================================================
//
// clears all portal data for a new level start
//
//============================================================================
void FLevelLocals::ClearPortals()
{
Displacements.Create(1);
linePortals.Clear();
linkedPortals.Clear();
sectorPortals.Resize(2);
PortalBlockmap.Clear();
// The first entry must always be the default skybox. This is what every sector gets by default.
memset(§orPortals[0], 0, sizeof(sectorPortals[0]));
sectorPortals[0].mType = PORTS_SKYVIEWPOINT;
sectorPortals[0].mFlags = PORTSF_SKYFLATONLY;
// The second entry will be the default sky. This is for forcing a regular sky through the skybox picker
memset(§orPortals[1], 0, sizeof(sectorPortals[0]));
sectorPortals[1].mType = PORTS_SKYVIEWPOINT;
sectorPortals[1].mFlags = PORTSF_SKYFLATONLY;
// also clear the render data
for (auto &sub : subsectors)
{
for (int j = 0; j < 2; j++)
{
if (sub.portalcoverage[j].subsectors != nullptr)
{
delete[] sub.portalcoverage[j].subsectors;
sub.portalcoverage[j].subsectors = nullptr;
}
}
}
for (unsigned i = 0; i < portalGroups.Size(); i++)
{
delete portalGroups[i];
}
portalGroups.Clear();
linePortalSpans.Clear();
}
//==========================================================================
//
//
//
//==========================================================================
void FLevelLocals::ClearLevelData()
{
interpolator.ClearInterpolations(); // [RH] Nothing to interpolate on a fresh level.
Thinkers.DestroyAllThinkers();
ClearAllSubsectorLinks(); // can't be done as part of the polyobj deletion process.
total_monsters = total_items = total_secrets =
killed_monsters = found_items = found_secrets = 0;
max_velocity = avg_velocity = 0;
for (int i = 0; i < 4; i++)
{
UDMFKeys[i].Clear();
}
SN_StopAllSequences(this);
FStrifeDialogueNode *node;
while (StrifeDialogues.Pop (node))
{
delete node;
}
DialogueRoots.Clear();
ClassRoots.Clear();
// delete allocated data in the level arrays.
if (sectors.Size() > 0)
{
delete[] sectors[0].e;
}
for (auto &sub : subsectors)
{
if (sub.BSP != nullptr) delete sub.BSP;
}
ClearPortals();
tagManager.Clear();
ClearTIDHashes();
if (SpotState) SpotState->Destroy();
SpotState = nullptr;
ACSThinker = nullptr;
FraggleScriptThinker = nullptr;
CorpseQueue.Clear();
canvasTextureInfo.EmptyList();
sections.Clear();
segs.Clear();
sectors.Clear();
linebuffer.Clear();
subsectorbuffer.Clear();
lines.Clear();
sides.Clear();
segbuffer.Clear();
loadsectors.Clear();
loadlines.Clear();
loadsides.Clear();
vertexes.Clear();
nodes.Clear();
gamenodes.Reset();
subsectors.Clear();
gamesubsectors.Reset();
rejectmatrix.Clear();
Zones.Clear();
blockmap.Clear();
Polyobjects.Clear();
for (auto &pb : PolyBlockMap)
{
polyblock_t *link = pb;
while (link != nullptr)
{
polyblock_t *next = link->next;
delete link;
link = next;
}
}
PolyBlockMap.Reset();
deathmatchstarts.Clear();
AllPlayerStarts.Clear();
memset(playerstarts, 0, sizeof(playerstarts));
Scrolls.Clear();
if (automap) automap->Destroy();
Behaviors.UnloadModules();
localEventManager->Shutdown();
if (aabbTree) delete aabbTree;
aabbTree = nullptr;
if (screen)
screen->SetAABBTree(nullptr);
}
//==========================================================================
//
//
//
//==========================================================================
void P_FreeLevelData ()
{
R_FreePastViewers();
for (auto Level : AllLevels())
{
Level->ClearLevelData();
}
// primaryLevel->FreeSecondaryLevels();
}
//===========================================================================
//
// P_SetupLevel
//
// [RH] position indicates the start spot to spawn at
//
//===========================================================================
void P_SetupLevel(FLevelLocals *Level, int position, bool newGame)
{
int i;
Level->ShaderStartTime = I_msTimeFS(); // indicate to the shader system that the level just started
// This is motivated as follows:
Level->maptype = MAPTYPE_UNKNOWN;
if (!savegamerestore)
{
Level->SetMusicVolume(Level->MusicVolume);
for (i = 0; i < MAXPLAYERS; ++i)
{
Level->Players[i]->killcount = Level->Players[i]->secretcount
= Level->Players[i]->itemcount = 0;
}
}
for (i = 0; i < MAXPLAYERS; ++i)
{
Level->Players[i]->mo = nullptr;
}
GPalette.ClearTranslationSlot(TRANSLATION_LevelScripted);
// Initial height of PointOfView will be set by player think.
auto p = Level->GetConsolePlayer();
if (p) p->viewz = NO_VALUE;
// Make sure all sounds are stopped before Z_FreeTags.
S_Start();
S_ResetMusic();
// Don't start the music if loading a savegame, because the music is stored there.
// Don't start the music if revisiting a level in a hub for the same reason.
if (!primaryLevel->IsReentering())
{
primaryLevel->SetMusic();
}
// [RH] clear out the mid-screen message
C_MidPrint(nullptr, nullptr);
// Free all level data from the previous map
P_FreeLevelData();
MapData *map = P_OpenMapData(Level->MapName, true);
if (map == nullptr)
{
I_Error("Unable to open map '%s'\n", Level->MapName.GetChars());
}
// [ZZ] init per-map static handlers. we need to call this before everything is set up because otherwise scripts don't receive PlayerEntered event
// (which happens at god-knows-what stage in this function, but definitely not the last part, because otherwise it'd work to put E_InitStaticHandlers before the player spawning)
Level->localEventManager->InitStaticHandlers(Level, true);
// generate a checksum for the level, to be included and checked with savegames.
map->GetChecksum(Level->md5);
// find map num
Level->lumpnum = map->lumpnum;
if (newGame)
{
Level->localEventManager->NewGame();
}
MapLoader loader(Level);
loader.LoadLevel(map, Level->MapName.GetChars(), position);
delete map;
// if deathmatch, randomly spawn the active players
if (deathmatch)
{
for (i = 0; i < MAXPLAYERS; i++)
{
if (Level->PlayerInGame(i))
{
Level->Players[i]->mo = nullptr;
Level->DeathMatchSpawnPlayer(i);
}
}
}
// the same, but for random single/coop player starts
else if (Level->flags2 & LEVEL2_RANDOMPLAYERSTARTS)
{
for (i = 0; i < MAXPLAYERS; ++i)
{
if (Level->PlayerInGame(i))
{
Level->Players[i]->mo = nullptr;
FPlayerStart *mthing = Level->PickPlayerStart(i);
Level->SpawnPlayer(mthing, i, (Level->flags2 & LEVEL2_PRERAISEWEAPON) ? SPF_WEAPONFULLYUP : 0);
}
}
}
// [SP] move unfriendly players around
// horribly hacky - yes, this needs rewritten.
if (Level->deathmatchstarts.Size() > 0)
{
for (i = 0; i < MAXPLAYERS; ++i)
{
auto p = Level->Players[i];
if (Level->PlayerInGame(i) && p->mo != nullptr)
{
if (!(p->mo->flags & MF_FRIENDLY))
{
AActor * oldSpawn = p->mo;
Level->DeathMatchSpawnPlayer(i);
oldSpawn->Destroy();
}
}
}
}
// Don't count monsters in end-of-level sectors if option is on
if (dmflags2 & DF2_NOCOUNTENDMONST)
{
auto it = Level->GetThinkerIterator<AActor>();
AActor * mo;
while ((mo = it.Next()))
{
if (mo->flags & MF_COUNTKILL)
{
if (mo->Sector->damageamount > 0 && (mo->Sector->Flags & (SECF_ENDGODMODE | SECF_ENDLEVEL)) == (SECF_ENDGODMODE | SECF_ENDLEVEL))
{
mo->ClearCounters();
}
}
}
}
T_PreprocessScripts(Level); // preprocess FraggleScript scripts
// build subsector connect matrix
// UNUSED P_ConnectSubsectors ();
R_OldBlend = 0xffffffff;
// [RH] Remove all particles
P_ClearParticles(Level);
// preload graphics and sounds
if (precache)
{
PrecacheLevel(Level);
S_PrecacheLevel(Level);
}
if (deathmatch)
{
AnnounceGameStart();
}
// This check was previously done at run time each time the heightsec was checked.
// However, since 3D floors are static data, we can easily precalculate this and store it in the sector's flags for quick access.
for (auto &s : Level->sectors)
{
if (s.heightsec != nullptr)
{
// If any of these 3D floors render their planes, ignore heightsec.
for (auto &ff : s.e->XFloor.ffloors)
{
if ((ff->flags & (FF_EXISTS | FF_RENDERPLANES)) == (FF_EXISTS | FF_RENDERPLANES))
{
s.MoreFlags |= SECMF_IGNOREHEIGHTSEC; // mark the heightsec inactive.
}
}
}
}
// Create a backup of the map data so the savegame code can toss out all fields that haven't changed in order to reduce processing time and file size.
// Note that we want binary identity here, so assignment is not sufficient because it won't initialize any padding bytes.
// Note that none of these structures may contain non POD fields anyway.
Level->loadsectors.Resize(Level->sectors.Size());
memcpy(&Level->loadsectors[0], &Level->sectors[0], Level->sectors.Size() * sizeof(Level->sectors[0]));
Level->loadlines.Resize(Level->lines.Size());
memcpy(&Level->loadlines[0], &Level->lines[0], Level->lines.Size() * sizeof(Level->lines[0]));
Level->loadsides.Resize(Level->sides.Size());
memcpy(&Level->loadsides[0], &Level->sides[0], Level->sides.Size() * sizeof(Level->sides[0]));
Level->automap = AM_Create(Level);
Level->automap->LevelInit();
Level->SetCompatLineOnSide(true);
// [RH] Start lightning, if MAPINFO tells us to
if (Level->flags & LEVEL_STARTLIGHTNING)
{
Level->StartLightning();
}
auto it = Level->GetThinkerIterator<AActor>();
AActor* ac;
// Initial setup of the dynamic lights.
while ((ac = it.Next()))
{
ac->SetDynamicLights();
}
}
//
// P_Init
//
void P_Init ()
{
P_InitEffects (); // [RH]
P_InitTerrainTypes ();
P_InitKeyMessages ();
R_InitSprites ();
}
void P_Shutdown ()
{
for (auto Level : AllLevels())
{
Level->Thinkers.DestroyThinkersInList(STAT_STATIC);
}
P_FreeLevelData ();
// [ZZ] delete global event handlers
staticEventManager.Shutdown(); // clear out the handlers before starting the engine shutdown
ST_Clear();
for (auto &p : players)
{
if (p.psprites != nullptr) p.psprites->Destroy();
}
}
//==========================================================================
//
// dumpgeometry
//
//==========================================================================
CCMD(dumpgeometry)
{
for (auto Level : AllLevels())
{
Printf("Geometry for %s\n", Level->MapName.GetChars());
for (auto §or : Level->sectors)
{
Printf(PRINT_LOG, "Sector %d\n", sector.sectornum);
for (int j = 0; j<sector.subsectorcount; j++)
{
subsector_t * sub = sector.subsectors[j];
Printf(PRINT_LOG, " Subsector %d - real sector = %d - %s\n", int(sub->Index()), sub->sector->sectornum, sub->hacked & 1 ? "hacked" : "");
for (uint32_t k = 0; k<sub->numlines; k++)
{
seg_t * seg = sub->firstline + k;
if (seg->linedef)
{
Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, linedef %d, side %d",
seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(),
seg->Index(), seg->linedef->Index(), seg->sidedef != seg->linedef->sidedef[0]);
}
else
{
Printf(PRINT_LOG, " (%4.4f, %4.4f), (%4.4f, %4.4f) - seg %d, miniseg",
seg->v1->fX(), seg->v1->fY(), seg->v2->fX(), seg->v2->fY(), seg->Index());
}
if (seg->PartnerSeg)
{
subsector_t * sub2 = seg->PartnerSeg->Subsector;
Printf(PRINT_LOG, ", back sector = %d, real back sector = %d", sub2->render_sector->sectornum, seg->PartnerSeg->frontsector->sectornum);
}
else if (seg->backsector)
{
Printf(PRINT_LOG, ", back sector = %d (no partnerseg)", seg->backsector->sectornum);
}
Printf(PRINT_LOG, "\n");
}
}
}
}
}
//==========================================================================
//
//
//
//==========================================================================
CCMD(listmapsections)
{
for (auto Level : AllLevels())
{
Printf("Map sections for %s:\n", Level->MapName.GetChars());
for (int i = 0; i < 100; i++)
{
for (auto &sub : Level->subsectors)
{
if (sub.mapsection == i)
{
Printf("Mapsection %d, sector %d, line %d\n", i, sub.render_sector->Index(), sub.firstline->linedef->Index());
break;
}
}
}
}
}
//==========================================================================
//
//
//
//==========================================================================
CUSTOM_CVAR(Bool, forcewater, false, CVAR_ARCHIVE | CVAR_SERVERINFO)
{
if (gamestate == GS_LEVEL) for (auto Level : AllLevels())
{
for (auto &sec : Level->sectors)
{
sector_t *hsec = sec.GetHeightSec();
if (hsec && !(hsec->MoreFlags & SECMF_UNDERWATER))
{
if (self)
{
hsec->MoreFlags |= SECMF_FORCEDUNDERWATER;
}
else
{
hsec->MoreFlags &= ~SECMF_FORCEDUNDERWATER;
}
}
}
}
}