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 (83 lines) | stat: -rw-r--r-- 2,165 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
/**
	Library_Flammable

	Contains the logic for any object/item that is flammable.
	Flammable objects (items) shouldn't burn like any other object because dealing with
	half burned (con < 100) items is a hassle.

	Implement OnBurnDown() to do this things right when the definition change is about to happen.
	Return true to prevent regular library behaviour.

	@author Clonkonaut
*/

// Obviously, we don't want these items to burn down
local NoBurnDecay = true;
// Items will burn for roughly 2 seconds until changing into a 'burned item' (no longer functional)
// Feel free to change this time in your object (in frames)
local BurnDownTime = 70;

public func Incineration(int caused_by)
{
	_inherited(caused_by);
	// You shouldn't remove the object in Incineration but let's check anyway
	if (!this) return;

	CreateEffect(LibraryFlammable, 1, 1, caused_by); // The effect will not last long, so timer 1 should be fine

	// Notify the clonk (if held) that this object is now burning
	if (Contained())
		Contained()->~OnInventoryChange();
}

public func Extinguishing()
{
	// Notify the clonk (if held) that this object is no longer burning
	if (Contained())
		Contained()->~OnInventoryChange();
}

local LibraryFlammable = new Effect {
	Construction = func (int caused_by)
	{
		this.caused_by = caused_by;
	},
	Timer = func (int time)
	{
		if (!this.Target->OnFire()) // Extinguished! No harm done
			return FX_Execute_Kill;
		if (time >= this.Target.BurnDownTime)
		{
			this.Target->BurnDown(this.caused_by);
			return FX_Execute_Kill;
		}
	}
};

public func BurnDown(int caused_by)
{
	if (this->~OnBurnDown())
		return;
	var burned = CreateObject(BurnedObject, 0, 0, GetOwner());
	var container = Contained();
	// Take over movement and rotation.
	burned->SetXDir(GetXDir(1000), 1000);
	burned->SetYDir(GetYDir(1000), 1000);
	burned->SetR(GetR());
	burned->SetRDir(GetRDir(1000), 1000);
	burned->Incinerate(100, caused_by);
	RemoveObject(true);
	if (container)
		burned->Enter(container);
}

public func GetInventoryIconOverlay() // Display a flame in the inventory bar
{
	if (!OnFire()) return;

	var overlay = 
	{
		Symbol = Icon_Flame
	};
	return overlay;
}