From c0c08bd85181e1cbf8781ce5989ac0be6e170464 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 3 Sep 2005 21:54:11 +0000 Subject: [PATCH] This was SVN commit r2661. --- .../data/mods/official/maps/random/test.js | 27 +++---- binaries/data/mods/official/maps/rmlibrary.js | 77 ++++++++++++++++--- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/binaries/data/mods/official/maps/random/test.js b/binaries/data/mods/official/maps/random/test.js index 5097f66bcb..b1bce06f9f 100644 --- a/binaries/data/mods/official/maps/random/test.js +++ b/binaries/data/mods/official/maps/random/test.js @@ -1,20 +1,17 @@ const SIZE = 64; -init(SIZE, "grass dirt 75", 0); +init(SIZE, ["grass dirt 50", "grass dirt 75"], 0); + +var tc = createTileClass(); +var tc2 = createTileClass(); createAreas( - new ClumpPlacer(23.0, 0.01, 0.01), - [new TerrainPainter("cliff_greekb_moss"), - new SmoothElevationPainter(ELEVATION_SET, 30.0, 3)], - null, - 20, - 200 -); + new ClumpPlacer(4.0, 0.01, 0.01), + [new TerrainPainter("dirt_forest|flora/wrld_flora_deci_1.xml"), new TileClassPainter(tc)], + new AvoidTileClassConstraint(tc, 5), + 100); -createAreas( - new ClumpPlacer(1.0, 1.0, 1.0), - new TerrainPainter(["grass_dirt_75|wrld_flora_oak", "grass_dirt_75|bush_medit_me"]), - new AvoidTextureConstraint("cliff_greekb_moss"), - 150, - 200 -); +createObjectGroups( + new SimpleGroup([new SimpleObject("foliage/bush.xml", 1, 0)], tc2), + [new AvoidTileClassConstraint(tc, 3), new AvoidTileClassConstraint(tc2, 2)], + 200); diff --git a/binaries/data/mods/official/maps/rmlibrary.js b/binaries/data/mods/official/maps/rmlibrary.js index e61fcde77c..bb987e00d2 100644 --- a/binaries/data/mods/official/maps/rmlibrary.js +++ b/binaries/data/mods/official/maps/rmlibrary.js @@ -1,15 +1,18 @@ // Object type constants const -TYPE_RECT_PLACER = 1, -TYPE_TERRAIN_PAINTER = 2, -TYPE_NULL_CONSTRAINT = 3, -TYPE_LAYERED_PAINTER = 4, -TYPE_AVOID_AREA_CONSTRAINT = 5, -TYPE_CLUMP_PLACER = 6, -TYPE_AVOID_TEXTURE_CONSTRAINT = 7, -TYPE_ELEVATION_PAINTER = 8, -TYPE_SMOOTH_ELEVATION_PAINTER = 9; + TYPE_RECT_PLACER = 1, + TYPE_TERRAIN_PAINTER = 2, + TYPE_NULL_CONSTRAINT = 3, + TYPE_LAYERED_PAINTER = 4, + TYPE_AVOID_AREA_CONSTRAINT = 5, + TYPE_CLUMP_PLACER = 6, + TYPE_AVOID_TEXTURE_CONSTRAINT = 7, + TYPE_ELEVATION_PAINTER = 8, + TYPE_SMOOTH_ELEVATION_PAINTER = 9, + TYPE_SIMPLE_GROUP = 10, + TYPE_AVOID_TILE_CLASS_CONSTRAINT = 11, + TYPE_TILE_CLASS_PAINTER = 12; // SmoothElevationPainter constants @@ -53,6 +56,10 @@ function chooseRand() { } function createAreas(centeredPlacer, painter, constraint, num, maxFail) { + if(maxFail == undefined) { + maxFail = 2*num; + } + var good = 0; var bad = 0; var ret = new Array(); @@ -71,6 +78,27 @@ function createAreas(centeredPlacer, painter, constraint, num, maxFail) { return ret; } +function createObjectGroups(placer, constraint, num, maxFail) { + if(maxFail == undefined) { + maxFail = 2*num; + } + + var good = 0; + var bad = 0; + while(good < num && bad <= maxFail) { + placer.x = randInt(SIZE); + placer.y = randInt(SIZE); + var r = createObjectGroup(placer, constraint); + if(r) { + good++; + } + else { + bad++; + } + } + return good; +} + // Area placers function RectPlacer(x1, y1, x2, y2) { @@ -91,8 +119,8 @@ function ClumpPlacer(size, coherence, smoothness, x, y) { this.size = size; this.coherence = coherence; this.smoothness = smoothness; - this.x = x ? x : -1; - this.y = y ? y : -1; + this.x = x==undefined ? x : -1; + this.y = y==undefined ? y : -1; } // Area painters @@ -108,6 +136,11 @@ function ElevationPainter(elevation) { this.elevation = elevation; } +function TileClassPainter(tileClass) { + this.TYPE = TYPE_TILE_CLASS_PAINTER; + this.tileClass = tileClass; +} + function SmoothElevationPainter(type, elevation, blendRadius) { this.TYPE = TYPE_SMOOTH_ELEVATION_PAINTER; this.type = type; @@ -130,3 +163,25 @@ function AvoidTextureConstraint(texture) { this.TYPE = TYPE_AVOID_TEXTURE_CONSTRAINT; this.texture = texture; } + +function AvoidTileClassConstraint(tileClass, distance) { + this.TYPE = TYPE_AVOID_TILE_CLASS_CONSTRAINT; + this.tileClass = tileClass; + this.distance = distance; +} + +// Object groups + +function SimpleObject(type, count, distance) { + this.type = type; + this.count = count; + this.distance = distance; +} + +function SimpleGroup(elements, tileClass, x, y) { + this.TYPE = TYPE_SIMPLE_GROUP; + this.elements = elements; + this.tileClass = tileClass==undefined ? tileClass : null; + this.x = x==undefined ? x : -1; + this.y = x==undefined ? y : -1; +} \ No newline at end of file