View topic - Multiple unit/feature/weapon defs per file



All times are UTC + 1 hour


Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: 02 Oct 2011, 11:49 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
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[i].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.


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:03 
User avatar

Joined: 01 Apr 2010, 20:05
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?


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:06 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
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.


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:12 
User avatar

Joined: 01 Apr 2010, 20:05
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, 12:17, edited 1 time in total.

Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:17 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
Quote:
That should be Engine implented to be honest
well, it is engine implented otherwise this would not work?
Quote:
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


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:18 
User avatar

Joined: 01 Apr 2010, 20:05
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


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:21 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
This is with current release.


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:23 
User avatar

Joined: 01 Apr 2010, 20:05
I must be sleeping under rocks how the hell i dint know that for 9+ Months about that?


Top
 Offline Profile  
 
PostPosted: 02 Oct 2011, 12:46 
Moderator
User avatar

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


Top
 Offline Profile  
 
PostPosted: 05 Oct 2011, 20:11 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
Kernel Panic hero units are created by code (with most of tags copied from spam units).


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


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.