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

real sailing mod

hawkeye

Landlubber
Hi Sailors,

I was unhappy with my schooner running slower abeam than before the wind, so I imported the real sailing mod from the POTC build series into AOP.

What you need:
Supermod v1.1 with updates 1 and 2
new sinking system mod and officers fix

Then just replace the AIShip.c in the Program/sea_ai folder.

Of course you can also replace the functions by hand, if your AIShip.c is otherwise different than this one (only changed things between Hawkeye --> and Hawkeye <---).

Have fun with it and feel free to play with the values in Ships_ini.c (the fWindAgainstSpeed is the key value) in case your fav vessel does not behave like she should. (I only made sure, the schooner and the big square riggers are identical, especially the barque is a little different in this one because of her value of 3, should perhaps be 1 or 2 like other square riggers)
Also, the mysterious function RS_GetRigTypeDivisor() from the POTC Build mods is _not_ modelled in this piece, since I don't know, how the engine is behaving. Needs testing, I think...

Please do write comments, or improve it yourselves.

And of course I don't claim credits for this one, since it was just copying and some minor fixing.
All thanks to NK, I think he wrote the original functions.

edit:

Hmm, can't seem to find the file. Maybe I post the code itself:

You have to change the AIShip.c between the lines:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
if (fWindDotShip >= 0.0)
<!--c2--></div><!--ec2-->

and

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
fMaxSpeedZ = fMaxSpeedZ * (0.75 - fWindDotShip/3 - pow(abs(fWindDotShip), fWindAgainstSpeed));
<!--c2--></div><!--ec2-->

or just comment them out.

Then insert:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
    // Hawkeye -->
    //     okay, here is the REAL_SAILING stuff
    //     first get best point and closest point based on that fWindAgainstSpeed thingy
    //     doing that with a simple linear formula and the values of the Schooner and the big square riggers from POTC as fix points:
    float fClosestPoint = (0.45 / 7) - 0.25 - (0.45 / 7) * fWindAgainstSpeed;
    float fBestPoint    = (0.5 / 7) + 0.75 - (0.5 / 7) * fWindAgainstSpeed;
    //     that way, the Schooner and the big ships will sail as in POTC and the others will differ a bit due to fWindAgainstSpeed in Ships_init.c
    //     beware: fWindDotShip != fOffWind from POTC!!
    //     (fWindDotShip is 0 when wind from abeam, 1 when running before wind
    //      while fOffWind was 0.5 when from abeam and 1 when before wind)

    //     calculate max speed scalar running before wind (linear function of fWindAgainstSpeed)
    float fRBWMax = -0.01371 * fWindAgainstSpeed + 0.9187;
    //     calculate max speed scalar on a beam reach (lin fct(fWAS))
    float fBeam   = 0.09171 * fWindAgainstSpeed + 0.4263;
    //     calc min speed scalar on tack (again lin fct)
    float fTackSpeed = 0.03386 * fWindAgainstSpeed + 0.3741;
    //     all prev speed scalars are calculated so that resulting scalars for Schooner and big ships will be the same as in POTC,
    //     others not necessarily equal, but in same order of magnitude, as the physicist says;)

    //     okay, that is the fore play, now I will just copy the code of the original REAL_SAILING mod
    //     with some changes to account for different fOffWind thingy
    //     (fOffWind_POTC = 0.5 * (fWindDotShip_AOP - 1)
    //     also had to replace the defines (RS_CP_OFFSET and RS_BACKWIND) with the actual values 0.04 (doubled because of different angles) resp. -0.25
    //     (otherwise the ENGINE.EXE would not run the code on my machine)
    
    //begin speedscalar calcs
    float fTempSpeedZ = 1.0; // PRS3 and below
    //reorganized we only do one b2r calc.
    if(fWindDotShip > fBestPoint) fTempSpeedZ = Bring2Range(1.0, fRBWMax, fBestPoint, 1.0, fWindDotShip); //scale speedscalar between best point of sail and running before the wind        
    else
    {
            if(fWindDotShip > 0) fTempSpeedZ = Bring2Range(fBeam, 1.0, 0, fBestPoint, fWindDotShip); //scale speedscalar between beam reach and best point of sail
            else
            {
                if(fWindDotShip > fClosestPoint + 0.04) fTempSpeedZ = Bring2Range(fTackSpeed, fBeam, fClosestPoint + 0.04, 0, fWindDotShip); //fixed by Hook
                //scale speedscalar between closest point of sail and beam reach.
                else
                {
                    if(fWindDotShip > fClosestPoint - 0.04) fTempSpeedZ = Bring2Range(0.0, fTackSpeed, fClosestPoint - 0.04, fClosestPoint + 0.04, fWindDotShip); //ramp quickly from 0 to min speed with wind
                    else //if(fOffWind <= fClosestPoint - RS_CP_OFFSET). Because that's the only thing it _can_ be.
                    {
                        if (fClosestPoint < -0.4) fTempSpeedZ = Bring2Range(-0.25, 0.0, 0.0, fClosestPoint - 0.04, fWindDotShip); //allow backwards travel
                        else fTempSpeedZ = 0.0; //if not square rigged, can't be pushed back
                    }
                }
            }
    }
    //end speedscalar calcs

    //     and finally adjust fMaxSpeedZ
    fMaxSpeedZ = fMaxSpeedZ * fTempSpeedZ;
    // JK <--
