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
+24 -26
View File
@@ -121,8 +121,31 @@ namespace Subsurface.Items.Components
if (reload > 0.0f) return false;
Projectile projectileComponent = null;
//search for a projectile from linked containers
Item projectile = null;
foreach (MapEntity e in item.linkedTo)
{
Item container = e as Item;
if (container == null) continue;
ItemContainer containerComponent = container.GetComponent<ItemContainer>();
if (containerComponent == null) continue;
for (int i = 0; i < containerComponent.inventory.items.Length; i++)
{
if (containerComponent.inventory.items[i] == null) continue;
if ((projectileComponent = containerComponent.inventory.items[i].GetComponent<Projectile>()) != null)
{
projectile = containerComponent.inventory.items[i];
break;
}
}
if (projectileComponent != null) break;
}
if (projectile == null || projectileComponent == null) return false;
//currPowerConsumption = powerConsumption;
float availablePower = 0.0f;
//List<PowerContainer> batteries = new List<PowerContainer>();
@@ -147,31 +170,6 @@ namespace Subsurface.Items.Components
if (availablePower < currPowerConsumption) return false;
//search for a projectile from linked containers
Item projectile = null;
foreach (MapEntity e in item.linkedTo)
{
Item container = e as Item;
if (container == null) continue;
ItemContainer containerComponent = container.GetComponent<ItemContainer>();
if (containerComponent == null) continue;
for (int i = 0; i < containerComponent.inventory.items.Length; i++)
{
if (containerComponent.inventory.items[i] == null) continue;
if ((projectileComponent = containerComponent.inventory.items[i].GetComponent<Projectile>()) != null)
{
projectile = containerComponent.inventory.items[i];
break;
}
}
if (projectileComponent != null) break;
}
if (projectile == null || projectileComponent==null) return false;
projectile.body.ResetDynamics();
projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);