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
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
SECTOR_OBJECTp DetectSectorObjectByWall(WALLp);
|
|
|
|
|
|
|
|
void SOwallmove(SECTOR_OBJECTp sop, SPRITEp sp, WALLp find_wallp, int dist, int *nx, int *ny)
|
|
|
|
{
|
|
|
|
int j,k,wallcount;
|
|
|
|
WALLp wp;
|
|
|
|
short startwall,endwall;
|
|
|
|
SECTORp *sectp;
|
|
|
|
|
|
|
|
if (TEST(sop->flags, SOBJ_SPRITE_OBJ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
wallcount = 0;
|
|
|
|
for (sectp = sop->sectp, j = 0; *sectp; sectp++, j++)
|
|
|
|
{
|
|
|
|
startwall = (*sectp)->wallptr;
|
|
|
|
endwall = startwall + (*sectp)->wallnum - 1;
|
|
|
|
|
|
|
|
// move all walls in sectors back to the original position
|
|
|
|
for (wp = &wall[startwall], k = startwall; k <= endwall; wp++, k++)
|
|
|
|
{
|
|
|
|
// find the one wall we want to adjust
|
|
|
|
if (wp == find_wallp)
|
|
|
|
{
|
|
|
|
short ang;
|
|
|
|
// move orig x and y in saved angle
|
2021-04-02 09:13:33 +00:00
|
|
|
ASSERT(User[sp - sprite].Data());
|
2015-05-19 21:54:34 +00:00
|
|
|
ang = User[sp - sprite]->sang;
|
|
|
|
|
2021-01-04 11:36:54 +00:00
|
|
|
*nx = MulScale(dist, bcos(ang), 14);
|
|
|
|
*ny = MulScale(dist, bsin(ang), 14);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
sop->xorig[wallcount] -= *nx;
|
|
|
|
sop->yorig[wallcount] -= *ny;
|
|
|
|
|
|
|
|
SET(sop->flags, SOBJ_UPDATE_ONCE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wallcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DoWallMove(SPRITEp sp)
|
|
|
|
{
|
|
|
|
int dist,nx,ny;
|
|
|
|
short shade1,shade2,ang,picnum1,picnum2;
|
|
|
|
WALLp wallp;
|
|
|
|
short prev_wall;
|
2020-09-09 18:32:24 +00:00
|
|
|
bool found = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
short dang;
|
2020-09-09 18:32:24 +00:00
|
|
|
bool SOsprite = false;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
dist = SP_TAG13(sp);
|
|
|
|
ang = SP_TAG4(sp);
|
|
|
|
picnum1 = SP_TAG5(sp);
|
|
|
|
picnum2 = SP_TAG6(sp);
|
|
|
|
shade1 = SP_TAG7(sp);
|
|
|
|
shade2 = SP_TAG8(sp);
|
|
|
|
dang = ((int)SP_TAG10(sp)) << 3;
|
|
|
|
|
|
|
|
if (dang)
|
|
|
|
ang = NORM_ANGLE(ang + (RANDOM_RANGE(dang) - dang/2));
|
|
|
|
|
2021-01-04 11:36:54 +00:00
|
|
|
nx = MulScale(dist, bcos(ang), 14);
|
|
|
|
ny = MulScale(dist, bsin(ang), 14);
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
for (wallp = wall; wallp < &wall[numwalls]; wallp++)
|
|
|
|
{
|
|
|
|
if (wallp->x == sp->x && wallp->y == sp->y)
|
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
found = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (TEST(wallp->extra, WALLFX_SECTOR_OBJECT))
|
|
|
|
{
|
|
|
|
SECTOR_OBJECTp sop;
|
|
|
|
sop = DetectSectorObjectByWall(wallp);
|
|
|
|
ASSERT(sop);
|
|
|
|
SOwallmove(sop, sp, wallp, dist, &nx, &ny);
|
|
|
|
|
2020-09-09 17:52:52 +00:00
|
|
|
SOsprite = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wallp->x = sp->x + nx;
|
|
|
|
wallp->y = sp->y + ny;
|
2021-03-30 19:51:37 +00:00
|
|
|
sector[wallp->sector].dirty = 255;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shade1)
|
|
|
|
wallp->shade = shade1;
|
|
|
|
if (picnum1)
|
|
|
|
wallp->picnum = picnum1;
|
|
|
|
|
|
|
|
// find the previous wall
|
|
|
|
prev_wall = PrevWall(wallp - wall);
|
|
|
|
if (shade2)
|
|
|
|
wall[prev_wall].shade = shade2;
|
|
|
|
if (picnum2)
|
|
|
|
wall[prev_wall].picnum = picnum2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SP_TAG9(sp)--;
|
|
|
|
if ((signed char)SP_TAG9(sp) <= 0)
|
|
|
|
{
|
|
|
|
KillSprite(sp - sprite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (SOsprite)
|
|
|
|
{
|
|
|
|
// move the sprite offset from center
|
|
|
|
User[sp - sprite]->sx -= nx;
|
|
|
|
User[sp - sprite]->sy -= ny;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sp->x += nx;
|
|
|
|
sp->y += ny;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2020-09-09 18:32:24 +00:00
|
|
|
bool CanSeeWallMove(SPRITEp wp, short 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
|
|
|
SPRITEp sp;
|
|
|
|
|
2020-10-15 15:40:22 +00:00
|
|
|
StatIterator it(STAT_WALL_MOVE_CANSEE);
|
|
|
|
while ((i = it.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
sp = &sprite[i];
|
|
|
|
|
|
|
|
if (SP_TAG2(sp) == match)
|
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
found = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
if (cansee(wp->x,wp->y,wp->z,wp->sectnum,sp->x,sp->y,sp->z,sp->sectnum))
|
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
return true;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
2020-09-09 17:52:52 +00:00
|
|
|
return false;
|
2015-05-19 21:54:34 +00:00
|
|
|
else
|
2020-09-09 17:52:52 +00:00
|
|
|
return true;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DoWallMoveMatch(short match)
|
|
|
|
{
|
|
|
|
SPRITEp sp;
|
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
|
|
|
|
|
|
|
// just all with the same matching tags
|
2020-10-15 15:40:22 +00:00
|
|
|
StatIterator it(STAT_WALL_MOVE);
|
|
|
|
while ((i = it.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
sp = &sprite[i];
|
|
|
|
|
|
|
|
if (SP_TAG2(sp) == match)
|
|
|
|
{
|
2020-09-09 17:52:52 +00:00
|
|
|
found = true;
|
2015-05-19 21:54:34 +00:00
|
|
|
DoWallMove(sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
NULL,0
|
|
|
|
};
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|