callin for unit actual destroyed?

callin for unit actual destroyed?

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

callin for unit actual destroyed?

Post by smoth »

In my digging I found this guy:

Code: Select all

void CUnit::KillUnit(bool selfDestruct, bool reclaimed, CUnit* attacker, bool showDeathSequence)
{
	if (isDead) { return; }
	if (crashing && !beingBuilt) { return; }

	isDead = true;
	deathSpeed = speed;

	eventHandler.UnitDestroyed(this, attacker);
so at this point unit destroyed callin is triggered right? (please correct my terminology if it is wrong as i don't think triggered is correct term)

Code: Select all

	eoh->UnitDestroyed(*this, attacker);
	// Will be called in the destructor again, but this can not hurt
	this->SetGroup(NULL);

	blockHeightChanges = false;

	if (unitDef->windGenerator > 0.0f) {
		wind.DelUnit(this);
	}

	if (showDeathSequence && (!reclaimed && !beingBuilt)) {
		const WeaponDef* wd = (selfDestruct)? unitDef->selfdExpWeaponDef: unitDef->deathExpWeaponDef;

		if (wd != NULL) {
			CGameHelper::ExplosionParams params = {
				pos,
				ZeroVector,
				wd->damages,
				wd,
				this,                              // owner
				NULL,                              // hitUnit
				NULL,                              // hitFeature
				wd->craterAreaOfEffect,
				wd->damageAreaOfEffect,
				wd->edgeEffectiveness,
				wd->explosionSpeed,
				wd->damages[0] > 500? 1.0f: 2.0f,  // gfxMod
				false,                             // impactOnly
				false,                             // ignoreOwner
				true,                              // damageGround
			};

			helper->Explosion(params);
		}

		if (selfDestruct) {
			recentDamage += maxHealth * 2;
		}

		// start running the unit's kill-script
		script->Killed();
yet killed has not completed yet. it didn't even generate a corpse yet.

Code: Select all

	} else {
		deathScriptFinished = true;
	}
The below looks kludgy. Maybe I am the only one who thinks so but shouldn't games control this final state? I guess we could reset the paralyze damage to get control back?

Code: Select all

	if (!deathScriptFinished) {
		// put the unit in a pseudo-zombie state until Killed finishes
		speed = ZeroVector;
		SetStunned(true);
		paralyzeDamage = 100.0f * maxHealth;
		health = std::max(health, 0.0f);
	}
}
So the only way I know to see if the unit is killed is to check it's paralyzed state. There is of course that one may write a check each gameframe afterwards to see if the unit still exists. Which should be able to be triggered after the unit dies.

is there a callin to know when a unitId has actually been freed and has returned to the ID pool? Aka the unit is actually dead and no longer in game.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: callin for unit actual destroyed?

Post by Silentwings »

I came up against similar problems when writing the handling for units dying in transports in BA.

There is a list of lots of things we tried that didn't work at the top of the gadget, but in the end I resorted to checking the gameframe after to see if it was dead or not.

Afaik there is no limit on how quickly a unitID can be reused so I doubt there is a callin for checking if its gone or not.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: callin for unit actual destroyed?

Post by Kloot »

smoth wrote:is there a callin to know when a unitId has actually been freed and has returned to the ID pool?
Nope.

After UnitDestroyed, all scripts should consider a unit dead and buried (and its ID invalid) no matter how long its death animation sequence is.
smoth wrote:So the only way I know to see if the unit is killed is to check it's paralyzed state.
So long as a thread spawned from Killed doesn't call UnitScript.SetDeathScriptFinished, you know if a unit is still busy dying.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: callin for unit actual destroyed?

Post by smoth »

Kloot wrote:
smoth wrote:is there a callin to know when a unitId has actually been freed and has returned to the ID pool?
Nope.

After UnitDestroyed, all scripts should consider a unit dead and buried (and its ID invalid) no matter how long its death animation sequence is.
This is fun! This creates 2 problems: 1: a unit is "dead" before it is dead. 2:freeing shaders becomes problematic.
Kloot wrote:
smoth wrote:So the only way I know to see if the unit is killed is to check it's paralyzed state.
So long as a thread spawned from Killed doesn't call UnitScript.SetDeathScriptFinished, you know if a unit is still busy dying.
how would a gadget synced/unsynced know though? is there a way to query this on a per unit basis from a gadget? I have no idea how to send data from a unit script.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: callin for unit actual destroyed?

Post by knorke »

smoth wrote:I have no idea how to send data from a unit script.
unitscript: GG.blabla()
gadget: function GG.blabla()
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: callin for unit actual destroyed?

Post by smoth »

does unit script have GG for unsynced as well?
Post Reply

Return to “Game Development”