@@ -82,19 +82,16 @@ function Handler.shuffle_array_in_place(t)
82
82
end
83
83
end
84
84
85
- function Handler .draw_random_card ()
86
- local already_shuffled = false
87
-
85
+ function Handler .draw_random_card (already )
88
86
while true do
89
- log (' infinite loop 1?' )
90
87
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
92
89
93
90
Handler .shuffle_array_in_place (global .pile )
94
91
global .deck = global .pile
95
92
global .pile = {}
96
93
97
- already_shuffled = true
94
+ already . shuffled = true
98
95
end
99
96
100
97
local struct = global .structs [table.remove (global .deck )]
@@ -103,15 +100,7 @@ function Handler.draw_random_card()
103
100
global .structs [struct .unit_number ] = nil
104
101
else
105
102
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
115
104
end
116
105
end
117
106
end
@@ -147,47 +136,55 @@ function Handler.handle_construction_alert(alert_target)
147
136
for _ , item_to_place_this in ipairs (alert_target .ghost_prototype .items_to_place_this ) do
148
137
if item_to_place_this .count == 1 then -- no support for e.g. curved rails (which need 4) yet
149
138
139
+ local already = {shuffled = false }
150
140
while true do
151
- log (' infinite loop 2?' )
152
- local struct = Handler .draw_random_card ()
141
+ local struct = Handler .draw_random_card (already )
153
142
if not struct then break end
154
143
155
144
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
189
186
end
190
- end
187
+ end -- force
191
188
192
189
end
193
190
end
0 commit comments