User:Flozi: Difference between revisions

From Spring
Jump to navigationJump to search
Flozi (talk | contribs)
Flozi (talk | contribs)
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= LUS Script Examples =
= My User Subpages =  
{{Special:PrefixIndex/User:Flozi/}}


== How to use ==
= Scratchpad =
* <code>FIXME</code> - Indicates a section of code you will need to tweak to suit your own unit / model
* <code>TODO</code> - Indicates an optional section of code is missing that you may wish to pad out e.g. with an animation


== Script Scaffolds ==
== Template:API proposal ==
=== Builder ===
Note that the number of 'arg1' etc is fixed (i.e. 10) but can be omitted without issue. the 'type' template is just a way to make inserting different styles within the param list easier, [[Template:Pipe]] already exists and is required as it is a special char within mediawiki syntax, could use <nowiki>{{!}}</nowiki> as a shorter alternative to pipe.
<code><pre>
<pre>
local nanoPieces = {}
{{API <!-- Callout example -->
-- FIXME: this example has 2 nano pieces to alternate between
|prefix = Spring
for i = 1, 2 do
|name = UseTeamResource
    -- FIXME: the pieces are named nanoPiece1 and nanoPiece2 in the model
|arg1 = {{type|number}} teamID
    nanoPieces[i] = piece("nanoPiece" .. i)
|arg2 = {{type|string}} "metal" {{pipe}} "energy"
end
|arg3 = {{type|number}} amount {{pipe}} { metal = {{type|number}} amount, energy = {{type|number}} amount }
Spring.SetUnitNanoPieces(unitID, nanoPieces)
|output = {{type|nil}} {{pipe}} {{type|bool}} hadEnough
 
|info = Imposes a one-off usage of resources on the given team. The return value indicates whether or not the team had sufficient resources to meet the usage demand.
function script.StartBuilding(heading, pitch)
}}</pre>
    -- TODO: This is where you would add your unpack / point towards animation
    SetUnitValue(COB.INBUILDSTANCE, 1)
end
function script.StopBuilding()
    -- TODO: This is where you would add your pack-up animation
    SetUnitValue(COB.INBUILDSTANCE, 0)
end
</pre></code>
 
=== Factory ===
<code><pre>
local nanoPieces = {}
-- FIXME: this example has 2 nano pieces to alternate between
for i = 1, 2 do
    -- FIXME: the pieces are named nanoPiece1 and nanoPiece2 in the model
    nanoPieces[i] = piece("nanoPiece" .. i)
end
Spring.SetUnitNanoPieces(unitID, nanoPieces)
 
function script.QueryBuildInfo()
    -- FIXME: the pad piece is named buildPad in the model
    return piece("buildPad")
end
 
local function OpenCloseAnim(open)
    Signal(1) -- Kill any other copies of this thread
    SetSignalMask(1) -- Allow this thread to be killed by fresh copies
    if open then
        -- TODO: This is where you would add your opening up anim
    else
        -- TODO: This is where you would add your closing up anim
    end
    SetUnitValue(COB.INBUILDSTANCE, open and 1 or 0)
    SetUnitValue(COB.BUGGER_OFF, open and 1 or 0)
end
 
-- Called when factory yard opens
function script.Activate()
    -- OpenCloseAnim must be threaded to call Sleep() or WaitFor functions
    StartThread(OpenCloseAnim, true)
end
 
-- Called when factory yard closes
function script.Deactivate()
    -- OpenCloseAnim must be threaded to call Sleep() or WaitFor functions
    StartThread(OpenCloseAnim, false)
end
 
function script.StartBuilding()
    -- TODO: You can run any animation that continues throughout the build process here e.g. spin pad
end
 
function script.StopBuilding()
    -- TODO: You can run any animation that signifies the end of the build process here
end
</pre></code>
 
=== Wind Generator ===
<code><pre>
-- FIXME: Assumes model has pieces named 'tower' and 'blades'
local tower, blades = piece("tower", "blades")
 
function script.WindChanged (number heading, number strength)
  -- Turn the tower to face the wind at 30deg/s
  Turn(tower, y_axis, heading, math.rad(30))
  -- Spin the turbine blades relative to wind strength
  -- FIXME: Here I set rotational speed to half of strength
  Spin(blades, z_axis, strength * 0.5)
end
</pre></code>
 
<hr/>
= Template:LuaCallout Examples =


