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 |
225 |
226 StartSound( |
226 StartSound( |
227 sound, |
227 sound, |
228 left / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, |
228 screen_x / max(1, vp->virtual_width / ((PANNING_LEVELS << 1) + 1)) - PANNING_LEVELS, |
229 (msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256 |
229 (msf.effect_vol * _vol_factor_by_zoom[vp->zoom - ZOOM_LVL_BEGIN]) / 256 |
230 ); |
230 ); |
231 return; |
231 return; |
232 } |
232 } |
233 } |
233 } |
236 |
236 |
237 void SndPlayTileFx(SoundFx sound, TileIndex tile) |
237 void SndPlayTileFx(SoundFx sound, TileIndex tile) |
238 { |
238 { |
239 /* emits sound from center of the tile */ |
239 /* emits sound from center of the tile */ |
240 int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
240 int x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2; |
241 int y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2; |
241 int y = TileY(tile) * TILE_SIZE - TILE_SIZE / 2; |
242 Point pt = RemapCoords(x, y, GetSlopeZ(x, y)); |
242 Point pt = RemapCoords(x, y, GetSlopeZ(x, y)); |
243 SndPlayScreenCoordFx(sound, pt.x, pt.y); |
243 y += 2 * TILE_SIZE; |
|
244 Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y)); |
|
245 SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y); |
244 } |
246 } |
245 |
247 |
246 void SndPlayVehicleFx(SoundFx sound, const Vehicle *v) |
248 void SndPlayVehicleFx(SoundFx sound, const Vehicle *v) |
247 { |
249 { |
248 SndPlayScreenCoordFx(sound, |
250 SndPlayScreenCoordFx(sound, |
249 (v->left_coord + v->right_coord) / 2, |
251 v->left_coord, v->right_coord, |
250 (v->top_coord + v->bottom_coord) / 2 |
252 v->top_coord, v->top_coord |
251 ); |
253 ); |
252 } |
254 } |
253 |
255 |
254 void SndPlayFx(SoundFx sound) |
256 void SndPlayFx(SoundFx sound) |
255 { |
257 { |