void procActionRepair()
{
int chrIdx = GetEventData();
int eRepType = GetEventData();
if(chrIdx<0) return;
if(!bSeaActive) return;
ref chref = GetCharacter(chrIdx);
if( LAi_IsDead(chref) ) return;
if(eRepType!=0)
{
float fMaterialH = GetEventData();
float fMaterialS = GetEventData();
}
if(bAbordageStarted)
{
if(eRepType==0)
{
PostEvent("evntActionRepair",BI_FAST_REPAIR_PERIOD,"ll", chrIdx, 0);
}
else
{
PostEvent("evntActionRepair",BI_FAST_REPAIR_PERIOD,"llff", chrIdx, eRepType, fMaterialH,fMaterialS);
}
return;
}
float hpp = GetHullPercent(chref);
float spp = GetSailPercent(chref);
float fRepairH,fRepairS;
if(eRepType==0)
//=====================================================
// Slow repair
//=====================================================
{
if(hpp<10.0)
{
fRepairH = 10.0-hpp;
if(fRepairH>BI_SLOW_REPAIR_PERCENT) {fRepairH=BI_SLOW_REPAIR_PERCENT;}
hpp += ProcessHullRepair(chref,fRepairH);
}
if(spp<10.0)
{
fRepairS = 10.0-spp;
if(fRepairS>BI_SLOW_REPAIR_PERCENT) {fRepairS=BI_SLOW_REPAIR_PERCENT;}
spp += ProcessSailRepair(chref,fRepairS);
}
if( IsPerkIntoList("LightRepair") ) {
PostEvent("evntActionRepair",BI_SLOW_REPAIR_PERIOD,"ll",chrIdx,0);
}
}
else
//======================================================
// Fast repair
//======================================================
{
float ftmp1,ftmp2;
int nMaterialH = GetCargoGoods(chref,GOOD_PLANKS);
int nMaterialS = GetCargoGoods(chref,GOOD_SAILCLOTH);
int nMatDeltaH = 0;
int nMatDeltaS = 0;
string goodsName;
if(hpp<90.0 && nMaterialH>0)
{
fRepairH = 90.0-hpp;
if(fRepairH>BI_FAST_REPAIR_PERCENT) {fRepairH=BI_FAST_REPAIR_PERCENT;}
ftmp1 = GetHullPPP(chref);
ftmp2 = fMaterialH + ftmp1*fRepairH;
if(ftmp2>nMaterialH)
{
fRepairH = (nMaterialH-fMaterialH)/ftmp1;
nMatDeltaH = nMaterialH;
fMaterialH = 0.0;
}
else
{
if(ftmp2>1.0)
{
nMatDeltaH = makeint(ftmp2);
fMaterialH = ftmp2 - nMatDeltaH;
}
}
hpp += ProcessHullRepair(chref,fRepairH);
}
if(spp<90.0 && nMaterialS>0)
{
fRepairS = 90.0-spp;
if(fRepairS>BI_FAST_REPAIR_PERCENT) {fRepairS=BI_FAST_REPAIR_PERCENT;}
ftmp1 = GetSailSPP(chref);
ftmp2 = fMaterialS + ftmp1*fRepairS;
if(ftmp2>nMaterialS) { fRepairS = (nMaterialS-fMaterialS)/ftmp1; }
fRepairS = ProcessSailRepair(chref,fRepairS);
if(fRepairS<=0.0)
{
nMatDeltaS = 0;
fMaterialS = 0.0;
nMaterialS = 0;
}
else
{
ftmp2 = fMaterialS + ftmp1*fRepairS;
if(ftmp2>1.0)
{
nMatDeltaS = makeint(ftmp2);
fMaterialS = ftmp2 - nMatDeltaS;
}
}
}
if(nMatDeltaH>0)
{
nMaterialH -= nMatDeltaH;
SetCharacterGoods(chref,GOOD_PLANKS,nMaterialH); // LDH probably should use this 29Jan09
}
if(nMatDeltaS>0)
{
nMaterialS -= nMatDeltaS;
SetCharacterGoods(chref,GOOD_SAILCLOTH,nMaterialS); // LDH probably should use this 29Jan09
}
if(hpp<90.0 && nMaterialH>0)
{ PostEvent("evntActionRepair",BI_FAST_REPAIR_PERIOD,"llff",chrIdx,1, fMaterialH,fMaterialS);
}
else
{ if(spp<90.0 && nMaterialS>0)
{ PostEvent("evntActionRepair",BI_FAST_REPAIR_PERIOD,"llff",chrIdx,1, fMaterialH,fMaterialS);
}
else
{ EnableUsingAbility(chref,"InstantRepair");
}
}
}
}