Author Topic: AdjustPowerSubsystem  (Read 519 times)

Offline Mark McWire

  • Posts: 83
  • Cookies: 1010
AdjustPowerSubsystem
« on: August 06, 2019, 03:49:31 AM »
Referring to -> http://www.bc-central.net/forums/index.php/topic,10618.0.html


Quote
I've added a new feature to loadspacehelper. This feature automatically calculates the energy you need based on the strength of the drive, sensors, shields, and weapons, and adjusts the power supply to that value. The values ​​of the warp core from the hardpoints are not taken into account.

Code: [Select]
###############################################################################
# AdjustSubsystemPower(pShip)
#
# Adjusts the power consumption of subsystems
#   and set Power Plants normal output to the sum of all subsystem power consumption
#
# Args: pShip - the ship
#
# Return: none
###############################################################################
def AdjustSubsystemPower(pShip):
debug(__name__ + ", AdjustSubsystemPower")

if (pShip == None):
return

if (pShip.GetPowerSubsystem() == None):
return

#Adjust Sensor Subsystem
fSensorPower = 0
if (pShip.GetSensorSubsystem()):
pSensor = pShip.GetSensorSubsystem().GetProperty()
pSensorRange = pSensor.GetBaseSensorRange()
fSensorPower = pSensorRange / 10
pSensor.SetNormalPowerPerSecond(fSensorPower)

#Adjust Warp Subsystem power to zero, because does only consume power while warping but not in idle state
if (pShip.GetWarpEngineSubsystem()):
pWarp = pShip.GetWarpEngineSubsystem().GetProperty()
pWarp.SetNormalPowerPerSecond(0.0)

#Adjust Impulse Engine Subsystem
fImpulsePower = 0
if (pShip.GetImpulseEngineSubsystem()):
pImpulse = pShip.GetImpulseEngineSubsystem().GetProperty()
fAccel = pImpulse.GetMaxAccel()
fVelocity = pImpulse.GetMaxSpeed()
fAngularAccel = pImpulse.GetMaxAngularAccel()
fAngularVelocity = pImpulse.GetMaxAngularVelocity()
pShipProperty = pShip.GetShipProperty()
fShipMass = pShipProperty.GetMass()
fKineticEnergy = (fShipMass / 2) * (fVelocity + fAngularVelocity) ** 2
fAccelTime = (fVelocity / fAccel) + (fAngularVelocity / fAngularAccel)
fImpulsePower = (fKineticEnergy / fAccelTime) / 64
pImpulse.SetNormalPowerPerSecond(fImpulsePower)

#Adjust Shield Subsystem
fShieldPower = 0
kShieldFacings = [App.ShieldProperty.FRONT_SHIELDS,
  App.ShieldProperty.REAR_SHIELDS,
  App.ShieldProperty.TOP_SHIELDS,
  App.ShieldProperty.BOTTOM_SHIELDS,
  App.ShieldProperty.LEFT_SHIELDS,
  App.ShieldProperty.RIGHT_SHIELDS]
if (pShip.GetShields()):
pShields = pShip.GetShields()
for kFacing in kShieldFacings:
fShieldPower = fShieldPower + 4 * pShields.GetShieldChargePerSecond(kFacing)

pShields.GetProperty().SetNormalPowerPerSecond(fShieldPower)

#Adjust Beam Weapon Subsystem
fBeamPower = 0
if (pShip.GetPhaserSystem()):
pBeamWeaponSystem = pShip.GetPhaserSystem()
for iIndex in range(pBeamWeaponSystem.GetNumChildSubsystems()):
if (pBeamWeaponSystem.GetChildSubsystem(iIndex)):
pBeamWeapon = App.PhaserBank_Cast(pBeamWeaponSystem.GetChildSubsystem(iIndex))
fBeamPower = fBeamPower + (pBeamWeapon.GetProperty().GetRechargeRate() * pBeamWeapon.GetProperty().GetMaxDamage() / 64)
pBeamWeaponSystem.GetProperty().SetNormalPowerPerSecond(fBeamPower)

