UnitReclaimed

UnitReclaimed

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

UnitReclaimed

Post 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
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: UnitReclaimed

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

Re: UnitReclaimed

Post 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.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: UnitReclaimed

Post 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.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: UnitReclaimed

Post by hoijui »

you mean, it is even hard to detect engine internally?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: UnitReclaimed

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

Re: UnitReclaimed

Post 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.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: UnitReclaimed

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

Re: UnitReclaimed

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

Re: UnitReclaimed

Post 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
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: UnitReclaimed

Post by jK »

erm what ?

check your `lua` code again ...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: UnitReclaimed

Post by Argh »

Oops :oops:
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Re: UnitReclaimed

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

Re: UnitReclaimed

Post 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
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: UnitReclaimed

Post by jK »

Argh wrote:Here's a working test:
so it works :p
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: UnitReclaimed

Post by Argh »

Yes. And you're entirely right, that was very simple.
Post Reply

Return to “Feature Requests”