User:Flozi/EngineSupportedResources

From Spring

A little scrapbook of (incomplete) ideas - purely from a game dev, not engine dev perspective - about how engine-supported multiple resources might look. Realistically, such support would be a huge undertaking and probably not worth the effort seen as most of this can already be done purely through lua, and the 2 engine 'hardcoded' resources are flexible enough to be used in various ways (c.f. S44 & MCL). Backwards compatibility would also be a maintenance nightmare.

Lua SyncedRead

Spring.GetTeamResources

( number teamID, string resourceName ) -> 

nil | number currentLevel,

        number storage,
        number pull,
        number income,
        number expense,
        number share,
        number sent,
        number received

Spring.GetTeamResourceStats

( number teamID,  string resourceName ) ->
  nil | number used,
        number produced,
        number excessed,
        number received,
        number sent

Spring.GetUnitResources

( number unitID ) -> nil | {make = {metal = 1.0, ...}, uses = {energy = 5.0, ...}}

Spring.GetUnitHarvestStorage

( number unitID ) -> nil | {coal = 50, gold = 2 ...}

Lua SyncedCtrl

Team

Spring.AddTeamResource

( number teamID, string resourceName, number amount ) -> nil
( number teamID, { ["metal"] = amount, ... } ) -> nil

Spring.UseTeamResource

( number teamID, 
  string resourceName, number amount |
  { ["metal"] = number amount, ...}
) -> nil | boolean hadEnough

Spring.SetTeamResource

( number teamID, string resourceName, number amount, bool storage = false ) -> nil

Spring.SetTeamShareLevel

( number teamID, string resourceName, number amount ) -> nil

Spring.ShareTeamResource

( number teamID_src, number teamID_recv, string resourceName, number amount ) -> nil

Unit

Spring.SetUnitResourcing

( number unitID,
  string resourceName, bool conditional, number amount |
  { ["metal"] = number amount, ... }
) -> nil

Spring.AddUnitResource

( number unitID, string resourceName, number amount ) -> nil
( number unitID, { ["metal"] = amount, ... } ) -> nil

Spring.UseUnitResource

( number unitID, string resourceName, number amount ) -> nil | boolean okay
( number unitID, { ["metal"] = amount, ... } ) -> nil | boolean okay

Spring.SetUnitHarvestStorage

( number unitid, string resourceName, number amount )
( number unitID, { ["metal"] = amount, ... } ) -> nil


Unit/FeatureDefs

 1 resources = {
 2 	cost = { -- features only support this, used for reclamation values
 3 		metal = 50,
 4 		energy = 130,
 5 		coal = 100,
 6 	},
 7 	makes = {
 8 		metal = 1.0,
 9 	},
10 	uses = {
11 		energy = 5.0,
12 	},
13 	extracts = {
14 		metal = {radius = 5.0, amount = 1.0},
15 		coal = {radius = 10.0, amount = 5.0},
16 	},
17 	generates = {
18 		wind = {energy = 25},
19 		tidal = {gold = 5}, -- panning or something, w/e it is an example!
20 	},
21 	storage = {
22 		metal = 50,
23 		harvest = 100, -- a single harvestStorage or per-resource?
24 	},
25 }

Gamedata/Resources.lua

Old one is renamed to Textures.lua or equivalent

return {
	metal = {
		extractable = true, -- all resources can be extractable, 
				    --  but for now only from the current single 'metal map'
	},
	energy = {
		tidal = true,
		wind = true,
	},
	gold = {
		harvestable = true, -- only resources which have this set can fill a units harvestStorage 
				    -- when reclaimed from a unit or feature
		tidal = true,
	},
	coal = {
		extractable = true,
		harvestable = true,
	},
}