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 (93 lines) | stat: -rw-r--r-- 2,049 bytes parent folder | download | duplicates (6)
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
/*-- Bubble --*/

local Plane = 300;

local creator; // The object that has created this bubble. Used to prevent Clonk from breathing from his own bubbles.

global func Bubble(int amount, int x, int y)
{
	if (amount==nil || amount==0) 
		amount=3;

	for (var i = 0; i < amount; i++)
	{
		var bubble = CreateObjectAbove(Fx_Bubble, x, y, NO_OWNER);
		if (bubble) bubble.creator = this;
	}
	return;
}

global func CastBubbles(int num, int level, int x, int y)
{
	return CastObjects(Fx_Bubble, num, level, x, y);
}

protected func Initialize()
{
	DoCon(RandomX(25, 100));
	AddEffect("Move", this, 100, 2, this);
	return;
}

public func FxMoveTimer(object target, effect, int time)
{
	if (!GBackLiquid(0, -3) && !GetEffect("Fade", this) || time > 108)
		AddEffect("Fade", target, 100, 1, target);

	// Bubbles burst into smaller bubles
	if (!Random(25) && target->GetCon() > 100)
	{
		for (var i = 0; i < 2; i++)
		{
			var bubble = CreateObjectAbove(Fx_Bubble);
			bubble->SetCon(2 * target->GetCon() / 3);
			bubble->SetYDir(target->GetYDir());
			bubble.creator = this.creator;
		}
		RemoveObject();
		return -1;
	}

	// Jittery movement
	SetYDir(GetYDir() - 3 + Random(7));
	if (Inside(GetXDir(), -6, 6))
		SetXDir(GetXDir() + 2 * Random(2) - 1);

	return 1;
}

public func FxFadeStart(object target, effect, int temporary)
{
	// Store alpha here
	if (temporary == 0)
		effect.alpha = 255;
	return 1;
}

public func FxFadeTimer(object target, effect)
{
	var alpha = effect.alpha;
	if (alpha <= 0)
	{
		RemoveEffect("Move", this);
		RemoveObject();
		return -1;
	}
	SetClrModulation(RGBa(255, 255, 255, alpha));
	effect.alpha = alpha - 5;
	return 1;
}

func OnClonkBreath(object clonk)
{
	// A Clonk is breathing us in
	clonk->DoBreath(GetCon()); // sound would be cool
	RemoveObject();
	return true;
}

// Bubbles can be breathed in by anything but their creator
func CanBeBreathed(object by_clonk) { return !creator || (by_clonk != creator); }

// No need to blow up scenario object list with bubble spam
func SaveScenarioObject() { return false; }