AI Self Preservation

Post Reply
farcelet
Posts: 6
Joined: Fri Jan 13, 2012 6:33 pm

Thu Apr 19, 2018 6:00 pm

It's been a while since I played Kenshi, it's come along real nice.

I'm trying to make AI act in a non-suicidal way. This is hard in most games, because most games have only two states: KILL and DIE.

Some games offer a little more graduation. I modded most the guns out of Fallout New Vegas, gave all gun-toting NPCs very limited ammo, which they'd spend lazily taking potshots at one another from behind cover. Those who didn't have guns would throw their javelins before entering melee, where they would circle one another, taking jabs at random intervals - focusing more on dodging and blocking than wildly swinging.

When things went poorly, they'd run. Few fights ended in slaughter, unless one group surprised the other. Most fights were skirmishes instead - meaning less xp, less loot, and with a high cost of medical supplies and ammunition it made each one a decision:

Is what they've got worth the trouble to get it?

The Bethesda Fallout games actually had hugely powerful AI parameters for life-like behaviour - they were just never used.

Kenshi looks to have a lot of that too. What other game are you gonna see a guy patch up his friend, put him on his back and run back home? This is the behaviour I like. My issue is getting them to assess whether the fight's worth it - and the threshold for them determining they've lost the fight.

I talked about graduation before. Kenshi nails this in the graduation between life and death with starvation, limb loss, various states of being a cripple - I want to achieve the same graduation between aggression and self preservation.

--------------------------------------------------------------------------------

My understanding is that there is a relative strength value somewhere that AI looks to to determine whether to run or fight.

My question are: where can I find it, and can I change it?

I've seen there are 'BRAVE' and 'FEARFUL' personalities - do these relate to anything other than dialogue? If they do, how does one modify them?

What are the conditions for 'self preservation' behaviour to trigger, and can I alter its likelihood?

A character that has a higher attack value than his opponent's defense (as far as I understand) will attack more, and how much more he attacks can be set in the editor. This means that characters have varying levels of AGGRESSIVENESS in combat, which is excellent. Can it be tied to morale - or is morale a binary (fight/flee)?

Thanks for the great game.

User avatar
Sol Lignum
Posts: 1085
Joined: Sun Sep 06, 2015 5:56 pm
Location: Mother Russia!
Contact:

Thu Apr 19, 2018 11:00 pm

I can assure you that some kind of self-preservation AI exist, since my guys has personally scrared some few holy servants during one battle. They were running away, screaming something along the "they're too strong, we can't win" lines. That felt good.

One particular direction i might point you in would be adding your desired behaviours through dialogues system.

When creating the dialogue (which might also be a monolog, by the way) you can add various conditions and effects to its lines.

There're many conditions that you might be interested in, like:
"T_TARGET DC_IS_STRONGER_THAN_ME" ;
"T_TARGET DC_IS_WEAKER_THAN_ME" ;
"T_TARGET DC_REPUTATION" ;
"T_TARGET DC_IS_OUTNUMBERED" , etc

with values 1 or 0, depending on the situation

And the effects such as:
"DA_ATTACK_STAY_NEAR_HOME",
"DA_RUN_AWAY" and
"DA_GO_HOME".

There's also the most right unnamed section, which has something like modifiers (?) and can add some other actions or conditions, like certain target race or check for if acting character is in the town of spesific faction.

So, basically, you can create a line and empower it with some effects and conditions. Then you can give that line to a particular character or group of characters, so when conditions are met, the line will play, and the effects will take action.

You can create several small lines for each particular situation, or join everything with large dialogue with many lines and various conditions and effects for each line.

I cannot tell you wether or not personalities affect any behaviour by themselves, but you can add them to conditions as well, so the brave ones will fight where fearfull will run, or something like that.

So, i hope that's something to start you off with :)

Welcome to the forums, and the community, and good luck with modding your awesome ideas into Kenshi!

farcelet
Posts: 6
Joined: Fri Jan 13, 2012 6:33 pm

Fri Apr 20, 2018 7:02 am

Thanks a lot for the in depth reply Sol - gives me a lot to look at.

Right now I'm going to exclusively be tinkering with Starving Bandits and trying to get them to a point where they behave in a realistic manner - taking into account their abilities and needs - and build from there. If you've ever played Myth The Fallen Lords (old, old Bungie game) you might recall the Ghols: they were cowardly creatures that would circle you JUST out of reach of your archers and wait till you were weakened to strike.

This is what I picture Starving Bandits as doing. They'll wander around looking for targets of opportunity and attack when odds are strongly in their favour, and only then - unless their starvation drops to a desperate level.

