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"
|
2020-08-18 07:52:08 +00:00
|
|
|
#include "aistuff.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "engine.h"
|
|
|
|
#include "exhumed.h"
|
|
|
|
#include "sequence.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2020-10-11 11:14:32 +00:00
|
|
|
enum { kMaxWasps = 100 };
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-10-11 09:33:28 +00:00
|
|
|
static short nWaspVelShift = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
short nWaspCount;
|
|
|
|
|
|
|
|
struct Wasp
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nHealth;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nFrame;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nAction;
|
|
|
|
short nSprite;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nRun;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nTarget;
|
|
|
|
short field_C;
|
|
|
|
short field_E;
|
|
|
|
short field_10;
|
|
|
|
short field_12;
|
|
|
|
short field_14;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nDamage;
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Wasp WaspList[kMaxWasps];
|
|
|
|
|
2020-10-11 09:33:28 +00:00
|
|
|
static actionSeq WaspSeq[] = {
|
2020-03-02 21:08:31 +00:00
|
|
|
{0, 0},
|
|
|
|
{0, 0},
|
|
|
|
{9, 0},
|
|
|
|
{18, 0},
|
|
|
|
{27, 1},
|
|
|
|
{28, 1},
|
|
|
|
{29, 1}
|
|
|
|
};
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-10-11 09:33:28 +00:00
|
|
|
static SavegameHelper sghwasp("wasp",
|
|
|
|
SV(nWaspVelShift),
|
2019-12-26 21:00:04 +00:00
|
|
|
SV(nWaspCount),
|
|
|
|
SA(WaspList),
|
|
|
|
nullptr);
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
void InitWasps()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
nWaspCount = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetWaspVel(short nSprite)
|
|
|
|
{
|
2020-10-11 09:33:28 +00:00
|
|
|
if (nWaspVelShift < 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-10-11 09:33:28 +00:00
|
|
|
sprite[nSprite].xvel = Cos(sprite[nSprite].ang) << -nWaspVelShift;
|
|
|
|
sprite[nSprite].yvel = Sin(sprite[nSprite].ang) << -nWaspVelShift;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-11 09:33:28 +00:00
|
|
|
sprite[nSprite].xvel = Cos(sprite[nSprite].ang) >> nWaspVelShift;
|
|
|
|
sprite[nSprite].yvel = Sin(sprite[nSprite].ang) >> nWaspVelShift;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BuildWasp(short nSprite, int x, int y, int z, short nSector, short nAngle)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nWaspCount >= kMaxWasps) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
short nWasp = nWaspCount;
|
|
|
|
nWaspCount++;
|
|
|
|
|
2020-08-18 08:28:19 +00:00
|
|
|
uint8_t bEggWasp = false;
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nSprite == -2) {
|
2020-08-18 08:28:19 +00:00
|
|
|
bEggWasp = true;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nSprite < 0)
|
|
|
|
{
|
|
|
|
nSprite = insertsprite(nSector, 107);
|
|
|
|
assert(nSprite >= 0 && nSprite < kMaxSprites);
|
|
|
|
|
|
|
|
sprite[nSprite].x = x;
|
|
|
|
sprite[nSprite].y = y;
|
|
|
|
sprite[nSprite].z = z;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nAngle = sprite[nSprite].ang;
|
|
|
|
changespritestat(nSprite, 107);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].shade = -12;
|
|
|
|
sprite[nSprite].cstat = 0x101;
|
|
|
|
sprite[nSprite].pal = sector[sprite[nSprite].sectnum].ceilingpal;
|
|
|
|
sprite[nSprite].clipdist = 70;
|
|
|
|
|
2019-11-13 15:36:31 +00:00
|
|
|
if (bEggWasp)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
sprite[nSprite].xrepeat = 20;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].yrepeat = 20;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSprite].xrepeat = 50;
|
|
|
|
sprite[nSprite].yrepeat = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].xoffset = 0;
|
|
|
|
sprite[nSprite].yoffset = 0;
|
|
|
|
sprite[nSprite].picnum = 1;
|
|
|
|
sprite[nSprite].ang = nAngle;
|
|
|
|
sprite[nSprite].xvel = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].yvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
// GrabTimeSlot(3);
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].nAction = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].nSprite = nSprite;
|
|
|
|
WaspList[nWasp].nTarget = -1;
|
|
|
|
WaspList[nWasp].nHealth = 800;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nDamage = 10;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-13 15:36:31 +00:00
|
|
|
if (bEggWasp)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
WaspList[nWasp].field_C = 60;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nDamage /= 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaspList[nWasp].field_C = RandomSize(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
WaspList[nWasp].field_E = 0;
|
|
|
|
WaspList[nWasp].field_14 = 0;
|
|
|
|
WaspList[nWasp].field_12 = 0;
|
|
|
|
WaspList[nWasp].field_10 = RandomSize(7) + 127;
|
|
|
|
|
|
|
|
sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nWasp | 0x1E0000);
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nRun = runlist_AddRunRec(NewRun, nWasp | 0x1E0000);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-08-23 12:39:14 +00:00
|
|
|
nCreaturesTotal++;
|
2019-08-31 07:47:15 +00:00
|
|
|
return nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FuncWasp(int a, int nDamage, int nRun)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nWasp = RunData[nRun].nVal;
|
|
|
|
short nSprite = WaspList[nWasp].nSprite;
|
|
|
|
short nAction = WaspList[nWasp].nAction;
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
short nTarget = -1;
|
|
|
|
|
|
|
|
bool bVal = false;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
int nMessage = a & kMessageMask;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
switch (nMessage)
|
|
|
|
{
|
|
|
|
case 0x90000:
|
|
|
|
{
|
2020-10-11 09:33:28 +00:00
|
|
|
seq_PlotSequence(a & 0xFFFF, SeqOffsets[kSeqWasp] + WaspSeq[nAction].a, WaspList[nWasp].nFrame, WaspSeq[nAction].b);
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0xA0000:
|
|
|
|
{
|
|
|
|
if (!(sprite[nSprite].cstat & 0x101))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nDamage = runlist_CheckRadialDamage(nSprite);
|
|
|
|
// fall through to case 0x80000
|
2019-12-02 14:56:24 +00:00
|
|
|
fallthrough__;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case 0x80000:
|
|
|
|
{
|
|
|
|
if (!nDamage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WaspList[nWasp].nHealth > 0)
|
|
|
|
{
|
|
|
|
WaspList[nWasp].nHealth -= nDamage;
|
|
|
|
|
|
|
|
if (WaspList[nWasp].nHealth > 0)
|
|
|
|
{
|
|
|
|
if (!RandomSize(4))
|
|
|
|
{
|
|
|
|
WaspList[nWasp].nAction = 3;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].nAction = 1;
|
|
|
|
sprite[nSprite].ang += RandomSize(9) + 768;
|
|
|
|
sprite[nSprite].ang &= kAngleMask;
|
|
|
|
|
|
|
|
WaspList[nWasp].field_12 = 3000;
|
|
|
|
|
|
|
|
sprite[nSprite].zvel = (-20) - RandomSize(6);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Wasp is dead
|
2020-10-11 09:33:28 +00:00
|
|
|
nWaspVelShift = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nAction = 4;
|
|
|
|
WaspList[nWasp].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].cstat = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].ang = (sprite[nSprite].ang + 1024) & kAngleMask;
|
|
|
|
|
|
|
|
SetWaspVel(nSprite);
|
|
|
|
|
|
|
|
sprite[nSprite].zvel = 512;
|
2020-03-02 21:08:31 +00:00
|
|
|
|
2020-08-23 12:39:14 +00:00
|
|
|
nCreaturesKilled++;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x20000:
|
|
|
|
{
|
2020-10-11 09:33:28 +00:00
|
|
|
short nSeq = SeqOffsets[kSeqWasp] + WaspSeq[nAction].a;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, WaspList[nWasp].nFrame);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
seq_MoveSequence(nSprite, nSeq, WaspList[nWasp].nFrame);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nFrame++;
|
|
|
|
if (WaspList[nWasp].nFrame >= SeqSize[nSeq])
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nFrame = 0;
|
|
|
|
bVal = true;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (WaspList[nWasp].nHealth > 0)
|
|
|
|
{
|
|
|
|
nTarget = WaspList[nWasp].nTarget;
|
|
|
|
|
|
|
|
if (nTarget > -1 && (!(sprite[nTarget].cstat & 0x101) || (SectFlag[sprite[nTarget].sectnum] & kSectUnderwater)))
|
|
|
|
{
|
|
|
|
// goto pink
|
|
|
|
WaspList[nWasp].nTarget = -1;
|
|
|
|
WaspList[nWasp].nAction = 0;
|
|
|
|
WaspList[nWasp].field_C = RandomSize(6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nAction)
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
sprite[nSprite].zvel = Sin(WaspList[nWasp].field_E) >> 4;
|
|
|
|
|
|
|
|
WaspList[nWasp].field_E += WaspList[nWasp].field_10;
|
|
|
|
WaspList[nWasp].field_E &= kAngleMask;
|
|
|
|
|
|
|
|
MoveCreature(nSprite);
|
|
|
|
|
|
|
|
if (nTarget >= 0)
|
|
|
|
{
|
|
|
|
WaspList[nWasp].field_C--;
|
|
|
|
if (WaspList[nWasp].field_C > 0)
|
|
|
|
{
|
|
|
|
PlotCourseToSprite(nSprite, nTarget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSprite].zvel = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nAction = 1;
|
|
|
|
WaspList[nWasp].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].field_12 = 1500;
|
|
|
|
WaspList[nWasp].field_C = RandomSize(5) + 60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((nWasp & 0x1F) == (totalmoves & 0x1F)) {
|
|
|
|
WaspList[nWasp].nTarget = FindPlayer(nSprite, 60);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
WaspList[nWasp].field_C--;
|
|
|
|
|
|
|
|
if (WaspList[nWasp].field_C <= 0)
|
|
|
|
{
|
|
|
|
WaspList[nWasp].nAction = 0;
|
|
|
|
WaspList[nWasp].field_C = RandomSize(6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nChaseVal = AngleChase(nSprite, nTarget, WaspList[nWasp].field_12, 0, 16);
|
|
|
|
|
|
|
|
switch (nChaseVal & 0xC000)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x8000:
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0xC000:
|
|
|
|
{
|
|
|
|
short nSprite2 = (nChaseVal & 0x3FFF);
|
|
|
|
if (nSprite2 == nTarget)
|
|
|
|
{
|
|
|
|
sprite[nSprite].xvel = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
runlist_DamageEnemy(nSprite2, nSprite, WaspList[nWasp].nDamage);
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].nAction = 2;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
if (bVal)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].ang += RandomSize(9) + 768;
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].ang &= kAngleMask;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].zvel = (-20) - RandomSize(6);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nAction = 1;
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].field_12 = 3000;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
int nMove = MoveCreature(nSprite) & 0x8000;
|
|
|
|
nMove |= 0xC000;
|
|
|
|
|
|
|
|
if (nMove)
|
|
|
|
{
|
|
|
|
sprite[nSprite].xvel = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].yvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].zvel = 1024;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nAction = 5;
|
|
|
|
WaspList[nWasp].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
short nSector = sprite[nSprite].sectnum;
|
|
|
|
|
|
|
|
sprite[nSprite].z += sprite[nSprite].zvel;
|
|
|
|
|
|
|
|
if (sprite[nSprite].z >= sector[nSector].floorz)
|
|
|
|
{
|
|
|
|
if (SectBelow[nSector] > -1)
|
|
|
|
{
|
|
|
|
BuildSplash(nSprite, nSector);
|
|
|
|
sprite[nSprite].cstat |= 0x8000;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].xvel = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
sprite[nSprite].zvel = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
WaspList[nWasp].nAction = 6;
|
2020-03-02 21:08:31 +00:00
|
|
|
WaspList[nWasp].nFrame = 0;
|
|
|
|
runlist_SubRunRec(WaspList[nWasp].nRun);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|