Beispiel #1
0
        private List <Deposit> generate(CelestialBody body, ResourceDefinition resource)
        {
            var random = new System.Random(depositSeed ^ (resource.Resource == "Kethane" ? bodySeeds[body.name] : 0) ^ resource.SeedModifier);

            var deposits = new List <Deposit>();

            for (int i = 0; i < resource.DepositCount; i++)
            {
                float R = random.Range(resource.MinRadius, resource.MaxRadius);
                for (int j = 0; j < resource.NumberOfTries; j++)
                {
                    Vector2 Pos     = new Vector2(random.Range(R, 360 - R), random.Range(R, 180 - R));
                    var     deposit = Deposit.Generate(Pos, R, random, resource);
                    if (!deposits.Any(d => d.Shape.Vertices.Any(v => deposit.Shape.PointInPolygon(new Vector2(v.x, v.y)))) && !deposit.Shape.Vertices.Any(v => deposits.Any(d => d.Shape.PointInPolygon(new Vector2(v.x, v.y)))))
                    {
                        deposits.Add(deposit);
                        break;
                    }
                }
            }

            return(deposits);
        }
Beispiel #2
0
            public BodyDeposits(GeneratorConfiguration resource, ConfigNode node)
            {
                if (node == null)
                {
                    node = new ConfigNode();
                }

                this.deposits = new List <Deposit>();
                this.seed     = Misc.Parse(node.GetValue("Seed"), seedGenerator.Next());

                var random = new System.Random(seed);

                for (int i = 0; i < resource.DepositCount; i++)
                {
                    float R = random.Range(resource.MinRadius, resource.MaxRadius);
                    for (int j = 0; j < resource.NumberOfTries; j++)
                    {
                        Vector2 Pos     = new Vector2(random.Range(R, 360 - R), random.Range(R, 180 - R));
                        var     deposit = Deposit.Generate(Pos, R, random, resource);
                        if (!deposits.Any(d => d.Shape.Vertices.Any(v => deposit.Shape.PointInPolygon(new Vector2(v.x, v.y)))) && !deposit.Shape.Vertices.Any(v => deposits.Any(d => d.Shape.PointInPolygon(new Vector2(v.x, v.y)))))
                        {
                            deposits.Add(deposit);
                            break;
                        }
                    }
                }

                var depositValues = node.GetValues("Deposit");

                for (int i = 0; i < Math.Min(deposits.Count, depositValues.Length); i++)
                {
                    deposits[i].Quantity = Misc.Parse(depositValues[i], deposits[i].InitialQuantity);
                }

                MaxQuantity = resource.MaxQuantity;
            }