1 QuestHelper_File
["collect_location.lua"] = "Development Version"
2 QuestHelper_Loadtime
["collect_location.lua"] = GetTime()
4 -- little endian two's complement
5 local function signed(c
)
6 QuestHelper
: Assert(not c
or c
>= -127 and c
< 127)
7 if not c
then c
= -128 end
8 if c
< 0 then c
= c
+ 256 end
12 local function float(c
)
14 c
= math
.floor(c
* 1000 + 0.5) -- get our 3 digits, then integer it
15 QuestHelper
: Assert(c
>= -2147483647 and c
< 2147483647)
19 if c
< 0 then c
= c
+ 4294967296 end
20 return strchar(bit
.band(c
, 0xff), bit
.band(c
, 0xff00) / 256, bit
.band(c
, 0xff0000) / 65536, bit
.band(c
, 0xff000000) / 16777216)
23 local function BolusizeLocation(c
, x
, y
, rc
, rz
)
24 -- c, rc, and rz are all *signed* integers that fit within an 8-bit int.
25 -- x and y are floating-point values. We're going to assume they're 5-digit, but we also want at least 3 digits of precision. (Note that 3 digits is a more than most sites use - most of them do 3 digits in terms of local map coordinates, but most maps are more than 1000 yards large, with the exception of some major cities.) That's 8 digits total, so we're gonna be spending 32 bits on this. Lua uses 64-bit float types, which have something like 53 digits of precision, so we've got plenty of accuracy for our 32 bits.
26 -- Overall we're using a somewhat-weird 11 bytes on this. Meh.
27 -- Also, any nil values are being turned into MIN_WHATEVER.
28 return signed(c
) .. float(x
) .. float(y
) .. signed(rc
) .. signed(rz
)
31 -- This merely provides another API function
32 function QH_Collect_Location_Init(_
, API
)
33 API
.Callback_LocationBolus
= BolusizeLocation
-- Yeah. *Bolusize*. You heard me.
34 API
.Callback_LocationBolusCurrent
= function () return BolusizeLocation(API
.Callback_RawLocation()) end -- This is just a convenience function, really