View topic - Lua weapondefs with inheritance



All times are UTC + 1 hour


Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 06 May 2012, 11:54 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
Started this ~10 months ago, finally converted the last S44 main weapons. :lol:

May or may not find it relevant to your interests:

The magic (Thanks to jk)

The weapondefs


Top
 Online Profile  
 
PostPosted: 07 May 2012, 11:47 
Evolution RTS Developer
User avatar

Joined: 17 Nov 2005, 02:43
Location: Raegquitting Spring on 04/24/12
I'm not sure I understand why you would do weapons this way (IE, not in the unitdef)? It seems grossly inefficient and difficult to maintain?


Top
 Offline Profile  
 
PostPosted: 07 May 2012, 12:16 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
S44 weapons have always been 'not in the unitdef' because they are shared across multiple units. It is far more efficient and much easier to maintain this way than defining the same machinegun 9 times. And with the inheritance it is now even easier.


Top
 Online Profile  
 
PostPosted: 07 May 2012, 17:06 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
That is imo a good idea.
Would use something like that, if not for two reasons:
-not enought similiar weapons
-did not use it right from start, now too lazy to change it. easier to pile on top of the existing mess :wink:


Top
 Offline Profile  
 
PostPosted: 07 May 2012, 17:25 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
Forboding Angel wrote:
I'm not sure I understand why you would do weapons this way (IE, not in the unitdef)? It seems grossly inefficient and difficult to maintain?

I don't store the weapons in the unitdef.


Top
 Offline Profile  
 
PostPosted: 07 May 2012, 17:26 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
flozi, what does this do? forbs post doesn't tell me anything more.

What would I be inheriting? can you give an example of how it works out?


Top
 Offline Profile  
 
PostPosted: 07 May 2012, 17:39 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
example:
http://spring1944.svn.sourceforge.net/v ... iew=markup

At top of file there is the "default" rifle, and under that the "variants" of that weapon.

All the sniper rifles are the same, except:
-each has a unique sound
-the british one reloads faster
-us rifle is more accurate when moving (fooking noscope)

So to make all snipers deal more damage (example) you only need to change one number instead of 4.

------------------------

That is not so nice imo:
Code:
return lowerkeys({
Enfield_T = Enfield_T,
K98kScope = K98kScope,
M1903Springfield = M1903Springfield,
MosinNagantPU = MosinNagantPU,
It just repeats things that already exist..

Would something like that work?
Code:
return {
["K98kScope" = SniperRifleClass:New{
name = [[Karabiner 98k Scoped]],
soundStart = [[GER_K98K]],
},
["M1903Springfield"] = SniperRifleClass:New{
...},
}


Top
 Offline Profile  
 
PostPosted: 07 May 2012, 17:52 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
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:
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:
-- 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:
-- 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:
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:
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. 8)


Top
 Online Profile  
 
PostPosted: 23 Dec 2012, 23:15 
Journeywar Developer & Mapper
User avatar

Joined: 24 Jan 2006, 21:12
Location: There is no god - and reality is his prophetess
Tried to port this to units: May be incomplete or completely wrong.

script:
http://paste.springfiles.com/view/664e1aca
example:
http://paste.springfiles.com/view/c1eea3b3


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.