// Used by AreaNodeVisualisation objects at initialisation time to register themselves as being-managed by this manager object.
 public void RegisterAreaNode(AreaNodeVisualisation a)
 {
     if (areaNodeVisualisations == null)
     {
         areaNodeVisualisations = new List <AreaNodeVisualisation>();
     }
     areaNodeVisualisations.Add(a);
     a.CharacterEnteredZone += HandleCharacterEnterAreaEvent;
     a.CharacterExitedZone  += HandleCharacterExitAreaEvent;
     a.AreaRequestsUpdate   += (area) => UpdateAreaStateBasedOnCharactersWithinIt(area);
 }
    private void HandleCharacterExitAreaEvent(object sender, ICharacter character)
    {
        // DebuggingHelpers.PrintCurrentMethodName();
        AreaNodeVisualisation area = (AreaNodeVisualisation)sender;

        if (characterAreaMap[character] == area)
        {
            characterAreaMap[character] = null;
        }

        // The state of the area the character just left (the sender) should become the highest ranking state of the ones associated to any characters still remaining in the area, else default.
        UpdateAreaStateBasedOnCharactersWithinIt(area);
    }
    // Handler functions for when characters move from zone to zone.
    private void HandleCharacterEnterAreaEvent(object sender, ICharacter character)
    {
        // DebuggingHelpers.PrintCurrentMethodName();
        AreaNodeVisualisation area = (AreaNodeVisualisation)sender;

        // Whatever the state of the area the Character was PREVIOUSLY in should become the state of the new area, unless the entered area already has a state which supersedes it.
        AreaNodeVisualisationStates state = characterStateMap[character];

        if (state.Priority() >= area.CurrentState.Priority())
        {
            area.CurrentState = state;
        }

        // ok! we better make sure we keep everything up to date.
        characterAreaMap[character] = area;
    }
    private void UpdateAreaStateBasedOnCharactersWithinIt(AreaNodeVisualisation area)
    {
        if (area == null)
        {
            return;
        }
        AreaNodeVisualisationStates state = AreaNodeVisualisationStates.UNCONTROLLED;

        foreach (ICharacter c in area.AgentsInZone)
        {
            if (characterStateMap[c].Priority() >= state.Priority())
            {
                state = characterStateMap[c];
            }
        }

        area.CurrentState = state;
    }