I've gotten started. Only planning, so far, and I won't be done for a long time (I still don't have a lot of free time).
I haven't familiarized myself with exactly how Riiak's mana functions work, but once I do, I'll use those functions wherever possible (such as replacing CW_AM_MarkCanProduceMana with Riiak's function if it'll work for what I need, and I imagine it will).
RSN_ObjectDC():Get_Chest(CW_AM_CHEST_REGISTER)
Parent chest in a card's ObjectDC within which all other data is stored.
0 (int 0-5): Current colour
1 (chest): Producible colours
2 (chest): Extra costs
RSN_ObjectDC():Get_Chest(CW_AM_CHEST_REGISTER):Get_Chest(1)
A list of integers which determine if a given card is able to produce a given colour.
0 (int 0-1): Colourless
1 (int 0-1): White
2 (int 0-1): Blue
3 (int 0-1): Black
4 (int 0-1): Red
5 (int 0-1): Green
RSN_ObjectDC():Get_Chest(CW_AM_CHEST_REGISTER):Get_Chest(2)
A list of integers which determine if a given producible colour has extra costs associated.
The purpose of this chest is to prevent the code from telling a card to produce a colour which has other costs associated but still be able to allow cards such as
Exotic Orchard to work.
0 (int 0-1): Colourless
1 (int 0-1): White
2 (int 0-1): Blue
3 (int 0-1): Black
4 (int 0-1): Red
5 (int 0-1): Green
On card:
CW_AM_MarkCanProduceColour("{W}{U}{B}{R}{G}{1}"}
EffectSource():GetCurrentCharacteristics():GrantAbility(RSN_ObjectDC():Get_Chest(CW_AM_CHEST_REGISTER):Get_Int(0))
Manager generation.
Activated ability to set produced colour, auto, or manual.
Auto mana abilities for all relevant colours.
Manual mana abilities for all relevant colours.
On manager:
Index mana producing permanents.
For each mana producing permanent, determine producible colours.
Create array from producible color sets.
Determine identical sets so they can be handled together.
Determine needed mana from hand, graveyard, and top of library if face-up (ignore top card if too difficult determine face-up status).
Remove from needed mana all producible mana from cards which produce only one color.
Determine which needed colours are available.
From available needed colours, determine maximum amount available per colour.
From available needed colours accounting for maximum available count, determine if full needed mana array can be produced from available mana producers.
If full needed mana array cannot be produced, restrict to hand and try again.
If full needed mana array cannot be produced, decrement highest needed colour count and try again until success.
When solution is achieved, for each mana producing permanent, pass that permanent's Colour to RSN_ObjectDC():Get_Chest(CW_AM_CHEST_REGISTER):Set_Int(0, Colour).
Even now I can see a few things which will need switched around and reworked slightly, but I'll do that as I go. (For instance, if I reduce the most expensive colour, causing the card that needs that number of that colour to be uncastable, I should make sure the other colours aren't now higher than necessary.
Example:
Hand:
Brilliant Ultimatum,
Cruel UltimatumBattlefield: 2
Boros Guildgate, 2
Golgari Guildgate, 3
Simic Guildgate.
It'll find it can't make 2W, 3U, 3B, and 2R, so it'll reduce U or B (let's assume the better outcome: B). It'll be left with 2W, 3U, 2B, and 2R. It still can't make that combination, so it reduces U, and still can't, so it reduces another one. No matter what it chooses, U is at less than 3 now, so when it finds a "solution", it won't allow either card to be cast. Work it such that it checks the maximum of each card before counting ANY of the card's mana, and it'll only try to produce 2W, 3U, and 2B, which it can do. A few other simple things like that need fixed, but it's at least a workable function. It'll be complicated, but doable.