File: Script.c

package info (click to toggle)
openclonk 8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 169,520 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (120 lines) | stat: -rw-r--r-- 2,868 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
/**
	Smoke bomb
	Spreads lots of smoke.
		
	@author Maikel
*/


protected func Initialize()
{

	return;
}

public func ControlUse(object clonk, int x, int y)
{
	// If already active don't do anything and let the clonk throw it.
	if (GetEffect("IntSmokeBomb", this))
		return false;
	Fuse();
	return true;
}

public func Fuse()
{
	// Add smoking effect.
	if (!GetEffect("IntSmokeBomb", this))
		AddEffect("IntSmokeBomb", this, 100, 2, this);
	return;
}

protected func Hit()
{
	Sound("Hits::Materials::Metal::DullMetalHit?");
	return;
}


/*-- Smoking --*/

protected func FxIntSmokeBombStart(object target, proplist effect, int temp)
{
	if (temp)
		return FX_OK;
	// Interval and length.
	effect.Interval = 4;
	effect.length = 18 * 36;
	// Store particles.
	effect.lifetime = 24 * 36;
	effect.smoke =
	{
		R = 255,
		G = 255,
		B = 255,
		Alpha = PV_KeyFrames(1, 0, 200, 500, PV_Random(200, 255), 1000, 0),
		CollisionVertex = 1000,
		OnCollision = PC_Stop(),
		ForceX = PV_Wind(50, PV_Random(-4, 4)),
		ForceY = PV_Random(-2, 1, 10),
		DampingX = 850,
		DampingY = 850,
		Size = PV_KeyFrames(0, 0, 1, 10, PV_Random(30, 40), 1000, PV_Random(25, 50)),
		Phase = PV_Random(0, 15)
	};
	// Sound.
	Sound("Fire::Smoke", false, 100, nil, +1);
	Sound("Liquids::SmokeSizzle", false, 100, nil, +1);
	// Make non-collectible.
	this.Collectible = false;
	return FX_OK;
}

protected func FxIntSmokeBombTimer(object target, proplist effect, int time)
{
	if (time > effect.length)
		return FX_Execute_Kill;
		
	// Increas interval to draw more particles.
	if (time > effect.length / 6)
		effect.Interval = 4;
	if (time > effect.length / 4)
		effect.Interval = 3;
	if (time > effect.length / 3)
		effect.Interval = 2;
	if (time > 2 * effect.length / 3)
		effect.Interval = 1;

	// Particles for smoke and a bit of fire.		
	var smoke_dx = GetVertex(0, VTX_X);
	var smoke_dy = GetVertex(0, VTX_Y);
	var fuse_dx = GetVertex(1, VTX_X);
	var fuse_dy = GetVertex(1, VTX_Y);
	var smoke_life = (effect.lifetime - time/2);
	CreateParticle("Smoke", smoke_dx, smoke_dy, PV_Random(smoke_dx - 100, smoke_dx + 100),  PV_Random(smoke_dy - 60, smoke_dy + 60), smoke_life, effect.smoke, 4);
	CreateParticle("Fire", fuse_dx, fuse_dy, PV_Random(2 * fuse_dx - 3, 2 * fuse_dx + 3),  PV_Random(2 * fuse_dy - 3, 2 * fuse_dy + 3), PV_Random(10, 20), Particles_Glimmer(), 2);
	
	return FX_OK;
}

protected func FxIntSmokeBombStop(object target, proplist effect, int reason, bool temp)
{
	if (temp)
		return FX_OK;
	// Sound.
	Sound("Fire::Smoke", false, 100, nil, -1);
	Sound("Liquids::SmokeSizzle", false, 100, nil, -1);
	RemoveObject();
	return FX_OK;
}

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


/*-- Properties --*/

local Collectible = 1;
local Name = "$Name$";
local Description = "$Description$";
local Components = {Firestone = 1, Coal = 1, Metal = 1};