Agrarsense
Vehicle.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "GameFramework/Pawn.h"
10#include "Engine/World.h"
11
18
19#include "Vehicle.generated.h"
20
21class UNiagaraComponent;
22class USensorsManagerComponent;
24class ATranformSensor;
25class AOverlapSensor;
26
31DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVehicleGarageChangedDelegate, bool, IsVehicleInGarage);
32
33/*
34* Base class for all vehicles
35*/
36UCLASS()
37class AGRARSENSE_API AVehicle : public APawn, public IInteractable, public IDestroyable, public IActorInformation
38{
39 GENERATED_BODY()
40
41public:
42
43 AVehicle();
44
49 UFUNCTION(BlueprintCallable)
50 virtual EVehicleTypes GetVehicleType() const
51 {
53 }
54
58 UFUNCTION(BlueprintPure)
59 virtual FString GetTopicName()
60 {
61 return FString(TEXT("Undefined"));
62 }
63
68 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
69 void TogglePhysics(bool isOn);
70
71
77 UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
78 void TeleportVehicleTo(FVector NewLocation, FRotator NewRotation);
79
85 virtual void TeleportVehicleTo_Implementation(FVector NewLocation, FRotator NewRotation);
86
90 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
91 void ResetCamera();
92
97 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
98 void ToggleLights(bool isOn);
99
104 UFUNCTION(BlueprintCallable)
105 void SetVisualizeVehicleOverlapArea(bool Visible);
106
112 UFUNCTION(BlueprintCallable)
113 FString ExportToJsonFile(const FString& FileName);
114
119 UFUNCTION(BlueprintCallable)
120 void SetVehicleIsInGarage(bool VehicleIsInGarage)
121 {
122 VehicleInGarage = VehicleIsInGarage;
123 OnVehicleGarageChanged.Broadcast(VehicleInGarage);
124 }
125
130 UFUNCTION(BlueprintPure)
131 bool IsVehicleInGarage() const
132 {
133 return VehicleInGarage;
134 }
135
140 UFUNCTION(BlueprintCallable)
141 USensorsManagerComponent* GetSensorsManager() const
142 {
143 return SensorsManager;
144 }
145
150 UFUNCTION(BlueprintPure)
151 ACollisionSensor* GetCollisionSensor() const
152 {
153 return CollisionSensor;
154 }
155
160 UFUNCTION(BlueprintPure)
161 ATransformSensor* GetTransformSensor() const
162 {
163 return TransformSensor;
164 }
165
170 UFUNCTION(BlueprintPure)
171 AOverlapSensor* GetOverlapSensor() const
172 {
173 return OverlapSensor;
174 }
175
176
181 UFUNCTION(BlueprintPure)
182 FTransform GetMovedFromGarageTransform() const
183 {
184 return MovedFromGarageTransform;
185 }
186
187 UFUNCTION(BlueprintCallable)
188 void SetCurrentTransformToMovedFromGarageTransform()
189 {
190 MovedFromGarageTransform = GetTransform();
191 }
192
193 virtual FText GetInteractableName_Implementation() const override
194 {
195 return InteractableName;
196 }
197
198 virtual FTransform GetInteractableWorldTransform_Implementation() const override
199 {
200 return GetActorTransform();
201 }
202
203 virtual FString GetActorID_Implementation() const override
204 {
205 return ActorID;
206 }
207
208 virtual FString GetActorName_Implementation() const override
209 {
210 return ActorName;
211 }
212
213 virtual FString GetActorInformation_Implementation() const override
214 {
215 const FString Vehicle = UEnumUtilities::ConvertVehicleTypeToString(GetVehicleType());
216 const FString ID = GetActorID_Implementation();
217 const FString Name = GetActorName_Implementation();
218 const FTransform VehicleTransform = GetActorTransform();
219 const FVector Location = VehicleTransform.GetLocation();
220 const FRotator Rotation = VehicleTransform.Rotator();
221 FString Information = FString::Printf(TEXT("Vehicle: %s, Name: %s, ID: %s, Location: %s, Rotation: %s"), *Vehicle, *Name, *ID, *Location.ToString(), *Rotation.ToString());
222
223 return Information;
224 }
225
226 virtual void SetActorName_Implementation(const FString& NewActorName) override
227 {
228 ActorName = NewActorName;
229 }
230
231 virtual void SetActorIDAndName_Implementation(const FString& NewActorName, const FString& NewID) override
232 {
233 ActorName = NewActorName;
234 ActorID = NewID;
235 SetAndValidateActorIDAndName(ActorName, ActorID, TWeakObjectPtr<AActor>(this));
236 }
237
238 virtual void PossessedBy(AController* NewController) override;
239
240 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interactable")
241 FText InteractableName;
242
243 UPROPERTY(BlueprintAssignable)
244 FVehicleGarageChangedDelegate OnVehicleGarageChanged;
245
246
247protected:
248
249 virtual void BeginPlay() override;
250
251 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
252
253 /*
254 * Manages sensors attached to this vehicle
255 */
256 UPROPERTY(Category = Vehicle, VisibleAnywhere, BlueprintReadOnly)
257 TObjectPtr<USensorsManagerComponent> SensorsManager;
258
259 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
260 ACollisionSensor* CollisionSensor = nullptr;
261
262 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
263 ATransformSensor* TransformSensor = nullptr;
264
265 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
266 AOverlapSensor* OverlapSensor = nullptr;
267
268 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
269 UNiagaraComponent* NiagaraComponent = nullptr;
270
271 UPROPERTY(VisibleAnywhere)
272 FString ActorName;
273
274 UPROPERTY(VisibleAnywhere)
275 FString ActorID;
276
277 UPROPERTY(EditAnywhere, BlueprintReadWrite)
278 FTransform OriginalCameraTransform;
279
280private:
281
282 bool VehicleInGarage = false;
283
284 FTransform MovedFromGarageTransform;
285};
EVehicleTypes
Definition: VehicleTypes.h:15
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVehicleGarageChangedDelegate, bool, IsVehicleInGarage)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void BeginPlay() override
AVehicle * Vehicle
FString ExportToJsonFile(const FString &FileName)
Definition: Sensor.cpp:113
virtual FString GetActorID_Implementation() const override
Definition: Sensor.h:207
virtual FString GetTopicName()
Definition: Sensor.h:124
virtual FString GetActorName_Implementation() const override
Definition: Sensor.h:212
virtual FText GetInteractableName_Implementation() const override
Definition: Vehicle.h:193
virtual FString GetActorID_Implementation() const override
Definition: Vehicle.h:203
virtual void SetActorIDAndName_Implementation(const FString &NewActorName, const FString &NewID) override
Definition: Vehicle.h:231
virtual FString GetActorInformation_Implementation() const override
Definition: Vehicle.h:213
virtual FString GetActorName_Implementation() const override
Definition: Vehicle.h:208
virtual FTransform GetInteractableWorldTransform_Implementation() const override
Definition: Vehicle.h:198
virtual void SetActorName_Implementation(const FString &NewActorName) override
Definition: Vehicle.h:226
static void SetAndValidateActorIDAndName(FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)
static FString ConvertVehicleTypeToString(EVehicleTypes VehicleType)