Curation round 16: Mom's Knife and the bone club, sin minibosses and death rewards, slots and beggars, NPC rendering and twelve bosses, alt path visuals, the Forgotten's flight and tainted HUDs, Sheol and the Cathedral to the credits, familiars and transformations

This commit is contained in:
shweet committed 2026-11-20 22:44:36 -05:00
1 parent 76c594f9a0
commit e9de039d0f
151 files changed
+14996 -5208

No files matched your search

+166
View File
@@ -0,0 +1,166 @@
#include "room_path.h"
#include "game.h"
#include "grid_entity_pit.h"
#include "grid_entity_teleporter.h"
#include "log.h"
#include <algorithm>
#include <cmath>
#include <set>
constexpr int PATH_NEIGHBORS_MAX = 32;
constexpr int PATH_CARVE_COST = 448;
constexpr int PATH_BLOCKED = 1000;
constexpr float PATH_HEURISTIC_SCALE = 10;
constexpr uint16_t PATH_NO_CELL = 0xffff;
// The obstacles a carving search may cross and break: the rocks but blocks and pillars, and the pits it fills.
static bool is_carvable(GridEntityType type)
{
switch (type)
{
case GRID_ROCK:
case GRID_ROCKT:
case GRID_ROCK_BOMB:
case GRID_ROCK_ALT:
case GRID_ROCK_SS:
case GRID_ROCK_SPIKED:
case GRID_ROCK_ALT2:
case GRID_ROCK_GOLD:
case GRID_PIT:
return true;
default:
return false;
}
}
// The distance from a cell to the goal in cells, ten times over, as the search's estimate.
static uint32_t path_estimate(const Room& room, int cell, int goal)
{
float columns = (float)(goal % room.gridWidth) - (float)(cell % room.gridWidth);
float rows = (float)(goal / room.gridWidth) - (float)(cell / room.gridWidth);
return (uint32_t)(std::sqrt(rows * rows + columns * columns) * PATH_HEURISTIC_SCALE);
}
// The cells a search steps to from one: left, right, up and down, then the other teleporters of the variant of a
// working teleporter it stands on. The scan for those starts past it and stops two cells short of a full turn.
static int path_neighbors_get(Room& room, int cell, uint32_t flags, std::array<int, PATH_NEIGHBORS_MAX>& neighbors)
{
int column = cell % room.gridWidth;
int row = cell / room.gridWidth;
int count = 0;
neighbors[count++] = room.GetGridIndexByTile(column - 1, row);
neighbors[count++] = room.GetGridIndexByTile(column + 1, row);
neighbors[count++] = room.GetGridIndexByTile(column, row - 1);
neighbors[count++] = room.GetGridIndexByTile(column, row + 1);
if (!(flags & GRID_PATH_TELEPORTERS)) return count;
GridEntity* teleporter = room.gridEntities[cell];
if (!teleporter || teleporter->type != GRID_TELEPORTER || teleporter->state == TELEPORTER_STATE_OFF) return count;
int cells = room.gridWidth * room.gridHeight;
int scan = teleporter->gridIndex;
for (int step = 0; step < cells - 2; step++)
{
scan = (scan + 1) % cells;
GridEntity* other = scan < ROOM_GRID_CELLS ? room.gridEntities[scan] : nullptr;
bool isPartner = other && other->type == GRID_TELEPORTER && other->variant == teleporter->variant;
if (isPartner && count < PATH_NEIGHBORS_MAX) neighbors[count++] = scan;
}
return count;
}
// What stepping onto a cell costs: 1 onto open ground, the carve cost onto an obstacle a carving search breaks, or
// nothing (0) when it is closed. Spikes and cells marked by the paths are solid.
static uint32_t path_step_cost(Room& room, int cell, uint32_t flags)
{
GridEntity* grid = room.gridEntities[cell];
int collision = grid ? (grid->type == GRID_SPIKES ? COLLISION_SOLID : grid->collisionClass) : COLLISION_NONE;
if (room.gridPaths[cell] >= PATH_BLOCKED) collision = COLLISION_SOLID;
if ((flags & GRID_PATH_PLAYER_WALLS) && collision == COLLISION_WALL_EXCEPT_PLAYER) collision = COLLISION_NONE;
if ((flags & GRID_PATH_CARVE) && collision == COLLISION_SOLID)
return grid && is_carvable(grid->type) ? PATH_CARVE_COST : 0;
return collision == COLLISION_NONE ? 1 : 0;
}
// The carve of a found path, from the goal back to the start: rocks break (lifted off on the room's first frame) and
// empty pits fill.
static void path_carve(Room& room, const std::array<uint16_t, ROOM_GRID_CELLS>& cameFrom, int goal)
{
for (int cell = goal; cell != PATH_NO_CELL; cell = cameFrom[cell])
{
GridEntity* grid = room.gridEntities[cell];
if (!grid || !is_carvable(grid->type)) continue;
if (grid->type == GRID_PIT)
{
if (grid->state != PIT_STATE_EMPTY) continue;
grid->state = PIT_STATE_FILLED;
static_cast<GridEntity_Pit*>(grid)->UpdateCollision();
}
else if (room.enterFrame == g_game->frameCount)
reconstruction_missing("Room::PickupGridEntity 00825c50");
else grid->Destroy(true, EntityRef());
}
}
// 00821fc0 Whether a path joins two cells, by an A* search that expands the open cell of lowest estimate, the first in
// cell order on a tie. Estimates are compared in 16 bits as the original's are. A carving search clears its path.
bool is_grid_path_valid(Room& room, const GridPath& path)
{
std::array<uint32_t, ROOM_GRID_CELLS> costs;
std::array<uint32_t, ROOM_GRID_CELLS> estimates;
std::array<uint16_t, ROOM_GRID_CELLS> cameFrom;
std::array<int, PATH_NEIGHBORS_MAX> neighbors;
std::set<int> closed;
std::set<int> open = {path.start};
costs.fill(UINT32_MAX);
estimates.fill(UINT32_MAX);
cameFrom.fill(PATH_NO_CELL);
costs[path.start] = 0;
estimates[path.start] = path_estimate(room, path.start, path.goal) & PATH_NO_CELL;
while (!open.empty())
{
int current = *std::ranges::min_element(open, {}, [&](int cell) { return (uint16_t)estimates[cell]; });
if (current == path.goal)
{
if (path.flags & GRID_PATH_CARVE) path_carve(room, cameFrom, current);
return true;
}
open.erase(current);
closed.insert(current);
int count = path_neighbors_get(room, current, path.flags, neighbors);
for (int i = 0; i < count; i++)
{
int next = neighbors[i];
if (next < 0) continue;
uint32_t step = path_step_cost(room, next, path.flags);
if (step == 0 || closed.contains(next)) continue;
uint32_t cost = costs[current] + step;
if (open.contains(next) && cost >= costs[next]) continue;
open.insert(next);
costs[next] = cost;
cameFrom[next] = (uint16_t)current;
estimates[next] = path_estimate(room, next, path.goal) + cost;
}
}
return false;
}
// 00823be0 Whether a position can walk to the room's entrance or to the player: its cell must be open (or a wall only
// players pass), then a path must join them through those walls and the teleporters.
bool is_reachable_from_player(Room& room, const Reach& reach)
{
Entity_Player* player = reach.player ? reach.player : g_game->GetPlayer(0);
int goal = room.GetGridIndex(reach.goal == REACH_PLAYER ? player->pos : player->GetEnterPosition());
int start = room.GetGridIndex(reach.position);
if (start < 0) return false;
uint32_t collision = room.GetGridCollision(start);
bool isStartOpen = collision == COLLISION_NONE || collision == COLLISION_WALL_EXCEPT_PLAYER;
return goal >= 0 && isStartOpen &&
is_grid_path_valid(room, {start, goal, GRID_PATH_PLAYER_WALLS | GRID_PATH_TELEPORTERS});
}