Update of /cvsroot/netrek/client/netrekxp/src
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7561/src
Modified Files:
local.c
Log Message:
Merge a bunch of common angular sound code into SetDistAngle() function.
Index: local.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/local.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- local.c 1 Mar 2007 18:31:18 -0000 1.66
+++ local.c 13 Mar 2007 19:11:10 -0000 1.67
@@ -40,6 +40,8 @@
static int last_speed = 0;
static int streaks_on = 0;
#ifdef SOUND
+static int distance = 0; /* For angular sound */
+static int angle = 0; /* For angular sound */
static int sound_torps = 0;
static int sound_other_torps = 0;
static int num_other_torps = 0;
@@ -75,6 +77,32 @@
/* Function Defininitions */
+#ifdef SOUND
+/* Sets global variables distance and sound used with angular sound */
+void SetDistAngle(int dx, int dy)
+{
+ int newdx, newdy;
+
+ newdx = dx - WINSIDE/2;
+ newdy = dy - WINSIDE/2;
+
+ distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
+ // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
+ // which would be a diagonal from player to corner of tactical
+ // Reason for normalization is Mix_SetDistance requires that range
+ distance = (int)((255 * distance)/CORNER_DIST);
+ // Calculate angle, then adjust as necessary for Mix_SetDistance
+ if (distance != 0)
+ {
+ angle = (int)(atan2(-newdy, newdx)*180/XPI);
+ angle = 90 - angle;
+ }
+ else
+ angle = 0;
+ return;
+}
+#endif
+
int
randcolor()
{
@@ -641,7 +669,6 @@
const int view = SCALE * WINSIDE / 2 + BMP_SHIELD_WIDTH * SCALE / 2;
int dx, dy, px, py, wx, wy, tx, ty, lx, ly;
int new_dx, new_dy;
- int newdx, newdy, distance, angle;
W_Icon (*ship_bits)[SHIP_VIEWS];
W_Icon (*ship_bitsHR);
@@ -722,23 +749,8 @@
{
// To avoid hearing twarp cloak sounds as the twarper/observer
if ( (myPlayer(j) || isObsLockPlayer(j)) ? ((me->p_flags & PFTWARP) ? 0 : 1) : 1 )
- {
- newdx = dx - WINSIDE/2;
- newdy = dy - WINSIDE/2;
-
- distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
- // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
- // which would be a diagonal from player to corner of tactical
- // Reason for normalization is Mix_SetDistance requires that range
- distance = (int)((255 * distance)/CORNER_DIST);
- // Calculate angle, then adjust as necessary for Mix_SetDistance
- if (distance != 0)
- {
- angle = (int)(atan2(-newdy, newdx)*180/XPI);
- angle = 90 - angle;
- }
- else
- angle = 0;
+ {
+ SetDistAngle(dx, dy);
// At short distances, don't use angular sound
if (!soundAngles || distance < SCALE/2)
Play_Sound_Loc(CLOAKED_WAV, SF_CLOAKING, -1, distance);
@@ -762,23 +774,8 @@
{
if (j->p_cloakphase == cloak_phases - 1)
{
- newdx = dx - WINSIDE/2;
- newdy = dy - WINSIDE/2;
-
- distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
- // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
- // which would be a diagonal from player to corner of tactical
- // Reason for normalization is Mix_SetDistance requires that range
- distance = (int)((255 * distance)/CORNER_DIST);
- // Calculate angle, then adjust as necessary for Mix_SetDistance
- if (distance != 0)
- {
- angle = (int)(atan2(-newdy, newdx)*180/XPI);
- angle = 90 - angle;
- }
- else
- angle = 0;
- // At short distances, don't use angular sound
+ SetDistAngle(dx, dy);
+ // At short distances, don't use angular sound
if (!soundAngles || distance < SCALE/2)
Play_Sound_Loc(UNCLOAK_WAV, SF_CLOAKING, -1, distance);
else
@@ -1297,24 +1294,7 @@
}
else
{
- int newdx, newdy, distance, angle;
-
- newdx = dx - WINSIDE/2;
- newdy = dy - WINSIDE/2;
-
- distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
- // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
- // which would be a diagonal from player to corner of tactical
- // Reason for normalization is Mix_SetDistance requires that range
- distance = (int)((255 * distance)/CORNER_DIST);
- // Calculate angle, then adjust as necessary for Mix_SetDistance
- if (distance != 0)
- {
- angle = (int)(atan2(-newdy, newdx)*180/XPI);
- angle = 90 - angle;
- }
- else
- angle = 0;
+ SetDistAngle(dx, dy);
// At short distances, don't use angular sound
if (!soundAngles || distance < SCALE/2)
{
@@ -1383,24 +1363,7 @@
Play_Sound(PHASER_WAV, SF_WEAPONS);
else
{
- int newdx, newdy, distance, angle;
-
- newdx = dx - WINSIDE/2;
- newdy = dy - WINSIDE/2;
-
- distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
- // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
- // which would be a diagonal from player to corner of tactical
- // Reason for normalization is Mix_SetDistance requires that range
- distance = (int)((255 * distance)/CORNER_DIST);
- // Calculate angle, then adjust as necessary for Mix_SetDistance
- if (distance != 0)
- {
- angle = (int)(atan2(-newdy, newdx)*180/XPI);
- angle = 90 - angle;
- }
- else
- angle = 0;
+ SetDistAngle(dx, dy);
// At short distances, don't use angular sound
if (!soundAngles || distance < SCALE/2)
Play_Sound_Loc(PHASER_OTHER_WAV, SF_OTHER|SF_WEAPONS, -1, distance);
@@ -1861,24 +1824,7 @@
#ifdef SOUND
if (k->t_fuse == (MAX(2, BMP_TORPDET_FRAMES * server_ups / 10) - 1))
{
- int newdx, newdy, distance, angle;
-
- newdx = dx - WINSIDE/2;
- newdy = dy - WINSIDE/2;
-
- distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
- // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
- // which would be a diagonal from player to corner of tactical
- // Reason for normalization is Mix_SetDistance requires that range
- distance = (int)((255 * distance)/CORNER_DIST);
- // Calculate angle, then adjust as necessary for Mix_SetDistance
- if (distance != 0)
- {
- angle = (int)(atan2(-newdy, newdx)*180/XPI);
- angle = 90 - angle;
- }
- else
- angle = 0;
+ SetDistAngle(dx, dy);
// At short distances, don't use angular sound
if (!soundAngles || distance < SCALE/2)
Play_Sound_Loc(TORP_HIT_WAV, SF_WEAPONS, -1, distance);
@@ -2123,24 +2069,7 @@
#ifdef SOUND
if (pt->pt_fuse == (MAX(2, BMP_TORPDET_FRAMES * server_ups / 10) - 1))
{
- int newdx, newdy, distance, angle;
-
- newdx = dx - WINSIDE/2;
- newdy = dy - WINSIDE/2;
-
- distance = (int) sqrt((newdx)*(newdx) + (newdy)*(newdy));
- // Normalize from 0 to 255, 0 being on top of player, 255 being max distance
- // which would be a diagonal from player to corner of tactical
- // Reason for normalization is Mix_SetDistance requires that range
- distance = (int)((255 * distance)/CORNER_DIST);
- // Calculate angle, then adjust as necessary for Mix_SetDistance
- if (distance != 0)
- {
- angle = (int)(atan2(-newdy, newdx)*180/XPI);
- angle = 90 - angle;
- }
- else
- angle = 0;
+ SetDistAngle(dx, dy);
// At short distances, don't use angular sound
if (!soundAngles || distance < SCALE/2)
Play_Sound_Loc(PLASMA_HIT_WAV, SF_WEAPONS, -1, distance);