private IHexCell GetValidNearbyCell(IHexCell centerCell, IUnitTemplate template, ICivilization owner)
        {
            for (int i = 0; i < 10; i++)
            {
                foreach (var nearbyCell in Grid.GetCellsInRing(centerCell, i))
                {
                    if (UnitFactory.CanBuildUnit(nearbyCell, template, owner))
                    {
                        return(nearbyCell);
                    }
                }
            }

            throw new InvalidOperationException("There is no cell within 10 cells of the argued location that can support this person");
        }
示例#2
0
        public void ApplyInfluenceToMap(
            float strength, float[] map, IHexCell center, int maxDistance,
            InfluenceRolloff rolloff, InfluenceApplier applier
            )
        {
            map[center.Index] = applier(map[center.Index], strength);

            for (int i = 1; i <= maxDistance; i++)
            {
                foreach (var cellInRing in Grid.GetCellsInRing(center, i))
                {
                    float effectiveStrength = rolloff(strength, i);

                    map[cellInRing.Index] = applier(map[cellInRing.Index], effectiveStrength);
                }
            }
        }
示例#3
0
        public IEnumerable <IHexCell> GetCellsVisibleToUnit(IUnit unit)
        {
            var retval = new List <IHexCell>();

            var unitLocation = UnitPositionCanon.GetOwnerOfPossession(unit);

            foreach (var cell in Grid.GetCellsInRadius(unitLocation, unit.VisionRange))
            {
                if (!HasObstructionsBetween(unitLocation, cell))
                {
                    retval.Add(cell);
                }
            }

            foreach (var cell in Grid.GetCellsInRing(unitLocation, unit.VisionRange + 1))
            {
                if (!HasObstructionsBetween(unitLocation, cell) && cell.Terrain.IsWater())
                {
                    retval.Add(cell);
                }
            }

            return(retval);
        }