File: Script.c

package info (click to toggle)
openclonk 8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 169,500 kB
  • sloc: cpp: 180,478; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 139; sh: 101; javascript: 34
file content (128 lines) | stat: -rw-r--r-- 2,785 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
	IronBomb
	Explodes after a short fuse. Explodes on contact if shot by the grenade launcher.
	
	@author Ringwaul, Clonkonaut
*/

// If true, explodes on contact.
local armed; 

public func ControlUse(object clonk, int x, int y)
{
	// If already activated, nothing (so, throw).
	if (GetEffect("FuseBurn", this))
	{
		clonk->ControlThrow(this, x, y);
		return true;
	}
	Fuse();
	return true;
}

public func Fuse(bool explode_on_hit)
{
	armed = explode_on_hit;
	AddEffect("FuseBurn", this, 1, 1, this);
	return;
}

public func FuseTime() { return 90; }

public func IsFusing() { return !!GetEffect("FuseBurn", this); }

public func OnCannonShot(object cannon)
{
	return Fuse(true);
}

public func FxFuseBurnStart(object target, effect fx, int temp)
{
	if (temp)
		return FX_OK;
	Sound("Fire::FuseLoop", {loop_count = +1});
	return FX_OK;
}


public func FxFuseBurnTimer(object target, effect fx, int time)
{
	// Emit some smoke from the fuse hole.
	var i = 3;
	var x = +Sin(GetR(), i);
	var y = -Cos(GetR(), i);
	CreateParticle("Smoke", x, y, x, y, PV_Random(18, 36), Particles_Smoke(), 2);
	// Explode if time is up.
	if (time >= FuseTime())
	{
		DoExplode();
		return FX_Execute_Kill;
	}
	return FX_OK;
}

public func FxFuseBurnStop(object target, effect fx, int reason, bool temp)
{
	if (temp)
		return FX_OK;
	Sound("Fire::FuseLoop", {loop_count = -1});
	return FX_OK;
}

public func DoExplode()
{
	// Cast lots of shrapnel.
	var shrapnel_count = 20;
	for (var cnt = 0; cnt < shrapnel_count; cnt++)
	{
		var shrapnel = CreateObjectAbove(Shrapnel);
		shrapnel->SetVelocity(Random(359), RandomX(100, 140));
		shrapnel->SetRDir(-30 + Random(61));
		shrapnel->Launch(GetController());
		CreateObject(BulletTrail)->Set(shrapnel, 2, 30);
	}
	if (GBackLiquid())
		Sound("Fire::BlastLiquid2");
	else
		Sound("Fire::BlastMetal");
	CreateParticle("Smoke", PV_Random(-30, 30), PV_Random(-30, 30), 0, 0, PV_Random(40, 60), Particles_Smoke(), 60);
	Explode(28);
	return;
}

protected func Hit(int x, int y)
{
	if (armed) 
		return DoExplode();
	return StonyObjectHit(x,y);
}

protected func Incineration(int caused_by)
{
	Extinguish(); 
	Fuse();
	SetController(caused_by);
	return;
}

// Drop fusing bomb on death to prevent explosion directly after respawn
public func IsDroppedOnDeath(object clonk)
{
	return !!GetEffect("FuseBurn", this);
}

public func HasExplosionOnImpact() { return armed; }

public func IsWeapon() { return true; }
public func IsArmoryProduct() { return true; }
public func IsGrenadeLauncherAmmo() { return true; }
public func IsExplosive() { return true; }

/*-- Properties --*/

local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local BlastIncinerate = 1;
local ContactIncinerate = 1;
local Components = {Firestone = 1, Metal = 1};