Skip to content

Add lua support for creatures returning from abyss - #5185

Merged
Loobinex merged 7 commits into
dkfans:masterfrom
rainlizard:return-from-abyss
Sep 3, 2026
Merged

Add lua support for creatures returning from abyss#5185
Loobinex merged 7 commits into
dkfans:masterfrom
rainlizard:return-from-abyss

Conversation

@rainlizard

@rainlizard rainlizard commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Some people liked my idea of creatures that fall into the abyss being relocated to your portal instead of dying, so here's some lua changes to support that.

  • Adds the CreatureFellIntoAbyss lua event.
  • Teleporting a falling creature will now prevent its default falling death. Using either lua or a creature spell.
  • Adds Creature:remove_from_play(turns) for temporarily placing a creature in limbo. You can use this in any other context (not just for abyss) where you need to take a creature out of play for a while.
function OnGameStart()
    RegisterCreatureFellIntoAbyssEvent(CreatureFellIntoAbyss)
end

function CreatureFellIntoAbyss(event)
    local unit = event.unit
    unit.health = unit.health - 100
    local rooms = GetRoomsOfPlayerAndType(unit.owner, "ENTRANCE")

    if unit.health >= 0 and #rooms > 0 then
        local room = rooms[math.random(#rooms)]
        unit:teleport(room.centerpos, 0)
        unit:remove_from_play(200)
    end
end

In this example I also added 100 falling damage and the creature won't return if it died from the damage taken. But how you use this lua is up to you. Falling can be pretty overpowered:

2026-09-01.15-01-04.mp4

@rainlizard
rainlizard marked this pull request as draft September 1, 2026 05:13
@rainlizard
rainlizard marked this pull request as draft September 2, 2026 12:57
@rainlizard rainlizard changed the title Add rule ReturnFromAbyss Add support for creatures returning from abyss Sep 3, 2026
@rainlizard
rainlizard marked this pull request as ready for review September 3, 2026 14:15
@rainlizard rainlizard changed the title Add support for creatures returning from abyss Add lua support for creatures returning from abyss Sep 3, 2026
@Loobinex
Loobinex merged commit 345d9c5 into dkfans:master Sep 3, 2026
2 checks passed
edorien added a commit to edorien/keeperfx-refactor that referenced this pull request Sep 4, 2026
Same approach as prior syncs: re-apply each upstream change on its
relocated file, preserving state-struct renames and the callback-struct
convention. Commits merged: dkfans#5190 (pathfinding lag behind lava), dkfans#5189
(spawn from entrance center), dkfans#5192/dkfans#5195 (custom-icon script command
fixes), dkfans#5180 (-nick CLI arg), dkfans#5196 (abyss distance log spam fix),
dkfans#5185 (lua support for creatures returning from abyss).

Cross-layer fixups beyond mechanical resolution:

- script_hooks.h (kfx_config): added lua_on_creature_fell_into_abyss
  callback slot. thing_list.c's new abyss-death path called
  lua_on_creature_fell_into_abyss() directly, which would have pulled
  in kfx_script's lua_triggers.h from kfx_sim; routed through
  script_hooks-> instead and wired the real function in main.cpp,
  matching the existing lua_on_creature_death slot right next to it.
- thing_creature.c: the new out-of-play/light-restore branch in
  update_creature() called light_turn_light_on() directly (kfx_render,
  above kfx_sim); changed to sim_feedback->light_turn_light_on(),
  matching the other light call already in this file.
- ariadne_regions.c: dropped the now-dead kfx_config_state.h include
  (added previously only for PLAYERS_COUNT, whose sole consumer
  navigation_regions_connected() moved to ariadne.c and dropped the
  owner-bounds check entirely in this commit).
- creature_states.h/globals.h: kept HEAD's already-completed relocation
  of enum CreatureStates into kfx_platform's globals.h rather than
  restoring the duplicate copy from origin's diff; applied upstream's
  one real change (CrSt_Null84 -> CrSt_CreatureOutOfPlay) there instead.
- room_entrance.c: added the map_columns.h include get_floor_height_at()
  needs now that create_creature_at_entrance() computes floor height
  directly instead of calling the removed
  find_random_valid_position_for_thing_in_room().

Verified with scripts/check_layering.py --strict and a full
KFX_OS=linux build of both keeperfx and keeperfx_hvlog.

Co-authored-by: edorien <317349250+edorien@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants