[patch] dynamic damage based on range

[patch] dynamic damage based on range

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

[patch] dynamic damage based on range

Post by rattle »

I thought this was a useful feature so I've made my first patch with some help from FLOZi.

It adds four new TDF tags, dynDamageExp, dynDamageMin, dynDamageInverted and dynDamageRange.

dynDamageExp=0 / >0
Exponent of the damage formula, 0 disables dynamic damage.
Defaults to 0. 1 means linear scaling.

edit:
dynDamageMin = 0 / >0
Minimum damage value. Disabled when set to 0.
ex: firstDamageValue = 500, dynDamageMin = 100, modifier will be 1/5

dynDamageInverted = 0 / 1
Inverts the curve (or line).

edit:
dynDamageRange = 0 / >0
If set it will use this value instead of the range value from the weapon in the calculation.

Formulas:
Damage = (1 - (1 / WeaponRange * TraveledDistance)^Exp * OrigDamage
Damage = OrigDamage - (1 - (1 / WeaponRange * TraveledDistance)^Exp * OrigDamage (inverted)

Graph:
Image
(clicky for a bigger picture)
x = distance, y = damage.
Red's the inverted one. This is with an exponent of 2.


Patch:
http://rattle.from-hell.net/spring/patc ... atch.patch

If there are any issues such as ugly code tell me. There are some problems left in when using an inverted curve. When a weapon is fired from maximum range it should do ~100% damage. Instead it was doing only ~77%. No idea why...
Last edited by rattle on 29 Mar 2007, 12:12, edited 2 times in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

I still think it would be better to make local copies of the damage array in the weapon itself rather than altering defs which should remain static... even if it means extra work. :wink:
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

It's not a big deal to change that, however as I pointed out the damages array direclty affects everything which is related to damage (size of scars, size of muzzle flares, etc.). I am working with the original values, this is why I added a backup array.

Does anyone else think that this is bad idea?

edit: Hmm it seems that this doesn't work with beam lasers. :(
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Post by Peet »

Nothing works with beam lasers >_>
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Yeah, we're already used to that.
User avatar
Lindir The Green
Posts: 815
Joined: 04 May 2005, 15:09

Post by Lindir The Green »

there should also be one like 10 - (10x)^(1/2) for if you want it to drop off quickly and then slowly.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

I'm being stupid again, I've tested this on XTA's annihilator weapon, that's what I thought at least. I edited the wrong weapon in the end because of XTA's stupid naming system. :P

So nothing's wrong (I hope).
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Still this doesn't get applied to beamlasers. Could someone tell me what method is called for beam lasers to do damage?
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Post by imbaczek »

Bonus points for making the tag accept arbitrary expressions in RPN, additional secret bonus for making it accept infix expressions, kudos for JITting them :)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Suggestion:

Add another tag, dynDamageRange, which is used in the calculation. Default is weapon range. This improves the flexibility of the curves we can produce quite considerably.


Also, just checking, is the damage value automatically clamped after exceeding max range of the weapon? (to prevent -ve damages)
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

TraveledRange is limited to weaponDef->range, the damage would go into the negatives I think. I'll add the additional range tag.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

I was going to suggest you always clamp it to dynDamageMin, meaning you can't deal -ve damage.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

It is if dynDamageMin is defined.

Code: Select all

if (weaponDef->dynDamageMin > 0)
	dynDamages[i] = max(weaponDef->damages[i] * weaponDef->dynDamageMin, dynDamages[i]);
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

I know, but i mean always do it - dynDamageMin defaults to 0, so if its not set otherwise the damage is clamped to 0, preventing issues with dealing -ve damage. :wink:
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Hmm... what's -ve damage? :?
It's limited to "0" damage by default.

Code: Select all

dynDamages[i] = max(0.0001f, dynDamages[i]);
If it ever goes into the negatives it will be 0.0001 anyway.
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Post by Guessmyname »

rattle wrote:Hmm... what's -ve damage? :?
shortform for negative I belive
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

-ve = negative

And ok, was just checking. :-)
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

That's good, I tend to forget things...
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Damn, I totally missed this before - dynDamageMin might (would be for me, anyway) be better off as an integer value rather than a %... Simpler to calculate a % of the original damage as an integer than to calculate an integer as a % of the original, well, not exactly, but its juist nicer, to me, anyway. </rambling>

That's why i was suggesting what i was suggesting before, hadn't read it closely enough. :oops:

edit: also, could you upload the latest .patch for me to look over? :-)
User avatar
MadRat
Posts: 532
Joined: 24 Oct 2006, 13:45

Post by MadRat »

This is a product of range and not flight-time, so high arc weapons won't be probably the best to use with this tag. Or am I missing something?

The first thought I had when reading about these new tags was for perhaps tank-vs-tank and battleship-vs-battleship duels. I like the inverse curve especially in that case.
Post Reply

Return to “Engine”