Ejemplo n.º 1
0
        private string getVesselStatus(CivPopVessel vessel)
        {
            var kVessel = FlightGlobals.Vessels
                          .Find(v => v.id.ToString().Equals(vessel.GetId()));

            var res = kVessel.GetName();

            res += " - ";
            if (!kVessel.LandedOrSplashed)
            {
                res += "in orbit around ";
            }
            else
            {
                res += "on surface of ";
            }
            res += kVessel.mainBody.name;
            var civCount = repo
                           .GetLivingRosterForVessel(vessel.GetId())
                           .Count(kerbal => kerbal.IsCivilian());

            res += " - ";
            res += civCount + " civilian";
            if (civCount > 1)
            {
                res += "s";
            }
            return(res);
        }
        public CivilianPopulationGrowthSimulator()
        {
            this.rng = new System.Random();
            this.idx = 0;

            CivPopKerbalBuilder builder = new CivPopKerbalBuilder(GetName);

            growth = new CivPopServiceGrowth(builder);
            death  = new CivPopServiceDeath();

            repo = new CivPopRepository();

            CivPopVessel vessel = new CivPopVessel("vessel");

            vessel.SetAllowBreeding(true);
            vessel.SetCapacity(1000000);
            repo.Add(vessel);

            CivPopKerbal male = new CivPopKerbal(GetName(CivPopKerbalGender.MALE), CivPopKerbalGender.MALE, 0, true);

            male.SetVesselId("vessel");
            repo.Add(male);
            CivPopKerbal female = new CivPopKerbal(GetName(CivPopKerbalGender.FEMALE), CivPopKerbalGender.FEMALE, 0, true);

            female.SetVesselId("vessel");
            repo.Add(female);
        }
Ejemplo n.º 3
0
        public void birthOfNewCivilans(double date, CivPopRepository repo)
        {
            List <CivPopKerbal> childs = new List <CivPopKerbal>();

            IEnumerable <CivPopKerbal> females = repo.GetRoster()
                                                 .Where(kerbal => kerbal.GetExpectingBirthAt() > 0)
                                                 .Where(kerbal => !kerbal.IsDead())
                                                 .Where(kerbal => kerbal.GetExpectingBirthAt() < date)
            ;

            foreach (CivPopKerbal female in females)
            {
                female.SetExpectingBirthAt(-1);
                if (female.GetVesselId() != null)
                {
                    CivPopVessel vessel = repo.GetVessel(female.GetVesselId());
                    if (vessel.GetCapacity() > repo.GetLivingRosterForVessel(vessel.GetId()).Count())
                    {
                        CivPopKerbal child = builder.build(date);
                        child.SetBirthdate(date);
                        child.SetVesselId(female.GetVesselId());
                        childs.Add(child);
                    }
                }
            }

            foreach (CivPopKerbal child in childs)
            {
                repo.Add(child);
            }
        }
