void Ship_SetSailState(int iCharacterIndex, int iSailState)
{
if (iCharacterIndex < 0) return; // bugfix here too
if (iSailState < 0) iSailState = 0;
if (iSailState > 2) iSailState = 2;
// NK, Amokachi -->
ref rCharacter = GetCharacter(iCharacterIndex);
if (CheckAttribute(rCharacter, "Ship.Sink")) return;
if (CheckAttribute(rCharacter, "Ship.Sails.Delay")) return; // PB
if (IsMainCharacter(rCharacter)) {
if (!CheckAttribute(rCharacter, "LastSailState")) rCharacter.LastSailState = iSailState;
if (iSailState == sti(rCharacter.LastSailState)) return;
if (actLoadFlag == 0) {
switch (iSailState)
{
case 0:
Log_SetStringToLog(TranslateString("", "Strike all sail!"));
break;
case 1:
Log_SetStringToLog(TranslateString("", "Battle sails!"));
break;
case 2:
Log_SetStringToLog(TranslateString("", "Make all sail!"));
break;
}
if (ENABLE_EXTRA_SOUNDS == 1) { // added by KAM after build 11 // KK
if (sti(rCharacter.LastSailState) > iSailState) {
PlayStereoSound("#sails_down");
} else {
PlayStereoSound("#sails_up");
}
}
}
if (SAIL_OPERATE_DELAY == 0 || iRealismMode == 0) {
rCharacter.LastSailState = iSailState;
DeleteAttribute(rCharacter, "Ship.Sails.Delay"); // PB: Just in case
} else {
int morale = MORALE_NORMAL;
if (CheckAttribute(rCharacter, "Ship.Crew.Morale")) morale = sti(rCharacter.Ship.Crew.Morale);
rCharacter.Ship.Sails.Delay = SAIL_OPERATE_DELAY + round(makefloat(MORALE_NORMAL - morale) / makefloat(MORALE_NORMAL));
rCharacter.Ship.Sails.Delay.StartTime = GetSeaTime();
rCharacter.Ship.Sails.Delay.SailsState = iSailState;
return;
}
}
// NK, Amokachi <--
float fSailState = makefloat(iSailState) / 2.0;
fSailState = clampf(fSailState); // NK 05-04-20 bugfix
SendMessage(&AISea, "laf", AI_MESSAGE_SHIP_SET_SAIL_STATE, rCharacter, fSailState);
}