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 (94 lines) | stat: -rw-r--r-- 2,679 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
/*--
		Script goal
		Author: Maikel
		
		The script goal can be fulfilled from other scripts, e.g. a scenario script.
--*/


#include Library_Goal

local fulfilled;

protected func Initialize()
{
	fulfilled = false;
	return inherited(...);
}

public func IsFulfilled()
{
	return fulfilled;
}

public func Fulfill()
{
	fulfilled = true;
	return;
}

public func SetFulfilled(bool to_val)
{
	fulfilled = to_val;
	return;
}

public func GetDescription(int plr)
{
	return GetTranslatedString(this.Description);
}

public func GetPictureDefinition(int plr)
{
	return this.Picture ?? this;
}

public func GetPictureName(int plr)
{
	return this.PictureName ?? "";
}

/* Editor */

local overlay_picture;

public func Definition(def)
{
	// Properties
	if (!def.EditorProps) def.EditorProps = {};
	def.EditorProps.Description = { Name="$PropDescription$", EditorHelp="$PropDescriptionHelp$", Type="string", Save="Description", Translatable=true };
	def.EditorProps.overlay_picture = { Name="$Picture$", EditorHelp="$PictureHelp$", Type="def", Set="SetOverlayPicture", Save="Picture" };
	// User actions
	UserAction->AddEvaluator("Action", "Game", "$SetScriptGoalData$", "$SetScriptGoalDataDesc$", "set_script_goal_data", [def, def.EvalAct_SetData],
			{ Target = { Function="action_object" }, Description = { Function="string_constant", Value="$Description$" }, Fulfilled = { Function="bool_constant", Value=false } },
			{ Type="proplist", Display="{{Description}}, {{OverlayPicture}}, {{Fulfilled}}",
		EditorProps = {
			Target = new UserAction->GetObjectEvaluator("IsScriptGoal", "$Goal$") { Priority=50 },
			Description = new UserAction.Evaluator.String { Name="$PropDescription$", EditorHelp="$PropDescriptionHelp$" },
			OverlayPicture = new UserAction.Evaluator.Definition { Name="$Picture$", EditorHelp="$PictureHelp$" },
			Fulfilled = new UserAction.Evaluator.Boolean { Name="$Fulfilled$", EditorHelp="$FulfilledHelp$" }
		} } );
}

public func SetOverlayPicture(to_picture_def)
{
	// Picutre + Overlay
	overlay_picture = to_picture_def;
	SetGraphics(nil, to_picture_def, 1, GFXOV_MODE_Picture);
	return true;
}

public func IsScriptGoal() { return true; }

private func EvalAct_SetData(props, context)
{
	var target = UserAction->EvaluateValue("Objct", props.Target, context);
	if (!target || !target->~IsScriptGoal()) return;
	target.Description = UserAction->EvaluateString(props.Description, context);
	target->~SetOverlayPicture(UserAction->EvaluateValue("Definition", props.OverlayPicture, context));
	target->~SetFulfilled(UserAction->EvaluateValue("Boolean", props.Fulfilled, context));
}

/*-- Proplist --*/
local Name = "$Name$";
local Description = "$Description$";