update changes
[QuestHelper.git] / collect_warp.lua
blob0a90b8e49f79004ac761612110018f073c57c660
1 QuestHelper_File["collect_warp.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_warp.lua"] = GetTime()
4 local debug_output = false
5 if QuestHelper_File["collect_warp.lua"] == "Development Version" then debug_output = true end
7 local QHCW
9 local GetLoc
10 local Merger
11 local RawLocation
13 local lastloc_bolus
14 local last_delayed, last_rc, last_rz, last_rx, last_ry
15 local last_valid
17 local last_warp = 0
19 local function valid(d, rc, rz, rx, ry)
20 return not d and rc and rz and rx and ry
21 end
23 local function OnUpdate()
24 local bolus = GetLoc()
25 local now_delayed, now_rc, now_rz, now_rx, now_ry = RawLocation()
26 local now_valid = valid(RawLocation())
28 if last_valid and now_valid then
29 local leapy = false
30 if last_rc ~= now_rc or last_rz ~= now_rz then
31 leapy = true
32 else
33 local dx, dy = last_rx - now_rx, last_ry - now_ry
34 dx, dy = dx * dx, dy * dy
35 if dx + dy > 0.01 * 0.01 then
36 leapy = true
37 end
38 end
40 if leapy then
41 if debug_output then QuestHelper:TextOut("Warpy!") end
42 end
44 if last_warp + 10 < GetTime() and leapy then
45 if debug_output then QuestHelper:TextOut("REAL Warpy!") end
46 Merger.Add(QHCW, lastloc_bolus .. bolus)
47 last_warp = GetTime()
48 end
49 end
51 lastloc_bolus = bolus
53 last_delayed, last_rc, last_rz, last_rx, last_ry, last_valid = now_delayed, now_rc, now_rz, now_rx, now_ry, now_valid
54 end
56 function QH_Collect_Warp_Init(QHCData, API)
57 if not QHCData.warp then QHCData.warp = {} end
58 QHCW = QHCData.warp
60 API.Registrar_OnUpdateHook(OnUpdate)
62 GetLoc = API.Callback_LocationBolusCurrent
63 QuestHelper: Assert(GetLoc)
65 RawLocation = API.Callback_Location_Raw
66 QuestHelper: Assert(RawLocation)
68 Merger = API.Utility_Merger
69 QuestHelper: Assert(Merger)
70 end