0.17 Unit & AI additions

Place to post guides, observations, things related to modding that are not mods themselves.
User avatar
wheybags
Former Staff
Former Staff
Posts: 328
Joined: Fri Jun 02, 2017 1:50 pm
Contact:

0.17 Unit & AI additions

Post by wheybags »

We have been making a lot of improvements to the Unit and AI moddability and scriptability:
  • Allowing units to pathfind through friendly buildings (i.e. walk over to it, destroy it, then continue over the place it used to stand). Only when explicitly requested, of course.
  • Allowing units to path through and open friendly gates.
  • Added a whole bunch of flags to go_to_location commands, exposing pathfinder internals such a low priority pathfind requests, and prioritising straight paths.
  • Units will now avoid pathing through all friendly entities, as opposed to the old behaviour of only avoiding same-force entities.
  • Added new AI command, stop, and improved the wander command significantly.
  • Callbacks on AI command completion, so you can have some custom code to decide what to do next.
If you have any ideas or suggestions related to the Unit and AI prototype/API, please let us know here
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: 0.17 Unit & AI additions

Post by eradicator »

Disclaimer: I have no experience with the unit AI part of modding.
Wheybags wrote: I've been adding prototype flags to units which disable these special behaviours by default, and enabling them only on biters (e.g., trying to return to a spawner every now and again, which can mess up your current command execution).
From just the text it sounds like the "return to spawner" behavior can only be disabled completely for the whole prototype. But it sounds like it would be useful to be able to remove it from just a few entities during runtime (i.e. to create lurking biter groups or permanent patrols like shown in the FFF, i.e. as a one-time guard around some map-object like a ruin, where the guarded object is not a spawner). So, am i just misunderstanding and it is actually possible to override it anyway?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: 0.17 Unit & AI additions

Post by Klonan »

eradicator wrote: Fri Sep 28, 2018 4:45 pm Disclaimer: I have no experience with the unit AI part of modding.
Wheybags wrote: I've been adding prototype flags to units which disable these special behaviours by default, and enabling them only on biters (e.g., trying to return to a spawner every now and again, which can mess up your current command execution).
From just the text it sounds like the "return to spawner" behavior can only be disabled completely for the whole prototype. But it sounds like it would be useful to be able to remove it from just a few entities during runtime (i.e. to create lurking biter groups or permanent patrols like shown in the FFF, i.e. as a one-time guard around some map-object like a ruin, where the guarded object is not a spawner). So, am i just misunderstanding and it is actually possible to override it anyway?
It can be changed at runtime for individual units
Mimp
Inserter
Inserter
Posts: 28
Joined: Mon Dec 19, 2016 8:12 pm
Contact:

Re: 0.17 Unit & AI additions

Post by Mimp »

I'm not a modder, please excuse my naivety. Would it be possible to use this new path finding for vehicles? Would "units" need to have a flag to allow them to be entered by forces? Could this open up the possibility for some gruesome creature spewing creatures?
Brambor
Fast Inserter
Fast Inserter
Posts: 189
Joined: Thu May 07, 2015 1:52 pm
Contact:

Re: 0.17 Unit & AI additions

Post by Brambor »

Is it possible to make an autonomous EV car mod?
An AEV that you will just request to drive you to desired destination and it will drive you there, either on concrete floor or possibly avoiding buildings and trees.
dauphin
Inserter
Inserter
Posts: 38
Joined: Fri Aug 19, 2016 1:59 am
Contact:

Re: 0.17 Unit & AI additions

Post by dauphin »

First and foremost, this will be a total game-changer for Robot Army, and I am now extremely excited for 0.17.


Does "Units will now avoid pathing through all friendly entities, as opposed to the old behaviour of only avoiding same-force entities" mean that units will intelligently avoid pathing through (and getting stuck on) belts and walls? Belts are the bane of a unit-modder's existence...

Even more than that, it would be awesome if units could move through a base while steering clear of places that might be under construction by bots, for instance.

Also, how does this affect/interact with unit groups, if at all? I've found groups to be fairly unstable, or at least unpredictable. Will the "command completion event" fire for groups? Will there be a toggle for not separating groups "automagically" under circumstances that are hard to precisely characterize?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: 0.17 Unit & AI additions

Post by eradicator »

Possibly slightly off topic but i just remembered an old problem: making the player character walk somewhere (old thread, forum update apparently broke the code sample.)

