public void DistributeStrategicsAcrossHomeland(HomelandData homelandData) { int nodesLeft = Mathf.CeilToInt(homelandData.YieldAndResources.StrategicNodesPerCell * homelandData.Cells.Count()); int copiesLeft = Mathf.CeilToInt(homelandData.YieldAndResources.StrategicCopiesPerCell * homelandData.Cells.Count()); var validStrategics = new List <IResourceDefinition>(StrategicResources); var resourceWeightsByRegion = new Dictionary <MapRegion, Dictionary <IResourceDefinition, int> >(); foreach (var region in homelandData.AllRegions) { resourceWeightsByRegion[region] = homelandData.GetDataOfRegion(region).GetResourceWeights(); } var regions = homelandData.AllRegions.ToList(); int iterations = regions.Count * 10; while (nodesLeft > 0 && copiesLeft > 0 && iterations-- > 0) { if (regions.Count == 0) { regions.AddRange(homelandData.AllRegions); } var region = regions.Random(); regions.Remove(region); var resourceWeights = resourceWeightsByRegion[region]; var strategic = ResourceRandomSampler.SampleElementsFromSet( validStrategics, 1, resource => resourceWeights.ContainsKey(resource) ? resourceWeights[resource] : 0 ).FirstOrDefault(); if (strategic == null) { continue; } var location = CellRandomSampler.SampleElementsFromSet( region.Cells, 1, cell => ResourceRestrictionCanon.GetPlacementWeightOnCell(strategic, cell) ).FirstOrDefault(); if (location != null && NodeFactory.CanBuildNode(location, strategic)) { int copies = StrategicCopiesLogic.GetWeightedRandomCopies(); copies = Math.Min(copies, copiesLeft); NodeFactory.BuildNode(location, strategic, copies); nodesLeft--; copiesLeft -= copies; } } }
private Func <IHexCell, int> GetCellPlacementWeightFunction(IResourceDefinition resource) { return(delegate(IHexCell cell) { if (ResourceNodeFactory.CanBuildNode(cell, resource)) { return ResourceRestrictionCanon.GetPlacementWeightOnCell(resource, cell); } else { return 0; } }); }
private Func <IHexCell, int> GetResourceWeightFunction(IResourceDefinition resource) { return(delegate(IHexCell cell) { return ResourceRestrictionCanon.GetPlacementWeightOnCell(resource, cell); }); }