Exemple #1
0
        // Constructs an xSize by ySize map. Default Tile set to TileBasicFloor.
        public Map(UInt16 xSize, UInt16 ySize, Int32 seed)
        {
            // creates and fills the tile array
            this._xMax = xSize;
            this._yMax = ySize;

            this._pixelMaxX = (UInt32)(xSize * Constants.TileSize);
            this._pixelMaxY = (UInt32)(ySize * Constants.TileSize);

            _tiles         = new Tile[xSize, ySize];
            _visibilityMap = new float[xSize, ySize];
            // tiles = new TileBasicFloor[xSize, ySize];
            for (Int32 i = 0; i < xSize; i++)
            {
                for (Int32 j = 0; j < ySize; j++)
                {
                    _tiles[i, j] = new TilePassable(this, new Coords(CoordsType.Tile, i, j), Constants.TileGeneratorGrass);
                }
            }

            this._passabilityMap = new BitArray[xSize];
            for (int i = 0; i < xSize; ++i)
            {
                _passabilityMap[i] = new BitArray(ySize);
            }

            this._myCollider          = new Collider(xSize, ySize, Constants.TileSize, Constants.TileSize, _passabilityMap);
            this._myVisibilityTracker = new VisiblityTracker(xSize, ySize, Constants.TileSize, Constants.TileSize, _passabilityMap, _visibilityMap);
            this._myPathfinder        = new Pathfinder(_passabilityMap);

            // initializes the random number generator associated with this map
            this._randomator = new RandomStuff(seed);
        }
