RFC: Lua weapondefs with inheritance


#1

Code untested, but as a structural idea:

pastebin.com/Rzv7yXSY

The Inherit function itself can probably be put elsewhere so it doesn’t need to be in every def, or at the very least can just be included. It automatically concatenates the ‘name’ tag and also copies subtables (probably not needed).


#2

IMO this should be in weapondefs_post, and inheritance should be controlled by a customParams tag (for ex. inheritFrom = ancestor_weapon_name).

Maybe there should be another tag, like templateWeapon = 1, which, if present, causes the weapon to be removed at the end of weapondefs_post (so that ingame weapon list does not contain “ancestor” weapons if those aren’t used by a unit).


#3

What reason other than that it could theoretically allow inheritance with tdf weapons? Even if that is the case, we still need to rewrite the weapons to do so, which we may as well do at the same time as luafication.

On another note, here is current (working) version (inherit function is placed in gamedata/system.lua):

pastebin.com/BmvhzP28

Also I believe we should put weapondefs under subfolders akin to unitdefs. i.e. weapons/us/US_M3-75mm.lua


#4

tdf inheritance was indeed in my mind, if everything gets converted to lua anyway, then that’s not important.

Subfolders for weapons are a good idea.


#5

Another example using my method:

pastebin.com/SU5DM1vd

An alternative format suggested by jk, which removes the need for the final loop:

pastebin.com/fbh9Shau (line 1 through 47 being hidden away of course)

He also proposed that each weapondef could register itself (automatically, as part of the Inherit function) so as to avoid actually returning the tables at the end of the file.


#6

Final design:

pastebin.com/CyKjEdUm

Uses JK’s OO style syntax, but with returned tables (myself and yuri felt they are preferable)


#7

Proposed structure of /weapons (Entries in bold are what I have converted thus far):

Aircraft/
AirAntiTankGuns.lua
AirAutoCannons.lua
AirRockets.lua
Bombs.lua
ParaDrops.lua

Artillery/
– AntiAircraftGuns.lua
ArtyRockets.lua
– Howitzers.lua
InfantryGuns.lua
Mortars.lua

Infantry/
AntiTankLaunchers.lua
AntiTankRifles.lua
Flamethrowers.lua
Grenades.lua
– Machineguns.lua
Pistols.lua
Rifles.lua
SniperRifles.lua
SubMachineGuns.lua

Misc/
– Binoculars.lua
– BulletProofs.lua
– Deaths.lua
– Mines.lua
– Tracers.lua

Tanks/
– not sure yet

Ships/
– no idea, will need feedback from yuri here

Inclusions:
Bombs.lua will include PTAB
AntiAircraftGuns.lua will include Flak38 including it’s AP round (I figure bofors is more likely to get AP than tank guns to get AA versions)
Wasp flamer is in Infantry/Flamethrowers.lua, I figure all flamers can go together and are an anti-infantry weapon.
Mines.lua includes satchel charge
ParaDrops.lua is both paratrooper and partisan supply weapons

Issues:
V1 explosion needs a home
Thoughts on how to break down tank weapons? One for each gun? AutoCannon, ~40mm, ~75mm, ~90mm, AssaultGuns?


#8

IMO breaking tank guns by caliber is a good idea. So TankGuns40mm.lua, TankGuns75mm.lua, etc. (with the idea that 37 mm goes to 40 mm and 76 mm to 75 mm, etc.)
Same for assault guns, or maybe they even should be grouped together with tank guns.

V1 can be said to be a bomb, it’s on the same power level.

Large ship weapons will need more categories, but they aren’t in the main build. Their categories will be:

  • Battleship/cruiser main guns (6" or greater)
  • non-universal destroyer artillery (more than 100 mm and less than 6", can’t fire at aircraft)
  • universal guns (can fire at both aircraft and ground targets, generally 75-127 mm - smaller ones go into automatic AA category, heavier ones can’t track aircraft)
  • torpedoes
  • depth charges
    (automatic AA guns are not included as they are mostly the same as on ground units and so can live in the ground AA file).

#9

AssaultGuns have smoke (with exception of ISU-152 & StuG, which is just same as PzIV weapons) which is the distinction I was making there.

V1 can be said to be a bomb, but it’s behaviour (and therefore one would expect its tags) are quite different. Really it belongs in Deaths.lua but it may be a bit hidden away there.

Could you make a list of currently used ship weapons? i.e. those only on ships we intend to use in S44Main

edit: Upon looking at the defs, V1 is near identical to bombs so that solves that. PTAB is quite different though!

I’ve moved the ‘noweapon’ weapon into weapondefs_pre.lua so there’s no need for GameplayExtras.lua anymore (as I already split out the paradrop weapons), may as well just have a Binoculars.lua. Funnily enough there was another ‘noweapon’ in deaths.tdf not being used! :unamused:


#10

Machineguns could do with some clearing up, they are quite messy:

pastebin.com/rLrj99pp

Lots of stuff that it seems can be the same across types, like sprayAngle (I doubt there is any discernible difference between 300 and 350), movingAccuracy, even ranges; why should one tank MG have greater range than another?


#11

So due to my internet connection being very unstable atm, and avoiding writing an important essay, I’ve found time to start lua-ising the tank guns.

Currently they are named ‘LightGun’ (37mm, 2pdr, 45mm), ‘LightMediumGun’ (50mm, 6pdr, 57mm), ‘MediumGun’ (75 & 76mm), I don’t know whether to then do ‘MediumHeavyGun’ (88mm, 90mm) and ‘HeavyGun’ (100mm+) or further split up the heavies.

Also I don’t know if numerical names would be better:
40mmGun, 50mmGun, 75mmGun, 90mmGun, 100mmGun

A more consistent (but imo less ‘intuitive’) approach would be to round down:
30mmGun, 50mmGun, 75mmGun, 80mmGun, 100mmGun

Nemo should also have a look over them once committed, I’ve flagged up a few inconsistencies and there may be more.


#12

So 10 months later, the process is complete. :laughing: