Rise
The Vieneo Province
Loading...
Searching...
No Matches
MarkerBeacons.cpp
Go to the documentation of this file.
1#include "Module.h"
2#include "../MathUtilities.h"
3
4void MarkerBeacons::FrameMove(float fElapsed)
5{
6 if (!sound)
7 return;
8
10 float volume = 0.0f, distance = 9999.0f;
11
12 if (!playerships[0].groundvehicle && ourcockpit.power > 0.5f && playerships[0].reference == REF_APNMODE)
13 {
14 for (UINT i = 1; i < bus->waypoint.size(); i++)
15 {
16 const Swaypoint waypoint = bus->waypoint.at(i);
17
18 if (waypoint.type != 1 && waypoint.type != 2 && waypoint.type != 4) // FAF, threshold, or MM
19 continue;
20
21 if (waypoint.ils == -1)
22 continue;
23
24 // @todo waypoint.distance should be calculated once ... and then reused
25 RiseMath::Vector3 result = waypoint.location - playerships[0].position;
26 distance = RiseMath::Vec3Length(&result);
27
28 // The valid signal area is a 2,400 ft (730 m) × 4,200 ft (1,280 m) ellipse (as measured 1,000 ft (300 m) above the antenna.)
29 // So what we do is a hemisphere that is 1.28km radius (1.28km AGL and 1.28km in all directions)
30
31 float maxRange = 1.58f;
32 if (f_AGL < 1.1172287142747450885533340921257f)
33 maxRange *= f_AGL / 1.1172287142747450885533340921257f;
34 maxRange *= 2.0f;
35
36 if (distance >= maxRange)
37 continue;
38
39 volume = Clamp(1.0f - distance / maxRange, 0, 1);
40 if (waypoint.type == 1)
42 else if (waypoint.type == 2)
44 else if (waypoint.type == 4)
46
47 break;
48 }
49 }
50
51 if (oldPlaying && oldPlaying != nowPlaying)
52 sound->Stop(static_cast<SOUNDS>(SOUND_OUTERMARKER + oldPlaying - 1));
53
54 if (nowPlaying)
55 sound->PlayEx(static_cast<SOUNDS>(SOUND_OUTERMARKER + nowPlaying - 1), true, volume, 1, 0, false);
56
57 bus->MarkerBeacon = nowPlaying;
59}
60
61MarkerBeacons::MarkerBeacons(Bus* prmBus, Logger* prmLogger, Sound* prmSound) : Module(prmBus)
62{
63 logger = prmLogger;
64 sound = prmSound;
65}
constexpr auto Clamp(T1 val, T2 min, T3 max)
@ REF_APNMODE
Definition ServerTypes.h:42
SOUNDS
Definition Sound.h:23
@ SOUND_OUTERMARKER
Definition Sound.h:176
Definition Bus.h:20
MarkerBeaconTypes
(29) Marker beacon passage;
Definition Bus.h:163
@ Inner
Definition Bus.h:167
@ Outer
Definition Bus.h:165
@ Middle
Definition Bus.h:166
@ None
Definition Bus.h:164
std::vector< Swaypoint > waypoint
Definition Bus.h:500
enum Bus::MarkerBeaconTypes MarkerBeacon
MarkerBeacons(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Logger * logger
Definition Module.h:484
Sound * sound
Definition Module.h:485
Bus::MarkerBeaconTypes oldPlaying
Definition Module.h:487
void FrameMove(float fElapsedTime) override
Bus * bus
Definition Module.h:21
Definition Sound.h:369
void Stop(SOUNDS soundEnum) const
Definition Sound.cpp:3397
void PlayEx(SOUNDS soundEnum, bool loop, float volume=1.0f, float frequencyMod=1.0f, float pan=0.0f, bool restart=true, bool fromOutside=false, bool partOfHull=false)
Definition Sound.cpp:1006
float f_AGL
Definition globals.cpp:9
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
float power
Definition globals.h:599
unsigned char type
RiseMath::Vector3 location
RiseMath::Vector3 position
Definition globals.h:511