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:
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:
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:
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:
In "GetNationByType", expand the check to filter out high nation numbers:
After that, when I ran my quest test again, there were no more errors about "nations.c".
Revised "nations.c" attached.
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
Function "GetNationByType" has a check for nation numbers less than 0:
Code:
if (iNationType < 0) iNationType = PIRATE; // LDH fix
return &Nations[iNationType];
Code:
ref rNation = GetNationByType(iNationType);
return rNation.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
Code:
if (iNationType < 0 || iNationType >= NATIONS_QUANTITY) iNationType = PIRATE; // LDH fix
Revised "nations.c" attached.