Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Follow-the-Leader AI  (Read 1510 times)

AceSV

  • Bay Watcher
  • [SUPER_VILLAIN]
    • View Profile
Follow-the-Leader AI
« on: September 08, 2015, 10:24:23 am »

You know how squads of dwarf have a tendency to split up and hit the enemy in small waves instead of all at once?  I've programmed a couple AIs in my day, and there's a simple way around that.  Instead of having different units each operate independently, each unit is basically given commands by a Leader unit, or bases their decisions on the position of the leader.  So instead of thinking "Attack the nearest enemy" the unit thinks "Attack the enemy nearest to the leader" or instead of "move to the station point" only the leader moves to the station point and all other units move to the leader.  For the Patrol and Defend orders, it would make more sense for them to split up, so there should be some way to activate and deactivate follow-the-leader AI as needed. 

If you'd prefer to get messy, there are more complicated ways to program units to keep cohesion, you see them in robotics demonstrations a lot.  Or, more appropriately, you could program the leader to make decisions and give commands.  For example, the leader might see a troll and a goblin nearby.  Leader has 6 subordinates nearby, so he sends 4 to fight the troll and 2 to fight the goblin.  Herein lies the danger of that approach though, is a troll actually more dangerous than a goblin?  An armored goblin lasher is probably way more dangerous than a troll. 

Alternatively, the "leader" does not need to be an actual unit.  For calculations' sake, the "leader" could be the squadron's mid-point or the point marked as a station command. 
Logged
Quote
could God in fact send a kea to steal Excalibur and thereby usurp the throne of the Britons? 
Furry Fortress 3 The third saga unfurls.  Now with Ninja Frogs and Dogfish Pirates.

Shonai_Dweller

  • Bay Watcher
    • View Profile
Re: Follow-the-Leader AI
« Reply #1 on: September 08, 2015, 04:50:47 pm »

I can picture it now. A slavering forgotten beast rushes towards the dining room. Only Urist McAxelord stands in it's way...until he rushes off to find the militia commander who's attending a party in the statue garden.

It'd be nice if it worked well, but it would also need to model discipline. Dwarves aren't robots. Rookie spearmen do break rank to slap the nearest troll instead of focussing on the crossbowman. Which would lead to bug reports of the feature not working properly...
« Last Edit: September 08, 2015, 06:06:02 pm by Shonai_Dweller »
Logged

Splint

  • Bay Watcher
  • War is a valid form of diplomacy.
    • View Profile
Re: Follow-the-Leader AI
« Reply #2 on: September 08, 2015, 05:26:33 pm »

I can picture it now. A slavering forgotten beast rushes towers the dining room. Only Urist McAxelord stands in it's way...until he rushes off to find the militia commander who's attending a party in the statue garden.

I think this might have actually been partially how the militia worked originally, which could result in some strangeness with your crack hammerlords not going into battle because thier squad leader was taking a nap. And they'd just sit there and watch him sleep or what have you. I remember seeing something like that happening in headshoots or Boatmurdered or something.

AceSV

  • Bay Watcher
  • [SUPER_VILLAIN]
    • View Profile
Re: Follow-the-Leader AI
« Reply #3 on: September 08, 2015, 08:46:55 pm »

I can picture it now. A slavering forgotten beast rushes towers the dining room. Only Urist McAxelord stands in it's way...until he rushes off to find the militia commander who's attending a party in the statue garden.

I think this might have actually been partially how the militia worked originally, which could result in some strangeness with your crack hammerlords not going into battle because thier squad leader was taking a nap. And they'd just sit there and watch him sleep or what have you. I remember seeing something like that happening in headshoots or Boatmurdered or something.

Ideally they would follow chain of command.  If the designated leader is indisposed, they should follow the next guy or follow their own judgement.  Obviously if the leader is killed or maimed in combat, you want the rest of the squad to pick itself up and carry on.  Or as I said, the "leader" doesn't have to be anything that physically exists, it's just a tool for guiding the AI. 
Logged
Quote
could God in fact send a kea to steal Excalibur and thereby usurp the throne of the Britons? 
Furry Fortress 3 The third saga unfurls.  Now with Ninja Frogs and Dogfish Pirates.

Dirst

  • Bay Watcher
  • [EASILY_DISTRA
    • View Profile
Re: Follow-the-Leader AI
« Reply #4 on: September 08, 2015, 08:53:59 pm »

Not sure about the squad leader thing, but station orders already work the way you described.  Each dwarf selects a spot near the station point and paths there.

I like the idea of the squad having a locus, which may or may not coincide with the squad leader's position.  It would at least give you a meaningful way of zooming to the squad, and ease future development of formations.  Pathing weights could be penalized for straying away from he locus, but if and only if there is a breakthrough that makes realtime pathing economical.  More likely, the locus would issue orders of "get over here" if the dwarf is supposed to be with the squad but is X tiles away (X varying with formation, discipline, and a player "tightness" setting).
Logged
Just got back, updating:
(0.42 & 0.43) The Earth Strikes Back! v2.15 - Pay attention...  It's a mine!  It's-a not yours!
(0.42 & 0.43) Appearance Tweaks v1.03 - Tease those hippies about their pointy ears.
(0.42 & 0.43) Accessibility Utility v1.04 - Console tools to navigate the map