-
Notifications
You must be signed in to change notification settings - Fork 54
/
Script.c
136 lines (126 loc) · 4.13 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
126
127
128
129
130
131
132
133
134
135
136
/*--
Escape the volcano EXTREME
Author: Sven2
Difficult upwards parkour. Now with extra volcano coming from bottom!
--*/
static g_volcano;
protected func Initialize()
{
var w = LandscapeWidth(), h = LandscapeHeight();
// Create the parkour goal.
var goal = FindObject(Find_ID(Goal_Parkour));
if (!goal) goal = CreateObject(Goal_Parkour, 0, 0, NO_OWNER);
goal->DisableRespawnHandling();
// Set start and finish point.
goal->SetStartpoint(w*2/5, h*93/100);
goal->SetFinishpoint(w/2, h*5/100);
// Create earth materials
// Create them in big clusters so the whole object arrangement looks a bit less uniform and more interesting
PlaceBatches([Firestone], 5, 100, 15);
PlaceBatches([Dynamite, Dynamite, Dynamite, DynamiteBox], 3, 50, 6);
PlaceBatches([Rock, Loam, Loam], 10, 200, 10);
// Some dead trees.
Tree_Coniferous_Burned->Place(4);
Tree_Coniferous2_Burned->Place(2);
Tree_Coniferous3_Burned->Place(2);
Tree_Coniferous4_Burned->Place(2);
// At night with stars.
Time->Init();
Time->SetTime(24 * 60);
Time->SetCycleSpeed(0);
// Starting chest
var start_chest = CreateObjectAbove(Chest, w*2/5, h*94/100);
if (start_chest)
{
start_chest->CreateContents(Loam,4);
start_chest->CreateContents(Bread,3);
start_chest->CreateContents(Firestone,3);
start_chest->CreateContents(DynamiteBox,2);
}
// Create big volcano
g_volcano=CreateObjectAbove(BigVolcano,0,0,NO_OWNER);
var h0 = h-10;
g_volcano->Activate(h0, h*10/100);
// Schedule script to update volcano speed multiplier
var fx_volcano = new Effect {
Name = "FxVolcano",
Timer = Scenario.VolcanoTimer
};
CreateEffect(fx_volcano, 1, 40);
// Bottom is open, so put some stable lava here to prevent remaining lava from just flowing out of the map
DrawMaterialQuad("StableLava",0,h0,w,h0,w,h,0,h);
return;
}
// Timer callback: Update volcano speed (rubberband effect)
func VolcanoTimer()
{
// Safety
if (!g_volcano) return;
// Get volcano height
var y_volcano = g_volcano->GetLavaPeak();
// Get player progress
var y_plr, crew, n_crew;
for (var i=0; i<GetPlayerCount(C4PT_User); ++i)
if (crew = GetCursor(GetPlayerByIndex(i, C4PT_User)))
{
y_plr += crew->GetY();
++n_crew;
}
if (n_crew) y_plr = y_plr / n_crew;
// Calc rubber band
var rubber_length = 85 * y_plr / LandscapeHeight() + 65;
var new_multiplier;
if (n_crew)
new_multiplier = Max(1, (y_volcano - y_plr) / rubber_length);
else
new_multiplier = 1;
g_volcano->SetSpeedMultiplier(new_multiplier);
//Log("speed %v", new_multiplier);
return true;
}
func InitializePlayer(int plr)
{
// Players only
if (GetPlayerType(plr)!=C4PT_User) return;
// Harsh zoom range
for (var flag in [PLRZOOM_LimitMax, PLRZOOM_Direct])
SetPlayerZoomByViewRange(plr,400,250,flag);
SetPlayerViewLock(plr, false); // no view lock so you can see the volcano!
return true;
}
private func PlaceBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
var loc,loc2,n_item_ids=GetLength(item_ids), n_created=0, obj;
for (var i=0; i<n_batches; ++i)
if (loc = FindLocation(Loc_Material("Earth")))
for (var j=0; j<n_per_batch; ++j)
if (loc2 = FindLocation(Loc_InRect(loc.x-batch_radius,loc.y-batch_radius,batch_radius*2,batch_radius*2), Loc_Material("Earth")))
if (obj=CreateObjectAbove(item_ids[Random(n_item_ids)],loc2.x,loc2.y))
{
obj->SetPosition(loc2.x,loc2.y);
++n_created;
}
return n_created;
}
// Gamecall from parkour goal, on respawning.
protected func OnPlayerRespawn(int plr, object cp)
{
var clonk = GetCrew(plr);
RecoverItem(clonk, Shovel);
RecoverItem(clonk, Pickaxe);
RecoverItem(clonk, Loam);
return;
}
private func RecoverItem(object clonk, id item_id)
{
// Try to recover the player's item. if it can't be found, recreate one
// Don't fetch item from allied Clonks though
var item = FindObject(Find_ID(item_id), Find_Owner(clonk->GetOwner()));
if (!item || item->Contained() && item->Contained()->GetAlive())
item = clonk->CreateContents(item_id);
else
item->Enter(clonk);
return item;
}