Skip to content

Commit 82ef671

Browse files
committed
Implemented ability to split drone stacks by ship's available bandwidth
1 parent 52063be commit 82ef671

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

gui/builtinContextMenus/droneSplitStack.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,50 @@ def activate(self, callingWindow, fullContext, mainItem, i):
3737
fitID = self.mainFrame.getActiveFit()
3838
fit = Fit.getInstance().getFit(fitID)
3939
cleanInput = re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip())
40-
4140
if mainItem in fit.drones:
4241
position = fit.drones.index(mainItem)
4342
self.mainFrame.command.Submit(cmd.GuiSplitLocalDroneStackCommand(
4443
fitID=fitID, position=position, amount=int(cleanInput)))
4544

4645

46+
class DroneSplitStackBandwidth(DroneSplitStack):
47+
"""
48+
Split drone stack to match ship's available bandwidth, ensuring that only
49+
one of the stacks is active so as not to exceed the bandwidth limit.
50+
"""
51+
def getText(self, callingWindow, itmContext, mainItem):
52+
return "Split {} Stack to Fit Max Bandwidth".format(itmContext)
53+
54+
def activate(self, callingWindow, fullContext, mainItem, i):
55+
fitID = self.mainFrame.getActiveFit()
56+
fit = Fit.getInstance().getFit(fitID)
57+
bandwidth_per_drone = fit.drones[0].item. \
58+
attributes['droneBandwidthUsed'].value
59+
ship_bandwidth = fit.ship.item.attributes['droneBandwidth'].value
60+
max_active_drones = int(ship_bandwidth/bandwidth_per_drone)
61+
if max_active_drones == 0:
62+
wx.MessageDialog(
63+
None, "Cannot split drone stack to fit bandwidth. Each drone "
64+
"uses {0} mbit/s and this ship only has {1} mbit/s."
65+
.format(int(bandwidth_per_drone), int(ship_bandwidth)),
66+
"Ship drone bandwidth exceeded", wx.OK | wx.ICON_ERROR
67+
).ShowModal()
68+
else:
69+
if max_active_drones > 5:
70+
max_active_drones = 5
71+
72+
if mainItem in fit.drones:
73+
position = fit.drones.index(mainItem)
74+
self.mainFrame.command.Submit(
75+
cmd.GuiSplitLocalDroneStackCommand(fitID=fitID,
76+
position=position,
77+
amount=max_active_drones,
78+
deactivate=True)
79+
)
80+
81+
4782
DroneSplitStack.register()
83+
DroneSplitStackBandwidth.register()
4884

4985

5086
class DroneStackSplit(wx.Dialog):

gui/fitCommands/calc/drone/localRemove.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
class CalcRemoveLocalDroneCommand(wx.Command):
1212

13-
def __init__(self, fitID, position, amount):
13+
def __init__(self, fitID, position, amount, deactivate=False):
1414
wx.Command.__init__(self, True, 'Remove Local Drone')
1515
self.fitID = fitID
1616
self.position = position
1717
self.amountToRemove = amount
1818
self.savedDroneInfo = None
1919
self.removedStack = None
20+
self.deactivate = deactivate
2021

2122
def Do(self):
2223
pyfalog.debug('Doing removal of {} local drones at position {} from fit {}'.format(self.amountToRemove, self.position, self.fitID))
@@ -26,7 +27,10 @@ def Do(self):
2627

2728
drone.amount = max(drone.amount - self.amountToRemove, 0)
2829
if drone.amountActive > 0:
29-
drone.amountActive = min(drone.amountActive, drone.amount)
30+
if self.deactivate:
31+
drone.amountActive = 0
32+
else:
33+
drone.amountActive = min(drone.amountActive, drone.amount)
3034

3135
if drone.amount == 0:
3236
fit.drones.remove(drone)

gui/fitCommands/gui/localDrone/stackSplit.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111

1212
class GuiSplitLocalDroneStackCommand(wx.Command):
1313

14-
def __init__(self, fitID, position, amount):
14+
def __init__(self, fitID, position, amount, deactivate=False):
15+
"""
16+
Deactivate argument is only True when splitting drone stacks to match
17+
ship's available bandwidth.
18+
"""
1519
wx.Command.__init__(self, True, 'Split Local Drone Stack')
1620
self.internalHistory = InternalCommandHistory()
1721
self.fitID = fitID
1822
self.position = position
1923
self.amount = amount
24+
self.deactivate = deactivate
2025

2126
def Do(self):
2227
sFit = Fit.getInstance()
@@ -31,7 +36,8 @@ def Do(self):
3136
commands.append(CalcRemoveLocalDroneCommand(
3237
fitID=self.fitID,
3338
position=self.position,
34-
amount=self.amount))
39+
amount=self.amount,
40+
deactivate=self.deactivate))
3541
commands.append(CalcAddLocalDroneCommand(
3642
fitID=self.fitID,
3743
droneInfo=info,

0 commit comments

Comments
 (0)