play low-pitched sounds if players ear got caught by a grenade
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2053 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+6
-2
@@ -339,6 +339,7 @@ struct playerent : dynent, playerstate
|
||||
int nextweapon; // weapon we switch to
|
||||
int skin, nextskin; // skin after respawning
|
||||
int spectatemode, followplayercn;
|
||||
int eardamagemillis;
|
||||
virtual float dyneyeheight() { return (state==CS_DEAD || state==CS_SPECTATE) && spectatemode==SM_FLY ? 1.0f : physent::dyneyeheight(); }
|
||||
bool allowmove() { return state!=CS_DEAD || spectatemode==SM_FLY; }
|
||||
|
||||
@@ -352,7 +353,7 @@ struct playerent : dynent, playerstate
|
||||
int smoothmillis;
|
||||
|
||||
playerent() : clientnum(-1), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), deaths(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT),
|
||||
skin(0), nextskin(0), spectatemode(SM_NONE), followplayercn(0),
|
||||
skin(0), nextskin(0), spectatemode(SM_NONE), followplayercn(0), eardamagemillis(0),
|
||||
weaponsel(NULL), nextweaponsel(NULL), primweap(NULL), nextprimweap(NULL), lastattackweapon(NULL),
|
||||
smoothmillis(-1)
|
||||
{
|
||||
@@ -377,6 +378,8 @@ struct playerent : dynent, playerstate
|
||||
vec push(dir);
|
||||
push.mul(damage/100.0f*guns[gun].pushfactor);
|
||||
vel.add(push);
|
||||
extern int lastmillis;
|
||||
if(gun==GUN_GRENADE && damage > 50) eardamagemillis = lastmillis+damage*100;
|
||||
}
|
||||
|
||||
void respawn()
|
||||
@@ -391,6 +394,7 @@ struct playerent : dynent, playerstate
|
||||
weaponchanging = 0;
|
||||
spectatemode = SM_NONE;
|
||||
followplayercn = 0;
|
||||
eardamagemillis = 0;
|
||||
}
|
||||
|
||||
void spawnstate(int gamemode)
|
||||
@@ -412,7 +416,7 @@ struct playerent : dynent, playerstate
|
||||
weaponsel->ondeselecting();
|
||||
weaponchanging = lastmillis;
|
||||
nextweaponsel = w;
|
||||
w->onselecting();
|
||||
w->onselecting();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+23
-3
@@ -244,10 +244,10 @@ struct oggstream
|
||||
name[0] = '\0';
|
||||
}
|
||||
|
||||
void randomseek()
|
||||
void seek(double offset)
|
||||
{
|
||||
if(!totalseconds) return;
|
||||
ov_time_seek_page(&oggfile, fmod((double)lastmillis, totalseconds*3/4.0f));
|
||||
ov_time_seek_page(&oggfile, fmod(offset, totalseconds));
|
||||
if(playing()) update();
|
||||
}
|
||||
};
|
||||
@@ -487,6 +487,7 @@ struct location
|
||||
alSourcef(id, AL_REFERENCE_DISTANCE, 1.0f);
|
||||
alSource3f(id, AL_POSITION, 0.0, 0.0, 0.0);
|
||||
alSource3f(id, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
alSourcef(id, AL_PITCH, 1.0f);
|
||||
}
|
||||
|
||||
void gain(float g)
|
||||
@@ -550,6 +551,11 @@ struct location
|
||||
}
|
||||
else alSourcefv(id, AL_POSITION, (ALfloat *) &pos); // static stuff
|
||||
}
|
||||
|
||||
void pitch(float p)
|
||||
{
|
||||
alSourcef(id, AL_PITCH, p);
|
||||
}
|
||||
};
|
||||
|
||||
const float location::maxgain = 0.1f;
|
||||
@@ -648,7 +654,7 @@ void musicsuggest(int id, int millis, bool rndofs) // play bg music if nothing e
|
||||
{
|
||||
gamemusic.fadein(lastmillis, 1000);
|
||||
gamemusic.fadeout(millis ? lastmillis+millis : 0, 1000);
|
||||
if(rndofs) gamemusic.randomseek();
|
||||
if(rndofs) gamemusic.seek(millis ? (double)rnd(millis/2) : (double)lastmillis);
|
||||
if(!gamemusic.playback(rndofs)) conoutf("could not play music: %s", name);
|
||||
}
|
||||
else conoutf("could not open music: %s", name);
|
||||
@@ -745,6 +751,18 @@ location *findsoundloc(int sound, physent *p)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lastpitch = 1.0f;
|
||||
|
||||
void updatepitch() // set lower pitch if "player's ear got damaged"
|
||||
{
|
||||
if(camera1->type!=ENT_PLAYER) return;
|
||||
playerent *p = (playerent *) camera1;
|
||||
float pitch = lastmillis>p->eardamagemillis ? 1.0f : 0.85f;
|
||||
if(pitch==lastpitch) return;
|
||||
loopv(locations) locations[i].pitch(pitch);
|
||||
lastpitch = pitch;
|
||||
}
|
||||
|
||||
void updateplayerfootsteps(playerent *p, int sound)
|
||||
{
|
||||
if(!p) return;
|
||||
@@ -827,6 +845,8 @@ void updatevol()
|
||||
alListenerfv(AL_ORIENTATION, (ALfloat *) &o);
|
||||
alListener3f(AL_POSITION, camera1->o.x, camera1->o.y, camera1->o.z);
|
||||
|
||||
updatepitch();
|
||||
|
||||
// update all sound locations
|
||||
loopv(locations) if(locations[i].inuse) locations[i].update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user