Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Akalabeth Angel on May 11, 2008, 02:00:17 pm

Title: How hard would it be to . . variable weapon damage
Post by: Akalabeth Angel on May 11, 2008, 02:00:17 pm
I'm wondering, some universes have lasers and the like whose damage decreases with range. How hard or not hard would it be to implement something like that?

I was thinking like a . . . percentage modifier or something, say in milliseconds or seconds where each second the damage is modified by that amount.

So if something had like
Lifetime: 2.0
Velocity: 500
Damage: 100
*Damage Mult(per second): 0.45

     After one second of lifetime, and at 500 metres it would only do 55 damage. At the extreme range of around 1000 metres it would only do 10 damage. Or would it be . .. 25ish damage, hmmn. Anyway, not sure how much use their would be in Freespace but it might make some interesting weapons. One could even either give a negative mofier (-0.45) or depending how it worked, maybe like (1.45) and the weapon damage would actually increase so it dealt more damage at range and very little in close.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Mobius on May 11, 2008, 02:02:53 pm
Hey, I like this idea...I'd really like to see the effects of such feature on the Maxim...
Title: Re: How hard would it be to . . variable weapon damage
Post by: haloboy100 on May 11, 2008, 03:11:39 pm
The WC team outta have something like this with their Particle cannon
Title: Re: How hard would it be to . . variable weapon damage
Post by: colecampbell666 on May 11, 2008, 03:28:22 pm
And also, have each shot do slightly different damage.

First problem would be easy.

if distance = x-y
       decrease damage z%

Second, just add a variable of 2-5% or something.
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 11, 2008, 03:47:25 pm
Excellent! Have a diff for me by the end of the week and I'll see about getting it commited.

The SCP team leave this idea entirely in colecampbell's hands. Shout at him and not us if it isn't implemented.
Title: Re: How hard would it be to . . variable weapon damage
Post by: colecampbell666 on May 11, 2008, 03:54:31 pm
I can't code, I'm just throwing ideas out. Christ...
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 11, 2008, 04:07:33 pm
Then don't patronise those of us who can code by telling us it's easy when you don't really have any idea. There is very little that annoys some of the coders on the team than that.
Title: Re: How hard would it be to . . variable weapon damage
Post by: colecampbell666 on May 11, 2008, 05:54:05 pm
Sorry.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Solatar on May 11, 2008, 07:12:39 pm
First, let it be known...I do not claim this is easy...

