예제 #1
0
 public void addAnomaly(DMAnomalyObject anom)
 {
     if (!anomalies.Contains(anom.Name))
     {
         anomalies.Add(anom.Name, anom);
     }
 }
예제 #2
0
        public bool scanBody()
        {
            scanned = true;

            if (body.pqsController == null)
            {
                return(false);
            }

            PQSSurfaceObject[] Cities = body.pqsSurfaceObjects;

            for (int i = 0; i < Cities.Length; i++)
            {
                PQSSurfaceObject city = Cities[i];

                if (city == null)
                {
                    continue;
                }

                if (city.transform.parent.name != body.name)
                {
                    continue;
                }

                DMAnomalyObject anom = new DMAnomalyObject(city);

                addAnomaly(anom);
            }

            return(AnomalyCount > 0);
        }
예제 #3
0
        public bool scanBody()
        {
            scanned = true;

            if (body.pqsController == null)
            {
                return(false);
            }

            PQSCity[] Cities = body.pqsController.GetComponentsInChildren <PQSCity>();

            for (int i = 0; i < Cities.Length; i++)
            {
                PQSCity city = Cities[i];

                if (city == null)
                {
                    continue;
                }

                if (city.transform.parent.name != body.name)
                {
                    continue;
                }

                DMAnomalyObject anom = new DMAnomalyObject(city);

                addAnomaly(anom);
            }

            return(AnomalyCount > 0);
        }
        internal static DMCollectScience fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City)
        {
            ExperimentSituations targetSituation;
            ScienceSubject sub;
            string subject, anomName;

            if (Body == null)
                return null;

            if (City == null)
                return null;

            if (ResearchAndDevelopment.GetExperiment("AnomalyScan") == null)
                return null;

            if (rand.Next(0, 2) == 0)
                targetSituation = ExperimentSituations.SrfLanded;
            else
                targetSituation = ExperimentSituations.FlyingLow;

            anomName = DMagic.Part_Modules.DMAnomalyScanner.anomalyCleanup(City.Name);

            string subId = string.Format("AnomalyScan@{0}{1}{2}", Body.name, targetSituation, anomName);

            if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId))
            {
                sub = ResearchAndDevelopment.GetSubjectByID(subId);
                if (sub.scientificValue < 0.4f)
                    return null;
            }

            return new DMCollectScience(Body, targetSituation, anomName, "Anomaly Scan", 2);
        }
예제 #5
0
        private void pqsBuild(CelestialBody b)
        {
            PQSCity[] Cities = FindObjectsOfType(typeof(PQSCity)) as PQSCity[];
            foreach (PQSCity anomalyObject in Cities)
            {
                if (!anomalies.ContainsKey(anomalyObject.transform.parent.name))
                {
                    Dictionary <string, DMAnomalyObject> anomDict = new Dictionary <string, DMAnomalyObject>();
                    DMAnomalyObject obj = new DMAnomalyObject(anomalyObject);
                    anomDict.Add(anomalyObject.name, obj);
                    anomalies.Add(anomalyObject.transform.parent.name, anomDict);
                }
                else if (!anomalies[anomalyObject.transform.parent.name].ContainsKey(anomalyObject.name))
                {
                    DMAnomalyObject obj = new DMAnomalyObject(anomalyObject);
                    anomalies[anomalyObject.transform.parent.name].Add(anomalyObject.name, obj);
                }
            }

            currentBodyAnomalies.Clear();

            if (anomalies.ContainsKey(b.name))
            {
                currentBodyAnomalies = anomalies[b.name].Values.ToList();
            }
            else
            {
                currentBodyAnomalies = new List <DMAnomalyObject>();
            }
        }
