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 (95 lines) | stat: -rw-r--r-- 1,972 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
/**
	Gravestone Rule
	Dead clonks are replaced by gravestones.
	
	@author Ringwaul
*/


local fade_out;


protected func Initialize()
{	
	// Under no circumstance there may by multiple copies of this rule.
	if (ObjectCount(Find_ID(Rule_Gravestones)) > 1)
		return RemoveObject();
	fade_out = nil;
	return;
}

public func SetFadeOut(int time)
{
	fade_out = time;
	return;
}

public func OnClonkDeath(object clonk)
{
	// Add a gravestone if the clonk died.
	if (!clonk->GetAlive())
		clonk->CreateEffect(FxAddGravestone, 100, 1, fade_out);
	return;
}

local FxAddGravestone = new Effect
{
	Construction = func(int fade_out)
	{
		this.fade_out = fade_out;	
	},
	Timer = func(int time)
	{
		// Wait for the death animation to be over.
		if (time >= 20)
			return FX_Execute_Kill;
		return FX_OK;
	},
	Destruction = func(int reason)
	{
		// Don't do anything if the clonk has been removed.
		if (reason == FX_Call_RemoveClear)
			return;
		// Create the grave and remove the clonk.
		this.grave = Target->CreateObjectAbove(Clonk_Grave, 0, 0, Target->GetController());
		this.grave->SetInscription(Target);
		if (this.fade_out > 0)
			this.grave->FadeOut(this.fade_out, true);
		Target->RemoveObject();
		// Smoke effect.
		var particles =
		{
			Prototype = Particles_Dust(),
			R = 200,
			G = 100,
			B = 50,
			Size = PV_KeyFrames(0, 0, 0, 300, 40, 1000, 15)
		};
		this.grave->CreateParticle("Dust", 0, 0, PV_Random(-3, 3), PV_Random(-3, 3), PV_Random(18, 1 * 36), particles, 6);
	}
};

public func Activate(int by_plr)
{
	MessageWindow(this.Description, by_plr);
	return true;
}


/*-- Scenario Saving -- */

public func SaveScenarioObject(props)
{
	if (!inherited(props, ...)) return false;
	if (fade_out != nil)
		props->AddCall("FadeOut", this, "SetFadeOut", fade_out);
	return true;
}


/*-- Properties --*/

local Name = "$Name$";
local Description = "$Description$";
local Visibility = VIS_Editor;
local EditorPlacementLimit = 1; // Rules are to be placed only once