Skip to content

Commit

Permalink
Re-tune wheel slip and static TE calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Dec 19, 2023
1 parent 5d18b3c commit 6e11293
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/main/java/cam72cam/immersiverailroading/entity/Locomotive.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract class Locomotive extends FreightTank {
@TagField("cogging")
private boolean cogging = false;

private boolean slipping = false;
protected boolean slipping = false;

/*
*
Expand Down Expand Up @@ -404,7 +404,7 @@ protected final double getStaticTractiveEffort(Speed speed) {
* 9.8 // M/S/S
* (slipping ? STEEL.kineticFriction(STEEL)/2 : STEEL.staticFriction(STEEL))
* slipCoefficient(speed)
/ getDefinition().factorOfAdhesion()
* (4/getDefinition().factorOfAdhesion()) // Physics are tuned to an adhesion factor of 4
* Config.ConfigBalance.tractionMultiplier;
}

Expand Down Expand Up @@ -611,21 +611,16 @@ public void setBell(int newBell) {
}

public double slipCoefficient(Speed speed) {
double slipMult = 1.0;
double slipMult = 0.5; //TODO Assumes dirty rails. Set this back to 1.0 and adjust physics coefficients
World world = getWorld();
if (world.isPrecipitating() && world.canSeeSky(getBlockPosition())) {
if (world.isRaining(getBlockPosition())) {
slipMult = 0.6;
slipMult *= 0.6;
}
if (world.isSnowing(getBlockPosition())) {
slipMult = 0.4;
slipMult *= 0.4;
}
}
// Wheel balance messing with friction
if (speed.metric() != 0) {
double balance = 1d/(Math.abs(speed.metric())+300) / (1d/300);
slipMult *= balance;
}
return slipMult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public double getAppliedTractiveEffort(Speed speed) {
if (getDefinition().hasDynamicTractionControl) {
double max = getStaticTractiveEffort(speed);
if (Math.abs(applied) > max) {
return Math.copySign(max, applied);
return Math.copySign(max, applied) * 0.95;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,25 @@ public double getTractiveEffortNewtons(Speed speed) {
return (getDefinition().cab_forward ? -1 : 1) * super.getTractiveEffortNewtons(speed);
}

@Override
@Override
public double slipCoefficient(Speed speed) {
double slipMult = super.slipCoefficient(speed);
// Wheel balance messing with friction
if (speed.metric() != 0) {
double balance = 1d/(Math.abs(speed.metric())+300) / (1d/300);
slipMult *= balance;
}

// TODO better approximation
// assume wheel diameter == 5m
double ratio = 0.35;
double hammer = ratio + (slipping ? 0 : Math.abs(Math.sin(Math.toRadians(360 * distanceTraveled / (5f * gauge.scale()/ 2))) * (1-ratio)));
slipMult *= hammer;

return slipMult;
}

@Override
protected double simulateWheelSlip() {
return (getDefinition().cab_forward ? -1 : 1) * super.simulateWheelSlip();
}
Expand Down

0 comments on commit 6e11293

Please sign in to comment.