Erwan
- replaced variables canPutLandsIntoPlay and landsPlayerCanStillPlay with a PlayRestrictions class.
- Added seenThisTurn(TargetChooser * tc) in MTGGameZones, which allows to count how many cards matching a targetChooser have been in a given zone in the current turn. With minor work, this can probably be reused by the ability parser for some cards that need to count how many **** where played or put on the stack during a turn.
-- for example player->game->stack->seenThisTurn([put a TypeTargetChooser("creature") here]) would give you the number of creature spells cast by the player this turn.
- This is the first step of a refactor that aims at removing all the adhoc variables for "cant cast". I plan to get rid of the following variables in Player.h (and the associated code, which hopefully will become smaller):
int castedspellsthisturn;
bool onlyonecast;
int castcount;
bool nocreatureinstant;
bool nospellinstant;
bool onlyoneinstant;
bool castrestrictedcreature;
bool castrestrictedspell;
bool onlyoneboth;
bool bothrestrictedspell;
bool bothrestrictedcreature;
They will be replaced by the PlayRestrictions system, and hopefully I'll have time to update the parser to make this more generic as well.
My initial goal with this change was to move the limit of 1 land per turn outside of the code, and make it an external rule in Rules/mtg.txt. I have yet to do it.
This commit is contained in:
@@ -100,13 +100,15 @@ int AIMomirPlayer::computeActions()
|
||||
ManaCost * potentialMana = getPotentialMana();
|
||||
int converted = potentialMana->getConvertedCost();
|
||||
SAFE_DELETE(potentialMana);
|
||||
if (canPutLandsIntoPlay && (converted < 8 || game->hand->nb_cards > 1))
|
||||
|
||||
if (converted < 8 || game->hand->nb_cards > 1)
|
||||
{
|
||||
//Attempt to put land into play
|
||||
cd.init();
|
||||
cd.setColor(Constants::MTG_COLOR_LAND);
|
||||
card = cd.match(game->hand);
|
||||
if (card)
|
||||
int canPutLandsIntoPlay = game->playRestrictions->canPutIntoZone(card, game->inPlay);
|
||||
if (card && (canPutLandsIntoPlay == PlayRestriction::CAN_PLAY))
|
||||
{
|
||||
MTGAbility * putIntoPlay = g->mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY);
|
||||
AIAction * a = NEW AIAction(putIntoPlay, card); //TODO putinplay action
|
||||
|
||||
@@ -1221,7 +1221,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
|
||||
continue;
|
||||
if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell )
|
||||
continue;
|
||||
if (card->hasType(Subtypes::TYPE_LAND) && !this->canPutLandsIntoPlay)
|
||||
if (card->hasType(Subtypes::TYPE_LAND) && (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY))
|
||||
continue;
|
||||
if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name))
|
||||
continue;
|
||||
|
||||
@@ -1456,13 +1456,13 @@ AACloner::~AACloner()
|
||||
}
|
||||
|
||||
// More Land - allow more lands to be played on a turn
|
||||
AAMoreLandPlz::AAMoreLandPlz(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, WParsedInt * _additional,
|
||||
int _tap, int who) :
|
||||
ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), additional(_additional)
|
||||
AMoreLandPlzUEOT::AMoreLandPlzUEOT(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * _additional, int who) :
|
||||
InstantAbilityTP(_id, card, _target, who), additional(_additional)
|
||||
{
|
||||
landsRestriction = NULL;
|
||||
}
|
||||
|
||||
int AAMoreLandPlz::resolve()
|
||||
int AMoreLandPlzUEOT::addToGame()
|
||||
{
|
||||
Targetable * _target = getTarget();
|
||||
Player * player;
|
||||
@@ -1476,25 +1476,38 @@ int AAMoreLandPlz::resolve()
|
||||
{
|
||||
player = (Player *) _target;
|
||||
}
|
||||
player->landsPlayerCanStillPlay += additional->getValue();
|
||||
landsRestriction = (MaxPerTurnRestriction *) (player->game->playRestrictions->getRestrictionById(PlayRestriction::LANDS_RULE_ID));
|
||||
if(landsRestriction && landsRestriction->maxPerTurn != MaxPerTurnRestriction::NO_MAX)
|
||||
landsRestriction->maxPerTurn += additional->getValue();
|
||||
return InstantAbility::addToGame();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AMoreLandPlzUEOT::destroy()
|
||||
{
|
||||
if (!landsRestriction)
|
||||
return 0;
|
||||
|
||||
if(landsRestriction && landsRestriction->maxPerTurn != MaxPerTurnRestriction::NO_MAX)
|
||||
landsRestriction->maxPerTurn -= additional->getValue();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char * AAMoreLandPlz::getMenuText()
|
||||
const char * AMoreLandPlzUEOT::getMenuText()
|
||||
{
|
||||
return "Additional Lands";
|
||||
}
|
||||
|
||||
AAMoreLandPlz * AAMoreLandPlz::clone() const
|
||||
AMoreLandPlzUEOT * AMoreLandPlzUEOT::clone() const
|
||||
{
|
||||
AAMoreLandPlz * a = NEW AAMoreLandPlz(*this);
|
||||
AMoreLandPlzUEOT * a = NEW AMoreLandPlzUEOT(*this);
|
||||
a->additional = NEW WParsedInt(*(a->additional));
|
||||
a->isClone = 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
AAMoreLandPlz::~AAMoreLandPlz()
|
||||
AMoreLandPlzUEOT::~AMoreLandPlzUEOT()
|
||||
{
|
||||
SAFE_DELETE(additional);
|
||||
}
|
||||
|
||||
@@ -108,8 +108,6 @@ void GameObserver::nextGamePhase()
|
||||
if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN)
|
||||
{
|
||||
cleanupPhase();
|
||||
currentPlayer->canPutLandsIntoPlay = true;
|
||||
currentPlayer->landsPlayerCanStillPlay = 1;
|
||||
currentPlayer->castedspellsthisturn = 0;
|
||||
currentPlayer->opponent()->castedspellsthisturn = 0;
|
||||
currentPlayer->castcount = 0;
|
||||
@@ -124,9 +122,8 @@ void GameObserver::nextGamePhase()
|
||||
mLayers->actionLayer()->Update(0);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
delete (players[i]->game->garbage);
|
||||
players[i]->game->garbage = NEW MTGGameZone();
|
||||
players[i]->game->garbage->setOwner(players[i]);
|
||||
//Cleanup of each player's gamezones
|
||||
players[i]->game->beforeBeginPhase();
|
||||
}
|
||||
combatStep = BLOCKERS;
|
||||
return nextGamePhase();
|
||||
@@ -377,14 +374,6 @@ void GameObserver::gameStateBasedEffects()
|
||||
//effects or menus actions
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (players[i]->landsPlayerCanStillPlay <= 0)
|
||||
{
|
||||
players[i]->canPutLandsIntoPlay = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
players[i]->canPutLandsIntoPlay = true;
|
||||
}
|
||||
if(players[i]->poisonCount > 0)
|
||||
{
|
||||
players[i]->isPoisoned = true;
|
||||
|
||||
@@ -725,9 +725,6 @@ void GameStateMenu::Render()
|
||||
|
||||
void GameStateMenu::ButtonPressed(int controllerId, int controlId)
|
||||
{
|
||||
int deckId;
|
||||
int result;
|
||||
|
||||
DebugTrace("GameStateMenu: controllerId " << controllerId << " selected");
|
||||
switch (controllerId)
|
||||
{
|
||||
|
||||
@@ -2206,9 +2206,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
||||
Targetable * t = NULL;
|
||||
if (spell)
|
||||
t = spell->getNextTarget();
|
||||
MTGAbility * a = NEW AAMoreLandPlz(id, card, t, NULL, additional, 0, who);
|
||||
a->oneShot = 1;
|
||||
return a;
|
||||
return NEW AMoreLandPlzUEOT(id, card, t, additional, who);
|
||||
}
|
||||
|
||||
//Deplete
|
||||
@@ -4238,7 +4236,7 @@ void InstantAbility::Update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
InstantAbility::InstantAbility(int _id, MTGCardInstance * source, Damageable * _target) :
|
||||
InstantAbility::InstantAbility(int _id, MTGCardInstance * source, Targetable * _target) :
|
||||
MTGAbility(_id, source, _target)
|
||||
{
|
||||
init = 0;
|
||||
@@ -4785,3 +4783,41 @@ Targetable * ActivatedAbilityTP::getTarget()
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InstantAbilityTP::InstantAbilityTP(int id, MTGCardInstance * card, Targetable * _target,int who) :
|
||||
InstantAbility(id, card), who(who)
|
||||
{
|
||||
if (_target)
|
||||
target = _target;
|
||||
}
|
||||
|
||||
//This is the same as Targetable * ActivatedAbilityTP::getTarget(), anyway to move them together?
|
||||
Targetable * InstantAbilityTP::getTarget()
|
||||
{
|
||||
switch (who)
|
||||
{
|
||||
case TargetChooser::TARGET_CONTROLLER:
|
||||
if (target)
|
||||
{
|
||||
switch (target->typeAsTarget())
|
||||
{
|
||||
case TARGET_CARD:
|
||||
return ((MTGCardInstance *) target)->controller();
|
||||
case TARGET_STACKACTION:
|
||||
return ((Interruptible *) target)->source->controller();
|
||||
default:
|
||||
return (Player *) target;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
case TargetChooser::CONTROLLER:
|
||||
return source->controller();
|
||||
case TargetChooser::OPPONENT:
|
||||
return source->controller()->opponent();
|
||||
case TargetChooser::OWNER:
|
||||
return source->owner;
|
||||
default:
|
||||
return target;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -68,10 +68,28 @@ MTGPlayerCards::~MTGPlayerCards()
|
||||
SAFE_DELETE(removedFromGame);
|
||||
SAFE_DELETE(garbage);
|
||||
SAFE_DELETE(temp);
|
||||
SAFE_DELETE(playRestrictions);
|
||||
}
|
||||
|
||||
void MTGPlayerCards::beforeBeginPhase()
|
||||
{
|
||||
delete garbage;
|
||||
garbage = NEW MTGGameZone();
|
||||
garbage->setOwner(this->owner);
|
||||
|
||||
library->beforeBeginPhase();
|
||||
graveyard->beforeBeginPhase();
|
||||
hand->beforeBeginPhase();
|
||||
inPlay->beforeBeginPhase();
|
||||
stack->beforeBeginPhase();
|
||||
removedFromGame->beforeBeginPhase();
|
||||
garbage->beforeBeginPhase();
|
||||
temp->beforeBeginPhase();
|
||||
}
|
||||
|
||||
void MTGPlayerCards::setOwner(Player * player)
|
||||
{
|
||||
this->owner = player;
|
||||
library->setOwner(player);
|
||||
graveyard->setOwner(player);
|
||||
hand->setOwner(player);
|
||||
@@ -241,6 +259,11 @@ void MTGPlayerCards::init()
|
||||
exile = removedFromGame;
|
||||
garbage = NEW MTGGameZone();
|
||||
temp = NEW MTGGameZone();
|
||||
|
||||
//This is a Rule that should ideally be moved as an ability in the game...
|
||||
playRestrictions = NEW PlayRestrictions();
|
||||
TargetChooser * tc = NEW TypeTargetChooser("land");
|
||||
playRestrictions->addRestriction(NEW MaxPerTurnRestriction(PlayRestriction::LANDS_RULE_ID, tc, 1, inPlay));
|
||||
}
|
||||
|
||||
void MTGPlayerCards::showHand()
|
||||
@@ -312,7 +335,7 @@ MTGCardInstance * MTGPlayerCards::putInZone(MTGCardInstance * card, MTGGameZone
|
||||
|
||||
//The "Temp" zone are purely for code purposes, and we don't want the abilities engine to
|
||||
//Trigger when cards move in this zone
|
||||
// Additionally, when they mve "from" this zone,
|
||||
// Additionally, when they move "from" this zone,
|
||||
// we trick the engine into believing that they moved from the zone the card was previously in
|
||||
// See http://code.google.com/p/wagic/issues/detail?id=335
|
||||
{
|
||||
@@ -391,6 +414,11 @@ MTGGameZone::~MTGGameZone()
|
||||
owner = NULL;
|
||||
}
|
||||
|
||||
void MTGGameZone::beforeBeginPhase()
|
||||
{
|
||||
cardsSeenThisTurn.clear();
|
||||
};
|
||||
|
||||
void MTGGameZone::setOwner(Player * player)
|
||||
{
|
||||
for (int i = 0; i < nb_cards; i++)
|
||||
@@ -583,6 +611,22 @@ int MTGGameZone::hasAbility(int ability)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MTGGameZone::seenThisTurn(TargetChooser * tc)
|
||||
{
|
||||
//The following 2 lines modify the passed TargetChooser. Call this function with care :/
|
||||
tc->setAllZones(); // This is to allow targetting cards without caring about the actual zone
|
||||
tc->targetter = NULL;
|
||||
|
||||
int count = 0;
|
||||
for (vector<MTGCardInstance *>::iterator iter = cardsSeenThisTurn.begin(); iter != cardsSeenThisTurn.end(); ++iter)
|
||||
{
|
||||
if (tc->canTarget(*iter))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
void MTGGameZone::cleanupPhase()
|
||||
{
|
||||
for (int i = 0; i < (nb_cards); i++)
|
||||
@@ -599,6 +643,7 @@ void MTGGameZone::addCard(MTGCardInstance * card)
|
||||
if (!card)
|
||||
return;
|
||||
cards.push_back(card);
|
||||
cardsSeenThisTurn.push_back(card);
|
||||
nb_cards++;
|
||||
cardsMap[card] = 1;
|
||||
card->lastController = this->owner;
|
||||
|
||||
@@ -35,11 +35,14 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if(!allowedToCast(card,player))
|
||||
return 0;
|
||||
if(!allowedToCast(card,player))
|
||||
return 0;
|
||||
|
||||
if (card->hasType("land"))
|
||||
{
|
||||
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay
|
||||
if (currentPlayer->game->playRestrictions->canPutIntoZone(card, currentPlayer->game->inPlay) == PlayRestriction::CANT_PLAY)
|
||||
return 0;
|
||||
if (player == currentPlayer
|
||||
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
|
||||
)
|
||||
{
|
||||
@@ -58,7 +61,7 @@ if(!allowedToCast(card,player))
|
||||
#ifdef WIN32
|
||||
cost->Dump();
|
||||
#endif
|
||||
if (player->castrestrictedspell && !card->hasType("land"))
|
||||
if (player->castrestrictedspell)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -154,7 +157,6 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card)
|
||||
spell->resolve();
|
||||
delete spellCost;
|
||||
delete spell;
|
||||
player->landsPlayerCanStillPlay--;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -259,7 +261,9 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
|
||||
|
||||
if (card->hasType("land"))
|
||||
{
|
||||
if (player == currentPlayer && currentPlayer->canPutLandsIntoPlay
|
||||
if (currentPlayer->game->playRestrictions->canPutIntoZone(card, currentPlayer->game->inPlay) == PlayRestriction::CANT_PLAY)
|
||||
return 0;
|
||||
if (player == currentPlayer
|
||||
&& (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN
|
||||
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
|
||||
)
|
||||
@@ -358,7 +362,6 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter
|
||||
copy->alternateCostPaid[alternateCostType] = 1;
|
||||
spell->resolve();
|
||||
SAFE_DELETE(spell);
|
||||
player->landsPlayerCanStillPlay--;
|
||||
game->mLayers->stackLayer()->addSpell(copy, NULL, NULL, alternateCostType, 1);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include "playRestrictions.h"
|
||||
#include "TargetChooser.h"
|
||||
#include "MTGCardInstance.h"
|
||||
|
||||
|
||||
PlayRestriction::PlayRestriction(unsigned int id, TargetChooser * tc): id(id), tc(tc)
|
||||
{
|
||||
tc->setAllZones(); // This is to allow targetting cards without caring about the actual zone
|
||||
tc->targetter = NULL;
|
||||
};
|
||||
|
||||
PlayRestriction::~PlayRestriction()
|
||||
{
|
||||
SAFE_DELETE(tc);
|
||||
};
|
||||
|
||||
|
||||
MaxPerTurnRestriction::MaxPerTurnRestriction(unsigned int id, TargetChooser * tc, int maxPerTurn, MTGGameZone * zone):
|
||||
PlayRestriction(id, tc), maxPerTurn(maxPerTurn), zone(zone)
|
||||
{}
|
||||
|
||||
int MaxPerTurnRestriction::canPutIntoZone(MTGCardInstance * card, MTGGameZone * destZone)
|
||||
{
|
||||
if (destZone != zone)
|
||||
return PlayRestriction::NO_OPINION;
|
||||
|
||||
if (!tc->canTarget(card))
|
||||
return PlayRestriction::NO_OPINION;
|
||||
|
||||
if (maxPerTurn == NO_MAX) return PlayRestriction::CAN_PLAY;
|
||||
|
||||
if (zone->seenThisTurn(tc) >= maxPerTurn)
|
||||
return PlayRestriction::CANT_PLAY;
|
||||
|
||||
return PlayRestriction::CAN_PLAY;
|
||||
};
|
||||
|
||||
|
||||
PlayRestriction * PlayRestrictions::getRestrictionById(unsigned int id)
|
||||
{
|
||||
if (id == PlayRestriction::UNDEF_ID)
|
||||
return NULL; // do not request Restrictions that don't have an id, there are several of them
|
||||
|
||||
for (vector<PlayRestriction *>::iterator iter = restrictions.begin(); iter != restrictions.end(); ++iter)
|
||||
{
|
||||
if ((*iter)->id == id)
|
||||
return *iter;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void PlayRestrictions::addRestriction(PlayRestriction * restriction)
|
||||
{
|
||||
//TODO control that the id does not already exist?
|
||||
restrictions.push_back(restriction);
|
||||
|
||||
}
|
||||
|
||||
void PlayRestrictions::removeRestriction(PlayRestriction * restriction)
|
||||
{
|
||||
for (vector<PlayRestriction *>::iterator iter = restrictions.begin(); iter != restrictions.end(); ++iter)
|
||||
{
|
||||
if(*iter == restriction)
|
||||
{
|
||||
restrictions.erase(iter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int PlayRestrictions::canPutIntoZone(MTGCardInstance * card, MTGGameZone * destZone)
|
||||
{
|
||||
if (!card)
|
||||
return PlayRestriction::CANT_PLAY;
|
||||
|
||||
for (vector<PlayRestriction *>::iterator iter = restrictions.begin(); iter != restrictions.end(); ++iter)
|
||||
{
|
||||
if ((*iter)->canPutIntoZone(card, destZone) == PlayRestriction::CANT_PLAY)
|
||||
return PlayRestriction::CANT_PLAY;
|
||||
}
|
||||
|
||||
return PlayRestriction::CAN_PLAY;
|
||||
}
|
||||
|
||||
PlayRestrictions::~PlayRestrictions()
|
||||
{
|
||||
for (vector<PlayRestriction *>::iterator iter = restrictions.begin(); iter != restrictions.end(); ++iter)
|
||||
{
|
||||
SAFE_DELETE(*iter);
|
||||
}
|
||||
restrictions.clear();
|
||||
}
|
||||
@@ -12,8 +12,6 @@ Damageable(20)
|
||||
deckFile = file;
|
||||
deckFileSmall = fileSmall;
|
||||
manaPool = NEW ManaPool(this);
|
||||
canPutLandsIntoPlay = true;
|
||||
landsPlayerCanStillPlay = 1;
|
||||
nomaxhandsize = false;
|
||||
castedspellsthisturn = 0;
|
||||
castrestrictedspell = false;
|
||||
|
||||
@@ -421,6 +421,7 @@ void TestSuite::initGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
zone->cardsSeenThisTurn.clear(); //don't consider those cards as having moved in this area during this turn
|
||||
}
|
||||
}
|
||||
DebugTrace("TESTUITE Init Game Done !");
|
||||
|
||||
Reference in New Issue
Block a user