Discriminatory Repair WIP, ideas?

Discriminatory Repair WIP, ideas?

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Discriminatory Repair WIP, ideas?

Post 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?
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Discriminatory Repair WIP, ideas?

Post by aegis »

what style is the mod?
==Troy==
Posts: 376
Joined: 29 Oct 2008, 15:55

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Discriminatory Repair WIP, ideas?

Post 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
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Discriminatory Repair WIP, ideas?

Post 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?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Discriminatory Repair WIP, ideas?

Post by bobthedinosaur »

So you are saying it is possible to intercept and kill all those "umbrella" orders?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Discriminatory Repair WIP, ideas?

Post 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.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Discriminatory Repair WIP, ideas?

Post 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.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Discriminatory Repair WIP, ideas?

Post 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?
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Discriminatory Repair WIP, ideas?

Post by CarRepairer »

Tobi wrote:Sidenote: what about onlyRepairCategory or so?
Sounds perfect. Thanks!
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Discriminatory Repair WIP, ideas?

Post 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
Post Reply

Return to “Lua Scripts”