コード例 #1
0
 public CivPopKerbal(Hashtable value)
 {
     if (!value.Contains("name"))
     {
         throw new Exception("no name");
     }
     if (!value.Contains("civilian"))
     {
         throw new Exception("no civilian");
     }
     this.name = (string)value["name"];
     if ((bool)value["male"])
     {
         this.gender = CivPopKerbalGender.MALE;
     }
     else
     {
         this.gender = CivPopKerbalGender.FEMALE;
     }
     this.birthdate        = (double)value["birthdate"];
     this.dead             = (bool)value["dead"];
     this.expectingBirthAt = (double)value["expectingBirthAt"];
     this.civilian         = (bool)value["civilian"];
     this.vesselId         = (string)value["vesselId"];
 }
コード例 #2
0
 public CivPopKerbal(string name, CivPopKerbalGender gender, double birthdate, bool civilian)
 {
     this.name             = name;
     this.gender           = gender;
     this.birthdate        = birthdate;
     this.dead             = false;
     this.expectingBirthAt = -1;
     this.civilian         = civilian;
     this.vesselId         = null;
 }
コード例 #3
0
        public CivPopKerbal build(double date)
        {
            CivPopKerbalGender gender = CivPopKerbalGender.FEMALE;

            if (rng.Next() % 2 == 0)
            {
                gender = CivPopKerbalGender.MALE;
            }
            double age = date - 15 * TimeUnit.YEAR - rng.Next(15 * TimeUnit.YEAR);

            return(new CivPopKerbal(getName(gender), gender, age, true));
        }
コード例 #4
0
        private string GenerateKerbalName(CivPopKerbalGender gender)
        {
            string res;

            if (CivPopKerbalGender.MALE.Equals(gender))
            {
                res = CrewGenerator.GetRandomName(ProtoCrewMember.Gender.Male);
            }
            else
            {
                res = CrewGenerator.GetRandomName(ProtoCrewMember.Gender.Female);
            }
            return(res);
        }
 public string GetName(CivPopKerbalGender gender)
 {
     this.idx++;
     return("kerbal-" + idx);
 }
コード例 #6
0
        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 string generateName(CivPopKerbalGender gender)
 {
     return(Guid.NewGuid().ToString());
 }