// TIH --> proper time spent loading/unloading cargo Jul20'06
// divide by zero fix, time calc adjustment, prevents months (even a year) lost buying ammo or unloading whole ships
// first function logs their starting cargo numbers - called in interface initialization
// second function figures out how much time it will take after you are done dealing with all cargo - called when exiting interface
// changed to base it off WEIGHT not UNITS (imagine buying 15000 gunpowder (only 50 weight), you could lose 100 days with a small crew!!!)
void CreateStartingCargo()
{
if( CheckAttribute(refCharacter,"startingCargo") ) DeleteAttribute(refCharacter,"startingCargo");
int i;
string sfstr;
for(i=0;i<GOODS_QUANTITY;i++)
{
sfstr = "good" + i;
refCharacter.startingCargo.(sfstr) = GetCargoGoods(refCharacter,i);
}
}
void CargoTransferTimelapse()
{
ref mainRef = GetMainCharacter(); // LDH 26Nov06 added
if( TIME_MOVEGOOD < 1 ) {return;} // no need to bother if the mod has been disabled
if( CheckAttribute(GetMainCharacter(),"skipstoretime") ) {return;} // tutorial has no time spendature
if( !CheckAttribute(refCharacter,"startingCargo") ) {return;} // no attribute? no execute
int goodsTransfer = 0;
int newQty = 0;
int oldQty = 0;
string attrGood = "";
// go through their hold, and see what changed
// if no quantities changed for a good, then OBVIOUSLY you dont spend time transfering it !!!
int i;
string sfstr;
for(i=0;i<GOODS_QUANTITY;i++)
{
sfstr = "good" + i;
newQty = GetCargoGoods(refCharacter,i);
oldQty = refCharacter.startingCargo.(sfstr);
// if a change in quantity, add it to transfer
if ( newQty != oldQty ) {
goodsTransfer += makeint( ( abs(newQty - oldQty) / sti( Goods[i].Units ) ) * sti( Goods[i].Weight ) );
}
}
DeleteAttribute(refCharacter,"startingCargo");
if ( goodsTransfer <= 0 ) return; // dont do anything if no goods to move about
int tmpLangFileID = LanguageOpenFile("interface_strings.txt");// MAXIMUS
LogIt(LanguageConvertString(tmpLangFileID,"Crew begins transfer of") + " " + goodsTransfer + " " + LanguageConvertString(tmpLangFileID,"cwt of cargo."));
// now figure out the calculation of how long your crew will take
// int crewNum = GetCrewQuantity(refCharacter);
int crewNum = GetSquadronCrewQuantity(mainRef); // LDH 26Nov06
if (crewNum < 1) crewNum = 1;// if no crew, then captain alone has to transfer the goods
float leaderDivisor = makefloat( GetSummonSkillFromName(mainRef, SKILL_LEADERSHIP) * 0.05 );// leadership reduces time wasted
if (leaderDivisor <= 0) leaderDivisor = 0.01;// if a seriously poor leader (skill 0), then set to lowest
int timeToAdd = 60 + makeint(((TIME_MOVEGOOD * goodsTransfer) / crewNum) / leaderDivisor);// takes at least one hour
if ( timeToAdd > 10080 ) timeToAdd = 10080;// never go above 7 days for ANY transfer
// LDH 16Oct06 changed rounding to more accurately reflect time passed
if ( timeToAdd > 1440 ) {
// if ( makeint(round(timeToAdd/1440)) < 2 ) LogIt(LanguageConvertString(tmpLangFileID,"Transfer takes roughly a day"));// MAXIMUS
if ( round(timeToAdd/1440) < 1.5 ) LogIt(LanguageConvertString(tmpLangFileID,"Transfer takes roughly a day"));// MAXIMUS
else LogIt(LanguageConvertString(tmpLangFileID,"Transfer takes roughly") + " " + makeint(round(timeToAdd/1440)) + " " + XI_ConvertString("days"));// MAXIMUS
} else {
// if ( makeint(round(timeToAdd/60)) < 2 ) LogIt(LanguageConvertString(tmpLangFileID,"Transfer takes roughly an hour"));// MAXIMUS
if ( round(timeToAdd/60) < 1.5 ) LogIt(LanguageConvertString(tmpLangFileID,"Transfer takes roughly an hour"));// MAXIMUS
else LogIt(LanguageConvertString(tmpLangFileID,"Transfer takes roughly") + " " + makeint(round(timeToAdd/60)) + " " + XI_ConvertString("hours"));// MAXIMUS
}
AddTimeToCurrent(0, timeToAdd );
LogIt("Time: " + GetStringTime(GetTime())); // LDH 15Oct06 added time display
LanguageCloseFile(tmpLangFileID);
}
// TIH <--