private static void SetupForProcessing(Variable variable, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining) { if (variable.Default != null) { SetupForProcessing(variable.Default, true, ref nextActivity, ref activitiesRemaining); } }
private static void SetupForProcessing(IList <RuntimeArgument> arguments, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining) { for (int i = 0; i < arguments.Count; i++) { SetupForProcessing(arguments[i], ref nextActivity, ref activitiesRemaining); } }
public override bool Cancel(Actor self, bool keepQueue = false) { if (ChildActivity == null) { return(base.Cancel(self, keepQueue)); } // Although MoveFirstHalf and MoveSecondHalf can't be interrupted, // we prevent them from moving forever by removing the path. if (path != null) { path.Clear(); } // Remove queued activities if (!keepQueue && NextInQueue != null) { NextInQueue = null; } // In current implementation, ChildActivity can be Turn, MoveFirstHalf and MoveSecondHalf. // Turn may be interrupted freely while they are turning. // Unlike Turn, MoveFirstHalf and MoveSecondHalf are not Interruptable, but clearing the // path guarantees that they will return as soon as possible, once the actor is back in a // valid position. // This means that it is safe to unconditionally return true, which avoids breaking parent // activities that rely on cancellation succeeding (but not necessarily immediately ChildActivity.Cancel(self, false); return(true); }
public override bool Tick(Actor self) { // We are not currently attacking a target, so scan for new targets. if (!IsCanceling && ChildActivity != null && ChildActivity.NextActivity == null && autoTarget != null) { // ScanForTarget already limits the scanning rate for performance so we don't need to do that here. var target = autoTarget.ScanForTarget(self, false, true); if (target.Type != TargetType.Invalid) { // We have found a target so cancel the current move activity and queue attack activities. ChildActivity.Cancel(self); var attackBases = autoTarget.ActiveAttackBases; foreach (var ab in attackBases) { QueueChild(ab.GetAttackActivity(self, AttackSource.AttackMove, target, false, false)); } // Make sure to continue moving when the attack activities have finished. QueueChild(getInner()); } } // The last queued childactivity is guaranteed to be the inner move, so if the childactivity // queue is empty it means we have reached our destination and there are no more enemies on our path. return(TickChild(self)); }
/// <summary> /// Prints the activity tree, starting from the top or optionally from a given origin. /// /// Call this method from any place that's called during a tick, such as the Tick() method itself or /// the Before(First|Last)Run() methods. The origin activity will be marked in the output. /// </summary> /// <param name="self">The actor performing this activity.</param> /// <param name="origin">Activity from which to start traversing, and which to mark. If null, mark the calling activity, and start traversal from the top.</param> /// <param name="level">Initial level of indentation.</param> protected void PrintActivityTree(Actor self, Activity origin = null, int level = 0) { if (origin == null) { self.CurrentActivity.PrintActivityTree(self, this); } else { Console.Write(new string(' ', level * 2)); if (origin == this) { Console.Write("*"); } Console.WriteLine(GetType().ToString().Split('.').Last()); if (ChildActivity != null) { ChildActivity.PrintActivityTree(self, origin, level + 1); } if (NextActivity != null) { NextActivity.PrintActivityTree(self, origin, level); } } }
/// <summary> /// Prints the activity tree, starting from the root or optionally from a given origin. /// /// Call this method from any place that's called during a tick, such as the Tick() method itself or /// the Before(First|Last)Run() methods. The origin activity will be marked in the output. /// </summary> /// <param name="origin">Activity from which to start traversing, and which to mark. If null, mark the calling activity, and start traversal from the root.</param> /// <param name="level">Initial level of indentation.</param> protected void PrintActivityTree(Activity origin = null, int level = 0) { if (origin == null) { RootActivity.PrintActivityTree(this); } else { Console.Write(new string(' ', level * 2)); if (origin == this) { Console.Write("*"); } Console.WriteLine(this.GetType().ToString().Split('.').Last()); if (ChildActivity != null) { ChildActivity.PrintActivityTree(origin, level + 1); } if (NextInQueue != null) { NextInQueue.PrintActivityTree(origin, level); } } }
public override bool Cancel(Actor self, bool keepQueue) { if (ChildActivity == null) { return(base.Cancel(self, keepQueue)); } //Although MoveFirstHalf and MoveSecondHalf can't be interrupted, //We prevent them from moving forever by removing the path. //通过消除路径来阻止他们永远移动 if (path != null) { path.Clear(); } //Remove queued activities if (!keepQueue && NextInQueue != null) { NextInQueue = null; } //In current implementation,ChildActivity can be Turn,MoveFirstHalf and MoveSecondHalf. //Turn may be interrupted freely while they are turning. //转弯时可能会自由中断 //Unlike Turn,MoveFirstHalf and MoveSecondHalf are not Interruptable,but clearing the path guarantees that they will return as soon as possible,once the actor is back in a valid position. //与Turn 不同,MoveFirstHalf 和 MoveSecondHalf 是不可被中断的,但清除路径可以保证一旦单位回到有效的位置,他们将尽快返回 //This means that it is safe to unconditionally return true,which avoids breaking parent activities that rely on cancellation succeeding (but not necessarily immediately) //这意味着无条件返回true 是安全的,避免了依靠取消成功(但不一定立即) ChildActivity.Cancel(self); return(true); }
private static void SetupForProcessing(IList <Variable> variables, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining) { for (int i = 0; i < variables.Count; i++) { SetupForProcessing(variables[i], ref nextActivity, ref activitiesRemaining); } }
private static void SetupForProcessing(RuntimeArgument argument, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining) { if ((argument.BoundArgument != null) && !argument.BoundArgument.IsEmpty) { SetupForProcessing(argument.BoundArgument.Expression, true, ref nextActivity, ref activitiesRemaining); } }
/// <summary> /// Runs once on Actor.Dispose(). /// Main purpose is to ensure ChildActivity.OnActorDispose runs as well (which isn't otherwise accessible due to protection level). /// </summary> internal void OnActorDisposeOuter(Actor self) { if (ChildActivity != null) { ChildActivity.OnActorDisposeOuter(self); } OnActorDispose(self); }
public void Push(ChildActivity childActivity) { if (!childActivity.CanBeExecuted) { this.nonExecutingParentCount++; } this.callStack.PushFront(childActivity); }
public override IEnumerable <Target> GetTargets(Actor self) { if (ChildActivity != null) { return(ChildActivity.GetTargets(self)); } return(Target.None); }
public virtual void QueueChild(Actor self, Activity activity, bool pretick = false) { if (ChildActivity != null) { ChildActivity.Queue(self, activity); } else { ChildActivity = pretick ? ActivityUtils.RunActivity(self, activity) : activity; } }
public void QueueChild(Activity activity) { if (ChildActivity != null) { ChildActivity.Queue(activity); } else { ChildActivity = activity; } }
private void CheckIfReachedBestLocation(Actor self, out MiningState state) { if ((self.Location - deployDestPosition).LengthSquared <= cellRange * cellRange) { ChildActivity.Cancel(self); state = MiningState.TryDeploy; } else { state = MiningState.Moving; } }
private static void SetupForProcessing(Activity activity, bool canBeExecuted, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining) { if (!nextActivity.Equals(ChildActivity.Empty)) { if (activitiesRemaining == null) { activitiesRemaining = new Stack <ChildActivity>(); } activitiesRemaining.Push(nextActivity); } nextActivity = new ChildActivity(activity, canBeExecuted); }
public override IEnumerable <TargetLineNode> TargetLineNodes(Actor self) { if (ChildActivity != null) { foreach (var n in ChildActivity.TargetLineNodes(self)) { yield return(n); } } else { yield return(new TargetLineNode(fallbackTarget, Color.OrangeRed)); } }
public override IEnumerable <TargetLineNode> TargetLineNodes(Actor self) { if (ChildActivity == null) { yield return(new TargetLineNode(host, Color.Green)); } else { foreach (var n in ChildActivity.TargetLineNodes(self)) { yield return(n); } } }
public override IEnumerable <TargetLineNode> TargetLineNodes(Actor self) { if (ChildActivity == null) { yield return(new TargetLineNode(Target.FromActor(dest), aircraft.Info.TargetLineColor)); } else { foreach (var n in ChildActivity.TargetLineNodes(self)) { yield return(n); } } }
public override void Cancel(Actor self, bool keepQueue = false) { if (!shouldCancel) { shouldCancel = true; if (ChildActivity is Move || ChildActivity is Turn) { ChildActivity.Cancel(self); } else if (ChildActivity is Drag && isDocking) { QueueChild(new Drag(dockableActor, dockTarget, dockableActor.World.Map.CenterOfCell(dockEntry), distance / speed)); } } }
public virtual void Cancel(Actor self, bool keepQueue = false) { if (!keepQueue) { NextActivity = null; } if (!IsInterruptible) { return; } ChildActivity?.Cancel(self); // Directly mark activities that are queued and therefore didn't run yet as done State = State == ActivityState.Queued ? ActivityState.Done : ActivityState.Canceling; }
public override IEnumerable <TargetLineNode> TargetLineNodes(Actor self) { if (targetLineColor != null) { if (returnToBase) { foreach (var n in ChildActivity.TargetLineNodes(self)) { yield return(n); } } if (!returnToBase || !attackAircraft.Info.AbortOnResupply) { yield return(new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value)); } } }
public IActionResult Add(AddActivityViewModel addActivityViewModel, string[] selectedChildren) { if (ModelState.IsValid) { var userId = _userManager.GetUserId(User); Activity newActivity = new Activity() { Name = addActivityViewModel.Name, StartTime = addActivityViewModel.StartTime, EndTime = addActivityViewModel.EndTime, IsOnline = addActivityViewModel.IsOnline, Location = addActivityViewModel.Location }; context.Activities.Add(newActivity); foreach (var childIdString in selectedChildren) { int childId = int.Parse(childIdString); ChildActivity newChildActivity = new ChildActivity { Activity = newActivity, ChildId = childId, ActivityId = newActivity.Id, Status = "toDo" }; context.ChildActivites.Add(newChildActivity); } context.SaveChanges(); return(Redirect("Index")); } List <Child> children = context.Children.ToList(); AddActivityViewModel wrongAddActivityViewModel = new AddActivityViewModel(children); wrongAddActivityViewModel.Name = addActivityViewModel.Name; wrongAddActivityViewModel.StartTime = addActivityViewModel.StartTime; wrongAddActivityViewModel.EndTime = addActivityViewModel.EndTime; wrongAddActivityViewModel.IsOnline = addActivityViewModel.IsOnline; wrongAddActivityViewModel.Location = addActivityViewModel.Location; wrongAddActivityViewModel.ChildIds = addActivityViewModel.ChildIds; return(View("Add", wrongAddActivityViewModel)); }
public virtual bool Cancel(Actor self) { if (!IsInterruptible) { return(false); } if (ChildActivity != null && !ChildActivity.Cancel(self)) { return(false); } State = ActivityState.Canceled; NextActivity = null; ChildActivity = null; return(true); }
public override IEnumerable <TargetLineNode> TargetLineNodes(Actor self) { if (ChildActivity != null) { foreach (var n in ChildActivity.TargetLineNodes(self)) { yield return(n); } } if (orderLocation != null) { yield return(new TargetLineNode(Target.FromCell(self.World, orderLocation.Value), harvInfo.HarvestLineColor)); } else if (deliverActor != null) { yield return(new TargetLineNode(Target.FromActor(deliverActor), harvInfo.DeliverLineColor)); } }
public override void Cancel(Actor self, bool keepQueue = false) { // HACK: force move activities to ignore the transit-only cells when cancelling // The idle handler will take over and move them into a safe cell if (ChildActivity != null) { foreach (var c in ChildActivity.ActivitiesImplementing <Move>()) { c.Cancel(self, false, true); } } foreach (var t in transportCallers) { t.MovementCancelled(self); } base.Cancel(self, keepQueue); }
public virtual void Cancel(Actor self, bool keepQueue = false) { if (!keepQueue) { NextActivity = null; } if (!IsInterruptible) { return; } if (ChildActivity != null) { ChildActivity.Cancel(self); } State = ActivityState.Canceling; }
public override bool Tick(Actor self) { // Refuse to take off if it would land immediately again. if (aircraft.ForceLanding) { Cancel(self); } if (IsCanceling) { return(true); } if (!self.World.Map.Contains(self.Location) && --endingDelay < 0) { ChildActivity.Cancel(self); } return(TickChild(self)); }
/// <summary> /// 活动取消 /// </summary> /// <param name="self"></param> /// <param name="keepQueue">标识是否保持队列顺序</param> /// <returns></returns> public virtual bool Cancel(Actor self, bool keepQueue = false) { if (!IsInterruptible) { return(false); } if (ChildActivity != null && !ChildActivity.Cancel(self)) { return(false); } if (!keepQueue) { NextActivity = null; } ChildActivity = null; State = ActivityState.Canceled; return(true); }
public IActionResult EditChildActivity(EditChildActivityViewModel editChildActivityViewModel) { ChildActivity selectedChildActivity = context.ChildActivites .Where(ca => ca.ChildId == editChildActivityViewModel.ChildId) .Single(ca => ca.ActivityId == editChildActivityViewModel.ActivityId); selectedChildActivity.Status = editChildActivityViewModel.ActivityStatus; selectedChildActivity.Note = editChildActivityViewModel.ActivityNote; context.SaveChanges(); Activity theActivity = context.Activities.Find(editChildActivityViewModel.ActivityId); List <ChildActivity> childActivities = context.ChildActivites .Where(ca => ca.ActivityId == editChildActivityViewModel.ActivityId) .Include(ca => ca.Child) .ToList(); ActivityDetailViewModel activityDetailViewModel = new ActivityDetailViewModel(theActivity, childActivities); return(View("Detail", activityDetailViewModel)); }