예제 #6
0
        public static void updateAnomaly(Vessel v, DMAnomalyObject a)
        {
            if (v == null)
            {
                return;
            }

            if (a == null)
            {
                return;
            }

            Vector3d vPos = v.transform.position;

            a.WorldLocation = v.mainBody.GetWorldSurfacePosition(a.Lat, a.Lon, a.Alt);

            //Calculate vectors from CBody position to object positions
            Vector3d anomBody   = v.mainBody.position - a.WorldLocation;
            Vector3d vesselBody = v.mainBody.position - v.transform.position;

            //Project vessel vector onto anomaly vector
            Vector3d projectedV = Vector3d.Project(vesselBody, anomBody);

            //Calculate height above or below anomaly by drawing a line between the projected vector and the anomaly vector
            //Take the magnitude of that line, which equals the height
            a.VHeight     = (anomBody - projectedV).magnitude;
            a.VDistance   = (a.WorldLocation - vPos).magnitude;
            a.VHorizontal = Math.Sqrt((a.VDistance * a.VDistance) - (a.VHeight * a.VHeight));
        }
예제 #7
0
 internal static void bearing(Vessel v, DMAnomalyObject a)
 {
     double vlat = v.latitude;
     double vlon = v.longitude;
     double longdiff = (a.Lon - vlon) * Mathf.Deg2Rad;
     double y = Math.Sin(longdiff) * Math.Cos(Mathf.Deg2Rad * a.Lat);
     double x = Math.Cos(Mathf.Deg2Rad * vlat) * Math.Sin(Mathf.Deg2Rad * a.Lat) - Math.Sin(Mathf.Deg2Rad * vlat) * Math.Cos(Mathf.Deg2Rad * a.Lat) * Math.Cos(longdiff);
     double aBearing = (Math.Atan2(y, x) * Mathf.Rad2Deg + 360) % 360;
     a.Bearing = aBearing;
 }
예제 #8
0
 internal DMAnomalyParameter(CelestialBody Body, DMAnomalyObject City, ExperimentSituations Situation, string Name)
 {
     body      = Body;
     situation = Situation;
     name      = Name;
     city      = City;
     DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
     partName = scienceContainer.sciPart;
     subject  = string.Format("{0}@{1}{2}", scienceContainer.exp.id, body.name, situation);
     hash     = city.name;
 }
예제 #9
0
        internal static void bearing(Vessel v, DMAnomalyObject a)
        {
            double vlat     = v.latitude;
            double vlon     = v.longitude;
            double longdiff = (a.lon - vlon) * Mathf.Deg2Rad;
            double y        = Math.Sin(longdiff) * Math.Cos(Mathf.Deg2Rad * a.lat);
            double x        = Math.Cos(Mathf.Deg2Rad * vlat) * Math.Sin(Mathf.Deg2Rad * a.lat) - Math.Sin(Mathf.Deg2Rad * vlat) * Math.Cos(Mathf.Deg2Rad * a.lat) * Math.Cos(longdiff);
            double aBearing = (Math.Atan2(y, x) * Mathf.Rad2Deg + 360) % 360;

            a.bearing = aBearing;
        }
예제 #10
0
        internal static DMCollectScience fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string subject, anomName;

            if (Body == null)
            {
                return(null);
            }

            if (City == null)
            {
                return(null);
            }

            if (ResearchAndDevelopment.GetExperiment("AnomalyScan") == null)
            {
                return(null);
            }

            if (rand.Next(0, 2) == 0)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                targetSituation = ExperimentSituations.FlyingLow;
            }

            anomName = DMagic.Part_Modules.DMAnomalyScanner.anomalyCleanup(City.name);

            subject = string.Format("AnomalyScan@{0}{1}{2}", Body.name, targetSituation, anomName);

            //Make sure that our chosen science subject has science remaining to be gathered
            if ((sub = ResearchAndDevelopment.GetSubjectByID(subject)) != null)
            {
                if (sub.scientificValue < 0.4f)
                {
                    return(null);
                }
            }

            DMUtils.DebugLog("Primary Anomaly Parameter Assigned");
            return(new DMCollectScience(Body, targetSituation, anomName, "Anomaly Scan", 2));
        }
