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
|
|
|
|
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
#define kMaxBubbles 200
|
|
|
|
#define kMaxMachines 125
|
|
|
|
|
|
|
|
struct Bubble
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
short nFrame;
|
|
|
|
short nSeq;
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSprite;
|
2020-03-02 21:08:31 +00:00
|
|
|
short nRun;
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct machine
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short _0;
|
|
|
|
short nSprite;
|
|
|
|
short _4;
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
short BubbleCount = 0;
|
|
|
|
|
|
|
|
short nFreeCount;
|
|
|
|
short nMachineCount;
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
uint8_t nBubblesFree[kMaxBubbles];
|
2019-08-26 03:59:14 +00:00
|
|
|
machine Machine[kMaxMachines];
|
|
|
|
Bubble BubbleList[kMaxBubbles];
|
|
|
|
|
2019-12-26 21:00:04 +00:00
|
|
|
static SavegameHelper sgh("bubbles",
|
2019-12-27 09:52:40 +00:00
|
|
|
SV(BubbleCount),
|
|
|
|
SV(nFreeCount),
|
|
|
|
SV(nMachineCount),
|
2019-12-26 21:00:04 +00:00
|
|
|
SA(nBubblesFree),
|
|
|
|
SA(Machine),
|
|
|
|
SA(BubbleList),
|
|
|
|
nullptr);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
|
|
|
void InitBubbles()
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
BubbleCount = 0;
|
|
|
|
nMachineCount = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
for (int i = 0; i < kMaxBubbles; i++) {
|
|
|
|
nBubblesFree[i] = i;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-12-02 21:51:22 +00:00
|
|
|
nFreeCount = kMaxBubbles;
|
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;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
runlist_DoSubRunRec(sprite[nSprite].lotag - 1);
|
|
|
|
runlist_DoSubRunRec(sprite[nSprite].owner);
|
2020-03-02 21:08:31 +00:00
|
|
|
runlist_SubRunRec(BubbleList[nBubble].nRun);
|
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
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nBubblesFree[nFreeCount] = nBubble;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
nFreeCount++;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
short GetBubbleSprite(short nBubble)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
return BubbleList[nBubble].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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nFreeCount <= 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nFreeCount--;
|
|
|
|
|
|
|
|
uint8_t nBubble = nBubblesFree[nFreeCount];
|
|
|
|
|
|
|
|
int nSprite = insertsprite(nSector, 402);
|
|
|
|
assert(nSprite >= 0 && nSprite < kMaxSprites);
|
|
|
|
|
|
|
|
sprite[nSprite].x = x;
|
|
|
|
sprite[nSprite].y = y;
|
|
|
|
sprite[nSprite].z = z;
|
|
|
|
sprite[nSprite].cstat = 0;
|
|
|
|
sprite[nSprite].shade = -32;
|
|
|
|
sprite[nSprite].pal = 0;
|
|
|
|
sprite[nSprite].clipdist = 5;
|
|
|
|
sprite[nSprite].xrepeat = 40;
|
|
|
|
sprite[nSprite].yrepeat = 40;
|
|
|
|
sprite[nSprite].xoffset = 0;
|
|
|
|
sprite[nSprite].yoffset = 0;
|
|
|
|
sprite[nSprite].picnum = 1;
|
|
|
|
sprite[nSprite].ang = inita;
|
|
|
|
sprite[nSprite].xvel = 0;
|
|
|
|
sprite[nSprite].yvel = 0;
|
|
|
|
sprite[nSprite].zvel = -1200;
|
|
|
|
sprite[nSprite].hitag = -1;
|
|
|
|
sprite[nSprite].extra = -1;
|
|
|
|
sprite[nSprite].lotag = runlist_HeadRun() + 1;
|
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
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nBubble | 0x140000);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
BubbleList[nBubble].nRun = runlist_AddRunRec(NewRun, nBubble | 0x140000);
|
2019-08-31 07:47:15 +00:00
|
|
|
return nBubble | 0x140000;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 09:02:13 +00:00
|
|
|
void FuncBubble(int a, int, int nRun)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
short nBubble = RunData[nRun].nVal;
|
|
|
|
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;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
int nMessage = a & kMessageMask;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
switch (nMessage)
|
|
|
|
{
|
|
|
|
case 0x20000:
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
seq_MoveSequence(nSprite, nSeq, BubbleList[nBubble].nFrame);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
BubbleList[nBubble].nFrame++;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
if (BubbleList[nBubble].nFrame >= SeqSize[nSeq]) {
|
|
|
|
BubbleList[nBubble].nFrame = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].z += sprite[nSprite].zvel;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
short nSector = sprite[nSprite].sectnum;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (sprite[nSprite].z <= sector[nSector].ceilingz)
|
|
|
|
{
|
|
|
|
short nSectAbove = SectAbove[nSector];
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
if (sprite[nSprite].hitag > -1 && nSectAbove != -1) {
|
|
|
|
BuildAnim(-1, 70, 0, sprite[nSprite].x, sprite[nSprite].y, sector[nSectAbove].floorz, nSectAbove, 64, 0);
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-20 16:21:32 +00:00
|
|
|
DestroyBubble(nBubble);
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
case 0x90000:
|
|
|
|
{
|
2020-03-02 21:08:31 +00:00
|
|
|
seq_PlotSequence(a & 0xFFFF, nSeq, BubbleList[nBubble].nFrame, 1);
|
2019-08-31 07:47:15 +00:00
|
|
|
tsprite[a & 0xFFFF].owner = -1;
|
|
|
|
return;
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
case 0x80000:
|
|
|
|
case 0xA0000:
|
|
|
|
return;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
default:
|
2019-11-24 09:03:19 +00:00
|
|
|
Printf("unknown msg %d for Bubble\n", nMessage);
|
2019-11-20 16:21:32 +00:00
|
|
|
return;
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
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++)
|
|
|
|
{
|
|
|
|
Machine[i]._0--;
|
|
|
|
|
|
|
|
if (Machine[i]._0 <= 0)
|
|
|
|
{
|
|
|
|
Machine[i]._0 = (RandomWord() % Machine[i]._4) + 30;
|
|
|
|
|
|
|
|
int nSprite = Machine[i].nSprite;
|
|
|
|
BuildBubble(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum);
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BuildBubbleMachine(int nSprite)
|
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nMachineCount >= kMaxMachines) {
|
2020-08-23 14:24:54 +00:00
|
|
|
I_Error("too many bubble machines in level %d\n", currentLevel->levelNumber);
|
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
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
Machine[nMachineCount]._4 = 75;
|
|
|
|
Machine[nMachineCount].nSprite = nSprite;
|
|
|
|
Machine[nMachineCount]._0 = Machine[nMachineCount]._4;
|
|
|
|
nMachineCount++;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2020-03-02 21:08:31 +00:00
|
|
|
sprite[nSprite].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);
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
sprite[nSprite].hitag = nPlayer;
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|