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

Wind direction in the Caribbean

Tingyun

Corsair
Storm Modder
One fun aspect of Sid Meier's Pirates is that the wind mostly blew to the west, leading to interesting strategic choices for the player in deciding their trade routes. Also, for privateer hunting, it would factor into their ship sail type and the direction of possible escapes/targets/friendly ports.

From some research, it does seem in the real world winds in the Caribbean tend to blow towards the west: Caribbean Weather

WITH A TOGGLE I think having a tendency for winds to usually blow to the west could be interesting for the mod as well.

One interesting fact--Sid Meier's Pirates, on the lowest difficulty level, winds always blew exactly west, and they became more variable as difficulty level increased. In other words, for those who choose to play with them on, predictability of winds actually might reduce difficulty in ways, but really only insofar as they lead the player to be able to take advantage of intelligent strategic choices--which seems a really good thing!

At any rate, I think it is worth trying--shouldn't be any harm with a toggle. Of course, if needed I can try it first as part of the experimental version I maintaining if needed.

I spent a couple of hours trying to figure this out tonight, but didn't have much luck on my own. I am hoping I can request some advice and assistance?

I went over all the weather files, and here are the parts I thought looked relevant (also, the two files attached):

In WhrGeneration we have

Code:
//Traceandlog("WhrInit.c : Whr_Generator() called -- gWeatherInit: " +gWeatherInit); //JL - Figuring out this weather system
    bool bWhrTornado = false;
    bool bWhrStorm = false;
    if(gWeatherInit == 1){
        goldRain = rand(100);
        goldFog = rand(20);
//        oldWind = rand(30);
        oldWind = rand(25) + 5;        // LDH 09Feb09
        fWeatherAngleOld = frand(PIm2);

But why is it called "old"? Because it is initial value, or because it will be changed later?

And

rWindA = frand(MAX_ANGLECHANGE)

and

fWeatherAngleOld = fWindA;

and

Code:
string direction1, direction2, direction3;

    fSeaA = PIm2 - fWindA;
    if (fSeaA >= (3.0 * PId2))
    {
        fSeaB = (fSeaA + PId2 - PIm2);
    }
    else
    {
        fSeaB = fSeaA + PId2;
    }
    Weathers.Wind.Angle = fWindA;
    Weathers.Wind.Speed.Min = minwind;
    Weathers.Wind.Speed.Max = maxwind;

    direction1 = fts(fSeaB, 4);
    direction2 = fts((fSeaB + (PId2 / 2.0)), 4);
    direction3 = fts((fSeaB - (PId2 / 2.0)), 4);

Globals defines some of these values:
#define PIm2 6.283185307179586476925286766559 // 6.28318530
#define PId2 1.5707963267948966192313216916398 // 1.57079632


in WhrWeather.c we have

Weather.Wind.Angle = Whr_GetFloat(aCurWeather,"Wind.Angle");

and later

fWeatherDelta = 0.0;
fWeatherAngle = stf(Weather.Wind.Angle);



And then for changes we have
Code:
void Whr_OnWindChange()
{
   float fDeltaTime = MakeFloat(GetDeltaTime()) * 0.001;
   fWeatherDelta = fWeatherDelta + fDeltaTime;
   float fSpd = fWeatherSpeed + (fWeatherSpeed / 6.0) * 0.1 * (sin(fWeatherDelta) + sin(0.2 * fWeatherDelta) + sin(PI + 0.8 * fWeatherDelta) + cos(1.5 * fWeatherDelta));
   float fAng = fWeatherAngle + 0.02 * (sin(fWeatherDelta) + sin(0.2 * fWeatherDelta) + sin(PI + 0.8 * fWeatherDelta) + cos(1.5 * fWeatherDelta));
   Weather.Wind.Angle = fAng;
   Weather.Wind.Speed = fSpd;
}


Could anyone help me understand this code better? I think I have the general idea--an initial wind direction is generated, and then over time changed according to the last bit of code I quoted. But I'm having troulble grasping the specific, as well as how to weight it towards a particular direction.

I guess it would have to be weighted more likely to the west in two places, first in the initial wind generation, and then in the onwindchange part when it slowly changes direction, so it both is more likely to start west and also drift towards west over time? Or if I could find where the final wind is used in game, I guess I could just scale that number to a new wind range that is mostly to the west? I'm just trying to figure out how to get started, so I can then finetune the values through extensive playtesting, but I'm not sure how to begin.

Thanks so much for any help or advice. :)
 

Attachments

  • WhrGeneration.c
    9.8 KB · Views: 299
  • WhrWeather.c
    19.2 KB · Views: 291