예제 #11
0
        internal static DMCollectScience fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City)
        {
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            string anomName;

            if (Body == null)
            {
                return(null);
            }

            if (City == null)
            {
                return(null);
            }

            if (ResearchAndDevelopment.GetExperiment("AnomalyScan") == null)
            {
                return(null);
            }

            if (rand.Next(0, 2) == 0)
            {
                targetSituation = ExperimentSituations.SrfLanded;
            }
            else
            {
                targetSituation = ExperimentSituations.FlyingLow;
            }

            anomName = DMagic.Part_Modules.DMAnomalyScanner.anomalyCleanup(City.Name);

            string subId = string.Format("AnomalyScan@{0}{1}{2}", Body.bodyName, targetSituation, anomName);

            if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId))
            {
                sub = ResearchAndDevelopment.GetSubjectByID(subId);
                if (sub.scientificValue < 0.4f)
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, targetSituation, anomName, "Anomaly Scan", 2));
        }
예제 #12
0
        internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City, DMScienceContainer DMScience)
        {
            AvailablePart               aPart;
            ExperimentSituations        targetSituation;
            List <ExperimentSituations> situations;
            string name;

            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            if (DMScience.exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.sciPart != "None")
            {
                DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart);
                aPart = PartLoader.getPartInfoByName(DMScience.sciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
                DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
            }

            if ((situations = DMUtils.availableSituationsLimited(DMScience.exp, DMScience.sitMask, Body)).Count == 0)
            {
                return(null);
            }
            else
            {
                DMUtils.DebugLog("Acceptable Situations Found");
                targetSituation = situations[rand.Next(0, situations.Count)];
                DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
            }

            return(new DMAnomalyParameter(Body, City, targetSituation, name));
        }
예제 #13
0
        public static void updateCoordinates(CelestialBody b)
        {
            if (anomalies.Contains(b.name))
            {
                for (int i = 0; i < anomalies[b.name].AnomalyCount; i++)
                {
                    DMAnomalyObject anom = anomalies[b.name].getAnomaly(i);

                    if (anom == null)
                    {
                        continue;
                    }

                    anom.WorldLocation = b.GetWorldSurfacePosition(anom.Lat, anom.Lon, anom.Alt);
                    anom.Lat           = b.GetLatitude(anom.WorldLocation);
                    anom.Lon           = b.GetLongitude(anom.WorldLocation);
                }
            }
        }
예제 #14
0
        internal static void updateAnomaly(Vessel v, DMAnomalyObject a)
        {
            Vector3d vPos = v.transform.position;

            a.worldLocation = a.city.transform.position;
            //Calculate vectors from CBody position to object positions
            Vector3d anomBody   = v.mainBody.position - a.worldLocation;
            Vector3d vesselBody = v.mainBody.position - v.transform.position;
            //Project vessel vector onto anomaly vector
            Vector3d projectedV = Vector3d.Project(vesselBody, anomBody);

            //Calculate height above or below anomaly by drawing a line between the projected vector and the anomaly vector
            //Take the magnitude of that line, which equals the height
            a.Vheight   = (projectedV - anomBody).magnitude;
            a.Vdistance = (a.worldLocation - vPos).magnitude;
            if (Math.Abs(a.Vheight) <= a.Vdistance)
            {
                a.Vhorizontal = Math.Sqrt((a.Vdistance * a.Vdistance) - (a.Vheight * a.Vheight));
            }
            else
            {
                a.Vhorizontal = double.MaxValue;                 //This should never happen...
            }
        }
