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 (150 lines) | stat: -rw-r--r-- 2,842 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
/**
	Sproutberry
	Fresh from nature's garden.
*/

#include Library_Edible

/*-- Engine Callbacks --*/

public func Construction()
{
	this.MeshTransformation = Trans_Scale(1500, 1500, 1500);
}

func Hit()
{
	Sound("Hits::SoftHit1");
}

// sproutberries are extremely unstable and likely to grow a new plant if not carried
func Departure(object what)
{
	if(!GetEffect("SproutCheck", this))
		AddEffect("SproutCheck", this, 1, 10, this);
}

func SaveScenarioObject(props, ...)
{
	// Do not save berries that are still attached to bushes
	if (Contained())
		if (Contained()->GetID() == SproutBerryBush_Sprout)
			return false;
	return inherited(props, ...);
}

/*-- Sprouting --*/

func FxSproutCheckTimer(target, effect, time)
{
	var c = Contained();
	if(c)
	{
		if(c->GetCategory() & C4D_Living)
		{
			return -1;
		}
	}
	
	// can only create a new bush after some time
	// or faster if burried!
	if(time < 35 * 30) return;
	if(!GBackSolid(0, -1))
		if(time < 35 * 60) return;
	
	// okay, create a bush or just remove
	this.Collectible = 0;
	
	// graphical effect
	AddEffect("Shrink", this, 1, 2, this);
	
	var y = -10;
	for(;y < 10; ++y)
	{
		if(GBackSolid(0, y+1)) break;
	}
	
	// no fitting ground found :/
	if((!GBackSolid(0, y+1)) || GBackSolid(0, y))
	{
		return -1;
	}
	
	// already a bush here?
	var b;
	if(b = FindObject(Find_Distance(20 + Random(10)), Find_ID(SproutBerryBush)))
	{
		// extra fertilizer
		b.saved_water += SproutBerryBush_water_per_berry * 2;
		return -1;
	}
	
	// create a bush!
	var bush = CreateObjectAbove(SproutBerryBush, 0, y + 8, NO_OWNER);
	
	// no insta-bush please..
	bush->GrowNormally();
	
	// no water is lost
	bush.saved_water += SproutBerryBush_water_per_berry;
	
	// but make sure the bush is removed if it can not grow sprouts after some time
	AddEffect("BushSuitable", bush, 1, 35 * 60 * 5, nil, GetID());
}

func FxBushSuitableTimer(target, effect, time)
{
	// bush could not grow yet :(
	if(target.sprout_count == 0)
	{
		target->Die();
	}
	
	// everything seems alright!
	return -1;
}

func FxShrinkStart(target, effect, temp)
{
	if(temp) return;
	effect.size = 1000;
	effect.color_sub = 0;
}

func FxShrinkTimer(target, effect, time)
{
	effect.size -= 10;
	
	// if contained we do not need a visual effect before removing..
	if((effect.size <= 0) || Contained())
	{
		RemoveObject();
		return -1;
	}
	
	SetObjDrawTransform(1000, 0, 0, 0, effect.size, 1000 - effect.size);
	
	if(effect.color_sub < 255)
	{
		effect.color_sub = Min(effect.color_sub + 5, 255);
		SetClrModulation(RGB(255 - effect.color_sub / 3, 255 - effect.color_sub / 2, 255 - effect.color_sub));
	}
}

/*-- Display --*/

public func GetCarryMode()
{
	return CARRY_Hand;
}

public func GetCarryBone()
{
	return "Main";
}

/*-- Properties --*/

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