Permalink
Browse files

Sounds will be silenced if out of range of the camera's targeted pilo…

…t or position.
  • Loading branch information...
1 parent ba8ac1d commit bebca4c726e5bf9841307b7456ad4c9d7b5aa845 @Deiz Deiz committed Feb 17, 2012
Showing with 41 additions and 2 deletions.
  1. +11 −0 src/camera.c
  2. +1 −0 src/camera.h
  3. +11 −0 src/pilot_ew.c
  4. +1 −0 src/pilot_ew.h
  5. +17 −2 src/sound.c
View
@@ -178,6 +178,17 @@ void cam_setTargetPos( double x, double y, int soft_over )
}
+/**
+ * @brief Returns the camera's current target.
+ *
+ * @return 0 if focused on position, else returns pilot ID.
+ */
+int cam_getTarget( void )
+{
+ return camera_followpilot;
+}
+
+
/**
* @brief Updates the camera.
*
View
@@ -16,6 +16,7 @@
double cam_getZoom (void);
double cam_getZoomTarget (void);
void cam_getPos( double *x, double *y );
+int cam_getTarget( void );
/*
View
@@ -113,6 +113,17 @@ void pilot_updateSensorRange (void)
}
+/**
+ * @brief Returns the default sensor range for the current system.
+ *
+ * @return Sensor range.
+ */
+double pilot_sensorRange( void )
+{
+ return sensor_curRange;
+}
+
+
/**
* @brief Check to see if a position is in range of the pilot.
*
View
@@ -15,6 +15,7 @@
* Sensors and range.
*/
void pilot_updateSensorRange (void);
+double pilot_sensorRange( void );
int pilot_inRange( const Pilot *p, double x, double y );
int pilot_inRangePilot( const Pilot *p, const Pilot *target );
int pilot_inRangePlanet( const Pilot *p, int target );
View
@@ -28,6 +28,7 @@
#include "physics.h"
#include "conf.h"
#include "player.h"
+#include "camera.h"
#define SOUND_PREFIX "snd/sounds/" /**< Prefix of where to find sounds. */
@@ -422,15 +423,29 @@ int sound_playPos( int sound, double px, double py, double vx, double vy )
{
alVoice *v;
alSound *s;
+ double cx, cy, dist;
+ int target;
if (sound_disabled)
return 0;
if ((sound < 0) || (sound >= sound_nlist))
return -1;
- if (player.p != NULL && !pilot_inRange( player.p, px, py ))
- return 0;
+ target = cam_getTarget();
+
+ /* Following a pilot. */
+ if (target) {
+ if (!pilot_inRange( pilot_get( target ), px, py ))
+ return 0;
+ }
+ /* Set to a position. */
+ else {
+ cam_getPos(&cx, &cy);
+ dist = pow2(px - cx) + pow2(py - cy);
+ if (dist > pilot_sensorRange())
+ return 0;
+ }
/* Gets a new voice. */
v = voice_new();

0 comments on commit bebca4c

Please sign in to comment.