public bool AddMemory(MemoryInstance memory) { MemoryInstance recentMemory = isRecentMemory(memory); if (recentMemory != null) { recentMemory.AddIteration(); //Debug.LogWarning("Iterating memory"); return(true); } if (currentMemoryIndex + 1 == shortTermMemory.Length) { currentMemoryIndex = 0; } if (currentMemoryIndex < shortTermMemory.Length) { shortTermMemory[currentMemoryIndex] = memory; currentMemoryIndex++; if (World.ISDEBUGSCENE) { StringBuilder builder = new StringBuilder("I will remember I "); if (memory.invertVerb) { builder.Append(" NOT "); } builder.Append(memory.verb); builder.Append(" " + memory.subject.GetThing().thingName); //Debug.LogWarning(builder.ToString()); DebugMenu.AppendLine(builder.ToString()); } return(true); } return(false); }
private Thing[] GetFoodFromMemory(CONSUMPTION_TYPE consumptionType) { List <Thing> memoriesOfFood = new List <Thing>(); for (int count = 0; count < shortTermMemory.Length; count++) { MemoryInstance memory = shortTermMemory[count]; if (memory == null) { continue; } if (memory.verb == Verb.SAW && memory.invertVerb == false && memory.subject.GetThing() != null && memory.subject.GetThing() .matchesConsumptionType(consumptionType)) { memoriesOfFood.Add(memory.subject.GetThing()); } } return(memoriesOfFood.ToArray()); }
private MemoryInstance isRecentMemory(MemoryInstance memory) { return(isRecentMemory(memory.verb, memory.subject.GetThing(), memory.invertVerb)); }
private Thing getClosestFoodProducerFromMemory(Vector3 origin, Thing[] exclusions, float discludeDistanceLessThan) { Thing closest = null; for (int count = 0; count < shortTermMemory.Length; count++) { MemoryInstance memory = shortTermMemory[count]; if (memory == null) { continue; } if (memory.verb == Verb.SAW && memory.invertVerb == false && memory.subject.GetThing() != null && memory.subject.GetThing() .produces == Thing.Thing_Produces.Food) { Thing currentThing = memory.subject.GetThing(); float currentDistance = Vector3.Distance(origin, currentThing.transform.position); float closestDistance = float.MaxValue; if (closest != null) { closestDistance = Vector3.Distance(origin, closest.transform.position); } if (currentDistance < closestDistance) { if (exclusions == null && discludeDistanceLessThan == 0) { closest = currentThing; } else { // Discard if an exclusion // bool exclude = false; if (exclusions != null) { foreach (Thing exclusion in exclusions) { if (exclusion == currentThing) { exclude = true; break; } } } // Discard if below min distance // if (discludeDistanceLessThan > 0) { if (currentDistance <= discludeDistanceLessThan) { exclude = true; } } if (!exclude) { closest = currentThing; } } } } } return(closest); }
public bool IsSameAs(MemoryInstance instance) { return(IsSameAs(instance.verb, instance.subject.GetThing(), instance.invertVerb)); }