Exemple #1
0
        public void SetWalkability(Position position, bool isWalkable)
        {
            float walkability = isWalkable ? 1f : 0f;

            _walkability.Set(position, walkability);
            _positionFlags.Set(position, 1);
            _pathfindingDataHolder.UpdateWalkability(position, walkability);
        }
Exemple #2
0
        public override IEnumerator Recalculating()
        {
            MatrixFloat walkabilityMap = _context.Walkability;

            foreach (Position cellMiddle in _waterMap.AllCellMiddles())
            {
                if (Math.Abs(_waterMap.Get(cellMiddle) - WaterIngredientGenerator.Ground) < 0.01f)
                {
                    Values.Set(cellMiddle, 1f);
                    walkabilityMap.Set(cellMiddle, 1f);
                }
                else
                {
                    Values.Set(cellMiddle, 0f);
                    walkabilityMap.Set(cellMiddle, 0f);
                }
            }

            yield return(new WaitForSeconds(0.1f));
        }
Exemple #3
0
        private Position BuildHouse(Area area)
        {
            bool ValidForBeingDoor(Position position)
            => position.y == area.Bounds.yMin && position.x > area.Bounds.xMin && position.x < area.Bounds.xMax - 1;

            Position doorPosition = RepeatedActionExecutor.Execute(() =>
            {
                var position = _rng.Choice(area.Perimeter);
                return(ValidForBeingDoor(position), position);
            });

            foreach (Position position in area.Perimeter)
            {
                if (position != doorPosition)
                {
                    Construct(position, House, _tileset.Wall);
                }
                else
                {
                    Construct(position, -1f, null);
                }
            }

            OsnowaBaseTile roofBaseTile = _tileset.Roof;

            foreach (Position housePosition in area.Positions)
            {
                Construct(housePosition, -1f, roofBaseTile);
                if (housePosition != doorPosition)
                {
                    _grid.SetWalkability(housePosition, 0f);
                    _walkability.Set(housePosition, 0f);
                }
            }

            BoundsInt boundsForRoofAdditions = area.Bounds;

            ++boundsForRoofAdditions.xMin;
            ++boundsForRoofAdditions.yMin;
            --boundsForRoofAdditions.xMax;
            --boundsForRoofAdditions.yMax;

            return(doorPosition);
        }