2015-03-12 21:21:51 +00:00
|
|
|
/**
|
2010-03-31 00:46:06 +00:00
|
|
|
Dynamite
|
2015-03-12 21:21:51 +00:00
|
|
|
A volatile tool that can be pressed into wallsfor accurate
|
|
|
|
mining, burning a short fuse before exploding.
|
2010-03-31 00:46:06 +00:00
|
|
|
|
2015-03-12 21:21:51 +00:00
|
|
|
@author Newton
|
2010-03-31 00:46:06 +00:00
|
|
|
*/
|
2013-11-28 22:29:25 +00:00
|
|
|
|
|
|
|
// time in frames until explosion
|
|
|
|
func FuseTime() { return 140; }
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2010-08-23 17:16:35 +00:00
|
|
|
public func ControlUse(object clonk, int x, int y, bool box)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
|
|
|
// if already activated, nothing (so, throw)
|
2010-08-23 17:16:35 +00:00
|
|
|
if(GetAction() == "Fuse" || box)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-08-23 17:16:35 +00:00
|
|
|
if(Place(clonk,x,y,box))
|
2010-03-25 13:57:19 +00:00
|
|
|
return true;
|
2010-08-23 17:16:35 +00:00
|
|
|
// if placed with the box, we are more tolerant where the
|
|
|
|
// user clicks and search for other positions too
|
|
|
|
else if(box)
|
|
|
|
{
|
|
|
|
|
|
|
|
// get rough direction (left, right, up down)
|
|
|
|
var angle = (Angle(0,0,x,y)+45)/90*90;
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2010-08-23 17:16:35 +00:00
|
|
|
var plusminus = -1;
|
|
|
|
// first check if it is possible to place the dynamite
|
|
|
|
// in roughly the same direction as he clicked, then
|
|
|
|
// in each left or right of that direction and then
|
|
|
|
// in the opposite direction.
|
|
|
|
for(var i=0; i<=3; ++i)
|
|
|
|
{
|
|
|
|
|
|
|
|
angle += plusminus * i * 90;
|
|
|
|
x = Sin(angle, 300);
|
|
|
|
y = -Cos(angle, 300);
|
|
|
|
|
|
|
|
if(Place(clonk,x,y,box))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
plusminus *= -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-03-25 13:57:19 +00:00
|
|
|
}
|
|
|
|
else
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-25 13:57:19 +00:00
|
|
|
Fuse();
|
2010-08-23 17:16:35 +00:00
|
|
|
return true;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
2010-08-23 17:16:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private func Place(object clonk, int x, int y, bool box)
|
|
|
|
{
|
|
|
|
var angle = Angle(0,0,x,y);
|
2010-09-11 17:30:45 +00:00
|
|
|
var pos = GetWall(angle);
|
|
|
|
if(pos)
|
2010-08-23 17:16:35 +00:00
|
|
|
{
|
|
|
|
if(box) SetReady();
|
|
|
|
|
|
|
|
// put into ...
|
|
|
|
Sound("Connect");
|
2010-09-11 17:30:45 +00:00
|
|
|
Exit(pos[0], pos[1], Angle(pos[0],pos[1]));
|
|
|
|
SetPosition(clonk->GetX()+pos[0], clonk->GetY()+pos[1]);
|
2010-08-23 17:16:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public func Fuse()
|
|
|
|
{
|
2015-01-07 19:05:17 +00:00
|
|
|
if (GetAction() != "Fuse")
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2015-01-07 19:05:17 +00:00
|
|
|
if (!FindObject(Find_Category(C4D_StaticBack), Find_Func("IsFuse"), Find_ActionTargets(this)))
|
|
|
|
Sound("Fuse");
|
2009-12-29 13:44:16 +00:00
|
|
|
SetAction("Fuse");
|
2015-01-07 19:05:17 +00:00
|
|
|
// Object can't be collected anymore when it fuses.
|
|
|
|
this.Collectible = false;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-21 19:55:25 +00:00
|
|
|
// returns true if there is a wall in direction in which "clonk" looks
|
2009-12-29 13:44:16 +00:00
|
|
|
// and puts the offset to the wall into "xo, yo" - looking from the clonk
|
2015-03-12 21:21:51 +00:00
|
|
|
private func GetWall(int angle)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-08-23 17:16:35 +00:00
|
|
|
var dist = 12;
|
2015-03-12 21:21:51 +00:00
|
|
|
for (var dist = 12; dist < 18; dist++)
|
2010-02-21 19:55:25 +00:00
|
|
|
{
|
2010-09-12 09:25:21 +00:00
|
|
|
var x = Sin(angle, dist);
|
|
|
|
var y = -Cos(angle, dist);
|
2015-03-12 21:21:51 +00:00
|
|
|
if (GBackSolid(x, y))
|
2010-09-11 17:30:45 +00:00
|
|
|
return [Sin(angle, dist-5), -Cos(angle, dist-5)];
|
2010-02-21 19:55:25 +00:00
|
|
|
}
|
2009-12-29 13:44:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 17:20:41 +00:00
|
|
|
protected func Hit() { Sound("GeneralHit?"); }
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2015-05-17 12:01:26 +00:00
|
|
|
protected func Incineration(int caused_by)
|
|
|
|
{
|
|
|
|
Extinguish();
|
|
|
|
Fuse();
|
|
|
|
SetController(caused_by);
|
|
|
|
}
|
2009-12-29 13:44:16 +00:00
|
|
|
|
|
|
|
protected func RejectEntrance()
|
|
|
|
{
|
2015-01-07 19:05:17 +00:00
|
|
|
return GetAction() == "Ready";
|
2010-02-12 23:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Controle of the Dynamite box
|
|
|
|
public func SetReady()
|
|
|
|
{
|
|
|
|
SetAction("Ready");
|
|
|
|
}
|
|
|
|
// Controle of the Dynamite box
|
|
|
|
public func SetFuse()
|
|
|
|
{
|
|
|
|
SetAction("Fuse");
|
2015-01-07 19:05:17 +00:00
|
|
|
// Object can't be collected anymore when it fuses.
|
|
|
|
this.Collectible = false;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2010-02-22 16:03:26 +00:00
|
|
|
public func Reset()
|
|
|
|
{
|
|
|
|
SetAction("Idle");
|
2015-01-07 19:05:17 +00:00
|
|
|
// Object can be collected again.
|
|
|
|
this.Collectible = true;
|
2010-02-22 16:03:26 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 15:27:48 +00:00
|
|
|
private func Fusing()
|
2010-03-30 04:44:43 +00:00
|
|
|
{
|
2013-11-28 22:29:25 +00:00
|
|
|
var x = Sin(GetR(), 5);
|
|
|
|
var y = -Cos(GetR(), 5);
|
2010-03-30 04:44:43 +00:00
|
|
|
|
2015-03-12 21:21:51 +00:00
|
|
|
if (Contained()!=nil)
|
2010-03-30 04:44:43 +00:00
|
|
|
{
|
2010-03-31 00:46:06 +00:00
|
|
|
//If the dynamite is held, sparks come from clonk's center.
|
2013-11-28 22:29:25 +00:00
|
|
|
x = y = 0;
|
2010-03-30 04:44:43 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 21:21:51 +00:00
|
|
|
// Effect: fire particles.
|
|
|
|
if (GetActTime() < FuseTime() - 20)
|
2013-12-17 20:40:40 +00:00
|
|
|
CreateParticle("Fire", x, y, PV_Random(x - 5, x + 5), PV_Random(y - 15, y + 5), PV_Random(10, 40), Particles_Glimmer(), 3);
|
2015-03-12 21:21:51 +00:00
|
|
|
// Explosion: after fusetime is over.
|
|
|
|
else if (GetActTime() > FuseTime())
|
2010-02-22 00:18:45 +00:00
|
|
|
DoExplode();
|
2015-03-12 21:21:51 +00:00
|
|
|
return;
|
2010-02-22 00:18:45 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 13:13:47 +00:00
|
|
|
public func OnFuseFinished()
|
|
|
|
{
|
|
|
|
DoExplode();
|
|
|
|
}
|
|
|
|
|
2010-02-22 00:18:45 +00:00
|
|
|
public func DoExplode()
|
|
|
|
{
|
2015-03-12 21:21:51 +00:00
|
|
|
// Activate all fuses.
|
|
|
|
for (var obj in FindObjects(Find_Category(C4D_StaticBack), Find_Func("IsFuse"), Find_ActionTargets(this)))
|
2010-04-13 13:13:47 +00:00
|
|
|
obj->~StartFusing(this);
|
2014-01-11 15:29:19 +00:00
|
|
|
Explode(26);
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 12:57:42 +00:00
|
|
|
public func IsChemicalProduct() { return true; }
|
2013-05-24 19:17:44 +00:00
|
|
|
public func IsGrenadeLauncherAmmo() { return true; }
|
2011-10-15 09:25:44 +00:00
|
|
|
|
2015-03-12 21:21:51 +00:00
|
|
|
|
|
|
|
/*-- Properties --*/
|
|
|
|
|
2010-09-09 21:29:11 +00:00
|
|
|
local ActMap = {
|
|
|
|
Fuse = {
|
|
|
|
Prototype = Action,
|
|
|
|
Name = "Fuse",
|
|
|
|
Procedure = DFA_NONE,
|
|
|
|
NextAction = "Fuse",
|
|
|
|
Delay = 1,
|
|
|
|
Length = 1,
|
|
|
|
FacetBase = 1,
|
|
|
|
Sound = "Fusing",
|
|
|
|
StartCall = "Fusing"
|
|
|
|
},
|
|
|
|
Ready = {
|
|
|
|
Prototype = Action,
|
|
|
|
Name = "Ready",
|
|
|
|
Procedure = DFA_NONE,
|
|
|
|
NextAction = "Ready",
|
|
|
|
Delay = 1,
|
|
|
|
Length = 1,
|
|
|
|
FacetBase = 1,
|
|
|
|
}
|
|
|
|
};
|
2010-10-29 17:51:09 +00:00
|
|
|
local Name = "$Name$";
|
2010-09-11 17:30:45 +00:00
|
|
|
local Description = "$Description$";
|
2012-03-19 00:03:05 +00:00
|
|
|
local UsageHelp = "$UsageHelp$";
|
2011-01-02 22:17:47 +00:00
|
|
|
local Collectible = 1;
|
2011-02-20 19:59:50 +00:00
|
|
|
local Rebuy = true;
|
2012-04-28 14:17:38 +00:00
|
|
|
local BlastIncinerate = 1;
|
|
|
|
local ContactIncinerate = 1;
|