2015-05-19 21:54:34 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-10-09 16:09:05 +00:00
|
|
|
#include "ns.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
#include "names2.h"
|
|
|
|
#include "panel.h"
|
2020-08-05 22:18:45 +00:00
|
|
|
#include "misc.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// WARPING - PLANE STYLE
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-09-09 18:32:24 +00:00
|
|
|
extern bool Prediction;
|
2021-11-26 16:03:00 +00:00
|
|
|
DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, sectortype** sect);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-26 16:03:00 +00:00
|
|
|
bool WarpPlaneSectorInfo(sectortype* sect, DSWActor** sp_ceiling, DSWActor** sp_floor)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-07-10 12:25:18 +00:00
|
|
|
*sp_floor = nullptr;
|
|
|
|
*sp_ceiling = nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (Prediction)
|
2020-09-09 17:52:52 +00:00
|
|
|
return false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-12-29 05:13:28 +00:00
|
|
|
if (sect== nullptr || !(sect->extra & SECTFX_WARP_SECTOR))
|
2020-09-09 17:52:52 +00:00
|
|
|
return false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-03 15:51:38 +00:00
|
|
|
SWStatIterator it(STAT_WARP);
|
|
|
|
while (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-30 15:51:56 +00:00
|
|
|
if (actor->sector() == sect)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// skip - don't teleport
|
2021-12-24 19:42:18 +00:00
|
|
|
if (SP_TAG10(actor) == 1)
|
2015-05-19 21:54:34 +00:00
|
|
|
continue;
|
|
|
|
|
2021-12-24 19:42:18 +00:00
|
|
|
if (actor->spr.hitag == WARP_CEILING_PLANE)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-03 15:51:38 +00:00
|
|
|
*sp_ceiling = actor;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
2021-12-24 19:42:18 +00:00
|
|
|
else if (actor->spr.hitag == WARP_FLOOR_PLANE)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-03 15:51:38 +00:00
|
|
|
*sp_floor = actor;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 17:52:52 +00:00
|
|
|
return true;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 14:33:07 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-26 16:03:00 +00:00
|
|
|
DSWActor* WarpPlane(int32_t* x, int32_t* y, int32_t* z, sectortype** sect)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-03 15:51:38 +00:00
|
|
|
DSWActor* sp_floor,* sp_ceiling;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (Prediction)
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-26 15:44:45 +00:00
|
|
|
if (!WarpPlaneSectorInfo(*sect, &sp_ceiling, &sp_floor))
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (sp_ceiling)
|
|
|
|
{
|
2022-02-01 23:08:21 +00:00
|
|
|
if (*z <= sp_ceiling->int_pos().Z)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-26 15:44:45 +00:00
|
|
|
return WarpToArea(sp_ceiling, x, y, z, sect);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sp_floor)
|
|
|
|
{
|
2022-02-01 23:08:21 +00:00
|
|
|
if (*z >= sp_floor->int_pos().Z)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-26 15:44:45 +00:00
|
|
|
return WarpToArea(sp_floor, x, y, z, sect);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 14:33:07 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-26 16:03:00 +00:00
|
|
|
DSWActor* WarpToArea(DSWActor* sp_from, int32_t* x, int32_t* y, int32_t* z, sectortype** sect)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
int xoff;
|
|
|
|
int yoff;
|
|
|
|
int zoff;
|
|
|
|
short match;
|
|
|
|
short to_tag = 0;
|
|
|
|
short match_rand[16];
|
|
|
|
int z_adj = 0;
|
|
|
|
|
2022-02-01 23:08:21 +00:00
|
|
|
xoff = *x - sp_from->int_pos().X;
|
|
|
|
yoff = *y - sp_from->int_pos().Y;
|
|
|
|
zoff = *z - sp_from->int_pos().Z;
|
2021-12-24 19:42:18 +00:00
|
|
|
match = sp_from->spr.lotag;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
TAG 2 = match
|
|
|
|
TAG 3 = Type
|
|
|
|
Sprite - 0,32 always teleports you to the center at the angle the sprite is facing
|
|
|
|
Offset - 1 always teleports you by the offset.Does not touch the angle
|
|
|
|
TAG 4 = angle
|
|
|
|
TAG 5 to 8 = random match locations
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(match_rand,0,sizeof(match_rand));
|
|
|
|
|
2021-12-24 19:42:18 +00:00
|
|
|
switch (sp_from->spr.hitag)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
case WARP_TELEPORTER:
|
|
|
|
to_tag = WARP_TELEPORTER;
|
|
|
|
|
|
|
|
// if tag 5 has something this is a random teleporter
|
2021-12-24 19:42:18 +00:00
|
|
|
if (SP_TAG5(sp_from))
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
short ndx = 0;
|
2021-12-24 13:12:21 +00:00
|
|
|
match_rand[ndx++] = SP_TAG2(sp_from);
|
2021-12-24 19:42:18 +00:00
|
|
|
match_rand[ndx++] = SP_TAG5(sp_from);
|
|
|
|
if (SP_TAG6(sp_from))
|
|
|
|
match_rand[ndx++] = SP_TAG6(sp_from);
|
|
|
|
if (SP_TAG7(sp_from))
|
|
|
|
match_rand[ndx++] = SP_TAG7(sp_from);
|
|
|
|
if (SP_TAG8(sp_from))
|
|
|
|
match_rand[ndx++] = SP_TAG8(sp_from);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// reset the match you are looking for
|
2021-09-20 06:59:54 +00:00
|
|
|
match = match_rand[RandomRange(ndx)];
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WARP_CEILING_PLANE:
|
|
|
|
to_tag = WARP_FLOOR_PLANE;
|
|
|
|
// make sure you warp outside of warp plane
|
|
|
|
z_adj = -Z(2);
|
|
|
|
break;
|
|
|
|
case WARP_FLOOR_PLANE:
|
|
|
|
to_tag = WARP_CEILING_PLANE;
|
|
|
|
// make sure you warp outside of warp plane
|
|
|
|
z_adj = Z(2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-03 15:51:38 +00:00
|
|
|
SWStatIterator it(STAT_WARP);
|
|
|
|
while (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-24 19:55:10 +00:00
|
|
|
if (actor->spr.lotag == match && actor != sp_from)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// exp: WARP_CEILING or WARP_CEILING_PLANE
|
2021-12-24 19:55:10 +00:00
|
|
|
if (actor->spr.hitag == to_tag)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-30 15:24:51 +00:00
|
|
|
if (!actor->insector())
|
2020-05-22 05:17:32 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
// determine new x,y,z position
|
2022-02-01 23:08:21 +00:00
|
|
|
*x = actor->int_pos().X + xoff;
|
|
|
|
*y = actor->int_pos().Y + yoff;
|
|
|
|
*z = actor->int_pos().Z + zoff;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// make sure you warp outside of warp plane
|
|
|
|
*z += z_adj;
|
|
|
|
|
|
|
|
// get new sector
|
2021-12-30 15:51:56 +00:00
|
|
|
*sect = actor->sector();
|
2021-11-26 16:03:00 +00:00
|
|
|
updatesector(*x, *y, sect);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-03 15:51:38 +00:00
|
|
|
return actor;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Warp - Teleporter style
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-11-24 22:27:20 +00:00
|
|
|
bool WarpSectorInfo(sectortype* sect, DSWActor** sp_warp)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-07-10 12:25:18 +00:00
|
|
|
*sp_warp = nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-12-29 05:13:28 +00:00
|
|
|
if (!sect || !(sect->extra & SECTFX_WARP_SECTOR))
|
2020-09-09 17:52:52 +00:00
|
|
|
return false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-03 15:51:38 +00:00
|
|
|
SWStatIterator it(STAT_WARP);
|
|
|
|
while (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-30 15:51:56 +00:00
|
|
|
if (actor->sector() == sect)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// skip - don't teleport
|
2021-12-24 19:42:18 +00:00
|
|
|
if (SP_TAG10(actor) == 1)
|
2015-05-19 21:54:34 +00:00
|
|
|
continue;
|
|
|
|
|
2021-12-24 19:42:18 +00:00
|
|
|
if (actor->spr.hitag == WARP_TELEPORTER)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-03 15:51:38 +00:00
|
|
|
*sp_warp = actor;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 17:52:52 +00:00
|
|
|
return true;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 14:33:07 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-26 16:03:00 +00:00
|
|
|
DSWActor* Warp(int32_t* x, int32_t* y, int32_t* z, sectortype** sect)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-03 15:51:38 +00:00
|
|
|
DSWActor* sp_warp;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (Prediction)
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-26 16:03:00 +00:00
|
|
|
if (!WarpSectorInfo(*sect, &sp_warp))
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (sp_warp)
|
|
|
|
{
|
2021-11-26 16:03:00 +00:00
|
|
|
return WarpToArea(sp_warp, x, y, z, sect);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 12:25:18 +00:00
|
|
|
return nullptr;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|