Improve unit economy and unitDefs

Improve unit economy and unitDefs

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

Moderator: Moderators

Post Reply
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Improve unit economy and unitDefs

Post by NeonStorm »

  • Table of contents
  • Problems with that
  • Facts
  • What/How we can improve
  • Visibility of this improvement
Some units have an internal economy like stockpile, shield charge or multiple weapons which all require energy.

Problems with that

We define the energy/metal requirements completely different if the weapon is a stockpiled one, a shield or use fuel for bombs (bombers)

And even more different if the unit cloaks, because cloak isn't even in weapon defs.

As far as I know, some feature requests from 2007 still apply:
http://springrts.com/phpbb/viewtopic.ph ... rgypershot
http://springrts.com/phpbb/viewtopic.ph ... rgypershot

Conclusion: Units can only have 1 stockpile weapon and stockpiling can't be assisted, mainly because the silo has a stockpile-time instead of projectiles and silo have workerTime variables, and thus you can't get the engine to support it without lua.


You can make weapons use fuel, but you can not - for example - make cloak or walking slow down the fuel regeneration without many lines of lua.


Fakts

I've read that you can change unit defs with lua before the engine sees them.

That could be used to convert UnitDef tables into engine-supported ones.
And extract all important things into a custom table (or customparams) - for a gadget.

It could also check if it can not waive the hacks - dependent on variable values.


Example failure today:

gun1: 300e per shot, 1s reload 1000 range, 500 damage
gun2: 1000e per shot, 3s reload 500 range, 3000 damage

Can you imagine what happens if you stall energy?
* gun2 will never fire, because gun1 converts energy before unit2 is allowed to.
* gun1 will maybe never fire too, because another unit's weapon converts 10e to 10 damage (a lot worse) before it could even see the 300e in player's storage.


What/How we can improve

The best because simpliest solution would be:

Code: Select all

PlayerDefinition, UnitDef, WeaponDef or AbilityDef ={
...
  storage ={
    <string: resource> = <number: limit>, ...
  },

  converters ={
    {
      cooldown = <number: gameframes> or false, -- if false it is evaluated as often as possible in one step (: =faster :) before evaluating the next converter

      importer = <boolean> or false,
      exporter = <boolean> or false,

      input ={
         <string: resource> = <number: amount>, ...
      },
      inputConditions = <table:{
         <string: resource> = {
            absolut = <int: value>, -- storedMin = value
            relative = <float(0..1): value>, -- storedMin = math.floor(value*storageLimit)
         },
      }> or false,

      output ={
         <string: resource> = <number: amount>, ...
      },
      outputConditions = <table:{
         <string: resource> = {
            absolut = <int: value>, -- storedMax = storageLimit -value
            relative = <float(0..1): value>, -- storedMax = storageLimit -math.floor(value*storageLimit)
         }
         ...
      }> or false,
    },
    ... -- more  converters
  },
...
}
--[[
input enhances the input conditions
if the converter has input (false for generators), output enhances the outputConditions

if the converter is an importer, all input is taken from the next higher obj with such storage
if the converter is an exporter, the output is given to the next higher obj with such storage defined
device < unit < player < team < ally-team < world

Converters in a unit are evaluated in the order they are defined.
]]--
If you want to stop charging shields in favor of fully powered weapons, you simply give the unit a storage/puffer for sum(shield+weapon) requirements, let the importer fill the internal energy storage and only convert the internal resource "energy" to internal "shield.charge" if it isn't already depleted by "energy"->"energyForWeapon alias stockpile or fuel" converter.

You are able to control the energy flow/distribution inside the unit
* set the energy importer of the unit to a cooldown of about 15-30 frames and the device energy importers to 5-10 frames cooldown.
* The lower cooldown let them alternately absorb the supply-spike into their device - they will be idle for some time if the spike is absorbed faster than it replenishes.

This makes reload, stockpile, shieldRecharge, fuel and other redundant implementations obsolete and provides a much more flexible solution.

You could easily implement assisting a silo by adding each assister's "workerTime" resource to the silo-unit's "workerTime" storage:

Code: Select all

converters ={
  { cooldown=0, importer=true, input={workerTime=1,metal=1,energy=1}, output={metal=1,energy=1} },
  { cooldown=0, input={workerTime=1}, output={} },
}
Visibility of this improvement

Widgets that make cons assisting silos would be a lot easier.

On estall, units which combine shield+weapons can stop charging their shields in favor of fully powered weapons without additional lua.

Abilities like flying/moving/cloaked can decrease the weapon output or shield recharge
-> Unit is more effective when not moving or uncloaked

Everything is unified
* widgets can still access reload time by getting the converter producing the required stockpile-resource and track down more complex behavior easier than it is with custom lua for each unit.
* see Zero-K's defender where widgets show wrong dps because burst is lua-ed to not waste shots after the target dies.

Finally:
* Helps game devs to balance units
* Makes game more interesting
Last edited by NeonStorm on 01 Apr 2013, 18:01, edited 2 times in total.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Improve unit economy and unitDefs

Post by FLOZi »

tl;dr

Pretty sure units can have multiple stockpile weapons now, though I may be wrong.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

Re: Improve unit economy and unitDefs

Post by Anarchid »

Neon neon is so neon :D
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Improve unit economy and unitDefs

Post by Google_Frog »

Lua.... it?

If you're suggesting a way to write a gadget just write the gadget. Priority control for cloaking and shield charge would be nice but it's not particularly high on my priorities. It would be nice if you did it.

If you're suggesting an engine change then why are you in this forum?

The fact that I can't tell which is which should be a warning sign.
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: Improve unit economy and unitDefs

Post by NeonStorm »

Google> The fact that I can't tell which is which should be a warning sign.

It is - it should become a gadget if the solution is good enough.

I have posted it here, because I would like some feedback or thoughts.


One improvement would be to put
. target = <number: 1> or false,
next to
. importer/exporter = <boolean> or false,

target = import/export from this unit instead of global if importer/exporter = true.
. target = 1:
* on a unit = guarded unit
* on a weapon = attack-target

special cases:
. target = BUILD_TARGET, REPAIR_TARGET, RECLAIM_TARGET, etc
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: Improve unit economy and unitDefs

Post by NeonStorm »

EDIT: Post-version 2.0 :)
Now I will try to find some speed-ups before I implement (or even try) this.


Unconditionally import/export could automatically "register"/"unregister" for the unit's life span.
-> That folds to 1 single step for all wind gens and solars each frame.

priority=SHIELD|WEAPON|... makes a request and these are processed in the order of priorities.
-> Units should be able to forward device requests or requests for a defined resource to a player, and back the success of it up.

Converters with import=true,export=true could be separated into "grantedAbilities".

Continuously converter efficiencies could depend on states, such as "windStrength" or "makerUseage",
* if exporter=true, it would make them an ability.

Abilities of same type can be fold together.



Based on expected supply-over-time, and impact on it, we could further improve it to allow such complex code for many units.

We could even skip some calculations and even fold frames together if it has no impact on the result.
* That depends on the complexity.
* Without any need to configure this behaviour per case ofc.


I hope by thinking about all this, I will see if I am going the right way or have to change something on the basics before going further.
Post Reply

Return to “Lua Scripts”