コード例 #1
0
        public List <Tile> getComposite(int variation)
        {
            List <Tile> empty = new List <Tile>();

            if (alternatives.Count() <= 0)
            {
                return(empty);
            }
            variation %= alternatives.Count();
            AlternativeBlock ab_ptr = alternatives[variation];

            //if (ab_ptr.composite_chance < 1) ab_ptr.composite_chance = 1;
            int chance = ab_ptr.composite_chance;

            if (chance < 1)
            {
                chance = 1;
            }

            int roll = random.Next(1, chance + 1);

            foreach (CompositeBlock cb in ab_ptr.composite_items)
            {
                if (roll <= cb.chance)
                {
                    return(cb.tiles);
                }
            }

            return(empty);
        }
コード例 #2
0
        public override void draw(GameMap map, Tile tile, object param = null)
        {
            int variation = 0;

            if (param != null)
            {
                variation = (int)param;
            }

            if (alternatives.Count() < 0)
            {
                return;
            }

            variation %= alternatives.Count();
            AlternativeBlock ab_ptr = alternatives[variation];


            int roll = random.Next(1, ab_ptr.single_chance + 1);

            foreach (SingleBlock sb in ab_ptr.single_items)
            {
                if (roll <= sb.chance)
                {
                    // Use this!

                    /*
                     * tile.startRemove();
                     * if  (Settings.GetBoolean(Key.RAW_LIKE_SIMONE) &&
                     *  (sb.item.Type.alwaysOnBottom && sb.item.Type.AlwaysOnTopOrder == 2))
                     * {
                     *  foreach (Item item in tile.Items)
                     *  {
                     *      if (item.getTopOrder() == sb.item.Type.AlwaysOnTopOrder)
                     *      {
                     *          tile.AddItemToRemove(item);
                     *          break;
                     *      }
                     *  }
                     * }*/
                    tile.RemoveItems();
                    tile.addItem(sb.item.deepCopy());
                    break;
                }
                roll -= sb.chance;
            }

            /*
             * if (clear_mapflags || clear_statflags)
             * {
             *  tile.setMapFlags(tile.getMapFlags() & (~clear_mapflags));
             *  tile.setMapFlags(tile.getStatFlags() & (~clear_statflags));
             * }   */
        }
コード例 #3
0
        public bool hasCompositeObjects(int ab)
        {
            if (alternatives.Count() <= 0)
            {
                return(false);
            }
            ab %= alternatives.Count();
            AlternativeBlock ab_ptr = alternatives[ab];

            return(ab_ptr.composite_chance > 0);
        }
コード例 #4
0
        public int getCompositeChance(int ab)
        {
            if (alternatives.Count() <= 0)
            {
                return(0);
            }
            ab %= alternatives.Count();
            AlternativeBlock ab_ptr = alternatives[ab];

            return(ab_ptr.composite_chance);
        }
コード例 #5
0
        public int getSingleChance(int ab)
        {
            if (alternatives.Count() <= 0)
            {
                return(0);
            }
            ab %= alternatives.Count();
            AlternativeBlock ab_ptr = alternatives[ab];

            return(ab_ptr.single_chance);
        }
コード例 #6
0
        private void loadAlternative(XElement node)
        {
            AlternativeBlock ab = null;

            foreach (XElement item_node in node.Elements("item"))
            {
                int chance;

                if ("".Equals(item_node.Attribute("chance").GetString()))
                {
                    Messages.AddWarning("Can't read chance tag of doodad item node.");
                    continue;
                }

                chance = item_node.Attribute("chance").GetInt32();

                Item item = Item.Create(Global.items.items[item_node.Attribute("id").GetInt32()]);
                if (item.Type == null)
                {
                    Messages.AddWarning("Can't read chance tag of doodad item node.");
                    continue;
                }
                ItemType it = item.Type;
                if (it.Id != 0)
                {
                    it.doodad_brush = this;
                }
                SingleBlock sb = new SingleBlock();
                sb.chance = chance;
                sb.item   = item;
                if (ab == null)
                {
                    ab = new AlternativeBlock();
                }
                ab.single_items.Add(sb);
                ab.single_chance += chance;
            }
            foreach (XElement composite_node in node.Elements("composite"))
            {
                int            chance;
                CompositeBlock cb = new CompositeBlock();
                if ("".Equals(composite_node.Attribute("chance").GetString()))
                {
                    Messages.AddWarning("Can't read chance tag of doodad item node.");
                    continue;
                }

                chance = composite_node.Attribute("chance").GetInt32();
                if (chance == 0)
                {
                    Messages.AddWarning("Can't read chance tag of doodad composite node.");
                    continue;
                }
                cb.chance = chance;
                if (ab == null)
                {
                    ab = new AlternativeBlock();
                }
                ab.composite_chance += cb.chance;
                cb.chance            = ab.composite_chance;

                foreach (XElement tile_composite_node in composite_node.Elements("tile"))
                {
                    int x = 0, y = 0, z = 0;

                    x = tile_composite_node.Attribute("x").GetInt32();
                    y = tile_composite_node.Attribute("y").GetInt32();
                    z = tile_composite_node.Attribute("z").GetInt32();

                    /*
                     *
                     * if (!readXMLValue(composite_child, "x", x))
                     * {
                     *  wxString warning;
                     *  warning = wxT("Couldn't read positionX values of composite tile node.");
                     *  warnings.push_back(warning);
                     *  composite_child = composite_child->next;
                     *  continue;
                     * }
                     * if (!readXMLValue(composite_child, "y", y))
                     * {
                     *  wxString warning;
                     *  warning = wxT("Couldn't read positionY values of composite tile node.");
                     *  warnings.push_back(warning);
                     *  composite_child = composite_child->next;
                     *  continue;
                     * }
                     * readXMLValue(composite_child, "z", z); // Don't halt on error
                     *
                     * if (x <= -0x8000 || x >= +0x8000)
                     * {
                     *  wxString warning;
                     *  warning = wxT("Invalid range of x value on composite tile node.");
                     *  warnings.push_back(warning);
                     *  composite_child = composite_child->next;
                     *  continue;
                     * }
                     * if (y <= -0x8000 || y >= +0x8000)
                     * {
                     *  wxString warning;
                     *  warning = wxT("Invalid range of y value on composite tile node.");
                     *  warnings.push_back(warning);
                     *  composite_child = composite_child->next;
                     *  continue;
                     * }
                     * if (z <= -0x8 || z >= +0x8)
                     * {
                     *  wxString warning;
                     *  warning = wxT("Invalid range of z value on composite tile node.");
                     *  warnings.push_back(warning);
                     *  composite_child = composite_child->next;
                     *  continue;
                     * } */

                    Tile t = new Tile(x, y, z);
                    foreach (XElement item_tile_composite_node in tile_composite_node.Elements("item"))
                    {
                        Item item = Item.Create(Global.items.items[item_tile_composite_node.Attribute("id").GetInt16()]);
                        if (item.Type != null)
                        {
                            t.addItem(item);
                            ItemType it = item.Type;
                            if (it.Id != 0)
                            {
                                it.doodad_brush = this;
                            }
                        }
                    }
                    if (t.size() > 0)
                    {
                        cb.tiles.Add(t);
                    }
                }
                ab.composite_items.Add(cb);
            }
            if (ab != null)
            {
                alternatives.Add(ab);
            }
        }