예제 #15
0
        internal static void updateAnomaly(Vessel v, DMAnomalyObject a)
        {
            Vector3d vPos = v.transform.position;
            a.WorldLocation = a.City.transform.position;

            a.Lat = v.mainBody.GetLatitude(a.WorldLocation);
            a.Lon = v.mainBody.GetLongitude(a.WorldLocation);

            //Calculate vectors from CBody position to object positions
            Vector3d anomBody = v.mainBody.position - a.WorldLocation;
            Vector3d vesselBody = v.mainBody.position - v.transform.position;

            //Project vessel vector onto anomaly vector
            Vector3d projectedV = Vector3d.Project(vesselBody, anomBody);

            //Calculate height above or below anomaly by drawing a line between the projected vector and the anomaly vector
            //Take the magnitude of that line, which equals the height
            a.VHeight = (anomBody - projectedV).magnitude;
            a.VDistance = (a.WorldLocation - vPos).magnitude;
            a.VHorizontal = Math.Sqrt((a.VDistance * a.VDistance) - (a.VHeight * a.VHeight));
        }
예제 #16
0
        protected override void OnLoad(ConfigNode node)
        {
            //if (DMScienceScenario.SciScenario != null)
            //	if (DMScienceScenario.SciScenario.contractsReload)
            //		DMUtils.resetContracts();
            int targetBodyID;

            string[] anomalyString = node.GetValue("Target_Anomaly").Split('|');
            hash = anomalyString[0];
            if (int.TryParse(anomalyString[1], out targetBodyID))
            {
                body = FlightGlobals.Bodies[targetBodyID];
            }
            else
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Target Body");
                this.Unregister();
                ContractSystem.Instance.Contracts.Remove(this);
                return;
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                try
                {
                    targetAnomaly = new DMAnomalyObject((UnityEngine.Object.FindObjectsOfType(typeof(PQSCity)) as PQSCity[]).FirstOrDefault(c => c.name == hash && c.transform.parent.name == body.name));
                    lat           = targetAnomaly.lat;
                    lon           = targetAnomaly.lon;
                }
                catch
                {
                    DMUtils.Logging("Failed To Load Anomaly Contract Object");
                    this.Unregister();
                    ContractSystem.Instance.Contracts.Remove(this);
                    return;
                }
            }
            else
            {
                if (!double.TryParse(anomalyString[2], out lat))
                {
                    DMUtils.Logging("Failed To Load Anomaly Lat Values");
                    lat = 0.000d;
                }
                if (!double.TryParse(anomalyString[3], out lon))
                {
                    DMUtils.Logging("Failed To Load Anomaly Long Values");
                    lon = 0.000d;
                }
            }
            fudgedLat = fudgeLat(lat);
            fudgedLon = fudgeLon(lon);
            cardNS    = NSDirection(lat);
            cardEW    = EWDirection(lon);
            if (this.ParameterCount == 0)
            {
                DMUtils.Logging("No Parameters Loaded For This Anomaly Contract; Removing Now...");
                this.Unregister();
                ContractSystem.Instance.Contracts.Remove(this);
                return;
            }
        }
예제 #17
0
        private void pqsBuild(CelestialBody b)
        {
            PQSCity[] Cities = FindObjectsOfType(typeof(PQSCity)) as PQSCity[];
            foreach (PQSCity anomalyObject in Cities)
            {
                if (!anomalies.ContainsKey(anomalyObject.transform.parent.name))
                {
                    Dictionary<string, DMAnomalyObject> anomDict = new Dictionary<string, DMAnomalyObject>();
                    DMAnomalyObject obj = new DMAnomalyObject(anomalyObject);
                    anomDict.Add(anomalyObject.name, obj);
                    anomalies.Add(anomalyObject.transform.parent.name, anomDict);

                }
                else if (!anomalies[anomalyObject.transform.parent.name].ContainsKey(anomalyObject.name))
                {
                    DMAnomalyObject obj = new DMAnomalyObject(anomalyObject);
                    anomalies[anomalyObject.transform.parent.name].Add(anomalyObject.name, obj);
                }
            }

            currentBodyAnomalies.Clear();

            if (anomalies.ContainsKey(b.name))
                currentBodyAnomalies = anomalies[b.name].Values.ToList();
            else
                currentBodyAnomalies = new List<DMAnomalyObject>();
        }
