1 -- Library for miscellaneous utilitiy functions and global helper variables |
1 -- Library for miscellaneous utilitiy functions and global helper variables |
|
2 |
|
3 HedgewarsScriptLoad("/Scripts/Locale.lua") |
2 |
4 |
3 --[[ FUNCTIONS ]] |
5 --[[ FUNCTIONS ]] |
4 -- Check if a gear is inside a box |
6 -- Check if a gear is inside a box |
5 function gearIsInBox(gear, x, y, w, h) |
7 function gearIsInBox(gear, x, y, w, h) |
6 local gx, gy = GetGearPosition(gear) |
8 local gx, gy = GetGearPosition(gear) |
31 if flush ~= false then |
33 if flush ~= false then |
32 FlushPoints() |
34 FlushPoints() |
33 end |
35 end |
34 end |
36 end |
35 |
37 |
|
38 local function challengeRecordToString(recordType, value) |
|
39 if recordType == "TimeRecord" or recordType == "TimeRecordHigh" then |
|
40 return string.format(loc("Team record: %.3fs"), value/1000) |
|
41 elseif recordType == "Highscore" then |
|
42 return string.format(loc("Team high score: %d"), value) |
|
43 else |
|
44 return string.format(loc("Team record: %d"), value) |
|
45 end |
|
46 end |
|
47 |
|
48 function getReadableChallengeRecord(recordType) |
|
49 local record = tonumber(GetMissionVar(recordType)) |
|
50 if type(record) ~= "number" then |
|
51 return "" |
|
52 else |
|
53 return challengeRecordToString(recordType, record) |
|
54 end |
|
55 end |
|
56 |
|
57 function updateChallengeRecord(recordType, value, stat) |
|
58 local oldRecord = tonumber(GetMissionVar(recordType)) |
|
59 local newRecord = false |
|
60 if stat == nil then |
|
61 stat = true |
|
62 end |
|
63 if type(oldRecord) ~= "number" then |
|
64 newRecord = true |
|
65 else |
|
66 local recordBeaten = false |
|
67 if recordType == "Lowscore" or recordType == "TimeRecord" then |
|
68 if value < oldRecord then |
|
69 recordBeaten = true |
|
70 newRecord = true |
|
71 end |
|
72 else |
|
73 if value > oldRecord then |
|
74 recordBeaten = true |
|
75 newRecord = true |
|
76 end |
|
77 end |
|
78 if stat then |
|
79 if recordBeaten then |
|
80 SendStat(siCustomAchievement, loc("You have beaten the team record, congratulations!")) |
|
81 else |
|
82 SendStat(siCustomAchievement, challengeRecordToString(recordType, oldRecord)) |
|
83 end |
|
84 end |
|
85 end |
|
86 if newRecord then |
|
87 SaveMissionVar(recordType, value) |
|
88 end |
|
89 end |
|
90 |
36 -- Completely fill the map with land. Requires MapGen=mgDrawn. |
91 -- Completely fill the map with land. Requires MapGen=mgDrawn. |
37 -- If flush is false, FlushPoints() is not called. |
92 -- If flush is false, FlushPoints() is not called. |
38 function fillMap(flush) |
93 function fillMap(flush) |
39 drawFullMap(false, flush) |
94 drawFullMap(false, flush) |
40 end |
95 end |