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 (743 lines) | stat: -rw-r--r-- 19,555 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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
/**
	Parkour
	
	The goal is to be the first to reach the finish, the team or player to do so wins the round.
	Checkpoints can be added to make the path more interesting and more complex.
	Checkpoints can have different functionalities:
		* Respawn: On/Off - The clonk respawns at the last passed checkpoint.
		* Check: On/Off - The clonk must pass through these checkpoints before being able to finish.
		* Ordered: On/Off - The checkpoints mussed be passed in the order specified.
		* The start and finish are also checkpoints.
	
	@author Maikel
*/


#include Library_Goal

local finished; // Whether the goal has been reached by some player.
local cp_list; // List of checkpoints.
local cp_count; // Number of checkpoints.
local respawn_list; // List of last reached respawn CP per player.
local plr_list; // Number of checkpoints the player completed.
local team_list; // Number of checkpoints the team completed.
local time_store; // String for best time storage in player file.
local no_respawn_handling; // Set to true if this goal should not handle respawn.
local transfer_contents; // Set to true if contents should be transferred on respawn.


/*-- General --*/

protected func Initialize(...)
{
	finished = false;
	no_respawn_handling = false;
	transfer_contents = false;
	cp_list = [];
	cp_count = 0;
	respawn_list = [];
	plr_list = [];
	team_list = [];
	// Best time tracking.
	time_store = Format("Parkour_%s_BestTime", GetScenTitle());
	AddEffect("IntBestTime", this, 100, 1, this);
	// Add a message board command "/resetpb" to reset the pb for this round.
	AddMsgBoardCmd("resetpb", "Goal_Parkour->~ResetPersonalBest(%player%)");
	// Activate restart rule, if there isn't any. But check delayed because it may be created later.
	ScheduleCall(this, this.EnsureRestartRule, 1, 1);
	// Scoreboard.
	InitScoreboard();
	// Assign unassigned checkpoints
	for (var obj in FindObjects(Find_ID(ParkourCheckpoint)))
		if (!obj->GetCPController())
			obj->SetCPController(this);
	return _inherited(...);
}

private func EnsureRestartRule()
{
	var relaunch = GetRelaunchRule();
	relaunch->SetAllowPlayerRestart(true);
	relaunch->SetPerformRestart(false);
	return true;
}

protected func Destruction(...)
{
	// Unassign checkpoints (updates editor help message)
	for (var obj in FindObjects(Find_ID(ParkourCheckpoint)))
		if (obj->GetCPController() == this)
			obj->SetCPController(nil);
	return _inherited(...);
}


/*-- Checkpoint creation --*/

public func SetStartpoint(int x, int y)
{
	// Safety, x and y inside landscape bounds.
	x = BoundBy(x, 0, LandscapeWidth());
	y = BoundBy(y, 0, LandscapeHeight());
	var cp = FindObject(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Start));
	if (!cp)	
		cp = CreateObjectAbove(ParkourCheckpoint, x, y, NO_OWNER);
	cp->SetCPController(this);
	cp->SetPosition(x, y);
	cp->SetCPMode(PARKOUR_CP_Start);
	return cp;
}

public func SetFinishpoint(int x, int y, bool team)
{
	// Safety, x and y inside landscape bounds.
	x = BoundBy(x, 0, LandscapeWidth());
	y = BoundBy(y, 0, LandscapeHeight());
	var cp = FindObject(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Finish));
	if (!cp)	
		cp = CreateObjectAbove(ParkourCheckpoint, x, y, NO_OWNER);
	cp->SetCPController(this);
	cp->SetPosition(x, y);
	var mode = PARKOUR_CP_Finish;
	if (team)
		mode = mode | PARKOUR_CP_Team;
	cp->SetCPMode(mode);
	return cp;
}

