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

Fixed Reluctance of AI captains to use all their perk points

Tingyun

Corsair
Storm Modder
@Levis

Some AI captains seem reluctant to use all their perk points, often seeming to have around 1/3 of their perk points remaining unassigned. I have noticed this before with past skill importances, and I saw it now with the upcoming importances as well (although it appears slightly improved).

(I use the demand wealth dialogue to get a look at their prehire skills and perk assignments)

Is there something that can be done to make them more likely to spend all or nearly all of their points rather than leave them unassigned? Maybe a check at the end that takes a second pass through the available skills, or makes AI more likely to purchase perks in general?
 
Last edited:
would need to look at it.
But this is a consideration for performance also.
 
That is a concern indeed. So we would want something other than a second complete and complicated round through the perk selection process, as that would impact performance.

I can try taking a look at this one and see if I could make a proposed solution, to save some of your time. I'll report back whether I can come up with anything, or whether the problem is beyond me. I know the relevant files somewhat, you told me a bit about how it works before.

I'll also report back on the merging/testing later today, when I can slip away form work for a moment, probably around my lunchtime.
 
Why are they not using some of their perk points in the first place?
I understand if they're saving up for a perk that costs more than 1 point, but once they get to that point, should they get it and then go back to 0 free points?
 
@Pieter Boelen

They don't really save up for something, instead a much more rough function makes them likely to skip perks:

Code:
int chance = 100;
        //if(hval <2) chance -= 40; //If the score is only 1 we have a 50% chance of taking this perk. There might be something better or we should wait till something with more points comes along
        //if(sti(chref.rank) < 10) chance -= 25; //If we are below level 10 we should have a large chance of skipping a perk because there is a large chance something better is out there.
        //if(sti(chref.rank) < 20) chance -= 15; //If we are below level 20 we should have a chance of skipping a perk because there is a large chance something better is out there.
        //if(type != GetAttributeName(GetAttributeN(PerkTypes, sti(chref.PerkTypes.highest)))) chance -= 35; //If this isn't the best PerkType we should have less chance of picking one.
        //if(rand(100)<chance)

I commented that out (as above) and now everyone buys perks, except it seems they don't quite completely exhaust their last perk type. IE, it seems they often have exactly one catagory of contributing perks (like naval captains with defense perks) and they buy everything but that and then just save up their points afterwards). Trying to figure out why they do that now.

I also got rid of locked perks for AI for now while testing, just in case that affects AI captains. Not sure it does, but random characters seem to borrow the main characters locked list.

Obviously, commenting out is NOT the solution, those lines are there for a reason. Just trying to isolate where it comes from.
 
Ah, so I incorrectly assumed there was more cleverness than there is to the behaviour.
That does indeed explain it. :onya
 
I'm not sure why this all operates on a level by level basis anyway--wouldn't it be less performance intensive to wait until the person has reached their full level (whether from finishing post init, or upon initilization), then just take their total perk points and buy up as many perks as they have points for? Then we wouldn't need random checks for skipping perk buying meant to simulate saving up.
 
That makes sense.

Interesting, I wouldn't have expected non player team characters to level up. Are there persistent characters who manage to do that?
 
I do actually doubt they'd have much of a chance most of the time.
Excepting fixed ones (who generally are either for quest use or don't fight), characters don't usually exist for very long.

This is all @Levis' baby though. :cheeky
 
I think the problem is, even with the temorary things I commented out above (so that it doesn't skip anything), it keeps rolling up catagories that it doesn't have available perks in.

Lots of things like this when I debug it, where it keeps going to the same old catagories and finding nothing assignable, often taking many tries before it finds a valid catagory.

PERK SELECT: Called SelectPerksForCharacter for: Bertram Costner
PERK SELECT: called SelectPerkForType for type: sailing with points: 14
PERK SELECT: Perk: shipturnrateup is non assignable
PERK SELECT: Perk: shipspeedup is non assignable
PERK SELECT: Perk: turn180 is non assignable
PERK SELECT: Perk: sailingprofessional is non assignable
PERK SELECT: attempt 2 to find a perk
PERK SELECT: attempt 2 random number: 54
PERK SELECT: called SelectPerkForType for type: sailing with points: 14
PERK SELECT: Perk: shipturnrateup is non assignable
PERK SELECT: Perk: shipspeedup is non assignable
PERK SELECT: Perk: turn180 is non assignable
PERK SELECT: Perk: sailingprofessional is non assignable
 
Every character in the game uses the same way to leven and the same rules are applied to them. If a character uses post init it will level during the runtime. This can't be done for captains because you need to know their level to see if they need officers so they will fully init during load. I believe something is build in to restrict the amount of calls to the perk function, maybe that should be increased a bit.
Besides that I would need to look more closely at the system again to give any comment on the other things
 
EDIT for captains only it has all the perks at beginning I think now that I have seen Levis's post. :)

PERK SELECT: Called SelectPerksForCharacter for: Bertram Costner
PERK SELECT: called SelectPerkForType for type: sailing with points: 57

@Levis , I'm not sure these lines are needed:

if(hval <2) chance -= 40; //If the score is only 1 we have a 50% chance of taking this perk. There might be something better or we should wait till something with more points comes along
if(sti(chref.rank) < 10) chance -= 25; //If we are below level 10 we should have a large chance of skipping a perk because there is a large chance something better is out there.
if(sti(chref.rank) < 20) chance -= 15; //If we are below level 20 we should have a chance of skipping a perk because there is a large chance something better is out there.

Especially since most everything that costs 1 perk point is a prerequisite to other, more powerful perks. Earlier in the formula, we add to the score if it is a prerequisite that leads to other perks, but then we have this line here that seems to work in the opposite direction almost always?

For the skipping because of low level, I think among the best it is mostly just sea wolf and a couple of others. I'm not sure if they need to skip to get them, as they will be exhausting the perks they could take anyway and probably end up with the points once they get a few levels past.

EDIT: just saw your post Levis :) edited according to the new understaning you have shared.
 
Last edited:
@Levis I had a thought, after exploring this process for awhile. Let me know what you think, when you have time (no rush at all, I know this has been a busy week!)

I think a problem, both for using points and for performance, is we have too many categories of skills. Currently they are divided into ten catagories, with each weight calculated as a combination of multiple skills.

Meaning characters generally will all have significant weights in catagories where they don't have much contriuting skills, or if they do, then after they purchase them they don't. And the system just loops back and back through the same catagories, despite them being empty, slowing things down and contributing to them not using all their points.

What if we consolidated the perk lists into a smaller number of catagories, maybe 4 or so? It would take some thought, but most cross the lines anyway, and since characters will mostly be picking from their contributing perks anyway, they won't really mind if some non contributing ones they won't pick anyway are on the same lists they roll up.

It should end up a boost for performance, as they'd find a catagory to purchase from much quicker, and largely solve the problem of them not spending all the points, and shouldn't lead to bad perk assignments, because the contributing skill requirement will still be there.

Maybe divide them into A) personal combat, B) sailing and sea combat, C) noncombat. Or something like that, and then rely on noncontributing status to steer choices correctly within whatever catagory.

