1 #pragma once
2 #ifndef CATA_SRC_SOUNDS_H
3 #define CATA_SRC_SOUNDS_H
4 
5 #include <string> // IWYU pragma: keep
6 #include <utility>
7 #include <vector>
8 
9 #include "units_fwd.h"
10 
11 class Character;
12 class Creature;
13 class JsonObject;
14 class item;
15 class monster;
16 class player;
17 class translation;
18 struct tripoint;
19 template <typename E> struct enum_traits;
20 
21 namespace sounds
22 {
23 enum class sound_t : int {
24     background = 0,
25     weather,
26     music,
27     movement,
28     speech,
29     electronic_speech, // Any electronic sound that's not music/alarm: Robot speech, radio, etc.
30     activity,
31     destructive_activity,
32     alarm,
33     combat, // any violent sounding activity
34     alert, // louder than speech to get attention
35     order,  // loudest to get attention
36     _LAST // must always be last
37 };
38 
39 // Methods for recording sound events.
40 /**
41  * Sound at (p) of intensity (vol)
42  *
43  * If the description parameter is a non-empty string, then a string message about the
44  * sound is generated for the player.
45  *
46  * @param p position of sound.
47  * @param vol Volume of sound.
48  * @param category general type of sound for faster parsing
49  * @param description Description of the sound for the player
50  * @param ambient Sound does not interrupt player activity if this is true
51  * @param id Id of sound effect
52  * @param variant Variant of sound effect given in id
53  * @returns true if the player could hear the sound.
54  */
55 void sound( const tripoint &p, int vol, sound_t category, const std::string &description,
56             bool ambient = false, const std::string &id = "",
57             const std::string &variant = "default" );
58 void sound( const tripoint &p, int vol, sound_t category, const translation &description,
59             bool ambient = false, const std::string &id = "",
60             const std::string &variant = "default" );
61 /** Functions identical to sound(..., true). */
62 void ambient_sound( const tripoint &p, int vol, sound_t category, const std::string &description );
63 /** Creates a list of coordinates at which to draw footsteps. */
64 void add_footstep( const tripoint &p, int volume, int distance, monster *source,
65                    const std::string &footstep );
66 
67 /* Make sure the sounds are all reset when we start a new game. */
68 void reset_sounds();
69 void reset_markers();
70 
71 // Methods for processing sound events, these
72 // process_sounds() applies the sounds since the last turn to monster AI,
73 void process_sounds();
74 // process_sound_markers applies sound events to the player and records them for display.
75 void process_sound_markers( player *p );
76 
77 // Return list of points that have sound events the player can hear.
78 std::vector<tripoint> get_footstep_markers();
79 // Return list of all sounds and the list of sound cluster centroids.
80 std::pair<std::vector<tripoint>, std::vector<tripoint>> get_monster_sounds();
81 // retrieve the sound event(s?) at a location.
82 std::string sound_at( const tripoint &location );
83 /** Tells us if sound has been enabled in options */
84 extern bool sound_enabled;
85 } // namespace sounds
86 
87 template<>
88 struct enum_traits<sounds::sound_t> {
89     static constexpr sounds::sound_t last = sounds::sound_t::_LAST;
90 };
91 
92 namespace sfx
93 {
94 //Channel assignments:
95 enum class channel : int {
96     any = -1,                   //Finds the first available channel
97     daytime_outdoors_env = 0,
98     nighttime_outdoors_env,
99     underground_env,
100     indoors_env,
101     indoors_rain_env,
102     outdoors_snow_env,
103     outdoors_flurry_env,
104     outdoors_thunderstorm_env,
105     outdoors_rain_env,
106     outdoors_drizzle_env,
107     outdoor_blizzard,
108     deafness_tone,
109     danger_extreme_theme,
110     danger_high_theme,
111     danger_medium_theme,
112     danger_low_theme,
113     stamina_75,
114     stamina_50,
115     stamina_35,
116     idle_chainsaw,
117     chainsaw_theme,
118     player_activities,
119     exterior_engine_sound,
120     interior_engine_sound,
121     radio,
122     MAX_CHANNEL                 //the last reserved channel
123 };
124 
125 //Group Assignments:
126 enum class group : int {
127     weather = 1,    //SFX related to weather
128     time_of_day,    //SFX related to time of day
129     context_themes, //SFX related to context themes
130     fatigue         //SFX related to fatigue
131 };
132 
133 void load_sound_effects( const JsonObject &jsobj );
134 void load_sound_effect_preload( const JsonObject &jsobj );
135 void load_playlist( const JsonObject &jsobj );
136 void play_variant_sound( const std::string &id, const std::string &variant, int volume,
137                          units::angle angle, double pitch_min = -1.0, double pitch_max = -1.0 );
138 void play_variant_sound( const std::string &id, const std::string &variant, int volume );
139 void play_ambient_variant_sound( const std::string &id, const std::string &variant, int volume,
140                                  channel channel, int fade_in_duration, double pitch = -1.0, int loops = -1 );
141 void play_activity_sound( const std::string &id, const std::string &variant, int volume );
142 void end_activity_sounds();
143 void generate_gun_sound( const player &source_arg, const item &firing );
144 void generate_melee_sound( const tripoint &source, const tripoint &target, bool hit,
145                            bool targ_mon = false, const std::string &material = "flesh" );
146 void do_hearing_loss( int turns = -1 );
147 void remove_hearing_loss();
148 void do_projectile_hit( const Creature &target );
149 int get_heard_volume( const tripoint &source );
150 units::angle get_heard_angle( const tripoint &source );
151 void do_footstep();
152 void do_danger_music();
153 void do_ambient();
154 void do_vehicle_engine_sfx();
155 void do_vehicle_exterior_engine_sfx();
156 void fade_audio_group( group group, int duration );
157 void fade_audio_channel( channel channel, int duration );
158 bool is_channel_playing( channel channel );
159 bool has_variant_sound( const std::string &id, const std::string &variant );
160 void stop_sound_effect_fade( channel channel, int duration );
161 void stop_sound_effect_timed( channel channel, int time );
162 int set_channel_volume( channel channel, int volume );
163 void do_player_death_hurt( const Character &target, bool death );
164 void do_fatigue();
165 // @param obst should be string id of obstacle terrain or vehicle part
166 void do_obstacle( const std::string &obst = "" );
167 } // namespace sfx
168 
169 #endif // CATA_SRC_SOUNDS_H
170