aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/player_service.rs
blob: 9aece40ae53fe0727862edaa3a4611567c67123f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::StaticVulkanApp;
use fparkan_runtime::cockpit_indicators::cockpit_indicators;
use fparkan_runtime::{
    at_research_laboratory, order_lab_research, toggle_camouflage, toggle_self_repair,
};

impl StaticVulkanApp {
    pub(super) fn toggle_player_camouflage(&mut self) {
        if let Some((engine, cockpit)) = self.mission_engine.as_mut().zip(self.cockpit) {
            toggle_camouflage(engine, cockpit);
        }
    }

    pub(super) fn announce_player_camouflage(&mut self) {
        let Some((engine, cockpit)) = self
            .mission_engine
            .as_ref()
            .zip(self.cockpit)
            .filter(|_| self.command_view.is_none() && self.demo_camera.is_none())
        else {
            return;
        };
        let Some(state) = cockpit_indicators(engine, cockpit) else {
            return;
        };
        let changed = if state.camouflage {
            self.camouflage_announced.insert(cockpit.handle)
        } else {
            self.camouflage_announced.remove(&cockpit.handle)
        };
        if changed {
            if let Some(audio) = &mut self.audio {
                let voice = if state.camouflage {
                    "VOICE_CHAMELEON_SYS_ON"
                } else {
                    "VOICE_CHAMELEON_SYS_OFF"
                };
                if let Err(error) = audio.queue_game_voice(voice) {
                    eprintln!("camouflage_voice_unavailable voice={voice} reason={error}");
                }
            }
        }
    }

    pub(super) fn handle_player_service(&mut self, clock_ms: u32) {
        let (true, Some(cockpit), Some(engine)) = (
            std::mem::take(&mut self.player_service_pressed),
            self.cockpit,
            self.mission_engine.as_mut(),
        ) else {
            return;
        };
        if self.boarded_hero_index.is_none() && at_research_laboratory(engine, cockpit) {
            match order_lab_research(engine, cockpit, clock_ms) {
                Ok((component, duration)) => {
                    eprintln!("laboratory_research_order component={component} duration_ms={duration} queue_time_ms={clock_ms}");
                }
                Err(error) => eprintln!("laboratory_research_rejected {error}"),
            }
            return;
        }
        if let Some(enabled) = toggle_self_repair(engine, cockpit) {
            eprintln!("player_self_repair enabled={enabled} queue_time_ms={clock_ms}");
            if let Some(audio) = &mut self.audio {
                let voice = if enabled {
                    "VOICE_REPAIR_SYS_ON"
                } else {
                    "VOICE_REPAIR_SYS_OFF"
                };
                if let Err(error) = audio.queue_game_voice(voice) {
                    eprintln!(
                        "sim_coverage mission_voice_unavailable=1 notice={voice} reason={error}"
                    );
                }
            }
        }
    }
}