public Program()
        {
            var container = GridTerminalSystem.GetBlockWithName(CONTAINERNAME) as IMyCargoContainer;

            if (container == null)
            {
                Print("Unable to find container with specified name!");
            }
            else
            {
                _hydrogenContainer = new CargoContainer(container);
            }
        }
Beispiel #2
0
        public void Bind()
        {
            tree.Initialize(32);
            var unitTypes = new List <VehicleTypes> {
                VehicleTypes.Drone, VehicleTypes.Fighter, VehicleTypes.Mine, VehicleTypes.Satellite, VehicleTypes.Troop, VehicleTypes.WeaponPlatform
            };

            if (CargoContainer != null)
            {
                var      cargo = CargoContainer.Cargo;
                var      used  = cargo.Size;
                var      total = CargoContainer.CargoStorage;
                var      free  = used - total;
                TreeNode typesNode;
                if (ShowAllUnitsAndPopulationAlways)
                {
                    typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var vt in unitTypes)
                    {
                        typesNode.AddItemWithImage($"All {vt}s", vt, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vt));
                    }
                    typesNode.Expand();
                }
                if (CargoContainer.AllUnits.Any())
                {
                    if (!ShowAllUnitsAndPopulationAlways)
                    {
                        typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                        foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.VehicleType))
                        {
                            typesNode.AddItemWithImage($"All {ug.Key}s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, ug.Key));
                        }
                        typesNode.Expand();
                    }
                    foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.VehicleType))
                    {
                        var typeNode = tree.GetAllNodes().First(x => x.Tag.ToString() == ug.Key.ToString());
                        foreach (var ug2 in ug.GroupBy(u => u.Design))
                        {
                            var designNode = typeNode.AddItemWithImage(ug.Count() + "x \"" + ug2.Key.Name + "\" " + ug2.Key.VehicleTypeName + " (" + ug2.Key.Hull.Size.Kilotons() + " each)", ug.Key, ug.First().Icon);
                            foreach (var u in ug2)
                            {
                                designNode.AddItemWithImage(u.Name, u, u.Icon);
                            }
                        }
                    }
                    var rolesNode = tree.AddItemWithImage("Units - Roles", "Roles", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.Role))
                    {
                        rolesNode.AddItemWithImage(ug.Count() + "x " + ug.Key, ug.Key, ug.First().Icon);
                    }
                    rolesNode.Expand();
                }
                TreeNode popNode = null;
                if (ShowAllUnitsAndPopulationAlways)
                {
                    popNode = tree.AddItemWithImage(CargoContainer.AllPopulation.Sum(kvp => kvp.Value).ToUnitString(true) + " Total Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                }
                if (CargoContainer.AllPopulation.Any())
                {
                    if (popNode == null)
                    {
                        popNode = tree.AddItemWithImage(CargoContainer.AllPopulation.Sum(kvp => kvp.Value).ToUnitString(true) + " Total Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                    }
                    foreach (var pop in CargoContainer.AllPopulation)
                    {
                        popNode.AddItemWithImage(pop.Value.ToUnitString(true) + " " + pop.Key + " Population", pop.Key, pop.Key.Icon);
                    }
                    popNode.Expand();
                }

                lblTonnage.Text = "Cargo Storage Free: " + CargoContainer.CargoStorageFree().Kilotons() + "\n" + "Population Storage Free: " + CargoContainer.PopulationStorageFree.ToUnitString(true);
            }
            else if (CargoDelta != null)
            {
                TreeNode typesNode;
                if (ShowAllUnitsAndPopulationAlways)
                {
                    typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var vt in unitTypes)
                    {
                        typesNode.AddItemWithImage($"All {vt}s", vt, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vt));
                    }
                    typesNode.Expand();
                }
                else
                {
                    if (CargoDelta.UnitTypeTonnage.Any())
                    {
                        typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                        foreach (var ug in CargoDelta.UnitTypeTonnage)
                        {
                            typesNode.AddItemWithImage(ug.Value.Kilotons("All") + " " + ug.Key.ToSpacedString() + "s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, ug.Key));
                        }
                        typesNode.Expand();
                    }
                }

                if (CargoDelta.UnitRoleTonnage.Any())
                {
                    var rolesNode = tree.AddItemWithImage("Units - Roles", "Roles", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var ug in CargoDelta.UnitRoleTonnage)
                    {
                        rolesNode.AddItemWithImage(ug.Value.Kilotons("All") + " " + ug.Key + "s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    }
                    rolesNode.Expand();
                }
                if (CargoDelta.UnitDesignTonnage.Any())
                {
                    var designsNode = tree.AddItemWithImage("Units - Designs", "Designs", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var ug in CargoDelta.UnitDesignTonnage)
                    {
                        designsNode.AddItemWithImage(ug.Value.Kilotons("All") + " \"" + ug.Key.Name + "\" " + ug.Key.VehicleType + "s + (" + ug.Key.Hull.Size.Kilotons() + " each)", ug.Key, ug.Key.Icon);
                    }
                    designsNode.Expand();
                }
                if (CargoDelta.Units.Any())
                {
                    var unitsNode = tree.AddItemWithImage("Units - Individual (" + CargoDelta.Units.Count + ")", "Units", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var u in CargoDelta.Units)
                    {
                        unitsNode.AddItemWithImage(u.Name, u, u.Icon);
                    }
                    // don't expand the units node, there's probably tons of stuff there!
                }
                TreeNode popNode = null;
                if (ShowAllUnitsAndPopulationAlways || CargoDelta.AllPopulation)
                {
                    popNode = tree.AddItemWithImage("All Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                    popNode.Expand();
                }
                if (CargoDelta.RacePopulation.Any() || CargoDelta.AnyPopulation != 0)
                {
                    if (popNode == null)
                    {
                        popNode = tree.AddItemWithImage("All Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                    }
                    foreach (var pop in CargoDelta.RacePopulation)
                    {
                        popNode.AddItemWithImage(pop.Value.ToUnitString(true, 4, "All") + " " + pop.Key + " Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", pop.Key, pop.Key.Icon);
                    }
                    if (CargoDelta.AnyPopulation != 0)
                    {
                        popNode.AddItemWithImage(CargoDelta.AnyPopulation.ToUnitString(true, 4) + " Population of Any Race (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Total", Pictures.GetGenericImage(typeof(Race)));
                    }
                    popNode.Expand();
                }

                // TODO - estimate tonnage based on available cargo, but we'd need the cargo transfer target for that...
                lblTonnage.Text = "Estimated Tonnage: " + CargoDelta.EstimatedTonnage.Kilotons("Unknown");
            }
        }
Beispiel #3
0
        private BehaviorExecutionResults DropOffCargoToJetCan()
        {
            var methodName = "DropOffCargoToJetCan";

            LogTrace(methodName);

            if (_jetcanDropOffState == JetcanDropOffStates.Idle)
            {
                SetJetcanDropoffState();
            }

            //If the jetcan doesn't exist, override the state to 'create can'.
            if (_jettisonContainer.CurrentContainer == null)
            {
                _jetcanDropOffState = JetcanDropOffStates.CreateCan;
            }

            switch (_jetcanDropOffState)
            {
            case JetcanDropOffStates.MarkCanFull:
                _jetcanDropOffState = JetcanDropOffStates.CreateCan;

                if (_jettisonContainer.CurrentContainer != null)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Marking active can full.");
                    MarkJetcanFull();
                }
                else
                {
                    goto case JetcanDropOffStates.CreateCan;
                }

                break;

            case JetcanDropOffStates.CreateCan:
                _jettisonContainer.SetActiveCan();

                if (_jettisonContainer.CurrentContainer != null)
                {
                    _jettisonContainer.RenameActiveCan(false);

                    _jetcanDropOffState = JetcanDropOffStates.OpenCan;
                    goto case JetcanDropOffStates.OpenCan;
                }

                if (_meCache.Ship.Ship.HasOreHold)
                {
                    if (!_ship.IsOreHoldActive)
                    {
                        LogMessage(methodName, LogSeverityTypes.Standard, "Making ship ore hold active before creating a jetcan.");
                        _ship.MakeOreHoldActive();
                        return(BehaviorExecutionResults.Incomplete);
                    }
                }
                else if (!_ship.IsCargoHoldActive)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Making ship cargo hold active before creating a jetcan.");
                    _ship.MakeCargoHoldActive();
                    return(BehaviorExecutionResults.Incomplete);
                }

                var ore = CargoContainer.GetOreFromList(_meCache.Ship.Ship.HasOreHold ? _meCache.Ship.Ship.GetOreHoldCargo() : _meCache.Ship.Cargo.ToList());

                if (ore.Count == 0)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Error: We're above the cargo full threshold but have no ore to jetisson.");
                    return(BehaviorExecutionResults.Error);
                }

                var item = ore.First();

                LogMessage(methodName, LogSeverityTypes.Standard, "Creating new jetcan from item \"{0}\" ({1}).",
                           item.Name, item.ID);

                _jettisonContainer.CreateJetCan(item);
                break;

            case JetcanDropOffStates.OpenCan:
                if (!_jettisonContainer.IsCurrentContainerWindowOpen)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Opening cargo of active jetcan \"{0}\" ({1}).",
                               _jettisonContainer.CurrentContainer.Name, _jettisonContainer.CurrentContainerId);
                    _jettisonContainer.CurrentContainer.Open();
                }
                else
                {
                    _jetcanDropOffState = JetcanDropOffStates.TransferCargo;
                    goto case JetcanDropOffStates.TransferCargo;
                }
                break;

            case JetcanDropOffStates.TransferCargo:
                if (_meCache.Ship.Ship.HasOreHold)
                {
                    if (!_ship.IsOreHoldActive)
                    {
                        LogMessage(methodName, LogSeverityTypes.Standard, "Making ship ore hold active before transferring cargo to a jetcan.");
                        _ship.MakeOreHoldActive();
                        return(BehaviorExecutionResults.Incomplete);
                    }
                }
                else if (!_ship.IsCargoHoldActive)
                {
                    LogMessage(methodName, LogSeverityTypes.Standard, "Making ship cargo hold active before transferring cargo to a jetcan.");
                    _ship.MakeCargoHoldActive();
                    return(BehaviorExecutionResults.Incomplete);
                }

                LogMessage(methodName, LogSeverityTypes.Standard, "Transferring ore to the active jetcan.");

                if (_meCache.Ship.Ship.HasOreHold)
                {
                    _ship.TransferOreHoldToJetCan(_jettisonContainer.CurrentContainerId);
                }
                else
                {
                    _ship.TransferCargoHoldToJetCan(_jettisonContainer.CurrentContainerId);
                }

                _jetcanDropOffState = JetcanDropOffStates.Idle;
                return(BehaviorExecutionResults.Complete);
            }

            return(BehaviorExecutionResults.Incomplete);
        }
Beispiel #4
0
 public static void UpdateCargoBuffer(CargoContainer __instance)
 {
     __instance.computeBuffer.Release();
     __instance.computeBuffer = new ComputeBuffer(__instance.poolCapacity, 32, ComputeBufferType.Default);
 }