Page 1 of 2
Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 04:36
by bobthedinosaur
CarRepairer and I were talking about making a repair function that allows for repairs of only units from a defined list or category, but there are many issues with setting this up.
Something as simple as guard could tell a unit to repair a unit, so there would need to be some kind of repair while guarding intercept and kill gadget that still allows guard to work, but that may prove difficult. Same with patrol orders.
We discussed making a weapon with negative damage, but that would be a disaster fighting with the attack commands, and getting it to work automatically on friendlies. So definitely a no go that way.
There is also an idea of not using the engine's repair function and making a custom heal, but that would be difficult setting up move orders to get to a target to be healed, and settign up auto heal on gaurd and patrol.
Does any one have an thoughts or insight on a way to get a customized repair function to work?
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 06:11
by aegis
what style is the mod?
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 06:42
by ==Troy==
Engine change, but a sensible one :
Apply damage/armor modifiers to the repair speed.
If 0 damage/repair is dealt on a certain armour the action is aborted.
Many games do that way, I am surprised that spring does not have such capability while providing armour system already.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 07:52
by bobthedinosaur
that sounds good to me troy, but I'll believe it when I see it.
aegis its for many games, I can use it for several of my projects and Car was talking about using it on his CA kingdoms game. As I was telling Car it looks weird having a mechanic walk up to a horse or pig and start healing it with its wrench.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 17:11
by CarRepairer
I tried working on this a few months ago but gave it up and ignored it for a while, until bob said he wanted the same feature. I'd love to hear suggestions.
Obvious example: In Starcraft SCVs can only repair mechanical units, medics can only heal organics.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 17:18
by Pxtl
Yup. There are millions of cases when you want only X to be able to repair Y. Same goes for assist and resurrection really.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 18:50
by AF
Isn't there a mechanism for intercepting the commands and discarding them given a certain piece of lua code? If so it would be a simple set of tests if the unit it applies to can repair the target unit or not.
You could even hide all the repair commands and do custom lua logic to issue a repair command behind the scenes on the target unit once the custom command is received
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 18:58
by Pxtl
AF wrote:Isn't there a mechanism for intercepting the commands and discarding them given a certain piece of lua code? If so it would be a simple set of tests if the unit it applies to can repair the target unit or not.
You could even hide all the repair commands and do custom lua logic to issue a repair command behind the scenes on the target unit once the custom command is received
You'd probably still have problems with units on patrol. How much control do we have over repair patrol behavior?
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 19:01
by AF
Patrol is just a series of repeating fight commands, and a fight command should be easy to replicate, since it's basically, move from A to B, and if you see an enemy within a certain range, attack it, and repair anything you find within that radius too.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 19:22
by CarRepairer
AF wrote:Isn't there a mechanism for intercepting the commands and discarding them given a certain piece of lua code? If so it would be a simple set of tests if the unit it applies to can repair the target unit or not.
That only triggers on commands, not sub commands (repair while patrolling).
Polling won't work because even when you cancel a repair that way, the unit will try to perform it again.
You'd have to rewrite fight, rewrite patrol, rewrite guard, maybe some others I can't think of, all to be able to control which units repair which. That's far too messy.
Even the friendly heal weapon concept is less messy.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 21:37
by AF
Those commands aren't nearly as complex as you make them out to be as they are not really commands, they're umbrellas for behaviour with sub commands.
The hardest part of your task, is the part where your telling yourself its hard.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 22:15
by bobthedinosaur
So you are saying it is possible to intercept and kill all those "umbrella" orders?
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 22:25
by Argh
This is pretty easy. Cancel the command, if the target is invalid. See examples in P.U.R.E.
That only triggers on commands, not sub commands (repair while patrolling).
I'd have to test that, but I'd be very surprised if that didn't register a command. If not, then there are other ways to check for the Repairing / Assisting state.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 22:34
by CarRepairer
Tell unit A to area repair in a circle which contains B and C.
1) Area repair command is issued.
2) It tries to repair B because it's closest.
3) Cancel the command.
4) Goto 1.
It will never get to unit C.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 22:35
by Argh
Oh. I know for a fact that area-commands issue individual commands.
I guess if it's set on Repeat, then you'd have to write a timer loop and re-cancel every quarter-second or so.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 22:44
by CarRepairer
I apologize for the above is an untested (I'll try it later) assumption and I may be wrong about area-repair. But I've experienced such behavior with other commands that issue sub commands.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 22:49
by Argh
I'd test it, with Patrol. I bet you see Commands get issued, just like area commands. Not sure on that one, but I'd be surprised.
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 23:00
by Tobi
CarRepairer wrote:Tell unit A to area repair in a circle which contains B and C.
1) Area repair command is issued.
2) It tries to repair B because it's closest.
3) Cancel the command.
4) Goto 1.
It will never get to unit C.
I think you may even have a hard time performing step 3.
Although area anything issues invididual commands, indeed for all/many(?) of them it doesn't go through LuaRules' AllowCommand.
And even if this is fixed, when AllowCommand is [or should be] called it's too late already to decide some units can not be repaired. (You need e.g. `CanRepair', that's called during the search for the next unit to repair. Or maybe a `FindNextRepairTarget' call-in.)
Argh wrote:Oh. I know for a fact that area-commands issue individual commands.
I guess if it's set on Repeat, then you'd have to write a timer loop and re-cancel every quarter-second or so.
Although area anything issues invididual commands, for all/many(?) of them it doesn't go through LuaRules' AllowCommand.
Repeat or not, area commands will be broken in the situation CarRepairer describes, even when a call to AllowCommand is added. (This is because C will never be repaired, as the unit AI will be stuck in a loop: find next repair target -> returns B -> issue command to repair B -> command cancelled -> find next repair target -> returns B -> command cancelled -> find next repair target -> returns B -> etc. etc.)
To do this properly you need to reimplement ALL the `highlevel' commands that can possibly issue the individual command you want to block in Lua, or (preferably) fix the engine.
Sidenote: what about onlyRepairCategory or so?
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 23:19
by CarRepairer
Tobi wrote:Sidenote: what about onlyRepairCategory or so?
Sounds perfect. Thanks!
Re: Discriminatory Repair WIP, ideas?
Posted: 24 Jun 2010, 23:30
by Argh
Although area anything issues invididual commands, for all/many(?) of them it doesn't go through LuaRules' AllowCommand.
Hrmm.
You sure that something like this won't work, substituting CMD_CAPTURE with CMD_REPAIR and dropping the command if conditions aren't met? It works great with Capture, effectively forbidding the command if not CanBeHacked...
Code: Select all
function gadget:GetInfo()
return {
name = "AutoHack",
desc = "Makes Engineering Teams automatically Hack capturable items.",
author = "Argh, with assistance from Lurker",
date = "June 11th, 2008",
license = "Public Domain, or the least-restrictive copyrights that exist in your country of residence.",
layer = 1,
enabled = true,
}
end
local myID, Group
local GetUnitDefID = Spring.GetUnitDefID
local CMD_CAPTURE = CMD.CAPTURE
local GetSelectedUnits = Spring.GetSelectedUnits
local CanHack = {}
local CanBeHacked = {}
function gadget:Initialize()
for ud,_ in pairs(UnitDefs) do
if UnitDefs[ud].customParams.can_hack == 'yes' then
table.insert(CanHack,ud,1)
end
if UnitDefs[ud].customParams.can_be_hacked == 'yes' then
table.insert(CanBeHacked,ud,1)
end
end
end
function gadget:DefaultCommand(type, id)
if (type == "unit") then
Group = GetSelectedUnits()
for _,u in ipairs(Group) do
if CanHack[GetUnitDefID(u)] and CanBeHacked[GetUnitDefID(id)] then return CMD_CAPTURE end
end
end
end