Пример #1
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);
            }
        }
Пример #2
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 turn_pregnant_some_female_when_in_couples()
        {
            for (int i = 0; i < 1000; i++)
            {
                CivPopKerbal kerbal = builder.build(0);
                kerbal.SetVesselId(vessel.GetId());
                repo.Add(kerbal);
            }
            IEnumerable <CivPopCouple> couples = service.makeCouples(0, vessel, repo);

            service.turnPregnantSomeFemales(0, couples, vessel.IsAllowBreeding());

            int count = repo.GetLivingRosterForVessel(vessel.GetId())
                        .Where(k => k.GetExpectingBirthAt() > 0)
                        .Count();

            Assert.AreEqual(14, count);
        }
        public void run(int days)
        {
            now = 1;
            for (int today = 0; today <= days; today++)
            {
                now = today * TimeUnit.DAY + 1;
                growth.Update(now, repo);
                death.Update(now, repo);

                Console.WriteLine(
                    (today / TimeUnit.DAYS_PER_YEARS)
                    + "\t" + today
                    + "\t" + repo.GetLivingRosterForVessel("vessel").Count()
                    + "\t" + repo.GetLivingRosterForVessel("vessel").Where(k => k.GetGender() == CivPopKerbalGender.MALE).Count()
                    + "\t" + repo.GetLivingRosterForVessel("vessel").Where(k => k.GetGender() == CivPopKerbalGender.FEMALE).Count()
                    + "\t" + repo.GetLivingRosterForVessel("vessel").Where(kerbal => kerbal.GetExpectingBirthAt() > 0).Count()
                    );
            }
        }
 public void Update(double date, CivPopRepository repo)
 {
     foreach (CivPopVessel vessel in repo.GetVessels())
     {
         if (vessel.IsOrbiting() &&
             vessel.GetBody().getType() != CelestialBodyType.OTHERS &&
             vessel.IsAllowDocking() &&
             vessel.GetCapacity() > repo.GetLivingRosterForVessel(vessel.GetId()).Count()
             )
         {
             if (vessel.GetMissionArrival() < 0)
             {
                 if (vessel.GetBody().getType() != CelestialBodyType.HOMEWORLD)
                 {
                     vessel.SetMissionArrival(date + MISSION_DURATION * 2);
                     vessel.SetMissionType(MOON);
                 }
                 else
                 {
                     vessel.SetMissionArrival(date + MISSION_DURATION);
                     vessel.SetMissionType(HOMEWORLD);
                 }
             }
             else
             {
                 if (HOMEWORLD.Equals(vessel.GetMissionType()) &&
                     !vessel.GetBody().getType().Equals(CelestialBodyType.HOMEWORLD))
                 {
                     CancelMission(vessel);
                 }
                 else if (MOON.Equals(vessel.GetMissionType()) &&
                          !vessel.GetBody().getType().Equals(CelestialBodyType.HOMEWORLD_MOON))
                 {
                     CancelMission(vessel);
                 }
                 else
                 {
                     if (date > vessel.GetMissionArrival())
                     {
                         CivPopKerbal kerbal = builder.build(date);
                         kerbal.SetVesselId(vessel.GetId());
                         repo.Add(kerbal);
                         CancelMission(vessel);
                     }
                 }
             }
         }
         else
         {
             CancelMission(vessel);
         }
     }
 }
        public void CreateKerbals(CivPopRepository repo, Vessel vessel)
        {
            foreach (CivPopKerbal current in repo.GetLivingRosterForVessel(vessel.id.ToString()))
            {
                var crew = vessel.GetVesselCrew().Find(c => c.name.Equals(current.GetName()));
                if (crew == null)
                {
                    var houses = vessel.FindPartModulesImplementing <CivilianPopulationHousingModule>();
                    if (houses.Count > 0)
                    {
                        foreach (var house in houses)
                        {
                            if (house.part.CrewCapacity > house.part.protoModuleCrew.Count)
                            {
                                var kspRoster = HighLogic.CurrentGame.CrewRoster;
                                var newKerbal = kspRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

                                var gender = ProtoCrewMember.Gender.Male;
                                if (current.GetGender().Equals(CivPopKerbalGender.FEMALE))
                                {
                                    gender = ProtoCrewMember.Gender.Female;
                                }

                                while (newKerbal.gender != gender || newKerbal.trait != "Civilian")
                                {
                                    kspRoster.Remove(newKerbal);
                                    newKerbal = kspRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                                }
                                if (!newKerbal.ChangeName(current.GetName()))
                                {
                                    kspRoster.Remove(newKerbal);
                                    continue;
                                }
                                if (house.part.AddCrewmember(newKerbal))
                                {
                                    vessel.SpawnCrew();
                                    Log.Info("CreateKerbals : " + newKerbal.name + " has been placed successfully");
                                    break;
                                }
                            }
                        }
                    }
                }
                crew = vessel.GetVesselCrew().Find(c => c.name.Equals(current.GetName()));
                if (crew == null)
                {
                    current.SetDead(true);
                    Log.Info("CreateKerbals : " + current.GetName() + " died because of a lack of room");
                }
            }
        }
Пример #7
0
        public void draw()
        {
            GUILayout.BeginVertical();
            foreach (CivPopVessel vessel in repo.GetVessels().OrderBy(v => v.GetId()))
            {
                if (vessel.GetCapacity() > 0)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(getVesselStatus(vessel));
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("M : " + repo.GetLivingRosterForVessel(vessel.GetId()).Count(k => k.GetGender() == CivPopKerbalGender.MALE)
                                    + " - F : " + repo.GetLivingRosterForVessel(vessel.GetId()).Count(k => k.GetGender() == CivPopKerbalGender.FEMALE)
                                    + " (" + repo.GetLivingRosterForVessel(vessel.GetId()).Count(k => k.GetExpectingBirthAt() > 0) + ")");
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("  Housing capacity : " + vessel.GetCapacity());
                    GUILayout.EndHorizontal();

                    if (vessel.GetMissionArrival() > 0)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("  Mission arrival : " + formatter.format(vessel.GetMissionArrival() - currentDate));
                        GUILayout.EndHorizontal();
                    }

                    foreach (CivPopKerbal female in repo.GetLivingRosterForVessel(vessel.GetId()).Where(k => k.GetExpectingBirthAt() > 0))
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("  " + female.GetName() + " will give birth in " + formatter.format(female.GetExpectingBirthAt() - currentDate));
                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUILayout.EndVertical();
        }
Пример #8
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);
        }