SBSPSS/source/enemy/npc.cpp

1808 lines
35 KiB
C++
Raw Normal View History

2001-01-16 22:56:29 +01:00
/*=========================================================================
npc.cpp
Author: CRB
2001-01-22 23:24:53 +01:00
Created:
2001-01-16 22:56:29 +01:00
Project: Spongebob
2001-01-22 23:24:53 +01:00
Purpose:
2001-01-16 22:56:29 +01:00
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
2001-01-16 20:35:34 +01:00
#include "enemy\npc.h"
2001-06-28 21:14:44 +02:00
#ifndef __PAD_VIBE_H__
#include "pad\vibe.h"
#endif
2001-01-16 20:35:34 +01:00
#ifndef __LEVEL_LEVEL_H__
#include "level\level.h"
#endif
#ifndef __FILE_EQUATES_H__
#include <biglump.h>
#endif
#ifndef __GAME_GAME_H__
#include "game\game.h"
#endif
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
2001-01-18 20:18:39 +01:00
#ifndef __ENEMY_NPCPATH_H__
#include "enemy\npcpath.h"
#endif
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
2001-01-22 21:57:39 +01:00
#ifndef __GAME_CONVO_H__
#include "game\convo.h"
#endif
2001-04-01 22:22:49 +02:00
#include "Gfx\actor.h"
2001-01-16 20:35:34 +01:00
2001-02-27 22:25:22 +01:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-04-04 00:01:52 +02:00
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-04-30 20:55:38 +02:00
#ifndef __PROJECTL_PRNPC_H__
#include "projectl\prnpc.h"
#endif
2001-06-12 23:47:22 +02:00
#include "fx\fx.h"
2001-04-20 17:43:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __ENEMY_NSJFISH_H__
#include "enemy\nsjfish.h"
#endif
#ifndef __ENEMY_NHCRAB_H__
#include "enemy\nhcrab.h"
#endif
#ifndef __ENEMY_NSCRAB_H__
#include "enemy\nscrab.h"
#endif
#ifndef __ENEMY_NGEN_H__
#include "enemy\ngen.h"
#endif
#ifndef __ENEMY_NANEMONE_H__
#include "enemy\nanemone.h"
#endif
#ifndef __ENEMY_NCLAM_H__
#include "enemy\nclam.h"
#endif
#ifndef __ENEMY_NOCTO_H__
#include "enemy\nocto.h"
#endif
#ifndef __ENEMY_NFFOLK_H__
#include "enemy\nffolk.h"
#endif
#ifndef __ENEMY_NBBLOB_H__
#include "enemy\nbblob.h"
#endif
#ifndef __ENEMY_NGPIRATE_H__
#include "enemy\ngpirate.h"
#endif
#ifndef __ENEMY_NPUFFA_H__
#include "enemy\npuffa.h"
#endif
#ifndef __ENEMY_NSHRKMAN_H__
#include "enemy\nshrkman.h"
#endif
#ifndef __ENEMY_NSKLFISH_H__
#include "enemy\nsklfish.h"
#endif
#ifndef __ENEMY_NEYEBALL_H__
#include "enemy\neyeball.h"
#endif
#ifndef __ENEMY_NFSKULL_H__
#include "enemy\nfskull.h"
#endif
2001-04-20 22:22:16 +02:00
#ifndef __ENEMY_NSSTOMP_H__
#include "enemy\nsstomp.h"
#endif
#ifndef __ENEMY_NBOOGER_H__
#include "enemy\nbooger.h"
#endif
#ifndef __ENEMY_NMJFISH_H__
#include "enemy\nmjfish.h"
#endif
#ifndef __ENEMY_NSSHARK_H__
#include "enemy\nsshark.h"
#endif
#ifndef __ENEMY_NWORM_H__
#include "enemy\nworm.h"
#endif
#ifndef __ENEMY_NFDUTCH_H__
#include "enemy\nfdutch.h"
#endif
#ifndef __ENEMY_NDOGFISH_H__
#include "enemy\ndogfish.h"
#endif
2001-04-24 17:01:42 +02:00
#ifndef __ENEMY_NDUSTDEV_H__
#include "enemy\ndustdev.h"
2001-04-20 22:22:16 +02:00
#endif
2001-04-21 18:58:13 +02:00
#ifndef __ENEMY_NSDART_H__
#include "enemy\nsdart.h"
#endif
#ifndef __ENEMY_NPBUG_H__
#include "enemy\npbug.h"
#endif
#ifndef __ENEMY_NSSNAKE_H__
#include "enemy\nssnake.h"
#endif
#ifndef __ENEMY_NANGLER_H__
#include "enemy\nangler.h"
#endif
#ifndef __ENEMY_NMINE_H__
#include "enemy\nmine.h"
#endif
#ifndef __ENEMY_NSTRFISH_H__
#include "enemy\nstrfish.h"
#endif
#ifndef __ENEMY_NGHOST_H__
#include "enemy\nghost.h"
#endif
#ifndef __ENEMY_NOILBLOB_H__
#include "enemy\noilblob.h"
#endif
2001-04-27 23:12:31 +02:00
#ifndef __ENEMY_NSHELL_H__
#include "enemy\nshell.h"
#endif
2001-05-09 18:04:17 +02:00
#ifndef __ENEMY_NMJBACK_H__
#include "enemy\nmjback.h"
#endif
2001-06-13 18:04:46 +02:00
#ifndef __ENEMY_NSJBACK_H__
#include "enemy\nsjback.h"
#endif
#ifndef __ENEMY_NBUTTFLY_H__
#include "enemy\nbuttfly.h"
#endif
2001-06-14 18:07:48 +02:00
#ifndef __ENEMY_NPROJJF_H__
#include "enemy\nprojjf.h"
#endif
2001-04-20 17:43:35 +02:00
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Enemy NPCs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
s32 CNpcEnemy::playerXDist;
s32 CNpcEnemy::playerYDist;
s32 CNpcEnemy::playerXDistSqr;
s32 CNpcEnemy::playerYDistSqr;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 00:09:59 +02:00
CNpcEnemy::NPC_UNIT_TYPE CNpcEnemy::getTypeFromMapEdit( u16 newType )
{
return( mapEditConvertTable[newType - NPC_ENEMY_MAPEDIT_OFFSET] );
}
2001-04-20 17:43:35 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-27 17:09:10 +02:00
2001-05-25 22:03:00 +02:00
CNpcEnemy *CNpcEnemy::Create(int enemyType)
2001-04-20 17:43:35 +02:00
{
2001-04-20 18:25:35 +02:00
CNpcEnemy *enemy;
2001-04-20 17:43:35 +02:00
2001-05-25 20:43:47 +02:00
enemy = (CNpcEnemy*)CThingManager::GetThing(TYPE_ENEMY,enemyType);
if (!enemy)
2001-04-20 18:25:35 +02:00
switch( enemyType )
{
case CNpcEnemy::NPC_SMALL_JELLYFISH_1:
2001-04-21 18:58:13 +02:00
case CNpcEnemy::NPC_SMALL_JELLYFISH_2:
2001-04-20 18:25:35 +02:00
{
enemy = new ("small jellyfish") CNpcSmallJellyfishEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_HERMIT_CRAB:
{
enemy = new ("hermit crab") CNpcHermitCrabEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_SPIDER_CRAB:
{
enemy = new ("spider crab") CNpcSpiderCrabEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_SPIDER_CRAB_SPAWNER:
{
enemy = new ("spider crab spawner") CNpcEnemyGenerator;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_ANEMONE_1:
{
enemy = new ("anemone 1") CNpcAnemone1Enemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_ANEMONE_2:
{
enemy = new ("anemone 2") CNpcAnemone2Enemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_ANEMONE_3:
{
enemy = new ("anemone 3") CNpcAnemone3Enemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_CLAM_JUMP:
{
enemy = new ("jumping clam") CNpcJumpingClamEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_CLAM_STATIC:
{
enemy = new ("static clam") CNpcStaticClamEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_BABY_OCTOPUS:
{
enemy = new ("baby octopus") CNpcBabyOctopusEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_FISH_FOLK:
case CNpcEnemy::NPC_ZOMBIE_FISH_FOLK:
{
enemy = new ("fish folk") CNpcFishFolk;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_BALL_BLOB:
{
enemy = new ("ball blob") CNpcBallBlobEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_GHOST_PIRATE:
{
enemy = new ("ghost pirate") CNpcGhostPirateEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_PUFFA_FISH:
{
enemy = new ("puffa fish") CNpcPuffaFishEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_SHARK_MAN:
{
enemy = new ("shark man") CNpcSharkManEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_SKELETAL_FISH:
{
enemy = new ("skeletal fish") CNpcSkeletalFishEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_EYEBALL:
{
enemy = new ("eyeball") CNpcEyeballEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
case CNpcEnemy::NPC_FLAMING_SKULL:
{
enemy = new ("flaming skull") CNpcFlamingSkullEnemy;
break;
}
2001-04-20 17:43:35 +02:00
2001-04-20 22:22:16 +02:00
case CNpcEnemy::NPC_SKULL_STOMPER:
{
enemy = new ("skull stomper") CNpcSkullStomperEnemy;
break;
}
case CNpcEnemy::NPC_BOOGER_MONSTER:
{
enemy = new ("booger monster") CNpcBoogerMonsterEnemy;
break;
}
case CNpcEnemy::NPC_MOTHER_JELLYFISH:
{
2001-05-25 20:43:47 +02:00
enemy = new ("mother jellyfish") CNpcMotherJellyfishEnemy;
2001-04-20 22:22:16 +02:00
break;
}
case CNpcEnemy::NPC_SUB_SHARK:
{
enemy = new ("sub shark") CNpcSubSharkEnemy;
break;
}
case CNpcEnemy::NPC_PARASITIC_WORM:
{
enemy = new ("parasitic worm") CNpcParasiticWormEnemy;
break;
}
case CNpcEnemy::NPC_FLYING_DUTCHMAN:
{
enemy = new ("flying dutchman") CNpcFlyingDutchmanEnemy;
break;
}
case CNpcEnemy::NPC_IRON_DOGFISH:
{
enemy = new ("iron dogfish") CNpcIronDogfishEnemy;
break;
}
case CNpcEnemy::NPC_DUST_DEVIL:
{
2001-04-24 17:01:42 +02:00
enemy = new ("dust devil") CNpcDustDevilEnemy;
2001-04-20 22:22:16 +02:00
break;
}
2001-04-21 18:58:13 +02:00
case CNpcEnemy::NPC_SQUID_DART:
{
enemy = new ("squid dart") CNpcSquidDartEnemy;
break;
}
case CNpcEnemy::NPC_PRICKLY_BUG:
{
enemy = new ("prickly bug") CNpcPricklyBugEnemy;
break;
}
case CNpcEnemy::NPC_SEA_SNAKE:
{
enemy = new ("sea snake") CNpcSeaSnakeEnemy;
break;
}
case CNpcEnemy::NPC_ANGLER_FISH:
{
enemy = new ("angler fish") CNpcAnglerFish;
break;
}
case CNpcEnemy::NPC_MINE:
{
enemy = new ("mine") CNpcMineEnemy;
break;
}
case CNpcEnemy::NPC_NINJA_STARFISH:
{
enemy = new ("ninja starfish") CNpcNinjaStarfishEnemy;
break;
}
case CNpcEnemy::NPC_GHOST:
{
enemy = new ("ghost") CNpcGhostEnemy;
break;
}
case CNpcEnemy::NPC_OIL_BLOB:
{
enemy = new ("oil blob") CNpcOilBlobEnemy;
break;
}
2001-04-27 23:12:31 +02:00
case CNpcEnemy::NPC_SHELL:
{
enemy = new ("shell") CNpcShellEnemy;
break;
}
2001-06-13 18:04:46 +02:00
case CNpcEnemy::NPC_SMALL_JELLYFISH_BACKGROUND:
{
enemy = new ("small jellyfish background") CNpcSmallJellyfishBackgroundEnemy;
break;
}
case CNpcEnemy::NPC_BUTTERFLY_BACKGROUND:
{
enemy = new ("butterfly background") CNpcButterflyBackgroundEnemy;
break;
}
2001-06-14 18:07:48 +02:00
case CNpcEnemy::NPC_PROJECTILE_JELLYFISH:
{
enemy = new ("projectile jellyfish") CNpcSmallJellyfishProjectileEnemy;
break;
}
2001-04-20 18:25:35 +02:00
default:
{
2001-05-25 20:43:47 +02:00
SYSTEM_DBGMSG("UNKNOWN %i\n",enemyType);
2001-04-20 18:25:35 +02:00
enemy = new ("npc enemy") CNpcEnemy;
2001-04-24 17:01:42 +02:00
ASSERT(0);
2001-04-20 18:25:35 +02:00
break;
}
}
ASSERT(enemy);
2001-04-20 17:43:35 +02:00
2001-05-25 22:03:00 +02:00
enemy->setType( (NPC_UNIT_TYPE)enemyType );
2001-05-25 20:43:47 +02:00
enemy->setThingSubType(enemyType);
2001-04-20 18:25:35 +02:00
enemy->init();
return(enemy);
2001-04-20 17:43:35 +02:00
}
2001-05-25 22:03:00 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CNpcEnemy *CNpcEnemy::Create(sThingActor *ThisActor)
{
CNpcEnemy *enemy;
NPC_UNIT_TYPE enemyType = CNpcEnemy::getTypeFromMapEdit( ThisActor->Type );
enemy = (CNpcEnemy*)Create(enemyType);
ASSERT(enemy);
return(enemy);
}
2001-04-20 00:09:59 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 18:25:35 +02:00
void CNpcEnemy::setupWaypoints( sThingActor *ThisActor )
2001-04-02 21:21:46 +02:00
{
2001-04-20 18:25:35 +02:00
u16 *PntList=(u16*)MakePtr(ThisActor,sizeof(sThingActor));
u16 newXPos, newYPos;
2001-05-30 00:07:28 +02:00
m_npcPath.setWaypointCount( ThisActor->PointCount - 1 );
2001-04-20 18:25:35 +02:00
newXPos = (u16) *PntList;
2001-05-30 00:07:28 +02:00
setWaypointPtr( PntList );
2001-04-20 18:25:35 +02:00
PntList++;
newYPos = (u16) *PntList;
PntList++;
setStartPos( newXPos, newYPos );
if ( ThisActor->PointCount > 1 )
{
2001-05-30 00:07:28 +02:00
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
2001-04-20 18:25:35 +02:00
2001-05-30 00:07:28 +02:00
setHeading( newXPos, newYPos );
2001-04-20 18:25:35 +02:00
}
2001-06-19 22:07:57 +02:00
2001-06-26 21:23:55 +02:00
setThinkArea();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::setThinkArea()
{
2001-06-19 22:07:57 +02:00
s32 minX, maxX, minY, maxY;
m_npcPath.getPathXExtents( &minX, &maxX );
m_npcPath.getPathYExtents( &minY, &maxY );
m_thinkArea.x1 = minX;
m_thinkArea.x2 = maxX;
m_thinkArea.y1 = minY;
m_thinkArea.y2 = maxY;
2001-04-02 21:21:46 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-30 00:07:28 +02:00
/*void CNpcEnemy::addWaypoint( u16 *ptr )
2001-04-02 21:21:46 +02:00
{
2001-05-30 00:07:28 +02:00
m_npcPath.addWaypoint( ptr );
}
2001-04-02 21:21:46 +02:00
2001-05-30 00:07:28 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-02 21:21:46 +02:00
2001-05-30 00:07:28 +02:00
void CNpcEnemy::addWaypoint( u16 *ptrX, u16 *ptrY )
{
m_npcPath.addWaypoint( ptrX, ptrY );
}*/
2001-04-02 21:21:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::setStartPos( s32 xPos, s32 yPos )
{
2001-05-31 18:24:48 +02:00
Pos.vx = ( xPos << 4 ) + 8;
Pos.vy = ( yPos << 4 ) + 16;
2001-04-03 17:36:31 +02:00
2001-04-07 00:21:01 +02:00
m_initPos = m_base = Pos;
2001-04-02 21:21:46 +02:00
}
2001-04-10 01:02:20 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-28 21:31:56 +02:00
void CNpcEnemy::setStartPosHighRes( s32 xPos, s32 yPos )
{
Pos.vx = xPos;
Pos.vy = yPos;
m_initPos = m_base = Pos;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-10 01:02:20 +02:00
void CNpcEnemy::setHeading( s32 xPos, s32 yPos )
{
2001-06-01 15:30:05 +02:00
m_heading = ( ratan2( ( ( yPos << 4 ) + 16 ) - Pos.vy, ( ( xPos << 4 ) + 8 ) - Pos.vx ) ) & 4095;
2001-04-10 01:02:20 +02:00
}
2001-04-03 22:03:16 +02:00
2001-04-02 21:21:46 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-27 22:25:22 +01:00
void CNpcEnemy::init()
2001-01-16 20:35:34 +01:00
{
2001-02-27 17:59:50 +01:00
CEnemyThing::init();
2001-04-20 17:43:35 +02:00
if (m_data[m_type].skelType)
{
m_actorGfx=CActorPool::GetActor((FileEquate)m_data[m_type].skelType);
}
else
{
m_actorGfx=0;
}
2001-02-27 22:25:22 +01:00
2001-02-28 22:05:39 +01:00
m_animPlaying = true;
m_animNo = m_data[m_type].initAnim;
2001-02-27 22:25:22 +01:00
m_frame = 0;
2001-01-18 20:18:39 +01:00
m_movementTimer = 0;
m_timerTimer = 0;
m_velocity = 0;
2001-01-18 22:19:43 +01:00
m_extension = 0;
2001-02-28 22:05:39 +01:00
m_reversed = false;
2001-04-07 00:21:01 +02:00
m_isActive = true;
2001-05-10 18:47:35 +02:00
m_isDying = false;
2001-01-18 20:18:39 +01:00
2001-03-05 22:29:44 +01:00
m_health = m_data[this->m_type].initHealth;
2001-03-13 21:45:51 +01:00
m_extendDir = EXTEND_RIGHT;
2001-02-12 21:03:44 +01:00
2001-01-18 20:18:39 +01:00
m_timerFunc = m_data[this->m_type].timerFunc;
m_sensorFunc = m_data[this->m_type].sensorFunc;
2001-04-19 01:12:24 +02:00
m_movementFunc = m_data[this->m_type].movementFunc;
2001-01-16 20:35:34 +01:00
2001-01-22 20:48:57 +01:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
2001-03-01 20:32:05 +01:00
m_npcPath.initPath();
2001-05-16 22:46:54 +02:00
// m_isShuttingDown = false;
2001-04-26 17:20:21 +02:00
m_drawRotation = 0;
2001-04-28 19:39:24 +02:00
m_isCaught = false;
2001-04-30 17:36:26 +02:00
m_isBlowerOn = false;
2001-05-09 23:27:23 +02:00
m_speed = m_data[m_type].speed;
2001-05-17 17:27:03 +02:00
m_heading = 0;
2001-05-17 23:07:43 +02:00
m_RGB = 0;
2001-05-11 00:19:55 +02:00
2001-06-18 21:06:43 +02:00
m_soundId = (int) NOT_PLAYING;
2001-05-11 00:19:55 +02:00
updateCollisionArea();
2001-04-04 00:01:52 +02:00
}
2001-03-30 19:26:29 +02:00
2001-04-04 00:01:52 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::postInit()
{
2001-04-20 22:22:16 +02:00
m_npcPath.setPathType( CNpcPath::PONG_PATH );
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-01-16 20:35:34 +01:00
2001-04-07 00:21:01 +02:00
void CNpcEnemy::reinit()
{
m_animPlaying = true;
m_animNo = m_data[m_type].initAnim;
m_frame = 0;
m_movementTimer = 0;
m_timerTimer = 0;
m_velocity = 0;
m_extension = 0;
m_reversed = false;
m_isActive = true;
2001-05-10 18:47:35 +02:00
m_isDying = false;
2001-04-07 00:21:01 +02:00
m_health = m_data[this->m_type].initHealth;
m_extendDir = EXTEND_RIGHT;
m_timerFunc = m_data[this->m_type].timerFunc;
m_sensorFunc = m_data[this->m_type].sensorFunc;
2001-04-19 01:12:24 +02:00
m_movementFunc = m_data[this->m_type].movementFunc;
2001-04-07 00:21:01 +02:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
Pos = m_initPos;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-27 22:25:22 +01:00
void CNpcEnemy::shutdown()
2001-01-16 20:35:34 +01:00
{
2001-06-18 21:06:43 +02:00
if ( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
2001-05-30 00:07:28 +02:00
//m_npcPath.removeAllWaypoints();
2001-02-27 17:59:50 +01:00
2001-04-25 22:04:25 +02:00
if (m_actorGfx) delete m_actorGfx;
2001-04-12 18:33:48 +02:00
2001-04-25 22:04:25 +02:00
CEnemyThing::shutdown();
}
2001-04-25 17:41:29 +02:00
2001-04-25 22:04:25 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-18 21:06:43 +02:00
void CNpcEnemy::leftThinkZone(int _frames)
{
if ( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
m_soundId = NOT_PLAYING;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-20 18:13:23 +02:00
int CNpcEnemy::getFrameCount()
{
return( m_actorGfx->getFrameCount( m_animNo ) );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-04 22:11:44 +02:00
void CNpcEnemy::processGraphicFlipping()
{
if ( m_heading > 1024 && m_heading < 3072 )
{
m_reversed = true;
}
else
{
m_reversed = false;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-15 00:59:31 +02:00
s32 CNpcEnemy::getFrameShift( int _frames )
{
return( ( _frames << 8 ) >> 1 );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-21 23:16:42 +02:00
void CNpcEnemy::processAnimFrames( int _frames )
{
2001-06-01 21:53:49 +02:00
if ( m_animPlaying && ( ( m_isDying && m_data[m_type].playDeathAnim ) || !m_isDying ) )
2001-05-21 23:16:42 +02:00
{
s32 frameCount;
frameCount = getFrameCount();
s32 frameShift = getFrameShift( _frames );
if ( ( frameCount << 8 ) - m_frame > frameShift )
{
m_frame += frameShift;
}
else
{
m_frame = ( frameCount - 1 ) << 8;
m_animPlaying = false;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-27 22:25:22 +01:00
void CNpcEnemy::think(int _frames)
2001-01-16 20:35:34 +01:00
{
2001-04-28 19:39:24 +02:00
int moveFrames = _frames;
2001-02-27 17:59:50 +01:00
2001-04-28 19:39:24 +02:00
if ( moveFrames > 2 )
2001-02-28 22:05:39 +01:00
{
2001-04-28 19:39:24 +02:00
// make sure enemies don't go berserk if too many frames are dropped
2001-04-20 17:43:35 +02:00
2001-04-28 19:39:24 +02:00
moveFrames = 2;
}
2001-04-20 18:13:23 +02:00
2001-04-28 19:39:24 +02:00
CEnemyThing::think(_frames);
2001-01-29 17:55:11 +01:00
2001-04-28 20:58:55 +02:00
processGenericGetUserDist( moveFrames, &playerXDist, &playerYDist );
2001-04-28 19:39:24 +02:00
playerXDistSqr = playerXDist * playerXDist;
playerYDistSqr = playerYDist * playerYDist;
2001-01-16 20:35:34 +01:00
2001-06-18 21:06:43 +02:00
if ( m_soundId != NOT_PLAYING )
{
if( !CSoundMediator::isSfxStillPlaying( (xmPlayingId) m_soundId ) )
{
// unlock sound if it has finished
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
m_soundId = NOT_PLAYING;
}
}
2001-04-28 19:39:24 +02:00
if ( m_isCaught )
{
processCoralBlower( moveFrames );
}
else
{
if ( m_isActive )
2001-04-07 00:21:01 +02:00
{
2001-05-21 23:16:42 +02:00
processAnimFrames( moveFrames );
2001-01-16 20:35:34 +01:00
2001-04-28 19:39:24 +02:00
switch ( this->m_controlFunc )
{
case NPC_CONTROL_NONE:
return;
2001-01-16 20:35:34 +01:00
2001-04-28 19:39:24 +02:00
case NPC_CONTROL_MOVEMENT:
if ( !processSensor() )
{
processMovement( moveFrames );
}
else
{
2001-04-28 20:58:55 +02:00
processClose( moveFrames );
2001-04-28 19:39:24 +02:00
}
2001-01-16 20:35:34 +01:00
2001-04-28 19:39:24 +02:00
break;
2001-01-16 20:35:34 +01:00
2001-04-28 19:39:24 +02:00
case NPC_CONTROL_SHOT:
2001-05-09 23:50:09 +02:00
processShot( moveFrames );
2001-01-16 20:35:34 +01:00
2001-04-28 19:39:24 +02:00
break;
2001-01-16 20:35:34 +01:00
2001-04-28 19:39:24 +02:00
case NPC_CONTROL_CLOSE:
2001-04-28 20:58:55 +02:00
processClose( moveFrames );
2001-04-02 21:25:37 +02:00
2001-04-28 19:39:24 +02:00
break;
2001-04-07 00:21:01 +02:00
2001-04-28 19:39:24 +02:00
case NPC_CONTROL_COLLISION:
processCollision();
break;
}
2001-05-04 22:11:44 +02:00
processGraphicFlipping();
2001-04-07 00:21:01 +02:00
}
2001-04-02 21:25:37 +02:00
}
2001-04-07 00:21:01 +02:00
2001-04-28 19:39:24 +02:00
if ( !m_isCaught )
{
2001-04-28 20:58:55 +02:00
processTimer( moveFrames );
2001-04-28 19:39:24 +02:00
}
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-01-16 20:35:34 +01:00
2001-05-04 20:54:27 +02:00
void CNpcEnemy::processAttackCollision()
{
//if ( m_controlFunc == NPC_CONTROL_CLOSE && m_data[m_type].closeFunc != NPC_CLOSE_NONE )
if ( m_controlFunc == NPC_CONTROL_CLOSE )
{
// only detect collision if in attack mode
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-06-12 23:47:22 +02:00
void CNpcEnemy::drawAttackEffect()
{
CRECT rect;
rect = getCollisionArea();
DVECTOR thwakPos;
s32 xDist;
CPlayer *player = GameScene.getPlayer();
DVECTOR playerPos = player->getPos();
xDist = playerPos.vx - this->Pos.vx;
if ( xDist > 0 )
{
thwakPos.vx = rect.x2;
if ( rect.x1 > thwakPos.vx )
{
thwakPos.vx = rect.x1;
}
}
else
{
thwakPos.vx = rect.x1;
if ( rect.x2 < thwakPos.vx )
{
thwakPos.vx = rect.x2;
}
}
thwakPos.vy = ( rect.y1 + rect.y2 ) >> 1;
CFX::Create( CFX::FX_TYPE_THWACK, thwakPos );
2001-06-28 21:14:44 +02:00
CPadVibrationManager::setVibration(0,CPadVibrationManager::VIBE_CHOP);
2001-06-12 23:47:22 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-03-05 22:11:51 +01:00
void CNpcEnemy::collidedWith( CThing *_thisThing )
2001-02-07 17:42:13 +01:00
{
2001-05-10 18:47:35 +02:00
if ( m_isActive && !m_isCaught && !m_isDying )
2001-02-07 17:42:13 +01:00
{
2001-04-12 21:42:10 +02:00
switch(_thisThing->getThingType())
2001-03-05 22:11:51 +01:00
{
2001-04-12 21:42:10 +02:00
case TYPE_PLAYER:
2001-03-05 22:11:51 +01:00
{
2001-04-12 21:42:10 +02:00
CPlayer *player = (CPlayer *) _thisThing;
ATTACK_STATE playerState = player->getAttackState();
2001-04-05 22:44:30 +02:00
2001-05-11 22:56:43 +02:00
if(playerState==ATTACK_STATE__NONE)
2001-03-06 21:13:16 +01:00
{
2001-05-11 22:56:43 +02:00
if ( !player->isRecoveringFromHit() )
2001-04-05 22:44:30 +02:00
{
2001-05-11 22:56:43 +02:00
switch( m_data[m_type].detectCollision )
2001-04-12 21:42:10 +02:00
{
2001-05-11 22:56:43 +02:00
case DETECT_NO_COLLISION:
2001-04-12 21:42:10 +02:00
{
2001-05-11 22:56:43 +02:00
// ignore
2001-03-06 21:13:16 +01:00
2001-05-11 22:56:43 +02:00
break;
}
2001-03-06 21:13:16 +01:00
2001-05-11 22:56:43 +02:00
case DETECT_ALL_COLLISION:
{
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
2001-04-12 21:42:10 +02:00
2001-05-11 22:56:43 +02:00
processUserCollision( _thisThing );
2001-05-10 01:14:35 +02:00
2001-05-11 22:56:43 +02:00
break;
}
2001-04-12 21:42:10 +02:00
2001-05-11 22:56:43 +02:00
case DETECT_ATTACK_COLLISION_GENERIC:
{
processAttackCollision();
processUserCollision( _thisThing );
2001-04-12 21:42:10 +02:00
2001-05-11 22:56:43 +02:00
break;
2001-04-12 21:42:10 +02:00
}
}
2001-04-05 22:44:30 +02:00
}
2001-05-11 22:56:43 +02:00
}
else
{
// player is attacking, respond appropriately
2001-04-05 22:44:30 +02:00
2001-05-11 22:56:43 +02:00
if ( m_controlFunc != NPC_CONTROL_SHOT )
2001-04-05 22:44:30 +02:00
{
2001-05-11 22:56:43 +02:00
if(playerState==ATTACK_STATE__BUTT_BOUNCE)
2001-04-12 21:42:10 +02:00
{
2001-05-11 22:56:43 +02:00
player->justButtBouncedABadGuy();
2001-04-05 22:44:30 +02:00
}
2001-05-11 22:56:43 +02:00
m_controlFunc = NPC_CONTROL_SHOT;
m_state = NPC_GENERIC_HIT_CHECK_HEALTH;
2001-06-12 23:47:22 +02:00
drawAttackEffect();
2001-04-05 22:44:30 +02:00
}
2001-03-06 21:13:16 +01:00
}
2001-04-12 21:42:10 +02:00
break;
2001-03-05 22:11:51 +01:00
}
2001-02-07 17:42:13 +01:00
2001-04-24 21:03:06 +02:00
case TYPE_ENEMY:
{
2001-04-26 23:29:44 +02:00
CNpcEnemy *enemy = (CNpcEnemy *) _thisThing;
2001-05-10 16:09:06 +02:00
if ( canCollideWithEnemy() && enemy->canCollideWithEnemy() )
2001-04-26 23:29:44 +02:00
{
processEnemyCollision( _thisThing );
}
2001-04-24 21:03:06 +02:00
break;
}
2001-04-12 21:42:10 +02:00
default:
ASSERT(0);
break;
2001-03-05 22:11:51 +01:00
}
2001-02-07 17:42:13 +01:00
}
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-07 17:42:13 +01:00
2001-02-27 22:25:22 +01:00
bool CNpcEnemy::processSensor()
2001-01-16 20:35:34 +01:00
{
2001-01-18 20:18:39 +01:00
switch( m_sensorFunc )
2001-01-16 20:35:34 +01:00
{
case NPC_SENSOR_NONE:
return( false );
2001-01-18 22:19:43 +01:00
default:
{
switch( m_sensorFunc )
{
2001-04-20 22:22:16 +02:00
case NPC_SENSOR_GENERIC_USER_CLOSE:
2001-01-19 22:46:30 +01:00
{
2001-02-07 17:42:13 +01:00
if ( playerXDistSqr + playerYDistSqr < 10000 )
2001-01-19 22:46:30 +01:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
2001-05-09 23:27:23 +02:00
m_velocity = m_speed;
2001-01-16 20:35:34 +01:00
2001-01-18 22:19:43 +01:00
return( true );
}
else
{
return( false );
}
}
2001-02-12 16:37:31 +01:00
case NPC_SENSOR_GENERIC_USER_VISIBLE:
2001-01-19 22:46:30 +01:00
{
s32 xDistWaypoint, yDistWaypoint;
2001-02-07 17:42:13 +01:00
if ( abs( playerXDist ) < 500 )
2001-01-19 22:46:30 +01:00
{
// within range
2001-02-12 16:37:31 +01:00
// make sure user is closer to npc than next waypoint
2001-01-19 22:46:30 +01:00
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
2001-02-07 17:42:13 +01:00
if ( abs( playerXDist ) < abs( xDistWaypoint ) )
2001-01-19 22:46:30 +01:00
{
2001-02-07 17:42:13 +01:00
s16 headingToPlayer = ratan2( playerYDist, playerXDist );
2001-01-19 22:46:30 +01:00
s16 decDir, incDir, moveDist;
s32 headingToWaypoint = ratan2( yDistWaypoint, xDistWaypoint );
// check waypoint is in the same direction as the user
decDir = headingToPlayer - headingToWaypoint;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToWaypoint - headingToPlayer;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist > 512 )
{
return( false );
}
else
{
2001-02-12 16:37:31 +01:00
// check if npc is facing user
2001-01-19 22:46:30 +01:00
decDir = m_heading - headingToPlayer;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToPlayer - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = decDir;
}
else
{
moveDist = incDir;
}
if ( moveDist < 1024 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_velocity = 8;
return( true );
}
else
{
return( false );
}
}
}
else
{
return( false );
}
}
else
{
return( false );
}
}
2001-01-18 22:19:43 +01:00
default:
return( false );
}
2001-01-16 20:35:34 +01:00
}
2001-01-18 22:19:43 +01:00
break;
2001-01-18 20:18:39 +01:00
}
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processMovement(int _frames)
2001-01-16 20:35:34 +01:00
{
2001-01-18 20:18:39 +01:00
s32 moveX = 0, moveY = 0;
s32 moveVel = 0;
2001-02-22 22:00:56 +01:00
s32 moveDist = 0;
2001-01-16 20:35:34 +01:00
2001-06-18 21:06:43 +02:00
if ( m_soundId == NOT_PLAYING && m_data[m_type].moveSfx < CSoundMediator::NUM_SFXIDS )
2001-05-21 23:16:42 +02:00
{
2001-06-18 21:06:43 +02:00
m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].moveSfx, true );
2001-05-21 23:16:42 +02:00
}
2001-04-19 01:12:24 +02:00
switch( m_movementFunc )
2001-01-18 20:18:39 +01:00
{
case NPC_MOVEMENT_STATIC:
{
2001-01-16 20:35:34 +01:00
break;
2001-01-18 20:18:39 +01:00
}
2001-01-16 20:35:34 +01:00
2001-04-02 17:52:09 +02:00
case NPC_MOVEMENT_STATIC_CYCLE_ANIM:
{
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].initAnim;
m_frame = 0;
}
break;
}
2001-01-16 20:35:34 +01:00
case NPC_MOVEMENT_FIXED_PATH:
2001-01-18 20:18:39 +01:00
{
2001-02-22 22:00:56 +01:00
processGenericFixedPathMove( _frames, &moveX, &moveY, &moveVel, &moveDist );
2001-01-16 20:35:34 +01:00
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
}
2001-01-16 20:35:34 +01:00
break;
2001-01-18 20:18:39 +01:00
}
2001-01-16 20:35:34 +01:00
2001-02-22 16:39:38 +01:00
case NPC_MOVEMENT_FIXED_PATH_WALK:
{
2001-02-22 22:00:56 +01:00
processGenericFixedPathWalk( _frames, &moveX, &moveY );
2001-02-22 16:39:38 +01:00
2001-04-02 17:52:09 +02:00
if ( !m_animPlaying )
{
m_animPlaying = true;
m_animNo = m_data[m_type].moveAnim;
m_frame = 0;
}
2001-02-22 16:39:38 +01:00
break;
}
2001-01-16 20:35:34 +01:00
default:
break;
}
2001-01-18 20:18:39 +01:00
2001-02-22 22:00:56 +01:00
processMovementModifier( _frames, moveX, moveY, moveVel, moveDist );
2001-01-18 20:18:39 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processMovementModifier(int _frames, s32 distX, s32 distY, s32 dist, s16 headingChange)
2001-01-18 20:18:39 +01:00
{
2001-04-20 16:48:15 +02:00
Pos.vx += distX;
Pos.vy += distY;
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-05 16:23:51 +02:00
2001-05-15 22:21:05 +02:00
u8 CNpcEnemy::hasBeenAttacked()
2001-04-05 16:23:51 +02:00
{
2001-06-01 21:53:49 +02:00
if ( m_controlFunc != NPC_CONTROL_SHOT )
{
m_controlFunc = NPC_CONTROL_SHOT;
m_state = NPC_GENERIC_HIT_CHECK_HEALTH;
}
2001-05-15 22:21:05 +02:00
return( true );
2001-04-05 16:23:51 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-27 22:25:22 +01:00
2001-05-09 23:50:09 +02:00
void CNpcEnemy::processShot( int _frames )
2001-01-16 20:35:34 +01:00
{
2001-04-05 21:03:55 +02:00
switch( m_data[m_type].shotFunc )
{
case NPC_SHOT_NONE:
{
// do nothing
2001-06-12 23:47:22 +02:00
m_controlFunc = m_oldControlFunc;
2001-04-05 21:03:55 +02:00
break;
}
2001-04-05 21:36:04 +02:00
case NPC_SHOT_GENERIC:
2001-04-05 21:03:55 +02:00
{
switch ( m_state )
{
2001-04-05 21:36:04 +02:00
case NPC_GENERIC_HIT_CHECK_HEALTH:
{
2001-05-30 00:07:28 +02:00
m_health -= 5;
if ( m_health < 0 )
2001-04-05 21:36:04 +02:00
{
m_state = NPC_GENERIC_HIT_DEATH_START;
2001-06-01 21:53:49 +02:00
m_isDying = true;
2001-04-05 21:36:04 +02:00
}
else
{
2001-05-30 00:07:28 +02:00
m_state = NPC_GENERIC_HIT_RECOIL;
2001-05-09 17:15:47 +02:00
2001-05-30 00:07:28 +02:00
m_animPlaying = true;
m_animNo = m_data[m_type].recoilAnim;
m_frame = 0;
2001-04-05 21:36:04 +02:00
}
break;
}
case NPC_GENERIC_HIT_RECOIL:
{
2001-06-28 22:29:14 +02:00
processShotRecoil( _frames );
2001-04-05 21:36:04 +02:00
break;
}
case NPC_GENERIC_HIT_DEATH_START:
2001-04-05 21:03:55 +02:00
{
2001-06-28 22:29:14 +02:00
processShotDeathStart( _frames );
2001-05-09 23:50:09 +02:00
2001-04-05 21:03:55 +02:00
break;
}
2001-04-05 21:36:04 +02:00
case NPC_GENERIC_HIT_DEATH_END:
2001-04-05 21:03:55 +02:00
{
2001-06-28 22:29:14 +02:00
processShotDeathEnd( _frames );
2001-05-10 18:47:35 +02:00
2001-06-28 22:29:14 +02:00
break;
}
}
2001-05-10 18:47:35 +02:00
2001-06-28 22:29:14 +02:00
break;
}
}
}
2001-05-09 23:50:09 +02:00
2001-06-28 22:29:14 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-09 23:50:09 +02:00
2001-06-28 22:29:14 +02:00
void CNpcEnemy::processShotRecoil( int _frames )
{
if ( !m_animPlaying )
{
m_state = 0;
m_controlFunc = NPC_CONTROL_MOVEMENT;
}
}
2001-04-12 18:33:48 +02:00
2001-06-28 22:29:14 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-05 21:03:55 +02:00
2001-06-28 22:29:14 +02:00
void CNpcEnemy::processShotDeathStart( int _frames )
{
m_animPlaying = true;
m_animNo = m_data[m_type].dieAnim;
m_frame = 0;
m_state = NPC_GENERIC_HIT_DEATH_END;
m_isDying = true;
2001-04-05 21:03:55 +02:00
2001-06-28 22:29:14 +02:00
if ( m_data[m_type].deathSfx < CSoundMediator::NUM_SFXIDS )
{
if( m_soundId != NOT_PLAYING )
{
CSoundMediator::stopAndUnlockSfx( (xmPlayingId) m_soundId );
}
m_soundId = (int) CSoundMediator::playSfx( m_data[m_type].deathSfx, true );
}
m_speed = -5;
if (m_data[m_type].skelType)
{
m_actorGfx->SetOtPos( 0 );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processShotDeathEnd( int _frames )
{
m_drawRotation += 64 * _frames;
m_drawRotation &= 4095;
Pos.vy += m_speed * _frames;
if ( m_speed < 5 )
{
m_speed++;
}
DVECTOR offset = CLevel::getCameraPos();
if ( Pos.vy - offset.vy > VidGetScrH() )
{
if ( m_data[m_type].respawning )
{
m_isActive = false;
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 4 * GameState::getOneSecondInFrames();
}
else
{
setToShutdown();
2001-04-05 21:03:55 +02:00
}
}
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processClose(int _frames)
2001-01-16 20:35:34 +01:00
{
2001-01-18 20:18:39 +01:00
switch( m_data[this->m_type].closeFunc )
{
2001-01-22 15:23:11 +01:00
case NPC_CLOSE_GENERIC_USER_SEEK:
2001-02-06 20:29:35 +01:00
{
2001-05-09 23:27:23 +02:00
processGenericGotoTarget( _frames, playerXDist, playerYDist, m_speed );
2001-01-19 22:46:30 +01:00
break;
2001-02-06 20:29:35 +01:00
}
2001-01-19 22:46:30 +01:00
2001-01-18 20:18:39 +01:00
default:
break;
}
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processCollision()
2001-01-16 20:35:34 +01:00
{
2001-04-20 00:09:59 +02:00
CPlayer *player = GameScene.getPlayer();
2001-02-07 17:42:13 +01:00
2001-05-11 21:49:41 +02:00
player->takeDamage( m_data[m_type].damageToUserType,REACT__GET_DIRECTION_FROM_THING,(CThing*)this );
2001-05-10 22:27:33 +02:00
processUserCollision( (CThing *) player );
2001-02-07 18:40:56 +01:00
2001-04-20 00:09:59 +02:00
m_controlFunc = m_oldControlFunc;
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processTimer(int _frames)
2001-01-16 20:35:34 +01:00
{
2001-01-22 18:44:58 +01:00
if ( m_timerTimer > 0 )
{
2001-04-07 00:21:01 +02:00
m_timerTimer -= _frames;
2001-01-22 18:44:58 +01:00
}
2001-01-18 20:18:39 +01:00
switch( m_timerFunc )
{
case NPC_TIMER_NONE:
{
break;
}
case NPC_TIMER_EVADE_DONE:
2001-01-18 22:19:43 +01:00
case NPC_TIMER_ATTACK_DONE:
2001-01-18 20:18:39 +01:00
{
if ( m_timerTimer <= 0 )
{
2001-04-07 00:21:01 +02:00
m_timerFunc = NPC_TIMER_NONE;
m_sensorFunc = m_data[this->m_type].sensorFunc;
}
break;
}
case NPC_TIMER_RESPAWN:
{
if ( m_timerTimer <= 0 )
{
reinit();
2001-01-18 20:18:39 +01:00
}
break;
}
default:
break;
}
2001-01-16 20:35:34 +01:00
}
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::render()
2001-01-16 20:35:34 +01:00
{
2001-04-20 00:09:59 +02:00
SprFrame = NULL;
2001-04-07 00:21:01 +02:00
if ( m_isActive )
{
CEnemyThing::render();
2001-02-27 22:25:22 +01:00
2001-05-14 23:08:03 +02:00
if (canRender())
2001-04-04 18:51:04 +02:00
{
2001-05-14 23:08:03 +02:00
DVECTOR &renderPos=getRenderPos();
2001-04-27 20:30:19 +02:00
2001-05-14 23:08:03 +02:00
SprFrame = m_actorGfx->Render(renderPos,m_animNo,( m_frame >> 8 ),m_reversed);
m_actorGfx->RotateScale( SprFrame, renderPos, m_drawRotation, 4096, 4096 );
sBBox boundingBox = m_actorGfx->GetBBox();
setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) );
setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 );
2001-04-04 18:51:04 +02:00
}
}
2001-01-16 20:35:34 +01:00
}
2001-01-16 21:55:44 +01:00
2001-02-27 22:25:22 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processEvent( GAME_EVENT evt, CThing *sourceThing )
2001-01-16 21:55:44 +01:00
{
2001-01-22 23:24:53 +01:00
switch( evt )
2001-01-16 21:55:44 +01:00
{
2001-01-22 23:24:53 +01:00
case PROJECTILE_RETURNED_TO_SOURCE_EVENT:
{
m_controlFunc = NPC_CONTROL_MOVEMENT;
m_timerFunc = NPC_TIMER_ATTACK_DONE;
m_timerTimer = GameState::getOneSecondInFrames();
m_sensorFunc = NPC_SENSOR_NONE;
2001-04-04 00:01:52 +02:00
//removeChild( sourceThing );
//sourceThing->shutdown();
//delete sourceThing;
CProjectile *projectile;
projectile = (CProjectile *) sourceThing;
projectile->setMovementType( CProjectile::PROJECTILE_FIXED );
projectile->setPosition( Pos );
2001-01-22 23:24:53 +01:00
break;
2001-01-16 21:55:44 +01:00
}
}
2001-04-07 00:21:01 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-15 22:34:37 +02:00
u8 CNpcEnemy::canBeCaughtByNet()
2001-04-07 00:21:01 +02:00
{
2001-05-10 18:47:35 +02:00
return( m_isActive && !m_isDying && m_data[m_type].canBeNetted );
2001-04-07 00:21:01 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::caughtWithNet()
{
2001-04-12 18:33:48 +02:00
if ( m_data[m_type].respawning )
2001-04-07 00:21:01 +02:00
{
2001-04-12 18:33:48 +02:00
if ( m_isActive )
{
m_isActive = false;
2001-04-07 00:21:01 +02:00
2001-04-12 18:33:48 +02:00
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 4 * GameState::getOneSecondInFrames();
}
}
else
{
2001-04-25 22:04:25 +02:00
setToShutdown();
2001-04-07 00:21:01 +02:00
}
2001-04-19 01:12:24 +02:00
}
2001-04-24 21:03:06 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int CNpcEnemy::canCollide()
{
2001-05-10 18:47:35 +02:00
return( m_isActive && !m_isDying );
2001-04-24 21:03:06 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processEnemyCollision( CThing *thisThing )
{
DVECTOR otherPos = thisThing->getPos();
DVECTOR otherDelta = thisThing->getPosDelta();
s32 xDist = Pos.vx - otherPos.vx;
s32 yDist = Pos.vy - otherPos.vy;
s16 headingFromTarget = ratan2( yDist, xDist );
2001-04-30 22:18:07 +02:00
if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) )
{
otherDelta.vx = -otherDelta.vx;
}
if ( ( yDist > 0 && otherDelta.vy < 0 ) || ( yDist < 0 && otherDelta.vy > 0 ) )
{
otherDelta.vy = -otherDelta.vy;
}
2001-04-24 21:03:06 +02:00
Pos.vx += otherDelta.vx;
2001-05-14 20:48:54 +02:00
2001-05-14 21:48:27 +02:00
if ( m_npcPath.getWaypointCount() )
{
s32 minX, maxX;
m_npcPath.getPathXExtents( &minX, &maxX );
if ( Pos.vx < minX )
{
Pos.vx = minX;
}
else if ( Pos.vx > maxX )
{
Pos.vx = maxX;
}
}
2001-05-25 20:43:47 +02:00
s32 groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, 16 );
2001-05-14 20:48:54 +02:00
if ( groundHeight < 8 )
{
Pos.vy += groundHeight;
}
else
{
Pos.vy += otherDelta.vy;
}
2001-04-24 21:03:06 +02:00
2001-04-30 21:57:49 +02:00
m_heading = headingFromTarget;
2001-04-24 21:03:06 +02:00
2001-04-30 22:32:28 +02:00
s32 waypointXDist;
s32 waypointYDist;
m_npcPath.getDistToNextWaypoint( Pos, &waypointXDist, &waypointYDist );
2001-04-30 22:18:07 +02:00
2001-04-30 22:32:28 +02:00
if ( ( xDist > 0 && waypointXDist < 0 ) || ( xDist < 0 && waypointXDist > 0 ) )
{
2001-04-30 22:18:07 +02:00
// try next waypoint to get around other enemy
2001-04-24 21:03:06 +02:00
2001-04-30 22:18:07 +02:00
m_npcPath.incPath();
}
2001-04-24 21:03:06 +02:00
}
2001-04-28 19:39:24 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-10 01:14:35 +02:00
void CNpcEnemy::processUserCollision( CThing *thisThing )
{
DVECTOR otherPos = thisThing->getPos();
DVECTOR otherDelta = thisThing->getPosDelta();
s32 xDist = Pos.vx - otherPos.vx;
s32 yDist = Pos.vy - otherPos.vy;
s16 headingFromTarget = ratan2( yDist, xDist );
2001-05-14 17:48:34 +02:00
/*if ( ( xDist > 0 && otherDelta.vx < 0 ) || ( xDist < 0 && otherDelta.vx > 0 ) )
2001-05-10 01:14:35 +02:00
{
otherDelta.vx = -otherDelta.vx;
}
if ( ( yDist > 0 && otherDelta.vy < 0 ) || ( yDist < 0 && otherDelta.vy > 0 ) )
{
otherDelta.vy = -otherDelta.vy;
}
Pos.vx += otherDelta.vx;
2001-05-10 18:47:35 +02:00
2001-05-25 20:43:47 +02:00
s32 groundHeight = CGameScene::getCollision()->getHeightFromGround( Pos.vx, Pos.vy, 16 );
2001-05-10 18:47:35 +02:00
if ( groundHeight < 8 )
{
Pos.vy += groundHeight;
}
else
{
Pos.vy += otherDelta.vy;
2001-05-14 17:48:34 +02:00
}*/
2001-05-10 01:14:35 +02:00
m_heading = headingFromTarget;
s32 waypointXDist;
s32 waypointYDist;
m_npcPath.getDistToNextWaypoint( Pos, &waypointXDist, &waypointYDist );
if ( ( xDist > 0 && waypointXDist < 0 ) || ( xDist < 0 && waypointXDist > 0 ) )
{
// try next waypoint to get around other enemy
m_npcPath.incPath();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-05-09 22:46:22 +02:00
bool CNpcEnemy::processCoralBlowerMovement( int _frames, s32 xDist, s32 yDist, u8 destroyAtTarget )
2001-04-28 19:39:24 +02:00
{
s32 moveX, moveY;
s16 headingToTarget;
2001-06-28 21:31:56 +02:00
2001-04-28 19:39:24 +02:00
headingToTarget = ratan2( yDist, xDist );
2001-06-28 22:55:01 +02:00
s32 preShiftX = _frames * 5 * rcos( headingToTarget );
s32 preShiftY = _frames * 5 * rsin( headingToTarget );
2001-04-28 19:39:24 +02:00
moveX = preShiftX >> 12;
if ( !moveX && preShiftX )
{
moveX = preShiftX / abs( preShiftX );
}
if ( xDist > 0 )
{
if ( moveX > xDist )
{
moveX = xDist;
}
}
else if ( xDist < 0 )
{
if ( moveX < xDist )
{
moveX = xDist;
}
}
else
{
moveX = 0;
}
moveY = preShiftY >> 12;
if ( !moveY && preShiftY )
{
moveY = preShiftY / abs( preShiftY );
}
if ( yDist > 0 )
{
if ( moveY > yDist )
{
moveY = yDist;
}
}
else if ( yDist < 0 )
{
if ( moveY < yDist )
{
moveY = yDist;
}
}
else
{
moveY = 0;
}
Pos.vx += moveX;
Pos.vy += moveY;
2001-04-30 20:55:38 +02:00
if ( moveX || moveY )
{
return( false );
}
else
{
2001-05-09 22:46:22 +02:00
// has reached target point
if ( destroyAtTarget )
{
if ( m_data[m_type].respawning )
{
if ( m_isActive )
{
m_isCaught = false;
m_isActive = false;
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 1 * GameState::getOneSecondInFrames();
}
}
else
{
setToShutdown();
}
}
2001-04-30 20:55:38 +02:00
return( true );
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CNpcEnemy::canBeSuckedUp()
{
return( m_data[m_type].canBeSuckedUp );
2001-04-28 19:39:24 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-30 17:42:07 +02:00
bool CNpcEnemy::suckUp( DVECTOR *suckPos, int _frames )
2001-04-28 19:39:24 +02:00
{
2001-04-30 17:36:26 +02:00
m_isCaught = true;
m_isBlowerOn = true;
2001-04-28 19:39:24 +02:00
2001-04-30 20:55:38 +02:00
bool returnVal = false;
2001-04-28 19:39:24 +02:00
switch( m_state )
{
case NPC_CORAL_BLOWER_SUCK:
{
// go to user
2001-04-30 17:42:07 +02:00
s32 targetXDist = suckPos->vx - Pos.vx;
s32 targetYDist = suckPos->vy - Pos.vy;
2001-04-28 19:39:24 +02:00
2001-05-09 22:46:22 +02:00
returnVal = processCoralBlowerMovement( _frames, targetXDist, targetYDist, true );
2001-04-28 19:39:24 +02:00
break;
}
2001-04-30 17:36:26 +02:00
case NPC_CORAL_BLOWER_RETURN:
{
m_state = NPC_CORAL_BLOWER_SUCK;
break;
}
default:
{
m_state = NPC_CORAL_BLOWER_SUCK;
m_oldState = m_state;
m_caughtPos = Pos;
break;
}
}
2001-04-30 17:42:07 +02:00
2001-04-30 20:55:38 +02:00
return( returnVal );
2001-04-30 17:36:26 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::processCoralBlower( int _frames )
{
s32 targetXDist, targetYDist;
switch( m_state )
{
case NPC_CORAL_BLOWER_SUCK:
{
if ( !m_isBlowerOn )
{
m_state = NPC_CORAL_BLOWER_RETURN;
}
break;
}
2001-04-28 19:39:24 +02:00
case NPC_CORAL_BLOWER_RETURN:
{
// go to original position
targetXDist = m_caughtPos.vx - Pos.vx;
targetYDist = m_caughtPos.vy - Pos.vy;
2001-05-09 22:46:22 +02:00
processCoralBlowerMovement( _frames, targetXDist, targetYDist, false );
2001-04-28 19:39:24 +02:00
if ( !targetXDist && !targetYDist )
{
m_state = m_oldState;
m_isCaught = false;
}
break;
}
default:
{
m_oldState = m_state;
m_state = NPC_CORAL_BLOWER_SUCK;
m_caughtPos = Pos;
break;
}
}
2001-04-30 17:36:26 +02:00
m_isBlowerOn = false;
2001-06-28 21:31:56 +02:00
}