Files
kiln/kiln-core/src/scripts/pusher.rhai
T

25 lines
1.2 KiB
Plaintext
Raw Normal View History

2026-06-16 14:34:42 -05:00
// Built-in script for the `pusher_*` archetypes (see kiln-core/src/builtin_scripts.rs).
//
// A pusher is a self-propelled solid that advances one cell in its facing
// direction every ~0.5s, shoving any pushable chain (including the player) ahead
// and stopping when blocked. The direction is not baked into this source — every
// pusher shares one compiled copy and learns its direction from the
// `BUILTIN_pusher_<dir>` tag the map loader attached to it.
2026-06-28 00:12:52 -05:00
fn tick(me, state, dt) {
2026-06-16 14:34:42 -05:00
// Only queue a step when idle. `move` shoves the chain ahead via step_object
// and is a no-op when blocked; the delay pads each step out to ~0.5s (move
// itself costs 0.25s), matching the old global pusher heartbeat.
//
// The direction is read here, at the top level of the hook, because `Me` is a
// per-object scope constant and is not visible inside other script functions.
2026-06-28 00:12:52 -05:00
if !me.waiting {
let dir = if me.has_tag("BUILTIN_pusher_north") { North }
else if me.has_tag("BUILTIN_pusher_south") { South }
else if me.has_tag("BUILTIN_pusher_east") { East }
2026-06-16 14:34:42 -05:00
else { West };
move(dir);
delay(0.25);
}
}