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

Solved Ship Names Limited by Class and Type

Modder01

Freebooter
Storm Modder
Hi all, I have been throwing around the idea about not only getting more historical ship names into the game from POTC and COAS into the Historical immersion Mod, but also to limit them by class and by trade vs war designation.

Say for example the names for English ships were: Sure Prize, Bonadventure, and London. Say these names were limited to class 2 warships, then if there were traders of the class that were hybrids (were both traders and warships), they could access the warship names too.

My pseudo-logic would look like this:
if shipclass >= 6
if type == trader
trader names here
else
warship names here
else if shipclass == 5 || shipclass == 4
if type == trader
trader names here
else
warship names here
else if shipclass == 3
if type == trader
trader names here
else
warship names here
else if shipclass == 2 || shipclass == 1
warship names here

Has anyone attempted to do this in COAS or POTC? If so, I would like to use the ship names and a similar logic to this based off of the code they already have and make it a reality in the mod.
 
Hasn't been done, no. Should be possible though. I know at least PotC has a single function that generates ship names based on nationality.
I imagine it should be quite possible to add class and type to that.
 
AOP already has it based on nationality as well... When I get back home from school this weekend I will play around with it by first looking at the ship names in POTC and AOP2. Then I will try a version of the naming logic that you see up there and see if it works. I may have to call a battleinterface function to do it though... I am aware of the functions that I need in battleinterface because I discovered a way to make the Flying Dutchman have the custom sails that I was wanting to implement in version 4.0 of the mod, but never was able to until now.
 
OK I have run into a problem. :modding I tested it just for England and the ships don't have names at all. Here is my code and the error log:

Code:
#include "SHIPS/ships.h"
...
int i = GetShipByType(); //from ships.h
...
if((i >= 0 && i < 2) || (i >= 8 && i <= 11) || i == 12 || i == 17){
n = AddStr2Array(&sRndShpEnName, n, "Trader")
} else if((i >= 3 && i <= 4) || i == 7 || i == 14 || i == 16){
n = AddStr2Array(&sRndShpEnName, n, "Trader, Warship")
} else if(i == 6 || i == 7 || i == 13 || i == 15 || (i >= 18 && i <= 25)) {
n = AddStr2Array(&sRndShpEnName, n, "Warship")
}

Error.log:
COMPILE ERROR - file: SHIPS/ships.h; line: 1
define redefinition: SAILS_COLOR_QUANTITY
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 19
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 35
Invalid string argument
RUNTIME ERROR - file: utils.c; line: 39
Invalid string argument

Note: error log wasn't showing up (except for battle-interface errors which have no impact) before this change occurred in ships_name.c

This is the function I want to use from ships.h:
ref GetShipByType(int iType) { return &ShipsTypes[iType]; }

EDIT: I already know the problem. It needs an int argument which I cannot provide. I was thinking that the game could make the determination for itself based on the new ships generated, but I am wrong obviously...
 
Last edited:
In theory the logic for the int "i" value should determine any randomly generated ship basetype for randomly generated NPCs and put it into int i for the above logic.
Then the logic above will allow me to group the ship names by trade, war and trade/war hybrid by the int number assigned to it. When it goes through the logic, It will narrow down the amount of names that can be randomly generated for a given ship basetype.

For example: If a randomly generated group of SHIP_SLOOP_L, SHIP_WARSHIP and SHIP_LUGGER were to be generated before the logic was implemented, for each ship in the group a name would be randomly selected from a list of choices in this file. With this logic, Ship_Sloop_L is assigned the integer 3, Ship_Warship is assigned the integer 22, and Ship_ Lugger is assigned the integer 2; Determined by Ships.h. The logic now determines the random name strings that best fit the basetypes of each ship.

Ship_Sloop_L by logic is a trade war hybrid and so it has access to both trader and some minor warship names. Ship_Warship will only have access to the Warship names (limited to the most elaborate) for the largest warships. Ship_Lugger is considered a trade ship and thus will only have access to trader names...

The logic also allows me to consider tier of ship (while still looking at basetype) to determine how elaborate the name should be...

