Example #1
0
        /// <summary>
        /// Informs the render plan that this component wants the specified resource as input.
        /// </summary>
        /// <param name="name">The name of the resource.</param>
        public void DefineInput(string name)
        {
            if (!AvailableResources.Any(info => info.Name == name))
            {
                throw new ArgumentException(string.Format("The resource {0} is not available.", name));
            }

            inputs.Add(name);
        }
Example #2
0
        public void UpdateAvailableResource(string resourceName, double changeAmount)
        {
            if (changeAmount == 0)
            {
                return;
            }

            AvailableResources.TryGetValue(resourceName, out double availableAmount);
            AvailableResources[resourceName] = availableAmount + changeAmount;
        }
Example #3
0
        public override void LoadAvailableResources()
        {
            AvailableResources.Clear();
            if (SelectedAvailableResourceGroup == null)
            {
                return;
            }

            string path = "./Data/" + SelectedAvailableResourceGroup.FolderName + "/";

            string[] files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                string json     = File.ReadAllText(file);
                var    dbObject = JsonConvert.DeserializeObject(json, SelectedAvailableResourceGroup.Type);
                AvailableResources.Add(dbObject);
            }
        }
        // Something wrong with upgrade
        private static List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> > PrepareUpgradeCommands(IEnumerable <PartyCharacterVM> upgradableTroops, PartyScreenLogic partyScreenLogic, ref UpgradeResults upgradeResults)
        {
            List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> > commands = new List <Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand> >();

            AvailableResources availableResources = new AvailableResources();

            foreach (PartyCharacterVM troops in upgradableTroops)
            {
                List <(int, PartyScreenLogic.PartyCommand.UpgradeTargetType)> upgradesPerTypes =
                    new List <(int maxUpgradableTroops, PartyScreenLogic.PartyCommand.UpgradeTargetType upgradeTargetType)> {
                    (int.MaxValue, PartyScreenLogic.PartyCommand.UpgradeTargetType.UpgradeTarget1)
                };

                if (HasTwoUpgradePaths(troops) && !YapoSettings.Instance.PlayerDecision && !MultipathUpgradeLogic.TryGetUpgradePaths(troops, out upgradesPerTypes))
                {
                    upgradeResults.MultiPathSkipped++;
                    continue;
                }

                foreach ((int maxUpgradableTroops, PartyScreenLogic.PartyCommand.UpgradeTargetType upgradeTargetType)upgradesPerType in upgradesPerTypes)
                {
                    int troopsToUpgrade = CalculateCountOfTroopsThatCanBeUpgraded(availableResources, troops, partyScreenLogic, upgradesPerType);
                    if (troopsToUpgrade == 0)
                    {
                        continue;
                    }

                    upgradeResults.UpgradedTypes++;
                    upgradeResults.UpgradedTotal += troopsToUpgrade;

                    PartyScreenLogic.PartyCommand upgradeCommand = new PartyScreenLogic.PartyCommand();
                    upgradeCommand.FillForUpgradeTroop(troops.Side, troops.Type, troops.Character, troopsToUpgrade, upgradesPerType.upgradeTargetType);
                    commands.Add(new Tuple <PartyCharacterVM, PartyScreenLogic.PartyCommand>(troops, upgradeCommand));

                    availableResources.UpdateAvailableResources(troops, troopsToUpgrade, (int)upgradesPerType.upgradeTargetType);
                }
            }

            return(commands);
        }
