Yes knorke that would work if you prefer it.
Personally I think the mortars/arty and tank guns are more interesting examples as they use a form of multiple inheritance (Base class, Armour Piercing or Smoke or High Explosive class, then the weapon specific base class)
http://spring1944.svn.sourceforge.net/v ... iew=markup
So, here is code spam:
Basic 'LightGun' class, a class for all 40-50mm direct fire (tank & ship) guns in S44.
Code: Select all
local LightGunClass = Weapon:New{
accuracy = 100,
collisionSize = 4,
impulseFactor = 0,
intensity = 0.25,
leadBonus = 0.5,
leadLimit = 0,
movingAccuracy = 500, --590 for 2pdr?
separation = 2,
size = 1,
soundStart = [[US_37mm]], -- move later?
stages = 50,
tolerance = 300,
turret = true,
weaponType = [[Cannon]],
}
Almost all of these weapons have two versions - AP and HE. So make additional classes with those shared attributes:
Code: Select all
-- HE Round Class
local LightGunHEClass = Weapon:New{
edgeEffectiveness = 0.2,
explosionGenerator = [[custom:HE_Small]],
explosionSpeed = 30, -- needed?
name = [[HE Shell]],
rgbColor = [[0.5 0.5 0.0]],
soundHit = [[GEN_Explo_2]],
customparams = {
damagetype = [[explosive]],
fearaoe = 40,
fearid = 301,
},
}
-- AP Round Class
local LightGunAPClass = Weapon:New{
areaOfEffect = 5,
canattackground = false,
colormap = [[ap_colormap.png]],
edgeEffectiveness = 0.1,
explosionGenerator = [[custom:AP_Small]],
explosionSpeed = 100, -- needed?
name = [[AP Shell]],
soundHit = [[GEN_Explo_1]],
customparams = {
damagetype = [[kinetic]],
},
}
Now I want to make a particular implementation of a 40mm gun, the British 2pdr:
Code: Select all
-- QF 2Pdr 40mm (GBR)
local QF2Pdr40mm = LightGunClass:New{
name = [[QF 2 Pdr Mk.X]],
range = 1070,
reloadTime = 4.5,
}
It should have a HE and an AP version, with some additional specific tags that are not common to the 2pdr itself nor all AP or HE weapons:
Code: Select all
local QF2Pdr40mmHE = QF2Pdr40mm:New(LightGunHEClass, true):New{
areaOfEffect = 42,
weaponVelocity = 1584,
damage = {
default = 350,
},
}
local QF2Pdr40mmAP = QF2Pdr40mm:New(LightGunAPClass, true):New{
weaponVelocity = 1616,
customparams = {
armor_penetration_1000m = 45,
armor_penetration_100m = 59,
},
damage = {
default = 1105,
},
}
At the end I return all the weapons I want to be available in the game, but not their base classes:
Code: Select all
return lowerkeys({
-- QF 2Pdr
QF2Pdr40mmHE = QF2Pdr40mmHE,
QF2Pdr40mmAP = QF2Pdr40mmAP,
}}
Essentially each call of :New just adds all of the new tags to the table, overwriting any that already exist.
The first parameter takes a table of the new values, so you can pass an existing table or a new one using {}.
The second parameter is whether or not to concatenate (true) or overwrite (false) the name string, I use it here to append ' AP Shell' and ' HE Shell' respectively.
edit:
knorke wrote:Would use something like that, if not for two reasons:
-not enought similiar weapons
Yes - Its really only useful if you have weapons used by multiple units that share many attributes. In that respect it's a solution to an S44 specific problem, but I thought others might find it useful / be inspired to do something similar / just interesting to see an alternative to the CA defs.
