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 "player.h"
|
|
|
|
#include "sequence.h"
|
2021-01-01 22:38:15 +00:00
|
|
|
#include "input.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
/* bjd - the content of the ra.* files originally resided in gun.c I think... */
|
|
|
|
|
|
|
|
RA Ra[kMaxPlayers]; // one Ra for each player
|
|
|
|
|
2020-10-11 09:33:28 +00:00
|
|
|
static actionSeq RaSeq[] = {
|
2020-03-02 21:08:31 +00:00
|
|
|
{2, 1},
|
|
|
|
{0, 0},
|
|
|
|
{1, 0},
|
|
|
|
{2, 0}
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
2020-11-29 23:29:34 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, RA& w, RA* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
|
|
|
arc ("frame", w.nFrame)
|
|
|
|
("action", w.nAction)
|
2021-10-19 13:06:46 +00:00
|
|
|
("sprite", w.pActor)
|
|
|
|
("target", w.pTarget)
|
2020-11-29 23:29:34 +00:00
|
|
|
("run", w.nRun)
|
|
|
|
("ata", w.field_A)
|
|
|
|
("atc", w.field_C)
|
|
|
|
("player", w.nPlayer)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
2019-12-26 21:00:04 +00:00
|
|
|
|
|
|
|
|
2020-11-29 23:29:34 +00:00
|
|
|
void SerializeRa(FSerializer& arc)
|
|
|
|
{
|
|
|
|
arc.Array("ra", Ra, PlayerCount);
|
|
|
|
}
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
void FreeRa(short nPlayer)
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
int nRun = Ra[nPlayer].nRun;
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pActor = Ra[nPlayer].pActor;
|
|
|
|
auto pSprite = &pActor->s();
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
runlist_SubRunRec(nRun);
|
2021-09-06 06:33:02 +00:00
|
|
|
runlist_DoSubRunRec(pSprite->owner);
|
|
|
|
runlist_FreeRun(pSprite->lotag - 1);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-19 13:06:46 +00:00
|
|
|
DeleteActor(pActor);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 16:37:39 +00:00
|
|
|
void BuildRa(short nPlayer)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-21 17:44:53 +00:00
|
|
|
auto pPlayerActor = PlayerList[nPlayer].Actor();
|
|
|
|
auto pPlayerSprite = &pPlayerActor->s();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-21 17:44:53 +00:00
|
|
|
auto pActor = insertActor(pPlayerSprite->sectnum, 203);
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pSprite = &pActor->s();
|
2021-09-06 06:33:02 +00:00
|
|
|
|
|
|
|
pSprite->cstat = 0x8000;
|
|
|
|
pSprite->xvel = 0;
|
|
|
|
pSprite->yvel = 0;
|
|
|
|
pSprite->zvel = 0;
|
|
|
|
pSprite->extra = -1;
|
|
|
|
pSprite->lotag = runlist_HeadRun() + 1;
|
|
|
|
pSprite->hitag = 0;
|
2021-10-15 16:37:39 +00:00
|
|
|
pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nPlayer, 0x210000);
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->pal = 1;
|
|
|
|
pSprite->xrepeat = 64;
|
|
|
|
pSprite->yrepeat = 64;
|
2021-10-21 17:44:53 +00:00
|
|
|
pSprite->pos = pPlayerSprite->pos;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
// GrabTimeSlot(3);
|
|
|
|
|
2021-10-19 13:06:46 +00:00
|
|
|
Ra[nPlayer].pActor = pActor;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 16:37:39 +00:00
|
|
|
Ra[nPlayer].nRun = runlist_AddRunRec(NewRun, nPlayer, 0x210000);
|
2021-10-19 13:06:46 +00:00
|
|
|
Ra[nPlayer].pTarget = nullptr;
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
Ra[nPlayer].nAction = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
Ra[nPlayer].field_C = 0;
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nPlayer = nPlayer;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitRa()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
memset(Ra, 0, sizeof(RA) * kMaxPlayers);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveRaToEnemy(short nPlayer)
|
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pTarget = Ra[nPlayer].pTarget;
|
|
|
|
auto pActor = Ra[nPlayer].pActor;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nAction = Ra[nPlayer].nAction;
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pSprite = &pActor->s();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-19 13:06:46 +00:00
|
|
|
if (pTarget)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pTargSprite = &pTarget->s();
|
2021-11-11 00:10:37 +00:00
|
|
|
if (!(pTargSprite->cstat & 0x101) || pTargSprite->statnum == MAXSTATUS)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
Ra[nPlayer].pTarget = nullptr;
|
2020-03-02 21:08:31 +00:00
|
|
|
if (nAction == 0 || nAction == 3) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
if (pSprite->sectnum != pTargSprite->sectnum) {
|
|
|
|
ChangeActorSect(pActor, pTargSprite->sectnum);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
if (nAction == 1 || nAction == 2)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
if (nAction) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->cstat = 0x8000;
|
2021-10-19 13:06:46 +00:00
|
|
|
pTarget = PlayerList[nPlayer].Actor();
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pTargSprite = &pTarget->s();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-19 13:06:46 +00:00
|
|
|
pSprite->x = pTargSprite->x;
|
|
|
|
pSprite->y = pTargSprite->y;
|
|
|
|
pSprite->z = pTargSprite->z - GetActorHeight(pTarget);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-19 13:06:46 +00:00
|
|
|
if (pSprite->sectnum != pTargSprite->sectnum) {
|
|
|
|
ChangeActorSect(pActor, pTargSprite->sectnum);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
void AIRa::Tick(RunListEvent* ev)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-17 14:22:25 +00:00
|
|
|
short nPlayer = RunData[ev->nRun].nObjIndex;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nCurrentWeapon = PlayerList[nPlayer].nCurrentWeapon;
|
|
|
|
|
2020-10-11 09:33:28 +00:00
|
|
|
short nSeq = SeqOffsets[kSeqEyeHit] + RaSeq[Ra[nPlayer].nAction].a;
|
2021-10-19 13:06:46 +00:00
|
|
|
auto pActor = Ra[nPlayer].pActor;
|
|
|
|
auto pSprite = &pActor->s();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
bool bVal = false;
|
|
|
|
|
2021-10-21 20:18:29 +00:00
|
|
|
Ra[nPlayer].pTarget = sPlayerInput[nPlayer].pTarget;
|
2021-10-15 20:55:44 +00:00
|
|
|
pSprite->picnum = seq_GetSeqPicnum2(nSeq, Ra[nPlayer].nFrame);
|
|
|
|
|
|
|
|
if (Ra[nPlayer].nAction)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
seq_MoveSequence(pActor, nSeq, Ra[nPlayer].nFrame);
|
2021-10-15 20:55:44 +00:00
|
|
|
|
|
|
|
Ra[nPlayer].nFrame++;
|
|
|
|
if (Ra[nPlayer].nFrame >= SeqSize[nSeq])
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 20:55:44 +00:00
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
bVal = true;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-15 20:55:44 +00:00
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
switch (Ra[nPlayer].nAction)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
MoveRaToEnemy(nPlayer);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-19 13:06:46 +00:00
|
|
|
if (!Ra[nPlayer].field_C || Ra[nPlayer].pTarget == nullptr)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 20:55:44 +00:00
|
|
|
pSprite->cstat = 0x8000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pSprite->cstat &= 0x7FFF;
|
|
|
|
Ra[nPlayer].nAction = 1;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if (!Ra[nPlayer].field_C)
|
|
|
|
{
|
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bVal) {
|
|
|
|
Ra[nPlayer].nAction = 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
MoveRaToEnemy(nPlayer);
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
MoveRaToEnemy(nPlayer);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
if (nCurrentWeapon != kWeaponRing)
|
|
|
|
{
|
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
if (Ra[nPlayer].nFrame || Ra[nPlayer].pTarget == nullptr)
|
2021-10-15 20:55:44 +00:00
|
|
|
{
|
|
|
|
if (!bVal) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PlayerList[nPlayer].nAmmo[kWeaponRing] > 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-19 13:06:46 +00:00
|
|
|
runlist_DamageEnemy(Ra[nPlayer].pTarget, PlayerList[Ra[nPlayer].nPlayer].Actor(), BulletInfo[kWeaponRing].nDamage);
|
2021-10-15 20:55:44 +00:00
|
|
|
AddAmmo(nPlayer, kWeaponRing, -WeaponInfo[kWeaponRing].d);
|
2021-10-19 13:06:46 +00:00
|
|
|
SetQuake(pActor, 100);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-15 20:55:44 +00:00
|
|
|
else
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 20:55:44 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
SelectNewWeapon(nPlayer);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 20:55:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
if (bVal)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-10-15 20:55:44 +00:00
|
|
|
pSprite->cstat |= 0x8000;
|
|
|
|
Ra[nPlayer].nAction = 0;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
Ra[nPlayer].field_C = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-15 20:55:44 +00:00
|
|
|
|
|
|
|
return;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2021-10-15 20:55:44 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AIRa::Draw(RunListEvent* ev)
|
|
|
|
{
|
2021-10-17 14:22:25 +00:00
|
|
|
short nPlayer = RunData[ev->nRun].nObjIndex;
|
2021-10-15 20:55:44 +00:00
|
|
|
short nSeq = SeqOffsets[kSeqEyeHit] + RaSeq[Ra[nPlayer].nAction].a;
|
|
|
|
|
2021-10-17 14:22:25 +00:00
|
|
|
seq_PlotSequence(ev->nParam, nSeq, Ra[nPlayer].nFrame, 1);
|
2021-10-20 20:16:50 +00:00
|
|
|
ev->pTSprite->owner = -1;
|
2021-10-15 20:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|