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 (123 lines) | stat: -rw-r--r-- 2,839 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
/**
	Call Airship
	Attached to the player which adds an interaction to call the airship.
	
	@author Maikel
*/


local pilot;
local airship;

public func Create(object clonk, object pilot, object airship)
{
	if (this != Helper_CallAirship)
		return;
	var helper = clonk->CreateObject(Helper_CallAirship);
	helper->SetAction("Attach", clonk);
	helper->SetPilot(pilot);
	helper->SetAirship(airship);
	return;
}

public func SetPilot(object to)
{
	pilot = to;
	return;
}

public func SetAirship(object to)
{
	airship = to;
	return;
}


/*-- Interaction --*/

// Players can talk to NPC via the interaction bar.
public func IsInteractable(object clonk) { return pilot && airship && ObjectDistance(clonk, airship) >= this.CallDistance; }

// Adapt appearance in the interaction bar.
public func GetInteractionMetaInfo(object clonk)
{
	if (GetEffect("MoveAirship", this))
		return { Description = "$MsgStopAirship$", IconName = nil, IconID = airship };
	return { Description = "$MsgCallAirship$", IconName = nil, IconID = airship };
}

// Called on player interaction.
public func Interact(object clonk)
{
	if (!clonk || !pilot || !airship)
		return true;
		
	if (GetEffect("MoveAirship", this))
		RemoveEffect("MoveAirship", this);
	else
		AddEffect("MoveAirship", this, 100, 1, this, nil, clonk, pilot, airship);
	return true;
}


/*-- Movement --*/

private func FxMoveAirshipStart(object target, proplist effect, int temp, object clonk, object pilot, object airship)
{
	if (temp)
		return FX_OK;
	effect.clonk = clonk;
	effect.pilot = pilot;
	effect.airship = airship;
	// Let the pilot grab the airship.
	effect.pilot->SetCommand("Grab", airship);
	// Let the pilot play a confirm sound.
	effect.pilot->PlaySoundConfirm();
	return FX_OK;
}

private func FxMoveAirshipTimer(object target, proplist effect)
{
	if (!effect.clonk || !effect.pilot || !effect.airship)
		return FX_Execute_Kill;
		
	if (ObjectDistance(effect.clonk, effect.airship) < this.CallDistance)
		return FX_Execute_Kill;
		
	if (effect.airship->GetCommand())
		return FX_OK;
	// Add a move to command to a bit above the clonk.	
	airship->SetCommand("MoveTo", nil, effect.clonk->GetX(), effect.clonk->GetY() - effect.airship->GetBottom() + effect.clonk->GetTop());
	return FX_OK;
}

private func FxMoveAirshipStop(object target, proplist effect, int reason, bool temp)
{
	if (temp)
		return FX_OK;
	// Let the pilot ungrab the airship.	
	if (effect.pilot)
		effect.pilot->SetCommand("UnGrab");
	// Remove the move command from the airship.
	if (effect.airship)
	{
		effect.airship->SetCommand("None");
		effect.airship->SetComDir(COMD_Stop);
	}
	return FX_OK;
}


/*-- Properties --*/

local ActMap = {
	Attach = {
		Prototype = Action,
		Name = "Attach",
		Procedure = DFA_ATTACH,
		Delay = 0,
		NextAction = "Attach",
	}
};
local Name = "$Name$";
local CallDistance = 60;