More explainations will come later but I would like some people to test it now and give feedback .Okay let's see if I can describe the procedure see below for more details
1) the game looks which 3 towns are closes to you.
2) It gets the fleetsize (both merchant and militia ships) for these towns.
3) It uses a adapted form of the inverse square law to determine the shiprate at your distance
4) It determines if there are warring ships
5) Determine the percentage of trader vs militia ships
6) The ships which are used for warring are subtracted from the other ship rates conform the percentage
7) Everything is converted to a chance per X hours.
8) Check the time of the day and adjust the chance by it
9) Checks the state of the moon and adjusts chances by it
10) With these new chance the encounter are created by the old way but now multiple ships can be created at 1 time if the chance is larger then 100%.
11) Check the relations and set the nation of the ship.
Distance to town
It takes the player X and Z coords and the town X and Z coords and then determines the distance with SQRT((x1-x-2)^2+(z1-z2)^2)
Get fleet size
By now these are still fixed numbers, but this will change.
Inversed Square Law
The law works as follows, the shiprate is determined by:
The constant is a value between 0 and 100 which can be set for each type of fleet. Most of the other values are found by trail and error to get a nice distribution of the shiprate. This way when you are still within the coastal waters of the harbor of the town the shipsrate is the fleetsize. The ship rate is how many ships you can encounter at 1 day which somewhere sounds logical cause these ships normally want to be in port as short as possible, especially when they are still carrying a cargo.fleetsize * 2 * constant * island_radius^0.3 * distance_to_town^0.55
distance_to_town^2
Warring Ships
For the warring ships it looks at how many ships there are in the vicinity (by checking the shiprate). There has to be at least 2 ships to get warring encounters. The amount of ships which are warring is determined by:
The upper part generates a value by taking the total amount of ships in and exponential function. The totalships variable is shifted right 2 because the first part increases to quickly and this way the curve matches the expectance better. The part in bold is added to add a distance variable also. It checks the difference in distance between the two closest ports. And this value then is used to determine a percentage of warring ships which are "okay". This means that if you are right in the middel of two ports the full number is used while if you are in a port no warring ships will be created (almost ). The whole thing is dived by 100 just because it had to or I had to use smaller numbers in the whole thing.(totalships+2)^(1+(totalships+2)^0.1)*(1 - sqrt((d1-d2)^2) / 400)
100
Chance per X hours
The game updates the world map every X hours. This depens on various factors. The functions check when the last update was and change the variables so it always is correct. so if you would add the chances for the last 24 hours (so say if you have blocks of 4 hours you take 6 blocks and add the chances together) you will get the normal shiprate / 100.
Time of the Day
A sinus function is used to check the rate on the time of the day.
The sinus goes between 0,25 and 1,25 with 8 o clock being the turning point. it has a period of 24 hours.
(sin((TIME_IN_HOURS-8)/12*PI)+1,5)/2
For the pirate chance this value is substracted from 2 to get the pirate chance.
Chance larger then 100%
There is a loop going which check how large the chance is. Say the chance is 150% then the loop will see it has to do 2 runs and uses a chance of 150/2 for each run to determine if a encounter has to be created.
Check the relations
It checks the relation of the nation of the closest island. For traders it takes all neutral and friendly nations and the ship can be any of these nations.
For war ships it takes only the friendly ones.
For now it uses fixed values for each islands production rate. This will be made dependable on the islands gold and garrison. But I first need to check those numbers better and come up with good formula's.
This mod will already give you some sense of where it's going. For example you will notice most battles take place between islands and on the open sea you will encounter way less boats while close to the ports it can be quite busy.
I also want to add a day/night troggle later but this is a first version. please let me know what you think off it .
To install extract the folder to your ROOT pirates folder.
Most recent version is included in the WIP version of the build mod
Last edited: