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 "ra.h"
|
|
|
|
#include "runlist.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "exhumed.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "move.h"
|
|
|
|
#include "sequence.h"
|
2019-11-24 09:03:19 +00:00
|
|
|
#include "ps_input.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "gun.h"
|
|
|
|
#include "bullet.h"
|
|
|
|
#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
|
|
|
|
short RaCount;
|
|
|
|
|
|
|
|
static actionSeq ActionSeq[] = {
|
2020-03-02 21:08:31 +00:00
|
|
|
{2, 1},
|
|
|
|
{0, 0},
|
|
|
|
{1, 0},
|
|
|
|
{2, 0}
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
2019-12-26 21:00:04 +00:00
|
|
|
static SavegameHelper sgh("ra",
|
|
|
|
SA(Ra),
|
|
|
|
SV(RaCount),
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
|
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;
|
2019-08-31 07:47:15 +00:00
|
|
|
int nSprite = Ra[nPlayer].nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
runlist_SubRunRec(nRun);
|
|
|
|
runlist_DoSubRunRec(sprite[nSprite].owner);
|
|
|
|
runlist_FreeRun(sprite[nSprite].lotag - 1);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
mydeletesprite(nSprite);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BuildRa(short nPlayer)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nPlayerSprite = PlayerList[nPlayer].nSprite;
|
|
|
|
|
|
|
|
int nSprite = insertsprite(sprite[nPlayerSprite].sectnum, 203);
|
|
|
|
|
|
|
|
sprite[nSprite].cstat = 0x8000;
|
|
|
|
sprite[nSprite].xvel = 0;
|
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
sprite[nSprite].zvel = 0;
|
|
|
|
sprite[nSprite].extra = -1;
|
|
|
|
sprite[nSprite].lotag = runlist_HeadRun() + 1;
|
|
|
|
sprite[nSprite].hitag = 0;
|
|
|
|
sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nPlayer | 0x210000);
|
|
|
|
sprite[nSprite].pal = 1;
|
|
|
|
sprite[nSprite].xrepeat = 64;
|
|
|
|
sprite[nSprite].yrepeat = 64;
|
|
|
|
sprite[nSprite].x = sprite[nPlayerSprite].x;
|
|
|
|
sprite[nSprite].y = sprite[nPlayerSprite].y;
|
|
|
|
sprite[nSprite].z = sprite[nPlayerSprite].z;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
// GrabTimeSlot(3);
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
Ra[nPlayer].nSprite = nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nRun = runlist_AddRunRec(NewRun, nPlayer | 0x210000);
|
2019-08-31 07:47:15 +00:00
|
|
|
Ra[nPlayer].nTarget = -1;
|
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
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
return nPlayer | 0x210000;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitRa()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
RaCount = 0;
|
|
|
|
memset(Ra, 0, sizeof(RA) * kMaxPlayers);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveRaToEnemy(short nPlayer)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nTarget = Ra[nPlayer].nTarget;
|
|
|
|
short nSprite = Ra[nPlayer].nSprite;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nAction = Ra[nPlayer].nAction;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (nTarget != -1)
|
|
|
|
{
|
2019-12-02 23:19:14 +00:00
|
|
|
if (!(sprite[nTarget].cstat & 0x101) || sprite[nTarget].sectnum == MAXSECTORS)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
Ra[nPlayer].nTarget = -1;
|
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
|
|
|
|
{
|
|
|
|
if (sprite[nSprite].sectnum != sprite[nTarget].sectnum) {
|
|
|
|
mychangespritesect(nSprite, sprite[nTarget].sectnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].cstat = 0x8000;
|
|
|
|
nTarget = PlayerList[nPlayer].nSprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprite[nSprite].x = sprite[nTarget].x;
|
|
|
|
sprite[nSprite].y = sprite[nTarget].y;
|
|
|
|
sprite[nSprite].z = sprite[nTarget].z - GetSpriteHeight(nTarget);
|
|
|
|
|
|
|
|
if (sprite[nSprite].sectnum != sprite[nTarget].sectnum) {
|
|
|
|
mychangespritesect(nSprite, sprite[nTarget].sectnum);
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 16:34:59 +00:00
|
|
|
void FuncRa(int a, int UNUSED(nDamage), int nRun)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nPlayer = RunData[nRun].nVal;
|
|
|
|
short nCurrentWeapon = PlayerList[nPlayer].nCurrentWeapon;
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
short nSeq = SeqOffsets[kSeqEyeHit] + ActionSeq[Ra[nPlayer].nAction].a;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite = Ra[nPlayer].nSprite;
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
bool bVal = false;
|
|
|
|
|
|
|
|
int nMessage = a & kMessageMask;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
switch (nMessage)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
Printf("unknown msg %d for Ra\n", nMessage);
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x30000:
|
|
|
|
case 0xA0000:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x20000:
|
|
|
|
{
|
|
|
|
Ra[nPlayer].nTarget = sPlayerInput[nPlayer].nTarget;
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, Ra[nPlayer].nFrame);
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
if (Ra[nPlayer].nAction)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
seq_MoveSequence(nSprite, nSeq, Ra[nPlayer].nFrame);
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nFrame++;
|
|
|
|
if (Ra[nPlayer].nFrame >= SeqSize[nSeq])
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nFrame = 0;
|
|
|
|
bVal = true;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
switch (Ra[nPlayer].nAction)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
MoveRaToEnemy(nPlayer);
|
|
|
|
|
|
|
|
if (!Ra[nPlayer].field_C || Ra[nPlayer].nTarget <= -1)
|
|
|
|
{
|
|
|
|
sprite[nSprite].cstat = 0x8000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite[nSprite].cstat &= 0x7FFF;
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 1;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if (!Ra[nPlayer].field_C)
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
if (bVal) {
|
|
|
|
Ra[nPlayer].nAction = 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MoveRaToEnemy(nPlayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
MoveRaToEnemy(nPlayer);
|
|
|
|
|
|
|
|
if (nCurrentWeapon != kWeaponRing)
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
if (Ra[nPlayer].nFrame || Ra[nPlayer].nTarget <= -1)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
if (!bVal) {
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (PlayerList[nPlayer].nAmmo[kWeaponRing] > 0)
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
runlist_DamageEnemy(Ra[nPlayer].nTarget, PlayerList[Ra[nPlayer].nPlayer].nSprite, BulletInfo[kWeaponRing].nDamage);
|
2019-08-31 07:47:15 +00:00
|
|
|
AddAmmo(nPlayer, kWeaponRing, -WeaponInfo[kWeaponRing].d);
|
|
|
|
SetQuake(nSprite, 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 3;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
SelectNewWeapon(nPlayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
if (bVal)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
|
|
|
sprite[nSprite].cstat |= 0x8000;
|
2020-03-02 21:08:31 +00:00
|
|
|
Ra[nPlayer].nAction = 0;
|
|
|
|
Ra[nPlayer].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
Ra[nPlayer].field_C = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x90000:
|
|
|
|
{
|
|
|
|
short nSprite2 = a & 0xFFFF;
|
2020-03-02 21:08:31 +00:00
|
|
|
seq_PlotSequence(nSprite2, nSeq, Ra[nPlayer].nFrame, 1);
|
2019-08-31 07:47:15 +00:00
|
|
|
tsprite[nSprite2].owner = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|