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 (233 lines) | stat: -rwxr-xr-x 5,173 bytes parent folder | download
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
	HUD Adapter
		
	Clonk-side scripts for the HUD. This object basically redirects the
	engine callbacks for the clonk to the HUD. All crew members that
	are to be shown in the HUD have to include this object and return
	_inherited(); if they overload one of the callbacks used here.

	This adapter redirects to the per player HUD controller and also
	directly to the per clonk HUD selector.

	Requires the ClonkControl.ocd to be included in the clonk too.

	@authors Newton
*/

local HUDcontroller;

public func IsHUDAdapter()
{
	return true;
}

// Either returns the current HUD controller or creates one.
// But only if owner is a human otherwise returns nil.
private func GetHUDController()
{
	var plr = GetOwner();
	if (GetPlayerType(plr) != C4PT_User) return nil;
	if (HUDcontroller) return HUDcontroller;
	HUDcontroller = FindObject(Find_ID(GUI_Controller), Find_Owner(plr));
	if (!HUDcontroller)
		HUDcontroller = CreateObject(GUI_Controller, AbsX(0), AbsY(0), plr);
	return HUDcontroller;
}

// Update HUD controller e.g. when it was reinitialized
public func SetHUDController(object new_controller)
{
	HUDcontroller = new_controller;
	return true;
}

/*-- Engine callbacks --*/

// Bootstrap the HUD on the recruitement of a crew member.
private func Recruitment(int plr)
{
	if (GetHUDController())
	{
		HUDcontroller->~OnCrewRecruitment(this, plr, ...);
		HUDcontroller->~ScheduleUpdateInventory();
	}
	return _inherited(plr, ...);
}

// On savegame load or after section change, ensure that there's a HUD adapter
public func OnSynchronized(...)
{
	if (GetHUDController())
		HUDcontroller->~ScheduleUpdateInventory();
	return _inherited(...);
}

private func DeRecruitment(int plr)
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewDeRecruitment(this, plr, ...);
	return _inherited(plr, ...);
}

private func Death(int killed_by)
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewDeath(this, killed_by, ...);
	return _inherited(killed_by, ...);
}

private func Destruction()
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewDestruction(this, ...);
	return _inherited(...);
}

public func ControlHotkey(int hotindex)
{
	if (HUDcontroller)
		return HUDcontroller->~ControlHotkey(hotindex);
}

private func OnPromotion()
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewRankChange(this);
	return _inherited(...); 
}

private func OnEnergyChange(int change, int cause, int caused_by)
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewHealthChange(this, change, cause, caused_by);
	return _inherited(...);

}
private func OnBreathChange(int change)
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewBreathChange(this, change);
	return _inherited(...);
}

private func OnMagicEnergyChange(int change)
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewMagicChange(this, change);
	return _inherited(...);
}

private func OnNameChanged()
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewNameChange(this);
	return _inherited(...);
}

private func OnPhysicalChange(string physical, int change)
{
	if (HUDcontroller)
	{
		if (!physical)
		{
			HUDcontroller->~OnCrewHealthChange(this, change);
			HUDcontroller->~OnCrewBreathChange(this, change);
		}
		else if (physical == "Energy") HUDcontroller->~OnCrewHealthChange(this, change);
		else if (physical == "Breath") HUDcontroller->~OnCrewBreathChange(this, change);
	}
	return _inherited(physical, change, ...);
}

private func CrewSelection(bool unselect)
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewSelection(this, unselect);
	return _inherited(unselect, ...);
}

private func OnCrewEnabled()
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewEnabled(this);
	return _inherited(...);
}

private func OnCrewDisabled()
{
	if (HUDcontroller)
		HUDcontroller->~OnCrewDisabled(this);
	return _inherited(...);
}

// from ClonkControl.ocd
private func OnSlotFull(int slot)
{
	if (HUDcontroller)
		HUDcontroller->~OnSlotObjectChanged(slot);
	return _inherited(slot, ...);
}

private func OnSlotEmpty(int slot)
{
	if (HUDcontroller)
		HUDcontroller->~OnSlotObjectChanged(slot);
	return _inherited(slot, ...);
}

// handled by GUI_Controller_ActionBars
func StartInteractionCheck(object clonk)
{
	if (HUDcontroller)
		return HUDcontroller->~StartInteractionCheck(clonk, ...);
}

// handled by GUI_Controller_ActionBars
func StopInteractionCheck()
{
	if (HUDcontroller)
		return HUDcontroller->~StopInteractionCheck(...);
}

private func OnInventoryHotkeyPress(int slot)
{
	if (HUDcontroller)
		HUDcontroller->~OnInventoryHotkeyPress(slot);
	return _inherited(slot, ...);
}

private func OnInventoryHotkeyRelease(int slot)
{
	if (HUDcontroller)
		HUDcontroller->~OnInventoryHotkeyRelease(slot);
	return _inherited(slot, ...);
}

// when something in the inventory changed
private func OnInventoryChange()
{
	if (HUDcontroller)
		HUDcontroller->~ScheduleUpdateInventory();
	return _inherited(...);
}

public func Collection2()
{
	if (HUDcontroller)
		HUDcontroller->~ScheduleUpdateInventory();
	return _inherited(...);
}

public func Ejection()
{
	if (HUDcontroller)
		HUDcontroller->~ScheduleUpdateInventory();
	return _inherited(...);
}

public func ControlContents()
{
	if (HUDcontroller)
		HUDcontroller->~ScheduleUpdateInventory();
	return _inherited(...);
}