diff --git a/functions/basic_markets.lua b/functions/basic_markets.lua index ba7ce0d6..7b3a5e27 100644 --- a/functions/basic_markets.lua +++ b/functions/basic_markets.lua @@ -179,9 +179,8 @@ function random_type_market(surface, position, rarity) if #items > 0 then table.shuffle_table(items) end local market = surface.create_entity({name = "market", position = position}) for i = 1, math.random(4, 10), 1 do - if items[i] then - market.add_market_item(items[i]) - end + if not items[i] then break end + market.add_market_item(items[i]) end return market end diff --git a/modules/wave_defense/biter_rolls.lua b/modules/wave_defense/biter_rolls.lua new file mode 100644 index 00000000..6142ad60 --- /dev/null +++ b/modules/wave_defense/biter_rolls.lua @@ -0,0 +1,67 @@ +function wave_defense_roll_biter_name() + local max_chance = 0 + for k, v in pairs(global.wave_defense.biter_raffle) do + max_chance = max_chance + v + end + local r = math.random(1, max_chance) + local current_chance = 0 + for k, v in pairs(global.wave_defense.biter_raffle) do + current_chance = current_chance + v + if r <= current_chance then return k end + end +end + +function wave_defense_set_biter_raffle(level) + global.wave_defense.biter_raffle = { + ["small-biter"] = 1000 - level * 2, + ["small-spitter"] = 1000 - level * 2, + ["medium-biter"] = level, + ["medium-spitter"] = level, + ["big-biter"] = 0, + ["big-spitter"] = 0, + ["behemoth-biter"] = 0, + ["behemoth-spitter"] = 0, + } + if level > 500 then + global.wave_defense.biter_raffle["big-biter"] = (level - 500) * 5 + global.wave_defense.biter_raffle["big-spitter"] = (level - 500) * 5 + end + if level > 800 then + global.wave_defense.biter_raffle["behemoth-biter"] = (level - 800) * 10 + global.wave_defense.biter_raffle["behemoth-spitter"] = (level - 800) * 10 + end + for k, v in pairs(global.wave_defense.biter_raffle) do + if global.wave_defense.biter_raffle[k] < 0 then global.wave_defense.biter_raffle[k] = 0 end + end +end + +function wave_defense_roll_worm_name() + local max_chance = 0 + for k, v in pairs(global.wave_defense.worm_raffle) do + max_chance = max_chance + v + end + local r = math.random(1, max_chance) + local current_chance = 0 + for k, v in pairs(global.wave_defense.worm_raffle) do + current_chance = current_chance + v + if r <= current_chance then return k end + end +end + +function wave_defense_set_worm_raffle(level) + global.wave_defense.worm_raffle = { + ["small-worm-turret"] = 1000 - level * 2, + ["medium-worm-turret"] = level, + ["big-worm-turret"] = 0, + ["behemoth-worm-turret"] = 0, + } + if level > 500 then + global.wave_defense.worm_raffle["big-worm-turret"] = (level - 500) * 5 + end + if level > 800 then + global.wave_defense.worm_raffle["behemoth-worm-turret"] = (level - 800) * 10 + end + for k, v in pairs(global.wave_defense.worm_raffle) do + if global.wave_defense.worm_raffle[k] < 0 then global.wave_defense.worm_raffle[k] = 0 end + end +end \ No newline at end of file diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 6527c716..90d9d579 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -1,3 +1,5 @@ +require "modules.wave_defense.biter_rolls" + local math_random = math.random local threat_values = { ["behemoth-biter"] = 10, @@ -16,43 +18,6 @@ local function debug_print(msg) end end -function wave_defense_roll_biter_name() - local max_chance = 0 - for k, v in pairs(global.wave_defense.biter_raffle) do - max_chance = max_chance + v - end - local r = math.random(1, max_chance) - local current_chance = 0 - for k, v in pairs(global.wave_defense.biter_raffle) do - current_chance = current_chance + v - if r <= current_chance then return k end - end -end - -function wave_defense_set_biter_raffle(level) - global.wave_defense.biter_raffle = { - ["small-biter"] = 1000 - level * 2, - ["small-spitter"] = 1000 - level * 2, - ["medium-biter"] = level, - ["medium-spitter"] = level, - ["big-biter"] = 0, - ["big-spitter"] = 0, - ["behemoth-biter"] = 0, - ["behemoth-spitter"] = 0, - } - if level > 500 then - global.wave_defense.biter_raffle["big-biter"] = (level - 500) * 5 - global.wave_defense.biter_raffle["big-spitter"] = (level - 500) * 5 - end - if level > 800 then - global.wave_defense.biter_raffle["behemoth-biter"] = (level - 800) * 10 - global.wave_defense.biter_raffle["behemoth-spitter"] = (level - 800) * 10 - end - for k, v in pairs(global.wave_defense.biter_raffle) do - if global.wave_defense.biter_raffle[k] < 0 then global.wave_defense.biter_raffle[k] = 0 end - end -end - local function is_unit_valid(biter) if not biter.entity then debug_print("is_unit_valid - Unit did no longer exist") return false end if not biter.entity.valid then debug_print("is_unit_valid - Unit invalid") return false end @@ -336,7 +301,7 @@ function reset_wave_defense() unit_groups = {}, unit_group_last_command = {}, unit_group_command_delay = 3600 * 5, - unit_group_command_step_length = 64, + unit_group_command_step_length = 96, max_active_unit_groups = 6, max_active_biters = 1024, max_group_size = 256,