1-- Name: The Edge-of-Space
2-- Description: You command the Technician Cruiser Apollo, a repair ship on the border of dangerous space.
3---
4--- The Apollo is outfitted with minimal weapons as there is a cease-fire between the Human Navy and the neighboring Kraylor.
5---
6--- You are tasked with discovering the cause of damage on one of your deep space telescopes.
7---
8--- This scenario is limited to one player ship: the Atlantis Apollo.
9-- Type: Mission
10-- Author: Visjammer
11
12--- Scenario
13-- @script scenario_06_edgeofspace
14
15--- Init is run when the scenario is started. Create your initial world.
16function init()
17    -- Create the main ship for the players.
18    Player = PlayerSpaceship():setFaction("Human Navy"):setTemplate("Atlantis"):setPosition(12400, 18200):setCallSign("Apollo"):addReputationPoints(250.0)
19    allowNewPlayerShips(false)
20
21    -- Modify the default cruiser into a technical cruiser, which has less weapon power than the normal player cruiser.
22    Player:setTypeName("Technician Cruiser")
23    --                 # Arc, Dir, Range, CycleTime, Dmg
24    Player:setBeamWeapon(0, 90, -25, 1000.0, 6.0, 10)
25    Player:setBeamWeapon(1, 90, 25, 1000.0, 6.0, 10)
26    Player:setWeaponTubeCount(1)
27    Player:setWeaponTubeDirection(0, 0)
28    Player:setWeaponStorageMax("Nuke", 0)
29    Player:setWeaponStorageMax("Mine", 0)
30
31    -- Create a "Technical Officer" entity hidden in sector Z81 to talk to Relay and prompt the Captain to give the order to return to Central Command. The position of this ship in relation to the station Nirvana was intended to serve as a sort of timer for the inspection job.
32    Technical_Officer = CpuShip():setFaction("Human Navy"):setTemplate("Flavia"):setCallSign("Technical Officer"):setPosition(1530000, 411000):orderIdle()
33    Technical_Officer:setCommsScript("") -- Disable the comms script for the Technical Officer station (though really, they should never find it all the way out in sector Z81).
34    -- Create a station called "Nirvana" for "Technical Officer" to approach. Surplus to requirements now but a good example of the crazy stuff a newbie might try.
35    Nirvana = SpaceStation():setTemplate("Small Station"):setFaction("Human Navy"):setPosition(1530000, 412000):setCallSign("Nirvana")
36
37    EOS_Station = SpaceStation():setTemplate("Small Station"):setFaction("Human Navy"):setPosition(60500, 42100):setCallSign("E.O.S. scope")
38    EOS_Station:setCommsScript("") -- Disable the comms script for the EOS Scope station.
39    Midspace_Station = SpaceStation():setTemplate("Medium Station"):setFaction("Human Navy"):setPosition(34643, 39301):setCallSign("Midspace Support")
40    Central_Command = SpaceStation():setTemplate("Huge Station"):setFaction("Human Navy"):setPosition(14500, 19100):setCallSign("Central Command")
41    Central_Command:setCommsScript("comms_station_scenario_06_central_command.lua")
42
43    Kraylor_Eline = SpaceStation():setTemplate("Small Station"):setFaction("Kraylor"):setPosition(79200, 38800):setCallSign("K-Endline")
44    Kraylor_Mline = SpaceStation():setTemplate("Large Station"):setFaction("Kraylor"):setPosition(101830, 26725):setCallSign("K-Midline")
45
46    Science_Galileo = SpaceStation():setTemplate("Medium Station"):setFaction("Arlenians"):setPosition(11100, -49150):setCallSign("Galileo")
47
48    -- Random-ass stations
49    SpaceStation():setTemplate("Small Station"):setFaction("Human Navy"):setCallSign("DS7"):setPosition(-44177, 20762)
50    SpaceStation():setTemplate("Medium Station"):setFaction("Human Navy"):setCallSign("DS4"):setPosition(1632, 30619)
51    SpaceStation():setTemplate("Small Station"):setFaction("Human Navy"):setCallSign("DS3"):setPosition(-9130, 10285)
52    SpaceStation():setTemplate("Medium Station"):setFaction("Human Navy"):setCallSign("DS2"):setPosition(-27987, 41095)
53
54    Human_m1 = CpuShip():setFaction("Human Navy"):setTemplate("MT52 Hornet"):setCallSign("HM1"):setScanned(true):setPosition(31875, 38653):orderDefendLocation(31875, 38653)
55    Human_m2 = CpuShip():setFaction("Human Navy"):setTemplate("MT52 Hornet"):setCallSign("HM2"):setScanned(true):setPosition(37493, 37185):orderDefendLocation(37493, 37185)
56    Human_m3 = CpuShip():setFaction("Human Navy"):setTemplate("MT52 Hornet"):setCallSign("HM3"):setScanned(true):setPosition(35519, 42854):orderDefendLocation(35519, 42854)
57
58    -- Nebulae that hide the enemy station.
59    Nebula():setPosition(52300, 42200)
60    Nebula():setPosition(51300, 34200)
61    Nebula():setPosition(48700, 30050)
62
63    -- Random-ass nebulae
64    Nebula():setPosition(49362, -18062)
65    Nebula():setPosition(-915, 27349)
66    Nebula():setPosition(-4159, 19240)
67    Nebula():setPosition(-10484, -10439)
68    Nebula():setPosition(21545, 64380)
69    Nebula():setPosition(-33690, 17766)
70    Nebula():setPosition(13626, 75799)
71    Nebula():setPosition(-68463, 42333)
72    Nebula():setPosition(-67320, 11857)
73    Nebula():setPosition(-46273, 39476)
74    Nebula():setPosition(-27368, 85952)
75    Nebula():setPosition(-33654, -41667)
76
77    -- Create 50 asteroids
78    for asteroid_counter = 1, 20 do
79        Asteroid():setPosition(random(-10000, 20000), random(-22000, -15000))
80        VisualAsteroid():setPosition(random(-10000, 20000), random(-22000, -15000))
81
82        Asteroid():setPosition(random(12000, 40000), random(-25000, -18000))
83        VisualAsteroid():setPosition(random(12000, 40000), random(-25000, -18000))
84
85        Asteroid():setPosition(random(35000, 55000), random(-27000, -20000))
86        VisualAsteroid():setPosition(random(35000, 55000), random(-27000, -20000))
87    end
88
89    -- Kraylor Endline ships protecting Eline until something happens
90    kraylor_e1 = CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setPosition(80200, 39900):setCallSign("K-EC1"):orderStandGround()
91    kraylor_e2 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setPosition(78200, 38000):setCallSign("K-EC2"):orderStandGround()
92    kraylor_e3 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setPosition(78000, 37100):setCallSign("K-EF1"):orderStandGround()
93    kraylor_e4 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setPosition(80200, 37900):setCallSign("K-EF2"):orderStandGround()
94
95    -- Kraylor ships primed to attack Galileo
96    kraylor_g1 = CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setScanned(true):setCallSign("K-Strike1"):setPosition(6273, -55399):orderIdle()
97    kraylor_g2 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setScanned(true):setCallSign("K-Fi2"):setPosition(10922, -51749):orderIdle()
98    kraylor_g3 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setScanned(true):setCallSign("K-Fi3"):setPosition(13948, -52838):orderIdle()
99
100    -- Kraylor Midline ships protecting Mline
101    kraylor_m1 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("K-MF1"):setPosition(103710, 31493):orderStandGround()
102    kraylor_m2 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("K-MF2"):setPosition(97993, 22149):orderStandGround()
103    kraylor_m3 = CpuShip():setFaction("Kraylor"):setTemplate("Atlantis X23"):setCallSign("K-MDFD"):setPosition(106363, 25218):orderStandGround()
104    kraylor_m4 = CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setCallSign("K-MC001"):setPosition(104829, 21454):orderStandGround()
105
106    -- Kraylor Nebula, that crazy maze with bad guys in it
107    Nebula():setPosition(82515, 1149)
108    Nebula():setPosition(88962, 3520)
109    Nebula():setPosition(83108, -7966)
110    Nebula():setPosition(94001, -4928)
111    Nebula():setPosition(105264, -8633)
112    Nebula():setPosition(85034, -16340)
113    Nebula():setPosition(93704, -17970)
114    Nebula():setPosition(106895, -18563)
115    Nebula():setPosition(102523, -28715)
116    Nebula():setPosition(111045, -27159)
117    Nebula():setPosition(88591, -26566)
118    Nebula():setPosition(83552, -35014)
119    Nebula():setPosition(97594, -36092)
120    Nebula():setPosition(84071, -44351)
121    Nebula():setPosition(90666, -50798)
122    Nebula():setPosition(98225, -52799)
123    Nebula():setPosition(106598, -53095)
124    Nebula():setPosition(113786, -48649)
125    Nebula():setPosition(116158, -41164)
126    Nebula():setPosition(118381, -32642)
127    Mine():setPosition(92000, -5669)
128    Mine():setPosition(104968, -7225)
129    Mine():setPosition(84960, 1371)
130    Mine():setPosition(81107, -4335)
131    Mine():setPosition(85479, -9596)
132    Mine():setPosition(85183, -17303)
133    Mine():setPosition(93779, -17377)
134    Mine():setPosition(91333, -25232)
135    Mine():setPosition(86887, -23380)
136    Mine():setPosition(83997, -29382)
137    Mine():setPosition(86442, -34717)
138    Mine():setPosition(80810, -35681)
139    Mine():setPosition(104672, -13598)
140    Mine():setPosition(109859, -18341)
141    Mine():setPosition(106006, -20045)
142    Mine():setPosition(108970, -25306)
143    Mine():setPosition(113786, -25454)
144    Mine():setPosition(115861, -31235)
145    Mine():setPosition(102300, -29752)
146    Mine():setPosition(99410, -31679)
147    Mine():setPosition(96298, -33309)
148    Mine():setPosition(99633, -36644)
149    Mine():setPosition(96076, -38348)
150    Mine():setPosition(118603, -38719)
151    Mine():setPosition(115120, -41164)
152    Mine():setPosition(119640, -32717)
153    Mine():setPosition(116380, -47908)
154    Mine():setPosition(111415, -50279)
155    Mine():setPosition(107932, -54132)
156    Mine():setPosition(98818, -51909)
157    Mine():setPosition(91778, -48056)
158    Mine():setPosition(91037, -52206)
159    Mine():setPosition(85479, -47908)
160    Mine():setPosition(86294, -43462)
161    Mine():setPosition(82070, -40497)
162    Mine():setPosition(96224, -3520)
163    Mine():setPosition(101930, -6855)
164    Mine():setPosition(107488, -9967)
165    Mine():setPosition(105635, -27159)
166    Mine():setPosition(113860, -29011)
167    Mine():setPosition(116899, -35977)
168    Mine():setPosition(85331, -26344)
169    Mine():setPosition(107117, -1816)
170    Mine():setPosition(96669, 852)
171    Mine():setPosition(78661, -13598)
172    Mine():setPosition(80292, -29752)
173    Mine():setPosition(114231, -19304)
174    Mine():setPosition(122605, -40794)
175    Mine():setPosition(113194, -55392)
176    Mine():setPosition(79402, -38867)
177    Mine():setPosition(82218, -51242)
178    Mine():setPosition(91704, -56874)
179    Mine():setPosition(102374, -58356)
180    CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setCallSign("K-SCN1"):setPosition(90940, -32988):orderDefendLocation(90940, -32988)
181    CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setCallSign("K-SCN2"):setPosition(95243, -29693):orderDefendLocation(95243, -29693)
182    CpuShip():setFaction("Kraylor"):setTemplate("Atlantis X23"):setCallSign("K-GDN1"):setPosition(105057, -46060):orderDefendLocation(105057, -46060)
183    CpuShip():setFaction("Kraylor"):setTemplate("Atlantis X23"):setCallSign("K-GDN2"):setPosition(102474, -42231):orderDefendLocation(102474, -42231)
184    CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("K-EGF1"):setPosition(87826, -3182):orderDefendLocation(87826, -3182)
185    Kraylor_hole = WormHole():setPosition(109190, -39762):setTargetPosition(-61730, 29490)
186
187    -- Central Command sends us to investigate the issues with E.O.S. scope.
188    -- Expanded text to attempt to explain why Apollo is shuttling this data around physically.
189    Central_Command:sendCommsMessage(
190        Player,
191        _([[Apollo, come in.
192
193Our edge-of-space telescope has been malfunctioning for the past few days. We expect the cause to be a mechanical failure, but we want you to take a look.
194
195The E.O.S. scope is on the border of Kraylor space, so maintain contact and keep up long-range scans.
196
197Dock with the E.O.S. scope and investigate the damage. Transmitting your report via standard communications channels is too dangerous given the already delicate nature of our treaty with the Kraylor, so return to Central Command to report your findings.
198
199Reopen communications if you have any questions.]])
200    )
201
202    Central_Command.mission_state = 1
203    kraylor_threat = 0
204    kraylor_warning = 0
205    command_warning = 0
206    inspection_init = 0
207    inspection_progress = 0
208    inspection_complete = 0
209    tech_databanks = 0
210    tech_stranded = 0
211end
212
213--- Update.
214--
215-- @param delta time delta in seconds
216function update(delta)
217    -- if you dead, you lose
218    if not Player:isValid() then
219        victory("Kraylor")
220    end
221
222    if not Central_Command:isValid() then
223        victory("Kraylor")
224    end
225
226    if not EOS_Station:isValid() then
227        victory("Kraylor")
228    end
229
230    if not Science_Galileo:isValid() then
231        victory("Kraylor")
232    end
233
234    if Central_Command.mission_state == 1 then
235        -- If K-Endline is destroyed at this stage Kraylor win
236        if not Kraylor_Eline:isValid() then
237            Central_Command:sendCommsMessage(
238                Player,
239                _([[Apollo, you've incited a war! What a disaster...]])
240            )
241            victory("Kraylor")
242        end
243
244        -- If the players get too close to K-Endline the station sends them a warning message
245        if distance(Player, Kraylor_Eline) < 10000 and kraylor_warning == 0 then
246            Kraylor_Eline:sendCommsMessage(
247                Player,
248                _([[A Human Naval cruiser encroaching on Kraylor space?
249
250Be warned: if you venture near our Endline territory, we will have no choice but to view your actions as hostile. Our indestructible fleet will make short work of you.]])
251            )
252
253            kraylor_warning = 1
254        end
255
256        -- When the players get within 40u of K-Endline they receive a message from Central Command telling them to be careful not to start a war.
257        if distance(Player, Kraylor_Eline) < 40000 and command_warning == 0 then
258            Central_Command:sendCommsMessage(
259                Player,
260                _([[The Kraylor's Endline station is near our E.O.S. scope.
261
262Do not confront them; we're not trying to start a war.]])
263            )
264
265            command_warning = 1
266        end
267
268        -- K-Endline warns the crew to behave themselves as the ship approaches EOS_Station (moved as I wanted to use docking event to trigger the Technical_Officer comms)
269        if distance(Player, EOS_Station) < 5000 then
270            if command_warning == 1 then
271                if kraylor_threat == 0 then
272                    Kraylor_Eline:sendCommsMessage(
273                        Player,
274                        _([[Attention Human Naval vessel:
275
276We have noted your expansion toward Kraylor Endline territory. Know that even the slightest act of aggression will be met with a forceful purging of all human ships and stations from our sector of space.
277
278Do what maintenance you must while you are here, but know also that we consider your telescopic station to be a potential threat.]])
279                    )
280
281                    Central_Command.mission_state = 2
282                    kraylor_threat = 1
283                end
284            end
285        end
286    end
287
288    inspection_progress = inspection_progress + delta
289    -- print(inspection_progress)  -- for Debugging
290
291    -- When the Apollo is docked with EOS_Station a message is received from the Technical Officer advising that his team is beginning their inspection
292    if Central_Command.mission_state == 2 then
293        if Player:isDocked(EOS_Station) and inspection_init == 0 then
294            globalMessage("Away Team in transit.")
295            Technical_Officer:sendCommsMessage(
296                Player,
297                _([[We're beginning our inspection of the E.O.S. scope facility.
298
299This shouldn't take long.]])
300            )
301            inspection_init = 1 -- inspection has begun (Timer event is pretty fool-proof but better to have a flag preventing "Job Done" somehow triggering before inspection starts)
302            inspection_progress = 0
303        end
304    end
305
306    if Central_Command.mission_state == 2 then
307        if Player:isDocked(EOS_Station) and inspection_init == 1 then
308            if inspection_progress > 30 then
309                if tech_databanks == 0 then
310                    Technical_Officer:sendCommsMessage(
311                        Player,
312                        _([[It looks like the databanks are still in good working order.
313
314We'll retrieve what we can.]])
315                    )
316                    tech_databanks = 1
317                end
318            end
319        end
320    end
321
322    -- Tech Officer complains about being left behind if the Apollo is not Docked since inspection began.
323    if Central_Command.mission_state == 2 then
324        if inspection_init == 1 then
325            if inspection_complete == 0 then
326                if inspection_progress > 50 then
327                    if not Player:isDocked(EOS_Station) then
328                        if tech_stranded == 0 then -- Without this the Technical Officer will always be harrassing the Apollo for pick-up once this event has triggered
329                            Technical_Officer:sendCommsMessage(
330                                Player,
331                                _([[Is something wrong Apollo? We're still in the facility.
332
333Please dock so we can come aboard.]])
334                            )
335                            tech_stranded = 1
336                        end
337                    end
338                end
339            end
340        end
341    end
342
343    -- "Job Done" message to prompt the Captain to give the order to Undock and head back to Central Command after a pseudo-random time period.
344    if Central_Command.mission_state == 2 then
345        if Player:isDocked(EOS_Station) then -- If the ship is not docked, the Tech Officer will complain.
346            if inspection_init == 1 and inspection_complete == 0 then
347                if inspection_progress > 50 then
348                    globalMessage("Away Team have returned.")
349                    Technical_Officer:sendCommsMessage(
350                        Player,
351                        _([[Our inspection of the scope facility is complete. We retrieved much of the data recorded over the past few days, though proper analysis will require an expert.
352
353We should hurry back to Central Command with this so they can begin work.]])
354                    )
355
356                    inspection_complete = 1 -- flag preventing continuous triggering of "Job Done" comms
357                end
358            end
359        end
360    end
361
362    -- Report back to Central Command
363    if Central_Command.mission_state == 2 then
364        -- If K-Endline is destroyed at this stage Kraylor win
365        if not Kraylor_Eline:isValid() then
366            Central_Command:sendCommsMessage(
367                Player,
368                _([[Apollo, you've incited a war! What a disaster...]])
369            )
370            victory("Kraylor")
371        end
372
373        if Player:isDocked(Central_Command) then
374            Central_Command:sendCommsMessage(
375                Player,
376                _([[It appears the damage was mechanical, but Kraylor ships in the area have been spotted in surveillance data you recovered from the E.O.S. scope. It's possible this was sabotage.
377
378Whatever the case, we need you to rendezvous with science station Galileo in sector C5. We've contracted this Arlenian station to interpret and analyze data retrieved from our various scope stations.]]
379                )
380            )
381
382            Central_Command.mission_state = 3
383        end
384    end
385
386    -- Get up to Galileo station
387    if Central_Command.mission_state == 3 then
388        -- If K-Endline is destroyed at this stage Kraylor win
389        if not Kraylor_Eline:isValid() then
390            Central_Command:sendCommsMessage(
391                Player,
392                _([[Apollo, you've incited a war! What a disaster...]])
393            )
394            victory("Kraylor")
395        end
396
397        if distance(Player, Science_Galileo) < 30000 then
398            Science_Galileo:sendCommsMessage(
399                Player,
400                _([[Distress signal incoming from Galileo station:
401
402Kraylor ships are in our vicinity, and we believe they intend to attack us! Please, you are the only battle-ready ship near our sector. Assist us!]])
403            )
404
405            kraylor_g1:orderRoaming()
406            kraylor_g2:orderRoaming()
407            kraylor_g3:orderRoaming()
408
409            Central_Command.mission_state = 4
410        end
411    end
412
413    -- Save the Galileo station from the Kraylor ships!
414    if Central_Command.mission_state == 4 then
415        -- If K-Endline is destroyed at this stage Kraylor win
416        if not Kraylor_Eline:isValid() then
417            Central_Command:sendCommsMessage(
418                Player,
419                _([[Apollo, you've incited a war! What a disaster...]])
420            )
421            victory("Kraylor")
422        end
423
424        if not kraylor_g1:isValid() and not kraylor_g2:isValid() and not kraylor_g3:isValid() then
425            Science_Galileo:sendCommsMessage(
426                Player,
427                _([[We don't know why Kraylor ships were attacking us. We had just recieved word that your ship was on its way with data from the edge-of-space telescopic station when they began interrupting transmissions.
428
429Thank you for defending our station. Please dock with us, and we'll analyze the data from the E.O.S. scope.]])
430            )
431
432            Central_Command.mission_state = 5
433        end
434    end
435
436    -- Dock with Galileo station
437    if Central_Command.mission_state == 5 then
438        if Player:isDocked(Science_Galileo) then
439            Central_Command:sendCommsMessage(
440                Player,
441                _([[Apollo, come in!
442
443Leave the E.O.S. data with Galileo for now, we've confirmed reports that Kraylor are brazen enough to attack our E.O.S. scope directly! All available ships should converge on E.O.S. territory in sector H8!
444
445That means you, Apollo!]])
446            )
447
448            kraylor_e1:orderRoaming()
449            kraylor_e2:orderRoaming()
450            kraylor_e3:orderRoaming()
451            kraylor_e4:orderRoaming()
452
453            Human_m1:orderDefendLocation(60500, 42100)
454            Human_m2:orderDefendLocation(60500, 42100)
455            Human_m3:orderDefendLocation(60500, 42100)
456
457            Central_Command.mission_state = 6
458        end
459    end
460
461    -- Save the E.O.S. station from Kraylor scum! K-Endline is a valid target at last!
462    if Central_Command.mission_state == 6 then
463        if not kraylor_e1:isValid() and not kraylor_e2:isValid() and not kraylor_e3:isValid() and not kraylor_e4:isValid() then
464            if Kraylor_Eline:isValid() then
465                -- HM1 gives you the exciting news that K-Endline is a valid target at last!
466                if Human_m1:isValid() then
467                    Human_m1:sendCommsMessage(
468                        Player,
469                        _([[Apollo, HM1 here.
470
471Central Command has no choice but to declare war. We're moving into Kraylor territory for our retaliatory strike. Attack the Kraylor Endline station!]])
472                    )
473
474                    kraylor_m1:orderRoaming()
475                    kraylor_m2:orderRoaming()
476                    kraylor_m3:orderRoaming()
477                    kraylor_m4:orderRoaming()
478
479                    Human_m1:orderFlyTowards(79200, 38800)
480                    Human_m2:orderFlyTowards(79200, 38800)
481                    Human_m3:orderFlyTowards(79200, 38800)
482
483                    Central_Command.mission_state = 7
484                end
485
486                -- If HM1 died then Central Command gives the order to destroy K-Endline
487                if not Human_m1:isValid() then
488                    Central_Command:sendCommsMessage(
489                        Player,
490                        _([[Apollo, come in.
491
492We have no choice but to declare war. Move into Kraylor territory and retaliate on their defenseless Endline station!]])
493                    )
494
495                    kraylor_m1:orderRoaming()
496                    kraylor_m2:orderRoaming()
497                    kraylor_m3:orderRoaming()
498                    kraylor_m4:orderRoaming()
499
500                    Human_m1:orderFlyTowards(79200, 38800)
501                    Human_m2:orderFlyTowards(79200, 38800)
502                    Human_m3:orderFlyTowards(79200, 38800)
503
504                    Central_Command.mission_state = 7
505                end
506            end
507
508            -- Time for some sweet upgrades!
509            if not Kraylor_Eline:isValid() then
510                if not kraylor_m1:isValid() and not kraylor_m2:isValid() and not kraylor_m3:isValid() and not kraylor_m4:isValid() then
511                    Central_Command:sendCommsMessage(
512                        Player,
513                        _([[Apollo, come in.
514
515Our cease-fire with the Kraylor is at a bitter end, and aggression will only rise from here. It is imperative that our ships be equipped with all counter-measures necessary to keep them safe.
516
517Dock with the E.O.S. scope. We are re-fitting your ship in preparation for wartime.]])
518                    )
519
520                    Human_m1:orderDefendLocation(31875, 38653)
521                    Human_m2:orderDefendLocation(37493, 37185)
522                    Human_m3:orderDefendLocation(35519, 42854)
523
524                    Central_Command.mission_state = 9
525                end
526
527                -- Kraylor scum talk a big game considering they just lost K-Endline
528                if kraylor_m1:isValid() or kraylor_m2:isValid() or kraylor_m3:isValid() or kraylor_m4:isValid() then
529                    if Kraylor_Mline:isValid() then
530                        Kraylor_Mline:sendCommsMessage(
531                            Player,
532                            _([[Broadcast on all Human Naval frequencies:
533
534Human scum, we warned you to stay out of Kraylor territory!]])
535                        )
536
537                        kraylor_m1:orderRoaming()
538                        kraylor_m2:orderRoaming()
539                        kraylor_m3:orderRoaming()
540                        kraylor_m4:orderRoaming()
541
542                        Human_m1:orderRoaming()
543                        Human_m2:orderRoaming()
544                        Human_m3:orderRoaming()
545
546                        Central_Command.mission_state = 8
547                    end
548
549                    if not Kraylor_Mline:isValid() then
550                        Central_Command:sendCommsMessage(
551                            Player,
552                            _([[Apollo, come in.
553
554Our cease-fire with the Kraylor is at a bitter end. Destroy the remaining Kraylor ships threatening our E.O.S. territory!]])
555                        )
556
557                        kraylor_m1:orderRoaming()
558                        kraylor_m2:orderRoaming()
559                        kraylor_m3:orderRoaming()
560                        kraylor_m4:orderRoaming()
561
562                        Human_m1:orderRoaming()
563                        Human_m2:orderRoaming()
564                        Human_m3:orderRoaming()
565
566                        Central_Command.mission_state = 8
567                    end
568                end
569            end
570        end
571    end
572
573    -- Time for some sweet upgrades!
574    -- Retaliate on the Kraylor Endline station!
575    if Central_Command.mission_state == 7 then
576        if not Kraylor_Eline:isValid() then
577            if not kraylor_m1:isValid() and not kraylor_m2:isValid() and not kraylor_m3:isValid() and not kraylor_m4:isValid() then
578                Central_Command:sendCommsMessage(
579                    Player,
580                    _([[Apollo, come in.
581
582Our cease-fire with the Kraylor is at a bitter end, and aggression will only rise from here. It is imperative that our ships be equipped with all counter-measures necessary to keep them safe.
583
584Dock with the E.O.S. scope. We are re-fitting your ship in preparation for wartime.]])
585                )
586
587                Human_m1:orderDefendLocation(31875, 38653)
588                Human_m2:orderDefendLocation(37493, 37185)
589                Human_m3:orderDefendLocation(35519, 42854)
590
591                Central_Command.mission_state = 9
592            end
593
594            if kraylor_m1:isValid() or kraylor_m2:isValid() or kraylor_m3:isValid() or kraylor_m4:isValid() then
595                if Kraylor_Mline:isValid() then
596                    Kraylor_Mline:sendCommsMessage(
597                        Player,
598                        _([[Broadcast on all Human Naval frequencies:
599
600Human scum, we warned you to stay out of Kraylor territory!]])
601                    )
602
603                    kraylor_m1:orderRoaming()
604                    kraylor_m2:orderRoaming()
605                    kraylor_m3:orderRoaming()
606                    kraylor_m4:orderRoaming()
607
608                    Human_m1:orderRoaming()
609                    Human_m2:orderRoaming()
610                    Human_m3:orderRoaming()
611
612                    Central_Command.mission_state = 8
613                end
614
615                if not Kraylor_Mline:isValid() then
616                    Central_Command:sendCommsMessage(
617                        Player,
618                        _([[Apollo, come in.
619
620Our cease-fire with the Kraylor is at a bitter end. Destroy the remaining Kraylor ships threatening our E.O.S. territory!]])
621                    )
622
623                    kraylor_m1:orderRoaming()
624                    kraylor_m2:orderRoaming()
625                    kraylor_m3:orderRoaming()
626                    kraylor_m4:orderRoaming()
627
628                    Human_m1:orderRoaming()
629                    Human_m2:orderRoaming()
630                    Human_m3:orderRoaming()
631
632                    Central_Command.mission_state = 8
633                end
634            end
635        end
636    end
637
638    -- Destroy the remaining Kraylor ships!
639    if Central_Command.mission_state == 8 then
640        -- if kraylor_m3:isValid() and not kraylor_m1:isValid() and not kraylor_m2:isValid() and not kraylor_m4:isValid() then
641        --    kraylor_m3:orderRoaming()
642        -- end
643
644        -- Time for some sweet upgrades!
645        if not kraylor_m1:isValid() and not kraylor_m2:isValid() and not kraylor_m3:isValid() and not kraylor_m4:isValid() then
646            Central_Command:sendCommsMessage(
647                Player,
648                _([[Apollo, come in.
649
650Kraylor aggression will only rise from here. It is imperative that our ships be equipped with all counter-measures necessary to keep them safe.
651
652Dock with the E.O.S. scope. We are re-fitting your ship in preparation for wartime.]])
653            )
654
655            Human_m1:orderDefendLocation(31875, 38653)
656            Human_m2:orderDefendLocation(37493, 37185)
657            Human_m3:orderDefendLocation(35519, 42854)
658
659            Central_Command.mission_state = 9
660        end
661    end
662
663    -- Dock at E.O.S. to get re-fitted with weapons
664    if Central_Command.mission_state == 9 then
665        if Player:isDocked(EOS_Station) then
666            -- Reconfigure the player ship into a Wartime Technician, which has more weapon capabilities then the Technical cruiser.
667            Player:setTypeName("Wartime Technician")
668            --                    # Arc, Dir, Range, CycleTime, Dmg
669            Player:setBeamWeapon(0, 100, -20, 1000.0, 6.0, 10)
670            Player:setBeamWeapon(1, 100, 20, 1000.0, 6.0, 10)
671            Player:setBeamWeapon(2, 90, 180, 1000.0, 6.0, 10)
672            Player:setWeaponTubeCount(3)
673            Player:setWeaponTubeDirection(0, 0):weaponTubeDisallowMissle(0, "Mine")
674            Player:setWeaponTubeDirection(1, 0):weaponTubeDisallowMissle(1, "Mine")
675            Player:setWeaponTubeDirection(2, 180)
676            Player:setWeaponTubeExclusiveFor(2, "Mine")
677            Player:setWeaponStorageMax("Homing", 12)
678            Player:setWeaponStorageMax("Nuke", 4)
679            Player:setWeaponStorageMax("Mine", 8)
680            Player:setWeaponStorageMax("EMP", 6)
681            Player:setWeaponStorage("Homing", 12)
682            Player:setWeaponStorage("Nuke", 4)
683            Player:setWeaponStorage("Mine", 8)
684            Player:setWeaponStorage("EMP", 6)
685
686            Central_Command:sendCommsMessage(
687                Player,
688                _([[Science station Galileo has completed their analysis of the E.O.S. scope data.
689
690Edge-of-space sensors picked up sparse signals from the super-nebula in Kraylor space that indicate they have some kind of wormhole. Intelligence suggests they intend to use it to infiltrate human space and attack us where we are defenseless!
691
692When your ship is finished being outfitted for war, move up to the nebula, but be cautious. There may be traps.]])
693            )
694
695            Central_Command.mission_state = 10
696        end
697    end
698
699    -- Get to the wormhole!
700    if Central_Command.mission_state == 10 then
701        if distance(Player, Kraylor_hole) < 10000 then
702            Central_Command:sendCommsMessage(
703                Player,
704                _([[Apollo, come in!
705
706Reports are coming in from core human space that a massive Kraylor strike force is attacking! Get through that wormhole and attack from within their ranks to hold them off. We'll send all our available ships to converge there.]])
707            )
708
709            -- Let's get crazy up in here
710            k01 = CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setCallSign("BR21"):setPosition(-50654, 32238):orderRoaming()
711            k02 = CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setCallSign("UT64"):setPosition(-48368, 27476):orderRoaming()
712            k03 = CpuShip():setFaction("Kraylor"):setTemplate("Phobos T3"):setCallSign("NC13"):setPosition(-34082, 40047):orderRoaming()
713            k04 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("CV45"):setPosition(-59606, 18904):orderRoaming()
714            k05 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("TI25"):setPosition(-43796, 43857):orderRoaming()
715            k06 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("IN16"):setPosition(-43796, 52428):orderRoaming()
716            k07 = CpuShip():setFaction("Kraylor"):setTemplate("Piranha F12"):setCallSign("VA27"):setPosition(-58082, 31285):orderRoaming()
717            k08 = CpuShip():setFaction("Kraylor"):setTemplate("Piranha F12"):setCallSign("CN78"):setPosition(-26082, 22333):orderRoaming()
718            k09 = CpuShip():setFaction("Kraylor"):setTemplate("Atlantis X23"):setCallSign("AL92"):setPosition(-42273, 12238):orderRoaming()
719            k10 = CpuShip():setFaction("Kraylor"):setTemplate("Starhammer II"):setCallSign("OH30"):setPosition(-26844, 48809):orderRoaming()
720            k11 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("SS11"):setPosition(-45320, 9381):orderRoaming()
721            k12 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("CS61"):setPosition(-40558, 8809):orderRoaming()
722            k13 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("JL33"):setPosition(-27796, 52428):orderRoaming()
723            k14 = CpuShip():setFaction("Kraylor"):setTemplate("MT52 Hornet"):setCallSign("SQ50"):setPosition(-24368, 46143):orderRoaming()
724            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("BN53"):setPosition(-40654, 47095):orderRoaming()
725            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("VK68"):setPosition(-37796, 56619):orderRoaming()
726            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("XD37"):setPosition(-29987, 55476):orderRoaming()
727            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("CC31"):setPosition(-45796, 26143):orderRoaming()
728            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("CM29"):setPosition(-51892, 24047):orderRoaming()
729            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("SO40"):setPosition(-2939, 40619):orderRoaming()
730            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("VS41"):setPosition(2966, 45000):orderRoaming()
731            -- CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("BR42"):setPosition(-12796, 16809):orderRoaming()
732            -- CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("MT52 Hornet"):setCallSign("UTI43"):setPosition(-10463, 7476):orderRoaming()
733            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("Phobos T3"):setCallSign("CI44"):setPosition(-10368, 13571):orderRoaming()
734            CpuShip():setFaction("Human Navy"):setScanned(true):setTemplate("Phobos T3"):setCallSign("NI15"):setPosition(-10368, 50143):orderRoaming()
735
736            Human_m1:orderRoaming()
737            Human_m2:orderRoaming()
738            Human_m3:orderRoaming()
739
740            Central_Command.mission_state = 11
741        end
742    end
743
744    if Central_Command.mission_state == 11 then
745        if
746            not k01:isValid() and not k02:isValid() and not k03:isValid() and not k04:isValid() and not k05:isValid() and not k06:isValid() and not k07:isValid() and not k08:isValid() and not k09:isValid() and not k10:isValid() and not k11:isValid() and not k12:isValid() and not k13:isValid() and
747                not k14:isValid()
748         then
749            victory("Human Navy")
750        end
751    end
752end
753
754--- Return the distance between two objects.
755function distance(obj1, obj2)
756    x1, y1 = obj1:getPosition()
757    x2, y2 = obj2:getPosition()
758    xd, yd = (x1 - x2), (y1 - y2)
759    return math.sqrt(xd * xd + yd * yd)
760end
761