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 FillDoodadPreviewBuffer() { DoodadBrush brush = EditorPalette.getSelectedPalette().GetSelectedBrush() as DoodadBrush; if (brush == null) { return; } if (Global.mapCanvas.secondary_map != null) { return; } GameMap doodad_buffer_map = Global.mapCanvas.doodad_buffer_map; Global.mapCanvas.secondary_map = doodad_buffer_map; doodad_buffer_map.clear(); if (brush.isEmpty(EditorPalette.getSelectedPalette().GetBrushVariation())) { return; } int object_count = 0; int area; if (EditorPalette.GetBrushShape() == BrushShape.BRUSHSHAPE_SQUARE) { area = 2 * EditorPalette.GetBrushSize(); area = area * area + 1; } else { if (EditorPalette.GetBrushSize() == 1) { // There is a huge deviation here with the other formula. area = 5; } else { area = (int)(0.5 + EditorPalette.GetBrushSize() * EditorPalette.GetBrushSize() * Math.PI); } } EditorPalette ed = EditorPalette.getSelectedPalette(); int object_range = (ed.use_custom_thickness ? (int)(area * ed.custom_thickness_mod) : brush.getThickness() * area / Math.Max(1, brush.getThicknessCeiling())); int final_object_count = Math.Max(1, object_range + random.Next(object_range + 1)); Position center_pos = new Position(0x8000, 0x8000, 0x8); int brush_size = EditorPalette.GetBrushSize(); if (EditorPalette.GetBrushSize() > 0 && brush.oneSizeFitsAll() == false) { while (object_count < final_object_count) { int retries = 0; bool exit = false; while (retries < 5 && exit == false) // Try to place objects 5 times { int pos_retries = 0; int xpos = 0; int ypos = 0; bool found_pos = false; if (EditorPalette.GetBrushShape() == BrushShape.BRUSHSHAPE_CIRCLE) { while (pos_retries < 5 && found_pos == false) { xpos = random.Next(-brush_size, brush_size + 1); ypos = random.Next(-brush_size, brush_size + 1); double distance = Math.Sqrt((double)(xpos * xpos) + (double)(ypos * ypos)); if (distance < EditorPalette.GetBrushSize() + 0.005) { found_pos = true; } } } else { found_pos = true; xpos = random.Next(-brush_size, brush_size + 1); ypos = random.Next(-brush_size, brush_size + 1); } if (found_pos == false) { ++retries; continue; } // Decide whether the zone should have a composite or several single objects. bool fail = false; if (random.Next(brush.getTotalChance(ed.GetBrushVariation()) + 1) <= brush.getCompositeChance(ed.GetBrushVariation())) { // Composite List <Tile> tiles = brush.getComposite(ed.GetBrushVariation()); // Figure out if the placement is valid foreach (Tile buffer_tile in tiles) { Position pos = center_pos + buffer_tile.getPosition() + new Position(xpos, ypos, 0); Tile tile = doodad_buffer_map.getTile(pos); if (tile != null) { if (tile.size() > 0) { fail = true; break; } } } if (fail) { ++retries; break; } // Transfer items to the stack foreach (Tile buffer_tile in tiles) { Position pos = center_pos + buffer_tile.getPosition() + new Position(xpos, ypos, 0); Tile tile; if ((tile = doodad_buffer_map.getTile(pos)) == null) { tile = new Tile(pos); } if (buffer_tile.Ground != null) { tile.addItem(buffer_tile.Ground.deepCopy()); } foreach (Item item_iter in buffer_tile.Items) { tile.addItem(item_iter.deepCopy()); } doodad_buffer_map.setTile(tile.getPosition(), tile); } exit = true; } else if (brush.hasSingleObjects(ed.GetBrushVariation())) { Position pos = center_pos + new Position(xpos, ypos, 0); Tile tile = doodad_buffer_map.getTile(pos); if (tile != null) { if (tile.size() > 0) { fail = true; break; } } else { tile = new Tile(pos); } int variation = ed.GetBrushVariation(); brush.draw(doodad_buffer_map, tile, variation); //std::cout << "\tpos: " << tile->getPosition() << std::endl; doodad_buffer_map.setTile(tile.getPosition(), tile); exit = true; } if (fail) { ++retries; break; } } ++object_count; } } else { if (brush.hasCompositeObjects(ed.GetBrushVariation()) && random.Next(brush.getTotalChance(ed.GetBrushVariation()) + 1) <= brush.getCompositeChance(ed.GetBrushVariation())) { // Composite List <Tile> tiles = brush.getComposite(ed.GetBrushVariation()); // All placement is valid... // Transfer items to the buffer foreach (Tile buffer_tile in tiles) { Position pos = center_pos + buffer_tile.getPosition(); Tile tile = new Tile(pos); //std::cout << pos << " = " << center_pos << " + " << buffer_tile->getPosition() << std::endl; if (buffer_tile.Ground != null) { tile.addItem(buffer_tile.Ground.deepCopy()); } foreach (Item item_iter in buffer_tile.Items) { tile.addItem(item_iter.deepCopy()); } doodad_buffer_map.setTile(tile.getPosition(), tile); } } else if (brush.hasSingleObjects(ed.GetBrushVariation())) { Tile tile = new Tile(center_pos); int variation = ed.GetBrushVariation(); brush.draw(doodad_buffer_map, tile, variation); doodad_buffer_map.setTile(center_pos, tile); } } }