Reset the simulator state
(self)
| 74 | self.modules = modules |
| 75 | |
| 76 | def reset(self): |
| 77 | """Reset the simulator state""" |
| 78 | self.state = [] |
| 79 | self.saved_changes_internal = {} |
| 80 | self.result_optimized_repeats = False |
| 81 | mods = {} |
| 82 | period = 1 |
| 83 | disable_period = False |
| 84 | |
| 85 | # Loop over modules, clearing clipSize if applicable, and group modules based on attributes |
| 86 | for (duration, capNeed, clipSize, disableStagger, reloadTime, isInjector) in self.modules: |
| 87 | if self.scale: |
| 88 | duration, capNeed = self.scale_activation(duration, capNeed) |
| 89 | |
| 90 | # set clipSize to infinite if reloads are disabled unless it's |
| 91 | # a cap booster module |
| 92 | if not self.reload and not isInjector: |
| 93 | clipSize = 0 |
| 94 | reloadTime = 0 |
| 95 | |
| 96 | # Group modules based on their properties |
| 97 | key = (duration, capNeed, clipSize, disableStagger, reloadTime, isInjector) |
| 98 | if key in mods: |
| 99 | mods[key] += 1 |
| 100 | else: |
| 101 | mods[key] = 1 |
| 102 | |
| 103 | # Loop over grouped modules, configure staggering and push to the simulation state |
| 104 | for (duration, capNeed, clipSize, disableStagger, reloadTime, isInjector), amount in mods.items(): |
| 105 | # period optimization doesn't work when reloads are active. |
| 106 | if clipSize: |
| 107 | disable_period = True |
| 108 | # Just push multiple instances if item is injector. We do not want to stagger them as we will |
| 109 | # use them as needed and want them to be available right away |
| 110 | if isInjector: |
| 111 | for i in range(amount): |
| 112 | heapq.heappush(self.state, [0, duration, capNeed, 0, clipSize, reloadTime, isInjector]) |
| 113 | continue |
| 114 | if self.stagger and not disableStagger: |
| 115 | # Stagger all mods if they do not need to be reloaded |
| 116 | if clipSize == 0: |
| 117 | duration = int(duration / amount) |
| 118 | # Stagger mods after first |
| 119 | else: |
| 120 | stagger_amount = (duration * clipSize + reloadTime) / (amount * clipSize) |
| 121 | for i in range(1, amount): |
| 122 | heapq.heappush(self.state, [i * stagger_amount, duration, capNeed, 0, clipSize, reloadTime, isInjector]) |
| 123 | # If mods are not staggered - just multiply cap use |
| 124 | else: |
| 125 | capNeed *= amount |
| 126 | |
| 127 | period = lcm(period, duration) |
| 128 | |
| 129 | heapq.heappush(self.state, [0, duration, capNeed, 0, clipSize, reloadTime, isInjector]) |
| 130 | |
| 131 | if disable_period: |
| 132 | self.period = self.t_max |
| 133 | else: |
no test coverage detected