2025-07-20 00:43 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0003587Spring engineAIpublic2015-03-22 15:44
Reportercranphin 
Assigned To 
PrioritynormalSeveritytweakReproducibilityalways
StatusnewResolutionopen 
Product Version93.2 
Target VersionFixed in Version 
Summary0003587: remove groupai code
DescriptionI cannot add units to groups from AI code.
There's a method for it, but it doesn't work.

I think it used to work (long ago), but it was broken in this change:
https://github.com/spring/spring/commit/c809eb749fe23024b8829f69eb996a1a69b295b5

The relevant code in rts\ExternalAI\SSkirmishAICallbackImpl.cpp seems to have been commented out in a big change, probably since it broke and to fix it later, but it was never fixed and re-enabled.

The problem is that COMMAND_GROUP_ADD_UNIT and COMMAND_GROUP_REMOVE_UNIT are now silently ignored.

For me this is significant, since I hoped to use groups to lower the amount of commands sent by the ai (one command to move a group, instead of many), this is more relevant since Spring limits bandwidth, which tends to break ai's if they send too many commands.
Additional InformationThis is the commented out bit of code:
/*
        case COMMAND_GROUP_ADD_UNIT:
        {
            SAddUnitToGroupCommand* cmd = (SAddUnitToGroupCommand*) commandData;
            cmd->ret_isExecuted =
                    clb->AddUnitToGroup(cmd->unitId, cmd->groupId);
            break;
        }
        case COMMAND_GROUP_REMOVE_UNIT:
        {
            SRemoveUnitFromGroupCommand* cmd =
                    (SRemoveUnitFromGroupCommand*) commandData;
            cmd->ret_isExecuted = clb->RemoveUnitFromGroup(cmd->unitId);
            break;
        }
*/
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files

-Relationships
has duplicate 0003247closedabma AI JavaOO 'Group' not constructable 
+Relationships

-Notes

~0010088

cranphin (reporter)

Not sure if this is relevant, but two related commands which were also commented out, were later un-commented in this commit:
https://github.com/spring/spring/commit/295232872dbc27f5f1ae416bd638de82ff9abaa1

~0010141

cranphin (reporter)

Yay, can build on windows now :)

Seems the commands/statics got changed a bit, so I'm guessing new code should be like this:
case COMMAND_UNIT_GROUP_ADD:
{
    SGroupAddUnitCommand* cmd = static_cast<SGroupAddUnitCommand*>(commandData);
    clb->AddUnitToGroup(cmd->unitId, cmd->groupId);
    break;
}
case COMMAND_UNIT_GROUP_CLEAR:
{
    SGroupClearUnitCommand* cmd = static_cast<SGroupClearUnitCommand*>(commandData);
    clb->RemoveUnitFromGroup(cmd->unitId);
    break;
}

Compiling that now (takes long! XD) so I can try it tomorrow :)

~0010144

cranphin (reporter)

Last edited: 2013-03-21 08:38

View 2 revisions

Hmm, bleh, somehow with that code adding to group still seems to do nothing at all :)

~0010145

cranphin (reporter)

This:
case COMMAND_GROUP_CREATE:
{
    SCreateGroupCommand* cmd = static_cast<SCreateGroupCommand*>(commandData);
    cmd->ret_groupId = clb->CreateGroup();
    LOG("GRP - SkirmishAI (ID = %i, team ID = %i) Created group %i!",
            skirmishAIId, skirmishAIId_teamId[skirmishAIId], cmd->ret_groupId);
    break;
}
case COMMAND_UNIT_GROUP_ADD:
{
        SGroupAddUnitCommand* cmd = static_cast<SGroupAddUnitCommand*>(commandData);
    LOG("GRP - SkirmishAI (ID = %i, team ID = %i) Adding %i to group %i!",
            skirmishAIId, skirmishAIId_teamId[skirmishAIId], cmd->unitId, cmd->groupId);
    clb->AddUnitToGroup(cmd->unitId, cmd->groupId);
    break;
}

Gives me this:
[f=0005370] GRP - SkirmishAI (ID = 0, team ID = 0) Created group 10!
[f=0005370] GRP - SkirmishAI (ID = 0, team ID = 0) Adding 13709 to group -1!

So I guess the group id isn't propagated somehow or such :)
Right, more tomorrow, out of time XD

~0010148

cranphin (reporter)

Ooh, this might work, using toGroupId instead of groupId:
case COMMAND_UNIT_GROUP_ADD:
{
    SGroupAddUnitCommand* cmd = static_cast<SGroupAddUnitCommand*>(commandData);
    clb->AddUnitToGroup(cmd->unitId, cmd->toGroupId);
    break;
}
case COMMAND_UNIT_GROUP_CLEAR:
{
    SGroupClearUnitCommand* cmd = static_cast<SGroupClearUnitCommand*>(commandData);
    clb->RemoveUnitFromGroup(cmd->unitId);
    break;
}
Compiling now :)