I could be completely wrong in this suggestion, just wanted to see what you'd think of the idea:p
 
Last edited:
Ran quick test:

Consolidated the many possible perk catagories into 3 (personal combat, ship realted perks, and a final catagory for medical/smuggling/commerce/misc), and adjusted the weights according to new components.

Officers always had plenty to pick from on their lists, so no looping again and again multiple times, and instead they basically always spent all their points (or had only 1 remaining) whether low or very high level. Even a level 40 captain or something would quickly buy everything, almost no repeated tries needed in compiled log.

The contributing perk classifications kept their choices appropriate and thematic just fine without the help of seperate perk lists. Basically, instead of a gunner rolling the sailing list, or the repair list, and rerolling until they finally get an appropriate list, they just roll the general ship related list, and then pick gunner perks from there, with the others marked as unassignable. Seems to end at the same effect, just without the rerolling.

Meanwhile, tailoring the weights between the personal combat vs ship related vs other lists seems to keep a sensible amount of variety based on the type of officer. It may need further work, but some tavern tests make it look like it is doing pretty good.

Performance wise I would expect it might be an improvement (and that is what it seems to be timing going in and out of dugeons), since there is less times through the process (almost all officers finish spending all their perk points ahead of schedule, with a bunch of "no perk points left" type messages at the end of compile).

It does make them spend all of their points pretty reliably, but there might be some disadvantage I'm not understanding?
 
Last edited:
the system which is in place now was designed before the non-contributing perks where working. this is why it has so many categories because I wanted the different officertypes to show it in their perks. Now thats easier because of the contributing perks so maybe indeed we can lower the amount of categories a bit, but it requires a lot of testing. My testcase mostly was officers in the tavern round level 10. They should show a significant difference in perk selection already depending on their officertype. if you can find an other balance in the perktypes etc to achieve this same result and also work better on higher levels please be my guest.

I prefer to keep the code in for skipping some perks at lower levels. This is mostly in place also to save up points for perks with a min level and stuff like that. Also it's there so if you hire a officer at the tavern he will almost certanly have 1 or 2 points which still can be attributed. personally I find that very nice because that gives you a bit more freedom. But feel free to tweak the numbers a bit to see if they produce better results. Most of these numbers came from testing a while back but after a while the feedback stopped so I asumed they where about right.
 
Also it's there so if you hire a officer at the tavern he will almost certanly have 1 or 2 points which still can be attributed. personally I find that very nice because that gives you a bit more freedom.
That makes sense for hireable officers. But if it is an NPC enemy, then it arbitrarily weakens that NPC, doesn't it?
 
That makes sense for hireable officers. But if it is an NPC enemy, then it arbitrarily weakens that NPC, doesn't it?
yeah but like I said before I want everyone to have the same rules :p.
And 1 or 2 perk points isn't a problem. You as a main player will sometimes have 2 perk points open also if you are saving up for a higher costing perk so doesn't sound that bad right?
 
And 1 or 2 perk points isn't a problem. You as a main player will sometimes have 2 perk points open also if you are saving up for a higher costing perk so doesn't sound that bad right?
Not until they get to higher levels and end up accumulating more than those 1-2 unused perk points.
 
Not until they get to higher levels and end up accumulating more than those 1-2 unused perk points.
Like I said that shouldn't happen, if it does it isn't right.
Ofcourse UNLESS they got all the perks they can actually contribute. after that they are allowed to have a bit more spare perkpoints. altough maybe there should be a check in the code to see if all perks which can be contributed are taken and if so set the noncontribute chance to 100% so it could take more perks from other things as well
 
Back
Top