Ran VS formatting on this file, as the indentation was all over the place. No actual code changes here.

This commit is contained in:
wrenczes@gmail.com
2010-12-01 08:54:45 +00:00
parent 65e38b0694
commit af6c7bd1f0
+190 -190
View File
@@ -1,6 +1,6 @@
/*
The Action Stack contains all information for Game Events that can be interrupted (Interruptible)
*/
The Action Stack contains all information for Game Events that can be interrupted (Interruptible)
*/
#include "PrecompiledHeader.h"
#include "ActionStack.h"
@@ -18,8 +18,8 @@
#include <typeinfo>
/*
NextGamePhase requested by user
*/
NextGamePhase requested by user
*/
int NextGamePhase::resolve()
{
@@ -55,7 +55,7 @@ void NextGamePhase::Render()
}
NextGamePhase::NextGamePhase(int id) :
Interruptible(id)
Interruptible(id)
{
mHeight = 40;
type = ACTION_NEXTGAMEPHASE;
@@ -70,11 +70,11 @@ ostream& NextGamePhase::toString(ostream& out) const
const string Interruptible::getDisplayName() const
{
return typeid(*this).name();
}
}
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)
{
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
mFont->SetColor(ARGB(255,255,255,255));
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
@@ -114,15 +114,15 @@ const string Interruptible::getDisplayName() const
{
mFont->DrawString(_(alt2).c_str(), x + 120, y);
}
}
}
/* Ability */
int StackAbility::resolve()
{
/* Ability */
int StackAbility::resolve()
{
return (ability->resolve());
}
void StackAbility::Render()
{
}
void StackAbility::Render()
{
string action = ability->getMenuText();
MTGCardInstance * source = ability->source;
string alt1 = source->getName();
@@ -153,67 +153,67 @@ const string Interruptible::getDisplayName() const
}
Interruptible::Render(source, quad, alt1, alt2, action);
}
StackAbility::StackAbility(int id, MTGAbility * _ability) :
Interruptible(id), ability(_ability)
{
}
StackAbility::StackAbility(int id, MTGAbility * _ability) :
Interruptible(id), ability(_ability)
{
type = ACTION_ABILITY;
}
}
ostream& StackAbility::toString(ostream& out) const
{
ostream& StackAbility::toString(ostream& out) const
{
out << "StackAbility ::: ability : " << ability;
return out;
}
}
const string StackAbility::getDisplayName() const
{
const string StackAbility::getDisplayName() const
{
std::ostringstream stream;
stream << "StackAbility. (Source: " << ability->source->getDisplayName() << ")";
return stream.str();
}
}
/* Spell Cast */
/* Spell Cast */
Spell::Spell(MTGCardInstance * _source) :
Interruptible(0)
{
Spell::Spell(MTGCardInstance * _source) :
Interruptible(0)
{
source = _source;
mHeight = 40;
type = ACTION_SPELL;
cost = NEW ManaCost();
tc = NULL;
from = _source->getCurrentZone();
}
}
Spell::Spell(int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost, int payResult) :
Interruptible(id), tc(tc), cost(_cost), payResult(payResult)
{
Spell::Spell(int id, MTGCardInstance * _source, TargetChooser * tc, ManaCost * _cost, int payResult) :
Interruptible(id), tc(tc), cost(_cost), payResult(payResult)
{
source = _source;
mHeight = 40;
type = ACTION_SPELL;
from = _source->getCurrentZone();
}
}
int Spell::computeX(MTGCardInstance * card)
{
int Spell::computeX(MTGCardInstance * card)
{
ManaCost * c = cost->Diff(card->getManaCost());
int x = c->getCost(Constants::MTG_NB_COLORS);
delete c;
return x;
}
}
int Spell::computeXX(MTGCardInstance * card)
{
int Spell::computeXX(MTGCardInstance * card)
{
ManaCost * c = cost->Diff(card->getManaCost());
int xx = c->getCost(Constants::MTG_NB_COLORS) / 2;
delete c;
return xx;
}
}
bool Spell::FullfilledAlternateCost(const int &costType)
{
bool Spell::FullfilledAlternateCost(const int &costType)
{
bool hasFullfilledAlternateCost = false;
switch (costType)
@@ -236,20 +236,20 @@ const string Interruptible::getDisplayName() const
}
return hasFullfilledAlternateCost;
}
}
const string Spell::getDisplayName() const
{
const string Spell::getDisplayName() const
{
return source->getName();
}
Spell::~Spell()
{
}
Spell::~Spell()
{
SAFE_DELETE(cost);
SAFE_DELETE(tc);
}
}
int Spell::resolve()
{
int Spell::resolve()
{
GameObserver * game = GameObserver::GetInstance();
if (!source->hasType("instant") && !source->hasType("sorcery"))
{
@@ -271,60 +271,60 @@ const string Interruptible::getDisplayName() const
AbilityFactory af;
af.addAbilities(game->mLayers->actionLayer()->getMaxId(), this);
return 1;
}
}
MTGCardInstance * Spell::getNextCardTarget(MTGCardInstance * previous)
{
MTGCardInstance * Spell::getNextCardTarget(MTGCardInstance * previous)
{
if (!tc)
return NULL;
return tc->getNextCardTarget(previous);
}
Player * Spell::getNextPlayerTarget(Player * previous)
{
}
Player * Spell::getNextPlayerTarget(Player * previous)
{
if (!tc)
return NULL;
return tc->getNextPlayerTarget(previous);
}
Damageable * Spell::getNextDamageableTarget(Damageable * previous)
{
}
Damageable * Spell::getNextDamageableTarget(Damageable * previous)
{
if (!tc)
return NULL;
return tc->getNextDamageableTarget(previous);
}
Interruptible * Spell::getNextInterruptible(Interruptible * previous, int type)
{
}
Interruptible * Spell::getNextInterruptible(Interruptible * previous, int type)
{
if (!tc)
return NULL;
return tc->getNextInterruptible(previous, type);
}
Spell * Spell::getNextSpellTarget(Spell * previous)
{
}
Spell * Spell::getNextSpellTarget(Spell * previous)
{
if (!tc)
return NULL;
return tc->getNextSpellTarget(previous);
}
Damage * Spell::getNextDamageTarget(Damage * previous)
{
}
Damage * Spell::getNextDamageTarget(Damage * previous)
{
if (!tc)
return NULL;
return tc->getNextDamageTarget(previous);
}
Targetable * Spell::getNextTarget(Targetable * previous, int type)
{
}
Targetable * Spell::getNextTarget(Targetable * previous, int type)
{
if (!tc)
return NULL;
return tc->getNextTarget(previous, type);
}
}
int Spell::getNbTargets()
{
int Spell::getNbTargets()
{
if (!tc)
return 0;
return tc->cursor;
}
}
void Spell::Render()
{
void Spell::Render()
{
string action = source->getName();
string alt1 = "";
@@ -340,26 +340,26 @@ const string Interruptible::getDisplayName() const
}
}
Interruptible::Render(source, quad, alt1, alt2, action, true);
}
}
ostream& Spell::toString(ostream& out) const
{
ostream& Spell::toString(ostream& out) const
{
out << "Spell ::: cost : " << cost;
return out;
}
}
/* Put a card in graveyard */
/* Put a card in graveyard */
PutInGraveyard::PutInGraveyard(int id, MTGCardInstance * _card) :
Interruptible(id)
{
PutInGraveyard::PutInGraveyard(int id, MTGCardInstance * _card) :
Interruptible(id)
{
card = _card;
removeFromGame = 0;
type = ACTION_PUTINGRAVEYARD;
}
}
int PutInGraveyard::resolve()
{
int PutInGraveyard::resolve()
{
GameObserver * g = GameObserver::GetInstance();
MTGGameZone * zone = card->getCurrentZone();
if (zone == g->players[0]->game->inPlay || zone == g->players[1]->game->inPlay)
@@ -368,10 +368,10 @@ const string Interruptible::getDisplayName() const
return 1;
}
return 0;
}
}
void PutInGraveyard::Render()
{
void PutInGraveyard::Render()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
@@ -395,31 +395,31 @@ const string Interruptible::getDisplayName() const
{
mFont->DrawString(_(card->name).c_str(), x, y - 15);
}
}
}
ostream& PutInGraveyard::toString(ostream& out) const
{
ostream& PutInGraveyard::toString(ostream& out) const
{
out << "PutInGraveyard ::: removeFromGame : " << removeFromGame;
return out;
}
}
/* Draw a Card */
DrawAction::DrawAction(int id, Player * _player, int _nbcards) :
Interruptible(id), nbcards(_nbcards), player(_player)
{
}
/* Draw a Card */
DrawAction::DrawAction(int id, Player * _player, int _nbcards) :
Interruptible(id), nbcards(_nbcards), player(_player)
{
}
int DrawAction::resolve()
{
int DrawAction::resolve()
{
for (int i = 0; i < nbcards; i++)
{
player->game->drawFromLibrary();
}
return 1;
}
}
void DrawAction::Render()
{
void DrawAction::Render()
{
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
mFont->SetBase(0);
mFont->SetScale(DEFAULT_MAIN_FONT_SCALE);
@@ -429,51 +429,51 @@ const string Interruptible::getDisplayName() const
playerId = 2;
sprintf(buffer, _("Player %i draws %i card").c_str(), playerId, nbcards);
mFont->DrawString(buffer, x + 20, y, JGETEXT_LEFT);
}
}
ostream& DrawAction::toString(ostream& out) const
{
ostream& DrawAction::toString(ostream& out) const
{
out << "DrawAction ::: nbcards : " << nbcards << " ; player : " << player;
return out;
}
}
/* The Action Stack itself */
int ActionStack::addPutInGraveyard(MTGCardInstance * card)
{
/* The Action Stack itself */
int ActionStack::addPutInGraveyard(MTGCardInstance * card)
{
PutInGraveyard * death = NEW PutInGraveyard(mCount, card);
addAction(death);
return 1;
}
}
int ActionStack::addAbility(MTGAbility * ability)
{
int ActionStack::addAbility(MTGAbility * ability)
{
StackAbility * stackAbility = NEW StackAbility(mCount, ability);
int result = addAction(stackAbility);
if (!game->players[0]->isAI() && ability->source->controller() == game->players[0] && 0
== options[Options::INTERRUPTMYABILITIES].number)
interruptDecision[0] = DONT_INTERRUPT;
return result;
}
}
int ActionStack::addDraw(Player * player, int nb_cards)
{
int ActionStack::addDraw(Player * player, int nb_cards)
{
DrawAction * draw = NEW DrawAction(mCount, player, nb_cards);
addAction(draw);
GameObserver *g = GameObserver::GetInstance();
WEvent * e = NEW WEventcardDraw(player, nb_cards);
g->receiveEvent(e);
return 1;
}
}
int ActionStack::addDamage(MTGCardInstance * _source, Damageable * _target, int _damage)
{
int ActionStack::addDamage(MTGCardInstance * _source, Damageable * _target, int _damage)
{
Damage * damage = NEW Damage(_source, _target, _damage);
addAction(damage);
return 1;
}
}
int ActionStack::AddNextGamePhase()
{
int ActionStack::AddNextGamePhase()
{
if (getNext(NULL, NOT_RESOLVED))
return 0;
NextGamePhase * next = NEW NextGamePhase(mCount);
@@ -486,19 +486,19 @@ const string Interruptible::getDisplayName() const
}
interruptDecision[playerId] = 1;
return 1;
}
}
int ActionStack::AddNextCombatStep()
{
int ActionStack::AddNextCombatStep()
{
if (getNext(NULL, NOT_RESOLVED))
return 0;
NextGamePhase * next = NEW NextGamePhase(mCount);
addAction(next);
return 1;
}
}
int ActionStack::setIsInterrupting(Player * player)
{
int ActionStack::setIsInterrupting(Player * player)
{
if (player == game->players[0])
{
interruptDecision[0] = -1;
@@ -510,10 +510,10 @@ const string Interruptible::getDisplayName() const
game->isInterrupting = player;
askIfWishesToInterrupt = NULL;
return 1;
}
}
int ActionStack::addAction(Interruptible * action)
{
int ActionStack::addAction(Interruptible * action)
{
for (int i = 0; i < 2; i++)
{
interruptDecision[i] = 0;
@@ -522,11 +522,11 @@ const string Interruptible::getDisplayName() const
DebugTrace("Action added to stack: " << action->getDisplayName());
return 1;
}
}
Spell * ActionStack::addSpell(MTGCardInstance * _source, TargetChooser * tc, ManaCost * mana, int payResult,
Spell * ActionStack::addSpell(MTGCardInstance * _source, TargetChooser * tc, ManaCost * mana, int payResult,
int storm)
{
{
DebugTrace("ACTIONSTACK Add spell");
if (storm > 0)
{
@@ -542,20 +542,20 @@ const string Interruptible::getDisplayName() const
== options[Options::INTERRUPTMYSPELLS].number)
interruptDecision[0] = DONT_INTERRUPT;
return spell;
}
}
Interruptible * ActionStack::getAt(int id)
{
Interruptible * ActionStack::getAt(int id)
{
if (id < 0)
id = mCount + id;
if (id > mCount - 1)
return NULL;
return (Interruptible *) mObjects[id];
}
}
ActionStack::ActionStack(GameObserver* game) :
game(game)
{
ActionStack::ActionStack(GameObserver* game) :
game(game)
{
for (int i = 0; i < 2; i++)
interruptDecision[i] = 0;
askIfWishesToInterrupt = NULL;
@@ -564,10 +564,10 @@ const string Interruptible::getDisplayName() const
mode = ACTIONSTACK_STANDARD;
checked = 0;
}
}
int ActionStack::has(MTGAbility * ability)
{
int ActionStack::has(MTGAbility * ability)
{
for (int i = 0; i < mCount; i++)
{
if (((Interruptible *) mObjects[i])->type == ACTION_ABILITY)
@@ -578,20 +578,20 @@ const string Interruptible::getDisplayName() const
}
}
return 0;
}
}
int ActionStack::has(Interruptible * action)
{
int ActionStack::has(Interruptible * action)
{
for (int i = 0; i < mCount; i++)
{
if (mObjects[i] == action)
return 1;
}
return 0;
}
}
int ActionStack::resolve()
{
int ActionStack::resolve()
{
Interruptible * action = getLatest(NOT_RESOLVED);
if (!action)
@@ -627,18 +627,18 @@ const string Interruptible::getDisplayName() const
return 1;
}
}
Interruptible * ActionStack::getPrevious(Interruptible * next, int type, int state, int display)
{
Interruptible * ActionStack::getPrevious(Interruptible * next, int type, int state, int display)
{
int n = getPreviousIndex(next, type, state, display);
if (n == -1)
return NULL;
return ((Interruptible *) mObjects[n]);
}
}
int ActionStack::getPreviousIndex(Interruptible * next, int type, int state, int display)
{
int ActionStack::getPreviousIndex(Interruptible * next, int type, int state, int display)
{
int found = 0;
if (!next)
found = 1;
@@ -656,10 +656,10 @@ const string Interruptible::getDisplayName() const
if (!found)
return getPreviousIndex(NULL, type, state, display);
return -1;
}
}
int ActionStack::count(int type, int state, int display)
{
int ActionStack::count(int type, int state, int display)
{
int result = 0;
for (int i = 0; i < mCount; i++)
{
@@ -671,18 +671,18 @@ const string Interruptible::getDisplayName() const
}
}
return result;
}
}
Interruptible * ActionStack::getNext(Interruptible * previous, int type, int state, int display)
{
Interruptible * ActionStack::getNext(Interruptible * previous, int type, int state, int display)
{
int n = getNextIndex(previous, type, state, display);
if (n == -1)
return NULL;
return ((Interruptible *) mObjects[n]);
}
}
int ActionStack::getNextIndex(Interruptible * previous, int type, int state, int display)
{
int ActionStack::getNextIndex(Interruptible * previous, int type, int state, int display)
{
int found = 0;
if (!previous)
found = 1;
@@ -700,10 +700,10 @@ const string Interruptible::getDisplayName() const
if (!found)
return getNextIndex(NULL, type, state, display);
return -1;
}
}
Interruptible * ActionStack::getLatest(int state)
{
Interruptible * ActionStack::getLatest(int state)
{
for (int i = mCount - 1; i >= 0; i--)
{
Interruptible * action = ((Interruptible *) mObjects[i]);
@@ -711,10 +711,10 @@ const string Interruptible::getDisplayName() const
return action;
}
return NULL;
}
}
int ActionStack::receiveEventPlus(WEvent * event)
{
int ActionStack::receiveEventPlus(WEvent * event)
{
int result = 0;
for (int i = 0; i < mCount; ++i)
{
@@ -722,10 +722,10 @@ const string Interruptible::getDisplayName() const
result += current->receiveEvent(event);
}
return result;
}
}
void ActionStack::Update(float dt)
{
void ActionStack::Update(float dt)
{
askIfWishesToInterrupt = NULL;
//modal = 0;
GameObserver * game = GameObserver::GetInstance();
@@ -827,10 +827,10 @@ const string Interruptible::getDisplayName() const
cancelInterruptOffer();
}
}
}
}
void ActionStack::cancelInterruptOffer(int cancelMode)
{
void ActionStack::cancelInterruptOffer(int cancelMode)
{
if (game->isInterrupting == game->players[0])
{
interruptDecision[0] = cancelMode;
@@ -842,10 +842,10 @@ const string Interruptible::getDisplayName() const
askIfWishesToInterrupt = NULL;
game->isInterrupting = NULL;
timer = -1;
}
}
void ActionStack::endOfInterruption()
{
void ActionStack::endOfInterruption()
{
if (game->isInterrupting == game->players[0])
{
interruptDecision[0] = 0;
@@ -855,10 +855,10 @@ const string Interruptible::getDisplayName() const
interruptDecision[1] = 0;
}
game->isInterrupting = NULL;
}
}
bool ActionStack::CheckUserInput(JButton key)
{
bool ActionStack::CheckUserInput(JButton key)
{
JButton trigger = (options[Options::REVERSETRIGGERS].number ? JGE_BTN_NEXT : JGE_BTN_PREV);
if (mode == ACTIONSTACK_STANDARD)
{
@@ -903,7 +903,7 @@ const string Interruptible::getDisplayName() const
{
mCurr = n;
mObjects[mCurr]->Entering();
DebugTrace ("ACTIONSTACK UP TO mCurr = " << mCurr);
DebugTrace ("ACTIONSTACK UP TO mCurr = " << mCurr);
}
}
return true;
@@ -939,9 +939,9 @@ DebugTrace ("ACTIONSTACK UP TO mCurr = " << m
}
}
return false;
}
}
//Cleans history of last turn
//Cleans history of last turn
int ActionStack::garbageCollect()
{
std::vector<JGuiObject *>::iterator iter = mObjects.begin();