public bool TestProgressionRequirements() { RequireResult[] results = new RequireResult[Requires.Length]; for (int i = 0; i < Requires.Length; i++) { results[i] = new RequireResult(Requires[i]); switch (Requires[i].require) { case Require.AstronautComplexLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.AstronautComplex), (int)Requires[i].value, results[i]); break; case Require.AstronautComplexLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.AstronautComplex), (int)Requires[i].value, results[i]); break; case Require.TrackingStationLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.TrackingStation), (int)Requires[i].value, results[i]); break; case Require.TrackingStationLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.TrackingStation), (int)Requires[i].value, results[i]); break; case Require.MissionControlLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.MissionControl), (int)Requires[i].value, results[i]); break; case Require.MissionControlLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.MissionControl), (int)Requires[i].value, results[i]); break; case Require.AdministrationLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.Administration), (int)Requires[i].value, results[i]); break; case Require.AdministrationLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.Administration), (int)Requires[i].value, results[i]); break; default: results[i].isValid = true; break; } if (!results[i].isValid) { return(false); } } return(true); }
public async Task <List <RequireResult> > CheckRequireListAsync(RequireData data) { List <RequireResult> resultlist = new List <RequireResult>(); RequireResult rr = null; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { rr = new RequireResult(); rr.Result = true; rr.Result = true; resultlist.Add(rr); return(resultlist); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandlerAsync handler; string prefix = null; string k = null; for (int i = 0; i < key.Length; i++) { try { k = key[i]; if (string.IsNullOrEmpty(k) || k == "0") { continue; } rr = new RequireResult(); prefix = k.Substring(0, 1); k = k.Substring(1); handler = mapAsync.Get(prefix); if (handler == null) { rr.Result = false; rr.Reason = "can not find require handler"; } else { var ret = await handler.Invoke(k, min[i], max[i]); rr.Result = ret.Item1; rr.CurVal = ret.Item2; rr.MaxVal = max[i]; rr.MinVal = min[i]; if (text != null) { rr.Reason = text[i]; } } } catch (Exception) { string info = string.Format("checkRequire Error key={0},min={1},max={2},reason{3}", key[i], min[i], max[i], text[i]); throw new Exception(info); } resultlist.Add(rr); } return(resultlist); }
public async Task <RequireResult> CheckDetailRequireByAppendCountAsync(RequireData data, int index, int count) { RequireResult result = new RequireResult(); result.Result = true; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { return(result); } if (data.Key.Length <= index) { result.Result = false; return(result); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandlerAsync handler; string k = key[index]; if (string.IsNullOrEmpty(k) || k == "0") { return(result); } string prefix = k.Substring(0, 1); handler = mapAsync.Get(prefix); if (handler == null) { result.Result = false; return(result); } var tuple = await handler.Invoke(k, min[index], max[index]); if (tuple.Item1 == false) { result.Result = false; if (text != null && index < text.Length) { result.Reason = text[index]; } return(result); } else { var checkVal = tuple.Item2 + count; if (max[index] == -1) { if (checkVal < min[index]) { result.Result = false; if (text != null && index < text.Length) { result.Reason = text[index]; } } } else { if (!(checkVal >= min[index] && checkVal < max[index])) { result.Result = false; if (text != null && index < text.Length) { result.Reason = text[index]; } } } return(result); } }
public async Task <RequireResult> CheckRequireAsync(RequireData data) { RequireResult result = new RequireResult(); result.Result = true; result.Reason = string.Empty; if (data == null || data.Key == null || data.Maxval == null || data.Minval == null) { return(result); } string[] key = data.Key; int[] min = data.Minval; int[] max = data.Maxval; string[] text = data.Text; CheckHandlerAsync handler; string prefix = null; string k = null; for (int i = 0; i < key.Length; i++) { try { k = key[i]; if (string.IsNullOrEmpty(k) || k == "0") { return(result); } prefix = k.Substring(0, 1); k = k.Substring(1); handler = mapAsync.Get(prefix); if (handler == null) { result.Result = false; return(result); } var tuple = await handler.Invoke(k, min[i], max[i]); if (tuple.Item1 == false) { if (text != null && i < text.Length) { result.Reason = text[i]; } result.Result = false; return(result); } } catch (Exception) { string info = string.Format("checkRequire Error key={0},min={1},max={2},reason{3}", key[i], min[i], max[i]); throw new Exception(info); } } return(result); }
private void TestReq <T, U>(Func <T, U, bool> Condition, T val, U reqVal, RequireResult result) { result.value = val; result.isValid = Condition(val, reqVal); }
private void TestReq(Func <bool> Condition, RequireResult result) { result.isValid = Condition(); }
public bool TestRequirements(Vessel v, out RequireResult[] results, bool testAll = false) { UnityEngine.Profiling.Profiler.BeginSample("Kerbalism.ExperimentRequirements.TestRequirements"); VesselData vd = v.KerbalismData(); results = new RequireResult[Requires.Length]; bool good = true; for (int i = 0; i < Requires.Length; i++) { results[i] = new RequireResult(Requires[i]); switch (Requires[i].require) { case Require.OrbitMinInclination: TestReq((c, r) => c >= r, v.orbit.inclination, (double)Requires[i].value, results[i]); break; case Require.OrbitMaxInclination: TestReq((c, r) => c <= r, v.orbit.inclination, (double)Requires[i].value, results[i]); break; case Require.OrbitMinEccentricity: TestReq((c, r) => c >= r, v.orbit.eccentricity, (double)Requires[i].value, results[i]); break; case Require.OrbitMaxEccentricity: TestReq((c, r) => c <= r, v.orbit.eccentricity, (double)Requires[i].value, results[i]); break; case Require.OrbitMinArgOfPeriapsis: TestReq((c, r) => c >= r, v.orbit.argumentOfPeriapsis, (double)Requires[i].value, results[i]); break; case Require.OrbitMaxArgOfPeriapsis: TestReq((c, r) => c <= r, v.orbit.argumentOfPeriapsis, (double)Requires[i].value, results[i]); break; case Require.TemperatureMin: TestReq((c, r) => c >= r, vd.EnvTemperature, (double)Requires[i].value, results[i]); break; case Require.TemperatureMax: TestReq((c, r) => c <= r, vd.EnvTemperature, (double)Requires[i].value, results[i]); break; case Require.AltitudeMin: TestReq((c, r) => c >= r, v.altitude, (double)Requires[i].value, results[i]); break; case Require.AltitudeMax: TestReq((c, r) => c <= r, v.altitude, (double)Requires[i].value, results[i]); break; case Require.RadiationMin: TestReq((c, r) => c >= r, vd.EnvRadiation, (double)Requires[i].value, results[i]); break; case Require.RadiationMax: TestReq((c, r) => c <= r, vd.EnvRadiation, (double)Requires[i].value, results[i]); break; case Require.VolumePerCrewMin: TestReq((c, r) => c >= r, vd.VolumePerCrew, (double)Requires[i].value, results[i]); break; case Require.VolumePerCrewMax: TestReq((c, r) => c <= r, vd.VolumePerCrew, (double)Requires[i].value, results[i]); break; case Require.SunAngleMin: TestReq((c, r) => c >= r, vd.EnvSunBodyAngle, (double)Requires[i].value, results[i]); break; case Require.SunAngleMax: TestReq((c, r) => c <= r, vd.EnvSunBodyAngle, (double)Requires[i].value, results[i]); break; case Require.SurfaceSpeedMin: TestReq((c, r) => c >= r, v.srfSpeed, (double)Requires[i].value, results[i]); break; case Require.SurfaceSpeedMax: TestReq((c, r) => c <= r, v.srfSpeed, (double)Requires[i].value, results[i]); break; case Require.VerticalSpeedMin: TestReq((c, r) => c >= r, v.verticalSpeed, (double)Requires[i].value, results[i]); break; case Require.VerticalSpeedMax: TestReq((c, r) => c <= r, v.verticalSpeed, (double)Requires[i].value, results[i]); break; case Require.SpeedMin: TestReq((c, r) => c >= r, v.speed, (double)Requires[i].value, results[i]); break; case Require.SpeedMax: TestReq((c, r) => c <= r, v.speed, (double)Requires[i].value, results[i]); break; case Require.DynamicPressureMin: TestReq((c, r) => c >= r, v.dynamicPressurekPa, (double)Requires[i].value, results[i]); break; case Require.DynamicPressureMax: TestReq((c, r) => c <= r, v.dynamicPressurekPa, (double)Requires[i].value, results[i]); break; case Require.StaticPressureMin: TestReq((c, r) => c >= r, v.staticPressurekPa, (double)Requires[i].value, results[i]); break; case Require.StaticPressureMax: TestReq((c, r) => c <= r, v.staticPressurekPa, (double)Requires[i].value, results[i]); break; case Require.AtmDensityMin: TestReq((c, r) => c >= r, v.atmDensity, (double)Requires[i].value, results[i]); break; case Require.AtmDensityMax: TestReq((c, r) => c <= r, v.atmDensity, (double)Requires[i].value, results[i]); break; case Require.AltAboveGroundMin: TestReq((c, r) => c >= r, v.heightFromTerrain, (double)Requires[i].value, results[i]); break; case Require.AltAboveGroundMax: TestReq((c, r) => c <= r, v.heightFromTerrain, (double)Requires[i].value, results[i]); break; case Require.MaxAsteroidDistance: TestReq((c, r) => c <= r, TestAsteroidDistance(v), (double)Requires[i].value, results[i]); break; case Require.AtmosphereAltMin: TestReq((c, r) => c >= r, v.mainBody.atmosphere ? v.altitude / v.mainBody.atmosphereDepth : double.NaN, (double)Requires[i].value, results[i]); break; case Require.AtmosphereAltMax: TestReq((c, r) => c <= r, v.mainBody.atmosphere ? v.altitude / v.mainBody.atmosphereDepth : double.NaN, (double)Requires[i].value, results[i]); break; case Require.CrewMin: TestReq((c, r) => c >= r, vd.CrewCount, (int)Requires[i].value, results[i]); break; case Require.CrewMax: TestReq((c, r) => c <= r, vd.CrewCount, (int)Requires[i].value, results[i]); break; case Require.CrewCapacityMin: TestReq((c, r) => c >= r, vd.CrewCapacity, (int)Requires[i].value, results[i]); break; case Require.CrewCapacityMax: TestReq((c, r) => c <= r, vd.CrewCapacity, (int)Requires[i].value, results[i]); break; case Require.AstronautComplexLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.AstronautComplex), (int)Requires[i].value, results[i]); break; case Require.AstronautComplexLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.AstronautComplex), (int)Requires[i].value, results[i]); break; case Require.TrackingStationLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.TrackingStation), (int)Requires[i].value, results[i]); break; case Require.TrackingStationLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.TrackingStation), (int)Requires[i].value, results[i]); break; case Require.MissionControlLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.MissionControl), (int)Requires[i].value, results[i]); break; case Require.MissionControlLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.MissionControl), (int)Requires[i].value, results[i]); break; case Require.AdministrationLevelMin: TestReq((c, r) => c >= r, GetFacilityLevel(SpaceCenterFacility.Administration), (int)Requires[i].value, results[i]); break; case Require.AdministrationLevelMax: TestReq((c, r) => c <= r, GetFacilityLevel(SpaceCenterFacility.Administration), (int)Requires[i].value, results[i]); break; case Require.Shadow: TestReq(() => vd.EnvInFullShadow, results[i]); break; case Require.Sunlight: TestReq(() => vd.EnvInSunlight, results[i]); break; case Require.Greenhouse: TestReq(() => vd.Greenhouses.Count > 0, results[i]); break; case Require.AbsoluteZero: TestReq(() => vd.EnvTemperature < 30.0, results[i]); break; case Require.InnerBelt: TestReq(() => vd.EnvInnerBelt, results[i]); break; case Require.OuterBelt: TestReq(() => vd.EnvOuterBelt, results[i]); break; case Require.MagneticBelt: TestReq(() => vd.EnvInnerBelt || vd.EnvOuterBelt, results[i]); break; case Require.Magnetosphere: TestReq(() => vd.EnvMagnetosphere, results[i]); break; case Require.InterStellar: TestReq(() => Lib.IsSun(v.mainBody) && vd.EnvInterstellar, results[i]); break; case Require.Part: TestReq(() => Lib.HasPart(v, (string)Requires[i].value), results[i]); break; case Require.Module: TestReq(() => Lib.FindModules(v.protoVessel, (string)Requires[i].value).Count > 0, results[i]); break; default: results[i].isValid = true; break; } if (!testAll && !results[i].isValid) { UnityEngine.Profiling.Profiler.EndSample(); return(false); } good &= results[i].isValid; } UnityEngine.Profiling.Profiler.EndSample(); return(good); }
private void TestReq(double val, RequireResult result) { result.result = val; result.value = val; }
private void TestReq <T, U>(Func <T, U, bool> Condition, T val, U reqVal, RequireResult result) { result.result = Condition(val, reqVal) ? 1.0 : 0.0; result.value = val; }
private void TestReq(Func <bool> Condition, RequireResult result) { result.result = Condition() ? 1.0 : 0.0; }