1--[[
2   Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
3   This file is part of OpenRA, which is free software. It is made
4   available to you under the terms of the GNU General Public License
5   as published by the Free Software Foundation, either version 3 of
6   the License, or (at your option) any later version. For more
7   information, see COPYING.
8]]
9AlliedReinforcementsA = { "e1", "e1", "e1", "e1", "e1" }
10AlliedReinforcementsB = { "e1", "e1", "e3", "e3", "e3" }
11AlliedBoatReinforcements = { "pt", "pt" }
12BadGuys = { BadGuy1, BadGuy2, BadGuy3, BadGuy4 }
13
14SovietDogPatrols =
15{
16	{ Patrol_1_e1, Patrol_1_dog },
17	{ Patrol_2_e1, Patrol_2_dog },
18	{ Patrol_3_e1, Patrol_3_dog },
19	{ Patrol_4_e1, Patrol_4_dog }
20}
21
22SovietDogPatrolPaths =
23{
24	{ Patrol6.Location, Patrol7.Location, Patrol8.Location, Patrol1.Location, Patrol2.Location, Patrol3.Location, Patrol4.Location, Patrol5.Location },
25	{ Patrol8.Location, Patrol1.Location, Patrol2.Location, Patrol3.Location, Patrol4.Location, Patrol5.Location, Patrol6.Location, Patrol7.Location },
26	{ Patrol1.Location, Patrol2.Location, Patrol3.Location, Patrol4.Location, Patrol5.Location, Patrol6.Location, Patrol7.Location, Patrol8.Location },
27	{ Patrol2.Location, Patrol3.Location, Patrol4.Location, Patrol5.Location, Patrol6.Location, Patrol7.Location, Patrol8.Location, Patrol1.Location }
28}
29
30Mammoths = { Mammoth1, Mammoth2, Mammoth3 }
31
32SovietMammothPaths =
33{
34	{ TnkPatrol1.Location, TnkPatrol2.Location,TnkPatrol3.Location, TnkPatrol4.Location, TnkPatrol5.Location, TnkPatrol6.Location },
35	{ TnkPatrol5.Location, TnkPatrol6.Location, TnkPatrol1.Location, TnkPatrol2.Location, TnkPatrol3.Location, TnkPatrol4.Location },
36	{ TnkPatrol6.Location, TnkPatrol1.Location, TnkPatrol2.Location, TnkPatrol3.Location, TnkPatrol4.Location, TnkPatrol5.Location }
37}
38
39SubPaths = {
40	{ SubPatrol1_1.Location, SubPatrol1_2.Location },
41	{ SubPatrol2_1.Location, SubPatrol2_2.Location },
42	{ SubPatrol3_1.Location, SubPatrol3_2.Location },
43	{ SubPatrol4_1.Location, SubPatrol4_2.Location },
44	{ SubPatrol5_1.Location, SubPatrol5_2.Location }
45}
46
47ParadropWaypoints =
48{
49	easy = { UnitBStopLocation },
50	normal = { UnitBStopLocation, UnitAStopLocation },
51	hard = { UnitBStopLocation, UnitCStopLocation, UnitAStopLocation }
52}
53
54SovietTechLabs = { TechLab1, TechLab2 }
55
56GroupPatrol = function(units, waypoints, delay)
57	local i = 1
58	local stop = false
59
60	Utils.Do(units, function(unit)
61		Trigger.OnIdle(unit, function()
62			if stop then
63				return
64			end
65			if unit.Location == waypoints[i] then
66				local bool = Utils.All(units, function(actor) return actor.IsIdle end)
67				if bool then
68					stop = true
69					i = i + 1
70					if i > #waypoints then
71						i = 1
72					end
73					Trigger.AfterDelay(delay, function() stop = false end)
74				end
75			else
76				unit.AttackMove(waypoints[i])
77			end
78		end)
79	end)
80end
81
82InitialSovietPatrols = function()
83	-- Dog Patrols
84	BeachDog.Patrol({ BeachPatrol1.Location, BeachPatrol2.Location, BeachPatrol3.Location })
85	for i = 1, 4 do
86		GroupPatrol(SovietDogPatrols[i], SovietDogPatrolPaths[i], DateTime.Seconds(5))
87	end
88
89	-- Mammoth Patrols
90	for i = 1, 3 do
91		Trigger.AfterDelay(DateTime.Seconds(6 * (i - 1)), function()
92			Trigger.OnIdle(Mammoths[i], function()
93				Mammoths[i].Patrol(SovietMammothPaths[i])
94			end)
95		end)
96	end
97
98	-- Sub Patrols
99	Patrol1Sub.Patrol(SubPaths[1])
100	Patrol2Sub.Patrol(SubPaths[2])
101	Patrol3Sub.Patrol(SubPaths[3])
102	Patrol4Sub.Patrol(SubPaths[4])
103	Patrol5Sub.Patrol(SubPaths[5])
104end
105
106InitialAlliedReinforcements = function()
107	local camera = Actor.Create("Camera", true, { Owner = player, Location = DefaultCameraPosition.Location })
108	Trigger.AfterDelay(DateTime.Seconds(30), camera.Destroy)
109
110	Trigger.AfterDelay(DateTime.Seconds(1), function()
111	Reinforcements.Reinforce(player, AlliedReinforcementsA, { AlliedEntry3.Location, UnitCStopLocation.Location }, 2)
112		Reinforcements.Reinforce(player, AlliedReinforcementsB, { AlliedEntry2.Location, UnitAStopLocation.Location }, 2)
113	end)
114	Trigger.AfterDelay(DateTime.Seconds(3), function()
115		Reinforcements.Reinforce(player, { "mcv" }, { AlliedEntry1.Location, UnitBStopLocation.Location })
116		Reinforcements.Reinforce(player, AlliedBoatReinforcements, { AlliedBoatEntry.Location, AlliedBoatStop.Location })
117	end)
118end
119
120CaptureRadarDome = function()
121	Trigger.OnKilled(RadarDome, function()
122		player.MarkFailedObjective(CaptureRadarDomeObj)
123	end)
124
125	Trigger.OnCapture(RadarDome, function()
126		player.MarkCompletedObjective(CaptureRadarDomeObj)
127
128		Utils.Do(SovietTechLabs, function(a)
129			if a.IsDead then
130				return
131			end
132
133			Beacon.New(player, a.CenterPosition)
134			if Map.LobbyOption("difficulty") ~= "hard" then
135				Actor.Create("TECH.CAM", true, { Owner = player, Location = a.Location + CVec.New(1, 1) })
136			end
137		end)
138
139		Media.DisplayMessage("Coordinates of the Soviet tech centers discovered.")
140
141		if Map.LobbyOption("difficulty") == "easy" then
142			Actor.Create("Camera", true, { Owner = player, Location = Weapcam.Location })
143		end
144	end)
145end
146
147InfiltrateTechCenter = function()
148	Utils.Do(SovietTechLabs, function(a)
149		Trigger.OnInfiltrated(a, function()
150			if infiltrated then
151				return
152			end
153			infiltrated = true
154			DestroySovietsObj = player.AddPrimaryObjective("Destroy all Soviet buildings and units in the area.")
155			player.MarkCompletedObjective(InfiltrateTechCenterObj)
156		end)
157
158		Trigger.OnCapture(a, function()
159			if not infiltrated then
160				Media.DisplayMessage("Do not capture the tech centers! Infiltrate one with a spy.")
161			end
162		end)
163	end)
164
165	Trigger.OnAllKilledOrCaptured(SovietTechLabs, function()
166		if not player.IsObjectiveCompleted(InfiltrateTechCenterObj) then
167			player.MarkFailedObjective(InfiltrateTechCenterObj)
168		end
169	end)
170end
171
172Tick = function()
173	if player.HasNoRequiredUnits() then
174		player.MarkFailedObjective(InfiltrateTechCenterObj)
175	end
176
177	if DestroySovietsObj and ussr.HasNoRequiredUnits() then
178		player.MarkCompletedObjective(DestroySovietsObj)
179	end
180end
181
182WorldLoaded = function()
183	player = Player.GetPlayer("Greece")
184	ussr = Player.GetPlayer("USSR")
185
186	Trigger.OnObjectiveAdded(player, function(p, id)
187		Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
188	end)
189
190	Trigger.OnObjectiveCompleted(player, function(p, id)
191		Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed")
192	end)
193
194	Trigger.OnObjectiveFailed(player, function(p, id)
195		Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed")
196	end)
197
198	Trigger.OnPlayerLost(player, function()
199		Media.PlaySpeechNotification(player, "MissionFailed")
200	end)
201	Trigger.OnPlayerWon(player, function()
202		Media.PlaySpeechNotification(player, "MissionAccomplished")
203	end)
204
205	InfiltrateTechCenterObj = player.AddPrimaryObjective("Infiltrate one of the Soviet tech centers with a spy.")
206	CaptureRadarDomeObj = player.AddSecondaryObjective("Capture the Radar Dome at the shore.")
207
208	Camera.Position = DefaultCameraPosition.CenterPosition
209
210	if Map.LobbyOption("difficulty") == "easy" then
211		Trigger.OnEnteredProximityTrigger(SovietDefenseCam.CenterPosition, WDist.New(1024 * 7), function(a, id)
212			if a.Owner == player then
213				Trigger.RemoveProximityTrigger(id)
214				local cam1 = Actor.Create("TECH.CAM", true, { Owner = player, Location = SovietDefenseCam.Location })
215				Trigger.AfterDelay(DateTime.Seconds(15), cam1.Destroy)
216				if not DefenseFlame1.IsDead then
217					local cam2 = Actor.Create("TECH.CAM", true, { Owner = player, Location = DefenseFlame1.Location })
218					Trigger.AfterDelay(DateTime.Seconds(15), cam2.Destroy)
219				end
220				if not DefenseFlame2.IsDead then
221					local cam3 = Actor.Create("TECH.CAM", true, { Owner = player, Location = DefenseFlame2.Location })
222					Trigger.AfterDelay(DateTime.Seconds(15), cam3.Destroy)
223				end
224			end
225		end)
226	end
227
228	if Map.LobbyOption("difficulty") ~= "hard" then
229		Trigger.OnKilled(DefBrl1, function(a, b)
230			if not DefenseFlame1.IsDead then
231				DefenseFlame1.Kill()
232			end
233		end)
234		Trigger.OnKilled(DefBrl2, function(a, b)
235			if not DefenseFlame2.IsDead then
236				DefenseFlame2.Kill()
237			end
238		end)
239	end
240
241	Utils.Do(BadGuys, function(a)
242		a.AttackMove(UnitCStopLocation.Location)
243	end)
244
245	InitialAlliedReinforcements()
246	Trigger.AfterDelay(DateTime.Seconds(1), function()
247		InitialSovietPatrols()
248	end)
249
250	Trigger.OnEnteredProximityTrigger(SovietMiniBaseCam.CenterPosition, WDist.New(1024 * 14), function(a, id)
251		if a.Owner == player then
252			Trigger.RemoveProximityTrigger(id)
253			local cam = Actor.Create("Camera", true, { Owner = player, Location = SovietMiniBaseCam.Location })
254			Trigger.AfterDelay(DateTime.Seconds(15), cam.Destroy)
255		end
256	end)
257	CaptureRadarDome()
258	InfiltrateTechCenter()
259	Trigger.AfterDelay(0, ActivateAI)
260end
261