Supercapacitor, shooting a turret wont use power if there isn't any ammo

This commit is contained in:
Regalis
2015-08-22 14:45:54 +03:00
parent d8904eaa56
commit 1e990784b2
6 changed files with 51 additions and 29 deletions
@@ -41,7 +41,27 @@
<ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]"> <ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver" type="Equipped"/> <requireditem name="Screwdriver" type="Equipped"/>
<input name="power_in"/> <input name="power"/>
</ConnectionPanel> </ConnectionPanel>
</Item> </Item>
<Item
name="Supercapacitor"
linkable="true"
pickdistance="150">
<Sprite texture ="supercapacitor.png" depth="0.8"/>
<PowerContainer capacity="2000.0" maxrechargespeed="2000.0" maxoutput="2000.0" canbeselected = "true">
<GuiFrame rect="0,0,0.3,0.3" alignment="Center" color="0.0,0.0,0.0,0.8"/>
</PowerContainer>
<ConnectionPanel canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver" type="Equipped"/>
<input name="power"/>
</ConnectionPanel>
</Item>
</Items> </Items>
Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

+2 -2
View File
@@ -5,9 +5,9 @@
Tags="smallitem" Tags="smallitem"
pickdistance="150"> pickdistance="150">
<Sprite texture ="idcard.png" depth="0.5f"/> <Sprite texture ="idcard.png" depth="0.8f"/>
<Body width="16" height="16" density="10"/> <Body width="16" height="16"/>
<Pickable/> <Pickable/>
</Item> </Item>
+25 -27
View File
@@ -121,32 +121,6 @@ namespace Subsurface.Items.Components
if (reload > 0.0f) return false; if (reload > 0.0f) return false;
Projectile projectileComponent = null; Projectile projectileComponent = null;
//currPowerConsumption = powerConsumption;
float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>();
foreach (Connection c in item.Connections)
{
foreach (Connection c2 in c.Recipients)
{
if (c2 == null || c2.Item == null) continue;
PowerContainer batteryComponent = c2.Item.GetComponent<PowerContainer>();
if (batteryComponent == null) continue;
float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut);
float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
batteryComponent.Charge -= takePower;
availablePower += takePower;
}
}
reload = reloadTime;
if (availablePower < currPowerConsumption) return false;
//search for a projectile from linked containers //search for a projectile from linked containers
Item projectile = null; Item projectile = null;
foreach (MapEntity e in item.linkedTo) foreach (MapEntity e in item.linkedTo)
@@ -170,7 +144,31 @@ namespace Subsurface.Items.Components
if (projectileComponent != null) break; if (projectileComponent != null) break;
} }
if (projectile == null || projectileComponent==null) return false; if (projectile == null || projectileComponent == null) return false;
float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>();
foreach (Connection c in item.Connections)
{
foreach (Connection c2 in c.Recipients)
{
if (c2 == null || c2.Item == null) continue;
PowerContainer batteryComponent = c2.Item.GetComponent<PowerContainer>();
if (batteryComponent == null) continue;
float batteryPower = Math.Min(batteryComponent.Charge, batteryComponent.MaxOutPut);
float takePower = Math.Min(currPowerConsumption - availablePower, batteryPower);
batteryComponent.Charge -= takePower;
availablePower += takePower;
}
}
reload = reloadTime;
if (availablePower < currPowerConsumption) return false;
projectile.body.ResetDynamics(); projectile.body.ResetDynamics();
projectile.body.Enabled = true; projectile.body.Enabled = true;
+4
View File
@@ -315,6 +315,9 @@
<Content Include="Content\Items\Electricity\lamp.png"> <Content Include="Content\Items\Electricity\lamp.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Items\Electricity\supercapacitor.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Items\Electricity\wifi.png"> <Content Include="Content\Items\Electricity\wifi.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@@ -594,6 +597,7 @@
</Content> </Content>
<Content Include="Content\Items\Electricity\poweritems.xml"> <Content Include="Content\Items\Electricity\poweritems.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content> </Content>
<Content Include="Content\Items\Weapons\railgun.xml"> <Content Include="Content\Items\Weapons\railgun.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Binary file not shown.