Please add a weapondef tag for friendly fire

Please add a weapondef tag for friendly fire

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Please add a weapondef tag for friendly fire

Post by Forboding Angel »

Boolean so that this explosion or weapon impact does either no damage, or damage to friendly units

Another Boolean that specifies whether this explosion does damage to enemy units or not.


THIS INCLUDES AOE!

Suggested tag names:

noFriendlyFire
noEnemyFire

Atm most of us are trying to achieve this via gadgets and the like but said gadgets are unreliable. Besides, there should be a switch in the engine for it.

Edit: This also goes for unit death explosions as well as weapons assigned to units.
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2700
Joined: 25 Aug 2004, 13:31

Re: Please add a weapondef tag for friendly fire

Post by bobthedinosaur »

how are gadgets unreliable?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Please add a weapondef tag for friendly fire

Post by FLOZi »

UnitPreDamaged should handle this fine :?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Please add a weapondef tag for friendly fire

Post by Forboding Angel »

http://pastebin.com/Tw5Cy8Ya

Works for units weapons, not for unit death explosions.

http://pastebin.com/vdhbT2RH

Doesn't work at all.


Plus, these are tags that should be in the engine weapondefs anyway.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Please add a weapondef tag for friendly fire

Post by Niobium »

Death explosion
=> Attacker is dead
=> Attacker parameters are nil (attackerID, attackerDefID, attackerTeam)
=> Your gadgets function doesn't fire

WeaponID works just fine however, so your gadget would turn into something like...

noFriendlyFireWeapons = {WeaponDefNames[...].weaponDef = true, ...}

Which is a bit more hassle than just putting a tag on the weapon (Unless weapons have customparams?)
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2700
Joined: 25 Aug 2004, 13:31

Re: Please add a weapondef tag for friendly fire

Post by bobthedinosaur »

You want deaths to damage enemies and features, but not friendlies? Why have death explosions do any damage at all then? I guess it is important for damaging nearby enemies when your units die?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Please add a weapondef tag for friendly fire

Post by Forboding Angel »

Kamikaze units that don't chain.

Also, why doesn't the noenemy fire one work? That one is a massive pain in the cock.

Thanks for explaining that niobium. Makes a lot mroe sense now.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Please add a weapondef tag for friendly fire

Post by CarRepairer »

Niobium wrote:Death explosion
=> Attacker is dead
=> Attacker parameters are nil (attackerID, attackerDefID, attackerTeam)
=> Your gadgets function doesn't fire
This is bad. Spring should be fixed so attackerDefID and attackerTeam are still there even if the unit is dead.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Please add a weapondef tag for friendly fire

Post by Argh »

You can set the kamikaze weapon to be a watchweapon, and then:

Code: Select all

function gadget:Explosion(weaponID, px, py, pz, ownerID)
	if(weaponID == myNiftyWeapon) then
		teamID = Spring.GetUnitTeam(ownerID)
	return false end
end
...I think that will give you a valid UnitID on death. The alternative is to manually cause an explosion in COB via emit-sfx during the death sequence before returning.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Please add a weapondef tag for friendly fire

Post by CarRepairer »

This wouldn't solve the scenario where a regular unit fires a weapon, dies before it reaches its target and again unitpredamaged would fail to give the parameters.

CarRepairer wrote:Spring should be fixed so attackerDefID and attackerTeam are still there even if the unit is dead.
...would solve it. Would it be difficult to fix?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Please add a weapondef tag for friendly fire

Post by Argh »

This wouldn't solve the scenario where a regular unit fires a weapon, dies before it reaches its target and again unitpredamaged would fail to give the parameters.
True, but it should fix Forb's immediate problem.

As for the fix, maybe just store the team ID? I can see all sorts of problems cropping up if dead unit IDs are still considered to be valid.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Please add a weapondef tag for friendly fire

Post by Niobium »

CarRepairer wrote:This wouldn't solve the scenario where a regular unit fires a weapon, dies before it reaches its target and again unitpredamaged would fail to give the parameters.

