• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fix in Progress Companion can't find his island

Confirmed, the original version does not work properly. I added a couple of trace statements: if 'GetCompanionIndex(rPlayer, c)' was positive then show the character's name, otherwise show the slot number of the faulty captain. As I have a savegame in a port where a couple of ships are berthed, I relaunched one of them into slot 3 (the relaunch interface calls it slot 4 because it counts from 1). Then I put to sea, quit, and checked "compile.log". It did exactly what I expected. 'GetCompanionQuantity(rPlayer)' is 2 (me plus one companion), so it cycled from 0 to 2, reported my name, reported slots 1 and 2 as faulty, and didn't report slot 3 at all.
Thanks for confirming!

Looks like there are a couple other spots where the same thing might happen then.
PROGRAM\Characters\Levelling.c:
Code:
    //Now handle the companions
   if(group == XP_GROUP_PARTY)
   {
       capt = GetCharacter(FindCommanderIndex(chref));                                               // Get the commander of the fleet
       for (i = 0; i <= GetCompanionQuantity(capt); i++) {
           cn = GetCompanionIndex(capt, i);
           if (cn < 0) continue;
           chr = GetCharacter(cn);                                                                   // Reference to the character

PROGRAM\WorldMap\DailyCrewUpdate.c:
Code:
           for (i = 0; i < GetCompanionQuantity(pchar); i++) {
               chref = GetCharacter(GetCompanionIndex(GetMainCharacter(), sti(i)));
               if(CheckCharacterItem(chref,"cursedcoin"))
               {
                   if(!CheckAttribute(chref, "curseddays"))   chref.curseddays = 0;
                   chref.curseddays = sti(chref.curseddays) + 1;
               }
           }

PROGRAM\SEA_AI\AIShip.c:
Code:
           for (int i = 1; i < GetCompanionQuantity(GetMainCharacter()); i++) {
               ch = GetCharacter(GetCompanionIndex(GetMainCharacter(), i));
               if(rOurCharacter.index == ch.index)
               {
                   loc = &locations[FindLocation("Companion_Cabin_"+i)];
               }
           }
       }

PROGRAM\NK.c:
Code:
bool KrakenAttackEnabled()
{
   ref pchar = GetMainCharacter();
   ref ch;
   if(CheckAttribute(pchar, "KrakenAttack"))                       return false;   // No Kraken attack is available until a set time after the previous attack
   if(CheckAttribute(pchar, "ship.SubmergeDutchman"))               return false;   // No Kraken attack is available while the Dutchman is submerged
   for (int i = 0; i <= GetCompanionQuantity(PChar); i++) {
       ch = GetCharacter(GetCompanionIndex(pchar, sti(i)));
       if(GetAttribute(ch, "ship.type") == "CursedDutchman")       return true;   // Only the CURSED Flying Dutchman can call upon the Kraken
   }
   return false;
}
Mostly my own code, so... I'm sorry. :modding
 
As well as correcting 'i <= GetCompanionQuantity(PChar)' to 'i < COMPANION_MAX' and adding the check to skip invalid companion slots, I've also changed 'GetCompanionIndex(pchar, sti(i))' to 'GetCompanionIndex(pchar, i)'. You don't need to use 'sti' when i is already an integer. :p
 
I've also changed 'GetCompanionIndex(pchar, sti(i))' to 'GetCompanionIndex(pchar, i)'. You don't need to use 'sti' when i is already an integer. :p
In theory, you are right.
We've had issues before though where data types weren't as they seemed.
I wonder why that 'sti' was ever added.
You wouldn't do that just for shits and giggles; would you?
 
A quick test run shows that I didn't make any typos which would cause the game to crash, nor was there anything about these files in the log files. So the fixed versions using 'COMPANION_MAX' instead of 'GetCompanionQuantity(PChar)' are going into the update - thanks for alerting me to the errors! :onya
 
Back
Top