Hi. I have a list of item that are grouped in group.
I made a new record containing the best of each group and then calculate the value for each group and store the best one. At the moment I duplicat the code for each group but it is starting to be unmanageable as I add more group. Is there a way to do this? I tried adding foreach exclusive before doing foreach item but it saves everything in one record and I end up with one item that is the best of all group.
I tried to figured out how ZapWizard does it, but it's a bit overwhelming.
Thanks
--Grab
Code:
record item_info {
item it;
effect ef;
string exclusive; // each item is given a group; groupA, groupB etc
float boostA;
float boostB;
float boostC
int turns; // number of turns the effect last
};
I made a new record containing the best of each group and then calculate the value for each group and store the best one. At the moment I duplicat the code for each group but it is starting to be unmanageable as I add more group. Is there a way to do this? I tried adding foreach exclusive before doing foreach item but it saves everything in one record and I end up with one item that is the best of all group.
Code:
record MutualyExcl{
item it;
int bestvalue;
};
MutualyExcl bestgroupA;
bestGroupA.bestvalue=0;
MutualyExcl bestgroupB;
bestgroupB.bestvalue=0;
MutualyExcl bestgroupC;
bestGroupC.bestvalue=0;
foreach it,value in Item_map {
int boost = to_float(( ValueA * value.boostA + ValueB * value.boostB + ValueC * value.boostC ) * value.turns);
if (value.exclusive=="GroupA"){
if(bestgroupA.bestvalue < boost | bestgroupA.bestvalue == 0)
bestgroupA.bestvalue = profit; bestgroupA.it=value.it;
}
if (value.exclusive=="GroupB"){
if(bestgroupB.bestvalue < boost | bestgroupB.bestvalue == 0)
bestgroupB.bestvalue = profit; bestgroupB.it=value.it;
}
if (value.exclusive=="GroupC"){
if(bestgroupC.bestvalue < boost | bestgroupC.bestvalue == 0)
bestgroupC.bestvalue = profit; bestgroupC.it=value.it;
}
}
print("The best is "+bestgroupA.it+" for a boost of "+bestgroupA.bestvalue);
print("The best is "+bestgroupB.it+" for a boost of "+bestgroupB.bestvalue);
print("The best is "+bestgroupC.it+" for a boost of "+bestgroupC.bestvalue);
I tried to figured out how ZapWizard does it, but it's a bit overwhelming.
Thanks
--Grab