unit info -- armor classes and weapon damage

unit info -- armor classes and weapon damage

Classic game design, maintained to please you...

Moderator: Content Developer

Post Reply
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

unit info -- armor classes and weapon damage

Post by cherub »

Hi,

as part of a mixture of a fun project and some 'serious' learning effort I'm writing yet another unit info. The main difference for me is that it is supposed to have more interactivity, i.e. a dedicated GUI, where one can not only browse information, but also display 'custom' selections. E.g. type an expression like 'Damage to Metal Ratio' and compare different units, etc.

I have relied heavily on existing code from pepeAmpere (mod stats 2 html, http://springfiles.com/spring/lua-scrip ... exporter-1) and I've had some looks in the past on the modinfo generation script from beherith and extended by abma and decay ( mod2html.py , http://imolarpg.dyndns.org/trac/balates ... od2html.py) plus checking the read/lua interface definitions in the spring code (e.g. https://github.com/spring/spring/blob/1 ... itDefs.cpp)

I can now read out most interesting things; I've written a widget that I load ingame, so that it's post-processed. This writes out a file, which I've formatted to be a python script that only defines dictionary items. A specific example looks like (the formatting comes from the fact that I process the lua script line per line and write the variables also line per line):

Code: Select all

armbanth = { 
"gameMod" : "Balanced Annihilation V9.27",
"unitName" : "armbanth",
"unitID" : 30,
"humanName" : "Bantha",
"Description" : "Assault Mech",
"techLevel" : 6,
"metalCost" : 13537,
"energyCost" : 285812,
"buildTime" : 276057,
"hitpoints" : 62000,
"metalUpkeep" : 0,
"energyUpkeep" : 0,
"makesMetal" : "0",
"metalMake" : 0,
"energyMake" : 12,
"metalStorage" : 0,
"energyStorage" : 120,
"isBuilder" : False,
"isFactory" : False,
"buildSpeed" : 0,
"speed" :  49.5,
"acc" :  0.10,
"turnRate" :  1056,
"los" :  308.5,
"radarRange" :  0,
"sonarRange" :  0,
"flyAlt" :  0,
"idleAutoheal" :  12.5,
"radarRange" :  0,
"weapons" : {
"ImpulsionBlaster" :  {
"weaponName" : "ImpulsionBlaster",
"weaponRange" : 465,
"weaponreload" : 0.69,
"weapondefDmg" :365,
"weaponlightDmg" : 365,
"weaponmediumDmg" : 365,
"weaponheavyDmg" : 365,
"weaponshipsDmg" : 365,
"weaponsubsDmg" : 5,
"weaponhoverDmg" : 365,
"weaponairDmg" : 365,
"weaponbaseDmg" : 365,
},
"DEEEEEEWWWMMM" :  {
"weaponName" : "DEEEEEEWWWMMM",
"weaponRange" : 800,
"weaponreload" : 5,
"weapondefDmg" :4000,
"weaponlightDmg" : 4000,
"weaponmediumDmg" : 4000,
"weaponheavyDmg" : 4000,
"weaponshipsDmg" : 4000,
"weaponsubsDmg" : 5,
"weaponhoverDmg" : 4000,
"weaponairDmg" : 4000,
"weaponbaseDmg" : 4000,
},
"HeavyRockets" :  {
"weaponName" : "HeavyRockets",
"weaponRange" : 800,
"weaponreload" : 2.75,
"weapondefDmg" :360,
"weaponlightDmg" : 360,
"weaponmediumDmg" : 360,
"weaponheavyDmg" : 360,
"weaponshipsDmg" : 360,
"weaponsubsDmg" : 5,
"weaponhoverDmg" : 360,
"weaponairDmg" : 360,
"weaponbaseDmg" : 360,
},
},
"armorClass" :  "heavyunits",
"cloakCost" :  0}
Now one of the most interesting values is of course, how much damage a certain unit can deal. In the given modinfo descriptions the highly descriptive DPS (damage per second) is calculated; which is basically not much more than "damage" divided by "reloadTime". But here my questions starts, and I can't figure it out with the information I have at hand:
how do I determine the correct pairing of damage a unit can deal against a certain other unit?
I guess it might have to do with the armorClass -- but this is "else" for basically most units. I can't find the place where a specific damage information is specified on the end of the damage recipient (victim, attacked unit, ...).

Any hints?

cheers,
christoph
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: unit info -- armor classes and weapon damage

Post by PepeAmpere »

Why armorClass is not good enough? You can have as many armorClasses as many units you have and in weapon setting you specify the damage for each "class"=unit.
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Maybe I didn't phrase the question correctly. I'll try to make an example, let's take a fight of a Commander against a Peewee.

My question is now: How do I determine the damage that the Commander deals to the Peewee and vice versa.

The information I have at hand is:

The Peewee has armorClass 'else' and a single weapon called peewee:
"peewee" : {
"weaponName" : "peewee",
"weaponRange" : 180,
"weaponreload" : 0.31,
"weapondefDmg" :11,
"weaponlightDmg" : 11,
"weaponmediumDmg" : 11,
"weaponheavyDmg" : 11,
"weaponshipsDmg" : 11,
"weaponsubsDmg" : 1,
"weaponhoverDmg" : 11,
"weaponairDmg" : 11,
"weaponbaseDmg" : 11,
}
The Commander has the armorClass 'commanders' and several weapons:
"weapons" : {
"J7Laser" : {
"weaponName" : "J7Laser",
"weaponRange" : 300,
"weaponreload" : 0.40,
"weapondefDmg" :75,
"weaponlightDmg" : 75,
"weaponmediumDmg" : 75,
"weaponheavyDmg" : 75,
"weaponshipsDmg" : 75,
"weaponsubsDmg" : 5,
"weaponhoverDmg" : 75,
"weaponairDmg" : 75,
"weaponbaseDmg" : 75,
},
"J7NSLaser" : {
"weaponName" : "J7NSLaser",
"weaponRange" : 260,
"weaponreload" : 1,
"weapondefDmg" :125,
"weaponlightDmg" : 125,
"weaponmediumDmg" : 125,
"weaponheavyDmg" : 125,
"weaponshipsDmg" : 125,
"weaponsubsDmg" : 75,
"weaponhoverDmg" : 125,
"weaponairDmg" : 125,
"weaponbaseDmg" : 125,
}
User avatar
PepeAmpere
Posts: 591
Joined: 03 Jun 2010, 01:28

Re: unit info -- armor classes and weapon damage

Post by PepeAmpere »

Maybe I do not get it still. You should specify your goal better. Are you:

:?: dev who try to archive some gameplay?
:?: widget maker, who want to export some gameplay info from game you dont want to change?

First story: Im developer and want to make gameplay

I have units
  • commander
  • peewee
I want to have weapons
  • comweap1 - commander laser which is good for killing peewees
  • comweap2 - commander rocket which is good for killing armored targets (e.g. other commanders) but do not do any special dmg to peewee
  • peeweap1 - peewee weapon, which good for killing light targets but really fail in damaging armored commander
So you define classes as specified in https://springrts.com/wiki/Armordefs.lua , e.g.

Code: Select all

armorDefs = {
	light = {
		"peewee",
	},
	armored = {
		"commander",
	},
}
So appropriate solution to capture weapons description would be

comweap1

Code: Select all

...
damage = {
	default = 30, -- "default damage i do to any unit which has not armor class"
	light = 30, -- "good for killing light units"
	armored = 5, -- "bad for damaging armored units"
},
...
comweap2

Code: Select all

...
damage = {
	default = 15, -- "default damage i do to any unit which has not armor class"
	light = 15, -- "do this dmg to light units"
	armored = 15, -- "its antiarmor, do the same damage to armored units as well"
},
...
peeweap1

Code: Select all

...
damage = {
	default = 5, -- "default damage i do to any unit which has not armor class"
	light = 10, -- "do this dmg to light units"
	armored = 2, -- "bad for damaging armored units"
},
...
If we add some new unit, which is not listed in armor classes definition, weapon will have effect of "default" damage. If unit is in armorclasses, weapon will do damage according given class.


Second story: Im widget maker and want to map armor class to weapon dmg
  • For each unit you have to get armor class
  • And for each weapon search for given class in definition
    - if there is such class, use given number
    - if there is not such class listed, default is used
----
Im not sure if you find it there (im in a hurry with finishing the post) but those places are good spots to start. In case of weapons I think you find it, in case of units you will maybe need to parse directly armordefs.lua/TDF and get classes from there
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Hi,

right away: all I want is information, to build "yet another info tool". I can get all postprocessed UnitDef parts via Lua ingame, I've given an example in my first post for the Bantha unit ('armbanth').

One piece of understanding is missing; the central questions are: I can't figure out how the specific damage one unit deals to another. So how is this calculated, how can I access that information?

afaiu, PepeAmpere posted the information I already had -- if I'm not mistaken. Looking at the armordefs.lua file I find that most units have the armorclass 'else'. So this doesn't match the description I find e.g. on the website http://springrts.ru:8080/ba901/armbanth.html. afaik this was generated from the script http://imolarpg.dyndns.org/trac/balates ... od2html.py. If you scroll down on the modinfo page you'll find that for weapon "tehlazerofdewm" there is listed the target 'commanders', which is dealt a damage of 1200, or a DPS of 240.00 respectively. How is that calculated? The script doesn't give a real answer to this. In a nutshell: the information I get from spring ( via lua ingame ) about the 'armbanth' unit has no notion of a commander. And I can't find any other connection, the 'armorclass' attribute is actually only my surmise in searching for straws.

Maybe I'm blind, which is why I'm asking.
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Hi, I am blind.

I'm still not sure how I missed it, but the information is given in the initial UnitDef file, as shipped with the mod itself. I had forgotten that the mod2html script ran on the original, unprocessed UnitDef files. Which in turn makes the whole system I had devised a lot easier, as usual.

So this topic can be closed. My only remaining question is how to get this information 'post-processed', I'd prefer right now from the ingame lua interface. But maybe all the values of interest to my info tool are unchanged anyhow.

Thanks for the help!
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: unit info -- armor classes and weapon damage

Post by gajop »

cherub wrote:My only remaining question is how to get this information 'post-processed', I'd prefer right now from the ingame lua interface
Spring.GetUnitDefID(number unitID)
https://springrts.com/wiki/Lua_UnitDefs
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Hi,

that's a quick reply. I can't check this right now, I'm still at work. In the UnitDef Tables I can see that there is one table 'weapondefs' and a second one called 'weapons'. 'weapons' seemingly extends the first table, based on the index of the 'wepondefs' table.
So it looks like I can access this ingame with lua like (pseudocode)

Code: Select all

UnitDefs[$UNIT].weapons[$WEAPONID].badTargets
UnitDefs[$UNIT].weapons[$WEAPONID].onlyTargets
And the all-deciding property, which until today I couldn't quite get is the 'category', which I can access via

Code: Select all

UnitDefs[$UNIT].modCategories
(and both snippets are visible in https://github.com/spring/spring/blob/1 ... itDefs.cpp )

So in short -- the key element is the category and nothing else. Thanks for the enlightment, I'm sure that I missed something in the wiki or a pointer elsewhere.

Thanks for the big help.
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Hi again,

I'm still not done. Unfortunately (and not unexpected from my side) the last pseudo-code snippets didn't work. I still can't retrieve the damage information per weapon per unit via the ingame lua interface (e.g. how much damage does the Bantha laser make against a Zeus?).

I could retrieve the category information, which is a table with the strings as key and a boolean as value:

Code: Select all

		---- Categories, the key in BA to unit damages
		local thisCategories = UnitDefs[i].modCategories
		local categories = {}
			if (thisCategories) then
			for key, value  in pairs(thisCategories) do
				categories[key] = { tostring(value) or "", }
			end
			end 
But regarding the damage list I've made little progress. Both "badTargets" and "onlyTargets" yield a 'nil' value, so they're no part of the interface. I've also iterated over all elements in the UnitDefs[$UNIT].weapons[$WEAPONID] part; but I only get back iterators and functions as key/value pairs. The iteration code is something along the lines of

Code: Select all

  --- looping over all units -> index i
		local thisWeaponsTable = UnitDefs[i].weapons
		--- note: WeaponsTable is actually an array
		--- iterate over array -> index j 
		for key, value  in pairs(WeaponDefs[UnitDefs[i].weapons[j].weaponDef]) do
			Spring.Echo("iterating the weapon table with (k,v) = " .. tostring(key) .. " / " .. tostring(value) .. ".")
		end
I've tried the lua documentation, but I can't find out how to determine the actual names I need to call. I've also failed so far to retrieve the information in terms of Spring code -- failing to figure out how it is processed. I've tried most of the interface names given in both LuaUnitDefs and LuaWeaponDefs -- but no success so far.

Maybe -- probably I'm missing something again. Does anyone have another idea or can offer some advice?

cheers
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: unit info -- armor classes and weapon damage

Post by Silentwings »

With all due respect, I don't think you have a hope of solving this yourself and I am too lazy to read the blurb above so here are the details:

(1) How much damage is potentially dealt by a given weapon to a given unit, on impact, is determined by (a) looking at the armor type of the target unit, and then (b) looking at the damage dealt by the weapon to that armor type.
(2) How much damage is actually dealt by a given weapon to a given unit is more complicated and depends on many factors, such as proximity of unit to explosion versus the weapons damage falloff, boosts for multiple/directed hits, addition damage modifications done at runtime by gadgets, etc. It is not worth trying to calculate/estimate this.
(3) As you discovered, which unit belongs to which armour class is specified in armordefs.lua and not in the unit def files. However, this is no use to you since the damage info inside UnitDefs and WeaponDefs are indexed by armorType, which is a number. Instead, to find out which armorType is possessed by a unit, you can read from the UnitDefs table. (Each armor type corresponds to one of the armor classes in armordefs.lua, and the Game.armorTypes table tell you which armor type is which armor class. But you don't need this, you can just work with armorTypes.)
(4) badTargets and onlyTargets are not nil and the wiki page is correct. modCategories, such as the entries of badTargets and onlyTargets do not control how much damage is dealt, they control whether or not a weapon will automatically shoot at a potential target. From the point of view of a player, this might mean you want to list badTargets as damage 0, or when onlyTargets is non-empty list eveything outside it as damage 0, even though the reality is not like that.
(5) To do all of this in practice:

Code: Select all

function widget:GetInfo()
    return {
        name      = "Test",
        version   = "0",
        desc      = "",
        author    = "Pope Brian IX",
        date      = "2000 BC",
        license   = "Je suis une pamplemousse",
        layer     = 0,
        enabled   = true
	}
end 


function widget:Initialize()
    for unitDefID, unitDef in pairs(UnitDefs) do
        local weapons = unitDef.weapons
        Spring.Echo("unit " .. unitDef.name .. " with unitDefID " .. unitDefID .. " has:")

        Spring.Echo(" armorType " .. unitDef.armorType .. " (which is armorClass " .. Game.armorTypes[unitDef.armorType] .. ")")

        local modCats = ""
        for k,_ in pairs(unitDef.modCategories) do
            modCats = modCats .. " " .. k
        end
        Spring.Echo(" modCategories: " .. modCats)        
        
        for i,weaponInfo in ipairs(weapons) do
            local weaponDefID = weaponInfo.weaponDef


            Spring.Echo(" weapon " .. i .. " with weaponDefID " .. weaponDefID)

            local badTargets = ""
            for modCat,_ in pairs(weaponInfo.badTargets) do
                badTargets = badTargets .. " " .. modCat
            end
            Spring.Echo("  with bad target categories: " .. badTargets)
            
             local onlyTargets = ""
            for modCat,_ in pairs(weaponInfo.onlyTargets) do
                onlyTargets = onlyTargets .. " " .. modCat
            end
            Spring.Echo("  with only target categories: " .. onlyTargets)
 
            Spring.Echo("  with damages:")
            PrintWeaponDamages(weaponDefID) -- not nil!            
        end    
    end
end

function PrintWeaponDamages(weaponDefID)
    local weaponDef = WeaponDefs[weaponDefID]
    local damages = weaponDef.damages
    for armorType,damage in pairs(damages) do
        if type(damageTarget)=='number' then -- this table also contains other damage related info e.g. craterboost, but all number keys match armour defs
            Spring.Echo("   " .. damage .. " damage to armorType " .. armorType)
        end
    end
end
(edit: included Game.armorTypes table)
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Hi again, stil at work; will try code later.

Some questions I can ask, though.
Silentwings wrote:[...](1) How much damage is potentially dealt by a given weapon to a given unit, on impact, is determined by (a) looking at the armor type of the target unit, and then (b) looking at the damage dealt by the weapon to that armor type.
This would have been my assumption. (b) I can do -- I can read/access the amount of damage per unit per weapon that is (potentially) dealt. But (a) doesn't work; my initial problem -- see first post -- is that almost no unit has a matching armor class, basically all units have armorClass 'else'.

I'll re-read the whole thread when I have more time, maybe I misunderstood something. The answers so far had pointed me in a different direction.
Silentwings wrote:[...](4) badTargets and onlyTargets are not nil [...]
I'll try again; sorry if the last message was spam in that case. Yesterday I tried for a while, but failed; being tired I thought I'd rather ask than spend more time on it.

thx
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: unit info -- armor classes and weapon damage

Post by Silentwings »

But (a) doesn't work; my initial problem -- see first post -- is that almost no unit has a matching armor class, basically all units have armorClass 'else'.
Read (3).
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: unit info -- armor classes and weapon damage

Post by hokomoko »

you actually have the Game.armorTypes table
https://springrts.com/wiki/Lua_ConstGame#Categories
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Hi,

I was using the Game.armorTypes table -- one of the part I shamelessly copied from pepeAmpere's modstats2html. Snippet:

Code: Select all

 defDmg		= tostring(WeaponDefs[wepID].damages[Game.armorTypes["default"] or 0]) or "-",
 lightDmg	= tostring(WeaponDefs[wepID].damages[Game.armorTypes["light"] or 0]) or "-",
 mediumDmg	= tostring(WeaponDefs[wepID].damages[Game.armorTypes["medium"] or 0]) or "-",
I can't remember if I tried to put in the names from armordefs.lua for BA (e.g. 'commanders', 'else', etc.). I'll try/say more later, once I'm at home.

cheers
cherub
Posts: 12
Joined: 08 Mar 2012, 18:52

Re: unit info -- armor classes and weapon damage

Post by cherub »

Great, it works!

Thanks for the help. Obviously written text to unknown people is not the best way to communicate. I'm glad that I finally understood, what you tried to tell me.

Once I have cleaned up a bit, then I'll put the widget up/out for comments and more; the "application" that does something with it is still in writing.

cheers
Post Reply

Return to “Balanced Annihilation”