コード例 #1
0
ファイル: WallBrush.cs プロジェクト: squall-tech/akmapeditor
        public override void load(XElement brush)
        {
            look_id = brush.Attribute("lookid").GetUInt16();
            if (brush.Attribute("server_lookid").GetUInt16() != 0)
            {
                look_id = brush.Attribute("server_lookid").GetUInt16();
            }

            foreach (XElement wall_brush in brush.Elements("wall"))
            {
                int    alignment = 0;
                String type      = wall_brush.Attribute("type").GetString();
                if (!"".Equals(type))
                {
                    if (type == "vertical")
                    {
                        alignment = BorderType.WALL_VERTICAL;
                    }
                    else if (type == "horizontal")
                    {
                        alignment = BorderType.WALL_HORIZONTAL;
                    }
                    else if (type == "corner")
                    {
                        alignment = BorderType.WALL_NORTHWEST_DIAGONAL;
                    }
                    else if (type == "pole")
                    {
                        alignment = BorderType.WALL_POLE;
                    }
                    else if (type == "south end")
                    {
                        alignment = BorderType.WALL_SOUTH_END;
                    }
                    else if (type == "east end")
                    {
                        alignment = BorderType.WALL_EAST_END;
                    }
                    else if (type == "north end")
                    {
                        alignment = BorderType.WALL_NORTH_END;
                    }
                    else if (type == "west end")
                    {
                        alignment = BorderType.WALL_WEST_END;
                    }
                    else if (type == "south T")
                    {
                        alignment = BorderType.WALL_SOUTH_T;
                    }
                    else if (type == "east T")
                    {
                        alignment = BorderType.WALL_EAST_T;
                    }
                    else if (type == "west T")
                    {
                        alignment = BorderType.WALL_WEST_T;
                    }
                    else if (type == "north T")
                    {
                        alignment = BorderType.WALL_NORTH_T;
                    }
                    else if (type == "northwest diagonal")
                    {
                        alignment = BorderType.WALL_NORTHWEST_DIAGONAL;
                    }
                    else if (type == "northeast diagonal")
                    {
                        alignment = BorderType.WALL_NORTHEAST_DIAGONAL;
                    }
                    else if (type == "southwest diagonal")
                    {
                        alignment = BorderType.WALL_SOUTHWEST_DIAGONAL;
                    }
                    else if (type == "southeast diagonal")
                    {
                        alignment = BorderType.WALL_SOUTHEAST_DIAGONAL;
                    }
                    else if (type == "intersection")
                    {
                        alignment = BorderType.WALL_INTERSECTION;
                    }
                    else if (type == "untouchable")
                    {
                        alignment = BorderType.WALL_UNTOUCHABLE;
                    }
                    else
                    {
                        Messages.AddWarning("Unknown wall alignment '" + type + "'");
                        continue;
                    }
                }
                else
                {
                    Messages.AddWarning("Could not read type tag of wall node");
                    continue;
                }
                foreach (XElement item_wall_brush in wall_brush.Elements("item"))
                {
                    int id     = 0;
                    int chance = 0;

                    id = item_wall_brush.Attribute("id").GetInt32();

                    if (id == 0)
                    {
                        Messages.AddWarning("Could not read id tag of item node");
                        break;
                    }

                    chance = item_wall_brush.Attribute("chance").GetInt32();
                    ItemType it = Global.items.items[id];
                    if (it == null)
                    {
                        Messages.AddWarning("There is no itemtype with id " + id);
                        continue;
                    }

                    if ((it.brush != null) && (it.brush != this))
                    {
                        Messages.AddWarning("Itemtype id " + id + " already has a brush");
                        continue;
                    }
                    it.IsWall          = true;
                    it.brush           = this;
                    it.BorderAlignment = alignment;

                    WallType wt = new WallType();
                    //issi é la do tipo
                    wall_items[alignment].total_chance += chance;
                    wt.chance = wall_items[alignment].total_chance;
                    wt.id     = (UInt16)id;
                    wall_items[alignment].items.Add(wt);
                }
                foreach (XElement door_wall_brush in wall_brush.Elements("door"))
                {
                    String type_door = "";
                    int    chance    = 0;
                    bool   isOpen;
                    bool   hate = false;
                    int    id   = door_wall_brush.Attribute("id").GetInt32();
                    if (id == 0)
                    {
                        Messages.AddWarning("Could not read id tag of item node");
                        break;
                    }
                    chance    = door_wall_brush.Attribute("chance").GetInt32();
                    type_door = door_wall_brush.Attribute("type").GetString();
                    if (!"".Equals(type_door))
                    {
                        String strVal = door_wall_brush.Attribute("open").GetString();
                        if (!"".Equals(strVal))
                        {
                            isOpen = Generic.isTrueString(strVal);
                        }
                        else
                        {
                            isOpen = true;
                            if ((!type_door.Equals("window")) && (!type_door.Equals("any window")) && (!type_door.Equals("hatch window")))
                            {
                                Messages.AddWarning("Could not read open tag of item node");
                                break;
                            }
                        }
                    }
                    else
                    {
                        Messages.AddWarning("Could not read type tag of item node");
                        break;
                    }

                    if (!"".Equals(door_wall_brush.Attribute("type").GetString()))
                    {
                        hate = Generic.isTrueString(door_wall_brush.Attribute("type").GetString());
                    }

                    ItemType it = Global.items.items[id];
                    if (it == null)
                    {
                        Messages.AddWarning("There is no itemtype with id " + id);
                        continue;
                    }
                    it.IsWall          = true;
                    it.brush           = this;
                    it.IsBrushDoor     = true;
                    it.WallHateMe      = hate;
                    it.IsOpen          = isOpen;
                    it.BorderAlignment = alignment;

                    DoorType dt          = new DoorType();
                    bool     all_windows = false;
                    bool     all_doors   = false;
                    if (type_door == "normal")
                    {
                        dt.type = EDoorType.WALL_DOOR_NORMAL;
                    }
                    else if (type_door == "locked")
                    {
                        dt.type = EDoorType.WALL_DOOR_LOCKED;
                    }
                    else if (type_door == "quest")
                    {
                        dt.type = EDoorType.WALL_DOOR_QUEST;
                    }
                    else if (type_door == "magic")
                    {
                        dt.type = EDoorType.WALL_DOOR_MAGIC;
                    }
                    else if (type_door == "archway")
                    {
                        dt.type = EDoorType.WALL_ARCHWAY;
                    }
                    else if (type_door == "window")
                    {
                        dt.type = EDoorType.WALL_WINDOW;
                    }
                    else if (type_door == "hatch_window" || type_door == "hatch window")
                    {
                        dt.type = EDoorType.WALL_HATCH_WINDOW;
                    }
                    else if (type_door == "any door")
                    {
                        all_doors = true;
                    }
                    else if (type_door == "any window")
                    {
                        all_windows = true;
                    }
                    else if (type_door == "any")
                    {
                        all_windows = true;
                        all_doors   = true;
                    }
                    else
                    {
                        Messages.AddWarning("Unknown door type '" + type_door + "'");
                        break;
                    }
                    dt.id = (UInt16)id;
                    if (all_windows)
                    {
                        dt.type = EDoorType.WALL_WINDOW; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_HATCH_WINDOW; door_items[alignment].Add(dt);
                    }

                    if (all_doors)
                    {
                        dt.type = EDoorType.WALL_ARCHWAY; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_NORMAL; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_LOCKED; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_QUEST; door_items[alignment].Add(dt);
                        dt.type = EDoorType.WALL_DOOR_MAGIC; door_items[alignment].Add(dt);
                    }
                    if (!all_doors && !all_windows)
                    {
                        door_items[alignment].Add(dt);
                    }
                }
            }
            foreach (XElement efriend_brush in brush.Elements("friend"))
            {
                String friendName = efriend_brush.Attribute("name").GetString();
                if (friendName != "")
                {
                    if ("all".Equals(friendName))
                    {
                        //nada
                    }
                    else
                    {
                        Brush friend_brush = Brushes.getInstance().getBrush(friendName);
                        if (friend_brush != null)
                        {
                            friends.Add(friend_brush.getID());
                        }
                        else
                        {
                            Messages.AddWarning("Brush '" + friendName + "' is not defined.");
                        }
                        String redirect = efriend_brush.Attribute("redirect").GetString();
                        if ((!"".Equals(redirect)) && Generic.isTrueString(redirect))
                        {
                            WallBrush rd = null;
                            try
                            {
                                rd = (WallBrush)friend_brush;
                            }
                            catch// (Exception ex)
                            {
                                Messages.AddWarning("Wall brush redirect link: '" + redirect + "' is not a wall brush.");
                            }
                            if (redirect_to == null)
                            {
                                redirect_to = rd;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: WallBrush.cs プロジェクト: squall-tech/akmapeditor
        public static void doWalls(GameMap map, Tile tile)
        {
            int x = tile.Position.X;
            int y = tile.Position.Y;
            int z = tile.Position.Z;

            List <Item> items_to_add   = new List <Item>();
            List <Item> items_to_erase = new List <Item>();

            foreach (Item wall in tile.Items)
            {
                if (!wall.Type.IsWall)
                {
                    continue;
                }
                WallBrush wall_brush = wall.getWallBrush();
                if (wall_brush == null)
                {
                    continue;
                }


                if (wall_brush as WallDecorationBrush != null)
                {
                    items_to_add.Add(wall);
                    continue;
                }


                bool[] neighbours = new bool[4];
                if (x == 0)
                {
                    if (y == 0)
                    {
                        neighbours[0] = false;
                        neighbours[1] = false;
                        neighbours[2] = hasMatchingWallBrushAtTile(map, wall_brush, x + 1, y, z);
                        neighbours[3] = hasMatchingWallBrushAtTile(map, wall_brush, x, y + 1, z);
                    }
                    else
                    {
                        neighbours[0] = hasMatchingWallBrushAtTile(map, wall_brush, x, y - 1, z);
                        neighbours[1] = false;
                        neighbours[2] = hasMatchingWallBrushAtTile(map, wall_brush, x + 1, y, z);
                        neighbours[3] = hasMatchingWallBrushAtTile(map, wall_brush, x, y + 1, z);
                    }
                }
                else if (y == 0)
                {
                    neighbours[0] = false;
                    neighbours[1] = hasMatchingWallBrushAtTile(map, wall_brush, x - 1, y, z);
                    neighbours[2] = hasMatchingWallBrushAtTile(map, wall_brush, x + 1, y, z);
                    neighbours[3] = hasMatchingWallBrushAtTile(map, wall_brush, x, y + 1, z);
                }
                else
                {
                    neighbours[0] = hasMatchingWallBrushAtTile(map, wall_brush, x, y - 1, z);
                    neighbours[1] = hasMatchingWallBrushAtTile(map, wall_brush, x - 1, y, z);
                    neighbours[2] = hasMatchingWallBrushAtTile(map, wall_brush, x + 1, y, z);
                    neighbours[3] = hasMatchingWallBrushAtTile(map, wall_brush, x, y + 1, z);
                }
                UInt32 tiledata = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (neighbours[i])
                    {
                        tiledata |= (UInt32)1 << i;
                    }
                }
                bool exit = false;
                for (int i = 0; i < 2; ++i)
                {
                    if (exit)
                    {
                        break;
                    }

                    int bt;
                    if (i == 0)
                    {
                        bt = Border_Types.full_border_types[tiledata];
                    }
                    else
                    {
                        bt = Border_Types.half_border_types[tiledata];
                    }
                    if (wall.getWallAlignment() == BorderType.WALL_UNTOUCHABLE)
                    {
                        items_to_add.Add(wall);
                        // items_to_remove.Add(wall);
                        exit = true;
                    }
                    else if (wall.getWallAlignment() == bt)
                    {
                        items_to_add.Add(wall);
                        //it = tile->items.erase(it);
                        exit = true;
                        //while(it != tile->items.end()) {
                        //  todo
                        // }
                    }
                    else
                    {
                        UInt16    id        = 0;
                        WallBrush try_brush = wall_brush;

                        while (true)
                        {
                            if (try_brush == null)
                            {
                                break;
                            }
                            if (id != 0)
                            {
                                break;
                            }

                            WallNode wn = try_brush.wall_items[(int)bt];
                            if (wn.total_chance <= 0)
                            {
                                if (wn.items.Count() == 0)
                                {
                                    try_brush = try_brush.redirect_to;
                                    if (try_brush == wall_brush)
                                    {
                                        break;                                                     // To prevent infinite loop
                                    }
                                    continue;
                                }
                                else
                                {
                                    id = wn.items[0].id;
                                }
                            }
                            else
                            {
                                int chance = random.Next(1, wn.total_chance + 1);
                                foreach (WallType node_iter in wn.items)
                                {
                                    if (chance <= node_iter.chance)
                                    {
                                        id = node_iter.id;
                                        break;
                                    }
                                }
                            }
                            // Propagate down the chain
                            try_brush = try_brush.redirect_to;
                            if (try_brush == wall_brush)
                            {
                                break;                                             // To prevent infinite loop
                            }
                        }
                        if (try_brush == null && id == 0)
                        {
                            if (i == 1)
                            {
                                //++it;
                            }
                            continue;
                        }
                        else
                        {
                            // If there is such an item, add it to the tile
                            Item new_wall = Item.Create(id);
                            if (wall.isSelected())
                            {
//						        new_wall.isSelected = true;
                            }
                            items_to_add.Add(new_wall);
                            exit = true;
                            //++it;
                        }
                    }
                }
            }
            tile.cleanWalls(null);
            foreach (Item item in items_to_add)
            {
                tile.addWallItem(item);
            }
        }
コード例 #3
0
        public override void draw(GameMap map, Tile tile, object param = null)
        {
            List <Pair <Item, Item> > replaceItems = new List <Pair <Item, Item> >();

            foreach (Item item in tile.Items)
            {
                if (item.Type.IsWall == false)
                {
                    continue;
                }
                WallBrush wb = item.getWallBrush();
                if (wb == null)
                {
                    continue;
                }

                int wall_alignment = item.getWallAlignment();

                ushort discarded_id  = 0;        // The id of a discarded match
                bool   close_match   = false;
                bool   perfect_match = false;

                bool open = false;
                if (param != null)
                {
                    open = (Boolean)param;
                }

                if (item.Type.IsBrushDoor)
                {
                    open = item.Type.IsOpen;
                }

                WallBrush test_brush = wb;
                do
                {
                    foreach (WallBrush.DoorType dt in test_brush.door_items[wall_alignment])
                    {
                        if (dt.type == doortype)
                        {
                            ItemType it = Global.items.items[dt.id];

                            if (it.IsOpen == open)
                            {
                                //      item = Item.transformItem(item, dt.id, tile);
                                //replaceItems.Add(new Pair<Item,Item>(item,Item.transformItem(item, dt.id, tile)));
                                item.setID(dt.id);
                                perfect_match = true;
                                break;
                            }
                            else if (close_match == false)
                            {
                                discarded_id = dt.id;
                                close_match  = true;
                            }
                            if (!close_match && discarded_id == 0)
                            {
                                discarded_id = dt.id;
                            }
                        }
                    }
                    test_brush = test_brush.redirect_to;
                    if (perfect_match)
                    {
                        break;
                    }
                } while (test_brush != wb && test_brush != null);

                // If we've found no perfect match, use a close-to perfect
                if (perfect_match == false && discarded_id != 0)
                {
                    //   item = Item.transformItem(item, discarded_id, tile);
                    // replaceItems.Add(new Pair<Item, Item>(item, Item.transformItem(item, discarded_id, tile)));
                    item.setID(discarded_id);
                }

                /* HOUSE
                 *      if (Settings.getInteger(Config.AUTO_ASSIGN_DOORID) && tile.isHouseTile())
                 *      {
                 *              Map mmap = map as Map;
                 *              Door door = item as Door;
                 *              if (mmap != null && door != null)
                 *              {
                 *                      House house = mmap.houses.getHouse(tile.getHouseID());
                 *                      Debug.Assert(house);
                 *                      Map real_map = map as Map;
                 *                      if (real_map != null)
                 *                      {
                 *                              door.setDoorID(house.getEmptyDoorID());
                 *                      }
                 *              }
                 *      }*/
                /*
                 *          // We need to consider decorations!
                 *      while (true)
                 *      {
                 *              // Vector has been modified, before we can use the iterator again we need to find the wall item again
                 *              item_iter = tile.items.begin();
                 *              while (true)
                 *              {
                 *                      if (item_iter == tile.items.end())
                 *                      {
                 *                              return;
                 *                      }
                 *                      if (*item_iter == item)
                 *                      {
                 ++item_iter;
                 *                              if (item_iter == tile.items.end())
                 *                              {
                 *                                      return;
                 *                              }
                 *                              break;
                 *                      }
                 ++item_iter;
                 *              }
                 *              // Now it points to the correct item!
                 *
                 *              item = *item_iter;
                 *              if (item.isWall())
                 *              {
                 *                      if (WallDecorationBrush * wdb = item.getWallBrush() as WallDecorationBrush)
                 *                      {
                 *                              // We got a decoration!
                 *                              for (List<WallBrush.DoorType>.Enumerator iter = wdb.door_items[wall_alignment].begin(); iter.MoveNext();)
                 *                              {
                 *                                      WallBrush.DoorType dt = iter.Current;
                 *                                      if (dt.type == doortype)
                 *                                      {
                 *                                              Debug.Assert(dt.id);
                 *                                              ItemType it = item_db[dt.id];
                 *                                              Debug.Assert(it.id != 0);
                 *
                 *                                              if (it.isOpen == open)
                 *                                              {
                 *                                                      item = transformItem(item, dt.id, tile);
                 *                                                      perfect_match = true;
                 *                                                      break;
                 *                                              }
                 *                                              else if (close_match == false)
                 *                                              {
                 *                                                      discarded_id = dt.id;
                 *                                                      close_match = true;
                 *                                              }
                 *                                              if (!close_match && discarded_id == 0)
                 *                                              {
                 *                                                      discarded_id = dt.id;
                 *                                              }
                 *                                      }
                 *                              }
                 *                              // If we've found no perfect match, use a close-to perfect
                 *                              if (perfect_match == false && discarded_id != 0)
                 *                              {
                 *                                      item = transformItem(item, discarded_id, tile);
                 *                              }
                 *                              continue;
                 *                      }
                 *              }
                 *              break;
                 *      } */
                // If we get this far in the loop we should return
            }

            foreach (Pair <Item, Item> replace in replaceItems)
            {
                int index = tile.Items.IndexOf(replace.first);
                if (index > -1)
                {
                    tile.Items.RemoveAt(index);
                    tile.Items.Insert(index, replace.second);
                }
            }
        }
コード例 #4
0
ファイル: Brushes.cs プロジェクト: squall-tech/akmapeditor
        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);
            }
        }
コード例 #5
0
        public override bool canDraw(GameMap map, Position pos)
        {
            Tile tile = map.getTile(pos);

            if (tile == null)
            {
                return(false);
            }
            Item item = tile.getWall();

            if (item == null)
            {
                return(false);
            }
            WallBrush wb = item.getWallBrush();

            if (wb == null)
            {
                return(false);
            }

            int wall_alignment = item.getWallAlignment();

            ushort discarded_id = 0; // The id of a discarded match
            bool   close_match  = false;

            bool open = false;

            if (item.Type.IsBrushDoor)
            {
                open = item.Type.IsOpen;
            }

            WallBrush test_brush = wb;

            do
            {
                foreach (WallBrush.DoorType dt in test_brush.door_items[wall_alignment])
                {
                    if (dt.type == doortype)
                    {
                        //Debug.Assert(dt.id);
                        ItemType it = Global.items.items[dt.id];
                        if (it.IsOpen == open)
                        {
                            return(true);
                        }
                        else if (close_match == false)
                        {
                            discarded_id = dt.id;
                            close_match  = true;
                        }
                        if (!close_match && discarded_id == 0)
                        {
                            discarded_id = dt.id;
                        }
                    }
                }
                test_brush = test_brush.redirect_to;
            } while (test_brush != wb && test_brush != null);
            // If we've found no perfect match, use a close-to perfect
            if (discarded_id != 0)
            {
                return(true);
            }

            return(false);
        }