~0010150

cranphin (reporter)

Yup, that's got it :)
I can make groups in a Java AI now, whee ^_^

Could someone stick it in git? :)
In rts\ExternalAI\SSkirmishAICallbackImpl.cpp
Replace
/*
        case COMMAND_GROUP_ADD_UNIT:
        {
            SAddUnitToGroupCommand* cmd = (SAddUnitToGroupCommand*) commandData;
            cmd->ret_isExecuted =
                    clb->AddUnitToGroup(cmd->unitId, cmd->groupId);
            break;
        }
        case COMMAND_GROUP_REMOVE_UNIT:
        {
            SRemoveUnitFromGroupCommand* cmd =
                    (SRemoveUnitFromGroupCommand*) commandData;
            cmd->ret_isExecuted = clb->RemoveUnitFromGroup(cmd->unitId);
            break;
        }
*/

With
case COMMAND_UNIT_GROUP_ADD:
{
    SGroupAddUnitCommand* cmd = static_cast<SGroupAddUnitCommand*>(commandData);
    clb->AddUnitToGroup(cmd->unitId, cmd->toGroupId);
    break;
}
case COMMAND_UNIT_GROUP_CLEAR:
{
    SGroupClearUnitCommand* cmd = static_cast<SGroupClearUnitCommand*>(commandData);
    clb->RemoveUnitFromGroup(cmd->unitId);
    break;
}

I don't think it can break anything significant, since no AI's call it anyways ;)
Thanks!

~0010151

cranphin (reporter)

Hmm, drat, rts\ExternalAI\AICallback.cpp:
int CAICallback::GiveGroupOrder(int groupId, Command* c)
{
    return 0;
}

I'm getting the impression group commands was never fully implemented? XD

~0010152

cranphin (reporter)

Ah, right, this could be an issue :)
https://github.com/spring/spring/commit/f53959305bd9c503a0716c3480002f4192d245bf

~0010153

abma (administrator)

sorry, didn't knew that... hoijui who removed this is already an inactive dev. so the guy who implemented this... who knows :)

so the fix is more likely to remove these functions?!

~0010157

cranphin (reporter)

Hmm, I was hoping groups would allow me to send less commands from the AI, send one command to move the group, instead of one command per unit.
I wanted that, since AI's tend to trigger the bandwidth limiter stuff :)

But it seems groups never quite supported sending commands to them in that way, and I'm not sure it would've sent lots of commands under water anyways :)

So considering that, mayby it would be good to remove all Group stuff from the ai interfaces? Right now it creates a Java Group class with many methods, all of which pretty much don't do anything. Very confusing for any AI dev's :)

I could possibly do that, if I know how to best provide code changes ;)
Use git somehow I guess? :)

~0010158

abma (administrator)

yep! at best make a pull request. only problem is that this commit shouldn't break existing ais if possible :)

are you on windows or linux? if windows i've heard sourcetree should be a good gui-client, but i never tried it...
+Notes

-Issue History
Date Modified Username Field Change
2013-03-16 17:20 cranphin New Issue
2013-03-16 17:25 cranphin Note Added: 0010088
2013-03-21 00:12 cranphin Note Added: 0010141
2013-03-21 08:38 cranphin Note Added: 0010144
2013-03-21 08:38 cranphin Note Edited: 0010144 View Revisions
2013-03-21 09:04 cranphin Note Added: 0010145
2013-03-21 20:20 cranphin Note Added: 0010148
2013-03-21 23:19 cranphin Note Added: 0010150
2013-03-22 00:00 cranphin Note Added: 0010151
2013-03-22 00:10 cranphin Note Added: 0010152
2013-03-22 00:24 abma Note Added: 0010153
2013-03-22 08:49 cranphin Note Added: 0010157
2013-03-22 10:50 abma Note Added: 0010158
2013-03-22 10:51 abma Severity minor => feature
2013-03-22 10:51 abma Summary Cannot add units to groups in AI (code got broken, and never fixed). => remove groupai code
2013-03-22 10:51 abma Summary remove groupai code => remove unused groupai code
2013-12-23 23:47 abma Summary remove unused groupai code => remove or fix (currently unused) groupai code
2013-12-24 00:09 abma Severity feature => tweak
2013-12-24 00:09 abma Summary remove or fix (currently unused) groupai code => remove groupai code
2015-03-22 15:44 abma Relationship added has duplicate 0003247
+Issue History