update 20.06.2009

git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@27 4df4b0f3-56ce-47cb-b001-ed939b7d65a6
This commit is contained in:
gerstrong
2009-06-20 18:08:58 +00:00
parent 0e9ddc542c
commit 053a44eeae
58 changed files with 838 additions and 1298 deletions

View File

@@ -7,10 +7,20 @@
#include <stdlib.h>
#include "CGame.h"
#include "fileio.h"
#include "keen.h"
#include "CGame.h"
#include "include/game.h"
#include "include/misc.h"
#include "include/main.h"
#include "include/menu.h"
#include "include/fileio/story.h"
#include "vorticon/CHighScores.h"
#include "vorticon/CIntro.h"
#include "vorticon/CCredits.h"
#include "CLogFile.h"
#include "fileio.h"
#include "sdl/sound/CSound.h"
#include "sdl/CVideoDriver.h"
CGame::CGame() {
m_Episode = 0;
@@ -22,9 +32,189 @@ CGame::~CGame() {
if(Latch){ delete Latch; Latch = NULL;}
}
void CGame::runCycle(void)
short CGame::runCycle(stCloneKeenPlus *pCKP)
{
// TODO: Code here!!
int opt = MAINMNU_1PLAYER;
int retval;
int eseq = 0;
int defaultopt = 0;
initgamefirsttime(pCKP, Latch->getLatchHeader()->NumSprites);
initgame(pCKP);
g_pLogFile->ftextOut("Game starting...<br>");
if (eseq)
{
endsequence(pCKP);
closeCKP(pCKP);
}
if(!pCKP->Control.skipstarting)
{
CIntro Intro;
Intro.Render(pCKP);
//if (intro(pCKP)){ pCKP->shutdown=SHUTDOWN_EXIT; return 0; }
pCKP->Control.skipstarting=0;
}
do
{
if (QuitState==QUIT_TO_TITLE) QuitState = NO_QUIT;
if(pCKP->Control.storyboard == 1) // Show the story of the game
{
char *text;
int textsize;
textsize = readStoryText(&text,
pCKP->GameData[pCKP->Resources.GameSelected-1].Episode,
pCKP->GameData[pCKP->Resources.GameSelected-1].DataDirectory); // Read text from
// and store it at the text pointer
if(textsize > 0)
{
showPage(text,pCKP,textsize);
free(text);
}
else if(textsize == 0)
{
g_pLogFile->ftextOut("readStoryText(): Error reading story text. Are you sure that there is any story text?");
}
else if(textsize == 0)
{
g_pLogFile->ftextOut("readStoryText(): Error reading story text. The version appears to be incompatible");
}
pCKP->Control.storyboard = 0;
}
if(pCKP->Control.levelcontrol.command != LVLC_START_LEVEL)
{
g_pLogFile->ftextOut("calling mainmenu()<br>");
opt = mainmenu(pCKP, defaultopt); // Read option from the main menu
// of the game.
pCKP->Control.skipstarting=0;
g_pLogFile->ftextOut("gcl: opt = %d<br>", opt);
}
defaultopt = 0;
IntroCanceled = 0;
switch(opt)
{
case MAINMNU_1PLAYER:
numplayers = 1;
defaultopt = 0;
current_demo = 1;
initgamefirsttime(pCKP, Latch->getLatchHeader()->NumSprites);
loadinggame = 0;
playgame_levelmanager(pCKP);
break;
case MAINMNU_2PLAYER:
defaultopt = 0;
current_demo = 1;
numplayers = 2;
initgamefirsttime(pCKP, Latch->getLatchHeader()->NumSprites);
loadinggame = 0;
playgame_levelmanager(pCKP);
break;
case MAINMNU_LOADGAME:
if (loadslot)
{
loadinggame = 1;
defaultopt = 0;
current_demo = 1;
numplayers = 1; // here was 2. Why was that? I don't understand
initgamefirsttime(pCKP, Latch->getLatchHeader()->NumSprites);
playgame_levelmanager(pCKP);
}
break;
case MAINMNU_STORY:
pCKP->Control.storyboard=1;
break;
case MAINMNU_HIGHSCORES:
CHighScores *pHighscores;
pHighscores = new CHighScores(pCKP);
if(pHighscores->showHighScore())
{
g_pLogFile->ftextOut("Error processing Highscore!!<br>");
}
delete pHighscores;
break;
case MAINMNU_NEW_GAME:
if(loadStartMenu(pCKP) == 1)
{
pCKP->shutdown = SHUTDOWN_EXIT;
break;
}
//loadResourcesforGame(pCKP);
loadResources(pCKP->Control.levelcontrol.episode, pCKP->GameData[pCKP->Resources.GameSelected-1].DataDirectory);
pCKP->shutdown = SHUTDOWN_RESTART;
break;
case MAINMNU_ABOUT:
CCredits *pCredit;
pCredit = new CCredits;
pCredit->Render(pCKP);
delete pCredit;
pCredit = NULL;
break;
case MAINMNU_TIMEOUT:
case MAINMNU_DEMO:
retval = play_demo(current_demo, pCKP, Latch->getLatchHeader()->NumSprites);
if (retval==DEMO_RESULT_FILE_BAD)
{
// we tried to play a demo that did not exist--assume we
// reached the last demo and go back to the intro
//intro(pCKP);
CIntro *pIntro;
pIntro = new CIntro();
delete pIntro;
pIntro = NULL;
current_demo = 0;
}
else if (retval==DEMO_RESULT_CANCELED)
{ // user hit a key to cancel demo
IntroCanceled = 1; // pop up menu
}
if (IntroCanceled)
{ // user canceled out of demo (or intro if at end of demos)
// if user selected "demo" have it selected when he comes back
if (opt==MAINMNU_DEMO)
{
defaultopt = MAINMNU_DEMO;
}
}
current_demo++;
break;
case RESTART_GAME:
g_pLogFile->ftextOut("********************<br>");
g_pLogFile->ftextOut(" Restarting game...<br>");
g_pLogFile->ftextOut("********************<br>\n");
cleanup(pCKP);
pCKP->shutdown = SHUTDOWN_RESTART;
return 0;
break;
case BACK2MAINMENU:
default: break;
}
g_pLogFile->ftextOut("bottom of game control loop opt=%d crashflag=%d<br>", opt, crashflag);
if(pCKP->shutdown == SHUTDOWN_EXIT) break;
} while(opt != MAINMNU_QUIT && opt != MAINMNU_NEW_GAME && !crashflag);
return 0;
}
int CGame::loadResources(unsigned short Episode, char *DataDirectory)
@@ -44,5 +234,36 @@ int CGame::loadResources(unsigned short Episode, char *DataDirectory)
return 0;
}
void CGame::preallocateCKP(stCloneKeenPlus *pCKP)
{
// This function prepares the CKP Structure so that the it is allocated in the memory.
pCKP->numGames = 0;
pCKP->Resources.GameSelected = 0;
TileProperty = NULL;
pCKP->GameData = NULL;
pCKP->GameData = new stGameData[1];
memset(pCKP->GameData, 0, sizeof(stGameData));
framebyframe = 0;
demomode = DEMO_NODEMO;
current_demo = 1;
memset(&pCKP->Control, 0, sizeof(stControl));
pCKP->Joystick = NULL;
acceleratemode = 0;
g_pVideoDriver->showFPS(false);
player[0].x = player[0].y = 0;
}
CLatch *CGame::getLatch(void)
{ return Latch; }