It is currently 19 Jul 2025, 09:14
   
Text Size

One day, Doc went coding...

Discuss Upcoming Releases, Coding New Cards, Etc.
PLEASE DO NOT REPORT BUGS HERE!

Moderators: BAgate, drool66, Aswan jaguar, gmzombie, stassy, CCGHQ Admins

One day, Doc went coding...

Postby DrLambda » 01 Jul 2010, 16:34

Okay, today i finally got up and started getting into coding a few new cards, thinking "How hard can it be?", seeing how i can now do them in C.

I didn't want to start with cards without code because coding is what i do. So, while thinking about which card to do first, i stumbled upon the mtg.com preview card for today, the Fauna Shaman. Easy enough, it's just changing the code for Survival of the Fittest a little, right?

I was wrong. After i wrote the code, compiled it and added the card with Skymagic, everything seemed fine at first. The game doesn't crash, i can play the creature fine, the game recognized it as an elf etc. The problem is that i can't activate it, and i have no idea why. The code pointer points to the correct code as far as i know, and i can't really find an error in my code (and i really didn't change a lot).

Could anyone tell me what's wrong here?

Code: Select all
#include "manalink.h"

int card_fauna_shaman(int player, int card, event_t event)

{
    target_definition_t td;
    default_target_definition(player, card, &td, TYPE_CREATURE);
    td.allowed_controller = player;
    td.preferred_controller = player;
    td.zone = TARGET_ZONE_HAND;
    td.illegal_abilities = 0;
    td.allow_cancel = 0;
    if(event == EVENT_CAN_ACTIVATE)
   {
      if( has_mana( player, COLOR_GREEN, 1 ) && target_available(player, card, &td)  && !is_tapped(player, card) && !is_sick(player, card))
      {
                  return 1;
           }
       }
    else if(event == EVENT_ACTIVATE)
   {
           charge_mana( player, COLOR_GREEN, 1);
      tap_card(player, card);
           if( spell_fizzled != 1 )
         {
                  select_target(player, card, &td, "Discard a creature", NULL);
                  card_instance_t *instance= get_card_instance(player, card);
                  discard_card( player, instance->targets[0].card );
              }
       }
    else if(event == EVENT_RESOLVE_ACTIVATION)
   {
           int selected = pick_card_from_deck(player);
           if( selected != -1)
         {
                     int *deck = deck_ptr[player];
                     if ( cards_data[ deck[selected] ].type & TYPE_CREATURE )
               {
                            add_card_to_hand(player, deck[selected] );
                            remove_card_from_deck(player, selected);
                            hand_count[player]++;
                        }
              }
              shuffle(player);
       }
    return 0;
}
The only thing i changed was adding the additional checks !is_tapped and !is_sick as well as "tap_card(player, card);" in EVENT_ACTIVATE. And yes, i tried removing every single if-Clause in EVENT_CAN_ACTIVATE.

Please help me #-o
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby DrLambda » 01 Jul 2010, 20:57

Just to let you know: Other cards work just fine. I'm almost done with all the Titans.

If anyone has an idea how to check if there are legal targets in the graveyard for Sun Titan before opening the graveyard without typing my arms off, please tell me :D

At the moment it just checks if there are cards in the graveyard at all, then opens the window and checks if the card you've chosen is legal.

Code: Select all
int effect_sun_titan(int player, int card, event_t event)
{
   if (count_graveyard(player) > 0)
   {
        int *grave = graveyard_ptr[player];
        int selected = show_deck( player, grave, 500, "Pick a card to reanimate", 0, 0x7375B0 );
        if( selected != -1)
      {
                  card_data_t card_d = cards_data[ grave[selected] ];
                  if(  card_d.cc[1] + card_d.cc[2] < 4 && card_d.type != 0x08 && card_d.type != 0x10)
            {
                         int card_added = add_card_to_hand(player, grave[selected] );
                             remove_card_from_grave( player, selected );
                             put_into_play(player, card_added);   
            }
      }
        }
   return 0;
}