Any of the coders want to chime in about how this might/could be done? Could a hackish solution be put in place where when damage is calculated it multiplies $damage by $armor, $shield, or $subsystem and then optionally multiplies it by a random number generated between two extremes? or something...(this would be for the random damage multiplier)
Title: Re: How hard would it be to . . variable weapon damage
Post by: WMCoolmon on May 11, 2008, 11:06:35 pm
Code: [Select]
[quote author=Solatar link=topic=53785.msg1087780#msg1087780 date=1210551159]Any of the coders want to chime in about how this might/could be done?[/quote]

Absolutely. Yes, it would be pretty easy. Karajorma should not be harassing cole or presuming to speak for the entire team.

In weapon.h:
[code]float damage_per_second;

In weapon.cpp:
Code: [Select]
if(optional_string("$Damage Per Second:")) {
stuff_float(&wip->damage_per_second);
}


Wherever damage is applied, you change
Code: [Select]
wip->damage
to
Code: [Select]
wip->damage+((float)(timestamp()-wp->creation_time)/1000.0f)*wip->damage_per_second;
There's more future-oriented ways of doing it, but that's the minimum. Oh, and you need to init the dps var to 0 when you init the weapon_info struct:

Code: [Select]
wip->damage_per_second = 0.0f;[/code]
Title: Re: How hard would it be to . . variable weapon damage
Post by: Backslash on May 12, 2008, 12:43:00 am
I did some work on this a few months ago, actually mostly to do with beams, but the concept could probably be migrated without too much trouble.

With beams this was once upon a time implemented as +Attenuation.  Time was irrelevant since beams get there instantly, so distance was the factor.  Apparently Attenuation no longer works in the code, but I'm working on fixing and expanding it.  So!  This is how it would work.  Let's call the Attenuation value in the table N for short.
If N is 0, the beam behaves as it does now... no change in damage at all.
If N is 1, the beam starts out at full damage, and ramps down until at maximum range it is zero damage.
If N is between 0 and 1, the beam starts out at full damage, and then at N*range it begins ramping down until at maximum range it is zero damage.

With me so far?  Now let's add a crazy additional twist!
If N is -1, the beam starts out at ZERO damage, and ramps up until at maximum range it is at maximum damage.
If N is between -1 and 0, the beam starts out at zero damage, and ramps up until at N*range it hits maximum damage, and remains maximum damage until maximum range.

Does that make sense?  Would you like me to post the graphs I made?

I've got this nearly finished for beams, just need more testing to make sure I did the maths right.  After that it is only a matter of applying the changes to non-beam weapons (and adding the setting since before only beams had +Attenuation)... give me a week or two.
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 12, 2008, 01:42:19 am
Absolutely. Yes, it would be pretty easy. Karajorma should not be harassing cole or presuming to speak for the entire team.

Ah but it solves two problems if I do.

1. It stops people posting annoying "It's easy" comments
2. People crawl out of the woodwork to prove it's easy and code features that otherwise they would have ignored in order to prove me wrong. This is exactly why I did the same thing the last time someone said a feature was easy. :p
Title: Re: How hard would it be to . . variable weapon damage
Post by: WMCoolmon on May 12, 2008, 06:32:09 am
1. It stops people posting annoying "It's easy" comments

It also cuts down on the flow of ideas, and alienates people who try to be helpful.

2. People crawl out of the woodwork to prove it's easy and code features that otherwise they would have ignored in order to prove me wrong. This is exactly why I did the same thing the last time someone said a feature was easy. :p

I've got a broken hand right now. You'll pardon me if I'm not thrilled to hear that I just wasted my time because you wanted to be a lazy jackass.
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 12, 2008, 07:02:58 am
1. It stops people posting annoying "It's easy" comments

It also cuts down on the flow of ideas, and alienates people who try to be helpful.

Posting "It's easy" contributes nothing. It's just post count +1. Unless someone has looked at the code they are in no position to comment on how easy a feature is to add because often easy sounding ideas turn out to be incredibly difficult to actually add.

And cole has been here long enough that he should be aware of that fact.

Quote
I've got a broken hand right now. You'll pardon me if I'm not thrilled to hear that I just wasted my time because you wanted to be a lazy jackass.

Nowt to do with me. I had no idea that Backslash was already working on something similar. If you decided to implement the code without checking if another coder was already doing something similar that's not my fault. If you decided to implement the code with your broken hand just to rub my nose in how easy it actually is then it sucks to be you but again is your fault.

Simple fact is that certain people here on HLP won't respond to a help request even when asked repeatedly (Wanderer for instance has been asking about that paging in question for days) but would crawl over broken glass with their flies unzipped to prove someone wrong. If you were foolish enough to be the latter then maybe you should ask yourself why it mattered to you so much.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Backslash on May 12, 2008, 11:29:48 am
Technically in cole's case he was only saying the math was easy.  Really though, I'd like to encourage the thinking things through ... there's a big difference between a noob going "lol curved beamz is easy why isn't it done yet" (and yes, I hate that), vs somebody posting "the concept seems easy, here's the maths I came up with".

Even us coders (well, at least me ;)) can think something is easy before really looking into it.

...as for the help requests, no idea where everyone else is this week, seems quieter than usual.  RL does come up from time to time I guess.  I knew nothing about the question so didn't answer...
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 12, 2008, 11:49:28 am
Technically in cole's case he was only saying the math was easy.  Really though, I'd like to encourage the thinking things through ... there's a big difference between a noob going "lol curved beamz is easy why isn't it done yet" (and yes, I hate that), vs somebody posting "the concept seems easy, here's the maths I came up with".

