Example #1
0
        protected override bool Generate()
        {
            TSTChemCamContract[] TSTChemCamContracts = ContractSystem.Instance.GetCurrentContracts <TSTChemCamContract>();
            offers = 0;
            active = 0;
            for (int i = 0; i < TSTChemCamContracts.Length; i++)
            {
                countActivecontracts = TSTChemCamContracts[i];
                if (countActivecontracts.ContractState == State.Offered)
                {
                    offers++;
                }
                else if (countActivecontracts.ContractState == State.Active)
                {
                    active++;
                }
            }
            Utilities.Log_Debug("ChemCam Contracts check offers={0}, active={1}", offers.ToString(), active.ToString());
            if (offers >= TSTMstStgs.Instance.TSTsettings.maxChemCamContracts)
            {
                return(false);
            }
            if (active >= TSTMstStgs.Instance.TSTsettings.maxChemCamContracts)
            {
                return(false);
            }

            Utilities.Log_Debug("Generating ChemCam Contract");
            agent        = AgentList.Instance.GetAgent("Tarsier Space Technology");
            expiryType   = DeadlineType.None;
            deadlineType = DeadlineType.None;
            Random r = new Random(MissionSeed);

            //If we only want Bodies that have already been PhotoGraphed by a Telescope
            if (TSTMstStgs.Instance.TSTsettings.photoOnlyChemCamContracts)
            {
                TSTTelescopeContract[] TSTTelescopeContractsCompleted = ContractSystem.Instance.GetCompletedContracts <TSTTelescopeContract>();
                List <CelestialBody>   availTelescopeBodies           = new List <CelestialBody>();
                for (int i = 0; i < TSTTelescopeContractsCompleted.Length; i++)
                {
                    if (TSTTelescopeContractsCompleted[i].target.type == typeof(CelestialBody))  //We only want Bodies, not Galaxies
                    {
                        CelestialBody contractBody = (CelestialBody)TSTTelescopeContractsCompleted[i].target.BaseObject;
                        availTelescopeBodies.Add(contractBody);
                    }
                }
                IEnumerable <CelestialBody> availableBodies = availTelescopeBodies.ToArray()
                                                                                                                      //.Where(b => !TSTMstStgs.Instance.TSTgasplanets.TarsierPlanetOrder.Contains(b.name) && b.Radius > 100 && b.pqsController != null);  //Exclude the GasPlanets
                                                              .Where(b => b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets & Sigma Binaries
                if (!availableBodies.Any())
                {
                    Utilities.Log_Debug("There are no Bodies that have been photographed, cannot generate ChemCam Contract at this time");
                    return(false);
                }
                target = availableBodies.ElementAt(r.Next(availableBodies.Count() - 1));
            }
            else  //We can use any Bodies
            {
                IEnumerable <CelestialBody> availableBodies = FlightGlobals.Bodies
                                                              //.Where(b => !TSTMstStgs.Instance.TSTgasplanets.TarsierPlanetOrder.Contains(b.name) && b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets
                                                              .Where(b => b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets & Sigma Binaries
                if (!availableBodies.Any())
                {
                    Utilities.Log_Debug("There are no Bodies that have been photographed, cannot generate ChemCam Contract at this time");
                    return(false);
                }
                target = availableBodies.ElementAt(r.Next(availableBodies.Count() - 1));
            }

            // if ResearchBodies is installed we need to check if the target body has been found. If it has not, then we set the target to default so a contract is not generated at this time.
            if (TSTMstStgs.Instance.isRBactive && RBWrapper.RBactualAPI.enabled)
            {
                try
                {
                    if (RBWrapper.APIRBReady)
                    {
                        List <KeyValuePair <CelestialBody, RBWrapper.CelestialBodyInfo> > trackbodyentry = TSTMstStgs.Instance.RBCelestialBodies.Where(e => e.Key.name == target.name).ToList();
                        if (trackbodyentry.Count != 1)
                        {
                            Utilities.Log("ChemCam Contract cannot find target in ResearchBodies TrackedBodies {0}", target.name);
                            return(false);
                        }
                        if (trackbodyentry[0].Value.isResearched == false)
                        {
                            Utilities.Log("ChemCam Contract target in ResearchBodies TrackedBodies is still not tracked {0}", target.name);
                            return(false);
                        }
                    }
                    else
                    {
                        Utilities.Log("ResearchBodies is not Ready, cannot test ChemCam target for contract generation at this time");
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Utilities.Log("Checking ResearchBodies status for target {0} Failed unexpectedly. Ex: {1}", target.name, ex.Message);
                }
            }

            Utilities.Log_Debug("Target: {0}", target.name);
            Utilities.Log_Debug("Creating Science Param");
            TSTScienceParam param2 = new TSTScienceParam();

            param2.matchFields.Add("TarsierSpaceTech.ChemCam");
            param2.matchFields.Add(target.name);
            biome = "";
            List <string> biomes = ResearchAndDevelopment.GetBiomeTags(target, true);

            if (biomes.Count > 1)
            {
                do
                {
                    biome = biomes[r.Next(biomes.Count - 1)];
                } while (biome.Contains("Water"));
                param2.matchFields.Add(biome);
            }
            AddParameter(param2);
            ContractPrestige p = TSTProgressTracker.getChemCamPrestige(target); //Get the target prestige level

            if (p != prestige)                                                  //If the prestige is not the required level don't generate.
            {
                return(false);
            }
            string targetname = target.name;

            if (biome != "")
            {
                targetname += "," + biome;
            }
            if (TSTProgressTracker.HasChemCamCompleted(targetname))
            {
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsdiscoveredChem * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsdiscoveredChem, target);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repDiscoveredChem, target);
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceDiscoveredChem, target);
            }
            else
            {
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredChem * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredChem, target);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repUndiscoveredChem, target);
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceUndiscoveredChem, target);
            }
            if (new Random(MissionSeed).Next(10) > 3)
            {
                Utilities.Log_Debug("Random Seed False, not generating contract");
                return(false);
            }
            Utilities.Log_Debug("Random Seed True, generating contract");
            return(true);
        }
