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 (105 lines) | stat: -rw-r--r-- 2,112 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
/**
	Grass 
	Is placed just behind the landscape.
	
	@authors
*/

protected func Initialize()
{
	DoCon(Random(50));
	if (Random(2))
		SetGraphics("1");
	return;
}

public func Incineration()
{
	Destroy();
	return;
}

public func CanBeHitByShockwaves() { return true; }

public func OnShockwaveHit()
{	
	Destroy();
	return true;
}

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

// Place some grass at the surface in the given area. The amount determines the density.
public func Place(int amount, proplist area)
{
	// Definition call.
	if (this != Grass)
		return;
	var rectangle = Shape->LandscapeRectangle();
	if (area) 
		rectangle = area->GetBoundingRectangle(); 
		
	var grass_list = [];
	for (var x = rectangle.x; x <= rectangle.x + rectangle.wdt; x += 9)
	{
		for (var y = rectangle.y; y <= rectangle.y + rectangle.hgt; y += 3)
		{
			if (GetMaterial(AbsX(x), AbsY(y)) == Material("Sky") && GetMaterial(AbsX(x), AbsY(y + 3)) == Material("Earth"))
			{
				if (Random(100) < amount)
				{
					var grass =	CreateObjectAbove(Grass, AbsX(x), AbsY(y + 1));
					PushBack(grass_list, grass);
				}
			}
		}
	}
	return grass_list;
}

// OUTDATED: use Grass->Place() instead, this function will be removed at some point.
global func PlaceGrass(int amount, int start, int end, int height, int bottom)
{
	if (!start)
		start = 0;
	if (!end)
		end = LandscapeWidth();
	if(!height)
		height = 0;
	if(!bottom)
		bottom = LandscapeHeight();
		
	var x = start, y; 
	while (x < end)
	{
		y = height;
		while (y < bottom)
		{
			if (GetMaterial(AbsX(x), AbsY(y)) == Material("Sky"))
				if (GetMaterial(AbsX(x), AbsY(y + 3)) == Material("Earth"))
					if (Random(100) < amount)
						CreateObjectAbove(Grass, AbsX(x), AbsY(y + 1), NO_OWNER);
			y += 3;
		}
		x += 9;
	}
}

public func SaveScenarioObject(props)
{
	if (!inherited(props, ...)) return false;
	props->Remove("Con");
	return true;
}


/*-- Properties --*/

local Name = "$Name$";
local Plane = -1;
local Placement = 0;
local BlastIncinerate = 1;