public void add_rent_every_day_for_1_civilian() { CivPopRepository repo = new CivPopRepository(); repo.Add(new CivPopVessel("vessel")); CivPopKerbal valentina = new CivPopKerbal("Valentina", CivPopKerbalGender.FEMALE, 0, true); repo.Add(valentina); valentina.SetVesselId("vessel"); CivPopKerbal bill = new CivPopKerbal("Bill", CivPopKerbalGender.MALE, 0, false); repo.Add(bill); bill.SetVesselId("vessel"); CivPopServiceRent service = new CivPopServiceRent(); double date = 0; service.Update(date, repo); Assert.AreEqual(0, repo.GetFunds()); date += 60 * 60; service.Update(date, repo); Assert.AreEqual(0, repo.GetFunds()); date += TimeUnit.DAY; service.Update(date, repo); Assert.AreEqual(200, repo.GetFunds()); date += TimeUnit.DAY; service.Update(date, repo); Assert.AreEqual(400, repo.GetFunds()); }
public void not_add_rent_for_1_civilians_on_KSC() { CivPopRepository repo = new CivPopRepository(); repo.Add(new CivPopKerbal("Valentina", CivPopKerbalGender.FEMALE, 0, true)); CivPopServiceRent service = new CivPopServiceRent(); double date = 0; service.Update(date, repo); Assert.AreEqual(0, repo.GetFunds()); date += 60 * 60; service.Update(date, repo); Assert.AreEqual(0, repo.GetFunds()); date += TimeUnit.DAY; service.Update(date, repo); Assert.AreEqual(0, repo.GetFunds()); date += TimeUnit.DAY; service.Update(date, repo); Assert.AreEqual(0, repo.GetFunds()); }
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); } } }