test / test (push) Failing after 11m56s
- strata_core/liquids.lua: strata.register_liquid; water and lava as leveled nodeboxes (level 1..64 in param2) moved by a cellular sim on z = 0 only: react (lava + water = ashglass), fall up to 3 rows, share level with lower side neighbours. Active-set driven; cells wake on place/dig next to them, neighbour changes and block load (LBM). - Buckets: empty, water and lava (3 iron bars at an anvil). - Mapgen: cave pools resting on a solid floor, water in the upper three layers, lava in the underworld (mg.pool_liquid). - strata_player/swim.lua: liquid physics for the avatar (slower walk, reduced gravity, sink cap, hold jump to swim, surface hop), own breath with a HUD bubble bar, drowning and lava damage; liquids break falls. - Placeholder textures for water, lava, ashglass, buckets and bubbles. - 8 new selftest cases; layer tests treat liquid as open cave. Closes #22 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
4.3 KiB
Lua
121 lines
4.3 KiB
Lua
-- Strata building blocks: one-way platforms (doors and chests live in
|
|
-- furniture.lua).
|
|
--
|
|
-- Platforms are non-walkable for the engine. Entities that should stand on
|
|
-- them (the avatar, creatures) call strata.platform_landing() each step and
|
|
-- hold themselves on the platform's top; see strata_player for the avatar
|
|
-- side, including dropping through with S.
|
|
|
|
local S = strata.S
|
|
local PLANE_Z = strata.PLANE_Z
|
|
|
|
local PLATFORM_THICKNESS = 0.1875 -- 3 px of a 16 px tile
|
|
local LANDING_EPS = 0.05 -- feet this far above a top still count as on it
|
|
|
|
--------------------------------------------------------------------------
|
|
-- Shared helpers
|
|
--------------------------------------------------------------------------
|
|
|
|
--- Physical Strata entities (avatars, creatures) whose collision box
|
|
-- overlaps the node cell at pos. Returns a list of ObjectRefs. Visual-only
|
|
-- entities such as the held item don't count.
|
|
function strata.objects_in_cell(pos)
|
|
local found = {}
|
|
for _, obj in ipairs(core.get_objects_inside_radius(pos, 2)) do
|
|
local ent = obj:get_luaentity()
|
|
local props = ent and ent.name:find("^strata_") and obj:get_properties()
|
|
if props and props.physical then
|
|
local cb = props.collisionbox
|
|
local op = obj:get_pos()
|
|
if op.x + cb[1] < pos.x + 0.5 and op.x + cb[4] > pos.x - 0.5
|
|
and op.y + cb[2] < pos.y + 0.5 and op.y + cb[5] > pos.y - 0.5
|
|
and op.z + cb[3] < pos.z + 0.5 and op.z + cb[6] > pos.z - 0.5 then
|
|
found[#found + 1] = obj
|
|
end
|
|
end
|
|
end
|
|
return found
|
|
end
|
|
|
|
--------------------------------------------------------------------------
|
|
-- One-way platforms
|
|
--------------------------------------------------------------------------
|
|
|
|
--- Register a one-way platform node.
|
|
function strata.register_platform(name, def)
|
|
core.register_node(name, {
|
|
description = def.description,
|
|
tiles = {def.texture},
|
|
use_texture_alpha = "clip",
|
|
drawtype = "nodebox",
|
|
paramtype = "light",
|
|
sunlight_propagates = true,
|
|
walkable = false,
|
|
node_box = {type = "fixed", fixed = {-0.5, 0.5 - PLATFORM_THICKNESS, -0.5, 0.5, 0.5, 0.5}},
|
|
-- full-cell selection so the thin strip is easy to aim at
|
|
selection_box = {type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}},
|
|
groups = {choppy = 3, platform = 1},
|
|
})
|
|
end
|
|
|
|
--- Find a platform an entity lands on.
|
|
-- x0..x1 is the entity's horizontal extent; its feet moved from y_from to
|
|
-- y_to this step. Returns the y of the highest platform top crossed, or nil.
|
|
-- Only platforms on the gameplay plane count.
|
|
function strata.platform_landing(x0, x1, y_from, y_to)
|
|
if y_to > y_from + LANDING_EPS then
|
|
return nil -- moving up: platforms let you through
|
|
end
|
|
local n_hi = math.floor(y_from + LANDING_EPS - 0.5)
|
|
local n_lo = math.ceil(y_to - 0.5)
|
|
local c0, c1 = math.floor(x0 + 0.51), math.floor(x1 + 0.49)
|
|
for ny = n_hi, n_lo, -1 do
|
|
for nx = c0, c1 do
|
|
local node = core.get_node({x = nx, y = ny, z = PLANE_Z})
|
|
if core.get_item_group(node.name, "platform") > 0 then
|
|
return ny + 0.5
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
--- Run one step of platform physics for a physical entity.
|
|
-- box is its collision box, vel its velocity this step (modified in place),
|
|
-- gravity its downward acceleration. Pass ignore = true while dropping
|
|
-- through. Returns true if the entity is standing on a platform. The caller
|
|
-- must call strata.platform_support() once it has settled vel.
|
|
function strata.platform_step(self, pos, vel, box, ignore)
|
|
local feet = pos.y + box[2]
|
|
local prev = self._prev_feet
|
|
self._prev_feet = feet
|
|
if ignore or not prev or vel.y > 0 then
|
|
return false
|
|
end
|
|
local top = strata.platform_landing(pos.x + box[1], pos.x + box[4], prev, feet)
|
|
if not top then
|
|
return false
|
|
end
|
|
if math.abs(feet - top) > 1e-3 then
|
|
pos.y = top - box[2]
|
|
self.object:set_pos(pos)
|
|
end
|
|
self._prev_feet = top
|
|
vel.y = 0
|
|
return true
|
|
end
|
|
|
|
--- Switch gravity off while an entity rests on a platform (so it doesn't
|
|
-- sink between steps) and back on otherwise.
|
|
function strata.platform_support(self, supported, gravity)
|
|
if self._supported ~= supported or self._gravity ~= gravity then
|
|
self._supported = supported
|
|
self._gravity = gravity
|
|
self.object:set_acceleration({x = 0, y = supported and 0 or -gravity, z = 0})
|
|
end
|
|
end
|
|
|
|
strata.register_platform("strata_core:platform_wood", {
|
|
description = S("Wood Platform"),
|
|
texture = "strata_platform_wood.png",
|
|
})
|