mtgrares wrote:I have no idea how Wagic or other Magic project create new card objects.
In Wagic we have 3 classes:
CardPrimitive is a class that hold all the basic data (power/toughness...) Basically the cardPrimitives represent our database. An example of Card Primitive is the data representing Llanowar Elves.
CardPrimitive Llanowar Elves:
- Code: Select all
name=Llanowar Elves
power=1
toughness=1
auto={t}:Add{G}
...
Card is a class that represent reprints. It has a cardPrimitive as an attribute, but everything specific to a reprint (id, picture, rarity,...) are distinct. So, for example, Llanowar Elves in 10E point to the "Llanowar Elves" primitive data, but additionally have rarity information (Common), a specific id (the id from gatherer) etc...
Card Llanowar Elves 10E:
- Code: Select all
primitive=Llanowar elves
id=12345
rarity=C
Technically, Card objects also represent our database, or rather, what cards are contained in what sets.
Then, in the game itself, we have MTGCardInstance. This class inherits from both CardPrimitive AND Card (which is kind of dirty). Every time I put a new "Llanowar Elf" in play, a new MTGCardInstance is created, and we manually copy the contents of the CardPrimitive and the Card it inherits from.
http://code.google.com/p/wagic/source/b ... nce.cpp#25 (but the copy of the actual contents happens in the Constructors of CardPrimitive and Card).
MTGCardInstance Llanowar Elves 1:
- Code: Select all
power=1
toughness=1
rarity=C
auto={T}:Add{G}
id=12345
...
Additionally, when a card changes zone, we create a new MTGCardInstance from its matching CardPrimitive. And we put a "backtrack" pointer to the previous MTGCardInstance.
For example, if my Llanowar Elves currently in play is called MTGCardInstance[1], then if it goes to the graveyard, I will create a MTGCardInstance[2] that points to MTGCardInstance[1]. This pointer is for abilities that say things like "when this card is put into a graveyard, if it was a creature, then...". It basically allows to look at what the card was in previous zones, without any major headache. (We didn't do that initially, but Incantus convinced me a while ago that a new object for every zone change is the good solution)
MTGCardInstance Llanowar Elves 2:
- Code: Select all
power=1
toughness=1
rarity=C
auto={T}:Add{G}
id=12345
previous=Llanowar Elves 1
...
To preserve ram, we delete as much "old" copies as possible at the end of each turn.
So, to summarize: we handle our copies manually in game.
(all code above is of course pseudo code)