Skip to content

Commit

Permalink
Merge pull request #1 from Glease/patch-1
Browse files Browse the repository at this point in the history
Fix overflow for larger coolant cell
  • Loading branch information
Prometheus0000 authored Nov 18, 2020
2 parents 46ef537 + e79d7a8 commit 967aba9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/Ic2ExpReactorPlanner/Reactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class Reactor {

// maximum paramatter types for a reactor component (current initial heat, automation threshold, reactor pause
private static final int MAX_PARAM_TYPES = 3;

public static final int MAX_COMPONENT_HEAT = 1_080_000;

public ReactorItem getComponentAt(final int row, final int column) {
if (row >= 0 && row < grid.length && column >= 0 && column < grid[row].length) {
Expand Down Expand Up @@ -498,6 +500,11 @@ private void readCodeString(final String code) {
BigintStorage storage = BigintStorage.inputBase64(code);
// read the code revision from the code itself instead of making it part of the prefix.
int codeRevision = storage.extract(255);
int maxComponentHeat;
if (codeRevision == 3)
maxComponentHeat = (int)1080e3;
else
maxComponentHeat = (int)360e3;
// Check if the code revision is supported yet.
if (codeRevision > 3) {
throw new IllegalArgumentException("Unsupported code revision in reactor code.");
Expand All @@ -523,9 +530,9 @@ private void readCodeString(final String code) {
ReactorItem component = ComponentFactory.createComponent(componentId);
int hasSpecialAutomationConfig = storage.extract(1);
if (hasSpecialAutomationConfig > 0) {
component.setInitialHeat(storage.extract((int)360e3));
component.setInitialHeat(storage.extract(maxComponentHeat));
if (codeRevision == 0 || (codeRevision >= 1 && automated)) {
component.setAutomationThreshold(storage.extract((int)360e3));
component.setAutomationThreshold(storage.extract(maxComponentHeat));
component.setReactorPause(storage.extract((int)10e3));
}
}
Expand Down Expand Up @@ -576,9 +583,9 @@ private String buildCodeString() {
if (component.getInitialHeat() > 0 || component.getAutomationThreshold() != ComponentFactory.getDefaultComponent(id).getAutomationThreshold() || component.getReactorPause() != ComponentFactory.getDefaultComponent(id).getReactorPause()) {
if (automated) {
storage.store(component.getReactorPause(), (int)10e3);
storage.store(component.getAutomationThreshold(), (int)360e3);
storage.store(component.getAutomationThreshold(), (int)1080e3);
}
storage.store((int)component.getInitialHeat(), (int)360e3);
storage.store((int)component.getInitialHeat(), (int)1080e3);
storage.store(1, 1);
} else {
storage.store(0, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/Ic2ExpReactorPlanner/ReactorPlannerFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ public void componentResized(java.awt.event.ComponentEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
temperatureAndComponentsPanel.add(componentHeatLabel, gridBagConstraints);

componentHeatSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 360000, 1));
componentHeatSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, Reactor.MAX_COMPONENT_HEAT, 1));
componentHeatSpinner.setMinimumSize(new java.awt.Dimension(70, 20));
componentHeatSpinner.setPreferredSize(new java.awt.Dimension(70, 20));
componentHeatSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
Expand All @@ -1140,7 +1140,7 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
temperatureAndComponentsPanel.add(placingThresholdLabel, gridBagConstraints);

placingThresholdSpinner.setModel(new javax.swing.SpinnerNumberModel(9000, 0, 360000, 1));
placingThresholdSpinner.setModel(new javax.swing.SpinnerNumberModel(9000, 0, Reactor.MAX_COMPONENT_HEAT, 1));
placingThresholdSpinner.setMinimumSize(new java.awt.Dimension(100, 20));
placingThresholdSpinner.setPreferredSize(new java.awt.Dimension(100, 20));
placingThresholdSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
Expand Down Expand Up @@ -1409,7 +1409,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
automationPanel.add(jLabel12, gridBagConstraints);

thresholdSpinner.setModel(new javax.swing.SpinnerNumberModel(9000, 0, 360000, 1));
thresholdSpinner.setModel(new javax.swing.SpinnerNumberModel(9000, 0, Reactor.MAX_COMPONENT_HEAT, 1));
thresholdSpinner.setMinimumSize(new java.awt.Dimension(100, 20));
thresholdSpinner.setPreferredSize(new java.awt.Dimension(100, 20));
thresholdSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
Expand Down

0 comments on commit 967aba9

Please sign in to comment.