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; }
public MineAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location, MineActionType mineActionType) : base(parent) { m_environment = environment; m_location = location; m_mineActionType = mineActionType; }
protected MoveBaseAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location) : base(parent) { this.Environment = environment; this.Location = location; m_state = 0; }
/* 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; }
/// <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); }
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)); }
public FellTreeParallelJob(IEnvironmentObject env, IntGrid3 area) : base(null) { m_environment = env; m_area = area; AddNewJobs(); }
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; }
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; }
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)); }
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; }
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); }
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); }
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(); }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
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); }
public void AddEnvironmentObjectToEnvironment(IEnvironmentObject obj) { environment.Add(obj); }
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)); }
public MoveFellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntPoint3 location) : base(parent, environment, location) { }
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)); }
public FellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntPoint3 location) : base(parent) { m_environment = environment; m_location = location; }
public XYLocation getCurrentLocationFor(IEnvironmentObject eo) { return(envState.getCurrentLocationFor(eo)); }
public void addObjectToLocation(IEnvironmentObject eo, XYLocation loc) { moveObjectToAbsoluteLocation(eo, loc); }
public static List <Line> ToLines(this IEnvironmentObject environmentObject) { return(ToLines(environmentObject as dynamic)); }
public AStarDelegateTarget(IEnvironmentObject env, Func <IntVector3, bool> func) : base(env) { m_func = func; }
public static double Tilt(this IEnvironmentObject environmentObject) { return(environmentObject.Polyline().Tilt()); }
protected AStarEnvTargetBase(IEnvironmentObject env) { m_env = env; }
/// <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); }
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; }
public static IEnvironmentObject ISetGeometry(this IEnvironmentObject environmentObject, ICurve curve) { return(SetGeometry(environmentObject as dynamic, curve as dynamic)); }
public virtual void RemoveEnvironmentObject(IEnvironmentObject eo) { envObjects.Remove(eo); agents.Remove(eo as IAgent); }
public static T FindFragment <T>(this IEnvironmentObject environmentObject, Type fragmentType) { return((T)System.Convert.ChangeType(environmentObject.Fragments.Where(x => x.GetType() == fragmentType).FirstOrDefault(), fragmentType)); }
public AStarAreaTarget(IEnvironmentObject env, IntGrid3 destination) : base(env) { m_destination = destination; }
public static double Height(this IEnvironmentObject environmentObject) { return(Height(environmentObject as dynamic)); }
public static double Tilt(this IEnvironmentObject environmentObject) { return(environmentObject.Tilt(BH.oM.Geometry.Tolerance.Distance, BH.oM.Geometry.Tolerance.Angle)); }
public MoveAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 destination, DirectionSet positioning) : base(parent, environment, positioning) { m_dest = destination; }
public FetchItems(IJobObserver parent, IEnvironmentObject env, IntPoint3 location, IEnumerable<IItemObject> items) : this(parent, env, location, items, DirectionSet.Exact) { }
public MyTarget(IEnvironmentObject env, VisionTrackerGlobalFOV tracker) { m_env = env; m_tracker = tracker; }
public void RemoveEnvironmentItem(IEnvironmentObject item) { environment.Remove(item); }
/// <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))); }
/// <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; }
/// <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)); }
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); }
public static Polyline Polyline(this IEnvironmentObject environmentObject) { return(Polyline(environmentObject as dynamic)); }
public FellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location) : base(parent) { m_environment = environment; m_location = location; }
public HaulAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 destination, DirectionSet positioning, IItemObject hauledItem) : base(parent, environment, positioning, hauledItem) { m_dest = destination; }
public MoveMineAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location, MineActionType mineActionType) : base(parent, environment, location) { m_mineActionType = mineActionType; }
public static double Width(this IEnvironmentObject environmentObject) { return(Width(environmentObject as dynamic)); }
public PatrolAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3[] waypoints) : base(parent) { m_environment = environment; m_waypoints = waypoints; }
public static double Azimuth(this IEnvironmentObject environmentObject, Vector refVector) { return(environmentObject.Polyline().Azimuth(refVector)); }
public MoveFellTreeAssignment(IJobObserver parent, IEnvironmentObject environment, IntVector3 location) : base(parent, environment, location) { }
public FetchItemAssignment(IJobObserver parent, IEnvironmentObject env, IntVector3 location, IItemObject item) : this(parent, env, location, item, DirectionSet.Exact) { }
public AStarDefaultTarget(IEnvironmentObject env, IntVector3 destination, DirectionSet positioning) : base(env) { m_destination = destination; m_positioning = positioning; }