int card_sun_titan(int player, int card, event_t event) //2002555
{
   vigilance(player, card);
       card_instance_t *instance = get_card_instance(player, card);
       if( event == EVENT_DECLARE_ATTACKERS && instance->state & STATE_ATTACKING )
   {
             effect_sun_titan(player, card, event);
   }
   if( comes_into_play(player, card, event) )
   {
             effect_sun_titan(player, card, event);   
          }       
    return 0;
}
Also, if anyone still has the code for Arc Lightning / Bogardan Hellkite / Fire/Ice, could you please post it in here so i have an easier job completing the red titan? That would be awesome.

Simply telling me the name of the function of Arc Lightning would also work, i guess :p
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby jatill » 01 Jul 2010, 21:29

I hope you are planning on sharing when you are done? If so, cheers, you'll save me some effort since I was going to do several of these cards as well.

Anyway, to address your questions:
Fauna Shaman: make sure the 'extra abilities' flag is set to '01' in the editor. This field and reserved information are very important, so copy them from similar cards (in this case, Survival)

Sun Titan: You can find the CMC for a card in your deck by adding the number of black mana + blue mana + ... etc. I'm doing this for other cards, but I can't remember which off the top of my head. It would probably make sense to write a function to get the cmc based on a card id. You cannot trust that card_d.cc[1] + card_d.cc[2] will always have the right information, though.

Red Titan: The code for all of those cards is in the exe, not C. What you can do, though, is do what I did to apply the effect of Time Walk to Emrakul. Check out his code, and the time_walk entries in manalink.lds and .h.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: One day, Doc went coding...

Postby DrLambda » 01 Jul 2010, 22:03

Hi. Yeah, i will obviously share the code once i'm done. I'm currently trying to make myself comfortable with a few cards from M11, but i'll probably try a few harder-to-program cards once i'm "in it."

