diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index c6127b7..089af67 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -209,12 +209,12 @@ public: void Update(unsigned int newtick); void PerformAction(unsigned int tick, int action, string param); /** - * - * @param tick Tick of the action - * @param action The action - * @param param Params. - * @return 1 if an action was selected - */ + * + * @param tick Tick of the action + * @param action The action + * @param param Params. + * @return 1 if an action was selected + */ int GotAction(unsigned int &tick,int &action,string ¶m); #if NETWORK //network play diff --git a/source/code/MenuSystem.cc b/source/code/MenuSystem.cc index f69b179..145ad56 100644 --- a/source/code/MenuSystem.cc +++ b/source/code/MenuSystem.cc @@ -312,7 +312,7 @@ void Menu::run() } //mouse clicked - if(buttonState&SDL_BUTTON(1)==SDL_BUTTON(1) && bMouseUp) + if( (buttonState&SDL_BUTTON(1) )==SDL_BUTTON(1) && bMouseUp) { bMouseUp = false; for(int i=0; i< buttons.size(); ++i) diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 63651e1..3a3a4fd 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h @@ -59,10 +59,10 @@ private: string label; //Pointer to a callback function. void (*action)(Button *b); - + //If true the menu should also be closed then the button is clicked bool popOnRun; - + ButtonGfx *gfx; public: @@ -85,11 +85,11 @@ public: bool isClicked(int x,int y); //Returns true if (x,y) is within the borders of the button virtual void doAction(); //Run the callback function void drawTo(SDL_Surface **surface); - void setPopOnRun(bool popOnRun); - bool isPopOnRun() const; - void setGfx(ButtonGfx* gfx); //Draws to screen + void setPopOnRun(bool popOnRun); + bool isPopOnRun() const; + void setGfx(ButtonGfx* gfx); //Draws to screen int getHeight(); - + //May hold any other information the callback might need int iGeneric1; }; diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp index 34bf99e..a91f778 100644 --- a/source/code/NetworkThing.hpp +++ b/source/code/NetworkThing.hpp @@ -54,6 +54,8 @@ public: enemyIsReady = false; enemyHasStarted = false; gameHasStarted = false; + bgAway = NULL; + bgHome = NULL; if (enet_initialize () != 0) { fprintf (stderr, "An error occurred while initializing ENet.\n"); @@ -69,6 +71,8 @@ public: //This function couses us to remove the connection to the other peer, plus destroying servers void ntDisconnect() { + if(!bgHome || !bgAway) + return; strcpy(bgAway->name,player2name); if (weAreConnected || weAreAClient || weAreAServer) { @@ -224,13 +228,14 @@ public: Sint32 action; Sint32 paramsize; string param; - while(bgHome->GotAction(tick,action,param)) + while(bgHome->GotAction(tick,action,param)) { if(action == ACTION_NEW || action == ACTION_NEWTT || action == ACTION_NEWVS) continue; //Do not send start messages paramsize = param.length(); char *tmpPacket = (char*)malloc(sizeof(Sint32)*3+param.length()+1); - if(!tmpPacket) { + if(!tmpPacket) + { cerr << "Failed to alloc memoroy" << endl; exit(-3); } @@ -239,8 +244,8 @@ public: memcpy(tmpPacket+sizeof(Sint32)*2,¶msize,sizeof(Sint32)); memcpy(tmpPacket+sizeof(Sint32)*3,param.c_str(),paramsize+1); ENetPacket * packet = enet_packet_create (tmpPacket, - sizeof(Sint32)*3+param.length()+1, - ENET_PACKET_FLAG_RELIABLE); + sizeof(Sint32)*3+param.length()+1, + ENET_PACKET_FLAG_RELIABLE); //Now lets send the package if (weAreAServer) enet_host_broadcast (server, 0, packet); @@ -417,10 +422,10 @@ public: } ntDisconnect(); //When we will disconnect! - break; - - case ENET_EVENT_TYPE_NONE: - break; + break; + + case ENET_EVENT_TYPE_NONE: + break; } } diff --git a/source/code/menu/MenuItem.hpp b/source/code/menu/MenuItem.hpp index 1ba634c..13c4c77 100644 --- a/source/code/menu/MenuItem.hpp +++ b/source/code/menu/MenuItem.hpp @@ -1,4 +1,4 @@ -/* +/* * File: MenuItem.hpp * Author: poul * @@ -12,12 +12,13 @@ using namespace std; -class MenuItem { - virtual void SetSelected(bool selected) = 0; - virtual void Activated() = 0; - virtual string GetText() = 0; - virtual void GetType() = 0; - virtual void SetText(string text) = 0; +class MenuItem +{ + virtual void SetSelected(bool selected) = 0; + virtual void Activated() = 0; + virtual string GetText() = 0; + virtual void GetType() = 0; + virtual void SetText(string text) = 0; }; diff --git a/source/code/menu/MenuItemCommand.hpp b/source/code/menu/MenuItemCommand.hpp index 682f47a..26ee49d 100644 --- a/source/code/menu/MenuItemCommand.hpp +++ b/source/code/menu/MenuItemCommand.hpp @@ -1,4 +1,4 @@ -/* +/* * File: MenuItemCommand.hpp * Author: poul * @@ -10,21 +10,22 @@ #include "MenuItem.hpp" -class MenuItemCommand : MenuItem{ +class MenuItemCommand : MenuItem +{ public: - MenuItemCommand(); - MenuItemCommand(string text, void (*pt2Function)(void)); - MenuItemCommand(const MenuItemCommand& orig); - virtual ~MenuItemCommand(); - void SetSelected(bool selected); - void Activated(); - string GetText(); - string GetType(); - void SetText(string text); + MenuItemCommand(); + MenuItemCommand(string text, void (*pt2Function)(void)); + MenuItemCommand(const MenuItemCommand& orig); + virtual ~MenuItemCommand(); + void SetSelected(bool selected); + void Activated(); + string GetText(); + string GetType(); + void SetText(string text); private: - bool selected; - string text; - void (*command)(void); + bool selected; + string text; + void (*command)(void); }; #endif /* _MENUITEMCOMMAND_HPP */ diff --git a/source/code/replay.cpp b/source/code/replay.cpp index 7fe4ad2..4b64870 100644 --- a/source/code/replay.cpp +++ b/source/code/replay.cpp @@ -61,7 +61,7 @@ bool Replay::saveReplay(string filename) { saveFile << "0 16 PLAYER 1\n"; saveFile << "0 16 NAME " << name << "\n"; - for(int i = 0; i < actions.size(); ++i) + for(unsigned int i = 0; i < actions.size(); ++i) { saveFile << actions.at(i).time << " " << actions.at(i).action << " " << actions.at(i).param << "\n"; } @@ -85,13 +85,13 @@ bool Replay::saveReplay(string filename,Replay p2) { saveFile << "0 16 PLAYER 1\n"; saveFile << "0 16 NAME " << name << "\n"; - for(int i = 0; i < actions.size(); ++i) + for(unsigned int i = 0; i < actions.size(); ++i) { saveFile << actions.at(i).time << " " << actions.at(i).action << " " << actions.at(i).param << "\n"; } saveFile << "0 16 PLAYER 2\n"; saveFile << "0 16 NAME " << name << "\n"; - for(int i = 0; i < p2.getActions().size(); ++i) + for(unsigned int i = 0; i < p2.getActions().size(); ++i) { saveFile << p2.getActions().at(i).time << " " << p2.getActions().at(i).action << " " << p2.getActions().at(i).param << "\n"; } @@ -154,7 +154,7 @@ bool Replay::loadReplay(string filename) cerr << "File not found or couldn't open: " << filename << endl; return false; } - + return true; } bool Replay::loadReplay2(string filename) @@ -210,7 +210,7 @@ bool Replay::loadReplay2(string filename) cerr << "File not found or couldn't open: " << filename << endl; return false; } - + return true; } void Replay::setName(string name) diff --git a/source/code/replay.h b/source/code/replay.h index 5c2402c..1ef1549 100644 --- a/source/code/replay.h +++ b/source/code/replay.h @@ -57,11 +57,11 @@ private: public: - + Replay(); //Constructor Replay(const Replay& r); //Copy constructor - + //New replay type 2.0.0+: void addAction(int tick, int action, string param); @@ -70,9 +70,9 @@ public: bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter bool loadReplay(string); //laods a replay bool loadReplay2(string); - void setName(string name); - string getName() const; - vector getActions() const; //loads the second part of the replay file, if it exists, returns false otherwise + void setName(string name); + string getName() const; + vector getActions() const; //loads the second part of the replay file, if it exists, returns false otherwise }; #endif