public func AddCheckpoint(int x, int y, int mode)
{
	// Safety, x and y inside landscape bounds.
	x = BoundBy(x, 0, LandscapeWidth());
	y = BoundBy(y, 0, LandscapeHeight());
	var cp = CreateObjectAbove(ParkourCheckpoint, x, y, NO_OWNER);
	cp->SetCPController(this);
	cp->SetPosition(x, y);
	cp->SetCPMode(mode);
	return cp;
}

public func DisableRespawnHandling()
{
	// Call this to disable respawn handling by goal. This might be useful if
	// a) you don't want any respawns, or
	// b) the scenario already provides an alternate respawn handling.
	no_respawn_handling = true;
	return true;
}

public func TransferContentsOnRelaunch(bool on)
{
	transfer_contents = on;
	return;
}

public func SetIndexedCP(object cp, int index)
{
	// Called directly from checkpoints after index assignment, resorting, etc.
	// Update internal list
	cp_list[index] = cp;
	if (cp->GetCPMode() & PARKOUR_CP_Finish)
	{
		cp_count = index;
		SetLength(cp_list, cp_count+1);
	}
	UpdateScoreboardTitle();
	return true;
}


/*-- Checkpoint interaction --*/

// Called from a finish CP to indicate that plr has reached it.
public func PlayerReachedFinishCP(int plr, object cp, bool is_first_clear)
{
	if (finished)
		return;
	var plrid = GetPlayerID(plr);
	var team = GetPlayerTeam(plr);
	plr_list[plrid]++;
	if (team)
		team_list[team]++;
	UpdateScoreboard(plr);
	DoBestTime(plr);
	SetEvalData(plr);
	EliminatePlayers(plr);
	finished = true;
	if (is_first_clear) UserAction->EvaluateAction(on_checkpoint_first_cleared, this, cp, plr);
	UserAction->EvaluateAction(on_checkpoint_cleared, this, cp, plr);
	return;
}

// Called from a respawn CP to indicate that plr has reached it.
public func SetPlayerRespawnCP(int plr, object cp)
{
	if (respawn_list[plr] == cp)
		return;
	respawn_list[plr] = cp;
	cp->PlayerMessage(plr, "$MsgNewRespawn$");
	return;
}

// Called from a check CP to indicate that plr has cleared it.
public func AddPlayerClearedCP(int plr, object cp, bool is_first_clear, bool is_team_auto_clear)
{
	if (finished)
		return;
	var plrid = GetPlayerID(plr);
	plr_list[plrid]++;
	UpdateScoreboard(plr);
	if (!is_team_auto_clear) // No callback if only auto-cleared for other team members after another player cleared it
	{
		if (is_first_clear) UserAction->EvaluateAction(on_checkpoint_first_cleared, this, cp, plr);
		UserAction->EvaluateAction(on_checkpoint_cleared, this, cp, plr);
	}
	return;
}

// Called from a check CP to indicate that plr has cleared it.
public func AddTeamClearedCP(int team, object cp)
{
	if (finished)
		return;
	if (team)
		team_list[team]++;
	return;
}

private func ResetAllClearedCP()
{
	plr_list = [];
	team_list = [];
	respawn_list = [];
	for (var cp in FindObjects(Find_ID(ParkourCheckpoint)))
		cp->ResetCleared();
	return true;
}


/*-- Goal interface --*/

// Eliminates all players apart from the winner and his team.
private func EliminatePlayers(int winner)
{
	var winteam = GetPlayerTeam(winner);
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		var plr = GetPlayerByIndex(i);
		var team = GetPlayerTeam(plr);
		if (plr == winner) // The winner self.
			continue;
		if (team && team == winteam) // In the same team as the winner.
			continue;
		EliminatePlayer(plr);
	}
	return;
}

public func IsFulfilled()
{
	return finished;
}

public func GetDescription(int plr)
{
	var team = GetPlayerTeam(plr);
	var msg;
	if (finished)
	{
		if (team)
		{
			if (IsWinner(plr))
				msg = "$MsgParkourWonTeam$";
			else
				msg = "$MsgParkourLostTeam$";
		}
		else
		{
			if (IsWinner(plr))
				msg = "$MsgParkourWon$";
			else
				msg = "$MsgParkourLost$";
		}
	}
	else
		msg = Format("$MsgParkour$", cp_count);

	return msg;
}