With your help, the Fauna Shaman finally works. Thanks a lot (also thanks a lot for all the work you've done for this project!). This means my progress with the cards is as follows:

Fauna Shaman: 100%
Grave Titan: 100%
Primeval Titan: 100%
Liliana's Specter: 100% (Everyone has to start with something ;) )
Inferno Titan: 100%
Sun Titan: 100%
Ajanis Pridemate: 100%
Temple Bell: 100%
Ember Hauler: 100%
Crystal Ball: 100%
Viscera Seer: 100%
Ajani's Mantra: 100%
War Priest of Thune: 100%
Preordain: 100%
Jace's Erasure: 100%
Frost Titan: 50% (Tapping permanents works, but i'm not sure if the first ability is actually possible)
Reassembling Skeleton: ~10% (Well, let's say i know where to add the code, but i'm still not sure how.)

*edit: Inferno Titan now done. I checked the code of Bloodbraid Elf, and it looks like it is also doing the cc[0]+cc[1] thing. I'll keep it at that for the moment.

*edit2: Adding more cards as they come. Let's see how many i can do before i fall asleep. ;)

*edit3: Let's call it a night.
Last edited by DrLambda on 02 Jul 2010, 13:21, edited 4 times in total.
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby DrLambda » 02 Jul 2010, 10:44

There also are quite a few cards in M11 that don't need new code which are almost pure improvements over other cards.

Garruk's Companion >> War Mammoth
Back to Nature >> Tranquility
Greater Basilisk >> Thicket Basilisk (Okay, if you want 100% functionality, you probably have to write new code to replace "Stoning" with Deathtouch.)
Plummet >> Wing Snare
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby DrLambda » 02 Jul 2010, 12:27

More questions: Why does Jace's Erasure mill my entire library if the CPU controls it? Does mill trigger the "draw a card" trigger? Why does it work when i control it then?

Code: Select all
int card_jaces_erasure(int player, int card, event_t event)
{
 if(trigger_condition == 0xD0 && reason_for_trigger_controller == player ){
  mill( 1-player, 1);
}
  return global_enchantment(player, card, event);
}
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby jatill » 02 Jul 2010, 12:51

DrLambda wrote:More questions: Why does Jace's Erasure mill my entire library if the CPU controls it? Does mill trigger the "draw a card" trigger? Why does it work when i control it then?

Code: Select all
int card_jaces_erasure(int player, int card, event_t event)
{
 if(trigger_condition == 0xD0 && reason_for_trigger_controller == player ){
  mill( 1-player, 1);
}
  return global_enchantment(player, card, event);
}
You're missing a bunch of code. Compare to lorescale:

Code: Select all
int card_lorescale_coatl(int player, int card, event_t event){
    if(trigger_condition == TRIGGER_REPLACE_CARD_DRAW && affect_me(player, card) && reason_for_trigger_controller == player){
        if(event == EVENT_TRIGGER){
            event_result |= 2;
        }
        else if(event == EVENT_RESOLVE_TRIGGER){
            card_instance_t *instance = get_card_instance( player, card);
            instance->counters++;
            instance->counter_power++;
            instance->counter_toughness++;
        }
    }
    return 0;
}
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: One day, Doc went coding...

Postby jatill » 02 Jul 2010, 13:01

If you keep up at this rate, maybe we can make the whole set! :) I wonder how many cards actually require non-trivial code?

I think Frost Titan is tricky (probably impossible to get perfect). I might give that a shot later.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: One day, Doc went coding...

Postby DrLambda » 02 Jul 2010, 13:43

I have to admit that i'm not 100% sure what the lorescale coatl code is doing, but it's working, and that's everything i need ;)

Coding the whole M11 set should be possible, although i won't be able to do a lot this weekend (a lot of drinking will occur though ;) )

M11 has 249. Out of those:
20 are basic lands.
16 are coded by me.
5 are the planeswalkers which are already coded.
5 more are the M10 Duals, also coded.
37 - Already done
10 - No code at all
82 - Unknown

74 - Cards to code left at the moment. Most of them are trivial.

Also, there are cards with only minimal changes or cheaper functional reprints, like Plummet, Back to Nature etc. Also Cultivate/Kodama's Reach and cards with the same code as an already existing card like Prized Unicorn.

Already done
Baneslayer Angel, Elite Vanguard, Holy Strength, Pacifism, Serra Angel, Wild Griffin, Azure Drake, Foresee, Mana Leak, Negate, Tome Scour, Unsummon, Corrupt, Diabolic Tutor, Gravedigger, Mind Rot, Nantuko Shade, Relentless Rats, Unholy Strength, Fireball, Goblin Balloon Brigade, Goblin Chieftain, Goblin Piker, Goblin Tunneler, Lava Axe, Lightning Bolt, Prodigal Pyromancer, Birds of Paradise, Elvish Archdruid, Fog, Giant Growth, Giant Spider, Llanowar Elves, Naturalize, Juggernaut, Platinum Angel, Voltaic Key

No Code at all:
Assault Griffin, Cloud Crusader, Silvercoat Lion, Barony Vampire, Stormfront Pegasus, Nether Horror, Garruk's Companion, Wall of Vines, Yavimaya Wurm, Stone Golem

Before i go out this evening, i'll upload my progress here.

*edit: More cards:
Serra Ascendant
Armored Ascension
Condemn
Cultivate
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby DrLambda » 02 Jul 2010, 16:32

Okay, here we go. This is my coding progress until now.

doc_titans.c has the 5 titans. The only thing missing is the targeting ability of Frost Titan. In my version, i replaced the following cards (but you can do whatever you want with them)
Sun Titan >> Personal Incarnation
Frost Titan >> Sea Serpent
Grave Titan >> Random Bad Card
Inferno Titan >> Volcanic Dragon
Primeval Titan >> Random Bad Card

doc_m11.c has the following cards:

Fauna Shaman >> Random Bad Card
Liliana's Specter >> Random Bad Card
Ajanis Pridemate >> Random Bad Card
Temple Bell >> Jalum Tome
Ember Hauler >> Goblin Glider
Crystal Ball >> Also some tome
Viscera Seer >> Plague Beetle
Ajani's Mantra >> Random Bad Card
War Priest of Thune >> Cloudchaser Eagle
Preordain >> Sleight of Hand
Jace's Erasure >> Land Equilibrium
Greater Basilisk >> Thicket Basilisk
Serra Ascendant >> A white 1-Drop
Armored Ascension >> Animate Wall
Condemn >> Purelace
Cultivate >> (Not tested)

There is also code for Reassembling Skeleton which you should ignore at this point. I just did some random tests and didn't really know what i was doing.
Attachments
doc_code.zip
DrLambda's code for some M11 cards.
(3.58 KiB) Downloaded 363 times
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby jatill » 03 Jul 2010, 19:01

Meanwhile I just spent about 4 hours working on just 1 card... Obstinate Baloth. What a pain.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: One day, Doc went coding...

Postby DrLambda » 03 Jul 2010, 22:50

If you want to put them in:

I found two bugs earlier. Primeval Titan misses a shuffle effect and Preordain needs a KILL_DESTROY line.

Also, while i'm at it:
Known Bugs:
Sun Titan - Will always open the graveyard prompt if there is at least 1 card in your graveyard. If there is no legal target to choose, he will simply cancel the action.
Inferno Titan - Deals damage in 1-point packets even if you only target one target. This only matters for Circle of Protection: Red etc.
Ajani's Pridemate - Sometimes doesn't trigger at all for some reason. Most obvious one would be Ivory Tower.

*edit: I fixed the bugs (Also found another one for Serra Ascendant) and added most of the remaining official white cards. The missing ones are Angelic Arbiter (i actually have no idea how to do this.), Safe Passage, Roc Egg (I don't know how to make new tokens), and Vengeful Archon (See Angelic Arbiter).
NEW:
Excommunicate
Goldenglow Moth
Mighty Leap
Solemn Offering
Squadron Hawk
Tireless Missionaries
Knight Exemplar

*edit: I think i actually got Angelic Arbiter.
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby DrLambda » 04 Jul 2010, 12:20

I'm actually close to completing Angelic Arbiter. I also spent like 4 hours on it yesterday. I still have one problem left: Stopping creatures from attacking. I actually found a legacy effect created by Blinding Angel in white_creatures.c, but it doesn't actually do anything as far as i can see. Is it supposed to work?

Code: Select all
int effect_angelic_arbiter(int player, int card, event_t event){
    if( eot_trigger(player, card, event) ){
        kill_card(player, card, KILL_SACRIFICE );
    }
    else if( event == EVENT_ATTACK_LEGALITY && player != current_turn  ){
        event_result = 1;
    }
    return 0;
}
The legacy card is created at the right time, it just doesn't stop creatures from attacking.
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Re: One day, Doc went coding...

Postby jatill » 04 Jul 2010, 13:51

It will work, but again, you need the proper reserved information. Also note that in the case of Arbiter, you don't want to use a legacy effect, since if Arbiter dies, the player can attack again. So just attack the effect directly to the creature's code, no legacy needed.
jatill
DEVELOPER
 
Posts: 2118
Joined: 24 Feb 2009, 16:35
Has thanked: 5 times
Been thanked: 17 times

Re: One day, Doc went coding...

Postby DrLambda » 04 Jul 2010, 14:03

Where do i get the proper reserved information for this? The Blinding Angel code is there, but Blinding Angel isn't in the current version as far as i can see. Also, how can i find out if the problem is the reserved information?

It shouldn't be a big problem to get the code into the card itself though. It's interesting to note how i got way more problems with SkyMagic editor than with the c code itself. ;)

Also it's interesting to note how i actually spent like 4-5 hours now on a card that probably noone will play ;) (Well, it's better than Archangel though.)
DrLambda
 
Posts: 49
Joined: 09 Jul 2008, 00:46
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 2 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 2 guests

Login Form