summaryrefslogtreecommitdiffstats
path: root/TemplePushing.c4s/Misc.c4d/SetupMenu.c4d/Script.c
blob: a453b2fd20cfdb670b4fffdfc2e35883dd10c314 (plain)
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*-- Setup Menu --*/

#strict 2

static const
	SETTING_Deathmatch = 0, SETTING_SuddenDeath = 1, SETTING_RotateInJump = 2,
	SETTING_RelaunchesInc = 3, SETTING_RelaunchesDec = 4,
	SETTING_DeathmatchScoreInc = 5, SETTING_DeathmatchScoreDec = 6,
	SETTING_Ambience = 7;

local Sections, Modes;
local clonk, setupPlayer;

// Selected values
local section, mode;
local selectRandomSection, selectRandomMode;
local suddendeathEnabled, rotateInJumpEnabled;
local ambienceEnabled;
local numRelaunches;
local deathmatchEnabled, deathmatchWinScore;

protected func Initialize()
{
	Sections = [];
	for (var i = 0, def; def = GetDefinition(i, C4D_StaticBack); ++i)
	{
		if (DefinitionCall(def, "SectionName")) Sections[GetLength(Sections)] = def;
	}
	section = Sections[0];

	Modes = [];
	for (var i = 0, def; def = GetDefinition(i, C4D_StaticBack); ++i)
	{
		if (DefinitionCall(def, "ModeName")) Modes[GetLength(Modes)] = def;
	}
	mode = Modes[0];
}

private func ShowSetup()
{
	ShowMessage();
	ShowSectionMenu();
}

private func ShowSectionMenu()
{
	CreateMenu(GetID(), clonk, 0, C4MN_Extra_None, 0, 0, C4MN_Style_Context);

	for (var i = 0; i < GetLength(Sections); ++i)
	{
		clonk->AddMenuItem(GetName(0, Sections[i]), Format("SelectSection(%i)", Sections[i]), Sections[i]);
		CheckPreselect(!selectRandomSection && Sections[i] == section, i);
	}

	clonk->AddMenuItem("$Random$", "SelectRandomSection()", SRND);
	CheckPreselect(selectRandomSection, GetLength(Sections));
}

private func SelectSection(id selectedSection)
{
	selectRandomSection = false;
	section = selectedSection;
	SectionSelectionDone();
}

private func SelectRandomSection()
{
	selectRandomSection = true;
	SectionSelectionDone();
}

private func SectionSelectionDone()
{
	ShowMessage();
	ShowModeMenu();
}

private func ShowModeMenu()
{
	CreateMenu(GetID(), clonk, 0, C4MN_Extra_None, 0, 0, C4MN_Style_Context);

	var menuItemIndex = 0;
	for (var m in Modes)
	{
		clonk->AddMenuItem(m->ModeName(), Format("SelectMode(%i)", m), m);
		CheckPreselect(!selectRandomMode && m == mode, menuItemIndex++);
	}

	clonk->AddMenuItem("$Random$", "SelectRandomMode()", SRND);
	CheckPreselect(selectRandomMode, menuItemIndex++);
	clonk->AddMenuItem("$Back$", "ShowSectionMenu()", SBCK);
}

private func SelectMode(id selectedMode)
{
	selectRandomMode = false;
	mode = selectedMode;
	ModeSelectionDone();
}

private func SelectRandomMode()
{
	selectRandomMode = true;
	ModeSelectionDone();
}

private func ModeSelectionDone()
{
	ShowMessage();
	ShowSettingsMenu();
}

private func ShowSettingsMenu(bool preselect, int selectedSetting)
{
	CreateMenu(GetID(), clonk, 0, C4MN_Extra_None, 0, 0, C4MN_Style_Context);

	var menuItemIndex = 0;

	// Deathmatch entry
	AddOptionMenuItem(GetName(0, DTHM), deathmatchEnabled, "SelectSetting(SETTING_Deathmatch)", DTHM);
	CheckPreselect(preselect && selectedSetting == SETTING_Deathmatch, menuItemIndex++);
	
	// Sudden Death entry
	AddOptionMenuItem(GetName(0, SDDT), suddendeathEnabled, "SelectSetting(SETTING_SuddenDeath)", SDDT);
	CheckPreselect(preselect && selectedSetting == SETTING_SuddenDeath, menuItemIndex++);
	
	// "Turn in jump" entry
	AddOptionMenuItem(GetName(0, RIJP), rotateInJumpEnabled, "SelectSetting(SETTING_RotateInJump)", RIJP);
	CheckPreselect(preselect && selectedSetting == SETTING_RotateInJump, menuItemIndex++);
	
	// Ambience entry
	AddOptionMenuItem("$Ambience$", ambienceEnabled, "SelectSetting(SETTING_Ambience)", SABC);
	CheckPreselect(preselect && selectedSetting == SETTING_Ambience, menuItemIndex++);

	if (!deathmatchEnabled)
	{
		clonk->AddMenuItem("$Relaunches$ +", "SelectSetting(SETTING_RelaunchesInc)", SREL);
		CheckPreselect(preselect && selectedSetting == SETTING_RelaunchesInc, menuItemIndex++);
		clonk->AddMenuItem("$Relaunches$ -", "SelectSetting(SETTING_RelaunchesDec)", SREL);
		CheckPreselect(preselect && selectedSetting == SETTING_RelaunchesDec, menuItemIndex++);
	}
	else
	{
		clonk->AddMenuItem("$Kills$ +", "SelectSetting(SETTING_DeathmatchScoreInc)", SKIL);
		CheckPreselect(preselect && selectedSetting == SETTING_DeathmatchScoreInc, menuItemIndex++);
		clonk->AddMenuItem("$Kills$ -", "SelectSetting(SETTING_DeathmatchScoreDec)", SKIL);
		CheckPreselect(preselect && selectedSetting == SETTING_DeathmatchScoreDec, menuItemIndex++);
	}

	clonk->AddMenuItem("$Done$", "SetupDone()", SDNE);
	CheckPreselect(!preselect, menuItemIndex++);
	clonk->AddMenuItem("$Back$", "ShowModeMenu()", SBCK);
}

