Esempio n. 1
0
        public void BeginResourceInform(List <ResourceData> resourceDatas)
        {
            //We are the first object to start this process.
            //We create a new hashset of tiles to ignore and start with adding ourselves.
            HashSet <GridTile> tilesToIgnore = new HashSet <GridTile>
            {
                ParentTile
            };

            foreach (GridTile tile in GetAdjacentGridTiles())
            {
                if (tile == null || !tile.Occipied)
                {
                    continue;
                }

                //If this tile has a resource conduct entity, we will inform it of the resources
                //We want to get the multi tile occupier instead if the entity is null
                ResourceConductEntity cEntity = (tile?.Entity ?? tile?.MultiTileOccupier) as ResourceConductEntity;
                if (cEntity != null)
                {
                    cEntity.OnNewResourceViaConnection_Event(resourceDatas, tilesToIgnore);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Look for new resources on neighbours.
        /// </summary>
        /// <returns>If there were any new resources found.</returns>
        public bool LookForResources(bool shouldInformNeighboursOfNewResources = true)
        {
            //We were just placed, lets look for resources on our neighbours.
            bool anyNewResources = false;

            foreach (GridTile tile in GetAdjacentGridTiles())
            {
                if (tile == null || !tile.Occipied)
                {
                    continue;
                }
                ResourceConductEntity rEntity = (tile?.Entity ?? tile?.MultiTileOccupier) as ResourceConductEntity;
                if (rEntity != null)
                {
                    if (CompareAndGetNewResources(rEntity.CurrentResources))
                    {
                        anyNewResources = true;
                    }
                }
            }

            if (anyNewResources)
            {
                //Inform neighbours of our new resources.
                //Get a new list with all the resources we have.
                //We want to send this list onwards via a resource inform.
                if (shouldInformNeighboursOfNewResources)
                {
                    BeginResourceInform(GetResourcesAsList());
                }
            }
            return(anyNewResources);
        }
Esempio n. 3
0
        public virtual void NotifyNeighboursOfChange(GridTile[] neighboursToNofify)
        {
            HashSet <GridTile> tilesToIgnore = new HashSet <GridTile>
            {
                ParentTile
            };

            //Inform neighbours that we were destroyed
            foreach (GridTile tile in neighboursToNofify)
            {
                if (tile != null && tile.Entity != null)
                {
                    ResourceConductEntity ent = tile.Entity as ResourceConductEntity;

                    //If somehow we have ourselves, skip this loop.
                    if (ent == this)
                    {
                        continue;
                    }

                    //Get a new node set for the grid we live on
                    //Manually change the tile we were on to not be populated anymore.
                    Node[,] nodeSet = ParentTile.ParentGridSystem.GetNodeSet();
                    nodeSet[ParentTile.Position.x, ParentTile.Position.y].Populated = false;
                    ent?.OnNeighbourChanged(this, nodeSet, tilesToIgnore);
                }
            }
        }
Esempio n. 4
0
        public virtual void BeginInformNoConnectionResource(List <ResourceData> resourceToRemove)
        {
            foreach (GridTile tile in GetAdjacentGridTiles())
            {
                if (tile == null)
                {
                    continue;
                }

                //If this tile has a resource conduct entity, we will inform it of the resources to remove.
                ResourceConductEntity cEntity = tile?.Entity as ResourceConductEntity;
                if (cEntity != null)
                {
                    cEntity.ResourceLostConnection_Event(resourceToRemove, tilesToIgnoreDestroy);
                }
            }
        }
Esempio n. 5
0
 public virtual void ContinueNoConnectionResourceInform(List <ResourceData> resourcesToRemove, HashSet <GridTile> tilesToIgnore)
 {
     //Tell our neighbours that these resource has no connection anymore.
     GridTile[] tiles = GetAdjacentGridTiles();
     foreach (GridTile tile in tiles)
     {
         if (tile == null)
         {
             continue;
         }
         //Skip this tile if it was informed already from this operation queue.
         if (tilesToIgnore.Contains(tile))
         {
             continue;
         }
         if (tile != null && tile.Entity != null)
         {
             ResourceConductEntity ent = tile.Entity as ResourceConductEntity;
             ent?.ResourceLostConnection_Event(resourcesToRemove, tilesToIgnore);
         }
     }
 }
Esempio n. 6
0
 public void ContinueResourceInform(List <ResourceData> resourceData, HashSet <GridTile> tilesToIgnore)
 {
     //Tell our neighbours that this resource exists.
     GridTile[] tiles = GetAdjacentGridTiles();
     foreach (GridTile tile in tiles)
     {
         if (tile == null)
         {
             continue;
         }
         //Skip this tile if it was informed already from this operation queue.
         if (tilesToIgnore.Contains(tile))
         {
             continue;
         }
         if (tile != null && tile.Entity != null)
         {
             ResourceConductEntity ent = tile.Entity as ResourceConductEntity;
             ent?.OnNewResourceViaConnection_Event(resourceData, tilesToIgnore);
         }
     }
 }