My problem is that whenever a new random NPC is generated I cannot capture that ship's basetypes (by ship basetype I mean like "SHIP_TARTANE = 0") int value until it goes to this file to have the name selected. I tried using the function defined as part of the code in Battleinterface.c that puts the dutchman's cursed sails on, but it gave me an invalid statement. Then I changed it to what you see now using Ships.h function as a template, but the function requires an int value.
 
Last edited:
Now I have switched to a different approach... Ships_name.c will retain it's original purpose....However Ships.c has been retrofitted with the following code for the SetRandomNameToShip and generateRandomNameToShip functions. I also added a second argument to the generate function and fixed the lack of addressing the second operand in dialogs.c where the only call of this function occurs.

Apparently SetRandomNameToShip is for all random encounters. For everything else such as escort quests and the like, the generateRandomNameToShip function is used to tell the player character by the NPC dialog what ship they need escorted or destroyed. Originally the functions divided ship names by nation. I expanded it with the following code so that each nation could be separated by trade, trade/war hybrid and two types of warships - small and large:
Code:
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
           } else {
               if(sti(rCharacter.ship.class) <= 6 && sti(rCharacter.ship.class >= 3) {
                   makeref(rMassiveOfNames, sRndShpEnSmWarName);
               } else {
                   makeref(rMassiveOfNames, sRndShpEnLgWarName);
               }
           }
Even though I put the references in ships_name.c the following error comes up in the error.log:
COMPILE ERROR - file: ships\ships.c; line: 41
invalid 2nd operand
 
A couple things...though you evidently abandoned the ships_name.c change from an earlier post, I can explain the error:

COMPILE ERROR - file: SHIPS/ships.h; line: 1
define redefinition: SAILS_COLOR_QUANTITY

You apparently added

#include "SHIPS/ships.h"
...
int i = GetShipByType(); //from ships.h

All of the includes in the Program script code is loaded into one large 'program' and you can't include files more than once if they are loaded at launch/compile time (an exception is code that is not loaded/included anywhere, but is used in a LoadSegment). So, you are being informed of a redefinition from the ships.h file. If you remove the #include "SHIPS/ships.h" from ships_name.c, that error would go away and you can still use the GetShipByType function as the ship.h is already included in the loaded program object.

Your latest problem requires more information:

COMPILE ERROR - file: ships\ships.c; line: 41
invalid 2nd operand

Line 41 is within void SetRandomNameToShip(ref rCharacter) and from your post, I gather you were really changing string generateRandomNameToShip(int iNation), which occurs at line 50, so we would probably need more information or a full posting to determine the syntax problem.
 
These are Lines 25-110 in ships.c:
Code:
void SetRandomNameToShip(ref rCharacter)
{
   ref rMassiveOfNames;
   if(!CheckAttribute(rCharacter, "nation"))
   {
       rCharacter.nation = PIRATE;
   }
   if(sti(rCharacter.nation) == -1)
   {
       rCharacter.nation = PIRATE;
   }

   switch (sti(rCharacter.nation))
   {
       case ENGLAND:
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
           } else {
               if(sti(rCharacter.ship.class) <= 6 && sti(rCharacter.ship.class >= 3) {
                   makeref(rMassiveOfNames, sRndShpEnSmWarName);
               } else {
                   makeref(rMassiveOfNames, sRndShpEnLgWarName);
               }
           }
       break;
       case FRANCE:
           makeref(rMassiveOfNames, sRndShpFrName);
       break;
       case SPAIN:
           makeref(rMassiveOfNames, sRndShpSpName);
       break;
       case PIRATE:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
       case HOLLAND:
           makeref(rMassiveOfNames, sRndShpHoName);
       break;
       case SMUGGLER:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
   }
   int iMassiveOfNamesSize = GetArraySize(rMassiveOfNames);
   rCharacter.Ship.Name = GetRandSubString(rMassiveOfNames[rand(iMassiveOfNamesSize-2)]);
}

string generateRandomNameToShip(int iNation, ref rCharacter)
{
   ref rMassiveOfNames;
   switch (iNation)
   {
       case ENGLAND:  
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
           } else {
               if(sti(rCharacter.ship.class) <= 6 && sti(rCharacter.ship.class >= 3) {
                   makeref(rMassiveOfNames, sRndShpEnSmWarName);
               } else {
                   makeref(rMassiveOfNames, sRndShpEnLgWarName);
               }
           }
       break;
       case FRANCE:  
           makeref(rMassiveOfNames, sRndShpFrName);
       break;
       case SPAIN:      
           makeref(rMassiveOfNames, sRndShpSpName);
       break;
       case PIRATE:  
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
       case HOLLAND:  
           makeref(rMassiveOfNames, sRndShpHoName);
       break;
       case SMUGGLER:  
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
   }
   int iMassiveOfNamesSize = GetArraySize(rMassiveOfNames);
   string sName = GetRandSubString(rMassiveOfNames[rand(iMassiveOfNamesSize-2)]);
  
   return sName;
}
line 41 refers to the second argument "sRndShpEnTraName" as part of the statement "makeref(rMassiveOfNames, sRndShpEnTraName);" Most like likely all of the English versions of this are affected (I did it only in English Names so that when that problem is fixed, I can apply it to the others with similar second args).

The reference in the second arg refers to the name of the argument in ship_name.c where in the English area I have the following:
Code:
   n = AddStr2Array(&sRndShpEnTraName, n, "Trader");
   n = AddStr2Array(&sRndShpEnHybName, n, "Hybrid");
   n = AddStr2Array(&sRndShpEnSmWarName, n, "Small Warship");
   n = AddStr2Array(&sRndShpEnLgWarName, n, "Large Warship");
Note: I put only one string in there on purpose to simplify to see if the code was working in game...
 
OK, if line 41 has sRndShpEnTraName as the 2nd parameter, your error is probably telling you that is not defined. Look at line 7 of Ships.c where the others are defined. Is it there? If not, add it similar to the others:

string sRndShpSpName[2], sRndShpEnName[2], sRndShpFrName[2], sRndShpPiName[2], sRndShpHoName[2], sRndShpPoName[2];

You can append a similar to the end, like so:

string sRndShpSpName[2], sRndShpEnName[2], sRndShpFrName[2], sRndShpPiName[2], sRndShpHoName[2], sRndShpPoName[2], sRndShpEnTraName[2];
 
That has been now appended for English ships only (for testing purposes) and now I have some syntax errors and missed parenthesis that I corrected. The logic now reads from lines 25-110:
Code:
void SetRandomNameToShip(ref rCharacter)
{
   ref rMassiveOfNames;
   if(!CheckAttribute(rCharacter, "nation"))
   {
       rCharacter.nation = PIRATE;
   }
   if(sti(rCharacter.nation) == -1)
   {
       rCharacter.nation = PIRATE;
   }

   switch (sti(rCharacter.nation))
   {
       case ENGLAND:
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
           } else {
               if((sti(rCharacter.ship.class) <= 6) && (sti(rCharacter.ship.class) >= 3)) {
                   makeref(rMassiveOfNames, sRndShpEnSmWarName);
               } else {
                   makeref(rMassiveOfNames, sRndShpEnLgWarName);
               }
           }
       break;
       case FRANCE:
           makeref(rMassiveOfNames, sRndShpFrName);
       break;
       case SPAIN:
           makeref(rMassiveOfNames, sRndShpSpName);
       break;
       case PIRATE:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
       case HOLLAND:
           makeref(rMassiveOfNames, sRndShpHoName);
       break;
       case SMUGGLER:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
   }
   int iMassiveOfNamesSize = GetArraySize(rMassiveOfNames);
   rCharacter.Ship.Name = GetRandSubString(rMassiveOfNames[rand(iMassiveOfNamesSize-2)]);
}

