A tool to place objects and keep track of channels & rift IDs more easily. Objects are allocating in the order of (relay) execution. Can overwrite existing stuff with some settings.
allocator = require("tools.allocator"):new(level,settings)
level
: the level to allocate stuff insettings
: a table of the settings:immediate
: whether the allocator should place objects immediately upon allocation, or wait untilallocator:finalize()
. Default isfalse
.size
: table containing the size of the area in which things should be allocated in the format{width,height}
. Use together withsetTopLeftCorner()
to limit the allocator to a specific area. Default is the size oflevel
.objectMask
: whether the allocator should have a mask that limits where objects can be placed. Required for area allocation. SeegetObjectMask()
for more info. Defaults tofalse
channelMask
: whether the allocator should have a mask that limits which channels can be used. SeegetChannelMask()
for more info. Defaults tofalse
riftIdMask
: whether the allocator should have a mask that limits which rift IDs can be used. SeegetRiftIdMask()
for more info. Defaults tofalse
preScan
: whether to automatically scan the level and mask away anything already used. Does not properly work with objects bigger than 1x1 due to data that still needs to be collected. (Objects bigger than 1x1 will not get masked off completely, causing overlap, causing undefined behaviour in Levelhead.) Defaults tofalse
.scanBgObjects
: whether to also scan background objects when scanning for the mask. Defaults totrue
.
relay = allocator:allocateRelay(receivingChannel, switchRequirements, sendingChannel)
Allocates a relay and returns the allocated object. Function arguments correspond to their in-game properties.
rift = allocator:allocateRift(riftId, receivingChannel, switchRequirements, destinationRiftId)
Allocates a rift and returns the allocated object. Function arguments correspond to their in-game properties.
obj = allocator:allocateObject(elementOrObject)
elementOrObject
: the name or id of the level element to allocate, or an existing objectobj
: an object that the allocator will make sure gets placed somewhere
channel = allocator:allocateChannel()
channels = allocator:allocateChannels(n)
channel
: a new unused channelchannels
: a table containingn
distinct unused channels
id = allocator:allocateRiftId()
ids = allocator:allocateRiftIds(n)
id
: a new unused rift idids
: a table containingn
distinct unused rift ids
area = allocator:allocateArea(width, height)
width, height
: the size fo the area to allocatearea
: an allocator limited to the specified area
An objectMask
is required for to prevent an area getting used for multiple things simultaneously.
There're no guarantees about the order in which areas are allocated, relating to objects and each other.
ralloc, calloc, idalloc = allocator:getShortcuts()
ralloc
: a wrapper aroundallocator:allocateRelay()
so you don't have to reference the allocator every timecalloc
: a wrapper aroundallocator:allocateChannel()
so you don't have to reference the allocator every timeridalloc
: a wrapper aroundallocator:allocateRiftId()
so you don't have to reference the allocator every time
allocator:finalize()
Actually places all objects when the immediate
setting is off/false, errors otherwise.
mask = allocator:getObjectMask()
mask
: (a reference to) the Bitplane masking where the allocator can place objects
Set a position to false
to block it off from the allocator. All spaces default to true
.
cmask = allocator:getChannelMask()
cmask
: (a reference to) the table masking which channels can be used by the allocator.
Channels are the keys in the tables.
Set one to false
to block it off from the allocator. The tables default to all true
.
ridmask = allocator:getRiftIdMask()
ridmask
: (a reference to) the table masking which rift IDs can be used by the allocator.
Rift IDs are the keys in the tables.
Set one to false
to block it off from the allocator. The tables default to all true
.
allocator:setTopLeftCorner(x, y)
x, y
: the position of the top-left corner (inclusive)
Sets the top-left corner of the area in which things can be allocated.
Use together with the size
setting to limit the allocator to a specific area.
x, y = allocator:getTopLeftCorner()
x, y
: the position of the top-left corner (inclusive)
Returns the top-left corner of the area in which things can be allocated.
width, height = allocator:getSize()
wdith, height
: the size of the area in which things can be allocated.