1 // Private header for shout.h.
8 // [ds] The old noise system was pretty simple: noise level (loudness) ==
9 // distance covered. Since the new system considers terrain when propagating
10 // sound, using the same noise attenuation of 1 unit per square traveled would
11 // mean greatly reduced sound propagation on average.
13 // To compensate for sound being blocked by walls and doors, I've lowered the
14 // base attenuation from its original value of 1 (1000 millis).
16 // Note that this reduced attenuation makes open levels nastier, since there's
17 // nothing to block sound propagation there, and the lowered attenuation means
18 // sound goes farther.
20 const int BASE_NOISE_ATTENUATION_MILLIS
= 850;
21 const int NOISE_ATTENUATION_COMPLETE
= 250000;
22 const int LOWEST_AUDIBLE_NOISE_INTENSITY_MILLIS
= 1000;
24 static inline int noise_is_audible(int noise_intensity_millis
)
26 return noise_intensity_millis
>= LOWEST_AUDIBLE_NOISE_INTENSITY_MILLIS
;
33 NF_MESSAGE_IF_UNSEEN
= 0x2,
38 coord_def noise_source
;
40 std::string noise_player_msg
;
42 // Thousandths of noise intensity (i.e. the intensity passed to
44 int noise_intensity_millis
;
48 int16_t noise_producer_id
;
52 noise_t(coord_def _noise_source
= coord_def(),
53 std::string _noise_player_msg
= "",
54 int _noise_intensity_millis
= 0,
55 int16_t _noise_producer_id
= -1,
57 : noise_source(_noise_source
),
58 noise_player_msg(_noise_player_msg
),
59 noise_intensity_millis(_noise_intensity_millis
),
61 noise_producer_id(_noise_producer_id
),
68 return !noise_is_audible(noise_intensity_millis
);
71 bool operator < (const noise_t
&other
) const
73 return noise_intensity_millis
< other
.noise_intensity_millis
;
79 // The cell from which the noise reached this cell (delta)
80 coord_def neighbour_delta
;
83 int noise_intensity_millis
;
84 int noise_travel_distance
;
87 bool can_apply_noise(int noise_intensity_millis
) const;
88 bool apply_noise(int noise_intensity_millis
,
91 const coord_def
&neighbour_delta
);
95 return !noise_is_audible(noise_intensity_millis
);
98 // Given a destination cell adjacent to this cell, returns the
99 // angle of <previous cell> <pos> <next-pos>:
100 // * If all three cells are in a straight line, returns 0
101 // * If the target cell is a knight's move from the original position,
103 // * If the target cell makes a right angle from the original position,
105 // * If the target cell makes a sharp 45 degree angle, returns 3.
106 // * If the original position is the same as the new position, returns 4.
107 // This number is used to multiply the noise attenuation for noise passing
108 // through this cell.
109 int turn_angle(const coord_def
&next_delta
) const;
117 // Register a noise on the noise grid. The noise will not actually
118 // propagate until propagate_noise() is called.
119 void register_noise(const noise_t
&noise
);
121 // Propagate noise from the noise sources registered.
122 void propagate_noise();
124 // Clear all noise from the noise grid.
127 bool dirty() const { return !noises
.empty(); }
129 #ifdef DEBUG_NOISE_PROPAGATION
130 void dump_noise_grid(const std::string
&filename
) const;
131 void write_noise_grid(FILE *outf
) const;
132 void write_cell(FILE *outf
, coord_def p
, int ch
) const;
136 bool propagate_noise_to_neighbour(int base_attenuation
,
138 const noise_cell
&cell
,
139 const coord_def
&pos
,
140 const coord_def
&next_position
);
141 void apply_noise_effects(const coord_def
&pos
,
142 int noise_intensity_millis
,
143 const noise_t
&noise
,
144 int noise_travel_distance
);
146 coord_def
noise_perceived_position(actor
*act
,
147 const coord_def
&affected_position
,
148 const noise_t
&noise
) const;
151 FixedArray
<noise_cell
, GXM
, GYM
> cells
;
152 std::vector
<noise_t
> noises
;
153 int affected_actor_count
;