예제 #18
0
        protected override bool Generate()
        {
            int total = ContractSystem.Instance.GetCurrentContracts <DMAnomalyContract>().Count();

            if (total >= DMUtils.maxAnomaly)
            {
                return(false);
            }

            //Make sure that the anomaly scanner is available
            AvailablePart aPart = PartLoader.getPartInfoByName("dmAnomScanner");

            if (aPart == null)
            {
                return(false);
            }
            if (!ResearchAndDevelopment.PartModelPurchased(aPart))
            {
                return(false);
            }

            //Kerbin or Mun Anomalies for trivial contracts
            if (this.Prestige == ContractPrestige.Trivial)
            {
                if (rand.Next(0, 3) == 0)
                {
                    body = FlightGlobals.Bodies[1];
                }
                else
                {
                    body = FlightGlobals.Bodies[2];
                }
            }
            //Minmus and Duna are next
            else if (this.Prestige == ContractPrestige.Significant)
            {
                if (!ProgressTracking.Instance.NodeComplete(new string[] { "Kerbin", "Escape" }))
                {
                    return(false);
                }
                if (rand.Next(0, 2) == 0)
                {
                    body = FlightGlobals.Bodies[3];
                }
                else
                {
                    body = FlightGlobals.Bodies[6];
                }
            }
            //Vall, Tylo, and Bop are last; only if we've been to Jool first
            else if (this.Prestige == ContractPrestige.Exceptional)
            {
                if (!ProgressTracking.Instance.NodeComplete(new string[] { "Jool", "Flyby" }))
                {
                    return(false);
                }
                int i = rand.Next(0, 3);
                if (i == 0)
                {
                    body = FlightGlobals.Bodies[10];
                }
                else if (i == 1)
                {
                    body = FlightGlobals.Bodies[11];
                }
                else if (i == 2)
                {
                    body = FlightGlobals.Bodies[12];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            PQSCity[] Cities = UnityEngine.Object.FindObjectsOfType(typeof(PQSCity)) as PQSCity[];
            foreach (PQSCity city in Cities)
            {
                if (city.transform.parent.name == body.name)
                {
                    cities.Add(city);
                }
            }

            //Select random anomaly
            targetAnomaly = new DMAnomalyObject(cities[rand.Next(0, cities.Count)]);
            hash          = targetAnomaly.name;
            lon           = targetAnomaly.lon;
            lat           = targetAnomaly.lat;
            fudgedLat     = fudgeLat(lat);
            fudgedLon     = fudgeLon(lon);
            cardNS        = NSDirection(lat);
            cardEW        = EWDirection(lon);
            DMUtils.DebugLog("Anomaly [{0}] Selected On {1} at Latitude: {2:N1} and Longitude: {3:N1}", targetAnomaly.name, body.theName, lat, lon);

            //Assign primary anomaly contract parameter
            if ((newParam = DMAnomalyGenerator.fetchAnomalyParameter(body, targetAnomaly)) == null)
            {
                return(false);
            }

            sciList.AddRange(DMUtils.availableScience[DMScienceType.Anomaly.ToString()].Values);

            for (i = 0; i < 3; i++)
            {
                if (sciList.Count > 0)
                {
                    DMScience     = sciList[rand.Next(0, sciList.Count)];
                    anomParams[i] = (DMAnomalyGenerator.fetchAnomalyParameter(body, targetAnomaly, DMScience));
                    sciList.Remove(DMScience);
                }
                else
                {
                    anomParams[i] = null;
                }
            }

            this.AddParameter(newParam);
            DMUtils.DebugLog("Added Primary Anomaly Parameter");
            float primaryLocationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(newParam.Situation), newParam.Body) * ((float)rand.Next(85, 116) / 100f);

            newParam.SetFunds(20000f * DMUtils.reward * primaryLocationMod, 10000f * DMUtils.penalty * primaryLocationMod, body);
            newParam.SetReputation(80f * DMUtils.reward * primaryLocationMod, 10f * DMUtils.penalty * primaryLocationMod, body);
            newParam.SetScience(35f * DMUtils.science * DMUtils.fixSubjectVal(newParam.Situation, 1f, body), null);

            foreach (DMAnomalyParameter aP in anomParams)
            {
                if (aP != null)
                {
                    this.AddParameter(aP, "collectDMAnomaly");
                    DMUtils.DebugLog("Added Secondary Anomaly Parameter");
                    float locationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(aP.Situation), aP.Body) * ((float)rand.Next(85, 116) / 100f);
                    aP.SetFunds(9000f * DMUtils.reward * locationMod, 6000f * DMUtils.penalty * locationMod, body);
                    aP.SetReputation(20f * DMUtils.reward * locationMod, 5f * DMUtils.penalty * locationMod, body);
                    aP.SetScience(aP.Container.exp.baseValue * 2f * DMUtils.science * DMUtils.fixSubjectVal(aP.Situation, 1f, body), null);
                }
            }

            if (this.ParameterCount == 0)
            {
                return(false);
            }

            this.agent = AgentList.Instance.GetAgent("DMagic");
            base.SetExpiry(10 * DMUtils.deadline, 20 * DMUtils.deadline);
            base.SetDeadlineYears(1.8f * ((float)rand.Next(80, 121)) / 100f * DMUtils.deadline, body);
            base.SetReputation(20f * DMUtils.reward * primaryLocationMod, 10f * DMUtils.penalty * primaryLocationMod, body);
            base.SetFunds(25000f * DMUtils.forward * primaryLocationMod, 22000f * DMUtils.reward * primaryLocationMod, 16000f * DMUtils.penalty * primaryLocationMod, body);
            return(true);
        }