The maths in this case though was towards the easier end of the scale. I'd be worried if the coder who handled the request couldn't come up with the maths to do it. Had it involved trig or tensors or something that would be much more valid.


That said there are other considerations that haven't been mentioned. For instance suppose you have something like the maxim fired by AI fighters at something the player is close to. The weapons hit, set off a big impact effect and then do no visible damage because the damage has attenuated away to next to nothing. That's going to look mighty odd.
Title: Re: How hard would it be to . . variable weapon damage
Post by: colecampbell666 on May 12, 2008, 01:14:17 pm
And cole has been here long enough that he should be aware of that fact.
Actually, I've never seen that before. I've seen one person post "it's easy" and they were left alone.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Wanderer on May 12, 2008, 01:24:57 pm
Varied damage might be something worth considering... Sorta like adjusting damage to 'simulate' a chance hit to a vulnerable spot... Sorta like ye good olde RPGs do it (with criticals) :P

I could even write it but as it seems like my diffs have snowballs chance in hell to get into SVN anytime soon i doubt i bother to do it
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 12, 2008, 05:09:45 pm
Having the environment cause damage attenuation itself is also worth considering. For instance in atmospheric missions a ballistic weapon could be expected to suffer from attenuation while in space the same weapon wouldn't be affected.
Title: Re: How hard would it be to . . variable weapon damage
Post by: blowfish on May 12, 2008, 07:03:48 pm
And cole has been here long enough that he should be aware of that fact.
Actually, I've never seen that before. I've seen one person post "it's easy" and they were left alone.

Who was that person?

I know that I don't speak for the team, but personally I think it is ok for someone to say that something is relatively easy if they know how to code and have actually looked at the source to determine whether adding that feature is, in fact, easy.  Though at that point they might as well code it themself.
Title: Re: How hard would it be to . . variable weapon damage
Post by: colecampbell666 on May 12, 2008, 07:34:04 pm
Could there be a code like:
Code: [Select]
If
>Shivan
>>Secondary
>>>Cyclops
Replace
>Shivan
>>Secondary
>>>ShivCyclops
That automatically takes care of this without having to edit things yourself?
I know nothing about coding though, so this is more like a SEXP than a code.

That isn't the exact place, but it's similar. IIRC it was Titan who said what I'm thinkinf of.

And I didn't say it was OK, I said that it was ignored.
Title: Re: How hard would it be to . . variable weapon damage
Post by: blowfish on May 12, 2008, 07:49:07 pm
If its ignored, then generally no one has a problem with it.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Nuke on May 12, 2008, 08:58:22 pm
you could probibly script this in 4 lines.

id probibly be more intrested in variable fire rate, have a minlife, maxlife acceleration time and deceleration time. that way i can make gatling guns that fire like gatling guns.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Akalabeth Angel on May 12, 2008, 09:09:17 pm
you could probibly script this in 4 lines.

id probibly be more intrested in variable fire rate, have a minlife, maxlife acceleration time and deceleration time. that way i can make gatling guns that fire like gatling guns.

     Gatling guns have an inconstant rate of fire???
Title: Re: How hard would it be to . . variable weapon damage
Post by: Nuke on May 12, 2008, 10:05:35 pm
yea its the current rpm / # of barrels, the laws of physics dictate the rest. also most guns (mainly ones in aircraft) have a speed select switch, so you can go fast or slow depending on the length of the mission, or your current ammo situation. i think the minigun that they use in choppers and on humvees, ect. have a variable speed trigger, much like the one on a power drill.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Akalabeth Angel on May 12, 2008, 10:08:47 pm
yea its the current rpm / # of barrels

    Yeah, but in the case of like a minigun, like on Predator, isn't it basically zero to full-bore almost instantly? There's not typically a warm-up phase of any appreciable time as far as I know. 
