#Merging two custom Memory objects

1 messages · Page 1 of 1 (latest)

vernal pulsar
#
public class Memory
{
    public Colony colony;
    public Dictionary<ResourceType, Vector3> nearestResource = new Dictionary<ResourceType, Vector3>();
    public Dictionary<ResourceType, List<Vector3>> resourceLocations = new Dictionary<ResourceType, List<Vector3>>();
    public Dictionary<ResourceType, int> colonyResources = new Dictionary<ResourceType, int>();

    public Memory(Colony colony)
    {
        this.colony = colony;
        colonyResources = colony.resourceAmounts;
        foreach (ResourceType resourceType in Enum.GetValues(typeof(ResourceType)))
        {
            resourceLocations[resourceType] = new List<Vector3>();
        }
    }
}
#

I am making a game involving ants and their colony, both of which have memories of the world around them. The ants go and explore the world, update their own memory, and report back to the colony, which updates its memory, too. But also, as ants return to the colony, they should update their own memory based on changes from the colony. So I want to merge two memory objects, updating one with new info from the other while also updating the other with new info from the one, without overwriting information. I am unsure how to do this.