I've already played with setting their relationships to 0 with factions and their individual agent's worth to 0 - they enter towns peacefully but eventually cause trouble by stealing food or picking a fight through their dialogue system. Their worth of 0 should mean that if I beat one group, the next won't hate me. What I need now is have every other faction reset their relationship with them after mischief.

I found values under the factions tab pertaining to relative party strength and whether or not to attack - it's set to a 2 to 1 ratio right now. Needs more testing to make sure it's functioning correctly.

"I can assure you that some kind of self-preservation AI exist, since my guys has personally scrared some few holy servants during one battle. They were running away, screaming something along the "they're too strong, we can't win" lines. That felt good."

Do you remember whether any of them turned and ran WHILE engaged in melee, or was it only after being knocked out and coming back? I've never seen anyone flee while engaged in mutually agreed target locked combat yet.

Dialogue system seems like a good way to go, I'll follow your recommendation and see what I can do! Thanks again.

User avatar
Sol Lignum
Posts: 1085
Joined: Sun Sep 06, 2015 5:56 pm
Location: Mother Russia!
Contact:

Fri Apr 20, 2018 12:30 pm

That's an interesting idea. I'm sure you'll be able to assemble something with given options. For instance, as i imagine, you can give a squad or faction the dialogue which contains the line with conditions: T_TARGET DC_IN_COMBAT = 1; T_ME DC_IS_OUTNUMBERED = 1; and effect would be to "ATTACK_STAY_NEAR_HOME" so the pack of bandits will only attack larger groups when those're in combat, so the chances of winning the fight, hopeless otherwise, are higher. Or you can create a more cowardish behaviour by switching DC_IS_OUTNUMBERED = 1 from ME to TARGET, or from 1 to 0, then they'll only attack smaller groups when those are in combat. There's also "IS_STARVING" condition, so what you're thinking should be doable. There's a lot of various conditions and combinations, playground is vast.

I have a feeling that i've only touched the tip of an iceberg though.

Also, i lied. You can't give a particular line to any character, they receive dialogues. What i meant was that you can create a dialogue that only contains one line, in case your only need is conditions and effects, and then give that dialogue to the character.

Also, dialogues could be groupped into packages, which could be given to not only individual characters but to squads and whole factions as well.

Here's the link on dialogue editor documentation with some first-party explanation on conditions, actions and events. My expertise isn't exhaustive, and this could be helpfull.

Also, i've just discovered another FCS tab, called AI packages. It seems to be containing goals for individual characters, and packages for squads and factions. You may probably find something interesting there as well.


About those servants.

They ran away in the middle of a figh, i think they weren't even wounded. I've not checked their packages, but i think several conditions might've been triggered that time, perhaps they were fearfull and when holy party became outnumbered, they ran, or they've targeted someone particular, who were stronger than them, and then ran.

I've also only seen this once, in that form. There were many fogmen who were retreating after severe injuring, but i don't think a single bandit ever ran from me, wounded or untouched. So, maybe i've had a rare luck, or perhaps it was the AI of that particular war campaign, which it was by the way, not a simple roaming squad.

farcelet
Posts: 6
Joined: Fri Jan 13, 2012 6:33 pm

Mon Apr 23, 2018 10:43 am

Hey Sol, thanks again.

Been working with AI packages with some success. Dialogue system definitely seems the superior method though. Problem now is that the dialogue tab in the FCS doesn't display an 'add' button for events - unless I'm doing it wrong it might be bugged. I'll get stuck into that when I get over this hurdle.

I've found I can make units run away when they've lost a set amount of units - but only if they've been knocked out first, or had to switch targets. Deciding not to engage because we're outnumbered never seems to trigger. My guess is that ATTACK and SELF DEFENSE override all. I need to figure out how often decision making triggers.

Actions can be set as URGENT and non-urgent. All can be weighted. Till I've solved my FCS dialogue issue I might play around with setting attack to non-urgent but weighed highly and fleeing to urgent. As it'll only trigger given certain conditions it should get closer to what I'm aiming for!

This might also solve the issue of enemies chasing you into bars and gates - I noticed that when I was being (verbally) harassed by Dust Bandits and I took refuge in the Hub's bar they gave up despite being at its doorstep. It must mean they weighted their distaste for that particular location more heavily than chasing me, which tells me both actions must've been set as non-urgent, one weighed more heavily than the other. In a separate occasion I was able to drag them in there when they were set on attacking me physically. This should never happen.

