Skip to content

Commit

Permalink
Add rocket, inventory & quality utils (#1482)
Browse files Browse the repository at this point in the history
* Add rocket, inventory & quality utils
  • Loading branch information
RedRafe authored Jan 3, 2025
1 parent ed84ed8 commit 1b75ab4
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 158 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ stds.factorio_defines = {
'on_force_created',
'on_forces_merged',
'on_forces_merging',
'on_force_reset',
'on_game_created_from_scenario',
'on_gui_checked_state_changed',
'on_gui_click',
Expand Down
20 changes: 2 additions & 18 deletions features/player_stats.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Global = require 'utils.global'
local Event = require 'utils.event'
local Rocket = require 'utils.rocket'
local SA = require 'utils.space_age'
local ScoreTracker = require 'utils.score_tracker'
require 'utils.table'
Expand Down Expand Up @@ -308,24 +309,7 @@ local function rocket_launched(event)

change_for_global(rockets_launched_name, 1)

local pod = entity.cargo_pod
if not pod or not pod.valid then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

Expand Down
26 changes: 3 additions & 23 deletions map_gen/maps/april_fools/scenario/rocket_launched.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Rocket = require 'utils.rocket'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.april_fools.scenario.shared_globals'

Expand Down Expand Up @@ -55,32 +56,11 @@ local function rocket_launched(event)
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
if satellite_count == 0 then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

local satellite_count = Rocket.get_item_launched({ name = 'satellite' })
if satellite_count == win_satellite_count then
disable_biters()
win()
Expand Down
24 changes: 4 additions & 20 deletions map_gen/maps/april_fools/scenario/rocket_waves.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local Task = require 'utils.task'
local Token = require 'utils.token'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.april_fools.scenario.shared_globals'
local Rocket = require 'utils.rocket'

ShareGlobals.data.map_won = false

Expand Down Expand Up @@ -134,7 +135,7 @@ local function start_waves(event)

Task.set_timeout_in_ticks(1, do_waves, data)

game.print('Warning incomming biter attack! Number of waves: ' .. number_of_waves)
game.print('Warning incoming biter attack! Number of waves: ' .. number_of_waves)
end

local function rocket_launched(event)
Expand All @@ -144,28 +145,11 @@ local function rocket_launched(event)
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
local satellite_count = Rocket.get_item_launched({ name = 'satellite' })
if satellite_count == 0 then
return
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Rocket = require 'utils.rocket'
local RS = require 'map_gen.shared.redmew_surface'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
Expand Down Expand Up @@ -36,28 +37,11 @@ return function()
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
local satellite_count = Rocket.get_item_launched({ name = 'satellite' })
if satellite_count == 0 then
return
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Event = require 'utils.event'
local RS = require 'map_gen.shared.redmew_surface'
local Rocket = require 'utils.rocket'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'

Expand Down Expand Up @@ -36,28 +37,11 @@ return function()
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
local satellite_count = Rocket.get_item_launched({ name = 'satellite' })
if satellite_count == 0 then
return
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Rocket = require 'utils.rocket'
local RS = require 'map_gen.shared.redmew_surface'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
Expand Down Expand Up @@ -36,28 +37,11 @@ return function()
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
local satellite_count = Rocket.get_item_launched({ name = 'satellite' })
if satellite_count == 0 then
return
end
Expand Down
1 change: 1 addition & 0 deletions map_gen/maps/danger_ores/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ return {
rocket_launched = {
enabled = true,
win_satellite_count = 1000,
win_satellite_quality = 'normal',
},
terraforming = {
enabled = true,
Expand Down
32 changes: 11 additions & 21 deletions map_gen/maps/danger_ores/modules/rocket_launched.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local Generate = require 'map_gen.shared.generate'
local Global = require 'utils.global'
local Queue = require 'utils.queue'
local AlienEvolutionProgress = require 'utils.alien_evolution_progress'
local Rocket = require 'utils.rocket'
local RS = require 'map_gen.shared.redmew_surface'
local Task = require 'utils.task'
local Token = require 'utils.token'
Expand All @@ -18,7 +19,8 @@ return function(config)

local win_data = {
evolution_rocket_maxed = -1,
extra_rockets = config.extra_rockets or 100
extra_rockets = config.extra_rockets or 100,
extra_rockets_quality = config.extra_rockets_quality or 'normal'
}

ShareGlobals.data.biters_disabled = false
Expand Down Expand Up @@ -152,7 +154,7 @@ return function(config)

Task.set_timeout_in_ticks(1, do_waves, data)

game.print('Warning incomming biter attack! Number of waves: ' .. number_of_waves)
game.print('Warning incoming biter attack! Number of waves: ' .. number_of_waves)
end

local function rocket_launched(event)
Expand All @@ -162,28 +164,16 @@ return function(config)
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite' }) then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
local satellite_count = Rocket.get_item_launched({
name = 'satellite',
force = 'player',
quality = win_data.extra_rockets_quality,
comparator = '>='
})
if satellite_count == 0 then
return
end
Expand Down
27 changes: 8 additions & 19 deletions map_gen/maps/danger_ores/modules/rocket_launched_simple.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Rocket = require 'utils.rocket'
local RS = require 'map_gen.shared.redmew_surface'
local Server = require 'features.server'
local ShareGlobals = require 'map_gen.maps.danger_ores.modules.shared_globals'
Expand Down Expand Up @@ -62,28 +63,16 @@ return function(config)
return
end

local pod = entity.cargo_pod
if not pod or not pod.valid then
if 0 == Rocket.count_rocket_contents(entity.cargo_pod, { name = 'satellite', quality = config.win_satellite_quality, comparator = '>=' }) then
return
end

local count = 0
local qualities = prototypes.quality
for k = 1, pod.get_max_inventory_index() do
local inventory = pod.get_inventory(k)
if inventory then
local add = inventory.get_item_count
for tier, _ in pairs(qualities) do
count = count + add({ name = 'satellite', quality = tier })
end
end
end

if count == 0 then
return
end

local satellite_count = game.forces.player.get_item_launched('satellite')
local satellite_count = Rocket.get_item_launched({
name = 'satellite',
force = 'player',
quality = config.win_satellite_quality,
comparator = '>=',
})
if satellite_count == 0 then
return
end
Expand Down
Loading

0 comments on commit 1b75ab4

Please sign in to comment.