diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 9aa662129..11983c661 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -2003,9 +2003,10 @@ void CGameClient::UpdatePrediction() m_GameWorld.m_WorldConfig.m_InfiniteAmmo = false; m_GameWorld.m_WorldConfig.m_IsSolo = !m_Snap.m_aCharacters[m_Snap.m_LocalClientID].m_HasExtendedData && !m_Tuning[g_Config.m_ClDummy].m_PlayerCollision && !m_Tuning[g_Config.m_ClDummy].m_PlayerHooking; - int TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_LocalCharacterPos)); + // update the tuning/tunezone at the local character position with the latest tunings received before the new snapshot + int TuneZone = Collision()->IsTune(Collision()->GetMapIndex(vec2(m_Snap.m_pLocalCharacter->m_X, m_Snap.m_pLocalCharacter->m_Y))); if(!TuneZone || !m_GameWorld.m_WorldConfig.m_PredictTiles) - m_GameWorld.m_Tuning[g_Config.m_ClDummy] = m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy]; + m_GameWorld.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy]; else m_GameWorld.TuningList()[TuneZone] = m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy]; diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index 44c5c33ad..077c0eea0 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -87,11 +87,9 @@ void CCharacter::HandleJetpack() { if (m_Jetpack) { - float Strength; + float Strength = GetTuning(m_TuneZone)->m_JetpackStrength; if(!m_TuneZone) Strength = m_LastJetpackStrength; - else - Strength = TuningList()[m_TuneZone].m_JetpackStrength; TakeDamage(Direction * -1.0f * (Strength / 100.0f / 6.11f), g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, GetCID(), m_Core.m_ActiveWeapon); } } @@ -328,11 +326,7 @@ void CCharacter::FireWeapon() else Dir = vec2(0.f, -1.f); - float Strength; - if (!m_TuneZone) - Strength = Tuning()->m_HammerStrength; - else - Strength = TuningList()[m_TuneZone].m_HammerStrength; + float Strength = GetTuning(m_TuneZone)->m_HammerStrength; vec2 Temp = pTarget->m_Core.m_Vel + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f; pTarget->Core()->LimitForce(&Temp); @@ -373,11 +367,7 @@ void CCharacter::FireWeapon() { if (!m_Jetpack) { - int Lifetime; - if (!m_TuneZone) - Lifetime = (int)(GameWorld()->GameTickSpeed()*Tuning()->m_GunLifetime); - else - Lifetime = (int)(GameWorld()->GameTickSpeed()*TuningList()[m_TuneZone].m_GunLifetime); + int Lifetime = (int)(GameWorld()->GameTickSpeed()*GetTuning(m_TuneZone)->m_GunLifetime); new CProjectile ( @@ -400,7 +390,6 @@ void CCharacter::FireWeapon() { if(GameWorld()->m_WorldConfig.m_IsVanilla) { - int ShotSpread = 2; for(int i = -ShotSpread; i <= ShotSpread; ++i) { @@ -408,7 +397,7 @@ void CCharacter::FireWeapon() float a = GetAngle(Direction); a += Spreading[i+2]; float v = 1-(absolute(i)/(float)ShotSpread); - float Speed = mix((float)GameWorld()->Tuning()->m_ShotgunSpeeddiff, 1.0f, v); + float Speed = mix((float)Tuning()->m_ShotgunSpeeddiff, 1.0f, v); new CProjectile ( GameWorld(), @@ -416,7 +405,7 @@ void CCharacter::FireWeapon() GetCID(),//Owner ProjStartPos,//Pos vec2(cosf(a), sinf(a))*Speed,//Dir - (int)(GameWorld()->GameTickSpeed()*GameWorld()->Tuning()->m_ShotgunLifetime),//Span + (int)(GameWorld()->GameTickSpeed()*Tuning()->m_ShotgunLifetime),//Span 0,//Freeze 0,//Explosive 0,//Force @@ -427,11 +416,7 @@ void CCharacter::FireWeapon() } else if(GameWorld()->m_WorldConfig.m_IsDDRace) { - float LaserReach; - if (!m_TuneZone) - LaserReach = Tuning()->m_LaserReach; - else - LaserReach = TuningList()[m_TuneZone].m_LaserReach; + float LaserReach = GetTuning(m_TuneZone)->m_LaserReach; new CLaser(GameWorld(), m_Pos, Direction, LaserReach, GetCID(), WEAPON_SHOTGUN); } @@ -439,11 +424,7 @@ void CCharacter::FireWeapon() case WEAPON_GRENADE: { - int Lifetime; - if (!m_TuneZone) - Lifetime = (int)(GameWorld()->GameTickSpeed()*Tuning()->m_GrenadeLifetime); - else - Lifetime = (int)(GameWorld()->GameTickSpeed()*TuningList()[m_TuneZone].m_GrenadeLifetime); + int Lifetime = (int)(GameWorld()->GameTickSpeed()*GetTuning(m_TuneZone)->m_GrenadeLifetime); new CProjectile ( @@ -463,11 +444,7 @@ void CCharacter::FireWeapon() case WEAPON_RIFLE: { - float LaserReach; - if(!m_TuneZone) - LaserReach = Tuning()->m_LaserReach; - else - LaserReach = TuningList()[m_TuneZone].m_LaserReach; + float LaserReach = GetTuning(m_TuneZone)->m_LaserReach; new CLaser(GameWorld(), m_Pos, Direction, LaserReach, GetCID(), WEAPON_RIFLE); } break; @@ -489,11 +466,7 @@ void CCharacter::FireWeapon() if(!m_ReloadTimer) { float FireDelay; - - if(!m_TuneZone) - Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay); - else - TuningList()[m_TuneZone].Get(38 + m_Core.m_ActiveWeapon, &FireDelay); + GetTuning(m_TuneZone)->Get(38 + m_Core.m_ActiveWeapon, &FireDelay); m_ReloadTimer = FireDelay * GameWorld()->GameTickSpeed() / 1000; } @@ -923,10 +896,7 @@ void CCharacter::HandleTuneLayer() int CurrentIndex = Collision()->GetMapIndex(m_Pos); m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(CurrentIndex) : 0; - if(m_TuneZone) - m_Core.m_pWorld->m_Tuning[g_Config.m_ClDummy] = TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore - else - m_Core.m_pWorld->m_Tuning[g_Config.m_ClDummy] = GameWorld()->m_Tuning[g_Config.m_ClDummy]; + m_Core.m_pWorld->m_Tuning[g_Config.m_ClDummy] = *GetTuning(m_TuneZone); // throw tunings (from specific zone if in a tunezone) into gamecore } void CCharacter::DDRaceTick() diff --git a/src/game/client/prediction/entities/laser.cpp b/src/game/client/prediction/entities/laser.cpp index 65e5a4831..b811515fc 100644 --- a/src/game/client/prediction/entities/laser.cpp +++ b/src/game/client/prediction/entities/laser.cpp @@ -20,7 +20,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner m_TelePos = vec2(0,0); m_WasTele = false; m_Type = Type; - m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos)); + m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0; GameWorld()->InsertEntity(this); DoBounce(); } @@ -46,12 +46,7 @@ bool CLaser::HitCharacter(vec2 From, vec2 To) { vec2 Temp; - float Strength; - if (!m_TuneZone) - Strength = GameWorld()->Tuning()->m_ShotgunStrength; - else - Strength = GameWorld()->TuningList()[m_TuneZone].m_ShotgunStrength; - + float Strength = GetTuning(m_TuneZone)->m_ShotgunStrength; if(!g_Config.m_SvOldLaser) Temp = pHit->Core()->m_Vel + normalize(m_PrevPos - pHit->Core()->m_Pos) * Strength; @@ -125,18 +120,12 @@ void CLaser::DoBounce() m_Pos = TempPos; m_Dir = normalize(TempDir); - if(!m_TuneZone) - m_Energy -= distance(m_From, m_Pos) + GameWorld()->Tuning()->m_LaserBounceCost; - else - m_Energy -= distance(m_From, m_Pos) + GameWorld()->TuningList()[m_TuneZone].m_LaserBounceCost; - + m_Energy -= distance(m_From, m_Pos) + GetTuning(m_TuneZone)->m_LaserBounceCost; m_Bounces++; m_WasTele = false; - int BounceNum = GameWorld()->Tuning()->m_LaserBounceNum; - if(m_TuneZone) - BounceNum = GameWorld()->TuningList()[m_TuneZone].m_LaserBounceNum; + int BounceNum = GetTuning(m_TuneZone)->m_LaserBounceNum; if(m_Bounces > BounceNum) m_Energy = -1; @@ -155,11 +144,7 @@ void CLaser::DoBounce() void CLaser::Tick() { - float Delay; - if(m_TuneZone) - Delay = GameWorld()->TuningList()[m_TuneZone].m_LaserBounceDelay; - else - Delay = GameWorld()->Tuning()->m_LaserBounceDelay; + float Delay = GetTuning(m_TuneZone)->m_LaserBounceDelay; if(GameWorld()->m_WorldConfig.m_IsVanilla) // predict old physics on vanilla 0.6 servers { @@ -181,8 +166,9 @@ CLaser::CLaser(CGameWorld *pGameWorld, int ID, CNetObj_Laser *pLaser) m_From.x = pLaser->m_FromX; m_From.y = pLaser->m_FromY; m_EvalTick = pLaser->m_StartTick; + m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0; m_Owner = -2; - m_Energy = pGameWorld->Tuning()->m_LaserReach; + m_Energy = GetTuning(m_TuneZone)->m_LaserReach; if(pGameWorld->m_WorldConfig.m_IsFNG && m_Energy < 10.f) m_Energy = 800.0f; @@ -193,7 +179,6 @@ CLaser::CLaser(CGameWorld *pGameWorld, int ID, CNetObj_Laser *pLaser) m_Energy = 0; m_Type = WEAPON_RIFLE; m_PrevPos = m_From; - m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos)); m_ID = ID; } diff --git a/src/game/client/prediction/entities/projectile.cpp b/src/game/client/prediction/entities/projectile.cpp index 5ef3e1060..b512431e6 100644 --- a/src/game/client/prediction/entities/projectile.cpp +++ b/src/game/client/prediction/entities/projectile.cpp @@ -38,7 +38,7 @@ CProjectile::CProjectile m_Number = Number; m_Freeze = Freeze; - m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos)); + m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0; GameWorld()->InsertEntity(this); } @@ -47,48 +47,23 @@ vec2 CProjectile::GetPos(float Time) { float Curvature = 0; float Speed = 0; + CTuningParams *pTuning = GetTuning(m_TuneZone); switch(m_Type) { case WEAPON_GRENADE: - if(!m_TuneZone) - { - Curvature = Tuning()->m_GrenadeCurvature; - Speed = Tuning()->m_GrenadeSpeed; - } - else - { - Curvature = TuningList()[m_TuneZone].m_GrenadeCurvature; - Speed = TuningList()[m_TuneZone].m_GrenadeSpeed; - } - + Curvature = pTuning->m_GrenadeCurvature; + Speed = pTuning->m_GrenadeSpeed; break; case WEAPON_SHOTGUN: - if(!m_TuneZone) - { - Curvature = Tuning()->m_ShotgunCurvature; - Speed = Tuning()->m_ShotgunSpeed; - } - else - { - Curvature = TuningList()[m_TuneZone].m_ShotgunCurvature; - Speed = TuningList()[m_TuneZone].m_ShotgunSpeed; - } - + Curvature = pTuning->m_ShotgunCurvature; + Speed = pTuning->m_ShotgunSpeed; break; case WEAPON_GUN: - if(!m_TuneZone) - { - Curvature = Tuning()->m_GunCurvature; - Speed = Tuning()->m_GunSpeed; - } - else - { - Curvature = TuningList()[m_TuneZone].m_GunCurvature; - Speed = TuningList()[m_TuneZone].m_GunSpeed; - } + Curvature = pTuning->m_GunCurvature; + Speed = pTuning->m_GunSpeed; break; } @@ -197,21 +172,21 @@ CProjectile::CProjectile(CGameWorld *pGameWorld, int ID, CNetObj_Projectile *pPr } m_Type = m_Weapon = pProj->m_Type; m_StartTick = pProj->m_StartTick; + m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0; int Lifetime = 20 * GameWorld()->GameTickSpeed(); m_SoundImpact = -1; if(m_Weapon == WEAPON_GRENADE) { - Lifetime = pGameWorld->Tuning()->m_GrenadeLifetime * GameWorld()->GameTickSpeed(); + Lifetime = GetTuning(m_TuneZone)->m_GrenadeLifetime * GameWorld()->GameTickSpeed(); m_SoundImpact = SOUND_GRENADE_EXPLODE; } else if(m_Weapon == WEAPON_GUN) - Lifetime = pGameWorld->Tuning()->m_GunLifetime * GameWorld()->GameTickSpeed(); + Lifetime = GetTuning(m_TuneZone)->m_GunLifetime * GameWorld()->GameTickSpeed(); else if(m_Weapon == WEAPON_SHOTGUN && !GameWorld()->m_WorldConfig.m_IsDDRace) - Lifetime = pGameWorld->Tuning()->m_ShotgunLifetime * GameWorld()->GameTickSpeed(); + Lifetime = GetTuning(m_TuneZone)->m_ShotgunLifetime * GameWorld()->GameTickSpeed(); m_LifeSpan = Lifetime - (pGameWorld->GameTick() - m_StartTick); m_ID = ID; - m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos)); } void CProjectile::FillInfo(CNetObj_Projectile *pProj) diff --git a/src/game/client/prediction/entity.h b/src/game/client/prediction/entity.h index 1e32b2b2c..1a3070b7a 100644 --- a/src/game/client/prediction/entity.h +++ b/src/game/client/prediction/entity.h @@ -41,6 +41,7 @@ public: class CGameWorld *GameWorld() { return m_pGameWorld; } CTuningParams *Tuning() { return GameWorld()->Tuning(); } CTuningParams *TuningList() { return GameWorld()->TuningList(); } + CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); } class CCollision *Collision() { return GameWorld()->Collision(); } CEntity *TypeNext() { return m_pNextTypeEntity; } CEntity *TypePrev() { return m_pPrevTypeEntity; } diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index 4a4fe3695..16b76edbb 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -281,7 +281,7 @@ void CGameWorld::ReleaseHooked(int ClientID) CTuningParams *CGameWorld::Tuning() { - return &m_Core.m_Tuning[g_Config.m_ClDummy]; + return &m_Tuning[g_Config.m_ClDummy]; } CEntity *CGameWorld::GetEntity(int ID, int EntType) diff --git a/src/game/client/prediction/gameworld.h b/src/game/client/prediction/gameworld.h index 91c108788..0acaca47f 100644 --- a/src/game/client/prediction/gameworld.h +++ b/src/game/client/prediction/gameworld.h @@ -91,6 +91,7 @@ public: CTuningParams m_Tuning[2]; CTuningParams *m_pTuningList; CTuningParams *TuningList() { return m_pTuningList; } + CTuningParams *GetTuning(int i) { return i == 0 ? Tuning() : &TuningList()[i]; } private: void RemoveEntities();