diff --git a/config.yml b/config.yml index 1406cfe3..18992c7e 100644 --- a/config.yml +++ b/config.yml @@ -2621,9 +2621,9 @@ nether_factory: repair_multiple: 1 fuel_time: 10 repair_time: 12 - scaling_radius: 5000 - cost_scaling_radius: 5000 use_fuel_on_teleport: false + cost_scaling: 0.25 + cost_epsilon: 0.05 production_recipes: Wood_XP_Bottle_0: name: Brew XP Bottles - 1 diff --git a/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java b/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java index 0e46791a..86f66f7f 100644 --- a/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java +++ b/src/com/github/igotyou/FactoryMod/managers/NetherFactoryManager.java @@ -379,8 +379,21 @@ public String getSavesFileName() public double getScalingFactor(Location location) { - double scalingFactor = 1; + NetherFactoryProperties properties = plugin.getNetherFactoryProperties(); + // scale distance to kilometers + double newFacX = location.getBlockX()/1000; + double newFacZ = location.getBlockZ()/1000; + + // Summation variable + double totalInverseDist = 0.0D; + + // Scaling factor for the curve - 0.25 value configured to not modify default cost if ~5,000 blocks from all factories + double scalingFactor = properties.getCostScaling(); + + // Accuracy of the cost multiplier before defaulting it to 1.0 + double epsilon = properties.getCostEpsilon(); + for (NetherFactory factory : netherFactorys) { Location factoryLoc = factory.getCenterLocation(); @@ -388,20 +401,19 @@ public double getScalingFactor(Location location) { continue; } - //the distance function uses square root, which is quite expensive, let's check if it's even realistic that it's within range first. - if ((location.getBlockX()-factoryLoc.getBlockX()) < properties.getScalingRadius() || (location.getBlockX()-factoryLoc.getBlockX()) > -(properties.getScalingRadius())) - { - if ((location.getBlockZ()-factoryLoc.getBlockZ()) < properties.getScalingRadius() || (location.getBlockZ()-factoryLoc.getBlockZ()) > -(properties.getScalingRadius())) - { - double distance = location.distance(factoryLoc); - if (distance <= properties.getScalingRadius()) - { - scalingFactor = scalingFactor * Math.exp(1/(distance/properties.getCostScalingRadius())); - } - } - } + double delX = newFacX - factoryLoc.getBlockX()/1000; + double delZ = newFacZ - factoryLoc.getBlockZ()/1000; + + totalInverseDist += 1.0D/(Math.sqrt(Math.pow(delX, 2) + Math.pow(delZ, 2))); } - return scalingFactor; + double multiplier = Math.pow(Math.exp(totalInverseDist), scalingFactor); + + // multiplier guaranteed >= 1 + if (multiplier - 1 < epsilon) { + multiplier = 1.0D; + } + + return multiplier; } } diff --git a/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java b/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java index 7591f2cf..058204ff 100644 --- a/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java +++ b/src/com/github/igotyou/FactoryMod/properties/NetherFactoryProperties.java @@ -18,13 +18,12 @@ public class NetherFactoryProperties private String name; private int repair; private double repairTime; - private int scalingMode; - private int scalingRadius; - private int costScalingRadius; + private double costScaling; + private double costEpsilon; private boolean useFuelOnTeleport; public NetherFactoryProperties(ItemList constructionMaterials, ItemList fuel, ItemList repairMaterials, - int energyTime, String name,int repair, double repairTime, int scalingRadius, boolean useFuelOnTeleport, int costScalingRadius) + int energyTime, String name,int repair, double repairTime, double costScaling, boolean useFuelOnTeleport, double costEpsilon) { this.constructionMaterials = constructionMaterials; this.fuel = fuel; @@ -33,8 +32,8 @@ public NetherFactoryProperties(ItemList constructionMaterials, I this.name = name; this.repair=repair; this.repairTime=repairTime; - this.scalingRadius = scalingRadius; - this.costScalingRadius = costScalingRadius; + this.costScaling = costScaling; + this.costEpsilon = costEpsilon; this.useFuelOnTeleport = useFuelOnTeleport; } @@ -43,14 +42,14 @@ public int getRepair() return repair; } - public int getScalingRadius() + public double getCostEpsilon() { - return scalingRadius; + return costEpsilon; } - public int getCostScalingRadius() + public double getCostScaling() { - return costScalingRadius; + return costScaling; } //0 == no scaling, 1==linear scaling, 2==exponential scaling @@ -99,10 +98,10 @@ public static NetherFactoryProperties fromConfig(FactoryModPlugin plugin, Config int nfRepair = costs.getInt("repair_multiple",1); String nfName = configNetherFactory.getString("name", "Nether Factory"); int repairTime = configNetherFactory.getInt("repair_time",12); - int nfScalingRadius = configNetherFactory.getInt("scaling_radius", 5000); - int costScalingRadius = configNetherFactory.getInt("scaling_radius", 5000); boolean nfUseFuelOnTeleport = configNetherFactory.getBoolean("use_fuel_on_teleport", false); - return new NetherFactoryProperties(nfConstructionCost, nfFuel, nfRepairCost, nfEnergyTime, nfName, nfRepair, repairTime, nfScalingRadius,nfUseFuelOnTeleport, costScalingRadius); + double nfCostScaling = configNetherFactory.getDouble("cost_scaling", 0.25D); + double nfCostEpsilon = configNetherFactory.getDouble("cost_epsilon", 0.05D); + return new NetherFactoryProperties(nfConstructionCost, nfFuel, nfRepairCost, nfEnergyTime, nfName, nfRepair, repairTime, nfCostScaling,nfUseFuelOnTeleport, nfCostEpsilon); }