MoltenMonarch: Clean code

The king size weapons overloaded entire functions from their original objects. This was replaced by adding interfaces that allow for the manipulation of the desired values.
alut-include-path
Mark 2017-01-07 02:21:22 +01:00
parent db9451dcce
commit 4b33beb9db
11 changed files with 115 additions and 121 deletions

View File

@ -2,3 +2,31 @@
// Arrows do not tumble
public func TumbleStrength() { return 0; }
// Callback from the bow
public func Launch(int angle, int str, object shooter, object weapon)
{
if (weapon && weapon.king_size)
{
AddEffect("KingSizeArrow", this, 100, 1, this);
SetClrModulation(RGB(255, 128, 0));
}
// Forward to the arrow for other functionality.
return _inherited(angle, str, shooter, weapon, ...);
}
public func FxKingSizeArrowTimer(object arrow, proplist fx, int time)
{
arrow->CreateParticle("Fire", 0, 0, PV_Random(-10, 10), PV_Random(-10, 10), PV_Random(10, 20), Particles_Glimmer(), 5);
fx.timer++;
if (!arrow->GetXDir() && !arrow->GetYDir())
{
fx.timer = Max(fx.timer, 65);
}
if (fx.timer > 90)
{
arrow->Explode(RandomX(15, 22));
}
}

View File

@ -2,45 +2,18 @@
local king_size;
public func MakeKingSize() { king_size = true; SetMeshMaterial("Kingwood",1); return(SetMeshMaterial("KingLeather", 0)); }
public func MakeNormalSize() { king_size = false; SetMeshMaterial("wood",0); return(SetMeshMaterial("Leather", 1)); }
public func MakeKingSize()
{
king_size = true;
SetMeshMaterial("Kingwood", 1);
SetMeshMaterial("KingLeather", 0);
}
public func MakeNormalSize()
{
king_size = false;
SetMeshMaterial("wood", 0);
SetMeshMaterial("Leather", 1);
}
public func Departure() { MakeNormalSize(); }
// Callback from the clonk, when he actually has stopped aiming
public func FinishedAiming(object clonk, int angle)
{
clonk->DetachMesh(iArrowMesh);
iArrowMesh = nil;
// shoot
if(Contents(0))
{
if(Contents(0)->~IsArrow())
{
var arrow = Contents(0)->TakeObject();
arrow->Launch(angle,this.shooting_strength,clonk);
if(king_size)
{
AddEffect("ExplosiveArrow",arrow,100,1,this);
arrow->SetClrModulation(RGB(255,128,0));
}
Sound("Objects::Weapons::Bow::Shoot?");
}
}
// Open the hand to let the string go and play the fire animation
PlayAnimation("Fire", CLONK_ANIM_SLOT_Hands, Anim_Linear(0, 0, GetAnimationLength("Fire"), animation_set["ShootTime"], ANIM_Hold));
clonk->PlayAnimation("Close1Hand", 11, Anim_Const(0));
clonk->StartShoot(this);
return true;
}
public func FxExplosiveArrowTimer(pTarget, effect, iEffectTime)
{
pTarget->CreateParticle("Fire", 0, 0, PV_Random(-10, 10), PV_Random(-10, 10), PV_Random(10, 20), Particles_Glimmer(), 5);
effect.timer++;
if(!pTarget->GetXDir() && !pTarget->GetYDir()) effect.timer = Max(effect.timer,65);
if(effect.timer>90) pTarget->Explode(15+Random(7));
}

View File

@ -2,53 +2,28 @@
local king_size;
public func MakeKingSize() { king_size = true; SetMeshMaterial("KingClub",0);}
public func MakeNormalSize() { king_size = false; SetMeshMaterial("Club",0);}
public func Departure() { MakeNormalSize(); }
func DoStrike(clonk, angle)
public func MakeKingSize()
{
var x=Sin(angle, 7);
var y=-Cos(angle, 7);
var found=false;
for(var obj in FindObjects(Find_Distance(7, x, y), Find_Or(Find_OCF(OCF_Alive), Find_Category(C4D_Object), Find_Category(C4D_Vehicle)), Find_Exclude(clonk), Find_NoContainer(), Find_Layer(GetObjectLayer())))
{
if(obj->Stuck()) continue;
// vehicles are only hit if they are pseudo vehicles. Bad system - has to be changed in the future
if(obj->GetCategory() & C4D_Vehicle)
if(!GetEffect("HitCheck", obj)) continue;
var en=Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if(GetEffect(en, obj)) continue;
if(obj->GetOCF() & OCF_Alive)
{
var damage=5*1000;
if (king_size)
damage+=3000;
ApplyWeaponBash(obj, 400, angle);
obj->DoEnergy(-damage, true, FX_Call_EngGetPunched, clonk->GetOwner());
}
else
{
var div=100;
if(obj->GetContact(-1)) div*=10;
if (king_size)
div/=2;
// mass/size factor
var fac1=10000/Max(2, obj->GetMass());
var fac2=BoundBy(10-Abs(obj->GetDefCoreVal("Width", "DefCore")-obj->GetDefCoreVal("Height", "DefCore")), 1, 10);
var speed=(3000 * fac1 * fac2) / 10 / 1000;
obj->SetXDir((obj->GetXDir(100) + Sin(angle, speed)) / 2, div);
obj->SetYDir((obj->GetYDir(100) - Cos(angle, speed)) / 2, div);
}
AddEffect(en, obj, 1, 15, nil);
found=true;
break;
}
if(found)
RemoveEffect("DuringClubShoot", clonk);
king_size = true;
SetMeshMaterial("KingClub", 0);
}
public func MakeNormalSize()
{
king_size = false;
SetMeshMaterial("Club", 0);
}
public func Departure() { MakeNormalSize(); }
func ClubDamage()
{
return _inherited(...) + 3000;
}
func ClubVelocityPrecision()
{
return _inherited(...) / 2;
}

