public ScenarioMap Expand(uint width, uint height, out RectangleMargins padding) { if (width < this.width) { throw new ArgumentOutOfRangeException(nameof(width)); } if (height < this.height) { throw new ArgumentOutOfRangeException(nameof(height)); } if (width == this.width && height == this.height) { throw new ArgumentException("Cannot expand when both width and height are same size as original."); } var map = new ScenarioMap(); map.width = width; map.height = height; map.terrain = new Terrain[width, height]; var padx = width - this.width; var pady = height - this.height; // padding priority goes to -x and +y due to camera angle var padright = padx / 2; var padbottom = pady / 2; var padleft = padx - padright; var padtop = pady - padbottom; padding = new RectangleMargins((int)padleft, (int)padright, (int)padbottom, (int)padtop); padright = width - padright; padtop = height - padtop; for (uint x = 0; x < width; x++) { for (uint y = 0; y < height; y++) { var i = x < padleft ? 0 : x >= padright ? this.width - 1 : x - padleft; var j = y < padbottom ? 0 : y >= padtop ? this.height - 1 : y - padbottom; var originalTile = terrain[i, j]; map.terrain[x, y].cnst = originalTile.cnst; map.terrain[x, y].elev = originalTile.elev; } } return(map); }
public static MapInfo Generate(Scenario scenario, RectangleMargins padding) { var map = scenario.Map; // var mapInfo = MapInfo.Default; var mapInfo = new MapInfo(MapInfoFormatVersion.Lua) { MapVersion = 1, EditorVersion = 6072, GameVersion = GamePatch.v1_31_1.ToVersion(), MapName = scenario.ScenarioName, RecommendedPlayers = scenario.PlayerCount.ToString(), CameraBounds = new Quadrilateral(0, map.width * 128, map.height * 128, 0), CameraBoundsComplements = padding, PlayableMapAreaWidth = (int)map.width, PlayableMapAreaHeight = (int)map.height, MapFlags = MapFlags.UseItemClassificationSystem | MapFlags.HasMapPropertiesMenuBeenOpened | MapFlags.MeleeMap, Tileset = Tileset.LordaeronSummer, LoadingScreenBackgroundNumber = -1, GameDataSet = GameDataSet.Unset, FogStyle = FogStyle.Linear, FogStartZ = 3000f, FogEndZ = 5000f, FogDensity = 0.5f, FogColor = Color.Black, GlobalWeather = WeatherType.None, WaterTintingColor = Color.White, ScriptLanguage = ScriptLanguage.Lua, }; const string NamePrefix = "MULTIPLAYER "; const string NameSuffix = ").SCN"; if (scenario.ScenarioName.StartsWith(NamePrefix, StringComparison.OrdinalIgnoreCase)) { var name = scenario.ScenarioName[NamePrefix.Length..];
public static MapDoodads Generate(ScenarioMap map, RectangleMargins padding) { var width = (int)map.width; var height = (int)map.height; var doodads = new List <DoodadData>(); var rnd = new Random(); for (uint x = 0; x < width; x++) { for (uint y = 0; y < height; y++) { var tileType = map.terrain[x, y].cnst; if (_treeTypes.TryGetValue(tileType, out var treeType)) { doodads.Add(new DoodadData { TypeId = treeType, Variation = rnd.Next(tileType == AoeTerrainType.PineForest ? 5 : 10), Position = 128f * new Vector3(x - padding.Left, y - padding.Bottom, 0f), Rotation = 0f, Scale = Vector3.One, CreationNumber = doodads.Count, State = DoodadState.Normal, Life = 100, }); } } } // TODO: convert scenario entities to doodads return(new MapDoodads(MapWidgetsFormatVersion.TFT, MapWidgetsSubVersion.V11, false) { Doodads = doodads, }); }
public static void Write(this BinaryWriter writer, RectangleMargins rectangleMargins) => rectangleMargins.WriteTo(writer);
public MapEnvironment(Tileset tileset, uint width, uint height, int cliffLevel, RectangleMargins cameraBoundsComplements) : this() { if (!Enum.IsDefined(typeof(Tileset), tileset)) { throw new ArgumentOutOfRangeException(nameof(tileset)); } var maxx = width - 1; if ((maxx % 32) != 0 || width == 0) { throw new ArgumentOutOfRangeException(nameof(width)); } var maxy = height - 1; if ((maxy % 32) != 0 || height == 0) { throw new ArgumentOutOfRangeException(nameof(height)); } if (cameraBoundsComplements is null) { throw new ArgumentNullException(nameof(cameraBoundsComplements)); } _tileset = tileset; _version = LatestVersion; _width = width; _height = height; _left = MapWidth / -2f; _bottom = MapHeight / -2f; _terrainTypes = GetDefaultTerrainTypes().ToList(); _cliffTypes = GetDefaultCliffTypes().ToList(); var edgeLeft = cameraBoundsComplements.Left; var edgeRight = maxx - cameraBoundsComplements.Right; var edgeBottom = cameraBoundsComplements.Bottom; var edgeTop = maxy - cameraBoundsComplements.Top; for (var y = 0; y < _width; y++) { for (var x = 0; x < _height; x++) { var tile = new MapTile(); tile.CliffLevel = cliffLevel; tile.CliffTexture = 15; tile.CliffVariation = 0; tile.Height = 0; tile.IsBlighted = false; tile.IsBoundary = false; tile.IsEdgeTile = x != maxx && y != maxy && (x < edgeLeft || x >= edgeRight || y < edgeBottom || y >= edgeTop); tile.IsRamp = false; tile.IsWater = false; tile.Texture = 0; tile.Variation = 0; tile.WaterHeight = 0; _tiles.Add(tile); } } }
public MapEnvironment(Tileset tileset, uint width, uint height, RectangleMargins cameraBoundsComplements) : this(tileset, width, height, DefaultCliffLevel, cameraBoundsComplements) { }