diff --git a/maps/mountain_fortress_v2/terrain.lua b/maps/mountain_fortress_v2/terrain.lua index 55cd81c5..ac726530 100644 --- a/maps/mountain_fortress_v2/terrain.lua +++ b/maps/mountain_fortress_v2/terrain.lua @@ -66,7 +66,7 @@ local function process_rock_chunk_position(p, seed, tiles, entities, markets, tr tiles[#tiles + 1] = {name = "dirt-7", position = p} if math_random(1,3) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end - if math_random(1,8192) == 1 then + if math_random(1,16384) == 1 then wave_defense_set_worm_raffle(math.abs(p.y) * 0.5) entities[#entities + 1] = {name = wave_defense_roll_worm_name(), position = p, force = "enemy"} end @@ -214,7 +214,7 @@ local function process_chunk(surface, left_top) end if left_top.y < 0 then rock_chunk(surface, left_top) return end if left_top.y > 128 then out_of_map(surface, left_top) return end - if left_top.y > 64 then biter_chunk(surface, left_top) return end + if left_top.y > 64 or left_top.x > 480 or left_top.x < -512 then biter_chunk(surface, left_top) return end if left_top.y >= 0 then border_chunk(surface, left_top) return end end diff --git a/modules/wave_defense/biter_rolls.lua b/modules/wave_defense/biter_rolls.lua index 6142ad60..49ace90b 100644 --- a/modules/wave_defense/biter_rolls.lua +++ b/modules/wave_defense/biter_rolls.lua @@ -13,8 +13,8 @@ end function wave_defense_set_biter_raffle(level) global.wave_defense.biter_raffle = { - ["small-biter"] = 1000 - level * 2, - ["small-spitter"] = 1000 - level * 2, + ["small-biter"] = 1000 - level * 1.75, + ["small-spitter"] = 1000 - level * 1.75, ["medium-biter"] = level, ["medium-spitter"] = level, ["big-biter"] = 0, @@ -23,12 +23,14 @@ function wave_defense_set_biter_raffle(level) ["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 + global.wave_defense.biter_raffle["medium-biter"] = 500 - (level - 500) + global.wave_defense.biter_raffle["medium-spitter"] = 500 - (level - 500) + global.wave_defense.biter_raffle["big-biter"] = (level - 500) * 2 + global.wave_defense.biter_raffle["big-spitter"] = (level - 500) * 2 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 + global.wave_defense.biter_raffle["behemoth-biter"] = (level - 800) * 4 + global.wave_defense.biter_raffle["behemoth-spitter"] = (level - 800) * 4 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 @@ -50,18 +52,25 @@ end function wave_defense_set_worm_raffle(level) global.wave_defense.worm_raffle = { - ["small-worm-turret"] = 1000 - level * 2, + ["small-worm-turret"] = 1000 - level * 1.75, ["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 + global.wave_defense.worm_raffle["medium-worm-turret"] = 500 - (level - 500) + global.wave_defense.worm_raffle["big-worm-turret"] = (level - 500) * 2 end if level > 800 then - global.wave_defense.worm_raffle["behemoth-worm-turret"] = (level - 800) * 10 + global.wave_defense.worm_raffle["behemoth-worm-turret"] = (level - 800) * 4 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 + +function wave_defense_print_chances(tbl) + for k, v in pairs(tbl) do + game.print(k .. " chance = " .. v) + end end \ No newline at end of file diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 90d9d579..5d59596f 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -1,16 +1,7 @@ require "modules.wave_defense.biter_rolls" - +require "modules.wave_defense.threat_events" +local threat_values = require "modules.wave_defense.threat_values" local math_random = math.random -local threat_values = { - ["behemoth-biter"] = 10, - ["behemoth-spitter"] = 10, - ["big-biter"] = 5, - ["big-spitter"] = 5, - ["medium-biter"] = 3, - ["medium-spitter"] = 3, - ["small-biter"] = 1, - ["small-spitter"] = 1, -} local function debug_print(msg) if global.wave_defense.debug then @@ -19,10 +10,10 @@ local function debug_print(msg) 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 - if not biter.entity.unit_group then debug_print("is_unit_valid - Unit had no unitgroup") return false end - if biter.spawn_tick + global.wave_defense.max_biter_age < game.tick then debug_print("is_unit_valid - Unit timed out") return false end + if not biter.entity then debug_print("is_unit_valid - unit destroyed - does no longer exist") return false end + if not biter.entity.valid then debug_print("is_unit_valid - unit destroyed - invalid") return false end + if not biter.entity.unit_group then debug_print("is_unit_valid - unit destroyed - no unitgroup") return false end + if biter.spawn_tick + global.wave_defense.max_biter_age < game.tick then debug_print("is_unit_valid - unit destroyed - timed out") return false end return true end @@ -76,7 +67,7 @@ local function set_group_spawn_position() if not spawner then return end local position = global.wave_defense.surface.find_non_colliding_position("rocket-silo", spawner.position, 48, 1) if not position then return end - global.wave_defense.spawn_position = position + global.wave_defense.spawn_position = {x = position.x, y = position.y} end local function set_enemy_evolution() @@ -138,6 +129,7 @@ end local function spawn_attack_groups() if global.wave_defense.active_biter_count >= global.wave_defense.max_active_biters then return false end + if global.wave_defense.threat <= 0 then return false end wave_defense_set_biter_raffle(global.wave_defense.wave_number) for a = 1, global.wave_defense.max_active_unit_groups - global.wave_defense.active_unit_group_count, 1 do if not spawn_unit_group() then break end @@ -266,14 +258,6 @@ local function update_gui(player) player.gui.top.wave_defense.threat.caption = "Threat: " .. global.wave_defense.threat end -local function on_entity_died(event) - if not event.entity.valid then return end - if event.entity.type ~= "unit" then return end - if not global.wave_defense.active_biters[event.entity.unit_number] then return end - global.wave_defense.active_biters[event.entity.unit_number] = nil - global.wave_defense.active_biter_count = global.wave_defense.active_biter_count - 1 -end - local function on_tick() if global.wave_defense.game_lost then return end @@ -302,13 +286,13 @@ function reset_wave_defense() unit_group_last_command = {}, unit_group_command_delay = 3600 * 5, unit_group_command_step_length = 96, - max_active_unit_groups = 6, - max_active_biters = 1024, max_group_size = 256, + max_active_unit_groups = 6, + max_active_biters = 256 * 6, max_biter_age = 3600 * 60, active_unit_group_count = 0, active_biter_count = 0, - spawn_position = {x = 0, y = 48}, + spawn_position = {x = 0, y = 64}, last_wave = game.tick, next_wave = game.tick + 3600 * 5, wave_interval = 1800, @@ -324,5 +308,4 @@ end local event = require 'utils.event' event.on_nth_tick(30, on_tick) -event.on_init(on_init) -event.add(defines.events.on_entity_died, on_entity_died) \ No newline at end of file +event.on_init(on_init) \ No newline at end of file diff --git a/modules/wave_defense/threat_events.lua b/modules/wave_defense/threat_events.lua new file mode 100644 index 00000000..44008cb7 --- /dev/null +++ b/modules/wave_defense/threat_events.lua @@ -0,0 +1,63 @@ +local threat_values = require "modules.wave_defense.threat_values" +local math_random = math.random + +local function get_circle_vectors(radius) + local vectors = {} + for x = radius * -1, radius, 1 do + for y = radius * -1, radius, 1 do + if math.sqrt(x^2 + y^2) <= radius then + vectors[#vectors + 1] = {x, y} + end + end + end + return vectors +end + +local acid_nova_entities = { + ["small-biter"] = {projectile = "acid-stream-worm-small", vectors = get_circle_vectors(3), amount = 8, threat_cost = 32}, + ["medium-biter"] = {projectile = "acid-stream-worm-medium", vectors = get_circle_vectors(4), amount = 8, threat_cost = 64}, + ["big-biter"] = {projectile = "acid-stream-worm-big", vectors = get_circle_vectors(5), amount = 8, threat_cost = 96}, + ["behemoth-biter"] = {projectile = "acid-stream-worm-behemoth", vectors = get_circle_vectors(6), amount = 8, threat_cost = 128}, +} + +local function acid_nova(entity) + if not acid_nova_entities[entity.name] then return end + if global.wave_defense.threat < 10000 then return end + if math_random(1, 32) ~= 1 then return end + for _ = 1, acid_nova_entities[entity.name].amount, 1 do + local i = math.random(1, #acid_nova_entities[entity.name].vectors) + entity.surface.create_entity({ + name = acid_nova_entities[entity.name].projectile, + position = entity.position, + force = entity.force.name, + source = entity.position, + target = {x = entity.position.x + acid_nova_entities[entity.name].vectors[i][1], y = entity.position.y + acid_nova_entities[entity.name].vectors[i][2]}, + max_range = radius, + speed = 0.001 + }) + end + global.wave_defense.threat = global.wave_defense.threat - acid_nova_entities[entity.name].threat_cost + return true +end + +local function spawn_worm(entity) + if global.wave_defense.threat < 10000 then return end + if math_random(1, 1024) ~= 1 then return end + + +end + +local function on_entity_died(event) + if not event.entity.valid then return end + if event.entity.type ~= "unit" then return end + if not global.wave_defense.active_biters[event.entity.unit_number] then return end + global.wave_defense.active_biters[event.entity.unit_number] = nil + global.wave_defense.active_biter_count = global.wave_defense.active_biter_count - 1 + + if acid_nova(event.entity) then return end + if acid_nova(event.entity) then return end + if acid_nova(event.entity) then return end +end + +local event = require 'utils.event' +event.add(defines.events.on_entity_died, on_entity_died) \ No newline at end of file diff --git a/modules/wave_defense/threat_values.lua b/modules/wave_defense/threat_values.lua new file mode 100644 index 00000000..9a49abef --- /dev/null +++ b/modules/wave_defense/threat_values.lua @@ -0,0 +1,14 @@ +return { + ["behemoth-biter"] = 24, + ["behemoth-spitter"] = 24, + ["big-biter"] = 8, + ["big-spitter"] = 8, + ["medium-biter"] = 4, + ["medium-spitter"] = 4, + ["small-biter"] = 1, + ["small-spitter"] = 1, + ["small-worm-turret"] = 16, + ["medium-worm-turret"] = 24, + ["big-worm-turret"] = 32, + ["behemoth-worm-turret"] = 48, +} \ No newline at end of file diff --git a/tools/base_market_items.lua b/tools/base_market_items.lua deleted file mode 100644 index 3122257d..00000000 --- a/tools/base_market_items.lua +++ /dev/null @@ -1,8 +0,0 @@ -local price_list = { - ["grenade"] = 10, - -} - -local rarity_list = { - ["grenade"] = 2, -} \ No newline at end of file