View File

@ -3,8 +3,18 @@
local king_size;
public func MakeKingSize() { king_size = true; SetMeshMaterial("KingJavelin", 0); }
public func MakeNormalSize() { king_size = false; SetMeshMaterial("javelin", 0); }
public func MakeKingSize()
{
king_size = true;
SetMeshMaterial("KingJavelin", 0);
}
public func MakeNormalSize()
{
king_size = false;
SetMeshMaterial("javelin", 0);
}
public func Departure() { MakeNormalSize(); }
protected func JavelinStrength()
@ -16,27 +26,12 @@ protected func JavelinStrength()
public func DoThrow(object clonk, int angle)
{
var javelin=TakeObject();
if (king_size)
var javelin = _inherited(clonk, angle, ...);
if (javelin && king_size)
{
javelin->MakeKingSize();
// The clonk can convert some, indicated by div in percentages, of its own kinetic energy to change the momenta of the javelin, a miracle.
var div = 60; // 40% is converted to the direction of the throwing angle.
var xdir = clonk->GetXDir(1000);
var ydir = clonk->GetYDir(1000);
var speed = clonk.ThrowSpeed * this.shooting_strength + (100 - div) * Sqrt(xdir**2 + ydir**2) / 100;
var jav_x = div * xdir / 100 + Sin(angle, speed);
var jav_y = div * ydir / 100 - Cos(angle, speed);
javelin->SetXDir(jav_x, 1000);
javelin->SetYDir(jav_y, 1000);
}
SetController(clonk->GetController());
javelin->AddEffect("Flight",javelin,1,1,javelin,nil);
javelin->AddEffect("HitCheck",javelin,1,1,nil,nil,clonk);
Sound("Objects::Weapons::Javelin::Throw?");
aiming = -1;
clonk->UpdateAttach();
return javelin;
}

View File

@ -2,13 +2,23 @@
local king_size;
public func MakeKingSize() { king_size = true; SetMeshMaterial("KingSword2",0); }
public func MakeNormalSize() { king_size = false; SetMeshMaterial("Sword2",0); }
public func MakeKingSize()
{
king_size = true;
SetMeshMaterial("KingSword2", 0);
}
public func MakeNormalSize()
{
king_size = false;
SetMeshMaterial("Sword2", 0);
}
public func Departure() { MakeNormalSize(); }
func SwordDamage(int shield)
{
var damage = _inherited(shield, ...);
if(king_size) damage+=3000+Random(3000);
if (king_size) damage += 3000 + Random(3000);
return damage;
}

View File

@ -18,7 +18,7 @@ protected func Construction()
return _inherited(...);
}
public func Launch(int angle, int str, object shooter)
public func Launch(int angle, int str, object shooter, object weapon)
{
SetShape(-2, -2, 4, 11);
SetVertex(0, VTX_Y, 3, 1);

View File

@ -10,11 +10,11 @@
// Callback from the bow: add burning effect to the arrow here.
public func Launch(int angle, int str, object shooter)
public func Launch(int angle, int str, object shooter, object weapon)
{
AddEffect("IntBurning", this, 1, 1, this);
// Forward to the arrow for other functionality.
return _inherited(angle, str, shooter, ...);
return _inherited(angle, str, shooter, weapon, ...);
}

View File

@ -62,6 +62,7 @@ public func FinishedLoading(object clonk)
}
// Callback from the clonk, when he actually has stopped aiming
// Calls "OnLaunchArrow"
public func FinishedAiming(object clonk, int angle)
{
clonk->DetachMesh(iArrowMesh);
@ -73,7 +74,7 @@ public func FinishedAiming(object clonk, int angle)
if(Contents(0)->~IsArrow())
{
var arrow = Contents(0)->TakeObject();
arrow->Launch(angle,shooting_strength,clonk);
arrow->Launch(angle, shooting_strength, clonk, this);
Sound("Objects::Weapons::Bow::Shoot?");
}
}

View File

@ -194,13 +194,13 @@ func DoStrike(clonk, angle)
if (obj->GetOCF() & OCF_Alive)
{
var damage=5*1000;
var damage = ClubDamage();
ApplyWeaponBash(obj, 400, angle, clonk);
obj->DoEnergy(-damage, true, FX_Call_EngGetPunched, clonk->GetOwner());
}
else
{
var div=100;
var div = ClubVelocityPrecision();
if(obj->GetContact(-1)) div*=10;
// the better you hit, the more power you have
@ -228,6 +228,16 @@ func DoStrike(clonk, angle)
}
}
func ClubDamage()
{
return 5*1000;
}
func ClubVelocityPrecision()
{
return 100;
}
/*-- Production --*/
public func IsWeapon() { return true; }

View File

@ -142,7 +142,7 @@ public func Reset(clonk)
public func DoThrow(object clonk, int angle)
{
var javelin=TakeObject();
var javelin = TakeObject();
var div = 60; // 40% is converted to the direction of the throwing angle.
var xdir = clonk->GetXDir(1000);
@ -163,6 +163,8 @@ public func DoThrow(object clonk, int angle)
aiming = -1;
clonk->UpdateAttach();
return javelin;
}
func Stick()