File: Script.c

package info (click to toggle)
openclonk 7.0-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 145,828 kB
  • ctags: 33,094
  • sloc: cpp: 163,891; ansic: 82,846; xml: 29,876; python: 1,203; php: 767; makefile: 138; sh: 77
file content (81 lines) | stat: -rwxr-xr-x 2,142 bytes parent folder | download | duplicates (6)
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
/**
	Elevator control
	This is to include in every vehicle that should fit into the elevator case. It will bypass the controls [Up] and [Down] to the elevator case.
	Also, only these objects will get snatched into the case.

	@author Clonkonaut
*/

// This object fits into an elevator case
public func FitsInElevator()
{
	return true;
}

// Set to true for objects that only fit into a double elevator
// Objects will be centered inbetween the two cases
public func FitsInDoubleElevator()
{
	return false;
}

/* Controls */

func ControlUp(object clonk)
{
	if (GetEffect("ElevatorControl", this)) return Control2Elevator(CON_Up, clonk);
	return _inherited(clonk);
}
func ControlDown(object clonk)
{
	if (GetEffect("ElevatorControl", this)) return Control2Elevator(CON_Down, clonk);
	return _inherited(clonk);
}
func ControlStop(object clonk, int control)
{
	if (GetEffect("ElevatorControl", this))
		if (control == CON_Up || control == CON_Down)
		{
			var effect = GetEffect("ElevatorControl", this);
			effect.controlled = nil;
			return effect.case->ControlStop(clonk, control);
		}
	return _inherited(clonk, control);
}

func Control2Elevator(int control, object clonk)
{
	var effect = GetEffect("ElevatorControl", this);
	if (control == CON_Up)
		effect.case->ControlUp(clonk);
	if (control == CON_Down)
		effect.case->ControlDown(clonk);
	effect.controlled = control;
}

/* Effect */

public func FxElevatorControlStart(object vehicle, proplist effect, int temp, object case)
{
	if (temp) return;
	effect.case = case;
}

public func FxElevatorControlTimer(object vehicle, proplist effect)
{
	if(!effect.case) return FX_Execute_Kill;
	if(effect.case->OutOfRange(vehicle)) return FX_Execute_Kill;

	if (effect.controlled && !FindObject(Find_Action("Push"), Find_ActionTarget(vehicle)))
	{
		effect.case->ControlStop(vehicle, effect.controlled);
		effect.controlled = nil;
	}
}

public func FxElevatorControlStop(object vehicle, proplist effect, int reason, bool temp)
{
	if (temp) return;
	if (effect.controlled && effect.case)
		effect.case->ControlStop(FindObject(Find_Action("Push"), Find_ActionTarget(vehicle)), effect.controlled);
}