public func Activate(int plr)
{
	var team = GetPlayerTeam(plr);
	var msg;
	if (finished)
	{
		if (team)
		{
			if (IsWinner(plr))
				msg = "$MsgParkourWonTeam$";
			else
				msg = "$MsgParkourLostTeam$";
		}
		else
		{
			if (IsWinner(plr))
				msg = "$MsgParkourWon$";
			else
				msg = "$MsgParkourLost$";
		}
	}
	else
		msg = Format("$MsgParkour$", cp_count);
	// Show goal message.
	MessageWindow(msg, plr);
	return;
}

public func GetShortDescription(int plr)
{
	var team = GetPlayerTeam(plr);
	var parkour_length = GetParkourLength();
	if (parkour_length == 0)
		return "";
	var length;
	if (team)
		length = GetTeamPosition(team);
	else
		length = GetPlayerPosition(plr);
	var percentage =  100 * length / parkour_length;
	var red = BoundBy(255 - percentage * 255 / 100, 0, 255);
	var green = BoundBy(percentage * 255 / 100, 0, 255);
	var color = RGB(red, green, 0);
	return Format("<c %x>$MsgShortDesc$</c>", color, percentage, color);
}

// Returns the length the player has completed.
private func GetPlayerPosition(int plr)
{
	var plrid = GetPlayerID(plr);
	var cleared = plr_list[plrid];
	var length = 0;
	// Add length of cleared checkpoints.
	for (var i = 0; i < cleared; i++)
		length += ObjectDistance(cp_list[i], cp_list[i + 1]);
	// Add length of current checkpoint.
	var add_length = 0;
	if (cleared < cp_count)
	{
		var path_length = ObjectDistance(cp_list[cleared], cp_list[cleared + 1]);
		add_length = Max(path_length - ObjectDistance(cp_list[cleared + 1], GetCursor(plr)), 0);
	}
	return length + add_length;
}

// Returns the length the team has completed.
private func GetTeamPosition(int team)
{
	var cleared = team_list[team];
	var length = 0;
	// Add length of cleared checkpoints.
	for (var i = 0; i < cleared; i++)
		length += ObjectDistance(cp_list[i], cp_list[i + 1]);
	// Add length of current checkpoint.
	var add_length = 0;
	if (cleared < cp_count)
	{
		for (var i = 0; i < GetPlayerCount(); i++)
		{
			var plr = GetPlayerByIndex(i);
			if (GetPlayerTeam(plr) == team)
			{
				var path_length = ObjectDistance(cp_list[cleared], cp_list[cleared + 1]);
				var test_length = Max(path_length - ObjectDistance(cp_list[cleared + 1], GetCursor(plr)), 0);
				if (test_length > add_length)
					add_length = test_length;
			}			
		}
	}
	return length + add_length;
}

// Returns the length of this parkour.
private func GetParkourLength()
{
	var length = 0;
	for (var i = 0; i < cp_count; i++)
		length += ObjectDistance(cp_list[i], cp_list[i + 1]);
	return length;
}	

// Returns the number of checkpoints cleared by the player.
public func GetPlayerClearedCheckpoints(int plr)
{
	var plrid = GetPlayerID(plr);
	return plr_list[plrid];
}

public func GetLeaderClearedCheckpoints()
{
	return Max(plr_list);
}

private func IsWinner(int plr)
{
	var team = GetPlayerTeam(plr);
	var finish = cp_list[cp_count];
	if (!finish)
		return false;
	if (team)
	{
		if (finish->ClearedByTeam(team))
			return true;
	}
	else
	{
		if (finish->ClearedByPlayer(plr))
			return true;
	}
	return false;
}

/*-- Player section --*/

