File: rehab_common.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 (127 lines) | stat: -rw-r--r-- 4,757 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
--common
--[[
--
-- Rehabilitation Mission
--
-- This mission allows you to remain neutral with a faction until you've done services for them.
-- This file is used by the various faction missions, which must set the faction variable.
--
--]]

require "scripts/numstring.lua"


misn_title = _("%s Rehabilitation")
misn_desc = _([[You may pay a fine for a chance to redeem yourself in the eyes of a faction you have offended. You may interact with this faction as if your reputation were neutral, but your reputation will not actually improve until you've regained their trust. ANY hostile action against this faction will immediately void this agreement.
Faction: %s
Cost: %s]])
misn_reward = _("None")

lowmoney = _("You don't have enough money. You need at least %s to buy a cessation of hostilities with this faction.")
accepted = _([[Your application has been processed. The %s security forces will no longer attack you on sight. You may conduct your business in %s space again, but remember that you still have a criminal record! If you attack any traders, civilians or %s ships, or commit any other felony against this faction, you will immediately become their enemy again.
While this agreement is active your reputation will not change, but if you continue to behave properly and perform beneficial services, your past offenses will eventually be stricken from the record.]])

failuretitle = _("%s Rehabilitation Canceled")
failuretext = _([[You have committed another offense against this faction! Your rehabilitation procedure has been canceled, and your reputation is once again bad. You may start another rehabilitation procedure at a later time.]])

successtitle = _("%s Rehabilitation Successful")
successtext = _([[Congratulations, you have successfully worked your way back into good standing with this faction. Try not to relapse into your life of crime!]])

osd_msg = {}
osd_msg[1] = "(null)"
osd_msg["__save"] = true


function create()
    -- Note: this mission does not make any system claims.

    -- Only spawn this mission if the player needs it.
    rep = fac:playerStanding()
    if rep >= 0 then
       misn.finish()
    end
    
    -- Don't spawn this mission if the player is buddies with this faction's enemies.
    for _, enemy in pairs(fac:enemies()) do
       if enemy:playerStanding() > 20 then
          misn.finish()
       end
    end

    setFine(rep)
    
    misn.setTitle(misn_title:format(fac:name()))
    misn.setDesc(misn_desc:format(fac:name(), creditstring(fine)))
    misn.setReward(misn_reward)
end

function accept()
    if player.credits() < fine then
        tk.msg("", lowmoney:format(creditstring(fine)))
        misn.finish()
    end
    
    player.pay(-fine)
    tk.msg(misn_title:format(fac:name()), accepted:format(fac:name(), fac:name(), fac:name()))
    
    fac:modPlayerRaw(-rep)
    
    misn.accept()
    osd_msg[1] = gettext.ngettext(
       "You need to gain %d more reputation",
       "You need to gain %d more reputation",
       -rep
    ):format(-rep)
    misn.osdCreate(misn_title:format(fac:name()), osd_msg)
    
    standhook = hook.standing("standing")
    
    excess = 5 -- The maximum amount of reputation the player can LOSE before the contract is void.
end

-- Function to set the height of the fine. Missions that require this script may override this.
function setFine(standing)
    fine = (-standing)^2 * 1000 -- A value between 0 and 10M credits
end

-- Standing hook. Manages faction reputation, keeping it at 0 until it goes positive.
function standing(hookfac, delta)
    if hookfac == fac then
        if delta >= 0 then
            rep = rep + delta
            if rep >= 0 then
                -- The player has successfully erased his criminal record.
                excess = excess + delta
                fac:modPlayerRaw(-delta + rep)
                tk.msg(successtitle:format(fac:name()), successtext)
                misn.finish(true)
            end

            excess = excess + delta
            fac:modPlayerRaw(-delta)
            osd_msg[1] = gettext.ngettext(
               "You need to gain %d more reputation",
               "You need to gain %d more reputation",
               -rep
            ):format(-rep)
            misn.osdCreate(misn_title:format(fac:name()), osd_msg)
        else
            excess = excess + delta
            if excess < 0 or fac:playerStanding() < 0 then
                abort()
            end
        end
    end
end

-- On abort, reset reputation.
function abort()
    -- Remove the standing hook prior to modifying reputation.
    hook.rm(standhook)

    -- Reapply the original negative reputation.
    fac:modPlayerRaw(rep)

    tk.msg(failuretitle:format(fac:name()), failuretext)
    misn.finish(false)
end