Population Cap Gadget - Page 2

Population Cap Gadget

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Population Cap Gadget

Post by Anarchid »

He's trying to say that you could generate supply-use values for your units based on an amalgam of their previously existing stats and some contrived neon-math.

He pulled the "wreckages" thing from the fact that ZK seems to automatically assign metal values to wreckages based on unit cost.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Population Cap Gadget

Post by zwzsg »

There are two ways to add a new property to a hundred items (Here, supply cost to all Evo units):
- The dumb way is to add a new tag to each one of your unit stat spreadsheet.
- The smart way is to add a couple lines of code in some gadget or gamedata/*.lua to calculate a value for each unit from a generic formula.

But I don't agree that the "smart" way is always better: NeonStorm might be of the opinion that it is easier to maintain a few lines of code than a hundred value spread in a hundred files, except that he forgets that if the code is too smart, it becomes impossible to understand (at a later stage or by another person), and thus impossible to maintain, while many values in many files, while laborious to edit, are at least understandable and editable by anybody, and with a much lower risk of breaking the Lua.

NeonStorm then propose a formula to derive Supply Cost from Metal Cost (which indeed isn't very clear).
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Population Cap Gadget

Post by knorke »

Most pro is to have both.
a) The dumb way is to add a new tag to each one of your unit stat spreadsheet.
b) The smart way is to add a couple lines of code in some gadget or gamedata/*.lua to calculate a value for each unit from a generic formula.
First try a) but if tag does not exist in unitdef then do b)
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: Population Cap Gadget

Post by NeonStorm »

Ofcourse I prefer the code lines - And this is the "Lua Scripts" subforum.

Spring already has a lot of code - few comments, a lot of side-steps (you need to know another file to know what the code in this file does), etc.

It is not more complex than any config-file (just an example how it would look like for a BA-unit):

Code: Select all

for unitname,x in pairs(unitdefs) do

  x.populationWeight = #offset + (x.metalcost + x.energycost/60) /#mPerWeightUnit
  x.energyCost = x.metalCost*60

end
x.energyCost is the same as in unit blueprints - just with leading "x."
very hard to break, very easy to find the bug.

It would be special code if just used for 1 thing, but ok if you need it for many stats and write it into a documentation.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Population Cap Gadget

Post by Forboding Angel »

The "smart" way would be idiotic. Since when is supply going to directly correlate with cost?

Just because something is expensive doesn't mean that it should use a bunch of supply.

Your assumption is quite faulty.
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Population Cap Gadget

Post by SinbadEV »

Might be a good idea to set a "default" somewhere (makes 0, uses 1) so that every unit has the stat... and then to manually specify in each unit that differs from the default.
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: Population Cap Gadget

Post by NeonStorm »

x.energyCost = x.energyCost or 0

if x.energyCost is not set, it will be set to 0.
But you have to do that before spring inserts own defaults.

I know from Supreme Commander - Forget Alliance, that a Walker-Bot inherits all defaults from a Walker-Class.
All air units inherit from AirUnit-class. A bomber can inherit from a bomber-class, which itself inherits from Plane-class, which inherit values from AirUnit-class.

It is like a Tree - everything inherits what comes from the roots.
Post Reply

Return to “Lua Scripts”