Skip to content

Commit

Permalink
Cleanup draw_random_card()
Browse files Browse the repository at this point in the history
  • Loading branch information
Quezler committed Dec 8, 2023
1 parent d55cbed commit 7fac1dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "se-interstellar-construction-requests-fulfillment",
"title": "Space Exploration - interstellar construction requests fulfillment",
"description": "Keeping building equipment stocked at every planet is tedious, just shoot it there from nauvis.",
"version": "0.0.16",
"version": "0.0.17",
"author": "Quezler",
"factorio_version": "1.1",
"dependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,30 @@ function Handler.shuffle_array_in_place(t)
end

function Handler.draw_random_card()
local shuffled_without_success = false
local already_shuffled = false

while true do
if #global.deck == 0 then
if shuffled_without_success or #global.pile == 0 then return nil end
if already_shuffled or #global.pile == 0 then return nil end

Handler.shuffle_array_in_place(global.pile)
global.deck = global.pile
global.pile = {}

shuffled_without_success = true
already_shuffled = true
end

local random_unit_number = global.deck[#global.deck]
table.remove(global.deck, #global.deck)
local struct = global.structs[table.remove(global.deck)]
if struct then
if not struct.entity.valid then
global.structs[unit_number] = nil
else
table.insert(global.pile, struct.unit_number)

local struct = global.structs[random_unit_number]
if struct and struct.entity.valid then
table.insert(global.pile, struct.unit_number)
if struct.entity.energy > Handler.get_max_energy() - 1 then
return struct
if struct.entity.energy > Handler.get_max_energy() - 1 then
return struct
end

end
end
end
Expand Down

0 comments on commit 7fac1dc

Please sign in to comment.