public void Awake()
        {
            if (Utils.IsModInstalled("KIS") == false)
            {
                return;
            }

            WBIKISInventoryWrapper inventory;
            int seatIndex = 0;

            //Try to get the max EVA volume from the KIS config settings
            ConfigNode nodeKISSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig");

            if (nodeKISSettings != null)
            {
                if (nodeKISSettings.HasNode("EvaInventory"))
                {
                    ConfigNode nodeEVAInventory = nodeKISSettings.GetNode("EvaInventory");
                    if (nodeEVAInventory.HasValue("maxVolume"))
                    {
                        maxSeatVolume = float.Parse(nodeEVAInventory.GetValue("maxVolume"));
                    }
                }
            }

            //No go through each part and find a ModuleKISInventory
            //If found, and we find parts with seat inventory volume,
            //then Set the seat index.
            foreach (AvailablePart part in PartLoader.LoadedPartsList)
            {
                if (part.name == "kerbalEVA" || part.name == "kerbalEVAfemale" || part.name == "kerbalEVA_RD")
                {
                    continue;
                }

                seatIndex = 0;
                foreach (PartModule partModule in part.partPrefab.Modules)
                {
                    if (partModule.moduleName == "ModuleKISInventory")
                    {
                        try
                        {
                            inventory = new WBIKISInventoryWrapper(partModule);
                            if (inventory.maxVolume <= 0.001f)
                            {
                                inventory.maxVolume = maxSeatVolume;
                                inventory.podSeat   = seatIndex;
                                inventory.invType   = WBIKISInventoryWrapper.InventoryType.Pod;
                                seatIndex          += 1;
                            }
                        }

                        catch (Exception ex)
                        {
                            Debug.Log("WBIKISSeatInventoryConfig encountered an error while setting up a seat inventory: " + ex.Message);
                            continue;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void processDeliveries()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            //We're interested in resource and inventory deliveries...
            List <WBIResourceManifest> resourceManifests = WBIResourceManifest.GetManifestsForDestination(this.uniqueIdentifier);

            Log("Resource manifests count: " + resourceManifests.Count);

            //Distribute the resources throughout the vessel
            WBIResourceManifest resourceManifest;
            int totalManifests = resourceManifests.Count;

            string[] resourceKeys;
            string   resourceName;
            double   amount;

            for (int index = 0; index < totalManifests; index++)
            {
                //Get the manifest
                resourceManifest = resourceManifests[index];

                //Go through all the resources and distribute them
                resourceKeys = resourceManifest.resourceAmounts.Keys.ToArray();
                for (int keyIndex = 0; keyIndex < resourceKeys.Length; keyIndex++)
                {
                    //Get the name
                    resourceName = resourceKeys[keyIndex];

                    //Get the amount
                    amount = resourceManifest.resourceAmounts[resourceName];

                    //Distribute the resource
                    this.part.RequestResource(resourceName, -amount, ResourceFlowMode.ALL_VESSEL);
                    Log("Added " + amount + " units of " + resourceName);
                }
            }

            //Deliver inventory items
            if (WBIKISWrapper.IsKISInstalled())
            {
                //Get the inventory and available volume
                WBIKISInventoryWrapper        inventory   = WBIKISInventoryWrapper.GetInventory(this.part);
                List <WBIKISInventoryWrapper> inventories = WBIKISInventoryWrapper.GetInventories(this.part.vessel);
                int   currentIndex    = 0;
                float contentVolume   = 0;
                float availableVolume = 0;

                //Grab the first available inventory
                if (inventory == null)
                {
                    inventory = inventories[0];
                    if (inventory == null)
                    {
                        return;
                    }
                }

                //Get available volume
                inventory.RefreshMassAndVolume();
                contentVolume   = inventory.GetContentVolume();
                availableVolume = inventory.maxVolume - contentVolume;

                //Get all the manifests
                List <WBIKISInventoryManifest> inventoryManifests = WBIKISInventoryManifest.GetManifestsForDestination(this.uniqueIdentifier);
                Log("Inventory manifest count: " + inventoryManifests.Count);
                WBIKISInventoryManifest  inventoryManifest;
                WBIInventoryManifestItem inventoryItem;
                totalManifests = inventoryManifests.Count;
                int           totalItems;
                AvailablePart availablePart = null;
                int           skippedItems  = 0;
                for (int index = 0; index < totalManifests; index++)
                {
                    //Get the manifest
                    inventoryManifest = inventoryManifests[index];

                    //Get the total items in the manifest
                    totalItems = inventoryManifest.inventoryItems.Count;
                    for (int itemIndex = 0; itemIndex < totalItems; itemIndex++)
                    {
                        //Get the item
                        inventoryItem = inventoryManifest.inventoryItems[itemIndex];
                        Log("Looking for enough room for " + inventoryItem.partName);

                        //If the inventory has room, then add it.
                        if (inventoryItem.volume < availableVolume)
                        {
                            Log("Current inventory has room.");
                            //Decrease the available volume
                            availableVolume -= inventoryItem.volume;

                            //Get the part info
                            availablePart = PartLoader.getPartInfoByName(inventoryItem.partName);

                            //Add the part
                            inventory.AddItem(availablePart, inventoryItem.partConfigNode, inventoryItem.quantity);
                            Log("Added " + inventoryItem.partName);
                        }

                        //See if another inventory has room
                        else
                        {
                            while (currentIndex < inventories.Count)
                            {
                                currentIndex += 1;
                                inventory     = inventories[currentIndex];
                                Log("New inventory found");

                                inventory.RefreshMassAndVolume();
                                contentVolume   = inventory.GetContentVolume();
                                availableVolume = inventory.maxVolume - contentVolume;

                                //If the inventory has room, then add it.
                                if (inventoryItem.volume < availableVolume)
                                {
                                    //Decrease the available volume
                                    availableVolume -= inventoryItem.volume;

                                    //Get the part info
                                    availablePart = PartLoader.getPartInfoByName(inventoryItem.partName);

                                    //Add the part
                                    inventory.AddItem(availablePart, inventoryItem.partConfigNode, inventoryItem.quantity);
                                    Log("Added " + inventoryItem.partName);
                                    break;
                                }

                                else
                                {
                                    skippedItems += 1;
                                }
                            }
                        }
                    }
                }

                //Inform the player if we skipped some items
                if (skippedItems > 0)
                {
                    ScreenMessages.PostScreenMessage(kItemSkippedMsg, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                }
            }
        }