public static CelestialBody TargetBody(Contract c) { if (c == null || c.GetType() != typeof(EnterSOI)) { return(null); } try { EnterSOI Instance = (EnterSOI)c; return(Instance.body); } catch (Exception e) { Debug.LogError("Errorwhile accessing EnterSoi contract Target Body\n" + e); return(null); } }
protected override bool Generate() { EnterSOI[] SOIContracts = ContractSystem.Instance.GetCurrentContracts <EnterSOI>(); int offers = 0; int active = 0; int MaxOffers = 1; int MaxActive = 3; for (int i = 0; i < SOIContracts.Length; i++) { EnterSOI m = SOIContracts[i]; if (m.ContractState == State.Offered) { offers++; } else if (m.ContractState == State.Active) { active++; } } if (offers >= MaxOffers) { return(false); } else if (active >= MaxActive) { return(false); } List <CelestialBody> bodies = new List <CelestialBody>(); Func <CelestialBody, bool> cb = null; switch (prestige) { case ContractPrestige.Trivial: cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Sun) { return(false); } if (b.scienceValues.RecoveryValue > 4) { return(false); } return(true); }; bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.ORBIT, true, cb)); bodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb)); break; case ContractPrestige.Significant: cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Sun) { return(false); } if (b == Planetarium.fetch.Home) { return(false); } if (b.scienceValues.RecoveryValue > 8) { return(false); } return(true); }; bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb)); bodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb)); break; case ContractPrestige.Exceptional: cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Home) { return(false); } if (Planetarium.fetch.Home.orbitingBodies.Count > 0) { foreach (CelestialBody B in Planetarium.fetch.Home.orbitingBodies) { if (b == B) { return(false); } } } if (b.scienceValues.RecoveryValue < 4) { return(false); } return(true); }; bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb)); bodies.AddRange(ProgressUtilities.GetNextUnreached(4, cb)); break; } if (bodies.Count <= 0) { return(false); } body = bodies[rand.Next(0, bodies.Count)]; if (body == null) { return(false); } this.AddParameter(new Contracts.Parameters.EnterSOI()); if (this.ParameterCount == 0) { return(false); } float primaryModifier = ((float)rand.Next(80, 121) / 100f); float diffModifier = 1 + ((float)this.Prestige * 0.5f); float Mod = primaryModifier * diffModifier; this.agent = AgentList.Instance.GetAgent("Kerbin World - Firsts Record - Keeping Society"); base.SetExpiry(1, 100); base.SetScience(20F); base.SetDeadlineYears(100F); base.SetReputation(5F, -2F); base.SetFunds(30000F, 50000F, -3000F); return(true); }