1 /**
2 	Flame
3 	Spreads fire.
4 
5 	@author Maikel
6 */
7 
8 
Initialize()9 public func Initialize()
10 {
11 	Incinerate(100, GetController());
12 	AddTimer("Burning", RandomX(24, 26));
13 	return;
14 }
15 
Burning()16 public func Burning()
17 {
18 	if (!OnFire())
19 		return RemoveObject();
20 	// Consume inflammable material and make the flame a little bigger.
21 	if (FlameConsumeMaterial() && GetCon() <= 80)
22 	{
23 		if (!this.NoBurnDecay)
24 		{
25 			DoCon(6);
26 			SetXDir(RandomX(-8, 8));
27 		}
28 	}
29 	// Split the flame if it is large enough and not too many flames are nearby.
30 	var amount = ObjectCount(Find_ID(GetID()), Find_Distance(10));
31 	if (amount < 5 && GetCon() > 50 && !this.NoBurnDecay && !Random(4))
32 	{
33 		var x = Random(15);
34 		var new_flame = CreateObjectAbove(GetID());
35 		new_flame->SetSpeed(x, -7);
36 		new_flame->SetCon(GetCon() / 2);
37 		SetSpeed(-x, -7);
38 		SetCon(GetCon() / 2);
39 	}
40 	return;
41 }
42 
DoCon(...)43 public func DoCon(...)
44 {
45 	var res = _inherited(...);
46 	// Update any existing fire effect, because it does not do it internally when NoBurnDecay is active.
47 	var fire_fx = GetEffect("Fire", this);
48 	if (fire_fx)
49 		EffectCall(this, fire_fx, "UpdateEffectProperties");
50 	return res;
51 }
52 
SetCon(...)53 public func SetCon(...)
54 {
55 	var res = _inherited(...);
56 	// Update any existing fire effect, because it does not do it internally when NoBurnDecay is active.
57 	var fire_fx = GetEffect("Fire", this);
58 	if (fire_fx)
59 		EffectCall(this, fire_fx, "UpdateEffectProperties");
60 	return res;
61 }
62 
63 
64 /*-- Saving --*/
65 
SaveScenarioObject(proplist props)66 public func SaveScenarioObject(proplist props)
67 {
68 	if (!inherited(props, ...))
69 		return false;
70 	// Don't incinerate twice in saved scenarios.
71 	props->Remove("Fire");
72 	return true;
73 }
74 
75 
76 /*-- Editor --*/
77 
EditorInitialize()78 public func EditorInitialize()
79 {
80 	// Assume the flame is eternal when placed in the editor
81 	this.NoBurnDecay = true;
82 	return;
83 }
84 
Definition(proplist def)85 public func Definition(proplist def)
86 {
87 	if (!def.EditorProps)
88 		def.EditorProps = {};
89 	def.EditorProps.NoBurnDecay = { Name = "$EditorEternal$", EditorHelp = "$EditorEternalHelp$", Type = "enum", Options = [{ Name = "$EditorEternalOff$", Value = false }, { Name = "$EditorEternalOn$", Value = true }] };
90 	return;
91 }
92 
93 
94 /*-- Properties --*/
95 
96 local Name = "$Name$";
97 local Description = "$Description$";
98 local Plane = 500;
99