<!--c2--></div><!--ec2-->

That's it.
 
Great stuff, Hawkeye! <img src="style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" /> This oughta git incorporated into the Mod package! <img src="style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" /> Mebbe ye kin upload yer file in a zip tew de FTP! <img src="style_emoticons/<#EMO_DIR#>/icon_wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="icon_wink.gif" />
 
<!--quoteo(post=166982:date=Oct 11 2006, 07:17 PM:name=Cyberops)--><div class='quotetop'>QUOTE(Cyberops @ Oct 11 2006, 07:17 PM) [snapback]166982[/snapback]</div><div class='quotemain'><!--quotec-->
will import it into the supermod, thanks for the convert hawkeye.
<!--QuoteEnd--></div><!--QuoteEEnd-->

wait a sec, just found an error on my side. Looks like the fWindDotShip is actually the cos of the angle between wind and ship, would make sense since it's called dot product, wouldn't it... <img src="style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />
Okay, changed the whole thing to use again the normalized angle fOffWind, but have to test it...
Will post again soon...
 
Okay Mateys,

I uploaded the AIShip.c in a .zip-File to the ftp. I changed the whole thing again to use the normalized angle value fOffWind, just like in the POTC build mods. Had to import some (two) functions to make that work:
float RS_CalcOffwind(float) to get that normalized value and float ClampAngle(float) which is used by the before mentioned function to get the ship and wind angles to the [0,PIm2] range.
I think you will understand the code, it's quite easy and was only copy-paste from the POTC AIShip.c with the builds installed.
Only thing I did was the calculations for fClosestPoint and fBestPoint as functions of fWindAgainstSpeed. I think that parameter needs some tuning, though. Eg. the barque has a value of 3, although she is a square rigged ship like the bigger ones. Should be 2 or even 1 imho. But who sails that thing anyway... <img src="style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />

Beware though, the AI is again likely to end up standing against the wind, as it did in POTC... At least that's a pretty good way to flee those encounters, if you're not up for a fight... <img src="style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />

Okay, I'm off... and be welcome write your opinions, maybe it's possible to improve that thing...
 
Ahoy Mateys,

just changed the AIShip.c to increase readability and added a small description to the archive.
The file is on the ftp. URL:

<a href="ftp://aop%40piratesahoy.org:piratesahoy@ftp.piratesahoy.org/AOP%20Real%20Sailing%20-%20AIShip.zip" target="_blank">ftp://aop%40piratesahoy.org:piratesahoy@f...0-%20AIShip.zip</a>

Have fun, and if you feel to change something, be welcome and give it to the community as well...
 
Back
Top