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 "exhumed.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "sequence.h"
|
2020-08-23 14:24:54 +00:00
|
|
|
#include "mapinfo.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
|
|
|
|
2020-10-11 11:14:32 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
kMaxBubbles = 200,
|
|
|
|
kMaxMachines = 125
|
|
|
|
};
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
struct Bubble
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
short nFrame;
|
|
|
|
short nSeq;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite;
|
2021-09-15 08:04:30 +00:00
|
|
|
short nRunIndex;
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct machine
|
|
|
|
{
|
2021-09-15 08:04:30 +00:00
|
|
|
short nCount;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite;
|
2021-09-15 08:04:30 +00:00
|
|
|
short nFrame;
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
short nMachineCount;
|
|
|
|
machine Machine[kMaxMachines];
|
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
FreeListArray<Bubble, kMaxBubbles> BubbleList;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, Bubble& w, Bubble* def)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2020-11-30 00:07:14 +00:00
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
|
|
|
arc("seq", w.nSeq)
|
|
|
|
("frame", w.nFrame)
|
2021-09-15 08:04:30 +00:00
|
|
|
("run", w.nRunIndex)
|
2020-11-30 00:07:14 +00:00
|
|
|
("sprite", w.nSprite)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, machine& w, machine* def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
2021-09-15 08:04:30 +00:00
|
|
|
arc("at0", w.nCount)
|
|
|
|
("at4", w.nFrame)
|
2020-11-30 00:07:14 +00:00
|
|
|
("sprite", w.nSprite)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
void SerializeBubbles(FSerializer& arc)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject("bubbles"))
|
|
|
|
{
|
|
|
|
arc ("machinecount", nMachineCount)
|
|
|
|
("list", BubbleList)
|
|
|
|
.Array("machines", Machine, nMachineCount)
|
|
|
|
.EndObject();
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2020-11-30 00:07:14 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
void InitBubbles()
|
|
|
|
{
|
|
|
|
nMachineCount = 0;
|
|
|
|
BubbleList.Clear();
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyBubble(short nBubble)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite = BubbleList[nBubble].nSprite;
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
runlist_DoSubRunRec(pSprite->lotag - 1);
|
|
|
|
runlist_DoSubRunRec(pSprite->owner);
|
2021-09-15 08:04:30 +00:00
|
|
|
runlist_SubRunRec(BubbleList[nBubble].nRunIndex);
|
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
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
BubbleList.Release(nBubble);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
short GetBubbleSprite(int nBubble)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2020-11-30 00:07:14 +00:00
|
|
|
return BubbleList[nBubble & 0xffff].nSprite;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BuildBubble(int x, int y, int z, short nSector)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
int nSize = RandomSize(3);
|
|
|
|
if (nSize > 4) {
|
|
|
|
nSize -= 4;
|
|
|
|
}
|
|
|
|
|
2020-11-30 00:07:14 +00:00
|
|
|
int nBubble = BubbleList.Get();
|
|
|
|
if (nBubble < 0) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nSprite = insertsprite(nSector, 402);
|
|
|
|
assert(nSprite >= 0 && nSprite < kMaxSprites);
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
|
|
|
|
|
|
|
pSprite->x = x;
|
|
|
|
pSprite->y = y;
|
|
|
|
pSprite->z = z;
|
|
|
|
pSprite->cstat = 0;
|
|
|
|
pSprite->shade = -32;
|
|
|
|
pSprite->pal = 0;
|
|
|
|
pSprite->clipdist = 5;
|
|
|
|
pSprite->xrepeat = 40;
|
|
|
|
pSprite->yrepeat = 40;
|
|
|
|
pSprite->xoffset = 0;
|
|
|
|
pSprite->yoffset = 0;
|
|
|
|
pSprite->picnum = 1;
|
|
|
|
pSprite->ang = inita;
|
|
|
|
pSprite->xvel = 0;
|
|
|
|
pSprite->yvel = 0;
|
|
|
|
pSprite->zvel = -1200;
|
|
|
|
pSprite->hitag = -1;
|
|
|
|
pSprite->extra = -1;
|
|
|
|
pSprite->lotag = runlist_HeadRun() + 1;
|
|
|
|
pSprite->backuppos();
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
// GrabTimeSlot(3);
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
BubbleList[nBubble].nSprite = nSprite;
|
2020-03-02 21:08:31 +00:00
|
|
|
BubbleList[nBubble].nFrame = 0;
|
|
|
|
BubbleList[nBubble].nSeq = SeqOffsets[kSeqBubble] + nSize;
|
2019-11-20 16:21:32 +00:00
|
|
|
|
2021-10-15 16:37:39 +00:00
|
|
|
pSprite->owner = runlist_AddRunRec(pSprite->lotag - 1, nBubble, 0x140000);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-09-15 08:04:30 +00:00
|
|
|
BubbleList[nBubble].nRunIndex = runlist_AddRunRec(NewRun, nBubble, 0x140000);
|
2019-08-31 07:47:15 +00:00
|
|
|
return nBubble | 0x140000;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
void AIBubble::Tick(RunListEvent* ev)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2021-10-15 19:07:58 +00:00
|
|
|
short nBubble = RunData[ev->nRun].nVal;
|
2019-08-31 07:47:15 +00:00
|
|
|
assert(nBubble >= 0 && nBubble < kMaxBubbles);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite = BubbleList[nBubble].nSprite;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nSeq = BubbleList[nBubble].nSeq;
|
2021-10-15 19:07:58 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
seq_MoveSequence(nSprite, nSeq, BubbleList[nBubble].nFrame);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
BubbleList[nBubble].nFrame++;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
if (BubbleList[nBubble].nFrame >= SeqSize[nSeq]) {
|
|
|
|
BubbleList[nBubble].nFrame = 0;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
pSprite->z += pSprite->zvel;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
short nSector = pSprite->sectnum;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
if (pSprite->z <= sector[nSector].ceilingz)
|
|
|
|
{
|
|
|
|
short nSectAbove = SectAbove[nSector];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
if (pSprite->hitag > -1 && nSectAbove != -1) {
|
|
|
|
BuildAnim(-1, 70, 0, pSprite->x, pSprite->y, sector[nSectAbove].floorz, nSectAbove, 64, 0);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
DestroyBubble(nBubble);
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
void AIBubble::Draw(RunListEvent* ev)
|
|
|
|
{
|
|
|
|
short nBubble = RunData[ev->nRun].nVal;
|
|
|
|
assert(nBubble >= 0 && nBubble < kMaxBubbles);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-10-15 19:07:58 +00:00
|
|
|
seq_PlotSequence(ev->nIndex, BubbleList[nBubble].nSeq, BubbleList[nBubble].nFrame, 1);
|
|
|
|
ev->pTSprite->owner = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FuncBubble(int nObject, int nMessage, int nDamage, int nRun)
|
|
|
|
{
|
|
|
|
AIBubble ai;
|
|
|
|
runlist_DispatchEvent(&ai, nObject, nMessage, nDamage, nRun);
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoBubbleMachines()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
for (int i = 0; i < nMachineCount; i++)
|
|
|
|
{
|
2021-09-15 08:04:30 +00:00
|
|
|
Machine[i].nCount--;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2021-09-15 08:04:30 +00:00
|
|
|
if (Machine[i].nCount <= 0)
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2021-09-15 08:04:30 +00:00
|
|
|
Machine[i].nCount = (RandomWord() % Machine[i].nFrame) + 30;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
int nSprite = Machine[i].nSprite;
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
|
|
|
BuildBubble(pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BuildBubbleMachine(int nSprite)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nMachineCount >= kMaxMachines) {
|
2021-05-01 21:09:24 +00:00
|
|
|
I_Error("too many bubble machines in level %s\n", currentLevel->labelName.GetChars());
|
2020-03-02 21:08:31 +00:00
|
|
|
exit(-1);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-09-15 08:04:30 +00:00
|
|
|
Machine[nMachineCount].nFrame = 75;
|
2019-08-31 07:47:15 +00:00
|
|
|
Machine[nMachineCount].nSprite = nSprite;
|
2021-09-15 08:04:30 +00:00
|
|
|
Machine[nMachineCount].nCount = Machine[nMachineCount].nFrame;
|
2019-08-31 07:47:15 +00:00
|
|
|
nMachineCount++;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
|
|
|
pSprite->cstat = 0x8000;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoBubbles(int nPlayer)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
int x, y, z;
|
|
|
|
short nSector;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
WheresMyMouth(nPlayer, &x, &y, &z, &nSector);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
int nBubble = BuildBubble(x, y, z, nSector);
|
|
|
|
int nSprite = GetBubbleSprite(nBubble);
|
2021-09-06 06:33:02 +00:00
|
|
|
auto pSprite = &sprite[nSprite];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2021-09-06 06:33:02 +00:00
|
|
|
pSprite->hitag = nPlayer;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|