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

Needs Testing Intelligent AI retreats and surrenders

Agreed! I'll get everything for retreat unified and using the new powerratio function over the next couple of weeks.
 
Agreed! I'll get everything for retreat unified and using the new powerratio function over the next couple of weeks.
Good luck :).
Just to warn you, do expect some bugs to pop up due to this ;) so be prepared to get frustrated because suddenly other stuff appears not to work anymore. :type1
 
Presumably the morale loss due to loss of crew, e.g. due to grapeshot, will continue to affect the enemy's chance of surrender?
 
Presumably the morale loss due to loss of crew, e.g. due to grapeshot, will continue to affect the enemy's chance of surrender?
From what I understand yes it will. It will only be moved to 1 function so it's easier to understand whats happening with the surrendering. Maybe eventually we can also figure out why sometimes stange things happen with flag ships which surrender etc.
 
Flagships certainly can surrender. There's a long-standing problem in which, when the flagship surrenders, the rest of the fleet turns neutral - they haven't surrendered, they're just not hostile any more. If you save and then reload game, they revert to being properly hostile. (Except for any which really have surrendered, that is.)
 
Flagships certainly can surrender. There's a long-standing problem in which, when the flagship surrenders, the rest of the fleet turns neutral - they haven't surrendered, they're just not hostile any more. If you save and then reload game, they revert to being properly hostile. (Except for any which really have surrendered, that is.)
That is indeed my point: They turn neutral, but do NOT surrender.
It's just the game getting confused for some strange reason. :facepalm
 
Presumably the morale loss due to loss of crew, e.g. due to grapeshot, will continue to affect the enemy's chance of surrender?

Yes, in fact I've specifically not changed "morale based" surrenders, except to remove one modifier that used powerratios (because the old powerratios function was broken in a way that the modifier would never ever occur, because the AI ships could only measure themselves, so this was the way to have it work as before).

Basically, the system now computes two chances for surrender, a "morale so low the crew forces the captain to surrender" chance (old system), and a "captain decides his cause is hopeless so he surrenders" chance (new system), and rolls them both independently.

Well, usually it will only be rolling one or the other, as they have very different threshold conditions (old morale based surrender need morale below a given threshold determined by captain leadership, captain based surrenders need a significant strength disparity to start being computed).

As an example, the test ship I posted about had 6% HP and was surrounded by warships, so it started rolling the captain based surrenders, but its morale was in the 50s still, and it's surrender threshold was 14, so it was never going to start rolling morale surrenders. On the other hand, if you grapeshot a ship, you won't change its powerratio, but you might drive it to surrender based on morale.

So it is about expanding player choice. If the player wants to take a nice condition prize ship, or feels his advantage lies in crew and boarding, he can pursue grapeshot. If the player has a firepower advantage, mainly wants the goods, or prefers ship-to-ship combat to boarding, he can pursue fighting at range.



I suspect this will make cannonballs more popular in opening up a new alternate way of being a privateer (at the cost of making much less money off of ship sales and looting) for those players who have more fun with long range combat.

So 100% preservation of the old system for morale based surrenders occurring, this is only about expanding player tactical options and playstyle choices, and not in any way limiting them.
 
Last edited:
I am removing the SURR_GLOBAL_SCL >0 check at the beginning of the surrender code, ie for people who play with surrenders turned off. If set to 0, you will still get 0% surrender chances, but your computer will waste some effort trying to compute them initially.

This allows me to put the new unified retreat code under the same function. Since it uses the same things like powerratios, hp, sails, etc that take some effort to compute, I'd rather only make the computer calculate them once.

