diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index ba1c2af..1b049e4 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -113,6 +113,9 @@ BlockGame::~BlockGame() void BlockGame::setGameSpeed(Uint8 globalSpeedLevel) { + format f("GAMESPEED %1%"); + f % globalSpeedLevel; + ActionPerformed(f.str()); switch (globalSpeedLevel) { case 0: @@ -138,6 +141,9 @@ void BlockGame::setGameSpeed(Uint8 globalSpeedLevel) void BlockGame::setHandicap(Uint8 globalHandicap) { + format f("HANDICAP %1%"); + f % globalHandicap; + ActionPerformed(f.str()); handicap=1000*((Uint32)globalHandicap); } @@ -251,6 +257,9 @@ int BlockGame::GetCursorY() void BlockGame::MoveCursorTo(int x, int y) { + format f("MC2 %1% %2%"); + f % x % y; + ActionPerformed(f.str()); cursorx = x; cursory = y; } @@ -348,11 +357,13 @@ void BlockGame::NewGame(int tx, int ty, unsigned int ticks) lastAImove = ticks+3000; showGame = true; theReplay = Replay(); + ActionPerformed("NEW"); } //NewGame void BlockGame::NewTimeTrialGame(int x,int y, unsigned int ticks) { NewGame(x,y,ticks); + ActionPerformed("NEWTT"); timetrial = true; putStartBlocks(); } @@ -439,6 +450,7 @@ void BlockGame::nextLevel(unsigned int ticks) void BlockGame::NewVsGame(int tx, int ty, BlockGame *target,unsigned int ticks) { NewGame(tx, ty,ticks); + ActionPerformed("NEWVS"); vsMode = true; putStartBlocks(); garbageTarget = target; @@ -492,6 +504,7 @@ void BlockGame::playNetwork(int tx, int ty,unsigned int ticks) //Prints "winner" and ends game void BlockGame::setPlayerWon() { + ActionPerformed("WON"); if (!bGameOver) { gameEndedAfter = ticks-gameStartedAt; //We game ends now! @@ -535,6 +548,7 @@ void BlockGame::setDisconnect() //Prints "draw" and ends the game void BlockGame::setDraw() { + ActionPerformed("DRAW"); bGameOver = true; if(!AI_Enabled && !bReplaying) { @@ -728,6 +742,9 @@ void BlockGame::putStartBlocks() void BlockGame::putStartBlocks(Uint32 n) { + format f("STARTBLOCKS %1%"); + f % n; + ActionPerformed(f.str()); for (int i=0; i<7; i++) for (int j=0; j<30; j++) { @@ -890,6 +907,9 @@ void BlockGame::ReduceStuff() //Creates garbage using a given wide and height bool BlockGame::CreateGarbage(int wide, int height) { + format f("CG %1% %2%"); + f % wide % height; + ActionPerformed(f.str()); #if NETWORK if (bNetworkPlayer) { @@ -933,6 +953,7 @@ bool BlockGame::CreateGarbage(int wide, int height) //Creates garbage using a given wide and height bool BlockGame::CreateGreyGarbage() { + ActionPerformed("GG"); #if NETWORK if (bNetworkPlayer) { @@ -1352,6 +1373,7 @@ void BlockGame::ClearBlocks() //prints "Game Over" and ends game void BlockGame::SetGameOver() { + ActionPerformed("GAMEOVER"); if (!bGameOver) { gameEndedAfter = ticks-gameStartedAt; //We game ends now! @@ -1452,6 +1474,9 @@ void BlockGame::FallDown() //Moves the cursor, receaves N,S,E or W as a char an moves as desired void BlockGame::MoveCursor(char way) { + format f("MC %1%"); + f % way; + ActionPerformed(f.str()); if (!bGameOver) //If game over nothing happends { if ((way == 'N') && ((cursory<10)||(TowerHeight>12) ||(((pixels==bsize)||(pixels==0)) && (cursory<11)))) @@ -1480,6 +1505,7 @@ void BlockGame::SwitchAtCursor() //Generates a new line and moves the field one block up (restart puzzle mode) void BlockGame::PushLine() { + ActionPerformed("PL"); //If not game over, not high tower and not puzzle mode if ((!bGameOver) && TowerHeight<13 && (!puzzleMode) && (gameStartedAt ticks+50) + { + ticks = newtick; + Update(); + } +} + +void BlockGame::ActionPerformed(string action) { + if(bGameOver) + return; + theReplay.addAction(ticks,action); } //////////////////////////////////////////////////////////////////////////////// ///////////////////////// BlockAttack class end //////////////////////////////// diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index c0d393b..6a365d8 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -295,6 +295,8 @@ private: private: + void ActionPerformed(string action); + //Updates evrything, if not called nothing happends void Update(); public: diff --git a/source/code/block.make b/source/code/block.make index 22b4618..f1282ee 100644 --- a/source/code/block.make +++ b/source/code/block.make @@ -47,7 +47,7 @@ $(BINARY): $(BUILDDIR)/main.o $(BUILDDIR)/highscore.o $(BUILDDIR)/ReadKeyboard. $(CPP) -O -o $(BINARY) $(BUILDDIR)/main.o $(BUILDDIR)/highscore.o $(BUILDDIR)/ReadKeyboard.o $(BUILDDIR)/joypad.o $(BUILDDIR)/listFiles.o $(BUILDDIR)/replay.o $(BUILDDIR)/common.o $(BUILDDIR)/stats.o $(BUILDDIR)/CppSdlException.o $(BUILDDIR)/CppSdlImageHolder.o $(BUILDDIR)/nfont.o $(BUILDDIR)/MenuSystem.o $(BUILDDIR)/menudef.o $(BASE_LIBS) #-lphysfs -$(BUILDDIR)/main.o: main.cpp mainVars.hpp common.h +$(BUILDDIR)/main.o: main.cpp mainVars.hpp common.h BlockGame.hpp BlockGame.cpp $(CPP) $(BASE_CFLAGS) main.cpp -o $(BUILDDIR)/main.o $(BUILDDIR)/blockgame.o: BlockGame.hpp BlockGame.cpp diff --git a/source/code/replay.cpp b/source/code/replay.cpp index 877ceb5..2798202 100644 --- a/source/code/replay.cpp +++ b/source/code/replay.cpp @@ -286,3 +286,11 @@ bool Replay::loadReplay2(string filename) } } + +void Replay::addAction(int tick, string action) { + cout << tick << " " << action << endl; + Action a; + a.time = tick; + a.action = action; + actions.push_back(a); +} diff --git a/source/code/replay.h b/source/code/replay.h index 24c21f4..d3520ff 100644 --- a/source/code/replay.h +++ b/source/code/replay.h @@ -55,12 +55,19 @@ struct boardPackage //92 bytes Uint8 result; //0=none,1=gameOver,2=winner,4=draw }; +struct Action +{ + Uint32 time; + string action; +}; + class Replay { private: //Our replay is stored in an array of TOTALFRAMES length //boardPackage bps[TOTALFRAMES]; vector bps; + vector actions; //The final package is not set to any specific time boardPackage finalPack; //We store number of frames, so we know how long to read the array @@ -85,6 +92,9 @@ public: boardPackage getFinalFrame(); //Gets the last frame, that must remain int getFinalStatus(); //Return the result: winner, looser, draw or gameOver bool isFinnished(Uint32); //Returns true if we are done + + //New replay type 1.5.0+: + void addAction(int tick, string action); //Ok, I'll ignore this for some time, and just save to file, if however, we ever use a dynamic saving structure, we are fucked bool saveReplay(string); //Saves a replay