Identifying a unit's builder

Identifying a unit's builder

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
LoidThanead
Posts: 58
Joined: 27 Feb 2008, 16:16

Identifying a unit's builder

Post by LoidThanead »

Hi all,

I am working on a Spring AI, and I ran into a small problem. The situation is as follows:

My AI consists of separate modules, each performing a specific task. One of these is the BuildManager, which handles the construction of units. Other modules can request the BuildManager to build a specific unit, and it will comply. It selects an available unit that can build the requested type, then gives the correct BuildUnitAIOrder to that unit. Next, I would like to be able to inform the requesting module which unit has been created for them. Unfortunately, I have no way of knowing.

The build command triggers a UnitCreated event in the Spring engine, containing the new unit. However, the AI only knows what unit it gave the build command to, and there seems to be no way to link the created unit to the unit that is building it.

At first glance it seems obvious, since the AI itself gave the build order, right? All it needs is to do is to handle the resulting UnitCreated event and remember that it was built by unit x.
It's not that easy however. It is perfectly possible that at the same moment multiple units, possibly of the same type, are created by different builders, since modules are not required to use the BuildManager for their construction needs.
This means that at any given moment it is possible that multiple build commands are given, and multiple UnitCreated events are triggered, with no way to tell which unit resulted from which command.

Therefore, my request is to include a 'createdBy' field in the UnitCreated event. This can be null whenever the unit was not created by another unit, such as the starting units, or units gained through cheats.


I'd like to think that I investigated the matter thoroughly. However, should I have missed some way to get the required information I would be happy to hear. Comments and suggestions are welcome, of course.
Last edited by LoidThanead on 26 May 2009, 13:42, edited 1 time in total.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Identifying a unit's builder

Post by imbaczek »

+1 need this in my ai for goal tracking, too.

to preserve compatibility, a UnitStartConstruction(builder, built) event would be fine.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Identifying a unit's builder

Post by Kloot »

Done.

IMO it was cleaner to add an extra argument to IGlobalAI::UnitCreated and update the AI's in Spring's repository than to introduce a new, mostly redundant event (despite breaking back-compat), since there is no previous major engine build that could load them in their current incarnation anyway.
User avatar
LoidThanead
Posts: 58
Joined: 27 Feb 2008, 16:16

Re: Identifying a unit's builder

Post by LoidThanead »

Thank you very much. :)
I'll try it out as soon as I can.
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

Re: Identifying a unit's builder

Post by Gnomre »

nevermind, they forgot to teach us how to read in gnomerica
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Identifying a unit's builder

Post by AF »

As simple as this sounds, it quickly gets complicated once you really start to think about it.

Here are some scenarios that blow thsi request and susbequent commits apart:
  • 5 units are all given exactly the same order, as a result the building has 5 builders, all of which started at the same time. Since the event only has 1 field for builder, which builder is 'the' designated builder?
  • In the above scenario the AI chooses the lead builder and does some logic on it, however we now have 4 builders who are unable to get back onto the AI logic merry go round, loose ends of sorts
  • The game developer has decided to make buildings build themselves, and the builder only spawns or creates the building before moving onto another project.
  • The builder is incapable of building and merely sets down foundations for which a construction unit finishes the job, hence a seperation of starting construction and construction in progress
  • The game developer has done away with builders entirely, and wants CC style building construction
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Identifying a unit's builder

Post by imbaczek »

the idea is to estabilish a link between the first builder and the unit that's being built; everything else the AI can keep track of by itself because it'll be giving assist commands, but there simply was no authoritative way to find out which builder started a construction.

re game developer parts: the game will have to tell the ai what it does when building via a protocol orthogonal to the engine. there's no way the ai interface could list all possibilities here.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Identifying a unit's builder

Post by lurker »

  • 5 units are all given exactly the same order, as a result the building has 5 builders, all of which started at the same time. Since the event only has 1 field for builder, which builder is 'the' designated builder?
    There's no such thing as 'at the same time'. 'builder' is defined as 'the unit that intiates construction'. Only one unit does this.
  • In the above scenario the AI chooses the lead builder and does some logic on it, however we now have 4 builders who are unable to get back onto the AI logic merry go round, loose ends of sorts
    If your AI can't handle assisting, you have bigger issues.
  • The game developer has decided to make buildings build themselves, and the builder only spawns or creates the building before moving onto another project.
    The only requirement here is knowing that the unit has been created. Done. But even the issues you only imply are taken care of. The AI will also get told when the builder is done working (instantly) and when the building is complete (later).
  • The builder is incapable of building and merely sets down foundations for which a construction unit finishes the job, hence a seperation of starting construction and construction in progress
    See the last reply, depending on what you mean by 'foundations'. If that doesn't fit, there might be issues with losing the builder, but it might also be true that the builder is a different unit (the AI will get told) or no unit at all (nothing to do then).
  • The game developer has done away with builders entirely, and wants CC style building construction
    Not an issue here. If the AI is capable of giving orders for construction, it will be capable of understanding the reply from lua. If it's not capable, then it has no builders to worry about.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Identifying a unit's builder

Post by AF »

As I understand it, 5 builders given an identical build order in the same frame isnt the same as assisting as assisting in AIs normally involves repair, however it is plausible that the only thing that 5 builders decide energy is needed and a solar is the best thing to build, and for all 5 the nearest free spot is the same, under the current engine logic builders that arrive late will auto assist, but they will not have repair commands.

To demonstrate this behaviour, take a swarm of air cons, select them all, and while hovering over a spot, order them to build a factory. None of them are repairing the factories, they're all building as if they started it themselves.

A simple AI logic could easily handle this scenario, but as the logic becomes more complex the assumption of a single or lead builder becomes a problem, and needs to be specifically handled by the logic or designed for to prevent unforeseen circumstances.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Identifying a unit's builder

Post by lurker »

You can give one builder the order, wait until it's about to start, and then give a builder on the other side of your base the same order. When it arrives, it'll start assisting. I don't know exactly what it uses in the engine, but it's not an artifact of starting in the same frame.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Identifying a unit's builder

Post by Tobi »

AF wrote:As I understand it, 5 builders given an identical build order in the same frame isnt the same as assisting as assisting in AIs normally involves repair, however it is plausible that the only thing that 5 builders decide energy is needed and a solar is the best thing to build, and for all 5 the nearest free spot is the same, under the current engine logic builders that arrive late will auto assist, but they will not have repair commands.

To demonstrate this behaviour, take a swarm of air cons, select them all, and while hovering over a spot, order them to build a factory. None of them are repairing the factories, they're all building as if they started it themselves.

A simple AI logic could easily handle this scenario, but as the logic becomes more complex the assumption of a single or lead builder becomes a problem, and needs to be specifically handled by the logic or designed for to prevent unforeseen circumstances.
Try in a game with canAssist=0. (e.g. SWIW)

You'll see easily only one builder builds and the others (don't) assist.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Identifying a unit's builder

Post by AF »

I mention the frames assuming all builders arrive and start construction within the same frame.

So if this si the case, the non lead builders, do they have a repair command or a construction command that gives the behaviour of assisting?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Identifying a unit's builder

Post by lurker »

It shouldn't matter when they arrive at all, when they init the construction either has begun or it hasn't, and this happens mid-frame. As to what order that is, probably build, but I'll test everything later.
Post Reply

Return to “Feature Requests”