The goal was to make the player walk a short distance (10-40ish tiles) towards an entity. As far as i understand currently i can't use ai commands on a player character, but i imagine the ability might come in handy in the campaign, i.e. for cutscenes. Would that be a reasonable request? ;)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
beiju
Inserter
Inserter
Posts: 42
Joined: Thu Feb 02, 2017 3:52 pm
Contact:

Re: 0.17 Unit & AI additions

Post by beiju »

I’m aware this might be difficult, depending on pathfinder implementation, but I’d love to be able to get paths that obey the constraints of vehicles — specifically the limited turning radius.
Veden
Filter Inserter
Filter Inserter
Posts: 294
Joined: Wed Jul 13, 2016 3:54 pm
Contact:

Re: 0.17 Unit & AI additions

Post by Veden »

Looking through the lua api 0.17 preview:

Commands:

Flee
Assuming that this command will interrupt a biter group that is attacking and move them away from an entity.
Could we get a position or an entity for the "from" parameter?
Could we get a "to" parameter that could be an entity or position that would be a place to retreat to?
Could we get a distance parameter that defaults to uint max, but otherwise limits the distance of the flee.

Unit Groups:

Kill all members

Group States:

defines.group_state.wandering
defines.group_state.fleeing
defines.group_state.stopped
defines.group_state.building
defines.group_state.attacking_area

Force:

Select all unit groups per force.

Events:

AI Unit Group Dissolved event - parameter the unit group being removed.
AI Unit Group Created event - parameter the unit group being created.
Berkys32
Fast Inserter
Fast Inserter
Posts: 113
Joined: Mon Mar 07, 2016 9:17 am
Contact:

Re: 0.17 Unit & AI additions

Post by Berkys32 »

Brambor wrote: Fri Sep 28, 2018 6:49 pm Is it possible to make an autonomous EV car mod?
An AEV that you will just request to drive you to desired destination and it will drive you there, either on concrete floor or possibly avoiding buildings and trees.
Its possible even now using AAI mod ;)
gaelyte
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Thu Mar 29, 2018 6:44 pm
Contact:

Re: 0.17 Unit & AI additions

Post by gaelyte »

I remember I issue with Bob's mod' Robottic attack robots that despawned if you were too far away from they. Could it be possible to deactivate the fact that they're desactivated if we are away?
voddan
Fast Inserter
Fast Inserter
Posts: 124
Joined: Sat Jun 03, 2017 9:22 pm
Contact:

Re: 0.17 Unit & AI additions

Post by voddan »

One of my favorite use cases for such an API would be finally modding grounded construction and/or delivery robots.

The idea of ground construction bots is well described by Factory Lobster in viewtopic.php?f=6&t=50791 where it shows the benefits of early-game usage of blueprints, automatic tree-cleaning, etc.

Alongside it comes an idea for ground delivery bots that run between chests and are able to adapt their paths to factory buildings. They would fill the niche of automatic delivery of rare items in low volumes while not being able to out-run belts because of the space constraints.

For those two use cases the API is almost there, but one nice thing missing is an ability to show a found (and possibly modified) path on the map and the ground as a dotted line. With that a bot could show several possible paths to the destination (kinda like a GPS navigator) and ask the player which one they prefer. Alternatively if a bot can't reach the destination it could show a path it thinks would be the best and ask the player to remove the obstacles on it.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: 0.17 Unit & AI additions

Post by Klonan »

gaelyte wrote: Sat Sep 29, 2018 8:51 am I remember I issue with Bob's mod' Robottic attack robots that despawned if you were too far away from they. Could it be possible to deactivate the fact that they're desactivated if we are away?

Yes, this is already fixed, they won't randomly despawn
(It was because they would repeatedly fail pathfinding)
CaveGrinder
Inserter
Inserter
Posts: 35
Joined: Fri Aug 24, 2018 7:42 pm
Contact:

Re: 0.17 Unit & AI additions

Post by CaveGrinder »

is it possible to limit pathfinding to a vector of tile names?
i have two use cases in mind:
a taxi than drives on roads (list of supported tiles like 'road', 'concrete'...)
a starcraft zerg-like enemy that would move on 'creep'

Overall the changes sound great, really looking forward to what becomes possible now!
abregado
Former Staff
Former Staff
Posts: 282
Joined: Sat Aug 30, 2014 9:43 am
Contact:

Re: 0.17 Unit & AI additions

Post by abregado »

