Multiple unit/feature/weapon defs per file

Multiple unit/feature/weapon defs per file

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Multiple unit/feature/weapon defs per file

Post by knorke »

You can have multiple *defs in one file.
I guess some knew that but I have never seen it anywhere except sometimes for cegs.

So why give a ohlala?
Imagine all the units in your mod are almost the same.
Or more realisticaly, you have alot of features that are really similiar:
if there are 10 different trees, then their featureDef is probally almost the same, except for the 3d model and name.
:arrow: Fact: Most trees are 99% identical.
This is also true for rocks and buildings. and e&e units trololo

Normally you would have 10 files like
tree1.lua, tree2.lua, tree2.lua ... tree10.lua
And to change something (ie increase the footprint of all trees) you go through all 10 files by hand. Or use some batch editor.

But why not put all the similiar things in one file!
Image

For example these signs:
Image
are made by this file:
http://pastebin.com/rjCEBfrt

At the top of the file there is the featureDef= which defines all the stuff that all 5 features have in common, like same footprint, reclaim stuff etc.

Notice name, description, object are commentated out because those will be different.

Then in the next lines some empty tables are declared and the for-loop fills those with the "base" featureDef thing.
Now all all those features are still the same which is changed in the next step where it goes like
tpsign_1.name = "tpsign_1"
tpsign_1.object = "tpsign_1.s3o"
tpsign_1.description ="woof woof"

...
And in the end all the new tables are returned so Spring can read them.

Of course could be taken further, ie one could do
for i=1,5 do
signs.object = "sign_" .. i .. ".s3o"
...

blabla.

Pay attention to all the , } etc, if something is wrong Spring will not give any message at all but just ignore the file. Also Echo does not work it seems.
User avatar
Karl
Panzerstahl Developer
Posts: 746
Joined: 01 Apr 2010, 21:05

Re: Multiple unit/feature/weapon defs per file

Post by Karl »

Does this mean i could basically have for example Stumpy and Instigator in one file and they behave exactly like they were in 2 file originaly?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Multiple unit/feature/weapon defs per file

Post by knorke »

To be honest I only tested with the the sign features so far.
But I do not see why it would not work with units etc too.
So I think yes.
User avatar
Karl
Panzerstahl Developer
Posts: 746
Joined: 01 Apr 2010, 21:05

Re: Multiple unit/feature/weapon defs per file

Post by Karl »

That should be Engine implented to be honest

This way Spring 1944 teams could box all those ausf├╝hrungs tanks
bashing in one file

Reducing clutter

Does this work for weapons as well?
nevermind redundant question.
Last edited by Karl on 02 Oct 2011, 13:17, edited 1 time in total.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Multiple unit/feature/weapon defs per file

Post by knorke »

That should be Engine implented to be honest
well, it is engine implented otherwise this would not work?
Does this work for weapons as well?
id think so.

I will test with units later by combining all the civilian vehicles into one file.
redvan, bluevan, whitevan, yellowbus -> civvehicle.lua
User avatar
Karl
Panzerstahl Developer
Posts: 746
Joined: 01 Apr 2010, 21:05

Re: Multiple unit/feature/weapon defs per file

Post by Karl »

Well i don't know about it because it seems to be a SVN feature? I don't really check the svn version of Spring
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Multiple unit/feature/weapon defs per file

Post by knorke »

This is with current release.
User avatar
Karl
Panzerstahl Developer
Posts: 746
Joined: 01 Apr 2010, 21:05

Re: Multiple unit/feature/weapon defs per file

Post by Karl »

I must be sleeping under rocks how the hell i dint know that for 9+ Months about that?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Multiple unit/feature/weapon defs per file

Post by FLOZi »

Multiple defs per file have always worked (they worked in TA! At least for weapons and features).

But OO style defs is something I've been planning for ages, and working on for the past few months;

Rifles - Has weapons inheriting from each other (see RUSMosinNagant and RUSPartisanMosinNagant)

Howitzers - has multiple inheritance (See how a howitzer weapon inherits from the howitzer base class, and then also either smoke or HE shell. The additional 'true' param concatenates the names together)

How it works:
http://spring1944.svn.sourceforge.net/v ... iew=markup

Also Echo works fine.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Multiple unit/feature/weapon defs per file

Post by zwzsg »

Kernel Panic hero units are created by code (with most of tags copied from spam units).
Post Reply

Return to “Game Development”