protected func InitializePlayer(int plr, int x, int y, object base, int team)
{
	// If the parkour is already finished, then immediately eliminate player.
	if (finished)
		return EliminatePlayer(plr);
	// Remove all hostilities.
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		SetHostility(plr, GetPlayerByIndex(i), false, true);
		SetHostility(GetPlayerByIndex(i), plr, false, true);
	}
	// Init Respawn CP to start CP.
	var plrid = GetPlayerID(plr);
	respawn_list[plr] = cp_list[0];
	plr_list[plrid] = 0;
	if (team)
		if (!team_list[team])
			team_list[team] = 0;
	// Scoreboard.
	Scoreboard->NewPlayerEntry(plr);
	UpdateScoreboard(plr);
	DoScoreboardShow(1, plr + 1);
	JoinPlayer(plr);
	// Scenario script callback.
	GameCall("OnPlayerRespawn", plr, FindRespawnCP(plr));
	return;
}

protected func OnClonkDeath(object clonk, int killed_by)
{
	var plr = clonk->GetOwner();
	// Only respawn if required and if the player still exists.
	if (no_respawn_handling || !GetPlayerName(plr) || GetCrewCount(plr)) 
		return;
	var new_clonk = CreateObjectAbove(Clonk, 0, 0, plr);
	new_clonk->MakeCrewMember(plr);
	SetCursor(plr, new_clonk);
	JoinPlayer(plr);
	// Transfer contents if active.
	if (transfer_contents)
		GetRelaunchRule()->TransferInventory(clonk, new_clonk);
	// Scenario script callback.
	GameCall("OnPlayerRespawn", plr, FindRespawnCP(plr));
	// Log message.
	Log(RndRespawnMsg(), GetPlayerName(plr));
	// Respawn actions
	var cp = FindRespawnCP(plr);
	UserAction->EvaluateAction(on_respawn, this, clonk, plr);
	if (cp)
		cp->OnPlayerRespawn(new_clonk, plr);
	return;
}

private func RndRespawnMsg()
{
	return Translate(Format("MsgRespawn%d", Random(4)));
}

protected func JoinPlayer(int plr)
{
	var clonk = GetCrew(plr);
	clonk->DoEnergy(clonk.MaxEnergy / 1000);
	var pos = FindRespawnPos(plr);
	clonk->SetPosition(pos[0], pos[1]);
	AddEffect("IntDirNextCP", clonk, 100, 1, this);
	return;
}

// You always respawn at the last completed checkpoint you passed by.
// More complicated behavior should be set by the scenario. 
private func FindRespawnCP(int plr)
{
	var respawn_cp = respawn_list[plr];
	if (!respawn_cp)
		respawn_cp = respawn_list[plr] = cp_list[0];
	return respawn_cp;
}

private func FindRespawnPos(int plr)
{
	var cp = FindRespawnCP(plr);
	if (!cp) cp = this; // Have to start somewhere
	return [cp->GetX(), cp->GetY()];
}

protected func RemovePlayer(int plr)
{
	respawn_list[plr] = nil;
	if (!finished)
		AddEvalData(plr);
	return;
}


/*-- Scenario saving --*/

public func SaveScenarioObject(props)
{
	if (!inherited(props, ...)) 
		return false;
	props->AddCall("Goal", this, "EnsureRestartRule");
	if (no_respawn_handling)
		props->AddCall("Goal", this, "DisableRespawnHandling");
	if (transfer_contents)
		props->AddCall("Goal", this, "TransferContentsOnRelaunch", true);
	return true;
}


/*-- Scoreboard --*/

static const SBRD_Checkpoints = 0;
static const SBRD_BestTime = 1;

private func UpdateScoreboardTitle()
{
	if (cp_count > 0)
		var caption = Format("$MsgCaptionX$", cp_count);
	else
		var caption = "$MsgCaptionNone$";
	return Scoreboard->SetTitle(caption);
}

