- Added new code for serialization/deserializaiton of full games including initial game and all the player actions.

- Added an undo menu using this code (beware, it's still very very alpha).
- Removed various warning
- Cleaned up avatar loading
- Added full random lists load/save including the deck shuffling (not sure if I could not replace that with seed load/save)
- Moved momir and Co rules configuration out of GameStateDuel
- Create a GameType type to avoid mixing int everywhere
This commit is contained in:
Xawotihs
2011-10-13 19:43:51 +00:00
parent 663058cdab
commit 0b6044551a
28 changed files with 595 additions and 156 deletions
+1 -17
View File
@@ -38,22 +38,6 @@ enum
#endif //NETWORK_SUPPORT
};
enum
{
GAME_TYPE_CLASSIC,
GAME_TYPE_MOMIR,
GAME_TYPE_RANDOM1,
GAME_TYPE_RANDOM2,
GAME_TYPE_STORY,
GAME_TYPE_DEMO,
GAME_TYPE_STONEHEWER,
GAME_TYPE_HERMIT,
#ifdef NETWORK_SUPPORT
GAME_TYPE_SLAVE,
#endif //NETWORK_SUPPORT
};
class MTGAllCards;
class TransitionBase;
@@ -73,7 +57,7 @@ private:
GameState* mGameStates[GAME_STATE_MAX];
public:
int gameType;
GameType gameType;
Rules * rules;
CardEffect *effect;
#ifdef NETWORK_SUPPORT
+21 -2
View File
@@ -26,10 +26,21 @@ class GameObserver{
protected:
MTGCardInstance * cardWaitingForTargets;
queue<WEvent *> eventsQueue;
list<string> actionsList;
int untap(MTGCardInstance * card);
bool WaitForExtraPayment(MTGCardInstance* card);
void initialize();
void cleanup();
string startupGameSerialized;
bool parseLine(const string& s);
void logAction(const string& s) {
actionsList.push_back(s);
};
bool processActions(bool undo);
friend ostream& operator<<(ostream&, GameObserver&);
bool load(const string& s, bool undo);
bool mLoading;
public:
int currentPlayerId;
@@ -49,6 +60,7 @@ class GameObserver{
vector<Player *> players; //created outside
time_t startedAt;
Rules * mRules;
GameType mGameType;
TargetChooser * getCurrentTargetChooser();
void stackObjectClicked(Interruptible * action);
@@ -74,10 +86,9 @@ class GameObserver{
void gameStateBasedEffects();
void enchantmentStatus();
void Affinity();
void eventOccured();
void addObserver(MTGAbility * observer);
bool removeObserver(ActionElement * observer);
void startGame(Rules * rules);
void startGame(GameType, Rules * rules);
void untapPhase();
MTGCardInstance * isCardWaiting(){ return cardWaitingForTargets; }
int isInPlay(MTGCardInstance * card);
@@ -90,6 +101,14 @@ class GameObserver{
int receiveEvent(WEvent * event);
bool connectRule;
void logAction(Player* player, const string& s="");
void logAction(int playerId, const string& s="") {
logAction(players[playerId], s);
};
void logAction(MTGCardInstance* card, MTGGameZone* zone = NULL);
bool undo();
bool isLoading(){ return mLoading; };
};
#endif
+3 -2
View File
@@ -78,9 +78,10 @@ public:
MENUITEM_MAIN_MENU = -13,
MENUITEM_EVIL_TWIN = kEvilTwinMenuID,
MENUITEM_MULLIGAN = -15,
MENUITEM_UNDO = -16,
#ifdef NETWORK_SUPPORT
MENUITEM_REMOTE_CLIENT = -16,
MENUITEM_REMOTE_SERVER = -17,
MENUITEM_REMOTE_CLIENT = -17,
MENUITEM_REMOTE_SERVER = -18,
#endif
MENUITEM_MORE_INFO = kInfoMenuID
};
+1 -2
View File
@@ -210,9 +210,8 @@ public:
static MTGCardInstance ExtraRules[2];
bool parseLine(const string& ss);
};
ostream& operator<<(ostream&, const MTGCardInstance&);
#endif
+17
View File
@@ -7,6 +7,23 @@ const float DEFAULT_TEXT_FONT_SCALE = 1.0f;
#include <string>
using std::string;
typedef enum
{
GAME_TYPE_CLASSIC,
GAME_TYPE_MOMIR,
GAME_TYPE_RANDOM1,
GAME_TYPE_RANDOM2,
GAME_TYPE_STORY,
GAME_TYPE_DEMO,
GAME_TYPE_STONEHEWER,
GAME_TYPE_HERMIT,
#ifdef NETWORK_SUPPORT
GAME_TYPE_SLAVE,
#endif //NETWORK_SUPPORT
} GameType;
class Constants
{
public:
+1
View File
@@ -83,6 +83,7 @@ class MTGGameZone {
void debugPrint();
MTGCardInstance * removeCard(MTGCardInstance * card, int createCopy = 1);
MTGCardInstance * hasCard(MTGCardInstance * card);
size_t getIndex(MTGCardInstance * card);
void cleanupPhase();
void beforeBeginPhase();
+7 -9
View File
@@ -15,6 +15,10 @@ class Player: public Damageable
{
protected:
ManaPool * manaPool;
JTexture * mAvatarTex;
JQuadPtr mAvatar;
bool loadAvatar(string file, string resName = "playerAvatar");
public:
enum ENUM_PLAY_MODE
@@ -25,8 +29,6 @@ public:
};
string mAvatarName;
JTexture * mAvatarTex;
JQuadPtr mAvatar;
int playMode;
bool nomaxhandsize;
MTGPlayerCards * game;
@@ -35,7 +37,7 @@ public:
string deckFileSmall;
string deckName;
string phaseRing;
int offerInterruptOnPhase;
int offerInterruptOnPhase;
Player(GameObserver *observer, string deckFile, string deckFileSmall, MTGDeck * deck = NULL);
virtual ~Player();
virtual void setObserver(GameObserver*g);
@@ -89,22 +91,18 @@ public:
{
}
void loadAvatar(string file);
/**
** Returns the path to the stats file of currently selected deck.
*/
std::string GetCurrentDeckStatsFile();
bool parseLine(const string& s);
friend ostream& operator<<(ostream&, const Player&);
};
class HumanPlayer: public Player
{
public:
HumanPlayer(GameObserver *observer, string deckFile, string deckFileSmall = "", MTGDeck * deck = NULL);
HumanPlayer(GameObserver *observer, string deckFile, string deckFileSmall, MTGDeck * deck = NULL);
};
ostream& operator<<(ostream&, const Player&);
#endif
+2 -2
View File
@@ -43,7 +43,7 @@ protected:
Player * loadPlayerRandom(GameObserver* observer, int isAI, int mode);
Player * initPlayer(GameObserver *observer, int playerId);
MTGDeck * buildDeck(int playerId);
int strToGameMode(string s);
GameType strToGameMode(string s);
bool postUpdateInitDone;
public:
enum
@@ -57,7 +57,7 @@ public:
string bg;
string filename;
int gamemode;
GameType gamemode;
bool hidden;
string displayName;
int unlockOption;
+1 -1
View File
@@ -67,7 +67,7 @@ public:
public:
int startTime, endTime;
int gameType;
GameType gameType;
unsigned int seed;
int nbFailed, nbTests, nbAIFailed, nbAITests;
TestSuite(const char * filename);
+3 -1
View File
@@ -63,9 +63,11 @@ std::string wordWrap(const std::string& s, float width, int fontId);
//basic hash function
unsigned long hash_djb2(const char *str);
int loadRandValues(string s);
void loadRandValues(string s);
ostream& saveRandValues(ostream& out);
int filesize(const char * filename);
int WRand();
ptrdiff_t MRand (ptrdiff_t i);
#ifdef LINUX
void dumpStack();