-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfloor-upgrades-queue.lua
101 lines (93 loc) · 2.72 KB
/
floor-upgrades-queue.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local Queue = require("queue")
local Util = require("util")
local GridUtil = require("grid-util")
local function assert_init()
if storage.tycoon_floor_upgrade_queue == nil then
storage.tycoon_floor_upgrade_queue = Queue.new()
end
end
local function push(city, coordinates, newTileType)
assert_init()
Queue.pushright(storage.tycoon_floor_upgrade_queue, {city = city, coordinates = coordinates, newTileType = newTileType})
end
local function pop()
assert_init()
return Queue.popleft(storage.tycoon_floor_upgrade_queue)
end
-- todo: consolidate with where this was copied from
--- @param direction Direction
--- @return string[] map
local function getMap(direction)
local result = nil
if direction == "north" then
result = {
"001100",
"001100",
"001100",
"001100",
"000000",
"000000",
}
elseif direction == "south" then
result = {
"000000",
"000000",
"001100",
"001100",
"001100",
"001100",
}
elseif direction == "west" then
result = {
"000000",
"000000",
"111100",
"111100",
"000000",
"000000",
}
elseif direction == "east" then
result = {
"000000",
"000000",
"001111",
"001111",
"000000",
"000000",
}
end
assert(result ~= nil, "Invalid direction for getMap")
return result
end
local function process()
local current = pop()
if current == nil then
return
end
local city, coordinates, newTileType = current.city, current.coordinates, current.newTileType
assert(current.city ~= nil and current.coordinates ~= nil and current.newTileType ~= nil, "Record in tycoon_floor_upgrade_queue doesn't have all required fields.")
local cell = GridUtil.safeGridAccess(city, coordinates)
local cell_type = cell.type
local startCoordinates = GridUtil.translateCityGridToTileCoordinates(city, coordinates)
if cell_type == "building" then
Util.printTiles(startCoordinates, {
"111111",
"111111",
"111111",
"111111",
"111111",
"111111",
}, newTileType, city.surface_index)
elseif cell_type == "road" then
for _, direction in ipairs(cell.roadSockets) do
Util.printTiles(startCoordinates, getMap(direction), newTileType, city.surface_index)
end
elseif cell_type ~= "unused" then
game.print("Would upgrade other cell: " .. cell_type)
end
end
return {
push = push,
pop = pop,
process = process,
}