#Adjust Pulse Weapon Subsystem #1
if (pShip.GetPulseWeaponSystem()):
pPulseWeaponSystem = pShip.GetPulseWeaponSystem()
for iIndex in range(pPulseWeaponSystem.GetNumChildSubsystems()):
if (pPulseWeaponSystem.GetChildSubsystem(iIndex)):
pPulseWeapon = App.PulseWeapon_Cast(pPulseWeaponSystem.GetChildSubsystem(iIndex))
pPulseProperty = pPulseWeapon.GetProperty()
sPulseScript = pPulseProperty.GetModuleName()
try:
pPulseScript = __import__(sPulseScript)
except:
pass
if (pPulseScript):
pPulseProperty.SetMaxDamage(pPulseScript.GetDamage())
pPulseProperty.SetDamageRadiusFactor(pPulseScript.GetDamageRadiusFactor())
pPulseProperty.SetMaxDamageDistance(pPulseScript.GetLaunchSpeed() * pPulseScript.GetLifetime())

#Adjust Pulse Weapon Subsystem #2
fPulsePower = 0
if (pShip.GetPulseWeaponSystem()):
pPulseWeaponSystem = pShip.GetPulseWeaponSystem()
for iIndex in range(pPulseWeaponSystem.GetNumChildSubsystems()):
if (pPulseWeaponSystem.GetChildSubsystem(iIndex)):
pPulseWeapon = App.PulseWeapon_Cast(pPulseWeaponSystem.GetChildSubsystem(iIndex))
fPulsePower = fPulsePower + (pPulseWeapon.GetProperty().GetRechargeRate() * pPulseWeapon.GetProperty().GetMaxDamage() / 64)
pPulseWeaponSystem.GetProperty().SetNormalPowerPerSecond(fPulsePower)

#Adjust Torpedo Weapon Subsystem
fLaunchPower = 0
if (pShip.GetTorpedoSystem()):
pTorpedoSystem = pShip.GetTorpedoSystem()
for iIndex in range(pTorpedoSystem.GetNumChildSubsystems()):
if (pTorpedoSystem.GetChildSubsystem(iIndex)):
pTorpedoTube = App.TorpedoTube_Cast(pTorpedoSystem.GetChildSubsystem(iIndex))
fLaunchPower = fLaunchPower + 10 * pTorpedoTube.GetNumReady()
pTorpedoSystem.GetProperty().SetNormalPowerPerSecond(fLaunchPower)

#Adjust Tractor Beam Subsystem
fTractorPower = 0
if (pShip.GetTractorBeamSystem()):
pTractorSystem = pShip.GetTractorBeamSystem()
for iIndex in range(pTractorSystem.GetNumChildSubsystems()):
if (pTractorSystem.GetChildSubsystem(iIndex)):
pTractorEmitter = App.TractorBeamProjector_Cast(pTractorSystem.GetChildSubsystem(iIndex))
fTractorPower = fTractorPower + (pTractorEmitter.GetProperty().GetMaxDamageDistance() * pTractorEmitter.GetProperty().GetMaxDamage() / 256)
pTractorSystem.GetProperty().SetNormalPowerPerSecond(fTractorPower)

#Adjust Cloaking Subsystem
fCloakPower = 0
if (pShip.GetCloakingSubsystem()):
pCloak = pShip.GetCloakingSubsystem()
fCloakPower = pCloak.GetProperty().GetCloakStrength()
pCloak.GetProperty().SetNormalPowerPerSecond(fCloakPower)

   
#Finally adjust Power Subsystem to sum of above
fPower = fSensorPower + fImpulsePower + fShieldPower + fBeamPower + fPulsePower + fLaunchPower
#print fTractorPower, fCloakPower
pPower = pShip.GetPowerSubsystem().GetProperty()
pPower.SetPowerOutput(fPower * 1.05)
pPower.SetMainBatteryLimit(fTractorPower * 600 + fPower * 60)
pPower.SetMainConduitCapacity(fTractorPower + fPower * 0.25)
pPower.SetBackupBatteryLimit(fCloakPower * 600 + fPower * 60)
pPower.SetBackupConduitCapacity(fCloakPower + fPower * 0.25)

return