Ironically the only enemies I saw act with self preservation were those who boast about never backing down - Krall's Chosen I think they were called, attacking my base - and retreating in good order.

Once the Starving Bandits are to my taste I'll be sorting out the dogs. Now that's gonna be fun.

User avatar
Sol Lignum
Posts: 1085
Joined: Sun Sep 06, 2015 5:56 pm
Location: Mother Russia!
Contact:

Mon Apr 23, 2018 5:10 pm

Events seems to be hardcoded, so you got only set amount. And what you do instead of adding events is adding dialogues to set events, thus creating the dialogue package.

Can't say anything about AI packages, these are out of my expertise, at least for now, but dialogues, as i understand, work as follows: you're creating diffirent lines with diffirent conditions, so one behaviour is shosen over another depending on those. I know i take this one way to often, but just as an example:

- One line is "WAAAGH!" with condition "T_TARGET DC_IS_OUTNUMBERED = 1" and with "DA_ATTACK_STAY_NEAR_HOME" effect. So desired squad will attack if condition is met, i.e. if target squad has less forces.

- The second line, that should be added to the root of the same dialogue, like this:

Image

would "Meh" with condition "T_TARGET DC_IS_OUTNUMBERED = 0" and with "DA_GO_HOME" effect or no effect at all. So desired squad will not attack if target forces are greater, and will retreat or keep doing what they were doing if no effect is chosen.

So we'll get the dialogue with two lines with diffirent conditions and effects for each. The idea is to separate those diffirent conditions and effects throughout the diffirent lines, and this way it should work finely. At least in my understanding.

As for the bandits, i'd be wise to investigate those particular dialogues and ai packages to maybe try and find the reasons for diffirent outcomes, as there might be plenty. What immediately comes to mind are: brave personality of the leader, and "DC_COPS_ARE_AROUND" condition, which might stop or force squads from or into certain actions, depending on variables. So there might've been that condition with cops that stops non brave from violent actions, but if character is brave or dumb, then they'll ignore them cops. Or maybe there simply were no cops. Anyway, many reasons might stay behind it.

Although maybe this is where AI comes into play, and interferes with dialogue settings. But sadly, this is where my expertise ends.

Interesting note about Kral's Chosens. That sounds like a bug since whole Shek philosophy is based upon glorious death in battle. Perhaps you got (un)lucky and were visited by a squad of fearfull peronalities? :)

farcelet
Posts: 6
Joined: Fri Jan 13, 2012 6:33 pm

Mon Apr 23, 2018 6:01 pm

Perfect example for my purposes.

My problem with the FCS is this:
http://www.lofigames.com/phpBB3/viewtop ... 2e3abfce7a

I can't add any dialogue effects because the 'ADD' button doesn't appear! Does your FCS look like mine? (check thread screenshot)

I noticed that certain dialogues are tied to specific personalities as conditions - that's very interesting and opens up a lot of possibilities.

About the Sheks: I was screwed. They were all in the 50's range, my best guys were closing in on 20. They outnumbered me. I was about to abandon my base when they got intercepted by a Holy Kingdom patrol, which barely beat them. I rushed in to loot what I could - some of them started getting up again, but instead of rushing me some held me off while the rest picked up their wounded and took off in a hurry.

It was a hectic fight and my best experience yet.

The one thing that dragged me out of the experience was pause-looting abuse: in the middle of battle I was teleporting loot to my pack beast as to deny awakening enemies a fighting chance. Hopefully the ability to teleport look from one character to another during battle will be disabled in future versions.

User avatar
Sol Lignum
Posts: 1085
Joined: Sun Sep 06, 2015 5:56 pm
Location: Mother Russia!
Contact:

Tue Apr 24, 2018 6:47 am

Something is messed up with your subwindows in the FCS, should look like this:

Large IMG click

You can try and drag the lower half, where lines and texts are, down, that might fix the effects section.

Interception by HN patrol explains alot. Probably those who survived didn't perceived you as an enemy, and since HN patrol was defeated, the only thing left for Sheks was to retreat. It's still strange they've gathered their wounded. I've not encountered them much ingame yet, but what i've gathered from dialogues was that they, at least should not retreat, and would left their wounded to die, since death in battle is honorable, and living through defeat is great shame.

As for the pause abuse: it wouldn't work if your pack animal woud'nt have been in trading range anyway, so, i'd say it's forgivable. 'Specially since dragging to and fro can be cumbersome and is affected by framerate, and i don't trhink it's really possible to forbid pause during any phase of battle, so we have what we've got, and it doesn't seems bad at all :)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests