diff --git a/changelog.txt b/changelog.txt
index 8bce63b4f..dce4a4700 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,11 +1,12 @@
Commander Genius Pre-Release v0.3 (CloneKeenPlus):
--------------------------------------------------
-
08-08-2009
+- Better source-code. At least a little bit :-)
- Special key items can only be taken once. Even replaying the levels
- Now levels can be exited without doing something before through the exit door. Be careful ;-)
- Vorticon Commander in Ep1 now dies with 105 shots.
- Improved consistency of the program
+- Improved memory management when decompressing graphics
- Improved Enemys AI
05-08-2009
diff --git a/src/CGame.cpp b/src/CGame.cpp
index 698f8ab37..b289ee2ea 100644
--- a/src/CGame.cpp
+++ b/src/CGame.cpp
@@ -111,6 +111,7 @@ short CGame::runCycle(stCloneKeenPlus *pCKP)
initgamefirsttime(pCKP, EGAGraphics->getNumSprites());
loadinggame = 0;
playgame_levelmanager(pCKP);
+
break;
case MAINMNU_2PLAYER:
defaultopt = 0;
@@ -167,34 +168,34 @@ short CGame::runCycle(stCloneKeenPlus *pCKP)
case MAINMNU_TIMEOUT:
case MAINMNU_DEMO:
- retval = play_demo(current_demo, pCKP, EGAGraphics->getNumSprites());
- 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
- }
+ retval = play_demo(current_demo, pCKP, EGAGraphics->getNumSprites());
- 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;
- }
- }
+ 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
+ }
- current_demo++;
+ 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("********************
");
diff --git a/src/ai/enemydata.h b/src/ai/enemydata.h
index cde4e8b6e..3029478db 100644
--- a/src/ai/enemydata.h
+++ b/src/ai/enemydata.h
@@ -100,13 +100,13 @@ typedef struct stTankData
{
char state;
- uint timer,animtimer;
+ unsigned int timer,animtimer;
unsigned char frame;
- uint dist_traveled;
+ unsigned int dist_traveled;
unsigned char movedir;
- uint ponsameleveltime;
+ unsigned int ponsameleveltime;
unsigned char alreadyfiredcauseonsamelevel;
unsigned char fireafterlook;
@@ -114,11 +114,11 @@ typedef struct stTankData
unsigned char detectedPlayerIndex; // index of player that was detected
// for tank2
- uint timetillnextshot;
- uint firetimes;
- uint timetillcanfire;
- uint timetillcanfirecauseonsamelevel;
- uint turnaroundtimer;
+ unsigned int timetillnextshot;
+ unsigned int firetimes;
+ unsigned int timetillcanfire;
+ unsigned int timetillcanfirecauseonsamelevel;
+ unsigned int turnaroundtimer;
int pausetime;
} stTankData;
diff --git a/src/cinematics/EndingSequenceEp1.cpp b/src/cinematics/EndingSequenceEp1.cpp
index 7a7747f4f..94e1dfa0e 100644
--- a/src/cinematics/EndingSequenceEp1.cpp
+++ b/src/cinematics/EndingSequenceEp1.cpp
@@ -280,17 +280,17 @@ int scrollingon;
int eseq1_BackAtHome(stCloneKeenPlus *pCKP)
{
-/*int draw;*/
-int i;
+ int i;
std::string text[10];
std::string strname;
std::string tempbuf;
-short textline, showtimer;
-unsigned short amountshown;
-signed int waittimer;
-int state;
-int enter, lastenterstate;
-int dlgX, dlgY, dlgW, dlgH;
+ short textline, showtimer;
+ unsigned short amountshown;
+ signed int waittimer;
+ int state;
+ int enter, lastenterstate;
+ int dlgX, dlgY, dlgW, dlgH;
+ int bmnum_window;
#define STATE_TEXTAPPEARING 0
#define STATE_WAITASEC 1
@@ -323,6 +323,7 @@ int dlgX, dlgY, dlgW, dlgH;
dlgY = GetStringAttribute("EP1_ESEQ_PART2_PAGE1", "TOP");
dlgW = GetStringAttribute("EP1_ESEQ_PART2_PAGE1", "WIDTH");
dlgH = GetStringAttribute("EP1_ESEQ_PART2_PAGE1", "HEIGHT");
+ bmnum_window = g_pGraphics->getBitmapNumberFromName("WINDOFF"); // window lights off
fade.mode = FADE_GO;
fade.rate = FADE_NORM;
@@ -331,81 +332,87 @@ int dlgX, dlgY, dlgW, dlgH;
fade.fadetimer = 0;
do
{
- enter = ( g_pInput->getPressedKey(KENTER) || g_pInput->getPressedKey(KCTRL) || g_pInput->getPressedKey(KALT) );
+ enter = ( g_pInput->getPressedKey(KENTER) || g_pInput->getPressedKey(KCTRL) || g_pInput->getPressedKey(KALT) );
- sb_dialogbox(dlgX, dlgY, dlgW, dlgH);
+ // Show the window (lights on or off)
+ g_pGraphics->drawBitmap(80, 0, bmnum_window);
- // draw the current text line up to the amount currently shown
+ sb_dialogbox(dlgX, dlgY, dlgW, dlgH);
+
+ // draw the current text line up to the amount currently shown
tempbuf = text[textline];
if(amountshown < tempbuf.size())
tempbuf.erase(amountshown);
- g_pGraphics->sb_font_draw( tempbuf, (dlgX+1)*8, (dlgY+1)*8);
+ g_pGraphics->sb_font_draw( tempbuf, (dlgX+1)*8, (dlgY+1)*8);
- if (state==STATE_TEXTAPPEARING)
- {
- if (enter) goto fullshow;
- if (showtimer > LETTER_SHOW_SPD)
- { // it's time to show a new letter
- amountshown++;
- if (amountshown > text[textline].size())
- { // reached end of line
- state = STATE_WAITASEC;
-// if (textline==8)
- // waittimer = -BACKHOME_SHORT_WAIT_TIME*3;
- // else
- waittimer = -BACKHOME_SHORT_WAIT_TIME*2;
- }
- // if the last letter shown is a dash/cr ('Billy...are you a-'),
- // show the rest of the text immediately
- // (for when the mom shouts "WHAT IS THIS ONE-EYED GREEN THING..."
- if (text[textline][amountshown]==13 && \
- text[textline][amountshown-1]=='-')
- {
- fullshow: ;
- amountshown = text[textline].size();
- state = STATE_WAITASEC;
- waittimer = -BACKHOME_SHORT_WAIT_TIME*3;
- }
- showtimer = 0;
- } else showtimer++;
+ if (state==STATE_TEXTAPPEARING)
+ {
+ if (enter) goto fullshow;
+ if (showtimer > LETTER_SHOW_SPD)
+ { // it's time to show a new letter
+ amountshown++;
+ if (amountshown > text[textline].size())
+ { // reached end of line
+ state = STATE_WAITASEC;
+ waittimer = -BACKHOME_SHORT_WAIT_TIME*2;
+ }
+ // if the last letter shown is a dash/cr ('Billy...are you a-'),
+ // show the rest of the text immediately
+ // (for when the mom shouts "WHAT IS THIS ONE-EYED GREEN THING..."
+ if (text[textline][amountshown]==13 && \
+ text[textline][amountshown-1]=='-')
+ {
+ fullshow: ;
+ amountshown = text[textline].size();
+ state = STATE_WAITASEC;
+ waittimer = -BACKHOME_SHORT_WAIT_TIME*3;
+ }
+ showtimer = 0;
+ } else showtimer++;
- // user pressed enter
- if (enter)
- { // show all text immediately
+ // user pressed enter
+ if (enter)
+ { // show all text immediately
- }
- }
- else if (state==STATE_WAITASEC)
- {
- if (enter) goto nextline;
- if (waittimer7)
- { // end of text
- break;
- }
- }
- }
- }
+ }
+ }
+ else if (state==STATE_WAITASEC)
+ {
+ if (enter) goto nextline;
+ if (waittimer 0 && textline < 5) || textline == 6)
+ bmnum_window = g_pGraphics->getBitmapNumberFromName("WINDON"); // lights on
+ else
+ bmnum_window = g_pGraphics->getBitmapNumberFromName("WINDOFF"); // lights off
- gamedo_fades();
- gamedo_frameskipping_blitonly();
+ textline++;
+ state = STATE_TEXTAPPEARING;
+ amountshown = 0;
+ if (textline>7)
+ { // end of text
+ break;
+ }
+ }
+ }
+ }
- lastenterstate = enter;
+ if (fade.dir==FADE_OUT && fade.mode==FADE_COMPLETE)
+ return 0;
- g_pInput->pollEvents();
- g_pTimer->SpeedThrottle();
- if (g_pInput->getPressedKey(KQUIT)) return 1;
+ gamedo_fades();
+ gamedo_frameskipping_blitonly();
+
+ lastenterstate = enter;
+
+ g_pInput->pollEvents();
+ g_pTimer->SpeedThrottle();
+ if (g_pInput->getPressedKey(KQUIT)) return 1;
} while(1);
finale_draw("finale.ck1", pCKP->GameData[pCKP->Resources.GameSelected-1].DataDirectory);
diff --git a/src/cinematics/EndingSequenceEp1.h b/src/cinematics/EndingSequenceEp1.h
index 42cee4112..f3bfe3383 100644
--- a/src/cinematics/EndingSequenceEp1.h
+++ b/src/cinematics/EndingSequenceEp1.h
@@ -12,5 +12,4 @@ void eseq_ToBeContinued();
void eseq_showmsg(const std::string& text, int boxleft, int boxtop,
int boxwidth, int boxheight, bool autodismiss);
-
#endif /* ENDINGSEQUENCEEP1_H_ */
diff --git a/src/demobox.h b/src/demobox.h
index 47ada6c9a..ba3961519 100644
--- a/src/demobox.h
+++ b/src/demobox.h
@@ -10,7 +10,7 @@
#define DEMOBOX_WIDTH 48
#define DEMOBOX_HEIGHT 16
-unsigned char demobox_image[768] = { \
+/*unsigned char demobox_image[768] = { \
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, \
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, \
15,15,15,12,12,12,12,12,12,15,15,15,15,12,12,12,12,12,12,12,15,15,12,15,15,15,15,15,15,15,12,15,15,15,15,12,12,12,12,15,15,15,15,15,15,15,15,15,15, \
@@ -27,6 +27,25 @@ unsigned char demobox_image[768] = { \
4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, \
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, \
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, \
+};*/
+
+unsigned char demobox_image[768] = { \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0, 0, 0,12,12,12,12,12,12, 0, 0, 0, 0,12,12,12,12,12,12,12, 0, 0,12, 0, 0, 0, 0, 0, 0, 0,12, 0, 0, 0, 0,12,12,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0, 0,12,12, 0, 0, 0,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0,12,12, 0, 0, 0, 0, 0,12,12, 0, 0, 0,12,12, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0,12,12, 0, 0, 0, 0,12,12, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0,12,12,12, 0, 0, 0,12,12,12, 0, 0,12,12, 0, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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44b44943c..b383e57b1 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -10,12 +10,12 @@
#include "sdl/sound/CSound.h"
#include "hqp/CMusic.h"
#include "include/fileio.h"
+#include
#include "include/fileio/rle.h"
#include "CLogFile.h"
#include "CGraphics.h"
#include
#include
-#include
#include "StringUtils.h"
#include "Debug.h"
#include "FindFile.h"
@@ -473,7 +473,6 @@ unsigned int temp1, temp2, temp3, temp4;
unsigned int loadmap(const std::string& filename, const std::string& path,
int lvlnum,stLevelControl* p_levelcontrol)
{
-
// TODO: Tie that one up in converting stuff into C++
FILE *fp;
@@ -495,37 +494,29 @@ unsigned int loadmap(const std::string& filename, const std::string& path,
fp = OpenGameFile(fname.c_str(), "rb");
if (!fp)
{
- // only record this error message on build platforms that log errors
- // to a file and not to the screen.
+ // only record this error message on build platforms that log errors
+ // to a file and not to the screen.
g_pLogFile->ftextOut("loadmap(): unable to open file %s
", fname.c_str());
- return 1;
+ return 1;
}
g_pLogFile->ftextOut("loadmap(): file %s opened. Loading...
", fname.c_str());
// decompress map RLEW data
curmapx = curmapy = mapdone = 0;
- unsigned int *filebuf; // big File Buffer for the uncompression
- filebuf = (unsigned int*) malloc(1000000*sizeof(int));
+ std::vector filebuf;
+ unsigned long finsize; // Final size
- if(filebuf == NULL)
- {
- g_pLogFile->ftextOut("loadmap(): unable to allocate memory for unpacking the level file
", fname.c_str());
- return 1;
- }
-
- int finsize; // Final size
-
- finsize = unRLEW(fp, filebuf);
+ finsize = unRLEW(fp, filebuf);
c=0;
- if(finsize == -1)
+ if(!finsize)
{
rewind(fp);
while(!feof(fp))
{
- filebuf[c] = fgeti(fp);
+ filebuf.push_back( fgeti(fp) );
c++;
}
}
@@ -569,8 +560,7 @@ unsigned int loadmap(const std::string& filename, const std::string& path,
c++;
}
- free(filebuf);
-
+ filebuf.clear();
fclose(fp);
// HQ Sounds. Load Music for a level if you have HQP
diff --git a/src/fileio/rle.cpp b/src/fileio/rle.cpp
index f4e938079..224eeaa69 100644
--- a/src/fileio/rle.cpp
+++ b/src/fileio/rle.cpp
@@ -5,14 +5,16 @@
* Author: gerstrong
*/
+#include
#include
-#include "../funcdefs.h"
+// Reference to ../fileio.cpp
+unsigned int fgeti(FILE *fp);
-int unRLEW(FILE *fp, unsigned int *filebuf)
+unsigned long unRLEW(FILE *fp, std::vector& filebuf)
{
-
- int t,i, howmany, cursize, finsize;
+ int t,i, howmany, cursize;
+ unsigned int finsize;
/*
1.) If implemented, get the first dword in the file, [Final Length]
2.) If [Length of data so far] < [Final Length] then:
@@ -31,28 +33,26 @@ int unRLEW(FILE *fp, unsigned int *filebuf)
rewind(fp);
-
while(!feof(fp)) // Detect, if the file is really RLEW compressed!
{
t = fgeti(fp);
if(t == 0xFEFE)
{
cursize = 1;
+ filebuf.push_back(1);
break;
}
}
if(cursize == 0)
- {
- return -1; // This file is not RLEW compressed!
- }
+ return 0; // This file is not RLEW compressed!
+
rewind(fp);
finsize = fgeti(fp);
-
- while( cursize < finsize )
+ while( filebuf.size() < finsize )
{
t = fgeti(fp);
if (t == 0xFEFE)
@@ -61,16 +61,19 @@ int unRLEW(FILE *fp, unsigned int *filebuf)
t = fgeti(fp);
for(i=0;iplaySound(SOUND_GET_CARD, PLAY_NOW);
- if (doortile==DOOR_YELLOW) player[p].inventory.HasCardYellow = keystack ? player[p].inventory.HasCardYellow + 1 : 1;
- else if (doortile==DOOR_RED) player[p].inventory.HasCardRed = keystack ? player[p].inventory.HasCardRed + 1 : 1;
- else if (doortile==DOOR_GREEN) player[p].inventory.HasCardGreen = keystack ? player[p].inventory.HasCardGreen + 1 : 1;
- else if (doortile==DOOR_BLUE) player[p].inventory.HasCardBlue = keystack ? player[p].inventory.HasCardBlue + 1 : 1;
+ if (doortile==DOOR_YELLOW && player[p].inventory.HasCardYellow < 9)
+ player[p].inventory.HasCardYellow++;
+ else if (doortile==DOOR_RED && player[p].inventory.HasCardRed < 9)
+ player[p].inventory.HasCardRed++;
+ else if (doortile==DOOR_GREEN && player[p].inventory.HasCardGreen < 9)
+ player[p].inventory.HasCardGreen++;
+ else if (doortile==DOOR_BLUE && player[p].inventory.HasCardBlue < 9)
+ player[p].inventory.HasCardBlue++;
else
{
- crashflag = 1;
+ crashflag = 0;
crashflag2 = doortile;
- why_term_ptr = "give_keycard(): invalid value for doortile parameter.";
+ g_pLogFile->textOut("give_keycard(): invalid value for doortile parameter.
");
}
}
// take away the specified keycard from player p
void take_keycard(int doortile, int p)
{
- if (doortile==DOOR_YELLOW) player[p].inventory.HasCardYellow--;
- else if (doortile==DOOR_RED) player[p].inventory.HasCardRed--;
- else if (doortile==DOOR_GREEN) player[p].inventory.HasCardGreen--;
- else if (doortile==DOOR_BLUE) player[p].inventory.HasCardBlue--;
-
- if(player[p].inventory.HasCardYellow > 9) player[p].inventory.HasCardYellow = 0;
- if(player[p].inventory.HasCardRed > 9) player[p].inventory.HasCardRed = 0;
- if(player[p].inventory.HasCardGreen > 9) player[p].inventory.HasCardGreen = 0;
- if(player[p].inventory.HasCardBlue > 9) player[p].inventory.HasCardBlue = 0;
+ if (doortile==DOOR_YELLOW && player[p].inventory.HasCardYellow > 0)
+ player[p].inventory.HasCardYellow--;
+ else if (doortile==DOOR_RED && player[p].inventory.HasCardRed > 0)
+ player[p].inventory.HasCardRed--;
+ else if (doortile==DOOR_GREEN && player[p].inventory.HasCardGreen > 0)
+ player[p].inventory.HasCardGreen--;
+ else if (doortile==DOOR_BLUE && player[p].inventory.HasCardBlue > 0)
+ player[p].inventory.HasCardBlue--;
}
// unregisters all animated tiles with baseframe tile
diff --git a/src/gamedo.cpp b/src/gamedo.cpp
index 7eb7177eb..6cb64631f 100644
--- a/src/gamedo.cpp
+++ b/src/gamedo.cpp
@@ -243,7 +243,7 @@ int i, topobj;
if (objects[i].hasbeenonscreen || objects[i].zapped ||
objects[i].type==OBJ_RAY || \
- objects[i].type==OBJ_ICECHUNK || objects[i].type==OBJ_PLATFORM ||\
+ objects[i].type==OBJ_ICECHUNK || objects[i].type==OBJ_PLATFORM ||
objects[i].type==OBJ_PLATVERT || objects[i].type==OBJ_YORP ||
objects[i].type==OBJ_FOOB || objects[i].type==OBJ_WALKER)
@@ -291,13 +291,14 @@ int i, topobj;
//case OBJ_GOTPOINTS: gotpoints_ai(i); break;
case OBJ_DEMOMSG: break;
+
default:
g_pLogFile->ftextOut("gamedo_enemy_ai: Object %d is of invalid type %d\n", i, objects[i].type);
break;
}
- objects[i].scrx = (objects[i].x>>CSF)-scroll_x;
- objects[i].scry = (objects[i].y>>CSF)-scroll_y;
+ objects[i].scrx = (objects[i].x>>CSF)-scroll_x;
+ objects[i].scry = (objects[i].y>>CSF)-scroll_y;
}
}
}
@@ -486,33 +487,26 @@ int xa,ya;
}
- // if we're playing a demo keep the "DEMO" message on the screen
- // as an object
- // TODO: It would be better to add this demo message as on object, like the other stuff that is shown
- // This still must be done...
- /*if (show_demo_title)
- {
- #define DEMO_X_POS 137
- #define DEMO_Y_POS 6
- objects[DemoObjectHandle].exists = 1;
- objects[DemoObjectHandle].onscreen = 1;
- objects[DemoObjectHandle].type = OBJ_DEMOMSG;
- objects[DemoObjectHandle].sprite = DemoSprite;
- objects[DemoObjectHandle].x = (DEMO_X_POS+scroll_x)<>CSF)-scroll_x);
- objects[i].scry = ((objects[i].y>>CSF)-scroll_y);
- g_pGraphics->drawSprite(objects[i].scrx, objects[i].scry, objects[i].sprite, i);
+ // Draw the Demo-Bar if it must be shown
+ if(objects[i].type == OBJ_DEMOMSG)
+ {
+ #define DEMO_X_POS 137
+ #define DEMO_Y_POS 6
+ objects[i].scrx = DEMO_X_POS;
+ objects[i].scry = DEMO_Y_POS;
+ }
+ else
+ {
+ objects[i].scrx = ((objects[i].x>>CSF)-scroll_x);
+ objects[i].scry = ((objects[i].y>>CSF)-scroll_y);
+ }
+ g_pGraphics->drawSprite(objects[i].scrx, objects[i].scry, objects[i].sprite, i);
if (objects[i].honorPriority)
{
@@ -552,9 +546,8 @@ int xa,ya;
}
}
- if(i==0) break;
+ if(i==0) break;
}
-
}
void gamedo_render_drawdebug(void)
diff --git a/src/gm_pdowm.cpp b/src/gm_pdowm.cpp
index 4c1c8aae0..67b99ddbb 100644
--- a/src/gm_pdowm.cpp
+++ b/src/gm_pdowm.cpp
@@ -49,14 +49,14 @@ void gamepdo_wm_HandlePlayer(int cp, stCloneKeenPlus *pCKP)
AllowMountUnmountNessie(cp);
}
- gamepdo_wm_SelectFrame(cp);
+ gamepdo_wm_SelectFrame(cp, pCKP->Control.levelcontrol.episode);
// copy player's keytable to lastkeytable
memcpy(&player[cp].lastkeytable, &player[cp].keytable, sizeof(player[cp].lastkeytable));
}
// select the appropriate player frame based on what he's doing
-void gamepdo_wm_SelectFrame(int cp)
+void gamepdo_wm_SelectFrame(int cp, int episode)
{
// select base frame for current direction
if (player[cp].pshowdir==RIGHT) player[cp].playframe = PMAPRIGHTFRAME;
@@ -64,6 +64,9 @@ void gamepdo_wm_SelectFrame(int cp)
else if (player[cp].pshowdir==UP) player[cp].playframe = PMAPUPFRAME;
else if (player[cp].pshowdir==DOWN) player[cp].playframe = PMAPDOWNFRAME;
+ // episode 3 map frames start at 31, ep1&2 at 32
+ if (episode==3) player[cp].playframe--;
+
// no walking animation if we're fading
if (fade.mode != NO_FADE) return;
diff --git a/src/include/fileio/rle.h b/src/include/fileio/rle.h
index 4cacc69a7..133da704d 100644
--- a/src/include/fileio/rle.h
+++ b/src/include/fileio/rle.h
@@ -5,4 +5,4 @@
* Author: gerstrong
*/
-int unRLEW(FILE *fp, unsigned int *filebuf);
+unsigned long unRLEW(FILE *fp, std::vector& filebuf);
diff --git a/src/include/gm_pdowm.h b/src/include/gm_pdowm.h
index 2b70ac729..2946aa49c 100644
--- a/src/include/gm_pdowm.h
+++ b/src/include/gm_pdowm.h
@@ -3,7 +3,7 @@ void gamepdo_wm_HandlePlayer(int cp, stCloneKeenPlus *pCKP);
void gamepdo_InertiaAndFriction_Y(int cp, stCloneKeenPlus *pCKP);
void gamepdo_InertiaAndFriction_X(unsigned int cp, stCloneKeenPlus *pCKP);
void gamepdo_wm_AllowEnterLevel(int cp, stCloneKeenPlus *pCKP);
-void gamepdo_wm_SelectFrame(int cp);
+void gamepdo_wm_SelectFrame(int cp, int episode);
void gamepdo_wm_setblockedlrud(int cp, stCloneKeenPlus *pCKP);
void gamepdo_wm_setdir(int cp, stCloneKeenPlus *pCKP);
diff --git a/src/main.cpp b/src/main.cpp
index 171907592..9a3a633fd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -109,6 +109,7 @@ unsigned int numplayers;
int crashflag,crashflag2,crashflag3;
const char *why_term_ptr = "No reason given.";
+
int main(int argc, char *argv[])
{
banner(); // Intro on the text-console.
@@ -172,11 +173,7 @@ int main(int argc, char *argv[])
if(!CKP.Control.skipstarting)
{
while(!loadStartMenu(&CKP))
- {
g_pLogFile->textOut(PURPLE,"Error! You have chosen a Game that doesn't exist. Please correct the \"games.cfg\" File under \"data\" and choose another game.
");
- //cleanupResources(&CKP);
- //return 0;
- }
}
if(!g_pInput->getExitEvent())
@@ -194,17 +191,14 @@ int main(int argc, char *argv[])
{
if(CKP.shutdown != SHUTDOWN_NEW_GAME) {
CKP.shutdown = SHUTDOWN_NONE; // Game is runnning
+
Game.runCycle(&CKP);
}
if(CKP.shutdown == SHUTDOWN_NEW_GAME)
{
while(!loadStartMenu(&CKP))
- {
g_pLogFile->textOut(PURPLE,"Error! You have chosen a Game that doesn't exist. Please correct the \"games.cfg\" File under \"data\" and choose another game.
");
- //cleanupResources(&CKP);
- //return 0;
- }
//loadResourcesforGame(pCKP);
if(Game.loadResources(CKP.Control.levelcontrol.episode, CKP.GameData[CKP.Resources.GameSelected-1].DataDirectory))
@@ -291,7 +285,6 @@ short closeCKP(stCloneKeenPlus *pCKP)
int eseq2_TantalusRay(stCloneKeenPlus *pCKP);
void eseq2_vibrate();
-
void playgame_levelmanager(stCloneKeenPlus *pCKP)
{
int i, o, wm, firsttime = 1;
@@ -357,7 +350,7 @@ void playgame_levelmanager(stCloneKeenPlus *pCKP)
p_levelcontrol->command = LVLC_NOCOMMAND;
- p_levelcontrol->dark = 0;
+ p_levelcontrol->dark = false;
p_levelcontrol->usedhintmb = false;
if (loadinggame)
{
@@ -378,6 +371,20 @@ void playgame_levelmanager(stCloneKeenPlus *pCKP)
g_pInput->flushAll();
+ // Check if we are in Demo-mode. If yes, add the upper logo to the objects
+ if(pCKP->Control.levelcontrol.demomode)
+ {
+ objects[DemoObjectHandle].exists = 1;
+ objects[DemoObjectHandle].onscreen = 1;
+ objects[DemoObjectHandle].type = OBJ_DEMOMSG;
+ objects[DemoObjectHandle].sprite = DemoSprite;
+ objects[DemoObjectHandle].x = 0;
+ objects[DemoObjectHandle].y = 0;
+ objects[DemoObjectHandle].honorPriority = 0;
+ }
+ else
+ objects[DemoObjectHandle].exists = 0;
+
if (wm)
{ // entering map from normal level, or first time around
if (!p_levelcontrol->tobonuslevel)
diff --git a/src/map.cpp b/src/map.cpp
index a7c2dc81f..3486ae496 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -178,32 +178,21 @@ int ya = y>>4;
if (xa<=255 && ya<=255)
{
- return map.mapdata[xa][ya];
+ return map.mapdata[xa][ya];
}
else
{
if(xa > 255)
- {
xa = 255;
- //player[cp].xa = 255;
- }
+
if(ya > 254)
- {
ya = 255;
- //player[cp].ya = 255;
- }
return map.mapdata[xa][ya];
- //crashflag = 1;
- //crashflag2 = x;
- //crashflag3 = y;
- //why_term_ptr = "getmaptileat(): OOB reading from mapdata.";
- //return 0;
}
}
unsigned int getlevelat(unsigned int x, unsigned int y)
{
-
return map.objectlayer[x>>4][y>>4];
}
@@ -212,11 +201,10 @@ unsigned int getlevelat(unsigned int x, unsigned int y)
// in stripes as it scrolls around.
void drawmap(void)
{
-int y;
+ int y;
+
for(y=0;y