public bool TryIncreaseYield( MapRegion region, RegionData regionData, YieldType type, out YieldSummary yieldAdded ) { if (type != YieldType.Production) { yieldAdded = YieldSummary.Empty; return(false); } var candidates = region.Cells.Where(HillCandidateFilter_ProductionIncreasing); if (candidates.Any()) { var newHill = candidates.Random(); var oldYield = YieldEstimator.GetYieldEstimateForCell(newHill, TechCanon.AvailableTechs); ModLogic.ChangeShapeOfCell(newHill, CellShape.Hills); var newYield = YieldEstimator.GetYieldEstimateForCell(newHill, TechCanon.AvailableTechs); yieldAdded = newYield - oldYield; return(true); } else { yieldAdded = YieldSummary.Empty; return(false); } }
public void BalanceHomelandYields(HomelandData homelandData) { YieldSummary currentYield = YieldSummary.Empty; foreach (var cell in homelandData.Cells) { currentYield += YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs); } float weightedCellCount = homelandData.LandCells.Count() * homelandData.YieldAndResources.LandWeight + homelandData.WaterCells.Count() * homelandData.YieldAndResources.WaterWeight; float minFood = homelandData.YieldAndResources.MinFoodPerCell * weightedCellCount; float minProduction = homelandData.YieldAndResources.MinProductionPerCell * weightedCellCount; BringYieldTypeToMin( YieldType.Food, minFood, homelandData, ref currentYield ); BringYieldTypeToMin( YieldType.Production, minProduction, homelandData, ref currentYield ); float minScore = homelandData.YieldAndResources.MinScorePerCell * weightedCellCount; float maxScore = homelandData.YieldAndResources.MaxScorePerCell * weightedCellCount; KeepScoreWithinBounds(homelandData, minScore, maxScore); }
public float GetScoreOfCell(IHexCell cell) { var ancientYield = YieldEstimator.GetYieldEstimateForCell(cell, AncientTechData); var classicalYield = YieldEstimator.GetYieldEstimateForCell(cell, ClassicalTechData); var medievalYield = YieldEstimator.GetYieldEstimateForCell(cell, MedievalTechData); var resourceNode = NodeLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault(); float ancientScore = MapScorer.GetScoreOfYield(ancientYield) + MapScorer.GetScoreOfResourceNode(resourceNode, AncientTechs); float classicalScore = MapScorer.GetScoreOfYield(classicalYield) + MapScorer.GetScoreOfResourceNode(resourceNode, ClassicalTechs); float medievalScore = MapScorer.GetScoreOfYield(medievalYield) + MapScorer.GetScoreOfResourceNode(resourceNode, MedievalTechs); return((ancientScore + classicalScore + medievalScore) / 3f); }
public bool TryIncreaseYield( MapRegion region, RegionData regionData, YieldType type, out YieldSummary yieldAdded ) { var availableResources = BonusResourcesWithYield[type].ToList(); while (availableResources.Count > 0) { var chosenResource = ResourceRandomSampler.SampleElementsFromSet( availableResources, 1, GetResourceSelectionWeightFunction(region, regionData) ).FirstOrDefault(); if (chosenResource == null) { break; } var cell = CellRandomSampler.SampleElementsFromSet( region.Cells, 1, GetCellPlacementWeightFunction(chosenResource) ).FirstOrDefault(); if (cell != null) { var oldYield = YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs); int copies = chosenResource.Type == ResourceType.Strategic ? StrategicCopiesLogic.GetWeightedRandomCopies() : 0; ResourceNodeFactory.BuildNode(cell, chosenResource, copies); yieldAdded = YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs) - oldYield; return(true); } else { availableResources.Remove(chosenResource); } } yieldAdded = YieldSummary.Empty; return(false); }
public bool TryIncreaseYield( MapRegion region, RegionData regionData, YieldType type, out YieldSummary yieldAdded ) { if (type != YieldType.Food) { yieldAdded = YieldSummary.Empty; return(false); } var candidates = region.Cells.Where(GetLakeCandidateFilter(region)); if (candidates.Any()) { var newLake = candidates.Random(); var oldYields = new Dictionary <IHexCell, YieldSummary>(); foreach (var cell in Grid.GetCellsInRadius(newLake, 1)) { oldYields[cell] = YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs); } ModLogic.ChangeTerrainOfCell(newLake, CellTerrain.FreshWater); yieldAdded = YieldSummary.Empty; foreach (var cell in oldYields.Keys) { yieldAdded += YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs) - oldYields[cell]; } return(true); } else { yieldAdded = YieldSummary.Empty; return(false); } }
public bool TryIncreaseYield( MapRegion region, RegionData regionData, YieldType type, out YieldSummary yieldAdded ) { yieldAdded = YieldSummary.Empty; if (type != YieldType.Food && type != YieldType.Gold) { return(false); } var newOasis = CellRandomSampler.SampleElementsFromSet( region.LandCells, 1, GetOasisCandidateWeightFunction(region) ).FirstOrDefault(); if (newOasis == null) { return(false); } var oldYields = new Dictionary <IHexCell, YieldSummary>(); foreach (var cell in Grid.GetCellsInRadius(newOasis, 1)) { oldYields[cell] = YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs); } ModLogic.ChangeFeatureOfCell(newOasis, CellFeature.Oasis); yieldAdded = YieldSummary.Empty; foreach (var cell in oldYields.Keys) { yieldAdded += YieldEstimator.GetYieldEstimateForCell(cell, TechCanon.AvailableTechs) - oldYields[cell]; } return(true); }