string generateRandomNameToShip(int iNation, ref rCharacter)
{
   ref rMassiveOfNames;
   switch (iNation)
   {
       case ENGLAND: 
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
           } else {
               if((sti(rCharacter.ship.class) <= 6) && (sti(rCharacter.ship.class) >= 3)) {
                   makeref(rMassiveOfNames, sRndShpEnSmWarName);
               } else {
                   makeref(rMassiveOfNames, sRndShpEnLgWarName);
               }
           }
       break;
       case FRANCE: 
           makeref(rMassiveOfNames, sRndShpFrName);
       break;
       case SPAIN:     
           makeref(rMassiveOfNames, sRndShpSpName);
       break;
       case PIRATE: 
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
       case HOLLAND: 
           makeref(rMassiveOfNames, sRndShpHoName);
       break;
       case SMUGGLER: 
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
   }
   int iMassiveOfNamesSize = GetArraySize(rMassiveOfNames);
   string sName = GetRandSubString(rMassiveOfNames[rand(iMassiveOfNamesSize-2)]);
 
   return sName;
}

Error log says:
COMPILE ERROR - file: ships\ships.c; line: 67
syntax error

This points to the ending brace of the first function's case statement.
 
The internal compiler does not behave entirely like a C program would and is a bit particular about if/else blocks. Add another set of brackets for the 'else' part of the beginning ENGLAND if statements in both functions, like so:

Code:
void SetRandomNameToShip(ref rCharacter)
{
   ref rMassiveOfNames;
   if(!CheckAttribute(rCharacter, "nation"))
   {
       rCharacter.nation = PIRATE;
   }
   if(sti(rCharacter.nation) == -1)
   {
       rCharacter.nation = PIRATE;
   }

   switch (sti(rCharacter.nation))
   {
       case ENGLAND:
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else {
               if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
               } else {
                   if((sti(rCharacter.ship.class) <= 6) && (sti(rCharacter.ship.class) >= 3)) {
                       makeref(rMassiveOfNames, sRndShpEnSmWarName);
                   } else {
                       makeref(rMassiveOfNames, sRndShpEnLgWarName);
                   }
               }
           }
       break;
       case FRANCE:
           makeref(rMassiveOfNames, sRndShpFrName);
       break;
       case SPAIN:
           makeref(rMassiveOfNames, sRndShpSpName);
       break;
       case PIRATE:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
       case HOLLAND:
           makeref(rMassiveOfNames, sRndShpHoName);
       break;
       case SMUGGLER:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
   }
   int iMassiveOfNamesSize = GetArraySize(rMassiveOfNames);
   rCharacter.Ship.Name = GetRandSubString(rMassiveOfNames[rand(iMassiveOfNamesSize-2)]);
}

string generateRandomNameToShip(int iNation, ref rCharacter)
{
   ref rMassiveOfNames;
   switch (iNation)
   {
       case ENGLAND:
           if(sti(rCharacter.ship.type.merchant)==true){
               makeref(rMassiveOfNames, sRndShpEnTraName);
           }else {
               if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
                   makeref(rMassiveOfNames, sRndShpEnHybName);
               } else {
                   if((sti(rCharacter.ship.class) <= 6) && (sti(rCharacter.ship.class) >= 3)) {
                       makeref(rMassiveOfNames, sRndShpEnSmWarName);
                   } else {
                       makeref(rMassiveOfNames, sRndShpEnLgWarName);
                   }
               }
           }
       break;
       case FRANCE:
           makeref(rMassiveOfNames, sRndShpFrName);
       break;
       case SPAIN:
           makeref(rMassiveOfNames, sRndShpSpName);
       break;
       case PIRATE:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
       case HOLLAND:
           makeref(rMassiveOfNames, sRndShpHoName);
       break;
       case SMUGGLER:
           makeref(rMassiveOfNames, sRndShpPiName);
       break;
   }
   int iMassiveOfNamesSize = GetArraySize(rMassiveOfNames);
   string sName = GetRandSubString(rMassiveOfNames[rand(iMassiveOfNamesSize-2)]);

   return sName;
}
 
Last edited:
Done... now two errors pop up:
COMPILE ERROR - file: ships\ships.c; line: 73
Duplicate variable name: rCharacter

When rCharacter for the second logic is fixed, this shows up:
COMPILE ERROR - file: ships\ships.c; line: 75
Duplicate variable name: rMassiveOfNames

