protected override void OnLoad(ConfigNode node) { int bodyID = int.Parse(node.GetValue("targetBody")); foreach (var body in FlightGlobals.Bodies) { if (body.flightGlobalsIndex == bodyID) { targetBody = body; } } ConfigNode touristNode = node.GetNode("TOURISTS"); KourageousTouristsAddOn.printDebug("tourist node: " + touristNode); if (touristNode == null) { KourageousTouristsAddOn.printDebug("Can't load tourists from save file"); return; } foreach (ConfigNode crewNode in touristNode.GetNodes()) { KourageousTouristsAddOn.printDebug("tourist: " + crewNode); this.tourists.Add( new ProtoCrewMember( HighLogic.CurrentGame.Mode, crewNode, ProtoCrewMember.KerbalType.Tourist)); } this.numTourists = tourists.Count; KourageousTouristsAddOn.printDebug("numtourists: " + this.numTourists + "; " + tourists.Count); }
protected KourageousAnomaly chooseAnomaly(CelestialBody body) { KourageousTouristsAddOn.printDebug("entered"); readAnomalyConfig(); KourageousTouristsAddOn.printDebug(String.Format("anomalies: {0}, distance: {1}", anomalies.Count, anomalyDiscoveryDistance)); List <KourageousAnomaly> chosen = new List <KourageousAnomaly> (); foreach (KeyValuePair <string, KourageousAnomaly> entry in anomalies) { if (entry.Value.body.name.Equals(body.name)) { chosen.Add(entry.Value); } } KourageousTouristsAddOn.printDebug(String.Format("chosen: {0}, cnt: {1}", chosen, chosen.Count)); if (chosen.Count == 0) { return(null); } Random rnd = new Random(); return(chosen [rnd.Next(chosen.Count)]); }
public Tourist createForLevel(int level, ProtoCrewMember crew) { Tourist t = new Tourist(); if (!initialized) { KourageousTouristsAddOn.printDebug("TouristFactory not initialized, can't make tourists!"); return(t); } ProtoTourist pt; if (!touristConfig.TryGetValue(level, out pt)) { KourageousTouristsAddOn.printDebug("Can't find config for level " + level); return(t); } t.level = pt.level; t.abilities = pt.abilities; t.situations = pt.situations; t.celestialBodies = pt.celestialBodies; t.srfspeed = pt.srfspeed; t.crew = crew; t.rnd = new System.Random(); return(t); }
protected override void OnAccepted() { KourageousTouristsAddOn.printDebug("entered: body=" + targetBody.bodyName); foreach (ProtoCrewMember tourist in tourists) { HighLogic.CurrentGame.CrewRoster.AddCrewMember(tourist); KourageousTouristsAddOn.printDebug("adding to roster: " + tourist.name); } }
protected List <CelestialBody> getCelestialBodyList() { List <CelestialBody> allBodies = GetBodies_Reached(false, false).Where( b => b.hasSolidSurface).ToList(); KourageousTouristsAddOn.printDebug("celestials: " + String.Join(",", allBodies)); return(allBodies); }
protected override void OnLoad(ConfigNode node) { base.OnLoad(node); this.anomalyName = String.Copy(node.GetValue("anomalyName")); KourageousAnomalyContract.readAnomalyConfig(); this.anomalyDisplayName = KourageousAnomalyContract.anomalies [targetBody.name + ":" + anomalyName].anomalyDescription; KourageousTouristsAddOn.printDebug("display name: " + anomalyDisplayName); setDistance(); }
private void OnEva(GameEvents.FromToAction <Part, Part> action) { Vessel v = action.to.vessel; KourageousTouristsAddOn.printDebug( String.Format("triggered; vessel: {0}, {1}; param tourist: {2}; body: {3}; vessel situation: {4}; vessel body: {5}", action.to.vessel, action.from.vessel, this.tourist, this.targetBody.bodyName, v.situation, v.mainBody.bodyName)); checkCompletion(v); }
private void checkCompletion(Vessel v) { foreach (ProtoCrewMember c in v.GetVesselCrew()) { KourageousTouristsAddOn.printDebug( String.Format("param vessel crew: {0}", c.name)); } if (v.isEVA && v.mainBody == targetBody && v.GetVesselCrew() [0].name.Equals(tourist) && v.situation == Vessel.Situations.LANDED) { base.SetComplete(); } }
protected override void OnCompleted() { KourageousTouristsAddOn.printDebug($"OnCompleted"); foreach (var tourist in tourists) { KourageousTouristsAddOn.printDebug($"Setting hasToured for {tourist.name}"); KerbalRoster roster = HighLogic.CurrentGame.CrewRoster; if (roster.Exists(tourist.name)) { ProtoCrewMember t = roster[tourist.name]; t.type = ProtoCrewMember.KerbalType.Tourist; t.hasToured = true; } } base.OnCompleted(); }
private bool isNearbyAnomaly(Vessel v, string anomalyName) { // FIXME: Can we have objects with same names, but on different bodies? // FIXME: So far I think we can. GameObject[] obj = UnityEngine.Object.FindObjectsOfType <GameObject>(); foreach (GameObject anomalyObj in obj) { Component[] c = anomalyObj.GetComponents <PQSCity> (); if (c == null || c.Length == 0) { continue; } KourageousTouristsAddOn.printDebug("has pqscity: " + anomalyObj.name); PQSCity pqscity = (PQSCity)c [0]; if (pqscity == null) { continue; } if (!pqscity.sphere.isAlive) { continue; } Transform tr = anomalyObj.GetComponent <Transform> (); if (!anomalyObj.name.Equals(anomalyName)) { continue; } if (tr == null) { return(false); } float dist1 = Vector3.Distance(v.transform.position, tr.position); KourageousTouristsAddOn.printDebug("distance: " + dist1.ToString() + "; min dist: " + minAnomalyDistance.ToString()); if (dist1 < this.minAnomalyDistance) { return(true); } } return(false); }
private void onSelfieTaken() { KourageousTouristsAddOn.printDebug("here"); foreach (Vessel v in FlightGlobals.VesselsLoaded) { if ( v.mainBody == targetBody && v.GetVesselCrew() [0].name.Equals(tourist) && v.GetVesselCrew().Count == 1 && v.situation == Vessel.Situations.LANDED && v.isEVA) { KourageousTouristsAddOn.printDebug("checking for " + tourist + " at " + anomalyName); if (this.isNearbyAnomaly(v, anomalyName)) { base.SetComplete(); } break; } } }
protected void setDistance() { ConfigNode config = GameDatabase.Instance.GetConfigNodes( KourageousTouristsAddOn.cfgRoot).FirstOrDefault(); this.minAnomalyDistance = defaultMinAnomalyDistance; if (config != null) { String dscvr = config.GetValue(discoveryDistance); if (dscvr != null) { try { this.minAnomalyDistance = (float)Convert.ToDouble(dscvr); } catch (Exception) { } } } else { KourageousTouristsAddOn.printDebug("no config found in game database"); } }
protected override bool Generate() //System.Type contractType, Contract.ContractPrestige difficulty, int seed, State state) { KourageousTouristsAddOn.printDebug("entered"); targetBody = selectNextCelestialBody(); if (targetBody == null) { return(false); } this.numTourists = UnityEngine.Random.Range(1, 5); KourageousTouristsAddOn.printDebug("num tourists: " + numTourists); for (int i = 0; i < this.numTourists; i++) { ProtoCrewMember tourist = CrewGenerator.RandomCrewMemberPrototype(ProtoCrewMember.KerbalType.Tourist); tourists.Add(tourist); KourageousTouristsAddOn.printDebug("generated: " + tourist.name); // TODO: Add support for gender for 1.3 build KerbalTourParameter itinerary = new KerbalTourParameter(tourist.name, tourist.gender); // TODO: Add difficulty multiplier itinerary.FundsCompletion = 25000.0; itinerary.ReputationCompletion = 0.0f; itinerary.ReputationFailure = 0.0f; itinerary.ScienceCompletion = 0.0f; this.AddParameter(itinerary); KerbalDestinationParameter dstParameter = new KerbalDestinationParameter( targetBody, FlightLog.EntryType.Land, tourist.name ); dstParameter.FundsCompletion = 1000.0f; dstParameter.FundsFailure = 0.0f; dstParameter.ReputationCompletion = 0.0f; dstParameter.ReputationFailure = 0.0f; dstParameter.ScienceCompletion = 0.0f; /*dstParameter.NestToParent (itinerary); * dstParameter.CreateID (); * dstParameter.AddParameter (new Contracts.Parameters.LandOnBody (targetBody));*/ itinerary.AddParameter(dstParameter); KourageousWalkParameter walkParameter = new KourageousWalkParameter(targetBody, tourist.name); walkParameter.FundsCompletion = 3000.0; walkParameter.FundsFailure = 0.0; walkParameter.ReputationCompletion = 0.0f; walkParameter.ReputationFailure = 0.0f; walkParameter.ScienceCompletion = 0.0f; itinerary.AddParameter(walkParameter); } GenerateHashString(); base.SetExpiry(); base.SetScience(0.0f, targetBody); base.SetDeadlineYears(1, targetBody); base.SetReputation(2, 5, targetBody); base.SetFunds(2000, 7000, 18000, targetBody); return(true); }
protected override string GetTitle() { KourageousTouristsAddOn.printDebug("entered: anomaly=" + chosenAnomaly); return(String.Format("Visit {0} with {1}", chosenAnomaly.anomalyDescription, getProperTouristWordLc())); }
protected override void OnRegister() { KourageousTouristsAddOn.printDebug("setting event OnEva"); GameEvents.onCrewOnEva.Add(OnEva); GameEvents.onVesselSituationChange.Add(OnSituationChange); }
private bool readConfig() { KourageousTouristsAddOn.printDebug("reading config"); ConfigNode config = GameDatabase.Instance.GetConfigNodes(KourageousTouristsAddOn.cfgRoot).FirstOrDefault(); if (config == null) { KourageousTouristsAddOn.printDebug("no config found in game database"); return(false); } // TODO: Remove this coupling String dbg = config.GetValue(KourageousTouristsAddOn.debugLog); if (dbg != null) { KourageousTouristsAddOn.debug = dbg.ToLower().Equals("true"); } ConfigNode[] nodes = config.GetNodes(KourageousTouristsAddOn.cfgLevel); foreach (ConfigNode cfg in nodes) { String tLvl = cfg.GetValue("touristlevel"); if (tLvl == null) { KourageousTouristsAddOn.printDebug("tourist config entry has no attribute 'level'"); return(false); } KourageousTouristsAddOn.printDebug("lvl=" + tLvl); ProtoTourist t = new ProtoTourist(); int lvl; if (!Int32.TryParse(tLvl, out lvl)) { KourageousTouristsAddOn.printDebug("Can't parse tourist level as int: " + tLvl); return(false); } t.level = lvl; if (cfg.HasValue("situations")) { t.situations.AddRange( cfg.GetValue("situations").Replace(" ", "").Split(',')); } t.situations.RemoveAll(str => String.IsNullOrEmpty(str)); if (cfg.HasValue("bodies")) { t.celestialBodies.AddRange( cfg.GetValue("bodies").Replace(" ", "").Split(',')); } t.celestialBodies.RemoveAll(str => String.IsNullOrEmpty(str)); if (cfg.HasValue("abilities")) { t.abilities.AddRange( cfg.GetValue("abilities").Replace(" ", "").Split(',')); } t.abilities.RemoveAll(str => String.IsNullOrEmpty(str)); if (cfg.HasValue("srfspeed")) { String srfSpeed = cfg.GetValue("srfspeed"); KourageousTouristsAddOn.printDebug("srfspeed = " + srfSpeed); double spd = 0.0; if (Double.TryParse(srfSpeed, out spd)) { t.srfspeed = spd; } else { t.srfspeed = Double.NaN; } } KourageousTouristsAddOn.printDebug("Adding cfg: " + t.ToString()); this.touristConfig.Add(lvl, t); } return(true); }
internal static void readAnomalyConfig() { if (anomalies != null) { return; } anomalies = new Dictionary <String, KourageousAnomaly> (); ConfigNode config = GameDatabase.Instance.GetConfigNodes( KourageousTouristsAddOn.cfgRoot).FirstOrDefault(); if (config == null) { return; } String distanceNode = config.GetValue(anomalyDistance); if (distanceNode != null) { try { anomalyDiscoveryDistance = (float)Convert.ToDouble(distanceNode); } catch (Exception) { } } ConfigNode[] nodes = config.GetNodes(anomalyCfgNode); foreach (ConfigNode node in nodes) { KourageousAnomaly anomaly = new KourageousAnomaly(); KourageousTouristsAddOn.printDebug(String.Format("cfg node: {0}", node)); String name = node.GetValue("name"); if (name == null) { continue; } anomaly.name = name; KourageousTouristsAddOn.printDebug(String.Format("anomaly name: {0}", name)); String anomalyDescription = node.GetValue("anomalyDescription"); if (anomalyDescription == null) { continue; } anomaly.anomalyDescription = anomalyDescription; String contractDescription = node.GetValue("contractDescription"); if (contractDescription == null) { continue; } anomaly.contractDescription = contractDescription; String contractSynopsis = node.GetValue("contractSynopsis"); if (contractSynopsis == null) { continue; } anomaly.contractSynopsis = contractSynopsis; String bodyStr = node.GetValue("body"); KourageousTouristsAddOn.printDebug(String.Format("anomaly body: {0}", bodyStr)); foreach (CelestialBody b in FlightGlobals.Bodies) { KourageousTouristsAddOn.printDebug(String.Format("list body name: {0}", b.name)); if (b.name.Equals(bodyStr)) { anomaly.body = b; break; } } KourageousTouristsAddOn.printDebug(String.Format("anomaly body obj: {0}", anomaly.body == null)); if (anomaly.body == null) { continue; } String payoutModifierStr = node.GetValue("payoutModifier"); KourageousTouristsAddOn.printDebug(String.Format("payout modifier str: {0}", payoutModifierStr)); if (payoutModifierStr == null) { continue; } float payoutModifier = 1.0f; try { payoutModifier = (float)Convert.ToDouble(payoutModifierStr); KourageousTouristsAddOn.printDebug(String.Format("payout modifier: {0}", payoutModifier)); } catch (Exception) { } anomaly.payoutModifier = payoutModifier; anomalies.Add(bodyStr + ":" + name, anomaly); KourageousTouristsAddOn.printDebug(String.Format("added: {0}", bodyStr + ":" + name)); } }