This will be better performance on everyone except people who play with SURR_GLOBAL_SCL = 0, who will get the same performance as everyone else. (and I'm not sure any such people exist anyway, so better to prioritize performance for those who play with surrender enabled )
 
Last edited:
@Pieter Boelen @Levis

I have unified the various AIship retreat code into the moralecheck function, done right before the surrender code (so we can conserve processing power by only running the powerratio function once and then use for both).

I studied the screwface functions for awhile, and am holding off on unifying them for now. The reason is twofold:

1) They generally deal with initial group decisions to attack or withdraw, while ShipAI retreats give ship specific tasks when under fire. So it isn't a simple matter to unify them really, and they should mostly work well in concert together in the meantime (as they have been doing up until now, with the ship retreats sometimes overriding the group orders).

2) In the shortterm, we have enough bug reports and issues cropping up that I don't want to complicate things. The virtue of the present changes is they are limited in scope (adding retreat checks or surrender checks to run in the same places and in the same ways as preexisting ones won't cause hidden bugs, while pulling in something a bit different might)


So if it is alright, I am going to be slightly less ambitious shortterm, and let the two withdrawal systems operate in concert (as they have been doing up until this point).

A) Screwface will still handle the initial group decisions.

B) AIShip will have (now unified) invidual ship withdrawal decisions that can override this default behavior, just as before with the HP loss withdrawals.

I might do some light edits to the screwface functions logic to make it work better, but only stuff I know to be fully safe.

For Beta 15, we can try taking the next step and unifying entirely.


This way I can guarantee a safe and bugfree improvement to the AI after a little testing and work.
 
Last edited:
Ok, here's an interesting example where a ship's morale and HP have both reached critical levels at the same time:

num of near ships found for CrOxbay1is 9, and friend power for is 13.enemy power for is 22.
strengthrat for char CrOxbay1 of ship San Lino strengthrat is 0.59091
char CrOxbay1 of ship San Lino has decided to run after taking damage, captain decision (may be reversed by group task)
char CrOxbay1 of ship San Linohas lost ful control of his crew and they are pressuring him to run1
SURR chance from morale (crew forced surrender) for char CrOxbay1 of ship San Lino surrender chance is 1.85e-002His surrender morale limit was 18.923While he currently has temp morale 0.2653
UPDATE 1 VERSION Captain surrender is possible, checking Sail percentile52.34strengthrat0.59091HP Percentage3.4608
Captain motivated surrender base surrender chance is4.8887e-011his outmatched factor was9.1413e-003his surrender global modifier is 4.e-002
Moderately scared of sinking, captain has increased his surrender chance to 3.5954e-007
Now very scared of sinking, captain has increased his surrender chance to 2.6442e-003
Moderate damage to sails, captain has increased his surrender chance to 2.4487e-002

His morale has basically reached close to 0, and his ship HP is at 3%

His morale surrender chance is about 2%, and his captain surrender chance is about 2% as well.

Both have factors resisting surrender (he is very high leadership holding back morale based surrender, and he has some friendly ships present and some sails left holding back captain surrender), explaining the low rates for his pretty terrible condition.
 
Last edited:
Does your code obey the "nosurrender" attribute which is often assigned to quest captains? These are characters who must not surrender under any circumstances or the quest may break. Examples are the captain of the Mefisto in "Strange Things Going On" and the captain of the Temeraire in the "Hornblower" storyline.

Edit: just noticed the thread in the "Build Testing List" section - the answer seems to be "yes". :onya
 
Yep, that's right. From a coding perspective, I'm trying to be very conservative and safe to avoid any unforseen problems like that, so I'm only:

1) fixing a broken function to actually work like it was intended. The fixed function is fully tested without errors, has checks to prevent errors and return 1 if something breaks, and is only ever used for surrender and retreat

2) adding new retreat checks alongside a place where one already existed (with all these retreat checks using the same sorts of inputs and outputs as the preexisting retreat check that was already there)

3) adding a parallel surrender mechanic that mirrors the original in inputs and structure, and runs in the same place as it. While at the same time not altering the way the original surrender chance is rolled.

