コード例 #1
0
        static DirectionSet GetPossiblePositioning(IEnvironmentObject env, IntPoint3 p, MineActionType mineActionType)
        {
            DirectionSet pos;

            var down = p + Direction.Down;

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

                    if (EnvironmentHelpers.CanMoveFrom(env, down, Direction.Up))
                        pos |= DirectionSet.Down;

                    break;

                case MineActionType.Stairs:
                    pos = DirectionSet.Planar | DirectionSet.Up;

                    if (EnvironmentHelpers.CanMoveFrom(env, down, Direction.Up))
                        pos |= DirectionSet.Down;

                    break;

                case MineActionType.Channel:
                    pos = DirectionSet.Planar;
                    break;

                default:
                    throw new Exception();
            }

            return pos;
        }
コード例 #2
0
ファイル: MineAssignment.cs プロジェクト: tomba/dwarrowdelf
 public MineAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location, MineActionType mineActionType)
     : base(parent)
 {
     m_environment = environment;
     m_location = location;
     m_mineActionType = mineActionType;
 }
コード例 #3
0
 protected MoveBaseAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location)
     : base(parent)
 {
     this.Environment = environment;
     this.Location = location;
     m_state = 0;
 }
コード例 #4
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        /* Parallel */
        /// <summary>
        /// Returns if dst can be reached from src
        /// </summary>
        public static bool CanReach(IEnvironmentObject env, IntVector3 src, IntVector3 dst, DirectionSet dstPositioning)
        {
            Debug.Assert(env != null);

            // Do pathfinding to both directions simultaneously to detect faster if the destination is blocked
            CancellationTokenSource cts = new CancellationTokenSource();

            AStarResult resBackward = null;
            AStarResult resForward = null;

            var taskForward = new Task(delegate
            {
                resForward = Find(env, src, DirectionSet.Exact, dst, dstPositioning, 200000, cts.Token);
            });
            taskForward.Start();

            var taskBackward = new Task(delegate
            {
                resBackward = Find(env, dst, dstPositioning.Reverse(), src, DirectionSet.Exact, 200000, cts.Token);
            });
            taskBackward.Start();

            Task.WaitAny(taskBackward, taskForward);

            cts.Cancel();

            Task.WaitAll(taskBackward, taskForward);

            if (resForward.Status == AStarStatus.Found || resBackward.Status == AStarStatus.Found)
                return true;
            else
                return false;
        }
コード例 #5
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        /// <summary>
        /// Find route from src to dst, using the given positionings
        /// </summary>
        public static AStarResult Find(IEnvironmentObject env, IntVector3 src, DirectionSet srcPositioning, IntVector3 dst, DirectionSet dstPositioning,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var initLocs = env.GetPositioningLocations(src, srcPositioning);
            var target = new AStarDefaultTarget(env, dst, dstPositioning);
            return Find(initLocs, target, maxNodeCount, cancellationToken);
        }
コード例 #6
0
ファイル: ConstructJob.cs プロジェクト: Fulborg/dwarrowdelf
        public ConstructJob(IJobObserver parent, ConstructMode mode, IItemObject[] items, IEnvironmentObject environment, IntPoint3 location)
            : base(parent)
        {
            m_mode = mode;
            m_items = items;
            m_environment = environment;
            m_location = location;

            m_state = 0;

            DirectionSet positioning;

            switch (mode)
            {
                case ConstructMode.Floor:
                    positioning = DirectionSet.Planar;
                    break;

                case ConstructMode.Pavement:
                    positioning = DirectionSet.Exact;
                    break;

                case ConstructMode.Wall:
                    positioning = DirectionSet.Planar;
                    break;

                default:
                    throw new Exception();
            }

            AddSubJob(new FetchItems(this, m_environment, m_location, items, positioning));
        }
コード例 #7
0
        public FellTreeParallelJob(IEnvironmentObject env, IntGrid3 area)
            : base(null)
        {
            m_environment = env;
            m_area = area;

            AddNewJobs();
        }
コード例 #8
0
 public ConstructAssignment(IJobObserver parent, ConstructMode mode, IEnvironmentObject environment, IntPoint3 location, IItemObject[] items)
     : base(parent)
 {
     m_mode = mode;
     m_environment = environment;
     m_location = location;
     m_items = items;
 }
