Exemplo n.º 1
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]));
        }
    }