Group AI help

Group AI help

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
User avatar
Acidd_UK
Posts: 963
Joined: 23 Apr 2006, 02:15

Group AI help

Post by Acidd_UK »

I'm making my first (simple) group AI. What I want is for the group AI to 'grab' orders issued to individual units - effectively, so that any orders given to iundividual units in the group are given to the group as a whole. Is there any way to do this? I see that the giveCommand method of a gorpu AI has no unit parameter so I assume it's only called when you give an order to the whole group...

Secondly, what's the easiest way to get the group AI to be compatable with the current release version of Spring (so I can test my AI against a known-good version of spring)? I don't really want to revert my whole svn back to an old revision if I don't have to...
colorblind
Spring Developer
Posts: 374
Joined: 14 Mar 2005, 12:32

Post by colorblind »

1:
AFAIK there is no groupAI function that is called whenever a unit in the group receives a user order.
You probably could determine when such an event has taken place by keeping track of aicb->GetCurrentUnitCommands(int unitid).

But why would you do such a thing anyway? Pressing Q once to select the group isn't any trouble at all ...

2:
The easiest way is to keep an addinitional checkout of tags/taspring_0.72b1 (or whatever the current release version is) alongside of your trunk checkout.
Giving the choice of developing against tags/taspring_0.72b1 or trunk, I'd go for trunk. Because then you can freely develop your AI without having to worry about interface changes, and you can also test it online.
User avatar
Acidd_UK
Posts: 963
Joined: 23 Apr 2006, 02:15

Post by Acidd_UK »

1. It's more trouble than not having to press it. Manaully keeping track of their orders to trap this situation also seems like an unnecessary overhead. Basically, I don't want the user to be able to control individual units in the group.

2. I can't test it online using the latest version of trunk, since trunk is a newer AI interface version than 0.72, isn't it? Certainly, if I put the dll in my main aidll folder and run spring, it crashes with a 'wrong AI interface' error. Am I doing something wrong?
colorblind
Spring Developer
Posts: 374
Joined: 14 Mar 2005, 12:32

Post by colorblind »

Acidd_UK wrote:Basically, I don't want the user to be able to control individual units in the group.
Ah, why didn't you say so in the first place :-).
Well if you really don't want users giving individual units orders, I guess the best way to fix it is to change the AI interface a bit:

* Have the GroupAI define a new boolean "AllowUserUnitControl"
* If it's true, keep things like they are
* If it's false, directly select the group when a user selects a unit belonging to that group.

That way we don't need another function IGroupAI::UnitIsGivenOrder() or something like that.
If AllowUserUnitControl is false, users can never select individual units in that particular groupAI, and thus can never issue orders to them. Problem solved.

I'll probably implement this sooner or later. In the mean time you'll just have to live with the current situation.


2. I didn't say you should or could test in online when you build it against trunk. You have to build it against tags/taspring_0.72b1. So do a seperate check out of that, develop and build your AI against it, and test it online.

But I believe I said the same thing two posts ago :? .
User avatar
Acidd_UK
Posts: 963
Joined: 23 Apr 2006, 02:15

Post by Acidd_UK »

First off, thanks for the advice!

1. I was thinking about something similar. However, for my group AI, I would like the player to be able to issue orders to individual units in the group, however, those orders would be processed by the group AI, rather than by the unit. In effect, the would be no difference between giving the order to 1, n or all of the units in the group - the groupAI would work out what the individual units do given the current 'group' order. I hope I explained that ok...

The thing that I thought about doing was to add another function to the group AI interface -

Code: Select all

UnitGetCommand(int unitid, command * c)
This funcdtion would effectively mirror the existing function GetCommand(int unitid, command * c), which is called when the whole group is issues an order by the player. UnitGetCommand would be called when an individual unit in the group was given an order. The default action would be to hand this off to wherever unit commands normally go - i.e. if you didn't redefine the function it in your specific groupAI, then individual unit orders would be handled as normal. However, I'm not sure you cxan do this with the current system, I think I'm thinking of subclassing and overriding and without having the spring source in front of me, I can't remember exactly how the group ai stuff is set up. However, it would be pretty easy to add this function to existing groupais anyway - it would probably look like

Code: Select all

UnitGetCommand(int unitid, command * c)
{
  aicb->UnitGiveCommand(unitid, c) // I can't actually remember how to do this atm, but you get the idea
}
The idea being that for group ais like mine, you could effectively 'grab' the unit's command before it's processed, this I could do something like

Code: Select all

UnitGetCommand(int unitid, command * c)
{
  GetCommand(c) // This effectively gives the order to the groupai
}
Does that make any sense - can you see what I'm trying to do, roughly? Is this a good way to do it? All it would need is for a quick check on the normal order-handling stuff to see if a unit given an order is in a groupAI and if so then hand off the command to the group ai's routine rahter than the unit's own ai routine.

E.g.

Currently (this is how i imagine it works, i cant check right now)
1. Global command order handler receives command
2. Passes command to unit ai

New system:
1. Global command order handler receives command
2. If the target of the command is a unit in a group ai, pass the command to the group ai's
2. Passes command to unit ai's UnitGiveCommand function
3. Otherwise pass it to the unit directly as normal.

Thanks!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

CommandRecieved() sounds better than UnitGetCommand()
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

colorblind wrote: * If it's false, directly select the group when a user selects a unit belonging to that group.
That way you can't remove units from the group. I guess it's better to show an empty menu in that case with only a few buttons like "Clear group", "Select group", etc.
Post Reply

Return to “AI”