public static List <WBIResourceManifest> GetManifestsForDestination(string destinationID) { List <WBIResourceManifest> manifestList = new List <WBIResourceManifest>(); //Find all the resource manifests that match the desired destination. WBIResourceManifest resourceManifest; List <ConfigNode> nodes = WBIManifestScenario.Instance.GetManifestConfigs(destinationID, WBIResourceManifest.kResourceManifestType); foreach (ConfigNode node in nodes) { resourceManifest = new WBIResourceManifest(); resourceManifest.Load(node); manifestList.Add(resourceManifest); } return(manifestList); }
protected void drawConfirmPage() { GUILayout.BeginVertical(); //Payload Summary GUILayout.Label("<color=white><b>Payload:</b></color>"); scrollPosResources = GUILayout.BeginScrollView(scrollPosResources, resourcePaneOptions); //Resources int totalResources = sourceDisplayNames.Length; WBIResourceTotals resourceTotals; for (int index = 0; index < totalResources; index++) { resourceTotals = sourceVesselResources[sourceDisplayNames[index]]; if (resourceTotals.transferPercent < 0.0001f) { continue; } GUILayout.BeginScrollView(panelPos, resourcePanelOptions); GUILayout.BeginVertical(); //Resource name GUILayout.Label("<color=white><b>" + resourceTotals.displayName + "</b></color>"); //Amount text field GUILayout.Label("<color=white> Units: " + string.Format("{0:f2}", resourceTotals.amount * resourceTotals.transferPercent) + "</color>"); GUILayout.EndVertical(); GUILayout.EndScrollView(); sourceVesselResources[sourceDisplayNames[index]] = resourceTotals; } //Packing list if (packingList.Count > 0) { WBIPackingItem packingItem; int totalItems = packingList.Count; for (int index = 0; index < totalItems; index++) { //Get the packing item packingItem = packingList[index]; //If selected list out the item if (packingItem.isSelected) { GUILayout.Label("<color=white>" + packingItem.partTitle + "(" + packingItem.quantity + ")</color>"); } } } GUILayout.EndScrollView(); //Buttons GUILayout.BeginHorizontal(); //Back button if (GUILayout.Button(kBackLabel)) { pageID = PipelineViewPages.ChooseResources; } //Launch button //At this time, deduct the required resources and payload resources if (GUILayout.Button(kLaunchLabel)) { //Pay EC cost double amountToTransfer = electricityCostPerTonne * projectileMass; this.part.RequestResource("ElectricCharge", amountToTransfer, ResourceFlowMode.ALL_VESSEL); //Pay LFO units this.part.RequestResource("LiquidFuel", liquidFuelUnits, ResourceFlowMode.ALL_VESSEL); this.part.RequestResource("Oxidizer", oxidizerUnits, ResourceFlowMode.ALL_VESSEL); //Pay guidance data cost if (setGuidanceDataAmount != null) { setGuidanceDataAmount(totalGuidanceData - totalDataCost); } //Create the resource manifest WBIResourceManifest manifest = new WBIResourceManifest(); manifest.destinationID = selectedPipelineNode.moduleValues.GetValue("uniqueIdentifier"); //Deduct payload resources and load them into the transfer request. for (int index = 0; index < totalResources; index++) { //Get the totals, skipping any that has no transfer percent resourceTotals = sourceVesselResources[sourceDisplayNames[index]]; if (resourceTotals.transferPercent < 0.0001f) { continue; } //Deduct the resource amount from the vessel amountToTransfer = resourceTotals.amount * resourceTotals.transferPercent; this.part.RequestResource(resourceTotals.resourceName, amountToTransfer, ResourceFlowMode.ALL_VESSEL); //Add the resource to the transfer manifest. manifest.resourceAmounts.Add(resourceTotals.resourceName, amountToTransfer); } if (manifest.resourceAmounts.Count > 0) { WBIManifestScenario.Instance.AddManifest(manifest); } //Create the Inventory manifest if (packingList.Count > 0) { int totalItems = packingList.Count; WBIKISInventoryManifest inventoryManifest = new WBIKISInventoryManifest(); inventoryManifest.destinationID = selectedPipelineNode.moduleValues.GetValue("uniqueIdentifier"); WBIPackingItem packingItem; WBIInventoryManifestItem manifestItem; for (int index = 0; index < totalItems; index++) { //Get the packing item packingItem = packingList[index]; if (!packingItem.isSelected) { continue; } //Fill out the manifest manifestItem = new WBIInventoryManifestItem(); manifestItem.partName = packingItem.kisItem.availablePart.name; manifestItem.quantity = packingItem.quantity; manifestItem.volume = packingItem.volume; ConfigNode partNode = new ConfigNode(WBIKISInventoryManifest.kPartNode); packingItem.kisItem.availablePart.partConfig.CopyTo(partNode); ConfigNode partConfigNode = new ConfigNode(WBIKISInventoryManifest.kPartConfig); partConfigNode.AddNode(partNode); manifestItem.partConfigNode = partConfigNode; inventoryManifest.inventoryItems.Add(manifestItem); //Remove the item from the inventory inventory.DeleteItem(packingItem.slot); } WBIManifestScenario.Instance.AddManifest(inventoryManifest); packingList.Clear(); } //Play launch effects and inform user. ScreenMessages.PostScreenMessage(kShipmentLaunched + selectedPipelineNode.vesselName, kMessageDuration, ScreenMessageStyle.UPPER_CENTER); //Change page pageID = PipelineViewPages.SelectVessel; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
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); } } }