private func SelectSetting(int selectedSetting)
{
	if (selectedSetting == SETTING_Deathmatch)
	{
		deathmatchEnabled = !deathmatchEnabled;
	}
	else if (selectedSetting == SETTING_SuddenDeath)
	{
		suddendeathEnabled = !suddendeathEnabled;
	}
	else if (selectedSetting == SETTING_RotateInJump)
	{
		rotateInJumpEnabled = !rotateInJumpEnabled;
	}
	else if (selectedSetting == SETTING_Ambience)
	{
		ambienceEnabled = !ambienceEnabled;
	}
	else if (selectedSetting == SETTING_RelaunchesInc)
	{
		numRelaunches = Min(numRelaunches + 1, 10);
	}
	else if (selectedSetting == SETTING_RelaunchesDec)
	{
		numRelaunches = Max(numRelaunches - 1, 3);
	}
	else if (selectedSetting == SETTING_DeathmatchScoreInc)
	{
		deathmatchWinScore = Min(deathmatchWinScore + 1, 30);
	}
	else if (selectedSetting == SETTING_DeathmatchScoreDec)
	{
		deathmatchWinScore = Max(deathmatchWinScore - 1, 10);
	}

	ShowMessage();

	ShowSettingsMenu(true, selectedSetting);
}

private func SetupDone()
{
	// Apply random selection
	if (selectRandomSection) section = Sections[Random(GetLength(Sections))];
	if (selectRandomMode) mode = Modes[Random(GetLength(Modes))];
	selectRandomSection = selectRandomMode = false;
	// Show final setup message and start the game
	ShowMessage();
	GameCall("SetupDone", this, GetMessage());
}

private func AddOptionMenuItem(string caption, bool enabled, string command, id idItem)
{
	clonk->AddMenuItem(IIf(enabled, caption, Format("<c a0a0a0>%s</c>", caption)), command, idItem);
}

private func CheckPreselect(bool preselect, int menuItemIndex)
{
	if (preselect) clonk->SelectMenuItem(menuItemIndex);
}

private func KeepMenuOpen()
{
	// Find new player?
	if (!GetPlayerID(setupPlayer))
	{
		clonk = 0;
		if (GetPlayerCount() == 0) return;
		setupPlayer = GetPlayerByIndex(0);
	}

	// Find clonk
	if (!clonk || !clonk->GetAlive()) clonk = GetCrew(setupPlayer);

	// (Re)open menu
	if (clonk && !clonk->GetMenu()) ShowSetup();
}

private func ShowMessage()
{
	var message = Format("@%s", GetMessage());
	CustomMessage(message, this, setupPlayer, -LandscapeWidth() / 5, 0, 0, 0, 0, MSG_NoLinebreak);
	for (var i = 0; i < GetPlayerCount(); ++i)
	{
		if (GetPlayerByIndex(i) == setupPlayer) continue;
		CustomMessage(message, this, GetPlayerByIndex(i), 0, 0, 0, 0, 0, MSG_NoLinebreak | MSG_Multiple);
	}
}

private func GetMessage()
{
	var msgSection;
	if (selectRandomSection)
	{
		msgSection = "$Landscape$: {{SRND}} $Random$";
	}
	else
	{
		msgSection = Format("$Landscape$: {{%i}} %s", section, GetName(0, section));
	}

	var msgMode;
	if (selectRandomMode)
	{
		msgMode = Format("$Mode$: {{SRND}} $Random$");
	}
	else
	{
		msgMode = Format("$Mode$: {{%i}} %s", mode, mode->ModeName());
	}

	var msgWinScore;
	if (!deathmatchEnabled)
	{
		msgWinScore = Format("{{SREL}} $Relaunches$: %d", numRelaunches);
	}
	else
	{
		msgWinScore = Format("{{SKIL}} %s: %d $Kills$", GetName(0, DTHM), deathmatchWinScore);
	}

	var msgSuddenDeath = Format("{{SDDT}} %s: %s", GetName(0, SDDT), IIf(suddendeathEnabled, "$Enabled$", "$Disabled$"));
	var msgRotateInJump = Format("{{RIJP}} %s: %s", GetName(0, RIJP), IIf(rotateInJumpEnabled, "$Enabled$", "$Disabled$"));
	var msgAmbience = Format("{{SABC}} $Ambience$: %s", IIf(ambienceEnabled, "$Enabled$", "$Disabled$"));

	return Format("%s|%s|%s|%s|%s|%s", msgSection, msgMode, msgWinScore, msgSuddenDeath, msgRotateInJump, msgAmbience);
}