Exemplo n.º 1
0
        //active version:
        //number of asteroid circles, planets and else is calculated before the elements are generated
        // 1 : 5 - 13
        // 2 : 5 - 14, danach per Zufall, aber nicht zu nah an dem ersten...
        // 3 : 5 - 15, danach per Zufall, aber nicht zu nah an dem ersten...
        //check if a circle and the next two circles are not asteroidic

        //
        private void createPlanetCircle(int _circleNo, int type)
        {
            if (_circleNo > 10)
            {
                return;
            }

            systemElement planet = createElement(_circleNo, 0);

            while (true)
            {
                int angle = randomGenerator.Next(360);
                planet.x = (int)(centerX + (_circleNo + 2) * Math.Cos(angle));
                planet.y = (int)(centerX + (_circleNo + 2) * Math.Sin(angle));

                neighbouringStars.Clear();
                neighbouringStars.Add(systemElements[planet.id - 1]);
                if (planet.id > 1)
                {
                    neighbouringStars.Add(systemElements[planet.id - 2]);
                }

                //if (planet.id > 3) neighbouringStars.Add(systemElements[planet.id - 3]);

                //if (planet.id > 6) neighbouringStars.Add(systemElements[planet.id - 3]);

                if (systemElements.Any(e => e.id != planet.id && e.x == planet.x && e.y == planet.y))
                {
                    continue;
                }

                if (planet.checkAgainstNeighbours(neighbouringStars, _circleNo))
                {
                    break;
                }
            }
            planet.type = type;
            writeCoords(planet);
            if (planet.type != 32)
            {
                PlanetsCount++;                    //Gas giants are not counted
            }
            if (planet.type == 25 || planet.type == 26 || planet.type == 24)
            {
                HabitablePlanetsCount++;
            }
        }
Exemplo n.º 2
0
        private void createMoons()
        {
            for (int i = 0; i < systemElements.Count; i++)
            {
                if (systemElements[i].circleNo < 2)
                {
                    continue;                                 //innermost circle has no moons
                }
                if (systemElements[i].type == 10 || systemElements[i].type == 11)
                {
                    continue;                                                               //no asteroid has moons
                }
                if (systemElements[i].childOf > 0)
                {
                    continue;                                   //moons themselves do not have moons
                }
                int numberOfMoons = randomGenerator.Next(0, 3); //up to two moons
                int firstMoonX    = -10;
                int firstMoonY    = -10;
                for (int j = 0; j < numberOfMoons; j++)
                {
                    int newX = systemElements[i].x;
                    int newY = systemElements[i].y;

                    systemElement dummymoon  = createDummyElement(systemElements[i].circleNo, systemElements[i].id);
                    bool          skip       = false;
                    int           retryCount = 0;
                    while (true)
                    {
                        retryCount++;
                        if (retryCount == 100)
                        {
                            skip = true;
                            break;
                        }

                        newX = randomGenerator.Next(-1, 2) + systemElements[i].x;
                        newY = randomGenerator.Next(-1, 2) + systemElements[i].y;
                        if (newX == systemElements[i].x && newY == systemElements[i].y)
                        {
                            continue;                                                             //moon has to be on a diefferent position than its planet
                        }
                        if (newX == firstMoonX && newY == firstMoonY)
                        {
                            continue;                                           //moon has to be on a diefferent position than its sibling-moon (values are set by the first moon
                        }
                        //todo: check that moon is not on same field as asteroid...
                        systemElement coordCheck = findSystemElementsWithCoords(newX, newY);
                        if (coordCheck != null)
                        {
                            continue;
                        }

                        dummymoon.x = newX;
                        dummymoon.y = newY;
                        neighbouringStars.Clear();
                        for (int z = 0; z < systemElements.Count; z++)
                        {
                            if (systemElements[z].type == 10 || systemElements[z].type == 11 || // no asteroids to check
                                systemElements[z].id == systemElements[i].id ||           //not the own motherplanet to check
                                systemElements[z].childOf == systemElements[i].id)        //not the sibling to check
                            {
                                continue;
                            }

                            neighbouringStars.Add(systemElements[z]);
                        }

                        if (dummymoon.checkAgainstNeighbours(neighbouringStars, 2))
                        {
                            break;
                        }
                    }
                    if (skip)
                    {
                        continue;
                    }

                    systemElement moon = createFromDummyElement(dummymoon);
                    firstMoonX = moon.x;
                    firstMoonY = moon.y;
                    moon.type  = typeDetector.getMoonType(systemElements[i].circleNo);
                    writeCoords(moon);
                }
            }
        }