예제 #19
0
        protected override void OnLoad(ConfigNode node)
        {
            //if (DMScienceScenario.SciScenario != null)
            //	if (DMScienceScenario.SciScenario.contractsReload)
            //		DMUtils.resetContracts();
            int bodyID, sitID;

            string[] anomalyString = node.GetValue("Target_Anomaly").Split('|');
            hash = anomalyString[0];
            if (int.TryParse(anomalyString[1], out bodyID))
            {
                body = FlightGlobals.Bodies[bodyID];
            }
            else
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Target Body Value; Parameter Removed");
                this.Unregister();
                this.Root.RemoveParameter(this);
                return;
            }
            name = anomalyString[2];
            DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
            if (scienceContainer == null)
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Science Container Variables; Parameter Removed");
                this.Unregister();
                this.Root.RemoveParameter(this);
                return;
            }
            else
            {
                partName = scienceContainer.sciPart;
            }
            if (int.TryParse(anomalyString[3], out sitID))
            {
                situation = (ExperimentSituations)sitID;
            }
            else
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Situation Value; Parameter Removed");
                this.Unregister();
                this.Root.RemoveParameter(this);
                return;
            }
            if (!bool.TryParse(anomalyString[4], out collected))
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Collected State; Reset Parameter");
                collected = false;
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                try
                {
                    city = new DMAnomalyObject((UnityEngine.Object.FindObjectsOfType(typeof(PQSCity)) as PQSCity[]).FirstOrDefault(c => c.name == hash && c.transform.parent.name == body.name));
                }
                catch
                {
                    DMUtils.Logging("Failed To Load Anomaly Contract Object; Parameter Removed");
                    this.Unregister();
                    this.Root.RemoveParameter(this);
                    return;
                }
            }
            subject = string.Format("{0}@{1}{2}", scienceContainer.exp.id, body.name, situation);
        }
예제 #20
0
 public static void bearing(Vessel v, DMAnomalyObject a)
 {
     a.Bearing = DMUtils.bearing(v.latitude, v.longitude, a.Lat, a.Lon);
 }