コード例 #9
0
 public MoveConstructAssignment(IJobObserver parent, ConstructMode mode, IItemObject[] items, IEnvironmentObject environment, IntVector3 location)
     : base(parent, environment, items[0].Location)
 {
     m_mode = mode;
     m_items = items;
     m_environment = environment;
     m_location = location;
 }
コード例 #10
0
ファイル: InstallItemJob.cs プロジェクト: Fulborg/dwarrowdelf
        public InstallItemJob(IJobObserver parent, IItemObject item, IEnvironmentObject env, IntPoint3 location)
            : base(parent)
        {
            m_item = item;
            m_location = location;

            m_state = 0;

            AddSubJob(new AssignmentGroups.FetchItemAssignment(this, env, location, item));
        }
コード例 #11
0
 public FetchItemAssignment(IJobObserver parent, IEnvironmentObject env, IntVector3 location, IItemObject item, DirectionSet positioning)
     : base(parent)
 {
     this.Item = item;
     m_environment = env;
     m_location = location;
     m_state = State.None;
     m_positioning = positioning;
     this.LaborID = Dwarrowdelf.LaborID.Hauling;
 }
コード例 #12
0
ファイル: FetchItems.cs プロジェクト: Fulborg/dwarrowdelf
        public FetchItems(IJobObserver parent, IEnvironmentObject env, IntPoint3 location, IEnumerable<IItemObject> items, DirectionSet positioning)
            : base(parent)
        {
            foreach (var item in items)
            {
                var job = new AssignmentGroups.FetchItemAssignment(this, env, location, item, positioning);
                AddSubJob(job);
            }

            Debug.Assert(this.SubJobs.Count > 0);
        }
コード例 #13
0
ファイル: AIHelpers.cs プロジェクト: Fulborg/dwarrowdelf
        public static IEnumerable<ILivingObject> FindEnemies(IEnvironmentObject env, IntPoint3 location, int range, LivingCategory categories)
        {
            int maxSide = 2 * range + 1;

            var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z);

            return env.GetContents(rect)
                .OfType<ILivingObject>()
                .Where(o => (o.LivingCategory & categories) != 0)
                .OrderBy(o => (location - o.Location).Length);
        }
コード例 #14
0
ファイル: AIHelpers.cs プロジェクト: tomba/dwarrowdelf
        public static ILivingObject FindNearestEnemy(IEnvironmentObject env, IntVector3 location, int range, LivingCategory categories)
        {
            int maxSide = 2 * range + 1;

            var rect = new IntGrid2Z(location.X - maxSide / 2, location.Y - maxSide / 2, maxSide, maxSide, location.Z);

            return env.GetContents(rect)
                .OfType<ILivingObject>()
                .Where(o => (o.LivingCategory & categories) != 0)
                .OrderBy(o => (location - o.Location).Length)
                .FirstOrDefault();
        }
コード例 #15
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;
        }
コード例 #16
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        /// <summary>
        /// Find route from src to dest, finding the route in parallel from both directions
        /// </summary>
        public static IEnumerable<Direction> Find(IEnvironmentObject env, IntVector3 src, IntVector3 dest, DirectionSet positioning)
        {
            AStarResult resBackward;
            AStarResult resForward;

            ParallelFind(env, src, dest, positioning, out resBackward, out resForward);

            IEnumerable<Direction> dirs;

            if (resForward.Status == AStarStatus.Found)
                dirs = resForward.GetPath();
            else if (resBackward.Status == AStarStatus.Found)
                dirs = resBackward.GetPathReverse();
            else
                dirs = null;

            return dirs;
        }