Example #2
0
        protected override bool Generate()
        {
            TSTTelescopeContract[] TSTTelescopeContracts = ContractSystem.Instance.GetCurrentContracts <TSTTelescopeContract>();
            int offers = 0;
            int active = 0;

            for (int i = 0; i < TSTTelescopeContracts.Length; i++)
            {
                TSTTelescopeContract m = TSTTelescopeContracts[i];
                if (m.ContractState == State.Offered)
                {
                    offers++;
                }
                else if (m.ContractState == State.Active)
                {
                    active++;
                }
            }
            Utilities.Log_Debug("Telescope Contracts check offers= {0} active= {1}", offers.ToString(), active.ToString());
            if (offers >= 1)
            {
                return(false);
            }
            if (active >= 1)
            {
                return(false);
            }
            Utilities.Log_Debug("Generating Telescope Contract");

            agent = AgentList.Instance.GetAgent("Tarsier Space Technology");
            SetExpiry();
            expiryType   = DeadlineType.None;
            deadlineType = DeadlineType.None;

            Utilities.Log_Debug("Creating Parameter");
            TSTTelescopeContractParam param = new TSTTelescopeContractParam();

            AddParameter(param);
            string target_name = TSTProgressTracker.GetNextTelescopeTarget();

            if (target_name == default(string))
            {
                Utilities.Log_Debug("target body is default (not set), cannot generate");
                return(false);
            }
            Utilities.Log_Debug("Target: {0}", target_name);
            AvailablePart ap2 = PartLoader.getPartInfoByName("tarsierAdvSpaceTelescope");

            if (!ResearchAndDevelopment.PartTechAvailable(ap2) && !ResearchAndDevelopment.PartModelPurchased(ap2) && target_name == "Galaxy1")
            {
                Utilities.Log_Debug("Contracts for Planets completed and Galaxy contracts require advanced space telescope");
                return(false);
            }
            Utilities.Log_Debug("Checking Celestial Bodies");
            target = FlightGlobals.Bodies.Find(b => b.name == target_name);
            if (target == null)
            {
                Utilities.Log_Debug("Checking Galaxies");
                target = TSTGalaxies.Galaxies.Find(g => g.name == target_name);
            }
            Utilities.Log_Debug("Using target: {0}", target.ToString());
            param.target = target;
            Utilities.Log_Debug("Creating Science Param");
            TSTScienceParam param2 = new TSTScienceParam();

            param2.matchFields.Add("TarsierSpaceTech.SpaceTelescope");
            param2.matchFields.Add("LookingAt" + target.name);
            AddParameter(param2);
            Utilities.Log_Debug("Created Science Param");
            prestige = TSTProgressTracker.getTelescopePrestige(target);
            if (TSTProgressTracker.HasTelescopeCompleted(target))
            {
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceDiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsdiscoveredScope * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsdiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repDiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
            }
            else
            {
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceUndiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredScope * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repUndiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
            }
            return(true);
        }
        protected override bool Generate()
        {
            TSTTelescopeContract[] TSTTelescopeContracts = ContractSystem.Instance.GetCurrentContracts<TSTTelescopeContract>();
            int offers = 0;
            int active = 0;

            for (int i = 0; i < TSTTelescopeContracts.Length; i++)
            {
                TSTTelescopeContract m = TSTTelescopeContracts[i];
                if (m.ContractState == State.Offered)
                    offers++;
                else if (m.ContractState == State.Active)
                    active++;
            }
            Utilities.Log_Debug("Telescope Contracts check offers= {0} active= {1}" , offers.ToString(), active.ToString());
            if (offers >= 1)
                return false;
            if (active >= 1)
                return false;
            Utilities.Log_Debug("Generating Telescope Contract");

            agent = AgentList.Instance.GetAgent("Tarsier Space Technology");
            SetExpiry();
            expiryType = DeadlineType.None;
            deadlineType = DeadlineType.None;

            Utilities.Log_Debug("Creating Parameter");
            TSTTelescopeContractParam param = new TSTTelescopeContractParam();
            AddParameter(param);
            string target_name = TSTProgressTracker.GetNextTelescopeTarget();
            if (target_name == default(string))
            {
                Utilities.Log_Debug("target body is default (not set), cannot generate");
                return false;
            }
            Utilities.Log_Debug("Target: {0}" , target_name);
            AvailablePart ap2 = PartLoader.getPartInfoByName("tarsierAdvSpaceTelescope");
            if (!ResearchAndDevelopment.PartTechAvailable(ap2) && !ResearchAndDevelopment.PartModelPurchased(ap2) && target_name == "Galaxy1")
            {
                Utilities.Log_Debug("Contracts for Planets completed and Galaxy contracts require advanced space telescope");
                return false;
            }
            Utilities.Log_Debug("Checking Celestial Bodies");
            target = FlightGlobals.Bodies.Find(b => b.name == target_name);
            if (target == null)
            {
                Utilities.Log_Debug("Checking Galaxies");
                target = TSTGalaxies.Galaxies.Find(g => g.name == target_name);
            }
            Utilities.Log_Debug("Using target: {0}" , target.ToString());
            param.target = target;
            Utilities.Log_Debug("Creating Science Param");
            TSTScienceParam param2 = new TSTScienceParam();
            param2.matchFields.Add("TarsierSpaceTech.SpaceTelescope");
            param2.matchFields.Add("LookingAt" + target.name);
            AddParameter(param2);
            Utilities.Log_Debug("Created Science Param");
            prestige = TSTProgressTracker.getTelescopePrestige(target);
            if (TSTProgressTracker.HasTelescopeCompleted(target))
            {
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceDiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsdiscoveredScope * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsdiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repDiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
            }
            else
            {
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceUndiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredScope * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repUndiscoveredScope, target.type == typeof(TSTGalaxy) ? null : (CelestialBody)target.BaseObject);
            }
            return true;
        }
        protected override bool Generate()
        {
            TSTChemCamContract[] TSTChemCamContracts = ContractSystem.Instance.GetCurrentContracts<TSTChemCamContract>();
            offers = 0;
            active = 0;
            for (int i = 0; i < TSTChemCamContracts.Length; i++)
            {
                countActivecontracts = TSTChemCamContracts[i];
                if (countActivecontracts.ContractState == State.Offered)
                    offers++;
                else if (countActivecontracts.ContractState == State.Active)
                    active++;
            }
            Utilities.Log_Debug("ChemCam Contracts check offers={0}, active={1}" , offers.ToString(), active.ToString());
            if (offers >= TSTMstStgs.Instance.TSTsettings.maxChemCamContracts)
                return false;
            if (active >= TSTMstStgs.Instance.TSTsettings.maxChemCamContracts)
                return false;

            Utilities.Log_Debug("Generating ChemCam Contract");
            agent = AgentList.Instance.GetAgent("Tarsier Space Technology");
            expiryType = DeadlineType.None;
            deadlineType = DeadlineType.None;
            Random r = new Random(MissionSeed);

            //If we only want Bodies that have already been PhotoGraphed by a Telescope
            if (TSTMstStgs.Instance.TSTsettings.photoOnlyChemCamContracts)
            {
                TSTTelescopeContract[] TSTTelescopeContractsCompleted = ContractSystem.Instance.GetCompletedContracts<TSTTelescopeContract>();
                List<CelestialBody> availTelescopeBodies = new List<CelestialBody>();
                for (int i = 0; i < TSTTelescopeContractsCompleted.Length; i++)
                {
                    if (TSTTelescopeContractsCompleted[i].target.type == typeof(CelestialBody))  //We only want Bodies, not Galaxies
                    {
                        CelestialBody contractBody = (CelestialBody)TSTTelescopeContractsCompleted[i].target.BaseObject;
                        availTelescopeBodies.Add(contractBody);
                    }
                }
                IEnumerable<CelestialBody> availableBodies = availTelescopeBodies.ToArray()
                    //.Where(b => !TSTMstStgs.Instance.TSTgasplanets.TarsierPlanetOrder.Contains(b.name) && b.Radius > 100 && b.pqsController != null);  //Exclude the GasPlanets
                    .Where(b => b.Radius > 100 && b.pqsController != null);  //Exclude the GasPlanets & Sigma Binaries
                if (!availableBodies.Any())
                {
                    Utilities.Log_Debug("There are no Bodies that have been photographed, cannot generate ChemCam Contract at this time");
                    return false;
                }
                target = availableBodies.ElementAt(r.Next(availableBodies.Count() - 1));
            }
            else  //We can use any Bodies
            {
                IEnumerable<CelestialBody> availableBodies = FlightGlobals.Bodies
                    //.Where(b => !TSTMstStgs.Instance.TSTgasplanets.TarsierPlanetOrder.Contains(b.name) && b.Radius > 100 && b.pqsController != null); //Exclude the GasPlanets
                    .Where(b => b.Radius > 100 && b.pqsController != null);  //Exclude the GasPlanets & Sigma Binaries
                if (!availableBodies.Any())
                {
                    Utilities.Log_Debug("There are no Bodies that have been photographed, cannot generate ChemCam Contract at this time");
                    return false;
                }
                target = availableBodies.ElementAt(r.Next(availableBodies.Count() - 1));
            }

            // if ResearchBodies is installed we need to check if the target body has been found. If it has not, then we set the target to default so a contract is not generated at this time.
            if (TSTMstStgs.Instance.isRBactive && RBWrapper.RBactualAPI.enabled)
            {
                try
                {
                    if (RBWrapper.APIRBReady)
                    {
                        List<KeyValuePair<CelestialBody, RBWrapper.CelestialBodyInfo>> trackbodyentry = TSTMstStgs.Instance.RBCelestialBodies.Where(e => e.Key.name == target.name).ToList();
                        if (trackbodyentry.Count != 1)
                        {
                            Utilities.Log("ChemCam Contract cannot find target in ResearchBodies TrackedBodies {0}" , target.name);
                            return false;
                        }
                        if (trackbodyentry[0].Value.isResearched == false)
                        {
                            Utilities.Log("ChemCam Contract target in ResearchBodies TrackedBodies is still not tracked {0}" , target.name);
                            return false;
                        }
                    }
                    else
                    {
                        Utilities.Log("ResearchBodies is not Ready, cannot test ChemCam target for contract generation at this time");
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    Utilities.Log("Checking ResearchBodies status for target {0} Failed unexpectedly. Ex: {1}" , target.name , ex.Message);
                }
            }

            Utilities.Log_Debug("Target: {0}" , target.name);
            Utilities.Log_Debug("Creating Science Param");
            TSTScienceParam param2 = new TSTScienceParam();
            param2.matchFields.Add("TarsierSpaceTech.ChemCam");
            param2.matchFields.Add(target.name);
            biome = "";
            List<string> biomes = ResearchAndDevelopment.GetBiomeTags(target);
            if (biomes.Count > 1)
            {
                do
                {
                    biome = biomes[r.Next(biomes.Count - 1)];
                } while (biome.Contains("Water"));
                param2.matchFields.Add(biome);
            }
            AddParameter(param2);
            ContractPrestige p = TSTProgressTracker.getChemCamPrestige(target); //Get the target prestige level
            if (p != prestige)  //If the prestige is not the required level don't generate.
                return false;
            string targetname = target.name;
            if (biome != "")
                    targetname += "," + biome;
            if (TSTProgressTracker.HasChemCamCompleted(targetname))
            {
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsdiscoveredChem * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsdiscoveredChem, target);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repDiscoveredChem, target);
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceDiscoveredChem, target);
            }
            else
            {
                SetFunds(TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredChem * 0.75f, TSTMstStgs.Instance.TSTsettings.fundsUndiscoveredChem, target);
                SetReputation(TSTMstStgs.Instance.TSTsettings.repUndiscoveredChem, target);
                SetScience(TSTMstStgs.Instance.TSTsettings.scienceUndiscoveredChem, target);
            }
            if (new Random(MissionSeed).Next(10) > 3)
            {
                Utilities.Log_Debug("Random Seed False, not generating contract");
                return false;
            }
            Utilities.Log_Debug("Random Seed True, generating contract");
            return true;
        }