Example #1
0
        /// <summary>
        /// Stores an item in the specified tile.
        /// If the tile is already full or cannot accept all of the item(s) being added,
        /// then this method returns any excess.
        /// Otherwise, this method returns null.
        /// </summary>
        internal static Item StoreItem(Chunk chunk, Point2D mapLocation, Item item)
        {
            Tile tile     = WorldUtil.GetTile(mapLocation, chunk);
            Item overflow = null;

            if (tile.Item == null)
            {
                tile.Item = item;
            }
            else
            {
                Item final = Item.Combine(tile.Item, item, out overflow);
            }

            return(overflow);
        }
Example #2
0
        /// <summary>
        /// Stores an item in the specified tile.
        /// If the tile is already full or cannot accept all of the item(s) being added,
        /// then this method returns any excess.
        /// Otherwise, this method returns null.
        /// </summary>
        internal static Item StoreItem(Chunk chunk, Point2D mapLocation, Item item)
        {
            Tile tile     = WorldUtil.GetTile(mapLocation, chunk);
            Item overflow = null;

            if (tile.MainObject == null)
            {
                tile.MainObject = item;
            }
            else
            {
                Item existing = tile.MainObject as Item;
                if (existing == null)
                {
                    throw new UnexpectedStateException("Invalid addition of an item to a tile with an object of another type occuping the main object slot.");
                }
                tile.MainObject = Item.Combine(existing, item, out overflow);
            }

            return(overflow);
        }
Example #3
0
        /// <summary>
        /// Lets a chunk know that there is an item of the specified type in the specified tile position.
        /// </summary>
        private static void RememberWhichTile(Item item, Point2D mapLocation, Chunk chunk)
        {
            if (!chunk.Items.ContainsKey(item.ItemID))
            {
                //chunk.Items doesn't store one key and value for every item in the game upfront.
                chunk.Items.Add(item.ItemID, new RTree <Point2D>());
            }

            RTree <Point2D> itemLocations = chunk.Items[item.ItemID];
            List <Point2D>  result        = itemLocations.Contains(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y));

            if (result.Count > 0)
            {
                //The chunk already knows that there is an item of the specified type in the specified position.
            }
            else
            {
                Rectangle           r          = new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y);
                Tile                tile       = WorldUtil.GetTile(mapLocation, chunk);
                ComponentSelectable selectable = tile.GetExactComponent <ComponentSelectable>();

                itemLocations.Add(r, selectable.MapLocation);
            }
        }
Example #4
0
        /// <summary>
        /// Lets a chunk know that there is an item of the specified type in the specified tile position.
        /// </summary>
        internal static void RememberWhichTile(Item item, Point2D mapLocation, Chunk chunk, int dimension)
        {
            if (!chunk.Items.ContainsKey(item.ItemID))
            {
                //chunk.Items doesn't store one key and value for every item in the game upfront.
                chunk.Items.Add(item.ItemID, new RTree <Point2D>());
            }

            RTree <Point2D> itemLocations = chunk.Items[item.ItemID];
            List <Point2D>  result        = itemLocations.Contains(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y));

            if (result.Count > 0)
            {
                //The chunk already knows that there is an item of the specified type in the specified position.
            }
            else
            {
                itemLocations.Add(new Rectangle(mapLocation.X, mapLocation.Y, mapLocation.X, mapLocation.Y), WorldUtil.GetTile(mapLocation, chunk).MapLocation);
            }
        }