Ejemplo n.º 1
0
    public override void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
    {
        ItemCue itemInfo = (ItemCue)memCue;

        status = itemInfo.Status;
        owner = itemInfo.Owner;
        durability = itemInfo.Durability;

        if (durability < 0.0f)
        {
            //Once durability starts to fall, a agent's affinity with an item will also drop.
            memoryGraph.UpdateCueOpinion(retainedMemory.MemoryNode, -UpdateFrequency);
        }

        base.UpdateMemory(memoryGraph, retainedMemory, memCue, UpdateFrequency);

        if (UpdateFrequency <= 0.0f || itemInfo.Owner == null)    //We want to strengthen the memory between the specific item and the place it has been observed.
            return;

        MemoryGraphNode charNode;
        if (memoryGraph.Contains(itemInfo.Owner.UniqueNodeID))
            charNode = memoryGraph.GetNamedNodeFromGraph(itemInfo.Owner.UniqueNodeID);
        else
            charNode = memoryGraph.AddNamedNodeToGraph(new CharacterNode(itemInfo.Owner));

        //First make a connection between the character and the item.
        int index = charNode.Neighbours.IndexOf(retainedMemory);
        if (index == -1)
            memoryGraph.AddDirectedEdge(charNode, retainedMemory, UpdateFrequency, UpdateFrequency);
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            charNode.StrengthenMemory(index, UpdateFrequency);
            //charNode.OpinionStrengths[index] += UpdateFrequency;
        }

        //Then between the item and the character.
        index = retainedMemory.Neighbours.IndexOf(charNode);
        if (index == -1)
            memoryGraph.AddDirectedEdge(retainedMemory, charNode, UpdateFrequency, UpdateFrequency);
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            retainedMemory.StrengthenMemory(index, UpdateFrequency);
            //retainedMemory.OpinionStrengths[index] += UpdateFrequency;
        }
    }
Ejemplo n.º 2
0
    public MemoryType MemoryType;   //This tells us what type of memory this is about.

    public virtual void UpdateMemory(MemoryGraph memoryGraph, MemoryGraphNode retainedMemory, MemoryCue memCue, float UpdateFrequency)
    {
        //LastLocation = memCue.CurrentLocation;

        //if(memCue.CachedTransform != null)
        //    LastPosition = memCue.CachedTransform.position;

        retainedMemory.LastLocation = memCue.CurrentLocation;

        if (memCue.CachedTransform != null)
            retainedMemory.LastPosition = memCue.CachedTransform.position;

        retainedMemory.LastUpdated = Time.time;

        //Debug.Log("Making a memory connection between " + memCue.UniqueNodeID + " and " + LastLocation.ToString() + " - " + UpdateFrequency);

        //if (UpdateFrequency <= 0.0f)    //We want to strengthen the memory between the specific item and the place it has been observed.
        //    return;

        MemoryGraphNode locNode;
        string locString = retainedMemory.LastLocation.ToString();

        if (!memoryGraph.Contains(locString))
        {
            locNode = memoryGraph.AddNamedNodeToGraph(new LocationNode(retainedMemory.LastLocation));
            memoryGraph.AddUndirectedEdge(locNode, retainedMemory);
        }

        if (UpdateFrequency <= 0.0f)    //We want to strengthen the memory between the specific item and the place it has been observed.
            return;

        if (memoryGraph.Contains(locString))
            locNode = memoryGraph.GetNamedNodeFromGraph(locString);
        else
            locNode = memoryGraph.AddNamedNodeToGraph(new LocationNode(retainedMemory.LastLocation));

        //First make a connection between the place and the item.
        int index = locNode.Neighbours.IndexOf(retainedMemory);
        if (index == -1)
        {
            //Somehow the cue relationship has been broken!?
            //Rebuild it!
            memoryGraph.AddDirectedEdge(locNode, retainedMemory, UpdateFrequency, UpdateFrequency);
        }
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            locNode.StrengthenMemory(index, UpdateFrequency);
            //locNode.StrengthenOpinion(index, UpdateFrequency);   //We keep opinion strength updating here because it represents how strongly the agent believes the item / character etc. is connected to this location.
            //Debug.Log(string.Format("Node: {0}, NS: {1}, ES: {2}", retainedMemory.UID, locNode.NodeStrengths[index], locNode.EdgeStrengths[index]));
            //Debug.Log(string.Format("NS: {0}, ES: {1}", locNode.NodeStrengths[index], cueNode.EdgeStrengths[index]));
        }

        //Then between the item and the place.
        index = retainedMemory.Neighbours.IndexOf(locNode);
        if (index == -1)
        {
            //Somehow the cue relationship has been broken!?
            //Rebuild it!
            memoryGraph.AddDirectedEdge(retainedMemory, locNode, UpdateFrequency, UpdateFrequency);
        }
        else
        {
            //Strengthing the memory based on the length of time it was active in the working set.
            retainedMemory.StrengthenMemory(index, UpdateFrequency);
            //retainedMemory.StrengthenOpinion(index, UpdateFrequency);   //We keep opinion strength updating here because it represents how strongly the agent believes the item / character etc. is connected to this location.
            //Debug.Log(string.Format("Node: {0}, NS: {1}, ES: {2}", locNode.UID, retainedMemory.NodeStrengths[index], retainedMemory.EdgeStrengths[index]));
            //Debug.Log(string.Format("NS: {0}, ES: {1}", locNode.NodeStrengths[index], cueNode.EdgeStrengths[index]));
        }
    }