Last edited:
This has been a wish of mine for years.
I've sailed around the actual Caribbean on a ship for a substantial amount of time, so I'm very familiar with the Beaufort 4 Eastern trade winds in the area.
But I never tried to add it to the game as I'm afraid it wouldn't be at all simple.
 
Pieter, what I'm thinking might work is this.

Find where the final wind angle is read.

Mathematically translate such that:
What used to be the 180 degrees around due west go to a 90 degree cone around due west, by doing a 2 to 1 function
What used to be the next 60 degrees from either side (ie total of 120 in two functions) then are sent by the function into the remaining 45 degrees on either side
What used to be the final 60 degrees pointing due east are sent to the remaining 180 degrees pointing eastward.

That should all work perfectly: the winds would change continuously all by the current function even at the boundaries, though changss would be more dramatic as the winds began pointing east (which makes sense if those are the rare winds).

I would then switch off that function in really stormy weather, and maybe soften the extent of the translation in some intermediate stormy state. The only suddenness would be that a sudden change of wind would portend the weather getting stormy, as it would get discontinous and have a sudden jump in angle at that time. Which wouldn't be a bad thing I think.

I can work out the math, all I would need is:

1) someone to help me identify where in the code I can insert that function to translate the angles. I would guess right before the final wind angle is read into game effect, but I am really unclear at to where. Ie If I am going to write an if( x< windangle < y) windangle= f(x) to do the translation, if someone can help me find where exactly to do that right at the end of everything.

2) Pieter to based on experience adjust the numbers above if they are wrong, ie, I have it set to a 60/360 chance of the wind pointing in any of the 180 degrees east, and 180/360 chance of being in a 90 degree cone around due west, that might be too dramatic or not dramatic enough a westerly direction

3) Pieter to tell me a bit about how storms and winds work. Ie, should we just switch off the function when it gets really rainy, because storms disrupt the usual wind? Or they don't really? Or soften it by degrees as the weather gets worse?

Anyway, if we followed that method I actually think it would be pretty easy, the math isn't hard to work out, and it couldn't really break anything as we aren't messing with the underlying calculation. But I'd need initial help on those 3, and then I think I could do it.
 
The stock game had no changing weather during scenes at all. Build 13 made "sudden jumps", but at least stuff changed.
Build 14 went further and made it into "gradual changes".

I am myself not very familiar at all with exactly how the relevant code works and I have been very hesitant to dive into it.
The amount of time required on my part might be substantial and since I don't have that time, it is on a very, VERY low priority from my side.

This is probably also because my ideal situation would require a complete and utter rewrite of the system.
I would want to have a "random weather system" that basically takes climatological data and throws some randomization on top for variety, then "overlay" storms on this.
That is, however, not easy and is something for the wish-list to do properly in Hearts of Oak some day, but for PotC I always figured it is quite out of scope.

If you want to try to do this using a simpler approach, you're very welcome to dive into the relevant code.
I'll be happy to try and explain to you what certain code (probably) does if you are confused by it.
But fact is that I am not at all an expert on this area of the PotC game code (nobody currently on the forum is), so I have no clue how feasible this might be.
 
Makes sense pieter, I might try to see what I can do in the meantime. Can I ask for non code guidance on 2 and 3 though, so purely your knowledge of how winds work in the caribbean?

Ie, about what percentage of the time do the winds blow west, is it nesrly always, or just most of the time, and how often do they drift towards north or south. General impressions are fine of course. :)

And what does the presence of a storm or rainy weather do to wind direction, does it then go unpredictable and likely to go east, or does it stay mostly pointing west still?

(Also, just curious, do winds near the coast of islands change or still mostly west?)
 
For climatological information, I'd recommend you have a look at the Pilot Charts here:
Maritime Safety Information
There is a separate file per month, because climatological winds/currents are considered to change every month.
These are classically used for navigation and weather routing of ships.

On these images, you can see some "compass roses" that indicate the various wind directions and their chances of occurring.
Refer to the explanantion written on there to understand how to read them.

Rainy weather doesn't necessarily influence the wind. But of course you have daily "sea breezes" and "land breezes" depending on your distance to land.

For the wind direction in storms, you get into meteorology with high pressure and low pressure systems:
http://scied.ucar.edu/sites/default/files/images/large_image_for_image_content/pressure_0.gif
The direction of rotation differs between the Northern and Southern hemisphere due to the Coriolis effect.

Long story short: Mostly the winds are from the East, but this changes a bit per month.
Land/sea breezes can modify the wind direction and speed depending on the time of day.
In addition to this, high islands could provide "shelter" for some of the areas of sea that lie behind them.
Storms are low pressure systems, so the wind will rotate counter-clockwise around the position of that low pressure system.
 
