SBSPSS/source/enemy/npc.cpp

1405 lines
22 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"
#ifndef __LEVEL_LEVEL_H__
#include "level\level.h"
#endif
#ifndef __FILE_EQUATES_H__
#include <biglump.h>
#endif
#ifndef __SPR_UIGFX_H__
#include <uigfx.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-01-16 20:35:34 +01:00
CNpc::NPC_DATA CNpc::m_data[NPC_UNIT_TYPE_MAX] =
{
2001-01-18 22:19:43 +01:00
{ // NPC_SANDY_CHEEKS
2001-01-16 21:55:44 +01:00
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
2001-01-18 22:19:43 +01:00
NPC_CLOSE_NONE,
2001-01-18 20:18:39 +01:00
NPC_TIMER_NONE,
2001-01-16 21:55:44 +01:00
true,
2001-01-19 16:07:53 +01:00
3,
128,
2001-01-16 20:35:34 +01:00
},
2001-01-18 22:19:43 +01:00
2001-01-29 21:00:30 +01:00
{ // NPC_FALLING_ITEM
NPC_INIT_FALLING_ITEM,
NPC_SENSOR_FALLING_ITEM_USER_CLOSE,
2001-01-29 17:55:11 +01:00
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
2001-01-29 21:00:30 +01:00
NPC_CLOSE_FALLING_ITEM_FALL,
2001-01-29 17:55:11 +01:00
NPC_TIMER_NONE,
false,
3,
128,
},
{ // NPC_FISH_HOOK
NPC_INIT_FISH_HOOK,
NPC_SENSOR_FISH_HOOK_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_FISH_HOOK_RISE,
NPC_TIMER_NONE,
false,
3,
128,
},
2001-01-29 22:18:11 +01:00
{ // NPC_DUST_DEVIL
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
2048,
},
2001-01-29 22:46:54 +01:00
{ // NPC_PENDULUM
NPC_INIT_PENDULUM,
NPC_SENSOR_NONE,
NPC_MOVEMENT_PENDULUM,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
2048,
},
2001-01-30 21:30:52 +01:00
{ // NPC_FIREBALL
NPC_INIT_FIREBALL,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIREBALL,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2001-01-30 23:58:25 +01:00
40,
2001-01-30 21:30:52 +01:00
2048,
},
2001-01-18 22:19:43 +01:00
{ // NPC_SMALL_JELLYFISH_1
NPC_INIT_DEFAULT,
NPC_SENSOR_JELLYFISH_USER_CLOSE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_JELLYFISH,
NPC_CLOSE_JELLYFISH_EVADE,
NPC_TIMER_NONE,
false,
2001-01-19 16:07:53 +01:00
3,
128,
},
{ // NPC_SMALL_JELLYFISH_2
NPC_INIT_DEFAULT,
NPC_SENSOR_JELLYFISH_USER_CLOSE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_JELLYFISH,
NPC_CLOSE_JELLYFISH_EVADE,
NPC_TIMER_NONE,
false,
3,
128,
},
{ // NPC_LARGE_JELLYFISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
128,
2001-01-18 22:19:43 +01:00
},
{ // NPC_ANEMONE_1
NPC_INIT_DEFAULT,
2001-01-22 18:44:58 +01:00
NPC_SENSOR_ANEMONE_USER_CLOSE,
2001-01-18 22:19:43 +01:00
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
2001-01-22 18:44:58 +01:00
NPC_CLOSE_ANEMONE_1_ATTACK,
2001-01-18 22:19:43 +01:00
NPC_TIMER_NONE,
false,
2001-01-19 22:46:30 +01:00
0,
2001-01-19 16:07:53 +01:00
128,
2001-01-18 22:19:43 +01:00
},
2001-01-22 17:02:38 +01:00
{ // NPC_ANEMONE_2
NPC_INIT_DEFAULT,
NPC_SENSOR_ANEMONE_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_ANEMONE_2_ATTACK,
NPC_TIMER_NONE,
false,
0,
128,
},
2001-01-18 22:19:43 +01:00
{ // NPC_CLAM
NPC_INIT_DEFAULT,
NPC_SENSOR_CLAM_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_CLAM_ATTACK,
NPC_TIMER_NONE,
2001-01-19 22:46:30 +01:00
0,
2001-01-19 16:07:53 +01:00
128,
},
{ // NPC_SQUID_DART
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
5,
256,
2001-01-18 22:19:43 +01:00
},
2001-01-19 16:07:53 +01:00
{ // NPC_FISH_FOLK
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_PRICKLY_BUG
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
1,
128,
},
2001-01-19 22:46:30 +01:00
{ // NPC_SEA_SNAKE_1
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
256,
},
{ // NPC_SEA_SNAKE_2
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
3,
256,
},
{ // NPC_PUFFA_FISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_ANGLER_FISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
1,
128,
},
{ // NPC_HERMIT_CRAB
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_MINE
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_BOOGER_MONSTER
NPC_INIT_DEFAULT,
2001-01-23 20:58:19 +01:00
NPC_SENSOR_BOOGER_MONSTER_USER_CLOSE,
2001-01-19 22:46:30 +01:00
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
2001-01-23 20:58:19 +01:00
NPC_CLOSE_BOOGER_MONSTER_ATTACK,
2001-01-19 22:46:30 +01:00
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_SPIDER_CRAB
NPC_INIT_DEFAULT,
NPC_SENSOR_SPIDER_CRAB_USER_CLOSE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_SPIDER_CRAB_ATTACK,
NPC_TIMER_NONE,
false,
3,
2048,
},
{ // NPC_EYEBALL
NPC_INIT_DEFAULT,
2001-01-22 23:24:53 +01:00
NPC_SENSOR_EYEBALL_USER_CLOSE,
2001-01-19 22:46:30 +01:00
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
2001-01-22 23:24:53 +01:00
NPC_CLOSE_EYEBALL_ATTACK,
2001-01-19 22:46:30 +01:00
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_BABY_OCTOPUS
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_ZOMBIE_FISH_FOLK
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_NINJA_STARFISH
NPC_INIT_DEFAULT,
NPC_SENSOR_NINJA_STARFISH_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
2001-01-22 15:23:11 +01:00
NPC_CLOSE_GENERIC_USER_SEEK,
2001-01-19 22:46:30 +01:00
NPC_TIMER_NONE,
false,
3,
64,
},
{ // NPC_GHOST
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
2,
128,
},
{ // NPC_GHOST_PIRATE
2001-01-22 20:48:57 +01:00
NPC_INIT_GHOST_PIRATE,
2001-01-19 22:46:30 +01:00
NPC_SENSOR_GHOST_PIRATE_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_GHOST_PIRATE_ATTACK,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_FLAMING_SKULL
NPC_INIT_DEFAULT,
NPC_SENSOR_NONE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_NONE,
NPC_TIMER_NONE,
false,
0,
128,
},
{ // NPC_SHARK_MAN
NPC_INIT_DEFAULT,
NPC_SENSOR_SHARK_MAN_USER_VISIBLE,
NPC_MOVEMENT_FIXED_PATH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_SHARK_MAN_ATTACK,
NPC_TIMER_NONE,
false,
3,
2048,
},
2001-01-22 15:23:11 +01:00
{ // NPC_OIL_BLOB
NPC_INIT_DEFAULT,
NPC_SENSOR_OIL_BLOB_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_GENERIC_USER_SEEK,
NPC_TIMER_NONE,
false,
3,
64,
},
2001-01-23 18:03:27 +01:00
{ // NPC_SKULL_STOMPER
NPC_INIT_SKULL_STOMPER,
NPC_SENSOR_SKULL_STOMPER_USER_CLOSE,
NPC_MOVEMENT_STATIC,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_SKULL_STOMPER_ATTACK,
NPC_TIMER_NONE,
false,
3,
2048,
},
2001-01-25 16:45:15 +01:00
{ // NPC_MOTHER_JELLYFISH
NPC_INIT_MOTHER_JELLYFISH,
NPC_SENSOR_NONE,
NPC_MOVEMENT_MOTHER_JELLYFISH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_MOTHER_JELLYFISH_ATTACK,
NPC_TIMER_NONE,
false,
3,
256,
},
2001-01-25 18:20:08 +01:00
{ // NPC_SUB_SHARK
NPC_INIT_SUB_SHARK,
NPC_SENSOR_NONE,
NPC_MOVEMENT_SUB_SHARK,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_SUB_SHARK_ATTACK,
NPC_TIMER_NONE,
false,
3,
256,
},
2001-01-25 16:45:15 +01:00
{ // NPC_FLYING_DUTCHMAN
NPC_INIT_FLYING_DUTCHMAN,
NPC_SENSOR_NONE,
NPC_MOVEMENT_FLYING_DUTCHMAN,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_FLYING_DUTCHMAN_ATTACK,
NPC_TIMER_NONE,
false,
3,
256,
},
2001-01-25 20:57:29 +01:00
{ // NPC_IRON_DOGFISH
NPC_INIT_IRON_DOGFISH,
2001-01-25 21:30:39 +01:00
NPC_SENSOR_IRON_DOGFISH_USER_CLOSE,
2001-01-25 20:57:29 +01:00
NPC_MOVEMENT_IRON_DOGFISH,
NPC_MOVEMENT_MODIFIER_NONE,
NPC_CLOSE_IRON_DOGFISH_ATTACK,
NPC_TIMER_NONE,
false,
3,
2048,
},
2001-01-16 20:35:34 +01:00
};
void CNpc::init()
{
2001-01-30 21:30:52 +01:00
m_type = NPC_FIREBALL;
2001-01-18 20:18:39 +01:00
2001-01-22 20:14:00 +01:00
m_heading = m_fireHeading = 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-01-18 20:18:39 +01:00
Pos.vx = 100;
Pos.vy = 100;
2001-01-25 16:45:15 +01:00
m_base = Pos;
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-01-16 20:35:34 +01:00
2001-01-22 20:48:57 +01:00
m_controlFunc = NPC_CONTROL_MOVEMENT;
2001-01-16 20:35:34 +01:00
switch ( m_data[this->m_type].initFunc )
{
case NPC_INIT_DEFAULT:
2001-01-23 18:03:27 +01:00
{
2001-01-18 20:18:39 +01:00
m_npcPath.initPath();
DVECTOR newPos;
newPos.vx = 100;
newPos.vy = 10;
m_npcPath.addWaypoint( newPos );
newPos.vx = 500;
newPos.vy = 10;
m_npcPath.addWaypoint( newPos );
2001-01-26 16:16:07 +01:00
newPos.vx = 500;
2001-01-18 20:18:39 +01:00
newPos.vy = 100;
m_npcPath.addWaypoint( newPos );
newPos.vx = 100;
newPos.vy = 100;
2001-01-26 16:16:07 +01:00
m_npcPath.addWaypoint( newPos );
2001-01-18 20:18:39 +01:00
2001-01-26 16:16:07 +01:00
m_npcPath.setPathType( PONG_PATH );
2001-01-18 20:18:39 +01:00
2001-01-16 20:35:34 +01:00
break;
2001-01-23 18:03:27 +01:00
}
2001-01-16 20:35:34 +01:00
2001-01-22 20:48:57 +01:00
case NPC_INIT_GHOST_PIRATE:
m_heading = m_fireHeading = 3072;
2001-01-23 18:03:27 +01:00
break;
case NPC_INIT_SKULL_STOMPER:
{
m_heading = m_fireHeading = 1024;
m_npcPath.initPath();
DVECTOR newPos;
newPos.vx = 100;
newPos.vy = 100;
m_npcPath.addWaypoint( newPos );
newPos.vx = 100;
newPos.vy = 10;
m_npcPath.addWaypoint( newPos );
m_npcPath.setPathType( SINGLE_USE_PATH );
break;
}
2001-01-25 16:45:15 +01:00
case NPC_INIT_MOTHER_JELLYFISH:
{
m_state = MOTHER_JELLYFISH_RETURN_TO_START;
break;
}
2001-01-25 18:20:08 +01:00
case NPC_INIT_FLYING_DUTCHMAN:
2001-01-25 16:45:15 +01:00
{
m_state = FLYING_DUTCHMAN_ATTACK_PLAYER_1;
m_extendDir = EXTEND_UP;
break;
}
2001-01-25 18:20:08 +01:00
case NPC_INIT_SUB_SHARK:
{
m_state = SUB_SHARK_CYCLE;
m_extendDir = EXTEND_RIGHT;
break;
}
2001-01-25 20:57:29 +01:00
case NPC_INIT_IRON_DOGFISH:
{
m_state = IRON_DOGFISH_THUMP_1;
m_extendDir = EXTEND_RIGHT;
break;
}
2001-01-29 21:11:05 +01:00
case NPC_INIT_FALLING_ITEM:
2001-01-29 17:55:11 +01:00
{
2001-01-29 21:11:05 +01:00
m_heading = m_fireHeading = 1024;
2001-01-29 17:55:11 +01:00
m_npcPath.initPath();
DVECTOR newPos;
newPos.vx = 100;
2001-01-29 21:11:05 +01:00
newPos.vy = 200;
2001-01-29 17:55:11 +01:00
m_npcPath.addWaypoint( newPos );
2001-01-29 21:11:05 +01:00
m_npcPath.setPathType( SINGLE_USE_PATH );
break;
}
case NPC_INIT_FISH_HOOK:
{
m_heading = m_fireHeading = 3072;
m_npcPath.initPath();
DVECTOR newPos;
2001-01-29 17:55:11 +01:00
newPos.vx = 100;
newPos.vy = -100;
m_npcPath.addWaypoint( newPos );
m_npcPath.setPathType( SINGLE_USE_PATH );
break;
}
2001-01-29 22:46:54 +01:00
case NPC_INIT_PENDULUM:
{
m_extendDir = EXTEND_LEFT;
m_extension = 0;
m_heading = 1024;
break;
}
2001-01-30 21:30:52 +01:00
case NPC_INIT_FIREBALL:
{
m_npcPath.initPath();
DVECTOR newPos;
2001-01-30 23:58:25 +01:00
newPos.vx = 300;
2001-01-30 21:30:52 +01:00
newPos.vy = 100;
m_npcPath.addWaypoint( newPos );
m_npcPath.setPathType( SINGLE_USE_PATH );
2001-01-30 23:58:25 +01:00
m_extension = 0;
2001-01-30 21:30:52 +01:00
m_velocity = m_data[m_type].speed;
m_timerTimer = GameState::getOneSecondInFrames() * 4;
break;
}
2001-01-16 20:35:34 +01:00
default:
break;
}
}
void CNpc::shutdown()
{
2001-01-26 16:16:07 +01:00
m_npcPath.removeAllWaypoints();
2001-01-16 20:35:34 +01:00
}
void CNpc::think(int _frames)
{
switch ( this->m_controlFunc )
{
2001-01-29 17:55:11 +01:00
case NPC_CONTROL_NONE:
return;
2001-01-16 20:35:34 +01:00
case NPC_CONTROL_MOVEMENT:
if ( !processSensor() )
{
2001-01-18 20:18:39 +01:00
processMovement(_frames);
}
else
{
processClose(_frames);
2001-01-16 20:35:34 +01:00
}
break;
case NPC_CONTROL_SHOT:
processShot();
break;
case NPC_CONTROL_CLOSE:
2001-01-18 20:18:39 +01:00
processClose(_frames);
2001-01-16 20:35:34 +01:00
break;
case NPC_CONTROL_COLLISION:
processCollision();
break;
}
2001-01-18 20:18:39 +01:00
processTimer(_frames);
2001-01-16 20:35:34 +01:00
}
bool CNpc::processSensor()
{
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:
{
CPlayer *player = GameScene.getPlayer();
2001-01-18 20:18:39 +01:00
2001-01-18 22:19:43 +01:00
DVECTOR playerPos = player->getPos();
2001-01-18 20:18:39 +01:00
2001-01-19 22:46:30 +01:00
s32 xDist, yDist;
2001-01-18 22:19:43 +01:00
s32 xDistSqr, yDistSqr;
2001-01-18 20:18:39 +01:00
2001-01-19 22:46:30 +01:00
xDist = playerPos.vx - this->Pos.vx;
xDistSqr = xDist * xDist;
2001-01-18 20:18:39 +01:00
2001-01-19 22:46:30 +01:00
yDist = playerPos.vy - this->Pos.vy;
yDistSqr = yDist * yDist;
2001-01-18 20:18:39 +01:00
2001-01-18 22:19:43 +01:00
switch( m_sensorFunc )
{
case NPC_SENSOR_JELLYFISH_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
2001-01-19 22:46:30 +01:00
m_controlFunc = NPC_CONTROL_CLOSE;
m_evadeClockwise = ( getRnd() % 2 ) - 1;
2001-01-18 22:19:43 +01:00
return( true );
}
else
{
return( false );
}
}
2001-01-18 20:18:39 +01:00
2001-01-18 22:19:43 +01:00
case NPC_SENSOR_CLAM_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
2001-01-19 22:46:30 +01:00
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
m_movementTimer = GameState::getOneSecondInFrames() >> 3;
m_velocity = ( getRnd() % 6 ) + 1;
return( true );
}
else
{
return( false );
}
}
case NPC_SENSOR_SPIDER_CRAB_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extension = 0;
m_velocity = 5;
2001-01-25 16:45:15 +01:00
m_base = Pos;
2001-01-19 22:46:30 +01:00
if ( playerPos.vx < Pos.vx )
{
m_extendDir = EXTEND_LEFT;
}
else
{
m_extendDir = EXTEND_RIGHT;
}
return( true );
}
else
{
return( false );
}
}
2001-01-22 15:23:11 +01:00
case NPC_SENSOR_OIL_BLOB_USER_CLOSE:
2001-01-19 22:46:30 +01:00
case NPC_SENSOR_NINJA_STARFISH_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_velocity = m_data[m_type].speed;
2001-01-16 20:35:34 +01:00
2001-01-18 22:19:43 +01:00
return( true );
}
else
{
return( false );
}
}
2001-01-19 22:46:30 +01:00
case NPC_SENSOR_GHOST_PIRATE_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 10000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_extendDir = EXTEND_UP;
m_extension = 0;
m_movementTimer = GameState::getOneSecondInFrames() >> 1;
m_velocity = 4;
return( true );
}
else
{
return( false );
}
}
case NPC_SENSOR_SHARK_MAN_USER_VISIBLE:
{
s32 xDistWaypoint, yDistWaypoint;
if ( abs( xDist ) < 500 )
{
// within range
// make sure user is closer to shark man than next waypoint
s32 xDistWaypoint, yDistWaypoint;
m_npcPath.getDistToNextWaypoint( Pos, &xDistWaypoint, &yDistWaypoint );
if ( abs( xDist ) < abs( xDistWaypoint ) )
{
s16 headingToPlayer = ratan2( yDist, xDist );
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
{
// check if shark man is facing user
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-22 17:02:38 +01:00
case NPC_SENSOR_ANEMONE_USER_CLOSE:
2001-01-25 20:57:29 +01:00
case NPC_SENSOR_EYEBALL_USER_CLOSE:
2001-01-22 17:02:38 +01:00
{
2001-01-22 18:44:58 +01:00
if ( xDistSqr + yDistSqr < 40000 )
2001-01-22 17:02:38 +01:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
return( true );
}
else
{
return( false );
}
}
2001-01-25 20:57:29 +01:00
case NPC_SENSOR_SKULL_STOMPER_USER_CLOSE:
2001-01-22 23:24:53 +01:00
{
if ( xDistSqr + yDistSqr < 40000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
2001-01-26 16:16:07 +01:00
m_extendDir = EXTEND_DOWN;
2001-01-22 23:24:53 +01:00
return( true );
}
else
{
return( false );
}
}
2001-01-25 20:57:29 +01:00
case NPC_SENSOR_BOOGER_MONSTER_USER_CLOSE:
2001-01-23 18:03:27 +01:00
{
2001-01-25 20:57:29 +01:00
if ( xDistSqr + yDistSqr < 400 )
2001-01-23 18:03:27 +01:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
2001-01-25 20:57:29 +01:00
m_extendDir = EXTEND_UP;
2001-01-23 18:03:27 +01:00
return( true );
}
else
{
return( false );
}
}
2001-01-25 20:57:29 +01:00
case NPC_SENSOR_IRON_DOGFISH_USER_CLOSE:
2001-01-23 20:58:19 +01:00
{
2001-01-25 20:57:29 +01:00
if ( xDistSqr + yDistSqr < 10000 )
2001-01-23 20:58:19 +01:00
{
m_controlFunc = NPC_CONTROL_CLOSE;
return( true );
}
else
{
return( false );
}
}
2001-01-29 17:55:11 +01:00
case NPC_SENSOR_FISH_HOOK_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 400 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
return( true );
}
else
{
return( false );
}
}
2001-01-29 21:11:05 +01:00
case NPC_SENSOR_FALLING_ITEM_USER_CLOSE:
{
if ( xDistSqr + yDistSqr < 40000 )
{
m_controlFunc = NPC_CONTROL_CLOSE;
m_movementTimer = GameState::getOneSecondInFrames() * 3;
return( true );
}
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-01-18 20:18:39 +01:00
void CNpc::processMovement(int _frames)
2001-01-16 20:35:34 +01:00
{
2001-01-18 20:18:39 +01:00
if ( _frames > 2 )
2001-01-16 20:35:34 +01:00
{
2001-01-18 20:18:39 +01:00
_frames = 2;
}
2001-01-16 20:35:34 +01:00
2001-01-18 20:18:39 +01:00
s32 moveX = 0, moveY = 0;
2001-01-16 20:35:34 +01:00
2001-01-18 20:18:39 +01:00
s16 moveDist = 0;
s32 moveVel = 0;
2001-01-16 20:35:34 +01:00
2001-01-18 20:18:39 +01:00
switch( m_data[this->m_type].movementFunc )
{
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
case NPC_MOVEMENT_FIXED_PATH:
2001-01-18 20:18:39 +01:00
{
bool pathComplete;
2001-01-23 18:03:27 +01:00
bool waypointChange;
2001-01-18 20:18:39 +01:00
2001-01-23 18:03:27 +01:00
s16 headingToTarget = m_npcPath.think( Pos, &pathComplete, &waypointChange );
2001-01-18 20:18:39 +01:00
if ( !pathComplete )
{
s16 decDir, incDir;
2001-01-19 16:07:53 +01:00
s16 maxTurnRate = m_data[m_type].turnSpeed;
2001-01-18 20:18:39 +01:00
decDir = m_heading - headingToTarget;
if ( decDir < 0 )
{
decDir += ONE;
}
incDir = headingToTarget - m_heading;
if ( incDir < 0 )
{
incDir += ONE;
}
if ( decDir < incDir )
{
moveDist = -decDir;
}
else
{
moveDist = incDir;
}
2001-01-19 16:07:53 +01:00
if ( moveDist < -maxTurnRate )
2001-01-18 20:18:39 +01:00
{
2001-01-19 16:07:53 +01:00
moveDist = -maxTurnRate;
2001-01-18 20:18:39 +01:00
}
2001-01-19 16:07:53 +01:00
else if ( moveDist > maxTurnRate )
2001-01-18 20:18:39 +01:00
{
2001-01-19 16:07:53 +01:00
moveDist = maxTurnRate;
2001-01-18 20:18:39 +01:00
}
m_heading += moveDist;
m_heading = m_heading % ONE;
2001-01-22 23:24:53 +01:00
2001-01-19 16:07:53 +01:00
s32 preShiftX = _frames * m_data[m_type].speed * rcos( m_heading );
s32 preShiftY = _frames * m_data[m_type].speed * rsin( m_heading );
moveX = preShiftX >> 12;
if ( !moveX && preShiftX )
{
moveX = preShiftX / abs( preShiftX );
}
moveY = preShiftY >> 12;
if ( !moveY && preShiftY )
{
moveY = preShiftY / abs( preShiftY );
}
moveVel = ( _frames * m_data[m_type].speed ) << 8;
2001-01-18 20:18:39 +01:00
}
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
case NPC_MOVEMENT_USER_SEEK:
2001-01-18 20:18:39 +01:00
{
2001-01-16 20:35:34 +01:00
CPlayer *player;
2001-01-22 23:24:53 +01:00
2001-01-16 20:35:34 +01:00
player = GameScene.getPlayer();
break;
2001-01-18 20:18:39 +01:00
}
2001-01-16 20:35:34 +01:00
case NPC_MOVEMENT_VERTICAL:
2001-01-18 20:18:39 +01:00
{
2001-01-16 20:35:34 +01:00
Pos.vy--;
break;
2001-01-18 20:18:39 +01:00
}
2001-01-16 20:35:34 +01:00
2001-01-25 16:45:15 +01:00
case NPC_MOVEMENT_MOTHER_JELLYFISH:
{
processMotherJellyfishMovement( _frames );
break;
}
case NPC_MOVEMENT_FLYING_DUTCHMAN:
{
processFlyingDutchmanMovement( _frames );
break;
}
2001-01-25 18:20:08 +01:00
case NPC_MOVEMENT_SUB_SHARK:
{
processSubSharkMovement( _frames );
break;
}
2001-01-25 20:57:29 +01:00
case NPC_MOVEMENT_IRON_DOGFISH:
{
processIronDogfishMovement( _frames );
break;
}
2001-01-29 22:46:54 +01:00
case NPC_MOVEMENT_PENDULUM:
{
processPendulumMovement( _frames );
break;
}
2001-01-30 21:30:52 +01:00
case NPC_MOVEMENT_FIREBALL:
{
processFireballMovement( _frames );
break;
}
2001-01-16 20:35:34 +01:00
default:
break;
}
2001-01-18 20:18:39 +01:00
processMovementModifier(_frames, moveX, moveY, moveVel, moveDist);
}
2001-01-18 22:19:43 +01:00
void CNpc::processMovementModifier(int _frames, s32 distX, s32 distY, s32 dist, s16 headingChange)
2001-01-18 20:18:39 +01:00
{
switch( m_data[m_type].movementModifierFunc )
{
case NPC_MOVEMENT_MODIFIER_NONE:
{
Pos.vx += distX;
Pos.vy += distY;
break;
}
case NPC_MOVEMENT_MODIFIER_BOB:
{
break;
}
case NPC_MOVEMENT_MODIFIER_JELLYFISH:
{
2001-01-18 22:19:43 +01:00
processSmallJellyfishMovementModifier( _frames, distX, distY, dist, headingChange );
2001-01-18 20:18:39 +01:00
break;
}
}
2001-01-16 20:35:34 +01:00
}
void CNpc::processShot()
{
}
2001-01-18 20:18:39 +01:00
void CNpc::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-18 22:19:43 +01:00
case NPC_CLOSE_JELLYFISH_EVADE:
processCloseSmallJellyfishEvade( _frames );
2001-01-18 20:18:39 +01:00
2001-01-18 22:19:43 +01:00
break;
2001-01-18 20:18:39 +01:00
2001-01-18 22:19:43 +01:00
case NPC_CLOSE_CLAM_ATTACK:
processCloseClamAttack( _frames );
2001-01-18 20:18:39 +01:00
break;
2001-01-19 22:46:30 +01:00
case NPC_CLOSE_SPIDER_CRAB_ATTACK:
processCloseSpiderCrabAttack( _frames );
break;
2001-01-22 15:23:11 +01:00
case NPC_CLOSE_GENERIC_USER_SEEK:
processCloseGenericUserSeek( _frames );
2001-01-19 22:46:30 +01:00
break;
case NPC_CLOSE_GHOST_PIRATE_ATTACK:
processCloseGhostPirateAttack( _frames );
break;
case NPC_CLOSE_SHARK_MAN_ATTACK:
processCloseSharkManAttack( _frames );
break;
2001-01-22 18:44:58 +01:00
case NPC_CLOSE_ANEMONE_1_ATTACK:
processCloseAnemone1Attack( _frames );
break;
2001-01-22 17:02:38 +01:00
case NPC_CLOSE_ANEMONE_2_ATTACK:
processCloseAnemone2Attack( _frames );
2001-01-22 18:44:58 +01:00
break;
2001-01-22 23:24:53 +01:00
case NPC_CLOSE_EYEBALL_ATTACK:
processCloseEyeballAttack( _frames );
break;
2001-01-23 18:03:27 +01:00
case NPC_CLOSE_SKULL_STOMPER_ATTACK:
processCloseSkullStomperAttack( _frames );
2001-01-23 20:58:19 +01:00
break;
case NPC_CLOSE_BOOGER_MONSTER_ATTACK:
processCloseBoogerMonsterAttack( _frames );
break;
2001-01-25 16:45:15 +01:00
case NPC_CLOSE_MOTHER_JELLYFISH_ATTACK:
processCloseMotherJellyfishAttack( _frames );
break;
case NPC_CLOSE_FLYING_DUTCHMAN_ATTACK:
processCloseFlyingDutchmanAttack( _frames );
break;
2001-01-25 18:20:08 +01:00
case NPC_CLOSE_SUB_SHARK_ATTACK:
processCloseSubSharkAttack( _frames );
break;
2001-01-25 20:57:29 +01:00
case NPC_CLOSE_IRON_DOGFISH_ATTACK:
processCloseIronDogfishAttack( _frames );
2001-01-29 17:55:11 +01:00
break;
2001-01-29 21:00:30 +01:00
case NPC_CLOSE_FALLING_ITEM_FALL:
processCloseFallingItemFall( _frames );
2001-01-29 17:55:11 +01:00
break;
case NPC_CLOSE_FISH_HOOK_RISE:
processCloseFishHookRise( _frames );
break;
2001-01-18 20:18:39 +01:00
default:
break;
}
2001-01-16 20:35:34 +01:00
}
void CNpc::processCollision()
{
}
2001-01-18 20:18:39 +01:00
void CNpc::processTimer(int _frames)
2001-01-16 20:35:34 +01:00
{
2001-01-22 18:44:58 +01:00
if ( m_timerTimer > 0 )
{
this->m_timerTimer -= _frames;
}
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 )
{
this->m_timerFunc = NPC_TIMER_NONE;
2001-01-18 22:19:43 +01:00
this->m_sensorFunc = m_data[this->m_type].sensorFunc;
2001-01-18 20:18:39 +01:00
}
break;
}
default:
break;
}
2001-01-16 20:35:34 +01:00
}
void CNpc::render()
{
}
2001-01-16 21:55:44 +01:00
void CNpc::processEvent( GAME_EVENT evt, CThing *sourceThing )
{
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 USER_REQUEST_TALK_EVENT:
{
if ( m_data[this->m_type].canTalk )
{
DVECTOR sourcePos;
s32 xDiffSqr, yDiffSqr;
2001-01-16 21:55:44 +01:00
2001-01-22 23:24:53 +01:00
// check talk distance
2001-01-16 21:55:44 +01:00
2001-01-22 23:24:53 +01:00
sourcePos = sourceThing->getPos();
2001-01-16 21:55:44 +01:00
2001-01-22 23:24:53 +01:00
xDiffSqr = this->Pos.vx - sourcePos.vx;
xDiffSqr *= xDiffSqr;
2001-01-16 21:55:44 +01:00
2001-01-22 23:24:53 +01:00
yDiffSqr = this->Pos.vy - sourcePos.vy;
yDiffSqr *= yDiffSqr;
2001-01-16 21:55:44 +01:00
2001-01-30 16:02:01 +01:00
if ( xDiffSqr + yDiffSqr < 10000 )
2001-01-22 23:24:53 +01:00
{
if( !CConversation::isActive() )
{
CConversation::trigger( SCRIPTS_SPEECHTEST_DAT );
}
}
2001-01-16 21:55:44 +01:00
}
2001-01-22 23:24:53 +01:00
break;
}
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;
removeChild( sourceThing );
2001-01-23 15:14:17 +01:00
sourceThing->shutdown();
2001-01-22 23:24:53 +01:00
delete sourceThing;
break;
2001-01-16 21:55:44 +01:00
}
}
2001-01-22 23:24:53 +01:00
}