Auto-follow

I'd even consider Patrol too. Assuming I'm remembering there was that option at one point in a previous version.
 
there is already a mod for workers, but I can't remember the name.

and you can control units from Lua, so such mods are possible without DLL access.
 
Okay, I've actually solved one part of this - and that's figuring out the interface for starting/stoping escorting.

If both the civilian and the military unit start on the same plot, and are automated (the automate button is clicked for each), the military unit will escort until you break the automate manually or there is an attack, etc.

Now I have to figure out how to make them move together - and how to tell if the unit was automated (minor details :p)

Update:

Okay, I've got this one I think. Woot. It will have one side effect, but I'll call it a feature. Basically it's going to be more an automation tweak. If an automated combat unit is in range of an unprotected civilian unit it will move to cover it. If a civilian unit is on the same plot as a military unit it will reduce it's movement to that of the military unit (if it's higher). I think that's all I'll have to do. Can do it all in PlayerDoTurn. I don't need to worry about non human players, they already escort.
 
Here is the simple logic, I'm working on coding it right now.

Spoiler :
Code:
        -- find unescorted civilians
	-- check if an automated combat unit is in range
	-- move combat unit to civilian and set both moves left to 0

	-- find escorted civilians
	-- if their moves is greater than the moves of their escorter
	-- reduce their moves to match

	-- if escorted unit is a worker and currently 'working' then
	-- set the moves of it's escorter to 0
 
Your simple logic breaks down at the end of the turn an automated worker finishes their current task

Start of Turn N
  • Worker is automated and working
  • Escort has moves set to zero by your code
  • Player makes moves other units and clicks Next Turn
  • "Auto-player" moves automated units, worker completes task
Start of Turn N+1
  • Worker is automated, but not working
  • Escort is unchanged by your code
  • Player makes moves and clicks Next Turn
  • "Auto-player" moves worker off towards next task (say due west)
  • "Auto-player" moves escort (which is "automated explore" towards the fog (say due east)
  • (Barbarians come from the west and capture the un-escorted worker)
Start Turn N+2
  • (Assuming worker hasn't been captured yet) Worker is automated and unescorted
  • Your code detects this and starts moving the automated escort back due west, however this escort is now playing "catch-up" until the worker reaches their next target and starts working, so the worker will be unescorted for M+2 turns where M is the number of turns it takes the worker to reach the target plot
  • An automated scouting unit (could be a scout, horseman, whatever) passes nearer to the automated worker than the old escort (who is 4 tiles away)

Start Turn N+3
[*]Depending how the code is written, automated scouting unit is re-deployed as the escort, old escort becomes scouting unit
 
Your simple logic breaks down at the end of the turn an automated worker finishes their current task

Start of Turn N
  • Worker is automated and working
  • Escort has moves set to zero by your code
  • Player makes moves other units and clicks Next Turn
  • "Auto-player" moves automated units, worker completes task
Start of Turn N+1
  • Worker is automated, but not working
  • Escort is unchanged by your code
  • Player makes moves and clicks Next Turn
  • "Auto-player" moves worker off towards next task (say due west)
  • "Auto-player" moves escort (which is "automated explore" towards the fog (say due east)
  • (Barbarians come from the west and capture the un-escorted worker)
Start Turn N+2
  • (Assuming worker hasn't been captured yet) Worker is automated and unescorted
  • Your code detects this and starts moving the automated escort back due west, however this escort is now playing "catch-up" until the worker reaches their next target and starts working, so the worker will be unescorted for M+2 turns where M is the number of turns it takes the worker to reach the target plot
  • An automated scouting unit (could be a scout, horseman, whatever) passes nearer to the automated worker than the old escort (who is 4 tiles away)

Start Turn N+3
[*]Depending how the code is written, automated scouting unit is re-deployed as the escort, old escort becomes scouting unit
That would never happen. Because the automated escort would never move toward the fog. It would detect the moved worker is now un-escorted and move to it instead.
 

Yeah, way past that point now lol :) Trying to figure out how to get the other unit on a plot with the current unit. I can see that in plot:GetNumUnits() the unit has an escort. Also, it's unclear but from the DLL not promissing that there is a function to determine if unit is in range of plot. I can write one, but ugg - it would have to take into account terrain, and all kinds of pathing issues.

Update: I can kludge the code to get the other unit on the plot. Now it's just time to see what the different pathing functions *really* do.
 
That would never happen.

If you leave the escort automated, the "auto-player" feature will kick in *before* your code does and send the escort off exploring
 
Your simple logic breaks down at the end of the turn an automated worker finishes their current task

Start of Turn N
  • Worker is automated and working
  • Escort has moves set to zero by your code
  • Player makes moves other units and clicks Next Turn
  • "Auto-player" moves automated units, worker completes task
Start of Turn N+1
  • Worker is automated, but not working
  • Escort is unchanged by your code
  • Player makes moves and clicks Next Turn
  • "Auto-player" moves worker off towards next task (say due west)
  • "Auto-player" moves escort (which is "automated explore" towards the fog (say due east)
  • (Barbarians come from the west and capture the un-escorted worker)
Start Turn N+2
  • (Assuming worker hasn't been captured yet) Worker is automated and unescorted
  • Your code detects this and starts moving the automated escort back due west, however this escort is now playing "catch-up" until the worker reaches their next target and starts working, so the worker will be unescorted for M+2 turns where M is the number of turns it takes the worker to reach the target plot
  • An automated scouting unit (could be a scout, horseman, whatever) passes nearer to the automated worker than the old escort (who is 4 tiles away)

Start Turn N+3
[*]Depending how the code is written, automated scouting unit is re-deployed as the escort, old escort becomes scouting unit
If the combat unit can't get there in one turn it doesn't try. So in this case the connection between the two would be broken, and it would get picked up by another unit if one was near. But, if this does turn out to be the case I'll see if I can find a good work around I guess.

I have a 'always move to cover' flag, that I will expose to the user, to handle this behavor. If they set it true, then you are right the closer unit will move to cover. If false, the assigned escort will just keep plugging away as best it can. If for some reason it falls too far behind it abandons the unit and returns to scouting. The unit is marked as abandon though so even if 'always move to cover' is false another unit can pick it up. However, so far I've seen no edge cases that invoke this (the escort never falls more than one turn behind).
 
Back
Top Bottom