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

Tutorial Modding Tips & Tricks

Pieter Boelen

Navigation Officer
Administrator
Storm Modder
Hearts of Oak Donator
Here's a bunch of tricks that REALLY help me doing any sort of work with the PotC code:

1. Don't use Windows Notepad as text editor; I use Notepad++ which is much better, free and can be found here: http://notepad-plus-plus.org/download/v6.7.5.html

2. Another complete and utter lifesaver that I use is WinMerge: http://winmerge.org/downloads/
This allows you to compare code files and folders with each other and find all differences.

3. Add your PotC folder to the Windows Search Index: http://windows.microsoft.com/en-us/windows/improve-windows-searches-using-index-faq#1TC=windows-7
That way, when using the regular Windows search functionality, it won't just search in the filename, but also in the file CONTENTS! And it is QUICK!

You can now use Windows Search to find all files that contain reference to certain function or variable names.
Then open all in Notepad++ and use "search in all files" and you'll have a list of all uses. And all that within a minute or so.

This is all based on free programs and built-in Windows functionality, but unlocks some really quite powerful options.

4. The wonderful world of CONSOLE!
- Open PROGRAM\console.c
- Find:
Code:
void ExecuteConsole()
{
   ref pchar = GetMainCharacter();
   ref ch;
   int i;
   int limit;
- Immediately below the last line shown here, add whatever code you want to execute
- Press F12 while ingame to execute

If you use windowed mode, this allows you to execute any code "on the fly" while you're still in the game.
There are a whole bunch of pre-defined sections of code available in the switch statement below. Change switch(0) to whichever one you want.
Outcomment whatever code you want to use.

The default "0" case does the following things:
- If in boarding, enable reload (for if you get stuck during boardings)
- If ashore or in boarding, set player to player type (returns control if you are stuck and unable to move)

5. DumpAttributes allows you to to see all the data for any "reference" in the game, which could be a character or a location or a ship or anything else.
Easiest is to run this through console (see above). The results are put into compile.log; delete that file prior to running this line to get a "clean" one containing only the data you want.

Examples:
Code:
DumpAttributes(pchar);
DumpAttributes(characterFromID(character_id));
DumpAttributes(GetShipByID(id));
DumpAttributes(Locations[FindLocation(pchar.location)]);

6. TraceAndLog combines the LogIt/Log_SetStringToLog and Trace commands.
In other words, this logs something to the screen so you can see it while in the game, but also writes it to compile.log so that you can find it later.
 
Last edited:
I'm responding here to some questions asked in private because the answers may be interesting to others as well.

It seems one of the main questions is "where is such and such code located?" Often I do not know the answer to that myself, so I use the tricks from the opening post to find out.
That is always what I find a more relevant skill: You don't need to know all the answers by the top of your head, as long as you know how to get the answers when you need them.
Of course I do admit to having a bit of a headstart since the past 10 years playing around with the PotC code have at least taught me in what direction to search.

Generally speaking, the trick is to find some code that you DO know to find, then use the opening post tricks to find the other references to it and repeat that until you find what you look for.
Good places to start are often InternalSettings.h and BuildSettings.h as those contain toggles and definitions for a wide range of things that are used all over the PROGRAM folder.
Another good place is seadogs.c because that is the first file that is loaded when you start the game.

At the moment I am not near my game, so I'm writing the below from memory. Hopefully it can point you in the right direction, though.

1. Goods fetching quests ie tailor and shipyard:
The store delivery quest works fine so I see no need to alter it but as far as the Tailor, Shipyard quests do you know where the code is located for them and or if it's adjustable?. If not no worries I can always adjust the amount of goods in the store to counteract the cargo space. I think the store goods amount code setting is in InternalSettings.h if I'm not mistaken
@Levis would be the expert here, since he wrote that mod. If I recall, most Fetch Quest code is found in PROGRAM\QUESTS\quests_common.c (search for "fetch"), with some being in PROGRAM\DIALOGS (search for the generic files for blacksmiths, tailors and shipyards as those contain pretty much ONLY fetch quest code).

2. Ships cargo after boarding:
After some play testing I noticed that the ships I captured weren't utilizing my new cargo system very well I assume the goods are randomized just like the store for Warships and Traders?. If you know the location of the code for them I would appreciate it.
That is probably somewhere in the PROGRAM\SEA_AI folder. My first suggestion would be AIFantom.c because that is where all random sea encounter charactersa are created.

3. Smugglers:
Do you know where is the code for smuggled goods price is ? Going to need to alter it as well since smuggling will be way too profitable if I don't.
@Levis recently moved all smuggling related code into PROGRAM\smuggling.c so that is where I would start looking.
The prices are of course displayed through PROGRAM\INTERFACE\TradeBook.c so that might be another starting point.

4. Quest cargo bugs:
Are there any story quest lines that might be affected by increasing/decreasing the cargo of the ships that you know of?. I've only played through a few, Hornblower and Hoist the Colors mostly. If so can you please point them out so I can alter the script/ship as necessary.
There are indeed some. The main ones that spring to mind are the cargo carrying quests early in the Bartolomeu and Assassin storylines.
Those require you to carry a certain amount of cargo in order to continue. Therefore that amount of cargo must be able to fit in the hold of the ship you are given, otherwise you're stuck.
@Bartolomeu o Portugues and @Talisman, do you happen to know any other examples?

1. How did you learn to code the game?:
Is there a specific place you learned the code ie. college/tech/trade school or maybe a book or website?. Most of what I've learned in the game is by blind searching and trial and error lol.
While we have had a fair few coders here who have a proper programming background, I am not one of them.
In fact, my education prepared me for ship navigation, ship stability, engineering, electrics but not for programming. So I am pretty much completely self-taught.
I started with some simple programs on my graphical calculator in secondary school and some playing with VBA from a CD-course and made a higher/lower game that way.
But when I started here at PA! I had very little programming knowledge. I started out by manually merging other people's mods together for my own use.
Then eventually I (semi-)officially took over the merging job from the great @Nathan Kell (who was a proper programmer). This community was a great help to me to get started.

When I went to do an internship at a research institute five years ago as part of my education, suddenly I had to do programming for real.
But while I had never heard of this "MATLAB" thing before, when I started to work with it, it was like "hey, this is just like PotC code!" :cheeky
And now I no longer work at sea and find myself back at the research institute, pretty much doing programming for a living and still, as I always did, figuring it out as I go along.... ;)

