Debian Codegraph @

dat/missions/empire/longdistanceshipping/es_longdistancecargo.lua

raw
1 --[[
2 <?xml version='1.0' encoding='utf8'?>
3 <mission name="Long Distance Empire Shipping">
4 <avail>
5 <priority>3</priority>
6 <cond>faction.playerStanding("Empire") &gt;= 0</cond>
7 <chance>350</chance>
8 <done>Empire Long Distance Recruitment</done>
9 <location>Computer</location>
10 <faction>Empire</faction>
11 </avail>
12 <notes>
13 <campaign>Long Distance Shipping</campaign>
14 </notes>
15 </mission>
16 --]]
17 --[[
18
19 Handles the randomly generated Empire long-distance cargo missions.
20
21 ]]--
22
23 require "cargo_common.lua"
24 require "numstring.lua"
25
26
27 misn_desc = _("Official Empire long distance cargo transport to %s in the %s system.")
28
29 piracyrisk = {}
30 piracyrisk[1] = _("Piracy Risk: None")
31 piracyrisk[2] = _("Piracy Risk: Low")
32 piracyrisk[3] = _("Piracy Risk: Medium")
33 piracyrisk[4] = _("Piracy Risk: High")
34
35 msg_timeup = _("MISSION FAILED: You have failed to deliver the goods to the Empire on time!")
36
37 osd_title = _("Long Distance Empire Shipping")
38 osd_msg1 = _("Fly to %s in the %s system before %s\n(%s remaining)")
39
40 --[[
41 -- Empire shipping missions are always timed, but quite lax on the schedules
42 -- pays a bit more then the rush missions
43 --]]
44
45
46 -- This is in cargo_common, but we need to increase the range
47 function cargo_selectMissionDistance ()
48 return rnd.rnd( 5, 12 )
49 end
50
51
52 -- Create the mission
53 function create()
54 -- Note: this mission does not make any system claims.
55
56 origin_p, origin_s = planet.cur()
57 local routesys = origin_s
58 local routepos = origin_p:pos()
59
60 -- target destination
61 destplanet, destsys, numjumps, traveldist, cargo, avgrisk, tier = cargo_calculateRoute()
62 if destplanet == nil then
63 misn.finish(false)
64 end
65 if destplanet:faction() == faction.get( "Empire" )
66 or destplanet:faction() == faction.get( "Independent" ) then
67 misn.finish(false)
68 end
69
70 -- mission generics
71 stuperpx = 0.3 - 0.015 * tier
72 stuperjump = 11000 - 75 * tier
73 stupertakeoff = 15000
74 timelimit = time.get() + time.create(0, 0, traveldist * stuperpx + numjumps * stuperjump + stupertakeoff + 480 * numjumps)
75
76 -- Allow extra time for refuelling stops.
77 local jumpsperstop = 3 + math.min(tier, 2)
78 if numjumps > jumpsperstop then
79 timelimit:add(time.create( 0, 0, math.floor((numjumps-1) / jumpsperstop) * stuperjump ))
80 end
81
82 --Determine risk of piracy
83 if avgrisk == 0 then
84 piracyrisk = piracyrisk[1]
85 riskreward = 0
86 elseif avgrisk <= 25 then
87 piracyrisk = piracyrisk[2]
88 riskreward = 10
89 elseif avgrisk > 25 and avgrisk <= 100 then
90 piracyrisk = piracyrisk[3]
91 riskreward = 25
92 else
93 piracyrisk = piracyrisk[4]
94 riskreward = 50
95 end
96
97 -- Choose amount of cargo and mission reward. This depends on the mission tier.
98 finished_mod = 2.0 -- Modifier that should tend towards 1.0 as Naev is finished as a game
99 amount = rnd.rnd(10 + 3 * tier, 20 + 4 * tier)
100 jumpreward = commodity.price(cargo)*1.5
101 distreward = math.log(300*commodity.price(cargo))/100
102 reward = 1.5^tier * (avgrisk*riskreward + numjumps * jumpreward + traveldist * distreward) * finished_mod * (1. + 0.05*rnd.twosigma())
103
104 misn.setTitle( string.format(
105 _("ES: Long distance cargo transport (%s of %s)"), tonnestring(amount),
106 _(cargo) ) )
107 misn.markerAdd(destsys, "computer")
108 cargo_setDesc( misn_desc:format( destplanet:name(), destsys:name() ), cargo, amount, destplanet, timelimit, piracyrisk );
109 misn.setReward( creditstring(reward) )
110 end
111
112 -- Mission is accepted
113 function accept()
114 local playerbest = cargoGetTransit( timelimit, numjumps, traveldist )
115 if timelimit < playerbest then
116 if not tk.yesno( _("Too slow"), string.format(
117 _("This shipment must arrive within %s, but it will take at least %s for your ship to reach %s, missing the deadline. Accept the mission anyway?"),
118 (timelimit - time.get()):str(), (playerbest - time.get()):str(),
119 destplanet:name() ) ) then
120 misn.finish()
121 end
122 end
123 if player.pilot():cargoFree() < amount then
124 tk.msg( _("No room in ship"), string.format(
125 _("You don't have enough cargo space to accept this mission. It requires %s of free space (%s more than you have)."),
126 tonnestring(amount),
127 tonnestring( amount - player.pilot():cargoFree() ) ) )
128 misn.finish()
129 end
130
131 misn.accept()
132
133 carg_id = misn.cargoAdd( cargo, amount )
134 tk.msg( _("Mission Accepted"), string.format(
135 _("The Empire workers load the %s of %s onto your ship."),
136 tonnestring(amount), _(cargo) ) )
137 local osd_msg = {}
138 osd_msg[1] = osd_msg1:format(
139 destplanet:name(), destsys:name(), timelimit:str(),
140 ( timelimit - time.get() ):str() )
141 misn.osdCreate(osd_title, osd_msg)
142 hook.land( "land" ) -- only hook after accepting
143 hook.date(time.create(0, 0, 100), "tick") -- 100STU per tick
144 end
145
146 -- Land hook
147 function land()
148 if planet.cur() == destplanet then
149 tk.msg( _("Successful Delivery"), string.format(
150 _("The Empire workers unload the %s at the docks."), _(cargo) ) )
151 player.pay(reward)
152 n = var.peek("es_misn")
153 if n ~= nil then
154 var.push("es_misn", n+1)
155 else
156 var.push("es_misn", 1)
157 end
158
159 -- increase faction
160 faction.modPlayerSingle("Empire", rnd.rnd(4, 6))
161 misn.finish(true)
162 end
163 end
164
165 -- Date hook
166 function tick()
167 if timelimit >= time.get() then
168 -- Case still in time
169 local osd_msg = {}
170 osd_msg[1] = osd_msg1:format(
171 destplanet:name(), destsys:name(), timelimit:str(),
172 ( timelimit - time.get() ):str() )
173 misn.osdCreate(osd_title, osd_msg)
174 elseif timelimit <= time.get() then
175 -- Case missed deadline
176 player.msg(msg_timeup)
177 misn.finish(false)
178 end
179 end