An odd bug popped up while I was playing "Tales of a Sea Hawk". I had just escaped from Speightstown with Rabel Yverneau's frigate and was making my way to Port Royale when I engaged a group of three pirate ships. Two were jackass barques which I couldn't catch, partly because my sails were still damaged from the escape and partly because frigates don't do as well as jackass barques when the wind is blowing from the side. But the third ship was a basic barque which eventually surrendered. The captain really did surrender so I made him an officer and put him back in command of his ship. After arriving at Port Royale and going through the shenanigans with Silehard, cursed pirates, being thrown into jail, and more Silehard, I went to the shipyard and sold the barque.
Which should not have been possible. The ship was carrying some coffee, which is contraband in Port Royale. "error.log" showed problems with "islands.c", where 'GetIslandByIndex' had been told to find island with index -1; and with "shipyard.c", where 'CheckForContraband' had failed to determine someone's island. Adding some "traceandlog" commands to various places nailed down the problem to 'GetCharacterCurrentIsland' in "CharacterUtilite.c":
A 'dumpattribute(_refCharacter)' showed that the ex-pirate companion captain was at location "None"! That has index 0, so 'locidx' was set to 0 and 'GetIslandIdxByLocationIdx(locidx)' returned -1.
I added a check that if it can't find an island for 'locidx' and '_refCharacter' is a companion, find the player's island instead - companions tend to be at the same place as you, otherwise they're not companions! With that check in place, 'CheckForContraband' worked correctly and the ship could not be sold with coffee aboard.
The fixed version of "CharacterUtilite.c" will be in the next update.
Which should not have been possible. The ship was carrying some coffee, which is contraband in Port Royale. "error.log" showed problems with "islands.c", where 'GetIslandByIndex' had been told to find island with index -1; and with "shipyard.c", where 'CheckForContraband' had failed to determine someone's island. Adding some "traceandlog" commands to various places nailed down the problem to 'GetCharacterCurrentIsland' in "CharacterUtilite.c":
Code:
int GetCharacterCurrentIsland(ref _refCharacter)
{
// KK -->
/*int curLocNum = FindLocation(Characters[GetMainCharacterIndex()].location);
if(curLocNum<0) return -1;
return GetIslandIdxByLocationIdx(curLocNum);*/
// PB: Make this work for companion ships while ashore too -->
string curLoc = "";
if (CheckAttribute(_refCharacter, "location.from_sea")) curLoc = _refCharacter.location.from_sea;
if (curLoc == "" && CheckAttribute(_refCharacter, "location")) curLoc = _refCharacter.location;
// PB: Make this work for companion ships while ashore too <--
int locidx = FindLocation(curLoc);
if (locidx < 0) return -1;
return GetIslandIdxByLocationIdx(locidx);
// <-- KK
}
I added a check that if it can't find an island for 'locidx' and '_refCharacter' is a companion, find the player's island instead - companions tend to be at the same place as you, otherwise they're not companions! With that check in place, 'CheckForContraband' worked correctly and the ship could not be sold with coffee aboard.
The fixed version of "CharacterUtilite.c" will be in the next update.