What command must be given to cloak units? (for AI players)

What command must be given to cloak units? (for AI players)

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

What command must be given to cloak units? (for AI players)

Post by submarine »

For some reason, I cannot get AAI to cloak units.

Browsing spring source I found the following line in AIScommands.cpp:
*c = Command(CMD_CLOAK, cmd->options, cmd->cloak ? 1 : 0);

Thus, I concluded issuing the following command would cloak a unit.
Command c(CMD_CLOAK, 0u, 1);

Nothing is happening though. Can anybody help?
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: What command must be given to cloak units? (for AI players)

Post by lamer »

Most recent AIs use NewOO API (like native Shard did). There cloak command is simple as
unit->Cloak(true);
where unit is of springai::Unit* class provided by NewOOAPI.
It is possible to track down how newOO wraps command as in the end both legacy and newOO interfaces use engine's CAICallback::GiveOrder call. (Your example looks correct)

Additionally some games replaced in-engine commands by own lua implementation, for example in Zero-K there's self-cloak and area-cloak modules
const int CMD_WANT_CLOAK = 37382;
const int CMD_CLOAK_SHIELD = 31101;
unit->ExecuteCustomCommand(CMD_WANT_CLOAK, {state ? 1.f : 0.f}); // personal
unit->ExecuteCustomCommand(CMD_CLOAK_SHIELD, {state ? 1.f : 0.f}); // area

So which game is this about, which engine version?
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: What command must be given to cloak units? (for AI players)

Post by lamer »

This works for BAR's commanders for example (BAR latest git and spring 104.0.1-1553-gd3c0012 maintenance)
Command c(37382, 0, state ? 1 : 0);
ai->ct->GiveOrder(unitID, &c);
Tested with KAIK.
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Re: What command must be given to cloak units? (for AI players)

Post by submarine »

Thank you very much! I was using balanced_annihilation-v10.24 and in fact, replacing CMD_CLOAK with 37382 solved the problem. This also explains why the code used to work years ago when I initially wrote it.

Out of interest: Why do mods overwrite game internal behavior like command IDs?

Would the NewOO API work independently from the mod specific overwriting?
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: What command must be given to cloak units? (for AI players)

Post by lamer »

> Why do mods overwrite game internal behavior like command IDs?
Some commands. Engine's CMD_CLOAK=95, but either it's too slow to cloak, or too fast, or uses only energy for upkeep but not metal so it doesn't satisfy mod's needs. Or maybe there was a bug that no mod-dev could fix in cpp so they rewrote it in lua.
New mechanics that other mods won't use are added through lua. Also i'd imagine that it is easier to fix own code in lua then trying to dig into other's cpp.
Zero-K is a good example of new weapon types, energy grid, different mex mechanics added though lua. And yet Spring RTS is a very good common base to handle interaction of 1000 units, pathing, terrain deformations.

> Would the NewOO API work independently from the mod specific overwriting?
I don't think so. NewOO API is just another wrapper, finished at 90%.
It looks nicer for beginners and Java; has support for {Game/Team/Unit}RulesParams, but it's heavier on memory allocations than legacy - wraps every ID into object though often AI has to query only ID. Yet legacy is deprecated, no one improved it. Both legacy and newOO can communicate with lua space, which can make AI even more mod specific. Native Shard was close to become mod-independent AI through scripting - lua configs.
And yet there's great and very specific mod Spring 1944 which still doesn't work with any current native AI (as i heard).

Some devs prefer mod-dependent lua-AIs (gadgets).
But those are only my assumptions and theories.
submarine
AI Developer
Posts: 834
Joined: 31 Jan 2005, 20:04

Re: What command must be given to cloak units? (for AI players)

Post by submarine »

Any good idea how a generic solution could look like? I do not want to hardcode a cloak command ID only valid for BA/BAR.

I could add the exact id to the mod configuration file of AAI and read it at startup.
lamer
Posts: 153
Joined: 08 Mar 2014, 23:13

Re: What command must be given to cloak units? (for AI players)

Post by lamer »

General rule is that you really don't want to write generalist AI.

So old-school approach: AI consists of rules and data. Make scriptable rules (lua/squirrel/angelscript) for economy system, unit behaviours; configs for data.
And general cpp backend (tools/framework) for AI to work, that includes terrain analyzer, building placement, pathing with theatmaps and whatnot-maps, clusterization, choke point detection.

Put CMD_IDs into configs. Though it's so low level, that without scriptable/dynamic rules such hassle doesn't seem worth it.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: What command must be given to cloak units? (for AI players)

Post by FLOZi »

lamer wrote: 03 Sep 2020, 15:13 General rule is that you really don't want to write generalist AI.
This is my opinion, too. Since your hey day submarine the lua API has expanded and its use has grown exponentially with games diverging ever further from the OTA 'template'.

No generic AI could get past the first hurdle in MechCommander: Legacy as to get _any_ unit on the battlefield requires use of a custom command. AI's don't even make sense for some games like the Ludum Dare projects.
Post Reply

Return to “Engine”