public static void LoadConfig() { if (loaded) { return; } Log("Loading config...", LogLevel.Important); BodyTravelTimes = new Dictionary <CelestialBody, double>(FlightGlobals.Bodies.Count); CelestialBody homePlanet = GetPlanet(Planetarium.fetch.Home); foreach (CelestialBody body in FlightGlobals.Bodies) { if (body.isHomeWorld) { BodyTravelTimes[body] = 0; } else if (body == Planetarium.fetch.Sun) { BodyTravelTimes[body] = homePlanet.orbit.period; } else if (body.HasParent(homePlanet)) { BodyTravelTimes[body] = body.orbit.period / 5; } else { BodyTravelTimes[body] = TimeBetweenLaunchWindows(homePlanet.orbit, GetPlanet(body).orbit) + HohmannMultiplier * HohmannTransferTime(homePlanet.orbit, GetPlanet(body).orbit); } Core.Log("Travel time for " + body.name + " is " + KSPUtil.PrintDateDeltaCompact(BodyTravelTimes[body], true, false), LogLevel.Important); } ConfigNode[] cfgArray = GameDatabase.Instance.GetConfigNodes("URGENT_CONTRACTS_CONFIG"); foreach (ConfigNode cfg in cfgArray) { foreach (ConfigNode n in cfg.GetNodes("CONTRACT_RULE")) { ContractRule rule = new ContractRule(n); ContractRules.Add(rule); Core.Log("Added contract from config file: " + rule, LogLevel.Important); } foreach (ConfigNode n in cfg.GetNodes("TRAVEL_TIME")) { CelestialBody body = FlightGlobals.GetBodyByName(GetString(n, "Name")); if (body == null) { continue; } BodyTravelTimes[body] = n.HasValue("TravelTime") ? GetDouble(n, "TravelTime") : (GetDouble(n, "TravelDays") * 21600); Core.Log("Overriding travel time for " + body.name + " to be " + KSPUtil.PrintDateDeltaCompact(BodyTravelTimes[body], true, false), LogLevel.Important); } } if (cfgArray.Length == 0) { Core.Log("Config file not found!", LogLevel.Error); } loaded = true; }
void LogContractInfo(Contract c) { if (!Core.IsLogging(Core.LogLevel.Debug)) { return; } Core.Log("Title: " + c.Title); Core.Log("Type: " + c.GetType().Name); Core.Log("State: " + c.ContractState); Core.Log("Target body: " + (ContractRule.GetTargetBody(c)?.name ?? "N/A")); Core.Log("Deadline: " + KSPUtil.PrintDateDeltaCompact(c.TimeDeadline, true, true)); }