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

Improve the Sea AI

Screwface

Flibustier
Storm Modder
<img src="style_emoticons/<#EMO_DIR#>/hi.gif" style="vertical-align:middle" emoid=":gday" border="0" alt="hi.gif" />

When you log in an island, coastraiders and directencounters (if you used directsail mod), have initial tasks when they are logged and it seems those tasks not change according to the situation around the island.

As i was specially tired of those enemy ships (pirates or war) who systematically attack me even if they were far behind the island or if there were other targets close to them than me. I was also fed up with enemy ships who can detect and attack me through a "london fog" where they shouldn't see me normaly. So i wrote some functions to improve the Sea Ai around islands and update it frequently.

First, i introduced a new notion which is the visiblity range. In this mod, other ships have a visibility range. They can't see ships who are out of their visibility range. Basically, the visiblilty range is a beam of 3000 yards around the ship but in facts it is less because it decrease with the fog density. More the fog is dense, less the visibility range is and by night, it is divide by 2.

As hook did with the DirectsailCheckFrequency, i used the procUpdateTime function in LogInterface.c to update the Ai with a regular frequency (every 5 minutes but it is adjustable in the buildsettings). I also puted a toggle to active/disactive the mod in buildsettings.

So each time the mod is called, groups of coastraiders and directencounters analyse all the enemy ships (who can be player too) they have in their visibilty range and update their task according to their own and enemy types (pirate, war or trade) and power. If they have no enemy ships in their visibility range, task of the war or pirate ships is to really patrol around the island to find a target and the trade ships keep their initial task (moving or anchoring).

I wrote the mod and tested it and it works perfectly on my computer which is not very old but i don't know how it could work on an older pc. If someone want to test it, i have puted it on the ftp. It is made for alpha 9.5 and as i said before, i puted a toggle in buildsettings and frequency of the timer is also adjustable.

The Island environment is much improved where we can see interesting battles between NPCs. Player can also be a prey and hunted like the other ships but no more and no less. The mod could be more improve so comments and suggestions are welcome <img src="style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />
 
This sounds as a real improvement <img src="style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />. We need some more lively NPC's <img src="style_emoticons/<#EMO_DIR#>/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />
 
That sounds ABSOLUTELY INCREDIBLE! The apparent "infinite visibility" of other ships in a fog was really bothering me too.
I think this deserves a round of applause! <img src="style_emoticons/<#EMO_DIR#>/bow.gif" style="vertical-align:middle" emoid=":bow" border="0" alt="bow.gif" />
 
*CLAP CLAP CLAP*

They aren't super sighted people anymore!!!

<img src="style_emoticons/<#EMO_DIR#>/razz.gif" style="vertical-align:middle" emoid=":razz" border="0" alt="razz.gif" />

Good work Screwface
 
Would it be possible to add some "checking for false flag" code to these updates too?
I could imagine that the closer you get to an enemy ship, the higher the chance of your fake flag being detected.
However, at the moment all nations detect your flag at the moment you enter 3D sailing mode near an island and you are even notified of this! <img src="style_emoticons/<#EMO_DIR#>/piratesing.gif" style="vertical-align:middle" emoid=":shock" border="0" alt="piratesing.gif" />
 
<!--quoteo(post=319993:date=May 15 2009, 10:36 AM:name=Pieter Boelen)--><div class='quotetop'>QUOTE (Pieter Boelen @ May 15 2009, 10:36 AM) <a href="index.php?act=findpost&pid=319993"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Would it be possible to add some "checking for false flag" code to these updates too?
I could imagine that the closer you get to an enemy ship, the higher the chance of your fake flag being detected.
However, at the moment all nations detect your flag at the moment you enter 3D sailing mode near an island and you are even notified of this! <img src="style_emoticons/<#EMO_DIR#>/piratesing.gif" style="vertical-align:middle" emoid=":shock" border="0" alt="piratesing.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->

Actually your relations with other ships is according to the flag you hoist and i think that's a great idea to add a checking false flag code if you are too close of an enemy ship <img src="style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" />

I will look to add this possibility but i think that the chance to be detected should be also based on your reputation or leadership skill. Why should you be recognized if you are only an unknown anonymous pirate or enemy ?
 
Absolutely true. Your fame is already taken into account by the current recognizing code though.
I imagine the main thing that would needed to be done is to move the calculation from the "enter 3D sailing mode" point to your "5-minute task update" code.
That way you would have a chance to be recognized on every such update, rather than only at the beginning.
And then add an exponential(?) distance-related factor of some kind that increases the chance from 0 (far away) to maximum when you're up close.

I think that upon entering 3D sailing mode, the ship relations should be based on the flag you're flying, without any chance of being recognized.
Then if you get close to a ship that is hostile to you, but friendly based on your flag, there's a chance to be recognized that depends on the distance.
It could be that a 5-minute check wouldn't be enough for this though; you can get very close within 5 minutes.