Note: This also points to the variable in the second function. There has been no problems with either of these variables being used more than once, as they are redefined in different functions, before this logic change occurred.
 
If I copy/paste over just those two functions, it compiles fine, so it now sounds like perhaps another problem, outside those two functions that is not bracketed properly; either an include, or some other function. It might be helpful to get the full Ships.c in order to find it.
 
I might be wrong but looking at your logic I think you need to swap your first two tests (once you sort out your syntax problem). I have often seen the last bracket Compile error or the sudden appearance of variable name problems (often in a completely untouched piece of code) when I have screwed up a previously fine function by the odd parentheses or something else - happy days wasted there

Anyway it appears to me that a hybrid ship will also pass the first if
if(sti(rCharacter.ship.type.merchant)==true)
and therefore not enact the else element with && war, however if you test for the merchant && war case first (being the more specific criteria) it should pick up the hybrid but not the trader, then the next else the trader and if not that then the small or large warship.
 
Last edited:
I might be wrong but looking at your logic I think you need to swap your first two tests (once you sort out your syntax problem). I have often seen the last bracket Compile error or the sudden appearance of variable name problems (often in a completely untouched piece of code) when I have screwed up a previously fine function by the odd parentheses or something else - happy days wasted there

Anyway it appears to me that a hybrid ship will also pass the first if
if(sti(rCharacter.ship.type.merchant)==true)
and therefore not enact the else element with && war, however if you test for the merchant && war case first (being the more specific criteria) it should pick up the hybrid but not the trader, then the next else the trader and if not that then the small or large warship.
Thank you, that has been fixed. I always forget that C/C++ doesn't take the second argument of an && statement into account sometimes, unless it is the first if statement in the series.

If I copy/paste over just those two functions, it compiles fine, so it now sounds like perhaps another problem, outside those two functions that is not bracketed properly; either an include, or some other function. It might be helpful to get the full Ships.c in order to find it.
Attached is the full ships.c file with the edits from pedrwyth.
 

Attachments

  • Ships.c
    3.7 KB · Views: 291
From your file, you are missing the end bracket for an else, in both of the case ENGLAND:

The first if, then an else with a beginning {
But there is no matching end brace for that block...the last end brace is matching with the if() that directly follows that first else.

Should look like this:

Code:
case ENGLAND:
           if(sti(rCharacter.ship.type.merchant)==true && sti(rCharacter.ship.type.war)==true){
               makeref(rMassiveOfNames, sRndShpEnHybName);
           }else {
                if(sti(rCharacter.ship.type.merchant)==true){
                    makeref(rMassiveOfNames, sRndShpEnTraName);
                } else {
                    if((sti(rCharacter.ship.class) <= 6) && (sti(rCharacter.ship.class) >= 3)) {
                        makeref(rMassiveOfNames, sRndShpEnSmWarName);
                    } else {
                        makeref(rMassiveOfNames, sRndShpEnLgWarName);
                    }
                }
           } //This one was added
 
Last edited:
Still gets the same two errors despite copying and pasting the above to replace....

COMPILE ERROR - file: ships\ships.c; line: 73
Duplicate variable name: rCharacter

COMPILE ERROR - file: ships\ships.c; line: 73
Duplicate variable name: rMassiveOfNames
 
Still gets the same two errors despite copying and pasting the above to replace....

I just edited the post to comment the one I added that eliminated the error in the compile from the Ships.c I downloaded from your earlier post. Does that now match what you tried? It fixed it in my downloaded copy of your file. In your downloaded version, there were only two braces } after the last else.
 
Edited the file to the updated code above... now new errors...

COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Invalid Expression
COMPILE ERROR - file: islands\islands_loader.c; line: 63
Undeclared identifier: FindClosestShipofRel

called up the game twice...
Could it be related to my recent changes to ships_init and related models and textures?
I did add two new ships and replaced the models and textures of two more... The Brig SW has a few models in gm viewer that cannot be viewed... should I delete them? Maybe that will fix it?
 
Last edited:
Back
Top