Ejemplo n.º 1
0
    public void CheckCropNeeds()
    {
        // Clear all needs first
        foreach (Hex cropHex in cropHexes)
        {
            cropHex.crop.ResetNeeds();
        }

        // Go through all workers and add resources to crop
        foreach (Worker worker in workers)
        {
            // Don't bother if not deployed
            if (worker.hex == null)
            {
                continue;
            }

            // Some workers might not affect tiles
            ITileAffector affector = worker.GetComponent <ITileAffector>();
            if (affector == null)
            {
                continue;
            }

            List <Key> affectedTiles = affector.GetAffectedTiles(worker.hex);

            foreach (Key hexPosition in affectedTiles)
            {
                Key key = new Key(hexPosition.x, hexPosition.y);
                Hex hex;
                if (grid.TryGetValue(key, out hex))
                {
                    Crop crop = hex.crop;

                    // If crop exists in hex, apply resources
                    if (crop != null)
                    {
                        crop.ApplyResources(worker.GetComponent <ResourceProducer>().GetProductionMap());
                    }
                }
            }
        }
    }