public UnitSpawnInfo TryGetValidSpawn( IEncampment encampment, Func <IHexCell, IEnumerable <IUnitTemplate> > unitSelector ) { var encampmentLocation = EncampmentLocationCanon.GetOwnerOfPossession(encampment); foreach (var cell in Grid.GetCellsInRadius(encampmentLocation, 1, true)) { var availableUnits = unitSelector(cell); if (availableUnits.Any()) { return(new UnitSpawnInfo() { IsValidSpawn = true, LocationOfUnit = cell, TemplateToBuild = Randomizer.TakeRandom(availableUnits) }); } } return(new UnitSpawnInfo() { IsValidSpawn = false, LocationOfUnit = null, TemplateToBuild = null }); }
public bool TrySpawnUnit(IEncampment encampment) { if (Randomizer.GetRandom01() <= BarbarianConfig.WaterSpawnChance) { var navalInfo = SpawningTools.TryGetValidSpawn(encampment, AvailableUnitsLogic.NavalTemplateSelector); if (navalInfo.IsValidSpawn) { UnitFactory.BuildUnit(navalInfo.LocationOfUnit, navalInfo.TemplateToBuild, CivFactory.BarbarianCiv); return(true); } } var landInfo = SpawningTools.TryGetValidSpawn(encampment, AvailableUnitsLogic.LandTemplateSelector); if (landInfo.IsValidSpawn) { UnitFactory.BuildUnit(landInfo.LocationOfUnit, landInfo.TemplateToBuild, CivFactory.BarbarianCiv); return(true); } else { return(false); } }
public void DestroyEncampment(IEncampment encampment) { if (encampment == null) { throw new ArgumentNullException("encampment"); } EncampmentLocationCanon.ChangeOwnerOfPossession(encampment, null); EncampmentList.Remove(encampment); }