File: shipwreck.lua

package info (click to toggle)
naev 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 386,084 kB
  • sloc: ansic: 93,149; xml: 87,292; python: 2,347; sh: 904; makefile: 654; lisp: 162; awk: 4
file content (88 lines) | stat: -rw-r--r-- 2,269 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--[[
<?xml version='1.0' encoding='utf8'?>
<event name="Shipwreck">
  <trigger>enter</trigger>
  <chance>3</chance>
  <cond>system.cur():presence("Pirate") &gt; 0</cond>
  <flags>
   <unique />
  </flags>
  <notes>
   <tier>1</tier>
  </notes>
 </event>
 --]]
--[[
-- Shipwreck Event
-- 
-- Creates a wrecked ship that asks for help. If the player boards it, the event switches to the Space Family mission.
-- See dat/missions/neutral/spacefamily.lua
-- 
-- 12/02/2010 - Added visibility/highlight options for use in big systems (Anatolis)
--]]

-- Text
broadcastmsg = _("SOS. This is %s. We are shipwrecked. Requesting immediate assistance.")
shipname = _("August") --The ship will have a unique name
shipwreck = _("Shipwrecked %s")

function create ()

    -- The shipwreck will be a random trader vessel.
    r = rnd.rnd()
    if r > 0.95 then
        ship = "Trader Gawain"
    elseif r > 0.8 then
        ship = "Trader Mule"
    elseif r > 0.5 then
        ship = "Trader Koala"
    else 
        ship = "Trader Llama"
    end

    -- Create the derelict.
    angle = rnd.rnd() * 2 * math.pi
    dist  = rnd.rnd(2000, 3000) -- place it a ways out
    pos   = vec2.new( dist * math.cos(angle), dist * math.sin(angle) )
    p     = pilot.add(ship, "dummy", pos)
    for k,v in ipairs(p) do
        v:setFaction("Derelict")
        v:disable()
        v:rename(shipwreck:format(shipname))
        -- Added extra visibility for big systems (A.)
        v:setVisplayer( true )
        v:setHilight( true )
    end

    hook.timer(3000, "broadcast")
   
    -- Set hooks
    hook.pilot( p[1], "board", "rescue" )
    hook.pilot( p[1], "death", "destroyevent" )
    hook.enter("endevent")
    hook.land("endevent")
end

function broadcast()
    -- Ship broadcasts an SOS every 10 seconds, until boarded or destroyed.
    if not p[1]:exists() then
       return
    end
    p[1]:broadcast( string.format(broadcastmsg, shipname), true )
    bctimer = hook.timer(15000, "broadcast")
end

function rescue()
    -- Player boards the shipwreck and rescues the crew, this spawns a new mission.
    hook.rm(bctimer)
    naev.missionStart("The Space Family")
    evt.finish(true)
end

function destroyevent ()
    evt.finish(true)
 end

function endevent ()
    evt.finish()
end