From 97ecd622144d23e56f88c41e28262b8f34e0302d Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Mon, 16 Jul 2018 00:43:54 +0200 Subject: [PATCH] fix timakro review --- src/game/server/entities/laser.cpp | 49 ++++++++++++------------- src/game/server/entities/projectile.cpp | 7 ++-- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index b9ed5a479..64dde9499 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -166,39 +166,36 @@ void CLaser::DoBounce() } } - if (m_Owner >= 0 && m_Energy <= 0 && m_Pos && !m_TeleportCancelled) + CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner); + if (m_Owner >= 0 && m_Energy <= 0 && m_Pos && !m_TeleportCancelled && pOwnerChar && + pOwnerChar->IsAlive() && pOwnerChar->m_HasTeleLaser && m_Type == WEAPON_RIFLE) { - CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner); + vec2 PossiblePos; + bool Found = false; - if (pOwnerChar && pOwnerChar->IsAlive() && pOwnerChar->m_HasTeleLaser && m_Type == WEAPON_RIFLE) + // Check if the laser hits a player. + bool pDontHitSelf = g_Config.m_SvOldLaser || (m_Bounces == 0 && !m_WasTele); + vec2 At; + CCharacter *pHit; + if (pOwnerChar ? (!(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_RIFLE) && m_Type == WEAPON_RIFLE) : g_Config.m_SvHit) + pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pDontHitSelf ? pOwnerChar : 0, m_Owner); + else + pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pDontHitSelf ? pOwnerChar : 0, m_Owner, pOwnerChar); + + if (pHit) + Found = GetNearestAirPosPlayer(pHit->m_Pos, &PossiblePos); + else + Found = GetNearestAirPos(m_Pos, m_From, &PossiblePos); + + if (Found && PossiblePos) { - vec2 PossiblePos; - bool Found = false; - - // Check if the laser hits a player. - bool pDontHitSelf = g_Config.m_SvOldLaser || (m_Bounces == 0 && !m_WasTele); - vec2 At; - CCharacter *pHit; - if(pOwnerChar ? (!(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_RIFLE) && m_Type == WEAPON_RIFLE) : g_Config.m_SvHit) - pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pDontHitSelf ? pOwnerChar : 0, m_Owner); - else - pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pDontHitSelf ? pOwnerChar : 0, m_Owner, pOwnerChar); - - if(pHit) - Found = GetNearestAirPosPlayer(pHit->m_Pos, &PossiblePos); - else - Found = GetNearestAirPos(m_Pos, m_From, &PossiblePos); - - if (Found && PossiblePos) - { - pOwnerChar->m_TeleGunPos = PossiblePos; - pOwnerChar->m_TeleGunTeleport = true; - } + pOwnerChar->m_TeleGunPos = PossiblePos; + pOwnerChar->m_TeleGunTeleport = true; } } else if(m_Owner >= 0 && m_Pos) { - int MapIndex = GameServer()->Collision()->GetPureMapIndex(round_to_int(Coltile.x), round_to_int(Coltile.y)); + int MapIndex = GameServer()->Collision()->GetPureMapIndex(Coltile); int TileIndex = GameServer()->Collision()->GetTileIndex(MapIndex); int TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex); diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index 4ac148cec..edecda386 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -122,7 +122,7 @@ void CProjectile::Tick() CCharacter *pTargetChr = nullptr; - if(!(pOwnerChar ? (pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit)) + if((pOwnerChar ? !(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit)) pTargetChr = GameServer()->m_World.IntersectCharacter(PrevPos, ColPos, m_Freeze ? 1.0f : 6.0f, ColPos, pOwnerChar, m_Owner); if(m_LifeSpan > -1) @@ -174,12 +174,11 @@ void CProjectile::Tick() if (pOwnerChar && ColPos && !GameLayerClipped(ColPos) && ((m_Type == WEAPON_GRENADE && pOwnerChar->m_HasTeleGrenade) || (m_Type == WEAPON_GUN && pOwnerChar->m_HasTeleGun))) { - int MapIndex = GameServer()->Collision()->GetPureMapIndex(pTargetChr ? pTargetChr->m_Pos.x : ColPos.x, - pTargetChr ? pTargetChr->m_Pos.y : ColPos.y); + int MapIndex = GameServer()->Collision()->GetPureMapIndex(pTargetChr ? pTargetChr->m_Pos : ColPos); int TileIndex = GameServer()->Collision()->GetTileIndex(MapIndex); int TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex); - if ((m_Type == WEAPON_GUN || m_Type == WEAPON_GRENADE) && (TileIndex != TILE_NO_TELE_GUN && TileFIndex != TILE_NO_TELE_GUN)) + if (TileIndex != TILE_NO_TELE_GUN && TileFIndex != TILE_NO_TELE_GUN) { bool Found; vec2 PossiblePos;