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 (122 lines) | stat: -rw-r--r-- 2,493 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
/**
	Lamp Library
	Include this by all lamps that should hang outside buildings.
	
	@author Clonkonaut
*/

/** Must define a dummy definition (i.e. the object which is shown outside the building)
*/
public func DummyDefinition() {}

/** Whether or not the lamp is on (true then).
*/
local lib_lamp_lit;

/** This is a lamp.
*/
public func IsLamp() { return true; }

/** Lamp property: How far it shines.
*/
public func GetLampRange() { return 160; }

/** Lamp property: How far it shines into material.
*/
public func GetLampFadeRange() { return 160; }

/** Lamp property: Which color it shines in.
*/
public func GetLampColor() { return FIRE_LIGHT_COLOR; }

/** Overload as needed to define a custom offset by the lamp.
*/
public func LampOffset() {}

/*-- Convenient calls --*/

/** Standard turning on procedure. Overload as needed.
	Default behaviour: lib_lamp_lit to true, light range 80,60, inherited
*/
public func TurnOn()
{
	if (lib_lamp_lit) return false;
	_inherited(...);
	TurnLightOn();
	lib_lamp_lit = true;
	return true;
}

func TurnLightOn()
{
	SetLightRange(this->GetLampRange(), this->GetLampFadeRange());
	SetLightColor(this->GetLampColor());
}

/** Standard turning off procedure. Overload as needed.
	Default behaviour: lib_lamp_lit to false, light range 0,0, inherited
*/
public func TurnOff()
{
	if (!lib_lamp_lit) return false;
	_inherited(...);
	TurnLightOff();
	lib_lamp_lit = false;
	return true;
}

func TurnLightOff()
{
	SetLightRange(0, 0);
}

// Returns whether the lamp currently is a source of light.
public func IsLightSource()
{
	return lib_lamp_lit;
}

/*-- Usage --*/

/** Standard control procedure. Overload as needed.
	Default behaviour: If clonk is ready, either turn on or off.
*/
public func ControlUse(object clonk)
{
	// Only do something if the clonk can do an action.
	if (!clonk->HasHandAction())
		return true;
	// Turn on or off
	if (lib_lamp_lit) {
		TurnOff();
	} else {
		TurnOn();
	}
	Sound("UI::Click2");
	return true;
}

/*-- Further stuff --*/

/** Calls LampDeparture() in the departed object.
*/
public func Departure(object container)
{
	container->~LampDeparture(this);
}

/** Calls LampDestruction() in a container if contained.
*/
public func Destruction()
{
	if (Contained()) Contained()->~LampDestruction(this);
}

/** Scenario saving: Store whether lamp is on
*/
public func SaveScenarioObject(props, ...)
{
	if (!_inherited(props, ...)) return false;
	if (lib_lamp_lit) props->AddCall("Lamp", this, "TurnOn");
	return true;
}