Example #5
0
        public void UpdateUnloadedVesselData()
        {
            // clear reference dictionaries
            foreach (var vesselDataResourceChange in ResourceChanges)
            {
                vesselDataResourceChange.Value.Change = 0;
            }

            // clear value dictionaries
            AvailableResources.Clear();
            MaxAmountResources.Clear();
            AvailableStorage.Clear();

            Position            = Vessel.GetWorldPos3D();
            Orbit               = Vessel.GetOrbit();
            OrbitalVelocityAtUt = Orbit.getOrbitalVelocityAtUT(Planetarium.GetUniversalTime()).xzy;

            // calculate heading vector once per frame per vessel
            HeadingVector = EngineBackgroundProcessing.GetHeadingVectorForAutoPilot(vesselData: this, UT: Planetarium.GetUniversalTime());

            if (HeadingVector != Vector3d.zero && DeltaTime != 0)
            {
                // apply Perturb once per frame per vessel
                AccelerationVector = Vector3d.zero;
                foreach (KeyValuePair <uint, PersistentEngineData> engineData in Engines)
                {
                    PersistentEngineData persistentEngineData = engineData.Value;

                    persistentEngineData.DeltaVVector = persistentEngineData.DeltaV * HeadingVector.normalized * persistentEngineData.PersistentEngine.cosine;
                    AccelerationVector += persistentEngineData.DeltaVVector / DeltaTime;
                }

                Orbit.Perturb(AccelerationVector * TimeWarp.fixedDeltaTime, Planetarium.GetUniversalTime());
            }

            // calculate vessel mass and total resource amounts
            TotalVesselMassInTon = 0;
            foreach (ProtoPartSnapshot protoPartSnapshot in Vessel.protoVessel.protoPartSnapshots)
            {
                TotalVesselMassInTon += protoPartSnapshot.mass;
                foreach (ProtoPartResourceSnapshot protoPartResourceSnapshot in protoPartSnapshot.resources)
                {
                    if (protoPartResourceSnapshot.definition == null)
                    {
                        continue;
                    }

                    TotalVesselMassInTon += protoPartResourceSnapshot.amount * protoPartResourceSnapshot.definition.density;

                    MaxAmountResources.TryGetValue(protoPartResourceSnapshot.resourceName, out double maxAmount);
                    MaxAmountResources[protoPartResourceSnapshot.resourceName] = maxAmount + protoPartResourceSnapshot.maxAmount;

                    UpdateAvailableResource(protoPartResourceSnapshot.resourceName, Math.Min(protoPartResourceSnapshot.maxAmount, protoPartResourceSnapshot.amount));
                }
            }
            TotalVesselMassInKg = TotalVesselMassInTon * 1000;

            // calculate storage room for resources
            foreach (KeyValuePair <string, double> availableResource in AvailableResources)
            {
                AvailableResources.TryGetValue(availableResource.Key, out double availableAmount);
                MaxAmountResources.TryGetValue(availableResource.Key, out double maxAmount);
                AvailableStorage[availableResource.Key] = maxAmount - availableAmount;
            }
        }
Example #6
0
        protected Boolean CheckResourceAvailability(Lot lot)
        {
            Boolean allAvailable;

            string  auxResourceA = lot.ReticleID1;
            Boolean auxResourceA_Available;

            // Special check if reticle = 4106
            if (auxResourceA == "4106")
            {
                if (ReticleDictionary[$"{auxResourceA}_a"] == "Stocker" || ReticleDictionary[$"{auxResourceA}_b"] == "Stocker")
                {
                    auxResourceA_Available = true;
                }
                else
                {
                    auxResourceA_Available = false;
                }
            }
            else
            {
                if (ReticleDictionary[auxResourceA] == "Stocker")
                {
                    auxResourceA_Available = true;
                }
                else
                {
                    auxResourceA_Available = false;
                }
            }

            string  auxResourceB = lot.IrdName;
            Boolean auxResourceB_Available;

            if (AvailableResources.ContainsKey(auxResourceB))
            {
                if (AvailableResources[auxResourceB] - AllocatedResources[auxResourceB] <= 0)
                {
                    auxResourceB_Available = false;
                }
                else
                {
                    auxResourceB_Available = true;
                }
            }
            else
            {
                auxResourceB_Available = true;
            }

            if (auxResourceA_Available && auxResourceB_Available)
            {
                allAvailable = true;
            }
            else
            {
                allAvailable = false;
            }

            return(allAvailable);
        }