Skip to content

Commit

Permalink
refactor: for locos without an explicit suppression detent, add 'or' …
Browse files Browse the repository at this point in the history
…logic with brake pipe reduction

It isn't always a good idea to require a lever position for suppression, particularly for NJT equipment with lapped brakes. But we can't rely entirely on brake pipe pressure, either, because the simulator can take several seconds to simulate that reduction. Adding an 'or' relationship allows a skilled player to enter suppression quickly and hold the train at 93 psi for softer braking action.
  • Loading branch information
YoRyan committed Jul 24, 2024
1 parent 885fc52 commit a306ae4
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/lib/frp-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ export class FrpEngine extends FrpVehicle {
);
}

/**
* Read suppression state from the brake pipe pressure. Requires a
* well-behaved air brake simulation that cuts out at 110 psi.
*/
createBrakePressureSuppressionBehavior() {
return () => {
const psi = this.rv.GetControlValue("AirBrakePipePressurePSI") as number;
return psi <= 110 - 17;
};
}

/**
* Create a behavior for the speedometer speed.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/lib/shared/multilevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ export function onInit(me: FrpEngine, version: Version) {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5
);
const speedoDigitsMph = me.createSpeedometerDigitsMphBehavior(3);
const equipmentSpeedMps = (version === Version.Marc ? 125 : 100) * c.mph.toMps;
const [aduState$, aduEvents$] = adu.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5
);
const speedoDigitsMph = me.createSpeedometerDigitsMphBehavior(3);
const [aduState$, aduEvents$] = adu.create({
e: me,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5
);
const [aduState$, aduEvents$] = adu.create({
atc: cs.njTransitAtc,
e: me,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
// There's no suppression detent, so we'd ordinarily incorporate brake pipe
// pressure here, but that isn't a reliable indicator due to the cut out
// being 90 psi.
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5;
const speedoDigitsMph = me.createSpeedometerDigitsMphBehavior(3);
const [aduState$, aduEvents$] = adu.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5
);
const [aduState$, aduEvents$] = adu.create({
e: me,
acknowledge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5
);
const speedoDigitsMph = me.createSpeedometerDigitsMphBehavior(3);
const [aduState$, aduEvents$] = adu.create({
e: me,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5
);
const [aduState$, aduEvents$] = adu.create({
atc: cs.njTransitAtc,
e: me,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) > 0.5
);
const speedoDigitsMph = me.createSpeedometerDigitsMphBehavior(3);
const [aduState$, aduEvents$] = adu.create({
e: me,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("VirtualBrake") as number) >= 0.5
);
const [aduState$, aduEvents$] = adu.create({
atc: cs.amtrakAtc,
e: me,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ const me = new FrpEngine(() => {

// Safety systems and ADU
const acknowledge = me.createAcknowledgeBehavior();
const suppression = () => (me.rv.GetControlValue("TrainBrakeControl") as number) >= 0.4;
const suppression = frp.liftN(
(bp, lever) => bp || lever,
me.createBrakePressureSuppressionBehavior(),
() => (me.rv.GetControlValue("TrainBrakeControl") as number) >= 0.4
);
const [aduState$, aduEvents$] = adu.create({
atc: cs.metroNorthAtc,
e: me,
Expand Down

0 comments on commit a306ae4

Please sign in to comment.