Esempio n. 1
0
 protected override void DoUpdate(double date, CivPopRepository repo)
 {
     SimpleLogger.fetch.Info("DoUpdate, repo.Count: " + repo.GetVessels().Count());
     foreach (CivPopVessel vessel in repo.GetVessels())
     {
         if (vessel.KSPVessel == null)
         {
             SimpleLogger.fetch.Info("KSPVessel is null");
         }
         else
         {
             IEnumerable <CivPopCouple> couples = makeCouples(date, vessel, repo);
             turnPregnantSomeFemales(vessel.KSPVessel, date, couples, vessel.IsAllowBreeding());
         }
     }
     birthOfNewCivilans(date, repo);
 }
Esempio n. 2
0
 protected override void DoUpdate(double date, CivPopRepository repo)
 {
     foreach (CivPopVessel vessel in repo.GetVessels())
     {
         IEnumerable <CivPopCouple> couples = makeCouples(date, vessel, repo);
         turnPregnantSomeFemales(date, couples, vessel.IsAllowBreeding());
     }
     birthOfNewCivilans(date, repo);
 }
 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);
         }
     }
 }
Esempio n. 4
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();
        }
        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);
                }
            }
        }