Page 1 of 1

UnitReclaimed

Posted: 19 Dec 2008, 10:33
by Argh
Lua Callin, would get a Unit's reclaimed status, if destroyed.

Looks like there needs to be an event put into Unit.cpp, and a new Lua callin added.

Currently, if reclaimed, the Unit just disappears, instantly.

I'd like to add special effects to things, based on whether they've been reclaimed, but it's currently impossible to differentiate whether a Unit has been reclaimed or merely destroyed. Pretty silly thing, really, since you can get the reclaimLeft for Features, but there just doesn't seem to be any way to do this for Units at all. I tried a few things, but there just doesn't seem to be any way to dig that out of Spring atm :P

Re: UnitReclaimed

Posted: 19 Dec 2008, 11:29
by hoijui
hmm..
would reclaim-left not always be equal to current-health?
but i understand what you mean with the UnitReclaimed event.
how does it work at the moment, if a unit is reclaimed, do you get a UnitDestroyed event? if so.. maybe you can find out if hte attacking unit has a nano weapon, or maybe you even get the attacking weapon directly?

Re: UnitReclaimed

Posted: 19 Dec 2008, 13:21
by Tobi
I'd doubt attacker is even set when a unit is being reclaimed.

Indeed unit health is basically reclaimLeft I think. Raising separate events seems to make sense tho.

Maybe you could already differentiate by looking at unit health at time it's destroyed? Possibly it's always exactly 0 or maybe -1 when it's been reclaimed.. but that's just a random guess.

Re: UnitReclaimed

Posted: 19 Dec 2008, 16:21
by imbaczek
from what I remember trying to fix the area reclaim bug, detecting that a reclaim was finished wasn't that easy... my memories are muddy in that, though. maybe it's not that hard, either.

Re: UnitReclaimed

Posted: 19 Dec 2008, 20:30
by hoijui
you mean, it is even hard to detect engine internally?

Re: UnitReclaimed

Posted: 19 Dec 2008, 20:48
by jK
why should it be complicated?

there is a AllowUnitBuildStep lua (synced) callin (and yeah it gets also called for negative buildsteps).

-> no need for engine changes ...

Re: UnitReclaimed

Posted: 19 Dec 2008, 22:12
by Argh
Maybe you could already differentiate by looking at unit health at time it's destroyed? Possibly it's always exactly 0 or maybe -1 when it's been reclaimed.. but that's just a random guess.
Didn't work, the negative value is not consistent.

And the buildProgress returned in UnitDestroyed is 1.0.
there is a AllowUnitBuildStep lua (synced) callin (and yeah it gets also called for negative buildsteps).
That's an idea, but I don't see any way to avoid some nasty logical problems with that.

For example... let's say some building gets destroyed in the middle of being reclaimed. We want a destroyed state. If we're watching for UnitDestroyed, and cross-referencing with negative BuildStep events... there is a fairly good possibility that you will not have a good result.

I'll go take a look at that angle, but I'm not terribly confident it will work, tbh.

Re: UnitReclaimed

Posted: 19 Dec 2008, 22:57
by jK
Argh wrote:For example... let's say some building gets destroyed in the middle of being reclaimed. We want a destroyed state. If we're watching for UnitDestroyed, and cross-referencing with negative BuildStep events... there is a fairly good possibility that you will not have a good result.
? .. ?? .. ???

the event gets called before the nano particle gets spawns (you can prevent that with the return value of the event), so with each calling there is a fixed amount of hp that gets reclaimed, so where is the "nasty logical problem"?

Re: UnitReclaimed

Posted: 19 Dec 2008, 23:01
by Argh
the event gets called before the nano particle gets spawns (you can prevent that with the return value of the event), so with each calling there is a fixed amount of hp that gets reclaimed, so where is the "nasty logical problem"?
So, you're saying watch for a specific number of negative HP on a given death? That doesn't work, the negative value returned = health - damage, so it can be anything. And yes, Reclaim is treated as damage...

Re: UnitReclaimed

Posted: 20 Dec 2008, 02:31
by Argh
there is a AllowUnitBuildStep lua (synced) callin (and yeah it gets also called for negative buildsteps).
It doesn't work. Here's some test code, you can see for yourselves.

Code: Select all

function gadget:GetInfo()
	return {
		name = "Reclaim Test",
		desc = "Attempts to determine if Reclaim is occuring.",
		author = "Argh",
		date = "October 2, 2008",
		license = "Public Domain, or the least-restrictive rights of your country of residence",
		layer = 1,
		enabled = true,
	}
end

local health, maxhealth, capture, paralyze, build

if (gadgetHandler:IsSyncedCode()) then
AllowUnitBuildStep(builderID, builderTeam, unitID, unitDefID, part)
	
	if part < 100 then
		Spring.Echo("reclaiming",part)
	end
end
end

Re: UnitReclaimed

Posted: 20 Dec 2008, 02:37
by jK
erm what ?

check your `lua` code again ...

Re: UnitReclaimed

Posted: 20 Dec 2008, 02:42
by Argh
Oops :oops:

Re: UnitReclaimed

Posted: 20 Dec 2008, 02:43
by Peet
How could you have gotten this far with lua if you are still making that sort of error? Is all of your working code modified copypasta of other peoples' code or what?

Re: UnitReclaimed

Posted: 20 Dec 2008, 02:51
by Argh
No, I'm just human, and I'm a little busy.

Here's a working test:

Code: Select all

function gadget:GetInfo()
	return {
		name = "Reclaim Test",
		desc = "Generates result if Unit is reclaimed.",
		author = "Argh",
		date = "December 18th, 2008",
		license = "Public Domain, or the least-restrictive rights of your country of residence",
		layer = 1,
		enabled = true,
	}
end

local GetUnitHealth = Spring.GetUnitHealth

if (gadgetHandler:IsSyncedCode()) then

function gadget:AllowUnitBuildStep(builderID, builderTeam, unitID, unitDefID, part)
	if part < 0 then
		health = GetUnitHealth(unitID)
		if health < 10 then
		Spring.Echo("Reclaimed",part)
		end
	end
	return true
end

end

Re: UnitReclaimed

Posted: 20 Dec 2008, 02:56
by jK
Argh wrote:Here's a working test:
so it works :p

Re: UnitReclaimed

Posted: 20 Dec 2008, 03:00
by Argh
Yes. And you're entirely right, that was very simple.