コード例 #17
0
        /// <summary>
        /// For PlanarUpDown directions, return Direction.None if the direction cannot be entered,
        /// or the direction, adjusted by slopes (i.e. or'ed with Up or Down)
        /// </summary>
        public static Direction AdjustMoveDir(IEnvironmentObject env, IntPoint3 location, Direction dir)
        {
            Debug.Assert(dir.IsValid());
            Debug.Assert(dir != Direction.None);
            Debug.Assert(dir.IsPlanarUpDown());

            if (EnvironmentHelpers.CanMoveFromTo(env, location, dir))
                return dir;

            if (dir == Direction.Up || dir == Direction.Down)
                return Direction.None;

            if (EnvironmentHelpers.CanMoveFromTo(env, location, dir | Direction.Up))
                return dir | Direction.Up;

            if (EnvironmentHelpers.CanMoveFromTo(env, location, dir | Direction.Down))
                return dir | Direction.Down;

            return Direction.None;
        }
コード例 #18
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;
        }
コード例 #19
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        public static IEnumerable<AStarResult> FindMany(IEnvironmentObject env,
			IntVector3 src, DirectionSet srcPositioning, Func<IntVector3, bool> func,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var target = new AStarDelegateTarget(env, func);
            return FindMany(env, src, srcPositioning, target, maxNodeCount, cancellationToken);
        }
コード例 #20
0
 public void AddEnvironmentObjectToEnvironment(IEnvironmentObject obj)
 {
     environment.Add(obj);
 }
コード例 #21
0
        public ConstructJob(IJobObserver parent, ConstructMode mode, IItemObject[] items, IEnvironmentObject environment, IntVector3 location)
            : base(parent)
        {
            m_mode        = mode;
            m_items       = items;
            m_environment = environment;
            m_location    = location;

            m_state = 0;

            DirectionSet positioning;

            switch (mode)
            {
            case ConstructMode.Floor:
                positioning = DirectionSet.Planar;
                break;

            case ConstructMode.Pavement:
                positioning = DirectionSet.Exact;
                break;

            case ConstructMode.Wall:
                positioning = DirectionSet.Planar;
                break;

            default:
                throw new Exception();
            }

            AddSubJob(new FetchItems(this, m_environment, m_location, items, positioning));
        }
コード例 #22
0
 public MoveFellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntPoint3 location)
     : base(parent, environment, location)
 {
 }
コード例 #23
0
 public static double Tilt(this IEnvironmentObject environmentObject, double distanceTolerance = BH.oM.Geometry.Tolerance.Distance, double angleTolerance = BH.oM.Geometry.Tolerance.Angle)
 {
     return(environmentObject.Polyline().Tilt(distanceTolerance, angleTolerance));
 }
コード例 #24
0
 public FellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntPoint3 location)
     : base(parent)
 {
     m_environment = environment;
     m_location = location;
 }
コード例 #25
0
 public MoveConstructAssignment(IJobObserver parent, ConstructMode mode, IItemObject[] items, IEnvironmentObject environment, IntVector3 location)
     : base(parent, environment, items[0].Location)
 {
     m_mode        = mode;
     m_items       = items;
     m_environment = environment;
     m_location    = location;
 }
コード例 #26
0
ファイル: XYEnvironment.cs プロジェクト: tvn-cosine/aima.net
 public XYLocation getCurrentLocationFor(IEnvironmentObject eo)
 {
     return(envState.getCurrentLocationFor(eo));
 }
コード例 #27
0
ファイル: XYEnvironment.cs プロジェクト: tvn-cosine/aima.net
 public void addObjectToLocation(IEnvironmentObject eo, XYLocation loc)
 {
     moveObjectToAbsoluteLocation(eo, loc);
 }
コード例 #28
0
ファイル: ToLines.cs プロジェクト: theThorsager/BHoM_Engine
 public static List <Line> ToLines(this IEnvironmentObject environmentObject)
 {
     return(ToLines(environmentObject as dynamic));
 }
コード例 #29
0
 public AStarDelegateTarget(IEnvironmentObject env, Func <IntVector3, bool> func)
     : base(env)
 {
     m_func = func;
 }
コード例 #30
0
ファイル: Tilt.cs プロジェクト: RasmusCanfjorden/BHoM_Engine
 public static double Tilt(this IEnvironmentObject environmentObject)
 {
     return(environmentObject.Polyline().Tilt());
 }
コード例 #31
0
 protected AStarEnvTargetBase(IEnvironmentObject env)
 {
     m_env = env;
 }