I think the absolute worst bug that could result is someone surrendering too quickly or running too quickly, but they would only be doing so under conditions thst enabled past surrenders or retreats anyway. Which means after a little playtesting it should be perfectly safe (since I'll be leaving the group decisions in screwface as they were previously).
 
The first result of my tests; posting it now before I test any further, because I'm not sure if this is enough information for you.

Played in: Arcade mode for accurate spyglass info
Disabled Direct Sail

####MY SHIP####
Jackass Bark, "Savage"
Crew: 52 | Crew Morale: Excellent | Hull: 100% | Sails: 100% | Cannons: 16

####ENEMIES####
BRITISH
Sloop, "Arab"
- Starting Stats -
Crew: 41 | Crew Morale: Poor | Hull: 84% | Sails: 94% | Cannons: 6

Sloop, "Swaggerer" (Flagship)
- Starting Stats -
Crew: 33 | Crew Morale: Poor | Hull: 99% | Sails: 73% | Cannons: 6

FRENCH
Naval Cutter, "Agricole"
- Starting Stats -
Crew: 51 | Crew Morale: High | Hull: 79% | Sails: 83% | Cannons: 12

Sloop, "Danae" (Flagship)
- Starting Stats -
Crew: 51 | Crew Morale: High | Hull: 90% | Sails: 95% | Cannons: 16

Found those ships at Nevis near the Pirate Settlement, where they were battling each other. The Swaggerer instantly tried to flee and after a short while the captain of the Arab apparently had the same idea.
A few minutes later the Swaggerer struck her colors, with remaining hull of 94% and sails 73%; that probably happened because the Danae was chasing her.

I decided to chase the Agricole, while the Arab went neutral in the meantime. After firing some grape salvos at the Agricole there was only one crewmember left, but no surrender happened. This is what I encountered a lot during the last weeks with navy ships and I find that odd. When that happened with the original AIShip file the captain only surrendered when I boarded the ship and then he always told me, that he was the last survivor of his crew. Those guys must be either really brave, stubborn or plainly insane.

While both the Agricole and the Danae tried to flee I had to board the Swaggerer, because my ship was low on ammunition; this made the Arab hostile to me again.
Shot the Arab's mast down which caused her to surrender a few seconds later (Sails: 0%, Hull: 80%) and then followed the Danae, because the Agricole was too far away now. Her mast didn't last long, but the Danae didn't surrender (Hull: 45%, Sails: 0%, Crew Morale: Awful). Instead she still tried to fight me (which was awesome), until her hull was at 37%, then she gave up.

I suspected that the Agricole would go neutral now, so I boarded the Danae first and then followed the Agricole. Found her - including her one-man army - with Morale: Treacherous, Hull: 57% and Sails: 68%. When her hull was at 54% I tried it with chainshots and she finally surrendered as soon as her sails went down to 36%. It's pretty funny though, the compile log says the "crew" was responsible for her surrender. Maybe the captain was schizophrenic.

And then the battle was over.
 

Attachments

  • compile.txt
    252.8 KB · Views: 208
@Cassadar , thank you, that is pretty awesome info, and your detailed description of the battle helps a great deal. It helps me to understand the compilelog wonderfully.

Let me annotate your narrative with info from the compilelog, and thoughts on what we might change going forward:

WITHDRAWL

The Swaggerer instantly tried to flee and after a short while the captain of the Arab apparently had the same idea.

Both made the decision at the same time, I imagine it was a position issue where the Arab just took longer to get in the direction he was going. Here are how they saw the tactical situations:

(enemies, including you)
SHIP had the following price of cannons1000and HP1282and cannon qty12and contributed the following power3
SHIP had the following price of cannons1200and HP947and cannon qty16and contributed the following power4
SHIP had the following price of cannons1000and HP1062and cannon qty16and contributed the following power4
(allies)
SHIP had the following price of cannons1000and HP1145and cannon qty6and contributed the following power2
Too far, not counting this ship
Too far, not counting this ship
Too far, not counting this ship
power of self is 2.so new total is4.
num of near ships found for is 7, and friend power for is 4.enemy power for is 11.
strengthrat for char CrQuebradasCostillas2 of ship Arab strengthrat is 0.36364
char CrQuebradasCostillas2 of ship Arab is making a tactical withdrawl

So it seems a smart decision--two little 6 cannon ships facing down 3 enemies with 16 and 12 cannon ships.

Interestingly, if your ship wasn't present, they would be just short of the line for instant withdrawal (they would see enemies as 7 power, themselves as 4, and they instantly withdraw when enemies have a 2x advantage)

So @Cassadar , what do you think? Looking at the hypothetical where it was just the british ships against the french (and you weren't there to scare them further), should this case be over the line where they decide to retreat immediately, or is it right that this is just short of an instant retreat? Any more of a power discrepency and they would run.

If kept as current, with withdrawal line at 2x, without you they probably would have exchanged a few salvos, and then retreated if they started losing.

I'm inclined to think it should be moved from 0.5 to .066, which means this situation (even minus you) becomes about the demonstrative example of when the AI will run. What do you think?


SURRENDER

A few minutes later the Swaggerer struck her colors, with remaining hull of 94% and sails 73%; that probably happened because the Danae was chasing her.

Hmm, this line is odd from the compilelog:
Captain motivated surrender base surrender chance is8.4377e-007his outmatched factor was0.23624his surrender global modifier is 4.

Notice the surrender global modifier is reading at 4? Here are the lines I got from my tests earlier in this thread:

Captain motivated surrender base surrender chance is5.3079e-006his outmatched factor was0.43609his surrender global modifier is 4.e-002

Reading the modifier at 0.04, as it should be.


I put that reading of the modifier in there as a debuging tool, in case people had changed default surrender settings, but it could also something odd is happening. But something is causing your Surrender Global modifier from internal settings to be read as 4, rather than the proper 0.04, making surrender more likely than it should be by two orders of magnitude.


Can you check your internal settings and tell me what SURR_GLOBAL_SCL is set at? Here is the default setting:
#define SURR_GLOBAL_SCL 0.04 // FLOAT - Ships will surrender if damage or crew morale become critical

If it isn't changed in your internal settings file, then this is a very weird bug indeed. Here's the lines applying it from the current posted version:
float captainsur = outmatched*SURR_GLOBAL_SCL;
Trace("Captain motivated surrender base surrender chance is" + captainsur + "his outmatched factor was" + outmatched + "his surrender global modifier is " + SURR_GLOBAL_SCL);

Which look fine.

We need to figure out this before understanding how to interpret the data, because 2 orders of magnitude on the initial number makes a big difference. Please let me know what your SURR_GLOBAL_SCL is set to, or post your internal settings file so I can take a look.



After firing some grape salvos at the Agricole there was only one crewmember left, but no surrender happened. This is what I encountered a lot during the last weeks with navy ships and I find that odd. When that happened with the original AIShip file the captain only surrendered when I boarded the ship and then he always told me, that he was the last survivor of his crew. Those guys must be either really brave, stubborn or plainly insane...
Found her - including her one-man army - with Morale: Treacherous, Hull: 57% and Sails: 68%. When her hull was at 54% I tried it with chainshots and she finally surrendered as soon as her sails went down to 36%. It's pretty funny though, the compile log says the "crew" was responsible for her surrender. Maybe the captain was schizophrenic.

Indeed, the original morale based system models decent level Navy ships as generally always in fight to the death mode no matter the circumstances. It is also very flaky--if you damage a navy ship slowly, then the temp morale of the crew tends to drop more, and surrender might be possible, but if you damage it quickly, temporary morale drops relatively little, and it just isn't going to surrender. I guess the original system models the idea of the crew forcing surrender on the captain decently, insofar as Navy crews generally don't turn on their captain because of low morale. It was a problem when it was the sole surrender system, but hopefully having captain driven tactical surrenders helps fill that gap.


I've taken a look at some things, partly in response to your feedback and partly in response to some playtesting, and will have a new version uploaded (complete with all levis suggested changes) in a couple of hours, when I am done testing. I'll shorten the range for estimating strength ratios, and move the withdrawal line to be a little less demanding and treat your reported situation as the borderline case that still permits withdrawal even if your ship weren't tipping the scales (at least until/unless I hear back you think that is a bad idea) Thanks for your continued help with this. :)
 
What do you think?
... :8qOoooh boy, that's a tricky question for me, because stuff like this isn't really my strongest point. This humble pirate is probably not the right person to decide such a thing. :p
I'll better trust you here, so If you think it would be better this way, then go for it. Better let me see this stuff in action.

Can you check your internal settings and tell me what SURR_GLOBAL_SCL is set at?
It's at default; never changed it.
 
Last edited:
@Cassadar

No clue why it was grabbing the wrong number then, weird! What I'm going to do is remove the modifier influence for my new surrender mechanic, the modifier can continue to influence the old one. It was always designed for the morale based surrenders anyway. That should fix whatever craziness was going on. I'm also dropping the range for powerratio measurement, and dropping the strength measurement cutoffs as well, which will make those surenders harder.

Basically, you'll find surrenders under the new system harder than before, will be interested to hear your feedback from future battles.


I just fixed the flagship surrender bug (well, 99%), and I want to try to see if I can fix the remaining 1% (that is, allied ships keep firing on the surrendered ship) before uploading the new version. So soon no more having the fleet go neutral just because the flagship surrenders. :)


@Cassadar I'll have the new version uploaded in a couple of hours, please do provide further feedback on surrenders, it is very very helpful.

Also, let me know if:

1) You still see any bugs cropping up with ships going neutral after flagship surrenders (you shouldn't with the fix, just in case)

2) You see any coastal raiders committing suicide against forts (they shouldn't now, if so I'll have to adjust the numbers)

