public bool IsAlreadyIntention(IntentionType type) { bool isAlreadyIntention = intentions.Any(i => i.Type == type); if (HasCurrentIntention) { if (CurrentIntention.Type == type) { isAlreadyIntention = true; } } return(isAlreadyIntention); }
/// <summary> /// Adds and intention based on the passed intention type to the from agent based on the passed to agent. Basically, the "fromAgent" /// will perform whatever intention is indicated by the "intentionType" on the "toAgent", such as walking to a snack machine to drink. /// </summary> /// <param name="fromAgent">From agent.</param> /// <param name="toAgent">To agent.</param> /// <param name="intentionType">Intention type.</param> private void AddIntentionToAgent(MobileAgent fromAgent, Agent toAgent, IntentionType intentionType) { Agent walkFromAgent; Intention finalIntention = fromAgent.FinalIntention; // if we have a final intention currently queued up, then we want to calculate the path from that position if (finalIntention != null) { walkFromAgent = finalIntention.WalkToAgent; } // otherwise, we want to calculate the path from our current position else { walkFromAgent = fromAgent; } var bestPathToClosestAgent = GetBestPathToAgent(walkFromAgent, toAgent); fromAgent.AddIntention(new Intention(toAgent, bestPathToClosestAgent, intentionType)); }
/// <summary> /// Walks the passed mobile agent to the closest agent of type T. /// </summary> /// <param name="agent">Agent.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public void WalkMobileAgentToClosest <T>(MobileAgent mobileAgent) where T : Agent { IntentionType intentionType = IntentionType.Unknown; if (typeof(T) == typeof(SodaMachine)) { intentionType = IntentionType.BuyDrink; } else if (typeof(T) == typeof(SnackMachine)) { intentionType = IntentionType.BuySnack; } else if (typeof(T) == typeof(OfficeDesk)) { intentionType = IntentionType.GoToDesk; } // if we don't already intend to perform that intention, proceed if (mobileAgent.IsAlreadyIntention(intentionType)) { return; } var agentsToCheck = GetTrackedAgentsByType <T>(); // if there are agents by that type to head towards, proceed if (agentsToCheck.Count() == 0) { return; } // find the closest agent by the type T to the employee and set the employee on his way towards that agent if any exists var closestAgent = GetClosestAgentByType(mobileAgent, agentsToCheck); // if there is an actual closest agent in the simulation, proceed if (closestAgent == null) { return; } // if this is a triggerable, subscribe to the trigger now that we intend to go to it // if (closestAgent is ITriggerable) // { // var triggerable = closestAgent as ITriggerable; // if (closestAgent is SodaMachine) // triggerable.Trigger.AddSubscriptionToActionByType(mobileAgent, SubscriptionType.Once, ActionType.DispenseDrink); // if (closestAgent is SnackMachine) // triggerable.Trigger.AddSubscriptionToActionByType(mobileAgent, SubscriptionType.Once, ActionType.DispenseFood); // } // we only want to add a "go to office desk" intention if the desk is not assigned to someone if (closestAgent is OfficeDesk) { var closestOfficeDesk = closestAgent as OfficeDesk; if (!closestOfficeDesk.IsAssignedToAnEmployee) { AddIntentionToAgent(mobileAgent, closestAgent, intentionType); } } else { AddIntentionToAgent(mobileAgent, closestAgent, intentionType); } }
/// <summary> /// Initializes a new instance of the <see cref="LimitedLiability.Intent"/> class. /// </summary> public Intention(Agent walkToAgent, Queue <PathNode> pathNodesToAgent, IntentionType type) { WalkToAgent = walkToAgent; PathNodesToAgent = pathNodesToAgent; Type = type; }