raze/source/games/sw/src/vis.cpp

190 lines
4.7 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 1997, 2005 - 3D Realms Entertainment
This file is part of Shadow Warrior version 1.2
Shadow Warrior 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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Original Source: 1997 - Frank Maddin and Jim Norwood
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include "build.h"
#include "gamecontrol.h"
#include "names2.h"
#include "game.h"
#include "tags.h"
#include "break.h"
#include "pal.h"
#include "sprite.h"
BEGIN_SW_NS
extern short NormalVisibility; // player.c
#define VIS_VisCur(sp) (SP_TAG2(sp))
#define VIS_VisDir(sp) (SP_TAG3(sp))
#define VIS_VisGoal(sp) (SP_TAG4(sp))
void ProcessVisOn(void)
{
SPRITEp sp;
2021-11-02 23:12:20 +00:00
SWStatIterator it(STAT_VIS_ON);
while (auto actor = it.Next())
{
2021-11-02 23:12:20 +00:00
sp = &actor->s();
if (VIS_VisDir(sp))
{
// get brighter
VIS_VisCur(sp) >>= 1;
//VIS_VisCur(sp) -= 16;
if (VIS_VisCur(sp) <= VIS_VisGoal(sp))
{
VIS_VisCur(sp) = VIS_VisGoal(sp);
VIS_VisDir(sp) ^= 1;
}
}
else
{
// get darker
VIS_VisCur(sp) <<= 1;
VIS_VisCur(sp) += 1;
//VIS_VisCur(sp) += 16;
if (VIS_VisCur(sp) >= NormalVisibility)
{
VIS_VisCur(sp) = NormalVisibility;
2021-11-02 23:12:20 +00:00
auto own = GetOwner(actor);
if (own != nullptr)
{
2021-11-02 23:12:20 +00:00
ASSERT(own->hasU());
RESET(own->u()->Flags2, SPR2_VIS_SHADING);
}
2021-11-02 23:12:20 +00:00
KillActor(actor);
}
}
}
}
void VisViewChange(PLAYERp pp, int *vis)
{
SPRITEp sp;
short BrightestVis = NormalVisibility;
int x,y,z;
2021-11-24 17:35:42 +00:00
sectortype* sectp;
if (paused)
return;
// find the closest quake - should be a strength value
2021-11-02 23:12:20 +00:00
SWStatIterator it(STAT_VIS_ON);
while (auto actor = it.Next())
{
2021-11-02 23:12:20 +00:00
sp = &actor->s();
2021-11-02 23:12:20 +00:00
auto own = GetOwner(actor);
if (own != nullptr)
{
2021-11-02 23:12:20 +00:00
x = own->s().x;
y = own->s().y;
z = own->s().z;
2021-11-24 17:35:42 +00:00
sectp = own->s().sector();
}
else
{
x = sp->x;
y = sp->y;
z = sp->z;
2021-11-24 17:35:42 +00:00
sectp = sp->sector();
}
// save off the brightest vis that you can see
2021-11-24 17:35:42 +00:00
if (FAFcansee(pp->posx, pp->posy, pp->posz, pp->cursector(), x, y, z, sectp))
{
if (VIS_VisCur(sp) < BrightestVis)
BrightestVis = VIS_VisCur(sp);
}
}
*vis = BrightestVis;
}
2021-11-02 23:12:20 +00:00
void SpawnVis(DSWActor* parentActor, short sectnum, int x, int y, int z, int amt)
{
SPRITEp sp;
2021-11-02 23:12:20 +00:00
if (parentActor != nullptr)
{
2021-11-02 23:12:20 +00:00
auto psp = &parentActor->s();
auto pu = parentActor->u();
if (sector[psp->sectnum].floorpal == PALETTE_FOG)
return;
2021-11-02 23:12:20 +00:00
if (sector[psp->sectnum].floorpal == PALETTE_DIVE_LAVA)
return;
// kill any others with the same parent
2021-11-02 23:12:20 +00:00
SWStatIterator it(STAT_VIS_ON);
while (auto itActor = it.Next())
{
2021-11-02 23:12:20 +00:00
if (GetOwner(itActor) == parentActor)
{
2021-11-02 23:12:20 +00:00
KillActor(itActor);
}
}
2021-11-02 23:12:20 +00:00
auto actorNew = InsertActor(psp->sectnum, STAT_VIS_ON);
sp = &actorNew->s();
SetOwner(parentActor, actorNew);
2021-11-02 23:12:20 +00:00
ASSERT(parentActor->hasU());
SET(pu->Flags2, SPR2_CHILDREN);
2021-11-02 23:12:20 +00:00
sp->x = psp->x;
sp->y = psp->y;
sp->z = psp->z;
2021-11-02 23:12:20 +00:00
SET(pu->Flags2, SPR2_VIS_SHADING);
}
else
{
if (sector[sectnum].floorpal == PALETTE_FOG)
2021-11-02 23:12:20 +00:00
return;
2021-11-02 23:12:20 +00:00
auto actorNew = InsertActor(sectnum, STAT_VIS_ON);
sp = &actorNew->s();
sp->x = x;
sp->y = y;
sp->z = z - Z(20);
}
sp->cstat = 0;
sp->extra = 0;
VIS_VisDir(sp) = 1;
VIS_VisCur(sp) = NormalVisibility;
VIS_VisGoal(sp) = amt;
}
END_SW_NS