From 2e93b031deb028717f41a7d3ab42d0f8def6fee4 Mon Sep 17 00:00:00 2001 From: MewMew Date: Fri, 27 Mar 2020 14:07:56 +0100 Subject: [PATCH] oil kill fix --- maps/railway_troopers/main.lua | 19 ++++++++++++------- modules/dynamic_player_spawn.lua | 2 +- modules/sticky_landfill.lua | 14 +++++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/maps/railway_troopers/main.lua b/maps/railway_troopers/main.lua index 2b3cdcd3..51528533 100644 --- a/maps/railway_troopers/main.lua +++ b/maps/railway_troopers/main.lua @@ -1,3 +1,6 @@ +require "modules.sticky_landfill" +require "modules.dynamic_player_spawn" + local math_random = math.random local math_floor = math.floor local table_insert = table.insert @@ -80,6 +83,8 @@ local function set_commands(unit_group) end end + if #commands == 0 then return end + unit_group.set_command({ type = defines.command.compound, structure_type = defines.compound_command.return_last, @@ -172,12 +177,12 @@ local function draw_east_side(surface, left_top) end if left_top.x == -32 then local entity = surface.create_entity({name = "cargo-wagon", position = {-24, 0}, force = "player", direction = 2}) - entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "firearm-magazine", count = 128}) - entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "shotgun", count = 1}) - entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "shotgun-shell", count = 16}) - entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "light-armor", count = 2}) - entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "grenade", count = 3}) - entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "pistol", count = 5}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "firearm-magazine", count = 600}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "shotgun", count = 2}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "shotgun-shell", count = 64}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "light-armor", count = 5}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "grenade", count = 32}) + entity.get_inventory(defines.inventory.cargo_wagon).insert({name = "pistol", count = 10}) end end @@ -356,7 +361,7 @@ local function on_init() local force = game.forces.player - force.set_spawn_position({0, 0}, surface) + force.set_spawn_position({-30, 0}, surface) force.technologies["landfill"].researched = true force.technologies["railway"].researched = true diff --git a/modules/dynamic_player_spawn.lua b/modules/dynamic_player_spawn.lua index 72c829a5..cc62fd70 100644 --- a/modules/dynamic_player_spawn.lua +++ b/modules/dynamic_player_spawn.lua @@ -2,7 +2,7 @@ local event = require 'utils.event' -local valid_types = {"boiler", "container", "furnace", "generator", "logistic-container", "offshore-pump", "lab", "assembling-machine"} +local valid_types = {"boiler", "furnace", "generator", "offshore-pump", "lab", "assembling-machine"} local function on_built_entity(event) if not event.created_entity.valid then return end diff --git a/modules/sticky_landfill.lua b/modules/sticky_landfill.lua index aa521764..4c570390 100644 --- a/modules/sticky_landfill.lua +++ b/modules/sticky_landfill.lua @@ -38,16 +38,28 @@ end local function sticky(surface, tiles, tile_name) local revert_tiles = {} + local revert_entities = {} local i = 1 + local i2 = 1 for _, placed_tile in pairs(tiles) do revert_tiles[i] = {name = placed_tile.old_tile.name, position = placed_tile.position} + local resources = surface.find_entities_filtered({type = "resource", area = {{placed_tile.position.x - 1, placed_tile.position.y - 1}, {placed_tile.position.x + 1, placed_tile.position.y + 1}}}) + for _, resource in pairs(resources) do + revert_entities[i2] = {name = resource.name, position = resource.position, amount = resource.amount} + resource.destroy() + i2 = i2 + 1 + end i = i + 1 end surface.set_tiles(revert_tiles, true) for _, placed_tile in pairs(tiles) do move_tile(surface, tile_name, placed_tile.position) - end + end + + for _, entity in pairs(revert_entities) do + surface.create_entity(entity) + end end local function on_player_built_tile(event)