public Dungeon(UInt16 id, DungeonClass type, int x = 0, int y = 0, bool isServer = false) : base(true, id, isServer) { DungeonClass = type; X = x; Y = y; SpawnList = new List <Vector2d>(); myHasGenerated = false; if (!isServer) { int iconIndex = DungeonClass.IconIndexes[id % DungeonClass.IconIndexes.Length]; int iconX = iconIndex % (DungeonClass.IconTexture.Width / 16); int iconY = iconIndex / (DungeonClass.IconTexture.Width / 16); IconSprite = new Sprite(DungeonClass.IconTexture) { SubrectSize = new Vector2(16.0f, 16.0f), SubrectOffset = new Vector2(iconX, iconY) * 16.0f }; } }
public static ChunkTemplate[] GetTemplates(DungeonClass mapType) { if (stTemplates.ContainsKey(mapType)) { return(stTemplates[mapType].ToArray()); } return(new ChunkTemplate[0]); }
private static void LoadDungeonClasses() { InfoObject[] dungeonInfos = Info.GetAll("dungeonclass"); stDungeonClasses = new DungeonClass[dungeonInfos.Length]; for (int i = 0; i < dungeonInfos.Length; ++i) { stDungeonClasses[i] = new DungeonClass(dungeonInfos[i]); } }
protected void LoadFromStream(BinaryReader stream) { myWidth = stream.ReadInt16(); myHeight = stream.ReadInt16(); myTiles = new TileTemplate[Width, Height]; for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { myTiles[x, y] = new TileTemplate(); myTiles[x, y].Load(stream); } } int types = stream.ReadInt16(); myMapTypes = new DungeonClass[types]; for (int i = 0; i < types; ++i) { myMapTypes[i] = DungeonClass.Get(stream.ReadString()); } int entCount = stream.ReadInt16(); myEntities = new Entity[entCount]; for (int i = 0; i < entCount; ++i) { myEntities[i] = Entity.Load(stream, false); myEntities[i].Probability = stream.ReadDouble(); } myConnectors = new ChunkConnector[4][]; for (int i = 0; i < 4; ++i) { int connectors = stream.ReadByte(); myConnectors[i] = new ChunkConnector[connectors]; for (int j = 0; j < connectors; ++j) { myConnectors[i][j] = new ChunkConnector(stream, this); } } FindOrganisedConnectors(); }
public OverworldMap(System.IO.BinaryReader reader, bool isServer) : base(false, 0xFFFF, isServer) { HorizontalChunks = reader.ReadInt16(); VerticalChunks = reader.ReadInt16(); ChunkWidth = reader.ReadInt16(); ChunkHeight = reader.ReadInt16(); Width = HorizontalChunks * ChunkWidth; Height = VerticalChunks * ChunkHeight; myTiles = new OverworldTile[HorizontalChunks, VerticalChunks]; for (int x = 0; x < HorizontalChunks; ++x) { for (int y = 0; y < VerticalChunks; ++y) { OverworldTile tile = myTiles[x, y] = new OverworldTile(x * ChunkWidth, y * ChunkHeight, this); tile.Load(reader); } } myDungeons = new List <Dungeon>(); UInt16 dungeonCount = reader.ReadUInt16(); for (int i = 0; i < dungeonCount; ++i) { UInt16 id = reader.ReadUInt16(); String dungClassName = reader.ReadString(); int x = reader.ReadInt32(); int y = reader.ReadInt32(); myDungeons.Add(new Dungeon(id, DungeonClass.Get(dungClassName), x, y, false)); } myVB = new VertexBuffer(); myTilesChanged = true; }
public virtual void Generate(uint seed = 0) { if (seed == 0) { seed = (uint)(Tools.Random() * 0xFFFFFFFF); } Random rand = new Random((int)seed); myHeightPerlin = new Perlin { Seed = rand.Next(int.MinValue, int.MaxValue), OctaveCount = 12, Frequency = 0.25, Lacunarity = 2.0, Persistence = 0.5 }; myTempPerlin = new Perlin { Seed = rand.Next(int.MinValue, int.MaxValue), OctaveCount = 8, Frequency = 0.25, Lacunarity = 2.0, Persistence = 0.5 }; myStartX = rand.NextDouble() * 256.0 - 128.0; myStartY = rand.NextDouble() * 256.0 - 128.0; myStartZ = rand.NextDouble() * 256.0 - 128.0; for (int x = 0; x < HorizontalChunks; ++x) { for (int y = 0; y < VerticalChunks; ++y) { OverworldTile tile = myTiles[x, y] = new OverworldTile(x * ChunkWidth, y * ChunkHeight, this); double height = GetHeight((x + 0.5) * ChunkWidth, (y + 0.5) * ChunkHeight); if (height < 0.0) { double temp = GetTemperature((x + 0.5) * ChunkWidth, (y + 0.5) * ChunkHeight); if (temp < -0.25) { tile.TileType = OverworldTileType.Water; tile.Alt = (byte)(rand.Next(4)); } else if (temp < 0.5) { tile.TileType = OverworldTileType.Blank; tile.Alt = (byte)(rand.Next(4)); } else { if (height > -0.5) { tile.TileType = OverworldTileType.EvergreenTree; } else { tile.TileType = OverworldTileType.RoundTree; } tile.Alt = (byte)(rand.Next(4)); } } else { tile.TileType = OverworldTileType.Mountain; tile.Alt = (byte)(rand.Next(2) + (height <= 0.5 ? 2 : 0)); } } } PostWorldInitialize(); myDungeons = new List <Dungeon>(); UInt16 dungeonID = 0; DungeonClass[] classes = DungeonClass.GetAll(); while (myDungeons.Count < 24) { int x = rand.Next(ChunkWidth * 3, Width - ChunkWidth * 3); int y = rand.Next(ChunkHeight * 3, Height - ChunkHeight * 3); bool canPlace = true; foreach (Dungeon dungeon in myDungeons) { if (System.Math.Abs(dungeon.X - x) <= 3 * ChunkWidth && System.Math.Abs(dungeon.Y - y) <= 3 * ChunkHeight) { canPlace = false; break; } } if (canPlace) { myTiles[x / ChunkWidth, y / ChunkHeight].TileType = OverworldTileType.Blank; myDungeons.Add(new Dungeon(dungeonID++, classes[rand.Next(classes.Length)], x, y, true)); } } }