Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sword's New scaling math(magic scaling) #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,29 +379,41 @@ 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();
if(factory.getCenterLocation().equals(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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NamedItemStack> constructionMaterials, ItemList<NamedItemStack> fuel, ItemList<NamedItemStack> 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;
Expand All @@ -33,8 +32,8 @@ public NetherFactoryProperties(ItemList<NamedItemStack> 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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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);

}

Expand Down