10#include <DTL/Base/RogueLike.hpp>
11#include <DTL/Random/RandomEngine.hpp>
12#include <DTL/Shape/MazeDig.hpp>
13#include <DTL/Shape/PerlinIsland.hpp>
14#include <DTL/Shape/SimpleRogueLike.hpp>
25 std::uint_fast8_t fill = 0) {
26 return std::vector<std::vector<std::uint_fast8_t>>(
28 size_t(
height), std::vector<std::uint_fast8_t>(
size_t(
width), fill));
35 const std::function<uint32_t(std::uint_fast8_t)> &mapValue) {
36 const int h = int(matrix.size());
37 const int w =
h > 0 ? int(matrix[0].
size()) : 0;
39 for (
int y = 0;
y <
h; ++
y) {
40 for (
int x = 0;
x <
w; ++
x) {
41 grid.setCell(
x,
y, mapValue(matrix[
size_t(
y)][
size_t(
x)]));
48 std::vector<std::pair<int, int>> walkable;
49 walkable.reserve(
size_t(grid.getWidth() * grid.getHeight() / 4));
50 for (
int y = 0;
y < grid.getHeight(); ++
y) {
51 for (
int x = 0;
x < grid.getWidth(); ++
x) {
52 const uint32_t
c = uint32_t(grid.getCell(
x,
y));
55 walkable.emplace_back(
x,
y);
59 if (walkable.empty())
return;
61 auto pick = [&](uint32_t salt) -> std::pair<int, int> {
62 const uint32_t
idx = (
seed * 1664525u + salt * 1013904223u) % uint32_t(walkable.size());
67 if (
a ==
b && walkable.size() > 1)
b = walkable[(size_t(
seed) + 1) % walkable.size()];
70 grid.addObjectAt(
"spawn",
"spawn",
float(
a.first), float(
a.second));
71 grid.addObjectAt(
"stairs",
"stairs",
float(
b.first), float(
b.second));
Intermediate 2D generation result. cells store semantic ids (see Semantic.h), not tile GIDs — convert...
constexpr uint32_t Corridor
void copyMatrixToGrid(const std::vector< std::vector< std::uint_fast8_t > > &matrix, Grid2D &grid, const std::function< uint32_t(std::uint_fast8_t)> &mapValue)
Copies matrix to grid.
void placeSpawnAndStairs(Grid2D &grid, uint32_t seed)
Place spawn + stairs on walkable cells (floor/corridor/grass/dirt/sand).
std::vector< std::vector< std::uint_fast8_t > > makeMatrix(int width, int height, std::uint_fast8_t fill=0)
Make matrix.