Skip to content
Permalink
Browse files

Melee Weapons: Code formatted

No actual changes, just added spaces and brackets for improved readability
  • Loading branch information
gitMarky committed Mar 19, 2018
1 parent aea27f8 commit 69d6b2e8d27d4af4441dced8221086801284d887
Showing with 98 additions and 75 deletions.
  1. +98 −75 planet/Objects.ocd/Libraries.ocd/MeleeWeapons.ocd/Script.c
@@ -21,14 +21,14 @@ func CheckStrike()

public func CanStrikeWithWeapon(clonk)
{
if(!(clonk->~IsClonk())) return false;
if (!(clonk->~IsClonk())) return false;

if(GetEffect("*WeaponCooldown*", clonk))
if (GetEffect("*WeaponCooldown*", clonk))
{
return false;
}

if(GetEffect("*WeaponCharge", clonk))
if (GetEffect("*WeaponCharge", clonk))
{
return false;
}
@@ -38,21 +38,21 @@ public func CanStrikeWithWeapon(clonk)

func FxDelayTranslateVelocityTimer(pTarget, effect, iEffectTime)
{
if(pTarget->GetContact(-1) & CNAT_Bottom) return -1;
if (pTarget->GetContact(-1) & CNAT_Bottom) return -1;
return 1;
}

func FxDelayTranslateVelocityStop(pTarget, effect, reason, temp)
{
if(temp) return;
if(!(pTarget->GetContact(-1) & CNAT_Bottom))
if(Sqrt(pTarget->GetXDir()**2 + pTarget->GetYDir()**2) > 10)
pTarget->SetSpeed(pTarget->GetXDir()/3, pTarget->GetYDir()/3);
if (temp) return;
if (!(pTarget->GetContact(-1) & CNAT_Bottom))
if (Sqrt(pTarget->GetXDir() ** 2 + pTarget->GetYDir() ** 2) > 10)
pTarget->SetSpeed(pTarget->GetXDir() / 3, pTarget->GetYDir() / 3);
}

func FxIntWeaponChargeStart(pTarget, effect, iTemp, length)
{
if(iTemp) return;
if (iTemp) return;

// saved velocity
effect.velocity = 0;
@@ -62,10 +62,10 @@ func FxIntWeaponChargeStart(pTarget, effect, iTemp, length)

func FxIntWeaponChargeTimer(pTarget, effect, iEffectTime)
{
if(this->Contained() != pTarget) return -1;
if(!pTarget->~IsWalking() && !pTarget->~IsJumping()) return -1;
var strikeTime=effect.length;
if(strikeTime != -1 && iEffectTime > strikeTime)
if (this->Contained() != pTarget) return -1;
if (!pTarget->~IsWalking() && !pTarget->~IsJumping()) return -1;
var strikeTime = effect.length;
if (strikeTime != -1 && iEffectTime > strikeTime)
{
this->~WeaponStrikeExpired();
return -1;
@@ -75,14 +75,13 @@ func FxIntWeaponChargeTimer(pTarget, effect, iEffectTime)

func FxIntWeaponChargeStop(pTarget, effect, iReason, iTemp)
{
if(iTemp) return;
if(!pTarget) return;
if(this)
if (iTemp) return;
if (!pTarget) return;
if (this)
{
this->StopWeaponAnimation(pTarget);
this->~OnWeaponHitCheckStop(pTarget);
}

}

func FxIntWeaponChargeAddWeaponSlow(pTarget, effect, iStrength)
@@ -107,7 +106,7 @@ func FxIntWeaponChargeHitByWeapon(pTarget, effect)

func FxIntIsBeingStruckStart(pTarget, effect, iTemp, iDamage, angle, object from)
{
if(iTemp) return;
if (iTemp) return;
effect.delay = 3;
effect.damage = iDamage;
effect.angle = angle;
@@ -119,22 +118,25 @@ func FxIntIsBeingStruckStart(pTarget, effect, iTemp, iDamage, angle, object from

func FxIntIsBeingStruckTimer(pTarget, effect, iEffectTime)
{
if(effect.delay -- == 0)
if (effect.delay-- == 0)
{
// FALCON PUNCH
if(pTarget->GetContact(-1) & CNAT_Bottom)
if (pTarget->GetContact(-1) & CNAT_Bottom)
{
if(!pTarget->Stuck())
if (!pTarget->Stuck())
{
pTarget->SetPosition(pTarget->GetX(), pTarget->GetY()-1);
if(pTarget->Stuck()) pTarget->SetPosition(pTarget->GetX(), pTarget->GetY()+1);
pTarget->SetPosition(pTarget->GetX(), pTarget->GetY() - 1);
if (pTarget->Stuck())
{
pTarget->SetPosition(pTarget->GetX(), pTarget->GetY() + 1);
}
}
if(effect.damage > 60)
if (effect.damage > 60)
pTarget->Fling();
}

pTarget->SetXDir(Sin(effect.angle, effect.damage ), 100);
pTarget->SetYDir(-Abs(Cos(effect.angle, effect.damage )), 100);
pTarget->SetXDir(Sin(effect.angle, effect.damage), 100);
pTarget->SetYDir(-Abs(Cos(effect.angle, effect.damage)), 100);

// in case the object is flung down a cliff
if (effect.from_player != NO_OWNER)
@@ -147,28 +149,36 @@ func FxIntIsBeingStruckTimer(pTarget, effect, iEffectTime)

func FxIntIsBeingStruckEffect(string szNewEffectName, object pTarget)
{
if(szNewEffectName == "IntIsBeingStruck") return -2;
if (szNewEffectName == "IntIsBeingStruck") return -2;
return 0;
}

func FxIntIsBeingStruckAdd (object pTarget, effect, string szNewEffectName, int iNewEffectTimer, int damage, int angle)
func FxIntIsBeingStruckAdd(object pTarget, effect, string szNewEffectName, int iNewEffectTimer, int damage, int angle)
{
// reset delay
effect.delay = 3;

// add damage!
if(damage > effect.damage)
if (damage > effect.damage)
{
effect.damage = damage;
}
else
effect.var1 = (effect.damage*2 + damage) / 2;
{
effect.var1 = (effect.damage * 2 + damage) / 2;
}

// check angle
if(!effect.angle)
if (!effect.angle)
{
effect.angle = angle;
else if(angle)
}
else if (angle)
{
// should actually set the new angle to the average between the old and the new one. but I don't feel like doing such calculations now
// let's see if anyone notices it
effect.angle = angle;
}
}

func GetStrikeAnimation()
@@ -179,61 +189,74 @@ func GetStrikeAnimation()

func StopWeaponAnimation(pTarget)
{
if(hWeaponAnimStrike == nil) return;
if (hWeaponAnimStrike == nil)
return;
pTarget->StopAnimation(hWeaponAnimStrike);
hWeaponAnimStrike = nil;
}

func PlayWeaponAnimation(pTarget)
{
if(hWeaponAnimStrike != nil) StopWeaponAnimation(pTarget);
if (hWeaponAnimStrike != nil)
{
StopWeaponAnimation(pTarget);
}
hWeaponAnimStrike = pTarget->PlayAnimation(...);
}


func GetRelativeVelocity(pObject1, pObject2)
{
var b=0;
var xVel=Abs(pObject1->GetXDir());
if(BoundBy(pObject1->GetXDir(), -1, 1) != BoundBy(pObject2->GetXDir(), -1, 1))
xVel+=Abs(pObject2->GetXDir());
else xVel-=Abs(pObject2->GetXDir());
var b = 0;
var xVel = Abs(pObject1->GetXDir());
if (BoundBy(pObject1->GetXDir(), -1, 1) != BoundBy(pObject2->GetXDir(), -1, 1))
{
xVel += Abs(pObject2->GetXDir());
}
else
{
xVel -= Abs(pObject2->GetXDir());
}

var yVel=Abs(pObject1->GetYDir());
if(BoundBy(pObject1->GetYDir(), -1, 1) != BoundBy(pObject2->GetYDir(), -1, 1))
yVel+=Abs(pObject2->GetYDir());
else yVel-=Abs(pObject2->GetYDir());
b = Sqrt((xVel**2)+(yVel**2));
var yVel = Abs(pObject1->GetYDir());
if (BoundBy(pObject1->GetYDir(), -1, 1) != BoundBy(pObject2->GetYDir(), -1, 1))
{
yVel += Abs(pObject2->GetYDir());
}
else
{
yVel -= Abs(pObject2->GetYDir());
}
b = Sqrt((xVel ** 2) + (yVel ** 2));
return b;
}

func ApplyShieldFactor(pFrom, pTo, damage)
{
// totally prevent the strike?
if(pTo->~QueryCatchBlow(pFrom)) return 100;
if (pTo->~QueryCatchBlow(pFrom)) return 100;

var state=0;
var shield=-1;
for(;state <= 1;state++)
var state = 0;
var shield = -1;
for (; state <= 1; state++)
{
var effect_name="*Shield*";
if(state == 1) effect_name="IntWeaponCharge";
var effect_name = "*Shield*";
if (state == 1) effect_name = "IntWeaponCharge";
var iEffect;
var i=0;
while(iEffect=GetEffect(effect_name, pTo, i++))
var i = 0;
while (iEffect = GetEffect(effect_name, pTo, i++))
{
var s=EffectCall(pTo, iEffect, "HitByWeapon", pFrom, damage);
if(s && shield == -1) shield=s;
else if(s)
var s = EffectCall(pTo, iEffect, "HitByWeapon", pFrom, damage);
if (s && shield == -1) shield = s;
else if (s)
{
shield=(100-(((100-s)*(100-shield))/100));
shield = (100 - (((100 - s) * (100 - shield)) / 100));
}

}
}

if(shield == -1) return 0;

if (shield == -1) return 0;
return shield;
}

@@ -244,30 +267,30 @@ func StartWeaponHitCheckEffect(pClonk, iLength, iInterval)

func StopWeaponHitCheckEffect(pClonk)
{
if(GetEffect("IntWeaponCharge", pClonk))
if (GetEffect("IntWeaponCharge", pClonk))
RemoveEffect("IntWeaponCharge", pClonk);
}

func DoWeaponSlow(pClonk, iStrength)
{
var e=GetEffect("IntWeaponCharge", pClonk);
var s=Sqrt( (pClonk->GetXDir(1000)) ** 2 + (pClonk->GetYDir(1000)) ** 2);
var angle=Angle(0,0,pClonk->GetXDir(), pClonk->GetYDir());
var e = GetEffect("IntWeaponCharge", pClonk);
var s = Sqrt((pClonk->GetXDir(1000)) ** 2 + (pClonk->GetYDir(1000)) ** 2);
var angle = Angle(0, 0, pClonk->GetXDir(), pClonk->GetYDir());

s-=iStrength;
if(s < 0) s=0;
s -= iStrength;
if (s < 0) s = 0;
pClonk->SetXDir(Sin(angle, s), 1000);
pClonk->SetYDir(-Cos(angle, s), 1000);

if(e)
if (e)
EffectCall(nil, e, "AddWeaponSlow", iStrength);
return true;
}

func GetWeaponSlow(pClonk)
{
var e=GetEffect("IntWeaponCharge", pClonk);
if(!e) return 0;
var e = GetEffect("IntWeaponCharge", pClonk);
if (!e) return 0;
return EffectCall(nil, e, "GetWeaponSlow");
}

@@ -279,14 +302,14 @@ func ApplyWeaponBash(pTo, int strength, angle, object from)

func TranslateVelocity(object pTarget, int angle, int iLimited, int iExtraVelocity)
{
var speed=Sqrt((pTarget->GetXDir(100) ** 2) + (pTarget->GetYDir(100) ** 2)) + iExtraVelocity;
var a=Angle(0, 0, pTarget->GetXDir(), pTarget->GetYDir());
var speed = Sqrt((pTarget->GetXDir(100) ** 2) + (pTarget->GetYDir(100) ** 2)) + iExtraVelocity;
var a = Angle(0, 0, pTarget->GetXDir(), pTarget->GetYDir());

if(iLimited)
if (iLimited)
{
angle+=360;
a+=360;
angle=BoundBy(angle, a-iLimited, a+iLimited);
angle += 360;
a += 360;
angle = BoundBy(angle, a - iLimited, a + iLimited);
}

pTarget->SetXDir(Sin(angle, speed), 100);

0 comments on commit 69d6b2e

Please sign in to comment.
You can’t perform that action at this time.