raze/source/games/blood/src/warp.cpp

336 lines
8.8 KiB
C++
Raw Normal View History

2019-09-19 22:42:45 +00:00
//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 Nuke.YKT
This file is part of NBlood.
NBlood is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
2019-09-19 22:42:45 +00:00
#include "build.h"
2019-09-19 22:42:45 +00:00
#include "blood.h"
BEGIN_BLD_NS
2019-09-19 22:42:45 +00:00
ZONE gStartZone[8];
#ifdef NOONE_EXTENSIONS
2021-12-29 21:56:21 +00:00
ZONE gStartZoneTeam1[8];
ZONE gStartZoneTeam2[8];
bool gTeamsSpawnUsed = false;
#endif
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void validateLinks()
{
2021-12-29 21:56:21 +00:00
int snum = 0;
for (auto& sect : sector)
{
DCoreActor* upper = sect.upperLink;
if (upper && !static_cast<DBloodActor*>(upper)->GetOwner())
{
Printf(PRINT_HIGH, "Unpartnered upper link in sector %d\n", snum);
sect.upperLink = nullptr;
}
DCoreActor* lower = sect.lowerLink;
if (lower && !static_cast<DBloodActor*>(lower)->GetOwner())
{
Printf(PRINT_HIGH, "Unpartnered lower link in sector %d\n", snum);
sect.lowerLink = nullptr;
}
snum++;
}
}
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void warpInit(TArray<DBloodActor*>& actors)
2019-09-19 22:42:45 +00:00
{
2021-12-29 21:56:21 +00:00
#ifdef NOONE_EXTENSIONS
int team1 = 0; int team2 = 0; gTeamsSpawnUsed = false; // increment if team start positions specified.
#endif
for (auto actor : actors)
{
if (!actor->exists()) continue;
if (actor->hasX()) {
switch (actor->spr.type) {
case kMarkerSPStart:
if (gGameOptions.nGameType < 2 && actor->xspr.data1 >= 0 && actor->xspr.data1 < kMaxPlayers) {
ZONE* pZone = &gStartZone[actor->xspr.data1];
2022-08-22 16:25:40 +00:00
pZone->pos = actor->spr.pos;
pZone->sector = actor->sector();
2022-08-16 21:17:01 +00:00
pZone->ang = actor->int_ang();
2021-12-29 21:56:21 +00:00
}
DeleteSprite(actor);
break;
case kMarkerMPStart:
if (actor->xspr.data1 >= 0 && actor->xspr.data2 < kMaxPlayers) {
if (gGameOptions.nGameType >= 2) {
// default if BB or teams without data2 specified
ZONE* pZone = &gStartZone[actor->xspr.data1];
2022-08-22 16:25:40 +00:00
pZone->pos = actor->spr.pos;
pZone->sector = actor->sector();
2022-08-16 21:17:01 +00:00
pZone->ang = actor->int_ang();
2021-12-29 21:56:21 +00:00
#ifdef NOONE_EXTENSIONS
// fill player spawn position according team of player in TEAMS mode.
if (gModernMap && gGameOptions.nGameType == 3) {
if (actor->xspr.data2 == 1) {
pZone = &gStartZoneTeam1[team1];
2022-08-22 16:25:40 +00:00
pZone->pos = actor->spr.pos;
pZone->sector = actor->sector();
2022-08-16 21:17:01 +00:00
pZone->ang = actor->int_ang();
2021-12-29 21:56:21 +00:00
team1++;
2019-09-19 22:42:45 +00:00
2021-12-29 21:56:21 +00:00
}
else if (actor->xspr.data2 == 2) {
pZone = &gStartZoneTeam2[team2];
2022-08-22 16:25:40 +00:00
pZone->pos = actor->spr.pos;
pZone->sector = actor->sector();
2022-08-16 21:17:01 +00:00
pZone->ang = actor->int_ang();
2021-12-29 21:56:21 +00:00
team2++;
}
}
#endif
2021-12-29 21:56:21 +00:00
}
DeleteSprite(actor);
}
break;
case kMarkerUpLink:
actor->sector()->upperLink = actor;
2021-12-29 21:56:21 +00:00
actor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
break;
case kMarkerLowLink:
actor->sector()->lowerLink = actor;
2021-12-29 21:56:21 +00:00
actor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
break;
case kMarkerUpWater:
case kMarkerUpStack:
case kMarkerUpGoo:
actor->sector()->upperLink = actor;
2021-12-29 21:56:21 +00:00
actor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2022-09-13 22:42:59 +00:00
actor->spr.pos.Z = getflorzofslopeptrf(actor->sector(), actor->spr.pos);
2021-12-29 21:56:21 +00:00
break;
case kMarkerLowWater:
case kMarkerLowStack:
case kMarkerLowGoo:
actor->sector()->lowerLink = actor;
2021-12-29 21:56:21 +00:00
actor->spr.cstat |= CSTAT_SPRITE_INVISIBLE;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
2022-09-13 22:42:59 +00:00
actor->spr.pos.Z = getceilzofslopeptrf(actor->sector(), actor->spr.pos);
2021-12-29 21:56:21 +00:00
break;
}
}
}
2019-09-19 22:42:45 +00:00
2021-12-29 21:56:21 +00:00
#ifdef NOONE_EXTENSIONS
// check if there is enough start positions for teams, if any used
if (team1 > 0 || team2 > 0) {
gTeamsSpawnUsed = true;
if (team1 < kMaxPlayers / 2 || team2 < kMaxPlayers / 2) {
viewSetSystemMessage("At least 4 spawn positions for each team is recommended.");
viewSetSystemMessage("Team A positions: %d, Team B positions: %d.", team1, team2);
}
}
#endif
for (auto& sect : sector)
{
auto actor = barrier_cast<DBloodActor*>(sect.upperLink);
if (actor && actor->hasX())
{
int nLink = actor->xspr.data1;
for (auto& isect : sector)
{
auto actor2 = barrier_cast<DBloodActor*>(isect.lowerLink);
if (actor2 && actor2->hasX())
{
if (actor2->xspr.data1 == nLink)
{
actor->SetOwner(actor2);
actor2->SetOwner(actor);
}
}
}
}
}
validateLinks();
2019-09-19 22:42:45 +00:00
}
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int CheckLink(DBloodActor* actor)
2019-09-19 22:42:45 +00:00
{
auto pSector = actor->sector();
2021-12-29 21:56:21 +00:00
auto aUpper = barrier_cast<DBloodActor*>(pSector->upperLink);
auto aLower = barrier_cast<DBloodActor*>(pSector->lowerLink);
if (aUpper)
{
2022-09-19 09:41:58 +00:00
double z;
2021-12-29 21:56:21 +00:00
if (aUpper->spr.type == kMarkerUpLink)
2022-09-19 09:41:58 +00:00
z = aUpper->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
2022-09-19 09:41:58 +00:00
z = getflorzofslopeptrf(actor->sector(), actor->spr.pos);
if (z <= actor->spr.pos.Z)
2021-12-29 21:56:21 +00:00
{
aLower = aUpper->GetOwner();
assert(aLower);
assert(aLower->insector());
ChangeActorSect(actor, aLower->sector());
2022-09-19 09:41:58 +00:00
double z2;
2021-12-29 21:56:21 +00:00
if (aLower->spr.type == kMarkerLowLink)
2022-09-19 09:41:58 +00:00
z2 = aLower->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
2022-09-19 09:41:58 +00:00
z2 = getceilzofslopeptrf(actor->sector(), actor->spr.pos);
actor->spr.pos += DVector3(aLower->spr.pos.XY() - aUpper->spr.pos.XY(), z2 - z);
2021-12-29 21:56:21 +00:00
actor->interpolated = false;
return aUpper->spr.type;
}
}
if (aLower)
{
2022-09-19 09:41:58 +00:00
double z;
2021-12-29 21:56:21 +00:00
if (aLower->spr.type == kMarkerLowLink)
2022-09-19 09:41:58 +00:00
z = aLower->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
2022-09-19 09:41:58 +00:00
z = getceilzofslopeptrf(actor->sector(), actor->spr.pos);
if (z >= actor->spr.pos.Z)
2021-12-29 21:56:21 +00:00
{
aUpper = aLower->GetOwner();
assert(aUpper);
assert(aUpper->insector());
ChangeActorSect(actor, aUpper->sector());
2022-09-19 09:41:58 +00:00
double z2;
2021-12-29 21:56:21 +00:00
if (aUpper->spr.type == kMarkerUpLink)
2022-09-19 09:41:58 +00:00
z2 = aUpper->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
2022-09-19 09:41:58 +00:00
z2 = getflorzofslopeptrf(actor->sector(), actor->spr.pos);
actor->spr.pos += DVector3(aUpper->spr.pos.XY() - aLower->spr.pos.XY(), z2 - z);
2021-12-29 21:56:21 +00:00
actor->interpolated = false;
return aLower->spr.type;
}
}
return 0;
2019-09-19 22:42:45 +00:00
}
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
int CheckLink(DVector3& cPos, sectortype** pSector)
2019-09-19 22:42:45 +00:00
{
2021-12-29 21:56:21 +00:00
auto aUpper = barrier_cast<DBloodActor*>((*pSector)->upperLink);
auto aLower = barrier_cast<DBloodActor*>((*pSector)->lowerLink);
if (aUpper)
{
double z1;
2021-12-29 21:56:21 +00:00
if (aUpper->spr.type == kMarkerUpLink)
z1 = aUpper->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
z1 = getflorzofslopeptrf(*pSector, cPos);
if (z1 <= cPos.Z)
2021-12-29 21:56:21 +00:00
{
aLower = aUpper->GetOwner();
assert(aLower);
assert(aLower->insector());
*pSector = aLower->sector();
cPos.XY() += aLower->spr.pos.XY() - aUpper->spr.pos.XY();
double z2;
2021-12-29 21:56:21 +00:00
if (aUpper->spr.type == kMarkerLowLink)
z2 = aLower->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
z2 = getceilzofslopeptrf(*pSector, cPos);
cPos.Z += z2 - z1;
2021-12-29 21:56:21 +00:00
return aUpper->spr.type;
}
}
if (aLower)
{
double z1;
2021-12-29 21:56:21 +00:00
if (aLower->spr.type == kMarkerLowLink)
z1 = aLower->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
z1 = getceilzofslopeptrf(*pSector, cPos);
if (z1 >= cPos.Z)
2021-12-29 21:56:21 +00:00
{
aUpper = aLower->GetOwner();
assert(aUpper);
*pSector = aUpper->sector();
cPos.XY() += aUpper->spr.pos.XY() - aLower->spr.pos.XY();
double z2;
2021-12-29 21:56:21 +00:00
if (aLower->spr.type == kMarkerUpLink)
z2 = aUpper->spr.pos.Z;
2021-12-29 21:56:21 +00:00
else
z2 = getflorzofslopeptrf(*pSector, cPos);
cPos.Z += z2 - z1;
2021-12-29 21:56:21 +00:00
return aLower->spr.type;
}
}
return 0;
2019-09-19 22:42:45 +00:00
}
2020-11-21 18:39:24 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
FSerializer& Serialize(FSerializer& arc, const char* keyname, ZONE& w, ZONE* def)
{
if (arc.BeginObject(keyname))
{
2022-08-22 16:25:40 +00:00
arc("pos", w.pos)
("sector", w.sector)
2020-11-21 18:39:24 +00:00
("angle", w.ang)
.EndObject();
}
return arc;
}
void SerializeWarp(FSerializer& arc)
{
if (arc.BeginObject("warp"))
{
arc.Array("startzone", gStartZone, kMaxPlayers)
.EndObject();
}
}
END_BLD_NS