Skip to content

Commit

Permalink
adding ecpershot option for weapons PapaJoesSoup#486
Browse files Browse the repository at this point in the history
  • Loading branch information
gomker committed Jul 8, 2018
1 parent 038afbf commit 8146622
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions BDArmory/BDArmory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Misc\CFEnable.cs" />
<Compile Include="Misc\EngageableWeapon.cs" />
<Compile Include="Misc\IEngageService.cs" />
<Compile Include="ModuleEMP.cs" />
<Compile Include="Parts\BDExplosivePart.cs" />
<Compile Include="Parts\MissileBase.cs" />
<Compile Include="Parts\ModuleWWC.cs" />
Expand Down
34 changes: 32 additions & 2 deletions BDArmory/ModuleWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,9 @@ private void Fire()
//Transform[] fireTransforms = part.FindModelTransforms("fireTransform");
for (int i = 0; i < fireTransforms.Length; i++)
{
if ((BDArmorySettings.INFINITE_AMMO || part.RequestResource(ammoName, requestResourceAmount) > 0))
{
//if ((BDArmorySettings.INFINITE_AMMO || part.RequestResource(ammoName, requestResourceAmount) > 0))
if (CanFire())
{
Transform fireTransform = fireTransforms[i];
spinningDown = false;

Expand Down Expand Up @@ -1211,6 +1212,8 @@ private void Fire()

//heat
heat += heatPerShot;
//EC
DrainECPerShot();
}
else
{
Expand Down Expand Up @@ -1444,6 +1447,33 @@ void ParseWeaponType()
}
}

void DrainECPerShot()
{
if (ECPerShot == 0) return;
//double drainAmount = ECPerShot * TimeWarp.fixedDeltaTime;
double drainAmount = ECPerShot;
double chargeAvailable = part.RequestResource("ElectricCharge", drainAmount, ResourceFlowMode.ALL_VESSEL);
}

bool CanFire()
{
if ((BDArmorySettings.INFINITE_AMMO || part.RequestResource(ammoName, requestResourceAmount) > 0))
{
if (ECPerShot != 0)
{
double chargeAvailable = part.RequestResource("ElectricCharge", ECPerShot, ResourceFlowMode.ALL_VESSEL);
if (chargeAvailable < ECPerShot * 0.95f)
{
ScreenMessages.PostScreenMessage("Weapon Requires EC", 5.0f, ScreenMessageStyle.UPPER_CENTER);
return false;
}
}

return true;
}

return false;
}

#endregion

Expand Down

0 comments on commit 8146622

Please sign in to comment.