Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
- apache doppler effect being controlled by a single player
- shock trooper shoot sprite
- excessive battery/health network messages being sent due to rounding errorr
- mstream bit writer not writing zeroes
  • Loading branch information
wootguy committed Nov 3, 2024
1 parent c1824ab commit 168f1ea
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dlls/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4321,7 +4321,7 @@ void CBasePlayer :: UpdateClientData( void )
gDisplayTitle = 0;
}

if (pev->health != m_iClientHealth)
if ((int)pev->health != m_iClientHealth)
{
int iHealth = clampf( pev->health, 0, 255 ); // make sure that no negative health values are sent
if ( pev->health > 0.0f && pev->health <= 1.0f )
Expand All @@ -4336,7 +4336,7 @@ void CBasePlayer :: UpdateClientData( void )
}


if (pev->armorvalue != m_iClientBattery)
if ((int)pev->armorvalue != m_iClientBattery)
{
m_iClientBattery = pev->armorvalue;

Expand Down
1 change: 1 addition & 0 deletions dlls/CBasePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class EXPORT CBasePlayer : public CBaseMonster
bool m_wantToExitObserver; // set to true if the player should spawn as soon as a spawn point is available
int IsObserver() { return m_isObserver; };
BOOL IsFirstPerson() { return m_hViewEntity.GetEdict() == edict(); }
BOOL IsBot() { return pev->flags & FL_FAKECLIENT; }
virtual int GetEntindexPriority() { return ENTIDX_PRIORITY_HIGH; }

int random_seed; // See that is shared between client & server for shared weapons code
Expand Down
45 changes: 30 additions & 15 deletions dlls/monster/CApache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ void CApache::Precache( void )

PRECACHE_MODEL(GetModel());

PRECACHE_SOUND("apache/ap_rotor1.wav");
//PRECACHE_SOUND("apache/ap_rotor1.wav");
PRECACHE_SOUND("apache/ap_rotor2.wav");
PRECACHE_SOUND("apache/ap_rotor3.wav");
PRECACHE_SOUND("apache/ap_whine1.wav");
//PRECACHE_SOUND("apache/ap_rotor3.wav");
//PRECACHE_SOUND("apache/ap_whine1.wav");

PRECACHE_SOUND("weapons/mortarhit.wav");

Expand Down Expand Up @@ -725,39 +725,54 @@ void CApache :: Flight( void )
// ALERT( at_console, "%.0f %.0f : %.0f %.0f : %.0f %.0f : %.0f\n", pev->origin.x, pev->velocity.x, flDist, flSpeed, pev->angles.x, pev->avelocity.x, m_flForce );
// ALERT( at_console, "%.0f %.0f : %.0f %0.f : %.0f\n", pev->origin.z, pev->velocity.z, vecEst.z, m_posDesired.z, m_flForce );

static int lastPitch[33];

// make rotor, engine sounds
if (m_iSoundState == 0)
{
EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0, 0.3, 0, 110 );
StartSound(edict(), CHAN_ITEM, "apache/ap_rotor2.wav", 1.0f, 0.3f, 0, 110, g_vecZero, 0xffffffff, false);
//EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0, 0.3, 0, 110 );
// EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "apache/ap_whine1.wav", 0.5, 0.2, 0, 110 );

memset(lastPitch, 0, sizeof(int) * 33);
m_iSoundState = SND_CHANGE_PITCH; // hack for going through level transitions
}
else
{
CBaseEntity *pPlayer = NULL;
for (int i = 1; i < gpGlobals->maxClients; i++) {
CBaseEntity* pPlayer = (CBaseEntity*)UTIL_PlayerByIndex(i);

pPlayer = UTIL_FindEntityByClassname( NULL, "player" );
// UNDONE: this needs to send different sounds to every player for multiplayer.
if (pPlayer)
{
if (!pPlayer) {
continue;
}

float pitch = DotProduct( pev->velocity - pPlayer->pev->velocity, (pPlayer->pev->origin - pev->origin).Normalize() );
float dot = DotProduct(pev->velocity - pPlayer->pev->velocity, (pPlayer->pev->origin - pev->origin).Normalize());

pitch = (int)(100 + pitch / 50.0);
int pitch = (int)(100 + dot / 50.0);

if (pitch > 250)
if (pitch > 250)
pitch = 250;
if (pitch < 50)
pitch = 50;

pitch = (pitch / 2) * 2; // reduce the amount of network messages

if (pitch == 100)
pitch = 101;
pitch = 101; // SND_CHANGE_PITCH will not work for 100 pitch (random sounds will play)

/*
float flVol = (m_flForce / 100.0) + .1;
if (flVol > 1.0)
if (flVol > 1.0)
flVol = 1.0;
*/

if (pitch == lastPitch[pPlayer->entindex()]) {
continue;
}

EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "apache/ap_rotor2.wav", 1.0, 0.3, SND_CHANGE_PITCH | SND_CHANGE_VOL, pitch);
StartSound(edict(), CHAN_ITEM, "apache/ap_rotor2.wav", 1.0f, 0.3f, SND_CHANGE_PITCH,
pitch, g_vecZero, PLRBIT(pPlayer->edict()), false);
lastPitch[pPlayer->entindex()] = pitch;
}
// EMIT_SOUND_DYN(ENT(pev), CHAN_STATIC, "apache/ap_whine1.wav", flVol, 0.2, SND_CHANGE_PITCH | SND_CHANGE_VOL, pitch);

Expand Down
5 changes: 3 additions & 2 deletions dlls/monster/CShockTrooper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,12 +964,13 @@ void CShockTrooper::HandleAnimEvent(MonsterEvent_t* pEvent)

GetAttachment(0, vecArmPos, vecArmAngles);

MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, vecArmPos);
//MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, vecArmPos);
MESSAGE_BEGIN(MSG_ALL, SVC_TEMPENTITY, vecArmPos);
WRITE_BYTE(TE_SPRITE);
WRITE_COORD(vecArmPos.x);
WRITE_COORD(vecArmPos.y);
WRITE_COORD(vecArmPos.z);
WRITE_COORD(iShockTrooperMuzzleFlash);
WRITE_SHORT(iShockTrooperMuzzleFlash);
WRITE_BYTE(4);
WRITE_BYTE(128);
MESSAGE_END();
Expand Down
7 changes: 6 additions & 1 deletion dlls/mstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ bool mstream::writeBit(bool value) {
currentBit = 0;
}

*((uint8_t*)pos) |= (value ? 1 : 0) << currentBit;
if (value) {
*((uint8_t*)pos) |= 1 << currentBit;
}
else {
*((uint8_t*)pos) &= ~(1 << currentBit);
}

currentBit++;
return 1;
Expand Down

0 comments on commit 168f1ea

Please sign in to comment.