Rise
The Vieneo Province
Loading...
Searching...
No Matches
VehicleWear.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4
5namespace VehicleWear
6{
7 // Initial gameplay tuning: linear wear up to these service-life references.
8 // The existing ground odometer accumulates kilometers; aircraft usage is hours.
9 constexpr float GroundUsageAtFullWearKm = 200000.0f;
10 constexpr float FlightUsageAtFullWearHours = 10000.0f;
11 constexpr float MaximumThrustLoss = 0.20f;
12 constexpr float MaximumDragIncrease = 0.20f;
13 constexpr float MaximumFuelFlowIncrease = 0.20f;
14 constexpr float MaximumControlPlay = 0.10f;
15
16 struct Factors
17 {
18 float thrust;
19 float drag;
20 float fuelFlow;
22 };
23
24 inline Factors Calculate(float usage, bool groundVehicle)
25 {
26 // Invalid/missing usage must not introduce NaNs or improve performance.
27 if (!std::isfinite(usage) || usage < 0.0f)
28 usage = 0.0f;
29 const float serviceLife = groundVehicle ? GroundUsageAtFullWearKm : FlightUsageAtFullWearHours;
30 const float wear = usage >= serviceLife ? 1.0f : usage / serviceLife;
31 return { 1.0f - MaximumThrustLoss * wear, 1.0f + MaximumDragIncrease * wear,
32 1.0f + MaximumFuelFlowIncrease * wear, groundVehicle ? 0.0f : MaximumControlPlay * wear };
33 }
34
35 // Mechanical play is applied to the final flight command, independently of
36 // device dead zones. Rescale the remaining travel so full authority is retained.
37 inline float ApplyControlPlay(float input, float play)
38 {
39 if (play <= 0.0f)
40 return input;
41 const float magnitude = std::fabs(input);
42 if (magnitude <= play)
43 return 0.0f;
44 const float output = magnitude >= 1.0f ? 1.0f : (magnitude - play) / (1.0f - play);
45 return std::copysign(output, input);
46 }
47
48 // Restore a command from a saved surface position without applying play twice.
49 inline float RestoreControlInput(float output, float play)
50 {
51 if (play <= 0.0f || output == 0.0f)
52 return output;
53 return std::copysign(play + std::fabs(output) * (1.0f - play), output);
54 }
55}
float ApplyControlPlay(float input, float play)
Definition VehicleWear.h:37
constexpr float MaximumThrustLoss
Definition VehicleWear.h:11
Factors Calculate(float usage, bool groundVehicle)
Definition VehicleWear.h:24
constexpr float MaximumControlPlay
Definition VehicleWear.h:14
float RestoreControlInput(float output, float play)
Definition VehicleWear.h:49
constexpr float FlightUsageAtFullWearHours
Definition VehicleWear.h:10
constexpr float MaximumFuelFlowIncrease
Definition VehicleWear.h:13
constexpr float MaximumDragIncrease
Definition VehicleWear.h:12
constexpr float GroundUsageAtFullWearKm
Definition VehicleWear.h:9