You can't ignore sail holes because that is precisely the measurement the engine is using to set the .SP value and you want to know how to arrive at that figure. The engine will send each sail through event "DoSailHole" (function ProcessSailDamage()). During a mast fall, sMastName will not equal "*" and holeCount will equal maxHoleCount. You could possibly record the number of holes for each fallen mast.
An idea that might work in ProcessSailDamage:
if(sMastName!="#") {
arSail.mastFall = sMastName;
if(CheckAttribute(chref, "mastFalls." + sMastName))
chref.mastFalls.(sMastName) = sti(chref.mastFalls.(sMastName)) + holeCount;
else
chref.mastFalls.(sMastName) = holeCount;
}
With that information, plus the example to arrive at the same engine .SP value below, should hopefully help.
Also, an example to arrive at the same .SP the engine calculates:
float CalculateShipSP(ref chref)
{
float fSP = GetCharacterShipSP(chref);
aref arRoot,arGroup,arSail;
int q,n,i,j;
int hc = 0;
makearef(arRoot, chref.ship.sails);
q = GetAttributesNum(arRoot);
for(i=0; i<q; i++)
{
arGroup = GetAttributeN(arRoot,i);
n = GetAttributesNum(arGroup);
for(j=0; j<n; j++)
{
arSail = GetAttributeN(arGroup,j);
if(!CheckAttribute(arSail, "dmg"))
{
arSail.dmg = 0.0;
}
if(CheckAttribute(arSail, "hc")) //Added for test to accumulate holeCount for each sail
{
hc += sti(arSail.hc);
}
fSP -= stf(arSail.dmg);
}
}
if(fSP<0.0) fSP = 0.0;
int st = GetCharacterShipType(GetCharacter(sti(chref.index)));
ref shref = GetRealShip(st); //This is .maxSP sent to engine in BI_objRetValue.maxSP from procGetSailTextureData() event
int ssP = sti(chref.ship.sails); //Engine stores cumulative maxHoles in .ship.sails root attribute
trace("ship.sails " + chref.ship.sails); //Engine stores cumulative maxHoles in .ship.sails root attribute
trace("hc " + hc); //Accumulated holeCount
trace("RSP = " + shref.sp); //This is the maxSP the engine will use to figure .SP
trace("CSP = " + chref.ship.sp); //This is engine recorded .SP
//ssP - hc is maxHoles - holecount
trace("SPtest = " + sti(shref.sp) * (ssP - hc) / ssP);
trace("fSP = " + fSP);
return fSP;
}
I just tested the following, by calling: CalculateShipSP(pchar);
This was the output in compile.log:
ship.sails 126
hc 9
RSP = 350
CSP = 325
SPtest = 325
fSP = 311.4
CSP is the engine recorded ship.SP
SPTest is figured from realship.SP * (chref.ship.sails - cumulative .hc) / chref.ship.sails