Optimize code flow

This commit is contained in:
Shtoyan 2023-04-09 14:30:28 +04:00
parent 2f3385583c
commit 3b5f46c2b5

View File

@ -332,22 +332,15 @@ function Actor GetMainActor(Actor other) {
return none; return none;
} }
if (!other.IsA('KFPawn') && !other.IsA('KFMonster')) {
// Try owner // Try owner
if ( if (other.owner.IsA('KFPawn') || other.owner.IsA('KFMonster')) {
KFPawn(other) == none && return other.owner;
KFMonster(other) == none &&
(KFPawn(other.owner) != none || KFMonster(other.owner) != none)
) {
other = other.owner;
} }
// Try base // Try base
if ( if (other.base.IsA('KFPawn') || other.base.IsA('KFMonster')) {
KFPawn(other) == none && return other.base;
KFMonster(other) == none && }
(KFPawn(other.base) != none || KFMonster(other.base) != none)
) {
other = other.base;
} }
return other; return other;
@ -694,16 +687,19 @@ function DoProcessMovement(float delta) {
} }
function Stick(Actor target, Vector hitLocation) { function Stick(Actor target, Vector hitLocation) {
local NiceMonster targetZed;
local name boneStick;
local float distToBone;
local float t;
local Vector boneStrickOrig; local Vector boneStrickOrig;
local ExplosionData expData; local ExplosionData expData;
local Actor resultTarget;
local NiceMonster targetZed;
local name boneStick;
local float distToBone, t;
if (bGhost) { if (bGhost) {
return; return;
} }
expData.instigator = instigator;
expData.sourceWeapon = sourceWeapon;
expData.bulletClass = class;
expData.explosionDamageType = charExplosionDamageType; expData.explosionDamageType = charExplosionDamageType;
expData.explosionDamage = charExplosionDamage; expData.explosionDamage = charExplosionDamage;
expData.explosionRadius = charExplosionRadius; expData.explosionRadius = charExplosionRadius;
@ -712,31 +708,13 @@ function Stick(Actor target, Vector hitLocation) {
expData.fuseTime = charFuseTime; expData.fuseTime = charFuseTime;
expData.explodeOnFuse = charExplodeOnFuse; expData.explodeOnFuse = charExplodeOnFuse;
expData.affectedByScream = charAffectedByScream; expData.affectedByScream = charAffectedByScream;
expData.sourceWeapon = sourceWeapon;
targetZed = NiceMonster(target);
if (targetZed == none) { if (!target.IsA('NiceMonster')) {
expData.bulletClass = class; hitLocation -= target.location;
expData.instigator = instigator; boneStick = 'None';
niceRI.ServerStickProjectile( resultTarget = target;
KFHumanPawn(instigator),
target,
'None',
hitLocation - target.location,
Rotator(movementDirection),
expData
);
class'NiceProjectileSpawner'.static.StickProjectile(
KFHumanPawn(instigator),
target,
'None',
hitLocation - target.location,
Rotator(movementDirection),
expData
);
} else { } else {
expData.bulletClass = class; targetZed = NiceMonster(target);
expData.instigator = instigator;
boneStick = targetZed.GetClosestBone(hitLocation, movementDirection, distToBone); boneStick = targetZed.GetClosestBone(hitLocation, movementDirection, distToBone);
if (CheckHeadshot(targetZed, hitLocation, movementDirection) > 0.0) { if (CheckHeadshot(targetZed, hitLocation, movementDirection) > 0.0) {
boneStick = targetZed.HeadBone; boneStick = targetZed.HeadBone;
@ -751,23 +729,27 @@ function Stick(Actor target, Vector hitLocation) {
t /= VSizeSquared(movementDirection); t /= VSizeSquared(movementDirection);
t *= 0.5; t *= 0.5;
hitLocation = hitLocation + t * movementDirection; hitLocation = hitLocation + t * movementDirection;
hitLocation -= boneStrickOrig;
resultTarget = targetZed;
}
niceRI.ServerStickProjectile( niceRI.ServerStickProjectile(
KFHumanPawn(instigator), KFHumanPawn(instigator),
targetZed, resultTarget,
boneStick, boneStick,
hitLocation - boneStrickOrig, hitLocation,
Rotator(movementDirection), Rotator(movementDirection),
expData expData
); );
class'NiceProjectileSpawner'.static.StickProjectile( class'NiceProjectileSpawner'.static.StickProjectile(
KFHumanPawn(instigator), KFHumanPawn(instigator),
targetZed, resultTarget,
boneStick, boneStick,
hitLocation - boneStrickOrig, hitLocation,
Rotator(movementDirection), Rotator(movementDirection),
expData expData
); );
}
KillBullet(); KillBullet();
} }