207 fe->volume = _sound_base_vol[i]; |
207 fe->volume = _sound_base_vol[i]; |
208 fe->priority = 0; |
208 fe->priority = 0; |
209 } |
209 } |
210 } |
210 } |
211 |
211 |
212 static void SndPlayScreenCoordFx(SoundFx sound, int x, int y) |
212 static void SndPlayScreenCoordFx(SoundFx sound, int left, int right, int top, int bottom) |
213 { |
213 { |
214 Window* const *wz; |
214 Window* const *wz; |
215 |
215 |
216 if (msf.effect_vol == 0) return; |
216 if (msf.effect_vol == 0) return; |
217 |
217 |
218 FOR_ALL_WINDOWS(wz) { |
218 FOR_ALL_WINDOWS(wz) { |
219 const ViewPort *vp = (*wz)->viewport; |
219 const ViewPort *vp = (*wz)->viewport; |
220 |
220 |
221 if (vp != NULL && |
221 if (vp != NULL && |
222 IsInsideBS(x, vp->virtual_left, vp->virtual_width) && |
222 left < vp->virtual_left + vp->virtual_width && right > vp->virtual_left && |
223 IsInsideBS(y, vp->virtual_top, vp->virtual_height)) { |
223 top < vp->virtual_top + vp->virtual_height && bottom > vp->virtual_top) { |
224 int left = (x - vp->virtual_left); |
224 int screen_x = (left + right) / 2 - vp->virtual_left; |
|
225 int width = (vp->virtual_width == 0 ? 1 : vp->virtual_width); |
|
226 int panning = (screen_x * PANNING_LEVELS * 2) / width - PANNING_LEVELS; |
225 |
227 |
226 StartSound( |
228 StartSound( |
227 sound, |
229 sound, |
228 left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, |
230 panning, |
229 (msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256 |
231 (msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256 |
230 ); |
232 ); |
231 return; |
233 return; |
232 } |
234 } |
233 } |
235 } |
236 |
238 |
237 void SndPlayTileFx(SoundFx sound, TileIndex tile) |
239 void SndPlayTileFx(SoundFx sound, TileIndex tile) |
238 { |
240 { |
239 /* emits sound from center of the tile */ |
241 /* emits sound from center of the tile */ |
240 int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
242 int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
241 int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
243 int y = TileY(tile) * TILE_SIZE - TILE_SIZE / 2; |
242 Point pt = RemapCoords(x, y, GetSlopeZ(x, y)); |
244 uint z = (y < 0 ? 0 : GetSlopeZ(x, y)); |
243 SndPlayScreenCoordFx(sound, pt.x, pt.y); |
245 Point pt = RemapCoords(x, y, z); |
|
246 y += 2 * TILE_SIZE; |
|
247 Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y)); |
|
248 SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y); |
244 } |
249 } |
245 |
250 |
246 void SndPlayVehicleFx(SoundFx sound, const Vehicle *v) |
251 void SndPlayVehicleFx(SoundFx sound, const Vehicle *v) |
247 { |
252 { |
248 SndPlayScreenCoordFx(sound, |
253 SndPlayScreenCoordFx(sound, |
249 (v->left_coord + v->right_coord) / 2, |
254 v->left_coord, v->right_coord, |
250 (v->top_coord + v->bottom_coord) / 2 |
255 v->top_coord, v->top_coord |
251 ); |
256 ); |
252 } |
257 } |
253 |
258 |
254 void SndPlayFx(SoundFx sound) |
259 void SndPlayFx(SoundFx sound) |
255 { |
260 { |