Esempio n. 1
0
        protected void drawPackingList()
        {
            inventory.RefreshMassAndVolume();
            Dictionary <int, WBIKISItem> items = inventory.items;

            //Rebuild the packing list if the item count has changed.
            WBIPackingItem packingItem;
            WBIKISItem     item;

            if (inventoryItemCount != items.Count)
            {
                inventoryItemCount = items.Count;
                packingList.Clear();
                packingListMass = 0;
                foreach (int key in items.Keys)
                {
                    item = items[key];

                    packingItem            = new WBIPackingItem();
                    packingItem.kisItem    = item;
                    packingItem.isSelected = false;
                    packingItem.partTitle  = item.availablePart.title;
                    packingItem.mass       = item.totalMass;
                    packingItem.volume     = item.volume;
                    packingItem.quantity   = item.quantity;
                    packingItem.slot       = key;
                    packingList.Add(packingItem);
                }
            }

            //Inventory mass
            GUILayout.Label(string.Format("<color=white><b>Package Mass: </b>{0:f3}tonnes</color>", packingListMass));

            //Now go through all the inventory items and let the player select the desired
            //items for the shipment.
            packingListMass = 0f;
            int    totalItems = packingList.Count;
            string toggleText;

            for (int index = 0; index < totalItems; index++)
            {
                //Get the packing item
                packingItem = packingList[index];

                //Get toggle text
                toggleText = packingItem.partTitle;
                if (packingItem.quantity > 1)
                {
                    toggleText = toggleText + " (" + Mathf.RoundToInt(packingItem.quantity).ToString() + ")";
                }

                //Draw toggle
                packingItem.isSelected = GUILayout.Toggle(packingItem.isSelected, toggleText);
                packingList[index]     = packingItem;

                //Update packing list mass
                if (packingItem.isSelected)
                {
                    packingListMass += packingItem.mass;
                }
            }
        }
Esempio 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);
                }
            }
        }