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 (130 lines) | stat: -rw-r--r-- 2,562 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
/**
	Firefly
	A small glowing being, often encountered in groups.
	
	@authors Randrian, Nachtschatten
*/

#include Library_InsectSwarm

local lib_swarm_standard = 10;
local lib_insect_max_dist = 40;
local lib_swarm_density = 8;
local lib_insect_nocturnal = true;

public func Initialize()
{
	SetAction("Fly");
	SetGraphics("", GetID(), 1, 1, nil, GFX_BLIT_Additive);
	SetClrModulation(RGBa(200, 255, 100, 50), 1);
	SetGraphics("", GetID(), 2, 1, nil, GFX_BLIT_Additive);
	SetClrModulation(RGBa(200, 255, 0, 255), 2);
	SetObjDrawTransform(300, 0, 0, 0, 300, 0, 2);
	
	// Fireflies shine a bit of light.
	SetLightRange(5, 30);
	SetLightColor(RGB(200, 255, 100));
	return _inherited(...);
}

public func Death()
{
	_inherited(...);
	return RemoveObject();
}

public func CatchBlow()
{
	_inherited(...);
	return RemoveObject();
}

public func Damage()
{
	_inherited(...);
	return RemoveObject();
}

// Attracted to trees.
private func GetAttraction(proplist coordinates)
{
	// Sometimes I don't want to fly to a plant.
	if (!Random(7)) return false;
	for (var plant in FindObjects(Find_Distance(150), Find_Func("IsTree"), Sort_Distance()))
	{
		if (!Random(4))
			continue;
		if (ObjectDistance(plant) < 20) // Too close.
			continue;
		if (plant->GetCon() < 30) // Too small.
			continue;
		if (plant->GBackSemiSolid()) // Under water or covered with solid material.
			continue;
		var width = plant->GetObjWidth();
		var height = plant->GetObjHeight();
		coordinates.x = plant->GetX() + Random(width) - width / 2;
		// The firefly assumes that the main part of a plant is in the upper half (below could just be the trunk).
		coordinates.y = plant->GetY() - Random(height) / 2;
		return true;
	}
	return false;
}

private func MissionComplete()
{
	// Fireflies are active.
	MoveToTarget();
	return;
}

// No sleeping.
private func Sleep()
{
	this.Visibility = VIS_None;
	_inherited(...);
}


private func WakeUp()
{
	this.Visibility = VIS_All;
	_inherited(...);
}

// Action end call.
private func Check()
{
	// Buried or in water: Instant death
	if (GBackSemiSolid())
	{
		Kill();
	}
	return;
}


/*-- Properties --*/

local ActMap = {
	Fly = {
		Prototype = Action,
		Name = "Fly",
		Procedure = DFA_FLOAT,
		Speed = 30,
		Accel = 5,
		Decel = 5,
		Directions = 2,
		Length = 1,
		Delay = 1,
		NextAction = "Fly",
		EndCall = "Check",
	},
};

local Name = "$Name$";
local MaxEnergy = 40000;
local MaxBreath = 125;
local Placement = 2;
local NoBurnDecay = true;
local BorderBound = C4D_Border_Sides | C4D_Border_Top | C4D_Border_Bottom;
local ContactCalls = true;