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

201 lines
6 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"
2021-03-20 22:01:16 +00:00
#include "automap.h"
#include "savegamehelp.h"
#include "blood.h"
#include "render.h"
2019-09-19 22:42:45 +00:00
BEGIN_BLD_NS
2019-09-19 22:42:45 +00:00
int mirrorcnt, mirrorsector, mirrorwall[4];
MIRROR mirror[16]; // only needed by Polymost.
2019-09-19 22:42:45 +00:00
void InitMirrors(void)
{
r_rortexture = 4080;
r_rortexturerange = 16;
mirrorcnt = 0;
tileDelete(504);
portalClear();
2019-09-19 22:42:45 +00:00
for (int i = 0; i < 16; i++)
{
tileDelete(4080 + i);
}
2021-12-21 09:51:41 +00:00
for (int i = (int)wall.Size() - 1; i >= 0; i--)
2019-09-19 22:42:45 +00:00
{
auto pWalli = &wall[i];
2019-09-19 22:42:45 +00:00
if (mirrorcnt == 16)
break;
int nTile = 4080+mirrorcnt;
if (pWalli->overpicnum == 504)
2019-09-19 22:42:45 +00:00
{
if (pWalli->extra > 0 && pWalli->type == kWallStack)
2019-09-19 22:42:45 +00:00
{
pWalli->overpicnum = nTile;
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].wallnum = i;
mirror[mirrorcnt].type = 0;
2021-12-18 14:18:50 +00:00
pWalli->cstat |= CSTAT_WALL_1WAY;
int tmp = pWalli->xw().data;
2019-09-19 22:42:45 +00:00
int j;
for (j = (int)wall.Size() - 1; j >= 0; j--)
2019-09-19 22:42:45 +00:00
{
if (j == i)
continue;
auto pWallj = &wall[j];
if (pWallj->extra > 0 && pWallj->type == kWallStack)
2019-09-19 22:42:45 +00:00
{
if (tmp != pWallj->xw().data)
2019-09-19 22:42:45 +00:00
continue;
pWalli->hitag = j; // hitag is only used by Polymost, the new renderer uses external links.
pWallj->hitag = i;
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].link = j;
2019-09-19 22:42:45 +00:00
break;
}
}
if (j < 0)
{
Printf(PRINT_HIGH, "wall[%d] has no matching wall link! (data=%d)\n", i, tmp);
}
else
{
mirrorcnt++;
pWalli->portalflags = PORTAL_WALL_VIEW;
pWalli->portalnum = j;
}
2019-09-19 22:42:45 +00:00
}
continue;
}
if (pWalli->picnum == 504)
2019-09-19 22:42:45 +00:00
{
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].link = i;
mirror[mirrorcnt].wallnum = i;
pWalli->picnum = nTile;
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].type = 0;
2021-12-18 14:18:50 +00:00
pWalli->cstat |= CSTAT_WALL_1WAY;
pWalli->portalflags = PORTAL_WALL_MIRROR;
2019-09-19 22:42:45 +00:00
mirrorcnt++;
continue;
}
}
2021-12-21 09:51:41 +00:00
for (int i = (int)sector.Size() - 1; i >= 0; i--)
2019-09-19 22:42:45 +00:00
{
if (mirrorcnt >= 15)
break;
2021-11-24 00:11:49 +00:00
auto secti = &sector[i];
if (secti->floorpicnum == 504)
2019-09-19 22:42:45 +00:00
{
auto link = barrier_cast<DBloodActor*>(secti->upperLink);
if (link == nullptr)
2019-09-19 22:42:45 +00:00
continue;
auto link2 = link->GetOwner();
if (link2 == nullptr)
continue;
auto sectj = link2->spr.sector();
int j = sectnum(sectj);
if (sectj->ceilingpicnum != 504)
I_Error("Lower link sector %d doesn't have mirror picnum\n", j);
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].type = 2;
mirror[mirrorcnt].dx = link2->spr.pos.X - link->spr.pos.X;
mirror[mirrorcnt].dy = link2->spr.pos.Y - link->spr.pos.Y;
mirror[mirrorcnt].dz = link2->spr.pos.Z - link->spr.pos.Z;
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].wallnum = i;
mirror[mirrorcnt].link = j;
secti->floorpicnum = 4080 + mirrorcnt;
secti->portalflags = PORTAL_SECTOR_FLOOR;
secti->portalnum = portalAdd(PORTAL_SECTOR_FLOOR, j, mirror[mirrorcnt].dx, mirror[mirrorcnt].dy, mirror[mirrorcnt].dz);
2019-09-19 22:42:45 +00:00
mirrorcnt++;
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].type = 1;
mirror[mirrorcnt].dx = link->spr.pos.X - link2->spr.pos.X;
mirror[mirrorcnt].dy = link->spr.pos.Y - link2->spr.pos.Y;
mirror[mirrorcnt].dz = link->spr.pos.Z - link2->spr.pos.Z;
2020-11-21 22:40:08 +00:00
mirror[mirrorcnt].wallnum = j;
mirror[mirrorcnt].link = i;
sectj->ceilingpicnum = 4080 + mirrorcnt;
sectj->portalflags = PORTAL_SECTOR_CEILING;
sectj->portalnum = portalAdd(PORTAL_SECTOR_CEILING, i, mirror[mirrorcnt].dx, mirror[mirrorcnt].dy, mirror[mirrorcnt].dz);
2019-09-19 22:42:45 +00:00
mirrorcnt++;
}
}
mirrorsector = sector.Size();
mergePortals();
InitPolymostMirrorHack();
2019-09-19 22:42:45 +00:00
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2019-09-19 22:42:45 +00:00
FSerializer& Serialize(FSerializer& arc, const char* keyname, MIRROR& w, MIRROR* def)
2019-09-19 22:42:45 +00:00
{
if (arc.BeginObject(keyname))
{
arc ("type", w.type)
("link", w.link)
("dx", w.dx)
("dy", w.dy)
("dz", w.dz)
("wallnum", w.wallnum)
.EndObject();
}
return arc;
2019-09-19 22:42:45 +00:00
}
void SerializeMirrors(FSerializer& arc)
2019-09-19 22:42:45 +00:00
{
if (arc.BeginObject("mirror"))
{
arc("mirrorcnt", mirrorcnt)
.Array("mirror", mirror, countof(mirror))
.EndObject();
}
2019-09-19 22:42:45 +00:00
if (arc.isReading())
{
tileDelete(504);
r_rortexture = 4080;
r_rortexturerange = 16;
for (int i = 0; i < 16; i++)
{
tileDelete(4080 + i);
}
InitPolymostMirrorHack();
}
2019-09-19 22:42:45 +00:00
}
END_BLD_NS