コード例 #32
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
 /// <summary>
 /// Flood-find the nearest location for which func returns true
 /// </summary>
 public static AStarResult FindNearest(IEnvironmentObject env, IntVector3 src, Func<IntVector3, bool> func, int maxNodeCount = 200000)
 {
     var initLocs = env.GetPositioningLocations(src, DirectionSet.Exact);
     var target = new AStarDelegateTarget(env, func);
     return Find(initLocs, target, maxNodeCount);
 }
コード例 #33
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        static void ParallelFind(IEnvironmentObject env, IntVector3 src, IntVector3 dest, DirectionSet positioning, out AStarResult resBackward, out AStarResult resForward)
        {
            Debug.Assert(env != null);

            // Do pathfinding to both directions simultaneously to detect faster if the destination is blocked
            CancellationTokenSource cts = new CancellationTokenSource();

            AStarResult rb = null;
            AStarResult rf = null;

            var taskForward = new Task(delegate
            {
                rf = Find(env, src, DirectionSet.Exact, dest, positioning, 200000, cts.Token);
            });
            taskForward.Start();

            var taskBackward = new Task(delegate
            {
                rb = Find(env, dest, positioning.Reverse(), src, DirectionSet.Exact, 200000, cts.Token);
            });
            taskBackward.Start();

            Task.WaitAny(taskBackward, taskForward);

            cts.Cancel();

            Task.WaitAll(taskBackward, taskForward);

            resForward = rf;
            resBackward = rb;
        }
コード例 #34
0
 public static IEnvironmentObject ISetGeometry(this IEnvironmentObject environmentObject, ICurve curve)
 {
     return(SetGeometry(environmentObject as dynamic, curve as dynamic));
 }
コード例 #35
0
 public virtual void RemoveEnvironmentObject(IEnvironmentObject eo)
 {
     envObjects.Remove(eo);
     agents.Remove(eo as IAgent);
 }
コード例 #36
0
 public static T FindFragment <T>(this IEnvironmentObject environmentObject, Type fragmentType)
 {
     return((T)System.Convert.ChangeType(environmentObject.Fragments.Where(x => x.GetType() == fragmentType).FirstOrDefault(), fragmentType));
 }
コード例 #37
0
 public AStarAreaTarget(IEnvironmentObject env, IntGrid3 destination)
     : base(env)
 {
     m_destination = destination;
 }
コード例 #38
0
ファイル: Height.cs プロジェクト: theThorsager/BHoM_Engine
 public static double Height(this IEnvironmentObject environmentObject)
 {
     return(Height(environmentObject as dynamic));
 }
コード例 #39
0
 public static double Tilt(this IEnvironmentObject environmentObject)
 {
     return(environmentObject.Tilt(BH.oM.Geometry.Tolerance.Distance, BH.oM.Geometry.Tolerance.Angle));
 }
コード例 #40
0
 public MoveAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 destination, DirectionSet positioning)
     : base(parent, environment, positioning)
 {
     m_dest = destination;
 }
コード例 #41
0
ファイル: FetchItems.cs プロジェクト: Fulborg/dwarrowdelf
 public FetchItems(IJobObserver parent, IEnvironmentObject env, IntPoint3 location, IEnumerable<IItemObject> items)
     : this(parent, env, location, items, DirectionSet.Exact)
 {
 }
コード例 #42
0
 public MyTarget(IEnvironmentObject env, VisionTrackerGlobalFOV tracker)
 {
     m_env     = env;
     m_tracker = tracker;
 }
コード例 #43
0
 public void RemoveEnvironmentItem(IEnvironmentObject item)
 {
     environment.Remove(item);
 }
コード例 #44
0
 /// <summary>
 /// Return enterable positions around the given location, based on positioning
 /// </summary>
 public static IEnumerable <IntVector3> GetPositioningLocations(this IEnvironmentObject env, IntVector3 pos,
                                                                DirectionSet positioning)
 {
     return(positioning.ToSurroundingPoints(pos).Where(p => CanEnter(env, p)));
 }
