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 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()); }
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); } } }