So I wrote this function to calculate the required cargo space for a ship when performing an auto-buy:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->int GetSupplyWeight(ref Ship)
{
int i;
int weight = 0;
for(i=0;i<GOODS_QUANTITY;i++)
{
int getQty = 0;
if(i == GOOD_WHEAT && FOOD_ON)
{
getQty = 1+makeint(makefloat(Ship.MaxCrew) * FOOD_PER_CREW * WHEAT_DAYS);
}
if(i == GOOD_RUM && FOOD_ON)
{
getQty = 1+makeint(makefloat(Ship.MaxCrew) * FOOD_PER_CREW * RUM_DAYS);
}
if(i == GOOD_GUNPOWDER && CANNONPOWDER_MOD && Ship.CannonsQuantity > 0)
{
ref rCannon; makeref(rCannon,Cannon[Ship.Cannon]);
int needPwdr = 0;
float averageQty = 0.0;
if (USE_REAL_CANNONS) { averageQty = makefloat(sti(Ship.CannonsQuantity) * BALLS_PER + sti(Ship.CannonsQuantity) * GRAPE_PER + sti(Ship.CannonsQuantity) * CHAIN_PER)/3; }
else { averageQty = makefloat(sti(Ship.CannonsQuantity) * BALLS_PER + sti(Ship.CannonsQuantity) * GRAPE_PER + sti(Ship.CannonsQuantity) * CHAIN_PER + sti(Ship.CannonsQuantity) * BOMBS_PER)/4; }
float canCharge = makefloat(averageQty/makefloat(Ship.CannonsQuantity));
if(CheckAttribute(rCannon,"gunpowder")) needPwdr = sti(rCannon.gunpowder);
getQty = makeint((makefloat(Ship.CannonsQuantity) * needPwdr * canCharge) + (makefloat(Ship.MaxCrew) * 3));
}
if(i == GOOD_BALLS)
{
getQty = makeint(makefloat(Ship.CannonsQuantity) * BALLS_PER);
}
if(i == GOOD_GRAPES)
{
getQty = makeint(makefloat(Ship.CannonsQuantity) * GRAPE_PER);
}
if(i == GOOD_KNIPPELS)
{
getQty = makeint(makefloat(Ship.CannonsQuantity) * CHAIN_PER);
}
if(i == GOOD_BOMBS && USE_REAL_CANNONS)
{
getQty = makeint(makefloat(Ship.CannonsQuantity) * BOMBS_PER);
}
if(i == GOOD_SAILCLOTH)
{
getQty = makeint(makefloat(Ship.HP) * SAIL_PER);
}
if(i == GOOD_PLANKS)
{
getQty = makeint(makefloat(Ship.HP) * PLANKS_PER);
}
weight = weight + GetGoodWeightByType(i,getQty);
}
return weight;
}<!--c2--></div><!--ec2-->
I then want it use in ships_init.c as such:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if(GetSupplyWeight(refShip)>sti(refShip.Capacity)) refShip.Capacity = GetSupplyWeight(refShip);<!--c2--></div><!--ec2-->
The idea is that this would ensure that all ships would be able to carry the cargo they would need to perform a proper auto-buy. However, this doesn't work for me, because this function requires the goods and cannons to already be initialized. So I added the ordinary intialization code above my check as such:<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> if (LoadSegment("STORE\initGoods.c")) // PB: Need the goods first
{
InitGoods();
UnloadSegment("STORE\initGoods.c");
}
if(LoadSegment("cannons\cannons_init.c")) // PB: And the cannons too
{
InitCannons();
UnloadSegment("cannons\cannons_init.c");
}<!--c2--></div><!--ec2-->
Now I'm getting "undeclared identifier" errors on InitGoods() and InitCannons(). <img src="style_emoticons/<#EMO_DIR#>/boom.gif" style="vertical-align:middle" emoid=":boom" border="0" alt="boom.gif" />
I am thinking I am going to abandon all this and just make sure that food and rum is supplied before the cannonballs so that you get the most important supplies first. GRRR! <img src="style_emoticons/<#EMO_DIR#>/modding.gif" style="vertical-align:middle" emoid="

" border="0" alt="modding.gif" />