Page 1 of 1

Rout Logic

Posted: Sun May 31, 2020 8:49 pm
by Ludendorf
This is something that has been bothering me for a while now. I've been playing this game for a long time, and I still don't fully understand how routing units path. Even the direction they initially break away in seems to be semi-random. Has anyone worked out fully how it works?

Re: Rout Logic

Posted: Sun May 31, 2020 11:43 pm
by Schweetness101
I can look at it. The evading stuff is pretty complicated though, especially when it has to take into account the pathing of a router, one ore more pursuers (who cannot each take the same path because they can't be on top of each other) and all of the potential terrain and unit obstacles to run around. Hence why it sometimes seems pretty wild.

The relevant code stuff generally involves the REPQueue, but it's all pretty complex. Not something I have looked into changing. Although if you look into the DoUnitNextREPQueueStep() function and its helper GetNextRetreatStep() you can see a lot of the logic for choosing evasion routs, but they are long and complex functions.

A few notes from the comments from the latter function though:

// After first square of initial rout/evade move, preferred facing (direction of move) is to continue in the direction the unit is already facing.
// If first square of evade or initial rout, favour facing (direction of rout) directly away from the enemy unit that charged or inflicted the rout
// Check whether pass through is possible
// If pass through not possible, check whether normal move possible
// If sufficient move to get to new square (or, in the case of pass-through, the passed through square).
// Prevent toing and froing
// Calculate risk according to threat map - higher value means more chance of being damaged
// favour moves that end further away from enemy
// Favour moves directly away from enemy in contact on first square of initial rout, then favour direction already travelling,
// less favour for 45 degree deviation, and forbid more than 90 degree deviation.
// Disfavour moves that get closer to the enemy
// Stop units coming back towards enemy
// This should make route prefer easier to enter squares, and prefer straight to diagonal moves
// Favour direction towards own baseline if we know where that is.
// Give priority to leaving playable area, but preferably towards own base edge.

hope that helps

Re: Rout Logic

Posted: Mon Jun 01, 2020 12:16 am
by Ludendorf
Schweetness101 wrote: Sun May 31, 2020 11:43 pm snip
Wow Schweetness. I wasn't expecting a technical breakdown like that. Thank you. This should be useful. :)

Re: Rout Logic

Posted: Mon Jun 01, 2020 7:20 am
by rbodleyscott
It is also worth noting that for the purpose of selecting the direction for the first square of rout movement, when a unit is fighting multiple units, the unit that "inflicted the rout" is the one whose combat was being resolved when the unit routed.

You can therefore influence the direction of rout by picking the order in which you activate the melees. But only, of course, if the unit you pick does actually rout them.