damagetype System

damagetype System

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Evil4Zerggin
Posts: 557
Joined: 16 May 2007, 06:34

damagetype System

Post by Evil4Zerggin »

A bit of weapon postdef code that allows you to define damagetypes, which you can assign to weapons via the damagetype customparam (default is "default"). You can then specify a multiplier to damage (relative to default) that each damagetype should get against different armortypes. Damages explicitly defined in the weapondefs override the calculated values.

Examples of use:

In a weapondef:

Code: Select all

  name=Molotov Cocktail;
  [...]
  [customParams] {
    damagetype=fire;
  }
  [...]
  [damages] {
    default=9001;
    magic=9001; //overrides calculated value
  }
In gamedata/damagedefs.lua:

Code: Select all

local damagedefs = {
  default = {
    invulnerable=0,
    magic=0.5,
  },
  fire = {
    fire=0.5,
    ice=2,
    invulnerable=0,
    magic=0.5,
  },
}

return damagedefs
Another example: part of Warcraft III's damagetype system:

Code: Select all

  name=Footman Sword;
  [...]
  [customParams] {
    damagetype=normal;
  }
  [...]
  [damages] {
    default=12.5;
  }

Code: Select all

local damagedefs = {
  normal = {
    medium = 1.5,
    fortified = 0.7,
  },
  piercing = {
    light = 2,
    medium = 0.75,
    fortified = 0.35,
    hero = 0.5,
    unarmored = 1.5,
  },
[...]
(note that I am not suggesting that anybody actually try to copy Warcraft III; this is just to use a well-known example)

S44's weapondefs_post.lua:
http://spring1944.svn.sourceforge.net/v ... iew=markup
Last edited by Evil4Zerggin on 29 Jul 2009, 06:12, edited 1 time in total.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: damagetype System

Post by Argh »

You might want to read Merc Squad.

I have custom weapon types and randomized damage implemented there, in a slightly different system (but invoking these things through weapon customParams would be trivial).
User avatar
Evil4Zerggin
Posts: 557
Joined: 16 May 2007, 06:34

Re: damagetype System

Post by Evil4Zerggin »

I did it in postdefs since the in-game performance cost is probably a bit lower, plus the adjusted values are available for widgets/gadgets to access. As for dynamic damage adjustments, there's a new UnitPreDamaged callin, which makes it unnecessary to use SetUnitHealth or AddUnitDamage calls to adjust damage. As it so happens, I used it for s44's upcoming armor system.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: damagetype System

Post by Argh »

I did it in postdefs since the in-game performance cost is probably a bit lower
No, it gets read at the start of the game, just like everything else does.

And yeah, it was written before UnitPreDamaged was available, but that just makes it cleaner. But it does other stuff.

The armor-pen system looks cool- definitely an improvement on Spring's native handling of same.

You should put in random damage effects and things, though, and maybe include some rules for spalling. Real-life effects of penetration are rather random, and spalling can kill a tank crew even if the the armor's technically intact. Stuff like an 88 should kill most tanks in one hit, but freak stuff happens all the time in war, and due to Spring's weapon behaviors, it's best to simulate "near misses" and "glancing blows" through a Lua system, imo. But at the very least, include results like "lost treadplate" or "lost track / wheel". Make it so that vehicles are functionally disabled more often than totally destroyed... that's real life.

Then one cool little "bail the crew" function, setting the disabled tank / vehicle to Neutral / Gaia later, and you'd have a pretty awesome simulation of real-world armored combat, imo.

But that's just details. The only thing I can actually quibble with in terms of the basic logic is that small arms do full damage, whereas they should do zero, because with the exception of heavy machineguns, most of them can't penetrate any armor worth spending the CPU to simulate this way (imo), and heavy machineguns should indeed have an armor penetration value, so they can kill the stuff they could IRL.

Suggested logic:

Code: Select all

if not unitInfo then return damage end --not armored, don't bother simulating

if unitInfo and not weaponInfo then return 0 end --no penetration, gg
Post Reply

Return to “Lua Scripts”