1 /*--
2 	Hideout
3 	Author: Mimmo
4 
5 	A capture the flag scenario for two teams, both teams occupy a hideout and must steal the flag from
6 	the opposing team.
7 --*/
8 
Initialize()9 protected func Initialize()
10 {
11 	// Environment
12 	CreateObject(Rule_ObjectFade)->DoFadeTime(10 * 36);
13 
14 	GetRelaunchRule()->SetLastWeaponUse(false);
15 
16 	var time=CreateObject(Time);
17 	time->SetTime();
18 	time->SetCycleSpeed();
19 	FindObject(Find_ID(Moon))->SetMoonPhase(3);
20 	FindObject(Find_ID(Moon))->SetCon(150);
21 	FindObject(Find_ID(Moon))->SetPosition(LandscapeWidth()/2,150);
22 
23 	// Goal: Capture the flag, with bases in both hideouts.
24 	var goal = CreateObject(Goal_CaptureTheFlag, 0, 0, NO_OWNER);
25 	goal->SetFlagBase(1, 135, 266);
26 	goal->SetFlagBase(2, LandscapeWidth() - 135, 266);
27 	CreateObject(Rule_KillLogs);
28 
29 	var gate = CreateObjectAbove(StoneDoor, 345, 272, NO_OWNER);
30 	gate->SetClrModulation(RGB(140,185,255));
31 	gate->SetAutoControl(1);
32 	var gate = CreateObjectAbove(StoneDoor, LandscapeWidth()-344, 272, NO_OWNER);
33 	gate->SetClrModulation(RGB(140,185,255));
34 	gate->SetAutoControl(2);
35 
36 	// Chests with weapons.
37 	var chest;
38 	chest = CreateObjectAbove(Chest, 60, 220, NO_OWNER);
39 	chest->MakeInvincible();
40 	AddEffect("FillBaseChest", chest, 100, 7 * 36,nil,nil,false);
41 	chest = CreateObjectAbove(Chest, 150, 370, NO_OWNER);
42 	chest->MakeInvincible();
43 	AddEffect("FillBaseChest", chest, 100, 7 * 36,nil,nil,true);
44 	chest = CreateObjectAbove(Chest, LandscapeWidth() - 60, 220, NO_OWNER);
45 	chest->MakeInvincible();
46 	AddEffect("FillBaseChest", chest, 100, 7 * 36,nil,nil,false);
47 	chest = CreateObjectAbove(Chest, LandscapeWidth() - 150, 370, NO_OWNER);
48 	chest->MakeInvincible();
49 	AddEffect("FillBaseChest", chest, 100, 7 * 36,nil,nil,true);
50 
51 
52 	chest = CreateObjectAbove(Chest, LandscapeWidth()/2, 320, NO_OWNER);
53 	chest->MakeInvincible();
54 	AddEffect("FillOtherChest", chest, 100, 5 * 36);
55 
56 	AddEffect("SnowyWinter", nil, 100, 1);
57 	Sound("Environment::WindLoop",true,20,nil,+1);
58 	AddEffect("GeysirExplosion", nil, 100, 1);
59 	// Brick edges, notice the symmetric landscape.
60 	PlaceEdges();
61 	return;
62 }
63 
CaptureFlagCount()64 protected func CaptureFlagCount() { return 2;} //4 + GetPlayerCount()) / 2; }
65 
FxGeysirExplosionTimer(object target,effect)66 global func FxGeysirExplosionTimer(object target, effect)
67 {
68 	effect.counter++;
69 
70 	if(Random(2))
71 	{
72 		var x=600+Random(300);
73 		var y=250+Random(200);
74 		while(GetMaterial(x,y) != Material("Water"))
75 		{
76 			var x=600+Random(300);
77 			var y=250+Random(200);
78 		}
79 		Bubble(1,x,y);
80 	}
81 	if(effect.counter>1900 && effect.counter<2030)
82 	{
83 
84 		for(var i=0; i<(-(1900-effect.counter)); i+=10 )
85 		{
86 			var x=600+Random(300);
87 			var y=250+Random(200);
88 			while(GetMaterial(x,y) != Material("Water"))
89 			{
90 				var x=600+Random(300);
91 				var y=250+Random(200);
92 			}
93 			Bubble(1,x,y);
94 		}
95 	}
96 	if(effect.counter>2000)
97 	{
98 		var x=LandscapeWidth()/2;
99 		var y=280;
100 		while(!GBackLiquid(x,y)) y++;
101 		y-=3;
102 		for(var i=0; i<(45); i++)InsertMaterial(Material("Water"),x+RandomX(-9,9),y-Random(5),RandomX(-10,10)+RandomX(-5,5)+RandomX(-10,10),-(10+Random(50)+Random(30)+Random(60)));
103 		for(var i=0; i<(25); i++)InsertMaterial(Material("Water"),x+RandomX(-16,16),y-Random(5),RandomX(-10,10)+RandomX(-15,15)+RandomX(-20,20),-(10+Random(50)));
104 		CreateParticle("Air", PV_Random(x-6, x+6), PV_Random(y-3, y), PV_Random(-15, 15), PV_Random(-90, -5), PV_Random(20, 100), Particles_Air());
105 		if(effect.counter>2072) effect.counter=0;
106 		for(var obj in FindObjects(Find_InRect(x-30,y-200,60,210)))
107 		{
108 			obj->SetYDir(Max(obj->GetYDir()-15,-50));
109 		}
110 
111 	}
112 }
113 
FxSnowyWinterTimer(object target,effect,int time)114 global func FxSnowyWinterTimer(object target, effect, int time)
115 {
116 	if(time%1200 == 100 )
117 	{
118 		var add=RandomX(-2,2);
119 		effect.snow_count=BoundBy(effect.snow_count+add,1,5);
120 	}
121 	for(var i=0; i<(effect.snow_count); i++)
122 	{
123 		InsertMaterial(Material("Snow"),RandomX(300,LandscapeWidth()-300),1,RandomX(-10,10),10);
124 		ExtractLiquid(LandscapeWidth()/2,295);
125 	}
126 	ExtractLiquid(LandscapeWidth()/2,295);
127 	ExtractLiquid(LandscapeWidth()/2,285);
128 	ExtractLiquid(340,340);
129 	ExtractLiquid(400,340);
130 	ExtractLiquid(1100,340);
131 	ExtractLiquid(1160,340);
132 	if(!Random(3)) for(var obj in FindObjects(Find_Or(Find_InRect(0,-250,300,280),Find_InRect(LandscapeWidth()-300,-250,300,280))))
133 	{
134 		obj->~DoEnergy(-1);
135 	}
136 }
137 
PlaceEdges()138 global func PlaceEdges()
139 {
140 	var x=[124, 116, 116, 236, 236, 223, 308, 364, 380, 353, 353, 336, 388, 724, 37, 45, 53, 356, 348, 118, 118, 732, 437, 437, 126, 118, 137, 145, 183, 175, 156, 164, 221, 194, 213, 202, 107, 99, 80, 88, 69, 46, 54, 74, 66, 86, 94, 45, 45, 45, 45, 45, 45, 140, 231, 677, 733, 212, 204, 122, 130, 234, 226, 239, 247, 217, 188, 188, 373, 353, 353, 389, 365, 397, 206, 214, 194, 186, 227, 219, 196, 204, 154, 146, 166, 174, 134, 126, 106, 114, 45, 45, 316, 308, 327, 335, 308, 194, 187, 174, 166, 53, 53, 394, 404, 386, 373, 270, 259, 240, 232, 278, 251, 297, 289, 308, 308, 53, 53, 130, 122, 146, 154, 167, 174, 186, 194, 205, 213, 224, 232, 196, 205, 225, 237, 257, 245, 205, 336, 336, 336, 373, 386, 420, 394, 357, 69, 69, 157, 157, 205, 347, 355, 375, 367, 407, 395, 387, 415, 435, 427, 429, 297, 305, 285, 277, 265, 325, 317, 267, 259, 279, 287, 307, 299, 340, 327, 319, 348, 356, 396, 353, 336, 353, 336];
141 	var y=[261, 261, 269, 313, 305, 300, 388, 156, 148, 218, 210, 210, 140, 357, 301, 269, 261, 309, 301, 305, 313, 349, 301, 309, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 157, 157, 157, 157, 157, 157, 173, 165, 185, 193, 213, 205, 277, 300, 300, 308, 300, 300, 301, 301, 157, 157, 188, 188, 205, 237, 229, 165, 205, 223, 157, 189, 148, 157, 157, 157, 157, 188, 188, 188, 188, 157, 157, 157, 157, 157, 157, 157, 157, 225, 232, 348, 349, 348, 348, 356, 300, 300, 300, 300, 328, 321, 317, 317, 317, 317, 388, 388, 388, 388, 388, 388, 388, 388, 366, 374, 338, 346, 317, 317, 317, 317, 317, 317, 317, 317, 317, 317, 317, 317, 237, 205, 205, 205, 205, 205, 215, 205, 223, 218, 300, 300, 300, 300, 276, 377, 369, 268, 276, 223, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 317, 205, 205, 205, 205, 205, 205, 205, 188, 188, 188, 188, 188, 188, 188, 188, 188, 180, 164, 140, 231, 231, 237, 237];
142 	var d=[0, 1, 3, 2, 0, 1, 1, 1, 1, 2, 0, 1, 1, 2, 2, 2, 2, 3, 3, 1, 3, 2, 0, 2, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 3, 2, 2, 3, 3, 2, 2, 0, 0, 2, 2, 0, 3, 0, 0, 0, 0, 1, 1, 0, 2, 3, 1, 0, 3, 3, 1, 2, 2, 0, 2, 2, 2, 3, 2, 2, 3, 0, 1, 1, 0, 2, 3, 3, 2, 2, 3, 3, 2, 0, 2, 0, 1, 1, 0, 3, 0, 1, 0, 1, 2, 0, 2, 3, 3, 2, 1, 0, 0, 1, 0, 1, 0, 1, 1, 3, 0, 2, 2, 3, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 2, 3, 3, 2, 0, 3, 1, 3, 0, 1, 1, 0, 0, 2, 0, 0, 2, 2, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 2, 3, 2, 2, 3, 2, 2, 3, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 2, 3, 0, 1];
143 	for (var i = 0; i < GetLength(x); i++)
144 	{
145 		DrawMaterialTriangle("Brick-brick", x[i], y[i], [0,3,1,2][d[i]]);
146 		DrawMaterialTriangle("Brick-brick", LandscapeWidth() + 1 - x[i], y[i], [3,0,2,1][d[i]]);
147 	}
148 	return 1;
149 }
150 
InitializePlayer(int plr)151 protected func InitializePlayer(int plr)
152 {
153 	SetPlayerZoomByViewRange(plr, 600, nil, PLRZOOM_Direct);
154 	return;
155 }
156 
RelaunchWeaponList()157 func RelaunchWeaponList() { return [Blunderbuss, Sword, Javelin,  FrostboltScroll, Shovel]; }
158 
159 /*-- Chest filler effects --*/
160 
FxFillBaseChestStart(object target,effect,int temporary,bool supply)161 global func FxFillBaseChestStart(object target, effect, int temporary, bool supply)
162 {
163 	if (temporary)
164 		return 1;
165 
166 	effect.supply_type=supply;
167 	if(effect.supply_type)
168 		var w_list = [Firestone, Dynamite, IronBomb, Shovel, Loam, Ropeladder];
169 	else
170 		var w_list = [Bow, Shield, Sword, Javelin, Blunderbuss, FrostboltScroll];
171 	for(var i=0; i<5; i++)
172 		target->CreateChestContents(w_list[i]);
173 	return 1;
174 }
FxFillBaseChestTimer(object target,effect)175 global func FxFillBaseChestTimer(object target, effect)
176 {
177 	var maxcount = [];
178 
179 	if(effect.supply_type)
180 	{
181 		var w_list = [Firestone, Dynamite, IronBomb, Shovel, Loam, Ropeladder];
182 		var maxcount = [2,2,1,2,1];
183 	}
184 	else
185 	{
186 		var w_list = [Bow, Shield, Sword, Javelin, Blunderbuss, FrostboltScroll];
187 		var maxcount = [1,2,1,1,1,2];
188 	}
189 
190 	var contents;
191 	for(var i=0; i<target->GetLength(w_list); i++)
192 		contents+=target->ContentsCount(w_list[i]);
193 	if(contents > 5) return 1;
194 
195 	for(var i=0; i<2 ; i++)
196 	{
197 		var r = Random(GetLength(w_list));
198 		if (target->ContentsCount(w_list[r]) < maxcount[r])
199 		{
200 			target->CreateChestContents(w_list[r]);
201 			i=3;
202 		}
203 	}
204 	return 1;
205 }
206 
207 
FxFillOtherChestStart(object target,effect,int temporary)208 global func FxFillOtherChestStart(object target, effect, int temporary)
209 {
210 	if (temporary)
211 		return 1;
212 	var w_list = [Sword, Javelin, Club, Firestone, Dynamite, IronBomb, Firestone];
213 	if (target->ContentsCount() < 5)
214 		target->CreateChestContents(w_list[Random(GetLength(w_list))]);
215 	return 1;
216 }
217 
FxFillOtherChestTimer(object target)218 global func FxFillOtherChestTimer(object target)
219 {
220 
221 	var w_list = [Sword, Javelin, Dynamite, IronBomb, WindScroll, FrostboltScroll, Loam, HardeningScroll, PowderKeg];
222 	var maxcount = [1,1,3,1,2,1,1,1];
223 
224 	var contents;
225 	for(var i=0; i<target->GetLength(w_list); i++)
226 		contents+=target->ContentsCount(w_list[i]);
227 	if(contents > 5) return 1;
228 
229 	for(var i=0; i<2 ; i++)
230 	{
231 		var r = Random(GetLength(w_list));
232 		if (target->ContentsCount(w_list[r]) < maxcount[r])
233 		{
234 			target->CreateChestContents(w_list[r]);
235 			i=3;
236 		}
237 	}
238 	return 1;
239 }
240 
CreateChestContents(id obj_id)241 global func CreateChestContents(id obj_id)
242 {
243 	if (!this)
244 		return;
245 	var obj = CreateObjectAbove(obj_id);
246 	if (obj_id == Bow)
247 		obj->CreateContents(Arrow);
248 	if (obj_id == Blunderbuss)
249 		obj->CreateContents(LeadBullet);
250 	obj->Enter(this);
251 	return;
252 }
253