{{prefix|Spring.}}{{name|[[#UseTeamResource|UseTeamResource]]}}{{var|1=({{type|number}} teamID, {{type|string}} {{value|"metal"}} {{pipe}} {{value|"energy"}}, {{type|number}} amount {{pipe}} { metal = {{type|number}} amount, energy = {{type|number}} amount })}}


{{LuaCallout
{{var|-> {{type|nil}} {{pipe}} {{type|bool}} hadEnough}}
|parent = Spring
|name = UseTeamResource
|params = number teamID, <br/> string "metal" {{pipe}} "energy", number amount {{pipe}} <br/> { metal = number amount, energy = number amount }
|return = nil {{pipe}} bool hadEnough
|description = Imposes a one-off usage of resources on the given team. The return value indicates whether or not the team had sufficient resources to meet the usage demand.}}
<hr/>


= Lua Callins =
:Deduct the specified amount from the team's metal or energy resource.
== Common ==
{{LuaCallin
|addon = addon
|name = Initialize
|params =
|return = none
|description = Called when the addon is (re)loaded.
}}


{{LuaCallin
{{prefix|Spring.}}{{name|CreateUnit}}{{var|1=( {{type|string}} "defName" {{pipe}} number unitDefID, {{type|number}} x, {{type|number}} y, {{type|number z}},
|addon = addon
({{type|number}} facing {{pipe}} {{type|string}} "facing"),
|name = Shutdown
{{type|number}} teamID
|params =  
[, {{type|boolean}} build = {{value|false}}]
|return = none
[, {{type|boolean}} flattenGround = {{value|true}}]
|description = Called when the addon or the game is shutdown.
[, {{type|number}} unitID]
}}
[, {{type|number}} builderID ])}}


{{var|-> {{type|number}} unitID {{pipe}} {{type|nil}}}}


== Unsynced Only ==
<pre>
{{LuaCallin
{{API <!-- Callin example -->
|addon = addon
|prefix = addon <!-- May use gadget: instead? -->
|name = DrawWorldPreUnit
|name = AllowUnitTransfer
|params =  
|arg1 = {{type|number}} unitID
|return = none
|arg2 = {{type|number}} unitDefID
|description = Spring draws units, features, some water types, cloaked units, and the sun.
|arg3 = {{type|number}} oldTeam
}}
|arg4 = {{type|number}} newTeam
|arg5 = {{type|bool}} capture
|return = {{type|bool}} allow <!-- note that this is a different entry than output above -->
|info = Called just before a unit is transferred to a different team, the boolean return value determines whether or not the transfer is permitted.
}}</pre>




== Synced - Unsynced Shared ==
{{prefix|addon.}}{{name|AllowUnitTransfer}}{{var|1=({{type|number}} unitID, {{type|number}} unitDefID, {{type|number}} oldTeam,
{{LuaCallin
{{type|number}} newTeam, {{type|bool}} capture)}}
|addon = addon
|name = PlayerChanged
|params = number playerID
|return = none
|description = Called whenever a player's status changes e.g. becoming a spectator.
}}


return: {{var|{{type|bool}} allow}}


== Synced Only ==
:Called just before a unit is transferred to a different team, the boolean return value determines whether or not the transfer is permitted.
{{LuaCallin
|addon = addon
|name = AllowUnitCreation
|params = number unitDefID, number builderID, number builderTeam, <br/> number x, number y, number z, number facing
|return = bool allow
|description = Called just before unit is created, the boolean return value determines whether or not the creation is permitted.
}}


=== Using syntaxhighlight instead ===


<hr/>
<syntaxhighlight lang="c">Spring.CreateUnit // offmap positions are clamped! (you still can use MoveCtrl todo so)
( string "defName" | int unitDefID,
  int x, int y, int z,
  (int facing | string "facing"),
  int teamID
  [, bool build = false]
  [, bool flattenGround = true]
  [, int unitID]
  [, int builderID]) -> int unitID | nil</syntaxhighlight>


= TODO: =
= TODO: =


Continue to improve [[Gamedev:Main]]
==Major==
 
* [[:Category:ShowCase]] template, main page, S44 & MCL as examples
[[Assimp]] build upon, metadata doc, split tutorial again >_>
* [[:Category:Tutorial]]
 
* Continue to improve [[Lua:Callins]] - Fill in blank explanations
Revamp [[LuaCallinReturn]]
* Clickable / right-click copy paste-able anchors in <nowiki>{{tag}}</nowiki> et al
 
* [[Assimp]] build upon, metadata doc, split tutorial again >_>
Page on spring wiki etiquette ([[SpringWiki]]) / style guide & template usage ([[Mapdev:WikiGuide]]) /namespace conventions ([[Spring:PageNamingConventions]]) - pages are good already; put these in revamped community portal?
* Cleanup old [[:Category:Map_making]] into new [[:Category:Map Dev]]


Move all pages in [http://springrts.com/mediawiki/index.php?title=Special%3APrefixIndex&prefix=Animation-&namespace=0 Animation-] to [http://springrts.com/mediawiki/index.php?title=Special%3APrefixIndex&prefix=Animation%3A&namespace=0 Animation:]
==Minor==
* Page on spring wiki etiquette ([[SpringWiki]]) / style guide & template usage ([[Mapdev:WikiGuide]]) /namespace conventions ([[Spring:PageNamingConventions]]) - pages are good already; put these in revamped community portal?
* Move all pages in [http://springrts.com/mediawiki/index.php?title=Special%3APrefixIndex&prefix=Animation-&namespace=0 Animation-] to [http://springrts.com/mediawiki/index.php?title=Special%3APrefixIndex&prefix=Animation%3A&namespace=0 Animation:]
* Continue to improve [[Gamedev:Main]] up to the high standard of [[Mapdev:Main]]


Clickable / right-click copy pasteable anchors in <nowiki>{{tag}}</nowiki> et al
==Undocumented Features==
* cmdcolors.txt (c.f. {{forumlink|topic=7099|title=GUI modifications in SVN}})
* ctrlpanel.txt (c.f. as above)
* isolated mode (isolated.txt 99+ c.f. {{forumlink|topic=26359|title=portable/isolation mode}}, [http://springrts.com/dl/buildbot/default/master/99.0/manpages/spring.6.html Spring manpages])

Latest revision as of 19:26, 28 March 2020

My User Subpages

Scratchpad

Template:API proposal

Note that the number of 'arg1' etc is fixed (i.e. 10) but can be omitted without issue. the 'type' template is just a way to make inserting different styles within the param list easier, Template:Pipe already exists and is required as it is a special char within mediawiki syntax, could use {{!}} as a shorter alternative to pipe.

{{API <!-- Callout example -->
|prefix = Spring
|name = UseTeamResource
|arg1 = {{type|number}} teamID
|arg2 = {{type|string}} "metal" {{pipe}} "energy"
|arg3 = {{type|number}} amount {{pipe}} { metal = {{type|number}} amount, energy = {{type|number}} amount }
|output = {{type|nil}} {{pipe}} {{type|bool}} hadEnough
|info = Imposes a one-off usage of resources on the given team. The return value indicates whether or not the team had sufficient resources to meet the usage demand.
}}

Spring.UseTeamResource(number teamID, string "metal" | "energy", number amount | { metal = number amount, energy = number amount })

-> nil | bool hadEnough

Deduct the specified amount from the team's metal or energy resource.

Spring.CreateUnit( string "defName" | number unitDefID, number x, number y, number z, (number facing | string "facing"), number teamID [, boolean build = false] [, boolean flattenGround = true] [, number unitID] [, number builderID ])

-> number unitID | nil

{{API <!-- Callin example -->
|prefix = addon <!-- May use gadget: instead? -->
|name = AllowUnitTransfer
|arg1 = {{type|number}} unitID
|arg2 = {{type|number}} unitDefID
|arg3 = {{type|number}} oldTeam
|arg4 = {{type|number}} newTeam
|arg5 = {{type|bool}} capture
|return = {{type|bool}} allow <!-- note that this is a different entry than output above -->
|info = Called just before a unit is transferred to a different team, the boolean return value determines whether or not the transfer is permitted.
}}


addon.AllowUnitTransfer(number unitID, number unitDefID, number oldTeam, number newTeam, bool capture)

return: bool allow

Called just before a unit is transferred to a different team, the boolean return value determines whether or not the transfer is permitted.

Using syntaxhighlight instead

<syntaxhighlight lang="c">Spring.CreateUnit // offmap positions are clamped! (you still can use MoveCtrl todo so)

( string "defName" | int unitDefID,
  int x, int y, int z,
  (int facing | string "facing"),
  int teamID
  [, bool build = false] 
  [, bool flattenGround = true]
  [, int unitID]
  [, int builderID]) -> int unitID | nil</syntaxhighlight>

TODO:

Major

Minor

Undocumented Features