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 (99 lines) | stat: -rwxr-xr-x 2,876 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
/**
	Mechanism
	
	A mechanism is something that can be controlled via input signals.
	* the input signal is sent by another object, which is usually a switch
	* for simplicity, we currently allow one input signal
	* for simplicity, we currently allow only boolean input signal
	
	Needs to call _inherited in the following functions:
	* Construction()
	
	@author Marky
*/


local lib_mechanism;

/*-- Engine callbacks --*/

public func Construction(object by_object)
{
	_inherited(by_object, ...);
	lib_mechanism = {
		set_plr_view = true,	// sets the player view to this object when the input signal changes
		temp_light = nil,		// temporary light, so that the player can see something when the object is being operated
	};
}

/*-- Public Interface --*/

/*
 Sets the input signal of this mechanism.
 
 This function should handle everything that happens when the input
 signal is set (on the generic level).
 For the object-specific functionality this function issues a callback to the object:
 * OnSetInputSignal(operator, sender, value)
 
 Use the callback to activate or deactivate certain functions in the mechanism.
 For example, the stone door opens if you pass 'true', and closes if you pass 'false'
 
 That callback happens after the generic handling is done, so that the object
 can safely be deleted in the callback.

 @par operator this object is operating the mechanism or the object that sent the signal-
 @par sender this object sent the signal - this is usually a switch.
 @par value this value is sent.
*/
public func SetInputSignal(object operator, object sender, bool value)
{
	// Show the object being operated
	if (operator && lib_mechanism.set_plr_view)
	{
		SetPlrView(operator->GetController(), this);
		if (lib_mechanism.temp_light)
		{
			lib_mechanism.temp_light->RemoveObject();
		}
		lib_mechanism.temp_light = Global->CreateLight(this->GetX(), this->GetY() + this->~GetFloorOffset(), 30, Fx_Light.LGT_Temp, operator->GetController(), 30, 50);
	}

	// Callback: current signal
	this->~OnSetInputSignal(operator, sender, value);
}


/*
 Determines whether the object should show that it is
 being operated when the signal changes.
 
 By default this is set to true.
 */
public func SetPlrViewOnSignalChange(bool show)
{
	lib_mechanism.set_plr_view = show;
}


/*-- Saving --*/

public func SaveScenarioObject(proplist props)
{
	if (!inherited(props, ...)) return false;
	if (lib_mechanism.set_plr_view) props->AddCall("PlrView", this, "SetPlrViewOnSignalChange", lib_mechanism.set_plr_view);
	return true;
}

/*-- Editor --*/

public func Definition(proplist def)
{
	if (!def.EditorProps) def.EditorProps = {};
	def.EditorProps.set_plr_view =  { Name = "$SetPlrView$", EditorHelp="$SetPlrViewDesc$", Type="bool", Set="SetPlrViewOnSignalChange" };
	return _inherited(def, ...);
}

/*-- Properties --*/

public func IsSwitchTarget() { return true; }