/// <summary>
        /// Determine if a living can move from srcLoc to dir, without considering the destination
        /// </summary>
        public static bool CanMoveFrom(this IEnvironmentObject env, IntVector3 srcLoc, Direction dir)
        {
            Debug.Assert(dir.IsValid());

            if (env.Contains(srcLoc) == false)
            {
                return(false);
            }

            var td = env.GetTileData(srcLoc);

            if (td.IsUndefined)
            {
                return(false);
            }

            // Perhaps this check is not needed
            if (td.IsWalkable == false)
            {
                return(false);
            }

            if (dir.IsPlanar())
            {
                return(true);
            }

            if (dir == Direction.Up)
            {
                return(td.ID == TileID.Stairs);
            }

            if (dir == Direction.Down)
            {
                return(true);
            }

            if (dir.ContainsDown())
            {
                return(true);
            }

            if (dir.ContainsUp() && env.Size.Depth > srcLoc.Z + 1)
            {
                if (env.GetTileData(srcLoc.Up).IsEmpty == false)
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        void AddNewJobs()
        {
            var c = this.SubJobs.Count;

            m_locs = m_area.Range().Where(p => !m_jobs.Any(i => i.Item1 == p) && m_environment.GetTileData(p).HasFellableTree).Take(3 - c);

            foreach (var p in m_locs)
            {
                var job = new AssignmentGroups.MoveFellTreeAssignment(this, m_environment, p);
                AddSubJob(job);
                m_jobs.Add(new Tuple <IntVector3, IJob>(p, job));
            }
        }
        /// <summary>
        /// Can the given tile be seen from any adjacent tile
        /// </summary>
        public static bool CanBeSeen(this IEnvironmentObject env, IntVector3 location)
        {
            foreach (var d in DirectionExtensions.PlanarUpDownDirections)
            {
                var p = location + d;
                if (env.Contains(p) && env.GetTileData(p).IsSeeThrough)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Can the given tile be seen from any direction
        /// </summary>
        public static bool CanBeSeen(IEnvironmentObject env, IntPoint3 location)
        {
            bool hidden = true;

            foreach (var d in DirectionExtensions.PlanarDirections)
            {
                var p = location + d;

                if (env.Contains(p) && env.GetTileData(p).IsSeeThrough)
                {
                    hidden = false;
                    break;
                }
            }

            if (hidden)
            {
                var p = location + Direction.Up;
                if (env.Contains(p) && env.GetTileData(p).IsSeeThroughDown)
                    hidden = false;
            }

            return !hidden;
        }
        /// <summary>
        /// Tile can be entered and stood upon
        /// </summary>
        public static bool CanEnter(this IEnvironmentObject env, IntVector3 location)
        {
            if (!env.Contains(location))
            {
                return(false);
            }

            var td = env.GetTileData(location);

            if (td.IsUndefined)
            {
                return(false);
            }

            return(td.IsWalkable);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Tile can be entered and stood upon
        /// </summary>
        public static bool CanEnter(IEnvironmentObject env, IntPoint3 location)
        {
            if (!env.Contains(location))
                return false;

            var td = env.GetTileData(location);

            if (td.IsUndefined)
                return false;

            var terrain = Terrains.GetTerrain(td.TerrainID);
            var interior = Interiors.GetInterior(td.InteriorID);
            var itemBlocks = (td.Flags & TileFlags.ItemBlocks) != 0;

            return terrain.IsSupporting && !terrain.IsBlocker && !interior.IsBlocker && !itemBlocks;
        }
            public IEnumerable <Direction> GetValidDirs(IntVector3 p)
            {
                var td = m_env.GetTileData(p);

                if (!td.IsSeeThrough)
                {
                    yield break;
                }

                foreach (var d in DirectionExtensions.PlanarUpDownDirections)
                {
                    var pp = p + d;
                    if (m_env.Contains(pp) && !m_tracker.GetVisible(pp))
                    {
                        yield return(d);
                    }
                }
            }
        /// <summary>
        /// Get possible positioning to perform mining to given location
        /// </summary>
        public static DirectionSet GetPossibleMiningPositioning(this IEnvironmentObject env, IntVector3 p,
                                                                MineActionType mineActionType)
        {
            DirectionSet ds;

            switch (mineActionType)
            {
            case MineActionType.Mine:
                ds = DirectionSet.Planar;

                if (env.GetTileData(p.Up).IsClear)
                {
                    ds |= DirectionSet.DownNorth |
                          DirectionSet.DownEast |
                          DirectionSet.DownSouth |
                          DirectionSet.DownWest;
                }

                break;

            case MineActionType.Stairs:
                ds = DirectionSet.Planar | DirectionSet.Down;

                if (env.CanMoveFrom(p.Down, Direction.Up))
                {
                    ds |= DirectionSet.Up;
                }

                break;

            default:
                throw new Exception();
            }

            return(ds);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Determine if a living can move from srcLoc to dir, without considering the destination
        /// </summary>
        public static bool CanMoveFrom(IEnvironmentObject env, IntPoint3 srcLoc, Direction dir)
        {
            Debug.Assert(dir.IsValid());

            if (env.Contains(srcLoc) == false)
                return false;

            var td = env.GetTileData(srcLoc);

            if (td.IsUndefined)
                return false;

            var srcTerrain = Terrains.GetTerrain(td.TerrainID);
            var srcInter = Interiors.GetInterior(td.InteriorID);
            var itemBlocks = (td.Flags & TileFlags.ItemBlocks) != 0;

            if (srcInter.IsBlocker || srcTerrain.IsBlocker || itemBlocks)
                return false;

            if (dir.IsPlanar())
                return true;

            if (dir == Direction.Up)
                return srcInter.ID == InteriorID.Stairs;

            if (dir == Direction.Down)
                return srcTerrain.ID == TerrainID.StairsDown;

            if (dir.ContainsDown())
            {
                return true;
            }

            if (dir.ContainsUp())
            {
                if (!srcTerrain.ID.IsSlope())
                    return false;

                if (env.GetTerrainID(srcLoc + Direction.Up) != TerrainID.Empty)
                    return false;

                return true;
            }

            return false;
        }