From d4666a99b88927e4c2e9b82a61b90d8d15de6ff9 Mon Sep 17 00:00:00 2001 From: noctilucentgames Date: Mon, 26 Oct 2020 18:36:50 +0000 Subject: [PATCH] fix windmill shape generation - non recursive --- src/js/game/map_chunk.js | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/js/game/map_chunk.js b/src/js/game/map_chunk.js index 50f324cb..78add3d6 100644 --- a/src/js/game/map_chunk.js +++ b/src/js/game/map_chunk.js @@ -198,36 +198,35 @@ export class MapChunk { weights[enumSubShape.windmill] = 0; } - if (distanceToOriginInChunks < 10) { - // Initial chunk patches always have the same shape - const subShape = this.internalGenerateRandomSubShape(rng, weights); - subShapes = [subShape, subShape, subShape, subShape]; - } else if (distanceToOriginInChunks < 15) { - // Later patches can also have mixed ones - const subShapeA = this.internalGenerateRandomSubShape(rng, weights); - const subShapeB = this.internalGenerateRandomSubShape(rng, weights); - subShapes = [subShapeA, subShapeA, subShapeB, subShapeB]; - } else { - // Finally there is a mix of everything - subShapes = [ - this.internalGenerateRandomSubShape(rng, weights), - this.internalGenerateRandomSubShape(rng, weights), - this.internalGenerateRandomSubShape(rng, weights), - this.internalGenerateRandomSubShape(rng, weights), - ]; - } - // Makes sure windmills never spawn as whole - let windmillCount = 0; - for (let i = 0; i < subShapes.length; ++i) { - if (subShapes[i] === enumSubShape.windmill) { - ++windmillCount; + let windmillCount; + do { + windmillCount = 0; + if (distanceToOriginInChunks < 10) { + // Initial chunk patches always have the same shape + weights[enumSubShape.windmill] = 0; // no whole windmills + const subShape = this.internalGenerateRandomSubShape(rng, weights); + subShapes = [subShape, subShape, subShape, subShape]; + } else if (distanceToOriginInChunks < 15) { + // Later patches can also have mixed ones + const subShapeA = this.internalGenerateRandomSubShape(rng, weights); + const subShapeB = this.internalGenerateRandomSubShape(rng, weights); + subShapes = [subShapeA, subShapeA, subShapeB, subShapeB]; + } else { + // Finally there is a mix of everything + subShapes = [ + this.internalGenerateRandomSubShape(rng, weights), + this.internalGenerateRandomSubShape(rng, weights), + this.internalGenerateRandomSubShape(rng, weights), + this.internalGenerateRandomSubShape(rng, weights), + ]; } - } - if (windmillCount > 2) { - this.internalGenerateShapePatch(rng, shapePatchSize, distanceToOriginInChunks); - return; - } + for (let i = 0; i < subShapes.length; ++i) { + if (subShapes[i] === enumSubShape.windmill) { + ++windmillCount; + } + } + } while (windmillCount > 2); const definition = this.root.shapeDefinitionMgr.getDefinitionFromSimpleShapes(subShapes); this.internalGeneratePatch(