Debian Codegraph @

dat/missions/soromid/comingout/srm_comingout3.lua

raw
1 --[[
2 <?xml version='1.0' encoding='utf8'?>
3 <mission name="A Friend's Aid">
4 <flags>
5 <unique />
6 </flags>
7 <avail>
8 <priority>2</priority>
9 <done>Coming of Age</done>
10 <chance>30</chance>
11 <location>Bar</location>
12 <faction>Soromid</faction>
13 <cond>var.peek("comingout_time") == nil or time.get() &gt;= time.fromnumber(var.peek("comingout_time")) + time.create(0, 20, 0)</cond>
14 </avail>
15 <notes>
16 <campaign>Coming Out</campaign>
17 <tier>3</tier>
18 </notes>
19 </mission>
20 --]]
21 --[[
22
23 A Friend's Aid
24
25 This program is free software: you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published by
27 the Free Software Foundation, either version 3 of the License, or
28 (at your option) any later version.
29
30 This program is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 GNU General Public License for more details.
34
35 You should have received a copy of the GNU General Public License
36 along with this program. If not, see <http://www.gnu.org/licenses/>.
37
38 --]]
39
40 require "numstring.lua"
41 require "cargo_common.lua"
42 require "nextjump.lua"
43 require "missions/soromid/common.lua"
44
45
46 title = {}
47 text = {}
48
49 title[1] = _("A Friend's Aid")
50 text[1] = _([[Chelsea gleefully waves you over. "It's nice to see you again!" she says. The two of you chat a bit about her venture into the piloting business; all is well from the sound of it. "Say," she says, "someone offered me a really interesting mission recently, but I had to decline because my ship isn't really up to task. If you could just escort my ship through that mission I could share the pay with you! Your half would be %s. How about it?"]])
51
52 text[2] = _([["Awesome! I really appreciate it!
53 "So the mission is in theory a pretty simple one: I need to deliver some cargo to %s in the %s system. Trouble is apparently I'll be getting in the middle of some sort of trade dispute with a shady Soromid company that's bribed the local Soromid pilots. Needless to say we can expect to be attacked by some thugs and the Soromid military isn't likely to be of much help.
54 "That's where you come in. I just need you to follow me along, make sure I finish jumping or landing before you do, and if we encounter any hostilities, help me shoot them down. Shouldn't be too too hard as long as you've got a decent ship. I'll meet you out in space!"]])
55
56 text[3] = _([["Ah, OK. Let me know if you change your mind."]])
57
58 text[4] = _([["I could still use your help with that mission! Could you help me out?"]])
59
60 title[5] = _("Mission Failed")
61 text[5] = _("You have lost contact with Chelsea and therefore failed the mission.")
62
63 title[6] = _("Another Happy Landing")
64 text[6] = _([[You successfully land and dock alongside Chelsea and she approaches the worker for the cargo delivery. The worker gives her a weird look, but collects the cargo with the help of some robotic drones and hands her a credit chip. When you get back to your ships, Chelsea transfers the sum of %s to your account, and you idly chat with her for a while.
65 "Anyway, I should probably get going now," she says. "But I really appreciated the help there! Get in touch with me again sometime. We make a great team!" You agree, and you both go your separate ways once again.]])
66
67 misn_title = _("A Friend's Aid")
68 misn_desc = _("Chelsea needs you to escort her to %s.")
69
70 npc_name = _("Chelsea")
71 npc_desc = _("You see Chelsea looking contemplative.")
72
73 osd_desc = {}
74 osd_desc[1] = _("Escort Chelsea to %s in the %s system.")
75
76 cheljump_msg = _("Chelsea has jumped to %s.")
77 chelland_msg = _("Chelsea has landed on %s.")
78 chelkill_msg = _("MISSION FAILED: A rift in the space-time continuum causes you to have never met Chelsea in that bar.")
79 chelflee_msg = _("MISSION FAILED: Chelsea has abandoned the mission.")
80 plflee_msg = _("MISSION FAILED: You have abandoned the mission.")
81
82 log_text = _([[You helped escort Chelsea through a dangerous cargo delivery mission where you had to protect her from the thugs of a shady company. She said that she would like to get back in touch with you again sometime for another mission.]])
83
84
85 function create ()
86 misplanet, missys, njumps, tdist, cargo, avgrisk = cargo_calculateRoute()
87 if misplanet == nil or missys == nil or avgrisk > 0 then
88 misn.finish( false )
89 end
90
91 credits = 500000
92 started = false
93
94 misn.setNPC( npc_name, "soromid/unique/chelsea" )
95 misn.setDesc( npc_desc )
96 end
97
98
99 function accept ()
100 local txt
101 if started then
102 txt = text[4]
103 else
104 txt = text[1]:format( creditstring( credits ) )
105 end
106 started = true
107
108 if tk.yesno( title[1], txt ) then
109 tk.msg( title[1], text[2]:format( misplanet:name(), missys:name() ) )
110
111 misn.accept()
112
113 misn.setTitle( misn_title )
114 misn.setDesc( misn_desc:format( misplanet:name() ) )
115 misn.setReward( creditstring( credits ) )
116 marker = misn.markerAdd( missys, "low" )
117
118 osd_desc[1] = osd_desc[1]:format( misplanet:name(), missys:name() )
119 misn.osdCreate( misn_title, osd_desc )
120
121 startplanet = planet.cur()
122
123 hook.takeoff( "takeoff" )
124 hook.jumpout( "jumpout" )
125 hook.jumpin( "jumpin" )
126 hook.land( "land" )
127 else
128 tk.msg( title[1], text[3] )
129 misn.finish()
130 end
131 end
132
133
134 function cargo_selectMissionDistance ()
135 return 3
136 end
137
138
139 function spawnChelseaShip( param )
140 chelsea = pilot.addRaw( "Llama", "mercenary", param, "Comingout_associates" )
141 chelsea:rmOutfit( "all" )
142 chelsea:rmOutfit( "cores" )
143 chelsea:addOutfit( "Unicorp PT-200 Core System" )
144 chelsea:addOutfit( "Unicorp Hawk 300 Engine" )
145 chelsea:addOutfit( "Unicorp D-4 Light Plating" )
146 chelsea:addOutfit( "Laser PD MK2", 2 )
147 chelsea:addOutfit( "Small Shield Booster", 2 )
148 chelsea:addOutfit( "Cargo Pod", 2 )
149
150 chelsea:setHealth( 100, 100 )
151 chelsea:setEnergy( 100 )
152 chelsea:setTemp( 0 )
153 chelsea:setFuel( true )
154
155 chelsea:cargoAdd( "Industrial Goods", chelsea:cargoFree() )
156
157 chelsea:setFriendly()
158 chelsea:setHilight()
159 chelsea:setVisible()
160 chelsea:setInvincPlayer()
161 chelsea:rename( "Chelsea" )
162
163 hook.pilot( chelsea, "death", "chelsea_death" )
164 hook.pilot( chelsea, "jump", "chelsea_jump" )
165 hook.pilot( chelsea, "land", "chelsea_land" )
166 hook.pilot( chelsea, "attacked", "chelsea_attacked" )
167
168 chelsea_jumped = false
169 end
170
171
172 function spawnThug( param )
173 local shiptypes = { "Hyena", "Hyena", "Hyena", "Shark", "Lancelot" }
174 local shiptype = shiptypes[ rnd.rnd( 1, #shiptypes ) ]
175 thug = pilot.addRaw( shiptype, "baddie", param, "Comingout_thugs" )
176
177 thug:setHostile()
178 thug:rename( "Thug " .. shiptype )
179
180 hook.pilot( thug, "death", "thug_removed" )
181 hook.pilot( thug, "jump", "thug_removed" )
182 hook.pilot( thug, "land", "thug_removed" )
183 end
184
185
186 function jumpNext ()
187 if chelsea ~= nil and chelsea:exists() then
188 chelsea:taskClear()
189 chelsea:control()
190 if system.cur() == missys then
191 chelsea:land( misplanet, true )
192 else
193 chelsea:hyperspace( getNextSystem( system.cur(), missys ), true )
194 end
195 end
196 end
197
198
199 function takeoff ()
200 spawnChelseaShip( startplanet )
201 jumpNext()
202 spawnThug()
203 end
204
205
206 function jumpout ()
207 lastsys = system.cur()
208 end
209
210
211 function jumpin ()
212 if chelsea_jumped and system.cur() == getNextSystem( lastsys, missys ) then
213 spawnChelseaShip( lastsys )
214 jumpNext()
215 hook.timer( 5000, "thug_timer" )
216 else
217 fail( plflee_msg )
218 end
219 end
220
221
222 function land ()
223 if planet.cur() == misplanet then
224 tk.msg( title[6], text[6]:format( creditstring( credits ) ) )
225 player.pay( credits )
226 srm_addComingOutLog( log_text )
227 misn.finish( true )
228 else
229 tk.msg( title[5], text[5] )
230 misn.finish( false )
231 end
232 end
233
234
235 function thug_timer ()
236 spawnThug()
237 if system.cur() == missys then
238 spawnThug( lastsys )
239 end
240 end
241
242
243 function chelsea_death ()
244 fail( chelkill_msg )
245 end
246
247
248 function chelsea_jump( p, jump_point )
249 if jump_point:dest() == getNextSystem( system.cur(), missys ) then
250 player.msg( cheljump_msg:format( jump_point:dest():name() ) )
251 chelsea_jumped = true
252 else
253 fail( chelflee_msg )
254 end
255 end
256
257
258 function chelsea_land( p, planet )
259 if planet == misplanet then
260 player.msg( chelland_msg:format( planet:name() ) )
261 chelsea_jumped = true
262 else
263 fail( chelflee_msg )
264 end
265 end
266
267
268 function chelsea_attacked ()
269 if chelsea ~= nil and chelsea:exists() then
270 chelsea:control( false )
271 if distress_timer_hook ~= nil then hook.rm( distress_timer_hook ) end
272 distress_timer_hook = hook.timer( 1000, "chelsea_distress_timer" )
273 end
274 end
275
276
277 function chelsea_distress_timer ()
278 jumpNext()
279 end
280
281
282 function thug_removed ()
283 spawnThug()
284 if distress_timer_hook ~= nil then hook.rm( distress_timer_hook ) end
285 jumpNext()
286 end
287
288
289 -- Fail the mission, showing message to the player.
290 function fail( message )
291 if message ~= nil then
292 -- Pre-colourized, do nothing.
293 if message:find("\a") then
294 player.msg( message )
295 -- Colourize in red.
296 else
297 player.msg( "\ar" .. message .. "\a0" )
298 end
299 end
300 misn.finish( false )
301 end