Esempio n. 1
0
        private void DistributeLuxuryAcrossSingleRegion(
            MapRegion region, int nodeCount, List <IResourceDefinition> validLuxuries,
            Dictionary <IResourceDefinition, int> weightForResources,
            HashSet <IResourceDefinition> luxuriesAlreadyChosen
            )
        {
            while (validLuxuries.Any())
            {
                var candidate = ResourceRandomSampler.SampleElementsFromSet(
                    validLuxuries, 1, luxury => weightForResources[luxury]
                    ).FirstOrDefault();
                validLuxuries.Remove(candidate);

                if (luxuriesAlreadyChosen.Contains(candidate))
                {
                    continue;
                }

                var validCells = region.Cells.Where(
                    cell => ResourceRestrictionCanon.IsResourceValidOnCell(candidate, cell)
                    );

                if (validCells.Count() >= nodeCount)
                {
                    DistributeResource(candidate, validCells, nodeCount);
                    luxuriesAlreadyChosen.Add(candidate);
                    return;
                }
            }

            Debug.LogWarning("Failed to perform luxury distribution on region");
        }
 public bool CanBuildNode(IHexCell location, IResourceDefinition resource)
 {
     if (location == null)
     {
         throw new ArgumentNullException("location");
     }
     else if (resource == null)
     {
         throw new ArgumentNullException("resource");
     }
     return(ResourceNodeLocationCanon.GetPossessionsOfOwner(location).Count() == 0 &&
            RestrictionCanon.IsResourceValidOnCell(resource, location));
 }
Esempio n. 3
0
 private Func <IResourceDefinition, int> GetResourceSelectionWeightFunction(
     MapRegion region, RegionData regionData
     )
 {
     return(delegate(IResourceDefinition resource) {
         if (region.Cells.Any(cell => ResourceRestrictionCanon.IsResourceValidOnCell(resource, cell)))
         {
             return regionData.GetWeightOfResource(resource);
         }
         else
         {
             return 0;
         }
     });
 }