Monday, June 23, 2008

Static Abilities

A friend asked me to program some slivers, so I took a deep breath and tried to figure out which slivers were the easiest to add. (If you have never gotten the change to crush a foe with slivers, you haven’t played Magic long enough.) This got me thinking about static abilities.

Magic’s static abilities are the hardest effects to program. Card with static abilities include Glorious Anthem (your creatures get +1/+1) and Nightmare (power and toughness are equal to the number of swamps you control.)

There are relatively few cards in MTG Forge that have static abilities, because they are hard to code. Activated abilities are almost trivial when compared to static. Examples of activated abilities include Elvish Piper (tap: put a creature from your hand into play) and Rootwalla (1G: Rootwalla gets +2/+2 until end of turn), all activated abilities have a colon “:”.

Let me try to explain why static abilities are so complicated. Glorious Anthem gives +1/+1 to all your creatures. So this means Anthem gives +1/+1 to all your current creatures and well as any future creatures you play. The “future” part of that sentence is what makes Anthem problematic. Otherwise Anthem would just be similar to Warrior's Honor, “Creatures you control get +1/+1 until end of turn.” Warrior’s Honor effect is done after it resolves, while Glorious Anthem’s effect stays around.

MTG Forge was written without any static abilities and after brainstorming I figured out a way to program Glorious Anthem (I really wanted to use that card) and Nightmare. But creatures like Nightmare have a problem, they can’t be pumped up by effects like Giant Growth.

The difficulty is that Magic applies effects in layers, while MTG Forge does not. MTG Forge uses a number (int) to represent a creature’s power. Thankfully the layering problem doesn’t crop up very often, but when it does it will surprise you. The only solution is to implement a complicated layering system, so until that happens just don’t target Nightmare with Giant Growth :+)

1 comment:

Anonymous said...

How about that: each card such as nightmare, bad moon, crusade... keeps a record (a hash) of all cards it has already taken into account.
On a regular basis (each event), it updates its hash, adding new cards and removing old ones.
For example, Bad Moon gives +1/+1 to all black creatures.
On a regular basis, it scans the black creatures in play and compares that to the ones it has in its hash. If there are new ones, it gives them +1/+1 and adds them to its hash. If there are some cards in its hash that are not black creatures (because they changed color or are not in play anymore, etc...), then it gives them -1/-1 and removes the entry from the hash.