eradicator wrote: Fri Sep 28, 2018 8:06 pm The goal was to make the player walk a short distance (10-40ish tiles) towards an entity. As far as i understand currently i can't use ai commands on a player character, but i imagine the ability might come in handy in the campaign, i.e. for cutscenes. Would that be a reasonable request? ;)
I cant comment on the plausibility of making the player behave like a Unit, but I can say that in the release Campaign this should never happen. Moving the character without the player's consent can be a massive immersion breaking no-no (without supporting mechanics like POV change, context switch, ect) so I placed a design constraint that this should never happen during our scripted content.
THC4k
Manual Inserter
Manual Inserter
Posts: 2
Joined: Tue May 16, 2017 2:20 pm
Contact:

Re: 0.17 Unit & AI additions

Post by THC4k »

I wonder if the pathfinder can avoid getting run over by trains? That would be pretty important for any kind of modded unit.
gaelyte
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Thu Mar 29, 2018 6:44 pm
Contact:

Re: 0.17 Unit & AI additions

Post by gaelyte »

THC4k wrote: Sun Sep 30, 2018 12:16 pm I wonder if the pathfinder can avoid getting run over by trains? That would be pretty important for any kind of modded unit.
It's rarther easy :
Solution 1 : The unit can't cross rails
Solution 2 : The unit can cross rails, and you have to put gates to protect them, like this : https://wiki.factorio.com/images/Fff-14 ... -gates.gif
User avatar
Earendel
Factorio Staff
Factorio Staff
Posts: 716
Joined: Sun Nov 23, 2014 11:57 am
Contact:

Re: 0.17 Unit & AI additions

Post by Earendel »

This is great news.

I requested that pathfinding be accessible as an API a while ago here: viewtopic.php?f=28&t=39896

If you're not already familiar with the AAI Programmable Vehicles mod, it enables you to select one or many vehicles and order them to locations, loop in paths with waypoints, transfer inventory between each other, or program them using structures connected to the circuit network.

The current setup involves spawning an invisible unit (the 'navigator'), issuing a go to command, logging the path, and then trying to use the path as a set of target tiles for a fake vehicle driver. As you can imagine, there are many issues with this approach. Usually the navigator gets close to the target point then wanders off in a random direction and goes in circles and I can't tell if that's part of the pathfinding or the actual found path so the vehicle follows the same pattern.

It would be great if an asynchronous pathfinding request could be made so that the path of a failed status code could be returned and I could use the returned path data to drive the vehicle. The kinds of data to send and get back are outlined here: viewtopic.php?f=28&t=39896

Here are some other things that are relevant to scripted unit control that are worth looking at:

Sometimes units disappear or lose their orders, especially on large maps. I'm guessing that's an optimization thing and hopefully part of the stuff that can be solved as part of the prototype changes in the blog post.

When requesting path for a unit, the current system assumes that the units are land based, the pathfinder doesn't obey the unit's collision masks, which would be important for amphibious or fully aquatic units.


When finding a path, if path fails, it would be good to be able to have it return the path that it did find that is closest to the target point, along with the distance of the path end to the target. I'm assuming that information is already there if you're using something similar to A*. An example would be: go to a water tile but it's a land unit, pathfinder fails but returns the path to the closest piece of land to the target.

The last time I checked it was almost impossible for figure out if a unit actually had a proper order already. I can't remember quite what I was checking for or what the return value was, but it's the situation where biters are essentially 'idle' outside their spawners all facing north and not moving. Being able to easily identify those would be useful, I think the problem was they seemed to already have a command be not be active for whatever reason. The specific use case was to trigger all idle biters in a certain radius to accept an attack move command. The important point is that only idle biters should be affected as if multiple of these calls go off they'd keep changing directions and not get anything done. Anyway it would be better if there was more transparency regarding the unit's actual status and activity.

This is not unique to units, but a lot of the time it is necessary to check that a unit's position is still valid, otherwise it would need to be nudged to the nearest valid position.
If trying to check that the current position is valid with surface.can_place_entity it will be false because the unit itself is in the way. It would be great if can_place_entity could specify an entity to ignore. Likewise specifying an ignore entity for surface.find_non_colliding_position would be useful for the same reason. The current workaround I use is to teleport the unit out of the way before the check then teleport it back afterwards.

