[CODE] Colorless Hybrid

All code submission.
Post Reply
Niegen
Posts: 200
Joined: Sun Jul 12, 2009 9:46 am

[CODE] Colorless Hybrid

Post by Niegen »

There is an issue that has been reported with colorless hybrid card (Spectral Procession and the likes).
Basically, you can't pay the colorless "part" of the mana cost with coloured mana, you have to use real *colorless* mana.
It means you can't cast Spectral Procession for BBWW for instance.

Attached is my attempt at fixing this by updating ManaCost::tryToPayHybrids, which, in its current state, could not handle colorless hybrid.

Using this code, I've been able to cast Spectral Procession with the following manapools.
  • 6 non-white mana
  • 5 mana (including 1 white)
  • 4 mana (including 2 white)
  • 3 white
If there is left-over mana, it isn't used and stays in the mana pool.

[The extension zip has been deactivated and can no longer be displayed.]

Code: Select all

/**
    starting from the end of the array (diff) 
*/
int ManaCost::tryToPayHybrids(std::vector<ManaCostHybrid>& _hybrids, int _nbhybrids, std::vector<int16_t>& diff)
{
    if (!_nbhybrids)
        return 1;
    int result = 0;
    ManaCostHybrid& h = _hybrids[_nbhybrids - 1];
    if (diff[h.color1 * 2 + 1] >= h.value1)
    {
        diff[h.color1 * 2 + 1] -= h.value1;
        result = tryToPayHybrids(_hybrids, _nbhybrids - 1, diff);
        if (result)
            return 1;
        diff[h.color1 * 2 + 1] += h.value1;
    }
    if (diff[h.color2 * 2 + 1] >= h.value2)
    {
        diff[h.color2 * 2 + 1] -= h.value2;
        result = tryToPayHybrids(_hybrids, _nbhybrids - 1, diff);
        if (result)
            return 1;
        diff[h.color2 * 2 + 1] += h.value2;
    }
    if (h.color1 == Constants::MTG_COLOR_ARTIFACT && h.value1 > 0)
    {
        int colorlesscost = h.value1;
        vector<int16_t> diffcopy;
        diffcopy.resize((Constants::NB_Colors + 1) * 2);
        diffcopy[Constants::NB_Colors * 2] = Constants::NB_Colors;
        for (int i = 0; i < Constants::NB_Colors*2; i++)
        {
            diffcopy[i] = diff[i];
        }
        for (int i = 0 ; i <= Constants::MTG_COLOR_LAND ; i++)
        {
            if (colorlesscost <= diffcopy[i * 2 + 1]) {
                diffcopy[i * 2 + 1] -= colorlesscost;
                colorlesscost = 0;
            }
            else
            {
                //update what's left to pay & empty that mana pool's color
                colorlesscost -= diffcopy[i * 2 + 1];
                diffcopy[i * 2 + 1] = 0;
            }            
        }
        if (colorlesscost == 0) {
            //we paid the whole cost, update the real mana cost and proceed
            for (int i = 0; i < Constants::NB_Colors*2; i++)
            {
                diff[i] = diffcopy[i];
            }
            result = tryToPayHybrids(_hybrids, _nbhybrids - 1, diff);
            if (result)
                return 1;
        }
    }
    return 0;
}
Edit: Sadly, my code doesn't work for Reaper King...
sandman423
Posts: 739
Joined: Thu Sep 10, 2009 8:59 pm

Re: [CODE] Colorless Hybrid

Post by sandman423 »

Has this been added to SVN 4861?
Niegen
Posts: 200
Joined: Sun Jul 12, 2009 9:46 am

Re: [CODE] Colorless Hybrid

Post by Niegen »

Code submission is for people who don't have write access to the svn (yet), so no :)
Post Reply