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

346 lines
9 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-08-23 20:24:01 +00:00
actor->set_int_z(getflorzofslopeptr(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-08-23 20:24:01 +00:00
actor->set_int_z(getceilzofslopeptr(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)
{
int z;
if (aUpper->spr.type == kMarkerUpLink)
z = aUpper->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
2022-08-23 20:24:01 +00:00
z = getflorzofslopeptr(actor->sector(), actor->spr.pos);
if (z <= actor->int_pos().Z)
2021-12-29 21:56:21 +00:00
{
aLower = aUpper->GetOwner();
assert(aLower);
assert(aLower->insector());
ChangeActorSect(actor, aLower->sector());
vec3_t add;
add.X = aLower->int_pos().X - aUpper->int_pos().X;
add.Y = aLower->int_pos().Y - aUpper->int_pos().Y;
2021-12-29 21:56:21 +00:00
int z2;
if (aLower->spr.type == kMarkerLowLink)
z2 = aLower->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
2022-08-23 20:24:01 +00:00
z2 = getceilzofslopeptr(actor->sector(), actor->spr.pos);
add.Z = z2 - z;
actor->add_int_pos(add);
2021-12-29 21:56:21 +00:00
actor->interpolated = false;
return aUpper->spr.type;
}
}
if (aLower)
{
int z;
if (aLower->spr.type == kMarkerLowLink)
z = aLower->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
2022-08-23 20:24:01 +00:00
z = getceilzofslopeptr(actor->sector(), actor->spr.pos);
if (z >= actor->int_pos().Z)
2021-12-29 21:56:21 +00:00
{
aUpper = aLower->GetOwner();
assert(aUpper);
assert(aUpper->insector());
ChangeActorSect(actor, aUpper->sector());
vec3_t add;
add.X = aUpper->int_pos().X - aLower->int_pos().X;
add.Y = aUpper->int_pos().Y - aLower->int_pos().Y;
2021-12-29 21:56:21 +00:00
int z2;
if (aUpper->spr.type == kMarkerUpLink)
z2 = aUpper->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
2022-08-23 20:24:01 +00:00
z2 = getflorzofslopeptr(actor->sector(), actor->spr.pos);
add.Z = z2 - z;
actor->add_int_pos(add);
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(int* x, int* y, int* z, 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)
{
int z1;
if (aUpper->spr.type == kMarkerUpLink)
z1 = aUpper->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
z1 = getflorzofslopeptr(*pSector, *x, *y);
if (z1 <= *z)
{
aLower = aUpper->GetOwner();
assert(aLower);
assert(aLower->insector());
*pSector = aLower->sector();
*x += aLower->int_pos().X - aUpper->int_pos().X;
*y += aLower->int_pos().Y - aUpper->int_pos().Y;
2021-12-29 21:56:21 +00:00
int z2;
if (aUpper->spr.type == kMarkerLowLink)
z2 = aLower->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
z2 = getceilzofslopeptr(*pSector, *x, *y);
*z += z2 - z1;
return aUpper->spr.type;
}
}
if (aLower)
{
int z1;
if (aLower->spr.type == kMarkerLowLink)
z1 = aLower->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
z1 = getceilzofslopeptr(*pSector, *x, *y);
if (z1 >= *z)
{
aUpper = aLower->GetOwner();
assert(aUpper);
*pSector = aUpper->sector();
*x += aUpper->int_pos().X - aLower->int_pos().X;
*y += aUpper->int_pos().Y - aLower->int_pos().Y;
2021-12-29 21:56:21 +00:00
int z2;
if (aLower->spr.type == kMarkerUpLink)
z2 = aUpper->int_pos().Z;
2021-12-29 21:56:21 +00:00
else
z2 = getflorzofslopeptr(*pSector, *x, *y);
*z += z2 - z1;
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