SBSPSS/source/level/level.cpp

784 lines
25 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-05-29 22:31:02 +02:00
#include "triggers\trigger.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-05-29 22:31:02 +02:00
*/
2001-05-08 18:58:07 +02:00
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-06-01 20:59:33 +02:00
#ifndef __PICKUPS_PKELP_H__
#include "pickups\pkelp.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-31 23:17:33 +02:00
#ifndef __LOCALE_TEXTDBASE_H__
#include "locale\textdbase.h"
#endif
2001-05-16 21:06:47 +02:00
#include "fx\fx.h"
#include "fx\fxfallingtile.h"
2001-05-04 21:34:09 +02:00
2001-05-03 00:49:59 +02:00
2001-05-30 16:58:29 +02:00
// Level data include files:
#include <CHAPTER01_LEVEL01_INF.h>
#include <CHAPTER01_LEVEL02_INF.h>
#include <CHAPTER01_LEVEL03_INF.h>
#include <CHAPTER01_LEVEL04_INF.h>
#include <CHAPTER02_LEVEL01_INF.h>
#include <CHAPTER02_LEVEL02_INF.h>
#include <CHAPTER02_LEVEL03_INF.h>
#include <CHAPTER02_LEVEL04_INF.h>
#include <CHAPTER03_LEVEL01_INF.h>
#include <CHAPTER03_LEVEL02_INF.h>
#include <CHAPTER03_LEVEL03_INF.h>
#include <CHAPTER03_LEVEL04_INF.h>
#include <CHAPTER04_LEVEL01_INF.h>
#include <CHAPTER04_LEVEL02_INF.h>
#include <CHAPTER04_LEVEL03_INF.h>
#include <CHAPTER04_LEVEL04_INF.h>
#include <CHAPTER05_LEVEL01_INF.h>
#include <CHAPTER05_LEVEL02_INF.h>
#include <CHAPTER05_LEVEL03_INF.h>
#include <CHAPTER05_LEVEL04_INF.h>
#include <CHAPTER06_LEVEL01_INF.h>
#include <CHAPTER06_LEVEL02_INF.h>
#include <CHAPTER06_LEVEL03_INF.h>
#include <CHAPTER06_LEVEL04_INF.h>
#include <CHAPTER06_LEVEL05_INF.h>
2001-04-19 01:04:03 +02:00
/*****************************************************************************/
2001-05-16 21:06:47 +02:00
sLvlTab LvlTable[]=
2001-02-12 20:40:01 +01:00
{
2001-03-05 18:04:28 +01:00
// C1
2001-06-22 22:06:39 +02:00
{1,1, CHAPTER01_LEVEL01_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER01_LEVEL01_LVL,LEVELS_CHAPTER01_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL1, STR__CHAPTER_1,STR__CHAPTER_1_LEVEL_1, CFmaScene::FMA_SCRIPT__NONE },
{1,2, CHAPTER01_LEVEL02_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER01_LEVEL02_LVL,LEVELS_CHAPTER01_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL2, STR__CHAPTER_1,STR__CHAPTER_1_LEVEL_2, CFmaScene::FMA_SCRIPT__NONE },
{1,3, CHAPTER01_LEVEL03_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER01_LEVEL03_LVL,LEVELS_CHAPTER01_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL3, STR__CHAPTER_1,STR__CHAPTER_1_LEVEL_3, CFmaScene::FMA_SCRIPT__NONE },
2001-06-25 23:56:27 +02:00
{1,4, CHAPTER01_LEVEL04_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER01_LEVEL04_LVL,LEVELS_CHAPTER01_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER1_LEVEL4, STR__CHAPTER_1,STR__CHAPTER_1_LEVEL_4, CFmaScene::FMA_SCRIPT__CH1FINISHED },
{1,5, CHAPTER06_LEVEL01_INF_TOTAL_ITEM_KELP_TOKEN, LEVELS_CHAPTER06_LEVEL01_LVL,LEVELS_CHAPTER06_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER6_ROLLERCOASTER, STR__KELP_WORLD,STR__CHAPTER_6_LEVEL_1, CFmaScene::FMA_SCRIPT__NONE },
2001-03-05 18:04:28 +01:00
// C2
2001-06-22 22:06:39 +02:00
{2,1, CHAPTER02_LEVEL01_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER02_LEVEL01_LVL,LEVELS_CHAPTER02_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL1, STR__CHAPTER_2,STR__CHAPTER_2_LEVEL_1, CFmaScene::FMA_SCRIPT__NONE },
{2,2, CHAPTER02_LEVEL02_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER02_LEVEL02_LVL,LEVELS_CHAPTER02_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL2, STR__CHAPTER_2,STR__CHAPTER_2_LEVEL_2, CFmaScene::FMA_SCRIPT__NONE },
{2,3, CHAPTER02_LEVEL03_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER02_LEVEL03_LVL,LEVELS_CHAPTER02_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL3, STR__CHAPTER_2,STR__CHAPTER_2_LEVEL_3, CFmaScene::FMA_SCRIPT__NONE },
2001-06-25 23:56:27 +02:00
{2,4, CHAPTER02_LEVEL04_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER02_LEVEL04_LVL,LEVELS_CHAPTER02_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER2_LEVEL4, STR__CHAPTER_2,STR__CHAPTER_2_LEVEL_4, CFmaScene::FMA_SCRIPT__CH2FINISHED },
{2,5, CHAPTER06_LEVEL02_INF_TOTAL_ITEM_KELP_TOKEN, LEVELS_CHAPTER06_LEVEL02_LVL,LEVELS_CHAPTER06_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER6_SNAILRACE, STR__KELP_WORLD,STR__CHAPTER_6_LEVEL_2, CFmaScene::FMA_SCRIPT__NONE },
2001-06-22 22:06:39 +02:00
// C3
{3,1, CHAPTER03_LEVEL01_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER03_LEVEL01_LVL,LEVELS_CHAPTER03_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL1, STR__CHAPTER_3,STR__CHAPTER_3_LEVEL_1, CFmaScene::FMA_SCRIPT__NONE },
{3,2, CHAPTER03_LEVEL02_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER03_LEVEL02_LVL,LEVELS_CHAPTER03_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL2, STR__CHAPTER_3,STR__CHAPTER_3_LEVEL_2, CFmaScene::FMA_SCRIPT__NONE },
{3,3, CHAPTER03_LEVEL03_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER03_LEVEL03_LVL,LEVELS_CHAPTER03_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL3, STR__CHAPTER_3,STR__CHAPTER_3_LEVEL_3, CFmaScene::FMA_SCRIPT__NONE },
2001-06-25 23:56:27 +02:00
{3,4, CHAPTER03_LEVEL04_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER03_LEVEL04_LVL,LEVELS_CHAPTER03_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER3_LEVEL4, STR__CHAPTER_3,STR__CHAPTER_3_LEVEL_4, CFmaScene::FMA_SCRIPT__CH3FINISHED },
{3,5, CHAPTER06_LEVEL03_INF_TOTAL_ITEM_KELP_TOKEN, LEVELS_CHAPTER06_LEVEL03_LVL,LEVELS_CHAPTER06_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER6_BIGWHEEL, STR__KELP_WORLD,STR__CHAPTER_6_LEVEL_3, CFmaScene::FMA_SCRIPT__NONE },
2001-06-22 22:06:39 +02:00
// C4
{4,1, CHAPTER04_LEVEL01_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER04_LEVEL01_LVL,LEVELS_CHAPTER04_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL1, STR__CHAPTER_4,STR__CHAPTER_4_LEVEL_1, CFmaScene::FMA_SCRIPT__NONE },
{4,2, CHAPTER04_LEVEL02_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER04_LEVEL02_LVL,LEVELS_CHAPTER04_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL2, STR__CHAPTER_4,STR__CHAPTER_4_LEVEL_2, CFmaScene::FMA_SCRIPT__NONE },
{4,3, CHAPTER04_LEVEL03_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER04_LEVEL03_LVL,LEVELS_CHAPTER04_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL3, STR__CHAPTER_4,STR__CHAPTER_4_LEVEL_3, CFmaScene::FMA_SCRIPT__NONE },
2001-06-25 23:56:27 +02:00
{4,4, CHAPTER04_LEVEL04_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER04_LEVEL04_LVL,LEVELS_CHAPTER04_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER4_LEVEL4, STR__CHAPTER_4,STR__CHAPTER_4_LEVEL_4, CFmaScene::FMA_SCRIPT__CH4FINISHED },
{4,5, CHAPTER06_LEVEL04_INF_TOTAL_ITEM_KELP_TOKEN, LEVELS_CHAPTER06_LEVEL04_LVL,LEVELS_CHAPTER06_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER6_TUNNELOFLOVE, STR__KELP_WORLD,STR__CHAPTER_6_LEVEL_4, CFmaScene::FMA_SCRIPT__NONE },
2001-06-22 22:06:39 +02:00
// C5
{5,1, CHAPTER05_LEVEL01_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER05_LEVEL01_LVL,LEVELS_CHAPTER05_LEVEL01_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL1, STR__CHAPTER_5,STR__CHAPTER_5_LEVEL_1, CFmaScene::FMA_SCRIPT__NONE },
{5,2, CHAPTER05_LEVEL02_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER05_LEVEL02_LVL,LEVELS_CHAPTER05_LEVEL02_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL2, STR__CHAPTER_5,STR__CHAPTER_5_LEVEL_2, CFmaScene::FMA_SCRIPT__NONE },
{5,3, CHAPTER05_LEVEL03_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER05_LEVEL03_LVL,LEVELS_CHAPTER05_LEVEL03_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL3, STR__CHAPTER_5,STR__CHAPTER_5_LEVEL_3, CFmaScene::FMA_SCRIPT__NONE },
2001-06-25 23:56:27 +02:00
{5,4, CHAPTER05_LEVEL04_INF_TOTAL_ITEM_GOLDEN_SPATULA, LEVELS_CHAPTER05_LEVEL04_LVL,LEVELS_CHAPTER05_LEVEL04_TEX, CSoundMediator::SONG_CHAPTER5_LEVEL4, STR__CHAPTER_5,STR__CHAPTER_5_LEVEL_4, CFmaScene::FMA_SCRIPT__CH5FINISHED },
{5,5, CHAPTER06_LEVEL05_INF_TOTAL_ITEM_KELP_TOKEN, LEVELS_CHAPTER06_LEVEL05_LVL,LEVELS_CHAPTER06_LEVEL05_TEX, CSoundMediator::SONG_CHAPTER6_TUNNELOFLOVE, STR__KELP_WORLD,STR__CHAPTER_6_LEVEL_5, CFmaScene::FMA_SCRIPT__NONE },
2001-06-22 22:06:39 +02:00
// FMA
2001-07-04 16:32:35 +02:00
{6,0, 0, LEVELS_FMA_SHADYSHOALS_LVL,LEVELS_FMA_SHADYSHOALS_TEX, CSoundMediator::SONG_FMA, STR__NOW_LOADING,STR__BLANK, CFmaScene::FMA_SCRIPT__NONE },
{6,0, 0, LEVELS_FMA_CONTROLROOM_LVL,LEVELS_FMA_CONTROLROOM_TEX, CSoundMediator::SONG_FMA, STR__NOW_LOADING,STR__BLANK, CFmaScene::FMA_SCRIPT__NONE },
2001-04-24 22:35:31 +02:00
2001-02-12 20:40:01 +01:00
};
2001-05-16 21:06:47 +02:00
const int LvlTableSize=sizeof(LvlTable)/sizeof(sLvlTab);
2001-02-12 20:40:01 +01:00
2001-06-04 18:10:06 +02:00
const FileEquate loadingScreens[7]=
2001-04-03 23:28:56 +02:00
{
2001-06-04 18:10:06 +02:00
LOADINGSCREENS_PINEAPPLE_GFX, // Chapter 1
LOADINGSCREENS_CULTURE_GFX, // Chapter 2
LOADINGSCREENS_PICKLES_GFX, // Chapter 3
LOADINGSCREENS_MONITOR_GFX, // Chapter 4
LOADINGSCREENS_KARATE_GFX, // Chapter 5
LOADINGSCREENS_PIZZA_GFX, // Fma
2001-04-03 23:28:56 +02:00
};
2001-04-19 01:04:03 +02:00
/*****************************************************************************/
2001-05-16 21:06:47 +02:00
DVECTOR CLevel::MapPos;
DVECTOR CLevel::s_playerSpawnPos;
sLevelHdr *CLevel::LevelHdr;
2001-04-19 01:04:03 +02:00
2001-05-04 23:58:41 +02:00
u8 CLevel::m_isBossRespawn;
s32 CLevel::m_bossHealth;
2001-04-03 23:28:56 +02:00
/*****************************************************************************/
2001-05-16 21:06:47 +02:00
CLevel::CLevel()
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
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-06-28 19:48:30 +02:00
LevelHdr->ElemBank2d=(sElem2d*) MakePtr(LevelHdr,(int)LevelHdr->ElemBank2d);
LevelHdr->ElemBank3d=(sElem3d*) MakePtr(LevelHdr,(int)LevelHdr->ElemBank3d);
2001-04-19 01:04:03 +02:00
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-06-28 19:48:30 +02:00
CModelGfx::SetData(LevelHdr);//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-05-16 21:06:47 +02:00
/*****************************************************************************/
bool CLevel::GetNextLevel(int &Lvl)
{
bool Finished=false;
Lvl++;
2001-05-23 22:24:33 +02:00
if (Lvl>=LvlTableSize)
2001-05-16 21:06:47 +02:00
{
Lvl=0;
Finished=true;
}
2001-05-17 15:43:43 +02:00
2001-05-16 21:06:47 +02:00
return(Finished);
}
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-06-28 21:14:44 +02:00
ScalableFontBank font;
char buf[256];
u8 *s_image;
int i;
2001-04-02 17:48:02 +02:00
font.initialise(&standardFont);
font.setJustification(FontBank::JUST_CENTRE);
2001-06-28 21:14:44 +02:00
font.setScale(370);
2001-05-31 23:17:33 +02:00
sprintf(buf,"%s\n\n%s",TranslationDatabase::getString(lvlTab->ChapterLoadingText),TranslationDatabase::getString(lvlTab->LevelLoadingText));
2001-04-19 01:04:03 +02:00
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);
2001-06-28 21:14:44 +02:00
font.print(256 ,90 ,buf);
2001-04-03 17:12:40 +02:00
font.setColour(0,0,0);
2001-06-28 21:14:44 +02:00
font.print(256-1,90-1,buf);
font.print(256-1,90 ,buf);
font.print(256-1,90+1,buf);
font.print(256 ,90-1,buf);
font.print(256 ,90+1,buf);
font.print(256+1,90-1,buf);
font.print(256+1,90 ,buf);
font.print(256+1,90+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-05-23 22:24:33 +02: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
2001-05-23 22:24:33 +02:00
if (LevelHdr->MidLayer)
2000-12-08 15:48:50 +01:00
{
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
2001-05-23 22:24:33 +02:00
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-05-23 22:24:33 +02:00
if (LevelHdr->CollisionLayer)
2001-02-02 20:16:49 +01:00
{
sLayerHdr *Layer=(sLayerHdr*)MakePtr(LevelHdr,LevelHdr->CollisionLayer);
CollisionLayer=new ("Collision Layer") CLayerCollision(Layer);
2001-05-25 21:04:29 +02:00
CGameScene::setCollision(CollisionLayer);
2001-02-02 20:16:49 +01:00
}
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)
{
2001-05-23 22:24:33 +02:00
2001-04-09 17:35:37 +02:00
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)
{
if (LevelHdr->TriggerList)
{
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->TriggerList);
TriggerCount=Hdr->Count;
TriggerList=(sThingTrigger*)MakePtr(Hdr,sizeof(sThingHdr));
2001-05-29 22:31:02 +02:00
// Cam Locks first
2001-05-04 21:34:09 +02:00
for(int i=0;i<TriggerCount;i++)
{
2001-05-29 22:31:02 +02:00
if (TriggerList[i].Type==CTrigger::TRIGGER_CAMLOCK)
2001-05-04 21:34:09 +02:00
{
2001-05-29 22:31:02 +02:00
CTrigger::Create(&TriggerList[i]);
2001-05-04 21:34:09 +02:00
}
}
2001-05-29 22:31:02 +02:00
// the rest
2001-05-04 21:34:09 +02:00
TriggerList=(sThingTrigger*)MakePtr(Hdr,sizeof(sThingHdr));
for(int i=0;i<TriggerCount;i++)
{
2001-06-12 01:30:23 +02:00
if (TriggerList[i].Type!=CTrigger::TRIGGER_CAMLOCK)
2001-05-04 21:34:09 +02:00
{
2001-05-29 22:31:02 +02:00
CTrigger::Create(&TriggerList[i]);
2001-05-04 21:34:09 +02:00
}
}
}
// Items
if (LevelHdr->ItemList)
{
2001-06-01 20:59:33 +02:00
DVECTOR pos;
int itemNumber;
2001-05-04 21:34:09 +02:00
sThingHdr *Hdr=(sThingHdr*)MakePtr(LevelHdr,LevelHdr->ItemList);
ItemCount=Hdr->Count;
ItemList=(sThingItem*)MakePtr(Hdr,sizeof(sThingHdr));
2001-06-01 20:59:33 +02:00
itemNumber=0;
2001-05-04 21:34:09 +02:00
for(int i=0;i<ItemCount;i++)
{
2001-05-15 18:48:29 +02:00
int createThisPickup;
2001-06-01 20:59:33 +02:00
int isNumberedItem;
2001-05-09 22:15:01 +02:00
CBasePickup *newPickup;
2001-05-23 22:24:33 +02:00
2001-05-15 18:48:29 +02:00
createThisPickup=true;
2001-06-01 20:59:33 +02:00
isNumberedItem=false;
2001-06-14 17:19:57 +02:00
if((PICKUP_TYPE)ItemList->Type==PICKUP__KELP_TOKEN)
2001-06-01 20:59:33 +02:00
{
isNumberedItem=true;
if(CGameSlotManager::getSlotData()->isKelpTokenUncollected(GameScene.getChapterNumber()-1,GameScene.getLevelNumber()-1,itemNumber)==false)
{
createThisPickup=false;
}
2001-05-15 18:48:29 +02:00
}
2001-05-18 23:03:51 +02:00
if((PICKUP_TYPE)ItemList->Type==PICKUP__HELMET&&
2001-05-17 20:42:59 +02:00
_respawningLevel)
2001-05-15 18:48:29 +02:00
{
createThisPickup=false;
}
if(createThisPickup)
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-06-01 20:59:33 +02:00
if(isNumberedItem)
2001-05-09 22:15:01 +02:00
{
2001-06-14 17:19:57 +02:00
if((PICKUP_TYPE)ItemList->Type==PICKUP__KELP_TOKEN)
2001-06-01 20:59:33 +02:00
{
((CKelpTokenPickup*)newPickup)->setTokenNumber(itemNumber);
}
else
{
ASSERT(0);
}
2001-05-09 22:15:01 +02:00
}
}
2001-06-01 20:59:33 +02:00
if(isNumberedItem)
2001-05-09 22:15:01 +02:00
{
2001-06-01 20:59:33 +02:00
itemNumber++;
2001-05-04 21:34:09 +02:00
}
2001-05-15 18:48:29 +02:00
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->setupWaypoints( ThisActor );
enemy->postInit();
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);
2001-05-30 22:24:02 +02:00
friendNpc->setupWaypoints( ThisActor );
2001-05-04 21:34:09 +02:00
friendNpc->postInit();
}
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->postInit();
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 );
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-11 01:51:14 +02:00
CThingManager::initAllThings();
2001-05-23 22:24:33 +02:00
CThingManager::matchWheelsAndWeights();
2001-05-24 01:16:43 +02:00
CThingManager::matchPressureSwitches();
2001-05-30 22:24:02 +02:00
CThingManager::matchGaryTriggers();
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-05-23 22:24:33 +02:00
CollisionLayer->shutdown();
2001-04-03 23:28:56 +02:00
delete CollisionLayer;
}
CSoundMediator::stopAllSound();
2001-05-22 21:48:25 +02:00
for(int i=0;i<5;i++)
{
VSync(0);CSoundMediator::think(1); // This is needed to let xmplay kill off the sounds properly (pkg)
}
2001-04-03 23:28:56 +02:00
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
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-05-16 21:06:47 +02:00
void CLevel::destroyMapArea(DVECTOR const &Pos)
2001-05-03 00:49:59 +02:00
{
2001-05-16 21:06:47 +02:00
DVECTOR TL,BR;
2001-05-30 19:07:26 +02:00
const int ColT=COLLISION_TYPE_DESTRUCTABLE_WALL;
2001-05-03 00:49:59 +02:00
2001-05-16 21:06:47 +02:00
TL.vx=Pos.vx&-16;;
TL.vy=Pos.vy&-16;;
BR=TL;
2001-05-30 19:07:26 +02:00
// if (CollisionLayer->getCollisionBlock(TL.vx,TL.vy)>>COLLISION_TYPE_FLAG_SHIFT==ColT)printf ("!!");
2001-05-16 21:06:47 +02:00
// Left
while (CollisionLayer->getCollisionBlock(TL.vx-16,TL.vy)>>COLLISION_TYPE_FLAG_SHIFT==ColT) TL.vx-=16;
// Top
while (CollisionLayer->getCollisionBlock(TL.vx,TL.vy-16)>>COLLISION_TYPE_FLAG_SHIFT==ColT) TL.vy-=16;
// Right
while (CollisionLayer->getCollisionBlock(BR.vx+16,BR.vy)>>COLLISION_TYPE_FLAG_SHIFT==ColT) BR.vx+=16;
// Bottom
while (CollisionLayer->getCollisionBlock(BR.vx,BR.vy+16)>>COLLISION_TYPE_FLAG_SHIFT==ColT) BR.vy+=16;
DVECTOR DP;
2001-05-23 22:24:33 +02:00
2001-05-16 21:06:47 +02:00
for (DP.vy=TL.vy; DP.vy<=BR.vy; DP.vy+=16)
{
for (DP.vx=TL.vx; DP.vx<=BR.vx; DP.vx+=16)
{
u8 *ColElem=CollisionLayer->getMapPtr(DP.vx,DP.vy);
2001-05-16 22:10:46 +02:00
if (*ColElem>>COLLISION_TYPE_FLAG_SHIFT==ColT)
2001-05-16 21:06:47 +02:00
{
sTileMapElem *MapElem=TileLayers[CLayerTile::LAYER_TILE_TYPE_ACTION]->getMapPtr(DP.vx,DP.vy);
CFXFallingTile *FX=(CFXFallingTile*)CFX::Create(CFX::FX_TYPE_FALLINGTILE,DP);
FX->SetTile(MapElem->Tile);
MapElem->Tile=0;
*ColElem=0;
}
}
}
2001-05-03 00:49:59 +02:00
}
2001-06-19 00:20:45 +02:00
/*****************************************************************************/
2001-06-20 21:06:35 +02:00
// fixed now, so takes out whole vertical section, wherever it is hit
// Note: relies on tiles not being top or bottom of map tho!!
2001-06-19 00:20:45 +02:00
void CLevel::destroyMapTile(DVECTOR const &Pos)
{
int Width=CollisionLayer->getMapWidth();
2001-06-20 21:06:35 +02:00
DVECTOR MP=Pos;
const int ColT=COLLISION_TYPE_DESTRUCTABLE_FLOOR;
// Goto Top
while (*CollisionLayer->getMapPtr(MP.vx,MP.vy-1)>>COLLISION_TYPE_FLAG_SHIFT==ColT)
{
MP.vy-=16;
}
2001-06-19 00:20:45 +02:00
2001-06-20 21:06:35 +02:00
u8 *ColElem=CollisionLayer->getMapPtr(MP.vx,MP.vy);
sTileMapElem *MapElem=TileLayers[CLayerTile::LAYER_TILE_TYPE_ACTION]->getMapPtr(MP.vx,MP.vy);
2001-06-19 00:20:45 +02:00
2001-06-20 21:06:35 +02:00
// Thrash em down
2001-06-19 00:20:45 +02:00
while (*ColElem>>COLLISION_TYPE_FLAG_SHIFT==ColT)
{
CFXFallingTile *FX=(CFXFallingTile*)CFX::Create(CFX::FX_TYPE_FALLINGTILE,MP);
FX->SetTile(MapElem->Tile);
MapElem->Tile=0;
*ColElem=0;
MapElem+=Width;
ColElem+=Width;
MP.vy+=16;
}
}
2001-05-03 00:49:59 +02:00
2001-06-06 22:23:44 +02:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLevel::reverseMapConveyor(DVECTOR const &Pos)
{
DVECTOR TL,BR;
TL.vx=Pos.vx&-16;;
TL.vy=Pos.vy&-16;;
BR=TL;
int ColT=CollisionLayer->getCollisionBlock(TL.vx,TL.vy)>>COLLISION_TYPE_FLAG_SHIFT;
// if (CollisionLayer->getCollisionBlock(TL.vx,TL.vy)>>COLLISION_TYPE_FLAG_SHIFT==ColT)printf ("!!");
// Left
while (CollisionLayer->getCollisionBlock(TL.vx-16,TL.vy)>>COLLISION_TYPE_FLAG_SHIFT==ColT) TL.vx-=16;
// Top
while (CollisionLayer->getCollisionBlock(TL.vx,TL.vy-16)>>COLLISION_TYPE_FLAG_SHIFT==ColT) TL.vy-=16;
// Right
while (CollisionLayer->getCollisionBlock(BR.vx+16,BR.vy)>>COLLISION_TYPE_FLAG_SHIFT==ColT) BR.vx+=16;
// Bottom
while (CollisionLayer->getCollisionBlock(BR.vx,BR.vy+16)>>COLLISION_TYPE_FLAG_SHIFT==ColT) BR.vy+=16;
DVECTOR DP;
for (DP.vy=TL.vy; DP.vy<=BR.vy; DP.vy+=16)
{
for (DP.vx=TL.vx; DP.vx<=BR.vx; DP.vx+=16)
{
u8 *ColElem=CollisionLayer->getMapPtr(DP.vx,DP.vy);
if (*ColElem>>COLLISION_TYPE_FLAG_SHIFT==ColT)
{
if ( ColT == COLLISION_TYPE_MOVE_LEFT )
{
*ColElem &= ~COLLISION_TYPE_FLAG_MOVE_LEFT;
*ColElem |= COLLISION_TYPE_FLAG_MOVE_RIGHT;
}
else if ( ColT == COLLISION_TYPE_MOVE_RIGHT )
{
*ColElem &= ~COLLISION_TYPE_FLAG_MOVE_RIGHT;
*ColElem |= COLLISION_TYPE_FLAG_MOVE_LEFT;
}
}
}
}
}