From 3b5f46c2b5b5be568468f2ab1fa410baba7fa31a Mon Sep 17 00:00:00 2001 From: Shtoyan Date: Sun, 9 Apr 2023 14:30:28 +0400 Subject: [PATCH] Optimize code flow --- sources/Weapons/NiceBullet.uc | 100 ++++++++++++++-------------------- 1 file changed, 41 insertions(+), 59 deletions(-) diff --git a/sources/Weapons/NiceBullet.uc b/sources/Weapons/NiceBullet.uc index d402fd7..8e03861 100644 --- a/sources/Weapons/NiceBullet.uc +++ b/sources/Weapons/NiceBullet.uc @@ -332,22 +332,15 @@ function Actor GetMainActor(Actor other) { return none; } - // Try owner - if ( - KFPawn(other) == none && - KFMonster(other) == none && - (KFPawn(other.owner) != none || KFMonster(other.owner) != none) - ) { - other = other.owner; - } - - // Try base - if ( - KFPawn(other) == none && - KFMonster(other) == none && - (KFPawn(other.base) != none || KFMonster(other.base) != none) - ) { - other = other.base; + if (!other.IsA('KFPawn') && !other.IsA('KFMonster')) { + // Try owner + if (other.owner.IsA('KFPawn') || other.owner.IsA('KFMonster')) { + return other.owner; + } + // Try base + if (other.base.IsA('KFPawn') || other.base.IsA('KFMonster')) { + return other.base; + } } return other; @@ -694,16 +687,19 @@ function DoProcessMovement(float delta) { } function Stick(Actor target, Vector hitLocation) { - local NiceMonster targetZed; - local name boneStick; - local float distToBone; - local float t; local Vector boneStrickOrig; local ExplosionData expData; + local Actor resultTarget; + local NiceMonster targetZed; + local name boneStick; + local float distToBone, t; if (bGhost) { return; } + expData.instigator = instigator; + expData.sourceWeapon = sourceWeapon; + expData.bulletClass = class; expData.explosionDamageType = charExplosionDamageType; expData.explosionDamage = charExplosionDamage; expData.explosionRadius = charExplosionRadius; @@ -712,31 +708,13 @@ function Stick(Actor target, Vector hitLocation) { expData.fuseTime = charFuseTime; expData.explodeOnFuse = charExplodeOnFuse; expData.affectedByScream = charAffectedByScream; - expData.sourceWeapon = sourceWeapon; - targetZed = NiceMonster(target); - if (targetZed == none) { - expData.bulletClass = class; - expData.instigator = instigator; - niceRI.ServerStickProjectile( - KFHumanPawn(instigator), - target, - 'None', - hitLocation - target.location, - Rotator(movementDirection), - expData - ); - class'NiceProjectileSpawner'.static.StickProjectile( - KFHumanPawn(instigator), - target, - 'None', - hitLocation - target.location, - Rotator(movementDirection), - expData - ); + if (!target.IsA('NiceMonster')) { + hitLocation -= target.location; + boneStick = 'None'; + resultTarget = target; } else { - expData.bulletClass = class; - expData.instigator = instigator; + targetZed = NiceMonster(target); boneStick = targetZed.GetClosestBone(hitLocation, movementDirection, distToBone); if (CheckHeadshot(targetZed, hitLocation, movementDirection) > 0.0) { boneStick = targetZed.HeadBone; @@ -751,23 +729,27 @@ function Stick(Actor target, Vector hitLocation) { t /= VSizeSquared(movementDirection); t *= 0.5; hitLocation = hitLocation + t * movementDirection; - niceRI.ServerStickProjectile( - KFHumanPawn(instigator), - targetZed, - boneStick, - hitLocation - boneStrickOrig, - Rotator(movementDirection), - expData - ); - class'NiceProjectileSpawner'.static.StickProjectile( - KFHumanPawn(instigator), - targetZed, - boneStick, - hitLocation - boneStrickOrig, - Rotator(movementDirection), - expData - ); + hitLocation -= boneStrickOrig; + resultTarget = targetZed; } + + niceRI.ServerStickProjectile( + KFHumanPawn(instigator), + resultTarget, + boneStick, + hitLocation, + Rotator(movementDirection), + expData + ); + class'NiceProjectileSpawner'.static.StickProjectile( + KFHumanPawn(instigator), + resultTarget, + boneStick, + hitLocation, + Rotator(movementDirection), + expData + ); + KillBullet(); }