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

Add luffing sounds when too close to wind

LarryHookins

Buccaneer
Staff member
Storm Modder
Here's an addition for the realistic sailing mod. Give it a try and let me know how y'all like it.

When a ship tried to sail too close to the wind, the sails would "luff," that is, flap because the wind was going around the front of the sail instead of blowing behind it. It's easy enough to add this to the game.

In AIShip.c in the function Ship_UpdateParameters right after the line that says,

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->float fOffWind = RS_CalcOffwind(fWindAngle, fShipAngle);<!--c2--></div><!--ec2-->
... add the lines...

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
if(iCharacterIndex == GetMainCharacterIndex()) {
    if(fOffWind < fClosestPoint + RS_CP_OFFSET) {  // Begin as soon as speed decreases
        if (fSailState > 0.1) {    // don't play sound if sails are furled
            PlaySound("AMBIENT\SEA\sails1.wav");
            PlaySound("AMBIENT\SEA\sails2.wav");
            PlaySound("AMBIENT\SEA\sails3.wav");
        }
    }
}<!--c2--></div><!--ec2-->
The effect is pretty good. And it's more than just ear candy; it lets you know when you're too close to the wind when your attention is fixed on some enemy ship and you're not watching the ship speed. It also reminds you to lower your sails completely when coming about through the wind so that you don't get pushed backwards. If you don't want to hear the sound, simply furl your sails and it will stop. Note that it only plays the sound in realistic sailing mode.

Enjoy!

Hook
 
Nice. I'll add it to the Post Build 13 mods. <img src="style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
 
hey, this is a very cool idea! i already addet it to my game, but, when i sail too close to wind, it doesnt make 'luff', its making "luffluffluffluffluffluffluff..." maybe you shoud program a break, so that it's just bringing this sound one time =)
 
It plays three sounds at once. Maybe you should add an switch(rand(2)) function to it, so that it'll randomly play one sound file instead? Or you could add a different sound file; I have some that would work from Virtual Sailor (a sailing simulator).
 
The repeated luffing sound is almost exactly what I was trying for. The major problem is that the function is called once a second, so each set of sounds starts every second and you have some unwanted periodicity to it.

One of the best uses for this is when you're trying to sail as close to the wind as possible. The wind direction varies a bit, so the luffing starts and stops when you're sailing as close to the wind as you can. Sometimes this makes a difference when navigating around shores or enemy ships. <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

The flutter.wav from Virtual Sailor sounds good alone, but in the game it doesn't sound good at all, and it messes up the other sounds. I have no idea why. I also tried the sound from Man of War 2, but it didn't sound as good as the sails sounds from PotC. I even tried editing some of the wav files with the sound recorder, but they wouldn't play in the game after editing.

If you want to tone down the sound, try replacing the three PlaySound() calls with the following:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->switch (Rand(2))
{
case 0:
    PlaySound("AMBIENT\SEA\sails1.wav");
    break;
case 1:
    PlaySound("AMBIENT\SEA\sails2.wav");
    break;
case 2:
    PlaySound("AMBIENT\SEA\sails3.wav");
    break;
}<!--c2--></div><!--ec2-->

I also tried combinations, playing 1 and 2 on the first, 2 and 3 on the second, and 1 and 3 on the third. This doesn't sound much different from the original however, but does add a bit of randomness.

I'm sure the effect could use a bit more tweaking.

Hook
 
I found a way to get rid of the rhythmic periodicity of the sound. Change the main part to the following:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if(iCharacterIndex == GetMainCharacterIndex()) {
    if(fOffWind < fClosestPoint + RS_CP_OFFSET) {
        if (fSailState > 0.1) {    // don't play if sails are furled
            PostEvent("luffing_event",Rand(999));  // As many or few as sounds good
            PostEvent("luffing_event",Rand(999));  // As many or few as sounds good
            PostEvent("luffing_event",Rand(999));  // As many or few as sounds good
        }
    }
}<!--c2--></div><!--ec2-->
... and add the following lines to the bottom of the file:

<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// Make luffing sounds more random
#event_handler("luffing_event", "PlayLuffSound");
void PlayLuffSound()
{
    switch (Rand(2))
    {
    case 0:
        PlaySound("AMBIENT\SEA\sails1.wav");
        break;
    case 1:
        PlaySound("AMBIENT\SEA\sails2.wav");
        break;
    case 2:
        PlaySound("AMBIENT\SEA\sails3.wav");
        break;
    }

}<!--c2--></div><!--ec2-->

The effect sounds a lot better this way.

Hook
 
Nice! <img src="style_emoticons/<#EMO_DIR#>/w00t.gif" style="vertical-align:middle" emoid=":woot" border="0" alt="w00t.gif" />
 
<!--quoteo(post=149995:date=Jun 1 2006, 12:38 PM:name=YourObed't Serv't LordNe)--><div class='quotetop'>QUOTE(YourObed't Serv't LordNe @ Jun 1 2006, 12:38 PM) [snapback]149995[/snapback]</div><div class='quotemain'><!--quotec-->
if this works, it'll be pretty sweet
<!--QuoteEnd--></div><!--QuoteEEnd-->
"IF THIS WORKS"??????? Hey, you think I'd post something like this without testing it first? hehe <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

I have it in my game right now.

Hook
 
lol... I like it. <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> This isn't quite along the lines of sound, but I think we should try to develop a code that lets you reef your sails. It would look more realistic... not just a piece of square canvas that pops down and back up... it slowly comes in, bit by bit. We could also make it so the sailors on deck climb aloft when you press the sails keys.
 
The reefing might be possible. Depending on certain factors, the speed of raising/lowering is changed. If you can change this speed while raising/lowering the sails, you could make it look as if it's raised/lowered bit by bit. I also had the idea of adding in a delay, so that you give the order to raise sails, but it isn't executed at once. This is possible; I already have some code that does this, but it's unfinished.

I think the crew on deck is hardcoded, so you can't make them do anything upon the pressing of a button, I think.
 
Ok. Sounds good. We could at least try to code it so the sails are delayed, then they move up slowly a few feet, then a break in the action for a few seconds, then a little more, etc. I play Age of Sail II: Pirvateer's Bounty, which is COMPLETELY realistic. Takes about five minutes to take in sail and for the first rates... around two minutes to re-load the guns! I've had battles where I'm chasing a French frigate for nearly three hours... tacking and peppering them with my bow chasers. Finally caught the bugger... took off his mizzen and shredded the rest of his sails. A final broadside of grape at point blank nearly wiped out the crew! They were massing on deck to board us... idiots!
 
Back
Top