SBSPSS/source/level/level.cpp

656 lines
18 KiB
C++
Raw Normal View History

2000-12-06 23:52:00 +01:00
/*************/
/*** Level ***/
/*************/
#include "system\global.h"
#include "fileio\fileio.h"
2000-12-07 16:56:20 +01:00
#include "utils\utils.h"
2001-04-03 23:28:56 +02:00
#include "utils\pak.h"
2000-12-07 16:56:20 +01:00
#include "gfx\tpage.h"
2000-12-08 15:48:50 +01:00
#include "gfx\prim.h"
2000-12-06 23:52:00 +01:00
#include <DStructs.h>
2001-01-15 16:22:33 +01:00
#include "game\game.h"
2000-12-06 23:52:00 +01:00
#include "level\level.h"
2000-12-07 16:56:20 +01:00
#include "level\layertile.h"
2001-01-15 16:22:33 +01:00
#include "level\layerback.h"
2000-12-14 17:38:34 +01:00
#include "level\layertile3d.h"
2001-02-02 20:16:49 +01:00
#include "level\layercollision.h"
2000-12-07 16:56:20 +01:00
2001-04-02 17:48:02 +02:00
#include "gfx\font.h"
2001-03-06 17:59:04 +01:00
#ifndef __TRIGGERS_TLEVEXIT_H__
#include "triggers\tlevexit.h"
#endif
2001-04-23 23:11:15 +02:00
#ifndef __TRIGGERS_TRESTART_H__
#include "triggers\trestart.h"
2001-04-17 22:09:33 +02:00
#endif
2001-05-01 23:34:41 +02:00
#ifndef __TRIGGERS_TTELEPRT_H__
#include "triggers\tteleprt.h"
#endif
2001-05-04 03:35:52 +02:00
#ifndef __TRIGGERS_TCAMLOCK_H__
#include "triggers\tcamlock.h"
#endif
2001-05-08 18:58:07 +02:00
#ifndef __TRIGGERS_TWATER_H__
#include "triggers\twater.h"
#endif
2001-04-02 19:02:29 +02:00
#ifndef __PICKUPS_PICKUP_H__
#include "pickups\pickup.h"
#endif
2001-05-09 22:15:01 +02:00
#ifndef __PICKUPS_PSPATULA_H__
#include "pickups\pspatula.h"
#endif
2001-03-29 18:12:32 +02:00
#ifndef __SOUND_SOUND_H__
#include "sound\sound.h"
#endif
2001-04-02 17:48:02 +02:00
#ifndef __VID_HEADER_
#include "system\vid.h"
#endif
2001-04-03 23:28:56 +02:00
#include "gfx\actor.h"
2000-12-08 15:48:50 +01:00
2001-05-04 21:34:09 +02:00
#ifndef __ENEMY_NPC_H__
#include "enemy\npc.h"
#endif
#ifndef __FRIEND_FRIEND_H__
#include "friend\friend.h"
#endif
#ifndef __PLATFORM_PLATFORM_H__
#include "platform\platform.h"
#endif
#ifndef __HAZARD_HAZARD_H__
#include "hazard\hazard.h"
#endif
#ifndef __PROJECTL_PROJECTL_H__
#include "projectl\projectl.h"
#endif
2001-05-10 16:09:06 +02:00
#ifndef __JELLFISH_JELLFISH_H__
#include "jellfish\jellfish.h"
#endif
2001-05-09 22:15:01 +02:00
#ifndef __GAME_GAMESLOT_H__
#include "game\gameslot.h"
#endif
2001-05-04 21:34:09 +02:00
2001-05-03 00:49:59 +02:00
/*****************************************************************************/
extern int s_globalLevelSelectThing;
2001-04-19 01:04:03 +02:00
/*****************************************************************************/
2001-02-12 20:40:01 +01:00
sLvlTab LvlTable[]=
{
2001-03-05 18:04:28 +01:00
// C1
2001-04-19 01:04:03 +02:00
{1,1,LEVELS_CHAPTER01_LEVEL01_LVL,LEVELS_CHAPTER01_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL1},
2001-04-24 22:35:31 +02:00
{1,2,LEVELS_CHAPTER01_LEVEL02_LVL,LEVELS_CHAPTER01_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL2},
{1,3,LEVELS_CHAPTER01_LEVEL03_LVL,LEVELS_CHAPTER01_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL3},
2001-04-19 01:04:03 +02:00
{1,4,LEVELS_CHAPTER01_LEVEL04_LVL,LEVELS_CHAPTER01_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL4},
2001-04-24 22:35:31 +02:00
2001-03-05 18:04:28 +01:00
// C2
2001-04-19 01:04:03 +02:00
{2,1,LEVELS_CHAPTER02_LEVEL01_LVL,LEVELS_CHAPTER02_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL1},
{2,2,LEVELS_CHAPTER02_LEVEL02_LVL,LEVELS_CHAPTER02_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL2},
{2,3,LEVELS_CHAPTER02_LEVEL03_LVL,LEVELS_CHAPTER02_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL3},
{2,4,LEVELS_CHAPTER02_LEVEL04_LVL,LEVELS_CHAPTER02_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL4},
2001-03-05 18:04:28 +01:00
// C3
2001-04-19 01:04:03 +02:00
{3,1,LEVELS_CHAPTER03_LEVEL01_LVL,LEVELS_CHAPTER03_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL1},
{3,2,LEVELS_CHAPTER03_LEVEL02_LVL,LEVELS_CHAPTER03_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL2},
{3,3,LEVELS_CHAPTER03_LEVEL03_LVL,LEVELS_CHAPTER03_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL3},
{3,4,LEVELS_CHAPTER03_LEVEL04_LVL,LEVELS_CHAPTER03_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL4},
2001-03-05 18:04:28 +01:00
// C4
2001-04-19 01:04:03 +02:00
{4,1,LEVELS_CHAPTER04_LEVEL01_LVL,LEVELS_CHAPTER04_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL1},
{4,2,LEVELS_CHAPTER04_LEVEL02_LVL,LEVELS_CHAPTER04_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL2},
{4,3,LEVELS_CHAPTER04_LEVEL03_LVL,LEVELS_CHAPTER04_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL3},
{4,4,LEVELS_CHAPTER04_LEVEL04_LVL,LEVELS_CHAPTER04_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL4},
2001-03-05 18:04:28 +01:00
// C5
2001-04-19 01:04:03 +02:00
{5,1,LEVELS_CHAPTER05_LEVEL01_LVL,LEVELS_CHAPTER05_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL1},
{5,2,LEVELS_CHAPTER05_LEVEL02_LVL,LEVELS_CHAPTER05_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL2},
{5,3,LEVELS_CHAPTER05_LEVEL03_LVL,LEVELS_CHAPTER05_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL3},
{5,4,LEVELS_CHAPTER05_LEVEL04_LVL,LEVELS_CHAPTER05_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL4},
2001-03-05 18:04:28 +01:00
// C6
2001-04-19 01:04:03 +02:00
{6,1,LEVELS_CHAPTER06_LEVEL01_LVL,LEVELS_CHAPTER06_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER6_ROLLERCOASTER},
{6,2,LEVELS_CHAPTER06_LEVEL02_LVL,LEVELS_CHAPTER06_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER6_SNAILRACE},
{6,3,LEVELS_CHAPTER06_LEVEL03_LVL,LEVELS_CHAPTER06_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER6_BIGWHEEL},
{6,4,LEVELS_CHAPTER06_LEVEL04_LVL,LEVELS_CHAPTER06_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER6_TUNNELOFLOVE},
{6,5,LEVELS_CHAPTER06_LEVEL05_LVL,LEVELS_CHAPTER06_LEVEL05_TEX, CSoundMediator::SONG_CHAPTER6_TUNNELOFLOVE},
2001-05-02 23:15:05 +02:00
// FMA
{6,99,LEVELS_FMA_SHADYSHOALS_LVL,LEVELS_FMA_SHADYSHOALS_TEX, CSoundMediator::SONG_TITLE},
2001-04-24 22:35:31 +02:00
2001-02-12 20:40:01 +01:00
};
2001-02-26 15:56:03 +01:00
const static int LvlTableSize=sizeof(LvlTable)/sizeof(sLvlTab);
2001-02-12 20:40:01 +01:00
2001-04-03 23:28:56 +02:00
const FileEquate loadingScreens[6]=
{
LOADINGSCREENS_PINEAPPLE_GFX,
LOADINGSCREENS_CULTURE_GFX,
LOADINGSCREENS_PICKLES_GFX,
LOADINGSCREENS_MONITOR_GFX,
LOADINGSCREENS_KARATE_GFX,
LOADINGSCREENS_PIZZA_GFX,
};
2001-04-19 01:04:03 +02:00
/*****************************************************************************/
DVECTOR CLevel::MapPos;
DVECTOR CLevel::s_playerSpawnPos;
2001-05-04 23:58:41 +02:00
u8 CLevel::m_isBossRespawn;
s32 CLevel::m_bossHealth;
2000-12-07 16:56:20 +01:00
/*****************************************************************************/
2001-04-03 23:28:56 +02:00
CLevel::CLevel()
2000-12-07 16:56:20 +01:00
{
2001-04-03 23:28:56 +02:00
}
/*****************************************************************************/
2001-05-02 22:42:07 +02:00
bool CLevel::GetNextLevel(int &Lvl)
2001-04-03 23:28:56 +02:00
{
2001-05-02 22:42:07 +02:00
bool Finished=false;
2001-04-03 23:28:56 +02:00
Lvl++;
// TMP
if (Lvl>=LvlTableSize) Lvl=0;
// Skip Blanks
2001-05-02 23:15:05 +02:00
while (CFileIO::getFileSize(LvlTable[Lvl ].LevelFilename)<=10000) // Dodgy blank level skip
2001-03-05 18:04:28 +01:00
{
2001-04-03 23:28:56 +02:00
Lvl++;
if (Lvl>=LvlTableSize) Lvl=0;
2001-03-05 18:04:28 +01:00
}
2001-04-03 23:28:56 +02:00
// End TMP
2001-05-02 22:42:07 +02:00
// Lvl&=3; // Ch1 only Bodge
return(Finished);
2001-04-03 23:28:56 +02:00
}
2001-03-05 18:04:28 +01:00
2001-04-03 23:28:56 +02:00
/*****************************************************************************/
2001-04-19 01:04:03 +02:00
void CLevel::init(int LevelNo)
2001-04-03 23:28:56 +02:00
{
// Load it
2001-04-19 01:04:03 +02:00
sLvlTab *lvlTab=&LvlTable[LevelNo];
2001-04-03 23:28:56 +02:00
2001-04-25 18:41:16 +02:00
CActorPool::Reset();
2001-04-03 23:28:56 +02:00
CSoundMediator::setSong((CSoundMediator::SONGID)lvlTab->songId);
2001-04-09 23:27:21 +02:00
2001-04-19 01:04:03 +02:00
DisplayLoadingScreen(lvlTab);
2001-04-04 18:14:52 +02:00
2001-04-19 17:12:21 +02:00
LevelHdr=(sLevelHdr*)CFileIO::loadFile(lvlTab->LevelFilename,"Level");
2001-04-19 01:04:03 +02:00
LevelHdr->TileBank2d=(sTile2d*) MakePtr(LevelHdr,(int)LevelHdr->TileBank2d);
LevelHdr->TileBank3d=(sTile3d*) MakePtr(LevelHdr,(int)LevelHdr->TileBank3d);
LevelHdr->TriList=(sTri*) MakePtr(LevelHdr,(int)LevelHdr->TriList);
LevelHdr->QuadList=(sQuad*) MakePtr(LevelHdr,(int)LevelHdr->QuadList);
LevelHdr->VtxList=(sVtx*) MakePtr(LevelHdr,(int)LevelHdr->VtxList);
2001-04-27 18:59:41 +02:00
LevelHdr->ModelList=(sModel*) MakePtr(LevelHdr,(int)LevelHdr->ModelList);
2001-04-04 18:14:52 +02:00
2001-04-27 18:59:41 +02:00
CModelGfx::SetData(LevelHdr->ModelList,LevelHdr->TriList,LevelHdr->QuadList,LevelHdr->VtxList);
2001-04-19 01:04:03 +02:00
m_levelTPage=TPLoadTex(lvlTab->TexFilename);
2001-04-07 23:17:27 +02:00
s_playerSpawnPos.vx=LevelHdr->PlayerStartX*16;
2001-04-20 22:46:57 +02:00
s_playerSpawnPos.vy=LevelHdr->PlayerStartY*16+16;
2001-04-07 23:17:27 +02:00
2001-04-03 23:28:56 +02:00
MapPos.vx=MapPos.vy=0;
initLayers();
2001-05-04 23:58:41 +02:00
m_isBossRespawn = false;
m_bossHealth = 0;
2001-04-03 23:28:56 +02:00
}
/*****************************************************************************/
2001-04-19 01:04:03 +02:00
void CLevel::DisplayLoadingScreen(sLvlTab *lvlTab)
2001-04-03 23:28:56 +02:00
{
2001-04-19 01:04:03 +02:00
FontBank font;
char buf[128];
u8 *s_image;
int i;
2001-04-02 17:48:02 +02:00
font.initialise(&standardFont);
font.setJustification(FontBank::JUST_CENTRE);
2001-04-19 01:04:03 +02:00
sprintf(buf,"LOADING CHAPTER %d LEVEL %d",lvlTab->Chapter,lvlTab->Level);
s_image=CFileIO::loadFile(loadingScreens[lvlTab->Chapter-1]);
2001-04-02 17:48:02 +02:00
ASSERT(s_image);
SetScreenImage(s_image);
for(i=0;i<2;i++)
{
2001-04-03 17:12:40 +02:00
font.setColour(255,255,255);
font.print(256 ,120 ,buf);
font.setColour(0,0,0);
font.print(256-1,120-1,buf);
2001-04-06 18:11:51 +02:00
font.print(256-1,120 ,buf);
2001-04-03 17:12:40 +02:00
font.print(256-1,120+1,buf);
2001-04-06 18:11:51 +02:00
font.print(256 ,120-1,buf);
font.print(256 ,120+1,buf);
font.print(256+1,120-1,buf);
font.print(256+1,120 ,buf);
2001-04-03 17:12:40 +02:00
font.print(256+1,120+1,buf);
2001-04-02 17:48:02 +02:00
PrimDisplay();
VSync(0);
VidSwapDraw();
}
ClearScreenImage();
MemFree(s_image);
VSync(20);
font.dump();
2001-04-03 23:28:56 +02:00
}
/*****************************************************************************/
void CLevel::initLayers()
{
// Init Layers
2000-12-09 18:22:06 +01:00
for (int i=0; i<CLayerTile::LAYER_TILE_TYPE_MAX; i++)
2000-12-08 15:48:50 +01:00
{
TileLayers[i]=0;
}
2001-03-05 18:04:28 +01:00
CollisionLayer=0;
2001-04-03 23:28:56 +02:00
ActorList=0;
ItemList=0;
PlatformList=0;
2001-04-09 17:35:37 +02:00
FXList=0;
2001-05-01 14:20:47 +02:00
HazardList=0;
2001-03-08 00:20:09 +01:00
2000-12-08 15:48:50 +01:00
// Back
2001-02-20 16:56:16 +01:00
if (LevelHdr->BackLayer)
2000-12-08 15:48:50 +01:00
{
sLayerHdr *Layer=(sLayerHdr*)MakePtr(LevelHdr,LevelHdr->BackLayer);
2001-04-19 01:04:03 +02:00
CLayerTile *NewLayer=new ("Back Layer") CLayerBack(LevelHdr,Layer);
2000-12-12 21:56:51 +01:00
NewLayer->init(MapPos,3);
2000-12-09 18:22:06 +01:00
TileLayers[CLayerTile::LAYER_TILE_TYPE_BACK]=NewLayer;
2000-12-08 15:48:50 +01:00
}
2000-12-12 21:56:51 +01:00
2000-12-08 15:48:50 +01:00
// Mid
if (LevelHdr->MidLayer)
{
sLayerHdr *Layer=(sLayerHdr*)MakePtr(LevelHdr,LevelHdr->MidLayer);
2001-04-19 01:04:03 +02:00
CLayerTile *NewLayer=new ("Mid Layer") CLayerTile(LevelHdr,Layer);
2000-12-12 21:56:51 +01:00
NewLayer->init(MapPos,2);
2000-12-09 18:22:06 +01:00
TileLayers[CLayerTile::LAYER_TILE_TYPE_MID]=NewLayer;
2000-12-08 15:48:50 +01:00
}
2000-12-14 17:38:34 +01:00
2000-12-08 15:48:50 +01:00
// Action
if (LevelHdr->ActionLayer)
2000-12-07 16:56:20 +01:00
{
2000-12-08 15:48:50 +01:00
sLayerHdr *Layer=(sLayerHdr*)MakePtr(LevelHdr,LevelHdr->ActionLayer);
2001-04-19 01:04:03 +02:00
CLayerTile *NewLayer=new ("Action Layer") CLayerTile3d(LevelHdr,Layer);
2000-12-14 17:38:34 +01:00
NewLayer->init(MapPos,0);
2000-12-09 18:22:06 +01:00
TileLayers[CLayerTile::LAYER_TILE_TYPE_ACTION]=NewLayer;
2000-12-08 15:48:50 +01:00
}
2001-02-02 20:16:49 +01:00
// Collision
2001-04-26 23:15:36 +02:00
2001-02-02 20:16:49 +01:00
if (LevelHdr->CollisionLayer)
{
sLayerHdr *Layer=(sLayerHdr*)MakePtr(LevelHdr,LevelHdr->CollisionLayer);
CollisionLayer=new ("Collision Layer") CLayerCollision(Layer);
}
2001-04-26 23:15:36 +02:00
else
{
ASSERT(!"Where is the collision, moron!");
}
2001-04-03 23:28:56 +02:00
2001-04-02 02:17:48 +02:00
// Actors
if (LevelHdr->ActorList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->ActorList);
ActorCount=Hdr->Count;
ActorList=(sThingActor**)MemAlloc(ActorCount*sizeof(sThingActor**),"Actor List");
u8 *ThingPtr=(u8*)MakePtr(Hdr,sizeof(sThingHdr));
for (int i=0; i<ActorCount; i++)
{
ActorList[i]=(sThingActor*)ThingPtr;
ThingPtr+=sizeof(sThingActor);
ThingPtr+=ActorList[i]->PointCount*sizeof(u16)*2;
}
}
2001-04-09 17:35:37 +02:00
// Platforms
if (LevelHdr->PlatformList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->PlatformList);
PlatformCount=Hdr->Count;
PlatformList=(sThingPlatform**)MemAlloc(PlatformCount*sizeof(sThingPlatform**),"Platform List");
u8 *ThingPtr=(u8*)MakePtr(Hdr,sizeof(sThingHdr));
for (int i=0; i<PlatformCount; i++)
{
PlatformList[i]=(sThingPlatform*)ThingPtr;
ThingPtr+=sizeof(sThingPlatform);
ThingPtr+=PlatformList[i]->PointCount*sizeof(u16)*2;
}
}
2001-04-07 23:17:27 +02:00
// FX
if (LevelHdr->FXList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->FXList);
FXCount=Hdr->Count;
FXList=(sThingFX*)MakePtr(Hdr,sizeof(sThingHdr));
}
2001-05-04 21:34:09 +02:00
2001-05-01 14:20:47 +02:00
// Hazards
if (LevelHdr->HazardList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->HazardList);
HazardCount=Hdr->Count;
HazardList=(sThingHazard**)MemAlloc(HazardCount*sizeof(sThingHazard**),"Hazard List");
u8 *ThingPtr=(u8*)MakePtr(Hdr,sizeof(sThingHdr));
for (int i=0; i<HazardCount; i++)
{
HazardList[i]=(sThingHazard*)ThingPtr;
ThingPtr+=sizeof(sThingHazard);
ThingPtr+=HazardList[i]->PointCount*sizeof(u16)*2;
}
}
2001-04-03 23:28:56 +02:00
2001-05-04 21:34:09 +02:00
initThings(false);
2000-12-06 23:52:00 +01:00
}
2001-05-04 21:34:09 +02:00
/*****************************************************************************/
void CLevel::initThings(int _respawningLevel)
{
// Triggers
// Yeah yeah - I'll put this crap into a seperate file when the numbers of trigger types get a bit bigger! (pkg)
if (LevelHdr->TriggerList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->TriggerList);
TriggerCount=Hdr->Count;
TriggerList=(sThingTrigger*)MakePtr(Hdr,sizeof(sThingHdr));
for(int i=0;i<TriggerCount;i++)
{
CTriggerThing *trigger=NULL; // I hate having to do this just to keep the compiler quiet :/ (pkg)
if(TriggerList->Type==3)
{
// Camera lock trigger
trigger=(CCameraLockTrigger*)new ("CameraLockTrigger") CCameraLockTrigger();
trigger->init();
trigger->setPositionAndSize(TriggerList->Pos.X<<4,TriggerList->Pos.Y<<4,
TriggerList->Width<<4,TriggerList->Height<<4);
trigger->setTargetBox(TriggerList->TargetPos.X<<4,TriggerList->TargetPos.Y<<4,TriggerList->TargetSize.X<<4,TriggerList->TargetSize.Y<<4);
}
TriggerList++;
}
}
if (LevelHdr->TriggerList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->TriggerList);
TriggerCount=Hdr->Count;
TriggerList=(sThingTrigger*)MakePtr(Hdr,sizeof(sThingHdr));
for(int i=0;i<TriggerCount;i++)
{
CTriggerThing *trigger=NULL; // I hate having to do this just to keep the compiler quiet :/ (pkg)
switch(TriggerList->Type)
{
// Exit trigger
case 0:
trigger=(CTriggerThing*)new ("LevelExitTrigger") CLevelExitTrigger();
break;
// Level respawn trigger
case 1:
trigger=(CRestartPointTrigger*)new ("RestartTrigger") CRestartPointTrigger();
break;
// Teleport trigger
case 2:
trigger=(CTeleportTrigger*)new ("TeleportTrigger") CTeleportTrigger();
break;
// Camera lock trigger
case 3:
trigger=NULL;
break;
2001-05-08 18:58:07 +02:00
// In/Out of water triggers
case 4:
trigger=(CInWaterTrigger*)new ("InWaterTrigger") CInWaterTrigger();
break;
case 5:
trigger=(COutOfWaterTrigger*)new ("OutOfWaterTrigger") COutOfWaterTrigger();
break;
2001-05-04 21:34:09 +02:00
}
if(trigger)
{
trigger->init();
trigger->setPositionAndSize(TriggerList->Pos.X<<4,TriggerList->Pos.Y<<4,
TriggerList->Width<<4,TriggerList->Height<<4);
trigger->setTargetBox(TriggerList->TargetPos.X<<4,TriggerList->TargetPos.Y<<4,TriggerList->TargetSize.X<<4,TriggerList->TargetSize.Y<<4);
2001-05-10 23:08:40 +02:00
trigger->updateCollisionArea();
2001-05-04 21:34:09 +02:00
}
TriggerList++;
}
}
// Items
if (LevelHdr->ItemList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->ItemList);
ItemCount=Hdr->Count;
ItemList=(sThingItem*)MakePtr(Hdr,sizeof(sThingHdr));
DVECTOR pos;
2001-05-09 22:15:01 +02:00
int spatNumber=0;
2001-05-04 21:34:09 +02:00
for(int i=0;i<ItemCount;i++)
{
2001-05-09 22:15:01 +02:00
int isSpat=(PICKUP_TYPE)ItemList->Type==PICKUP__SPATULA;
CBasePickup *newPickup;
if(!isSpat||CGameSlotManager::getSlotData()->isSpatulaUncollected(0,0,spatNumber))
2001-05-04 21:34:09 +02:00
{
pos.vx=ItemList->Pos.X<<4;
pos.vy=ItemList->Pos.Y<<4;
2001-05-09 22:15:01 +02:00
newPickup=createPickup((PICKUP_TYPE)ItemList->Type,&pos);
2001-05-10 23:08:40 +02:00
newPickup->updateCollisionArea();
2001-05-09 22:15:01 +02:00
if(isSpat)
{
((CSpatulaPickup*)newPickup)->setSpatulaNumber(spatNumber);
}
}
if(isSpat)
{
spatNumber++;
2001-05-04 21:34:09 +02:00
}
ItemList++;
}
}
// Init actors (needs moving and tidying
int actorNum;
int platformNum;
int hazardNum;
sThingActor **actorList = getActorList();
if (actorList)
{
for ( actorNum = 0 ; actorNum < getActorCount() ; actorNum++ )
{
sThingActor *ThisActor=actorList[actorNum];
CGameScene::ACTOR_TYPE actorType = CGameScene::getActorType( actorList[actorNum]->Type );
switch ( actorType )
{
case CGameScene::ACTOR_ENEMY_NPC:
{
CNpcEnemy *enemy;
enemy=CNpcEnemy::Create(ThisActor);
enemy->setLayerCollision( getCollisionLayer() );
enemy->setupWaypoints( ThisActor );
enemy->postInit();
2001-05-10 23:08:40 +02:00
enemy->updateCollisionArea();
2001-05-09 23:27:23 +02:00
if ( ThisActor->Speed )
{
enemy->setSpeed( ThisActor->Speed );
}
2001-05-04 21:34:09 +02:00
}
break;
case CGameScene::ACTOR_FRIEND_NPC:
{
CNpcFriend *friendNpc;
friendNpc=CNpcFriend::Create(ThisActor);
friendNpc->setLayerCollision( getCollisionLayer() );
friendNpc->postInit();
2001-05-10 23:08:40 +02:00
friendNpc->updateCollisionArea();
2001-05-04 21:34:09 +02:00
}
break;
default:
break;
}
}
}
sThingPlatform **platformList = getPlatformList();
if (platformList)
{
for ( platformNum = 0 ; platformNum < getPlatformCount() ; platformNum++ )
{
sThingPlatform *ThisPlatform = platformList[platformNum];
CNpcPlatform *platform;
platform = CNpcPlatform::Create( ThisPlatform );
platform->setLayerCollision( getCollisionLayer() );
platform->postInit();
2001-05-10 23:08:40 +02:00
platform->updateCollisionArea();
2001-05-09 23:27:23 +02:00
if ( ThisPlatform->Speed )
{
platform->setSpeed( ThisPlatform->Speed );
}
2001-05-04 21:34:09 +02:00
}
}
sThingHazard **hazardList = getHazardList();
if (hazardList)
{
for ( hazardNum = 0 ; hazardNum < getHazardCount() ; hazardNum++ )
{
sThingHazard *ThisHazard = hazardList[hazardNum];
CNpcHazard *hazard;
hazard = CNpcHazard::Create( ThisHazard );
hazard->setLayerCollision( getCollisionLayer() );
2001-05-10 23:08:40 +02:00
hazard->updateCollisionArea();
2001-05-10 21:27:57 +02:00
if ( ThisHazard->Respawn )
{
hazard->setRespawnRate( ThisHazard->Respawn );
}
2001-05-04 21:34:09 +02:00
}
}
2001-05-10 16:09:06 +02:00
// initialise jellyfish generator
CJellyfishGenerator::init();
2001-05-04 21:34:09 +02:00
}
/*****************************************************************************/
void CLevel::respawnLevel()
{
2001-05-04 23:58:41 +02:00
m_isBossRespawn = false;
m_bossHealth = 0;
2001-05-04 21:34:09 +02:00
CThingManager::killAllThingsForRespawn();
initThings(true);
}
2000-12-06 23:52:00 +01:00
/*****************************************************************************/
2001-04-19 01:04:03 +02:00
void CLevel::shutdown()
2000-12-06 23:52:00 +01:00
{
2001-02-12 18:18:17 +01:00
for (int i=0; i<CLayerTile::LAYER_TILE_TYPE_MAX; i++)
{
if (TileLayers[i])
{
TileLayers[i]->shutdown();
delete TileLayers[i];
}
}
2001-03-05 18:04:28 +01:00
if (CollisionLayer)
{
2001-04-03 23:28:56 +02:00
CollisionLayer->shutdown();
delete CollisionLayer;
}
CSoundMediator::stopAllSound();
VSync(0);CSoundMediator::think(1); // This is needed to let xmplay kill off the sounds properly (pkg)
if (ActorList) MemFree(ActorList);
2001-04-09 17:35:37 +02:00
if (PlatformList) MemFree(PlatformList);
2001-05-01 14:20:47 +02:00
if (HazardList) MemFree(HazardList);
2001-04-03 23:28:56 +02:00
2001-04-19 01:04:03 +02:00
MemFree(LevelHdr);
2001-04-25 18:41:16 +02:00
CActorPool::Reset();
2001-04-19 01:04:03 +02:00
TPFree(m_levelTPage);
2000-12-06 23:52:00 +01:00
}
2000-12-08 15:48:50 +01:00
/*****************************************************************************/
/*****************************************************************************/
2000-12-06 23:52:00 +01:00
/*****************************************************************************/
void CLevel::render()
{
2000-12-09 18:22:06 +01:00
for (int i=0; i<CLayerTile::LAYER_TILE_TYPE_MAX; i++)
2000-12-08 15:48:50 +01:00
{
if (TileLayers[i]) TileLayers[i]->render();
}
2001-04-26 23:15:36 +02:00
2001-02-13 23:36:49 +01:00
#ifdef __SHOW_COLLISION__
if(CollisionLayer)
{
CollisionLayer->render(MapPos);
}
#endif
2000-12-06 23:52:00 +01:00
}
/*****************************************************************************/
2000-12-08 15:48:50 +01:00
/*****************************************************************************/
/*****************************************************************************/
2000-12-06 23:52:00 +01:00
void CLevel::think(int _frames)
{
2001-04-26 23:15:36 +02:00
2000-12-09 18:22:06 +01:00
for (int i=0; i<CLayerTile::LAYER_TILE_TYPE_MAX; i++)
2000-12-08 15:48:50 +01:00
{
2000-12-12 21:56:51 +01:00
if (TileLayers[i]) TileLayers[i]->think(MapPos);
2000-12-08 15:48:50 +01:00
}
2000-12-06 23:52:00 +01:00
}
2001-02-12 16:26:00 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
DVECTOR CLevel::getMapSize()
{
2001-04-03 23:28:56 +02:00
DVECTOR size;
sLayerHdr *layer;
2001-02-12 16:26:00 +01:00
2001-04-03 23:28:56 +02:00
layer=(sLayerHdr*)MakePtr(LevelHdr,LevelHdr->ActionLayer);
size.vx=layer->Width;
size.vy=layer->Height;
2001-02-12 16:26:00 +01:00
2001-04-03 23:28:56 +02:00
return size;
2001-02-12 16:26:00 +01:00
}
2001-05-03 00:49:59 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
int CLevel::getCurrentChapter()
{
return( LvlTable[s_globalLevelSelectThing].Chapter );
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
int CLevel::getCurrentChapterLevel()
{
return( LvlTable[s_globalLevelSelectThing].Level );
}
2000-12-06 23:52:00 +01:00
/*****************************************************************************/