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 (71 lines) | stat: -rw-r--r-- 1,620 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
/**
	Flower
	The beauty in nature

	@author Nachtfalter, Armin
*/

#include Library_Plant

local is_explicit_skin = false;

local plant_seed_chance = 33;
local plant_seed_area = 120;
local plant_seed_amount = 6;
local plant_seed_offset = 5;

public func Construction()
{
	StartGrowth(1);
	SetSkin(Random(4));
	is_explicit_skin = false;
	SetProperty("MeshTransformation", Trans_Mul(Trans_Scale(RandomX(850,1200)), Trans_Rotate(RandomX(0,359),0,1,0)));
	
	inherited(...);
}

// Set one of four possible flower skins (skin from 0 to 3)
// Also makes the skin explicit for saved scenarios
public func SetSkin(int skin)
{
	var skin_name = "flower";
	if (skin) skin_name = Format("flower%d", skin);
	SetMeshMaterial(skin_name);
}

public func SetMeshMaterial(...)
{
	is_explicit_skin = true;
	return inherited(...);
}

public func Incineration()
{
	CreateParticle("Grass", 0, 0, PV_Random(-20, 20), PV_Random(-20, 10), PV_Random(30, 100), Particles_Straw(), 10);
	RemoveObject();
}

public func SaveScenarioObject(proplist props, ...)
{
	if (!inherited(props, ...)) return false;
	// Do not set automatic skin, but set it if made explicit (or e.g. an external flower skin was used)
	if (!is_explicit_skin)
		props->Remove("MeshMaterial");
	else
	{
		var mat = GetMeshMaterial();
		var flower_skins = ["flower", "flower1", "flower2", "flower3"];
		var skin = GetIndexOf(flower_skins, mat);
		if (skin >= 0)
		{
			props->Remove("MeshMaterial");
			props->AddCall("MeshMaterial", this, "SetSkin", skin);
		}
	}
	return true;
}

local Name = "$Name$";
local BlastIncinerate = 1;
local ContactIncinerate = 3;
local Placement = 4;