Skip to content

Commit 87d4a59

Browse files
committed
Fix infinite loop by persisting already_shuffled
1 parent dcb2432 commit 87d4a59

File tree

2 files changed

+49
-52
lines changed

2 files changed

+49
-52
lines changed

mods/se-interstellar-construction-requests-fulfillment/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "se-interstellar-construction-requests-fulfillment",
33
"title": "Space Exploration - interstellar construction requests fulfillment",
44
"description": "Keeping building equipment stocked at every planet is tedious, just shoot it there from nauvis.",
5-
"version": "1.0.10",
5+
"version": "1.0.11",
66
"author": "Quezler",
77
"factorio_version": "1.1",
88
"dependencies": [

mods/se-interstellar-construction-requests-fulfillment/scripts/handler.lua

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,16 @@ function Handler.shuffle_array_in_place(t)
8282
end
8383
end
8484

85-
function Handler.draw_random_card()
86-
local already_shuffled = false
87-
85+
function Handler.draw_random_card(already)
8886
while true do
89-
log('infinite loop 1?')
9087
if #global.deck == 0 then
91-
if already_shuffled or #global.pile == 0 then return nil end
88+
if already.shuffled or #global.pile == 0 then return nil end
9289

9390
Handler.shuffle_array_in_place(global.pile)
9491
global.deck = global.pile
9592
global.pile = {}
9693

97-
already_shuffled = true
94+
already.shuffled = true
9895
end
9996

10097
local struct = global.structs[table.remove(global.deck)]
@@ -103,15 +100,7 @@ function Handler.draw_random_card()
103100
global.structs[struct.unit_number] = nil
104101
else
105102
table.insert(global.pile, struct.unit_number)
106-
107-
if struct.entity.energy >= Handler.get_energy_per_shot() then
108-
if not struct.proxy or not struct.proxy.valid then
109-
if struct.buffer_chest.logistic_network then
110-
return struct
111-
end
112-
end
113-
end
114-
103+
return struct
115104
end
116105
end
117106
end
@@ -147,47 +136,55 @@ function Handler.handle_construction_alert(alert_target)
147136
for _, item_to_place_this in ipairs(alert_target.ghost_prototype.items_to_place_this) do
148137
if item_to_place_this.count == 1 then -- no support for e.g. curved rails (which need 4) yet
149138

139+
local already = {shuffled = false}
150140
while true do
151-
log('infinite loop 2?')
152-
local struct = Handler.draw_random_card()
141+
local struct = Handler.draw_random_card(already)
153142
if not struct then break end
154143

155144
if alert_target.force == struct.entity.force then
156-
if struct.buffer_chest.logistic_network.can_satisfy_request(item_to_place_this.name, item_to_place_this.count, true) then
157-
local proxy = struct.entity.surface.create_entity{
158-
name = 'item-request-proxy',
159-
force = struct.entity.force,
160-
target = struct.entity,
161-
position = struct.entity.position,
162-
modules = {[item_to_place_this.name] = item_to_place_this.count}
163-
}
164-
165-
rendering.draw_text{
166-
color = {1, 1, 1},
167-
alignment = 'center',
168-
text = Zone._get_rich_text_name(zone),
169-
surface = proxy.surface,
170-
target = proxy,
171-
target_offset = {0, 0.5},
172-
use_rich_text = true,
173-
}
174-
175-
global.handled_alerts[alert_target.unit_number] = {
176-
struct_unit_number = struct.unit_number,
177-
unit_number = alert_target.unit_number,
178-
entity = alert_target,
179-
proxy = proxy,
180-
itemstack = item_to_place_this,
181-
}
182-
183-
struct.proxy = proxy -- the struct doesn't need a reference to the handled alert right?
184-
struct.updated_at = game.tick
185-
186-
global.deathrattles[script.register_on_entity_destroyed(proxy)] = alert_target.unit_number
187-
global.deathrattles[script.register_on_entity_destroyed(alert_target)] = alert_target.unit_number
188-
return
145+
if struct.entity.energy >= Handler.get_energy_per_shot() then
146+
if not struct.proxy or not struct.proxy.valid then
147+
if struct.buffer_chest.logistic_network then
148+
149+
if struct.buffer_chest.logistic_network.can_satisfy_request(item_to_place_this.name, item_to_place_this.count, true) then
150+
local proxy = struct.entity.surface.create_entity{
151+
name = 'item-request-proxy',
152+
force = struct.entity.force,
153+
target = struct.entity,
154+
position = struct.entity.position,
155+
modules = {[item_to_place_this.name] = item_to_place_this.count}
156+
}
157+
158+
rendering.draw_text{
159+
color = {1, 1, 1},
160+
alignment = 'center',
161+
text = Zone._get_rich_text_name(zone),
162+
surface = proxy.surface,
163+
target = proxy,
164+
target_offset = {0, 0.5},
165+
use_rich_text = true,
166+
}
167+
168+
global.handled_alerts[alert_target.unit_number] = {
169+
struct_unit_number = struct.unit_number,
170+
unit_number = alert_target.unit_number,
171+
entity = alert_target,
172+
proxy = proxy,
173+
itemstack = item_to_place_this,
174+
}
175+
176+
struct.proxy = proxy -- the struct doesn't need a reference to the handled alert right?
177+
struct.updated_at = game.tick
178+
179+
global.deathrattles[script.register_on_entity_destroyed(proxy)] = alert_target.unit_number
180+
global.deathrattles[script.register_on_entity_destroyed(alert_target)] = alert_target.unit_number
181+
return
182+
end
183+
end -- network
184+
185+
end
189186
end
190-
end
187+
end -- force
191188

192189
end
193190
end

0 commit comments

Comments
 (0)