Title: Re: How hard would it be to . . variable weapon damage
Post by: Nuke on May 12, 2008, 10:16:05 pm
the bigger the gun, the bigger the spinup/spindown. also on how powerfull the drive system is. miniguns in games that spin up before feeding ammo are bs. such a system in real life would jam. you get alot more reliability mechanically linking the feed system to the barrels. works like a bicycle chain, think of every link as carrying a bullet, and when the chain passes betweeen the teeth on the sproket, that bullet may then be locked loaded and ejected and the casing exit on the very same link. thats pretty much how gatling guns work.

russian gatling guns are a little wierd. they use the gas from the bullet going off as sort of a truster to keep the barrels spinning. its initiated with a pyro charge (limiting the number of times they can fire it). breaks engage when the trigger is released. but the guns get insane rates of fire and almost no spinup delay, in excess of 10k rpm. :D i think the rounds are linked and spin directly off a feed drum with no complex conveyor systems, which is why it gets such awesome rates of fire, less stuff to work.

as for the gun in predator, its not possible to use it in that way. its designed to be operated as a manual turret on vehicles or as an implacement (tripod burried in sandbags so as to take the recoil). it was a real minigun but the only way they managed to fire it from the waist is by shooting blanks, and limiting its rpm. nukemod has gatling guns ranging from minigun size to a 105mm gatling-howitzer :D
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 13, 2008, 01:37:42 am
That isn't the exact place, but it's similar. IIRC it was Titan who said what I'm thinkinf of.

And I didn't say it was OK, I said that it was ignored.

First off, Retsof's post is actually a feature request rather than an attempt to tell the coder how to do it. Secondly he never said that it was easy and in fact said he didn't know the code and asked if it was possible. If you notice I don't think any coder actually posted after he did anyway.
Title: Re: How hard would it be to . . variable weapon damage
Post by: WMCoolmon on May 14, 2008, 02:06:49 am
Nowt to do with me. I had no idea that Backslash was already working on something similar. If you decided to implement the code without checking if another coder was already doing something similar that's not my fault. If you decided to implement the code with your broken hand just to rub my nose in how easy it actually is then it sucks to be you but again is your fault.

Simple fact is that certain people here on HLP won't respond to a help request even when asked repeatedly (Wanderer for instance has been asking about that paging in question for days) but would crawl over broken glass with their flies unzipped to prove someone wrong. If you were foolish enough to be the latter then maybe you should ask yourself why it mattered to you so much.

I've suggested meetings and more communication b/t coders and have been ignored/opposed.

I don't know about paging - taylor does. I replied because he didn't. I'm sorry to see that SCP members are supposed to mock those who can't defend themselves, attack those who stand up for them, and use assistance as ammunition.
Title: Re: How hard would it be to . . variable weapon damage
Post by: karajorma on May 14, 2008, 05:41:09 am
I've suggested meetings and more communication b/t coders and have been ignored/opposed.

Have I ever opposed it? You're completely in the wrong if you're trying to claim I'm responsible for that.

Quote
I'm sorry to see that SCP members are supposed to mock those who can't defend themselves, attack those who stand up for them, and use assistance as ammunition.

Who was that masked man! It's Burro, defender of the oppressed masses of HLP!
Title: Re: How hard would it be to . . variable weapon damage
Post by: colecampbell666 on May 14, 2008, 01:16:27 pm
Like I said, that wasn't the exact place I saw it.
Title: Re: How hard would it be to . . variable weapon damage
Post by: MP-Ryan on May 14, 2008, 01:53:27 pm
Could a system like this be applied to beam weapons instead of a locked range?  Also feeding in a variable to decrease accuracy the further out the ships are?

It's always seemed mighty strange that beam weapons preserve their power no matter the distance, but also that they have a physical limitation on range at which they will fire.

It would be a useful feature to toggle on and off for mods that don't want to set ridiculously high range values in tables nor have beam weapons that are accurate and powerful when engaging at long range.
Title: Re: How hard would it be to . . variable weapon damage
Post by: Wanderer on May 14, 2008, 02:05:53 pm
Err?

http://www.hard-light.net/wiki/index.php/Weapons.tbl#.24BeamInfo:

Especially range and attenuation fields.... As for range limitation... what (apart from the default range being set to 30 000) ?