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:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user