Got it. Never going to be modeled close to accurate this way, I see why you say it would need a compelte rewrite.

I might try a sid meir's pirates type version of a simplified system: western winds generally based on an average of months, and turn it off for storms so storms becomes completely random.

One worry, near islands we'd still have the western wind. Should we turn it off near islands to allow ships to enter ports easier? Or is there even a simple check for whether the ship is within sight of an island or is on the open ocean in direct sail?
 
I might try a sid meir's pirates type version of a simplified system: western winds generally based on an average of months, and turn it off for storms so storms becomes completely random.
Would be interesting for sure.

One worry, near islands we'd still have the western wind. Should we turn it off near islands to allow ships to enter ports easier? Or is there even a simple check for whether the ship is within sight of an island or is on the open ocean in direct sail?
It should be possible to find out the distance to land, or at least something similar, because the DirectSail island transfer code (CCCdirectsail.c) checks that too.
I'm not sure if it is necessary though to disable it near islands. More predictable wind direction might make entering/exiting ports easier; at least in some cases.
 
Got it, simpler that way too. I think this is actually very doable, unless I am missing something. Will be looking into it.

If anyone does have time to look over the specific code snippets I posted in the original post, and see if one looks like the place where final wind speed is used so I can plug my function in there, it would help out. But if noone understands them either, then I'll stare at it for a few more hours and plug things in random places and see if it starts making sense.:p
 
But why is it called "old"? Because it is initial value, or because it will be changed later?
The wind now changes gradually, so I would assume "old" is refers to the previous timestep so that the "new" will not be too much different from that initial value.

Could anyone help me understand this code better? I think I have the general idea--an initial wind direction is generated, and then over time changed according to the last bit of code I quoted. But I'm having troulble grasping the specific, as well as how to weight it towards a particular direction.
This will probably require some substantial research.
If you haven't used Trace/TraceAndLog yet to see what code does while being executed, you'll definitely end up needing that here.

What you could do is to add Trace lines EVERYWHERE so you'll get a compile.log showing exactly what happens during the various calculations.
That's what I normally do when I haven't got a clue what is going on. Bit labour-intensive, but also quite illuminating.
 
Thanks Pieter. I haven't used trace before, I'll check Levis's tutorials and see if there is an explanation on how.
 
Got it.

I really do think the simplified sid meier's pirates version is doable, and I'm rather excited about trying. In theory, as long as I can find the place where the final wind angle is, and I should be able to, the translation function will work perfectly and won't cause any disruptions to how any of the complex wind changes are handled.

Let's see how it works out when I actually try it. :)
 
I think we have the mathematical function we need, thanks to the kind contribution of user edderiofer over at reddit. (I wimped out and asked for advice ;) )

"Otherwise, you could try the function ((x-pi)^3)/(pi^2)+pi, which maps [0,2pi] to [0,2pi], and bunches everything closer to pi."

By adjusting the exponents to make it a bit more dramatic, 7 on the top and 6 on the below, then we have

((x-pi)^7)/(pi^6)+pi

So to test the 90% range, we plug in 1.9pi and get about 1.48 pi. Meaning 90% of the time the wind will blow in some westerly direction. I'll just have to translate it to whatever value the game uses for x, and we have the solution in maybe 3 lines, now I just have to figure out where to place those lines. And probably another line to turn it off when the weather gets bad.
 
Very cool! I really hope you manage to pull this off. It would be very nice indeed. :woot
 
If you do anything about this please let me know .... I personally would like it if the storm generation on the worldmap was more accurate too, and as far as I know storms are tied to wind speeds/directions a lot.
 
I personally would like it if the storm generation on the worldmap was more accurate too, and as far as I know storms are tied to wind speeds/directions a lot.
What do you mean? The worldmap is mostly handled by the engine side, so we have not much control over it.
 
What do you mean? The worldmap is mostly handled by the engine side, so we have not much control over it.
:wp remeber my earlier attempts at making the worldmap more interesting? I still want to get them back ... storm generation can be handled by code in some degree. You can increase or decrease the chance of a storm being generated depending on the location of the ship.
 
@Levis

I am indeed working on this! Right now I have only one missing thing to be able to do this: I need to find where the final wind speed is calculated, and then I will sub in this function, only called if a storm is not occurring:

((x-pi)^7)/(pi^6)+pi

That concentrates everything at pie, but has the full range of possibilities. Then I translate it to the correct angle for west.

And that should work perfectly. It is incredibly easy to do I think, and very safe, I just have to find the right part of that very complicated code where I can introduce a transformation on the final wind speed! :p
 
Back
Top