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

Included in Build Realistic Game Mode: Modify NPC Tacking Behaviour at Sea

Hylie Pistof

Curmudgeon
QA Tester
Storm Modder
Pirate Legend
Years ago when the realism mod was being made I was one of the play testers. The AI ships were turning too quickly and tacking into the wind too well and leaving me behind badly. So I requested that they be detuned and they were.

Now years later I am tired of constantly just sailing away from the AI whenever there is a head wind. And there is almost always a head wind. Even when I give them much faster ships they have trouble keeping up.

So, would it be possible to make the AI better sailors?
 
I can't remember what you are referring to there.
All I know is that an "AI tacking feature" was added years ago that should have made them more "clever" in dealing with head winds.
But I don't know if that (still?) works like it was meant to.
 
It works like it always has methinks. I'm just getting tired of having to furl sails and wait on them when they have the faster ships. The tacking feature is it. They start furling sails far too soon when in a head wind.
 
The tacking mod is supposed to force them to alter course until the wind isn't from dead ahead anymore.
Are they still doing that at all?
 
YES!

They tack too often and also raise sails and slow down too soon before they start tacking.
 
The raising a lowering of sails probably isn't controlled by the same code.
In fact, I'm not sure we could control that at all.

The tack mod purely forces them to one side so they don't keep heading straight into the wind.
But there is nothing "clever" about that manoeuvre and NPC ships don't understand they need to keep their speed up to do it.
 
I'm not sure how to do anything about this, but I think this is the relevant code from PROGRAM\SEA_AI\AIShip.c:
Code:
//TM --> Detect when non player ship is sailing into wind and use rotate function to turn it out of wind
     float fTacking2 = 0;
     
     if (iCharacterIndex != GetMainCharacterIndex()) {
       if (fSeaExpTimer > 5) {
         if(fOffWind < fClosestPoint + (RS_CP_OFFSET * 8) && fOffWind > fClosestPoint && fSailState > 0.0) {Ship_SetSailState(iCharacterIndex, 1.00);};
         if(fOffWind < fClosestPoint) {
           if (fSailState > 0.0) {   
             Ship_SetSailState(iCharacterIndex, 0.001);
             float fTacking = stf(arCharShip.Speed.y);
             if(fTacking <= 0) {fTacking2 = -0.0015; arCharShip.Impulse.Rotate.y = fTacking2;}; //Left     
             else {fTacking2 = 0.0015; arCharShip.Impulse.Rotate.y = fTacking2;}; //Right         
           } else {
             arCharShip.Impulse.Rotate.y = 0
             fTacking = 0
             fTacking2 = 0
           }
         } else {
           arCharShip.Impulse.Rotate.y = 0
           fTacking = 0
           fTacking2 = 0
         }
       }
     }
// <-- TM

As far as I can tell, it should still work and indeed does contain lines to raise/lower sails.

There are the following numbers to play around with:
Code:
#define RS_CP_OFFSET   0.02 // fudge on either side of Closest Point
And that "*8" multiplier in the code I quoted above.

Not sure what effect those numbers would have, but that is what you would probably need to edit.
Somehow. :confused:
 
They work like they always have as the only thing that has changed is my attitude.
 
You could try to the code I quoted above altogether and see if that is better or worse.
 
It is in that same AIShip.c file, near the top.
Just use Find and you should get to it.

Not sure if that one should be edited though.
For now, my suggestion would be to remove that first section marked TM and see what difference that makes.
 
So I changed that 0.02 to -0.02 and the ships seem to follow me a lot better without getting hung up on the wind much at all. Maybe they are too good, or maybe not.
 
So I changed that 0.02 to -0.02 and the ships seem to follow me a lot better without getting hung up on the wind much at all. Maybe they are too good, or maybe not.
As long as that number is positive, the "sail luffing sound" and "tacking behaviour" should kick in before you are actually caught in irons.
I think if you make it negative, effectively those two things will technically happen "too late".
So no more advance warning from the "sail luffing sound" based on what I understand of it.

Maybe instead of doing that, see what happens if you replace this line:
Code:
if(fOffWind < fClosestPoint + (RS_CP_OFFSET * 8) && fOffWind > fClosestPoint && fSailState > 0.0) {Ship_SetSailState(iCharacterIndex, 1.00);};
With this:
Code:
if(fOffWind < fClosestPoint) && fOffWind > fClosestPoint && fSailState > 0.0) {Ship_SetSailState(iCharacterIndex, 1.00);};
 
What does that do? To me it looks like a "gross" adjustment while changing the numbers in that other line is more of a "fine" adjustment.

Anyways, I went from 0.02 to -0.02 and sailed around for a while. I am sailing the CastelF which sails into the wind VERY well. The other ships are another CastelF and a Postiliionen square rig frigate which sails into the wind very well for the type.

The other CastelF followed me like a shadow while the Postillionen struggled a bit but recovered quickly and caught up using its better speed.

So I set it to 0.00 and they are still keeping up well in the first testing. Overall they are doing better than they used to, which keeps the fleet together much better.
 
My suggestion effectively sets that value to 0.0, but ONLY in the code that deals with the tacking itself.
Changing the define also affects the sail luffing sound, which I do not think is a good idea.

So if you say 0.0 seems to work well, try my suggestion and it should work equally well.
Just without affecting extra stuff as well.
 
This is for the NPCs isn't it? If so I will not be affected by changing the luffing sound. I'm not sure I even noticed any difference there.
 
This is for the NPCs isn't it? If so I will not be affected by changing the luffing sound. I'm not sure I even noticed any difference there.
That #define DOES affect the player luffing sound; just search through that AIShip.c file for "RS_CP_OFFSET" and you'll see that it is used in more places than one.
That is why I am suggesting to not edit it but modify ONLY the spot that you actually need changed.
 
Back
Top