-
Notifications
You must be signed in to change notification settings - Fork 54
/
Script.c
125 lines (103 loc) · 2.85 KB
/
Script.c
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
/*--
Ruby hunt
Author: Sven2
Mine one ruby and return to start
--*/
#include Library_Goal
local goal_rect, has_winner;
local is_cooperative;
protected func Initialize()
{
// default to race mode
is_cooperative = false;
return inherited(...);
}
func SetGoalRect(r)
{
goal_rect = r;
return true;
}
func SetCooperative(bool to_val)
{
is_cooperative = to_val;
return true;
}
/* Scenario saving */
func SaveScenarioObject(props)
{
if (!inherited(props, ...)) return false;
if (goal_rect) props->AddCall("Goal", this, "SetGoalRect", goal_rect);
if (is_cooperative) props->AddCall("Goal", this, "SetCooperative", is_cooperative);
return true;
}
/*-- Goal interface --*/
// The goal is fulfilled if a ruby is in the goal rectangle
public func IsFulfilled()
{
var winner=NO_OWNER, winners, winner_teams;
if (has_winner) return true;
for (var ruby in FindObjects(Find_InRect(goal_rect.x, goal_rect.y, goal_rect.wdt, goal_rect.hgt), Find_ID(Ruby)))
{
if (ruby->Contained()) winner = ruby->Contained()->GetOwner();
if (winner==NO_OWNER) winner = ruby->GetController();
if (winner==NO_OWNER) continue;
if (!winners) winners = [winner]; else winners[GetLength(winners)] = winner;
var team = GetPlayerTeam(winner);
if (team) if (!winner_teams) winner_teams = [team]; else winner_teams[GetLength(winner_teams)] = team;
}
if (!winners) return false;
has_winner = true;
var iplr=GetPlayerCount();
while (iplr--)
{
var plr = GetPlayerByIndex(iplr);
// Free view when game is over
for (var flag in [PLRZOOM_LimitMax, PLRZOOM_Direct])
SetPlayerZoomByViewRange(plr,LandscapeWidth(),LandscapeWidth(),flag);
SetPlayerViewLock(plr, false);
SetFoW(false, plr);
// Eliminate non-winning players
if (is_cooperative) continue; // in coop mode, everyone wins
if (GetIndexOf(winners, plr) >= 0) continue;
if (winner_teams) if (GetIndexOf(winner_teams, GetPlayerTeam(plr)) >= 0) continue;
EliminatePlayer(plr);
}
return true;
}
// Shows or hides a message window with information.
public func GetDescription(int plr)
{
var message;
if (IsFulfilled())
message = "$MsgGoalFulfilled$";
else
message = "$MsgGoalUnfulfilled$";
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 = "@$MsgGoalFulfilled$";
else
message = "@$MsgGoalUnfulfilled$";
CustomMessage(message, nil, plr, 0, 16 + 64, 0xffffff, GUI_MenuDeco, this, MSG_HCenter);
return;
}
protected func FxGoalMessageStart() {}
public func GetShortDescription(int plr)
{
return nil;
}
/*-- Proplist --*/
local Name = "$Name$";