Exemple #2
0
        public void CreateItem(Coords startPoint, ItemGenerator item)
        {
            Item newItem = new Item(this.IssueItemID(), item);

            this.CatalogueAddItemTo(newItem.ID, newItem);
            //Coords bedLocation = new Coords((Int32)((bottomRight.X + topLeft.X) * 0.5), (Int32)((bottomRight.Y + topLeft.Y) * 0.5));
            TilePassable itemTile = this.GetTile(startPoint) as TilePassable;

            itemTile.InventoryAddItem(newItem);
        }
        /// <summary>
        /// Returns list of possible moves, sorted by
        /// 1) amount of increase, 2) distance to influence map source
        /// THIS METHOD SHOULD BE IMPROVED
        /// </summary>
        public List <Direction> PossibleMoves(Coords currentPosition)
        {
            List <Direction> dirList = new List <Direction>();

            // Dangerous cast?
            TilePassable currentTile = (TilePassable)this._currentMap.GetTile(currentPosition);

            for (byte i = 1; i <= 8; i++)
            {
                Direction currentDir = (Direction)i;
                if (currentTile.AllowedMovesCheckInDirection(currentDir))
                {
                    dirList.Add(currentDir);
                }
            }

            dirList.Sort(
                delegate(Direction d1, Direction d2)
            {
                Coords c1 = StaticMathFunctions.CoordsNeighboringInDirection(currentPosition, d1);
                Coords c2 = StaticMathFunctions.CoordsNeighboringInDirection(currentPosition, d2);

                Int32 returnVal = (this._influenceMap[c1.X, c1.Y]).CompareTo(this._influenceMap[c2.X, c2.Y]);

                if (returnVal == 0)
                {
                    returnVal = (StaticMathFunctions.DistanceBetweenTwoCoordsEucledean(c1, currentPosition)).CompareTo
                                    (StaticMathFunctions.DistanceBetweenTwoCoordsEucledean(c2, currentPosition));
                }

                return(returnVal);
            }
                );

            return(dirList);
        }
        // Constructs an xSize by ySize map. Default Tile set to TileBasicFloor.
        public Map(UInt16 xSize, UInt16 ySize, Int32 seed)
        {
            // creates and fills the tile array
            this._xMax = xSize;
            this._yMax = ySize;

            this._pixelMaxX = (UInt32)(xSize * Constants.TileSize);
            this._pixelMaxY = (UInt32)(ySize * Constants.TileSize);

            _tiles = new Tile[xSize, ySize];
            _visibilityMap = new float[xSize, ySize];
            // tiles = new TileBasicFloor[xSize, ySize];
            for (Int32 i = 0; i < xSize; i++)
            {
                for (Int32 j = 0; j < ySize; j++)
                {
                    _tiles[i, j] = new TilePassable(this, new Coords(CoordsType.Tile, i, j), Constants.TileGeneratorGrass);
                }
            }

            this._passabilityMap = new BitArray[xSize];
            for (int i = 0; i < xSize; ++i)
            {
                _passabilityMap[i] = new BitArray(ySize);
            }

            this._myCollider = new Collider(xSize, ySize, Constants.TileSize, Constants.TileSize, _passabilityMap);
            this._myVisibilityTracker = new VisiblityTracker(xSize, ySize, Constants.TileSize, Constants.TileSize, _passabilityMap, _visibilityMap);
            this._myPathfinder = new Pathfinder(_passabilityMap);

            // initializes the random number generator associated with this map
            this._randomator = new RandomStuff(seed);
        }
 public Inventory(TilePassable ownerTile)
     : this()
 {
     this._ownerTile = ownerTile;
     this._ownerCreature = null;
 }
 public Inventory(Creature owner)
     : this()
 {
     this._ownerTile = null;
     this._ownerCreature = owner;
 }
 public Inventory(TilePassable ownerTile)
     : this()
 {
     this._ownerTile     = ownerTile;
     this._ownerCreature = null;
 }
 public Inventory(Creature owner)
     : this()
 {
     this._ownerTile     = null;
     this._ownerCreature = owner;
 }
        /// Generates the influence map.
        /// Uses a silly recursive algorithm.
        /// Stopping conditions: Let's use two, to avoid stupid infinite loops.
        /// One is a distance threshold check.
        // Second is a min influence threshold check.

        /// <summary>
        /// Generates the influence map.
        /// Uses a silly recursive algorithm.
        /// Stopping conditions: Let's use two, to avoid stupid infinite loops.
        /// One is a distance threshold check.
        /// Second is a min influence threshold check.
        /// </summary>
        public void GenerateInfluenceMap()
        {
            // boolean array to keep note of which tiles have been processed
            //BitArray[,] takenCareOf = new BitArray[_currentMap.BoundX, _currentMap.BoundY];
            BitArray[] takenCareOf = new BitArray[_currentMap.BoundX];
            for (int i = 0; i < _currentMap.BoundX; ++i)
            {
                takenCareOf[i] = new BitArray(_currentMap.BoundY);
            }
            takenCareOf[Source.X][Source.Y] = true;

            // sets up two queues - one for the current pass, one for the next one
            // distance increments by one at each pass
            // if too slow, the process should be broken up so it does a number of passes each tick
            Queue <Coords> currentQueue = new Queue <Coords>();
            Queue <Coords> nextQueue    = new Queue <Coords>();

            currentQueue.Enqueue(_source);

            UInt32 currentDistance = 0;

            // main loop
            // Stopping conditions: the two queues are exhausted, OR InfluenceMapMaxDistance is reached
            while
            (
                ((currentQueue.Count > 0) & (nextQueue.Count > 0))
                |
                (currentDistance < Constants.InfluenceMapMaxDistance)
            )
            {
                // Checks if it's time to start the next pass
                if (currentQueue.Count == 0)
                {
                    currentQueue = nextQueue;
                    nextQueue    = new Queue <Coords>();
                    currentDistance++;
                    continue;
                }

                Coords       currentCoords = currentQueue.Peek();
                TilePassable currentTile   = (TilePassable)CurrentMap.GetTile(currentCoords);

                // Analyzes the neighbors of the current Tile for possible additions to nextQueue
                for (byte i = 1; i <= 8; i++)
                {
                    Direction currentDir = (Direction)i;
                    if (currentTile.AllowedMovesCheckInDirection(currentDir))
                    {
                        Coords toCheck = StaticMathFunctions.CoordsNeighboringInDirection(currentCoords, currentDir);
                        if (!takenCareOf[toCheck.X][toCheck.Y])
                        {
                            nextQueue.Enqueue(toCheck);
                            takenCareOf[toCheck.X][toCheck.Y] = true;
                        }
                    }
                }

                float newVal = _f(currentDistance);

                // Check to avert infnite / excessively deep loop
                if (newVal > Constants.InfluenceMapMinThreshold)
                {
                    this.SetMapValue(currentCoords, newVal);
                }

                currentQueue.Dequeue();
            }
        }