void ProcessSatellites(CelestialObject parent, int orbitNestingLevel, CelestialObject star)
 {
     foreach (var body in CelestialObjects.Where(o => o.ParentObject == parent.CelestialObjectID))
     {
         body.OrbitNestingLevel = orbitNestingLevel;
         body.Parent            = parent;
         body.ParentStar        = star;
         body.StarMap           = this;
         ProcessSatellites(body, orbitNestingLevel + 1, star);
     }
 }
 public void Initialize()
 {
     if (isInitialized)
     {
         return;
     }
     isInitialized        = true;
     Config.RetrievalTime = DateTime.Now;
     players = Players.ToDictionary(p => p.PlayerID);
     foreach (var star in CelestialObjects.Where(o => o.CelestialObjectType == CelestialObjectType.Star))
     {
         star.StarMap = this;
         star.Size    = 10;
         ProcessSatellites(star, 1, star);
     }
     foreach (var body in CelestialObjects)
     {
         body.Children = CelestialObjects.Where(o => o.ParentObject == body.CelestialObjectID).ToArray(); // todo: don't use linear search?
     }
 }
Ejemplo n.º 3
0
        public void ApplyResourceTurn(int turn)
        {
            MetalIncome        = 0;
            FoodIncome         = 0;
            QuantiumIncome     = 0;
            DarkMatterIncome   = 0;
            ResearchIncome     = 0;
            PopulationCapacity = 0;


            var curPeople = 0;

            foreach (var o in CelestialObjects)
            {
                curPeople = o.Population;
            }

            foreach (var t in PopulationTransports)
            {
                curPeople += t.Count;
            }

            FoodIncome -= curPeople;

            foreach (var o in CelestialObjects)
            {
                MetalIncome        += o.MetalIncome * o.Efficiency;
                FoodIncome         += o.FoodIncome * o.Efficiency;
                QuantiumIncome     += o.QuantiumIncome * o.Efficiency;
                DarkMatterIncome   += o.DarkMatterIncome * o.Efficiency;
                ResearchIncome     += o.ResearchIncome * o.Efficiency;
                PopulationCapacity += o.MaxPopulation;
                o.BuildpowerUsed    = 0;             // reset bp to 0
            }

            Metal          += MetalIncome;
            Food           += FoodIncome;
            Quantium       += QuantiumIncome;
            DarkMatter     += DarkMatterIncome;
            ResearchPoints += ResearchIncome;

            if (Food < 0)
            {
                var toKill = 1 + (int)-Food;

                curPeople -= toKill;
                if (curPeople < 0)
                {
                    curPeople = 0;
                }

                Food = 0;
                foreach (var o in CelestialObjects.OrderByDescending(x => x.Population))
                {
                    if (o.Population > 0)
                    {
                        var killed = Math.Min(o.Population, toKill);
                        o.Population -= killed;
                        o.UpdateIncomeInfo();
                        var ev = Event1.CreateEvent(EventType.Player, turn, "{0}m people have died on planet {1} from starvation", killed, o.Name);
                        ev.Connect(this);
                        ev.Connect(o);

                        toKill -= killed;
                    }
                    if (toKill <= 0)
                    {
                        break;
                    }
                }
            }

            Population = curPeople;
        }
Ejemplo n.º 4
0
        private void GenerateObjects()
        {
            var takenPoints = new List <Point>();

            takenPoints.Add(new Point(Program.Player.X, Program.Player.Y));
            // Check to see if this is the first sector... if it is, we don't want to make a link to itself
            if (Program.CurrentSector > 0)
            {
                Point p = GenerateRandomPoint(takenPoints);
                CelestialObjects.Add(new Wormhole(Links[0])
                {
                    Color  = RLColor.Blue,
                    Symbol = '@',
                    X      = p.X,
                    Y      = p.Y,
                    Menu   = new WormholeMenu()
                });
            }

            int runTimes = Ran.dom.Next(2, 4);

            for (int i = 0; i < runTimes; i++)
            {
                Point point = GenerateRandomPoint(takenPoints);
                CelestialObjects.Add(new Wormhole(++Program.CurrentSector)
                {
                    Color  = RLColor.Blue,
                    Symbol = '@',
                    X      = point.X,
                    Y      = point.Y,
                    Menu   = new WormholeMenu()
                });
                Links.Add(Program.CurrentSector);
            }


            runTimes = Ran.dom.Next(2, 15);
            for (int i = 0; i < runTimes; i++)
            {
                Point point = GenerateRandomPoint(takenPoints);
                CelestialObjects.Add(new Nebula()
                {
                    Color     = RLColor.LightRed,
                    Name      = "Nebula " + i,
                    Symbol    = '#',
                    TotalFuel = Ran.dom.Next(0, 100),
                    X         = point.X,
                    Y         = point.Y,
                    Menu      = new NebulaMenu()
                });
                point = GenerateRandomPoint(takenPoints);
                CelestialObjects.Add(new Wreckage()
                {
                    Color            = RLColor.Yellow,
                    Name             = "Wreckage " + i,
                    Symbol           = 'W',
                    SalvageAvailable = Ran.dom.Next(0, 50),
                    X    = point.X,
                    Y    = point.Y,
                    Menu = new WreckageMenu()
                });
            }

            runTimes = Ran.dom.Next(2, 4);
            for (int i = 0; i < runTimes; i++)
            {
                Point point = GenerateRandomPoint(takenPoints);
                CelestialObjects.Add(new Station()
                {
                    Color  = RLColor.LightBlue,
                    Name   = "Nebula " + i,
                    Symbol = 'S',
                    X      = point.X,
                    Y      = point.Y,
                    Menu   = new StationMenu()
                });
            }
        }