Ejemplo n.º 4
0
        public void birthOfNewCivilans(double date, CivPopRepository repo)
        {
            List <CivPopKerbal> childs = new List <CivPopKerbal>();

            IEnumerable <CivPopKerbal> females = repo.GetRoster()
                                                 .Where(kerbal => kerbal.GetExpectingBirthAt() > 0)
                                                 .Where(kerbal => !kerbal.IsDead())
                                                 .Where(kerbal => kerbal.GetExpectingBirthAt() < date)
            ;

            foreach (CivPopKerbal female in females)
            {
                female.SetExpectingBirthAt(-1);
                if (female.GetVesselId() != null)
                {
                    CivPopVessel vessel = repo.GetVessel(female.GetVesselId());
                    if (vessel.GetCapacity() > repo.GetLivingRosterForVessel(vessel.GetId()).Count())
                    {
                        CivPopKerbal child = builder.build(date);
                        child.SetBirthdate(date);
                        child.SetVesselId(female.GetVesselId());

                        ProtoCrewMember pcm = new ProtoCrewMember(ProtoCrewMember.KerbalType.Crew, child.GetName());
                        KerbalRoster.SetExperienceTrait(pcm, "Civilian");//Set the Kerbal as the specified role (kerbalTraitName)
                        var plist = vessel.KSPVessel.parts.FindAll(p => p.CrewCapacity > p.protoModuleCrew.Count);

                        // There may be a better way, but this will look for space in the same part as the female giving birth
                        Part part = null;
                        foreach (var p in plist)
                        {
                            var crew = p.protoModuleCrew.Find(c => c.name == female.GetName());
                            if (crew != null)
                            {
                                part = p;
                                SimpleLogger.fetch.Info("Crew member: " + female.GetName() + ", found on part: " + p.partInfo.title);
                                break;
                            }
                        }
                        // If part is null, no room in same part, so just find a part with room
                        if (part == null)
                        {
                            part = vessel.KSPVessel.parts.Find(p => p.CrewCapacity > p.protoModuleCrew.Count);
                        }
                        if (part != null)
                        {
                            part.AddCrewmember(pcm);
                            vessel.KSPVessel.SpawnCrew();
                            SimpleLogger.fetch.Info("Child added to childs, name: " + child.GetName());
                        }
                        childs.Add(child);
                    }
                }
            }

            foreach (CivPopKerbal child in childs)
            {
                repo.Add(child);
            }
        }
        public void SetUp()
        {
            CivPopKerbalBuilder builder = new CivPopKerbalBuilder(g => Guid.NewGuid().ToString());

            repo = new CivPopRepository();

            vessel = new CivPopVessel("vessel");
            repo.Add(vessel);
            vessel.SetCapacity(4);

            service = new CivPopServiceContractors(builder);
        }
        public void SetUp()
        {
            System.Random rng = new System.Random(42);

            builder = new CivPopKerbalBuilder(g => Guid.NewGuid().ToString(), rng);

            repo   = new CivPopRepository();
            vessel = new CivPopVessel("vessel");
            vessel.SetAllowBreeding(true);
            repo.Add(vessel);

            service = new CivPopServiceGrowth(builder, rng);
        }
