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 "game.h"
|
|
|
|
#include "tags.h"
|
|
|
|
#include "weapon.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
|
|
|
|
//#include "ai.h"
|
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2021-12-31 14:50:44 +00:00
|
|
|
SECTOR_OBJECT* DetectSectorObjectByWall(walltype*);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2022-09-08 14:45:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-09-08 14:48:26 +00:00
|
|
|
void SOwallmove(SECTOR_OBJECT* sop, DSWActor* actor, walltype* find_wallp, double dist, DVector2& nvec)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
int j,k,wallcount;
|
2021-12-31 14:41:39 +00:00
|
|
|
walltype* wp;
|
2015-05-19 21:54:34 +00:00
|
|
|
short startwall,endwall;
|
2021-12-31 14:43:47 +00:00
|
|
|
sectortype* *sectp;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-12-29 05:53:36 +00:00
|
|
|
if (!actor->hasU() || (sop->flags & SOBJ_SPRITE_OBJ))
|
2015-05-19 21:54:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
wallcount = 0;
|
|
|
|
for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++)
|
|
|
|
{
|
|
|
|
|
|
|
|
// move all walls in sectors back to the original position
|
2022-11-15 14:24:17 +00:00
|
|
|
for (auto& wal : (*sectp)->walls)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// find the one wall we want to adjust
|
2021-11-24 21:06:50 +00:00
|
|
|
if (&wal == find_wallp)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// move orig x and y in saved angle
|
2022-09-01 17:28:33 +00:00
|
|
|
auto ang = actor->user.sang;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2022-09-08 14:48:26 +00:00
|
|
|
nvec = dist * ang.ToVector();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2022-09-08 14:48:26 +00:00
|
|
|
sop->orig[wallcount] -= nvec;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-12-27 16:22:41 +00:00
|
|
|
sop->flags |= (SOBJ_UPDATE_ONCE);
|
2015-05-19 21:54:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wallcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 14:45:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-11-02 23:50:01 +00:00
|
|
|
int DoWallMove(DSWActor* actor)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2022-09-08 14:48:26 +00:00
|
|
|
short shade1,shade2,picnum1,picnum2;
|
2020-09-09 18:32:24 +00:00
|
|
|
bool found = false;
|
|
|
|
bool SOsprite = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2022-09-08 14:48:26 +00:00
|
|
|
double dist = SP_TAG13(actor) * maptoworld;
|
2022-09-11 11:47:47 +00:00
|
|
|
DAngle ang = mapangle(SP_TAG4(actor));
|
2021-12-24 19:55:10 +00:00
|
|
|
picnum1 = SP_TAG5(actor);
|
|
|
|
picnum2 = SP_TAG6(actor);
|
|
|
|
shade1 = SP_TAG7(actor);
|
|
|
|
shade2 = SP_TAG8(actor);
|
2022-09-08 14:48:26 +00:00
|
|
|
int dang = ((int)SP_TAG10(actor)) << 3;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (dang)
|
2022-09-11 12:02:04 +00:00
|
|
|
ang += mapangle(RandomRange(dang) - dang/2);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2022-09-08 14:48:26 +00:00
|
|
|
DVector2 nvec = dist * ang.ToVector();
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-12-21 08:23:39 +00:00
|
|
|
for(auto& wal : wall)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2022-09-08 14:48:26 +00:00
|
|
|
if (wal.pos.X == actor->spr.pos.X && wal.pos.Y == actor->spr.pos.Y)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
found = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-12-29 05:53:36 +00:00
|
|
|
if ((wal.extra & WALLFX_SECTOR_OBJECT))
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-31 14:50:44 +00:00
|
|
|
SECTOR_OBJECT* sop;
|
2021-11-24 21:06:50 +00:00
|
|
|
sop = DetectSectorObjectByWall(&wal);
|
2015-05-19 21:54:34 +00:00
|
|
|
ASSERT(sop);
|
2022-09-08 14:48:26 +00:00
|
|
|
SOwallmove(sop, actor, &wal, dist, nvec);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-09-09 17:52:52 +00:00
|
|
|
SOsprite = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-08 14:48:26 +00:00
|
|
|
wal.move(actor->spr.pos + nvec);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shade1)
|
2021-11-24 21:06:50 +00:00
|
|
|
wal.shade = int8_t(shade1);
|
2015-05-19 21:54:34 +00:00
|
|
|
if (picnum1)
|
2021-11-24 21:06:50 +00:00
|
|
|
wal.picnum = picnum1;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// find the previous wall
|
2021-11-24 21:06:50 +00:00
|
|
|
auto prev_wall = PrevWall(&wal);
|
2015-05-19 21:54:34 +00:00
|
|
|
if (shade2)
|
2021-11-24 17:58:14 +00:00
|
|
|
prev_wall->shade = int8_t(shade2);
|
2015-05-19 21:54:34 +00:00
|
|
|
if (picnum2)
|
2021-11-24 17:58:14 +00:00
|
|
|
prev_wall->picnum = picnum2;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 19:55:10 +00:00
|
|
|
SP_TAG9(actor)--;
|
|
|
|
if ((int8_t)SP_TAG9(actor) <= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-11-02 23:50:01 +00:00
|
|
|
KillActor(actor);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (SOsprite)
|
|
|
|
{
|
|
|
|
// move the sprite offset from center
|
2022-09-08 14:48:26 +00:00
|
|
|
actor->user.pos -= nvec;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-08 14:48:26 +00:00
|
|
|
actor->spr.pos += nvec;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2022-09-08 14:45:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-12-24 19:03:38 +00:00
|
|
|
bool CanSeeWallMove(DSWActor* caller, int match)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-10-15 15:45:07 +00:00
|
|
|
int i;
|
2020-09-09 18:32:24 +00:00
|
|
|
bool found = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2021-11-02 23:50:01 +00:00
|
|
|
SWStatIterator it(STAT_WALL_MOVE_CANSEE);
|
|
|
|
while (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-24 13:12:21 +00:00
|
|
|
if (SP_TAG2(actor) == match)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
found = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2022-08-22 16:41:05 +00:00
|
|
|
if (cansee(caller->spr.pos, caller->sector(), actor->spr.pos, actor->sector()))
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 23:50:01 +00:00
|
|
|
return !found;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 14:45:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
int DoWallMoveMatch(short match)
|
|
|
|
{
|
2020-09-09 18:32:24 +00:00
|
|
|
bool found = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
// just all with the same matching tags
|
2021-11-02 23:50:01 +00:00
|
|
|
SWStatIterator it(STAT_WALL_MOVE);
|
|
|
|
while (auto actor = it.Next())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2021-12-24 13:12:21 +00:00
|
|
|
if (SP_TAG2(actor) == match)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
found = true;
|
2021-11-02 23:50:01 +00:00
|
|
|
DoWallMove(actor);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2022-09-08 14:45:29 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
#include "saveable.h"
|
|
|
|
|
|
|
|
static saveable_code saveable_wallmove_code[] =
|
|
|
|
{
|
|
|
|
SAVE_CODE(DoWallMove),
|
|
|
|
SAVE_CODE(CanSeeWallMove),
|
|
|
|
SAVE_CODE(DoWallMoveMatch),
|
|
|
|
};
|
|
|
|
|
|
|
|
saveable_module saveable_wallmove =
|
|
|
|
{
|
|
|
|
// code
|
|
|
|
saveable_wallmove_code,
|
|
|
|
SIZ(saveable_wallmove_code),
|
|
|
|
|
|
|
|
// data
|
2021-07-10 12:25:18 +00:00
|
|
|
nullptr,0
|
2015-05-19 21:54:34 +00:00
|
|
|
};
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|