Curation round 10: combat, pathfinding, death and game over, items and stats, room state, Continue, Lua callbacks

Seven agents took over tear and contact collision, NPC death with blood and gibs, champions, PathFinder, the Gaper's
kin, the player's death with the game over screen, item pedestals with collectible pickup, AddCollectible and
EvaluateItems, room state save and restore, GameState::read, pressure plates, fireplaces, entity lights, ambient
sounds, and one Lua callback enum with gated runners. Integration reconstructed Room::Update's loot preview and
Entity_NPC::UpdatePickupGhosts and replaced a leftover Sacred Orb stub that stopped every pedestal roll.
Under gdb: Gapers die with blood and gibs, a cleared room opens its doors, the treasure room's item is taken (banner,
costume, stats: a Magic Mushroom gives damage 3.5 -> 6.12 and a heart), death leads to the game over diary, and a saved
run is read back on the next boot with Continue offered. 3028 functions taken over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-20 09:55:14 -05:00
1 parent 48933cd312
commit d8385e6c64
64 files changed
+8665 -3059

No files matched your search

+45 -49
View File
@@ -1,14 +1,17 @@
#pragma once
#include "lua_callbacks.h"
#include <array>
#include <bitset>
#include <cstdint>
#include <list>
#include <optional>
#include <string>
#include <string_view>
struct Entity;
struct Entity_Bomb;
struct Entity_Effect;
struct Entity_Familiar;
struct Entity_Knife;
struct Entity_NPC;
@@ -16,45 +19,23 @@ struct Entity_Pickup;
struct Entity_Player;
struct Entity_Projectile;
struct Entity_Tear;
struct EntitySpawn;
struct RNG;
struct Vector;
struct lua_State;
constexpr int LUA_CALLBACK_COUNT = 74;
constexpr int LUA_GC_HISTORY_SIZE = 10;
constexpr int LUA_GC_STEP_MIN = 50;
constexpr int LUA_MEMORY_HISTORY_SIZE = 128;
// Lua's LUA_NOREF: a registry reference to nothing.
constexpr int LUA_REF_NONE = -2;
// The built-in callbacks the game runs mods' functions for, by their ModCallbacks ids in enums.lua.
enum LuaCallback
{
MC_POST_RENDER = 2,
MC_USE_ITEM = 3,
MC_EVALUATE_CACHE = 8,
MC_POST_PLAYER_INIT = 9,
MC_USE_PILL = 10,
MC_POST_GAME_STARTED = 15,
MC_POST_NEW_LEVEL = 18,
MC_POST_NEW_ROOM = 19,
MC_PRE_FAMILIAR_COLLISION = 26,
MC_PRE_NPC_COLLISION = 30,
MC_PRE_PLAYER_COLLISION = 33,
MC_PRE_PICKUP_COLLISION = 38,
MC_PRE_TEAR_COLLISION = 42,
MC_PRE_PROJECTILE_COLLISION = 46,
MC_POST_KNIFE_INIT = 50,
MC_PRE_KNIFE_COLLISION = 53,
MC_PRE_BOMB_COLLISION = 60,
MC_GET_PILL_EFFECT = 65,
MC_POST_ENTITY_KILL = 68
};
// The game classes callbacks hand objects of to Lua, each with the registry key of the metatable the API gives it.
enum LuaClass
{
LUA_CLASS_ENTITY,
LUA_CLASS_BOMB,
LUA_CLASS_EFFECT,
LUA_CLASS_FAMILIAR,
LUA_CLASS_KNIFE,
LUA_CLASS_NPC,
@@ -63,6 +44,7 @@ enum LuaClass
LUA_CLASS_PROJECTILE,
LUA_CLASS_RNG,
LUA_CLASS_TEAR,
LUA_CLASS_VECTOR,
LUA_CLASS_COUNT
};
@@ -73,14 +55,6 @@ enum LuaMode
LUA_MODE_DEBUG
};
// What a callback returned that can be true, false or nothing, as the game's Pre*Collision checks read it.
enum LuaResult
{
LUA_RESULT_FALSE = -1,
LUA_RESULT_NIL,
LUA_RESULT_TRUE
};
// A mod a script registered with RegisterMod, kept until that script runs again or Lua resets.
struct LuaMod
{
@@ -91,19 +65,6 @@ struct LuaMod
int tableRef = LUA_REF_NONE;
};
// An active item's use as MC_USE_ITEM sees it. A table result sets isDischarge and isRemove when it has their keys.
struct LuaItemUse
{
Entity_Player* player = nullptr;
RNG* rng = nullptr;
int activeSlot = 0;
int collectibleType = 0;
int customVarData = 0;
unsigned int useFlags = 0;
bool isDischarge = false;
bool isRemove = false;
};
// The mod scripting host: the Lua 5.3 state, the game's scripts in resources/scripts/, the mods scripts register, and
// the entry points that run mods' callbacks. A callback runs only while enabledCallbacks has its id, which the API's
// SetBuiltInCallbackState sets once a mod adds a function for it. Lua errors are logged, never fatal.
@@ -146,18 +107,53 @@ struct LuaEngine
LuaResult PreProjectileCollision(Entity_Projectile* projectile, Entity* collider, bool isLow);
LuaResult PreTearCollision(Entity_Tear* tear, Entity* collider, bool isLow);
void EvaluateItems(Entity_Player* player, int cacheFlag);
int GetCard(const LuaCardDraw& draw);
int GetPillColor(uint32_t seed);
int GetPillEffect(int pillEffect, int pillColor);
int GetTrinket(int trinket, const RNG& rng);
std::optional<bool> InputAction(Entity* entity, int hook, int action);
int PostCurseEval(int curses);
int PostGetCollectible(const LuaCollectibleDraw& draw);
int PreGetCollectible(const LuaCollectibleDraw& draw);
bool PreNPCUpdate(Entity_NPC* npc);
void Callback_PreEntitySpawn(EntitySpawn& spawn);
void PostPickupSelection(Entity_Pickup* pickup, int& variant, int& subType);
bool UseItem(LuaItemUse& use);
void EvaluateItems(Entity_Player* player, int cacheFlag);
void PostEffectInit(Entity_Effect* effect);
void PostEffectRender(Entity_Effect* effect, const Vector& offset);
void PostEffectUpdate(Entity_Effect* effect);
void PostEntityKill(Entity* entity);
void PostEntityRemove(Entity* entity);
void PostFireTear(Entity_Tear* tear);
void PostGameStart(bool isContinued);
void PostKnifeInit(Entity_Knife* knife);
void PostNewLevel();
void PostNewRoom();
void PostNPCDeath(Entity_NPC* npc);
void PostNPCInit(Entity_NPC* npc);
void PostNPCRender(Entity_NPC* npc, const Vector& offset);
void PostNPCUpdate(Entity_NPC* npc);
void PostPickupInit(Entity_Pickup* pickup);
void PostPickupRender(Entity_Pickup* pickup, const Vector& offset);
void PostPickupUpdate(Entity_Pickup* pickup);
void PostPlayerInit(Entity_Player* player);
void PostRender();
bool UseItem(LuaItemUse& use);
void PostTearInit(Entity_Tear* tear);
void PostTearRender(Entity_Tear* tear, const Vector& offset);
void PostTearUpdate(Entity_Tear* tear);
void PostUpdate();
void UsePill(int pillEffect, Entity_Player* player, unsigned int useFlags);
};
extern void* g_luaEngine;
const void* lua_class_key(LuaClass luaClass);
void lua_callback_check(int callback, const char* name);
void lua_error_log(lua_State* state, const char* name);
// The game's Lua engine, which Manager creates at startup.
inline LuaEngine& lua_engine_get()
{
return *static_cast<LuaEngine*>(g_luaEngine);
}