diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index e44a27d..43aab07 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -347,6 +347,7 @@ void BlockGame::NewGame(int tx, int ty, unsigned int ticks) pushedPixelAt = gameStartedAt; nextGarbageNumber = 10; handicap=0; + actionIndex = 0; for (int i=0; i<7; i++) for (int j=0; j<30; j++) { @@ -2252,6 +2253,19 @@ void BlockGame::ActionPerformed(int action, string param) theReplay.addAction(ticks-gameStartedAt,action,param); } +int BlockGame::GotAction(Sint32 &tick,int &action,string ¶m) +{ + if(actionIndex < theReplay.getActions().size()) { + Action a = theReplay.getActions().at(replayIndex); + tick = a.time; + action = a.action; + param = a.param; + ++actionIndex; + return 1; + } + return 0; +} + void BlockGame::PerformAction(int tick, int action, string param) { ss.str(std::string()); @@ -2265,7 +2279,7 @@ void BlockGame::PerformAction(int tick, int action, string param) UpdateInternal(tick); break; case ACTION_MOVECURSOR: - MoveCursor(param.at(1)); + MoveCursor(param.at(0)); break; case ACTION_MOVECURSORTO: { diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 16e1224..8137ac7 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -100,7 +100,8 @@ protected: unsigned int ticks; Sint32 gameStartedAt; Sint32 gameEndedAfter; //How long did the game last? - int replayIndex; + int replayIndex; //Used during replay to remeber how many replay actions we have performed. + int actionIndex; //Used during network to remeber how many actions we have sent. int linesCleared; int TowerHeight; BlockGame *garbageTarget; @@ -301,6 +302,14 @@ private: ///////////////////////////// AI ends here! ////////////////////////////// ////////////////////////////////////////////////////////////////////////// + /** + * + * @param tick Tick of the action + * @param action The action + * @param param Params. + * @return 1 if an action was selected + */ + int GotAction(int &tick,int &action,string ¶m); void ActionPerformed(int action, string param); void PushLineInternal(); //Updates evrything, if not called nothing happends diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp index fc166cd..8fb6dfc 100644 --- a/source/code/NetworkThing.hpp +++ b/source/code/NetworkThing.hpp @@ -338,16 +338,16 @@ public: enet_peer_send (peer, 3, answerPacket); } } - else if (event.packet->dataLength==sizeof("version3")) //We have recieved aversion number + else if (event.packet->dataLength==sizeof("version4")) //We have recieved aversion number { - if (0!=strcmp((const char*)event.packet->data,"version3")) + if (0!=strcmp((const char*)event.packet->data,"version4")) { - cout << "Incompatible version: " << event.packet->data << "!=" << "version3" << endl; + cout << "Incompatible version: " << event.packet->data << "!=" << "version4" << endl; ntDisconnect(); } if (weAreAClient) //We will send our version number { - ENetPacket * answerPacket = enet_packet_create("version3",sizeof("version3"),ENET_PACKET_FLAG_RELIABLE); + ENetPacket * answerPacket = enet_packet_create("version4",sizeof("version4"),ENET_PACKET_FLAG_RELIABLE); enet_peer_send (peer, 3, answerPacket); } } diff --git a/source/code/replay.cpp b/source/code/replay.cpp index 98db327..0fe4408 100644 --- a/source/code/replay.cpp +++ b/source/code/replay.cpp @@ -122,7 +122,10 @@ bool Replay::loadReplay(string filename) Action a; a.time = time; a.action = action; - a.param = restOfLine; + if(restOfLine.length()>1) + a.param = restOfLine.substr(1); + else + a.param = ""; actions.push_back(a); } diff --git a/source/code/replay.h b/source/code/replay.h index 78c7e70..3119f4b 100644 --- a/source/code/replay.h +++ b/source/code/replay.h @@ -56,7 +56,7 @@ struct boardPackage //92 bytes struct Action { Sint32 time; - int action; + Sint32 action; string param; };