Instantly remove units
Moderators: hoijui, Moderators
Instantly remove units
Hi,
To do numerous battle simulations in a row, we use the command COMMAND_UNIT_SELF_DESTROY to destroy surviving units from the previous battle, in order to be ready to simulate the next battle.
To initiate the next battle, we can spawn new units instantly using the command COMMAND_CHEATS_GIVE_ME_NEW_UNIT. However, since there is a looong wait before the COMMAND_UNIT_SELF_DESTROY command actually makes the units suicide, we have to wait a long time before we can initiate the new battle.
Is there any possibility to instantly remove/suicide/destroy/kill/vanish a unit?
To do numerous battle simulations in a row, we use the command COMMAND_UNIT_SELF_DESTROY to destroy surviving units from the previous battle, in order to be ready to simulate the next battle.
To initiate the next battle, we can spawn new units instantly using the command COMMAND_CHEATS_GIVE_ME_NEW_UNIT. However, since there is a looong wait before the COMMAND_UNIT_SELF_DESTROY command actually makes the units suicide, we have to wait a long time before we can initiate the new battle.
Is there any possibility to instantly remove/suicide/destroy/kill/vanish a unit?
Re: Instantly remove units
This is lua gadget land
It would be faster to run headless spring at uber high gamespeed, and simply exit the game and restart. This would have the benefit of avoiding problems such as changed terrain, or not being able to 'reset' the state of lua game logic
It would be faster to run headless spring at uber high gamespeed, and simply exit the game and restart. This would have the benefit of avoiding problems such as changed terrain, or not being able to 'reset' the state of lua game logic
Re: Instantly remove units
it should be possible, but will take some work to implement.
please tell us about your AI please!
its it open source, can we see it? are you writing a paper?
as they are already doing it this way, i guess they sorted out the other problems already, eg. using undeformable map and using BA (which will may have little Lua state problems. and of course insta-killing all units and reading commanders is much faster then restarting spring.
please tell us about your AI please!
its it open source, can we see it? are you writing a paper?
as they are already doing it this way, i guess they sorted out the other problems already, eg. using undeformable map and using BA (which will may have little Lua state problems. and of course insta-killing all units and reading commanders is much faster then restarting spring.
Re: Instantly remove units
Well, our very-much work-in-progress AI is actually public, but it is not at all a usable AI, since we are just using it to do research in som specific areas, and hence it actually does not play the game.
We are writing both papers and reports, but just as the current AI, they are not about a complete AI. The report from our last semester can be found here, but our paper from the last semester is currently not public, since it is under review for ADMI-10.
The battle simulation i'm referring to in this thread is still in a private repository, but will be made public when completed. We are simulating every single relevant battle between unit group compilations in BA, in order to use this as critical information for implementing RL for battle decisions.
Regarding the instant-kill we have currently just "hacked" it in our version of spring, by forcing selfDCountdown to be 1 in rts\Sim\Units\Unit.cpp. Though we still have some issues where it seems like the units are still not suiciding in some rare cases (<%1 of the times).
And yes, hoijui, you are right that we are using undeformable map, no-wrecks, and BA
We are writing both papers and reports, but just as the current AI, they are not about a complete AI. The report from our last semester can be found here, but our paper from the last semester is currently not public, since it is under review for ADMI-10.
The battle simulation i'm referring to in this thread is still in a private repository, but will be made public when completed. We are simulating every single relevant battle between unit group compilations in BA, in order to use this as critical information for implementing RL for battle decisions.
Regarding the instant-kill we have currently just "hacked" it in our version of spring, by forcing selfDCountdown to be 1 in rts\Sim\Units\Unit.cpp. Though we still have some issues where it seems like the units are still not suiciding in some rare cases (<%1 of the times).
And yes, hoijui, you are right that we are using undeformable map, no-wrecks, and BA

Re: Instantly remove units
Spring.RevertHeightMap() can be used to revert
the terrain's height map to its original state.
Spring.KillUnit() can be used to instantly remove units.
the terrain's height map to its original state.
Spring.KillUnit() can be used to instantly remove units.
Re: Instantly remove units
yeah.. there are basically two options.
1. allowing to kill units instantly with a chat command, the ones that users can use too. that would work somehow like:
2. writing a gadget (Lua), and putting it into the mod. the gadget would use the functions that trepan showed. you could then communicate with that gadget using chat commands, eg. like in 1., but you had to use others, not already used by the engine.
Writing a gadget is simple. just extract the contents of the mod, go to right folder (something like LuaUI/Gadgets or Rules), then copy paste one file and edit it using the functions trepan mentioned and this reference:
http://springrts.com/wiki/Lua_Scripting
http://springrts.com/wiki/LuaCallinReturn
if you always use the same mod (plus version), and i guess you, then 2. seems like a viable option.
... and thanks for the info about your project
1. allowing to kill units instantly with a chat command, the ones that users can use too. that would work somehow like:
Code: Select all
/cheat
/destroy 456 prune
Writing a gadget is simple. just extract the contents of the mod, go to right folder (something like LuaUI/Gadgets or Rules), then copy paste one file and edit it using the functions trepan mentioned and this reference:
http://springrts.com/wiki/Lua_Scripting
http://springrts.com/wiki/LuaCallinReturn
if you always use the same mod (plus version), and i guess you, then 2. seems like a viable option.
... and thanks for the info about your project

Re: Instantly remove units
Code: Select all
function gadget:GetInfo()
return {
name = "Wipe Units Cmd",
desc = "Implement the new command /luarules wipeunits",
author = "zwzsg",
date = "18 february 2010",
version = "1.0",
license = "Free",
layer = 0,
enabled = true
}
end
if (gadgetHandler:IsSyncedCode()) then
--SYNCED
local function WipeUnits(Cmd,Line,WordList,Player)
for _,u in ipairs(Spring.GetAllUnits()) do
Spring.DestroyUnit(u,false,true)
end
end
local function SetupWipeUnitsCmd()
local cmd,func,help
cmd = "wipeunits"
func = WipeUnits
help = " instantly remove all units"
gadgetHandler:AddChatAction(cmd,func,help)
Script.AddActionFallback(cmd..' ',help)
end
function gadget:Initialize()
SetupWipeUnitsCmd()
end
end
- Attachments
-
- BA-WipeUnits.sd7
- Must be placed along side BA71.sd7
Is a new mod, "Balanced Annihilation V7.1-WU" that is just like BA, but with the addition of a new command, /luarules wipeunits - (912 Bytes) Downloaded 16 times
Re: Instantly remove units
Thank you very much for your Lua inputs. We will try to see if we get better results with that approach, instead of hacking in the engine 

Re: Instantly remove units
I now tested it, and it looks very good. Great that we don't have to wait for the explosions!
However, one problem is remaining. Is there any way to activate such a lua command from the AI? I tried sending the command by using "COMMAND_SEND_TEXT_MESSAGE", but that just makes the AI write the "/luarules wipeunits" command in the chat, without activating the command.
However, one problem is remaining. Is there any way to activate such a lua command from the AI? I tried sending the command by using "COMMAND_SEND_TEXT_MESSAGE", but that just makes the AI write the "/luarules wipeunits" command in the chat, without activating the command.
Re: Instantly remove units
you can make a widget that listens for chats from AI and invokes this command, but i don't know if it'll work in spring headless.
Re: Instantly remove units
i think it should.. with latest springheadless. hugh removed the engine internal setting enforcements (which included Lua widgets disabling).
Re: Instantly remove units
I hoped you would know how an AI can send commands, for I know nothing about the C++ AI interface.
If all else fails, I could make the gadget analyse every chat line and look for a keyword.
If all else fails, I could make the gadget analyse every chat line and look for a keyword.
- Attachments
-
- cnslcmd.lua
- Here is my console command widgets. It is a file that must be saved into the \LuaUI\Widgets\ folder, either inside a mod, or outside. I originally made that widget to remove the hassle to append "luarules" to every gadget command. Since it parses chat lines instead of registering commands, hopefully it will parse the AI text message too. Make your AI say the TEXT /wipeunits, and that widget will translate it into the COMMAND /luarules wipeunits
- (523 Bytes) Downloaded 17 times
Re: Instantly remove units
Thank you very much, yet again zwzsg! Your code showed me how to let Lua parse AI chat commands.
And no, as far as i know, there isn't any direct way to access Lua commands from the C++ AI interface, but i might have missed something.
Nevertheless, based on your code, i made this simple code, which takes every "/luarules x" command from the chat, and executes it:
Without that code, the "/luarules xxx" chat-commands from the AI, would just be shown in the chat-history without being executed.
And no, as far as i know, there isn't any direct way to access Lua commands from the C++ AI interface, but i might have missed something.
Nevertheless, based on your code, i made this simple code, which takes every "/luarules x" command from the chat, and executes it:
Code: Select all
function widget:AddConsoleLine(line,priority)
if string.match(line,"/luarules (.+)") then
Spring.SendCommands(string.match(line,"/(luarules .+)"))
end
end
Re: Instantly remove units
>_< That's practically what my widget does, except with mine the AI wouldn't even need to write "luarules" between the "/" and the command.
I also had some worries issuing the same chat command that was read could cause infinite loop, hence why I discarded chat messages already starting by /luarules.
FYI, Spring.SendCommands is not limited to sending Lua commands. It's a lua command to execute any Spring command, including hard coded local or remote commands, such as for instance Spring.SendCommands{"cheat","advshading 1"} I am actually surprised that the C++ AI interface has no equivalent to this SendCommands fonction.
Symmetrically, the commands registered by a Lua gadget can be called in all the same ways as hardcoded commands. If you were to tell your AI to run any of the commands listed in /docs/cmds.txt, how would you?
Anyway, since your main goal is to work on your learning AI thesis, not to learn Lua, as long as what you have now gives satisfaction, we could leave it at that.
I also had some worries issuing the same chat command that was read could cause infinite loop, hence why I discarded chat messages already starting by /luarules.
FYI, Spring.SendCommands is not limited to sending Lua commands. It's a lua command to execute any Spring command, including hard coded local or remote commands, such as for instance Spring.SendCommands{"cheat","advshading 1"} I am actually surprised that the C++ AI interface has no equivalent to this SendCommands fonction.
Symmetrically, the commands registered by a Lua gadget can be called in all the same ways as hardcoded commands. If you were to tell your AI to run any of the commands listed in /docs/cmds.txt, how would you?
Anyway, since your main goal is to work on your learning AI thesis, not to learn Lua, as long as what you have now gives satisfaction, we could leave it at that.
Re: Instantly remove units
Well just almost - the problem with using your function as-is, is that the AI's chat lines didn't match your regex:zwzsg wrote:>_< That's practically what my widget does, except with mine the AI wouldn't even need to write "luarules" between the "/" and the command.
Code: Select all
<SkirmishAI: BattleSim 666 (team 0)>: /luarules wipencunits
Well we can't directly. There are "wrapper" functions for some common-used commands, but far from all of them.zwzsg wrote: If you were to tell your AI to run any of the commands listed in /docs/cmds.txt, how would you?
Re: Instantly remove units
Oh. Then tell you can probably workaround by making the AI say "\n/wipeunits"allanmc wrote:Well just almost - the problem with using your function as-is, is that the AI's chat lines didn't match your regex:Code: Select all
<SkirmishAI: BattleSim 666 (team 0)>: /luarules wipencunits
IDKallanmc wrote:Is there any way to discard matched console-lines, so that they are not printed in the console or written to infolog.txt? Discarding default behavior. I thought of using "return false", but that didn't do anything.
Well, if the need ever arise, you now know how to plumb that with Lua.allanmc wrote:Well we can't directly. There are "wrapper" functions for some common-used commands, but far from all of them.zwzsg wrote:If you were to tell your AI to run any of the commands listed in /docs/cmds.txt, how would you?
Re: Instantly remove units
If anyone's interested, i solved the problem by allowing the AI to send console commands using the chat (just as the user can). The small change to rts/ExternalAI/AICallback.cpp can be seen here:
http://github.com/initram/springheadles ... 5ac#diff-0
http://github.com/initram/springheadles ... 5ac#diff-0
- Attachments
-
- 0001-AI-can-do-console-commands.txt
- 0001-AI-can-do-console-commands
- (1.76 KiB) Downloaded 95 times
Last edited by allanmc on 23 Feb 2010, 16:06, edited 1 time in total.
Re: Instantly remove units
And, if anyone is interested, here is the battle-simulator AI:
http://github.com/allanmc/BattleSim/
It requires the above mentioned patch, which is included in this Spring fork:
http://github.com/initram/springheadless/
If two instances of the AI is added to a game, they will simply fight 225625 battles between various group compilations, and in a binary file store a value [-100;100] for each battle indicating which team won, and how "well" it won.
http://github.com/allanmc/BattleSim/
It requires the above mentioned patch, which is included in this Spring fork:
http://github.com/initram/springheadless/
If two instances of the AI is added to a game, they will simply fight 225625 battles between various group compilations, and in a binary file store a value [-100;100] for each battle indicating which team won, and how "well" it won.