private func InitScoreboard()
{
	Scoreboard->Init(
		[
		{key = "checkpoints", title = "#", sorted = true, desc = true, default = 0, priority = 80},
		{key = "besttime", title = GUI_Clock, sorted = true, desc = true, default = 0, priority = 70}
		]
		);
	UpdateScoreboardTitle();
	return;
}

private func UpdateScoreboard(int plr)
{
	if (finished)
		return;
	var plrid = GetPlayerID(plr);
	Scoreboard->SetPlayerData(plr, "checkpoints", plr_list[plrid]);
	var bt = GetPlrExtraData(plr, time_store);
	Scoreboard->SetPlayerData(plr, "besttime", TimeToString(bt), bt);
	return;
}


/*-- Direction indication --*/

// Effect for direction indication for the clonk.
protected func FxIntDirNextCPStart(object target, effect fx)
{
	var arrow = CreateObjectAbove(GUI_GoalArrow, 0, 0, target->GetOwner());
	arrow->SetAction("Show", target);
	fx.arrow = arrow;
	return FX_OK;
}

protected func FxIntDirNextCPTimer(object target, effect fx)
{
	var plr = target->GetOwner();
	var team = GetPlayerTeam(plr);
	var arrow = fx.arrow;
	// Find nearest CP.
	var nextcp;
	for (var cp in FindObjects(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Check | PARKOUR_CP_Finish), Sort_Distance(target->GetX() - GetX(), target->GetY() - GetY())))
		if (!cp->ClearedByPlayer(plr) && (cp->IsActiveForPlayer(plr) || cp->IsActiveForTeam(team)))
		{
			nextcp = cp;
			break;
		}
	if (!nextcp)
		return arrow->SetClrModulation(RGBa(0, 0, 0, 0));
	// Calculate parameters.
	var angle = Angle(target->GetX(), target->GetY(), nextcp->GetX(), nextcp->GetY());
	var dist = Min(510 * ObjectDistance(GetCrew(plr), nextcp) / 400, 510);
	var red = BoundBy(dist, 0, 255);
	var green = BoundBy(510 - dist, 0, 255);
	var blue = 0;
	// Arrow is colored a little different for the finish.
	if (cp->GetCPMode() & PARKOUR_CP_Finish)
		blue = 128;
	var color = RGBa(red, green, blue, 128);
	// Draw arrow.
	arrow->SetR(angle);
	arrow->SetClrModulation(color);
	// Check if clonk is contained in a vehicle, if so attach arrow to vehicle.
	var container = target->Contained();
	if (container && container->GetCategory() & C4D_Vehicle)
	{
		if (arrow->GetActionTarget() != container)
		{
			arrow->SetActionTargets(container);
			arrow->SetCategory(C4D_Vehicle);
		}
	} 
	else
	{
		if (arrow->GetActionTarget() != target)
		{
			arrow->SetActionTargets(target);
			arrow->SetCategory(C4D_StaticBack);
		}
	}
	return FX_OK;
}

protected func FxIntDirNextCPStop(object target, effect fx)
{
	fx.arrow->RemoveObject();
	return;
}


/*-- Time tracker --*/

// Store the best time in the player file, same for teammembers.
private func DoBestTime(int plr)
{
	var effect = GetEffect("IntBestTime", this);
	var time = effect.besttime;
	var winteam = GetPlayerTeam(plr);
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		var check_plr = GetPlayerByIndex(i);
		if (winteam == 0 && check_plr != plr)
			continue;
		if (winteam != GetPlayerTeam(check_plr))
			continue;
		// Store best time for all players in the winning team.
		var rectime = GetPlrExtraData(check_plr, time_store);
		if (time != 0 && (!rectime || time < rectime))
		{
			SetPlrExtraData(check_plr, time_store, time);
			Log(Format("$MsgBestTime$", GetPlayerName(check_plr), TimeToString(time)));
		}
	}
	return;
}

