mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-25 19:46:50 -05:00
Map engine now fully supports multi-map rendering.
This commit is contained in:
parent
8e603f987e
commit
3500a07b45
17
OpenDiablo2.Common/Enums/eLevelSubType.cs
Normal file
17
OpenDiablo2.Common/Enums/eLevelSubType.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace OpenDiablo2.Common.Enums
|
||||
{
|
||||
public enum eLevelSubType
|
||||
{
|
||||
Act1BorderCliff = 1,
|
||||
Act1BorderMiddle = 2,
|
||||
Act1BorderCorner = 2,
|
||||
Act1BorderBorder = 3,
|
||||
Act1Waypoint = 4,
|
||||
Act1Shrine = 5,
|
||||
Act1Wilderness = 6,
|
||||
Act2Waypoint = 7,
|
||||
Act2Shrine = 8,
|
||||
Act2Desert = 9,
|
||||
|
||||
}
|
||||
}
|
18
OpenDiablo2.Common/Enums/eWildBorder.cs
Normal file
18
OpenDiablo2.Common/Enums/eWildBorder.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace OpenDiablo2.Common.Enums
|
||||
{
|
||||
public enum eWildBorder
|
||||
{
|
||||
South,
|
||||
West,
|
||||
North,
|
||||
East,
|
||||
SouthWest,
|
||||
NorthWest,
|
||||
NorthEast,
|
||||
SouthEast,
|
||||
ClosedBoxTopRight,
|
||||
ClosedBoxBottomRight,
|
||||
ClosedBoxBottomLeft,
|
||||
ClosedBoxTopLeft
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Models;
|
||||
|
||||
@ -15,5 +16,7 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
void Update(long ms);
|
||||
IEnumerable<MapCellInfo> GetMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType);
|
||||
void UpdateMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType, IEnumerable<MapCellInfo> mapCellInfo);
|
||||
MapInfo LoadMap(eLevelId levelId, Point origin);
|
||||
MapInfo LoadSubMap(int levelDefId, Point origin);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,5 @@ namespace OpenDiablo2.Common.Interfaces
|
||||
PointF CameraLocation { get; set; }
|
||||
void Update(long ms);
|
||||
void Render();
|
||||
void NotifyMapChanged();
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ namespace OpenDiablo2.Common.Models
|
||||
{
|
||||
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public string MapFile { get; set; }
|
||||
|
||||
public Int32 Version { get; internal set; }
|
||||
public Int32 Width { get; internal set; }
|
||||
public Int32 Height { get; internal set; }
|
||||
|
@ -7,6 +7,7 @@ namespace OpenDiablo2.Common.Models
|
||||
public sealed class MapInfo
|
||||
{
|
||||
public eLevelId LevelId { get; set; } = eLevelId.None;
|
||||
public MapInfo PrimaryMap { get; set; } = null;
|
||||
public MPQDS1 FileData { get; set; }
|
||||
public LevelPreset LevelPreset { get; set; }
|
||||
public LevelDetail LevelDetail { get; set; }
|
||||
|
@ -74,8 +74,10 @@
|
||||
<Compile Include="Enums\eButtonType.cs" />
|
||||
<Compile Include="Enums\eHero.cs" />
|
||||
<Compile Include="Enums\eLevelId.cs" />
|
||||
<Compile Include="Enums\eLevelSubType.cs" />
|
||||
<Compile Include="Enums\eMPQFormatVersion.cs" />
|
||||
<Compile Include="Enums\eRenderCellType.cs" />
|
||||
<Compile Include="Enums\eWildBorder.cs" />
|
||||
<Compile Include="Interfaces\IButton.cs" />
|
||||
<Compile Include="Interfaces\IEngineDataManager.cs" />
|
||||
<Compile Include="Interfaces\IFont.cs" />
|
||||
|
@ -64,8 +64,71 @@ namespace OpenDiablo2.Core.GameState_
|
||||
// TODO: Loading may make this 'fun'..
|
||||
mapInfo = new List<MapInfo>();
|
||||
|
||||
LoadMap(eLevelId.Act1_Town1, new Point(0, 0));
|
||||
(new MapGenerator(this)).Generate();
|
||||
|
||||
// TODO: We need a map generator here...
|
||||
/*
|
||||
{
|
||||
// TODO: TEMP CODE AHEAD!
|
||||
var transId = nw ? 3 : 2;
|
||||
var level = engineDataManager.LevelPresets.First(x => x.Def == (int)transId);
|
||||
var levelDetails = engineDataManager.LevelDetails.First(x => x.Id == level.LevelId);
|
||||
var levelType = engineDataManager.LevelTypes.First(x => x.Id == levelDetails.LevelType);
|
||||
|
||||
// Some maps have variations, so lets pick a random one
|
||||
var mapNames = new List<string>();
|
||||
if (level.File1 != "0") mapNames.Add(level.File1);
|
||||
if (level.File2 != "0") mapNames.Add(level.File2);
|
||||
if (level.File3 != "0") mapNames.Add(level.File3);
|
||||
if (level.File4 != "0") mapNames.Add(level.File4);
|
||||
if (level.File5 != "0") mapNames.Add(level.File5);
|
||||
if (level.File6 != "0") mapNames.Add(level.File6);
|
||||
|
||||
|
||||
var random = new Random(Seed);
|
||||
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
||||
_mapDataTemp2 = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
public MapInfo LoadSubMap(int levelDefId, Point origin)
|
||||
{
|
||||
var level = engineDataManager.LevelPresets.First(x => x.Def == levelDefId);
|
||||
var levelDetails = engineDataManager.LevelDetails.First(x => x.Id == level.LevelId);
|
||||
var levelType = engineDataManager.LevelTypes.First(x => x.Id == levelDetails.LevelType);
|
||||
|
||||
// Some maps have variations, so lets pick a random one
|
||||
var mapNames = new List<string>();
|
||||
if (level.File1 != "0") mapNames.Add(level.File1);
|
||||
if (level.File2 != "0") mapNames.Add(level.File2);
|
||||
if (level.File3 != "0") mapNames.Add(level.File3);
|
||||
if (level.File4 != "0") mapNames.Add(level.File4);
|
||||
if (level.File5 != "0") mapNames.Add(level.File5);
|
||||
if (level.File6 != "0") mapNames.Add(level.File6);
|
||||
|
||||
|
||||
var random = new Random(Seed);
|
||||
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
||||
var fileData = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
|
||||
|
||||
var result = new MapInfo
|
||||
{
|
||||
LevelId = eLevelId.None,
|
||||
LevelPreset = level,
|
||||
LevelDetail = levelDetails,
|
||||
LevelType = levelType,
|
||||
FileData = fileData,
|
||||
CellInfo = new Dictionary<eRenderCellType, MapCellInfo[]>(),
|
||||
TileLocation = new Rectangle(origin, new Size(fileData.Width, fileData.Height))
|
||||
};
|
||||
|
||||
mapInfo.Add(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public MapInfo LoadMap(eLevelId levelId, Point origin)
|
||||
@ -108,32 +171,8 @@ namespace OpenDiablo2.Core.GameState_
|
||||
};
|
||||
|
||||
mapInfo.Add(result);
|
||||
|
||||
return result;
|
||||
/*
|
||||
{
|
||||
// TODO: TEMP CODE AHEAD!
|
||||
var transId = nw ? 3 : 2;
|
||||
var level = engineDataManager.LevelPresets.First(x => x.Def == (int)transId);
|
||||
var levelDetails = engineDataManager.LevelDetails.First(x => x.Id == level.LevelId);
|
||||
var levelType = engineDataManager.LevelTypes.First(x => x.Id == levelDetails.LevelType);
|
||||
|
||||
// Some maps have variations, so lets pick a random one
|
||||
var mapNames = new List<string>();
|
||||
if (level.File1 != "0") mapNames.Add(level.File1);
|
||||
if (level.File2 != "0") mapNames.Add(level.File2);
|
||||
if (level.File3 != "0") mapNames.Add(level.File3);
|
||||
if (level.File4 != "0") mapNames.Add(level.File4);
|
||||
if (level.File5 != "0") mapNames.Add(level.File5);
|
||||
if (level.File6 != "0") mapNames.Add(level.File6);
|
||||
|
||||
|
||||
var random = new Random(Seed);
|
||||
var mapName = "data\\global\\tiles\\" + mapNames[random.Next(mapNames.Count())].Replace("/", "\\");
|
||||
_mapDataTemp2 = resourceManager.GetMPQDS1(mapName, level, levelDetails, levelType);
|
||||
|
||||
}
|
||||
*/
|
||||
getMapEngine().NotifyMapChanged();
|
||||
}
|
||||
|
||||
public IEnumerable<MapCellInfo> GetMapCellInfo(int cellX, int cellY, eRenderCellType renderCellType)
|
||||
@ -174,7 +213,6 @@ namespace OpenDiablo2.Core.GameState_
|
||||
var map = mapInfo.FirstOrDefault(z => z.TileLocation.Contains(x, y));
|
||||
if (map == null)
|
||||
{
|
||||
// TODO: Generate map here
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -283,7 +321,7 @@ namespace OpenDiablo2.Core.GameState_
|
||||
}
|
||||
|
||||
int frame = 0;
|
||||
var tiles = map.FileData.LookupTable
|
||||
var tiles = (map.PrimaryMap ?? map).FileData.LookupTable
|
||||
.Where(x => x.MainIndex == main_index && x.SubIndex == sub_index && x.Orientation == orientation)
|
||||
.Select(x => x.TileRef);
|
||||
|
||||
|
@ -50,17 +50,6 @@ namespace OpenDiablo2.Core.Map_Engine
|
||||
loadingSprite = renderWindow.LoadSprite(ResourcePaths.LoadingScreen, Palettes.Loading, new Point(300, 400));
|
||||
}
|
||||
|
||||
public void NotifyMapChanged()
|
||||
{
|
||||
LoadNewMapData();
|
||||
CameraLocation = new PointF(0, 0);
|
||||
}
|
||||
|
||||
private void LoadNewMapData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
var cx = -(cameraLocation.X - Math.Truncate(cameraLocation.X));
|
||||
|
53
OpenDiablo2.Core/MapGenerator.cs
Normal file
53
OpenDiablo2.Core/MapGenerator.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDiablo2.Common.Enums;
|
||||
using OpenDiablo2.Common.Interfaces;
|
||||
using OpenDiablo2.Common.Models;
|
||||
|
||||
namespace OpenDiablo2.Core
|
||||
{
|
||||
public sealed class MapGenerator
|
||||
{
|
||||
private readonly IGameState gameState;
|
||||
|
||||
public MapGenerator(IGameState gameState)
|
||||
{
|
||||
this.gameState = gameState;
|
||||
}
|
||||
|
||||
public void Generate()
|
||||
{
|
||||
var wildBorder = 5; // (4-15)
|
||||
// TODO: Is there no data file that explicitly defines this??
|
||||
var townMap = gameState.LoadMap(eLevelId.Act1_Town1, new Point(0, 0));
|
||||
if (townMap.FileData.MapFile.Contains("S1"))
|
||||
{
|
||||
var defId = 3; // Act 1 - Town 1 Transition S
|
||||
var borderMap = gameState.LoadSubMap(defId, new Point(0, townMap.FileData.Height));
|
||||
borderMap.PrimaryMap = townMap;
|
||||
|
||||
var wilderness = gameState.LoadSubMap(wildBorder, new Point(26, townMap.FileData.Height + borderMap.FileData.Height));
|
||||
wilderness.PrimaryMap = townMap;
|
||||
}
|
||||
else if (townMap.FileData.MapFile.Contains("E1"))
|
||||
{
|
||||
var defId = 2; // Act 1 - Town 1 Transition E
|
||||
var borderMap = gameState.LoadSubMap(defId, new Point(townMap.FileData.Width, 0));
|
||||
borderMap.PrimaryMap = townMap;
|
||||
|
||||
for (int i = 4; i <= 15; i++)
|
||||
{
|
||||
var wilderness = gameState.LoadSubMap(i, new Point(townMap.FileData.Width + borderMap.FileData.Width + ((i-4) * 10), 26));
|
||||
wilderness.PrimaryMap = townMap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -77,6 +77,7 @@
|
||||
<Compile Include="GameEngine.cs" />
|
||||
<Compile Include="GameState\GameState.cs" />
|
||||
<Compile Include="Map Engine\MapEngine.cs" />
|
||||
<Compile Include="MapGenerator.cs" />
|
||||
<Compile Include="MPQProvider.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ResourceManager.cs" />
|
||||
|
@ -43,7 +43,10 @@ namespace OpenDiablo2.Core
|
||||
public MPQDS1 GetMPQDS1(string resourcePath, LevelPreset level, LevelDetail levelDetail, LevelType levelType)
|
||||
{
|
||||
var mapName = resourcePath.Replace("data\\global\\tiles\\", "").Replace("\\", "/");
|
||||
return new MPQDS1(mpqProvider.GetStream(resourcePath), level, levelDetail, levelType, engineDataManager, this);
|
||||
return new MPQDS1(mpqProvider.GetStream(resourcePath), level, levelDetail, levelType, engineDataManager, this)
|
||||
{
|
||||
MapFile = resourcePath
|
||||
};
|
||||
}
|
||||
|
||||
public Palette GetPalette(string paletteFile)
|
||||
|
Loading…
Reference in New Issue
Block a user