Do you know if it is possible to set only those ships near you hostile, but not those further away?
For example, there's French ships on each side of an island and you are at war with France, byt flying Portuguese colours.
You'd get too close to the first French fleet and they'd turn hostile, but the other French fleet would not be aware of this and would remain friendly.
Unless they're actually within visible range as well, of course.
 
<!--quoteo(post=320027:date=May 15 2009, 01:15 PM:name=Pieter Boelen)--><div class='quotetop'>QUOTE (Pieter Boelen @ May 15 2009, 01:15 PM) <a href="index.php?act=findpost&pid=320027"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Do you know if it is possible to set only those ships near you hostile, but not those further away?
For example, there's French ships on each side of an island and you are at war with France, byt flying Portuguese colours.
You'd get too close to the first French fleet and they'd turn hostile, but the other French fleet would not be aware of this and would remain friendly.
Unless they're actually within visible range as well, of course.<!--QuoteEnd--></div><!--QuoteEEnd-->

I was wondering the same thing but actually i have no answer at this question. I need to perfect my knowledges in the nations and characters relations system. Maybe the SetCharacterRelationBoth function could bring a solution !

<!--quoteo(post=320027:date=May 15 2009, 01:15 PM:name=Pieter Boelen)--><div class='quotetop'>QUOTE (Pieter Boelen @ May 15 2009, 01:15 PM) <a href="index.php?act=findpost&pid=320027"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I think that upon entering 3D sailing mode, the ship relations should be based on the flag you're flying, without any chance of being recognized.
Then if you get close to a ship that is hostile to you, but friendly based on your flag, there's a chance to be recognized that depends on the distance.
It could be that a 5-minute check wouldn't be enough for this though; you can get very close within 5 minutes.<!--QuoteEnd--></div><!--QuoteEEnd-->

i completely agree but we need to add a check for players who wont' use the mod. In case where mod would set off, the detection of false flag would remain at the entrance of 3D sailing mode. For the 5 minutes frequency, it can be change to be less but i would like to have returns of how the mod reacts on different kind of processor before decrease or increase it <img src="style_emoticons/<#EMO_DIR#>/dunno.gif" style="vertical-align:middle" emoid=":shrug" border="0" alt="dunno.gif" />
 
<!--quoteo(post=320039:date=May 15 2009, 02:12 PM:name=Screwface)--><div class='quotetop'>QUOTE (Screwface @ May 15 2009, 02:12 PM) <a href="index.php?act=findpost&pid=320039"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I was wondering the same thing but actually i have no answer at this question. I need to perfect my knowledges in the nations and characters relations system. Maybe the SetCharacterRelationBoth function could bring a solution !<!--QuoteEnd--></div><!--QuoteEEnd-->You'd have to somehow change the relations between groups of ships instead of between nations; might be possible, but I'm not sure and can't check right now.

<!--quoteo(post=320039:date=May 15 2009, 02:12 PM:name=Screwface)--><div class='quotetop'>QUOTE (Screwface @ May 15 2009, 02:12 PM) <a href="index.php?act=findpost&pid=320039"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->i completely agree but we need to add a check for players who wont' use the mod. In case where mod would set off, the detection of false flag would remain at the entrance of 3D sailing mode. For the 5 minutes frequency, it can be change to be less but i would like to have returns of how the mod reacts on different kind of processor before decrease or increase it <img src="style_emoticons/<#EMO_DIR#>/dunno.gif" style="vertical-align:middle" emoid=":shrug" border="0" alt="dunno.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->True, agreed and fair enough. <img src="style_emoticons/<#EMO_DIR#>/yes.gif" style="vertical-align:middle" emoid=":yes" border="0" alt="yes.gif" />
Would it be possible to increase the frequency as you come closer to a (not yet) hostile ship?
And restore the frequency to the default when the ship turns hostile? It's only required to check frequently if there's a chance for the other ship going hostile.
For all other purposes, like those described in your first post, I think a 5-minute interval could be enough.
 
I can turn the frequency to 1 mn if you are closer to 1000 yards of the neutral ship, i think that could be good values ! This is in game time not in real time.

Plus, i found a way to turn only a group to hostile and not the complete nation. But for the moment, i already encounter some problems. First if you fire the ship, all the nation will become hostile. Plus if a ship around the island surrender, the ship who have turned to hostile will become again neutral until the next time he will recognize you <img src="style_emoticons/<#EMO_DIR#>/modding.gif" style="vertical-align:middle" emoid=":modding" border="0" alt="modding.gif" />
In facts, i succeed to turn only a group to hostile but each time the updaterelations() functions is called after an event, this group restore his initial relation of his nation with your flag <img src="style_emoticons/<#EMO_DIR#>/laugh.gif" style="vertical-align:middle" emoid="xD:" border="0" alt="laugh.gif" />
 
