From d947f23696d71040b941eb0c15548346ff39baff Mon Sep 17 00:00:00 2001 From: WayofTime Date: Thu, 18 Feb 2016 09:03:18 -0500 Subject: [PATCH] Attempted to improve the crucible's logic. --- .settings/org.eclipse.jdt.core.prefs | 6 +- .../bloodmagic/tile/TileDemonCrucible.java | 74 +++++++++++++------ 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 7135a263..29c63ff9 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ # -#Tue Feb 09 07:17:21 EST 2016 +#Thu Feb 18 08:35:51 EST 2016 org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert org.eclipse.jdt.core.formatter.brace_position_for_block=next_line org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert @@ -288,10 +288,10 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -eclipse.preferences.version=1 org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=next_line -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +eclipse.preferences.version=1 org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java b/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java index 2a09d74f..4670d47f 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileDemonCrucible.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.tile; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -26,7 +27,7 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo public HashMap willMap = new HashMap(); public final int maxWill = 100; public final double maxTransferPerTick = 1; - public final double thresholdFill = 0.01; + public final double thresholdFill = 0.0; public final double gemDrainRate = 10; public int internalCounter = 0; @@ -120,6 +121,7 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo double maxWeight = 0; List tileList = new ArrayList(); + Collections.shuffle(tileList); Iterator iterator = conduitList.iterator(); while (iterator.hasNext()) @@ -140,38 +142,64 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo { for (EnumDemonWillType type : EnumDemonWillType.values()) { + List copyTileList = new ArrayList(); + copyTileList.addAll(tileList); + double currentAmount = this.getCurrentWill(type); if (currentAmount <= 0) { continue; } - for (IDemonWillConduit conduit : tileList) + double transfered = 0; + double newMaxWeight = 0; + double transferTotalLastRound = 0; + + int pass = 0; + final int maxPasses = 2; + while (pass < maxPasses && transfered < maxTransferPerTick && maxWeight > 0) { - if (!conduit.canFill(type)) + pass++; + newMaxWeight = 0; + Iterator conduitIterator = copyTileList.iterator(); + + while (conduitIterator.hasNext()) { - continue; + IDemonWillConduit conduit = conduitIterator.next(); + + if (!conduit.canFill(type)) + { + conduitIterator.remove(); + continue; + } + + newMaxWeight += conduit.getWeight(); + double transfer = Math.min(currentAmount, conduit.getWeight() * (maxTransferPerTick - transferTotalLastRound) / maxWeight); + if (transfer <= 0) + { + conduitIterator.remove(); + continue; + } + + double conduitAmount = conduit.getCurrentWill(type); + + if (currentAmount - conduitAmount <= thresholdFill) // Will only fill if this conduit's amount is greater than the conduit it is filling. + { + conduitIterator.remove(); + continue; + } + + transfer = conduit.fillDemonWill(type, transfer, false); + if (transfer > 0) + { + conduit.fillDemonWill(type, transfer, true); + currentAmount -= transfer; + transfered += transfer; + } } - double transfer = Math.min(currentAmount, conduit.getWeight() * maxTransferPerTick / maxWeight); - if (transfer <= 0) - { - break; - } - - double conduitAmount = conduit.getCurrentWill(type); - - if (currentAmount - conduitAmount <= thresholdFill) // Will only fill if this conduit's amount is greater than the conduit it is filling. - { - continue; - } - - transfer = conduit.fillDemonWill(type, transfer, false); - if (transfer > 0) - { - conduit.fillDemonWill(type, transfer, true); - currentAmount -= transfer; - } + maxWeight = newMaxWeight; + transferTotalLastRound = transfered; } if (currentAmount <= 0)