File: Script.c

package info (click to toggle)
openclonk 8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 169,484 kB
  • sloc: cpp: 180,478; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 139; sh: 101
file content (152 lines) | stat: -rw-r--r-- 2,962 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/** 
	Dynamite Igniter
	Can be used to ignite dynamite from a distance.
	
	@author Newton
*/

#include DynamiteBox


/*-- Engine Callbacks --*/

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


/*-- Callbacks --*/

public func OnFuseFinished()
{
	if (Contained() != nil) 
		return ResetClonk(Contained());
	return RemoveObject();
}

/*-- Usage --*/

public func HoldingEnabled() { return true; }

public func ControlUseStart(object clonk, int x, int y)
{
	if (clonk->GetAction() != "Walk") 
		return true;
	if (IsBeingIgnited())
		return true;
		
	var ignite_time = 40;
	// Launch the ignition effect.
	CreateEffect(FxScheduleIgnite, 100, ignite_time, clonk);

	// The clonk has to stand.
	clonk->SetAction("Stand");
	clonk->SetXDir(0);

	// Play ignite animation.
	clonk->PlayAnimation("DoIgnite", CLONK_ANIM_SLOT_Arms, Anim_Linear(0, 0, clonk->GetAnimationLength("DoIgnite"), ignite_time, ANIM_Hold), Anim_Const(1000));
	PlayAnimation("Ignite", 1, Anim_Linear(0, 0, GetAnimationLength("Ignite"), ignite_time, ANIM_Hold));
	return true;
}

public func ControlUseStop(object clonk, int x, int y)
{
	var fx = GetEffect("FxScheduleIgnite", this);
	if (fx)
		fx->Remove();
	return true;
}

public func ControlUseCancel(object clonk, int x, int y)
{
	var fx = GetEffect("FxScheduleIgnite", this);
	if (fx)
		fx->Remove();
	return true;
}

local FxScheduleIgnite = new Effect
{
	Construction = func(object clonk)
	{
		this.clonk = clonk;
	},
	Timer = func()
	{
		Target->Ignite(this.clonk);
		return FX_Execute_Kill;	
	},
	Destruction = func()
	{
		Target->ResetClonk(this.clonk, false);
	}
};

public func IsBeingIgnited()
{
	return !!GetEffect("FxScheduleIgnite", this);
}

public func Ignite(object clonk)
{
	// Ignite all connected wires
	for (var obj in FindFuses())
		obj->~StartFusing(this);
	ScheduleCall(this, "ResetClonk", 4, 1, clonk, true);
	return;
}

public func ResetClonk(object clonk, bool remove_igniter)
{
	// Reset animation of the clonk.
	clonk->StopAnimation(clonk->GetRootAnimation(CLONK_ANIM_SLOT_Arms));
	clonk->SetAction("Walk");
	if (remove_igniter)
		clonk->DetachObject(this);
	// Reset animation of the igniter and remove it.
	StopAnimation(GetRootAnimation(1));
	if (remove_igniter)
		RemoveObject();
	return;
}


/*-- Production --*/

public func IsTool() { return true; }
public func IsChemicalProduct() { return false; }


/*-- Display --*/

public func GetCarryMode()
{
	return CARRY_BothHands;
}

public func GetCarryPhase() { return 250; }

public func GetCarryTransform()
{
	if (IsBeingIgnited())
		return Trans_Mul(Trans_Rotate(0, 1), Trans_Translate(-1000));
}

public func GetCarrySpecial()
{ 
	if (IsBeingIgnited())
		return "pos_hand2";
}

public func Definition(proplist def)
{
	SetProperty("PictureTransformation", Trans_Mul(Trans_Rotate(-25, 1, 0, 0), Trans_Rotate(40, 0, 1, 0)), def);
}


/*-- Properties --*/

local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;