aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/mission_notices.rs
blob: 048674fb46366736d4d3cb5b6d332d48b21698a2 (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
79
80
81
82
83
84
85
86
87
88
89
use crate::StaticVulkanApp;
use fparkan_runtime::MissionNotice;

impl StaticVulkanApp {
    #[cfg(windows)]
    pub(super) fn present_computer_notice(&mut self, id: u32, clock_ms: u32) {
        let posted = self
            .overlay
            .hints
            .as_mut()
            .ok_or_else(|| "pager unavailable".to_string())
            .and_then(|hints| hints.post_computer(id, clock_ms));
        let result = posted.and_then(|(sender, body)| {
            if let Some(help) = &mut self.overlay.help {
                help.post(sender, body)?;
            }
            Ok(())
        });
        if let Err(error) = result {
            eprintln!("computer_notice_unavailable id={id:#06x} reason={error}");
        }
    }

    pub(super) fn present_mission_notice(&mut self, notice: MissionNotice, clock_ms: u32) {
        match notice {
            MissionNotice::BuildingCaptured { .. } | MissionNotice::VehicleCaptured => {}
            MissionNotice::ObjectiveComplete(index) => {
                eprintln!(
                    "mission_objective index={index} status=complete queue_time_ms={clock_ms}"
                );
            }
            MissionNotice::Completed | MissionNotice::Failed => {
                let status = if notice == MissionNotice::Completed {
                    "completed"
                } else {
                    "failed"
                };
                eprintln!("mission_outcome status={status} queue_time_ms={clock_ms}");
            }
            MissionNotice::Information(index) => {
                #[cfg(windows)]
                {
                    let posted = self
                        .overlay
                        .hints
                        .as_mut()
                        .ok_or_else(|| "mission text resources unavailable".to_string())
                        .and_then(|hints| hints.post(index, clock_ms));
                    match posted {
                        Ok((sender, body)) => {
                            if let Some(help) = &mut self.overlay.help {
                                if let Err(error) = help.post(sender, body) {
                                    eprintln!("mission_help_message_unavailable index={index} reason={error}");
                                }
                            }
                        }
                        Err(error) => eprintln!(
                            "sim_coverage mission_text_unavailable=1 index={index} reason={error}"
                        ),
                    }
                }
                #[cfg(not(windows))]
                eprintln!("sim_coverage mission_text_unavailable=1 index={index} reason=platform");
            }
        }
        if let Some(audio) = &mut self.audio {
            let voice = match notice {
                MissionNotice::Information(index) => audio.queue_mission_voice(index),
                MissionNotice::ObjectiveComplete(_) => audio.queue_game_voice("VOICE_OBJ_COMPLETE"),
                MissionNotice::BuildingCaptured { neutral } => audio.queue_game_voice(if neutral {
                    "VOICE_NBUILD_CAPTURE"
                } else {
                    "VOICE_EBUILD_CAPTURE"
                }),
                MissionNotice::VehicleCaptured => audio.queue_vehicle_capture_voice(),
                MissionNotice::Completed => audio.queue_game_voice("VOICE_MISSION_COMPLETE"),
                MissionNotice::Failed => audio.queue_game_voice("VOICE_MISSION_FAIL"),
            };
            match voice {
                Ok(resource) => eprintln!(
                    "mission_voice notice={notice:?} resource={resource} queue_time_ms={clock_ms}"
                ),
                Err(error) => eprintln!(
                    "sim_coverage mission_voice_unavailable=1 notice={notice:?} reason={error}"
                ),
            }
        }
    }
}