Well, if you fire on the ship yourself, it's fair enough if the whole nation goes hostile. After all, you opened hostilies.
Realistically there ought to be a delay, of course, but it's fine if there isn't. <img src="style_emoticons/<#EMO_DIR#>/dunno.gif" style="vertical-align:middle" emoid=":shrug" border="0" alt="dunno.gif" />

Short term memory loss? <img src="style_emoticons/<#EMO_DIR#>/24.gif" style="vertical-align:middle" emoid=":rofl" border="0" alt="24.gif" />
There should hopefully be some way to make ships that have already recognized you not forget that and do so again. <img src="style_emoticons/<#EMO_DIR#>/mybad.gif" style="vertical-align:middle" emoid=":facepalm" border="0" alt="mybad.gif" />
Maybe add a flag to the captains of that ship group like <i>Enemyship.recognized = true</i> or something like that.
Then those ships will remain hostile no matter what?
 
<!--quoteo(post=320099:date=May 15 2009, 09:36 PM:name=Pieter Boelen)--><div class='quotetop'>QUOTE (Pieter Boelen @ May 15 2009, 09:36 PM) <a href="index.php?act=findpost&pid=320099"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Well, if you fire on the ship yourself, it's fair enough if the whole nation goes hostile. After all, you opened hostilies.<!--QuoteEnd--></div><!--QuoteEEnd-->

No, it happens even if the enemy ship open hostilities first and if you respond to his fire. That's a problem because if you don't want to have the whole nation become hostile, you can't respond to the fire of the other ship <img src="style_emoticons/<#EMO_DIR#>/dunno.gif" style="vertical-align:middle" emoid=":shrug" border="0" alt="dunno.gif" />
So i will continue to persevere for a while to find a solution to this problem but i'm not sure that the relation system allows that <img src="style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" />
 
Man I can't find that file anywhere... I'm havin trouble with FTP commander, It says it can't find:
Error Unable to open local file C:\FTPDIR3541820.TXT
 
I don't really know how to help you with your ftp commander. Here is the parameters of the files ftp server.

PotC Files FTP Login Details:
Adress: 74.54.143.226
Username: potc@piratesahoy.net
Password: p1rate5ah0y

you will find the files in the screwface\Update Sea Ai mod\ folder
 
<img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I had to run it in Admin Settings! I'm using Vista! :p
 
<!--quoteo(post=320130:date=May 16 2009, 12:31 AM:name=Screwface)--><div class='quotetop'>QUOTE (Screwface @ May 16 2009, 12:31 AM) <a href="index.php?act=findpost&pid=320130"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->No, it happens even if the enemy ship open hostilities first and if you respond to his fire. That's a problem because if you don't want to have the whole nation become hostile, you can't respond to the fire of the other ship <img src="style_emoticons/<#EMO_DIR#>/dunno.gif" style="vertical-align:middle" emoid=":shrug" border="0" alt="dunno.gif" />
So i will continue to persevere for a while to find a solution to this problem but i'm not sure that the relation system allows that <img src="style_emoticons/<#EMO_DIR#>/unsure.gif" style="vertical-align:middle" emoid=":?" border="0" alt="unsure.gif" /><!--QuoteEnd--></div><!--QuoteEEnd-->AH! No, that's NOT right. Oh well, in the worst case, things would just be all-nation-at-once. Which would still be better than it is.
And if you can reset the relations again after a while with that updaterelations() function... <img src="style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />
 
Ok pieter, i found the way to keep hostile the enemy who have recognized you <img src="style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" />

But i would like to know for the coastraiders. If they recognized you, is it better to keep them hostile until they will be regenerate ? In this case, even if you sail to an other island and come back, they will remain hostile at your return.
 
Maybe they could store your type of ship and it's name? Then on your return, if you have a different ship/ship name they wouldn't recognise you, but else they would?
 
That's brilliant! <img src="style_emoticons/<#EMO_DIR#>/w00t.gif" style="vertical-align:middle" emoid=":woot" border="0" alt="w00t.gif" />

How long does it take for them to regenerate? And if so, does only the group that recognized you remain hostile or do they all?
It probably is quite realistic if at least those ships who recognized you in the first place will immiedately recognize you a second time too.
 
Yes, that's only the group who have recognized you in the first place who will remain hostile the second time, not all the groups of same nation. Usually, groups regenerate after 5 days, defined by CR_PERSIST in buildsettings, unless they are destroyed or surrended before the end of this period.

For your idea, a simple virtual sailor, it is doable but as the game allows the player to change the name of his ship when he wants, i think it would quickly become unrealistic and easy for players to by-pass the permanent hostility of those coastraiders <img src="style_emoticons/<#EMO_DIR#>/laugh.gif" style="vertical-align:middle" emoid="xD:" border="0" alt="laugh.gif" /> and after all that's only for 5 days maximum <img src="style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />
 
Back
Top