Module pg2
[hook-sys] Utility for procedurally generating maps of various kinds.
Required hooks: update
.
Functions
Procmap([name]) | Create a new Procmap. |
procmap:setOffset(x[, y]) | Set the base offset for this procmap. |
procmap:setBounds(x0, x1[, y0[, y1]]) | Set an area to restrict chunk loading to. |
procmap:load(cx, cy) | Load a chunk by index. |
procmap:unloadAll() | Unload all currently-loaded chunks. |
procmap:unload(cx, cy) | Unload a chunk by index. |
procmap:loadNearPlayer([loadRadius[, unloadRadius[, probeRadius]]]) | Set the radius for loading and unloading chunks automatically near player ships. |
procmap:maxOperationsPerUpdate(n) | Set the maximum number of chunk load/unload operations per update call for this Procmap. |
procmap:setDebug(on) | Set the debug state for this Procmap. |
DebugZone() | Create a new DebugZone. |
debugZone:setPoints(...) | Set the points for the DebugZone. |
debugZone:setColor(r, g, b) | Set the color for the DebugZone. |
debugZone:setLabel(label) | Set the label for the DebugZone. |
Functions
- Procmap([name])
-
Create a new Procmap.
Procmap derives from
NoisePlane
; all functions exceptsample
may be called directly.Parameters:
- name string The name of the map for GM debug. If not provided, defaults to "Map <n>". (optional)
Returns:
-
The new Procmap instance.
- procmap:setOffset(x[, y])
-
Set the base offset for this procmap.
Parameters:
- x integer The new x offset.
- y
integer
The new y offset. If not specified, defaults to
x
. (optional)
Returns:
-
self
- procmap:setBounds(x0, x1[, y0[, y1]])
-
Set an area to restrict chunk loading to.
Parameters:
- x0 integer The lowest x chunk index to allow loading.
- x1 integer The highest x chunk index to allow loading.
- y0
integer
The lowest y chunk index to allow loading. If not specified, defaults to
x0
. (optional) - y1
integer
The highest y chunk index to allow loading. If not specified, defaults to
x1
. (optional)
Returns:
-
self
- procmap:load(cx, cy)
-
Load a chunk by index.
Parameters:
- cx integer The x index of the chunk to load.
- cy integer The y index of the chunk to load.
Returns:
true
if the chunk was loaded by this call; otherwisefalse
. - procmap:unloadAll()
- Unload all currently-loaded chunks.
- procmap:unload(cx, cy)
-
Unload a chunk by index.
Parameters:
- cx integer The x index of the chunk to unload.
- cy integer The y index of the chunk to unload.
Returns:
true
if the chunk was unloaded by this call; otherwisefalse
. - procmap:loadNearPlayer([loadRadius[, unloadRadius[, probeRadius]]])
-
Set the radius for loading and unloading chunks automatically near player ships.
The default for a newly constructed Procmap is equivalent to passing
nil
for all parameters.Parameters:
- loadRadius integer The radius beyond a player ship's long-range radar to load chunks, or nil to not load chunks around player ships. (optional)
- unloadRadius integer The radius beyond a player ship's long-range radar to unload chunks, or nil to not unload chunks automatically. (optional)
- probeRadius
integer
The radius beyond a probe's radar range to load chunks. If nil, defaults to
loadRadius
. (optional)
- procmap:maxOperationsPerUpdate(n)
-
Set the maximum number of chunk load/unload operations per update call for this Procmap.
This maximum is converted into a cost per update and shared between all Procmap instances; in case of insufficient update budget, earlier instances take priority.
Parameters:
- n number The maximum number of load/unload operations per update call.
- procmap:setDebug(on)
-
Set the debug state for this Procmap.
Parameters:
- on boolean Whether debug should be enabled.
- DebugZone()
- Create a new DebugZone. DebugZone works like Zone, but is only visible when its containing Procmap's debug flag is enabled.
- debugZone:setPoints(...)
-
Set the points for the DebugZone.
Parameters:
- ... The points for the zone, as Zone:setPoints(...)
Returns:
-
self
- debugZone:setColor(r, g, b)
-
Set the color for the DebugZone.
Parameters:
- r number The amount of red.
- g number The amount of green.
- b number The amount of blue.
Returns:
-
self
- debugZone:setLabel(label)
-
Set the label for the DebugZone.
Parameters:
- label string The text label for the zone.
Returns:
-
self