CarRepairer wrote:Spring should be fixed so attackerDefID and attackerTeam are still there even if the unit is dead.
...would solve it. Would it be difficult to fix?
Units dying before shots hit is common enough that it makes it impossible to implement team-based or unitdef-based special damages consistently. While unitdef-based things could be handled by unique weapondefs through a troublesome process, even simple team-based damages like 'Team X has +10% damage' are impossible, especially so when the damage modifications are large.

Imo this is bug (in that it causes buggy inconsistent behavior), but looking at the spring code it doesn't appear to be a super easy fix of tacking on some parameters in one place. It seems like it would require all projectiles to get ownerTeam/ownerDef on creation , and then passing those values onto created explosions/damage, which would then pass them into the damage functions. Basic changes, but quite a few of them.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Please add a weapondef tag for friendly fire

Post by CarRepairer »

Argh wrote:
I can see all sorts of problems cropping up if dead unit IDs are still considered to be valid.
Not unitID, I just said unitDefID (attackerDefID + attackerTeamID).
Niobium wrote:Imo this is bug (in that it causes buggy inconsistent behavior), but looking at the spring code it doesn't appear to be a super easy fix of tacking on some parameters in one place. It seems like it would require all projectiles to get ownerTeam/ownerDef on creation , and then passing those values onto created explosions/damage, which would then pass them into the damage functions. Basic changes, but quite a few of them.
Thanks for the explanation. I hope this could be resolved. Even if it's just teamID that is maintained, it would suffice (teamID + weaponID).
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Please add a weapondef tag for friendly fire

Post by Pxtl »

Perhaps a better method would be to have dead units leave behind a data-tombstone that contains some simple information, and add a method GetDeadUnitInfo(unitID) that returns as subset of the live unit's info. In this case, that would happen transparently in the background and the DeadUnitINfo's DefID and TeamID would be passed into the predamaged handler?

edit: too bad we don't just get an invalid AttackerID instead of a "nil" one. Then you could simply cache all the Unit IDs on unit creation, storing their team and unitdefID there. That collection would logically outlive the units, so you could use that to check the info of dead units.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Please add a weapondef tag for friendly fire

Post by lurker »

There are tombstones, they just get cleared after each frame.

It would be nice for a projectile to give at least some of the information even after a unit's long gone.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Please add a weapondef tag for friendly fire

Post by Argh »

Hmm. So, does Explosion() return nil for the ownerID, or a number, if the firing Unit is dead?

If the second case, and you want a tombstone keeper, that's a fairly routine Gadget- we could put Units in an array, with dead/alive states, and sync that with weapons instead of querying Spring. I don't think there's a need for an engine fix on this, frankly:

Code: Select all

local unitList = {}
function gadget:UnitCreated(unitID, unitDefID, teamID, builderID)
  unitList[unitID] = {dead = false, deadTimes = 0}
end

function gadget:UnitDestroyed(unitID, unitDefID, teamID, attackerID)
  unitList[unitID].dead = true
end

function gadget:GameFrame(f)
  if f % 33 < 0.1 then
    for i,k in ipairs(unitList) do
      if k.dead = true then
        if k.deadTimes > 2 then
          unitList[i] = nil --clear this location
        else
          k.deadTimes = k.deadTimes + 1
        end
      end
    end
 end
end

function gadget:Explosion()
  --check for match with dead / living here, if yes then set something up for UnitPreDamaged()...
end

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Please add a weapondef tag for friendly fire

Post by zwzsg »

Pxtl: Don't forget unitIds get reused!
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Please add a weapondef tag for friendly fire

Post by Argh »

True. What's the rationale behind that, btw? Seems unlikely we'd ever hit the limit on that number...
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Please add a weapondef tag for friendly fire

Post by Pxtl »

@zwzsg - well, that depends on teh unitID reuse algorithm. If it keeps going upwards until wraparound and then grabs the next available one, the UnitID should last long enough for any death explosion. Plus, if you're using an "on unit create" approach I mentioned, you would at least *know* when a UnitID was reused, and could keep track of all uses of the unitID.

But either way, you still need AttackerID to be passed in UnitPreDamaged instead of Nil to take that approach.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Please add a weapondef tag for friendly fire

Post by hoijui »

unitIds for new units are chosen randomly out of the currently unused IDs. this is to make some forms of cheating harder.
Post Reply

Return to “Feature Requests”