private bool vTile(Tile tile) { if (tile != null) { GroundBrush bb = tile.getGroundBrush(); if (bb != null) { if (bb.hasOptionalBorder()) { return(true); } } } return(false); }
public override void draw(GameMap map, Tile tile, object param) { if (param != null) { Pair <bool, GroundBrush> ret = (Pair <bool, GroundBrush>)param; GroundBrush other = tile.getGroundBrush(); if (ret.first) { if (other != null) { return; } } else if ((other != null) && (ret.second.id != other.id)) { return; } } if (total_chance < 1) { total_chance = 1; } int chance = random.Next(1, total_chance + 1); UInt16 id = 0; foreach (ItemChanceBlock it in border_items) { if (chance < it.chance) { id = it.id; break; } } if ((id == 0) && (border_items.Count > 0)) { id = border_items.First().id; } if (id == 0) { id = look_id; } if (id != 0) { tile.addItem(Item.Create(Global.items.items[id])); } }
public void Load(XElement border_node, GroundBrush owner = null, UInt16 groundEquivalent = 0) { String type = border_node.Attribute("type").GetString(); if ("optional".Equals(type)) { this.IsOptionalBorder = true; } this.Group = border_node.Attribute("type").GetUInt16(); foreach (var borderitem_node in border_node.Elements("borderitem")) { UInt16 itemId = borderitem_node.Attribute("item").GetUInt16(); ItemType itemType = Global.items.items[itemId]; if (itemType == null) { continue; } if (owner != null) { itemType.Group = ItemGroup.None; itemType.GroundEquivalent = Global.items.items[groundEquivalent]; if (itemType.GroundEquivalent != null) { itemType.GroundEquivalent.HasEquivalent = true; } } itemType.alwaysOnBottom = true; itemType.IsBorder = true; itemType.IsOptionalBorder = this.IsOptionalBorder; itemType.Group = (ItemGroup)this.Group; int edge = EdgeNameToEdge(borderitem_node.Attribute("edge").GetString()); if (edge != BorderType.BORDER_NONE) { tiles[edge] = itemId; if (itemType.BorderAlignment == BorderType.BORDER_NONE) { itemType.BorderAlignment = edge; } } } }
public void unserializeBrush(XElement border_node) { Brush brush = null; String name = border_node.Attribute("name").GetString(); if (name == "") { // } brush = getBrush(name); if (brush == null) { String type = border_node.Attribute("type").GetString(); switch (type) { case "border": brush = new GroundBrush(); break; case "ground": brush = new GroundBrush(); break; case "wall": brush = new WallBrush(); break; case "wall decoration": brush = new WallDecorationBrush(); break; case "carpet": brush = new CarpetBrush(); break; case "table": brush = new TableBrush(); break; case "doodad": brush = new DoodadBrush(); break; default: Messages.AddWarning("Unknown brush type type:" + type); break; } brush.setName(name); } if (!border_node.HasElements) { brushList.Add(name, brush); } else { brush.load(border_node); if (getBrush(name) != null) { if (getBrush(name).getLookID() != brush.getLookID()) { //erro } else { return; } } brushList.Add(name, brush); } }
public static void doBorders(GameMap map, Tile tile) { //Console.WriteLine("------------------------------"); GroundBrush border_brush = tile.getGroundBrush(); int x = tile.Position.X; int y = tile.Position.Y; int z = tile.Position.Z; Pair <Boolean, GroundBrush>[] neighbours = new Pair <bool, GroundBrush> [8]; if (x == 0) { if (y == 0) { neighbours[0] = new Pair <bool, GroundBrush>(false, null); neighbours[1] = new Pair <bool, GroundBrush>(false, null); neighbours[2] = new Pair <bool, GroundBrush>(false, null); neighbours[3] = new Pair <bool, GroundBrush>(false, null); neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z)); neighbours[5] = new Pair <bool, GroundBrush>(false, null); neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z)); neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z)); } else { neighbours[0] = new Pair <bool, GroundBrush>(false, null); neighbours[1] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y - 1, z)); neighbours[2] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y - 1, z)); neighbours[3] = new Pair <bool, GroundBrush>(false, null); neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z)); neighbours[5] = new Pair <bool, GroundBrush>(false, null); neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z)); neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z)); } } else if (y == 0) { neighbours[0] = new Pair <bool, GroundBrush>(false, null); neighbours[1] = new Pair <bool, GroundBrush>(false, null); neighbours[2] = new Pair <bool, GroundBrush>(false, null); neighbours[3] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y, z)); neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z)); neighbours[5] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y + 1, z)); neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z)); neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z)); } else { neighbours[0] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y - 1, z)); neighbours[1] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y - 1, z)); neighbours[2] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y - 1, z)); neighbours[3] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y, z)); neighbours[4] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y, z)); neighbours[5] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x - 1, y + 1, z)); neighbours[6] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x, y + 1, z)); neighbours[7] = new Pair <bool, GroundBrush>(false, extractGroundBrushFromTile(map, x + 1, y + 1, z)); } List <BorderCluster> border_list = new List <BorderCluster>(); specific_list.Clear(); for (int i = 0; i < 8; i++) { if (neighbours[i].first) { continue; } GroundBrush other = neighbours[i].second; if (border_brush != null) { if (other != null) { if (other.getID() == border_brush.getID()) { continue; } if (other.hasOuterBorder() || border_brush.hasInnerBorder()) { bool only_mountain = false; if ((other.friendOf(border_brush) || border_brush.friendOf(other))) { if (other.hasOptionalBorder()) { only_mountain = true; } else { continue; } } UInt32 tiledata = 0; for (int j = i; j < 8; j++) { if (!neighbours[j].first && (neighbours[j].second != null) && neighbours[j].second.getID() == other.getID()) { neighbours[j].first = true; tiledata |= Convert.ToUInt32(1) << j; } } if (tiledata != 0) { if (other.hasOptionalBorder() && tile.hasOptionalBorder()) { BorderCluster cluster = new BorderCluster(); cluster.alignment = tiledata; cluster.z = 0x7FFFFFFF; // Above all other borders //cluster.z = 0; cluster.border = other.optional_border; //Console.WriteLine("Aqui 01"); border_list.Add(cluster); if (other.useSoloOptionalBorder()) { only_mountain = true; } } if (!only_mountain) { BorderBlock bb = getBrushTo(border_brush, other); if (bb != null) { bool found = false; foreach (BorderCluster bc in border_list) { if (bc.border.Equals(bb.autoborder)) { bc.alignment |= tiledata; if (bc.z < other.getZ()) { bc.z = other.getZ(); } if (bb.specific_cases.Count() > 0) { if (!specific_list.Contains(bb)) { specific_list.Add(bb); } } found = true; break; } } if (!found) { BorderCluster bc = new BorderCluster(); bc.alignment = tiledata; bc.z = other.getZ(); bc.border = bb.autoborder; //Console.WriteLine("Aqui 02"); border_list.Add(bc); if (bb.specific_cases.Count() > 0) { if (!specific_list.Contains(bb)) { specific_list.Add(bb); } } } } } } } } else if (border_brush.hasInnerZilchBorder()) { UInt32 tiledata = 0; for (int j = i; j < 8; j++) { if (neighbours[j].first == false && neighbours[j].second == null) { neighbours[j].first = true; tiledata |= Convert.ToUInt32(1) << j; } } if (tiledata != 0) { BorderCluster cluster = new BorderCluster(); cluster.alignment = tiledata; cluster.z = 5000; BorderBlock bb = getBrushTo(border_brush, null); if (bb == null) { continue; } cluster.border = bb.autoborder; if (cluster.border != null) { //Console.WriteLine("Aqui 03"); border_list.Add(cluster); } if (bb.specific_cases.Count() > 0) { if (!specific_list.Contains(bb)) { specific_list.Add(bb); } } } continue; } } else if (other != null && other.hasOuterZilchBorder()) { UInt32 tiledata = 0; for (int j = i; j < 8; j++) { if (neighbours[j].first == false && (neighbours[j].second != null) && neighbours[j].second.getID() == other.getID()) { neighbours[j].first = true; tiledata |= Convert.ToUInt32(1) << j; } } if (tiledata != 0) { BorderCluster cluster = new BorderCluster(); cluster.alignment = tiledata; cluster.z = other.getZ(); BorderBlock bb = getBrushTo(null, other); if (bb != null) { cluster.border = bb.autoborder; if (cluster.border != null) { //Console.WriteLine("where 04 - " + i); border_list.Add(cluster); } if (bb.specific_cases.Count() > 0) { if (!specific_list.Contains(bb)) { specific_list.Add(bb); } } } if (other.hasOptionalBorder() && tile.hasOptionalBorder()) { BorderCluster _cluster = new BorderCluster(); _cluster.alignment = tiledata; _cluster.z = 0x7FFFFFFF; // Above other zilch borders // _cluster.z = 0; _cluster.border = other.optional_border; //Console.WriteLine("Aqui 05"); border_list.Add(_cluster); } else { tile.setOptionalBorder(false); } } } neighbours[i].first = true; } tile.clearBorders(); //Messages.AddLogMessage("Quantidade de border list: " + border_list.Count); //people.OrderBy(x => x.LastName).ToList(); border_list = border_list.OrderByDescending(item => item.z).ToList(); while (border_list.Count > 0) { //BorderCluster cluster = border_list.Last(); BorderCluster cluster = border_list.First(); if (cluster.border == null) { border_list.Remove(cluster); continue; } //Console.WriteLine("id: " + cluster.border.Id + " alignment: " + cluster.alignment); long[] i = new long[4]; i[0] = ((Border_Types.border_types[cluster.alignment] & 0x000000FF) >> 0); i[1] = ((Border_Types.border_types[cluster.alignment] & 0x0000FF00) >> 8); i[2] = ((Border_Types.border_types[cluster.alignment] & 0x00FF0000) >> 16); i[3] = ((Border_Types.border_types[cluster.alignment] & 0xFF000000) >> 24); for (int iter = 0; iter < 4; ++iter) { if (i[iter] != 0) { if (cluster.border.tiles[i[iter]] != 0) { tile.addBorderItem(Item.Create(cluster.border.tiles[i[iter]])); } else { if (i[iter] == BorderType.NORTHWEST_DIAGONAL) { tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.WEST_HORIZONTAL])); tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.NORTH_HORIZONTAL])); } else if (i[iter] == BorderType.NORTHEAST_DIAGONAL) { tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.EAST_HORIZONTAL])); tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.NORTH_HORIZONTAL])); } else if (i[iter] == BorderType.SOUTHWEST_DIAGONAL) { tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.SOUTH_HORIZONTAL])); tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.WEST_HORIZONTAL])); } else if (i[iter] == BorderType.SOUTHEAST_DIAGONAL) { tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.SOUTH_HORIZONTAL])); tile.addBorderItem(Item.Create(cluster.border.tiles[BorderType.EAST_HORIZONTAL])); } } } else { break; } } border_list.Remove(cluster); } if (specific_list.Count > 1) { // Global.mapCanvas.drawing = false; // MessageBox.Show("Tem especifico"); } }
public static BorderBlock getBrushTo(GroundBrush first, GroundBrush second) { if (first != null) { if (second != null) { //Console.WriteLine("Aqui ninguem é nulo"); if (first.getZ() < second.getZ() && second.hasOuterBorder()) { //Console.WriteLine("getBrushTo 01"); if (first.hasInnerBorder()) { //Console.WriteLine("getBrushTo 02"); foreach (BorderBlock bb in first.borders) { //Console.WriteLine("getBrushTo 03"); if (bb.outer == true) { continue; } else if (bb.to == second.getID() || bb.to == 0xFFFFFFFF) { return(bb); } } } //Console.WriteLine("getBrushTo 04"); foreach (BorderBlock bb in second.borders) { //Console.WriteLine("getBrushTo 05"); if (!bb.outer) { continue; } else if (bb.to == first.getID()) { //Console.WriteLine("getBrushTo 05 1"); return(bb); } else if (bb.to == 0xFFFFFFFF) { //Console.WriteLine("getBrushTo 05 2"); return(bb); } } } else if (first.hasInnerBorder()) { //Console.WriteLine("getBrushTo 06"); foreach (BorderBlock bb in first.borders) { //Console.WriteLine("getBrushTo 07"); if (bb.outer == true) { continue; } else if (bb.to == second.getID()) { return(bb); } else if (bb.to == 0xFFFFFFFF) { return(bb); } } } } else if (first.hasInnerZilchBorder()) { { foreach (BorderBlock bb in first.borders) { if (bb.outer == true) { continue; } else if (bb.to == 0) { return(bb); } } } } } else if (second != null && second.hasOuterZilchBorder()) { foreach (BorderBlock bb in second.borders) { if (bb.outer == false) { continue; } else if (bb.to == 0) { return(bb); } } } return(null); }
public override bool canDraw(GameMap map, Position pos) { Tile tile = map.getTile(pos); // You can't do gravel on a mountain tile if (tile != null) { GroundBrush bb = tile.getGroundBrush(); if (bb != null) { if (bb.hasOptionalBorder()) { return(false); } } //tile.clearBorders(); } int x = pos.x; int y = pos.y; int z = pos.z; tile = map.getTile(x - 1, y - 1, z); if (vTile(tile)) { return(true); } tile = map.getTile(x, y - 1, z); if (vTile(tile)) { return(true); } tile = map.getTile(x + 1, y - 1, z); if (vTile(tile)) { return(true); } tile = map.getTile(x - 1, y, z); if (vTile(tile)) { return(true); } tile = map.getTile(x + 1, y, z); if (vTile(tile)) { return(true); } tile = map.getTile(x - 1, y + 1, z); if (vTile(tile)) { return(true); } tile = map.getTile(x, y + 1, z); if (vTile(tile)) { return(true); } tile = map.getTile(x + 1, y + 1, z); if (vTile(tile)) { return(true); } return(false); }