Exemplo n.º 1
0
        /// <summary>
        /// Computes the world model's urgency.
        /// </summary>
        /// <param name="factSelectionMode">Method by which to compute fact urgency.</param>
        /// <param name="mostUrgentFacts">Gets set to a list of most-urgent facts in the world model.</param>
        /// <param name="ignoreList">Ignore entities named in this list when computing urgency.</param>
        /// <param name="numTopFactsToChoose">Maximum number of most-urgent facts to return in mostUrgentFacts.</param>
        /// <param name="debug">If true, logs details of this function's operation.</param>
        /// <returns>The cumulative urgency of all facts in the world model.</returns>
        public float ComputeUrgency(UrgentFactSelectionMode factSelectionMode, out Fact[] mostUrgentFacts, string[] ignoreList = null, bool debug = false)
        {
            var   mostUrgentFactsList = new List <Fact>(); // Maintained in ascending urgency, up to factionSelectMode.max facts.
            Fact  mostUrgentFact      = null;
            int   maxUrgentFacts      = factSelectionMode.max;
            float cumulativeUrgency   = 0;
            float minTopUrgency       = Mathf.NegativeInfinity; // Urgency of least-urgent fact in mostUrgentFacts[].
            var   debugInfo           = QuestMachine.debug ? "WORLD MODEL: (observer:" + observer.entityType.name + ")\n" : string.Empty;

            for (int i = 0; i < facts.Count; i++)
            {
                var fact = facts[i];
                if (fact == null || fact.entityType == null)
                {
                    continue;
                }
                if (ShouldIgnore(fact.entityType.name, ignoreList))
                {
                    continue;
                }
                observed = fact;
                var urgency = GetFactUrgency(fact);
                urgency            = factSelectionMode.AdjustUrgency(urgency);
                fact.urgency       = urgency;
                cumulativeUrgency += urgency;
                if (urgency > 0 && (mostUrgentFactsList.Count < maxUrgentFacts || urgency > minTopUrgency))
                {
                    if (mostUrgentFactsList.Count >= maxUrgentFacts)
                    {
                        mostUrgentFactsList.RemoveAt(0);
                    }
                    var added = false;
                    for (int j = 0; j < mostUrgentFactsList.Count; j++)
                    {
                        if (mostUrgentFactsList[j].urgency > urgency)
                        {
                            mostUrgentFactsList.Insert(j, fact);
                            added = true;
                            break;
                        }
                    }
                    if (!added)
                    {
                        mostUrgentFactsList.Add(fact);
                    }
                    mostUrgentFact = fact;
                    minTopUrgency  = mostUrgentFactsList[0].urgency;
                }
                if (debug)
                {
                    debugInfo += string.Format("Domain:{0}, EntityType:{1}, Count:{2}\n", new object[] { fact.domainType.name, fact.entityType.name, fact.count });
                    debugInfo += string.Format("   Urgency:{0}\n", new object[] { urgency });
                }
            }
            mostUrgentFact = (mostUrgentFactsList.Count > 0) ? mostUrgentFactsList[mostUrgentFactsList.Count - 1] : null;
            if (debug)
            {
                if (mostUrgentFact != null)
                {
                    debugInfo += string.Format("MOST URGENT: Domain:{0}, EntityType:{1}, Count:{2}, Urgency:{3}\n", new object[] { mostUrgentFact.domainType.name, mostUrgentFact.entityType.name, mostUrgentFact.count, minTopUrgency });
                }
                debugInfo += string.Format("CUMULATIVE URGENCY: {0}", new object[] { cumulativeUrgency });
                Debug.Log(debugInfo);
            }
            mostUrgentFacts = mostUrgentFactsList.ToArray();
            return(cumulativeUrgency);
        }
Exemplo n.º 2
0
 public WorldModel(Fact observer)
 {
     this.observer = observer;
 }
Exemplo n.º 3
0
 public PlanStep(Fact fact, Action action, int requiredCounterValue = 1)
 {
     this.fact   = fact;
     this.action = action;
     this.requiredCounterValue = Mathf.Min(fact.count, requiredCounterValue);
 }