public static new Container LoadFromFile(BinaryReader stream) { Toolkit.ExpectFromFile(stream, "CONT", "container entity"); var e = Entity.LoadFromFile(stream); var newContainer = new Container(string.Empty, null) { ID = e.ID, Glyph = e.Glyph, ForegroundColor = e.ForegroundColor, BackgroundColor = e.BackgroundColor, XPosition = e.XPosition, YPosition = e.YPosition, }; newContainer.Token = Token.LoadFromFile(stream); Clutter.ResetToKnown(newContainer); return(newContainer); }
public static new Clutter LoadFromFile(BinaryReader stream) { Toolkit.ExpectFromFile(stream, "CLUT", "clutter entity"); var e = Entity.LoadFromFile(stream); var newClutter = new Clutter() { ID = e.ID, Glyph = e.Glyph, ForegroundColor = e.ForegroundColor, BackgroundColor = e.BackgroundColor, XPosition = e.XPosition, YPosition = e.YPosition, Blocking = e.Blocking }; newClutter.Name = stream.ReadString(); newClutter.Description = stream.ReadString(); newClutter.CanBurn = stream.ReadBoolean(); newClutter.Life = stream.ReadInt32(); Clutter.ResetToKnown(newClutter); return(newClutter); }
public virtual void ToTilemap(ref Tile[,] map) { var woodFloor = Color.FromArgb(86, 63, 44); var caveFloor = Color.FromArgb(65, 66, 87); var wall = Color.FromArgb(20, 15, 12); var water = BiomeData.Biomes[BiomeData.ByName(biome.Realm == Realms.Nox ? "Water" : "KoolAid")]; allowCaveFloor = false; Clutter.ParentBoardHack = Board; var doorCount = 0; var safeZones = new List <Rectangle>(); for (var row = 0; row < plotRows; row++) { for (var col = 0; col < plotCols; col++) { if (plots[col, row].BaseID == null) { //Can clutter this up! if (includeClutter && Random.Flip()) { Board.AddClutter(col * plotWidth, row * plotHeight, (col * plotWidth) + plotWidth, (row * plotHeight) + plotHeight + row); } else { safeZones.Add(new Rectangle() { Left = col * plotWidth, Top = row * plotHeight, Right = (col * plotWidth) + plotWidth, Bottom = (row * plotHeight) + plotHeight + row }); } continue; } if (plots[col, row].BaseID == "<spillover>") { continue; } var building = plots[col, row]; var template = building.Template; var sX = (col * plotWidth) + building.XShift; var sY = (row * plotHeight) + building.YShift; for (var y = 0; y < template.Height; y++) { for (var x = 0; x < template.Width; x++) { var tc = template.MapScans[y][x]; var def = string.Empty; var fluid = Fluids.Dry; var addDoor = true; if (tc == '/') { addDoor = false; tc = '\\'; } switch (tc) { case '\'': continue; case ',': def = "pathWay"; // FIXME: kind of ugly but does the job break; case '.': def = "woodFloor"; break; case '+': //Exit -- can't be seen, coaxes walls into shape. def = "doorwayClosed"; if (addDoor) { doorCount++; var door = new Door() { XPosition = sX + x, YPosition = sY + y, ForegroundColor = woodFloor, BackgroundColor = woodFloor.Darken(), ID = building.BaseID + "_Door" + doorCount, ParentBoard = Board, Closed = true, Glyph = '+' }; Board.Entities.Add(door); } break; case '=': def = "outerWoodWall"; break; case '-': def = "innerWoodWall"; break; case '#': def = allowCaveFloor ? "stoneFloor" : "woodFloor"; break; default: if (template.Markings.ContainsKey(tc)) { #region Custom markings var m = template.Markings[tc]; if (m.Text == "block") { throw new Exception("Got a BLOCK-type marking in a building template."); } if (m.Text != "tile" && m.Text != "floor" && m.Text != "water") { //Keep a floor here. The entity fills in the blank. def = "woodFloor"; var tileDef = TileDefinition.Find(def, false); map[sX + x, sY + y].Index = tileDef.Index; //var owner = m.Owner == 0 ? null : building.Inhabitants[m.Owner - 1]; var owner = (Character)null; if (m.HasToken("owner")) { owner = building.Inhabitants[(int)m.GetToken("owner").Value - 1]; } if (m.Text == "bed") { var newBed = new Clutter() { XPosition = sX + x, YPosition = sY + y, Name = "Bed", ID = "Bed_" + (owner == null ? Board.Entities.Count.ToString() : owner.Name.ToID()), Description = owner == null?i18n.GetString("freebed") : i18n.Format("someonesbed", owner.Name.ToString(true)), ParentBoard = Board, }; Clutter.ResetToKnown(newBed); Board.Entities.Add(newBed); } if (m.Text == "container") { //var type = c == '\x14B' ? "cabinet" : c == '\x14A' ? "chest" : "container"; var type = "chest"; if (m.HasToken("wardrobe")) { type = "wardrobe"; } var contents = DungeonGenerator.GetRandomLoot("container", type, new Dictionary <string, string>() { { "gender", owner.PreferredGender.ToString().ToLowerInvariant() }, { "biome", BiomeData.Biomes[DungeonGenerator.DungeonGeneratorBiome].Name.ToLowerInvariant() }, }); if (owner != null) { foreach (var content in contents) { content.AddToken("owner", 0, owner.ID); } } var newContainer = new Container(type, contents) //owner == null ? type.Titlecase() : owner.Name.ToString(true) + "'s " + type, contents) { XPosition = sX + x, YPosition = sY + y, ID = "Container_" + type + "_" + (owner == null ? Board.Entities.Count.ToString() : owner.Name.ToID()), ParentBoard = Board, }; Clutter.ResetToKnown(newContainer); Board.Entities.Add(newContainer); } else if (m.Text == "clutter") { if (m.HasToken("id")) { var newClutter = new Clutter() { XPosition = sX + x, YPosition = sY + y, ParentBoard = Board, ID = m.GetToken("id").Text, Name = string.Empty, }; Clutter.ResetToKnown(newClutter); Board.Entities.Add(newClutter); } else { var newClutter = new Clutter() { Glyph = (char)m.GetToken("char").Value, //m.Params.Last()[0], XPosition = sX + x, YPosition = sY + y, ForegroundColor = Color.Black, BackgroundColor = tileDef.Background, ParentBoard = Board, Name = m.GetToken("name").Text, //Name, Description = m.HasToken("description") ? m.GetToken("description").Text : string.Empty, Blocking = m.HasToken("blocking"), }; Board.Entities.Add(newClutter); } } } else if (m.Text == "water") { fluid = Fluids.Water; } else { def = TileDefinition.Find((int)m.GetToken("index").Value).Name; } #endregion } break; } map[sX + x, sY + y].Index = TileDefinition.Find(def).Index; map[sX + x, sY + y].Fluid = fluid; } } for (var i = 0; i < building.Inhabitants.Count; i++) { var inhabitant = building.Inhabitants[i]; //Find each inhabitant's bed so we can give them a starting place. //Alternatively, place them anywhere there's a ' ' within their sector. var bc = new BoardChar(inhabitant); //var bedID = building.BaseID + "_Bed_" + inhabitant.Name.FirstName; //var bed = Board.Entities.OfType<Clutter>().FirstOrDefault(b => b.ID == bedID); //if (bed != null) //{ // bc.XPosition = bed.XPosition; // bc.YPosition = bed.YPosition; //} //else { //var okay = false; var x = 0; var y = 0; var lives = 100; while (lives > 0) { lives--; x = (col * plotWidth) + Random.Next(plotWidth); y = (row * plotHeight) + Random.Next(plotHeight); if (!map[x, y].Definition.Wall && (!template.AllowOutside && map[x, y].Definition.Ceiling) && Board.Entities.FirstOrDefault(e => e.XPosition == x && e.YPosition == y) == null) { break; } } bc.XPosition = x; bc.YPosition = y; } bc.Character.AddToken("sectorlock"); bc.ParentBoard = Board; bc.AdjustView(); bc.Sector = string.Format("s{0}x{1}", row, col); Board.Entities.Add(bc); } } } Board.ResolveVariableWalls(); if (safeZones.Count > 0 && includeWater) { Board.AddWater(safeZones); } }
public void MergeBitmap(string fileName, string tiledefs) { var bitmap = Mix.GetBitmap(fileName); var tileset = new Token(); tileset.AddSet(Mix.GetTokenTree(tiledefs, true)); var width = Width; var height = Height; if (width > bitmap.Width) { width = bitmap.Width; } if (height > bitmap.Height) { height = bitmap.Height; } for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var color = bitmap.GetPixel(x, y); if (color.Name == "ff000000" || color.A == 0) { continue; } var key = color.Name.Substring(2).ToUpperInvariant(); if (!tileset.HasToken(key)) { continue; } var tile = tileset.GetToken(key); //Keep the original tile, but drain it. if (tile.Text == "drain") { this.Tilemap[x, y].Fluid = Fluids.Dry; continue; } this.Tilemap[x, y].Index = TileDefinition.Find(tile.Text).Index; if (tile.Text.StartsWith("doorway")) { var door = new Door() { XPosition = x, YPosition = y, ForegroundColor = this.Tilemap[x, y].Definition.Background, BackgroundColor = this.Tilemap[x, y].Definition.Background.Darken(), ID = "mergeBitmap_Door" + x + "_" + y, ParentBoard = this, Closed = tile.Text.EndsWith("Closed"), Glyph = '+' }; this.Entities.Add(door); } if (tile.HasToken("clutter")) { var nc = new Clutter() { XPosition = x, YPosition = y, ParentBoard = this }; this.Entities.Add(nc); var properties = tile.GetToken("clutter"); foreach (var property in properties.Tokens) { switch (property.Name) { case "id": nc.ID = property.Text; break; case "name": nc.Name = property.Text; break; case "desc": nc.Description = property.Text; break; case "glyph": nc.Glyph = (int)property.Value; break; case "fg": if (property.Text.StartsWith('#')) { nc.ForegroundColor = Color.FromCSS(property.Text); } else { nc.ForegroundColor = Color.FromName(property.Text); } break; case "bg": if (property.Text.StartsWith('#')) { nc.BackgroundColor = Color.FromCSS(property.Text); } else { nc.BackgroundColor = Color.FromName(property.Text); } break; case "block": nc.Blocking = true; break; case "burns": nc.CanBurn = true; break; } } } if (tile.HasToken("unique")) { var unique = tile.GetToken("unique"); var newChar = new BoardChar(Character.GetUnique(unique.Text)) { XPosition = x, YPosition = y, ParentBoard = this }; this.Entities.Add(newChar); newChar.AssignScripts(unique.Text); newChar.ReassignScripts(); } if (!tile.HasToken("fluid")) { this.Tilemap[x, y].Fluid = Fluids.Dry; } else { this.Tilemap[x, y].Fluid = (Fluids)Enum.Parse(typeof(Fluids), tile.GetToken("fluid").Text, true); } } } this.ResolveVariableWalls(); }