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 (109 lines) | stat: -rw-r--r-- 2,145 bytes parent folder | download | duplicates (6)
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
/*-- 
	Wealth
	Author: Maikel
	
	Each player much reach the specified wealth to complete the goal.
--*/


#include Library_Goal

local wealth_goal;

protected func Initialize()
{
	wealth_goal = 0;
	return inherited(...);
}

/*-- Wealth goal --*/

public func SetWealthGoal(int wealth)
{
	wealth_goal = Max(0, wealth);
	return;
}

public func GetWealthGoal()
{
	return wealth_goal;
}


/* Scenario saving */

func SaveScenarioObject(props)
{
	if (!inherited(props, ...)) return false;
	var v = GetWealthGoal();
	if (v) props->AddCall("Goal", this, "SetWealthGoal", v);
	return true;
}



/*-- Goal interface --*/

// The goal is fulfilled if all players have the specfied wealth.
public func IsFulfilled()
{
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		var plr = GetPlayerByIndex(i);
		if (GetWealth(plr) < GetWealthGoal())
			return false;
	}
	// Goal fulfilled.
	return true;
}

public func GetDescription(int plr)
{
	var message;
	if (IsFulfilled())
		message = Format("$MsgGoalFulfilled$", GetWealthGoal());	
	else
		message = Format("$MsgGoalUnfulfilled$", GetWealth(plr), GetWealthGoal());

	return message;
}

// Shows or hides a message window with information.
public func Activate(int plr)
{
	// If goal message open -> hide it.
	if (GetEffect("GoalMessage", this))
	{
		CustomMessage("", nil, plr, nil, nil, nil, nil, nil, MSG_HCenter);
		RemoveEffect("GoalMessage", this);
		return;
	}
	// Otherwise open a new message.
	AddEffect("GoalMessage", this, 100, 0, this);
	var message;
	if (IsFulfilled())
		message = Format("@$MsgGoalFulfilled$", GetWealthGoal());	
	else
		message = Format("@$MsgGoalUnfulfilled$", GetWealth(plr), GetWealthGoal());

	CustomMessage(message, nil, plr, 0, 16 + 64, 0xffffff, GUI_MenuDeco, this, MSG_HCenter);
	return;
}

protected func FxGoalMessageStart() {}

public func GetShortDescription(int plr)
{
	// Show acquired wealth compared to goal.
	var wealth = GetWealth(plr);
	var goal = GetWealthGoal();
	var clr = RGB(255, 0, 0);
	if (wealth >= goal)
		clr = RGB(0, 255, 0);
	var msg = Format("<c %x>%d</c>{{%i}}", clr, goal, Icon_Wealth);
	return msg;
}

/*-- Proplist --*/

local Name = "$Name$";