2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood 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-09-21 18:59:54 +00:00
|
|
|
|
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "pragmas.h"
|
|
|
|
#include "mmulti.h"
|
|
|
|
#include "common_game.h"
|
|
|
|
|
2019-10-19 19:11:39 +00:00
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "actor.h"
|
|
|
|
#include "ai.h"
|
2020-07-25 15:56:39 +00:00
|
|
|
#include "aistate.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
#include "blood.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "dude.h"
|
|
|
|
#include "eventq.h"
|
|
|
|
#include "levels.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "seq.h"
|
2020-07-25 16:53:44 +00:00
|
|
|
#include "sound.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
static void sub_7034C(spritetype *, XSPRITE *);
|
|
|
|
static void sub_70380(spritetype *, XSPRITE *);
|
|
|
|
static void sub_704D8(spritetype *, XSPRITE *);
|
|
|
|
|
|
|
|
AISTATE podIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, aiThinkTarget, NULL };
|
|
|
|
AISTATE pod13A600 = { kAiStateMove, 7, -1, 3600, NULL, aiMoveTurn, sub_70380, &podSearch };
|
|
|
|
AISTATE podSearch = { kAiStateSearch, 0, -1, 3600, NULL, aiMoveTurn, sub_7034C, &podSearch };
|
|
|
|
AISTATE pod13A638 = { kAiStateChase, 8, dword_279B34, 600, NULL, NULL, NULL, &podChase };
|
|
|
|
AISTATE podRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &podChase };
|
|
|
|
AISTATE podChase = { kAiStateChase, 6, -1, 0, NULL, aiMoveTurn, sub_704D8, NULL };
|
|
|
|
AISTATE tentacleIdle = { kAiStateIdle, 0, -1, 0, NULL, NULL, aiThinkTarget, NULL };
|
|
|
|
AISTATE tentacle13A6A8 = { kAiStateOther, 7, dword_279B3C, 0, NULL, NULL, NULL, &tentacle13A6C4 };
|
|
|
|
AISTATE tentacle13A6C4 = { kAiStateOther, -1, -1, 0, NULL, NULL, NULL, &tentacleChase };
|
|
|
|
AISTATE tentacle13A6E0 = { kAiStateOther, 8, dword_279B40, 0, NULL, NULL, NULL, &tentacle13A6FC };
|
|
|
|
AISTATE tentacle13A6FC = { kAiStateOther, -1, -1, 0, NULL, NULL, NULL, &tentacleIdle };
|
|
|
|
AISTATE tentacle13A718 = { kAiStateOther, 8, -1, 3600, NULL, aiMoveTurn, sub_70380, &tentacleSearch };
|
|
|
|
AISTATE tentacleSearch = { kAiStateOther, 0, -1, 3600, NULL, aiMoveTurn, sub_7034C, NULL };
|
|
|
|
AISTATE tentacle13A750 = { kAiStateOther, 6, dword_279B38, 120, NULL, NULL, NULL, &tentacleChase };
|
|
|
|
AISTATE tentacleRecoil = { kAiStateRecoil, 5, -1, 0, NULL, NULL, NULL, &tentacleChase };
|
|
|
|
AISTATE tentacleChase = { kAiStateChase, 6, -1, 0, NULL, aiMoveTurn, sub_704D8, NULL };
|
|
|
|
|
2020-11-21 15:34:32 +00:00
|
|
|
void sub_6FF08(int, int nXSprite)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
XSPRITE *pXSprite = &xsprite[nXSprite];
|
|
|
|
int nSprite = pXSprite->reference;
|
|
|
|
sfxPlay3DSound(&sprite[nSprite], 2503, -1, 0);
|
|
|
|
}
|
|
|
|
|
2020-11-21 15:34:32 +00:00
|
|
|
void sub_6FF54(int, int nXSprite)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
XSPRITE *pXSprite = &xsprite[nXSprite];
|
|
|
|
int nSprite = pXSprite->reference;
|
|
|
|
sfxPlay3DSound(&sprite[nSprite], 2500, -1, 0);
|
|
|
|
}
|
|
|
|
|
2020-11-21 15:34:32 +00:00
|
|
|
void sub_6FFA0(int, int nXSprite)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
XSPRITE *pXSprite = &xsprite[nXSprite];
|
|
|
|
int nSprite = pXSprite->reference;
|
|
|
|
spritetype *pSprite = &sprite[nSprite];
|
2020-10-11 10:38:17 +00:00
|
|
|
///assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
|
2019-10-19 19:11:39 +00:00
|
|
|
if (!(pXSprite->target >= 0 && pXSprite->target < kMaxSprites)) {
|
2020-10-11 10:38:17 +00:00
|
|
|
Printf(PRINT_HIGH, "pXSprite->target >= 0 && pXSprite->target < kMaxSprites");
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
2019-10-19 19:11:39 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
2019-10-19 19:11:39 +00:00
|
|
|
|
2020-10-11 10:38:17 +00:00
|
|
|
///assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2019-10-19 19:11:39 +00:00
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
2020-10-11 10:38:17 +00:00
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
2019-10-19 19:11:39 +00:00
|
|
|
}
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
int x = pTarget->x-pSprite->x;
|
|
|
|
int y = pTarget->y-pSprite->y;
|
|
|
|
int dz = pTarget->z-pSprite->z;
|
|
|
|
x += Random2(1000);
|
|
|
|
y += Random2(1000);
|
|
|
|
int nDist = approxDist(x, y);
|
|
|
|
int nDist2 = nDist / 540;
|
|
|
|
spritetype *pMissile = NULL;
|
|
|
|
switch (pSprite->type)
|
|
|
|
{
|
2019-10-11 21:59:39 +00:00
|
|
|
case kDudePodGreen:
|
2019-09-19 22:42:45 +00:00
|
|
|
dz += 8000;
|
|
|
|
if (pDudeInfo->seeDist*0.1 < nDist)
|
|
|
|
{
|
|
|
|
if (Chance(0x8000))
|
|
|
|
sfxPlay3DSound(pSprite, 2474, -1, 0);
|
|
|
|
else
|
|
|
|
sfxPlay3DSound(pSprite, 2475, -1, 0);
|
2019-11-08 19:57:01 +00:00
|
|
|
pMissile = actFireThing(pSprite, 0, -8000, dz/128-14500, kThingPodGreenBall, (nDist2<<23)/120);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
if (pMissile)
|
|
|
|
seqSpawn(68, 3, pMissile->extra, -1);
|
|
|
|
break;
|
2019-10-11 21:59:39 +00:00
|
|
|
case kDudePodFire:
|
2019-09-19 22:42:45 +00:00
|
|
|
dz += 8000;
|
|
|
|
if (pDudeInfo->seeDist*0.1 < nDist)
|
|
|
|
{
|
|
|
|
sfxPlay3DSound(pSprite, 2454, -1, 0);
|
2019-11-08 19:57:01 +00:00
|
|
|
pMissile = actFireThing(pSprite, 0, -8000, dz/128-14500, kThingPodFireBall, (nDist2<<23)/120);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
if (pMissile)
|
|
|
|
seqSpawn(22, 3, pMissile->extra, -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
sub_746D4(pSprite, 240);
|
|
|
|
}
|
|
|
|
|
2020-11-21 15:34:32 +00:00
|
|
|
void sub_70284(int, int nXSprite)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
XSPRITE *pXSprite = &xsprite[nXSprite];
|
|
|
|
int nSprite = pXSprite->reference;
|
|
|
|
spritetype *pSprite = &sprite[nSprite];
|
|
|
|
sfxPlay3DSound(pSprite, 2502, -1, 0);
|
|
|
|
int nDist, nBurn;
|
|
|
|
DAMAGE_TYPE dmgType;
|
2019-10-11 21:59:39 +00:00
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudeTentacleGreen:
|
|
|
|
default: // ???
|
|
|
|
nBurn = 0;
|
|
|
|
dmgType = DAMAGE_TYPE_2;
|
|
|
|
nDist = 50;
|
|
|
|
break;
|
|
|
|
case kDudeTentacleFire: // ???
|
|
|
|
nBurn = (gGameOptions.nDifficulty*120)>>2;
|
|
|
|
dmgType = DAMAGE_TYPE_3;
|
|
|
|
nDist = 75;
|
|
|
|
break;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
sub_2A620(nSprite, pSprite->x, pSprite->y, pSprite->z, pSprite->sectnum, nDist, 1, 5*(1+gGameOptions.nDifficulty), dmgType, 2, nBurn, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_7034C(spritetype *pSprite, XSPRITE *pXSprite)
|
|
|
|
{
|
|
|
|
aiChooseDirection(pSprite, pXSprite, pXSprite->goalAng);
|
|
|
|
aiThinkTarget(pSprite, pXSprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_70380(spritetype *pSprite, XSPRITE *pXSprite)
|
|
|
|
{
|
2020-10-11 10:38:17 +00:00
|
|
|
///assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2019-10-19 19:11:39 +00:00
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
2020-10-11 10:38:17 +00:00
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
2019-10-19 19:11:39 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2019-09-19 22:42:45 +00:00
|
|
|
int dx = pXSprite->targetX-pSprite->x;
|
|
|
|
int dy = pXSprite->targetY-pSprite->y;
|
|
|
|
int nAngle = getangle(dx, dy);
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
aiChooseDirection(pSprite, pXSprite, nAngle);
|
2019-10-11 21:59:39 +00:00
|
|
|
if (nDist < 512 && klabs(pSprite->ang - nAngle) < pDudeInfo->periphery) {
|
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePodGreen:
|
|
|
|
case kDudePodFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &podSearch);
|
|
|
|
break;
|
|
|
|
case kDudeTentacleGreen:
|
|
|
|
case kDudeTentacleFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &tentacleSearch);
|
|
|
|
break;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
aiThinkTarget(pSprite, pXSprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sub_704D8(spritetype *pSprite, XSPRITE *pXSprite)
|
|
|
|
{
|
2019-10-11 21:59:39 +00:00
|
|
|
if (pXSprite->target == -1) {
|
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePodGreen:
|
|
|
|
case kDudePodFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &pod13A600);
|
|
|
|
break;
|
|
|
|
case kDudeTentacleGreen:
|
|
|
|
case kDudeTentacleFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &tentacle13A718);
|
|
|
|
break;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-10-11 10:38:17 +00:00
|
|
|
///assert(pSprite->type >= kDudeBase && pSprite->type < kDudeMax);
|
2019-10-19 19:11:39 +00:00
|
|
|
if (!(pSprite->type >= kDudeBase && pSprite->type < kDudeMax)) {
|
2020-10-11 10:38:17 +00:00
|
|
|
Printf(PRINT_HIGH, "pSprite->type >= kDudeBase && pSprite->type < kDudeMax");
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
2019-10-19 19:11:39 +00:00
|
|
|
}
|
2020-02-05 21:17:05 +00:00
|
|
|
DUDEINFO *pDudeInfo = getDudeInfo(pSprite->type);
|
2020-10-11 10:38:17 +00:00
|
|
|
///assert(pXSprite->target >= 0 && pXSprite->target < kMaxSprites);
|
2019-10-19 19:11:39 +00:00
|
|
|
if (!(pXSprite->target >= 0 && pXSprite->target < kMaxSprites)) {
|
2020-10-11 10:38:17 +00:00
|
|
|
Printf(PRINT_HIGH, "pXSprite->target >= 0 && pXSprite->target < kMaxSprites");
|
2019-09-19 22:42:45 +00:00
|
|
|
return;
|
2019-10-19 19:11:39 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
spritetype *pTarget = &sprite[pXSprite->target];
|
|
|
|
XSPRITE *pXTarget = &xsprite[pTarget->extra];
|
|
|
|
int dx = pTarget->x-pSprite->x;
|
|
|
|
int dy = pTarget->y-pSprite->y;
|
|
|
|
aiChooseDirection(pSprite, pXSprite, getangle(dx, dy));
|
2019-10-11 21:59:39 +00:00
|
|
|
if (pXTarget->health == 0) {
|
|
|
|
|
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePodGreen:
|
|
|
|
case kDudePodFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &podSearch);
|
|
|
|
break;
|
|
|
|
case kDudeTentacleGreen:
|
|
|
|
case kDudeTentacleFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &tentacleSearch);
|
|
|
|
break;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nDist = approxDist(dx, dy);
|
|
|
|
if (nDist <= pDudeInfo->seeDist)
|
|
|
|
{
|
|
|
|
int nDeltaAngle = ((getangle(dx,dy)+1024-pSprite->ang)&2047)-1024;
|
|
|
|
int height = (pDudeInfo->eyeHeight*pSprite->yrepeat)<<2;
|
|
|
|
if (cansee(pTarget->x, pTarget->y, pTarget->z, pTarget->sectnum, pSprite->x, pSprite->y, pSprite->z - height, pSprite->sectnum))
|
|
|
|
{
|
|
|
|
if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery)
|
|
|
|
{
|
|
|
|
aiSetTarget(pXSprite, pXSprite->target);
|
2019-10-11 21:59:39 +00:00
|
|
|
if (klabs(nDeltaAngle) < 85 && pTarget->type != kDudePodGreen && pTarget->type != kDudePodFire) {
|
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePodGreen:
|
|
|
|
case kDudePodFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &pod13A638);
|
|
|
|
break;
|
|
|
|
case kDudeTentacleGreen:
|
|
|
|
case kDudeTentacleFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &tentacle13A750);
|
|
|
|
break;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 21:59:39 +00:00
|
|
|
switch (pSprite->type) {
|
|
|
|
case kDudePodGreen:
|
|
|
|
case kDudePodFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &pod13A600);
|
|
|
|
break;
|
|
|
|
case kDudeTentacleGreen:
|
|
|
|
case kDudeTentacleFire:
|
|
|
|
aiNewState(pSprite, pXSprite, &tentacle13A718);
|
|
|
|
break;
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
pXSprite->target = -1;
|
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|