2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 sirlemonhead, Nuke.YKT
|
|
|
|
This file is part of PCExhumed.
|
|
|
|
PCExhumed is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "exhumed.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "runlist.h"
|
|
|
|
#include "roach.h"
|
|
|
|
#include "typedefs.h"
|
|
|
|
#include "sequence.h"
|
|
|
|
#include "move.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "trigdat.h"
|
|
|
|
#include "bullet.h"
|
|
|
|
#include "items.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
#define kMaxRoach 100
|
|
|
|
|
2019-08-31 09:08:38 +00:00
|
|
|
int16_t RoachSprite = -1;
|
|
|
|
int16_t RoachCount = -1;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
static actionSeq ActionSeq[] = {{ 24, 0 }, { 0, 0 }, { 0, 0 }, { 16, 0 }, { 8, 0 }, { 32, 1 }, { 42, 1 }};
|
|
|
|
|
|
|
|
struct Roach
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nHealth;
|
|
|
|
short field_2;
|
2019-11-15 20:42:46 +00:00
|
|
|
short nAction;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite;
|
|
|
|
short nTarget;
|
|
|
|
short field_A;
|
|
|
|
short field_C;
|
|
|
|
short field_E;
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Roach RoachList[kMaxRoach];
|
|
|
|
|
|
|
|
|
|
|
|
/* Kilmaat Sentry */
|
|
|
|
|
|
|
|
void InitRoachs()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachCount = kMaxRoach;
|
|
|
|
RoachSprite = 1;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2019-11-15 20:42:46 +00:00
|
|
|
// TODO - make nType a bool?
|
|
|
|
int BuildRoach(int nType, int nSprite, int x, int y, int z, short nSector, int angle)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachCount--;
|
|
|
|
if (RoachCount < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nSprite == -1)
|
|
|
|
{
|
|
|
|
nSprite = insertsprite(nSector, 105);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
changespritestat(nSprite, 105);
|
|
|
|
x = sprite[nSprite].x;
|
|
|
|
y = sprite[nSprite].y;
|
|
|
|
z = sector[sprite[nSprite].sectnum].floorz;
|
|
|
|
angle = sprite[nSprite].ang;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(nSprite >= 0 && nSprite < kMaxSprites);
|
|
|
|
|
|
|
|
sprite[nSprite].x = x;
|
|
|
|
sprite[nSprite].y = y;
|
|
|
|
sprite[nSprite].z = z;
|
2019-11-15 20:42:46 +00:00
|
|
|
sprite[nSprite].cstat = 0x101;
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].shade = -12;
|
|
|
|
sprite[nSprite].xoffset = 0;
|
|
|
|
sprite[nSprite].yoffset = 0;
|
|
|
|
sprite[nSprite].picnum = 1;
|
|
|
|
sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal;
|
|
|
|
sprite[nSprite].clipdist = 60;
|
|
|
|
sprite[nSprite].ang = angle;
|
|
|
|
sprite[nSprite].xrepeat = 40;
|
|
|
|
sprite[nSprite].yrepeat = 40;
|
|
|
|
sprite[nSprite].xvel = 0;
|
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
sprite[nSprite].zvel = 0;
|
|
|
|
sprite[nSprite].hitag = 0;
|
|
|
|
sprite[nSprite].lotag = runlist_HeadRun() + 1;
|
|
|
|
sprite[nSprite].extra = -1;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
// GrabTimeSlot(3);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-15 20:42:46 +00:00
|
|
|
if (nType)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[RoachCount].nAction = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[RoachCount].nAction = 1;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[RoachCount].nSprite = nSprite;
|
|
|
|
RoachList[RoachCount].field_2 = 0;
|
|
|
|
RoachList[RoachCount].field_C = 0;
|
|
|
|
RoachList[RoachCount].nTarget = -1;
|
|
|
|
RoachList[RoachCount].nHealth = 600;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, RoachCount | 0x1C0000);
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[RoachCount].field_A = runlist_AddRunRec(NewRun, RoachCount | 0x1C0000);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nCreaturesLeft++;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
return RoachCount | 0x1C0000;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GoRoach(short nSprite)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].xvel = (Sin(sprite[nSprite].ang + 512) >> 1) - (Sin(sprite[nSprite].ang + 512) >> 3);
|
|
|
|
sprite[nSprite].yvel = (Sin(sprite[nSprite].ang) >> 1) - (Sin(sprite[nSprite].ang) >> 3);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
void FuncRoach(int a, int nDamage, int nRun)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nRoach = RunData[nRun].nVal;
|
|
|
|
assert(nRoach >= 0 && nRoach < kMaxRoach);
|
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
bool bVar_24 = false;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite = RoachList[nRoach].nSprite;
|
2019-11-15 20:42:46 +00:00
|
|
|
short nAction = RoachList[nRoach].nAction;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
int nMessage = a & 0x7F0000;
|
|
|
|
|
|
|
|
switch (nMessage)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
DebugOut("unknown msg %d for Roach\n", a & 0x7F0000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x90000:
|
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
seq_PlotSequence(a & 0xFFFF, ActionSeq[nAction].a + SeqOffsets[kSeqRoach], RoachList[nRoach].field_2, ActionSeq[nAction].b);
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
case 0xA0000: // fall through to next case
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
nDamage = runlist_CheckRadialDamage(nSprite);
|
|
|
|
}
|
|
|
|
case 0x80000:
|
|
|
|
{
|
|
|
|
if (nDamage)
|
|
|
|
{
|
|
|
|
if (RoachList[nRoach].nHealth <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RoachList[nRoach].nHealth -= nDamage;
|
|
|
|
if (RoachList[nRoach].nHealth <= 0)
|
|
|
|
{
|
|
|
|
sprite[nSprite].xvel = 0;
|
2019-11-15 20:42:46 +00:00
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
sprite[nSprite].zvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].nHealth = 0;
|
2019-11-15 20:42:46 +00:00
|
|
|
sprite[nSprite].cstat &= 0xFEFE;
|
|
|
|
nCreaturesLeft++; // This seems to be incorrect in original exe? should be decrementing?
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-15 20:42:46 +00:00
|
|
|
if (nAction < 5)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
DropMagic(nSprite);
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 5;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
short nSprite2 = a & 0xFFFF;
|
2019-11-15 20:42:46 +00:00
|
|
|
if (nSprite2 >= 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
if (sprite[nSprite2].statnum < 199) {
|
|
|
|
RoachList[nRoach].nTarget = nSprite2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nAction == 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 2;
|
|
|
|
GoRoach(nSprite);
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
2019-11-15 20:42:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!RandomSize(4))
|
|
|
|
{
|
|
|
|
RoachList[nRoach].nAction = 4;
|
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x20000:
|
|
|
|
{
|
|
|
|
Gravity(nSprite);
|
|
|
|
|
2019-11-15 20:42:46 +00:00
|
|
|
int nSeq = SeqOffsets[kSeqRoach] + ActionSeq[RoachList[nRoach].nAction].a;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, RoachList[nRoach].field_2);
|
|
|
|
seq_MoveSequence(nSprite, nSeq, RoachList[nRoach].field_2);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
RoachList[nRoach].field_2++;
|
2019-11-13 16:50:52 +00:00
|
|
|
if (RoachList[nRoach].field_2 >= SeqSize[nSeq])
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-13 16:50:52 +00:00
|
|
|
bVar_24 = true;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nFlag = FrameFlag[SeqBase[nSeq] + RoachList[nRoach].field_2];
|
|
|
|
short nTarget = RoachList[nRoach].nTarget;
|
|
|
|
|
2019-11-15 20:42:46 +00:00
|
|
|
if (nAction > 5) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-15 20:42:46 +00:00
|
|
|
switch (nAction)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if (RoachList[nRoach].field_2 == 1)
|
|
|
|
{
|
|
|
|
RoachList[nRoach].field_C--;
|
|
|
|
if (RoachList[nRoach].field_C <= 0)
|
|
|
|
{
|
|
|
|
RoachList[nRoach].field_C = RandomSize(6);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
if (((nRoach & 0xF) == (totalmoves & 0xF)) && nTarget < 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
short nTarget = FindPlayer(nSprite, 50);
|
|
|
|
if (nTarget >= 0)
|
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
RoachList[nRoach].nTarget = nTarget;
|
|
|
|
GoRoach(nSprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// parltly the same as case 0...
|
2019-11-13 16:50:52 +00:00
|
|
|
if (((nRoach & 0xF) == (totalmoves & 0xF)) && nTarget < 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
short nTarget = FindPlayer(nSprite, 100);
|
|
|
|
if (nTarget >= 0)
|
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
RoachList[nRoach].nTarget = nTarget;
|
|
|
|
GoRoach(nSprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
if ((totalmoves & 0xF) == (nRoach & 0xF))
|
|
|
|
{
|
|
|
|
PlotCourseToSprite(nSprite, nTarget);
|
|
|
|
GoRoach(nSprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nVal = MoveCreatureWithCaution(nSprite);
|
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
if ((nVal & 0xC000) == 49152)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
if ((nVal & 0x3FFF) == nTarget)
|
|
|
|
{
|
|
|
|
// repeated below
|
|
|
|
RoachList[nRoach].field_E = RandomSize(2) + 1;
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 3;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
sprite[nSprite].xvel = 0;
|
|
|
|
sprite[nSprite].yvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].ang = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y);
|
|
|
|
|
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
2019-11-13 16:50:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask;
|
|
|
|
GoRoach(nSprite);
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-11-13 16:50:52 +00:00
|
|
|
else if ((nVal & 0xC000) == 32768)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
sprite[nSprite].ang = (sprite[nSprite].ang + 256) & kAngleMask;
|
|
|
|
GoRoach(nSprite);
|
|
|
|
}
|
2019-11-13 16:50:52 +00:00
|
|
|
//else if ((nVal & 0xC000) < 32768)
|
2019-08-31 07:47:15 +00:00
|
|
|
else
|
|
|
|
{
|
2019-11-13 16:50:52 +00:00
|
|
|
if (RoachList[nRoach].field_C != 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
RoachList[nRoach].field_C--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// same as above
|
|
|
|
RoachList[nRoach].field_E = RandomSize(2) + 1;
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 3;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-13 16:50:52 +00:00
|
|
|
sprite[nSprite].xvel = 0;
|
|
|
|
sprite[nSprite].yvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].ang = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].y - sprite[nSprite].y);
|
|
|
|
|
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nTarget != -1 && !(sprite[nTarget].cstat & 0x101))
|
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 1;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
RoachList[nRoach].field_C = 100;
|
|
|
|
RoachList[nRoach].nTarget = -1;
|
|
|
|
sprite[nSprite].xvel = 0;
|
2019-11-20 16:21:32 +00:00
|
|
|
sprite[nSprite].yvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2019-11-13 16:50:52 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
case 3:
|
|
|
|
{
|
2019-11-13 16:50:52 +00:00
|
|
|
if (bVar_24)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
RoachList[nRoach].field_E--;
|
|
|
|
if (RoachList[nRoach].field_E <= 0)
|
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
GoRoach(nSprite);
|
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
RoachList[nRoach].field_C = RandomSize(7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nFlag & 0x80)
|
|
|
|
{
|
|
|
|
BuildBullet(nSprite, 13, 0, 0, -1, sprite[nSprite].ang, nTarget + 10000, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
2019-11-13 16:50:52 +00:00
|
|
|
if (bVar_24)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
{
|
2019-11-13 16:50:52 +00:00
|
|
|
if (bVar_24)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
sprite[nSprite].cstat = 0;
|
2019-11-15 20:42:46 +00:00
|
|
|
RoachList[nRoach].nAction = 6;
|
2019-08-31 07:47:15 +00:00
|
|
|
RoachList[nRoach].field_2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|