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

Changing ship names (new mod)

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
 
Yarr! Dat be a nice piece o' werk ye be doin' thar, matey! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />

Ye surely be thirsty now, so's have ye a rum on ol' Fred Bob! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/cheers.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="cheers.gif" />:
 
cool iamthejarha <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" /> this will be useful for people like me who spend more time collecting the perfect fleet and naming their ships than actually plundering and pirating <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/happy.gif" style="vertical-align:middle" emoid="^_^" border="0" alt="happy.gif" />
 
What the...?

The <i>exact same</i> code that worked yesterday is erroring out on me today! The code is unchanged from above, but here's what I'm getting <i>now</i> (this worked before!!!):

COMPILE ERROR - file: Reinit.c; line: 507
missed ')'

For reference, this is line 507:

if(FLAGSHIP=="" || FLAGSHIP==char.ship.name) Log_SetStringToLog("No change to flagship...");

Like I said, exactly the same as before, and I don't know about you, but I don't see any "missed ')'". I know it was mentioned somewhere that POTC doesn't always respond correctly to 'or' operators ('||'). Is that causing the problem? Hrm. I'll try rewriting it to use && instead of ||, see if that helps.

EDIT: UGH. I found the problem. Somehow, the code editor I started using has corrupted all the files it's edited. I've got to reinstall the whole thing just to make sure no other files are corrupted. For future reference, <b>DON'T USE CRIMSON EDITOR!</b>

By the way, does anyone have a preferential `syntax-coloring` text editor they'd like to recommend? It seems I'm in the market. :x
 
I use UltraEdit. <a href="http://www.ultraedit.com/" target="_blank">http://www.ultraedit.com/</a> - free trial, and IMHO well worth the price to register. I've used it for years.

Nathan Kell uses Source Insight <a href="http://www.sourcedyn.com/prodinfo.html" target="_blank">http://www.sourcedyn.com/prodinfo.html</a> which he says he cannot live without. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
i find that when it gives you line numbers with compile errors, the line numbers are almost always wrong <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/happy.gif" style="vertical-align:middle" emoid="^_^" border="0" alt="happy.gif" /> are you sure there's not a missed bracket <i>before</i> that line somewhere?
 
Usually I find that the error log gives me an error in a file I haven't altered, so I typically ignore it... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> Unless of course it crashes the game! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_eek.gif" style="vertical-align:middle" emoid=":shock:" border="0" alt="icon_eek.gif" /> But that's a good tip, Kieron, I hadn't noticed that before but I'll be looking for it now... <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" />
 
I've been trying out Notepad2, and it seems to be working pretty well thus far.

Kieron, I narrowed it down to a problem with my editor when I copied the information to a backup file in <i>Notepad</i>, and the exact same code worked. The only files that freaked out were ones I'd recently edited with Crimson Editor. I wiped out the old POTC folder and reloaded from a backup archive I made, and everything works fine now.

By the way, I rewrote the mod code, just streamlined it a bit (and removed the OR operators). Here's the new code--it does the exact same thing as the code at the top, so if that's working for you and you don't want to change it, don't worry about it.

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->EDITED to remove obsolete code--check first post for current code<!--c2--></div><!--ec2-->
 
Does Notepad2 do `syntax-highlighting`? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />
 
<!--QuoteBegin-CatalinaThePirate+--><div class='quotetop'>QUOTE(CatalinaThePirate)</div><div class='quotemain'><!--QuoteEBegin-->Does Notepad2 do `syntax-highlighting`? <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->

It sure does, Cat. The only things it doesn't have that Crimson did are a directory tree pane, and the ability to open multiple files in the same window. I miss those, but if this one doesn't screw up my code in any way, I can live without them. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" /> Cool. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="8)" border="0" alt="cool.gif" />

I love UltraEdit - does `multi-file` searching and all sorts of other handy things. Even has an Html Tidy which believe me is a true timesaver when you're a webmaster trying to fix files somebody else (or some program) has already screwed up! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />

I'll have to take a look at Notepad2! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/keith.gif" style="vertical-align:middle" emoid=":keith" border="0" alt="keith.gif" />
 
<!--QuoteBegin-CatalinaThePirate+--><div class='quotetop'>QUOTE(CatalinaThePirate)</div><div class='quotemain'><!--QuoteEBegin--><img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" /> Cool. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="8)" border="0" alt="cool.gif" />

I love UltraEdit - does `multi-file` searching and all sorts of other handy things. Even has an Html Tidy which believe me is a true timesaver when you're a webmaster trying to fix files somebody else (or some program) has already screwed up! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />

I'll have to take a look at Notepad2! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/keith.gif" style="vertical-align:middle" emoid=":keith" border="0" alt="keith.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->

Heh, it doesn't have all those features, but most importantly (for me, at least), it's <i>free,</i> and a great replacement for the standard Notepad--once I make sure it won't corrupt my files! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/tongue.gif" style="vertical-align:middle" emoid=":blah:" border="0" alt="tongue.gif" />
 
i just use windows notepad... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />

i can tell which of you use editor ultraedit, because it uses `non-win32` carriage returns, and when you open the edited files in windows notepad they have no line breaks <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_eek.gif" style="vertical-align:middle" emoid=":shock:" border="0" alt="icon_eek.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/laugh.gif" style="vertical-align:middle" emoid="xD:" border="0" alt="laugh.gif" />
 
Yup, none of those nasssssty linebreaks for ME! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
<!--QuoteBegin-Kieron+--><div class='quotetop'>QUOTE(Kieron)</div><div class='quotemain'><!--QuoteEBegin-->i just use windows notepad... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />

i can tell which of you use editor ultraedit, because it uses `non-win32` carriage returns, and when you open the edited files in windows notepad they have no line breaks <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_eek.gif" style="vertical-align:middle" emoid=":shock:" border="0" alt="icon_eek.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/laugh.gif" style="vertical-align:middle" emoid="xD:" border="0" alt="laugh.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->

That's one of the nice things about Notepad2: it can read (and insert) LF+CR (Win), LF (*nix), <i>or</i> CR (Mac) line endings. It really helps when I come across a file that has *nix line breaks--one click of a menu item, and I've got my Windows line breaks back. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="8)" border="0" alt="cool.gif" />
 
Yeah, I've got that too, it's word wrap. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
I updated the first post to publish the final version of this mod. The function is now set in a <b>for()</b> loop, which is what I'd envisioned all along and was finally able to achieve. It also avoids unnecessary log entries, and keeps Reinit.c from getting too bloated (the original mod had way too much code for such a simple function). This is the version I'd recommend for use. If you have any problems, let me know! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" />
 
<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" /> EXCELLENT! WTG, <b>iamthejarha!</b> Have a beer! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/beer2.gif" style="vertical-align:middle" emoid=":beer" border="0" alt="beer2.gif" />
 
Great, mate!!

Love this smiley <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/beer2.gif" style="vertical-align:middle" emoid=":beer" border="0" alt="beer2.gif" />
 
Thanks, mates! <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" />

Now I've just got to figure out why I keep replacing finished projects with increasingly more <i>difficult</i> projects, LOL! To quote Cat.. "<img src="http://www.ganotherapyusa.com/extras/modding.gif" border="0" class="linked-image" />" <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/dev.gif" style="vertical-align:middle" emoid=":d:" border="0" alt="dev.gif" />
 
Back
Top