From 98c79d31a7f570cbb5556cf86a217dbfdd0ddbb2 Mon Sep 17 00:00:00 2001 From: MewMew Date: Mon, 23 Sep 2019 13:36:34 +0200 Subject: [PATCH] added spawners; shops now spawn randomly south; --- maps/island_troopers/enemies.lua | 18 ++++++++++++++++ maps/island_troopers/main.lua | 7 ++++++- maps/island_troopers/terrain.lua | 19 ++++++++++++++--- modules/shopping_chests.lua | 36 ++++++++++++++++++++++++++------ 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/maps/island_troopers/enemies.lua b/maps/island_troopers/enemies.lua index 2244f39a..6cab18d1 100644 --- a/maps/island_troopers/enemies.lua +++ b/maps/island_troopers/enemies.lua @@ -108,6 +108,24 @@ function add_enemies(surface, tiles) end end + if global.current_level > 2 then + if math.random(1, 5) == 1 or is_boss_stage() then + local evolution = (global.current_level * 2 * difficulties_votes[global.difficulty_vote_index].strength_modifier) * 0.01 + if evolution > 1 then evolution = 1 end + game.forces.enemy.evolution_factor = evolution + local count = math.random(1, math.ceil(global.current_level * 0.05)) + if count > 3 then count = 3 end + for k, tile in pairs(tiles) do + if surface.can_place_entity({name = "biter-spawner", position = tile.position, force = "enemy"}) then + surface.create_entity({name = "biter-spawner", position = tile.position, force = "enemy"}) + global.alive_enemies = global.alive_enemies + 1 + count = count - 1 + if count == 0 then break end + end + end + end + end + if math.random(1, 4) == 1 or is_boss_stage() then set_worm_chances(global.current_level) local worm_count = math.random(1, math.ceil(global.current_level * 0.5)) diff --git a/maps/island_troopers/main.lua b/maps/island_troopers/main.lua index 5c166ef5..9f784c04 100644 --- a/maps/island_troopers/main.lua +++ b/maps/island_troopers/main.lua @@ -224,11 +224,16 @@ local function on_entity_died(event) if not entity.valid then return end if entity.force.name ~= "enemy" then return end + if entity.type == "unit" then + if entity.spawner then return end + end + global.alive_enemies = global.alive_enemies - 1 update_stage_gui() if entity.type ~= "unit" then return end if not global.alive_boss_enemy_entities[entity.unit_number] then return end + global.alive_boss_enemy_entities[entity.unit_number] = nil global.alive_boss_enemy_count = global.alive_boss_enemy_count - 1 if global.alive_boss_enemy_count == 0 then @@ -254,7 +259,7 @@ local gamestate_functions = { local function on_tick() gamestate_functions[global.gamestate]() - if game.tick % 180 == 0 then drift_corpses_toward_beach() end + if game.tick % 120 == 0 then drift_corpses_toward_beach() end end local event = require 'utils.event' diff --git a/maps/island_troopers/terrain.lua b/maps/island_troopers/terrain.lua index 6da0605a..332ef26f 100644 --- a/maps/island_troopers/terrain.lua +++ b/maps/island_troopers/terrain.lua @@ -268,18 +268,31 @@ local function process_tile(surface, position) if position.x < -128 then surface.set_tiles({{name = "out-of-map", position = position}}, true) return end if position.x > 8192 then surface.set_tiles({{name = "out-of-map", position = position}}, true) return end if position.y < 0 then surface.set_tiles({{name = "deepwater", position = position}}, true) return end - if position.y > 32 then surface.set_tiles({{name = "water-green", position = position}}, true) return end + if position.y > 32 then surface.set_tiles({{name = "water-green", position = position}}, true) + if math.random(1, 4096) == 1 then + if math.random(1, 4) == 1 then + create_dump_chest(surface, position, false) + else + create_shopping_chest(surface, position, false) + end + end + return + end if position.y > 10 + simplex_noise(position.x * 0.010, 0, game.surfaces[1].map_gen_settings.seed) * 4 then surface.set_tiles({{name = "water-green", position = position}}, true) return end local index = math.floor((simplex_noise(position.x * 0.01, position.y * 0.01, game.surfaces[1].map_gen_settings.seed) * 10) % 3) + 1 surface.set_tiles({{name = "sand-" .. index, position = position}}, true) + if position.x > 32 then return true end + if position.y == 6 then - if position.x % 60 == 30 then - create_dump_chest(surface, {x = position.x, y = position.y - 1}, false) + if position.x == -16 then create_shopping_chest(surface, position, false) end + if position.x == 16 then + create_dump_chest(surface, position, false) + end end return true diff --git a/modules/shopping_chests.lua b/modules/shopping_chests.lua index fad3ff34..4080a987 100644 --- a/modules/shopping_chests.lua +++ b/modules/shopping_chests.lua @@ -12,15 +12,15 @@ local shop_list = { } function create_shopping_chest(surface, position, destructible) - global.shopping_chests[#global.shopping_chests + 1] = surface.create_entity({name = "logistic-chest-requester", position = position, force = "shopping_chests"}) - global.shopping_chests[#global.shopping_chests].minable = false - if not destructible then global.shopping_chests[#global.shopping_chests].destructible = false end + local entity = surface.create_entity({name = "logistic-chest-requester", position = position, force = "shopping_chests"}) + entity.minable = false + if not destructible then entity.destructible = false end end function create_dump_chest(surface, position, destructible) - global.dump_chests[#global.dump_chests + 1] = surface.create_entity({name = "logistic-chest-passive-provider", position = position, force = "shopping_chests"}) - global.dump_chests[#global.dump_chests].minable = false - if not destructible then global.dump_chests[#global.dump_chests].destructible = false end + local entity = surface.create_entity({name = "logistic-chest-passive-provider", position = position, force = "shopping_chests"}) + entity.minable = false + if not destructible then entity.destructible = false end end local function get_affordable_item_count(name, count) @@ -99,6 +99,28 @@ local function gui() end end +local function on_gui_opened(event) + if not event.entity then return end + if event.entity.force.name ~= "shopping_chests" then return end + + local index = event.entity.position.x .. "_" + index = index .. event.entity.position.y + if global.registerd_shopping_chests[index] then return end + + if event.entity.name == "logistic-chest-passive-provider" then + global.dump_chests[#global.dump_chests + 1] = event.entity + global.registerd_shopping_chests[index] = true + event.entity.surface.create_entity({name = "flying-text", position = event.entity.position, text = "Chest registered, shop active!", color = {r = 200, g = 160, b = 30}}) + return + end + if event.entity.name == "logistic-chest-requester" then + global.shopping_chests[#global.shopping_chests + 1] = event.entity + global.registerd_shopping_chests[index] = true + event.entity.surface.create_entity({name = "flying-text", position = event.entity.position, text = "Chest registered, shop active!", color = {r = 200, g = 160, b = 30}}) + return + end +end + local function tick() for k, chest in pairs(global.shopping_chests) do process_shopping_chest(k, chest) @@ -112,6 +134,7 @@ end local function on_init() global.shopping_chests = {} global.dump_chests = {} + global.registerd_shopping_chests = {} global.credits = 0 game.create_force("shopping_chests") game.forces.player.set_friend("shopping_chests", true) @@ -119,5 +142,6 @@ local function on_init() end local event = require 'utils.event' +event.add(defines.events.on_gui_opened, on_gui_opened) event.on_nth_tick(120, tick) event.on_init(on_init) \ No newline at end of file