Hideout: Make code more readable

Avoiding duplicate code.
alut-include-path
Mark 2017-01-07 01:30:13 +01:00
parent df031f600e
commit 80b3ceb560
5 changed files with 45 additions and 41 deletions

View File

@ -50,7 +50,6 @@ global func FxGemPyreStart(object target, effect, int temporary, array coordinat
effect.x = coordinates[0];
effect.y = coordinates[1];
effect.e = e;
effect.thrower = thrower_owner;
effect.owner = owner;
effect.objects = [];
@ -78,45 +77,37 @@ global func FxGemPyreTimer(object target, effect, int time)
{
var x = effect.x;
var y = effect.y;
var e = effect.e;
var radius_max = ((time / 2) + 1) * 6;
var radius_min = ((time / 2) + 1) * 4;
if (time > 32) return -1;
for (var i = 0; i < (20 + time); i++)
{
var r = Random(360);
var d = Random((((time / 2) + 1) * 6) - ((time / 2) * 4)) + ((time / 2) * 4) + RandomX(-2, 2);
var d = Random(radius_max - radius_min) + radius_min + RandomX(-2, 2);
var xoff = +Sin(r, d);
var yoff = -Cos(r, d);
if (!PathFree(x, y, x + xoff, y + yoff)) continue;
var color; // TODO: this is not actually used??
if (e)
{
color = RGB(190 + Random(10), 0, 20 + Random(20));
}
else
{
color = RGB(122 + Random(20), 18 + Random(10), 90 + Random(20));
}
CreateParticle("Air", x + xoff, y + yoff, PV_Random(xoff - 3, xoff + 3), PV_Random(yoff - 3, yoff + 3), PV_Random(5, 10), effect.particles, 2);
}
for (var obj in FindObjects(Find_NoContainer(), Find_OCF(OCF_Alive), Find_Distance(((time / 2) + 1) * 6, x, y), Find_Not(Find_Distance((time / 2) * 4, x, y)), Find_ID(Clonk)))
var potential = 30 - time;
for (var obj in FindObjects(Find_NoContainer(), Find_OCF(OCF_Alive), Find_Distance(radius_max, x, y), Find_Not(Find_Distance(radius_min, x, y)), Find_ID(Clonk)))
{
var end = false;
for (var i = 0; i < GetLength(effect.objects); i++)
if (IsValueInArray(effect.objects, obj))
{
if (obj == effect.objects[i]) end = true;
continue;
}
if (end) continue;
if (PathFree(x, y, obj->GetX(), obj->GetY()))
{
obj->DoEnergy((-BoundBy((30-time), 1, 26) * 3) / 5, 0, 0, effect.thrower);
obj->DoEnergy((-BoundBy(potential, 1, 26) * 3) / 5, 0, 0, effect.thrower);
obj->CreateParticle("MagicFire", 0, 0, PV_Random(-15, 15), PV_Random(-15, 15), PV_Random(5, 10), effect.particles, 20);
obj->Fling(RandomX(-2, 2), -2 - (BoundBy((30 - time), 10, 30) / 10));
obj->Fling(RandomX(-2, 2), -2 -(BoundBy(potential, 10, 30) / 10));
effect.objects[GetLength(effect.objects)] = obj;
}
}

View File

@ -65,7 +65,7 @@ global func FxGemShieldCreationStart(object target, effect, int temporary, int x
}
}
global func FxGemShieldCreationTimer(object target, effect, int time)
global func FxGemShieldCreationTimer(object target, proplist effect, int time)
{
if (time > 26) return -1;
var x = effect.x;
@ -82,18 +82,24 @@ global func FxGemShieldCreationTimer(object target, effect, int time)
color = RGB(122 + Random(20), 18 + Random(10), 90 + Random(20));
}
var shield=CreateObjectAbove(CrystalShield, x + Sin(time * 7, 35), y + Cos(time * 7, 35));
shield->SetR(-time * 7);
shield->SetClrModulation(color);
CreateParticle("MagicSpark", x + Sin(time * 7, 39), y + Cos(time * 7, 39), PV_Random(-10, 10), PV_Random(-10, 10), PV_Random(10, 20), effect.particles, 10);
var shield = CreateObjectAbove(CrystalShield, x - Sin(-7 + time * 7, 35),y + Cos(-7 + time * 7, 35));
shield->SetR(-7 + time*7);
shield->SetClrModulation(color);
CreateParticle("MagicSpark", x - Sin(-7 + time * 7, 39), y + Cos(-7 + time * 7, 39), PV_Random(-10, 10), PV_Random(-10, 10), PV_Random(10, 20), effect.particles, 10);
var angle = time * 7;
SpawnGemShield(effect.particles, x, y, angle, color);
SpawnGemShield(effect.particles, x, y, -angle + 7, color);
return 1;
}
global func SpawnGemShield(proplist particles, int x, int y, int angle, int color)
{
var dist_min = 35;
var dist_max = 39;
var shield = CreateObjectAbove(CrystalShield, x + Sin(angle, dist_min), y + Cos(angle, dist_min));
shield->SetR(-angle);
shield->SetClrModulation(color);
CreateParticle("MagicSpark", x + Sin(angle, dist_max), y + Cos(angle, dist_max), PV_Random(-10, 10), PV_Random(-10, 10), PV_Random(10, 20), particles, 10);
}
local Collectible = true;
local Name = "$Name$";
local Description = "$Description$";

View File

@ -40,7 +40,7 @@ func Hit()
RemoveObject();
}
global func FxGemSlowFieldStart(object target, effect, int temporary, int x, int y, bool e)
global func FxGemSlowFieldStart(object target, proplist effect, int temporary, int x, int y, bool e)
{
if (temporary)
return 1;
@ -68,7 +68,7 @@ global func FxGemSlowFieldStart(object target, effect, int temporary, int x, int
}
}
global func FxGemSlowFieldTimer(object target, effect, int time)
global func FxGemSlowFieldTimer(object target, proplist effect, int time)
{
var x = effect.x;
var y = effect.y;
@ -97,8 +97,8 @@ global func FxGemSlowFieldTimer(object target, effect, int time)
var angle = Angle(0, 0, obj->GetXDir(), obj->GetYDir());
obj->SetXDir(obj->GetXDir(100) + Sin(-angle, speed * 3), 100);
obj->SetYDir(obj->GetYDir(100) + Cos(-angle, speed * 3) -10, 100);
obj->SetYDir(obj->GetYDir()-5);
obj->SetYDir(obj->GetYDir(100) + Cos(-angle, speed * 3) - 10, 100);
obj->SetYDir(obj->GetYDir() - 5);
}
return 1;

View File

@ -13,9 +13,10 @@ protected func FxNoRemovalStop(object target, effect, int reason)
if (reason == 3)
{
var container = target->Contained();
if (!container)
return 1;
container->CreateContents(PowderKeg);
if (container)
{
container->CreateContents(PowderKeg);
}
}
return 1;
}
}

View File

@ -1,10 +1,16 @@
#appendto Ropeladder_Grabber
public func IsInteractable(object clonk) { if(GetEffect("NoInteract",this)) return false; else return true;}
public func IsInteractable(object clonk)
{
return !GetEffect("NoInteract", this);
}
public func FxNoInteractTime()
public func FxNoInteractTime() // TODO: Fix this error
{
return -1;
}
public func Initialize() { AddEffect("NoInteract",this,100,10*36,this); }
public func Initialize()
{
AddEffect("NoInteract", this, 100, 10*36, this);
}