- Replaced static parts by per-instance parts of of several classes when they were not threadsafe (AIMomirPlayer, SimpleMenu, Trash, AIAction, MTGCardInstance, ATutorialMessage, MTGRules). The direct consequence is that we could consumme more memory. So, tell me if you have problems with low memory devices (PSP), there are some threadsafe optimizations that could be implemented if needed.
- Reworked the testsuite to be able to work multithreaded. This is deactivated by default everywhere except in QT_CONFIG as one testcase still refuses to pass in multithreaded mode. On my 4 cores linux desktop, the 650 tests passes now in 4 seconds (1 fails). - Replaced usage of CardSelectorSingleton by a card selector per game observer. - Modified the resource manager to be optionnal and per game observer instance instead of being a singleton. Two reasons here : threading AND Open Gl access. I only updated the crashing parts called from the game observer, so most of the code is still using the single instance. Beware of copy-paste concerning resources ... - Cleaned up the game observer constructors - Fixed several problems in action logging code while testing proliferate decks - Cleaned up Threading implementation based on QThread
This commit is contained in:
@@ -449,15 +449,15 @@ namespace boost
|
|||||||
{
|
{
|
||||||
detail::thread_data_ptr mThreadInfo;
|
detail::thread_data_ptr mThreadInfo;
|
||||||
public:
|
public:
|
||||||
static threadImpl* spThreadImpl;
|
|
||||||
threadImpl(detail::thread_data_ptr threadInfo) : mThreadInfo(threadInfo)
|
threadImpl(detail::thread_data_ptr threadInfo) : mThreadInfo(threadInfo)
|
||||||
{
|
{
|
||||||
setTerminationEnabled();
|
setTerminationEnabled();
|
||||||
spThreadImpl = this;
|
|
||||||
};
|
};
|
||||||
static void mymsleep(unsigned long msecs)
|
static void mymsleep(unsigned long msecs)
|
||||||
{
|
{
|
||||||
spThreadImpl->msleep(msecs);
|
QThread* currentThread = QThread::currentThread();
|
||||||
|
if(currentThread)
|
||||||
|
currentThread->msleep(msecs);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
void run()
|
void run()
|
||||||
@@ -467,8 +467,6 @@ namespace boost
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
threadImpl* threadImpl::spThreadImpl = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** A simplistic implementation of boost::thread, using QThread.
|
** A simplistic implementation of boost::thread, using QThread.
|
||||||
**
|
**
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public:
|
|||||||
int getEfficiency(OrderedAIAction * action);
|
int getEfficiency(OrderedAIAction * action);
|
||||||
int momir();
|
int momir();
|
||||||
int computeActions();
|
int computeActions();
|
||||||
static MTGAbility * momirAbility;
|
MTGAbility * momirAbility;
|
||||||
MTGAbility * getMomirAbility();
|
MTGAbility * getMomirAbility();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ class AIPlayer;
|
|||||||
|
|
||||||
class AIAction
|
class AIAction
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
static int currentId;
|
|
||||||
public:
|
public:
|
||||||
AIPlayer * owner;
|
AIPlayer * owner;
|
||||||
MTGAbility * ability;
|
MTGAbility * ability;
|
||||||
@@ -43,7 +41,6 @@ public:
|
|||||||
AIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
|
AIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
|
||||||
: owner(owner), ability(a), player(NULL), click(c), target(t),playerAbilityTarget(NULL)
|
: owner(owner), ability(a), player(NULL), click(c), target(t),playerAbilityTarget(NULL)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t = NULL);
|
AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t = NULL);
|
||||||
@@ -56,13 +53,11 @@ public:
|
|||||||
AIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
|
AIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
|
||||||
: owner(owner), ability(a), player(NULL), click(c), mAbilityTargets(targetCards),playerAbilityTarget(NULL)
|
: owner(owner), ability(a), player(NULL), click(c), mAbilityTargets(targetCards),playerAbilityTarget(NULL)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AIAction(AIPlayer * owner, MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
|
AIAction(AIPlayer * owner, MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
|
||||||
: owner(owner), ability(a), click(c),target(NULL), playerAbilityTarget(p)
|
: owner(owner), ability(a), click(c),target(NULL), playerAbilityTarget(p)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
|
||||||
};
|
};
|
||||||
int Act();
|
int Act();
|
||||||
int clickMultiAct(vector<Targetable*>&actionTargets);
|
int clickMultiAct(vector<Targetable*>&actionTargets);
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ public:
|
|||||||
DrawAction(GameObserver* observer, int id, Player * _player, int _nbcards);
|
DrawAction(GameObserver* observer, int id, Player * _player, int _nbcards);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ATutorialMessage;
|
||||||
class LifeAction: public Interruptible
|
class LifeAction: public Interruptible
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -196,6 +197,7 @@ protected:
|
|||||||
int currentState;
|
int currentState;
|
||||||
int mode;
|
int mode;
|
||||||
int checked;
|
int checked;
|
||||||
|
ATutorialMessage* currentTutorial;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -216,7 +218,7 @@ public:
|
|||||||
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
|
int getNextIndex(Interruptible * previous, int type = 0, int state = 0 , int display = -1);
|
||||||
void Fizzle(Interruptible * action);
|
void Fizzle(Interruptible * action);
|
||||||
Interruptible * getAt(int id);
|
Interruptible * getAt(int id);
|
||||||
void cancelInterruptOffer(int cancelMode = 1);
|
void cancelInterruptOffer(int cancelMode = 1, bool log = true);
|
||||||
void endOfInterruption(bool log = true);
|
void endOfInterruption(bool log = true);
|
||||||
Interruptible * getLatest(int state);
|
Interruptible * getLatest(int state);
|
||||||
Player * askIfWishesToInterrupt;
|
Player * askIfWishesToInterrupt;
|
||||||
@@ -241,7 +243,8 @@ public:
|
|||||||
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
#if defined (WIN32) || defined (LINUX) || defined (IOS)
|
||||||
void Dump();
|
void Dump();
|
||||||
#endif
|
#endif
|
||||||
|
void setCurrentTutorial(ATutorialMessage* message) {currentTutorial = message;};
|
||||||
|
ATutorialMessage* getCurrentTutorial() {return currentTutorial;};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -781,9 +781,6 @@ public:
|
|||||||
|
|
||||||
//JGuiListener Implementation
|
//JGuiListener Implementation
|
||||||
void ButtonPressed(int controllerId, int controlId);
|
void ButtonPressed(int controllerId, int controlId);
|
||||||
|
|
||||||
static ATutorialMessage * Current;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ protected:
|
|||||||
ActionStack* stack;
|
ActionStack* stack;
|
||||||
GuiHandSelf *hand;
|
GuiHandSelf *hand;
|
||||||
GuiAvatars * avatars;
|
GuiAvatars * avatars;
|
||||||
|
GameObserver* observer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DuelLayers();
|
DuelLayers();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
class MTGGamePhase;
|
class MTGGamePhase;
|
||||||
class MTGAbility;
|
class MTGAbility;
|
||||||
class MTGCardInstance;
|
class MTGCardInstance;
|
||||||
@@ -20,7 +21,8 @@ struct CardGui;
|
|||||||
class Player;
|
class Player;
|
||||||
class TargetChooser;
|
class TargetChooser;
|
||||||
class Rules;
|
class Rules;
|
||||||
class TestSuite;
|
class TestSuiteGame;
|
||||||
|
class Trash;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class GameObserver{
|
class GameObserver{
|
||||||
@@ -46,6 +48,7 @@ class GameObserver{
|
|||||||
void nextGamePhase();
|
void nextGamePhase();
|
||||||
void shuffleLibrary(Player* p);
|
void shuffleLibrary(Player* p);
|
||||||
RandomGenerator randomGenerator;
|
RandomGenerator randomGenerator;
|
||||||
|
WResourceManager* mResourceManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int currentPlayerId;
|
int currentPlayerId;
|
||||||
@@ -66,6 +69,8 @@ class GameObserver{
|
|||||||
time_t startedAt;
|
time_t startedAt;
|
||||||
Rules * mRules;
|
Rules * mRules;
|
||||||
GameType mGameType;
|
GameType mGameType;
|
||||||
|
MTGCardInstance* ExtraRules;
|
||||||
|
Trash* mTrash;
|
||||||
|
|
||||||
TargetChooser * getCurrentTargetChooser();
|
TargetChooser * getCurrentTargetChooser();
|
||||||
void stackObjectClicked(Interruptible * action);
|
void stackObjectClicked(Interruptible * action);
|
||||||
@@ -80,19 +85,19 @@ class GameObserver{
|
|||||||
void userRequestNextGamePhase(bool allowInterrupt = true, bool log = true);
|
void userRequestNextGamePhase(bool allowInterrupt = true, bool log = true);
|
||||||
void cleanupPhase();
|
void cleanupPhase();
|
||||||
void nextPlayer();
|
void nextPlayer();
|
||||||
void setPlayers(vector<Player *> _players);
|
|
||||||
|
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
void loadTestSuitePlayer(int playerId, TestSuite* testSuite);
|
void loadTestSuitePlayer(int playerId, TestSuiteGame* testSuite);
|
||||||
#endif //TESTSUITE
|
#endif //TESTSUITE
|
||||||
void loadPlayer(int playerId, PlayerType playerType = PLAYER_TYPE_HUMAN, int decknb=0, bool premadeDeck=false);
|
void loadPlayer(int playerId, PlayerType playerType = PLAYER_TYPE_HUMAN, int decknb=0, bool premadeDeck=false);
|
||||||
|
void loadPlayer(int playerId, Player* player);
|
||||||
|
|
||||||
Player * currentPlayer;
|
Player * currentPlayer;
|
||||||
Player * currentActionPlayer;
|
Player * currentActionPlayer;
|
||||||
Player * isInterrupting;
|
Player * isInterrupting;
|
||||||
Player * opponent();
|
Player * opponent();
|
||||||
Player * currentlyActing();
|
Player * currentlyActing();
|
||||||
GameObserver();
|
GameObserver(WResourceManager* resourceManager = NULL);
|
||||||
GameObserver(vector<Player *> _players);
|
|
||||||
~GameObserver();
|
~GameObserver();
|
||||||
void gameStateBasedEffects();
|
void gameStateBasedEffects();
|
||||||
void enchantmentStatus();
|
void enchantmentStatus();
|
||||||
@@ -125,6 +130,8 @@ class GameObserver{
|
|||||||
Player* getPlayer(size_t index) { return players[index];};
|
Player* getPlayer(size_t index) { return players[index];};
|
||||||
bool isStarted() { return (mLayers!=NULL);};
|
bool isStarted() { return (mLayers!=NULL);};
|
||||||
RandomGenerator* getRandomGenerator() { return &randomGenerator; };
|
RandomGenerator* getRandomGenerator() { return &randomGenerator; };
|
||||||
|
WResourceManager* getResourceManager() { if(this) return mResourceManager;else return 0;};
|
||||||
|
CardSelectorBase* getCardSelector() { return mLayers->mCardSelector;};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -208,8 +208,6 @@ public:
|
|||||||
static MTGCardInstance AnyCard;
|
static MTGCardInstance AnyCard;
|
||||||
static MTGCardInstance NoCard;
|
static MTGCardInstance NoCard;
|
||||||
|
|
||||||
static MTGCardInstance ExtraRules[2];
|
|
||||||
|
|
||||||
bool parseLine(const string& ss);
|
bool parseLine(const string& ss);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -306,8 +306,8 @@ class MTGMomirRule: public PermanentAbility
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int genRandomCreatureId(int convertedCost);
|
int genRandomCreatureId(int convertedCost);
|
||||||
static vector<int> pool[20];
|
vector<int> pool[20];
|
||||||
static int initialized;
|
int initialized;
|
||||||
|
|
||||||
int textAlpha;
|
int textAlpha;
|
||||||
string text;
|
string text;
|
||||||
@@ -335,8 +335,8 @@ class MTGStoneHewerRule: public PermanentAbility
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int genRandomEquipId(int convertedCost);
|
int genRandomEquipId(int convertedCost);
|
||||||
static vector<int> pool[20];
|
vector<int> pool[20];
|
||||||
static int initialized;
|
int initialized;
|
||||||
public:
|
public:
|
||||||
MTGAllCards * collection;
|
MTGAllCards * collection;
|
||||||
MTGCardInstance * genEquip(int id);
|
MTGCardInstance * genEquip(int id);
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ private:
|
|||||||
|
|
||||||
static JQuadPtr spadeR, spadeL, jewel, side;
|
static JQuadPtr spadeR, spadeL, jewel, side;
|
||||||
static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex;
|
static JTexture *spadeRTex, *spadeLTex, *jewelTex, *sideTex;
|
||||||
static WFont* titleFont;
|
hgeParticleSystem* stars;
|
||||||
static hgeParticleSystem* stars;
|
|
||||||
|
|
||||||
inline void MogrifyJewel();
|
inline void MogrifyJewel();
|
||||||
void drawHorzPole(float x, float y, float width);
|
void drawHorzPole(float x, float y, float width);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#define MAX_TESTSUITE_ACTIONS 100
|
#define MAX_TESTSUITE_ACTIONS 100
|
||||||
#define MAX_TESTUITE_CARDS 100
|
#define MAX_TESTUITE_CARDS 100
|
||||||
|
|
||||||
|
#include "Threading.h"
|
||||||
#include "AIPlayerBaka.h"
|
#include "AIPlayerBaka.h"
|
||||||
|
|
||||||
class TestSuiteActions
|
class TestSuiteActions
|
||||||
@@ -19,6 +20,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TestSuiteGame;
|
||||||
class TestSuite;
|
class TestSuite;
|
||||||
class TestSuiteAI;
|
class TestSuiteAI;
|
||||||
class TestSuiteState
|
class TestSuiteState
|
||||||
@@ -30,64 +32,87 @@ public:
|
|||||||
~TestSuiteState();
|
~TestSuiteState();
|
||||||
|
|
||||||
vector<TestSuiteAI*> players;
|
vector<TestSuiteAI*> players;
|
||||||
void cleanup(TestSuite*);
|
void cleanup(TestSuiteGame* tsGame);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestSuitePregame
|
class TestSuiteGame
|
||||||
{
|
{
|
||||||
|
friend class TestSuiteAI;
|
||||||
|
friend class TestSuite;
|
||||||
|
protected:
|
||||||
|
string filename;
|
||||||
|
int summoningSickness;
|
||||||
|
bool forceAbility;
|
||||||
|
GameType gameType;
|
||||||
|
unsigned int seed;
|
||||||
|
int aiMaxCalls;
|
||||||
|
TestSuiteState endState;
|
||||||
|
TestSuiteState initState;
|
||||||
|
TestSuiteActions actions;
|
||||||
|
float timerLimit;
|
||||||
|
bool isOK;
|
||||||
|
int currentAction;
|
||||||
|
GameObserver* observer;
|
||||||
|
|
||||||
|
static boost::mutex mMutex;
|
||||||
|
virtual void handleResults(bool wasAI, int error);
|
||||||
|
TestSuite* testsuite;
|
||||||
|
bool load();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void performTest() = 0;
|
~TestSuiteGame();
|
||||||
|
TestSuiteGame(TestSuite* testsuite);
|
||||||
|
TestSuiteGame(TestSuite* testsuite, string _filename);
|
||||||
|
void initGame();
|
||||||
|
void assertGame();
|
||||||
|
MTGPlayerCards * buildDeck(Player* player, int playerId);
|
||||||
|
GameType getGameType() { return gameType; };
|
||||||
|
string getNextAction();
|
||||||
|
Interruptible * getActionByMTGId(int mtgid);
|
||||||
|
static int Log(const char * text);
|
||||||
|
void setObserver(GameObserver* anObserver) {observer = anObserver; };
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestSuite
|
class TestSuite : public TestSuiteGame
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int currentfile;
|
int currentfile;
|
||||||
int nbfiles;
|
int nbfiles;
|
||||||
string files[1024];
|
string files[1024];
|
||||||
TestSuiteState endState;
|
|
||||||
TestSuiteActions actions;
|
|
||||||
bool forceAbility;
|
|
||||||
|
|
||||||
int load(const char * filename);
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
vector<boost::thread> mWorkerThread;
|
||||||
public:
|
Rules* mRules;
|
||||||
/* but only used by the testsuite classes */
|
bool mProcessing;
|
||||||
float timerLimit;
|
|
||||||
int aiMaxCalls;
|
|
||||||
int currentAction;
|
|
||||||
int summoningSickness;
|
|
||||||
|
|
||||||
TestSuiteState initState;
|
|
||||||
string getNextAction();
|
|
||||||
MTGPlayerCards * buildDeck(Player*, int playerId);
|
|
||||||
Interruptible * getActionByMTGId(GameObserver* observer, int mtgid);
|
|
||||||
int assertGame(GameObserver*);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int startTime, endTime;
|
int startTime, endTime;
|
||||||
GameType gameType;
|
|
||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
int nbFailed, nbTests, nbAIFailed, nbAITests;
|
int nbFailed, nbTests, nbAIFailed, nbAITests;
|
||||||
TestSuite(const char * filename);
|
TestSuite(const char * filename);
|
||||||
void initGame(GameObserver* g);
|
void initGame(GameObserver* g);
|
||||||
void pregameTests();
|
void pregameTests();
|
||||||
int loadNext();
|
int loadNext();
|
||||||
static int Log(const char * text);
|
string getNextFile() {
|
||||||
|
boost::mutex::scoped_lock lock(mMutex);
|
||||||
|
if (currentfile >= nbfiles) return "";
|
||||||
|
currentfile++;
|
||||||
|
return files[currentfile - 1];
|
||||||
|
};
|
||||||
|
static void ThreadProc(void* inParam);
|
||||||
|
void setRules(Rules* rules) {mRules = rules;};
|
||||||
|
void handleResults(bool wasAI, int error);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO This should inherit from AIPlayer instead!
|
|
||||||
class TestSuiteAI:public AIPlayerBaka
|
class TestSuiteAI:public AIPlayerBaka
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
MTGCardInstance * getCard(string action);
|
MTGCardInstance * getCard(string action);
|
||||||
float timer;
|
float timer;
|
||||||
TestSuite * suite;
|
TestSuiteGame * suite;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestSuiteAI(GameObserver *observer, TestSuite * suite, int playerId);
|
TestSuiteAI(TestSuiteGame *tsGame, int playerId);
|
||||||
virtual int Act(float dt);
|
virtual int Act(float dt);
|
||||||
virtual int displayStack();
|
virtual int displayStack();
|
||||||
bool summoningSickness() {return (suite->summoningSickness == 1); }
|
bool summoningSickness() {return (suite->summoningSickness == 1); }
|
||||||
|
|||||||
@@ -4,22 +4,39 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Pos.h"
|
#include "Pos.h"
|
||||||
#include "WEvent.h"
|
#include "WEvent.h"
|
||||||
|
#include "DamagerDamaged.h"
|
||||||
|
|
||||||
|
class CardView;
|
||||||
|
class AttackerDamaged;
|
||||||
|
class DamagerDamaged;
|
||||||
|
typedef DamagerDamaged DefenserDamaged;
|
||||||
|
|
||||||
template<class T> void trash(T*);
|
template<class T> void trash(T*);
|
||||||
class Trash
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void cleanup();
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class TrashBin
|
class TrashBin
|
||||||
{
|
{
|
||||||
std::vector<T*> bin;
|
std::vector<T> bin;
|
||||||
void put_out();
|
void put_out();
|
||||||
int receiveEvent(WEvent* e);
|
int receiveEvent(WEvent* e);
|
||||||
template<class Q> friend void trash(Q*);
|
template<class Q> friend void trash(Q*);
|
||||||
friend class Trash;
|
friend class Trash;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Trash
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
TrashBin<CardView*> CardViewTrash;
|
||||||
|
TrashBin<DefenserDamaged*> DefenserDamagedTrash;
|
||||||
|
TrashBin<AttackerDamaged*> AttackerDamagedTrash;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Trash(){};
|
||||||
|
void cleanup();
|
||||||
|
void trash(CardView* garbage);
|
||||||
|
void trash(DefenserDamaged* garbage);
|
||||||
|
void trash(AttackerDamaged* garbage);
|
||||||
|
};
|
||||||
|
|
||||||
#endif // _TRASH_H_
|
#endif // _TRASH_H_
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
#include "AIStats.h"
|
#include "AIStats.h"
|
||||||
#include "AllAbilities.h"
|
#include "AllAbilities.h"
|
||||||
|
|
||||||
MTGAbility * AIMomirPlayer::momirAbility = NULL;
|
|
||||||
|
|
||||||
AIMomirPlayer::AIMomirPlayer(GameObserver *observer, string file, string fileSmall, string avatarFile, MTGDeck * deck) :
|
AIMomirPlayer::AIMomirPlayer(GameObserver *observer, string file, string fileSmall, string avatarFile, MTGDeck * deck) :
|
||||||
AIPlayerBaka(observer, file, fileSmall, avatarFile, deck)
|
AIPlayerBaka(observer, file, fileSmall, avatarFile, deck)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,28 +17,24 @@
|
|||||||
|
|
||||||
const char * const MTG_LAND_TEXTS[] = { "artifact", "forest", "island", "mountain", "swamp", "plains", "other lands" };
|
const char * const MTG_LAND_TEXTS[] = { "artifact", "forest", "island", "mountain", "swamp", "plains", "other lands" };
|
||||||
|
|
||||||
int AIAction::currentId = 0;
|
|
||||||
|
|
||||||
AIAction::AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t)
|
AIAction::AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t)
|
||||||
: owner(owner), ability(NULL), player(NULL), click(c), target(t)
|
: owner(owner), ability(NULL), player(NULL), click(c), target(t)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
|
||||||
|
|
||||||
// useability tweak - assume that the user is probably going to want to see the full res card,
|
// useability tweak - assume that the user is probably going to want to see the full res card,
|
||||||
// so prefetch it. The idea is that we do it here as we want to start the prefetch before it's time to render,
|
// so prefetch it. The idea is that we do it here as we want to start the prefetch before it's time to render,
|
||||||
// and waiting for it to actually go into play is too late, as we start drawing the card during the interrupt window.
|
// and waiting for it to actually go into play is too late, as we start drawing the card during the interrupt window.
|
||||||
// This is a good intercept point, as the AI has committed to using this card.
|
// This is a good intercept point, as the AI has committed to using this card.
|
||||||
|
|
||||||
// if we're not in text mode, always get the thumb
|
// if we're not in text mode, always get the thumb
|
||||||
if (CardSelectorSingleton::Instance()->GetDrawMode() != DrawMode::kText)
|
if (owner->getObserver()->getCardSelector()->GetDrawMode() != DrawMode::kText)
|
||||||
{
|
{
|
||||||
//DebugTrace("Prefetching AI card going into play: " << c->getImageName());
|
//DebugTrace("Prefetching AI card going into play: " << c->getImageName());
|
||||||
WResourceManager::Instance()->RetrieveCard(c, RETRIEVE_THUMB);
|
owner->getObserver()->getResourceManager()->RetrieveCard(c, RETRIEVE_THUMB);
|
||||||
|
|
||||||
// also cache the large image if we're using kNormal mode
|
// also cache the large image if we're using kNormal mode
|
||||||
if (CardSelectorSingleton::Instance()->GetDrawMode() == DrawMode::kNormal)
|
if (owner->getObserver()->getCardSelector()->GetDrawMode() == DrawMode::kNormal)
|
||||||
{
|
{
|
||||||
WResourceManager::Instance()->RetrieveCard(c);
|
owner->getObserver()->getResourceManager()->RetrieveCard(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ void AIStats::Render()
|
|||||||
x0 = 280;
|
x0 = 280;
|
||||||
JRenderer::GetInstance()->FillRoundRect(x0, 10, 200, 180, 5, ARGB(50,0,0,0));
|
JRenderer::GetInstance()->FillRoundRect(x0, 10, 200, 180, 5, ARGB(50,0,0,0));
|
||||||
|
|
||||||
WFont * f = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * f = g->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
list<AIStat *>::iterator it;
|
list<AIStat *>::iterator it;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const string NextGamePhase::getDisplayName() const
|
|||||||
|
|
||||||
void NextGamePhase::Render()
|
void NextGamePhase::Render()
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetBase(0);
|
mFont->SetBase(0);
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
@@ -81,20 +81,20 @@ const string Interruptible::getDisplayName() const
|
|||||||
|
|
||||||
float Interruptible::GetVerticalTextOffset() const
|
float Interruptible::GetVerticalTextOffset() const
|
||||||
{
|
{
|
||||||
static const float kTextVerticalOffset = (mHeight - WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT)->GetHeight()) / 2;
|
static const float kTextVerticalOffset = (mHeight - observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT)->GetHeight()) / 2;
|
||||||
return kTextVerticalOffset;
|
return kTextVerticalOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interruptible::Render(MTGCardInstance * source, JQuad * targetQuad, string alt1, string alt2, string action,
|
void Interruptible::Render(MTGCardInstance * source, JQuad * targetQuad, string alt1, string alt2, string action,
|
||||||
bool bigQuad)
|
bool bigQuad)
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetColor(ARGB(255,255,255,255));
|
mFont->SetColor(ARGB(255,255,255,255));
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
|
|
||||||
mFont->DrawString(_(action).c_str(), x + 35, y + GetVerticalTextOffset(), JGETEXT_LEFT);
|
mFont->DrawString(_(action).c_str(), x + 35, y + GetVerticalTextOffset(), JGETEXT_LEFT);
|
||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(source, CACHE_THUMB);
|
JQuadPtr quad = observer->getResourceManager()->RetrieveCard(source, CACHE_THUMB);
|
||||||
if (!quad.get())
|
if (!quad.get())
|
||||||
quad = CardGui::AlternateThumbQuad(source);
|
quad = CardGui::AlternateThumbQuad(source);
|
||||||
if (quad.get())
|
if (quad.get())
|
||||||
@@ -111,7 +111,7 @@ void Interruptible::Render(MTGCardInstance * source, JQuad * targetQuad, string
|
|||||||
if (bigQuad)
|
if (bigQuad)
|
||||||
{
|
{
|
||||||
Pos pos = Pos(CardGui::BigWidth / 2, CardGui::BigHeight / 2 - 10, 1.0, 0.0, 220);
|
Pos pos = Pos(CardGui::BigWidth / 2, CardGui::BigHeight / 2 - 10, 1.0, 0.0, 220);
|
||||||
CardGui::DrawCard(source, pos, CardSelectorSingleton::Instance()->GetDrawMode());
|
CardGui::DrawCard(source, pos, observer->getCardSelector()->GetDrawMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetQuad)
|
if (targetQuad)
|
||||||
@@ -409,7 +409,7 @@ int PutInGraveyard::resolve()
|
|||||||
|
|
||||||
void PutInGraveyard::Render()
|
void PutInGraveyard::Render()
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetBase(0);
|
mFont->SetBase(0);
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
if (!removeFromGame)
|
if (!removeFromGame)
|
||||||
@@ -421,7 +421,7 @@ void PutInGraveyard::Render()
|
|||||||
mFont->DrawString(_("is exiled").c_str(), x + 30, y, JGETEXT_LEFT);
|
mFont->DrawString(_("is exiled").c_str(), x + 30, y, JGETEXT_LEFT);
|
||||||
}
|
}
|
||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
|
JQuadPtr quad = observer->getResourceManager()->RetrieveCard(card, CACHE_THUMB);
|
||||||
if (quad.get())
|
if (quad.get())
|
||||||
{
|
{
|
||||||
quad->SetColor(ARGB(255,255,255,255));
|
quad->SetColor(ARGB(255,255,255,255));
|
||||||
@@ -457,7 +457,7 @@ int DrawAction::resolve()
|
|||||||
|
|
||||||
void DrawAction::Render()
|
void DrawAction::Render()
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetBase(0);
|
mFont->SetBase(0);
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
@@ -487,7 +487,7 @@ target->life += amount;
|
|||||||
|
|
||||||
void LifeAction::Render()
|
void LifeAction::Render()
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetBase(0);
|
mFont->SetBase(0);
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
char buffer[200];
|
char buffer[200];
|
||||||
@@ -574,7 +574,7 @@ int ActionStack::setIsInterrupting(Player * player, bool log)
|
|||||||
|
|
||||||
if (!gModRules.game.canInterrupt())
|
if (!gModRules.game.canInterrupt())
|
||||||
{
|
{
|
||||||
cancelInterruptOffer();
|
cancelInterruptOffer(1, log);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,7 +632,7 @@ Interruptible * ActionStack::getAt(int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ActionStack::ActionStack(GameObserver* game)
|
ActionStack::ActionStack(GameObserver* game)
|
||||||
: GuiLayer(game)
|
: GuiLayer(game), currentTutorial(0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
interruptDecision[i] = 0;
|
interruptDecision[i] = 0;
|
||||||
@@ -642,11 +642,12 @@ ActionStack::ActionStack(GameObserver* game)
|
|||||||
mode = ACTIONSTACK_STANDARD;
|
mode = ACTIONSTACK_STANDARD;
|
||||||
checked = 0;
|
checked = 0;
|
||||||
|
|
||||||
|
if(!observer->getResourceManager()) return;
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "iconspsp" << i;
|
stream << "iconspsp" << i;
|
||||||
pspIcons[i] = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", (float) i * 32, 0, 32, 32, stream.str(), RETRIEVE_MANAGE);
|
pspIcons[i] = observer->getResourceManager()->RetrieveQuad("iconspsp.png", (float) i * 32, 0, 32, 32, stream.str(), RETRIEVE_MANAGE);
|
||||||
pspIcons[i]->SetHotSpot(16, 16);
|
pspIcons[i]->SetHotSpot(16, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -829,7 +830,7 @@ void ActionStack::Update(float dt)
|
|||||||
{
|
{
|
||||||
//This is a hack to avoid updating the stack while tuto messages are being shown
|
//This is a hack to avoid updating the stack while tuto messages are being shown
|
||||||
//Ideally, the tuto messages should be moved to a layer above this one
|
//Ideally, the tuto messages should be moved to a layer above this one
|
||||||
if (ATutorialMessage::Current)
|
if (getCurrentTutorial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
askIfWishesToInterrupt = NULL;
|
askIfWishesToInterrupt = NULL;
|
||||||
@@ -955,13 +956,14 @@ void ActionStack::Update(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionStack::cancelInterruptOffer(int cancelMode)
|
void ActionStack::cancelInterruptOffer(int cancelMode, bool log)
|
||||||
{
|
{
|
||||||
int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0;
|
int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0;
|
||||||
interruptDecision[playerId] = cancelMode;
|
interruptDecision[playerId] = cancelMode;
|
||||||
askIfWishesToInterrupt = NULL;
|
askIfWishesToInterrupt = NULL;
|
||||||
observer->isInterrupting = NULL;
|
observer->isInterrupting = NULL;
|
||||||
timer = -1;
|
timer = -1;
|
||||||
|
if(log)
|
||||||
observer->logAction(playerId, "no");
|
observer->logAction(playerId, "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,7 +1103,7 @@ void ActionStack::Render()
|
|||||||
{
|
{
|
||||||
//This is a hack to avoid rendering the stack above the tuto messages
|
//This is a hack to avoid rendering the stack above the tuto messages
|
||||||
//Ideally, the tuto messages should be moved to a layer above this one
|
//Ideally, the tuto messages should be moved to a layer above this one
|
||||||
if (ATutorialMessage::Current)
|
if (getCurrentTutorial())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static const float kSpacer = 8;
|
static const float kSpacer = 8;
|
||||||
@@ -1123,7 +1125,7 @@ void ActionStack::Render()
|
|||||||
height += current->mHeight;
|
height += current->mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetBase(0);
|
mFont->SetBase(0);
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
mFont->SetColor(ARGB(255,255,255,255));
|
mFont->SetColor(ARGB(255,255,255,255));
|
||||||
@@ -1201,7 +1203,7 @@ void ActionStack::Render()
|
|||||||
height += current->mHeight;
|
height += current->mHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = observer->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
|
||||||
mFont->SetColor(ARGB(255,255,255,255));
|
mFont->SetColor(ARGB(255,255,255,255));
|
||||||
|
|
||||||
|
|||||||
@@ -2241,7 +2241,7 @@ int MayAbility::testDestroy()
|
|||||||
if(game->currentPlayer == source->controller() && game->isInterrupting == source->controller() && dynamic_cast<AManaProducer*>(AbilityFactory::getCoreAbility(ability)))
|
if(game->currentPlayer == source->controller() && game->isInterrupting == source->controller() && dynamic_cast<AManaProducer*>(AbilityFactory::getCoreAbility(ability)))
|
||||||
//if its my turn, and im interrupting myself(why?) then set interrupting to previous interrupter if the ability was a manaability
|
//if its my turn, and im interrupting myself(why?) then set interrupting to previous interrupter if the ability was a manaability
|
||||||
//special case since they don't use the stack.
|
//special case since they don't use the stack.
|
||||||
game->mLayers->stackLayer()->setIsInterrupting(previousInterrupter);
|
game->mLayers->stackLayer()->setIsInterrupting(previousInterrupter, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2305,7 +2305,7 @@ void MenuAbility::Update(float dt)
|
|||||||
{
|
{
|
||||||
game->mLayers->actionLayer()->setCustomMenuObject(source, must,abilities);
|
game->mLayers->actionLayer()->setCustomMenuObject(source, must,abilities);
|
||||||
previousInterrupter = game->isInterrupting;
|
previousInterrupter = game->isInterrupting;
|
||||||
game->mLayers->stackLayer()->setIsInterrupting(source->controller());
|
game->mLayers->stackLayer()->setIsInterrupting(source->controller(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2359,10 +2359,9 @@ int MenuAbility::reactToChoiceClick(Targetable * object,int choice,int control)
|
|||||||
mClone->resolve();
|
mClone->resolve();
|
||||||
SAFE_DELETE(mClone);
|
SAFE_DELETE(mClone);
|
||||||
if (source->controller() == game->isInterrupting)
|
if (source->controller() == game->isInterrupting)
|
||||||
game->mLayers->stackLayer()->cancelInterruptOffer();
|
game->mLayers->stackLayer()->cancelInterruptOffer(1, false);
|
||||||
this->forceDestroy = 1;
|
this->forceDestroy = 1;
|
||||||
removeMenu = true;
|
removeMenu = true;
|
||||||
game->logAction(source->controller(), "choice " + choice);
|
|
||||||
return reactToTargetClick(object);
|
return reactToTargetClick(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3913,8 +3912,6 @@ AAConnect * AAConnect::clone() const
|
|||||||
|
|
||||||
//Tutorial Messaging
|
//Tutorial Messaging
|
||||||
|
|
||||||
ATutorialMessage * ATutorialMessage::Current = NULL;
|
|
||||||
|
|
||||||
ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * source, string message, int limit)
|
ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * source, string message, int limit)
|
||||||
: MTGAbility(observer, 0, source), IconButtonsController(0, 0), mLimit(limit)
|
: MTGAbility(observer, 0, source), IconButtonsController(0, 0), mLimit(limit)
|
||||||
{
|
{
|
||||||
@@ -3926,7 +3923,7 @@ ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * sou
|
|||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
mBg[i] = NULL;
|
mBg[i] = NULL;
|
||||||
|
|
||||||
string gfx = WResourceManager::Instance()->graphicsFile(message);
|
string gfx = game->getResourceManager()->graphicsFile(message);
|
||||||
if (fileExists(gfx.c_str()))
|
if (fileExists(gfx.c_str()))
|
||||||
{
|
{
|
||||||
mIsImage = true;
|
mIsImage = true;
|
||||||
@@ -3987,10 +3984,10 @@ bool ATutorialMessage::CheckUserInput(JButton key)
|
|||||||
|
|
||||||
void ATutorialMessage::Update(float dt)
|
void ATutorialMessage::Update(float dt)
|
||||||
{
|
{
|
||||||
if (!Current && !mDontShow)
|
if (!game->mLayers->stackLayer()->getCurrentTutorial() && !mDontShow)
|
||||||
Current = this;
|
game->mLayers->stackLayer()->setCurrentTutorial(this);
|
||||||
|
|
||||||
if (Current != this)
|
if (game->mLayers->stackLayer()->getCurrentTutorial() != this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mUserCloseRequest && mY < -SCREEN_HEIGHT)
|
if (mUserCloseRequest && mY < -SCREEN_HEIGHT)
|
||||||
@@ -3998,7 +3995,7 @@ void ATutorialMessage::Update(float dt)
|
|||||||
|
|
||||||
if (mDontShow)
|
if (mDontShow)
|
||||||
{
|
{
|
||||||
Current = NULL;
|
game->mLayers->stackLayer()->setCurrentTutorial(0);
|
||||||
forceDestroy = 1;
|
forceDestroy = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4048,14 +4045,14 @@ void ATutorialMessage::Render()
|
|||||||
{
|
{
|
||||||
if (mIsImage)
|
if (mIsImage)
|
||||||
{
|
{
|
||||||
mBgTex = WResourceManager::Instance()->RetrieveTexture(mMessage, RETRIEVE_LOCK);
|
mBgTex = game->getResourceManager()->RetrieveTexture(mMessage, RETRIEVE_LOCK);
|
||||||
if (mBgTex)
|
if (mBgTex)
|
||||||
{
|
{
|
||||||
mBg[0] = NEW JQuad(mBgTex, 0, 0, (float) mBgTex->mWidth, (float) mBgTex->mHeight);
|
mBg[0] = NEW JQuad(mBgTex, 0, 0, (float) mBgTex->mWidth, (float) mBgTex->mHeight);
|
||||||
mBg[0]->SetHotSpot(mBg[0]->mWidth / 2, mBg[0]->mHeight / 2);
|
mBg[0]->SetHotSpot(mBg[0]->mWidth / 2, mBg[0]->mHeight / 2);
|
||||||
|
|
||||||
//Continue Button
|
//Continue Button
|
||||||
JQuadPtr quad = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", 4 * 32, 0, 32, 32, "iconpsp4", RETRIEVE_MANAGE);
|
JQuadPtr quad = game->getResourceManager()->RetrieveQuad("iconspsp.png", 4 * 32, 0, 32, 32, "iconpsp4", RETRIEVE_MANAGE);
|
||||||
quad->SetHotSpot(16, 16);
|
quad->SetHotSpot(16, 16);
|
||||||
IconButton * iconButton = NEW IconButton(1, this, quad.get(), 0, mBg[0]->mHeight / 2, 0.7f, Fonts::MAGIC_FONT, _("continue"), 0, 16, true);
|
IconButton * iconButton = NEW IconButton(1, this, quad.get(), 0, mBg[0]->mHeight / 2, 0.7f, Fonts::MAGIC_FONT, _("continue"), 0, 16, true);
|
||||||
Add(iconButton);
|
Add(iconButton);
|
||||||
@@ -4063,14 +4060,14 @@ void ATutorialMessage::Render()
|
|||||||
|
|
||||||
if (options[Options::SFXVOLUME].number > 0)
|
if (options[Options::SFXVOLUME].number > 0)
|
||||||
{
|
{
|
||||||
JSample * sample = WResourceManager::Instance()->RetrieveSample("tutorial.wav");
|
JSample * sample = game->getResourceManager()->RetrieveSample("tutorial.wav");
|
||||||
if (sample)
|
if (sample)
|
||||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mBgTex = WResourceManager::Instance()->RetrieveTexture("taskboard.png", RETRIEVE_LOCK);
|
mBgTex = game->getResourceManager()->RetrieveTexture("taskboard.png", RETRIEVE_LOCK);
|
||||||
|
|
||||||
float unitH = static_cast<float> (mBgTex->mHeight / 4);
|
float unitH = static_cast<float> (mBgTex->mHeight / 4);
|
||||||
float unitW = static_cast<float> (mBgTex->mWidth / 4);
|
float unitW = static_cast<float> (mBgTex->mWidth / 4);
|
||||||
@@ -4090,7 +4087,7 @@ void ATutorialMessage::Render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Continue Button
|
//Continue Button
|
||||||
JQuadPtr quad = WResourceManager::Instance()->RetrieveQuad("iconspsp.png", 4 * 32, 0, 32, 32, "iconpsp4", RETRIEVE_MANAGE);
|
JQuadPtr quad = game->getResourceManager()->RetrieveQuad("iconspsp.png", 4 * 32, 0, 32, 32, "iconpsp4", RETRIEVE_MANAGE);
|
||||||
quad->SetHotSpot(16, 16);
|
quad->SetHotSpot(16, 16);
|
||||||
IconButton * iconButton = NEW IconButton(1, this, quad.get(), SCREEN_WIDTH_F / 2, SCREEN_HEIGHT_F - 60, 0.7f, Fonts::MAGIC_FONT, _("continue"), 0, 16, true);
|
IconButton * iconButton = NEW IconButton(1, this, quad.get(), SCREEN_WIDTH_F / 2, SCREEN_HEIGHT_F - 60, 0.7f, Fonts::MAGIC_FONT, _("continue"), 0, 16, true);
|
||||||
Add(iconButton);
|
Add(iconButton);
|
||||||
@@ -4100,7 +4097,7 @@ void ATutorialMessage::Render()
|
|||||||
|
|
||||||
if (options[Options::SFXVOLUME].number > 0)
|
if (options[Options::SFXVOLUME].number > 0)
|
||||||
{
|
{
|
||||||
JSample * sample = WResourceManager::Instance()->RetrieveSample("chain.wav");
|
JSample * sample = game->getResourceManager()->RetrieveSample("chain.wav");
|
||||||
if (sample)
|
if (sample)
|
||||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||||
}
|
}
|
||||||
@@ -4126,7 +4123,7 @@ void ATutorialMessage::Render()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Setup fonts.
|
//Setup fonts.
|
||||||
WFont * f2 = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
|
WFont * f2 = game->getResourceManager()->GetWFont(Fonts::MAGIC_FONT);
|
||||||
f2->SetColor(ARGB(255, 205, 237, 240));
|
f2->SetColor(ARGB(255, 205, 237, 240));
|
||||||
|
|
||||||
r->FillRect(0, mY, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(128,0,0,0));
|
r->FillRect(0, mY, SCREEN_WIDTH, SCREEN_HEIGHT, ARGB(128,0,0,0));
|
||||||
@@ -4159,8 +4156,8 @@ void ATutorialMessage::Render()
|
|||||||
float posX = 40, posY = mY + 20;
|
float posX = 40, posY = mY + 20;
|
||||||
string title = _("Help");
|
string title = _("Help");
|
||||||
|
|
||||||
WFont * f = WResourceManager::Instance()->GetWFont(Fonts::MAGIC_FONT);
|
WFont * f = game->getResourceManager()->GetWFont(Fonts::MAGIC_FONT);
|
||||||
WFont * f3 = WResourceManager::Instance()->GetWFont(Fonts::MENU_FONT); //OPTION_FONT
|
WFont * f3 = game->getResourceManager()->GetWFont(Fonts::MENU_FONT); //OPTION_FONT
|
||||||
f->SetColor(ARGB(255, 55, 46, 34));
|
f->SetColor(ARGB(255, 55, 46, 34));
|
||||||
f3->SetColor(ARGB(255, 219, 206, 151));
|
f3->SetColor(ARGB(255, 219, 206, 151));
|
||||||
|
|
||||||
@@ -4187,7 +4184,7 @@ ATutorialMessage::~ATutorialMessage()
|
|||||||
{
|
{
|
||||||
if (mBgTex)
|
if (mBgTex)
|
||||||
{
|
{
|
||||||
WResourceManager::Instance()->Release(mBgTex);
|
game->getResourceManager()->Release(mBgTex);
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
SAFE_DELETE(mBg[i]);
|
SAFE_DELETE(mBg[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ void CardDisplay::Render()
|
|||||||
{
|
{
|
||||||
pos.actY = 150;
|
pos.actY = 150;
|
||||||
if (x < (CardGui::BigWidth / 2)) pos.actX = SCREEN_WIDTH - 10 - CardGui::BigWidth / 2;
|
if (x < (CardGui::BigWidth / 2)) pos.actX = SCREEN_WIDTH - 10 - CardGui::BigWidth / 2;
|
||||||
drawMode = CardSelectorSingleton::Instance()->GetDrawMode();
|
drawMode = observer->getCardSelector()->GetDrawMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
cardg->DrawCard(pos, drawMode);
|
cardg->DrawCard(pos, drawMode);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ void CardGui::DrawCard(MTGCard* inCard, const Pos& inPosition, int inMode)
|
|||||||
|
|
||||||
void CardGui::Render()
|
void CardGui::Render()
|
||||||
{
|
{
|
||||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * mFont = card->getObserver()->getResourceManager()->GetWFont(Fonts::MAIN_FONT);
|
||||||
|
|
||||||
JRenderer * renderer = JRenderer::GetInstance();
|
JRenderer * renderer = JRenderer::GetInstance();
|
||||||
GameObserver * game = card->getObserver();
|
GameObserver * game = card->getObserver();
|
||||||
@@ -140,7 +140,7 @@ void CardGui::Render()
|
|||||||
tc = game->getCurrentTargetChooser();
|
tc = game->getCurrentTargetChooser();
|
||||||
|
|
||||||
bool alternate = true;
|
bool alternate = true;
|
||||||
JQuadPtr quad = WResourceManager::Instance()->RetrieveCard(card, CACHE_THUMB);
|
JQuadPtr quad = card->getObserver()->getResourceManager()->RetrieveCard(card, CACHE_THUMB);
|
||||||
|
|
||||||
if (quad.get())
|
if (quad.get())
|
||||||
alternate = false;
|
alternate = false;
|
||||||
@@ -153,7 +153,7 @@ void CardGui::Render()
|
|||||||
JQuadPtr shadow;
|
JQuadPtr shadow;
|
||||||
if (actZ > 1)
|
if (actZ > 1)
|
||||||
{
|
{
|
||||||
shadow = WResourceManager::Instance()->GetQuad("shadow");
|
shadow = card->getObserver()->getResourceManager()->GetQuad("shadow");
|
||||||
shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255));
|
shadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,255,255,255));
|
||||||
renderer->RenderQuad(shadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
|
renderer->RenderQuad(shadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ void CardGui::Render()
|
|||||||
JQuadPtr extracostshadow;
|
JQuadPtr extracostshadow;
|
||||||
if (card->isExtraCostTarget)
|
if (card->isExtraCostTarget)
|
||||||
{
|
{
|
||||||
extracostshadow = WResourceManager::Instance()->GetQuad("extracostshadow");
|
extracostshadow = card->getObserver()->getResourceManager()->GetQuad("extracostshadow");
|
||||||
extracostshadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,100,0,0));
|
extracostshadow->SetColor(ARGB(static_cast<unsigned char>(actA)/2,100,0,0));
|
||||||
renderer->RenderQuad(extracostshadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
|
renderer->RenderQuad(extracostshadow.get(), actX + (actZ - 1) * 15, actY + (actZ - 1) * 15, actT, 28 * actZ / 16, 40 * actZ / 16);
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ void CardGui::Render()
|
|||||||
}
|
}
|
||||||
if (isActiveConnectedParent)
|
if (isActiveConnectedParent)
|
||||||
{
|
{
|
||||||
JQuadPtr white = WResourceManager::Instance()->GetQuad("white");
|
JQuadPtr white = card->getObserver()->getResourceManager()->GetQuad("white");
|
||||||
if(white)
|
if(white)
|
||||||
{
|
{
|
||||||
white->SetColor(ARGB(255,230,50,50));
|
white->SetColor(ARGB(255,230,50,50));
|
||||||
@@ -212,7 +212,7 @@ void CardGui::Render()
|
|||||||
}
|
}
|
||||||
if (isActiveConnectedChild)
|
if (isActiveConnectedChild)
|
||||||
{
|
{
|
||||||
JQuadPtr white = WResourceManager::Instance()->GetQuad("white");
|
JQuadPtr white = card->getObserver()->getResourceManager()->GetQuad("white");
|
||||||
if(white)
|
if(white)
|
||||||
{
|
{
|
||||||
white->SetColor(ARGB(255,0,0,255));
|
white->SetColor(ARGB(255,0,0,255));
|
||||||
@@ -235,15 +235,15 @@ void CardGui::Render()
|
|||||||
|
|
||||||
JQuadPtr icon;
|
JQuadPtr icon;
|
||||||
if (card->hasSubtype("plains"))
|
if (card->hasSubtype("plains"))
|
||||||
icon = WResourceManager::Instance()->GetQuad("c_white");
|
icon = card->getObserver()->getResourceManager()->GetQuad("c_white");
|
||||||
else if (card->hasSubtype("swamp"))
|
else if (card->hasSubtype("swamp"))
|
||||||
icon = WResourceManager::Instance()->GetQuad("c_black");
|
icon = card->getObserver()->getResourceManager()->GetQuad("c_black");
|
||||||
else if (card->hasSubtype("forest"))
|
else if (card->hasSubtype("forest"))
|
||||||
icon = WResourceManager::Instance()->GetQuad("c_green");
|
icon = card->getObserver()->getResourceManager()->GetQuad("c_green");
|
||||||
else if (card->hasSubtype("mountain"))
|
else if (card->hasSubtype("mountain"))
|
||||||
icon = WResourceManager::Instance()->GetQuad("c_red");
|
icon = card->getObserver()->getResourceManager()->GetQuad("c_red");
|
||||||
else if (card->hasSubtype("island"))
|
else if (card->hasSubtype("island"))
|
||||||
icon = WResourceManager::Instance()->GetQuad("c_blue");
|
icon = card->getObserver()->getResourceManager()->GetQuad("c_blue");
|
||||||
|
|
||||||
if (icon.get())
|
if (icon.get())
|
||||||
{
|
{
|
||||||
@@ -256,7 +256,7 @@ void CardGui::Render()
|
|||||||
JQuadPtr mor;
|
JQuadPtr mor;
|
||||||
if(card->isMorphed && !alternate)
|
if(card->isMorphed && !alternate)
|
||||||
{
|
{
|
||||||
mor = WResourceManager::Instance()->GetQuad("morph");
|
mor = card->getObserver()->getResourceManager()->GetQuad("morph");
|
||||||
mor->SetColor(ARGB(255,255,255,255));
|
mor->SetColor(ARGB(255,255,255,255));
|
||||||
renderer->RenderQuad(mor.get(), actX, actY, actT,scale, scale);
|
renderer->RenderQuad(mor.get(), actX, actY, actT,scale, scale);
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ void CardGui::Render()
|
|||||||
if (tc && !tc->canTarget(card))
|
if (tc && !tc->canTarget(card))
|
||||||
{
|
{
|
||||||
if (!shadow)
|
if (!shadow)
|
||||||
shadow = WResourceManager::Instance()->GetQuad("shadow");
|
shadow = card->getObserver()->getResourceManager()->GetQuad("shadow");
|
||||||
shadow->SetColor(ARGB(200,255,255,255));
|
shadow->SetColor(ARGB(200,255,255,255));
|
||||||
renderer->RenderQuad(shadow.get(), actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
|
renderer->RenderQuad(shadow.get(), actX, actY, actT, (28 * actZ + 1) / 16, 40 * actZ / 16);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "MTGRules.h"
|
#include "MTGRules.h"
|
||||||
#include "CardSelectorSingleton.h"
|
#include "CardSelector.h"
|
||||||
#include "GuiCombat.h"
|
#include "GuiCombat.h"
|
||||||
#include "GuiBackground.h"
|
#include "GuiBackground.h"
|
||||||
#include "GuiFrame.h"
|
#include "GuiFrame.h"
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
void DuelLayers::init(GameObserver* go)
|
void DuelLayers::init(GameObserver* go)
|
||||||
{
|
{
|
||||||
mCardSelector = CardSelectorSingleton::Create(go, this);
|
observer = go;
|
||||||
|
mCardSelector = NEW CardSelector(go, this);
|
||||||
//1 Action Layer
|
//1 Action Layer
|
||||||
action = NEW ActionLayer(go);
|
action = NEW ActionLayer(go);
|
||||||
action->Add(NEW MTGGamePhase(go, action->getMaxId()));
|
action->Add(NEW MTGGamePhase(go, action->getMaxId()));
|
||||||
@@ -65,7 +66,7 @@ void DuelLayers::CheckUserInput(int isAI)
|
|||||||
JGE::GetInstance()->LeftClickedProcessed();
|
JGE::GetInstance()->LeftClickedProcessed();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (CardSelectorSingleton::Instance()->CheckUserInput(key)) {
|
if (mCardSelector->CheckUserInput(key)) {
|
||||||
JGE::GetInstance()->LeftClickedProcessed();
|
JGE::GetInstance()->LeftClickedProcessed();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -126,10 +127,9 @@ DuelLayers::~DuelLayers()
|
|||||||
|
|
||||||
for (size_t i = 0; i < waiters.size(); ++i)
|
for (size_t i = 0; i < waiters.size(); ++i)
|
||||||
delete (waiters[i]);
|
delete (waiters[i]);
|
||||||
Trash::cleanup();
|
observer->mTrash->cleanup();
|
||||||
|
|
||||||
CardSelectorSingleton::Terminate();
|
SAFE_DELETE(mCardSelector);
|
||||||
mCardSelector = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DuelLayers::Add(GuiLayer * layer)
|
void DuelLayers::Add(GuiLayer * layer)
|
||||||
@@ -203,7 +203,7 @@ int DuelLayers::receiveEvent(WEvent * e)
|
|||||||
|
|
||||||
if (WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e))
|
if (WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e))
|
||||||
if (Constants::MTG_PHASE_BEFORE_BEGIN == event->to->id)
|
if (Constants::MTG_PHASE_BEFORE_BEGIN == event->to->id)
|
||||||
Trash::cleanup();
|
observer->mTrash->cleanup();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "GuiPhaseBar.h"
|
#include "GuiPhaseBar.h"
|
||||||
#include "AIPlayerBaka.h"
|
#include "AIPlayerBaka.h"
|
||||||
#include "MTGRules.h"
|
#include "MTGRules.h"
|
||||||
|
#include "Trash.h"
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
#include "TestSuiteAI.h"
|
#include "TestSuiteAI.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -35,6 +36,7 @@ void GameObserver::initialize()
|
|||||||
connectRule = false;
|
connectRule = false;
|
||||||
mLoading = false;
|
mLoading = false;
|
||||||
mLayers = NULL;
|
mLayers = NULL;
|
||||||
|
mTrash = new Trash();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameObserver::cleanup()
|
void GameObserver::cleanup()
|
||||||
@@ -63,7 +65,6 @@ void GameObserver::cleanup()
|
|||||||
combatStep = BLOCKERS;
|
combatStep = BLOCKERS;
|
||||||
connectRule = false;
|
connectRule = false;
|
||||||
actionsList.clear();
|
actionsList.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObserver::~GameObserver()
|
GameObserver::~GameObserver()
|
||||||
@@ -82,31 +83,21 @@ GameObserver::~GameObserver()
|
|||||||
SAFE_DELETE(players[i]);
|
SAFE_DELETE(players[i]);
|
||||||
}
|
}
|
||||||
players.clear();
|
players.clear();
|
||||||
|
delete[] ExtraRules;
|
||||||
|
ExtraRules = 0;
|
||||||
LOG("==GameObserver Destroyed==");
|
LOG("==GameObserver Destroyed==");
|
||||||
|
SAFE_DELETE(mTrash);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObserver::GameObserver()
|
GameObserver::GameObserver(WResourceManager *resourceManager)
|
||||||
: randomGenerator(true)
|
: randomGenerator(true), mResourceManager(resourceManager)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
ExtraRules = new MTGCardInstance[2]();
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObserver::GameObserver(vector<Player *> _players)
|
|
||||||
: randomGenerator(true)
|
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
setPlayers(_players);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameObserver::setPlayers(vector<Player *> _players)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < _players.size(); i++)
|
|
||||||
{
|
|
||||||
players.push_back(_players[i]);
|
|
||||||
players[i]->setObserver(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int GameObserver::getCurrentGamePhase()
|
int GameObserver::getCurrentGamePhase()
|
||||||
{
|
{
|
||||||
return currentGamePhase;
|
return currentGamePhase;
|
||||||
@@ -1009,8 +1000,11 @@ int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
|
|||||||
} else {
|
} else {
|
||||||
backup = card;
|
backup = card;
|
||||||
zone = card->currentZone;
|
zone = card->currentZone;
|
||||||
|
if(zone)
|
||||||
|
{
|
||||||
index = zone->getIndex(card);
|
index = zone->getIndex(card);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (targetChooser)
|
if (targetChooser)
|
||||||
@@ -1136,7 +1130,7 @@ int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
|
|||||||
|
|
||||||
if (clickedPlayer) {
|
if (clickedPlayer) {
|
||||||
logAction(clickedPlayer);
|
logAction(clickedPlayer);
|
||||||
} else {
|
} else if(zone) {
|
||||||
logAction(backup, zone, index, toReturn);
|
logAction(backup, zone, index, toReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1451,7 +1445,7 @@ bool GameObserver::processActions(bool undo)
|
|||||||
if (s.find("p1") != string::npos)
|
if (s.find("p1") != string::npos)
|
||||||
p = players[0];
|
p = players[0];
|
||||||
|
|
||||||
for (int i = 0; i<5; i++)
|
for (int i = 0; i<1; i++)
|
||||||
{
|
{
|
||||||
// let's fake an update
|
// let's fake an update
|
||||||
Update(counter);
|
Update(counter);
|
||||||
@@ -1500,7 +1494,7 @@ bool GameObserver::processActions(bool undo)
|
|||||||
|
|
||||||
size_t nb = actionsList.size();
|
size_t nb = actionsList.size();
|
||||||
|
|
||||||
for (int i = 0; i<5; i++)
|
for (int i = 0; i<3; i++)
|
||||||
{
|
{
|
||||||
// let's fake an update
|
// let's fake an update
|
||||||
Update(counter);
|
Update(counter);
|
||||||
@@ -1563,12 +1557,17 @@ void GameObserver::Mulligan(Player* player)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
void GameObserver::loadTestSuitePlayer(int playerId, TestSuite* testSuite)
|
void GameObserver::loadTestSuitePlayer(int playerId, TestSuiteGame* testSuite)
|
||||||
{
|
{
|
||||||
players.push_back(new TestSuiteAI(this, testSuite, playerId));
|
players.push_back(new TestSuiteAI(testSuite, playerId));
|
||||||
}
|
}
|
||||||
#endif //TESTSUITE
|
#endif //TESTSUITE
|
||||||
|
|
||||||
|
void GameObserver::loadPlayer(int playerId, Player* player)
|
||||||
|
{
|
||||||
|
players.push_back(player);
|
||||||
|
}
|
||||||
|
|
||||||
void GameObserver::loadPlayer(int playerId, PlayerType playerType, int decknb, bool premadeDeck)
|
void GameObserver::loadPlayer(int playerId, PlayerType playerType, int decknb, bool premadeDeck)
|
||||||
{
|
{
|
||||||
if (decknb)
|
if (decknb)
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ void GameStateDuel::Start()
|
|||||||
renderer->EnableVSync(true);
|
renderer->EnableVSync(true);
|
||||||
OpponentsDeckid = 0;
|
OpponentsDeckid = 0;
|
||||||
|
|
||||||
game = NEW GameObserver();
|
game = NEW GameObserver(WResourceManager::Instance());
|
||||||
|
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
SAFE_DELETE(testSuite);
|
SAFE_DELETE(testSuite);
|
||||||
@@ -200,12 +200,13 @@ void GameStateDuel::loadTestSuitePlayers()
|
|||||||
if (!testSuite) return;
|
if (!testSuite) return;
|
||||||
initRand(testSuite->seed);
|
initRand(testSuite->seed);
|
||||||
SAFE_DELETE(game);
|
SAFE_DELETE(game);
|
||||||
game = new GameObserver();
|
game = new GameObserver(WResourceManager::Instance());
|
||||||
|
testSuite->setObserver(game);
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
game->loadTestSuitePlayer(i, testSuite);
|
game->loadTestSuitePlayer(i, testSuite);
|
||||||
}
|
}
|
||||||
mParent->gameType = testSuite->gameType;
|
mParent->gameType = testSuite->getGameType();
|
||||||
|
|
||||||
game->startGame(mParent->gameType, mParent->rules);
|
game->startGame(mParent->gameType, mParent->rules);
|
||||||
}
|
}
|
||||||
@@ -294,6 +295,8 @@ void GameStateDuel::Update(float dt)
|
|||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE)
|
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE)
|
||||||
{
|
{
|
||||||
|
testSuite->setRules(mParent->rules);
|
||||||
|
|
||||||
if (testSuite && testSuite->loadNext())
|
if (testSuite && testSuite->loadNext())
|
||||||
{
|
{
|
||||||
loadTestSuitePlayers();
|
loadTestSuitePlayers();
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ GuiAvatars::GuiAvatars(GameObserver* observer) :
|
|||||||
Add(opponentLibrary = NEW GuiLibrary(5 + GuiAvatar::Width * 1.4 - GuiGameZone::Width / 2, 5 + GuiGameZone::Height + 5, false,
|
Add(opponentLibrary = NEW GuiLibrary(5 + GuiAvatar::Width * 1.4 - GuiGameZone::Width / 2, 5 + GuiGameZone::Height + 5, false,
|
||||||
observer->players[1], this));
|
observer->players[1], this));
|
||||||
|
|
||||||
CardSelectorSingleton::Instance()->Add(self);
|
observer->getCardSelector()->Add(self);
|
||||||
CardSelectorSingleton::Instance()->Add(selfGraveyard);
|
observer->getCardSelector()->Add(selfGraveyard);
|
||||||
CardSelectorSingleton::Instance()->Add(selfLibrary);
|
observer->getCardSelector()->Add(selfLibrary);
|
||||||
CardSelectorSingleton::Instance()->Add(opponent);
|
observer->getCardSelector()->Add(opponent);
|
||||||
CardSelectorSingleton::Instance()->Add(opponentGraveyard);
|
observer->getCardSelector()->Add(opponentGraveyard);
|
||||||
CardSelectorSingleton::Instance()->Add(opponentLibrary);
|
observer->getCardSelector()->Add(opponentLibrary);
|
||||||
CardSelectorSingleton::Instance()->Add(opponentHand);
|
observer->getCardSelector()->Add(opponentHand);
|
||||||
selfGraveyard->alpha = selfLibrary->alpha = opponentGraveyard->alpha = opponentLibrary->alpha = opponentHand->alpha = 0;
|
selfGraveyard->alpha = selfLibrary->alpha = opponentGraveyard->alpha = opponentLibrary->alpha = opponentHand->alpha = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,17 +44,17 @@ GuiCombat::GuiCombat(GameObserver* go) :
|
|||||||
GuiLayer(go), active(false), activeAtk(NULL), ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255), enemy_avatar(SCREEN_WIDTH
|
GuiLayer(go), active(false), activeAtk(NULL), ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255), enemy_avatar(SCREEN_WIDTH
|
||||||
- MARGIN, TOP_LINE, 2, 0, 255), cursor_pos(NONE), step(DAMAGE)
|
- MARGIN, TOP_LINE, 2, 0, 255), cursor_pos(NONE), step(DAMAGE)
|
||||||
{
|
{
|
||||||
if (NULL == ok_tex)
|
if (NULL == ok_tex && go->getResourceManager())
|
||||||
{
|
{
|
||||||
ok_tex = WResourceManager::Instance()->RetrieveTexture("Ok.png", RETRIEVE_LOCK);
|
ok_tex = go->getResourceManager()->RetrieveTexture("Ok.png", RETRIEVE_LOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiCombat::~GuiCombat()
|
GuiCombat::~GuiCombat()
|
||||||
{
|
{
|
||||||
if (ok_tex)
|
if (ok_tex && observer->getResourceManager())
|
||||||
{
|
{
|
||||||
WResourceManager::Instance()->Release(ok_tex);
|
observer->getResourceManager()->Release(ok_tex);
|
||||||
ok_tex = NULL;
|
ok_tex = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ bool GuiCombat::CheckUserInput(JButton key)
|
|||||||
if (NONE == cursor_pos)
|
if (NONE == cursor_pos)
|
||||||
return false;
|
return false;
|
||||||
DamagerDamaged* oldActive = active;
|
DamagerDamaged* oldActive = active;
|
||||||
/* This is untested
|
/*
|
||||||
int x,y;
|
int x,y;
|
||||||
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||||
{
|
{
|
||||||
@@ -537,7 +537,7 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
|||||||
if (activeAtk == *it)
|
if (activeAtk == *it)
|
||||||
activeAtk = NULL;
|
activeAtk = NULL;
|
||||||
attackers.erase(it);
|
attackers.erase(it);
|
||||||
trash(d);
|
observer->mTrash->trash(d);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -546,7 +546,7 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
DefenserDamaged* d = *q;
|
DefenserDamaged* d = *q;
|
||||||
(*it)->blockers.erase(q);
|
(*it)->blockers.erase(q);
|
||||||
trash(d);
|
observer->mTrash->trash(d);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -560,7 +560,7 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
AttackerDamaged* d = *it;
|
AttackerDamaged* d = *it;
|
||||||
attackers.erase(it);
|
attackers.erase(it);
|
||||||
trash(d);
|
observer->mTrash->trash(d);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -574,7 +574,7 @@ int GuiCombat::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
DefenserDamaged* d = *q;
|
DefenserDamaged* d = *q;
|
||||||
(*it)->blockers.erase(q);
|
(*it)->blockers.erase(q);
|
||||||
trash(d);
|
observer->mTrash->trash(d);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -6,26 +6,28 @@
|
|||||||
GuiFrame::GuiFrame(GameObserver* observer)
|
GuiFrame::GuiFrame(GameObserver* observer)
|
||||||
: GuiLayer(observer)
|
: GuiLayer(observer)
|
||||||
{
|
{
|
||||||
if (WResourceManager::Instance()->GetTexture("wood.png"))
|
if (observer->getResourceManager())
|
||||||
wood = WResourceManager::Instance()->RetrieveQuad("wood.png", 0, 0, SCREEN_WIDTH, 28);
|
{
|
||||||
|
if (observer->getResourceManager()->GetTexture("wood.png"))
|
||||||
|
wood = observer->getResourceManager()->RetrieveQuad("wood.png", 0, 0, SCREEN_WIDTH, 28);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GameApp::systemError += "Can't load wood texture : " __FILE__ "\n";
|
GameApp::systemError += "Can't load wood texture : " __FILE__ "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WResourceManager::Instance()->GetTexture("gold.png"))
|
if (observer->getResourceManager()->GetTexture("gold.png"))
|
||||||
{
|
{
|
||||||
gold1 = WResourceManager::Instance()->RetrieveQuad("gold.png", 0, 0, SCREEN_WIDTH, 6, "gold1");
|
gold1 = observer->getResourceManager()->RetrieveQuad("gold.png", 0, 0, SCREEN_WIDTH, 6, "gold1");
|
||||||
gold2 = WResourceManager::Instance()->RetrieveQuad("gold.png", 0, 6, SCREEN_WIDTH, 6, "gold2");
|
gold2 = observer->getResourceManager()->RetrieveQuad("gold.png", 0, 6, SCREEN_WIDTH, 6, "gold2");
|
||||||
if (WResourceManager::Instance()->GetTexture("goldglow.png"))
|
if (observer->getResourceManager()->GetTexture("goldglow.png"))
|
||||||
goldGlow = WResourceManager::Instance()->RetrieveQuad("goldglow.png", 1, 1, SCREEN_WIDTH - 2, 18);
|
goldGlow = observer->getResourceManager()->RetrieveQuad("goldglow.png", 1, 1, SCREEN_WIDTH - 2, 18);
|
||||||
if (gold2)
|
if (gold2)
|
||||||
{
|
{
|
||||||
gold2->SetColor(ARGB(127, 255, 255, 255));
|
gold2->SetColor(ARGB(127, 255, 255, 255));
|
||||||
gold2->SetHFlip(true);
|
gold2->SetHFlip(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
step = 0.0;
|
step = 0.0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,14 @@ HandLimitor::HandLimitor(GuiHand* hand) :
|
|||||||
GuiHand::GuiHand(GameObserver* observer, MTGHand* hand) :
|
GuiHand::GuiHand(GameObserver* observer, MTGHand* hand) :
|
||||||
GuiLayer(observer), hand(hand)
|
GuiLayer(observer), hand(hand)
|
||||||
{
|
{
|
||||||
back = WResourceManager::Instance()->RetrieveTempQuad("handback.png");
|
if(observer->getResourceManager())
|
||||||
|
{
|
||||||
|
back = observer->getResourceManager()->RetrieveTempQuad("handback.png");
|
||||||
if (back.get())
|
if (back.get())
|
||||||
back->SetTextureRect(1, 0, 100, 250);
|
back->SetTextureRect(1, 0, 100, 250);
|
||||||
else
|
else
|
||||||
GameApp::systemError = "Error loading hand texture : " __FILE__;
|
GameApp::systemError = "Error loading hand texture : " __FILE__;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiHand::~GuiHand()
|
GuiHand::~GuiHand()
|
||||||
@@ -175,10 +178,10 @@ bool GuiHandSelf::CheckUserInput(JButton key)
|
|||||||
{
|
{
|
||||||
state = (Open == state ? Closed : Open);
|
state = (Open == state ? Closed : Open);
|
||||||
if (Open == state)
|
if (Open == state)
|
||||||
CardSelectorSingleton::Instance()->Push();
|
observer->getCardSelector()->Push();
|
||||||
CardSelectorSingleton::Instance()->Limit(Open == state ? limitor : NULL, CardView::handZone);
|
observer->getCardSelector()->Limit(Open == state ? limitor : NULL, CardView::handZone);
|
||||||
if (Closed == state)
|
if (Closed == state)
|
||||||
CardSelectorSingleton::Instance()->Pop();
|
observer->getCardSelector()->Pop();
|
||||||
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
if (OptionHandDirection::HORIZONTAL == options[Options::HANDDIRECTION].number)
|
||||||
backpos.y = Open == state ? OpenY : ClosedY;
|
backpos.y = Open == state ? OpenY : ClosedY;
|
||||||
else
|
else
|
||||||
@@ -264,7 +267,7 @@ int GuiHandSelf::receiveEventPlus(WEvent* e)
|
|||||||
card = NEW CardView(CardView::handZone, ev->card, ClosedRowX, 0);
|
card = NEW CardView(CardView::handZone, ev->card, ClosedRowX, 0);
|
||||||
card->t = 6 * M_PI;
|
card->t = 6 * M_PI;
|
||||||
cards.push_back(card);
|
cards.push_back(card);
|
||||||
CardSelectorSingleton::Instance()->Add(card);
|
observer->getCardSelector()->Add(card);
|
||||||
Repos();
|
Repos();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -279,10 +282,10 @@ int GuiHandSelf::receiveEventMinus(WEvent* e)
|
|||||||
if (event->card->previous == (*it)->card)
|
if (event->card->previous == (*it)->card)
|
||||||
{
|
{
|
||||||
CardView* cv = *it;
|
CardView* cv = *it;
|
||||||
CardSelectorSingleton::Instance()->Remove(cv);
|
observer->getCardSelector()->Remove(cv);
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
Repos();
|
Repos();
|
||||||
trash(cv);
|
observer->mTrash->trash(cv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -317,7 +320,7 @@ int GuiHandOpponent::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
CardView* cv = *it;
|
CardView* cv = *it;
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
trash(cv);
|
observer->mTrash->trash(cv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ GuiPhaseBar::GuiPhaseBar(GameObserver* observer) :
|
|||||||
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
GameApp::systemError = "Error loading phasebar texture : " __FILE__;
|
||||||
|
|
||||||
zoom = ICONSCALE;
|
zoom = ICONSCALE;
|
||||||
CardSelectorSingleton::Instance()->Add(this);
|
observer->getCardSelector()->Add(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ int GuiPlay::receiveEventPlus(WEvent * e)
|
|||||||
// Make sure that the card is repositioned before adding it to the CardSelector, as
|
// Make sure that the card is repositioned before adding it to the CardSelector, as
|
||||||
// the card's position is a cue for certain CardSelector variants as to what zone the card is placed in
|
// the card's position is a cue for certain CardSelector variants as to what zone the card is placed in
|
||||||
Replace();
|
Replace();
|
||||||
CardSelectorSingleton::Instance()->Add(card);
|
observer->getCardSelector()->Add(card);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,9 +420,9 @@ int GuiPlay::receiveEventMinus(WEvent * e)
|
|||||||
else if (event->card->attacker)
|
else if (event->card->attacker)
|
||||||
battleField.removeAttacker(event->card);
|
battleField.removeAttacker(event->card);
|
||||||
CardView* cv = *it;
|
CardView* cv = *it;
|
||||||
CardSelectorSingleton::Instance()->Remove(cv);
|
observer->getCardSelector()->Remove(cv);
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
trash(cv);
|
observer->mTrash->trash(cv);
|
||||||
Replace();
|
Replace();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ void GuiGameZone::Update(float dt)
|
|||||||
if (fabs(c->actX - c->x) < 0.01 && fabs(c->actY - c->y) < 0.01)
|
if (fabs(c->actX - c->x) < 0.01 && fabs(c->actY - c->y) < 0.01)
|
||||||
{
|
{
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
trash(c);
|
zone->owner->getObserver()->mTrash->trash(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ int GuiGraveyard::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
CardView* cv = *it;
|
CardView* cv = *it;
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
trash(cv);
|
zone->owner->getObserver()->mTrash->trash(cv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -322,7 +322,7 @@ int GuiOpponentHand::receiveEventMinus(WEvent* e)
|
|||||||
{
|
{
|
||||||
CardView* cv = *it;
|
CardView* cv = *it;
|
||||||
cards.erase(it);
|
cards.erase(it);
|
||||||
trash(cv);
|
zone->owner->getObserver()->mTrash->trash(cv);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ SUPPORT_OBJECT_ANALYTICS(MTGCardInstance)
|
|||||||
MTGCardInstance MTGCardInstance::AnyCard = MTGCardInstance();
|
MTGCardInstance MTGCardInstance::AnyCard = MTGCardInstance();
|
||||||
MTGCardInstance MTGCardInstance::NoCard = MTGCardInstance();
|
MTGCardInstance MTGCardInstance::NoCard = MTGCardInstance();
|
||||||
|
|
||||||
MTGCardInstance MTGCardInstance::ExtraRules[] = { MTGCardInstance(), MTGCardInstance() };
|
|
||||||
|
|
||||||
MTGCardInstance::MTGCardInstance() :
|
MTGCardInstance::MTGCardInstance() :
|
||||||
CardPrimitive(), MTGCard(), Damageable(0, 0), view(NULL)
|
CardPrimitive(), MTGCard(), Damageable(0, 0), view(NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -247,15 +247,16 @@ void MTGPlayerCards::drawFromLibrary()
|
|||||||
// so prefetch it.
|
// so prefetch it.
|
||||||
|
|
||||||
// if we're not in text mode, always get the thumb
|
// if we're not in text mode, always get the thumb
|
||||||
if (CardSelectorSingleton::Instance()->GetDrawMode() != DrawMode::kText)
|
if (library->owner->getObserver()->getCardSelector()->GetDrawMode() != DrawMode::kText
|
||||||
|
&& library->owner->getObserver()->getResourceManager())
|
||||||
{
|
{
|
||||||
DebugTrace("Prefetching AI card going into play: " << toMove->getImageName());
|
DebugTrace("Prefetching AI card going into play: " << toMove->getImageName());
|
||||||
WResourceManager::Instance()->RetrieveCard(toMove, RETRIEVE_THUMB);
|
library->owner->getObserver()->getResourceManager()->RetrieveCard(toMove, RETRIEVE_THUMB);
|
||||||
|
|
||||||
// also cache the large image if we're using kNormal mode
|
// also cache the large image if we're using kNormal mode
|
||||||
if (CardSelectorSingleton::Instance()->GetDrawMode() == DrawMode::kNormal)
|
if (library->owner->getObserver()->getCardSelector()->GetDrawMode() == DrawMode::kNormal)
|
||||||
{
|
{
|
||||||
WResourceManager::Instance()->RetrieveCard(toMove);
|
library->owner->getObserver()->getResourceManager()->RetrieveCard(toMove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,9 +340,9 @@ MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone
|
|||||||
{
|
{
|
||||||
if (to == g->players[0]->game->graveyard || to == g->players[1]->game->graveyard)
|
if (to == g->players[0]->game->graveyard || to == g->players[1]->game->graveyard)
|
||||||
{
|
{
|
||||||
if (card->isCreature())
|
if (card->isCreature() && g->getResourceManager())
|
||||||
{
|
{
|
||||||
JSample * sample = WResourceManager::Instance()->RetrieveSample("graveyard.wav");
|
JSample * sample = g->getResourceManager()->RetrieveSample("graveyard.wav");
|
||||||
if (sample)
|
if (sample)
|
||||||
JSoundSystem::GetInstance()->PlaySample(sample);
|
JSoundSystem::GetInstance()->PlaySample(sample);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1197,11 +1197,11 @@ int MTGAttackRule::reactToClick(MTGCardInstance * card)
|
|||||||
//Graphically select the next card that can attack
|
//Graphically select the next card that can attack
|
||||||
if (!card->isAttacker())
|
if (!card->isAttacker())
|
||||||
{
|
{
|
||||||
CardSelectorSingleton::Instance()->PushLimitor();
|
game->getCardSelector()->PushLimitor();
|
||||||
CardSelectorSingleton::Instance()->Limit(this, CardView::playZone);
|
game->getCardSelector()->Limit(this, CardView::playZone);
|
||||||
CardSelectorSingleton::Instance()->CheckUserInput(JGE_BTN_RIGHT);
|
game->getCardSelector()->CheckUserInput(JGE_BTN_RIGHT);
|
||||||
CardSelectorSingleton::Instance()->Limit(NULL, CardView::playZone);
|
game->getCardSelector()->Limit(NULL, CardView::playZone);
|
||||||
CardSelectorSingleton::Instance()->PopLimitor();
|
game->getCardSelector()->PopLimitor();
|
||||||
}
|
}
|
||||||
card->toggleAttacker();
|
card->toggleAttacker();
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1416,11 +1416,8 @@ MTGBlockRule * MTGBlockRule::clone() const
|
|||||||
// * Momir
|
// * Momir
|
||||||
//
|
//
|
||||||
|
|
||||||
int MTGMomirRule::initialized = 0;
|
|
||||||
vector<int> MTGMomirRule::pool[20];
|
|
||||||
|
|
||||||
MTGMomirRule::MTGMomirRule(GameObserver* observer, int _id, MTGAllCards * _collection) :
|
MTGMomirRule::MTGMomirRule(GameObserver* observer, int _id, MTGAllCards * _collection) :
|
||||||
PermanentAbility(observer, _id)
|
PermanentAbility(observer, _id), initialized(false)
|
||||||
{
|
{
|
||||||
collection = _collection;
|
collection = _collection;
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
@@ -1565,11 +1562,8 @@ MTGMomirRule * MTGMomirRule::clone() const
|
|||||||
//less than or equal to the creature.
|
//less than or equal to the creature.
|
||||||
//note this can kill your creature if the equipment contains negitive toughness
|
//note this can kill your creature if the equipment contains negitive toughness
|
||||||
|
|
||||||
int MTGStoneHewerRule::initialized = 0;
|
|
||||||
vector<int> MTGStoneHewerRule::pool[20];
|
|
||||||
|
|
||||||
MTGStoneHewerRule::MTGStoneHewerRule(GameObserver* observer, int _id, MTGAllCards * _collection) :
|
MTGStoneHewerRule::MTGStoneHewerRule(GameObserver* observer, int _id, MTGAllCards * _collection) :
|
||||||
PermanentAbility(observer, _id)
|
PermanentAbility(observer, _id), initialized(false)
|
||||||
{
|
{
|
||||||
collection = _collection;
|
collection = _collection;
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
|
|||||||
@@ -60,21 +60,25 @@ Player::~Player()
|
|||||||
{
|
{
|
||||||
SAFE_DELETE(manaPool);
|
SAFE_DELETE(manaPool);
|
||||||
SAFE_DELETE(game);
|
SAFE_DELETE(game);
|
||||||
WResourceManager::Instance()->Release(mAvatarTex);
|
if(mAvatarTex && observer->getResourceManager())
|
||||||
|
observer->getResourceManager()->Release(mAvatarTex);
|
||||||
mAvatarTex = NULL;
|
mAvatarTex = NULL;
|
||||||
SAFE_DELETE(mDeck);
|
SAFE_DELETE(mDeck);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Player::loadAvatar(string file, string resName)
|
bool Player::loadAvatar(string file, string resName)
|
||||||
{
|
{
|
||||||
|
WResourceManager * rm = observer->getResourceManager();
|
||||||
|
if(!rm) return false;
|
||||||
|
|
||||||
if (mAvatarTex)
|
if (mAvatarTex)
|
||||||
{
|
{
|
||||||
WResourceManager::Instance()->Release(mAvatarTex);
|
rm->Release(mAvatarTex);
|
||||||
mAvatarTex = NULL;
|
mAvatarTex = NULL;
|
||||||
}
|
}
|
||||||
mAvatarTex = WResourceManager::Instance()->RetrieveTexture(file, RETRIEVE_LOCK, TEXTURE_SUB_AVATAR);
|
mAvatarTex = rm->RetrieveTexture(file, RETRIEVE_LOCK, TEXTURE_SUB_AVATAR);
|
||||||
if (mAvatarTex) {
|
if (mAvatarTex) {
|
||||||
mAvatar = WResourceManager::Instance()->RetrieveQuad(file, 0, 0, 35, 50, resName, RETRIEVE_NORMAL, TEXTURE_SUB_AVATAR);
|
mAvatar = rm->RetrieveQuad(file, 0, 0, 35, 50, resName, RETRIEVE_NORMAL, TEXTURE_SUB_AVATAR);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ void Rules::addExtraRules(GameObserver* g)
|
|||||||
{
|
{
|
||||||
Player * p = g->players[i];
|
Player * p = g->players[i];
|
||||||
//Trick so that the abilities don't die;
|
//Trick so that the abilities don't die;
|
||||||
MTGCardInstance::ExtraRules[i].currentZone = p->game->inPlay;
|
g->ExtraRules[i].currentZone = p->game->inPlay;
|
||||||
MTGCardInstance::ExtraRules[i].lastController = p;
|
g->ExtraRules[i].lastController = p;
|
||||||
for (size_t j = 0; j < initState.playerData[i].extraRules.size(); ++j)
|
for (size_t j = 0; j < initState.playerData[i].extraRules.size(); ++j)
|
||||||
{
|
{
|
||||||
AbilityFactory af(g);
|
AbilityFactory af(g);
|
||||||
@@ -153,7 +153,7 @@ void Rules::addExtraRules(GameObserver* g)
|
|||||||
int handsize = 7;
|
int handsize = 7;
|
||||||
int difficultyRating = 0;
|
int difficultyRating = 0;
|
||||||
int Optimizedhandcheat = options[Options::OPTIMIZE_HAND].number;
|
int Optimizedhandcheat = options[Options::OPTIMIZE_HAND].number;
|
||||||
MTGAbility * a = af.parseMagicLine(initState.playerData[i].extraRules[j], id++, NULL, &MTGCardInstance::ExtraRules[i]);
|
MTGAbility * a = af.parseMagicLine(initState.playerData[i].extraRules[j], id++, NULL, &(g->ExtraRules[i]));
|
||||||
if (p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
|
if (p->playMode != Player::MODE_TEST_SUITE && g->mRules->gamemode != GAME_TYPE_MOMIR && g->mRules->gamemode
|
||||||
!= GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
|
!= GAME_TYPE_RANDOM1 && g->mRules->gamemode != GAME_TYPE_RANDOM2 && g->mRules->gamemode
|
||||||
!= GAME_TYPE_STORY &&
|
!= GAME_TYPE_STORY &&
|
||||||
@@ -214,7 +214,7 @@ void Rules::addExtraRules(GameObserver* g)
|
|||||||
for (size_t j = 0; j < extraRules.size(); ++j)
|
for (size_t j = 0; j < extraRules.size(); ++j)
|
||||||
{
|
{
|
||||||
AbilityFactory af(g);
|
AbilityFactory af(g);
|
||||||
MTGAbility * a = af.parseMagicLine(extraRules[j], id++, NULL, &MTGCardInstance::ExtraRules[0]);
|
MTGAbility * a = af.parseMagicLine(extraRules[j], id++, NULL, &(g->ExtraRules[0]));
|
||||||
if (a)
|
if (a)
|
||||||
{
|
{
|
||||||
if (a->oneShot)
|
if (a->oneShot)
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ JTexture* SimpleMenu::spadeRTex = NULL;
|
|||||||
JTexture* SimpleMenu::spadeLTex = NULL;
|
JTexture* SimpleMenu::spadeLTex = NULL;
|
||||||
JTexture* SimpleMenu::jewelTex = NULL;
|
JTexture* SimpleMenu::jewelTex = NULL;
|
||||||
JTexture* SimpleMenu::sideTex = NULL;
|
JTexture* SimpleMenu::sideTex = NULL;
|
||||||
WFont* SimpleMenu::titleFont = NULL;
|
|
||||||
hgeParticleSystem* SimpleMenu::stars = NULL;
|
|
||||||
|
|
||||||
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical)
|
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical)
|
||||||
: JGuiController(id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical)
|
: JGuiController(id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical)
|
||||||
@@ -58,7 +56,6 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, floa
|
|||||||
jewel.reset(NEW JQuad(jewelTex, 1, 1, 3, 3));
|
jewel.reset(NEW JQuad(jewelTex, 1, 1, 3, 3));
|
||||||
side = WResourceManager::Instance()->RetrieveQuad("menuside.png", 1, 1, 1, kPoleWidth, "menuside", RETRIEVE_MANAGE);
|
side = WResourceManager::Instance()->RetrieveQuad("menuside.png", 1, 1, 1, kPoleWidth, "menuside", RETRIEVE_MANAGE);
|
||||||
|
|
||||||
if (NULL == stars)
|
|
||||||
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get()));
|
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get()));
|
||||||
|
|
||||||
stars->FireAt(mX, mY);
|
stars->FireAt(mX, mY);
|
||||||
@@ -66,6 +63,7 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, floa
|
|||||||
|
|
||||||
SimpleMenu::~SimpleMenu()
|
SimpleMenu::~SimpleMenu()
|
||||||
{
|
{
|
||||||
|
SAFE_DELETE(stars);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleMenu::drawHorzPole(float x, float y, float width)
|
void SimpleMenu::drawHorzPole(float x, float y, float width)
|
||||||
@@ -247,6 +245,5 @@ void SimpleMenu::Close()
|
|||||||
void SimpleMenu::destroy()
|
void SimpleMenu::destroy()
|
||||||
{
|
{
|
||||||
SimpleMenu::jewel.reset();
|
SimpleMenu::jewel.reset();
|
||||||
SAFE_DELETE(SimpleMenu::stars);
|
|
||||||
SAFE_DELETE(SimpleMenu::jewelTex);
|
SAFE_DELETE(SimpleMenu::jewelTex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,27 +303,24 @@ StoryChoice::StoryChoice(string pageId, string text, int JGOid, float mX, float
|
|||||||
//Actually loads a duel
|
//Actually loads a duel
|
||||||
void StoryDuel::init()
|
void StoryDuel::init()
|
||||||
{
|
{
|
||||||
vector<Player *> players;
|
game = new GameObserver();
|
||||||
|
|
||||||
char folder[255], deckFile[255], deckFileSmall[255];
|
char folder[255], deckFile[255], deckFileSmall[255];
|
||||||
sprintf(folder, CAMPAIGNS_FOLDER"%s/%s", mParent->folder.c_str(), pageId.c_str());
|
sprintf(folder, CAMPAIGNS_FOLDER"%s/%s", mParent->folder.c_str(), pageId.c_str());
|
||||||
|
|
||||||
sprintf(deckFile, "%s/deck.txt", folder);
|
sprintf(deckFile, "%s/deck.txt", folder);
|
||||||
sprintf(deckFileSmall, "campaign_%s", mParent->folder.c_str());
|
sprintf(deckFileSmall, "campaign_%s", mParent->folder.c_str());
|
||||||
players.push_back(NEW HumanPlayer(0, deckFile, deckFileSmall, true));
|
game->loadPlayer(0, NEW HumanPlayer(game, deckFile, deckFileSmall, true));
|
||||||
|
|
||||||
|
|
||||||
sprintf(deckFile, "%s/opponent_deck.txt", folder);
|
sprintf(deckFile, "%s/opponent_deck.txt", folder);
|
||||||
sprintf(deckFileSmall, "campaign_ennemy_%s_%s", mParent->folder.c_str(), pageId.c_str());
|
sprintf(deckFileSmall, "campaign_ennemy_%s_%s", mParent->folder.c_str(), pageId.c_str());
|
||||||
players.push_back(NEW AIPlayerBaka(0, deckFile, deckFileSmall, "baka.jpg"));
|
game->loadPlayer(1, NEW AIPlayerBaka(game, deckFile, deckFileSmall, "baka.jpg"));
|
||||||
|
|
||||||
string rulesFile = folder;
|
string rulesFile = folder;
|
||||||
rulesFile.append("/rules.txt");
|
rulesFile.append("/rules.txt");
|
||||||
rules = NEW Rules(bg);
|
rules = NEW Rules(bg);
|
||||||
rules->load(rulesFile);
|
rules->load(rulesFile);
|
||||||
|
|
||||||
game = new GameObserver(players);
|
|
||||||
|
|
||||||
rules->gamemode = GAME_TYPE_STORY;
|
rules->gamemode = GAME_TYPE_STORY;
|
||||||
game->startGame(GAME_TYPE_STORY, rules);
|
game->startGame(GAME_TYPE_STORY, rules);
|
||||||
}
|
}
|
||||||
|
|||||||
+221
-121
@@ -15,14 +15,14 @@ using std::string;
|
|||||||
|
|
||||||
// NULL is sent in place of a MTGDeck since there is no way to create a MTGDeck without a proper deck file.
|
// NULL is sent in place of a MTGDeck since there is no way to create a MTGDeck without a proper deck file.
|
||||||
// TestSuiteAI will be responsible for managing its own deck state.
|
// TestSuiteAI will be responsible for managing its own deck state.
|
||||||
TestSuiteAI::TestSuiteAI(GameObserver *observer, TestSuite * _suite, int playerId) :
|
TestSuiteAI::TestSuiteAI(TestSuiteGame *tsGame, int playerId) :
|
||||||
AIPlayerBaka(observer, "testsuite", "testsuite", "baka.jpg", NULL)
|
AIPlayerBaka(tsGame->observer, "testsuite", "testsuite", "baka.jpg", NULL)
|
||||||
{
|
{
|
||||||
SAFE_DELETE(game); //game might have been set in the parent with default values
|
SAFE_DELETE(game); //game might have been set in the parent with default values
|
||||||
game = _suite->buildDeck(this, playerId);
|
game = tsGame->buildDeck(this, playerId);
|
||||||
game->setOwner(this);
|
game->setOwner(this);
|
||||||
|
|
||||||
suite = _suite;
|
suite = tsGame;
|
||||||
timer = 0;
|
timer = 0;
|
||||||
playMode = MODE_TEST_SUITE;
|
playMode = MODE_TEST_SUITE;
|
||||||
this->deckName = "Test Suite AI";
|
this->deckName = "Test Suite AI";
|
||||||
@@ -55,7 +55,7 @@ MTGCardInstance * TestSuiteAI::getCard(string action)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Interruptible * TestSuite::getActionByMTGId(GameObserver* observer, int mtgid)
|
Interruptible * TestSuiteGame::getActionByMTGId(int mtgid)
|
||||||
{
|
{
|
||||||
ActionStack * as = observer->mLayers->stackLayer();
|
ActionStack * as = observer->mLayers->stackLayer();
|
||||||
Interruptible * action = NULL;
|
Interruptible * action = NULL;
|
||||||
@@ -121,7 +121,7 @@ int TestSuiteAI::Act(float dt)
|
|||||||
if (action == "")
|
if (action == "")
|
||||||
{
|
{
|
||||||
//end of game
|
//end of game
|
||||||
suite->assertGame(observer);
|
suite->assertGame();
|
||||||
observer->gameOver = observer->players[0];
|
observer->gameOver = observer->players[0];
|
||||||
DebugTrace("================================ END OF TEST =======================\n");
|
DebugTrace("================================ END OF TEST =======================\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -221,7 +221,7 @@ int TestSuiteAI::Act(float dt)
|
|||||||
if (mtgid)
|
if (mtgid)
|
||||||
{
|
{
|
||||||
DebugTrace("TESTSUITE CARD ID:" << mtgid);
|
DebugTrace("TESTSUITE CARD ID:" << mtgid);
|
||||||
toInterrupt = suite->getActionByMTGId(observer, mtgid);
|
toInterrupt = suite->getActionByMTGId(mtgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toInterrupt)
|
if (toInterrupt)
|
||||||
@@ -277,7 +277,7 @@ void TestSuiteState::parsePlayerState(int playerId, string s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string TestSuite::getNextAction()
|
string TestSuiteGame::getNextAction()
|
||||||
{
|
{
|
||||||
currentAction++;
|
currentAction++;
|
||||||
if (actions.nbitems && currentAction <= actions.nbitems)
|
if (actions.nbitems && currentAction <= actions.nbitems)
|
||||||
@@ -287,40 +287,15 @@ string TestSuite::getNextAction()
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
MTGPlayerCards * TestSuite::buildDeck(Player* player, int playerId)
|
void TestSuiteGame::handleResults(bool wasAI, int error)
|
||||||
{
|
{
|
||||||
int list[100];
|
testsuite->handleResults(wasAI, error);
|
||||||
int nbcards = 0;
|
};
|
||||||
MTGPlayerCards * deck = NULL;
|
|
||||||
|
|
||||||
if(initState.players.size() > (size_t)playerId)
|
|
||||||
{
|
|
||||||
MTGGameZone * loadedPlayerZones[] = { initState.players[playerId]->game->graveyard,
|
|
||||||
initState.players[playerId]->game->library,
|
|
||||||
initState.players[playerId]->game->hand,
|
|
||||||
initState.players[playerId]->game->inPlay };
|
|
||||||
|
|
||||||
for (int j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
for (size_t k = 0; k < loadedPlayerZones[j]->cards.size(); k++)
|
|
||||||
{
|
|
||||||
int cardid = loadedPlayerZones[j]->cards[k]->getId();
|
|
||||||
list[nbcards] = cardid;
|
|
||||||
nbcards++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deck = NEW MTGPlayerCards(player, list, nbcards);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
deck = NEW MTGPlayerCards();
|
|
||||||
}
|
|
||||||
|
|
||||||
return deck;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestSuite::initGame(GameObserver* g)
|
void TestSuite::initGame(GameObserver* g)
|
||||||
{
|
{
|
||||||
|
observer = g;
|
||||||
//The first test runs slowly, the other ones run faster.
|
//The first test runs slowly, the other ones run faster.
|
||||||
//This way a human can see what happens when testing a specific file,
|
//This way a human can see what happens when testing a specific file,
|
||||||
// or go faster when it comes to the whole test suite.
|
// or go faster when it comes to the whole test suite.
|
||||||
@@ -334,64 +309,10 @@ void TestSuite::initGame(GameObserver* g)
|
|||||||
timerLimit = 3;
|
timerLimit = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugTrace("TESTSUITE Init Game");
|
TestSuiteGame::initGame();
|
||||||
g->phaseRing->goToPhase(initState.phase, g->players[0]);
|
|
||||||
g->currentGamePhase = initState.phase;
|
|
||||||
for (int i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
AIPlayerBaka * p = (AIPlayerBaka *) (g->players[i]);
|
|
||||||
p->forceBestAbilityUse = forceAbility;
|
|
||||||
p->life = initState.players[i]->life;
|
|
||||||
p->poisonCount = initState.players[i]->poisonCount;
|
|
||||||
stringstream stream;
|
|
||||||
stream << initState.players[i]->getRandomGenerator()->saveLoadedRandValues(stream);
|
|
||||||
p->getRandomGenerator()->loadRandValues(stream.str());
|
|
||||||
MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay };
|
|
||||||
MTGGameZone * loadedPlayerZones[] = { initState.players[i]->game->graveyard,
|
|
||||||
initState.players[i]->game->library,
|
|
||||||
initState.players[i]->game->hand,
|
|
||||||
initState.players[i]->game->inPlay };
|
|
||||||
for (int j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
MTGGameZone * zone = playerZones[j];
|
|
||||||
for (size_t k = 0; k < loadedPlayerZones[j]->cards.size(); k++)
|
|
||||||
{
|
|
||||||
MTGCardInstance * card = Rules::getCardByMTGId(g, loadedPlayerZones[j]->cards[k]->getId());
|
|
||||||
if (card && zone != p->game->library)
|
|
||||||
{
|
|
||||||
if (zone == p->game->inPlay)
|
|
||||||
{
|
|
||||||
MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack);
|
|
||||||
Spell * spell = NEW Spell(g, copy);
|
|
||||||
spell->resolve();
|
|
||||||
if (!summoningSickness && (size_t)p->game->inPlay->nb_cards > k) p->game->inPlay->cards[k]->summoningSickness = 0;
|
|
||||||
delete spell;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!p->game->library->hasCard(card))
|
|
||||||
{
|
|
||||||
LOG ("TESTUITE ERROR, CARD NOT FOUND IN LIBRARY\n");
|
|
||||||
}
|
|
||||||
p->game->putInZone(card, p->game->library, zone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!card)
|
|
||||||
{
|
|
||||||
LOG ("TESTUITE ERROR, card is NULL\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
zone->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn
|
|
||||||
}
|
|
||||||
p->game->stack->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn
|
|
||||||
|
|
||||||
}
|
|
||||||
DebugTrace("TESTUITE Init Game Done !");
|
|
||||||
}
|
}
|
||||||
int TestSuite::Log(const char * text)
|
|
||||||
|
int TestSuiteGame::Log(const char * text)
|
||||||
{
|
{
|
||||||
ofstream file;
|
ofstream file;
|
||||||
if (JFileSystem::GetInstance()->openForWrite(file, "test/results.html", ios_base::app))
|
if (JFileSystem::GetInstance()->openForWrite(file, "test/results.html", ios_base::app))
|
||||||
@@ -405,27 +326,29 @@ int TestSuite::Log(const char * text)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
int TestSuite::assertGame(GameObserver* g)
|
|
||||||
|
void TestSuiteGame::assertGame()
|
||||||
{
|
{
|
||||||
|
mMutex.lock();
|
||||||
//compare the game state with the results
|
//compare the game state with the results
|
||||||
char result[4096];
|
char result[4096];
|
||||||
sprintf(result, "<h3>%s</h3>", files[currentfile - 1].c_str());
|
sprintf(result, "<h3>%s</h3>", filename.c_str());
|
||||||
Log(result);
|
Log(result);
|
||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
bool wasAI = false;
|
bool wasAI = false;
|
||||||
|
|
||||||
if (g->currentGamePhase != endState.phase)
|
if (observer->currentGamePhase != endState.phase)
|
||||||
{
|
{
|
||||||
sprintf(result, "<span class=\"error\">==phase problem. Expected [ %s ](%i), got [ %s ](%i)==</span><br />",
|
sprintf(result, "<span class=\"error\">==phase problem. Expected [ %s ](%i), got [ %s ](%i)==</span><br />",
|
||||||
Constants::MTGPhaseNames[endState.phase],endState.phase,
|
Constants::MTGPhaseNames[endState.phase],endState.phase,
|
||||||
Constants::MTGPhaseNames[g->currentGamePhase], g->currentGamePhase);
|
Constants::MTGPhaseNames[observer->currentGamePhase], observer->currentGamePhase);
|
||||||
Log(result);
|
Log(result);
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
TestSuiteAI * p = (TestSuiteAI *) (g->players[i]);
|
TestSuiteAI * p = (TestSuiteAI *) (observer->players[i]);
|
||||||
if (p->playMode == Player::MODE_AI) wasAI = true;
|
if (p->playMode == Player::MODE_AI) wasAI = true;
|
||||||
|
|
||||||
if (p->life != endState.players[i]->life)
|
if (p->life != endState.players[i]->life)
|
||||||
@@ -484,7 +407,7 @@ int TestSuite::assertGame(GameObserver* g)
|
|||||||
MTGCardInstance* cardToCheck = (k<endstateZones[j]->cards.size())?endstateZones[j]->cards[k]:0;
|
MTGCardInstance* cardToCheck = (k<endstateZones[j]->cards.size())?endstateZones[j]->cards[k]:0;
|
||||||
if(cardToCheck)
|
if(cardToCheck)
|
||||||
{ // Can be NULL if used "*" in the testcase.
|
{ // Can be NULL if used "*" in the testcase.
|
||||||
MTGCardInstance* card = Rules::getCardByMTGId(g, cardToCheck->getId());
|
MTGCardInstance* card = Rules::getCardByMTGId(observer, cardToCheck->getId());
|
||||||
if (card != 0 && !zone->hasCard(card))
|
if (card != 0 && !zone->hasCard(card))
|
||||||
{
|
{
|
||||||
sprintf(result, "<span class=\"error\">==Card ID not the same. Didn't find %i</span><br />", card->getId());
|
sprintf(result, "<span class=\"error\">==Card ID not the same. Didn't find %i</span><br />", card->getId());
|
||||||
@@ -495,13 +418,23 @@ int TestSuite::assertGame(GameObserver* g)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleResults(wasAI, error);
|
||||||
|
|
||||||
|
if(!error)
|
||||||
|
Log("<span class=\"success\">==Test Succesful !==</span>");
|
||||||
|
else
|
||||||
|
Log("<span class=\"error\">==Test Failed !==</span>");
|
||||||
|
mMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestSuite::handleResults(bool wasAI, int error)
|
||||||
|
{
|
||||||
if (wasAI)
|
if (wasAI)
|
||||||
{
|
{
|
||||||
nbAITests++;
|
nbAITests++;
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
nbAIFailed++;
|
nbAIFailed++;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -510,14 +443,13 @@ int TestSuite::assertGame(GameObserver* g)
|
|||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
nbFailed++;
|
nbFailed++;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log("<span class=\"success\">==Test Succesful !==</span>");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TestSuite::TestSuite(const char * filename)
|
TestSuite::TestSuite(const char * filename)
|
||||||
|
: TestSuiteGame(this), mRules(0), mProcessing(false)
|
||||||
{
|
{
|
||||||
timerLimit = 0;
|
timerLimit = 0;
|
||||||
|
|
||||||
@@ -572,26 +504,46 @@ TestSuite::TestSuite(const char * filename)
|
|||||||
file2.close();
|
file2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SAFE_DELETE(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TestSuite::loadNext()
|
int TestSuite::loadNext()
|
||||||
{
|
{
|
||||||
|
|
||||||
endTime = JGEGetTime();
|
endTime = JGEGetTime();
|
||||||
summoningSickness = 0;
|
summoningSickness = 0;
|
||||||
seed = 0;
|
seed = 0;
|
||||||
aiMaxCalls = -1;
|
aiMaxCalls = -1;
|
||||||
if (!nbfiles) return 0;
|
if (!nbfiles) return 0;
|
||||||
if (currentfile >= nbfiles) return 0;
|
|
||||||
currentfile++;
|
|
||||||
|
|
||||||
string currFilename = files[currentfile - 1];
|
filename = getNextFile();
|
||||||
if (currFilename == "+pregametests")
|
if (filename == "") {
|
||||||
|
// we let GameStateDuel delete the latest gameObserver.
|
||||||
|
mProcessing = false;
|
||||||
|
observer = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename == "+pregametests")
|
||||||
{
|
{
|
||||||
pregameTests();
|
pregameTests();
|
||||||
return loadNext();
|
return loadNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load(currFilename.c_str()))
|
if(!mProcessing)
|
||||||
|
{ // "I don't like to wait" mode
|
||||||
|
mProcessing = true;
|
||||||
|
mWorkerThread.clear();
|
||||||
|
size_t thread_count = 1;
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
thread_count = QThread::idealThreadCount();
|
||||||
|
#endif
|
||||||
|
for(size_t i = 0; i < (thread_count-1); i++)
|
||||||
|
mWorkerThread.push_back(boost::thread(ThreadProc, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
if (!load())
|
||||||
return loadNext();
|
return loadNext();
|
||||||
else
|
else
|
||||||
cout << "Starting test : " << files[currentfile - 1] << endl;
|
cout << "Starting test : " << files[currentfile - 1] << endl;
|
||||||
@@ -603,8 +555,7 @@ void TestSuiteActions::cleanup()
|
|||||||
nbitems = 0;
|
nbitems = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestSuiteState::cleanup(TestSuiteGame* tsGame)
|
||||||
void TestSuiteState::cleanup(TestSuite* suite)
|
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < players.size(); i++)
|
for (size_t i = 0; i < players.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -612,36 +563,34 @@ void TestSuiteState::cleanup(TestSuite* suite)
|
|||||||
}
|
}
|
||||||
players.clear();
|
players.clear();
|
||||||
|
|
||||||
players.push_back(new TestSuiteAI(0, suite, 0));
|
players.push_back(new TestSuiteAI(tsGame, 0));
|
||||||
players.push_back(new TestSuiteAI(0, suite, 1));
|
players.push_back(new TestSuiteAI(tsGame, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSuite::cleanup()
|
void TestSuite::cleanup()
|
||||||
{
|
{
|
||||||
currentAction = 0;
|
currentAction = 0;
|
||||||
|
observer = 0;
|
||||||
initState.cleanup(this);
|
initState.cleanup(this);
|
||||||
endState.cleanup(this);
|
endState.cleanup(this);
|
||||||
actions.cleanup();
|
actions.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TestSuite::load(const char * _filename)
|
|
||||||
|
bool TestSuiteGame::load()
|
||||||
{
|
{
|
||||||
summoningSickness = 0;
|
summoningSickness = 0;
|
||||||
forceAbility = false;
|
forceAbility = false;
|
||||||
gameType = GAME_TYPE_CLASSIC;
|
gameType = GAME_TYPE_CLASSIC;
|
||||||
char filename[4096];
|
|
||||||
sprintf(filename, "test/%s", _filename);
|
|
||||||
|
|
||||||
std::string s;
|
std::string s;
|
||||||
|
|
||||||
int state = -1;
|
int state = -1;
|
||||||
|
|
||||||
std::string contents;
|
std::string contents;
|
||||||
if (JFileSystem::GetInstance()->readIntoString(filename, contents))
|
if (JFileSystem::GetInstance()->readIntoString("test/"+filename, contents))
|
||||||
{
|
{
|
||||||
std::stringstream stream(contents);
|
std::stringstream stream(contents);
|
||||||
|
|
||||||
cleanup();
|
|
||||||
while (std::getline(stream, s))
|
while (std::getline(stream, s))
|
||||||
{
|
{
|
||||||
if (!s.size()) continue;
|
if (!s.size()) continue;
|
||||||
@@ -754,9 +703,9 @@ int TestSuite::load(const char * _filename)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSuite::pregameTests()
|
void TestSuite::pregameTests()
|
||||||
@@ -773,4 +722,155 @@ void TestSuite::pregameTests()
|
|||||||
if (!sb.unitTest()) nbFailed++;
|
if (!sb.unitTest()) nbFailed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestSuite::ThreadProc(void* inParam)
|
||||||
|
{
|
||||||
|
LOG("Entering TestSuite::ThreadProc");
|
||||||
|
TestSuite* instance = reinterpret_cast<TestSuite*>(inParam);
|
||||||
|
if (instance)
|
||||||
|
{
|
||||||
|
string filename;
|
||||||
|
float counter = 1.0f;
|
||||||
|
// while(instance->mProcessing)
|
||||||
|
{
|
||||||
|
while((filename = instance->getNextFile()) != "")
|
||||||
|
{
|
||||||
|
TestSuiteGame theGame(instance, filename);
|
||||||
|
if(theGame.isOK)
|
||||||
|
{
|
||||||
|
theGame.observer->loadTestSuitePlayer(0, &theGame);
|
||||||
|
theGame.observer->loadTestSuitePlayer(1, &theGame);
|
||||||
|
|
||||||
|
theGame.observer->startGame(theGame.gameType, instance->mRules);
|
||||||
|
theGame.initGame();
|
||||||
|
|
||||||
|
while(!theGame.observer->gameOver)
|
||||||
|
theGame.observer->Update(counter++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::this_thread::sleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG("Leaving TestSuite::ThreadProc");
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::mutex TestSuiteGame::mMutex;
|
||||||
|
|
||||||
|
TestSuiteGame::~TestSuiteGame()
|
||||||
|
{
|
||||||
|
SAFE_DELETE(observer);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestSuiteGame::TestSuiteGame(TestSuite* testsuite)
|
||||||
|
: summoningSickness(0), forceAbility(false), gameType(GAME_TYPE_CLASSIC), timerLimit(0),
|
||||||
|
currentAction(0), observer(0), testsuite(testsuite)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TestSuiteGame::TestSuiteGame(TestSuite* testsuite, string _filename)
|
||||||
|
: summoningSickness(0), forceAbility(false), gameType(GAME_TYPE_CLASSIC), timerLimit(3),
|
||||||
|
currentAction(0), observer(0), testsuite(testsuite)
|
||||||
|
{
|
||||||
|
filename = _filename;
|
||||||
|
observer = new GameObserver();
|
||||||
|
|
||||||
|
initState.cleanup(this);
|
||||||
|
endState.cleanup(this);
|
||||||
|
|
||||||
|
isOK = load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestSuiteGame::initGame()
|
||||||
|
{
|
||||||
|
DebugTrace("TESTSUITE Init Game");
|
||||||
|
observer->phaseRing->goToPhase(initState.phase, observer->players[0]);
|
||||||
|
observer->currentGamePhase = initState.phase;
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
AIPlayerBaka * p = (AIPlayerBaka *) (observer->players[i]);
|
||||||
|
p->forceBestAbilityUse = forceAbility;
|
||||||
|
p->life = initState.players[i]->life;
|
||||||
|
p->poisonCount = initState.players[i]->poisonCount;
|
||||||
|
stringstream stream;
|
||||||
|
stream << initState.players[i]->getRandomGenerator()->saveLoadedRandValues(stream);
|
||||||
|
p->getRandomGenerator()->loadRandValues(stream.str());
|
||||||
|
MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay };
|
||||||
|
MTGGameZone * loadedPlayerZones[] = { initState.players[i]->game->graveyard,
|
||||||
|
initState.players[i]->game->library,
|
||||||
|
initState.players[i]->game->hand,
|
||||||
|
initState.players[i]->game->inPlay };
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
MTGGameZone * zone = playerZones[j];
|
||||||
|
for (size_t k = 0; k < loadedPlayerZones[j]->cards.size(); k++)
|
||||||
|
{
|
||||||
|
MTGCardInstance * card = Rules::getCardByMTGId(observer, loadedPlayerZones[j]->cards[k]->getId());
|
||||||
|
if (card && zone != p->game->library)
|
||||||
|
{
|
||||||
|
if (zone == p->game->inPlay)
|
||||||
|
{
|
||||||
|
MTGCardInstance * copy = p->game->putInZone(card, p->game->library, p->game->stack);
|
||||||
|
Spell * spell = NEW Spell(observer, copy);
|
||||||
|
spell->resolve();
|
||||||
|
if (!summoningSickness && (size_t)p->game->inPlay->nb_cards > k) p->game->inPlay->cards[k]->summoningSickness = 0;
|
||||||
|
delete spell;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!p->game->library->hasCard(card))
|
||||||
|
{
|
||||||
|
LOG ("TESTUITE ERROR, CARD NOT FOUND IN LIBRARY\n");
|
||||||
|
}
|
||||||
|
p->game->putInZone(card, p->game->library, zone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!card)
|
||||||
|
{
|
||||||
|
LOG ("TESTUITE ERROR, card is NULL\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zone->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn
|
||||||
|
}
|
||||||
|
p->game->stack->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn
|
||||||
|
|
||||||
|
}
|
||||||
|
DebugTrace("TESTUITE Init Game Done !");
|
||||||
|
}
|
||||||
|
|
||||||
|
MTGPlayerCards * TestSuiteGame::buildDeck(Player* player, int playerId)
|
||||||
|
{
|
||||||
|
int list[100];
|
||||||
|
int nbcards = 0;
|
||||||
|
MTGPlayerCards * deck = NULL;
|
||||||
|
|
||||||
|
if(initState.players.size() > (size_t)playerId)
|
||||||
|
{
|
||||||
|
MTGGameZone * loadedPlayerZones[] = { initState.players[playerId]->game->graveyard,
|
||||||
|
initState.players[playerId]->game->library,
|
||||||
|
initState.players[playerId]->game->hand,
|
||||||
|
initState.players[playerId]->game->inPlay };
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
for (size_t k = 0; k < loadedPlayerZones[j]->cards.size(); k++)
|
||||||
|
{
|
||||||
|
int cardid = loadedPlayerZones[j]->cards[k]->getId();
|
||||||
|
list[nbcards] = cardid;
|
||||||
|
nbcards++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deck = NEW MTGPlayerCards(player, list, nbcards);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
deck = NEW MTGPlayerCards();
|
||||||
|
}
|
||||||
|
|
||||||
|
return deck;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,15 +9,11 @@
|
|||||||
template<class T>
|
template<class T>
|
||||||
void TrashBin<T>::put_out()
|
void TrashBin<T>::put_out()
|
||||||
{
|
{
|
||||||
for (typename std::vector<T*>::iterator it = bin.begin(); it != bin.end(); ++it)
|
for (typename std::vector<T>::iterator it = bin.begin(); it != bin.end(); ++it)
|
||||||
SAFE_DELETE(*it);
|
SAFE_DELETE(*it);
|
||||||
bin.clear();
|
bin.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static TrashBin<CardView> CardViewTrash;
|
|
||||||
static TrashBin<DefenserDamaged> DefenserDamagedTrash;
|
|
||||||
static TrashBin<AttackerDamaged> AttackerDamagedTrash;
|
|
||||||
|
|
||||||
void Trash::cleanup()
|
void Trash::cleanup()
|
||||||
{
|
{
|
||||||
CardViewTrash.put_out();
|
CardViewTrash.put_out();
|
||||||
@@ -25,15 +21,15 @@ void Trash::cleanup()
|
|||||||
AttackerDamagedTrash.put_out();
|
AttackerDamagedTrash.put_out();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void trash(CardView* garbage)
|
void Trash::trash(CardView* garbage)
|
||||||
{
|
{
|
||||||
CardViewTrash.bin.push_back(garbage);
|
CardViewTrash.bin.push_back(garbage);
|
||||||
}
|
}
|
||||||
template<> void trash(DefenserDamaged* garbage)
|
void Trash::trash(DefenserDamaged* garbage)
|
||||||
{
|
{
|
||||||
DefenserDamagedTrash.bin.push_back(garbage);
|
DefenserDamagedTrash.bin.push_back(garbage);
|
||||||
}
|
}
|
||||||
template<> void trash(AttackerDamaged* garbage)
|
void Trash::trash(AttackerDamaged* garbage)
|
||||||
{
|
{
|
||||||
AttackerDamagedTrash.bin.push_back(garbage);
|
AttackerDamagedTrash.bin.push_back(garbage);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user