Skip to content

Commit

Permalink
Merge pull request #43 from BobPalmer/DEVELOP
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BobPalmer committed Mar 3, 2016
2 parents d2b0a3c + 71df094 commit d4faa2c
Show file tree
Hide file tree
Showing 8 changed files with 956 additions and 7 deletions.
9 changes: 9 additions & 0 deletions FOR_RELEASE/GameData/000_USITools/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0.6.3 - 2016.03.02
------------------
Logistics pulls are now restricted to warehouses
Warehouses can be toggled

0.6.2 - 2016.02.05
------------------
Added support for Blizzy's Toolbar (thanks nanathan!)

0.6.1 - 2016.02.02
------------------
Fixed an issue where distributed warehouses were excessively greedy
Expand Down
Binary file modified FOR_RELEASE/GameData/000_USITools/USITools.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion FOR_RELEASE/GameData/000_USITools/USITools.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION":{
"MAJOR":0,
"MINOR":6,
"PATCH":1,
"PATCH":3,
"BUILD":0
},
"KSP_VERSION":{
Expand Down
8 changes: 7 additions & 1 deletion USITools/USITools/Logistics/ModuleDistributedWarehouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ private void LevelResources(string resource)
var resParts = new List<Part>();
foreach (var d in depots)
{
resParts.AddRange(d.parts.Where(p => p.Resources.Contains(resource) && p.Modules.Contains("ModuleDistributedWarehouse")));
var pList = d.parts.Where(p => p.Resources.Contains(resource) && p.Modules.Contains("ModuleDistributedWarehouse"));
foreach (var p in pList)
{
var wh = p.FindModuleImplementing<USI_ModuleResourceWarehouse>();
if(wh != null && wh.transferEnabled)
resParts.Add(p);
}
}
var amountSum = 0d;
var maxSum = 0d;
Expand Down
18 changes: 15 additions & 3 deletions USITools/USITools/Logistics/ModuleLogisticsConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ private void CheckLogistics(List<ResourceRatio> resList)

public List<Vessel> GetResourceStockpiles()
{
var depots = LogisticsTools.GetNearbyVessels(LogisticsSetup.Instance.Config.ScavangeRange, false, vessel, true);
List<Vessel> depots = LogisticsTools.GetNearbyVessels(LogisticsSetup.Instance.Config.ScavangeRange, false, vessel, true)
.Where(dv => dv.FindPartModulesImplementing<USI_ModuleResourceWarehouse>().Any()).ToList();
var nearbyVesselList = LogisticsTools.GetNearbyVessels(LogisticsTools.PHYSICS_RANGE, false, vessel, true);
foreach (var v in nearbyVesselList)
{
Expand All @@ -130,8 +131,8 @@ public List<Vessel> GetResourceStockpiles()
if (range <= m.ResourceDistributionRange)
{
//Now find ones adjacent to our depot.
var stockpiles = LogisticsTools.GetNearbyVessels(m.ResourceDistributionRange, false, vessel,
true);
List<Vessel> stockpiles = LogisticsTools.GetNearbyVessels(m.ResourceDistributionRange, false, vessel,
true).Where(sv=>sv.FindPartModulesImplementing<USI_ModuleResourceWarehouse>().Any()).ToList();
foreach (var s in stockpiles)
{
if (!depots.Contains(s))
Expand All @@ -142,6 +143,7 @@ public List<Vessel> GetResourceStockpiles()
}
return depots;
}


public List<Vessel> GetPowerDistributors()
{
Expand Down Expand Up @@ -223,6 +225,16 @@ private double FetchResources(double amount, PartResourceDefinition resource, do
var partList = v.Parts.Where(p => p.Resources.Contains(resource.name));
foreach (var p in partList)
{
//Guard clause.
if (resource.name != "ElectricCharge")
{
var wh = p.FindModuleImplementing<USI_ModuleResourceWarehouse>();
if(wh == null)
continue;
if(!wh.transferEnabled)
continue;
}

var pr = p.Resources[resource.name];
if (pr.amount >= demand)
{
Expand Down
32 changes: 30 additions & 2 deletions USITools/USITools/Logistics/USI_ModuleResourceWarehouse.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
namespace KolonyTools
{
public class USI_ModuleResourceWarehouse : PartModule
{

{
[KSPField(isPersistant = true)]
public bool transferEnabled = true;

[KSPEvent(guiName = "Disable Warehouse", active = true, guiActive = true)]
public void DisableTransfer()
{
ToggleTransfer(false);
}

[KSPEvent(guiName = "Enable Warehouse", active = true, guiActive = false)]
public void EnableTransfer()
{
ToggleTransfer(true);
}

private void ToggleTransfer(bool state)
{
transferEnabled = state;
Events["DisableTransfer"].guiActive = state;
Events["EnableTransfer"].guiActive = !state;
MonoUtilities.RefreshContextWindows(part);
}

public override void OnStart(StartState state)
{
Events["DisableTransfer"].guiActive = transferEnabled;
Events["EnableTransfer"].guiActive = !transferEnabled;

}
}
}
1 change: 1 addition & 0 deletions USITools/USITools/USITools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="EnginesAndTanks\USI_PulseDrive.cs" />
<Compile Include="EnginesAndTanks\USI_WiggleEngine.cs" />
<Compile Include="USI_ToolbarWrapper.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Loading

0 comments on commit d4faa2c

Please sign in to comment.