And of course if you can write more detailed reports like your last one of battles, it is wonderfully useful, and very fun to read! :)
 
Also, let me know if:

1) You still see any bugs cropping up with ships going neutral after flagship surrenders (you shouldn't with the fix, just in case)

2) You see any coastal raiders committing suicide against forts (they shouldn't now, if so I'll have to adjust the numbers)

And of course if you can write more detailed reports like your last one of battles, it is wonderfully useful, and very fun to read! :)
Will do. Improving the ShipAI is generally a good thing to make sea battles more fun, so I'm happy to wait for the new version.:onya
 
New Version posted to first post!

Included fix for that old bug of flagship surrender causing other ships to go neutral, caveat is if all of an enemy fleet surrenders, and you have allies, and you don't board any vessels, then some of the remaining allies might keep firing on the surrendered fleet. It will clear up right away if you board a vessel, and they should retarget to the non-surrendered ones if there are any valid enemies left (let me know if they don't).

EDIT: figured out how to fix the final piece of that and stop any firing upon surrendered enemy groups, will do so and upload sometime tomorrow.


FEEDBACK REQUESTS:

If you force a flagship to surrender, and you get the old bug of the other ships in the fleet turning neutral, please tell me and post a compile log.

If you see any weirdness at all after surrender, please report (want to make sure my fix is completely safe, I tested it over 10 times without problems, but just to be sure). NOTE: you will not be able to go to worldmap until you either board the vessel or sail away. Better than having to load I think, just board it or sail away if you don't want the ship. ;) EDIT: this minor issue too will be fixed in tomorrow's hot fix..

If you see a coastal raider not run from a fort, please tell me and post the compile log if you have it. I may need to increase the percieved fort power.

If you demast an enemy vessel and they keep running away, please tell me and post a compile log if you have it.

And, of course, any compile logs or personal reports regarding surrenders (especially if one was too early for your tastes) or withdrawals.


@Cassadar please let me know how it runs. :)
 
Last edited:
Back
Top