Author Topic: Imitating BCs shield recharge when gen offline?  (Read 3966 times)

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: Imitating BCs shield recharge when gen offline?
« Reply #20 on: July 19, 2012, 09:24:17 AM »
Whats wrong with GetPowerPercentageWanted()?

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: Imitating BCs shield recharge when gen offline?
« Reply #21 on: July 19, 2012, 10:58:09 AM »
Whats wrong with GetPowerPercentageWanted()?
:angel

PERFECT! It works! Muhahahahahahaaa. I was so obsessed with the shield class in App.py that I just plain didn't see GetPowerPercentageWanted().

Code: [Select]
# imitates what Bridge Commander does when shields are powered to 0%
# increases stored shield values for generators on ships that aren't currently being used
def UpdateStoredGenHealth(pObject, pEvent):
if nonActiveGens and shipShieldVals:
#print "UpdateStoredGenHealth() ---------"
# for each ship in dictionary
for shipID in nonActiveGens.keys():
# get the ship, use the ship to get fake generator names, use names to get correct fake generator
ship = App.ShipClass_GetObjectByID(App.SetClass_GetNull(), shipID)
ship = App.ShipClass_Cast(ship)
genNames = GetPrimarySecondaryGenNames(ship)
currGenerator = MissionLib.GetSubsystemByName(ship, genNames[0])
generator = 0
if not currGenerator.GetObjID() == nonActiveGens[shipID]:
currGenerator = MissionLib.GetSubsystemByName(ship, genNames[1])
generator = 1
# for all stored shield values of that generator
noChangeMade = 1
currGenerator = App.ShieldClass_Cast(currGenerator)
for shield in range(0, 6):
# set shield strength equal to current + perSecond amount, but don't allow it to go over maximum charge
charge = 0
if currGenerator.GetShieldChargePerSecond(shield) > 0:
charge = currGenerator.GetShieldChargePerSecond(shield) / 100 * ship.GetShields().GetPowerPercentageWanted() * 100
result = shipShieldVals[shipID][generator][shield] + charge
max = currGenerator.GetMaxShields(shield)
if shipShieldVals[shipID][generator][shield] == max:
continue
elif max > result:
shipShieldVals[shipID][generator][shield] = result
noChangeMade = 0
else:
shipShieldVals[shipID][generator][shield] = max
noChangeMade = 0
if noChangeMade:
# if no change was made then values are all at full strength, remove it
del nonActiveGens[shipID]
# call again and again
MissionLib.CreateTimer(Lib.LibEngineering.GetEngineeringNextEventType(), __name__ + ".UpdateStoredGenHealth", App.g_kUtopiaModule.GetGameTime() + 1, 0, 0)

Enjoy your cookie.
Great men are not peacemakers! Great men are conquerors!