// Starts at goal initialization, should be equivalent to gamestart.
protected func FxIntBestTimeTimer(object target, effect, time)
{
	effect.besttime = time;
	return FX_OK;
}

// Returns a best time string.
private func TimeToString(int time)
{
	if (!time) // No time.
		return "N/A";
	if (time > 36 * 60 * 60) // Longer than an hour.
		return Format("%d:%.2d:%.2d.%.1d", (time / 60 / 60 / 36) % 24, (time / 60 / 36) % 60, (time / 36) % 60, (10 * time / 36) % 10);
	if (time > 36 * 60) // Longer than a minute.
		return Format("%d:%.2d.%.1d", (time / 60 / 36) % 60, (time / 36) % 60, (10 * time / 36) % 10);
	else // Only seconds.
		return Format("%d.%.1d", (time / 36) % 60, (10 * time / 36) % 10);
}

// Resets the personal best (call from message board).
public func ResetPersonalBest(int plr)
{
	if (!GetPlayerName(plr))
		return;
	// Forward call to actual goal.
	if (this == Goal_Parkour)
	{
		var goal = FindObject(Find_ID(Goal_Parkour));
		if (goal)
			goal->ResetPersonalBest(plr);
	}
	SetPlrExtraData(plr, time_store, nil);
	// Also update the scoreboard.
	UpdateScoreboard(plr);
	return;
}


/*-- Evaluation data --*/

private func SetEvalData(int winner)
{
	var winteam = GetPlayerTeam(winner);
	var effect = GetEffect("IntBestTime", this);
	var time = effect.besttime;
	var msg;
	// General data.
	if (winteam)
		msg = Format("$MsgEvalTeamWon$", GetTeamName(winteam), TimeToString(time));
	else
		msg = Format("$MsgEvalPlrWon$", GetPlayerName(winner), TimeToString(time));
	AddEvaluationData(msg, 0);
	// Individual data.
	for (var i = 0; i < GetPlayerCount(); i++)
		AddEvalData(GetPlayerByIndex(i));
	// Obviously get rid of settlement score.
	HideSettlementScoreInEvaluation(true);
	return;
}

private func AddEvalData(int plr)
{
	if (finished)
		return;
	var plrid = GetPlayerID(plr);
	var cps = plr_list[plrid];
	var msg;
	if (cps == cp_count)
		msg = "$MsgEvalPlayerAll$";
	else
		msg = Format("$MsgEvalPlayerX$", cps, cp_count);
	AddEvaluationData(msg, plrid);
	return;
}


/* Editor */

local on_checkpoint_cleared, on_checkpoint_first_cleared, on_respawn;

public func SetOnCheckpointCleared(v) { on_checkpoint_cleared=v; return true; }
public func SetOnCheckpointFirstCleared(v) { on_checkpoint_first_cleared=v; return true; }
public func SetOnRespawn(v) { on_respawn=v; return true; }

public func Definition(def)
{
	_inherited(def);
	if (!def.EditorProps) def.EditorProps = {};
	def.EditorProps.on_checkpoint_cleared = new UserAction.Prop { Name="$OnCleared$", EditorHelp="$OnClearedHelp$", Set="SetOnCheckpointCleared", Save="Checkpoint" };
	def.EditorProps.on_checkpoint_first_cleared = new UserAction.Prop { Name="$OnFirstCleared$", EditorHelp="$OnFirstClearedHelp$", Set="SetOnCheckpointFirstCleared", Save="Checkpoint" };
	def.EditorProps.on_respawn = new UserAction.Prop { Name="$OnRespawn$", EditorHelp="$OnRespawnHelp$", Set="SetOnRespawn", Save = "Checkpoint" };
	if (!def.EditorActions) def.EditorActions = {};
	def.EditorActions.reset_all_cleared = { Name="$ResetAllCleared$", EditorHelp="$ResetAllClearedHelp$", Command="ResetAllClearedCP()" };
}


/*-- Proplist --*/

local Name = "$Name$";