- 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:
wagic.the.homebrew@gmail.com
2011-02-12 16:31:07 +00:00
parent 2690a3f9a0
commit 60017a6652
20 changed files with 366 additions and 76 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS)) DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache) RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)
+1
View File
@@ -36,6 +36,7 @@ generic/hybrid_mana_3.txt
generic/indestructible.txt generic/indestructible.txt
generic/kicker.txt generic/kicker.txt
generic/kicker2.txt generic/kicker2.txt
generic/lands_max_per_turn.txt
generic/landwalk.txt generic/landwalk.txt
generic/legendary.txt generic/legendary.txt
generic/level_up.txt generic/level_up.txt
@@ -0,0 +1,16 @@
#Tests that more than 1 land cannot be played per turn
[INIT]
FIRSTMAIN
[PLAYER1]
hand:swamp,plains
[PLAYER2]
[DO]
swamp
plains
[ASSERT]
FIRSTMAIN
[PLAYER1]
inplay:swamp
hand:plains
[PLAYER2]
[END]
+37 -27
View File
@@ -1281,18 +1281,18 @@ public:
}; };
//lands, allows to play more land during a turn: //lands, allows to play more land during a turn:
class AMoreLandPlzUEOT: public InstantAbilityTP
class AAMoreLandPlz: public ActivatedAbilityTP
{ {
public: public:
WParsedInt *additional; WParsedInt *additional;
MaxPerTurnRestriction * landsRestriction;
AAMoreLandPlz(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, WParsedInt * _additional, int _tap = 0, AMoreLandPlzUEOT(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * _additional, int who = TargetChooser::UNSET);
int who = TargetChooser::UNSET); int addToGame();
int resolve(); int destroy();
const char * getMenuText(); const char * getMenuText();
AAMoreLandPlz * clone() const; AMoreLandPlzUEOT * clone() const;
~AAMoreLandPlz(); ~AMoreLandPlzUEOT();
}; };
@@ -4709,43 +4709,39 @@ public:
class AFastbond: public TriggeredAbility class AFastbond: public TriggeredAbility
{ {
public: public:
int alreadyPlayedALand;
int previous; TargetChooser * counter;
MaxPerTurnRestriction * landsRestriction;
int landsPlayedThisTurn;
AFastbond(int _id, MTGCardInstance * card) : AFastbond(int _id, MTGCardInstance * card) :
TriggeredAbility(_id, card) TriggeredAbility(_id, card)
{ {
alreadyPlayedALand = 0;
if (source->controller()->landsPlayerCanStillPlay == 0)
{
alreadyPlayedALand = 1;
source->controller()->landsPlayerCanStillPlay += 1;
source->controller()->canPutLandsIntoPlay = true;
} counter = NEW TypeTargetChooser("land");
previous = source->controller()->landsPlayerCanStillPlay; landsPlayedThisTurn = source->controller()->game->inPlay->seenThisTurn(counter);
PlayRestrictions * restrictions = source->controller()->game->playRestrictions;
landsRestriction = (MaxPerTurnRestriction *) (restrictions->getRestrictionById(PlayRestriction::LANDS_RULE_ID));
restrictions->removeRestriction(landsRestriction);
} }
void Update(float dt) void Update(float dt)
{ {
if (newPhase != currentPhase && newPhase == Constants::MTG_PHASE_UNTAP) if (newPhase != currentPhase && newPhase == Constants::MTG_PHASE_UNTAP)
{ {
alreadyPlayedALand = 0; landsPlayedThisTurn = 0;
} }
TriggeredAbility::Update(dt); TriggeredAbility::Update(dt);
} }
int trigger() int trigger()
{ {
if (source->controller()->landsPlayerCanStillPlay == 0 && previous >= 1) int landsPlayedThisTurnUpdated = source->controller()->game->inPlay->seenThisTurn(counter);
if (landsPlayedThisTurnUpdated > 1 && landsPlayedThisTurnUpdated > landsPlayedThisTurn)
{ {
previous = 0; landsPlayedThisTurn = landsPlayedThisTurnUpdated;
source->controller()->canPutLandsIntoPlay = true; return 1;
source->controller()->landsPlayerCanStillPlay += 1;
if (alreadyPlayedALand) return 1;
alreadyPlayedALand = 1;
return 0;
} }
previous = source->controller()->landsPlayerCanStillPlay;
return 0; return 0;
} }
@@ -4756,9 +4752,18 @@ public:
return 1; return 1;
} }
int destroy()
{
PlayRestrictions * restrictions = source->controller()->game->playRestrictions;
if(restrictions->getRestrictionById(PlayRestriction::LANDS_RULE_ID))
return 1;
restrictions->addRestriction(landsRestriction);
return 1;
}
virtual ostream& toString(ostream& out) const virtual ostream& toString(ostream& out) const
{ {
out << "AFastbond ::: alreadyPlayedALand : " << alreadyPlayedALand << " ; previous : " << previous << " (";
return TriggeredAbility::toString(out) << ")"; return TriggeredAbility::toString(out) << ")";
} }
AFastbond * clone() const AFastbond * clone() const
@@ -4767,6 +4772,11 @@ public:
a->isClone = 1; a->isClone = 1;
return a; return a;
} }
~AFastbond()
{
delete counter;
}
}; };
//1165 Hypnotic Specter //1165 Hypnotic Specter
+8 -1
View File
@@ -289,7 +289,7 @@ class InstantAbility:public MTGAbility{
virtual void Update(float dt); virtual void Update(float dt);
virtual int testDestroy(); virtual int testDestroy();
InstantAbility(int _id, MTGCardInstance * source); InstantAbility(int _id, MTGCardInstance * source);
InstantAbility(int _id, MTGCardInstance * source,Damageable * _target); InstantAbility(int _id, MTGCardInstance * source,Targetable * _target);
virtual int resolve(){return 0;}; virtual int resolve(){return 0;};
virtual InstantAbility* clone() const = 0; virtual InstantAbility* clone() const = 0;
virtual ostream& toString(ostream& out) const; virtual ostream& toString(ostream& out) const;
@@ -399,6 +399,13 @@ public:
Targetable * getTarget(); Targetable * getTarget();
}; };
class InstantAbilityTP:public InstantAbility{
public:
int who;
InstantAbilityTP(int id, MTGCardInstance * card, Targetable * _target = NULL, int who = TargetChooser::UNSET);
Targetable * getTarget();
};
class AManaProducer: public ActivatedAbilityTP{ class AManaProducer: public ActivatedAbilityTP{
protected: protected:
+13 -3
View File
@@ -6,6 +6,7 @@ using std::map;
#include "MTGDeck.h" #include "MTGDeck.h"
#include "MTGCardInstance.h" #include "MTGCardInstance.h"
#include "playRestrictions.h"
#include "TargetChooser.h" #include "TargetChooser.h"
#define MTG_MAX_PLAYER_CARDS 100 #define MTG_MAX_PLAYER_CARDS 100
@@ -68,9 +69,12 @@ class MTGGameZone {
}; };
Player * owner; Player * owner;
//Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array //Both cards and cardsMap contain the cards of a zone. The vector is used to keep the order, useful for some zones such as the stack, library, etc...
vector<MTGCardInstance *> cards; //[MTG_MAX_PLAYER_CARDS]; vector<MTGCardInstance *> cards;
map<MTGCardInstance *,int> cardsMap; map<MTGCardInstance *,int> cardsMap;
//list of cards that have been through this zone in the current turn
vector<MTGCardInstance *> cardsSeenThisTurn;
int nb_cards; int nb_cards;
MTGGameZone(); MTGGameZone();
~MTGGameZone(); ~MTGGameZone();
@@ -80,6 +84,8 @@ class MTGGameZone {
MTGCardInstance * removeCard(MTGCardInstance * card, int createCopy = 1); MTGCardInstance * removeCard(MTGCardInstance * card, int createCopy = 1);
MTGCardInstance * hasCard(MTGCardInstance * card); MTGCardInstance * hasCard(MTGCardInstance * card);
void cleanupPhase(); void cleanupPhase();
void beforeBeginPhase();
int countByType(const char * value); int countByType(const char * value);
int countByCanTarget(TargetChooser * tc); int countByCanTarget(TargetChooser * tc);
MTGCardInstance * findByName(string name); MTGCardInstance * findByName(string name);
@@ -91,6 +97,7 @@ class MTGGameZone {
int hasName(string value); int hasName(string value);
int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise
int hasX(); int hasX();
int seenThisTurn(TargetChooser * tc); //How many cards matching a TargetChooser have been put in this zone during the turn
void setOwner(Player * player); void setOwner(Player * player);
MTGCardInstance * lastCardDrawn; MTGCardInstance * lastCardDrawn;
static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target); static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target);
@@ -145,7 +152,9 @@ class MTGPlayerCards {
protected: protected:
void init(); void init();
public: public:
Player * owner;
PlayRestrictions * playRestrictions;
MTGLibrary * library; MTGLibrary * library;
MTGGraveyard * graveyard; MTGGraveyard * graveyard;
MTGHand * hand; MTGHand * hand;
@@ -170,6 +179,7 @@ class MTGPlayerCards {
void showHand(); void showHand();
void resetLibrary(); void resetLibrary();
void initDeck(MTGDeck * deck); void initDeck(MTGDeck * deck);
void beforeBeginPhase();
MTGCardInstance * putInGraveyard(MTGCardInstance * card); MTGCardInstance * putInGraveyard(MTGCardInstance * card);
MTGCardInstance * putInExile(MTGCardInstance * card); MTGCardInstance * putInExile(MTGCardInstance * card);
MTGCardInstance * putInLibrary(MTGCardInstance * card); MTGCardInstance * putInLibrary(MTGCardInstance * card);
+61
View File
@@ -0,0 +1,61 @@
#ifndef _PLAY_RESTRICTIONS_H_
#define _PLAY_RESTRICTIONS_H_
class TargetChooser;
class MTGCardInstance;
class MTGGameZone;
class PlayRestriction
{
public:
enum
{
LANDS_RULE_ID,
UNDEF_ID
};
enum
{
CAN_PLAY,
CANT_PLAY,
NO_OPINION
};
unsigned int id;
TargetChooser * tc;
virtual int canPutIntoZone(MTGCardInstance * card, MTGGameZone * destZone) = 0;
PlayRestriction(unsigned int id, TargetChooser * tc);
~PlayRestriction();
};
class MaxPerTurnRestriction: public PlayRestriction
{
public:
enum
{
NO_MAX = -1,
};
int maxPerTurn;
MTGGameZone * zone;
MaxPerTurnRestriction(unsigned int id, TargetChooser * tc, int maxPerTurn, MTGGameZone * zone);
int canPutIntoZone(MTGCardInstance * card, MTGGameZone * destZone);
};
class PlayRestrictions
{
protected:
vector<PlayRestriction *>restrictions;
public:
PlayRestriction * getRestrictionById(unsigned int id);
void addRestriction(PlayRestriction * restriction);
void removeRestriction(PlayRestriction * restriction);
int canPutIntoZone(MTGCardInstance * card, MTGGameZone * destZone);
~PlayRestrictions();
};
#endif
-2
View File
@@ -27,8 +27,6 @@ public:
JTexture * mAvatarTex; JTexture * mAvatarTex;
JQuadPtr mAvatar; JQuadPtr mAvatar;
int playMode; int playMode;
bool canPutLandsIntoPlay;
int landsPlayerCanStillPlay;
bool nomaxhandsize; bool nomaxhandsize;
int castedspellsthisturn; int castedspellsthisturn;
bool onlyonecast; bool onlyonecast;
+4 -2
View File
@@ -100,13 +100,15 @@ int AIMomirPlayer::computeActions()
ManaCost * potentialMana = getPotentialMana(); ManaCost * potentialMana = getPotentialMana();
int converted = potentialMana->getConvertedCost(); int converted = potentialMana->getConvertedCost();
SAFE_DELETE(potentialMana); 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 //Attempt to put land into play
cd.init(); cd.init();
cd.setColor(Constants::MTG_COLOR_LAND); cd.setColor(Constants::MTG_COLOR_LAND);
card = cd.match(game->hand); 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); MTGAbility * putIntoPlay = g->mLayers->actionLayer()->getAbility(MTGAbility::PUT_INTO_PLAY);
AIAction * a = NEW AIAction(putIntoPlay, card); //TODO putinplay action AIAction * a = NEW AIAction(putIntoPlay, card); //TODO putinplay action
+1 -1
View File
@@ -1221,7 +1221,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
continue; continue;
if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell ) if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell )
continue; 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; continue;
if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name)) if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name))
continue; continue;
+22 -9
View File
@@ -1456,13 +1456,13 @@ AACloner::~AACloner()
} }
// More Land - allow more lands to be played on a turn // More Land - allow more lands to be played on a turn
AAMoreLandPlz::AAMoreLandPlz(int _id, MTGCardInstance * card, Targetable * _target, ManaCost * _cost, WParsedInt * _additional, AMoreLandPlzUEOT::AMoreLandPlzUEOT(int _id, MTGCardInstance * card, Targetable * _target, WParsedInt * _additional, int who) :
int _tap, int who) : InstantAbilityTP(_id, card, _target, who), additional(_additional)
ActivatedAbilityTP(_id, card, _target, _cost, _tap, who), additional(_additional)
{ {
landsRestriction = NULL;
} }
int AAMoreLandPlz::resolve() int AMoreLandPlzUEOT::addToGame()
{ {
Targetable * _target = getTarget(); Targetable * _target = getTarget();
Player * player; Player * player;
@@ -1476,25 +1476,38 @@ int AAMoreLandPlz::resolve()
{ {
player = (Player *) _target; 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; return 1;
} }
const char * AAMoreLandPlz::getMenuText() const char * AMoreLandPlzUEOT::getMenuText()
{ {
return "Additional Lands"; 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->additional = NEW WParsedInt(*(a->additional));
a->isClone = 1; a->isClone = 1;
return a; return a;
} }
AAMoreLandPlz::~AAMoreLandPlz() AMoreLandPlzUEOT::~AMoreLandPlzUEOT()
{ {
SAFE_DELETE(additional); SAFE_DELETE(additional);
} }
+2 -13
View File
@@ -108,8 +108,6 @@ void GameObserver::nextGamePhase()
if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN) if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN)
{ {
cleanupPhase(); cleanupPhase();
currentPlayer->canPutLandsIntoPlay = true;
currentPlayer->landsPlayerCanStillPlay = 1;
currentPlayer->castedspellsthisturn = 0; currentPlayer->castedspellsthisturn = 0;
currentPlayer->opponent()->castedspellsthisturn = 0; currentPlayer->opponent()->castedspellsthisturn = 0;
currentPlayer->castcount = 0; currentPlayer->castcount = 0;
@@ -124,9 +122,8 @@ void GameObserver::nextGamePhase()
mLayers->actionLayer()->Update(0); mLayers->actionLayer()->Update(0);
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
delete (players[i]->game->garbage); //Cleanup of each player's gamezones
players[i]->game->garbage = NEW MTGGameZone(); players[i]->game->beforeBeginPhase();
players[i]->game->garbage->setOwner(players[i]);
} }
combatStep = BLOCKERS; combatStep = BLOCKERS;
return nextGamePhase(); return nextGamePhase();
@@ -377,14 +374,6 @@ void GameObserver::gameStateBasedEffects()
//effects or menus actions //effects or menus actions
for (int i = 0; i < 2; i++) 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) if(players[i]->poisonCount > 0)
{ {
players[i]->isPoisoned = true; players[i]->isPoisoned = true;
-3
View File
@@ -725,9 +725,6 @@ void GameStateMenu::Render()
void GameStateMenu::ButtonPressed(int controllerId, int controlId) void GameStateMenu::ButtonPressed(int controllerId, int controlId)
{ {
int deckId;
int result;
DebugTrace("GameStateMenu: controllerId " << controllerId << " selected"); DebugTrace("GameStateMenu: controllerId " << controllerId << " selected");
switch (controllerId) switch (controllerId)
{ {
+40 -4
View File
@@ -2206,9 +2206,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
Targetable * t = NULL; Targetable * t = NULL;
if (spell) if (spell)
t = spell->getNextTarget(); t = spell->getNextTarget();
MTGAbility * a = NEW AAMoreLandPlz(id, card, t, NULL, additional, 0, who); return NEW AMoreLandPlzUEOT(id, card, t, additional, who);
a->oneShot = 1;
return a;
} }
//Deplete //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) MTGAbility(_id, source, _target)
{ {
init = 0; init = 0;
@@ -4785,3 +4783,41 @@ Targetable * ActivatedAbilityTP::getTarget()
} }
return NULL; 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;
}
+46 -1
View File
@@ -68,10 +68,28 @@ MTGPlayerCards::~MTGPlayerCards()
SAFE_DELETE(removedFromGame); SAFE_DELETE(removedFromGame);
SAFE_DELETE(garbage); SAFE_DELETE(garbage);
SAFE_DELETE(temp); 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) void MTGPlayerCards::setOwner(Player * player)
{ {
this->owner = player;
library->setOwner(player); library->setOwner(player);
graveyard->setOwner(player); graveyard->setOwner(player);
hand->setOwner(player); hand->setOwner(player);
@@ -241,6 +259,11 @@ void MTGPlayerCards::init()
exile = removedFromGame; exile = removedFromGame;
garbage = NEW MTGGameZone(); garbage = NEW MTGGameZone();
temp = 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() 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 //The "Temp" zone are purely for code purposes, and we don't want the abilities engine to
//Trigger when cards move in this zone //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 // 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 // See http://code.google.com/p/wagic/issues/detail?id=335
{ {
@@ -391,6 +414,11 @@ MTGGameZone::~MTGGameZone()
owner = NULL; owner = NULL;
} }
void MTGGameZone::beforeBeginPhase()
{
cardsSeenThisTurn.clear();
};
void MTGGameZone::setOwner(Player * player) void MTGGameZone::setOwner(Player * player)
{ {
for (int i = 0; i < nb_cards; i++) for (int i = 0; i < nb_cards; i++)
@@ -583,6 +611,22 @@ int MTGGameZone::hasAbility(int ability)
return 0; 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() void MTGGameZone::cleanupPhase()
{ {
for (int i = 0; i < (nb_cards); i++) for (int i = 0; i < (nb_cards); i++)
@@ -599,6 +643,7 @@ void MTGGameZone::addCard(MTGCardInstance * card)
if (!card) if (!card)
return; return;
cards.push_back(card); cards.push_back(card);
cardsSeenThisTurn.push_back(card);
nb_cards++; nb_cards++;
cardsMap[card] = 1; cardsMap[card] = 1;
card->lastController = this->owner; card->lastController = this->owner;
+10 -7
View File
@@ -35,11 +35,14 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
} }
return 1; return 1;
} }
if(!allowedToCast(card,player)) if(!allowedToCast(card,player))
return 0; return 0;
if (card->hasType("land")) 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) && (game->currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
) )
{ {
@@ -58,7 +61,7 @@ if(!allowedToCast(card,player))
#ifdef WIN32 #ifdef WIN32
cost->Dump(); cost->Dump();
#endif #endif
if (player->castrestrictedspell && !card->hasType("land")) if (player->castrestrictedspell)
{ {
return 0; return 0;
} }
@@ -154,7 +157,6 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card)
spell->resolve(); spell->resolve();
delete spellCost; delete spellCost;
delete spell; delete spell;
player->landsPlayerCanStillPlay--;
} }
else else
{ {
@@ -259,7 +261,9 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
if (card->hasType("land")) 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_FIRSTMAIN
|| game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN) || game->currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
) )
@@ -358,7 +362,6 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter
copy->alternateCostPaid[alternateCostType] = 1; copy->alternateCostPaid[alternateCostType] = 1;
spell->resolve(); spell->resolve();
SAFE_DELETE(spell); SAFE_DELETE(spell);
player->landsPlayerCanStillPlay--;
game->mLayers->stackLayer()->addSpell(copy, NULL, NULL, alternateCostType, 1); game->mLayers->stackLayer()->addSpell(copy, NULL, NULL, alternateCostType, 1);
} }
else else
+95
View File
@@ -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();
}
-2
View File
@@ -12,8 +12,6 @@ Damageable(20)
deckFile = file; deckFile = file;
deckFileSmall = fileSmall; deckFileSmall = fileSmall;
manaPool = NEW ManaPool(this); manaPool = NEW ManaPool(this);
canPutLandsIntoPlay = true;
landsPlayerCanStillPlay = 1;
nomaxhandsize = false; nomaxhandsize = false;
castedspellsthisturn = 0; castedspellsthisturn = 0;
castrestrictedspell = false; castrestrictedspell = false;
+1
View File
@@ -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 !"); DebugTrace("TESTUITE Init Game Done !");
+8
View File
@@ -769,6 +769,10 @@
RelativePath=".\src\PlayGuiObjectController.cpp" RelativePath=".\src\PlayGuiObjectController.cpp"
> >
</File> </File>
<File
RelativePath=".\src\PlayRestrictions.cpp"
>
</File>
<File <File
RelativePath=".\src\Pos.cpp" RelativePath=".\src\Pos.cpp"
> >
@@ -1234,6 +1238,10 @@
RelativePath=".\include\PlayGuiObjectController.h" RelativePath=".\include\PlayGuiObjectController.h"
> >
</File> </File>
<File
RelativePath=".\include\PlayRestrictions.h"
>
</File>
<File <File
RelativePath=".\include\Pos.h" RelativePath=".\include\Pos.h"
> >