Exemple #1
0
 public UrbTile[] GetAdjacent(bool GetLinked = false, int xOffset = 1, int yOffset = 1)
 {
     using (s_GetAdjacent_p.Auto())
     {
         return(OwningMap.GetAdjacent(XAddress, YAddress, GetLinked, xOffset, yOffset));
     }
 }
Exemple #2
0
 public UrbTile GetRelativeTile(int Xdistance, int Ydistance)
 {
     if (Xdistance == 0 && Ydistance == 0)
     {
         return(this);
     }
     return(OwningMap.GetTile(XAddress + Xdistance, YAddress - Ydistance));
 }
Exemple #3
0
    protected void PropagateSizeLimit()
    {
        UrbTile[] Adjacent = OwningMap.GetAdjacent(XAddress, YAddress);
        EvaluateSizeLimit();
        for (int i = 0; i < Adjacent.Length; i++)
        {
            if (Adjacent[i] == null)
            {
                continue;
            }

            Adjacent[i].EvaluateSizeLimit();
        }
    }
Exemple #4
0
    public void EvaluateSizeLimit()
    {
        if (Blocked)
        {
            PathableSize = 0;
            return;
        }
        UrbTile[] Adjacent = OwningMap.GetAdjacent(XAddress, YAddress);

        int fullOpen   = 0;
        int mediumOpen = 0;

        for (int i = 0; i < Adjacent.Length; i++)
        {
            UrbTile Tile = Adjacent[i];

            if (Tile == null || Tile.Blocked)
            {
                if (i > 4)
                {
                    break;
                }
            }
            else
            {
                fullOpen++;
                if (i > 1 && i < 5)
                {
                    mediumOpen++;
                }
            }
        }

        if (fullOpen > 7) // all eight directions are open
        {
            PathableSize = 3;
        }
        else if (mediumOpen > 2)
        {
            PathableSize = 2;
        }
        else
        {
            PathableSize = 1;
        }
        ScentDirty = true;
    }
Exemple #5
0
    public IEnumerator ScentCoroutine()
    {
        float       LastReorderTime             = 0.0f;
        const float MinimumTimeSinceLastReorder = .25f;

        float       LastScentUpdate    = 0.0f;
        const float MinimumScentUpdate = 1.0f;

        while (true)
        {
            yield return(new WaitForSeconds(UrbScent.ScentInterval * TimeMultiplier));

            if (!UrbSystemIO.HasInstance || UrbSystemIO.Instance.Loading)
            {
                continue;
            }

            //Now we update ordering on similar timescales as our Scents
            if (Time.fixedTime - LastReorderTime > MinimumTimeSinceLastReorder)
            {
                VisualShuffle();
                LastReorderTime = Time.fixedTime;
            }

            if (LinksDirty)
            {
                Adjacent   = OwningMap.GetAdjacent(XAddress, YAddress, true);
                LinksDirty = false;
            }

            UpdateClearance();

            //Don't need to call this _that_ often, but I'm still not sure how often we SHOULD call it
            SynchronizeScents();

            for (int t = 0; t < TerrainTypes.Length; t++)
            {
                var terrainType          = (int)TerrainTypes[t];
                var currentTerrainScents = TerrainFilter[terrainType];

                for (int s = 0; s < SizeLimit; s++)
                {
                    var terrainFilter = TerrainFilter[terrainType][s];
                    if (terrainFilter == null)
                    {
                        continue;
                    }

                    int idx        = 0;
                    var currentTag = AgentScentCache.GetScentTag(idx);
                    //This enumerations' kinda terrible
                    while (currentTag != UrbScentTag.MaxScentTag)
                    {
                        var value = AgentScentCache.Values[idx];
                        //In the "OG" version, the equivalent of these was set
                        //by dividing the value of the scent by the number of tiles that
                        //were expected to get touched.
                        //This "base" value seems to be somewhat strong even so.
                        currentTerrainScents[s][currentTag] = value * ScentDiffusion;
                        currentTag = AgentScentCache.GetScentTag(++idx);
                    }

                    if (!terrainFilter.dirty)
                    {
                        continue;
                    }

                    terrainFilter.dirty = false;
                    yield return(terrainFilter.DecayScent());

                    ScentDirty = ScentDirty || terrainFilter.dirty;
                }
                if (ScentDirty)
                {
                    yield return(DiffuseScent(terrainType));
                }
            }
            ScentDirty = false;

            if (!ScentDirty && Occupants.Count > 0)
            {
                if (Time.fixedTime - LastScentUpdate > MinimumScentUpdate)
                {
                    ScentDirty      = true;
                    LastScentUpdate = Time.fixedTime;
                }
            }
        }
    }
Exemple #6
0
 public UrbTile(UrbMap CreatingMap, Vector2 MapLocation, UrbTile[] LinkedTiles)
 {
     Constructor(CreatingMap);
     OwningMap.LocationToTileAddress(MapLocation, out XAddress, out YAddress);
     Links = LinkedTiles;
 }
Exemple #7
0
 public UrbTile(UrbMap CreatingMap, Vector2 MapLocation)
 {
     Constructor(CreatingMap);
     OwningMap.LocationToTileAddress(MapLocation, out XAddress, out YAddress);
     Links = new UrbTile[] { null, null, null };
 }
Exemple #8
0
    public void VisualShuffle()
    {
        LocationOffset = Vector3.zero;
        if (Occupants.Count <= 0)
        {
            return;
        }

        Vector3         Center           = OwningMap.TileAddressToLocation(XAddress, YAddress);
        List <UrbAgent> OrderedOccupants = new List <UrbAgent>(Occupants.Count);
        float           BiggestMass      = Occupants[0].MassPerTile;

        for (int i = 0; i < Occupants.Count; i++)
        {
            var occupant = Occupants[i];
            if (occupant.WasDestroyed || !occupant.isActiveAndEnabled)
            {
                continue;
            }

            if (occupant.MassPerTile > BiggestMass)
            {
                OrderedOccupants.Insert(0, occupant);
                BiggestMass = occupant.MassPerTile;
            }
            else
            {
                OrderedOccupants.Add(occupant);
            }
        }

        float Turn               = 0;
        float TurnAdjust         = (Mathf.PI);
        float Radius             = 0;
        float RadiusAdjust       = 3;
        float TileCapacityOffset = TileCapacity / 4f;

        for (int i = 0; i < OrderedOccupants.Count; i++)
        {
            if (OrderedOccupants[i].CurrentTile != this)
            {
                continue;
            }

            LocationOffset  = new Vector3(Mathf.Sin(Turn), Mathf.Cos(Turn), 0);
            LocationOffset *= (Radius * OwningMap.TileSize);
            var summedLocationOffset = new Vector3(0, 0, (LocationOffset.y * DepthPush) - LocationOffset.x) + LocationOffset;

            if (OrderedOccupants[i].Shuffle)
            {
                OrderedOccupants[i].Location = Center + summedLocationOffset;
            }
            else
            {
                OrderedOccupants[i].Location = Center;
            }

            Turn         += (OrderedOccupants[i].MassPerTile / TileCapacityOffset) * TurnAdjust;
            TurnAdjust   *= 0.85f;
            Radius       += (OrderedOccupants[i].MassPerTile / TileCapacityOffset) / RadiusAdjust;
            RadiusAdjust += 5f;
        }

        Occupants = OrderedOccupants;
    }