iamthejarha
Landlubber
Yes, I already know the first question you probably have. "Why do we need a mod for this, when we can already rename ships in the game?" Well, this idea started out with a very simple desire: the desire to have unavailable characters in my ship names. The apostrophe is the most notable instance. With the way the game's set up, you can't have the Queen Anne's Revenge, for example, because the apostrophe isn't included on the `in-game` 'keyboard.' The real coding gurus have much more important things to work on than trying to add an apostrophe (or exclamation point, or question mark, or anything else your twisted pirate mind wants to add <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid="
" border="0" alt="wink.gif" /> ), so I decided to work it out. I did this for my own game, but I'm offering it here in case any of you have wanted to do the same thing.
The modifications are somewhat numerous, but simple. I created a function that does the actual `name-changing`, with checks to ensure that you don't accidentally rename ships with blank names or try to rename a ship that doesn't exist, then set the process to a hotkey--in this case, the V key. The ship names are stored in BuildSettings.h, right beneath NK's name definitions. Even if you install this mod, you don't <i>have</i> to use it. Just leave the name slots blank, and the function won't change a thing. Now, this is the code and how it works.
First, the meat of the code goes into Reinit.c. I put it at the very bottom.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// iamthejarha -->
void ChangeShipName(ref char)
{
string sh[4];
AddStr2Array(&sh, 0, FLAGSHIP);
AddStr2Array(&sh, 1, SHIP2);
AddStr2Array(&sh, 2, SHIP3);
AddStr2Array(&sh, 3, SHIP4);
int i, p;
int tc = 0;
for(i = 0; i < 4; i++)
{
p = GetCompanionIndex(char,i);
ref ch = GetCharacter(p);
if(p != -1 && sh != "" && sh != ch.ship.name)
{
DeleteAttribute(ch,"ship.name");
ch.ship.name = sh;
if(LogsToggle) Log_SetStringToLog("Changing ship name to " + sh + "...");
tc++;
}
}
if(tc == 0) { if(LogsToggle) Log_SetStringToLog("No ship names changed..."); }
}
// iamthejarha <--<!--c2--></div><!--ec2-->
Basically, what the function does is this: it creates an array (string sh[4]) with a total of four entries that stores the name of each ship as set (or not set) in BuildSettings.h. After initializing a few variables, it runs through the <b>for()</b> loop and checks three conditions before making any changes: if the ship exists (p != -1), if a name has been specified in BuildSettings.h (sh[] != ""), <i>and</i> if the name hasn't already been set (sh[] != ch.ship.name), the function will change the name as necessary. The last line runs just once, and prints to the log only if the function made no changes (tc == 0).
Here's where I put the definitions of each ship in BuildSettings.h:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->//************Name************
#define FIRSTNAME "Nathaniel" // put your character's first name between the quotes
#define LASTNAME "Hawk" // put your character's last name between the quotes
//then press N during the game to set your character's name to this.
// Change the names of your ships (optional; it isn't necessary to name them here!)
#define FLAGSHIP "Emily's Love" // Put the name of your flagship between the quotes
#define SHIP2 "" // Put the name of your second ship between the quotes
#define SHIP3 "" // Put the name of your third ship between the quotes
#define SHIP4 "" // Put the name of your fourth ship between the quotes
// Press V during the game to set your ships' names to these.<!--c2--></div><!--ec2-->
I inserted it directly beneath Nathan's name definitions. All you have to do is put your desired ship name(s) between the respective quotes. Or don't, it's totally optional.
To assign the function to its own keystroke, add this line to CONTROLSpc_init.c:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> // weather
//CI_CreateAndSetControls( "", "WhrPrevWeather", CI_GetKeyCode("KEY_M"), 0, false );
//CI_CreateAndSetControls( "", "WhrNextWeather", CI_GetKeyCode("KEY_N"), 0, false );
//CI_CreateAndSetControls( "", "WhrUpdateWeather", CI_GetKeyCode("KEY_B"), 0, false );
CI_CreateAndSetControls( "", "NK_NameChange", CI_GetKeyCode("KEY_N"), 0, false ); // NK
CI_CreateAndSetControls("", "JAR_ShipChange", CI_GetKeyCode("KEY_V"), 0, false ); // iamthejarha<!--c2--></div><!--ec2-->
Again, I inserted my code right beneath NK's `name-change` mod. In almost all cases, they're very close to each other, since the functions are related. You can, of course, replace "KEY_V" with any key of your choice. Just make sure that it isn't already used for something else first.
To complete the hotkey assignment, you need to add this line into Seadogs.c:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void ProcessControls()
{
string ControlName;
ControlName = GetEventData();
//trace("ProcessControls() : " + ControlName);
//if(ControlName == "WhrPrevWeather") { Whr_LoadNextWeather(-1); }
//if(ControlName == "WhrNextWeather") { Whr_LoadNextWeather(1); }
//if(ControlName == "WhrUpdateWeather") { Whr_UpdateWeather(); }
if(ControlName == "NK_NameChange") { ChangeName(GetMainCharacter()); } // NK
if(ControlName == "JAR_ShipChange") { ChangeShipName(GetMainCharacter()); } // iamthejarha<!--c2--></div><!--ec2-->
What that does is tell the game, "If the proper hotkey is pressed, execute the function 'ChangeShipName()' using the parameters from 'GetMainCharacter()'." Pretty simple, really.
If you don't want this function to update at the start of a new game or during reinitialization (pressing the 'I' key), that's all you have to do. If you want it to happen automatically during those instances, you need to add one more line to two files.
First, go back to Reinit.c and add a line near the top:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void Reinit(bool start, bool show)
{
int n,i,j;
ChangeName(GetMainCharacter());
ChangeShipName(GetMainCharacter());
bool oldlogs = LogsToggle;
LogsToggle = show;
if(LogsToggle) Log_SetStringToLog("Reinitializing...");<!--c2--></div><!--ec2-->
As you can see, the ChangeShipName() function is right beneath NK's ChangeName() function. Add this same line into CharactersCharacters_init.c, right beneath NK's ChangeName() function:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> ch.married = false;
// RM <--
ChangeName(GetMainCharacter()); // NK, this sets mainchar name to name in ..BuildSettings.h // Scheffnow - file renamed
ChangeShipName(GetMainCharacter()); // iamthejarha, this will set any/all of your ships to names in ..BuildSettings.h
// QUESTS BEGINNINGS<!--c2--></div><!--ec2-->
And that's all there is to it. I really don't know how useful this mod will be to anyone else, but I see no point in keeping it to myself. I've certainly taken enough from this forum, I feel almost obligated to give back whatever I can. So if this will be of some use for you, by all means, <i>use it.</i> And if it doesn't ... use it anyway! LOL

The modifications are somewhat numerous, but simple. I created a function that does the actual `name-changing`, with checks to ensure that you don't accidentally rename ships with blank names or try to rename a ship that doesn't exist, then set the process to a hotkey--in this case, the V key. The ship names are stored in BuildSettings.h, right beneath NK's name definitions. Even if you install this mod, you don't <i>have</i> to use it. Just leave the name slots blank, and the function won't change a thing. Now, this is the code and how it works.
First, the meat of the code goes into Reinit.c. I put it at the very bottom.
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// iamthejarha -->
void ChangeShipName(ref char)
{
string sh[4];
AddStr2Array(&sh, 0, FLAGSHIP);
AddStr2Array(&sh, 1, SHIP2);
AddStr2Array(&sh, 2, SHIP3);
AddStr2Array(&sh, 3, SHIP4);
int i, p;
int tc = 0;
for(i = 0; i < 4; i++)
{
p = GetCompanionIndex(char,i);
ref ch = GetCharacter(p);
if(p != -1 && sh != "" && sh != ch.ship.name)
{
DeleteAttribute(ch,"ship.name");
ch.ship.name = sh;
if(LogsToggle) Log_SetStringToLog("Changing ship name to " + sh + "...");
tc++;
}
}
if(tc == 0) { if(LogsToggle) Log_SetStringToLog("No ship names changed..."); }
}
// iamthejarha <--<!--c2--></div><!--ec2-->
Basically, what the function does is this: it creates an array (string sh[4]) with a total of four entries that stores the name of each ship as set (or not set) in BuildSettings.h. After initializing a few variables, it runs through the <b>for()</b> loop and checks three conditions before making any changes: if the ship exists (p != -1), if a name has been specified in BuildSettings.h (sh[] != ""), <i>and</i> if the name hasn't already been set (sh[] != ch.ship.name), the function will change the name as necessary. The last line runs just once, and prints to the log only if the function made no changes (tc == 0).
Here's where I put the definitions of each ship in BuildSettings.h:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->//************Name************
#define FIRSTNAME "Nathaniel" // put your character's first name between the quotes
#define LASTNAME "Hawk" // put your character's last name between the quotes
//then press N during the game to set your character's name to this.
// Change the names of your ships (optional; it isn't necessary to name them here!)
#define FLAGSHIP "Emily's Love" // Put the name of your flagship between the quotes
#define SHIP2 "" // Put the name of your second ship between the quotes
#define SHIP3 "" // Put the name of your third ship between the quotes
#define SHIP4 "" // Put the name of your fourth ship between the quotes
// Press V during the game to set your ships' names to these.<!--c2--></div><!--ec2-->
I inserted it directly beneath Nathan's name definitions. All you have to do is put your desired ship name(s) between the respective quotes. Or don't, it's totally optional.
To assign the function to its own keystroke, add this line to CONTROLSpc_init.c:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> // weather
//CI_CreateAndSetControls( "", "WhrPrevWeather", CI_GetKeyCode("KEY_M"), 0, false );
//CI_CreateAndSetControls( "", "WhrNextWeather", CI_GetKeyCode("KEY_N"), 0, false );
//CI_CreateAndSetControls( "", "WhrUpdateWeather", CI_GetKeyCode("KEY_B"), 0, false );
CI_CreateAndSetControls( "", "NK_NameChange", CI_GetKeyCode("KEY_N"), 0, false ); // NK
CI_CreateAndSetControls("", "JAR_ShipChange", CI_GetKeyCode("KEY_V"), 0, false ); // iamthejarha<!--c2--></div><!--ec2-->
Again, I inserted my code right beneath NK's `name-change` mod. In almost all cases, they're very close to each other, since the functions are related. You can, of course, replace "KEY_V" with any key of your choice. Just make sure that it isn't already used for something else first.
To complete the hotkey assignment, you need to add this line into Seadogs.c:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void ProcessControls()
{
string ControlName;
ControlName = GetEventData();
//trace("ProcessControls() : " + ControlName);
//if(ControlName == "WhrPrevWeather") { Whr_LoadNextWeather(-1); }
//if(ControlName == "WhrNextWeather") { Whr_LoadNextWeather(1); }
//if(ControlName == "WhrUpdateWeather") { Whr_UpdateWeather(); }
if(ControlName == "NK_NameChange") { ChangeName(GetMainCharacter()); } // NK
if(ControlName == "JAR_ShipChange") { ChangeShipName(GetMainCharacter()); } // iamthejarha<!--c2--></div><!--ec2-->
What that does is tell the game, "If the proper hotkey is pressed, execute the function 'ChangeShipName()' using the parameters from 'GetMainCharacter()'." Pretty simple, really.
If you don't want this function to update at the start of a new game or during reinitialization (pressing the 'I' key), that's all you have to do. If you want it to happen automatically during those instances, you need to add one more line to two files.
First, go back to Reinit.c and add a line near the top:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void Reinit(bool start, bool show)
{
int n,i,j;
ChangeName(GetMainCharacter());
ChangeShipName(GetMainCharacter());
bool oldlogs = LogsToggle;
LogsToggle = show;
if(LogsToggle) Log_SetStringToLog("Reinitializing...");<!--c2--></div><!--ec2-->
As you can see, the ChangeShipName() function is right beneath NK's ChangeName() function. Add this same line into CharactersCharacters_init.c, right beneath NK's ChangeName() function:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> ch.married = false;
// RM <--
ChangeName(GetMainCharacter()); // NK, this sets mainchar name to name in ..BuildSettings.h // Scheffnow - file renamed
ChangeShipName(GetMainCharacter()); // iamthejarha, this will set any/all of your ships to names in ..BuildSettings.h
// QUESTS BEGINNINGS<!--c2--></div><!--ec2-->
And that's all there is to it. I really don't know how useful this mod will be to anyone else, but I see no point in keeping it to myself. I've certainly taken enough from this forum, I feel almost obligated to give back whatever I can. So if this will be of some use for you, by all means, <i>use it.</i> And if it doesn't ... use it anyway! LOL