private static bool hasMatchingTableBrushAtTile(GameMap map, TableBrush table_brush, int x, int y, int z) { Tile t = map.getTile(x, y, z); if (t == null) { return(false); } foreach (Item it in t.Items) { TableBrush tb = it.getTableBrush(); if (tb == table_brush) { return(true); } } return(false); }
public override void undraw(GameMap map, Tile tile) { List <Item> itemsToRemove = new List <Item>(); foreach (Item it in tile.Items) { if (it.Type.IsTable) { TableBrush tb = it.getTableBrush(); if (this.Equals(tb)) { itemsToRemove.Add(it); } } } foreach (Item it in itemsToRemove) { tile.Items.Remove(it); } }
public static void doTables(GameMap map, Tile tile) { if (tile.hasTable() == false) { return; } int x = tile.getPosition().x; int y = tile.getPosition().y; int z = tile.getPosition().z; foreach (Item item in tile.Items) { TableBrush table_brush = item.getTableBrush(); if (table_brush == null) { continue; } bool[] neighbours = new bool[8]; if (x == 0) { if (y == 0) { neighbours[0] = false; neighbours[1] = false; neighbours[2] = false; neighbours[3] = false; neighbours[4] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y, z); neighbours[5] = false; neighbours[6] = hasMatchingTableBrushAtTile(map, table_brush, x, y + 1, z); neighbours[7] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y + 1, z); } else { neighbours[0] = false; neighbours[1] = hasMatchingTableBrushAtTile(map, table_brush, x, y - 1, z); neighbours[2] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y - 1, z); neighbours[3] = false; neighbours[4] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y, z); neighbours[5] = false; neighbours[6] = hasMatchingTableBrushAtTile(map, table_brush, x, y + 1, z); neighbours[7] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y + 1, z); } } else if (y == 0) { neighbours[0] = false; neighbours[1] = false; neighbours[2] = false; neighbours[3] = hasMatchingTableBrushAtTile(map, table_brush, x - 1, y, z); neighbours[4] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y, z); neighbours[5] = hasMatchingTableBrushAtTile(map, table_brush, x - 1, y + 1, z); neighbours[6] = hasMatchingTableBrushAtTile(map, table_brush, x, y + 1, z); neighbours[7] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y + 1, z); } else { neighbours[0] = hasMatchingTableBrushAtTile(map, table_brush, x - 1, y - 1, z); neighbours[1] = hasMatchingTableBrushAtTile(map, table_brush, x, y - 1, z); neighbours[2] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y - 1, z); neighbours[3] = hasMatchingTableBrushAtTile(map, table_brush, x - 1, y, z); neighbours[4] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y, z); neighbours[5] = hasMatchingTableBrushAtTile(map, table_brush, x - 1, y + 1, z); neighbours[6] = hasMatchingTableBrushAtTile(map, table_brush, x, y + 1, z); neighbours[7] = hasMatchingTableBrushAtTile(map, table_brush, x + 1, y + 1, z); } uint tiledata = 0; for (int i = 0; i < 8; i++) { if (neighbours[i]) { tiledata |= Convert.ToUInt32(1) << i; } } int bt = Border_Types.table_types[tiledata]; TableNode tn = table_brush.table_items[bt]; if (tn.total_chance == 0) { return; } int chance = Global.random.Next(1, tn.total_chance + 1); ushort id = 0; foreach (TableType node_iter in tn.items) { if (chance <= node_iter.chance) { id = node_iter.item_id; break; } chance -= node_iter.chance; } if (id != 0) { item.setID(id); } } }
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); } }