DeskSim v2 0.1
Train simulator prototype created for Lokførerskolen
Train.h
1// Copyright 2022 Thomas Arinesalingam, John Ole Bjerke, Endre Heksum & Henrik Markengbakken Karlsen . All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Pawn.h"
7#include "SplineActor.h"
8#include "Wagon.h"
9#include <DeskSimV2/Editor/UI/EditorHUD.h>
10#include <DeskSimV2/SaveGame/IsSaveableInterface.h>
11#include "Camera/CameraComponent.h"
12#include "Engine/StaticMeshSocket.h"
13#include "Train.generated.h"
14
15UCLASS()
16class DESKSIMV2_API ATrain : public APawn, public IIsSaveableInterface
17{
18 GENERATED_BODY()
19
20public:
21 // Sets default values for this pawn's properties
22 ATrain();
23
24protected:
25 // Called when the game starts or when spawned
26 virtual void BeginPlay() override;
27
28
29public:
30 // Called every frame
31 virtual void Tick(float DeltaTime) override;
32
33 // Called to bind functionality to input
34 virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
35
36 bool HasWagonsChanged();
37 void AddOrRemoveWagonActors();
38
42 UFUNCTION(BlueprintPure, Category = "Speed")
43 float GetSpeed();
44
45 // The EditAnywhere macro lets you modify the element where you want to
46
47 UPROPERTY(EditAnywhere, Category = "Speed")
48 float Velocity;
49
50
51 UPROPERTY(EditAnywhere)
52 UStaticMeshComponent* TrainComponent;
53
54 UStaticMeshSocket* TrainSocket;
55
56 UPROPERTY(EditAnywhere)
57 ASplineActor* OurSplineActor;
58
59 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "UCameraComponent")
60 UCameraComponent* OurCamera;
61
62
63 void TrainControl(float DeltaTime);
64 void UpdateTrain(float DeltaTime);
65 void UpdateWagons(float DeltaTime);
66 void UpdateWagonEditor();
67
68 void SwitchToDrone();
69
70 void AccelerateAxis(float AxisValue);
71 void BreakAxis(float AxisValue);
72
73 UFUNCTION()
74 void UpdateText();
75
76 FVector GetPosition();
77 FVector GetRotation();
78
79
80 ASplineActor* GetNearestRailwaySplineComponent();
81
82 void SetPause();
83 void ShowDMI();
84
85 TArray<AWagon*> WagonActors;
86
87 UPROPERTY(EditAnywhere, BlueprintReadOnly)
88 FName ID;
89
90 // Train Speed
91
92 FVector LastPosition;
93 float TimesinceUpdate;
94 float Speed = 0.0f;
95 FTimerHandle TextTimerHandle;
96 // Train Movement
97
98 float Acceleration;
99 float BreakForce;
100
101 // Input acceleration and braking from axis bindings
102
103 float AxisAcceleration;
104 float AxisBreakForce;
105
106 // Default values for the train
107
108 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Train")
109 float AccelerationStrength = 200.0f;
110
111 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Train")
112 float BrakingStrength = 200.0f;
113
114 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Train")
115 float MaxAcceleration = 200.f;
116
117 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Train")
118 float MaxBreakForce = 200.f;
119
120
121 float DistanceAlongSpline;
122
123 // Train emergency stop
124 UPROPERTY(VisibleAnywhere)
125 bool bEmergencyStop = false;
126
127 // Tick check
128 bool bEditorMode;
129
130 int OldWagonCount;
131
132 FVector TotalWagonOffset;
133
134 AEditorHUD* HUD;
135
136};
A component for placing static meshes along a spline.
Definition: EditorHUD.h:91
Definition: SplineActor.h:22
Definition: Train.h:17
Definition: Wagon.h:13
Definition: IsSaveableInterface.h:20