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"
|
2020-08-05 22:18:45 +00:00
|
|
|
#include "misc.h"
|
2020-05-22 11:11:52 +00:00
|
|
|
#include "interpso.h"
|
2021-05-17 22:26:57 +00:00
|
|
|
#include "render.h"
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2019-10-09 16:09:05 +00:00
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2019-11-17 17:02:17 +00:00
|
|
|
extern int GlobSpeedSO;
|
|
|
|
|
2015-05-19 21:54:34 +00:00
|
|
|
void CopySectorWalls(short dest_sectnum, short src_sectnum)
|
|
|
|
{
|
|
|
|
short dest_wall_num, src_wall_num, start_wall;
|
2020-05-22 11:11:52 +00:00
|
|
|
SECTOR_OBJECTp sop;
|
|
|
|
SECTORp *sectp;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
dest_wall_num = sector[dest_sectnum].wallptr;
|
|
|
|
src_wall_num = sector[src_sectnum].wallptr;
|
|
|
|
|
|
|
|
start_wall = dest_wall_num;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wall[dest_wall_num].picnum = wall[src_wall_num].picnum;
|
|
|
|
|
|
|
|
wall[dest_wall_num].xrepeat = wall[src_wall_num].xrepeat;
|
|
|
|
wall[dest_wall_num].yrepeat = wall[src_wall_num].yrepeat;
|
|
|
|
wall[dest_wall_num].overpicnum = wall[src_wall_num].overpicnum;
|
|
|
|
wall[dest_wall_num].pal = wall[src_wall_num].pal;
|
|
|
|
wall[dest_wall_num].cstat = wall[src_wall_num].cstat;
|
|
|
|
wall[dest_wall_num].shade = wall[src_wall_num].shade;
|
2020-11-26 07:38:59 +00:00
|
|
|
wall[dest_wall_num].xpan_ = wall[src_wall_num].xpan_;
|
|
|
|
wall[dest_wall_num].ypan_ = wall[src_wall_num].ypan_;
|
2015-05-19 21:54:34 +00:00
|
|
|
wall[dest_wall_num].hitag = wall[src_wall_num].hitag;
|
|
|
|
wall[dest_wall_num].lotag = wall[src_wall_num].lotag;
|
|
|
|
wall[dest_wall_num].extra = wall[src_wall_num].extra;
|
|
|
|
|
2019-11-27 07:33:34 +00:00
|
|
|
uint16_t const dest_nextwall = wall[dest_wall_num].nextwall;
|
|
|
|
uint16_t const src_nextwall = wall[src_wall_num].nextwall;
|
|
|
|
|
|
|
|
if (dest_nextwall < MAXWALLS && src_nextwall < MAXWALLS)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
2019-11-27 07:33:34 +00:00
|
|
|
wall[dest_nextwall].picnum = wall[src_nextwall].picnum;
|
|
|
|
wall[dest_nextwall].xrepeat = wall[src_nextwall].xrepeat;
|
|
|
|
wall[dest_nextwall].yrepeat = wall[src_nextwall].yrepeat;
|
|
|
|
wall[dest_nextwall].overpicnum = wall[src_nextwall].overpicnum;
|
|
|
|
wall[dest_nextwall].pal = wall[src_nextwall].pal;
|
|
|
|
wall[dest_nextwall].cstat = wall[src_nextwall].cstat;
|
|
|
|
wall[dest_nextwall].shade = wall[src_nextwall].shade;
|
2020-11-26 07:38:59 +00:00
|
|
|
wall[dest_nextwall].xpan_ = wall[src_nextwall].xpan_;
|
|
|
|
wall[dest_nextwall].ypan_ = wall[src_nextwall].ypan_;
|
2019-11-27 07:33:34 +00:00
|
|
|
wall[dest_nextwall].hitag = wall[src_nextwall].hitag;
|
|
|
|
wall[dest_nextwall].lotag = wall[src_nextwall].lotag;
|
|
|
|
wall[dest_nextwall].extra = wall[src_nextwall].extra;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dest_wall_num = wall[dest_wall_num].point2;
|
|
|
|
src_wall_num = wall[src_wall_num].point2;
|
|
|
|
}
|
|
|
|
while (dest_wall_num != start_wall);
|
2020-05-22 11:11:52 +00:00
|
|
|
|
|
|
|
// TODO: Mapping a sector to the sector object to which it belongs is better
|
|
|
|
for (sop = SectorObject; sop < &SectorObject[MAX_SECTOR_OBJECTS]; sop++)
|
|
|
|
{
|
|
|
|
if (SO_EMPTY(sop))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (sectp = sop->sectp; *sectp; sectp++)
|
|
|
|
if (*sectp - sector == dest_sectnum)
|
|
|
|
{
|
|
|
|
so_setinterpolationtics(sop, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CopySectorMatch(short match)
|
|
|
|
{
|
2020-10-15 15:30:55 +00:00
|
|
|
int ed,ss;
|
2015-05-19 21:54:34 +00:00
|
|
|
SPRITEp dest_sp, src_sp;
|
|
|
|
SECTORp dsectp,ssectp;
|
2020-10-15 16:07:35 +00:00
|
|
|
int kill;
|
2015-05-19 21:54:34 +00:00
|
|
|
SPRITEp k;
|
|
|
|
|
2020-10-15 15:30:55 +00:00
|
|
|
StatIterator it(STAT_COPY_DEST);
|
|
|
|
while ((ed = it.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
dest_sp = &sprite[ed];
|
|
|
|
dsectp = §or[dest_sp->sectnum];
|
|
|
|
|
|
|
|
if (match != sprite[ed].lotag)
|
|
|
|
continue;
|
|
|
|
|
2020-10-15 15:30:55 +00:00
|
|
|
StatIterator it2(STAT_COPY_SOURCE);
|
|
|
|
while ((ss = it2.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
src_sp = &sprite[ss];
|
|
|
|
|
|
|
|
if (SP_TAG2(src_sp) == SPRITE_TAG2(ed) &&
|
|
|
|
SP_TAG3(src_sp) == SPRITE_TAG3(ed))
|
|
|
|
{
|
2020-10-15 16:07:35 +00:00
|
|
|
int src_move;
|
2015-05-19 21:54:34 +00:00
|
|
|
ssectp = §or[src_sp->sectnum];
|
|
|
|
|
|
|
|
// !!!!!AAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHH
|
|
|
|
// Don't kill anything you don't have to
|
|
|
|
// this wall killing things on a Queue causing
|
|
|
|
// invalid situations
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
// kill all sprites in the dest sector that need to be
|
2020-10-15 16:07:35 +00:00
|
|
|
SectIterator itsec(dest_sp->sectnum);
|
|
|
|
while ((kill = itsec.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
k = &sprite[kill];
|
|
|
|
|
|
|
|
// kill anything not invisible
|
|
|
|
if (!TEST(k->cstat, CSTAT_SPRITE_INVISIBLE))
|
|
|
|
{
|
2021-04-02 09:13:33 +00:00
|
|
|
if (User[kill].Data())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// be safe with the killing
|
|
|
|
//SetSuicide(kill);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SpriteQueueDelete(kill); // new function to allow killing - hopefully
|
|
|
|
KillSprite(kill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CopySectorWalls(dest_sp->sectnum, src_sp->sectnum);
|
|
|
|
|
2020-10-15 16:07:35 +00:00
|
|
|
itsec.Reset(src_sp->sectnum);
|
|
|
|
while ((src_move = itsec.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
// don't move ST1 Copy Tags
|
|
|
|
if (SPRITE_TAG1(src_move) != SECT_COPY_SOURCE)
|
|
|
|
{
|
|
|
|
int sx,sy,dx,dy,src_xoff,src_yoff,trash;
|
|
|
|
|
|
|
|
// move sprites from source to dest - use center offset
|
|
|
|
|
|
|
|
// get center of src and dest sect
|
|
|
|
SectorMidPoint(src_sp->sectnum, &sx, &sy, &trash);
|
|
|
|
SectorMidPoint(dest_sp->sectnum, &dx, &dy, &trash);
|
|
|
|
|
|
|
|
// get offset
|
|
|
|
src_xoff = sx - sprite[src_move].x;
|
|
|
|
src_yoff = sy - sprite[src_move].y;
|
|
|
|
|
|
|
|
// move sprite to dest sector
|
|
|
|
sprite[src_move].x = dx - src_xoff;
|
|
|
|
sprite[src_move].y = dy - src_yoff;
|
|
|
|
|
|
|
|
// change sector
|
|
|
|
changespritesect(src_move, dest_sp->sectnum);
|
|
|
|
|
|
|
|
// check to see if it moved on to a sector object
|
|
|
|
if (TEST(sector[dest_sp->sectnum].extra, SECTFX_SECTOR_OBJECT))
|
|
|
|
{
|
|
|
|
SECTOR_OBJECTp sop;
|
|
|
|
|
|
|
|
// find and add sprite to SO
|
|
|
|
sop = DetectSectorObject(§or[sprite[src_move].sectnum]);
|
|
|
|
AddSpriteToSectorObject(src_move, sop);
|
|
|
|
|
|
|
|
// update sprites postions so they aren't in the
|
|
|
|
// wrong place for one frame
|
|
|
|
GlobSpeedSO = 0;
|
2020-09-09 17:52:52 +00:00
|
|
|
RefreshPoints(sop, 0, 0, true);
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy sector user if there is one
|
2021-04-02 10:55:58 +00:00
|
|
|
if (SectUser[src_sp->sectnum].Data() || SectUser[dest_sp->sectnum].Data())
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
SECT_USERp ssectu = GetSectUser(src_sp->sectnum);
|
|
|
|
SECT_USERp dsectu = GetSectUser(dest_sp->sectnum);
|
|
|
|
|
|
|
|
memcpy(dsectu, ssectu, sizeof(SECT_USER));
|
|
|
|
}
|
|
|
|
|
|
|
|
dsectp->hitag = ssectp->hitag;
|
|
|
|
dsectp->lotag = ssectp->lotag;
|
|
|
|
|
|
|
|
dsectp->floorz = ssectp->floorz;
|
|
|
|
dsectp->ceilingz = ssectp->ceilingz;
|
|
|
|
|
|
|
|
dsectp->floorshade = ssectp->floorshade;
|
|
|
|
dsectp->ceilingshade = ssectp->ceilingshade;
|
|
|
|
|
|
|
|
dsectp->floorpicnum = ssectp->floorpicnum;
|
|
|
|
dsectp->ceilingpicnum = ssectp->ceilingpicnum;
|
|
|
|
|
|
|
|
dsectp->floorheinum = ssectp->floorheinum;
|
|
|
|
dsectp->ceilingheinum = ssectp->ceilingheinum;
|
|
|
|
|
|
|
|
dsectp->floorpal = ssectp->floorpal;
|
|
|
|
dsectp->ceilingpal = ssectp->ceilingpal;
|
|
|
|
|
2020-11-25 19:52:06 +00:00
|
|
|
dsectp->floorxpan_ = ssectp->floorxpan_;
|
|
|
|
dsectp->ceilingxpan_ = ssectp->ceilingxpan_;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
2020-11-25 19:52:06 +00:00
|
|
|
dsectp->floorypan_ = ssectp->floorypan_;
|
|
|
|
dsectp->ceilingypan_ = ssectp->ceilingypan_;
|
2015-05-19 21:54:34 +00:00
|
|
|
|
|
|
|
dsectp->floorstat = ssectp->floorstat;
|
|
|
|
dsectp->ceilingstat = ssectp->ceilingstat;
|
|
|
|
|
|
|
|
dsectp->extra = ssectp->extra;
|
|
|
|
dsectp->visibility = ssectp->visibility;
|
2021-05-17 22:26:57 +00:00
|
|
|
|
|
|
|
dsectp->portalnum = ssectp->portalnum;
|
|
|
|
dsectp->portalflags = ssectp->portalflags;
|
|
|
|
|
|
|
|
if (ssectp->portalflags & (PORTAL_SECTOR_CEILING|PORTAL_SECTOR_FLOOR)) allPortals[ssectp->portalnum].dx = allPortals[ssectp->portalnum].dy = 0;
|
2015-05-19 21:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do this outside of processing loop for safety
|
|
|
|
|
|
|
|
// kill all matching dest
|
2020-10-15 15:30:55 +00:00
|
|
|
it.Reset(STAT_COPY_DEST);
|
|
|
|
while ((ed = it.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
if (match == sprite[ed].lotag)
|
|
|
|
KillSprite(ed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// kill all matching sources
|
2020-10-15 15:30:55 +00:00
|
|
|
it.Reset(STAT_COPY_SOURCE);
|
|
|
|
while ((ss = it.NextIndex()) >= 0)
|
2015-05-19 21:54:34 +00:00
|
|
|
{
|
|
|
|
if (match == sprite[ss].lotag)
|
|
|
|
KillSprite(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-10-09 16:09:05 +00:00
|
|
|
END_SW_NS
|