File: preload.lua

package info (click to toggle)
cataclysm-dda 0.C%2Bgit20190228.faafa3a-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 181,636 kB
  • sloc: cpp: 256,609; python: 2,621; makefile: 862; sh: 495; perl: 37; xml: 33
file content (76 lines) | stat: -rw-r--r-- 1,915 bytes parent folder | download
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
function message(...)
    local s = string.format(...)
    game.add_msg(s)
end

function iuse_test_npc(item, active)
    local um
    local feature

    -- Create select menu
    um = game.create_uimenu()
    um.title = "What do you do?"
    um:addentry("Check NPC's opinion")
    um:addentry("Make NPC angry")
    um:addentry("Make NPC your follower")
    um:addentry("Cancel")
    -- Wait for player selection
    um:query(true)

    if um.selected == 3 then
        -- Canceled
        return 0
    end
    feature = um.selected

    local p = player:pos()
    local delta_x
    local delta_y
    local npc_num = 0
    local npcs = {}
    local npc

    -- Create select menu
    um = game.create_uimenu()
    um.title = "Select NPC"
    -- Search NPCs around you
    for delta_x = -1, 1 do
        for delta_y = -1, 1 do
            local tp = tripoint(p.x + delta_x, p.y + delta_y, p.z)
            npc = game.get_npc_at(tp)
            if npc then
                um:addentry(npc:get_name())
                table.insert(npcs, npc)
                npc_num = npc_num + 1
            end
        end
    end
    um:addentry("Cancel")
    -- Wait for player selection
    um:query(true)

    if um.selected == npc_num then
        -- Canceled
        return 0
    end

    local target = npcs[um.selected + 1]
    if feature == 0 then
        local opinion = target.op_of_u
        message("Trust: %d", opinion.trust)
        message("Fear: %d", opinion.fear)
        message("Value: %d", opinion.value)
        message("Anger: %d", opinion.anger)
        message("Owed: %d", opinion.owed)
    elseif feature == 1 then
        target:make_angry()
        message("%s gets angry!", target:disp_name())
    elseif feature == 2 then
        target:set_attitude("NPCATT_FOLLOW")
        message("%s is your follower now.", target:disp_name())
    end

    return 0
end

game.register_iuse("TEST_NPC", iuse_test_npc)