Skip to content

Commit

Permalink
AimManager: Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
gitMarky committed Jun 10, 2019
1 parent a4be544 commit 6881722
Showing 1 changed file with 115 additions and 52 deletions.
167 changes: 115 additions & 52 deletions planet/Objects.ocd/Libraries.ocd/AimManager.ocd/Script.c
Expand Up @@ -80,26 +80,26 @@ func IsAiming() { return !!GetEffect("IntAim", this); }

func FxIntAimCheckProcedureStart(target, effect, tmp)
{
if(tmp) return;
if (tmp) return;
}

func FxIntAimCheckProcedureTimer()
{
// Care about the aim schedules
if(aim_schedule_timer != nil)
if (aim_schedule_timer != nil)
{
aim_schedule_timer--;
if(aim_schedule_timer == 0)
if (aim_schedule_timer == 0)
{
Call(aim_schedule_call);
aim_schedule_call = nil;
aim_schedule_timer = nil;
}
}
if(aim_schedule_timer2 != nil)
if (aim_schedule_timer2 != nil)
{
aim_schedule_timer2--;
if(aim_schedule_timer2 == 0)
if (aim_schedule_timer2 == 0)
{
Call(aim_schedule_call2);
aim_schedule_call2 = nil;
Expand All @@ -108,20 +108,25 @@ func FxIntAimCheckProcedureTimer()
}

// check procedure
if(!ReadyToAction())
if (!ReadyToAction())
PauseAim();
}

func FxIntAimCheckProcedureStop(target, effect, reason, tmp)
{
if(tmp) return;
if(reason == 4)
if (tmp) return;
if (reason == 4)
{
CancelAiming();
}
}

func PauseAim()
{
if(!aim_weapon || aim_stop) return CancelAiming();
if (!aim_weapon || aim_stop)
{
return CancelAiming();
}
// reissue the CON_Use command to the weapon when ready
this->PauseUse(aim_weapon);
CancelAiming();
Expand All @@ -130,11 +135,17 @@ func PauseAim()
public func StartLoad(object weapon)
{
// only if we aren't adjusted to this weapon already
if(weapon != aim_weapon)
if (weapon != aim_weapon)
{
// Reset old
if(aim_weapon != nil) aim_weapon->~Reset();
if(aim_set != nil) ResetHands();
if (aim_weapon != nil)
{
aim_weapon->~Reset();
}
if (aim_set != nil)
{
ResetHands();
}

// Remember new
aim_weapon = weapon;
Expand All @@ -147,13 +158,15 @@ public func StartLoad(object weapon)
AddEffect("IntAimCheckProcedure", this, 1, 1, this);
}

if(aim_set["AnimationLoad"] != nil)
if (aim_set["AnimationLoad"] != nil)
{
PlayAnimation(aim_set["AnimationLoad"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationLoad"]), aim_set["LoadTime"], ANIM_Remove), Anim_Const(1000));
}

aim_schedule_timer = aim_set["LoadTime"];
aim_schedule_call = "StopLoad";

if(aim_set["LoadTime2"] != nil)
if (aim_set["LoadTime2"] != nil)
{
aim_schedule_timer2 = aim_set["LoadTime2"];
aim_schedule_call2 = "DuringLoad";
Expand All @@ -164,18 +177,26 @@ public func DuringLoad() { aim_weapon->~DuringLoad(this); }

public func StopLoad()
{
if(!aim_weapon || !aim_weapon->~FinishedLoading(this)) // return 1 means the weapon goes on doing something (e.g. start aiming) then we don't reset
if (!aim_weapon || !aim_weapon->~FinishedLoading(this)) // return 1 means the weapon goes on doing something (e.g. start aiming) then we don't reset
{
ResetHands();
}
}

public func StartAim(object weapon, int angle)
{
// only if we aren't adjusted to this weapon already
if(weapon != aim_weapon)
if (weapon != aim_weapon)
{
// Reset old
if(aim_weapon != nil) aim_weapon->~Reset();
if(aim_set != nil) ResetHands();
if (aim_weapon != nil)
{
aim_weapon->~Reset();
}
if (aim_set != nil)
{
ResetHands();
}

// Remember new
aim_weapon = weapon;
Expand All @@ -188,11 +209,13 @@ public func StartAim(object weapon, int angle)
AddEffect("IntAimCheckProcedure", this, 1, 1, this);
}

if(aim_set["AnimationAim"] != nil)
if (aim_set["AnimationAim"] != nil)
{
if(aim_set["AimMode"] == AIM_Position)
aim_animation_index = PlayAnimation(aim_set["AnimationAim"], CLONK_ANIM_SLOT_Arms, Anim_Const(GetAnimationLength(aim_set["AnimationAim"])/2), Anim_Const(1000));
if(aim_set["AimMode"] == AIM_Weight)
if (aim_set["AimMode"] == AIM_Position)
{
aim_animation_index = PlayAnimation(aim_set["AnimationAim"], CLONK_ANIM_SLOT_Arms, Anim_Const(GetAnimationLength(aim_set["AnimationAim"]) / 2), Anim_Const(1000));
}
else if (aim_set["AimMode"] == AIM_Weight)
{
aim_animation_index = PlayAnimation(aim_set["AnimationAim"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationAim"]), aim_set["AimTime"], ANIM_Loop), Anim_Const(1000));
aim_animation_index = PlayAnimation(aim_set["AnimationAim2"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationAim2"]), aim_set["AimTime"], ANIM_Loop), Anim_Const(1000), aim_animation_index);
Expand All @@ -207,25 +230,37 @@ func FxIntAimTimer(target, effect, time)
{
var angle, delta_angle, length;
var speed = aim_set["AimSpeed"];
if(speed == nil) speed = 50;
else speed *= 10;
if(aim_angle < 0) SetTurnForced(DIR_Left);
if(aim_angle > 0) SetTurnForced(DIR_Right);
if(aim_set["AimMode"] == AIM_Position)
if (speed == nil)
{
speed = 50;
}
else
{
speed *= 10;
}
if (aim_angle < 0)
{
SetTurnForced(DIR_Left);
}
if (aim_angle > 0)
{
SetTurnForced(DIR_Right);
}
if (aim_set["AimMode"] == AIM_Position)
{
length = GetAnimationLength(aim_set["AnimationAim"]);
angle = Abs(aim_angle)*10;//GetAnimationPosition(aim_animation_index)*1800/length;
angle = Abs(aim_angle) * 10;//GetAnimationPosition(aim_animation_index)*1800/length;
delta_angle = 0;//BoundBy(Abs(aim_angle*10)-angle, -speed, speed);
SetAnimationPosition(aim_animation_index, Anim_Const( (angle+delta_angle)*length/1800 ));
SetAnimationPosition(aim_animation_index, Anim_Const( (angle + delta_angle) * length / 1800 ));
}
if(aim_set["AimMode"] == AIM_Weight)
else if (aim_set["AimMode"] == AIM_Weight)
{
angle = Abs(aim_angle)*10;//GetAnimationWeight(aim_animation_index)*1800/1000;
angle = Abs(aim_angle) * 10;//GetAnimationWeight(aim_animation_index)*1800/1000;
delta_angle = 0;//BoundBy(Abs(aim_angle*10)-angle, -speed, speed);
SetAnimationWeight(aim_animation_index, Anim_Const( (angle+delta_angle)*1000/1800 ));
SetAnimationWeight(aim_animation_index, Anim_Const( (angle + delta_angle) * 1000 / 1800 ));
}
// We have reached the angle and we want to stop
if(Abs(delta_angle) <= 5 && aim_stop == 1)
if (Abs(delta_angle) <= 5 && aim_stop == 1)
{
DoStopAim();
return -1;
Expand Down Expand Up @@ -253,18 +288,26 @@ private func DoStopAim()
{
// Return true means the weapon goes on doing something (e.g. start aiming) then we don't reset.
if (!aim_weapon || !aim_weapon->~FinishedAiming(this, aim_angle))
{
ResetHands();
}
return;
}

public func StartShoot(object weapon)
{
// only if we aren't adjusted to this weapon already
if(weapon != aim_weapon)
if (weapon != aim_weapon)
{
// Reset old
if(aim_weapon != nil) aim_weapon->~Reset();
if(aim_set != nil) ResetHands();
if (aim_weapon != nil)
{
aim_weapon->~Reset();
}
if (aim_set != nil)
{
ResetHands();
}

// Remember new
aim_weapon = weapon;
Expand All @@ -277,13 +320,15 @@ public func StartShoot(object weapon)
AddEffect("IntAimCheckProcedure", this, 1, 1, this);
}

if(aim_set["AnimationShoot"] != nil)
if (aim_set["AnimationShoot"] != nil)
{
// Do we just have one animation? Then just play it
if(aim_set["AnimationShoot2"] == nil)
if (aim_set["AnimationShoot2"] == nil)
{
PlayAnimation(aim_set["AnimationShoot"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationShoot"]), aim_set["ShootTime"], ANIM_Remove), Anim_Const(1000));
}
// Well two animations blend betweend them (animtion 1 is 0° animation2 for 180°)
else if(aim_set["AnimationShoot3"] == nil)
else if (aim_set["AnimationShoot3"] == nil)
{
var iAim;
iAim = PlayAnimation(aim_set["AnimationShoot"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationShoot"] ), aim_set["ShootTime"], ANIM_Remove), Anim_Const(1000));
Expand All @@ -294,7 +339,7 @@ public func StartShoot(object weapon)
else
{
var iAim;
if(Abs(aim_angle) < 90)
if (Abs(aim_angle) < 90)
{
iAim = PlayAnimation(aim_set["AnimationShoot2"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationShoot2"]), aim_set["ShootTime"], ANIM_Remove), Anim_Const(1000));
iAim = PlayAnimation(aim_set["AnimationShoot"], CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, GetAnimationLength(aim_set["AnimationShoot"] ), aim_set["ShootTime"], ANIM_Remove), Anim_Const(1000), iAim);
Expand All @@ -312,7 +357,7 @@ public func StartShoot(object weapon)
aim_schedule_timer = aim_set["ShootTime"];
aim_schedule_call = "StopShoot";

if(aim_set["ShootTime2"] != nil)
if (aim_set["ShootTime2"] != nil)
{
aim_schedule_timer2 = aim_set["ShootTime2"];
aim_schedule_call2 = "DuringShoot";
Expand All @@ -323,8 +368,10 @@ public func DuringShoot() { if (aim_weapon) aim_weapon->~DuringShoot(this, aim_a

public func StopShoot()
{
if(aim_weapon == nil || !aim_weapon->~FinishedShooting(this, aim_angle)) // return 1 means the weapon goes on doing something (e.g. start aiming) then we don't reset
if (aim_weapon == nil || !aim_weapon->~FinishedShooting(this, aim_angle)) // return 1 means the weapon goes on doing something (e.g. start aiming) then we don't reset
{
ResetHands();
}
}

public func CancelAiming()
Expand All @@ -337,32 +384,48 @@ public func ApplySet(set)
// Setting the hands as blocked, so that no other items are carried in the hands
SetHandAction(1);

if(set["TurnType"] != nil)
if (set["TurnType"] != nil)
{
SetTurnType(set["TurnType"], 1);
}

if(set["AnimationReplacements"] != nil)
for(var replace in set["AnimationReplacements"])
if (set["AnimationReplacements"] != nil)
{
for (var replace in set["AnimationReplacements"])
{
ReplaceAction(replace[0], replace[1]);
}
}

if(set["WalkSpeed"] != nil)
if (set["WalkSpeed"] != nil)
{
AddEffect("IntWalkSlow", this, 1, 0, this, nil, set["WalkSpeed"]);
}

if(set["WalkBack"] != nil)
if (set["WalkBack"] != nil)
{
SetBackwardsSpeed(set["WalkBack"]);
}
}

public func ResetHands()
{
if(!GetEffect("IntAimCheckProcedure", this))
if (!GetEffect("IntAimCheckProcedure", this))
{
return;
}

if(aim_weapon != nil)
if (aim_weapon != nil)
{
aim_weapon->~Reset(this);

if(aim_set["AnimationReplacements"] != nil)
for(var replace in aim_set["AnimationReplacements"])
if (aim_set["AnimationReplacements"] != nil)
{
for (var replace in aim_set["AnimationReplacements"])
{
ReplaceAction(replace[0], nil);
}
}
}

aim_stop = 0;
Expand Down Expand Up @@ -395,7 +458,7 @@ public func ResetHands()

func FxIntWalkSlowStart(pTarget, effect, fTmp, iValue)
{
if(iValue == nil) iValue = 84;
iValue = iValue ?? 84;
pTarget->PushActionSpeed("Walk", iValue);
}

Expand Down

0 comments on commit 6881722

Please sign in to comment.