コード例 #45
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        /// <summary>
        /// Find route from src to dest, finding the route in parallel from both directions
        /// </summary>
        public static IEnumerable<Direction> Find(IEnvironmentObject env, IntVector3 src, IntVector3 dest, DirectionSet positioning,
			out IntVector3 finalLocation)
        {
            AStarResult resBackward;
            AStarResult resForward;

            ParallelFind(env, src, dest, positioning, out resBackward, out resForward);

            IEnumerable<Direction> dirs;

            if (resForward.Status == AStarStatus.Found)
            {
                dirs = resForward.GetPath();
                finalLocation = resForward.LastNode.Loc;
            }
            else if (resBackward.Status == AStarStatus.Found)
            {
                dirs = resBackward.GetPathReverse();

                AStarNode n = resBackward.LastNode;
                while (n.Parent != null)
                    n = n.Parent;

                finalLocation = n.Loc;
            }
            else
            {
                dirs = null;
                finalLocation = new IntVector3();
            }

            return dirs;
        }
コード例 #46
0
        /// <summary>
        /// Determine if a living can move from srcLoc to dir
        /// </summary>
        public static bool CanMoveFromTo(this IEnvironmentObject env, IntVector3 srcLoc, Direction dir)
        {
            var dstLoc = srcLoc + dir;

            return(CanMoveFrom(env, srcLoc, dir) && CanMoveTo(env, dstLoc, dir));
        }
コード例 #47
0
ファイル: AStarHelpers.cs プロジェクト: tomba/dwarrowdelf
        public static IEnumerable<AStarResult> FindMany(IEnvironmentObject env,
			IntVector3 src, DirectionSet srcPositioning, IAStarTarget target,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var initLocs = env.GetPositioningLocations(src, srcPositioning);

            var astar = new AStar(initLocs, target);
            astar.MaxNodeCount = maxNodeCount;
            if (cancellationToken.HasValue)
                astar.CancellationToken = cancellationToken.Value;

            AStarStatus status;
            while ((status = astar.Find()) == AStarStatus.Found)
                yield return new AStarResult(status, astar.LastNode);
        }
コード例 #48
0
 public static Polyline Polyline(this IEnvironmentObject environmentObject)
 {
     return(Polyline(environmentObject as dynamic));
 }
コード例 #49
0
 public FellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location)
     : base(parent)
 {
     m_environment = environment;
     m_location    = location;
 }
コード例 #50
0
 public HaulAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 destination, DirectionSet positioning, IItemObject hauledItem)
     : base(parent, environment, positioning, hauledItem)
 {
     m_dest = destination;
 }
コード例 #51
0
 public MoveMineAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location, MineActionType mineActionType)
     : base(parent, environment, location)
 {
     m_mineActionType = mineActionType;
 }
コード例 #52
0
ファイル: Width.cs プロジェクト: theThorsager/BHoM_Engine
 public static double Width(this IEnvironmentObject environmentObject)
 {
     return(Width(environmentObject as dynamic));
 }
コード例 #53
0
ファイル: PatrolAssignment.cs プロジェクト: tomba/dwarrowdelf
 public PatrolAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3[] waypoints)
     : base(parent)
 {
     m_environment = environment;
     m_waypoints = waypoints;
 }
コード例 #54
0
ファイル: Azimuth.cs プロジェクト: LivAndersson/BHoM_Engine
 public static double Azimuth(this IEnvironmentObject environmentObject, Vector refVector)
 {
     return(environmentObject.Polyline().Azimuth(refVector));
 }
コード例 #55
0
ファイル: HaulAssignment.cs プロジェクト: tomba/dwarrowdelf
 public HaulAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 destination, DirectionSet positioning, IItemObject hauledItem)
     : base(parent, environment, positioning, hauledItem)
 {
     m_dest = destination;
 }
コード例 #56
0
 public MoveFellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location)
     : base(parent, environment, location)
 {
 }
コード例 #57
0
 public FetchItemAssignment(IJobObserver parent, IEnvironmentObject env, IntVector3 location, IItemObject item)
     : this(parent, env, location, item, DirectionSet.Exact)
 {
 }
コード例 #58
0
 public AStarDefaultTarget(IEnvironmentObject env, IntVector3 destination, DirectionSet positioning)
     : base(env)
 {
     m_destination = destination;
     m_positioning = positioning;
 }