private void GeneralObservation(ElectricalBarrier master) { if (!_witnessedBreakdown && (master.Vehicle.Damaged || master.Barrier.IsBroken)) { _witnessedBreakdown = true; Bubble.ShowAs(BubbleSprite.Bubble.Say, BubbleSprite.Expression.Attention, 4, true); } }
private void Idle(ElectricalBarrier master) { if (_reactionTimer > 10000) { Bubble.ShowAs(BubbleSprite.Bubble.Think, BubbleSprite.Expression.Sleeping, 2); _reactionTimer = 0; } master.SimulationOutput.SetValue(OpenGateSwitchKey, false); }
private void CheckCollision(ElectricalBarrier master) { PathFollow car = GetNode <PathFollow>("VehiclePath/PathFollow"); float unitOffset = car.UnitOffset; if (unitOffset > PathCheckpointCollisionStart && unitOffset < PathCheckpointCollisionEnd) { if (master.Barrier.BarrierRotation < 10) { BreakDown(); } } }
/// <summary> /// Calculates the next simulation step. /// </summary> public void Update(ElectricalBarrier master, int deltaTime) { PathFollow car = GetNode <PathFollow>("VehiclePath/PathFollow"); if (IsCarDriving(car)) { OnDriving(car, master, deltaTime); } else { OnWait(master, deltaTime); } CheckCollision(master); }
/// <summary> /// Initializes the whole test viewer. Called before the node is added to the tree by the lesson controller. /// </summary> public void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson) { _simulation = GetNode <ElectricalBarrier>("Viewport/ElectricalBarrier"); _simulationMaster = DiagramSimulationLoader.LoadTemp(openedLesson, _simulation); if (_simulationMaster != null) { _simulation.InitialiseWith(mainNode, openedLesson); _isExecutable = _simulationMaster.IsProgramSimulationValid(); } else { _isExecutable = false; Result = 0; GetNode <Label>("Label").Text = "Program can not be executed"; } }
private void ReactToInvalidCar(ElectricalBarrier master) { if (_lastCarNumber != master.Vehicle.TimesPassedTrack && master.Vehicle.IsCarAtCheckpoint) { _lastCarNumber = master.Vehicle.TimesPassedTrack; if (!_witnessedBreakdown) { Bubble.ShowAs(BubbleSprite.Bubble.Say, BubbleSprite.Expression.Nok, 1); } } if (master.Vehicle.IsCarUnderBarrier) { Bubble.ShowAs(BubbleSprite.Bubble.Shout, BubbleSprite.Expression.Exclamation, 2, true); } master.SimulationOutput.SetValue(OpenGateSwitchKey, false); }
/// <summary> /// Calculates the next simulation step. /// </summary> public void Update(ElectricalBarrier master, int deltaTime) { if (IsBroken) { return; } int motor = master.SimulationInput.PollInteger(MotorKey); GetNode <MeshInstance>("BarrierElectricalPole").RotateZ(motor * deltaTime * 0.0004f); float rotation = GetNode <MeshInstance>("BarrierElectricalPole").RotationDegrees.z; master.SimulationOutput.SetValue(SensorOpenedKey, rotation > 60); master.SimulationOutput.SetValue(SensorClosedKey, rotation < 2); if (rotation < -10 || rotation > 133 || master.Vehicle.Damaged) { BreakDown(); } }
/// <summary> /// Calculates the next simulation step. /// </summary> public void Update(ElectricalBarrier master, int deltaTime) { if (master.Vehicle.IsCarAtCheckpoint || master.Vehicle.IsCarUnderBarrier) { if (AllowVehiclePass) { ReactToValidCar(master, deltaTime); } else { ReactToInvalidCar(master); } } else { Idle(master); } GeneralObservation(master); }
private void OnDriving(PathFollow car, ElectricalBarrier master, int deltaTime) { float newOffset = car.UnitOffset + (CarSpeed * deltaTime); if (newOffset < 1) { car.UnitOffset = newOffset; } else { ResetAgent(car); TimesPassedTrack++; } if (car.UnitOffset > EntersTunnel && car.UnitOffset < ExitsTunnel) { if (!master.TunnelLights.AreLightsOn) { Bubble.ShowAs(BubbleSprite.Bubble.Think, BubbleSprite.Expression.Confused, 0.5f); } } }
private void ReactToValidCar(ElectricalBarrier master, int deltaTime) { if (_lastCarNumber != master.Vehicle.TimesPassedTrack) { _lastCarNumber = master.Vehicle.TimesPassedTrack; _reactionTimer = 0; } _reactionTimer += deltaTime; if (_reactionTimer > 6000) { if (!_witnessedBreakdown) { Bubble.ShowAs(BubbleSprite.Bubble.Think, BubbleSprite.Expression.Confused, 2); } _reactionTimer = 0; } if (master.Vehicle.WaitingTime >= 28000) { Bubble.ShowAs(BubbleSprite.Bubble.Think, BubbleSprite.Expression.Annoyed, 2); } master.SimulationOutput.SetValue(OpenGateSwitchKey, true); }
private void OnWait(ElectricalBarrier master, int deltaTime) { if (!master.Guard.AllowVehiclePass) { return; } WaitingTime += deltaTime; if (WaitingTime > 3000 && WaitingTime < 3500) { Bubble.ShowAs(BubbleSprite.Bubble.Think, BubbleSprite.Expression.Confused, 1); } else if (WaitingTime > 6000 && WaitingTime < 6800) { Bubble.ShowAs(BubbleSprite.Bubble.Think, BubbleSprite.Expression.Annoyed, 0.5f); } else if (WaitingTime > 6800 && WaitingTime < 7500) { Bubble.ShowAs(BubbleSprite.Bubble.Say, BubbleSprite.Expression.Confused, 1); } else if (WaitingTime > 15000 && WaitingTime < 15500) { Bubble.ShowAs(BubbleSprite.Bubble.Shout, BubbleSprite.Expression.Surprised, 1); } else if (WaitingTime > 25000 && WaitingTime < 26000) { Bubble.ShowAs(BubbleSprite.Bubble.Shout, BubbleSprite.Expression.Surprised, 1); } else if (WaitingTime > 26000 && WaitingTime < 26500) { Bubble.ShowAs(BubbleSprite.Bubble.Say, BubbleSprite.Expression.Frustrated, 1); } else if (WaitingTime > 26500 && WaitingTime < 27000) { Bubble.ShowAs(BubbleSprite.Bubble.Shout, BubbleSprite.Expression.Exclamation, 3); } }
/// <summary> /// Called when the user can have options to influence the simulation. /// </summary> public void SetupUi(ElectricalBarrier electricalBarrier) { _electricalBarrier = electricalBarrier; Visible = true; GetNode <Button>("BlockEntryButton").Connect("toggled", this, nameof(OnBlockEntryToggled)); }
/// <summary> /// Initializes the controller. /// </summary> public void Initialise() { _simulation = GetNode <ElectricalBarrier>("../ElectricalBarrier"); }