/// <summary>
 /// Remove a population from the RPM.
 /// </summary>
 public void RemovePopulation(Population population)
 {
     if (!Populations.Contains(population))
     {
         return;
     }
     Populations.Remove(population);
     TypesOfTerrain.Remove(population);
     openID.Enqueue(PopulationToID[population]);
     PopulationByID.Remove(PopulationToID[population]); // free ID
     PopulationToID.Remove(population);                 // free ID
     CleanupAccessMapForRecycledID();
 }
    /// <summary>
    /// Check if a population can access CellPos.
    /// </summary>
    public bool CanAccess(Population population, Vector3Int cellPos)
    {
        // if accessible
        // check if the nth bit is set (i.e. accessible for the population)
        if (AccessMap.ContainsKey(cellPos) && PopulationToID.ContainsKey(population))
        {
            if (((AccessMap[cellPos] >> PopulationToID[population]) & 1L) == 1L)
            {
                return(true);
            }
        }

        // population can't access the position
        return(false);
    }
    /// <summary>
    /// Add a population to the RPM.
    /// </summary>
    public void AddPopulation(Population population)
    {
        if (!Populations.Contains(population))
        {
            // ignore their old id and assign it a new one
            int id = openID.Dequeue();

            // since IDs after maxPopulation-1 are recycled ids, we need to do clean up old values
            if (id == lastRecycledID)
            {
                CleanupAccessMapForRecycledID();
            }
            PopulationToID.Add(population, id);
            PopulationByID.Add(id, population);
            Populations.Add(population);

            TypesOfTerrain.Add(population, new int[(int)TileType.TypesOfTiles]);
            // generate the map with the new id
            GenerateMap(population);
        }
    }