Erwan
- fixed a bug with Flagstones of Trokair. There was no easy fix (cloned objects deleting stuff from their parents...) and I ended up using a "garbage collect at end of turn" technique the way I did with the ActionStack. As a result, the memory print of a turn will become bigger, and even more bugs might occur at the end of a turn... I'm ready to discuss this, although I think it's the best solution (in terms of result/amount of work) given the way abilities work right now - Test suite now gives the number of failed/success at the end of the tests
This commit is contained in:
@@ -94,19 +94,6 @@ type=Instant
|
|||||||
mana={2}{U}
|
mana={2}{U}
|
||||||
[/card]
|
[/card]
|
||||||
[card]
|
[card]
|
||||||
id=108901
|
|
||||||
name=Bogardan Rager
|
|
||||||
mana={5}{R}
|
|
||||||
type=Creature
|
|
||||||
subtype=Elemental
|
|
||||||
power=3
|
|
||||||
toughness=4
|
|
||||||
text=Flash (You may play this spell any time you could play an instant.) When Bogardan Rager comes into play, target creature gets +4/+0 until end of turn.
|
|
||||||
abilities=flash
|
|
||||||
auto=4/0 target(creature)
|
|
||||||
rarity=C
|
|
||||||
[/card]
|
|
||||||
[card]
|
|
||||||
id=109697
|
id=109697
|
||||||
name=Bonesplitter Sliver
|
name=Bonesplitter Sliver
|
||||||
mana={3}{R}
|
mana={3}{R}
|
||||||
|
|||||||
@@ -109,6 +109,19 @@ text=Flash Flying When Bogardan Hellkite comes into play, it deals 5 damage divi
|
|||||||
rarity=R
|
rarity=R
|
||||||
[/card]
|
[/card]
|
||||||
[card]
|
[card]
|
||||||
|
id=108901
|
||||||
|
name=Bogardan Rager
|
||||||
|
mana={5}{R}
|
||||||
|
type=Creature
|
||||||
|
subtype=Elemental
|
||||||
|
power=3
|
||||||
|
toughness=4
|
||||||
|
text=Flash (You may play this spell any time you could play an instant.) When Bogardan Rager comes into play, target creature gets +4/+0 until end of turn.
|
||||||
|
abilities=flash
|
||||||
|
auto=4/0 target(creature)
|
||||||
|
rarity=C
|
||||||
|
[/card]
|
||||||
|
[card]
|
||||||
id=118895
|
id=118895
|
||||||
name=Brine Elemental
|
name=Brine Elemental
|
||||||
mana={4}{U}{U}
|
mana={4}{U}{U}
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ dross_harvester.txt
|
|||||||
elvish_piper.txt
|
elvish_piper.txt
|
||||||
elvish_promenade.txt
|
elvish_promenade.txt
|
||||||
emblem_of_the_warmind.txt
|
emblem_of_the_warmind.txt
|
||||||
|
flagstones.txt
|
||||||
farhaven_elf.txt
|
farhaven_elf.txt
|
||||||
fastbond.txt
|
fastbond.txt
|
||||||
fastbond2.txt
|
fastbond2.txt
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class WEvent;
|
|||||||
|
|
||||||
class ActionLayer: public GuiLayer, public JGuiListener{
|
class ActionLayer: public GuiLayer, public JGuiListener{
|
||||||
public:
|
public:
|
||||||
|
vector <ActionElement *> garbage;
|
||||||
Targetable * menuObject;
|
Targetable * menuObject;
|
||||||
SimpleMenu * abilitiesMenu;
|
SimpleMenu * abilitiesMenu;
|
||||||
int stuffHappened;
|
int stuffHappened;
|
||||||
@@ -42,6 +43,8 @@ class ActionLayer: public GuiLayer, public JGuiListener{
|
|||||||
void doReactTo(int menuIndex);
|
void doReactTo(int menuIndex);
|
||||||
TargetChooser * getCurrentTargetChooser();
|
TargetChooser * getCurrentTargetChooser();
|
||||||
MTGAbility * getAbility(int type);
|
MTGAbility * getAbility(int type);
|
||||||
|
int moveToGarbage(ActionElement * e);
|
||||||
|
int cleanGarbage();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -215,9 +215,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~MultiAbility(){
|
~MultiAbility(){
|
||||||
if (!isClone){
|
if (!isClone){
|
||||||
vector<int>::size_type sz = abilities.size();
|
vector<int>::size_type sz = abilities.size();
|
||||||
for (unsigned int i = 0; i < sz; i++){
|
for (size_t i = 0; i < sz; i++){
|
||||||
delete abilities[i];
|
delete abilities[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class TestSuite{
|
|||||||
string files[1024];
|
string files[1024];
|
||||||
int nbfiles;
|
int nbfiles;
|
||||||
int currentfile;
|
int currentfile;
|
||||||
|
int nbFailed, nbTests;
|
||||||
int load(const char * filename);
|
int load(const char * filename);
|
||||||
TestSuite(const char * filename,MTGAllCards* _collection);
|
TestSuite(const char * filename,MTGAllCards* _collection);
|
||||||
void initGame();
|
void initGame();
|
||||||
|
|||||||
@@ -14,6 +14,27 @@ MTGAbility* ActionLayer::getAbility(int type){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ActionLayer::moveToGarbage(ActionElement * e){
|
||||||
|
int i = getIndexOf(e);
|
||||||
|
if (i != -1){
|
||||||
|
e->destroy();
|
||||||
|
mObjects.erase(mObjects.begin()+i);
|
||||||
|
mCount--;
|
||||||
|
garbage.push_back(e);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int ActionLayer::cleanGarbage(){
|
||||||
|
for (size_t i = 0; i < garbage.size(); ++i){
|
||||||
|
delete(garbage[i]);
|
||||||
|
}
|
||||||
|
garbage.clear();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int ActionLayer::reactToClick(ActionElement * ability, MTGCardInstance * card){
|
int ActionLayer::reactToClick(ActionElement * ability, MTGCardInstance * card){
|
||||||
int result = ability->reactToClick(card);
|
int result = ability->reactToClick(card);
|
||||||
if (result) stuffHappened = 1;
|
if (result) stuffHappened = 1;
|
||||||
@@ -72,7 +93,7 @@ void ActionLayer::Update(float dt){
|
|||||||
if (mObjects[i]!= NULL){
|
if (mObjects[i]!= NULL){
|
||||||
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
ActionElement * currentAction = (ActionElement *)mObjects[i];
|
||||||
if (currentAction->testDestroy())
|
if (currentAction->testDestroy())
|
||||||
game->removeObserver(currentAction);
|
game->removeObserver(currentAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int newPhase = game->getCurrentGamePhase();
|
int newPhase = game->getCurrentGamePhase();
|
||||||
@@ -254,4 +275,5 @@ void ActionLayer::ButtonPressed(int controllerid, int controlid){
|
|||||||
|
|
||||||
ActionLayer::~ActionLayer(){
|
ActionLayer::~ActionLayer(){
|
||||||
SAFE_DELETE(abilitiesMenu);
|
SAFE_DELETE(abilitiesMenu);
|
||||||
|
cleanGarbage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ void GameObserver::nextGamePhase(){
|
|||||||
//Auto Hand cleaning, in case the player didn't do it himself
|
//Auto Hand cleaning, in case the player didn't do it himself
|
||||||
while(currentPlayer->game->hand->nb_cards > 7)
|
while(currentPlayer->game->hand->nb_cards > 7)
|
||||||
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
|
currentPlayer->game->putInGraveyard(currentPlayer->game->hand->cards[0]);
|
||||||
|
mLayers->actionLayer()->cleanGarbage(); //clean abilities history for this turn;
|
||||||
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
|
mLayers->stackLayer()->garbageCollect(); //clean stack history for this turn;
|
||||||
mLayers->actionLayer()->Update(0);
|
mLayers->actionLayer()->Update(0);
|
||||||
for (int i=0; i < 2; i++){
|
for (int i=0; i < 2; i++){
|
||||||
@@ -240,13 +241,8 @@ void GameObserver::addObserver(MTGAbility * observer){
|
|||||||
|
|
||||||
|
|
||||||
void GameObserver::removeObserver(ActionElement * observer){
|
void GameObserver::removeObserver(ActionElement * observer){
|
||||||
if (observer)
|
if (observer)mLayers->actionLayer()->moveToGarbage(observer);
|
||||||
{
|
|
||||||
if (mLayers->actionLayer()->getIndexOf(observer) != -1){
|
|
||||||
observer->destroy();
|
|
||||||
mLayers->actionLayer()->Remove(observer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{} //TODO log error
|
{} //TODO log error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,31 +181,22 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
|
|||||||
|
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
void GameStateDuel::loadTestSuitePlayers(){
|
void GameStateDuel::loadTestSuitePlayers(){
|
||||||
OutputDebugString ("loading suite 1\n");
|
|
||||||
if (!testSuite) return;
|
if (!testSuite) return;
|
||||||
for (int i = 0; i < 2; i++){
|
for (int i = 0; i < 2; i++){
|
||||||
SAFE_DELETE(mPlayers[i]);
|
SAFE_DELETE(mPlayers[i]);
|
||||||
SAFE_DELETE(deck[i]);
|
SAFE_DELETE(deck[i]);
|
||||||
mPlayers[i] = NEW TestSuiteAI(testSuite, i);
|
mPlayers[i] = NEW TestSuiteAI(testSuite, i);
|
||||||
OutputDebugString ("loading suite 2\n");
|
|
||||||
deck[i] = mPlayers[i]->game;
|
deck[i] = mPlayers[i]->game;
|
||||||
}
|
}
|
||||||
mParent->gameType = testSuite->gameType;
|
mParent->gameType = testSuite->gameType;
|
||||||
if (game) delete game;
|
SAFE_DELETE(game);
|
||||||
game = NULL;
|
GameObserver::Init(mPlayers, 2);
|
||||||
if (!game){
|
game = GameObserver::GetInstance();
|
||||||
GameObserver::Init(mPlayers, 2);
|
game->startGame(0,0);
|
||||||
OutputDebugString ("loading suite 3\n");
|
if (mParent->gameType == GAME_TYPE_MOMIR){
|
||||||
game = GameObserver::GetInstance();
|
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
||||||
OutputDebugString ("loading suite 4\n");
|
for (int i = 0; i < 2; i++){
|
||||||
game->startGame(0,0);
|
game->players[i]->life+=4;
|
||||||
OutputDebugString ("loading suite 5\n");
|
|
||||||
|
|
||||||
if (mParent->gameType == GAME_TYPE_MOMIR){
|
|
||||||
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
|
|
||||||
for (int i = 0; i < 2; i++){
|
|
||||||
game->players[i]->life+=4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,6 +396,21 @@ void GameStateDuel::Render()
|
|||||||
JRenderer * r = JRenderer::GetInstance();
|
JRenderer * r = JRenderer::GetInstance();
|
||||||
r->ClearScreen(ARGB(200,0,0,0));
|
r->ClearScreen(ARGB(200,0,0,0));
|
||||||
credits->Render();
|
credits->Render();
|
||||||
|
#ifdef TESTSUITE
|
||||||
|
if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
|
||||||
|
r->ClearScreen(ARGB(255,0,0,0));
|
||||||
|
char buf[4096];
|
||||||
|
int nbFailed = testSuite->nbFailed;
|
||||||
|
int nbTests = testSuite->nbTests;
|
||||||
|
if (!nbFailed){
|
||||||
|
sprintf(buf, "All %i tests successful!", nbTests);
|
||||||
|
}else{
|
||||||
|
sprintf(buf, "%i tests out of %i FAILED!", nbFailed, nbTests);
|
||||||
|
}
|
||||||
|
|
||||||
|
mFont->DrawString(buf,0,SCREEN_HEIGHT/2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DUEL_STATE_ERROR:
|
case DUEL_STATE_ERROR:
|
||||||
|
|||||||
@@ -379,7 +379,11 @@ int TestSuite::assertGame(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error) return 0;
|
nbTests++;
|
||||||
|
if (error) {
|
||||||
|
nbFailed++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Log("<span class=\"success\">==Test Succesful !==</span>");
|
Log("<span class=\"success\">==Test Succesful !==</span>");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -391,6 +395,8 @@ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
|
|||||||
std::string s;
|
std::string s;
|
||||||
nbfiles = 0;
|
nbfiles = 0;
|
||||||
currentfile = 0;
|
currentfile = 0;
|
||||||
|
nbFailed = 0;
|
||||||
|
nbTests = 0;
|
||||||
int comment = 0;
|
int comment = 0;
|
||||||
if(file){
|
if(file){
|
||||||
while(std::getline(file,s)){
|
while(std::getline(file,s)){
|
||||||
|
|||||||
Reference in New Issue
Block a user