Small Tutorial on How to Hardcode Abilities/Aliases

All additions requested or suggested to improve the card coding language.
Post Reply
Posts: 129
Joined: Tue Mar 30, 2010 12:47 am

Small Tutorial on How to Hardcode Abilities/Aliases

Post by pake1 » Sun Jul 04, 2010 8:54 am

Hey guys,

I think a small tutorial regarding hardcoded abilities would be most beneficial to all of us card coders.

I know Wagic is written in C++, but a small tutorial on the foundations,keywords/variables, and what to tinker with will allow us to further push this project forward.

For instance
Animate Dead uses an Alias:1143

Code: Select all

  case 1143: //Animate Dead
      AAnimateDead * a = NEW AAnimateDead(_id, card, card->target);
      card->target = ((MTGCardInstance * )a->target);
Looking at this code, a tutorial on what is doing what will allow us to correlate what goes on with these aliases' and even hardcode some abilities ourselves.

Erg Raiders uses alias=1159

Code: Select all

 case 1159: //Erg Raiders
      AErgRaiders* ability = NEW AErgRaiders(_id, card);
This small code; is nowhere else seen in the Wagic source code, however,

Code: Select all

name=Erg Raiders
text=At the beginning of your end step, if Erg Raiders didn't attack this turn, Erg Raiders deals 2 damage to you unless it came under your control this turn.
subtype=Human Warrior
Is all that it takes for the card to do as advertised.

Any help would be greatly be appreciated!

Posts: 976
Joined: Wed Oct 15, 2008 7:46 am
Location: Switzerland

Re: Small Tutorial on How to Hardcode Abilities/Aliases

Post by abrasax » Tue Jul 06, 2010 1:05 pm


also there is here a small wording confusion, some cards are "harcoded", they are hardcoded with a number that you can call to "attach" the effect to any card. If you create a card with aline "id=1143" it will have the effect of animate dead... if your card has the same effect as animate dead but another id then you need to use the "alias=" line. Since we are now using primitive the "primitive" version of animate dead is using the "alias" line... not sure if I'm clear...

Well anyway, for these specific card you are mentioning you need to look also at the header AllAbilities.h : ... bilities.h

for some other like traumatize the whole code is in the MTGAbility.cpp and is pretty much self speaking if you ask me:

Code: Select all

case 129774: // Traumatize 
                   int nbcards; 
                   Player * player = spell->getNextPlayerTarget(); 
                   MTGLibrary * library = player->game->library; 
                   nbcards = (library->nb_cards)/2; 
                   for (int i = 0; i < nbcards; i++){ 
                           if (library->nb_cards) 
                                   player->game->putInZone(library->cards[library->nb_cards-1],library, player->game->graveyard); 
this will result in half of TargetPlayer library being "puInZone"->graveyard.... pretty much straight forward.

Now if you want to now what an alias can or can't do, find the "alias=line" in the primitive, look at the rest of the cards code in the mtg.txt, everything that you cannot find softcoded in the mtg.txt is hardcoded in the alias... But I would say that we still have a lot of cards in these files that could be 100% softcoded (like animate dead, the beacons, etc... etc...), the example you are mentioning are not the best one, because there is a lot of code line for something that could probably be softcoded... I suggest you begin to look at "simple" card "hardcode" like the traumatize....basically all "case" in the MTGAbility.cpp that do not have a line looking like "game->addObserver( NEW A....."

Nervertheless I agree we should do some kind of quick sticky explaining the usage of the aliases... but this is mainly for the development of custom sets... as all cards that could profit from alias should already be included in the SVN (or we might have miss something ;) ).


We need your Help !!!
New to wagic ? Be sure to check the following :

Bug report: Bug reporting
Help us: Add cards & Compiling.
Customize: Themes FAQ, All images thread, Abra's Mediafire folder

Post Reply