-
Notifications
You must be signed in to change notification settings - Fork 7
/
achievements.lua
67 lines (61 loc) · 2.16 KB
/
achievements.lua
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
local function assert_global_achievements()
if global.tycoon_achievements == nil then
global.tycoon_achievements = {}
end
end
local function unlock_achievement_for_all(achievement_name)
for _, player in pairs(game.players) do
player.unlock_achievement(achievement_name)
end
end
--- @param city City
local function countCitizens(city)
local total = 0
for _, count in pairs(city.citizens) do
total = total + count
end
return total
end
local function check_population_achievements()
assert_global_achievements()
if global.tycoon_achievements.population_complete then
return
end
local total = 0;
local next_step = global.tycoon_achievements.population_next_step or 100
for _, city in ipairs(global.tycoon_cities or {}) do
local citizen_count = countCitizens(city)
total = total + citizen_count
if total >= next_step then
unlock_achievement_for_all("tycoon-population-" .. next_step)
if next_step >= 100000 then
global.tycoon_achievements.population_complete = true
else
global.tycoon_achievements.population_next_step = next_step * 10
end
return
end
end
end
local function check_passenger_transport_achievements()
assert_global_achievements()
if global.tycoon_achievements.passenger_transport_complete then
return
end
local next_step = global.passenger_transport_next_step or 100
local passengers_transported = global.tycoon_passenger_transported_count or 0
if passengers_transported >= next_step then
unlock_achievement_for_all("tycoon-passenger-transport-" .. next_step)
if next_step >= 100000 then
global.tycoon_achievements.passenger_transport_complete = true
else
global.tycoon_achievements.passenger_transport_next_step = next_step * 10
end
return
end
end
return {
unlock_achievement_for_all = unlock_achievement_for_all,
check_population_achievements = check_population_achievements,
check_passenger_transport_achievements = check_passenger_transport_achievements,
}