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

How does the `name-change` function work? (Solved! ... sorta.)

iamthejarha

Landlubber
I'd like to create a small mod that allows me to change my main ship's name through a text file, the way build 11 uses BuildSettings.h to change the main character's name. Why do I want to do it that way? Simple; I want to have characters like apostrophes, which aren't available from the `in-game` 'keyboard.' I've been digging through code for hours, and the only things I've found on the `name-change` function are these small bits of code:

<i>In PROGRAMBuildSettings.h:</i>
#define FIRSTNAME ""
#define LASTNAME ""

<i>In PROGRAMCONTROLSinit_pc.c:</i>
CI_CreateAndSetControls( "", "NK_NameChange", CI_GetKeyCode("KEY_N"), 0, false );

<i>In PROGRAMseadogs.c:</i>
if(ControlName == "NK_NameChange") { ChangeName(GetMainCharacter()); }

<i>In PROGRAMCharacterscharacters_init.c:</i>
ChangeName(GetMainCharacter()); // NK, this sets mainchar name to name in ..BuildSettings.h


I haven't found a reference to the "ChangeName()" function <i>anywhere</i>. Is it built into the game engine or something? How does it reference the globals in BuildSettings.h? Essentially, <i>how does it work?</i> If anybody can help me figure this out, I'd greatly appreciate it. I want to use essentially the same process to change my ship name, but I'm having a rough go at it, to put it mildly.
 
Okay, I found the ChangeName() function defined in Reinit.c. Unfortunately, I don't entirely understand it. Here's the code:


void ChangeName(ref char)
{
DeleteAttribute(char,<b>"firstname"</b>);
char.name = FIRSTNAME;
char.lastname = LASTNAME;
<b>UpdateTitle(&char);</b>
}


I emboldened the parts I don't really understand. The reference to 'char' makes sense, but "firstname" is what I don't understand. In addition, what does "UpdateTitle()" do, exactly? I can sort of see how I'd create a similar function that would change a ship title, but I'm not certain how to update said changes. Should I use the same function? Would it work if I simply added "char.ship.name = SHIPNAME" into this function, or do I need to create a new one? I'm slightly lost. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />
 
I did it! I created a function to change the name of my main ship, based on the function created to change the main character's name.

It's actually a very simple function. I don't know if anyone else will use it--although in my opinion, it could come in very handy if you have a name with apostrophes that you want to keep when you capture new ships. Below I've listed the files that you need to edit, and the code that needs to be added. All of these files are in the PROGRAM folder or a subdirectory of it.


In BuildSettings.h:
<b>// This sets your main ship's name
#define SHIPNAME "your ship's name"</b>
<i>(I added this just beneath the #define keys for FIRSTNAME and LASTNAME.)</i>


In Reinit.c:
<b>ChangeShipName(GetMainCharacter());</b>
<i>(This is added at the top, just below the "ChangeName(GetMainCharacter());" function call.)</i>

<b>void ChangeShipName(ref char)
{
DeleteAttribute(char,"Ship.Name");
char.Ship.Name = SHIPNAME;
}</b>
<i>(This is the actual function that changes the ship's name. I just added it to the bottom of Reinit.c.)</i>


I also mapped the process to a hotkey, in this case 'V', which was one of the only keys I knew wasn't used for something else. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />


In CONTROLSinit_pc.c:
<b>CI_CreateAndSetControls("", "JR_ShipNameChange", CI_GetKeyCode("KEY_V"), 0, false );</b>
<i>(I added this a little more than halfway down the file, right beneath NK's mapping of 'N' to "NK_NameChange".)</i>


In Seadogs.c:
<b>if(ControlName == "JR_ShipNameChange") { ChangeShipName(GetMainCharacter()); }</b>
<i>(Again, this was added directly beneath the reference to "NK_NameChange" in the "ProcessControls()" function, about `two-thirds` of the way down the file.)</i>


In CharactersCharacters_init.c:
<b>ChangeShipName(GetMainCharacter());</b>
<i>(This call was added directly beneath NK's "ChangeName(GetMainCharacter());" call, almost halfway down the file.)</i>


That's all there is to it. I've already tested it, and it works like a charm, even with previously saved games!
 
Great mate! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" />

But you can't change the name of your ship in the shipyard?? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/huh.gif" style="vertical-align:middle" emoid=":huh" border="0" alt="huh.gif" />
No??
 
<!--QuoteBegin-CapitainDams+--><div class='quotetop'>QUOTE(CapitainDams)</div><div class='quotemain'><!--QuoteEBegin-->Great mate! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" />

But you can't change the name of your ship in the shipyard?? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/huh.gif" style="vertical-align:middle" emoid=":huh" border="0" alt="huh.gif" />
No??<!--QuoteEnd--></div><!--QuoteEEnd-->

Yes, you can change the name of your ships `in-game`, but the `in-game` keyboard is very restrictive. I like to have names with apostrophes (Emily's Love, Queen Anne's Revenge, etc.), which aren't allowed from within the game.

Of course, you can also simply change the name of your main ship from Characters_init.c, but if you capture ships and transfer over rather than purchasing new ships to replace your main ship, you can't keep the name you created. With this mod, you can do that. I also intend to do a little more coding and extend the functionality to include all four ship slots, but right now, I'm just happy that I was able to figure this one out on my own.
 
<!--QuoteBegin-CapitainDams+--><div class='quotetop'>QUOTE(CapitainDams)</div><div class='quotemain'><!--QuoteEBegin-->Alright mate! It's looks like a great mod!!<!--QuoteEnd--></div><!--QuoteEEnd-->

It's turning out pretty well, I think. I'm still working on a way to change the names of all four ships, but I don't want it to <i>automatically</i> happen on reinit or starting a new game. On top of that, I'm having trouble figuring out how to make sure that the function <i>doesn't</i> set a new ship name if a ship doesn't already exist. The problem is that new ships aren't set in Characters_init.c, so there's no real 'check' for it--I'm beginning to think that info is stored in each individual save file, in which case this whole idea is screwed. I'm going to test something, to see if changing other ship names in Characters_init.c has any effect. It probably won't work, but it's worth a shot, I suppose.

EDIT: After doing quite a bit of screwing around, trying to find a way to change the names of your other three ships, I haven't found a way to do it yet. If anyone knows, feel free to chime in. Otherwise, I'm satisfied with being able to change my main ship's name--this way I can capture all of my ships, instead of having to buy them just to keep the name. Huzzah! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />
 
Back
Top