forked from Mirrors/openclonk
clean up shovel script
parent
145b902f65
commit
978b236596
|
@ -1228,21 +1228,31 @@ func FxRollingStop(object target, proplist effect, int reason, temp)
|
|||
The effect just is responsible for the sound and the termination of digging.
|
||||
--*/
|
||||
|
||||
func StartDigging()
|
||||
public func StartDigging()
|
||||
{
|
||||
if(!GetEffect("IntDig", this))
|
||||
if (!GetEffect("IntDig", this))
|
||||
AddEffect("IntDig", this, 1, 1, this);
|
||||
}
|
||||
|
||||
func StopDigging()
|
||||
public func StopDigging()
|
||||
{
|
||||
if(GetAction() != "Dig") RemoveEffect("IntDig", this);
|
||||
if (GetAction() != "Dig")
|
||||
RemoveEffect("IntDig", this);
|
||||
}
|
||||
|
||||
func FxIntDigStart(pTarget, effect, fTmp)
|
||||
public func GetDiggingAnimation()
|
||||
{
|
||||
if(fTmp) return;
|
||||
effect.var1 = PlayAnimation("Dig", CLONK_ANIM_SLOT_Movement, Anim_Linear(0, 0, GetAnimationLength("Dig"), 36, ANIM_Loop), Anim_Linear(0, 0, 1000, 5, ANIM_Remove));
|
||||
var dig_effect = GetEffect("IntDig", this);
|
||||
if (dig_effect)
|
||||
return dig_effect.animation;
|
||||
return;
|
||||
}
|
||||
|
||||
public func FxIntDigStart(object target, effect fx, int temp)
|
||||
{
|
||||
if (temp)
|
||||
return FX_OK;
|
||||
fx.animation = PlayAnimation("Dig", CLONK_ANIM_SLOT_Movement, Anim_Linear(0, 0, GetAnimationLength("Dig"), 36, ANIM_Loop), Anim_Linear(0, 0, 1000, 5, ANIM_Remove));
|
||||
|
||||
// Update carried items
|
||||
UpdateAttach();
|
||||
|
@ -1252,26 +1262,29 @@ func FxIntDigStart(pTarget, effect, fTmp)
|
|||
|
||||
// Set proper turn type
|
||||
SetTurnType(0);
|
||||
return FX_OK;
|
||||
}
|
||||
|
||||
func FxIntDigTimer(pTarget, effect, iTime)
|
||||
public func FxIntDigTimer(object target, effect fx, int time)
|
||||
{
|
||||
if(iTime % 36 == 0)
|
||||
if (time % 36 == 0)
|
||||
{
|
||||
Sound("Clonk::Action::Dig::Dig?");
|
||||
}
|
||||
if( (iTime-18) % 36 == 0 || iTime > 35)
|
||||
if (time == 18 || time >= 36)
|
||||
{
|
||||
var noDig = 1;
|
||||
for(var pShovel in FindObjects(Find_ID(Shovel), Find_Container(this)))
|
||||
if(pShovel->IsDigging()) noDig = 0;
|
||||
if(noDig)
|
||||
var no_dig = true;
|
||||
for (var shovel in FindObjects(Find_ID(Shovel), Find_Container(this)))
|
||||
if (shovel->IsDigging())
|
||||
no_dig = false;
|
||||
if (no_dig)
|
||||
{
|
||||
SetAction("Walk");
|
||||
SetComDir(COMD_Stop);
|
||||
return -1;
|
||||
return FX_Execute_Kill;
|
||||
}
|
||||
}
|
||||
return FX_OK;
|
||||
}
|
||||
|
||||
/*--
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
/*-- Shovel --*/
|
||||
/**
|
||||
Shovel
|
||||
Essential tool for the clonk, used to dig through materials.
|
||||
|
||||
@author Newtom, Sven2, Zapper, Maikel
|
||||
*/
|
||||
|
||||
|
||||
local is_digging;
|
||||
|
||||
private func Hit()
|
||||
{
|
||||
|
@ -20,63 +28,60 @@ private func Destruction()
|
|||
|
||||
public func GetCarryMode(clonk) { return CARRY_Back; }
|
||||
|
||||
public func GetCarrySpecial(clonk) { if(clonk->~GetAction() == "Dig") return "pos_hand1"; }
|
||||
public func GetCarrySpecial(clonk) { if (clonk->~GetAction() == "Dig") return "pos_hand1"; }
|
||||
|
||||
local fDigging;
|
||||
local DigAngle;
|
||||
local DigX, DigY;
|
||||
local stuck_count;
|
||||
|
||||
public func IsDigging() { return fDigging; }
|
||||
public func IsDigging() { return is_digging; }
|
||||
|
||||
|
||||
public func ControlUseStart(object clonk, int x, int y)
|
||||
{
|
||||
AddEffect("ShovelDig",clonk,1,1,this);
|
||||
// ControlUseHolding(clonk, x, y);
|
||||
|
||||
//temporary workaround to allow clonks to dig free when they are stuck in dirt
|
||||
if(clonk->Stuck()){
|
||||
DigFree(clonk->GetX(), clonk->GetY(), 10);
|
||||
}
|
||||
|
||||
ControlUseHolding(clonk, x, y); // initial coordinate setup
|
||||
|
||||
return true;
|
||||
}
|
||||
/*-- Usage --*/
|
||||
|
||||
public func HoldingEnabled() { return true; }
|
||||
|
||||
public func ControlUseStart(object clonk, int x, int y)
|
||||
{
|
||||
AddEffect("ShovelDig", clonk, 1, 1, this);
|
||||
|
||||
// Temporary workaround to allow clonks to dig free when they are stuck in dirt.
|
||||
if (clonk->Stuck())
|
||||
DigFree(clonk->GetX(), clonk->GetY(), 10);
|
||||
|
||||
// Initial coordinate setup.
|
||||
ControlUseHolding(clonk, x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
public func ControlUseHolding(object clonk, int x, int y)
|
||||
{
|
||||
DigX = x;
|
||||
DigY = y;
|
||||
DigAngle = Angle(0,0,x,y);
|
||||
var dig_effect = GetEffect("ShovelDig", clonk);
|
||||
if (dig_effect)
|
||||
{
|
||||
dig_effect.dig_x = x;
|
||||
dig_effect.dig_y = y;
|
||||
dig_effect.dig_angle = Angle(0, 0, x, y);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public func ControlUseCancel(object clonk, int x, int y)
|
||||
{
|
||||
ControlUseStop(clonk, x, y);
|
||||
return ControlUseStop(clonk, x, y);
|
||||
}
|
||||
|
||||
public func ControlUseStop(object clonk, int x, int y)
|
||||
{
|
||||
fDigging = 0;
|
||||
RemoveEffect("ShovelDig",clonk);
|
||||
if(clonk->GetAction() != "Dig") return true;
|
||||
|
||||
// EffectCall(clonk, GetEffect("IntDig", clonk), "StopDig");
|
||||
clonk->SetXDir(0,100);
|
||||
clonk->SetYDir(0,100);
|
||||
// clonk->SetAction("Walk");
|
||||
// clonk->SetComDir(COMD_Stop);
|
||||
is_digging = false;
|
||||
RemoveEffect("ShovelDig", clonk);
|
||||
|
||||
if (clonk->GetAction() != "Dig")
|
||||
return true;
|
||||
|
||||
clonk->SetXDir(0);
|
||||
clonk->SetYDir(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public func FxShovelDigTimer(object clonk, effect, int time)
|
||||
public func FxShovelDigTimer(object clonk, effect fx, int time)
|
||||
{
|
||||
// Left the clonk?
|
||||
if (Contained() != clonk)
|
||||
|
@ -90,26 +95,28 @@ public func FxShovelDigTimer(object clonk, effect, int time)
|
|||
}
|
||||
var xdir_boost = 0, ydir_boost = 0;
|
||||
// Currently not digging?
|
||||
if(clonk->GetAction() != "Dig" || clonk->GBackLiquid(0,-4))
|
||||
if (clonk->GetAction() != "Dig" || clonk->GBackLiquid(0, -4))
|
||||
{
|
||||
var is_scaling = (clonk->GetProcedure() == "SCALE");
|
||||
var can_dig = (clonk->GetAction() == "Walk" || is_scaling || clonk->GetProcedure() == "HANGLE");
|
||||
// Prevent clonk from starting to dig if in deep liquid
|
||||
if (clonk->GBackLiquid(0,-4)) can_dig = false;
|
||||
// Prevent clonk from starting to dig if in deep liquid.
|
||||
if (clonk->GBackLiquid(0, -4))
|
||||
can_dig = false;
|
||||
if (can_dig)
|
||||
{
|
||||
clonk->SetAction("Dig");
|
||||
clonk->SetComDir(COMD_Stop);
|
||||
if (is_scaling)
|
||||
{
|
||||
// speed boost when Clonk started digging from scaling, so we don't drop down
|
||||
var clnk_xdir = clonk->GetDir()*2-1;
|
||||
if (Abs(DigX) > Abs(DigY) && DigX*clnk_xdir > 0) // only if player actually wants to go sideways in the scaling direction (|x|>|y| and sign(x)==sign(clnk_xdir))
|
||||
// Speed boost when Clonk started digging from scaling, so we don't drop down.
|
||||
var clnk_xdir = clonk->GetDir() * 2 - 1;
|
||||
// Only if player actually wants to go sideways in the scaling direction (|x|>|y| and sign(x)==sign(clnk_xdir)).
|
||||
if (Abs(fx.dig_x) > Abs(fx.dig_y) && fx.dig_x * clnk_xdir > 0)
|
||||
{
|
||||
// not if standing on ground (to prevent speed boost digging) or on ceiling (to make working your way upwards through earth a little harder)
|
||||
if (!clonk->GetContact(-1, CNAT_Top|CNAT_Bottom))
|
||||
// Not if standing on ground (to prevent speed boost digging) or on ceiling (to make working your way upwards through earth a little harder).
|
||||
if (!clonk->GetContact(-1, CNAT_Top | CNAT_Bottom))
|
||||
{
|
||||
xdir_boost = clnk_xdir*1000;
|
||||
xdir_boost = clnk_xdir * 1000;
|
||||
ydir_boost = -100;
|
||||
}
|
||||
}
|
||||
|
@ -117,82 +124,80 @@ public func FxShovelDigTimer(object clonk, effect, int time)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (fDigging)
|
||||
if (is_digging)
|
||||
{
|
||||
fDigging = false;
|
||||
RemoveEffect("ShovelDust",clonk);
|
||||
is_digging = false;
|
||||
}
|
||||
return true;
|
||||
return FX_OK;
|
||||
}
|
||||
}
|
||||
// Dig start procedure
|
||||
if(!fDigging && clonk->GetAction() == "Dig")
|
||||
if (!is_digging && clonk->GetAction() == "Dig")
|
||||
{
|
||||
AddEffect("ShovelDust",clonk,1,1,this);
|
||||
fDigging = true;
|
||||
stuck_count = 0;
|
||||
is_digging = true;
|
||||
fx.stuck_count = 0;
|
||||
}
|
||||
if(fDigging)
|
||||
if (is_digging)
|
||||
{
|
||||
// Get animation-adjusted dig speed.
|
||||
var speed = this->GetDigSpeed(clonk);
|
||||
|
||||
|
||||
// Limit the digging angle: one can dig maximally 30 degrees upwards.
|
||||
DigAngle = BoundBy(DigAngle, 60, 300);
|
||||
var dig_xdir = Sin(DigAngle, speed);
|
||||
var dig_ydir = -Cos(DigAngle, speed);
|
||||
fx.dig_angle = BoundBy(fx.dig_angle, 60, 300);
|
||||
|
||||
var dig_xdir = Sin(fx.dig_angle, speed);
|
||||
var dig_ydir = -Cos(fx.dig_angle, speed);
|
||||
|
||||
// Stuck-check: When player wants to go horizontally while standing on the ground but can't, add a vertical redirect
|
||||
// This helps with Clonks getting "stuck" not moving on certain terrain when dig speed is not sufficient to push him up a slope
|
||||
// It also helps e.g. when just digging through earth just above rock, because it will nudge the clonk over the rock
|
||||
if (!clonk->GetXDir(100) && !clonk->GetYDir(100) && GetContact(-1, CNAT_Bottom) && Abs(dig_xdir) > Abs(dig_ydir) && Abs(dig_xdir) > 10)
|
||||
{
|
||||
if (stuck_count++)
|
||||
{
|
||||
if (fx.stuck_count++)
|
||||
ydir_boost -= 100;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stuck_count = 0;
|
||||
fx.stuck_count = 0;
|
||||
}
|
||||
|
||||
clonk->SetXDir(dig_xdir+xdir_boost,100);
|
||||
clonk->SetYDir(dig_ydir+ydir_boost,100);
|
||||
clonk->SetXDir(dig_xdir + xdir_boost, 100);
|
||||
clonk->SetYDir(dig_ydir + ydir_boost, 100);
|
||||
|
||||
// Dust
|
||||
if (!Random(10))
|
||||
Dust(clonk);
|
||||
}
|
||||
return FX_OK;
|
||||
}
|
||||
|
||||
private func GetDigSpeed(object clonk)
|
||||
{
|
||||
var speed = clonk.ActMap.Dig.Speed * 2;
|
||||
// Adjust speed at current animation position.
|
||||
var iAnimation = GetEffect("IntDig", clonk).var1;
|
||||
var iPosition = clonk->GetAnimationPosition(iAnimation)*180/clonk->GetAnimationLength("Dig");
|
||||
speed = speed*(Cos(iPosition-45, 50)**2)/2500;
|
||||
var animation = clonk->GetDiggingAnimation();
|
||||
var position = clonk->GetAnimationPosition(animation) * 180 / clonk->GetAnimationLength("Dig");
|
||||
speed = speed * Cos(position - 45, 50)**2 / 2500;
|
||||
return speed;
|
||||
}
|
||||
|
||||
public func Dust(object target)
|
||||
{
|
||||
// Only when the clonk moves the shovel
|
||||
var iAnimation = GetEffect("IntDig", target).var1;
|
||||
var iPosition = target->GetAnimationPosition(iAnimation)*100/target->GetAnimationLength("Dig");
|
||||
if(iPosition > 50)
|
||||
// Only when the clonk moves the shovel.
|
||||
var animation = target->GetDiggingAnimation();
|
||||
var position = target->GetAnimationPosition(animation) * 100 / target->GetAnimationLength("Dig");
|
||||
if (position > 50)
|
||||
return;
|
||||
var xdir = target->GetXDir();
|
||||
var ydir = target->GetYDir();
|
||||
|
||||
// particle effect
|
||||
var angle = Angle(0,0,xdir,ydir)+iPosition-25;//RandomX(-25,25);
|
||||
var groundx = Sin(angle,15);
|
||||
var groundy = -Cos(angle,15);
|
||||
// Particle effect.
|
||||
var angle = Angle(0, 0, xdir, ydir) + position - 25;
|
||||
var groundx = Sin(angle, 15);
|
||||
var groundy = -Cos(angle, 15);
|
||||
var mat = GetMaterial(groundx, groundy);
|
||||
var tex = GetTexture(groundx,groundy);
|
||||
if(GetMaterialVal("DigFree","Material",mat))
|
||||
var tex = GetTexture(groundx, groundy);
|
||||
if (GetMaterialVal("DigFree", "Material", mat))
|
||||
{
|
||||
var clr = GetAverageTextureColor(tex);
|
||||
var particles =
|
||||
|
@ -203,17 +208,22 @@ public func Dust(object target)
|
|||
B = clr & 0xff,
|
||||
Size = PV_KeyFrames(0, 0, 0, 300, 20, 1000, 7),
|
||||
};
|
||||
CreateParticle("Dust", groundx/2, groundy/2, PV_Random(-6, 6), PV_Random(-6, 6), PV_Random(18, 1 * 36), particles, 8);
|
||||
CreateParticle("Dust", groundx / 2, groundy / 2, PV_Random(-6, 6), PV_Random(-6, 6), PV_Random(18, 36), particles, 8);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public func IsTool() { return true; }
|
||||
public func IsToolProduct() { return true; }
|
||||
|
||||
func Definition(def) {
|
||||
SetProperty("PictureTransformation", Trans_Mul(Trans_Rotate(135, 0, 0, 1),Trans_Rotate(30, 0, 1, 0)),def);
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
public func Definition(proplist def)
|
||||
{
|
||||
def.PictureTransformation = Trans_Mul(Trans_Rotate(135, 0, 0, 1), Trans_Rotate(30, 0, 1, 0));
|
||||
}
|
||||
|
||||
local Collectible = 1;
|
||||
local Collectible = true;
|
||||
local Name = "$Name$";
|
||||
local Description = "$Description$";
|
||||
|
|
Loading…
Reference in New Issue