Curation round 17: Theora and Vorbis cutscene videos, Ludovico, Epic and Dr. Fetus, Tractor Beam and Eye of the Occult, familiars and blue spiders, fortune teller and restock, the Bag of Crafting and four tainted characters, ten enemies, water and the ultra secret door, Isaac, ???, the Lamb and Hush
This commit is contained in:
1 parent
e9de039d0f
commit
024cb12016
133 files changed
+13325
-2520
No files matched your search
@@ -2,6 +2,8 @@
|
||||
#include "game.h"
|
||||
#include "grid_entity_pit.h"
|
||||
#include "grid_entity_teleporter.h"
|
||||
#include "entity_pickup.h"
|
||||
#include "entity_effect.h"
|
||||
#include "log.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -13,6 +15,10 @@ constexpr int PATH_BLOCKED = 1000;
|
||||
constexpr float PATH_HEURISTIC_SCALE = 10;
|
||||
constexpr uint16_t PATH_NO_CELL = 0xffff;
|
||||
|
||||
// The sides CanSpawnObstacleAtPosition keeps joined around a new obstacle, and its mark for a door beside it.
|
||||
constexpr std::array<std::array<int, 2>, 4> OBSTACLE_SIDES = {{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}};
|
||||
constexpr int OBSTACLE_BESIDE_DOOR = -2;
|
||||
|
||||
// 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)
|
||||
{
|
||||
@@ -164,3 +170,73 @@ bool is_reachable_from_player(Room& room, const Reach& reach)
|
||||
return goal >= 0 && isStartOpen &&
|
||||
is_grid_path_valid(room, {start, goal, GRID_PATH_PLAYER_WALLS | GRID_PATH_TELEPORTERS});
|
||||
}
|
||||
|
||||
// Whether two cells lie less than two steps apart along the grid.
|
||||
static bool is_cell_near(Room& room, int cell, int other)
|
||||
{
|
||||
return std::abs(cell % room.gridWidth - other % room.gridWidth) + std::abs(cell / room.gridWidth - other / room.gridWidth) <
|
||||
2;
|
||||
}
|
||||
|
||||
// Whether a cell beside a new obstacle is one the paths around it must still join: a free cell, or a grid entity a
|
||||
// walker passes (TNT and poop always) but a trapdoor, stairs, plate or teleporter. A door beside it forbids it (-2).
|
||||
static int obstacle_neighbor_get(Room& room, int cell)
|
||||
{
|
||||
GridEntity* grid = room.gridEntities[cell];
|
||||
if (!grid) return room.gridPaths[cell] < PATH_BLOCKED ? cell : -1;
|
||||
if (grid->type == GRID_DOOR) return OBSTACLE_BESIDE_DOOR;
|
||||
|
||||
bool isPassable = (uint32_t)grid->gridIndex >= ROOM_GRID_CELLS || room.gridPaths[grid->gridIndex] < PATH_BLOCKED ||
|
||||
grid->type == GRID_TNT || grid->type == GRID_POOP;
|
||||
return isPassable && !is_grid_floor_special(grid->type) ? cell : -1;
|
||||
}
|
||||
|
||||
// 00822820 Whether an obstacle may go on a cell: inside the room (not a crawlspace), on a free or walkable cell that is
|
||||
// not floor special, under no grounded player (unless forced), two steps from the doors, the Stairway's ladder and the
|
||||
// shop items, and leaving the cells around it joined.
|
||||
bool Room::CanSpawnObstacleAtPosition(int gridIndex, bool isForced)
|
||||
{
|
||||
if ((uint32_t)gridIndex >= ROOM_GRID_CELLS || !IsPositionInRoom(GetGridPosition(gridIndex), 0) ||
|
||||
roomType == ROOM_DUNGEON)
|
||||
return false;
|
||||
|
||||
GridEntity* grid = gridEntities[gridIndex];
|
||||
bool isWalkable = grid && (grid->IsEasyCrushableOrWalkable() || grid->IsDangerousCrushableOrWalkable());
|
||||
if (grid && (!isWalkable || is_grid_floor_special(grid->type))) return false;
|
||||
|
||||
for (Entity_Player* player : g_game->playerManager.playerList)
|
||||
{
|
||||
bool isGrounded = player->entityGridCollisionClass > GRIDCOLL_WALLS;
|
||||
if (!isForced && isGrounded && GetGridIndex(player->pos) == gridIndex) return false;
|
||||
}
|
||||
for (int slot = 0; slot < DOOR_SLOT_COUNT; slot++)
|
||||
{
|
||||
bool isDoor = descriptor->data && descriptor->data->doors & (1u << slot);
|
||||
if (isDoor && is_cell_near(*this, doorGridPositions[slot], gridIndex)) return false;
|
||||
}
|
||||
for (Entity* entity : entityList.updateEL)
|
||||
{
|
||||
bool isKept = (entity->type == ENTITY_EFFECT && entity->variant == EFFECT_TALL_LADDER) ||
|
||||
(entity->type == ENTITY_PICKUP && static_cast<Entity_Pickup*>(entity)->price != 0);
|
||||
int cell = isKept ? GetGridIndex(entity->pos) : -1;
|
||||
if (cell >= 0 && is_cell_near(*this, cell, gridIndex)) return false;
|
||||
}
|
||||
|
||||
std::vector<int> neighbors;
|
||||
for (auto [column, row] : OBSTACLE_SIDES)
|
||||
{
|
||||
int cell = GetGridIndexByTile(gridIndex % gridWidth + column, gridIndex / gridWidth + row);
|
||||
int neighbor = cell >= 0 ? obstacle_neighbor_get(*this, cell) : -1;
|
||||
if (neighbor == OBSTACLE_BESIDE_DOOR) return false;
|
||||
if (neighbor >= 0) neighbors.push_back(neighbor);
|
||||
}
|
||||
|
||||
int savedPath = gridPaths[gridIndex];
|
||||
bool isJoined = true;
|
||||
gridPaths[gridIndex] = PATH_BLOCKED;
|
||||
for (size_t i = 0; i + 1 < neighbors.size() && isJoined; i++)
|
||||
for (size_t j = i + 1; j < neighbors.size() && isJoined; j++)
|
||||
isJoined = is_grid_path_valid(*this, {neighbors[i], neighbors[j], 0});
|
||||
gridPaths[gridIndex] = savedPath;
|
||||
return isJoined;
|
||||
}
|
||||
Reference in new issue
Block a user