• 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!

Fixed "nations.c" does not properly deal with PRIVATEER_NATION

Grey Roger

Sea Dog
Staff member
Administrator
Storm Modder
While testing something in a quest which I'm writing, I got an "error.log" which pointed to problems in "nations.c". This is because the quest involved another use of PRIVATEER_NATION, and the same errors probably show up when it's used for the "Assassin" storyline and the "Smuggling for Thomas O'Reily" sidequest.

One problem is in function "InvalidNation", which doesn't take specific account of PRIVATEER_NATION the way it does for NEUTRAL_NATION and PERSONAL_NATION. It does have a catch-all line which ought to handle any other invalid nation codes, including PRIVATEER_NATION:
Code:
if (iNationType < -1 && iNationType >= NATIONS_QUANTITY)   return "unknown";   // NK
This, of course, won't work. iNationType can't be both less than -1 and greater than NATIONS_QUANTITY! "&&" should be "||".

Function "GetNationByType" has a check for nation numbers less than 0:
Code:
   if (iNationType < 0) iNationType = PIRATE;       // LDH fix
   return &Nations[iNationType];
But that doesn't handle nation numbers which are too high, e.g. 8 for PRIVATEER_NATION, so that's what caused one of the error messages. The other came from function "GetNationNameByType" which uses "InvalidNation" to filter out various fake nations, then ends with:
Code:
   ref rNation = GetNationByType(iNationType);
   return rNation.Name;
And if "InvalidNation" isn't working then a faulty value of iNationType will lead to faulty rNation which has no "Name".

Fixes:

In "InvalidNation", add a check for PRIVATEER_NATION and correct the catch-all condition:
Code:
   if (iNationType == PRIVATEER_NATION)                           return "privateer";   // GR
   if (iNationType < -1 || iNationType >= NATIONS_QUANTITY)   return "unknown";   // NK
In "GetNationByType", expand the check to filter out high nation numbers:
Code:
   if (iNationType < 0 || iNationType >= NATIONS_QUANTITY) iNationType = PIRATE;       // LDH fix
After that, when I ran my quest test again, there were no more errors about "nations.c".

Revised "nations.c" attached.
 

Attachments

  • nations.c
    63.6 KB · Views: 183
Back
Top