Page 1 of 1

Card isInZone function

PostPosted: 06 Aug 2013, 14:26
by Sloth
The isInZone function in the card class is not really doing what it's supposed to do.

It's used a lot to test whether a card is still on the battlefield (or in a nother zone). When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.

When i search for "isInPlay()" in our code i get 73 results and nearly all of them do not function properly with this isInZone function.

@Max: What was the reason to change the isInZone function (r22432)?

For reference, here is the old version:

Code: Select all
    public boolean isInZone(final ZoneType zone) {
        return getGame().isCardInZone(this, zone);
    }

Re: Card isInZone function

PostPosted: 07 Aug 2013, 09:24
by Max mtg
Sloth wrote: When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
Then it's the problem in code that does not update the Card instance with new zone.

It is the card that may belong to one and only zone (or none at all). Lists of cards present an opportunity to hold a single card in several zones at once, that is nonsense.

There are also some code routines that iterate over cardlist and need to know the zone each card belongs to. Using the previous implementation would lead to quadruple loop (1st loop is over card list, 2nd one is over players, 3rd over zones of current player and 4th is the lookup inside zone for a certain card)

Re: Card isInZone function

PostPosted: 07 Aug 2013, 11:09
by Sloth
Max mtg wrote:
Sloth wrote: When a card object is outdated (like the source of an ability or trigger waiting on the stack) it will still pretend to be in the previous zone even though the current card has benn destroyed or otherwise changed zone.
Then it's the problem in code that does not update the Card instance with new zone.
The problem is that a card moving from the battlefield to any other zone will create a new card object and the old card object (lingering around as source of a spell/ability or triggering object) will have the wrong currentZone variable.

r22822 fixes most of the issues, but there is still the corner case that a card can change zones multiple times while something on the stack refers to it.