BSP: include walls in room boundary
This commit is contained in:
parent
c4c2b26653
commit
757cca1392
@ -29,16 +29,11 @@ void main() async {
|
||||
int seed = 0;
|
||||
|
||||
while (true) {
|
||||
Vault output = Generator(math.Random(seed), vaults).generateBoxed(
|
||||
Requirement(
|
||||
32,
|
||||
24,
|
||||
DirectionSet({
|
||||
Direction.up,
|
||||
Direction.left,
|
||||
Direction.right,
|
||||
Direction.down
|
||||
})));
|
||||
Vault output = Generator(math.Random(seed), vaults).generate(Requirement(
|
||||
32,
|
||||
24,
|
||||
DirectionSet(
|
||||
{Direction.up, Direction.left, Direction.right, Direction.down})));
|
||||
var w = output.vx;
|
||||
var h = output.vy;
|
||||
for (var y = 0; y < h; y++) {
|
||||
|
@ -20,21 +20,6 @@ class Generator {
|
||||
|
||||
Generator(this._random, this._vaults);
|
||||
|
||||
Vault generateBoxed(Requirement req) {
|
||||
var vx = req.vx;
|
||||
var vy = req.vy;
|
||||
|
||||
var v = Vault.blank(vx, vy, req.smooth, VaultTile.wall);
|
||||
|
||||
if (req.vx < 2 || req.vy < 2) {
|
||||
return v;
|
||||
}
|
||||
var req2 = Requirement(vx - 2, vy - 2, req.smooth);
|
||||
var inner = generate(req2);
|
||||
v.blitFrom(inner, 1, 1);
|
||||
return v;
|
||||
}
|
||||
|
||||
Vault generate(Requirement requirement) {
|
||||
Vault? suggested = _suggest(vaultTries, requirement);
|
||||
if (suggested != null) {
|
||||
@ -66,21 +51,23 @@ class Generator {
|
||||
var vy = req.vy;
|
||||
var v = Vault.blank(vx, vy, req.smooth, VaultTile.wall);
|
||||
|
||||
if (vx < 5 || vx * vy < 10) {
|
||||
v.clear(VaultTile.bspfloor);
|
||||
if (vx < 2 || vy < 2) {
|
||||
} else if (vx < 9 || (vx - 2) * (vy - 2) < 12) {
|
||||
var v2 = Vault.blank(vx - 2, vy - 2, req.smooth, VaultTile.bspfloor);
|
||||
v.blitFrom(v2, 1, 1);
|
||||
} else {
|
||||
// pick a split point
|
||||
var splitVx = _random.nextInt(vx - 4) + 2;
|
||||
var splitVx = _random.nextInt(vx - 8) + 4;
|
||||
|
||||
var reqLeft = Requirement(splitVx, vy, req.smooth.clone());
|
||||
reqLeft.smooth.directions.add(Direction.right);
|
||||
var reqRight = Requirement((vx - splitVx - 1), vy, req.smooth.clone());
|
||||
var reqRight = Requirement((vx - splitVx + 1), vy, req.smooth.clone());
|
||||
reqRight.smooth.directions.add(Direction.left);
|
||||
|
||||
var vaultLeft = generate(reqLeft);
|
||||
var vaultRight = generate(reqRight);
|
||||
v.blitFrom(vaultLeft, 0, 0);
|
||||
v.blitFrom(vaultRight, splitVx + 1, 0);
|
||||
v.blitFrom(vaultRight, splitVx - 1, 0);
|
||||
}
|
||||
|
||||
return v;
|
||||
|
@ -9,47 +9,6 @@ class Vault {
|
||||
assert(tiles.length == vx * vy);
|
||||
}
|
||||
|
||||
// TODO: We should be assessing this based on whether the pattern in the input
|
||||
// PNG had right-angled borders on this side, not based on the literal
|
||||
// presence or absence of walls
|
||||
//
|
||||
// In other words, this is wrong.
|
||||
static Vault fromVaultData(int vx, int vy, List<VaultTile> tiles) {
|
||||
assert(tiles.length == vx * vy);
|
||||
var smooth = {
|
||||
Direction.up,
|
||||
Direction.left,
|
||||
Direction.down,
|
||||
Direction.right
|
||||
};
|
||||
for (var x = 0; x < vx; x++) {
|
||||
if (tiles[x + 0 * vx] == VaultTile.wall) {
|
||||
smooth.remove(Direction.up);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (var x = 0; x < vx; x++) {
|
||||
if (tiles[x + (vy - 1) * vx] == VaultTile.wall) {
|
||||
smooth.remove(Direction.down);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (var y = 0; y < vy; y++) {
|
||||
if (tiles[0 + y * vx] == VaultTile.wall) {
|
||||
smooth.remove(Direction.left);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (var y = 0; y < vy; y++) {
|
||||
if (tiles[vx - 1 + y * vx] == VaultTile.wall) {
|
||||
smooth.remove(Direction.right);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Vault(vx, vy, DirectionSet(smooth), tiles);
|
||||
}
|
||||
|
||||
void clear(VaultTile lt) {
|
||||
for (var y = 0; y < vy; y++) {
|
||||
for (var x = 0; x < vx; x++) {
|
||||
|
Loading…
Reference in New Issue
Block a user