Ejemplo n.º 7
0
        public IEnumerable <CivPopCouple> makeCouples(double date, CivPopVessel vessel, CivPopRepository repo)
        {
            IEnumerable <CivPopKerbal> adults
                = repo.GetLivingRosterForVessel(vessel.GetId())
                  .Where(kerbal => kerbal.getAge(date) != CivilianKerbalAge.YOUNG);

            IEnumerable <CivPopKerbal> males
                = adults.Where(kerbal => kerbal.GetGender() == CivPopKerbalGender.MALE);
            IEnumerable <CivPopKerbal> females
                = adults.Where(kerbal => kerbal.GetGender() == CivPopKerbalGender.FEMALE);


            List <CivPopKerbal> availableMales = new List <CivPopKerbal>();

            foreach (CivPopKerbal kerbal in males)
            {
                if (rng.Next() % MALE_AVAILABILITY == 0)
                {
                    availableMales.Add(kerbal);
                }
            }

            List <CivPopKerbal> availableFemales = new List <CivPopKerbal>();

            foreach (CivPopKerbal kerbal in females)
            {
                if (rng.Next() % FEMALE_AVAILABILITY == 0)
                {
                    availableFemales.Add(kerbal);
                }
            }

            List <CivPopCouple> couples = new List <CivPopCouple>();

            foreach (CivPopKerbal male in availableMales)
            {
                if (availableFemales.Count > 0)
                {
                    int          index  = rng.Next() % availableFemales.Count();
                    CivPopKerbal female = availableFemales[index];
                    availableFemales.RemoveAt(index);
                    couples.Add(new CivPopCouple(male, female));
                }
            }
            return(couples);
        }
        private void UpdateRepository(CivPopRepository repo)
        {
            if (repo.GetFunds() > 0)
            {
                Funding.Instance.AddFunds(repo.GetFunds(), TransactionReasons.Progression);
                repo.AddFunds(repo.GetFunds() * -1);
            }

            ProtoCrewMember.KerbalType type = ProtoCrewMember.KerbalType.Crew;
            //ProtoCrewMember.KerbalType.Applicant;
            //ProtoCrewMember.KerbalType.Crew;
            //ProtoCrewMember.KerbalType.Tourist;
            //ProtoCrewMember.KerbalType.Unowned;

            ProtoCrewMember.RosterStatus[] statuses =
            {
                ProtoCrewMember.RosterStatus.Assigned,
                ProtoCrewMember.RosterStatus.Available,
                ProtoCrewMember.RosterStatus.Dead,
                ProtoCrewMember.RosterStatus.Missing
            };
            IEnumerable <ProtoCrewMember> kerbals = HighLogic.CurrentGame.CrewRoster.Kerbals(type, statuses);

            foreach (ProtoCrewMember kerbal in kerbals)
            {
                CivPopKerbal civKerbal = repo.GetKerbal(kerbal.name);
                if (civKerbal == null)
                {
                    string             kerbalName = kerbal.name;
                    CivPopKerbalGender gender     = CivPopKerbalGender.FEMALE;
                    if (ProtoCrewMember.Gender.Male.Equals(kerbal.gender))
                    {
                        gender = CivPopKerbalGender.MALE;
                    }
                    double birthdate = Planetarium.GetUniversalTime() - 15 * TimeUnit.YEAR - rng.Next(15 * TimeUnit.YEAR);
                    civKerbal = new CivPopKerbal(kerbalName, gender, birthdate, false);
                }
                bool civilian = "Civilian".Equals(kerbal.trait);
                civKerbal.SetCivilian(civilian);
                if (ProtoCrewMember.RosterStatus.Assigned.Equals(kerbal.rosterStatus))
                {
                    repo.Add(civKerbal);
                }
                else
                {
                    repo.Remove(civKerbal);
                }
            }

            foreach (Vessel vessel in FlightGlobals.Vessels)
            {
                CivPopVessel civVessel;
                if (vessel != null && !repo.VesselExists(vessel.id.ToString()))
                {
                    civVessel = new CivPopVessel(vessel);
                }
                else
                {
                    civVessel = repo.GetVessel(vessel.id.ToString());
                }
                civVessel.SetOrbiting(!vessel.LandedOrSplashed);
                civVessel.SetBody(new Domain.CelestialBody(vessel.mainBody.name, GetBodyType(vessel.mainBody)));

                foreach (VesselModule module in vessel.vesselModules)
                {
                    if (module.GetType() == typeof(CivilianPopulationVesselModule))
                    {
                        CivilianPopulationVesselModule civModule = (CivilianPopulationVesselModule)module;
                        civVessel.SetCapacity(civModule.capacity);
                        civVessel.SetAllowDocking(civModule.allowDocking);
                        civVessel.SetAllowBreeding(civModule.allowBreeding);
                    }
                }

                foreach (ProtoCrewMember kerbal in vessel.GetVesselCrew())
                {
                    CivPopKerbal civKerbal = repo.GetKerbal(kerbal.name);
                    if (civKerbal != null)
                    {
                        civKerbal.SetVesselId(vessel.id.ToString());
                    }
                }
                repo.Add(civVessel);
            }

            foreach (CivPopVessel civVessel in repo.GetVessels())
            {
                bool found = false;
                foreach (Vessel vessel in FlightGlobals.Vessels)
                {
                    if (vessel != null && vessel.id.ToString().Equals(civVessel.GetId()))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    repo.Remove(civVessel);
                }
            }
        }
 private void CancelMission(CivPopVessel vessel)
 {
     vessel.SetMissionArrival(-1);
     vessel.SetMissionType(null);
 }