public void rmTerrainInitialize(string baseTerrain, float height) { var type = TerrainType.FromString(baseTerrain); Debug.Assert(type != null, "Unable to find " + baseTerrain + " terrain type"); for (int x = 0; x < world.Terrain.Width; ++x) { for (int y = 0; y < world.Terrain.Height; ++y) { world.Terrain[x, y] = new TerrainNode() { Height = height, Type = type }; } } }
/** * Builds the specified area. Actually builds the area. * Choosing when to use this command can have a big effect on your map. * For example, if you place each player area one by one, the first few will have enough room to build, * but if after 11 areas, area 12 still needs to be placed, it might have run out of space because the others were to greedy. * To avoid this, build all player area's at the same time, so that the script can try to find a fair balance between all areas. * @see #rmBuildAllAreas() */ public bool rmBuildArea(int areaID) { //if (areaID != 128) return; var area = areas[areaID]; for (int t = 0; t < 100 && float.IsNaN(area.Position.X); ++t) { float tAreaX = (float)rand.NextDouble() * MapSizeX * MetersPerTile, tAreaY = (float)rand.NextDouble() * MapSizeX * MetersPerTile; bool ok = true; for (int c = 0; c < area.Constraints.Count; ++c) { var constraint = area.Constraints[c]; if (!constraint.IsPointOk(tAreaX, tAreaY)) { ok = false; break; } } if (ok) { area.Position = fracToMeters(new XVector2(tAreaX, tAreaY)); } } int areaX = rmXMetersToTiles(area.Position.X), areaY = rmZMetersToTiles(area.Position.Y); float areaSizeF = rmXMetersToFraction( (area.MinSize + (area.MaxSize - area.MinSize) * (float)rand.NextDouble()) ); /*int areaSize = 1 + (int)Math.Sqrt(rmAreaFractionToTiles( * (area.MinSize + (area.MaxSize - area.MinSize) * (float)rand.NextDouble()) * ));*/ int areaSize = 1 + (int)Math.Sqrt(rmAreaFractionToTiles(areaSizeF)); List <TerrainType> types = new List <TerrainType>(); for (int l = 0; l < area.TerrainLayers.Count; ++l) { types.Add(TerrainType.FromString(area.TerrainLayers[l].TerrainType)); } var influence = new RMInflueceMap(world.Terrain.Width, world.Terrain.Height); influence.AddArea(new XPoint2(areaX, areaY), areaSize, area.Coherence); influence.BlurArea((int)(area.InfluenceBlurDistance / MetersPerTile)); influence.WithAreaTiles(delegate(XPoint2 pnt, int dist) { int x = pnt.X, y = pnt.Y; var terrain = world.Terrain[x, y]; float heightBlendTiles = area.HeightBlendDistance / MetersPerTile; if (!float.IsNaN(area.BaseHeight)) { if (dist < -heightBlendTiles / 2) { // Out of range: Do nothing } else if (dist < heightBlendTiles / 2) { float lerp = (float)dist / heightBlendTiles + 0.5f; terrain.Height += (area.BaseHeight - terrain.Height) * (lerp * lerp * (2 - lerp) * (2 - lerp)); } else { terrain.Height = area.BaseHeight; } } if (types.Count > 0 && dist >= 0) { TerrainType type = types[0]; for (int t = 1; t < area.TerrainLayers.Count; ++t) { if (area.TerrainLayers[t].MinDist <= dist && dist < area.TerrainLayers[t].MaxDist && types[t] != null) { type = types[t]; break; } } terrain.Type = type; } if (area.CliffType != null) { if (dist >= -2 && dist < 2) { terrain.Type = TerrainType.GreekCliff; } } world.Terrain[x, y] = terrain; }); /*Random rand2 = new Random(areaID); * for (int x = range.Left; x < range.Right; ++x) { * for (int y = range.Top; y < range.Bottom; ++y) { * int dist2 = (x - areaX) * (x - areaX) + (y - areaY) * (y - areaY); * float noise = (SimplexNoise.simplex_noise_2octaves((float)x / 20, 0, (float)y / 20) - 1) / 2; * int rnd = (int)(noise * areaSize); * int size = areaSize - rnd; * int smoothSize = size + areaSmooth; * if (dist2 < smoothSize * smoothSize) { * var terrain = world.Terrain[x, y]; * if (!float.IsNaN(area.BaseHeight)) { * float over = dist2 > size * size ? * ((float)Math.Sqrt(dist2) - size) / areaSmooth : * 0; * terrain.Height += (area.BaseHeight - terrain.Height) * (1 - over); * } * if (types.Count > 0 && dist2 < size * size) { * int dist = size - (int)Math.Sqrt(dist2); * TerrainType type = types[0]; * for (int t = 1; t < area.TerrainLayers.Count; ++t) { * if (area.TerrainLayers[t].MinDist <= dist && * dist <= area.TerrainLayers[t].MaxDist && types[t] != null) * { * type = types[t]; * break; * } * } * terrain.Type = type; * } * world.Terrain[x, y] = terrain; * } * } * }*/ area.Built = true; return(true); }