SBSPSS/source/enemy/npc.cpp

1647 lines
31 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 __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-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-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-04-20 17:43:35 +02:00
CNpcEnemy *CNpcEnemy::Create(sThingActor *ThisActor)
{
2001-04-20 18:25:35 +02:00
CNpcEnemy *enemy;
2001-04-20 17:43:35 +02:00
2001-04-20 18:25:35 +02:00
NPC_UNIT_TYPE enemyType = CNpcEnemy::getTypeFromMapEdit( ThisActor->Type );
2001-04-20 17:43:35 +02:00
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
{
2001-04-21 00:49:10 +02:00
printf("JFish\n");
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_HERMIT_CRAB\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_SPIDER_CRAB\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_SPIDER_CRAB_SPAWNER\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_ANEMONE_1\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_ANEMONE_2\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_ANEMONE_3\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_CLAM_JUMP\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_CLAM_STATIC\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_BABY_OCTOPUS\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_FISH_FOLK\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_BALL_BLOB\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_GHOST_PIRATE\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_PUFFA_FISH\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_SHARK_MAN\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_SKELETAL_FISH\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_EYEBALL\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_FLAMING_SKULL\n");
2001-04-20 18:25:35 +02:00
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:
{
2001-04-21 00:49:10 +02:00
printf("NPC_SKULL_STOMPER\n");
2001-04-20 22:22:16 +02:00
enemy = new ("skull stomper") CNpcSkullStomperEnemy;
break;
}
case CNpcEnemy::NPC_BOOGER_MONSTER:
{
2001-04-21 00:49:10 +02:00
printf("NPC_BOOGER_MONSTER\n");
2001-04-20 22:22:16 +02:00
enemy = new ("booger monster") CNpcBoogerMonsterEnemy;
break;
}
case CNpcEnemy::NPC_MOTHER_JELLYFISH:
{
2001-04-21 00:49:10 +02:00
printf("NPC_MOTHER_JELLYFISH\n");
2001-04-20 22:22:16 +02:00
enemy = new ("mother jellyfish") CNpcMotherJellyfishEnemy;
break;
}
case CNpcEnemy::NPC_SUB_SHARK:
{
2001-04-21 00:49:10 +02:00
printf("NPC_SUB_SHARK\n");
2001-04-20 22:22:16 +02:00
enemy = new ("sub shark") CNpcSubSharkEnemy;
break;
}
case CNpcEnemy::NPC_PARASITIC_WORM:
{
2001-04-21 00:49:10 +02:00
printf("NPC_PARASITIC_WORM\n");
2001-04-20 22:22:16 +02:00
enemy = new ("parasitic worm") CNpcParasiticWormEnemy;
break;
}
case CNpcEnemy::NPC_FLYING_DUTCHMAN:
{
2001-04-21 00:49:10 +02:00
printf("NPC_FLYING_DUTCHMAN\n");
2001-04-20 22:22:16 +02:00
enemy = new ("flying dutchman") CNpcFlyingDutchmanEnemy;
break;
}
case CNpcEnemy::NPC_IRON_DOGFISH:
{
2001-04-21 00:49:10 +02:00
printf("NPC_IRON_DOGFISH\n");
2001-04-20 22:22:16 +02:00
enemy = new ("iron dogfish") CNpcIronDogfishEnemy;
break;
}
2001-04-24 17:01:42 +02:00
/*case CNpcEnemy::NPC_FALLING_ITEM:
2001-04-20 22:22:16 +02:00
{
2001-04-21 00:49:10 +02:00
printf("NPC_FALLING_ITEM\n");
2001-04-20 22:22:16 +02:00
enemy = new ("falling item") CNpcFallingItemHazard;
break;
2001-04-24 17:01:42 +02:00
}*/
2001-04-20 22:22:16 +02:00
2001-04-24 17:01:42 +02:00
/*case CNpcEnemy::NPC_FISH_HOOK:
2001-04-20 22:22:16 +02:00
{
2001-04-21 00:49:10 +02:00
printf("NPC_FISH_HOOK\n");
2001-04-20 22:22:16 +02:00
enemy = new ("fish hook") CNpcFishHookHazard;
break;
2001-04-24 17:01:42 +02:00
}*/
2001-04-20 22:22:16 +02:00
2001-04-24 17:01:42 +02:00
/*case CNpcEnemy::NPC_PENDULUM:
2001-04-20 22:22:16 +02:00
{
2001-04-21 00:49:10 +02:00
printf("NPC_PENDULUM\n");
2001-04-20 22:22:16 +02:00
enemy = new ("pendulum") CNpcPendulumHazard;
break;
2001-04-24 17:01:42 +02:00
}*/
2001-04-20 22:22:16 +02:00
2001-04-24 17:01:42 +02:00
/*case CNpcEnemy::NPC_FIREBALL:
2001-04-20 22:22:16 +02:00
{
2001-04-21 00:49:10 +02:00
printf("NPC_FIREBALL\n");
2001-04-20 22:22:16 +02:00
enemy = new ("fireball") CNpcFireballHazard;
break;
2001-04-24 17:01:42 +02:00
}*/
2001-04-20 22:22:16 +02:00
2001-04-24 17:01:42 +02:00
/*case CNpcEnemy::NPC_SAW_BLADE:
2001-04-20 22:22:16 +02:00
{
2001-04-21 00:49:10 +02:00
printf("NPC_SAW_BLADE\n");
2001-04-20 22:22:16 +02:00
enemy = new ("saw blade") CNpcReturningHazard;
break;
2001-04-24 17:01:42 +02:00
}*/
2001-04-20 22:22:16 +02:00
case CNpcEnemy::NPC_DUST_DEVIL:
{
2001-04-21 00:49:10 +02:00
printf("NPC_DUST_DEVIL\n");
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-04-20 18:25:35 +02:00
default:
{
2001-04-21 00:49:10 +02:00
printf("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-04-20 18:25:35 +02:00
enemy->setType( enemyType );
enemy->init();
return(enemy);
2001-04-20 17:43:35 +02:00
}
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;
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
setStartPos( newXPos, newYPos );
addWaypoint( newXPos, newYPos );
if ( ThisActor->PointCount > 1 )
{
for (int pointNum = 1 ; pointNum < ThisActor->PointCount ; pointNum++ )
{
newXPos = (u16) *PntList;
PntList++;
newYPos = (u16) *PntList;
PntList++;
addWaypoint( newXPos, newYPos );
if ( pointNum == 1 )
{
setHeading( newXPos, newYPos );
}
}
}
2001-04-02 21:21:46 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::addWaypoint( s32 xPos, s32 yPos )
{
DVECTOR newPos;
newPos.vx = xPos << 4;
newPos.vy = yPos << 4;
m_npcPath.addWaypoint( newPos );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::setStartPos( s32 xPos, s32 yPos )
{
Pos.vx = xPos << 4;
Pos.vy = yPos << 4;
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
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::setHeading( s32 xPos, s32 yPos )
{
m_heading = ratan2( ( yPos << 4 ) - Pos.vy, ( xPos << 4 ) - Pos.vx );
}
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);
m_spriteBank=0;
2001-02-27 17:59:50 +01:00
2001-04-20 17:43:35 +02:00
}
else
{
m_actorGfx=0;
m_spriteBank=new ("enemy sprites") SpriteBank();
m_spriteBank->load(SPRITES_SPRITES_SPR);
}
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-04-04 17:53:44 +02:00
m_heading = m_fireHeading = 0;
2001-01-18 20:18:39 +01:00
m_movementTimer = 0;
m_timerTimer = 0;
2001-04-24 21:03:06 +02:00
m_collisionTimer = 0;
2001-01-18 20:18:39 +01:00
m_velocity = 0;
2001-01-18 22:19:43 +01:00
m_extension = 0;
2001-02-23 22:35:11 +01:00
m_rotation = 0;
2001-02-28 22:05:39 +01:00
m_reversed = false;
2001-03-13 18:01:35 +01:00
m_salvoCount = 0;
2001-04-07 00:21:01 +02:00
m_isActive = true;
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-03-22 20:10:19 +01:00
DVECTOR ofs = getCollisionSize();
m_drawOffset.vx = 0;
2001-04-21 19:29:15 +02:00
m_drawOffset.vy = -( ofs.vy >> 1 );
2001-03-22 20:10:19 +01:00
2001-03-30 19:26:29 +02:00
m_positionHistory = NULL;
2001-04-25 17:41:29 +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-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_heading = m_fireHeading = 0;
m_movementTimer = 0;
m_timerTimer = 0;
2001-04-24 21:03:06 +02:00
m_collisionTimer = 0;
2001-04-07 00:21:01 +02:00
m_velocity = 0;
m_extension = 0;
m_rotation = 0;
m_reversed = false;
m_salvoCount = 0;
m_isActive = true;
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-04-25 22:04:25 +02:00
if (m_spriteBank) m_spriteBank->dump(); delete m_spriteBank;
// remove waypoints
2001-03-30 19:26:29 +02:00
2001-04-25 22:04:25 +02:00
m_npcPath.removeAllWaypoints();
2001-02-27 17:59:50 +01:00
2001-04-25 22:04:25 +02:00
// remove position history
2001-03-30 19:26:29 +02:00
2001-04-25 22:04:25 +02:00
CNpcPositionHistory *currentPosition;
CNpcPositionHistory *oldPosition;
2001-03-30 19:26:29 +02:00
2001-04-25 22:04:25 +02:00
currentPosition = m_positionHistory;
2001-03-30 19:26:29 +02:00
2001-04-25 22:04:25 +02:00
while( currentPosition )
{
oldPosition = currentPosition;
currentPosition = currentPosition->next;
2001-03-30 19:26:29 +02:00
2001-04-25 22:04:25 +02:00
delete oldPosition;
}
2001-03-30 19:26:29 +02:00
2001-04-25 22:04:25 +02:00
m_positionHistory = NULL;
2001-03-30 19:26:29 +02: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
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::setToShutdown()
{
m_isShuttingDown = true;
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-30 20:55:38 +02:00
bool gitTrigger = false;
2001-04-20 18:13:23 +02:00
int CNpcEnemy::getFrameCount()
{
return( m_actorGfx->getFrameCount( m_animNo ) );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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-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-04-28 19:39:24 +02:00
if ( m_animPlaying )
{
s32 frameCount;
2001-04-25 17:10:26 +02:00
2001-04-28 19:39:24 +02:00
frameCount = getFrameCount();
2001-04-25 17:10:26 +02:00
2001-04-28 20:58:55 +02:00
s32 frameShift = ( moveFrames << 8 ) >> 1;
2001-04-25 17:10:26 +02:00
2001-04-28 19:39:24 +02:00
if ( ( frameCount << 8 ) - m_frame > frameShift )
{
m_frame += frameShift;
2001-04-07 00:21:01 +02:00
}
else
{
2001-04-28 19:39:24 +02:00
m_frame = ( frameCount - 1 ) << 8;
m_animPlaying = false;
2001-04-07 00:21:01 +02:00
}
2001-04-28 19:39:24 +02:00
}
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:
processShot();
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;
}
if ( m_heading > 1024 && m_heading < 3072 )
{
m_reversed = true;
}
else
{
m_reversed = false;
}
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-04-30 20:55:38 +02:00
if ( gitTrigger )
{
fireAsProjectile( 0 );
}
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-03-05 22:11:51 +01:00
void CNpcEnemy::collidedWith( CThing *_thisThing )
2001-02-07 17:42:13 +01:00
{
2001-04-28 19:39:24 +02:00
if ( m_isActive && !m_isCaught )
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-04-12 21:42:10 +02:00
switch( playerState )
2001-03-06 21:13:16 +01:00
{
2001-04-12 21:42:10 +02:00
case ATTACK_STATE__NONE:
2001-04-05 22:44:30 +02:00
{
2001-04-12 21:42:10 +02:00
if ( !player->isRecoveringFromHit() )
{
switch( m_data[m_type].detectCollision )
{
case DETECT_NO_COLLISION:
{
// ignore
2001-03-06 21:13:16 +01:00
2001-04-12 21:42:10 +02:00
break;
}
2001-03-06 21:13:16 +01:00
2001-04-12 21:42:10 +02:00
case DETECT_ALL_COLLISION:
{
m_oldControlFunc = m_controlFunc;
m_controlFunc = NPC_CONTROL_COLLISION;
break;
}
case DETECT_ATTACK_COLLISION_GENERIC:
{
//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;
}
break;
}
}
}
2001-04-05 22:44:30 +02:00
break;
}
2001-04-12 21:42:10 +02:00
default:
2001-04-05 22:44:30 +02:00
{
2001-04-12 21:42:10 +02:00
// player is attacking, respond appropriately
2001-04-05 22:44:30 +02:00
2001-04-12 21:42:10 +02:00
if ( m_controlFunc != NPC_CONTROL_SHOT )
{
m_controlFunc = NPC_CONTROL_SHOT;
m_state = NPC_GENERIC_HIT_CHECK_HEALTH;
2001-04-05 22:44:30 +02:00
}
break;
}
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;
if ( enemy->canCollideWithEnemy() )
{
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;
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-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-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
void CNpcEnemy::hasBeenAttacked()
{
2001-04-05 16:24:34 +02:00
m_controlFunc = NPC_CONTROL_SHOT;
2001-04-12 18:33:48 +02:00
m_state = NPC_GENERIC_HIT_CHECK_HEALTH;
2001-04-05 16:23:51 +02:00
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-02-27 22:25:22 +01:00
void CNpcEnemy::processShot()
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
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:
{
m_health -= 5;
if ( m_health < 0 )
{
m_state = NPC_GENERIC_HIT_DEATH_START;
}
else
{
m_state = NPC_GENERIC_HIT_RECOIL;
m_animPlaying = true;
m_animNo = m_data[m_type].recoilAnim;
m_frame = 0;
}
break;
}
case NPC_GENERIC_HIT_RECOIL:
{
if ( !m_animPlaying )
{
m_state = 0;
m_controlFunc = NPC_CONTROL_MOVEMENT;
}
break;
}
case NPC_GENERIC_HIT_DEATH_START:
2001-04-05 21:03:55 +02:00
{
m_animPlaying = true;
m_animNo = m_data[m_type].dieAnim;
m_frame = 0;
2001-04-05 21:36:04 +02:00
m_state = NPC_GENERIC_HIT_DEATH_END;
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
{
if ( !m_animPlaying )
{
2001-04-12 18:33:48 +02:00
if ( m_data[m_type].respawning )
{
m_isActive = false;
m_timerFunc = NPC_TIMER_RESPAWN;
m_timerTimer = 4 * GameState::getOneSecondInFrames();
}
else
{
2001-04-25 22:04:25 +02:00
setToShutdown();
2001-04-12 18:33:48 +02:00
}
2001-04-05 21:03:55 +02:00
}
break;
}
}
break;
}
}
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-02-07 17:42:13 +01:00
processGenericGotoTarget( _frames, playerXDist, playerYDist, m_data[m_type].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-04-20 00:09:59 +02:00
player->takeDamage( m_data[m_type].damageToUserType );
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-04-24 21:03:06 +02:00
if ( m_collisionTimer > 0 )
{
m_collisionTimer -= _frames;
}
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-04-07 00:21:01 +02:00
// Render
DVECTOR renderPos;
DVECTOR offset = CLevel::getCameraPos();
2001-02-27 22:25:22 +01:00
2001-04-07 00:21:01 +02:00
renderPos.vx = Pos.vx - offset.vx;
renderPos.vy = Pos.vy - offset.vy;
2001-02-27 22:25:22 +01:00
2001-04-07 00:21:01 +02:00
if ( renderPos.vx >= 0 && renderPos.vx <= VidGetScrW() )
2001-04-04 18:51:04 +02:00
{
2001-04-07 00:21:01 +02:00
if ( renderPos.vy >= 0 && renderPos.vy <= VidGetScrH() )
{
2001-04-20 18:25:35 +02:00
SprFrame = m_actorGfx->Render(renderPos,m_animNo,( m_frame >> 8 ),m_reversed);
2001-04-26 17:20:21 +02:00
m_actorGfx->RotateScale( SprFrame, renderPos, m_drawRotation, 4096, 4096 );
2001-04-27 20:30:19 +02:00
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-07 00:21:01 +02:00
}
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 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;
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
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CNpcEnemy::canBeCaughtByNet()
{
2001-04-12 18:44:11 +02:00
return( m_isActive && 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()
{
return( m_isActive );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 );
if ( xDist > 0 )
{
Pos.vx += 6;
}
else
{
Pos.vx -= 6;
}
if ( yDist > 0 )
{
2001-04-26 23:29:44 +02:00
Pos.vy += 3;
2001-04-24 21:03:06 +02:00
}
else
{
2001-04-26 23:29:44 +02:00
Pos.vy -= 3;
2001-04-24 21:03:06 +02:00
}
Pos.vx += otherDelta.vx;
Pos.vy += otherDelta.vy;
if ( m_collisionTimer <= 0 )
{
m_collisionTimer = GameState::getOneSecondInFrames();
m_heading = headingFromTarget;
// try next waypoint to get around other enemy
m_npcPath.incPath();
}
}
2001-04-28 19:39:24 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2001-04-30 20:55:38 +02:00
bool CNpcEnemy::processCoralBlowerMovement( int _frames, s32 xDist, s32 yDist )
2001-04-28 19:39:24 +02:00
{
s32 moveX, moveY;
s16 headingToTarget;
headingToTarget = ratan2( yDist, xDist );
s32 preShiftX = _frames * 3 * rcos( headingToTarget );
s32 preShiftY = _frames * 3 * rsin( headingToTarget );
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
{
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-04-30 20:55:38 +02:00
returnVal = processCoralBlowerMovement( _frames, targetXDist, targetYDist );
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;
processCoralBlowerMovement( _frames, targetXDist, targetYDist );
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-04-28 19:39:24 +02:00
}
2001-04-30 20:55:38 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CNpcEnemy::fireAsProjectile( s16 heading )
{
m_isActive = false;
setToShutdown();
DVECTOR newPos = Pos;
newPos.vy -= 10;
CEnemyAsProjectile *projectile;
projectile = new( "blower projectile" ) CEnemyAsProjectile;
projectile->init( newPos,
heading,
CPlayerProjectile::PLAYER_PROJECTILE_DUMBFIRE,
CPlayerProjectile::PLAYER_PROJECTILE_FINITE_LIFE,
5*60);
projectile->setLayerCollision( m_layerCollision );
projectile->setGraphic( m_actorGfx );
}