The option of being able to ignore trees as part of pathfinding would be very useful. I have a harvester unit (https://mods.factorio.com/mod/aai-vehicles-miner) that can harvest trees as it moves so it pathfinding around them makes no sense.

Being able to make a unit prototype immune to all 'stickers' would be great. The invisible 'navigator' unit I mentioned before can catch on fire, so there would be a weird flaming sprite running about the map if there was fire on the ground near vehicles.

A lot of people that use my vehicles put a lot of time into making road systems (even though my vehicles tend to ignore them most of the time). It would be great if the pathfinder had the option to factor in the vehicle friction modifier or walking speed modifier into the tile cost and heuristic so that units could follow paths and roads.

This may be hoping for too much, but it would be great if the a lot of the unit mechanics could be extended to vehicles, or perhaps an extended version of a unit that supports most of the vehicle properties such as:
Turning speed (probably have to force tank turning mode otherwise that would be very difficult)
Acceleration
A separate turret
Fuel use
An Inventory
Ammo

Edit: Also, a flag to prevent units from attacking blocking trees and other obstacles would be nice. I couldn't make a unit without an attack, so I tried making one with 0 damage but it gets stuck endlessly attacking trees for no damage.
gaelyte
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Thu Mar 29, 2018 6:44 pm
Contact:

Re: 0.17 Unit & AI additions

Post by gaelyte »

It would also be nice to have swimmer bitter, new bitters that can be an additional challenge for huge industries.
RocketManChronicles
Filter Inserter
Filter Inserter
Posts: 362
Joined: Mon Aug 01, 2016 2:38 pm
Contact:

Re: 0.17 Unit & AI additions

Post by RocketManChronicles »

Earendel wrote: Mon Oct 01, 2018 12:04 am A lot of people that use my vehicles put a lot of time into making road systems (even though my vehicles tend to ignore them most of the time). It would be great if the pathfinder had the option to factor in the vehicle friction modifier or walking speed modifier into the tile cost and heuristic so that units could follow paths and roads.
As a heavy user of the AAI modpack, I can attest to using roads. But due to the behavior, I have modified builds to accommodate the weird pathing the units take. In order to get the units to use "roads" through the factory, I use the mods' zones to make waypoints at intersections (this is before the latest updates with waypoints and pathfinding) and program the vehicles to go from point A to point B. Even though the y-coordinate of both points is the same, the unit does not always follow a straight line [along the road]. A lot of times, the vehicle will wander off to the side and in amongst assembling machines and furnaces, usually ending up on a belt and getting caught in an infinite attempt to drive against the belt direction until it eventually runs out of fuel. To combat that, I have set up walls along the "roads" to keep vehicles out of hazardous areas and control their movement better. They seem to like to run right up next to the wall, follow it, and then move out toward the next zone point. I would love to see them follow the straight line.
Brambor wrote: Fri Sep 28, 2018 6:49 pm Is it possible to make an autonomous EV car mod?
An AEV that you will just request to drive you to desired destination and it will drive you there, either on concrete floor or possibly avoiding buildings and trees.
Check out AAI mods, seriously. It's a game changer to enter a vehicle, and tell it where to drive you!
Klonan wrote: Sun Sep 30, 2018 10:30 am
gaelyte wrote: Sat Sep 29, 2018 8:51 am I remember I issue with Bob's mod' Robottic attack robots that despawned if you were too far away from they. Could it be possible to deactivate the fact that they're desactivated if we are away?

Yes, this is already fixed, they won't randomly despawn
(It was because they would repeatedly fail pathfinding)
This is really good news!
gaelyte wrote: Sun Sep 30, 2018 2:36 pm
THC4k wrote: Sun Sep 30, 2018 12:16 pm I wonder if the pathfinder can avoid getting run over by trains? That would be pretty important for any kind of modded unit.
It's rarther easy :
Solution 1 : The unit can't cross rails
Solution 2 : The unit can cross rails, and you have to put gates to protect them, like this : https://wiki.factorio.com/images/Fff-14 ... -gates.gif
With AAI mods, I have haulers and wardens moving all over the main area of my base, and they cross rails. With the mod, I am able to connect the circuit network that controls the units to the rail crossing circuit network. When a vehicle approaches, I have it stop and wait for a clear signal; which is checking several blocks up-stream of the rails for any trains. If any of the rail signals are red or yellow, the vehicle waits until the trains pass. Once given the clear, the vehicle crosses the tracks. While doing so, I set the last signal before the crossing to red and if any trains approach, they will stop. Once the vehicle reaches the other side, the AAI mod buildings send a signal to allow free flow of trains again and all signals turn green. Then the vehicle continues on its path. Quite fun setting it all up via circuit network.
Post Reply

Return to “Modding discussion”