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 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); } }
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 launch_a_mission_to_replace_a_dead_crew() { vessel.SetOrbiting(true); vessel.SetBody(KERBIN); vessel.SetMissionType(null); vessel.SetMissionArrival(-1); vessel.SetAllowDocking(true); for (int i = 0; i < 4; i++) { CivPopKerbal kerbal = new CivPopKerbal("kerbal" + i, CivPopKerbalGender.FEMALE, 0, true); repo.Add(kerbal); kerbal.SetVesselId(vessel.GetId()); repo.Kill(kerbal); } service.Update(0, repo); Assert.AreEqual(TimeUnit.DAY * 85, repo.GetVessel("vessel").GetMissionArrival()); Assert.AreEqual("HOMEWORLD", repo.GetVessel("vessel").GetMissionType()); }
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); }
public void create_no_couples_when_no_females() { for (int i = 0; i < 100; i++) { CivPopKerbal kerbal = builder.build(0); kerbal.SetVesselId(vessel.GetId()); if (CivPopKerbalGender.MALE.Equals(kerbal.GetGender())) { repo.Add(kerbal); } } IEnumerable <CivPopCouple> couples = service.makeCouples(0, vessel, repo); Assert.AreEqual(0, couples.Count()); }