2. Where can I learn how to code?:
If it won't set me back too far in time or cash, money being the greater concern. Is there a website or book I can buy/go to?. I know that they offer courses at my college in coding but I work during the evening and sleep in the day so a book I can read or something online would be a better fit for my schedule.
There are many ways and many places. A proper programmer might be able to give you proper advice here.
As mentioned above though, I never learned at school and never learned from a book so I can't really give you any references I've actually used.
One website that has been a great help to me though (in addition to Google) is http://www.matlabtips.com/ .
That is specifically about MATLAB but a lot of the logic applies to other languages as well and, as I mentioned, the PotC code is at least close enough to MATLAB that my familiarity with the one helped quite a bit with the other.

Other than that, the best way is to "learn by doing" and ask on the forum if you're not sure about anything so that we can point you in the right direction.

3. Would you mind testing/consulting on my mod?
Know you probably have tons already on your plate but I could really use the advice/second opinion on the goods settings and the price want to try to keep a nice balance between the amount of cargo space and the new cost of goods might make it a little bit more lucrative for players but I want to keep the game challenging as well.
I'll definitely advise you in whatever way I can. But when it comes to testing, I am not the right person for that one.
@Hylie Pistof would be the best for that and maybe @ANSEL and @Grey Roger too.
I myself haven't played the game properly in many, many years but am hoping to get to that again soon once I have sorted out my current main projects.

What I will probably do is to include your work in the Beta 3.5 WIP once you have something you'd like to get tested so that everybody can play with it and comment.
Then you can tweak it based on the feedback you get. And if the worst comes to the worst and it doesn't work out, we can always remove it later.
But while we're still in WIP stage, we can easily put stuff in there just to "see what happens". :wp
 
If you're working with windows 8 maybe you want your most used folders to keep their
proportions and positions on the desktop. This really speeds up modding for me. And avoids
a lot of mistakes too.

@Levis showed me the link to this Shellfolderfix program.
The picture is just an example of my desktop.
 

Attachments

  • shellfolderfix.7z
    1.7 MB · Views: 435
  • desktop.jpg
    desktop.jpg
    752.9 KB · Views: 457
There are indeed some. The main ones that spring to mind are the cargo carrying quests early in the Bartolomeu and Assassin storylines.
Those require you to carry a certain amount of cargo in order to continue. Therefore that amount of cargo must be able to fit in the hold of the ship you are given, otherwise you're stuck.
@Bartolomeu o Portugues and @Talisman, do you happen to know any other examples?
No, I don't remember any other examples.
 
Some more amazing modding tricks:

4. The wonderful world of CONSOLE!
- Open PROGRAM\console.c
- Find:
Code:
void ExecuteConsole()
{
   ref pchar = GetMainCharacter();
   ref ch;
   int i;
   int limit;
- Below this, add whatever code you want to execute
- Press F12 while ingame to execute

If you use windowed mode, this allows you to execute any code "on the fly" while you're still in the game.
There are a whole bunch of pre-defined sections of code available in the switch statement below. Change switch(0) to whichever one you want.
Outcomment whatever code you want to use.

The default "0" case does the following things:
- If in boarding, enable reload (for if you get stuck during boardings)
- If ashore or in boarding, set player to player type (returns control if you are stuck and unable to move)
- If you are not in danger, but the location is locked, unlock the location (safeguard for the Soldier Reinforcements and Merchant Guild changes)

5. DumpAttributes allows you to to see all the data for any "reference" in the game, which could be a character or a location or a ship or anything else.
Easiest is to run this through console (see above). The results are put into compile.log; delete that file prior to running this line to get a "clean" one containing only the data you want.

Examples:
Code:
DumpAttributes(pchar);
DumpAttributes(characterFromID(character_id));
DumpAttributes(GetShipByID(id));
DumpAttributes(Locations[FindLocation(pchar.location)]);

6. TraceAndLog combined the LogIt/Log_SetStringToLog and Trace commands.
In other words, this logs something to the screen so you can see it while in the game, but also writes it to compile.log so that you can find it later.

All three are definite life-savers for any sort of vaguely advanced modding efforts.

Edit: This is now added to the opening post as well.
 
Last edited:
This thread moved to the "Tutorials" forum.

I noticed we don't seem to have an easy-to-find "HEX editing" guide. Could someone write up a comprehensive one for future reference?
@Jack Rackham or @Hylie Pistof perhaps?

A general "adding locators to GM files" might be welcome too as that is quite a common thing to do, but newly joined modders may not be very familiar with that.
 
A general "adding locators to GM files" might be welcome too as that is quite a common thing to do, but newly joined modders may not be very familiar with that.
There's still my Locators Tutorial from ages ago which goes through what each locator is for, how they are formatted and how to change them using Excel.
It doesn't cover normal editing via TOOL though, so a tutorial on that would be welcome.
 
I volunteer then as I already have started on both. If you don't mind Hylie?

I don't know enough to write a guide. I used to know more but the tutorial I worked off of then is now long gone. Now all I can do is rename what is already there.
 
Back
Top