From a8538ebd67b070df0e572a1cf45f3027156654e1 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sun, 28 Jan 2024 20:42:28 +0100 Subject: [PATCH] Move folders to utils --- control.lua | 16 +- maps/anarchy.lua | 2 +- .../biter_battles_terrain_neko.lua | 7 +- maps/biter_battles_v2/terrain.lua | 8 +- maps/cave_choppy/forest_world.lua | 10 +- maps/cave_miner_v2/functions.lua | 4 +- maps/cave_miner_v2/market.lua | 2 +- maps/choppy.lua | 26 +- maps/choppy_dx.lua | 12 +- maps/chronosphere/event_functions.lua | 16 +- maps/chronosphere/main.lua | 11 +- maps/crab_defender/main.lua | 2 +- maps/crab_defender/terrain.lua | 2 +- maps/cratewood_forest.lua | 2 +- maps/crossing.lua | 2 +- maps/deep_jungle/main.lua | 2 +- maps/dungeons/biome_acid_zone.lua | 2 +- maps/dungeons/biome_concrete.lua | 2 +- maps/dungeons/functions.lua | 90 +- maps/dungeons/main.lua | 4 +- maps/dungeons/tiered_dungeon.lua | 84 +- maps/expanse/functions.lua | 24 +- maps/fish_defender/main.lua | 2 +- maps/fish_defender/terrain.lua | 2 +- maps/fish_defender_v1/fish_defender.lua | 4 +- maps/fish_defender_v2/main.lua | 2 +- maps/fish_defender_v2/terrain.lua | 2 +- maps/hedge_maze.lua | 31 +- maps/island_troopers/main.lua | 4 +- maps/journey/functions.lua | 2650 +++++++------- maps/journey/unique_modifiers.lua | 440 ++- maps/junkyard.lua | 1006 +++--- maps/junkyard_pvp/main.lua | 2 +- maps/junkyard_pvp/terrain.lua | 8 +- maps/labyrinth.lua | 14 +- maps/lost_desert.lua | 2 +- maps/maze_challenge.lua | 2 +- maps/minesweeper/functions.lua | 2 +- maps/mountain_fortress.lua | 2 +- maps/mountain_fortress_v2/main.lua | 6 +- maps/mountain_fortress_v2/terrain.lua | 2 +- maps/mountain_fortress_v2/treasure.lua | 2 +- .../locomotive/spawn_locomotive.lua | 2 +- maps/mountain_fortress_v3/loot.lua | 2 +- maps/mountain_race/terrain.lua | 2 +- maps/native_war/main.lua | 2 +- maps/native_war/terrain.lua | 21 +- maps/nightfall.lua | 17 +- maps/overgrowth.lua | 6 +- maps/pidgeotto/main.lua | 2 +- maps/pidgeotto/terrain.lua | 2 +- maps/pirates/common.lua | 3092 +++++++++-------- maps/planet_prison.lua | 2 +- maps/railway_troopers_v2/main.lua | 2 +- maps/rainbow_road.lua | 4 +- maps/rivers.lua | 2 +- maps/rocky_waste.lua | 4 +- maps/scrap_railworld.lua | 2 +- maps/scrap_towny_ffa/nauvis.lua | 2 +- maps/scrap_towny_ffa/trap.lua | 6 +- maps/spiral_troopers.lua | 5 +- maps/spooky_forest.lua | 4 +- maps/stone_maze/1x1_rooms.lua | 2 +- maps/stone_maze/2x2_rooms.lua | 2 +- maps/stone_maze/main.lua | 7 +- maps/stoneblock.lua | 2 +- maps/tank_battles_old.lua | 2 +- maps/tank_conquest/tank_conquest.lua | 70 +- maps/territorial_control.lua | 10 +- maps/tetris/main.lua | 16 +- modules/dangerous_nights.lua | 8 +- modules/towny/main.lua | 2 +- utils/antigrief.lua | 2 +- .../functions}/basic_markets.lua | 0 .../functions}/biter_raffle.lua | 0 {functions => utils/functions}/boss_unit.lua | 0 .../functions}/connect_belts.lua | 0 .../functions}/create_entity_chain.lua | 0 .../functions}/create_tile_chain.lua | 0 .../functions}/loot_raffle.lua | 0 {functions => utils/functions}/maze.lua | 0 .../functions}/noise_vector_path.lua | 0 .../functions}/omegakaboom.lua | 0 .../functions}/room_generator.lua | 0 {functions => utils/functions}/soft_reset.lua | 0 .../functions}/tick_tack_trap.lua | 0 .../functions}/unearthing_biters.lua | 0 .../functions}/unearthing_worm.lua | 0 utils/gui/admin.lua | 1 + .../biters_and_resources_east.lua | 0 .../terrain_layouts}/caves.lua | 0 .../terrain_layouts}/cone_to_east.lua | 0 .../terrain_layouts}/scrap_01.lua | 0 .../terrain_layouts}/scrap_02.lua | 0 .../terrain_layouts}/tree_01.lua | 2 +- .../terrain_layouts}/watery_world.lua | 0 .../terrain_layouts}/winter.lua | 0 {tools => utils/tools}/cheat_mode.lua | 0 {tools => utils/tools}/fancy_time.lua | 0 {tools => utils/tools}/map_functions.lua | 0 {tools => utils/tools}/map_intro.lua | 0 {tools => utils/tools}/map_pregen.lua | 0 {tools => utils/tools}/rainbow_colors.lua | 0 {tools => utils/tools}/scrap.lua | 0 {tools => utils/tools}/shapes.lua | 0 105 files changed, 4052 insertions(+), 3770 deletions(-) rename {functions => utils/functions}/basic_markets.lua (100%) rename {functions => utils/functions}/biter_raffle.lua (100%) rename {functions => utils/functions}/boss_unit.lua (100%) rename {functions => utils/functions}/connect_belts.lua (100%) rename {functions => utils/functions}/create_entity_chain.lua (100%) rename {functions => utils/functions}/create_tile_chain.lua (100%) rename {functions => utils/functions}/loot_raffle.lua (100%) rename {functions => utils/functions}/maze.lua (100%) rename {functions => utils/functions}/noise_vector_path.lua (100%) rename {functions => utils/functions}/omegakaboom.lua (100%) rename {functions => utils/functions}/room_generator.lua (100%) rename {functions => utils/functions}/soft_reset.lua (100%) rename {functions => utils/functions}/tick_tack_trap.lua (100%) rename {functions => utils/functions}/unearthing_biters.lua (100%) rename {functions => utils/functions}/unearthing_worm.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/biters_and_resources_east.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/caves.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/cone_to_east.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/scrap_01.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/scrap_02.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/tree_01.lua (97%) rename {terrain_layouts => utils/terrain_layouts}/watery_world.lua (100%) rename {terrain_layouts => utils/terrain_layouts}/winter.lua (100%) rename {tools => utils/tools}/cheat_mode.lua (100%) rename {tools => utils/tools}/fancy_time.lua (100%) rename {tools => utils/tools}/map_functions.lua (100%) rename {tools => utils/tools}/map_intro.lua (100%) rename {tools => utils/tools}/map_pregen.lua (100%) rename {tools => utils/tools}/rainbow_colors.lua (100%) rename {tools => utils/tools}/scrap.lua (100%) rename {tools => utils/tools}/shapes.lua (100%) diff --git a/control.lua b/control.lua index 694ea364..67c680cc 100644 --- a/control.lua +++ b/control.lua @@ -251,14 +251,14 @@ require 'utils.remote_chunks' --------------------------------------------------------------- ---------------- MOSTLY TERRAIN LAYOUTS HERE ---------------- ---require 'terrain_layouts.winter' ---require 'terrain_layouts.caves' ---require 'terrain_layouts.cone_to_east' ---require 'terrain_layouts.biters_and_resources_east' ---require 'terrain_layouts.scrap_01' ---require 'terrain_layouts.scrap_02' ---require 'terrain_layouts.watery_world' ---require 'terrain_layouts.tree_01' +--require 'utils.terrain_layouts.winter' +--require 'utils.terrain_layouts.caves' +--require 'utils.terrain_layouts.cone_to_east' +--require 'utils.terrain_layouts.biters_and_resources_east' +--require 'utils.terrain_layouts.scrap_01' +--require 'utils.terrain_layouts.scrap_02' +--require 'utils.terrain_layouts.watery_world' +--require 'utils.terrain_layouts.tree_01' --------------------------------------------------------------- --- this file exists only for the panel to sync and start from within the panel diff --git a/maps/anarchy.lua b/maps/anarchy.lua index cd709008..a135e244 100644 --- a/maps/anarchy.lua +++ b/maps/anarchy.lua @@ -6,7 +6,7 @@ require 'modules.dynamic_player_spawn' local Event = require 'utils.event' local math_random = math.random -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local function on_player_joined_game(event) local player = game.players[event.player_index] diff --git a/maps/biter_battles/biter_battles_terrain_neko.lua b/maps/biter_battles/biter_battles_terrain_neko.lua index fb4a2f9a..71b99ec0 100644 --- a/maps/biter_battles/biter_battles_terrain_neko.lua +++ b/maps/biter_battles/biter_battles_terrain_neko.lua @@ -1,5 +1,5 @@ --luacheck:ignore -local simplex_noise = require 'tools.simplex_noise' +local simplex_noise = require 'utils.tools.simplex_noise' local Event = require 'utils.event' biter_battles_terrain = {} @@ -471,10 +471,7 @@ function biter_battles_terrain.generate_spawn_ores(ore_layout) end end surface.set_tiles(tiles, true) - local entities = - surface.find_entities( - {{(rocket_silo.position.x - 4) - size / 2, (rocket_silo.position.y - 5) - size / 2}, {rocket_silo.position.x + 4 + size / 2, rocket_silo.position.y + 5 + size / 2}} - ) + local entities = surface.find_entities({{(rocket_silo.position.x - 4) - size / 2, (rocket_silo.position.y - 5) - size / 2}, {rocket_silo.position.x + 4 + size / 2, rocket_silo.position.y + 5 + size / 2}}) for _, entity in pairs(entities) do if entity.type == 'simple-entity' or entity.type == 'tree' or entity.type == 'resource' then entity.destroy() diff --git a/maps/biter_battles_v2/terrain.lua b/maps/biter_battles_v2/terrain.lua index edf01471..b6960a30 100644 --- a/maps/biter_battles_v2/terrain.lua +++ b/maps/biter_battles_v2/terrain.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Public = {} -local LootRaffle = require 'functions.loot_raffle' -local BiterRaffle = require 'functions.biter_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' local bb_config = require 'maps.biter_battles_v2.config' local table_insert = table.insert @@ -646,9 +646,7 @@ function Public.generate_silo(surface) for _, t in pairs(surface.find_tiles_filtered({area = {{pos.x - 6, pos.y - 6}, {pos.x + 6, pos.y + 6}}, name = {'water', 'deepwater'}})) do surface.set_tiles({{name = get_replacement_tile(surface, t.position), position = t.position}}) end - for _, t in pairs( - surface.find_tiles_filtered({area = {{mirror_position.x - 6, mirror_position.y - 6}, {mirror_position.x + 6, mirror_position.y + 6}}, name = {'water', 'deepwater'}}) - ) do + for _, t in pairs(surface.find_tiles_filtered({area = {{mirror_position.x - 6, mirror_position.y - 6}, {mirror_position.x + 6, mirror_position.y + 6}}, name = {'water', 'deepwater'}})) do surface.set_tiles({{name = get_replacement_tile(surface, t.position), position = t.position}}) end diff --git a/maps/cave_choppy/forest_world.lua b/maps/cave_choppy/forest_world.lua index c4506719..c6383729 100644 --- a/maps/cave_choppy/forest_world.lua +++ b/maps/cave_choppy/forest_world.lua @@ -4,12 +4,12 @@ require 'modules.dynamic_landfill' require 'modules.satellite_score' require 'modules.spawners_contain_biters' -require 'functions.create_entity_chain' -require 'functions.create_tile_chain' +require 'utils.functions.create_entity_chain' +require 'utils.functions.create_tile_chain' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' -local tick_tack_trap = require 'functions.tick_tack_trap' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' local Module = require 'infinity_chest' local Simplex = require 'utils.simplex_noise'.d2 local Event = require 'utils.event' diff --git a/maps/cave_miner_v2/functions.lua b/maps/cave_miner_v2/functions.lua index b4f28319..e3c15b0f 100644 --- a/maps/cave_miner_v2/functions.lua +++ b/maps/cave_miner_v2/functions.lua @@ -3,8 +3,8 @@ local Public = {} local GetNoise = require 'utils.get_noise' local Constants = require 'maps.cave_miner_v2.constants' -local BiterRaffle = require 'functions.biter_raffle' -local LootRaffle = require 'functions.loot_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local Esq = require 'modules.entity_spawn_queue' local Pets = require 'modules.biter_pets' diff --git a/maps/cave_miner_v2/market.lua b/maps/cave_miner_v2/market.lua index fa34d921..031b4ce6 100644 --- a/maps/cave_miner_v2/market.lua +++ b/maps/cave_miner_v2/market.lua @@ -3,7 +3,7 @@ local Public = {} local Constants = require 'maps.cave_miner_v2.constants' local Functions = require 'maps.cave_miner_v2.functions' -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local math_floor = math.floor local math_random = math.random diff --git a/maps/choppy.lua b/maps/choppy.lua index 09e6966e..ffbdc59a 100644 --- a/maps/choppy.lua +++ b/maps/choppy.lua @@ -5,17 +5,17 @@ require 'modules.dynamic_landfill' require 'modules.satellite_score' require 'modules.spawners_contain_biters' local Map = require 'modules.map_info' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' -local tick_tack_trap = require 'functions.tick_tack_trap' -local create_entity_chain = require 'functions.create_entity_chain' -local create_tile_chain = require 'functions.create_tile_chain' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' +local create_entity_chain = require 'utils.functions.create_entity_chain' +local create_tile_chain = require 'utils.functions.create_tile_chain' local simplex_noise = require 'utils.simplex_noise'.d2 local event = require 'utils.event' local table_insert = table.insert local math_random = math.random -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local disabled_for_deconstruction = { ['fish'] = true, @@ -164,9 +164,7 @@ local function process_tile(surface, pos, tile, seed) surface.create_entity({name = 'tree-01', position = pos}) end end - surface.create_decoratives( - {check_collision = false, decoratives = {{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}} - ) + surface.create_decoratives({check_collision = false, decoratives = {{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}}) return end @@ -180,9 +178,7 @@ local function process_tile(surface, pos, tile, seed) surface.create_entity({name = 'tree-02-red', position = pos}) end end - surface.create_decoratives( - {check_collision = false, decoratives = {{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}} - ) + surface.create_decoratives({check_collision = false, decoratives = {{name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2)}}}) return end @@ -387,11 +383,7 @@ local function on_entity_died(event) return end if event.entity.type == 'tree' then - for _, entity in pairs( - event.entity.surface.find_entities_filtered( - {area = {{event.entity.position.x - 4, event.entity.position.y - 4}, {event.entity.position.x + 4, event.entity.position.y + 4}}, name = 'fire-flame-on-tree'} - ) - ) do + for _, entity in pairs(event.entity.surface.find_entities_filtered({area = {{event.entity.position.x - 4, event.entity.position.y - 4}, {event.entity.position.x + 4, event.entity.position.y + 4}}, name = 'fire-flame-on-tree'})) do if entity.valid then entity.destroy() end diff --git a/maps/choppy_dx.lua b/maps/choppy_dx.lua index 193e8e62..0bbb0385 100644 --- a/maps/choppy_dx.lua +++ b/maps/choppy_dx.lua @@ -4,17 +4,17 @@ require 'modules.satellite_score' require 'modules.spawners_contain_biters' -require 'functions.create_entity_chain' -require 'functions.create_tile_chain' -require 'tools.map_functions' +require 'utils.functions.create_entity_chain' +require 'utils.functions.create_tile_chain' +require 'utils.tools.map_functions' require 'modules.surrounded_by_worms' require 'modules.biter_noms_you' local Map = require 'modules.map_info' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' -local tick_tack_trap = require 'functions.tick_tack_trap' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' local simplex_noise = require 'utils.simplex_noise'.d2 local Event = require 'utils.event' diff --git a/maps/chronosphere/event_functions.lua b/maps/chronosphere/event_functions.lua index af50355b..025cf960 100644 --- a/maps/chronosphere/event_functions.lua +++ b/maps/chronosphere/event_functions.lua @@ -5,9 +5,9 @@ local Chrono = require 'maps.chronosphere.chrono' local Upgrades = require 'maps.chronosphere.upgrades' local Public = {} -local tick_tack_trap = require 'functions.tick_tack_trap' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' local math_random = math.random local math_floor = math.floor @@ -162,10 +162,7 @@ function Public.shred_simple_entities(entity) if game.forces.enemy.evolution_factor < 0.25 then return end - local simple_entities = - entity.surface.find_entities_filtered( - {type = {'simple-entity', 'tree'}, area = {{entity.position.x - 3, entity.position.y - 3}, {entity.position.x + 3, entity.position.y + 3}}} - ) + local simple_entities = entity.surface.find_entities_filtered({type = {'simple-entity', 'tree'}, area = {{entity.position.x - 3, entity.position.y - 3}, {entity.position.x + 3, entity.position.y + 3}}}) for _, simple_entity in pairs(simple_entities) do if simple_entity.valid then simple_entity.destroy() @@ -447,10 +444,7 @@ end function Public.check_if_overstayed() local objective = Chrono_table.get_table() - if - objective.passivetimer * objective.passive_chronocharge_rate > (objective.chronochargesneeded * 0.75) and - objective.chronojumps >= Balance.jumps_until_overstay_is_on(Difficulty.get().difficulty_vote_value) - then + if objective.passivetimer * objective.passive_chronocharge_rate > (objective.chronochargesneeded * 0.75) and objective.chronojumps >= Balance.jumps_until_overstay_is_on(Difficulty.get().difficulty_vote_value) then objective.overstaycount = objective.overstaycount + 1 end end diff --git a/maps/chronosphere/main.lua b/maps/chronosphere/main.lua index bd5092a7..8a8cdcdb 100644 --- a/maps/chronosphere/main.lua +++ b/maps/chronosphere/main.lua @@ -19,7 +19,7 @@ local Locomotive = require 'maps.chronosphere.locomotive' local Map = require 'modules.map_info' local Minimap = require 'maps.chronosphere.minimap' local On_Event = require 'maps.chronosphere.on_event' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Tick_functions = require 'maps.chronosphere.tick_functions' local Upgrades = require 'maps.chronosphere.upgrades' local Worlds = require 'maps.chronosphere.world_list' @@ -92,12 +92,7 @@ local function chronojump(choice) end if objective.chronojumps <= 24 then - Locomotive.award_coins( - Balance.coin_reward_per_second_jumped_early( - objective.chronochargesneeded / objective.passive_chronocharge_rate + 180 - objective.passivetimer, - Difficulty.get().difficulty_vote_value - ) - ) + Locomotive.award_coins(Balance.coin_reward_per_second_jumped_early(objective.chronochargesneeded / objective.passive_chronocharge_rate + 180 - objective.passivetimer, Difficulty.get().difficulty_vote_value)) end Chrono.process_jump() @@ -180,7 +175,7 @@ local function do_tick() local objective = Chrono_table.get_table() local tick = game.tick Ai.Tick_actions(tick) - if objective.passivetimer < 160 then + if objective.passivetimer < 160 then Tick_functions.request_chunks() end if tick % 30 == 20 then diff --git a/maps/crab_defender/main.lua b/maps/crab_defender/main.lua index 1bf5da96..b2943425 100644 --- a/maps/crab_defender/main.lua +++ b/maps/crab_defender/main.lua @@ -14,7 +14,7 @@ local Session = require 'utils.datastore.session_data' local Difficulty = require 'modules.difficulty_vote' local Map = require 'modules.map_info' local Event = require 'utils.event' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Server = require 'utils.server' local Poll = require 'utils.gui.poll' local boss_biter = require 'maps.crab_defender.boss_biters' diff --git a/maps/crab_defender/terrain.lua b/maps/crab_defender/terrain.lua index 2ca82601..03f81992 100644 --- a/maps/crab_defender/terrain.lua +++ b/maps/crab_defender/terrain.lua @@ -1,6 +1,6 @@ local Event = require 'utils.event' local Builder = require 'maps.crab_defender.b' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local FDT = require 'maps.crab_defender.table' local math_random = math.random diff --git a/maps/cratewood_forest.lua b/maps/cratewood_forest.lua index 968c118e..59f14eae 100644 --- a/maps/cratewood_forest.lua +++ b/maps/cratewood_forest.lua @@ -12,7 +12,7 @@ local math_floor = math.floor local math_abs = math.abs local math_sqrt = math.sqrt -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local function get_noise(name, pos) local seed = game.surfaces[1].map_gen_settings.seed diff --git a/maps/crossing.lua b/maps/crossing.lua index 1c8d0407..3f47ff8f 100644 --- a/maps/crossing.lua +++ b/maps/crossing.lua @@ -1,7 +1,7 @@ -- crossing -- by mewmew -- local Event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local function on_player_joined_game(event) diff --git a/maps/deep_jungle/main.lua b/maps/deep_jungle/main.lua index 0b175d24..65b4270e 100644 --- a/maps/deep_jungle/main.lua +++ b/maps/deep_jungle/main.lua @@ -6,7 +6,7 @@ require 'modules.flashlight_toggle_button' require 'maps.deep_jungle.generate' local Event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local Task = require 'utils.task' local DPT = require 'maps.deep_jungle.table' local random = math.random diff --git a/maps/dungeons/biome_acid_zone.lua b/maps/dungeons/biome_acid_zone.lua index 026416ed..28e404ae 100644 --- a/maps/dungeons/biome_acid_zone.lua +++ b/maps/dungeons/biome_acid_zone.lua @@ -1,5 +1,5 @@ local Functions = require 'maps.dungeons.functions' -local BiterRaffle = require 'functions.biter_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' local DungeonsTable = require 'maps.dungeons.table' local table_shuffle_table = table.shuffle_table diff --git a/maps/dungeons/biome_concrete.lua b/maps/dungeons/biome_concrete.lua index 199f354b..3617dfa5 100644 --- a/maps/dungeons/biome_concrete.lua +++ b/maps/dungeons/biome_concrete.lua @@ -1,5 +1,5 @@ local Functions = require 'maps.dungeons.functions' -local BiterRaffle = require 'functions.biter_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' local DungeonsTable = require 'maps.dungeons.table' local table_shuffle_table = table.shuffle_table diff --git a/maps/dungeons/functions.lua b/maps/dungeons/functions.lua index c92bf012..7ca7cfe4 100644 --- a/maps/dungeons/functions.lua +++ b/maps/dungeons/functions.lua @@ -7,8 +7,8 @@ local LOOT_EVOLUTION_SCALE_FACTOR = 0.9 local LOOT_MULTIPLIER = 3000 local EVOLUTION_PER_FLOOR = 0.06 -local BiterRaffle = require 'functions.biter_raffle' -local LootRaffle = require 'functions.loot_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local Get_noise = require 'utils.get_noise' local DungeonsTable = require 'maps.dungeons.table' @@ -22,28 +22,30 @@ local math_floor = math.floor -- floor 4 = 8512 .. 9024 -- floor 9 = 16512 .. 17024 -- floor 19 = 32512 .. 33024 -LootRaffle.TweakItemWorth({ - ['modular-armor'] = 512, -- floors 1-5 from research.lua - ['power-armor'] = 4096, -- floors 8-13 from research.lua - ['personal-laser-defense-equipment'] = 1536, -- floors 10-14 from research.lua - ['power-armor-mk2'] = 24576, -- floors 14-21 from research.lua - -- reduce ammo/follower rates - ['firearm-magazine'] = 8, - ['piercing-rounds-magazine'] = 16, - ['uranium-rounds-magazine'] = 128, - ['shotgun-shell'] = 8, - ['piercing-shotgun-shell'] = 64, - ['flamethrower-ammo'] = 128, - ['rocket'] = 16, - ['explosive-rocket'] = 128, - ['grenade'] = 32, - ['cluster-grenade'] = 128, - ['poison-capsule'] = 64, - ['slowdown-capsule'] = 32, - ['defender-capsule'] = 96, - ['distractor-capsule'] = 512, - ['destroyer-capsule'] = 2048, -}) +LootRaffle.TweakItemWorth( + { + ['modular-armor'] = 512, -- floors 1-5 from research.lua + ['power-armor'] = 4096, -- floors 8-13 from research.lua + ['personal-laser-defense-equipment'] = 1536, -- floors 10-14 from research.lua + ['power-armor-mk2'] = 24576, -- floors 14-21 from research.lua + -- reduce ammo/follower rates + ['firearm-magazine'] = 8, + ['piercing-rounds-magazine'] = 16, + ['uranium-rounds-magazine'] = 128, + ['shotgun-shell'] = 8, + ['piercing-shotgun-shell'] = 64, + ['flamethrower-ammo'] = 128, + ['rocket'] = 16, + ['explosive-rocket'] = 128, + ['grenade'] = 32, + ['cluster-grenade'] = 128, + ['poison-capsule'] = 64, + ['slowdown-capsule'] = 32, + ['defender-capsule'] = 96, + ['distractor-capsule'] = 512, + ['destroyer-capsule'] = 2048 + } +) function Public.get_dungeon_evolution_factor(surface_index) local dungeontable = DungeonsTable.get_dungeontable() @@ -62,8 +64,8 @@ local function blacklist(surface_index, special) local dungeontable = DungeonsTable.get_dungeontable() local evolution_factor = Public.get_loot_evolution_factor(surface_index) if special then - -- treasure rooms act as if they are 3 levels farther down. - evolution_factor = evolution_factor + 3 * EVOLUTION_PER_FLOOR + -- treasure rooms act as if they are 3 levels farther down. + evolution_factor = evolution_factor + 3 * EVOLUTION_PER_FLOOR end local blacklists = {} --general unused items on dungeons @@ -74,7 +76,7 @@ local function blacklist(surface_index, special) blacklists['power-armor-mk2'] = true blacklists['fusion-reactor-equipment'] = true blacklists['rocket-silo'] = true - blacklists['atomic-bomb'] = true + blacklists['atomic-bomb'] = true end if evolution_factor < 0.7 then -- floor 14 blacklists['energy-shield-mk2-equipment'] = true @@ -85,11 +87,11 @@ local function blacklist(surface_index, special) blacklists['artillery-wagon'] = true blacklists['power-armor'] = true end - if evolution_factor < 0.55 then -- floor 11 + if evolution_factor < 0.55 then -- floor 11 blacklists['discharge-defense-equipment'] = true blacklists['discharge-defense-remote'] = true blacklists['nuclear-reactor'] = true - end + end if evolution_factor < 0.4 then -- floor 8 blacklists['steam-turbine'] = true blacklists['heat-exchanger'] = true @@ -144,10 +146,10 @@ function Public.get_common_resource_amount(surface_index) if dungeontable.tiered then amount = amount / 8 local floor = surface_index - dungeontable.original_surface_index - -- rocks stop going up here, so more than make up for it in resources on ground - if floor > FLOOR_FOR_MAX_ROCK_ORE then - amount = amount * (1+(floor - FLOOR_FOR_MAX_ROCK_ORE)/10) - end + -- rocks stop going up here, so more than make up for it in resources on ground + if floor > FLOOR_FOR_MAX_ROCK_ORE then + amount = amount * (1 + (floor - FLOOR_FOR_MAX_ROCK_ORE) / 10) + end end return amount end @@ -191,7 +193,7 @@ function Public.epic_loot_crate(surface, position, special) local dungeontable = DungeonsTable.get_dungeontable() local loot_value = get_loot_value(surface.index, 8) + math_random(512, 1024) if special then - loot_value = loot_value * 1.5 + loot_value = loot_value * 1.5 end local bonus_loot = nil if dungeontable.tiered and loot_value > 32000 and Public.get_dungeon_evolution_factor(surface.index) > 1 then @@ -409,10 +411,10 @@ function Public.on_marked_for_deconstruction(event) end local function get_ore_amount(surface_index) - local floor = surface_index - DungeonsTable.get_dungeontable().original_surface_index + local floor = surface_index - DungeonsTable.get_dungeontable().original_surface_index - local amount = FLOOR_ZERO_ROCK_ORE + ROCK_ORE_INCREASE_PER_FLOOR * math.min(FLOOR_FOR_MAX_ROCK_ORE, floor) - return math_random(math_floor(amount * 0.7), math_floor(amount * 1.3)) + local amount = FLOOR_ZERO_ROCK_ORE + ROCK_ORE_INCREASE_PER_FLOOR * math.min(FLOOR_FOR_MAX_ROCK_ORE, floor) + return math_random(math_floor(amount * 0.7), math_floor(amount * 1.3)) end local function reward_ores(amount, mined_loot, surface, player, entity) @@ -470,15 +472,15 @@ function Public.rocky_loot(event) local player = game.players[event.player_index] local amount = math.ceil(get_ore_amount(player.surface.index)) local rock_mining - local floor = player.surface.index - DungeonsTable.get_dungeontable().original_surface_index; + local floor = player.surface.index - DungeonsTable.get_dungeontable().original_surface_index if floor < 10 then - -- early game science uses less copper and more iron/stone - rock_mining = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'stone', 'stone', 'coal', 'coal', 'coal'} + -- early game science uses less copper and more iron/stone + rock_mining = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'stone', 'stone', 'coal', 'coal', 'coal'} else - -- end game prod 3 base uses (for all-sciences) 1 stone : 2 coal : 3.5 copper : 4.5 iron - -- this is a decent approximation which will still require some modest amount of mining setup - -- coal gets 3 to compensate for coal-based power generation - rock_mining = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'copper-ore', 'stone', 'coal', 'coal', 'coal'} + -- end game prod 3 base uses (for all-sciences) 1 stone : 2 coal : 3.5 copper : 4.5 iron + -- this is a decent approximation which will still require some modest amount of mining setup + -- coal gets 3 to compensate for coal-based power generation + rock_mining = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'copper-ore', 'stone', 'coal', 'coal', 'coal'} end local mined_loot = rock_mining[math_random(1, #rock_mining)] local text = '+' .. amount .. ' [item=' .. mined_loot .. ']' diff --git a/maps/dungeons/main.lua b/maps/dungeons/main.lua index 47375670..f5c4f81a 100644 --- a/maps/dungeons/main.lua +++ b/maps/dungeons/main.lua @@ -4,10 +4,10 @@ require 'modules.mineable_wreckage_yields_scrap' require 'modules.satellite_score' local MapInfo = require 'modules.map_info' -local Room_generator = require 'functions.room_generator' +local Room_generator = require 'utils.functions.room_generator' require 'modules.rpg' local BiterHealthBooster = require 'modules.biter_health_booster' -local BiterRaffle = require 'functions.biter_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' local Functions = require 'maps.dungeons.functions' local Get_noise = require 'utils.get_noise' local DungeonsTable = require 'maps.dungeons.table' diff --git a/maps/dungeons/tiered_dungeon.lua b/maps/dungeons/tiered_dungeon.lua index 0ca75862..03d2e6b9 100644 --- a/maps/dungeons/tiered_dungeon.lua +++ b/maps/dungeons/tiered_dungeon.lua @@ -8,10 +8,10 @@ require 'modules.charging_station' local MIN_ROOMS_TO_DESCEND = 100 local MapInfo = require 'modules.map_info' -local Room_generator = require 'functions.room_generator' +local Room_generator = require 'utils.functions.room_generator' local RPG = require 'modules.rpg.main' local BiterHealthBooster = require 'modules.biter_health_booster_v2' -local BiterRaffle = require 'functions.biter_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' local Functions = require 'maps.dungeons.functions' local Get_noise = require 'utils.get_noise' local Alert = require 'utils.alert' @@ -51,9 +51,9 @@ local function enable_hard_rooms(position, surface_index) -- 140 puts hard rooms halfway between the only dirtlands and the edge local floor_mindist = 140 - floor * 10 if floor_mindist < 80 then -- all dirtlands within this - return true + return true end - return position.x ^ 2 + position.y ^ 2 > floor_mindist^2 + return position.x ^ 2 + position.y ^ 2 > floor_mindist ^ 2 end local function get_biome(position, surface_index) @@ -70,20 +70,20 @@ local function get_biome(position, surface_index) return 'glitch' end if enable_hard_rooms(position, surface_index) then - a = a + 1 - if Get_noise('dungeons', position, seed + seed_addition * a) > 0.60 then - return 'doom' - end - a = a + 1 - if Get_noise('dungeons', position, seed + seed_addition * a) > 0.62 then - return 'acid_zone' - end - a = a + 1 - if Get_noise('dungeons', position, seed + seed_addition * a) > 0.60 then - return 'concrete' - end + a = a + 1 + if Get_noise('dungeons', position, seed + seed_addition * a) > 0.60 then + return 'doom' + end + a = a + 1 + if Get_noise('dungeons', position, seed + seed_addition * a) > 0.62 then + return 'acid_zone' + end + a = a + 1 + if Get_noise('dungeons', position, seed + seed_addition * a) > 0.60 then + return 'concrete' + end else - a = a + 3 + a = a + 3 end a = a + 1 if Get_noise('dungeons', position, seed + seed_addition * a) > 0.71 then @@ -179,7 +179,7 @@ local function expand(surface, position) end local treasure_room_one_in = 30 + 15 * dungeontable.treasures[surface.index] if dungeontable.surface_size[surface.index] >= 225 and math.random(1, treasure_room_one_in) == 1 and room.room_tiles[1] then - log('Found treasure room, change was 1 in ' .. treasure_room_one_in) + log('Found treasure room, change was 1 in ' .. treasure_room_one_in) Biomes['treasure'](surface, room) if room.room_tiles[1] then dungeontable.treasures[surface.index] = dungeontable.treasures[surface.index] + 1 @@ -266,19 +266,19 @@ end local function init_player(player, surface) if surface == game.surfaces['dungeons_floor0'] then if player.character then - player.disassociate_character(player.character) + player.disassociate_character(player.character) player.character.destroy() end - if not player.connected then - log('BUG Player ' .. player.name .. ' is not connected; how did we get here?') - end + if not player.connected then + log('BUG Player ' .. player.name .. ' is not connected; how did we get here?') + end player.set_controller({type = defines.controllers.god}) player.teleport(surface.find_non_colliding_position('character', {0, 0}, 50, 0.5), surface) if not player.create_character() then - log('BUG: create_character for ' .. player.name .. ' failed') - end + log('BUG: create_character for ' .. player.name .. ' failed') + end player.insert({name = 'raw-fish', count = 8}) player.set_quick_bar_slot(1, 'raw-fish') @@ -398,11 +398,11 @@ local function on_player_joined_game(event) end local player = game.players[event.player_index] if player.online_time == 0 then - init_player(player, game.surfaces['dungeons_floor0']) + init_player(player, game.surfaces['dungeons_floor0']) end if player.character == nil and player.ticks_to_respawn == nil then - log('BUG: ' .. player.name .. ' is missing associated character and is not waiting to respawn') - init_player(player, game.surfaces['dungeons_floor0']) + log('BUG: ' .. player.name .. ' is missing associated character and is not waiting to respawn') + init_player(player, game.surfaces['dungeons_floor0']) end draw_light(player) end @@ -472,7 +472,7 @@ local function on_player_mined_entity(event) if size < math.abs(entity.position.y) or size < math.abs(entity.position.x) then entity.surface.create_entity({name = entity.name, position = entity.position}) entity.destroy() - local player = game.players[event.player_index] + local player = game.players[event.player_index] RPG.gain_xp(player, -10) Alert.alert_player_warning(player, 30, {'dungeons_tiered.too_small'}, {r = 0.98, g = 0.22, b = 0}) event.buffer.clear() @@ -558,7 +558,7 @@ local function descend(player, button, shift) end local surface = game.surfaces[player.surface.index + 1] if not surface then - if dungeontable.surface_size[player.surface.index] < 200 + MIN_ROOMS_TO_DESCEND/4 then + if dungeontable.surface_size[player.surface.index] < 200 + MIN_ROOMS_TO_DESCEND / 4 then player.print({'dungeons_tiered.floor_size_required', MIN_ROOMS_TO_DESCEND}) return end @@ -850,9 +850,13 @@ Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_player_changed_surface, on_player_changed_surface) Event.add(defines.events.on_player_respawned, on_player_respawned) -Changelog.SetVersions({ - { ver = 'next', date = 'the future', desc = 'Make suggestions in the comfy #dungeons discord channel' }, - { ver = '1.1.1', date = '2022-04-10', desc = [[ +Changelog.SetVersions( + { + {ver = 'next', date = 'the future', desc = 'Make suggestions in the comfy #dungeons discord channel'}, + { + ver = '1.1.1', + date = '2022-04-10', + desc = [[ Balancing patch * Evolution goes up faster with floor level 0.05/level -> 0.06/level; e.g. floor 20 now like floor 24 before * Now require 100 open rooms to descend @@ -869,8 +873,12 @@ Balancing patch * Require getting to room 100 before you can descend * Science from rooms 40-160+2.5*floor to 60-300+2.5*floor * Atomic bomb research moved to 40-50 -]]}, - { ver = '1.1', date = '2022-03-13', desc = [[ +]] + }, + { + ver = '1.1', + date = '2022-03-13', + desc = [[ * All research is now found at random. * Red science floors 0-1 * Green on floors 1-5 @@ -891,6 +899,8 @@ Balancing patch * Autostash and corpse clearing from Mountain Fortress enabled * Harder rooms will occur somewhat farther out on the early floors. * Spawners and worm counts bounded in early rooms. -]]}, - { ver = '1.0', date = 'past', desc = "Pre-changelog version of multi-floor dungeons" }, -}) +]] + }, + {ver = '1.0', date = 'past', desc = 'Pre-changelog version of multi-floor dungeons'} + } +) diff --git a/maps/expanse/functions.lua b/maps/expanse/functions.lua index 8310f981..a3f48eed 100644 --- a/maps/expanse/functions.lua +++ b/maps/expanse/functions.lua @@ -1,5 +1,5 @@ local Price_raffle = require 'maps.expanse.price_raffle' -local BiterRaffle = require 'functions.biter_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' local Task = require 'utils.task' local Token = require 'utils.token' local Public = {} @@ -142,7 +142,8 @@ local function is_container_position_valid(expanse, position) end local function create_costs_render(entity, name, offset) - local id = rendering.draw_sprite{ + local id = + rendering.draw_sprite { sprite = 'virtual-signal/signal-grey', surface = entity.surface, target = entity, @@ -152,8 +153,9 @@ local function create_costs_render(entity, name, offset) target_offset = {offset, -1.5}, only_in_alt_mode = true } - local id2 = rendering.draw_sprite{ - sprite = 'item/' ..name, + local id2 = + rendering.draw_sprite { + sprite = 'item/' .. name, surface = entity.surface, target = entity, x_scale = 0.75, @@ -185,7 +187,7 @@ function Public.spawn_units(spawner) local position = spawner.position for i = 1, 4 + math.floor(8 * evolution), 1 do local biter_roll = BiterRaffle.roll('mixed', evolution) - local free_pos = spawner.surface.find_non_colliding_position(biter_roll, {x = position.x + math.random(-8,8), y = position.y + math.random(-8,8)}, 12, 0.05) + local free_pos = spawner.surface.find_non_colliding_position(biter_roll, {x = position.x + math.random(-8, 8), y = position.y + math.random(-8, 8)}, 12, 0.05) spawner.surface.create_entity({name = biter_roll, position = free_pos or position, force = 'enemy'}) end end @@ -196,7 +198,7 @@ end function Public.invasion_numbers() local evo = game.forces.enemy.evolution_factor - return {candidates = 3 + math.floor(evo * 10), groups = 1 + math.floor(evo * 4)} + return {candidates = 3 + math.floor(evo * 10), groups = 1 + math.floor(evo * 4)} end function Public.invasion_warn(event) @@ -207,13 +209,13 @@ end function Public.invasion_detonate(event) local surface = event.surface local position = event.position - local entities_close = surface.find_entities_filtered{position = position, radius = 8} + local entities_close = surface.find_entities_filtered {position = position, radius = 8} for _, entity in pairs(entities_close) do if entity.valid then entity.die('enemy') end end - local entities_nearby = surface.find_entities_filtered{position = position, radius = 16} + local entities_nearby = surface.find_entities_filtered {position = position, radius = 16} for _, entity in pairs(entities_nearby) do if entity.valid and entity.is_entity_with_health then entity.damage(entity.prototype.max_health * 0.75, 'enemy') @@ -230,10 +232,10 @@ function Public.invasion_trigger(event) local biters = {} for i = 1, 5 + math.floor(30 * evolution) + round * 5, 1 do local biter_roll = BiterRaffle.roll('mixed', evolution) - local free_pos = surface.find_non_colliding_position(biter_roll, {x = position.x + math.random(-8,8), y = position.y + math.random(-8,8)}, 12, 0.05) + local free_pos = surface.find_non_colliding_position(biter_roll, {x = position.x + math.random(-8, 8), y = position.y + math.random(-8, 8)}, 12, 0.05) biters[#biters + 1] = surface.create_entity({name = biter_roll, position = free_pos or position, force = 'enemy'}) end - local group = surface.create_unit_group{position = position, force = 'enemy'} + local group = surface.create_unit_group {position = position, force = 'enemy'} for _, biter in pairs(biters) do group.add_member(biter) end @@ -241,7 +243,7 @@ function Public.invasion_trigger(event) group.start_moving() local worm_roll = BiterRaffle.roll('worm', evolution) for i = 1, 3 + math.floor(7 * evolution), 1 do - local worm_pos = surface.find_non_colliding_position(worm_roll, {x = position.x + math.random(-12,12), y = position.y + math.random(-12,12)}, 12, 0.1) + local worm_pos = surface.find_non_colliding_position(worm_roll, {x = position.x + math.random(-12, 12), y = position.y + math.random(-12, 12)}, 12, 0.1) if worm_pos then surface.create_entity({name = worm_roll, position = worm_pos, force = 'enemy'}) end diff --git a/maps/fish_defender/main.lua b/maps/fish_defender/main.lua index 76889fcd..c1ef1caa 100644 --- a/maps/fish_defender/main.lua +++ b/maps/fish_defender/main.lua @@ -19,7 +19,7 @@ local Session = require 'utils.datastore.session_data' local Difficulty = require 'modules.difficulty_vote' local Map = require 'modules.map_info' local Event = require 'utils.event' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Server = require 'utils.server' local Poll = require 'utils.gui.poll' local boss_biter = require 'maps.fish_defender.boss_biters' diff --git a/maps/fish_defender/terrain.lua b/maps/fish_defender/terrain.lua index b6a92ddd..61bc22a2 100644 --- a/maps/fish_defender/terrain.lua +++ b/maps/fish_defender/terrain.lua @@ -1,6 +1,6 @@ --luacheck: ignore local Event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local FDT = require 'maps.fish_defender.table' local math_random = math.random diff --git a/maps/fish_defender_v1/fish_defender.lua b/maps/fish_defender_v1/fish_defender.lua index 9cce343d..ced6b047 100644 --- a/maps/fish_defender_v1/fish_defender.lua +++ b/maps/fish_defender_v1/fish_defender.lua @@ -18,8 +18,8 @@ local event = require 'utils.event' local Server = require 'utils.server' local boss_biter = require 'maps.fish_defender.boss_biters' local Score = require 'utils.gui.score' -require 'functions.boss_unit' -local map_functions = require 'tools.map_functions' +require 'utils.functions.boss_unit' +local map_functions = require 'utils.tools.map_functions' local Difficulty = require 'modules.difficulty_vote' local math_random = math.random local insert = table.insert diff --git a/maps/fish_defender_v2/main.lua b/maps/fish_defender_v2/main.lua index e1d6402e..bcbcb131 100644 --- a/maps/fish_defender_v2/main.lua +++ b/maps/fish_defender_v2/main.lua @@ -12,7 +12,7 @@ local Unit_health_booster = require 'modules.biter_health_booster_v2' local Difficulty = require 'modules.difficulty_vote' local Map = require 'modules.map_info' local Event = require 'utils.event' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Server = require 'utils.server' local Session = require 'utils.datastore.session_data' local Poll = require 'utils.gui.poll' diff --git a/maps/fish_defender_v2/terrain.lua b/maps/fish_defender_v2/terrain.lua index cab10b7c..08a472f5 100644 --- a/maps/fish_defender_v2/terrain.lua +++ b/maps/fish_defender_v2/terrain.lua @@ -1,5 +1,5 @@ local Event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local Public = require 'maps.fish_defender_v2.table' local Task = require 'utils.task' diff --git a/maps/hedge_maze.lua b/maps/hedge_maze.lua index b828c303..8254923d 100644 --- a/maps/hedge_maze.lua +++ b/maps/hedge_maze.lua @@ -7,7 +7,7 @@ require 'modules.no_deconstruction_of_neutral_entities' require 'modules.spawners_contain_biters' local event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local math_random = math.random @@ -358,12 +358,7 @@ local function draw_ores(surface, position) end local function draw_water(surface, position) - map_functions.draw_noise_tile_circle( - {x = position.x + labyrinth_cell_size * 0.5, y = position.y + labyrinth_cell_size * 0.5}, - 'water', - surface, - math.floor(labyrinth_cell_size * 0.3) - ) + map_functions.draw_noise_tile_circle({x = position.x + labyrinth_cell_size * 0.5, y = position.y + labyrinth_cell_size * 0.5}, 'water', surface, math.floor(labyrinth_cell_size * 0.3)) for _, tile in pairs(surface.find_tiles_filtered({name = 'water', area = {{position.x, position.y}, {position.x + labyrinth_cell_size, position.y + labyrinth_cell_size}}})) do if math_random(1, 12) == 1 then surface.create_entity({name = 'fish', position = tile.position}) @@ -406,21 +401,13 @@ end local function draw_rocks(surface, position) local r = math_random(0, 100) if r < 50 then - surface.create_entity( - {name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.5, y = position.y + labyrinth_cell_size * 0.5}} - ) + surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.5, y = position.y + labyrinth_cell_size * 0.5}}) return end if r <= 100 then - surface.create_entity( - {name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.5, y = position.y + labyrinth_cell_size * 0.25}} - ) - surface.create_entity( - {name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.75, y = position.y + labyrinth_cell_size * 0.75}} - ) - surface.create_entity( - {name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.25, y = position.y + labyrinth_cell_size * 0.75}} - ) + surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.5, y = position.y + labyrinth_cell_size * 0.25}}) + surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.75, y = position.y + labyrinth_cell_size * 0.75}}) + surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = {x = position.x + labyrinth_cell_size * 0.25, y = position.y + labyrinth_cell_size * 0.75}}) return end end @@ -545,11 +532,7 @@ local function on_entity_died(event) return end if event.entity.type == 'tree' then - for _, entity in pairs( - event.entity.surface.find_entities_filtered( - {area = {{event.entity.position.x - 4, event.entity.position.y - 4}, {event.entity.position.x + 4, event.entity.position.y + 4}}, name = 'fire-flame-on-tree'} - ) - ) do + for _, entity in pairs(event.entity.surface.find_entities_filtered({area = {{event.entity.position.x - 4, event.entity.position.y - 4}, {event.entity.position.x + 4, event.entity.position.y + 4}}, name = 'fire-flame-on-tree'})) do if entity.valid then entity.destroy() end diff --git a/maps/island_troopers/main.lua b/maps/island_troopers/main.lua index 90596f06..ae4472c0 100644 --- a/maps/island_troopers/main.lua +++ b/maps/island_troopers/main.lua @@ -2,7 +2,7 @@ --map by mewmew and kyte require 'maps.island_troopers.map_intro' -require 'functions.noise_vector_path' +require 'utils.functions.noise_vector_path' require 'modules.shopping_chests' require 'modules.no_turrets' require 'modules.dangerous_goods' @@ -327,4 +327,4 @@ event.add(defines.events.on_tick, on_tick) event.add(defines.events.on_entity_died, on_entity_died) event.add(defines.events.on_player_joined_game, on_player_joined_game) -require 'functions.boss_unit' +require 'utils.functions.boss_unit' diff --git a/maps/journey/functions.lua b/maps/journey/functions.lua index f8bf6bbc..1373ea4f 100644 --- a/maps/journey/functions.lua +++ b/maps/journey/functions.lua @@ -1,5 +1,5 @@ --luacheck: ignore -local Map_functions = require 'tools.map_functions' +local Map_functions = require 'utils.tools.map_functions' local Server = require 'utils.server' local Get_noise = require 'utils.get_noise' local Autostash = require 'modules.autostash' @@ -17,1505 +17,1645 @@ local Public = {} local mixed_ores = {'copper-ore', 'iron-ore', 'stone', 'coal'} local function clear_selectors(journey) - for k, world_selector in pairs(journey.world_selectors) do - for _, ID in pairs(world_selector.texts) do - rendering.destroy(ID) - end - journey.world_selectors[k].texts = {} - journey.world_selectors[k].activation_level = 0 - end - for _, ID in pairs(journey.reroll_selector.texts) do - rendering.destroy(ID) - end - journey.reroll_selector.texts = {} - journey.reroll_selector.activation_level = 0 + for k, world_selector in pairs(journey.world_selectors) do + for _, ID in pairs(world_selector.texts) do + rendering.destroy(ID) + end + journey.world_selectors[k].texts = {} + journey.world_selectors[k].activation_level = 0 + end + for _, ID in pairs(journey.reroll_selector.texts) do + rendering.destroy(ID) + end + journey.reroll_selector.texts = {} + journey.reroll_selector.activation_level = 0 end local function protect(entity, operable) - entity.minable = false - entity.destructible = false - entity.operable = operable + entity.minable = false + entity.destructible = false + entity.operable = operable end function Public.place_mixed_ore(event, journey) - if math_random(1, 192) ~= 1 then return end - local surface = event.surface - local x = event.area.left_top.x + math_random(0, 31) - local y = event.area.left_top.y + math_random(0, 31) - local base_amount = 1000 + math_sqrt(x ^ 2 + y ^ 2) * 5 - local richness = journey.mixed_ore_richness - Map_functions.draw_rainbow_patch({x = x, y = y}, surface, math_random(17, 22), base_amount * richness + 100) + if math_random(1, 192) ~= 1 then + return + end + local surface = event.surface + local x = event.area.left_top.x + math_random(0, 31) + local y = event.area.left_top.y + math_random(0, 31) + local base_amount = 1000 + math_sqrt(x ^ 2 + y ^ 2) * 5 + local richness = journey.mixed_ore_richness + Map_functions.draw_rainbow_patch({x = x, y = y}, surface, math_random(17, 22), base_amount * richness + 100) end local function place_teleporter(journey, surface, position, build_beacon) - local tiles = {} - for x = -2, 2, 1 do - for y = -2, 2, 1 do - local pos = {x = position.x + x, y = position.y + y} - table.insert(tiles, {name = Constants.teleporter_tile, position = pos}) - end - end - surface.set_tiles(tiles, false) - surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x - 1.5, y = position.y - 1.5}, target = {x = position.x + 2.5, y = position.y - 1.0}}) - surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x + 2.5, y = position.y - 1.5}, target = {x = position.x + 2.5, y = position.y + 3.0}}) - surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x + 2.5, y = position.y + 2.5}, target = {x = position.x - 1.5, y = position.y + 3.0}}) - surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x - 1.5, y = position.y + 2.5}, target = {x = position.x - 1.5, y = position.y - 1.0}}) - surface.destroy_decoratives({area = {{position.x - 3, position.y - 3}, {position.x + 3, position.y + 3}}}) - if build_beacon then - local beacon = surface.create_entity({name = 'beacon', position = {x = position.x, y = position.y}, force = 'player'}) - journey.beacon_objective_health = 10000 - beacon.operable = false - beacon.minable = false - beacon.active = false - rendering.draw_text { - text = {'journey.teleporter'}, - surface = surface, - target = beacon, - target_offset = {0, -1.5}, - color = {0, 1, 0}, - scale = 0.90, - font = 'default-game', - alignment = 'center', - scale_with_zoom = false - } - local hp = rendering.draw_text { - text = {'journey.beacon_hp', journey.beacon_objective_health}, - surface = surface, - target = beacon, - target_offset = {0, -1.0}, - color = {0, 1, 0}, - scale = 0.90, - font = 'default-game', - alignment = 'center', - scale_with_zoom = false - } - journey.beacon_objective = beacon - journey.beacon_objective_hp_label = hp - end + local tiles = {} + for x = -2, 2, 1 do + for y = -2, 2, 1 do + local pos = {x = position.x + x, y = position.y + y} + table.insert(tiles, {name = Constants.teleporter_tile, position = pos}) + end + end + surface.set_tiles(tiles, false) + surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x - 1.5, y = position.y - 1.5}, target = {x = position.x + 2.5, y = position.y - 1.0}}) + surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x + 2.5, y = position.y - 1.5}, target = {x = position.x + 2.5, y = position.y + 3.0}}) + surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x + 2.5, y = position.y + 2.5}, target = {x = position.x - 1.5, y = position.y + 3.0}}) + surface.create_entity({name = 'electric-beam-no-sound', position = position, source = {x = position.x - 1.5, y = position.y + 2.5}, target = {x = position.x - 1.5, y = position.y - 1.0}}) + surface.destroy_decoratives({area = {{position.x - 3, position.y - 3}, {position.x + 3, position.y + 3}}}) + if build_beacon then + local beacon = surface.create_entity({name = 'beacon', position = {x = position.x, y = position.y}, force = 'player'}) + journey.beacon_objective_health = 10000 + beacon.operable = false + beacon.minable = false + beacon.active = false + rendering.draw_text { + text = {'journey.teleporter'}, + surface = surface, + target = beacon, + target_offset = {0, -1.5}, + color = {0, 1, 0}, + scale = 0.90, + font = 'default-game', + alignment = 'center', + scale_with_zoom = false + } + local hp = + rendering.draw_text { + text = {'journey.beacon_hp', journey.beacon_objective_health}, + surface = surface, + target = beacon, + target_offset = {0, -1.0}, + color = {0, 1, 0}, + scale = 0.90, + font = 'default-game', + alignment = 'center', + scale_with_zoom = false + } + journey.beacon_objective = beacon + journey.beacon_objective_hp_label = hp + end end local function destroy_teleporter(journey, surface, position) - local tiles = {} - for x = -2, 2, 1 do - for y = -2, 2, 1 do - local pos = {x = position.x + x, y = position.y + y} - table.insert(tiles, {name = 'lab-dark-1', position = pos}) - end - end - surface.set_tiles(tiles, true) - for _, e in pairs(surface.find_entities_filtered({name = 'electric-beam-no-sound', area = {{position.x - 3, position.y - 3}, {position.x + 3, position.y + 3}}})) do - e.destroy() - end + local tiles = {} + for x = -2, 2, 1 do + for y = -2, 2, 1 do + local pos = {x = position.x + x, y = position.y + y} + table.insert(tiles, {name = 'lab-dark-1', position = pos}) + end + end + surface.set_tiles(tiles, true) + for _, e in pairs(surface.find_entities_filtered({name = 'electric-beam-no-sound', area = {{position.x - 3, position.y - 3}, {position.x + 3, position.y + 3}}})) do + e.destroy() + end end local function drop_player_items(journey, player) - local character = player.character - if not character then return end - if not character.valid then return end + local character = player.character + if not character then + return + end + if not character.valid then + return + end - player.clear_cursor() + player.clear_cursor() - for i = 1, player.crafting_queue_size, 1 do - if player.crafting_queue_size > 0 then - player.cancel_crafting{index = 1, count = 99999999} - end - end + for i = 1, player.crafting_queue_size, 1 do + if player.crafting_queue_size > 0 then + player.cancel_crafting {index = 1, count = 99999999} + end + end - local surface = player.surface - local spill_blockage = surface.create_entity{name = 'oil-refinery', position = journey.beacon_objective.position or player.position} + local surface = player.surface + local spill_blockage = surface.create_entity {name = 'oil-refinery', position = journey.beacon_objective.position or player.position} - for _, define in pairs({defines.inventory.character_main, defines.inventory.character_guns, defines.inventory.character_ammo, defines.inventory.character_armor, defines.inventory.character_vehicle, defines.inventory.character_trash}) do - local inventory = character.get_inventory(define) - if inventory and inventory.valid then - for i = 1, #inventory, 1 do - local slot = inventory[i] - if slot.valid and slot.valid_for_read then - surface.spill_item_stack(player.position, slot, true, nil, false) - end - end - inventory.clear() - end - end + for _, define in pairs({defines.inventory.character_main, defines.inventory.character_guns, defines.inventory.character_ammo, defines.inventory.character_armor, defines.inventory.character_vehicle, defines.inventory.character_trash}) do + local inventory = character.get_inventory(define) + if inventory and inventory.valid then + for i = 1, #inventory, 1 do + local slot = inventory[i] + if slot.valid and slot.valid_for_read then + surface.spill_item_stack(player.position, slot, true, nil, false) + end + end + inventory.clear() + end + end - spill_blockage.destroy() + spill_blockage.destroy() end function Public.clear_player(player) - local character = player.character - if not character then return end - if not character.valid then return end - player.character.destroy() - player.set_controller({type = defines.controllers.god}) - player.create_character() - player.clear_items_inside() + local character = player.character + if not character then + return + end + if not character.valid then + return + end + player.character.destroy() + player.set_controller({type = defines.controllers.god}) + player.create_character() + player.clear_items_inside() end local function remove_offline_players(maximum_age_in_hours) - local maximum_age_in_ticks = maximum_age_in_hours * 216000 - local t = game.tick - maximum_age_in_ticks - if t < 0 then return end - local players_to_remove = {} - for _, player in pairs(game.players) do - if player.last_online < t then - table.insert(players_to_remove, player) - end - end - game.remove_offline_players(players_to_remove) + local maximum_age_in_ticks = maximum_age_in_hours * 216000 + local t = game.tick - maximum_age_in_ticks + if t < 0 then + return + end + local players_to_remove = {} + for _, player in pairs(game.players) do + if player.last_online < t then + table.insert(players_to_remove, player) + end + end + game.remove_offline_players(players_to_remove) end local function calc_modifier(journey, name) - return journey.world_modifiers[name] * (journey.world_specials[name] or 1) + return journey.world_modifiers[name] * (journey.world_specials[name] or 1) end local function set_map_modifiers(journey) - local mgs = game.surfaces.nauvis.map_gen_settings - for _, name in pairs({'iron-ore', 'copper-ore', 'uranium-ore', 'coal', 'stone', 'crude-oil'}) do - mgs.autoplace_controls[name].richness = calc_modifier(journey, name) - mgs.autoplace_controls[name].size = calc_modifier(journey, 'ore_size') - mgs.autoplace_controls[name].frequency = calc_modifier(journey, 'ore_frequency') - end - journey.mixed_ore_richness = calc_modifier(journey, 'mixed_ore') + local mgs = game.surfaces.nauvis.map_gen_settings + for _, name in pairs({'iron-ore', 'copper-ore', 'uranium-ore', 'coal', 'stone', 'crude-oil'}) do + mgs.autoplace_controls[name].richness = calc_modifier(journey, name) + mgs.autoplace_controls[name].size = calc_modifier(journey, 'ore_size') + mgs.autoplace_controls[name].frequency = calc_modifier(journey, 'ore_frequency') + end + journey.mixed_ore_richness = calc_modifier(journey, 'mixed_ore') - mgs.autoplace_controls['trees'].richness = calc_modifier(journey, 'trees_richness') - mgs.autoplace_controls['trees'].size = calc_modifier(journey, 'trees_size') - mgs.autoplace_controls['trees'].frequency = calc_modifier(journey, 'trees_frequency') - mgs.autoplace_controls['enemy-base'].richness = calc_modifier(journey, 'enemy_base_richness') - mgs.autoplace_controls['enemy-base'].size = calc_modifier(journey, 'enemy_base_size') - mgs.autoplace_controls['enemy-base'].frequency = calc_modifier(journey, 'enemy_base_frequency') - mgs.starting_area = calc_modifier(journey, 'starting_area') - mgs.cliff_settings.cliff_elevation_interval = calc_modifier(journey, 'cliff_frequency') - mgs.cliff_settings.richness = calc_modifier(journey, 'cliff_continuity') - mgs.water = calc_modifier(journey, 'water') - game.map_settings.enemy_evolution['time_factor'] = calc_modifier(journey, 'time_factor') - game.map_settings.enemy_evolution['destroy_factor'] = calc_modifier(journey, 'destroy_factor') - game.map_settings.enemy_evolution['pollution_factor'] = calc_modifier(journey, 'pollution_factor') - game.map_settings.enemy_expansion.min_expansion_cooldown = calc_modifier(journey, 'expansion_cooldown') - game.map_settings.enemy_expansion.max_expansion_cooldown = calc_modifier(journey, 'expansion_cooldown') * 4 - game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = calc_modifier(journey, 'enemy_attack_pollution_consumption_modifier') - game.map_settings.pollution.ageing = calc_modifier(journey, 'ageing') - game.map_settings.pollution.diffusion_ratio = calc_modifier(journey, 'diffusion_ratio') - game.map_settings.pollution.min_pollution_to_damage_trees = calc_modifier(journey, 'tree_durability') * 6 - game.map_settings.pollution.pollution_restored_per_tree_damage = calc_modifier(journey, 'tree_durability') - game.map_settings.unit_group.max_unit_group_size = calc_modifier(journey, 'max_unit_group_size') - game.difficulty_settings.technology_price_multiplier = calc_modifier(journey, 'technology_price_multiplier') - game.surfaces.nauvis.map_gen_settings = mgs + mgs.autoplace_controls['trees'].richness = calc_modifier(journey, 'trees_richness') + mgs.autoplace_controls['trees'].size = calc_modifier(journey, 'trees_size') + mgs.autoplace_controls['trees'].frequency = calc_modifier(journey, 'trees_frequency') + mgs.autoplace_controls['enemy-base'].richness = calc_modifier(journey, 'enemy_base_richness') + mgs.autoplace_controls['enemy-base'].size = calc_modifier(journey, 'enemy_base_size') + mgs.autoplace_controls['enemy-base'].frequency = calc_modifier(journey, 'enemy_base_frequency') + mgs.starting_area = calc_modifier(journey, 'starting_area') + mgs.cliff_settings.cliff_elevation_interval = calc_modifier(journey, 'cliff_frequency') + mgs.cliff_settings.richness = calc_modifier(journey, 'cliff_continuity') + mgs.water = calc_modifier(journey, 'water') + game.map_settings.enemy_evolution['time_factor'] = calc_modifier(journey, 'time_factor') + game.map_settings.enemy_evolution['destroy_factor'] = calc_modifier(journey, 'destroy_factor') + game.map_settings.enemy_evolution['pollution_factor'] = calc_modifier(journey, 'pollution_factor') + game.map_settings.enemy_expansion.min_expansion_cooldown = calc_modifier(journey, 'expansion_cooldown') + game.map_settings.enemy_expansion.max_expansion_cooldown = calc_modifier(journey, 'expansion_cooldown') * 4 + game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = calc_modifier(journey, 'enemy_attack_pollution_consumption_modifier') + game.map_settings.pollution.ageing = calc_modifier(journey, 'ageing') + game.map_settings.pollution.diffusion_ratio = calc_modifier(journey, 'diffusion_ratio') + game.map_settings.pollution.min_pollution_to_damage_trees = calc_modifier(journey, 'tree_durability') * 6 + game.map_settings.pollution.pollution_restored_per_tree_damage = calc_modifier(journey, 'tree_durability') + game.map_settings.unit_group.max_unit_group_size = calc_modifier(journey, 'max_unit_group_size') + game.difficulty_settings.technology_price_multiplier = calc_modifier(journey, 'technology_price_multiplier') + game.surfaces.nauvis.map_gen_settings = mgs end --raw == true returns directly the number --raw == false returs ratio compared to default local function get_modifier(name, journey, raw) - local value = calc_modifier(journey, name) - if raw then - return value - else - return value * (1 / (Constants.modifiers[name].base or 1)) - end + local value = calc_modifier(journey, name) + if raw then + return value + else + return value * (1 / (Constants.modifiers[name].base or 1)) + end end local function delete_nauvis_chunks(journey) - local surface = game.surfaces.nauvis - if not journey.nauvis_chunk_positions then - journey.nauvis_chunk_positions = {} - for chunk in surface.get_chunks() do table.insert(journey.nauvis_chunk_positions, {chunk.x, chunk.y}) end - journey.size_of_nauvis_chunk_positions = #journey.nauvis_chunk_positions - for _, e in pairs(surface.find_entities_filtered{type = 'radar'}) do e.destroy() end - for _, player in pairs(game.players) do - local button = player.gui.top.add({type = 'sprite-button', name = 'chunk_progress', caption = ''}) - button.style.font = 'heading-1' - button.style.font_color = {222, 222, 222} - button.style.minimal_height = 38 - button.style.maximal_height = 38 - button.style.minimal_width = 240 - button.style.padding = -2 - end - end + local surface = game.surfaces.nauvis + if not journey.nauvis_chunk_positions then + journey.nauvis_chunk_positions = {} + for chunk in surface.get_chunks() do + table.insert(journey.nauvis_chunk_positions, {chunk.x, chunk.y}) + end + journey.size_of_nauvis_chunk_positions = #journey.nauvis_chunk_positions + for _, e in pairs(surface.find_entities_filtered {type = 'radar'}) do + e.destroy() + end + for _, player in pairs(game.players) do + local button = player.gui.top.add({type = 'sprite-button', name = 'chunk_progress', caption = ''}) + button.style.font = 'heading-1' + button.style.font_color = {222, 222, 222} + button.style.minimal_height = 38 + button.style.maximal_height = 38 + button.style.minimal_width = 240 + button.style.padding = -2 + end + end - if journey.size_of_nauvis_chunk_positions == 0 then return end + if journey.size_of_nauvis_chunk_positions == 0 then + return + end - for c = 1, 12, 1 do - local chunk_position = journey.nauvis_chunk_positions[journey.size_of_nauvis_chunk_positions] - if chunk_position then - surface.delete_chunk(chunk_position) - journey.size_of_nauvis_chunk_positions = journey.size_of_nauvis_chunk_positions - 1 - else - break - end - end + for c = 1, 12, 1 do + local chunk_position = journey.nauvis_chunk_positions[journey.size_of_nauvis_chunk_positions] + if chunk_position then + surface.delete_chunk(chunk_position) + journey.size_of_nauvis_chunk_positions = journey.size_of_nauvis_chunk_positions - 1 + else + break + end + end - local caption = {'journey.chunks_delete', journey.size_of_nauvis_chunk_positions} - for _, player in pairs(game.connected_players) do - if player.gui.top.chunk_progress then player.gui.top.chunk_progress.caption = caption end - end - return true + local caption = {'journey.chunks_delete', journey.size_of_nauvis_chunk_positions} + for _, player in pairs(game.connected_players) do + if player.gui.top.chunk_progress then + player.gui.top.chunk_progress.caption = caption + end + end + return true end function Public.mothership_message_queue(journey) - local text = journey.mothership_messages[1] - if not text then return end - if text ~= '' then - game.print({'journey.mothership_format', text}) - end - table.remove(journey.mothership_messages, 1) + local text = journey.mothership_messages[1] + if not text then + return + end + if text ~= '' then + game.print({'journey.mothership_format', text}) + end + table.remove(journey.mothership_messages, 1) end function Public.deny_building(event) - local entity = event.created_entity - if not entity.valid then return end - if entity.surface.name ~= 'mothership' then return end - if Constants.build_type_whitelist[entity.type] then - entity.destructible = false - return - end - entity.die() + local entity = event.created_entity + if not entity.valid then + return + end + if entity.surface.name ~= 'mothership' then + return + end + if Constants.build_type_whitelist[entity.type] then + entity.destructible = false + return + end + entity.die() end function Public.register_built_silo(event, journey) - local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type ~= 'rocket-silo' then return end - entity.auto_launch = false - table.insert(journey.rocket_silos, entity) + local entity = event.created_entity + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type ~= 'rocket-silo' then + return + end + entity.auto_launch = false + table.insert(journey.rocket_silos, entity) end local function cargo_gui(name, itemname, tooltip, value, hidden) - for _, player in pairs(game.connected_players) do - if not player.gui.top[name] then - local frame = player.gui.top.add({type = 'frame', name = name}) - frame.style.left_margin = 0 - frame.style.padding = 0 - local sprite = frame.add({type = 'sprite', sprite = 'item/' .. itemname, name = name .. '_sprite', resize_to_sprite = false}) - sprite.style.minimal_width = 28 - sprite.style.minimal_height = 28 - sprite.style.maximal_width = 28 - sprite.style.maximal_height = 28 - sprite.style.margin = 0 - sprite.style.padding = 0 - local progressbar = frame.add({type = 'progressbar', name = name .. '_progressbar', value = 0}) - progressbar.style = 'achievement_progressbar' - progressbar.style.minimal_width = 100 - progressbar.style.maximal_width = 100 - progressbar.style.top_margin = 2 - progressbar.style.right_margin = 6 - end - local frame = player.gui.top[name] - frame.tooltip = tooltip - local sprite = player.gui.top[name][name .. '_sprite'] - sprite.sprite = 'item/' .. itemname - sprite.tooltip = tooltip - local progressbar = player.gui.top[name][name .. '_progressbar'] - progressbar.value = value - progressbar.tooltip = tooltip - if hidden then - frame.visible = false - else - frame.visible = true - end - end + for _, player in pairs(game.connected_players) do + if not player.gui.top[name] then + local frame = player.gui.top.add({type = 'frame', name = name}) + frame.style.left_margin = 0 + frame.style.padding = 0 + local sprite = frame.add({type = 'sprite', sprite = 'item/' .. itemname, name = name .. '_sprite', resize_to_sprite = false}) + sprite.style.minimal_width = 28 + sprite.style.minimal_height = 28 + sprite.style.maximal_width = 28 + sprite.style.maximal_height = 28 + sprite.style.margin = 0 + sprite.style.padding = 0 + local progressbar = frame.add({type = 'progressbar', name = name .. '_progressbar', value = 0}) + progressbar.style = 'achievement_progressbar' + progressbar.style.minimal_width = 100 + progressbar.style.maximal_width = 100 + progressbar.style.top_margin = 2 + progressbar.style.right_margin = 6 + end + local frame = player.gui.top[name] + frame.tooltip = tooltip + local sprite = player.gui.top[name][name .. '_sprite'] + sprite.sprite = 'item/' .. itemname + sprite.tooltip = tooltip + local progressbar = player.gui.top[name][name .. '_progressbar'] + progressbar.value = value + progressbar.tooltip = tooltip + if hidden then + frame.visible = false + else + frame.visible = true + end + end end function Public.update_tooltips(journey) - local modiftt = {''} - for k, v in pairs(Constants.modifiers) do - modiftt = {'', modiftt, {'journey.tooltip_modifier', v.name, math.round(get_modifier(k, journey) * 100)}} - end - journey.tooltip_modifiers = modiftt + local modiftt = {''} + for k, v in pairs(Constants.modifiers) do + modiftt = {'', modiftt, {'journey.tooltip_modifier', v.name, math.round(get_modifier(k, journey) * 100)}} + end + journey.tooltip_modifiers = modiftt - local capsulett = {''} - local c = 0 - for k, v in pairs(journey.bonus_goods) do - local str = ' ' - local v2 = tostring(v) - v = string.sub(str, 1, -string.len(v2)) .. v2 - c = c + 1 - if c % 3 == 0 then - capsulett = {'', capsulett, {'journey.tooltip_capsule2', v, k}} - else - capsulett = {'', capsulett, {'journey.tooltip_capsule', v, k}} - end - end - journey.tooltip_capsules = capsulett + local capsulett = {''} + local c = 0 + for k, v in pairs(journey.bonus_goods) do + local str = ' ' + local v2 = tostring(v) + v = string.sub(str, 1, -string.len(v2)) .. v2 + c = c + 1 + if c % 3 == 0 then + capsulett = {'', capsulett, {'journey.tooltip_capsule2', v, k}} + else + capsulett = {'', capsulett, {'journey.tooltip_capsule', v, k}} + end + end + journey.tooltip_capsules = capsulett end function Public.draw_gui(journey) - local surface = game.surfaces.nauvis - local mgs = surface.map_gen_settings - local caption = {'journey.world', journey.world_number, Constants.unique_world_traits[journey.world_trait].name} - local tooltip = {'journey.world_tooltip', Constants.unique_world_traits[journey.world_trait].desc, journey.tooltip_modifiers, journey.tooltip_capsules} + local surface = game.surfaces.nauvis + local mgs = surface.map_gen_settings + local caption = {'journey.world', journey.world_number, Constants.unique_world_traits[journey.world_trait].name} + local tooltip = {'journey.world_tooltip', Constants.unique_world_traits[journey.world_trait].desc, journey.tooltip_modifiers, journey.tooltip_capsules} - for _, player in pairs(game.connected_players) do - if not player.gui.top.journey_button then - local element = player.gui.top.add({type = 'sprite-button', name = 'journey_button', caption = ''}) - element.style.font = 'heading-1' - element.style.font_color = {222, 222, 222} - element.style.minimal_height = 38 - element.style.maximal_height = 38 - element.style.minimal_width = 250 - element.style.padding = -2 - end - local gui = player.gui.top.journey_button - gui.caption = caption - gui.tooltip = tooltip - end + for _, player in pairs(game.connected_players) do + if not player.gui.top.journey_button then + local element = player.gui.top.add({type = 'sprite-button', name = 'journey_button', caption = ''}) + element.style.font = 'heading-1' + element.style.font_color = {222, 222, 222} + element.style.minimal_height = 38 + element.style.maximal_height = 38 + element.style.minimal_width = 250 + element.style.padding = -2 + end + local gui = player.gui.top.journey_button + gui.caption = caption + gui.tooltip = tooltip + end - local fuel_requirement = journey.mothership_cargo_space['uranium-fuel-cell'] - local value - if fuel_requirement == 0 then - value = 1 - else - value = journey.mothership_cargo['uranium-fuel-cell'] / fuel_requirement - end - cargo_gui('journey_fuel', 'uranium-fuel-cell', {'journey.tooltip_fuel', fuel_requirement, journey.mothership_cargo['uranium-fuel-cell']}, value) + local fuel_requirement = journey.mothership_cargo_space['uranium-fuel-cell'] + local value + if fuel_requirement == 0 then + value = 1 + else + value = journey.mothership_cargo['uranium-fuel-cell'] / fuel_requirement + end + cargo_gui('journey_fuel', 'uranium-fuel-cell', {'journey.tooltip_fuel', fuel_requirement, journey.mothership_cargo['uranium-fuel-cell']}, value) - local max_satellites = journey.mothership_cargo_space['satellite'] - local value2 = journey.mothership_cargo['satellite'] / max_satellites - cargo_gui('journey_satellites', 'satellite', {'journey.tooltip_satellite', journey.mothership_cargo['satellite'], max_satellites}, value2) + local max_satellites = journey.mothership_cargo_space['satellite'] + local value2 = journey.mothership_cargo['satellite'] / max_satellites + cargo_gui('journey_satellites', 'satellite', {'journey.tooltip_satellite', journey.mothership_cargo['satellite'], max_satellites}, value2) - local max_emergency_fuel = journey.mothership_cargo_space['nuclear-reactor'] - local value3 = journey.mothership_cargo['nuclear-reactor'] / max_emergency_fuel - cargo_gui('journey_emergency', 'nuclear-reactor', {'journey.tooltip_nuclear_fuel', journey.mothership_cargo['nuclear-reactor'], max_emergency_fuel}, value3) + local max_emergency_fuel = journey.mothership_cargo_space['nuclear-reactor'] + local value3 = journey.mothership_cargo['nuclear-reactor'] / max_emergency_fuel + cargo_gui('journey_emergency', 'nuclear-reactor', {'journey.tooltip_nuclear_fuel', journey.mothership_cargo['nuclear-reactor'], max_emergency_fuel}, value3) - local item = journey.speedrun.item - local time = math.round(journey.speedrun.time / 6) / 10 - local speedgoal = journey.mothership_cargo_space[item] or 1 - local value4 = (journey.mothership_cargo[item] or 0) / speedgoal - if journey.speedrun.enabled then - cargo_gui('journey_delivery', item, {'journey.tooltip_delivery', journey.mothership_cargo[item] or 0, speedgoal, time}, value4) - else - cargo_gui('journey_delivery', item, {'journey.tooltip_delivery', journey.mothership_cargo[item] or 0, speedgoal, time}, value4, true) - end + local item = journey.speedrun.item + local time = math.round(journey.speedrun.time / 6) / 10 + local speedgoal = journey.mothership_cargo_space[item] or 1 + local value4 = (journey.mothership_cargo[item] or 0) / speedgoal + if journey.speedrun.enabled then + cargo_gui('journey_delivery', item, {'journey.tooltip_delivery', journey.mothership_cargo[item] or 0, speedgoal, time}, value4) + else + cargo_gui('journey_delivery', item, {'journey.tooltip_delivery', journey.mothership_cargo[item] or 0, speedgoal, time}, value4, true) + end end local function is_mothership(position) - if math.abs(position.x) > Constants.mothership_radius then return false end - if math.abs(position.y) > Constants.mothership_radius then return false end - local p = {x = position.x, y = position.y} - if p.x > 0 then p.x = p.x + 1 end - if p.y > 0 then p.y = p.y + 1 end - local d = math.sqrt(p.x ^ 2 + p.y ^ 2) - if d < Constants.mothership_radius then - return true - end + if math.abs(position.x) > Constants.mothership_radius then + return false + end + if math.abs(position.y) > Constants.mothership_radius then + return false + end + local p = {x = position.x, y = position.y} + if p.x > 0 then + p.x = p.x + 1 + end + if p.y > 0 then + p.y = p.y + 1 + end + local d = math.sqrt(p.x ^ 2 + p.y ^ 2) + if d < Constants.mothership_radius then + return true + end end function Public.on_mothership_chunk_generated(event) - local left_top = event.area.left_top - local surface = event.surface - local seed = surface.map_gen_settings.seed - local tiles = {} - for x = 0, 31, 1 do - for y = 0, 31, 1 do - local position = {x = left_top.x + x, y = left_top.y + y} - if is_mothership(position) then - table.insert(tiles, {name = 'black-refined-concrete', position = position}) - else - table.insert(tiles, {name = 'out-of-map', position = position}) - end - end - end - surface.set_tiles(tiles, true) + local left_top = event.area.left_top + local surface = event.surface + local seed = surface.map_gen_settings.seed + local tiles = {} + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local position = {x = left_top.x + x, y = left_top.y + y} + if is_mothership(position) then + table.insert(tiles, {name = 'black-refined-concrete', position = position}) + else + table.insert(tiles, {name = 'out-of-map', position = position}) + end + end + end + surface.set_tiles(tiles, true) end function Public.export_journey(journey, import_flag) - local data = { - world_number = journey.world_number, - world_modifiers = journey.world_modifiers, - bonus_goods = journey.bonus_goods, - world_selectors = journey.world_selectors, - mothership_cargo = journey.mothership_cargo, - mothership_cargo_space = journey.mothership_cargo_space, - } - local secs = Server.get_current_time() + local data = { + world_number = journey.world_number, + world_modifiers = journey.world_modifiers, + bonus_goods = journey.bonus_goods, + world_selectors = journey.world_selectors, + mothership_cargo = journey.mothership_cargo, + mothership_cargo_space = journey.mothership_cargo_space + } + local secs = Server.get_current_time() if not secs then return else - Server.set_data('scenario_settings', 'journey_data', data) - Server.set_data('scenario_settings', 'journey_updating', import_flag) - game.print('Journey data exported...') - end + Server.set_data('scenario_settings', 'journey_data', data) + Server.set_data('scenario_settings', 'journey_updating', import_flag) + game.print('Journey data exported...') + end end function Public.import_journey(journey) - local state = journey.game_state - if state == 'world' or state == 'dispatch_goods' or state == 'mothership_waiting_for_players' then - log('Can run import command only during world selection stages') - return - end - local secs = Server.get_current_time() + local state = journey.game_state + if state == 'world' or state == 'dispatch_goods' or state == 'mothership_waiting_for_players' then + log('Can run import command only during world selection stages') + return + end + local secs = Server.get_current_time() if not secs then return else - Server.try_get_data('scenario_settings', 'journey_data', journey.import) - Server.set_data('scenario_settings', 'journey_updating', false) - end + Server.try_get_data('scenario_settings', 'journey_data', journey.import) + Server.set_data('scenario_settings', 'journey_updating', false) + end end local function check_if_restarted(journey) - local secs = Server.get_current_time() + local secs = Server.get_current_time() if not secs or journey.import_checked then return else - Server.try_get_data('scenario_settings', 'journey_updating', journey.check_import) - end + Server.try_get_data('scenario_settings', 'journey_updating', journey.check_import) + end end function Public.restart_server(journey) - local state = journey.game_state - if state == 'world' or state == 'dispatch_goods' or state == 'mothership_waiting_for_players' then - log('Can force restart only during world selection stages') - return - end - game.print({'journey.cmd_server_restarting'}, {r = 255, g = 255, b = 0}) - Public.export_journey(journey, true) - Server.start_scenario('Journey') - return + local state = journey.game_state + if state == 'world' or state == 'dispatch_goods' or state == 'mothership_waiting_for_players' then + log('Can force restart only during world selection stages') + return + end + game.print({'journey.cmd_server_restarting'}, {r = 255, g = 255, b = 0}) + Public.export_journey(journey, true) + Server.start_scenario('Journey') + return end function Public.hard_reset(journey) - if journey.restart_from_scenario then - game.print({'journey.cmd_server_restarting'}, {r = 255, g = 255, b = 0}) - Public.export_journey(journey, false) - Server.start_scenario('Journey') - return - end - Vacants.reset() - BottomFrame.activate_custom_buttons(true) - BottomFrame.reset() - Autostash.insert_into_furnace(true) - Autostash.bottom_button(true) - Misc.bottom_button(true) - if game.surfaces.mothership and game.surfaces.mothership.valid then - game.delete_surface(game.surfaces.mothership) - end + if journey.restart_from_scenario then + game.print({'journey.cmd_server_restarting'}, {r = 255, g = 255, b = 0}) + Public.export_journey(journey, false) + Server.start_scenario('Journey') + return + end + Vacants.reset() + BottomFrame.activate_custom_buttons(true) + BottomFrame.reset() + Autostash.insert_into_furnace(true) + Autostash.bottom_button(true) + Misc.bottom_button(true) + if game.surfaces.mothership and game.surfaces.mothership.valid then + game.delete_surface(game.surfaces.mothership) + end - game.forces.enemy.character_inventory_slots_bonus = 9999 + game.forces.enemy.character_inventory_slots_bonus = 9999 - game.map_settings.enemy_expansion.enabled = true - game.map_settings.enemy_expansion.max_expansion_distance = 20 - game.map_settings.enemy_expansion.settler_group_min_size = 5 - game.map_settings.enemy_expansion.settler_group_max_size = 50 + game.map_settings.enemy_expansion.enabled = true + game.map_settings.enemy_expansion.max_expansion_distance = 20 + game.map_settings.enemy_expansion.settler_group_min_size = 5 + game.map_settings.enemy_expansion.settler_group_max_size = 50 - game.map_settings.pollution.enabled = true - game.map_settings.pollution.min_to_diffuse = 75 - game.map_settings.pollution.expected_max_per_chunk = 300 + game.map_settings.pollution.enabled = true + game.map_settings.pollution.min_to_diffuse = 75 + game.map_settings.pollution.expected_max_per_chunk = 300 - game.map_settings.enemy_expansion.max_expansion_distance = 5 --default 7 - game.map_settings.enemy_expansion.friendly_base_influence_radius = 1 --default 2 - game.map_settings.enemy_expansion.enemy_building_influence_radius = 5 --default 2 - game.map_settings.enemy_expansion.building_coefficient = 0.02 --default 0.1 - game.map_settings.enemy_expansion.neighbouring_chunk_coefficient = 0.25 --defualt 0.5 - game.map_settings.enemy_expansion.neighbouring_base_chunk_coefficient = 0.25 --default 0.4 + game.map_settings.enemy_expansion.max_expansion_distance = 5 --default 7 + game.map_settings.enemy_expansion.friendly_base_influence_radius = 1 --default 2 + game.map_settings.enemy_expansion.enemy_building_influence_radius = 5 --default 2 + game.map_settings.enemy_expansion.building_coefficient = 0.02 --default 0.1 + game.map_settings.enemy_expansion.neighbouring_chunk_coefficient = 0.25 --defualt 0.5 + game.map_settings.enemy_expansion.neighbouring_base_chunk_coefficient = 0.25 --default 0.4 - local surface = game.surfaces[1] + local surface = game.surfaces[1] - surface.clear(true) - surface.daytime = math.random(1, 100) * 0.01 + surface.clear(true) + surface.daytime = math.random(1, 100) * 0.01 - if journey.world_selectors and journey.world_selectors[1].border then - for k, world_selector in pairs(journey.world_selectors) do - for _, ID in pairs(world_selector.rectangles) do - rendering.destroy(ID) - end - rendering.destroy(world_selector.border) - end - end + if journey.world_selectors and journey.world_selectors[1].border then + for k, world_selector in pairs(journey.world_selectors) do + for _, ID in pairs(world_selector.rectangles) do + rendering.destroy(ID) + end + rendering.destroy(world_selector.border) + end + end - journey.world_selectors = {} - journey.reroll_selector = {activation_level = 0} - for i = 1, 3, 1 do journey.world_selectors[i] = {activation_level = 0, texts = {}} end - journey.mothership_speed = 0.5 - journey.characters_in_mothership = 0 - journey.world_color_filters = {} - journey.mixed_ore_richness = 1 - journey.mothership_messages = {} - journey.mothership_cargo = {} - journey.mothership_cargo['uranium-fuel-cell'] = 10 - journey.mothership_cargo['satellite'] = 1 - journey.mothership_cargo['nuclear-reactor'] = 60 - journey.mothership_cargo_space = { - ['satellite'] = 1, - ['uranium-fuel-cell'] = 0, - ['nuclear-reactor'] = 60 - } - journey.bonus_goods = {} - journey.tooltip_capsules = '' - journey.tooltip_modifiers = '' - journey.nauvis_chunk_positions = nil - journey.beacon_objective_health = 10000 - journey.beacon_objective_resistance = 0.9 - journey.beacon_timer = 0 - journey.world_number = 0 - journey.world_trait = 'lush' - journey.world_modifiers = {} - journey.world_specials = {} - journey.emergency_triggered = false - journey.emergency_selected = false - journey.game_state = 'create_mothership' - journey.speedrun = {enabled = false, time = 0, item = 'iron-stick'} - journey.vote_minimum = 1 - journey.mothership_messages_last_damage = game.tick - for k, modifier in pairs(Constants.modifiers) do - journey.world_modifiers[k] = modifier.base - end - Public.update_tooltips(journey) + journey.world_selectors = {} + journey.reroll_selector = {activation_level = 0} + for i = 1, 3, 1 do + journey.world_selectors[i] = {activation_level = 0, texts = {}} + end + journey.mothership_speed = 0.5 + journey.characters_in_mothership = 0 + journey.world_color_filters = {} + journey.mixed_ore_richness = 1 + journey.mothership_messages = {} + journey.mothership_cargo = {} + journey.mothership_cargo['uranium-fuel-cell'] = 10 + journey.mothership_cargo['satellite'] = 1 + journey.mothership_cargo['nuclear-reactor'] = 60 + journey.mothership_cargo_space = { + ['satellite'] = 1, + ['uranium-fuel-cell'] = 0, + ['nuclear-reactor'] = 60 + } + journey.bonus_goods = {} + journey.tooltip_capsules = '' + journey.tooltip_modifiers = '' + journey.nauvis_chunk_positions = nil + journey.beacon_objective_health = 10000 + journey.beacon_objective_resistance = 0.9 + journey.beacon_timer = 0 + journey.world_number = 0 + journey.world_trait = 'lush' + journey.world_modifiers = {} + journey.world_specials = {} + journey.emergency_triggered = false + journey.emergency_selected = false + journey.game_state = 'create_mothership' + journey.speedrun = {enabled = false, time = 0, item = 'iron-stick'} + journey.vote_minimum = 1 + journey.mothership_messages_last_damage = game.tick + for k, modifier in pairs(Constants.modifiers) do + journey.world_modifiers[k] = modifier.base + end + Public.update_tooltips(journey) end function Public.create_mothership(journey) - local surface = game.create_surface('mothership', Constants.mothership_gen_settings) - surface.request_to_generate_chunks({x = 0, y = 0}, 6) - surface.force_generate_chunk_requests() - surface.freeze_daytime = true - journey.game_state = 'draw_mothership' + local surface = game.create_surface('mothership', Constants.mothership_gen_settings) + surface.request_to_generate_chunks({x = 0, y = 0}, 6) + surface.force_generate_chunk_requests() + surface.freeze_daytime = true + journey.game_state = 'draw_mothership' end function Public.draw_mothership(journey) - local surface = game.surfaces.mothership + local surface = game.surfaces.mothership - local positions = {} - for x = Constants.mothership_radius * -1, Constants.mothership_radius, 1 do - for y = Constants.mothership_radius * -1, Constants.mothership_radius, 1 do - local position = {x = x, y = y} - if is_mothership(position) then table.insert(positions, position) end - end - end + local positions = {} + for x = Constants.mothership_radius * -1, Constants.mothership_radius, 1 do + for y = Constants.mothership_radius * -1, Constants.mothership_radius, 1 do + local position = {x = x, y = y} + if is_mothership(position) then + table.insert(positions, position) + end + end + end - table.shuffle_table(positions) + table.shuffle_table(positions) - for _, position in pairs(positions) do - if surface.count_tiles_filtered({area = {{position.x - 1, position.y - 1}, {position.x + 2, position.y + 2}}, name = 'out-of-map'}) > 0 then - local e = surface.create_entity({name = 'stone-wall', position = position, force = 'player'}) - protect(e, true) - end - if surface.count_tiles_filtered({area = {{position.x - 1, position.y - 1}, {position.x + 2, position.y + 2}}, name = 'lab-dark-1'}) < 4 then - surface.set_tiles({{name = 'lab-dark-1', position = position}}, true) - end - end + for _, position in pairs(positions) do + if surface.count_tiles_filtered({area = {{position.x - 1, position.y - 1}, {position.x + 2, position.y + 2}}, name = 'out-of-map'}) > 0 then + local e = surface.create_entity({name = 'stone-wall', position = position, force = 'player'}) + protect(e, true) + end + if surface.count_tiles_filtered({area = {{position.x - 1, position.y - 1}, {position.x + 2, position.y + 2}}, name = 'lab-dark-1'}) < 4 then + surface.set_tiles({{name = 'lab-dark-1', position = position}}, true) + end + end - for _, tile in pairs(surface.find_tiles_filtered({area = {{Constants.mothership_teleporter_position.x - 2, Constants.mothership_teleporter_position.y - 2}, {Constants.mothership_teleporter_position.x + 2, Constants.mothership_teleporter_position.y + 2}}})) do - surface.set_tiles({{name = 'lab-dark-1', position = tile.position}}, true) - end + for _, tile in pairs( + surface.find_tiles_filtered({area = {{Constants.mothership_teleporter_position.x - 2, Constants.mothership_teleporter_position.y - 2}, {Constants.mothership_teleporter_position.x + 2, Constants.mothership_teleporter_position.y + 2}}}) + ) do + surface.set_tiles({{name = 'lab-dark-1', position = tile.position}}, true) + end - for k, area in pairs(Constants.world_selector_areas) do - journey.world_selectors[k].rectangles = {} - local position = area.left_top - local rectangle = rendering.draw_rectangle { - width = 1, - filled=true, - surface = surface, - left_top = position, - right_bottom = {position.x + Constants.world_selector_width, position.y + Constants.world_selector_height}, - color = Constants.world_selector_colors[k], - draw_on_ground = true, - only_in_alt_mode = false - } - table.insert(journey.world_selectors[k].rectangles, rectangle) - journey.world_selectors[k].border = rendering.draw_rectangle { - width = 8, - filled=false, - surface = surface, - left_top = position, - right_bottom = {position.x + Constants.world_selector_width, position.y + Constants.world_selector_height}, - color = {r = 100, g = 100, b = 100, a = 255}, - draw_on_ground = true, - only_in_alt_mode = false - } - end + for k, area in pairs(Constants.world_selector_areas) do + journey.world_selectors[k].rectangles = {} + local position = area.left_top + local rectangle = + rendering.draw_rectangle { + width = 1, + filled = true, + surface = surface, + left_top = position, + right_bottom = {position.x + Constants.world_selector_width, position.y + Constants.world_selector_height}, + color = Constants.world_selector_colors[k], + draw_on_ground = true, + only_in_alt_mode = false + } + table.insert(journey.world_selectors[k].rectangles, rectangle) + journey.world_selectors[k].border = + rendering.draw_rectangle { + width = 8, + filled = false, + surface = surface, + left_top = position, + right_bottom = {position.x + Constants.world_selector_width, position.y + Constants.world_selector_height}, + color = {r = 100, g = 100, b = 100, a = 255}, + draw_on_ground = true, + only_in_alt_mode = false + } + end - journey.reroll_selector.rectangle = rendering.draw_rectangle { - width = 8, - filled=true, - surface = surface, - left_top = Constants.reroll_selector_area.left_top, - right_bottom = Constants.reroll_selector_area.right_bottom, - color = Constants.reroll_selector_area_color, - draw_on_ground = true, - only_in_alt_mode = false - } - journey.reroll_selector.border = rendering.draw_rectangle { - width = 8, - filled=false, - surface = surface, - left_top = Constants.reroll_selector_area.left_top, - right_bottom = Constants.reroll_selector_area.right_bottom, - color = {r = 100, g = 100, b = 100, a = 255}, - draw_on_ground = true, - only_in_alt_mode = false - } + journey.reroll_selector.rectangle = + rendering.draw_rectangle { + width = 8, + filled = true, + surface = surface, + left_top = Constants.reroll_selector_area.left_top, + right_bottom = Constants.reroll_selector_area.right_bottom, + color = Constants.reroll_selector_area_color, + draw_on_ground = true, + only_in_alt_mode = false + } + journey.reroll_selector.border = + rendering.draw_rectangle { + width = 8, + filled = false, + surface = surface, + left_top = Constants.reroll_selector_area.left_top, + right_bottom = Constants.reroll_selector_area.right_bottom, + color = {r = 100, g = 100, b = 100, a = 255}, + draw_on_ground = true, + only_in_alt_mode = false + } - for k, item_name in pairs({'arithmetic-combinator', 'constant-combinator', 'decider-combinator', 'programmable-speaker', 'red-wire', 'green-wire', 'small-lamp', 'substation', 'pipe', 'gate', 'stone-wall', 'transport-belt'}) do - local chest = surface.create_entity({name = 'infinity-chest', position = {-7 + k, Constants.mothership_radius - 3}, force = 'player'}) - chest.set_infinity_container_filter(1, {name = item_name, count = game.item_prototypes[item_name].stack_size}) - protect(chest, false) - local loader = surface.create_entity({name = 'express-loader', position = {-7 + k, Constants.mothership_radius - 4}, force = 'player'}) - protect(loader, true) - loader.direction = 4 - end + for k, item_name in pairs({'arithmetic-combinator', 'constant-combinator', 'decider-combinator', 'programmable-speaker', 'red-wire', 'green-wire', 'small-lamp', 'substation', 'pipe', 'gate', 'stone-wall', 'transport-belt'}) do + local chest = surface.create_entity({name = 'infinity-chest', position = {-7 + k, Constants.mothership_radius - 3}, force = 'player'}) + chest.set_infinity_container_filter(1, {name = item_name, count = game.item_prototypes[item_name].stack_size}) + protect(chest, false) + local loader = surface.create_entity({name = 'express-loader', position = {-7 + k, Constants.mothership_radius - 4}, force = 'player'}) + protect(loader, true) + loader.direction = 4 + end - for m = -1, 1, 2 do - local inter = surface.create_entity({name = 'electric-energy-interface', position = {11 * m, Constants.mothership_radius - 4}, force = 'player'}) - protect(inter, true) - local sub = surface.create_entity({name = 'substation', position = {9 * m, Constants.mothership_radius - 4}, force = 'player'}) - protect(sub, true) - end + for m = -1, 1, 2 do + local inter = surface.create_entity({name = 'electric-energy-interface', position = {11 * m, Constants.mothership_radius - 4}, force = 'player'}) + protect(inter, true) + local sub = surface.create_entity({name = 'substation', position = {9 * m, Constants.mothership_radius - 4}, force = 'player'}) + protect(sub, true) + end - for m = -1, 1, 2 do - local x = Constants.mothership_radius - 3 - if m > 0 then x = x - 1 end - local y = Constants.mothership_radius * 0.5 - 7 - local turret = surface.create_entity({name = 'artillery-turret', position = {x * m, y}, force = 'player'}) - turret.direction = 4 - protect(turret, false) - local ins = surface.create_entity({name = 'burner-inserter', position = {(x - 1) * m, y}, force = 'player'}) - ins.direction = 4 + m * 2 - ins.rotatable = false - protect(ins, false) - local chest = surface.create_entity({name = 'infinity-chest', position = {(x - 2) * m, y}, force = 'player'}) - chest.set_infinity_container_filter(1, {name = 'solid-fuel', count = 50}) - chest.set_infinity_container_filter(2, {name = 'artillery-shell', count = 1}) - protect(chest, false) - end + for m = -1, 1, 2 do + local x = Constants.mothership_radius - 3 + if m > 0 then + x = x - 1 + end + local y = Constants.mothership_radius * 0.5 - 7 + local turret = surface.create_entity({name = 'artillery-turret', position = {x * m, y}, force = 'player'}) + turret.direction = 4 + protect(turret, false) + local ins = surface.create_entity({name = 'burner-inserter', position = {(x - 1) * m, y}, force = 'player'}) + ins.direction = 4 + m * 2 + ins.rotatable = false + protect(ins, false) + local chest = surface.create_entity({name = 'infinity-chest', position = {(x - 2) * m, y}, force = 'player'}) + chest.set_infinity_container_filter(1, {name = 'solid-fuel', count = 50}) + chest.set_infinity_container_filter(2, {name = 'artillery-shell', count = 1}) + protect(chest, false) + end - for _ = 1, 3, 1 do - local comp = surface.create_entity({name = 'compilatron', position = Constants.mothership_teleporter_position, force = 'player'}) - comp.destructible = false - end - Public.draw_gui(journey) - surface.daytime = 0.5 + for _ = 1, 3, 1 do + local comp = surface.create_entity({name = 'compilatron', position = Constants.mothership_teleporter_position, force = 'player'}) + comp.destructible = false + end + Public.draw_gui(journey) + surface.daytime = 0.5 - journey.game_state = 'set_world_selectors' + journey.game_state = 'set_world_selectors' end function Public.teleport_players_to_mothership(journey) - local surface = game.surfaces.mothership - for _, player in pairs(game.connected_players) do - if player.surface.name ~= 'mothership' then - Public.clear_player(player) - player.teleport(surface.find_non_colliding_position('character', {0,0}, 32, 0.5), surface) - journey.characters_in_mothership = journey.characters_in_mothership + 1 - table.insert(journey.mothership_messages, 'Welcome home ' .. player.name .. '!') - return - end - end + local surface = game.surfaces.mothership + for _, player in pairs(game.connected_players) do + if player.surface.name ~= 'mothership' then + Public.clear_player(player) + player.teleport(surface.find_non_colliding_position('character', {0, 0}, 32, 0.5), surface) + journey.characters_in_mothership = journey.characters_in_mothership + 1 + table.insert(journey.mothership_messages, 'Welcome home ' .. player.name .. '!') + return + end + end end function Public.set_minimum_to_vote(journey) - --server_id returns only on Comfy server - --therefore on Comfy, there is minimum of 3 players to vote for a world. - --in any multiplayer there is minimum of 2 players - --in singleplayer the minimum is 1 - --this does change only behaviour if there is less players connected than the minimum - --the minimum should actualize on player join or when mothership builds the selectors - if Server.get_server_id() ~= '' then - journey.vote_minimum = 3 - elseif game.is_multiplayer() then - journey.vote_minimum = 2 - else - journey.vote_minimum = 1 - end - local surface = game.surfaces.mothership - if #game.connected_players <= journey.vote_minimum and surface and surface.daytime <= 0.5 then - table.insert(journey.mothership_messages, {'journey.message_min_players', journey.vote_minimum}) - end + --server_id returns only on Comfy server + --therefore on Comfy, there is minimum of 3 players to vote for a world. + --in any multiplayer there is minimum of 2 players + --in singleplayer the minimum is 1 + --this does change only behaviour if there is less players connected than the minimum + --the minimum should actualize on player join or when mothership builds the selectors + if Server.get_server_id() ~= '' then + journey.vote_minimum = 3 + elseif game.is_multiplayer() then + journey.vote_minimum = 2 + else + journey.vote_minimum = 1 + end + local surface = game.surfaces.mothership + if #game.connected_players <= journey.vote_minimum and surface and surface.daytime <= 0.5 then + table.insert(journey.mothership_messages, {'journey.message_min_players', journey.vote_minimum}) + end end local function get_activation_level(journey, surface, area) - local player_count_in_area = surface.count_entities_filtered({area = area, name = 'character'}) - local player_count_for_max_activation = math.max(#game.connected_players, journey.vote_minimum) * (2/3) - local level = player_count_in_area / player_count_for_max_activation - level = math.round(level, 2) - return level + local player_count_in_area = surface.count_entities_filtered({area = area, name = 'character'}) + local player_count_for_max_activation = math.max(#game.connected_players, journey.vote_minimum) * (2 / 3) + local level = player_count_in_area / player_count_for_max_activation + level = math.round(level, 2) + return level end local function animate_selectors(journey) - for k, world_selector in pairs(journey.world_selectors) do - local activation_level = journey.world_selectors[k].activation_level - if activation_level < 0.2 then activation_level = 0.2 end - if activation_level > 1 then activation_level = 1 end - for _, rectangle in pairs(world_selector.rectangles) do - local color = Constants.world_selector_colors[k] - rendering.set_color(rectangle, {r = color.r * activation_level, g = color.g * activation_level, b = color.b * activation_level, a = 255}) - end - end - local activation_level = journey.reroll_selector.activation_level - if activation_level < 0.2 then activation_level = 0.2 end - if activation_level > 1 then activation_level = 1 end - local color = Constants.reroll_selector_area_color - rendering.set_color(journey.reroll_selector.rectangle, {r = color.r * activation_level, g = color.g * activation_level, b = color.b * activation_level, a = 255}) + for k, world_selector in pairs(journey.world_selectors) do + local activation_level = journey.world_selectors[k].activation_level + if activation_level < 0.2 then + activation_level = 0.2 + end + if activation_level > 1 then + activation_level = 1 + end + for _, rectangle in pairs(world_selector.rectangles) do + local color = Constants.world_selector_colors[k] + rendering.set_color(rectangle, {r = color.r * activation_level, g = color.g * activation_level, b = color.b * activation_level, a = 255}) + end + end + local activation_level = journey.reroll_selector.activation_level + if activation_level < 0.2 then + activation_level = 0.2 + end + if activation_level > 1 then + activation_level = 1 + end + local color = Constants.reroll_selector_area_color + rendering.set_color(journey.reroll_selector.rectangle, {r = color.r * activation_level, g = color.g * activation_level, b = color.b * activation_level, a = 255}) end local function draw_background(journey, surface) - if journey.characters_in_mothership == 0 then return end - local speed = journey.mothership_speed - for c = 1, 16 * speed, 1 do - local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] - surface.create_entity({name = 'shotgun-pellet', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) - end - for c = 1, 16 * speed, 1 do - local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] - surface.create_entity({name = 'piercing-shotgun-pellet', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) - end - for c = 1, 2 * speed, 1 do - local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] - surface.create_entity({name = 'cannon-projectile', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) - end - for c = 1, 1 * speed, 1 do - local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] - surface.create_entity({name = 'uranium-cannon-projectile', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) - end - if math.random(1, 32) == 1 then - local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] - surface.create_entity({name = 'explosive-uranium-cannon-projectile', position = position, target = {position[1], position[2] + Constants.mothership_radius * 3}, speed = speed}) - end - if math.random(1, 90) == 1 then - local position_x = math.random(64, 160) - local position_y = math.random(64, 160) - if math.random(1, 2) == 1 then position_x = position_x * -1 end - if math.random(1, 2) == 1 then position_y = position_y * -1 end - surface.create_entity({name = 'big-worm-turret', position = {position_x, position_y}, force = 'enemy'}) - end + if journey.characters_in_mothership == 0 then + return + end + local speed = journey.mothership_speed + for c = 1, 16 * speed, 1 do + local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] + surface.create_entity({name = 'shotgun-pellet', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) + end + for c = 1, 16 * speed, 1 do + local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] + surface.create_entity({name = 'piercing-shotgun-pellet', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) + end + for c = 1, 2 * speed, 1 do + local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] + surface.create_entity({name = 'cannon-projectile', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) + end + for c = 1, 1 * speed, 1 do + local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] + surface.create_entity({name = 'uranium-cannon-projectile', position = position, target = {position[1], position[2] + Constants.mothership_radius * 2}, speed = speed}) + end + if math.random(1, 32) == 1 then + local position = Constants.particle_spawn_vectors[math.random(1, Constants.size_of_particle_spawn_vectors)] + surface.create_entity({name = 'explosive-uranium-cannon-projectile', position = position, target = {position[1], position[2] + Constants.mothership_radius * 3}, speed = speed}) + end + if math.random(1, 90) == 1 then + local position_x = math.random(64, 160) + local position_y = math.random(64, 160) + if math.random(1, 2) == 1 then + position_x = position_x * -1 + end + if math.random(1, 2) == 1 then + position_y = position_y * -1 + end + surface.create_entity({name = 'big-worm-turret', position = {position_x, position_y}, force = 'enemy'}) + end end local function roll_bonus_goods(journey, trait, amount) - local loot = Constants.unique_world_traits[trait].loot - local bonus_goods = {} - while #bonus_goods < (amount or 3) do - for key, numbers in pairs(loot) do - local loot_table = Constants.starter_goods_pool[key] - if #bonus_goods < (amount or 3) and math.random(numbers[1], numbers[2]) >= 1 then - - local item = loot_table[math.random(1, #loot_table)] - bonus_goods[#bonus_goods + 1] = {item[1], math.random(item[2], item[3])} - end - end - end - return bonus_goods + local loot = Constants.unique_world_traits[trait].loot + local bonus_goods = {} + while #bonus_goods < (amount or 3) do + for key, numbers in pairs(loot) do + local loot_table = Constants.starter_goods_pool[key] + if #bonus_goods < (amount or 3) and math.random(numbers[1], numbers[2]) >= 1 then + local item = loot_table[math.random(1, #loot_table)] + bonus_goods[#bonus_goods + 1] = {item[1], math.random(item[2], item[3])} + end + end + end + return bonus_goods end function Public.set_world_selectors(journey) - local surface = game.surfaces.mothership - local x = Constants.reroll_selector_area.left_top.x + 3.2 - journey.reroll_selector.texts = { - rendering.draw_text{ - text = journey.mothership_cargo.satellite .. ' x ', - surface = surface, - target = {x, Constants.reroll_selector_area.left_top.y - 1.5}, - color = {255, 255, 255, 255}, - scale = 1.5, - font = 'default-large-bold', - alignment = 'center', - scale_with_zoom = false, - }, - rendering.draw_sprite{ - sprite = 'item/satellite', - surface = surface, - y_scale = 1.5, - x_scale = 1.5, - target = {x + 1.6, Constants.reroll_selector_area.left_top.y - 1}, - }, - } + local surface = game.surfaces.mothership + local x = Constants.reroll_selector_area.left_top.x + 3.2 + journey.reroll_selector.texts = { + rendering.draw_text { + text = journey.mothership_cargo.satellite .. ' x ', + surface = surface, + target = {x, Constants.reroll_selector_area.left_top.y - 1.5}, + color = {255, 255, 255, 255}, + scale = 1.5, + font = 'default-large-bold', + alignment = 'center', + scale_with_zoom = false + }, + rendering.draw_sprite { + sprite = 'item/satellite', + surface = surface, + y_scale = 1.5, + x_scale = 1.5, + target = {x + 1.6, Constants.reroll_selector_area.left_top.y - 1} + } + } - local modifier_names = {} - for k, v in pairs(Constants.modifiers) do - if not v.static then - table.insert(modifier_names, k) - end - end + local modifier_names = {} + for k, v in pairs(Constants.modifiers) do + if not v.static then + table.insert(modifier_names, k) + end + end - local unique_world_traits = {} - for k, _ in pairs(Constants.unique_world_traits) do - table.insert(unique_world_traits, k) - end - table.shuffle_table(unique_world_traits) + local unique_world_traits = {} + for k, _ in pairs(Constants.unique_world_traits) do + table.insert(unique_world_traits, k) + end + table.shuffle_table(unique_world_traits) - for k, world_selector in pairs(journey.world_selectors) do - if not journey.importing then - table.shuffle_table(modifier_names) - world_selector.modifiers = {} - world_selector.bonus_goods = {} - world_selector.world_trait = unique_world_traits[k] - world_selector.fuel_requirement = math.random(25, 50) - end - local position = Constants.world_selector_areas[k].left_top - local texts = world_selector.texts - local modifiers = world_selector.modifiers - local y_modifier = -11.3 - local limits = {6, Constants.unique_world_traits[world_selector.world_trait].mods} - local counts = {0, 0} - local i = 1 - if journey.importing then goto skip_reroll end - while (limits[1] + limits[2] > counts[1] + counts[2]) and i < #modifier_names do - local modifier = modifier_names[i] - local data = Constants.modifiers[modifier] - local v - if journey.world_modifiers[modifier] >= data.max then - if data.dmin > 0 and counts[2] < limits[2] then - --at max, so we lower it as a positive modifier - v = math.floor(math.random(data.dmin, data.dmax) * -0.5) - counts[2] = counts[2] + 1 - modifiers[i] = {name = modifier, value = v, neg = false} - elseif data.dmin < 0 and counts[1] < limits[1] then - --at max, but it is good modifier, so lower it as negative modifier - v = math.floor(math.random(data.dmin, data.dmax)) - counts[1] = counts[1] + 1 - modifiers[i] = {name = modifier, value = v, neg = true} - end - elseif journey.world_modifiers[modifier] <= data.min then - if data.dmin < 0 and counts[1] < limits[1] then - --at min, but good to have it min, so we grow it as negative modifier - v = math.floor(math.random(data.dmin, data.dmax)) - counts[1] = counts[1] + 1 - modifiers[i] = {name = modifier, value = v, neg = true} - elseif data.dmin > 0 and counts[2] < limits[2] then - --at min, but min is bad, so we grow it as positive modifier - v = math.floor(math.random(data.dmin, data.dmax) * -0.5) - counts[2] = counts[2] + 1 - modifiers[i] = {name = modifier, value = v, neg = false} - end - else - --somewhere in middle, we first try to fill the positives then negatives. table is shuffled so it should be fine - if counts[2] < limits[2] then - v = math.floor(math.random(data.dmin, data.dmax) * -0.5) - counts[2] = counts[2] + 1 - modifiers[i] = {name = modifier, value = v, neg = false} - elseif counts[1] < limits[1] then - v = math.floor(math.random(data.dmin, data.dmax)) - counts[1] = counts[1] + 1 - modifiers[i] = {name = modifier, value = v, neg = true} - end - end - i = i + 1 - end - world_selector.bonus_goods = roll_bonus_goods(journey, world_selector.world_trait) - ::skip_reroll:: + for k, world_selector in pairs(journey.world_selectors) do + if not journey.importing then + table.shuffle_table(modifier_names) + world_selector.modifiers = {} + world_selector.bonus_goods = {} + world_selector.world_trait = unique_world_traits[k] + world_selector.fuel_requirement = math.random(25, 50) + end + local position = Constants.world_selector_areas[k].left_top + local texts = world_selector.texts + local modifiers = world_selector.modifiers + local y_modifier = -11.3 + local limits = {6, Constants.unique_world_traits[world_selector.world_trait].mods} + local counts = {0, 0} + local i = 1 + if journey.importing then + goto skip_reroll + end + while (limits[1] + limits[2] > counts[1] + counts[2]) and i < #modifier_names do + local modifier = modifier_names[i] + local data = Constants.modifiers[modifier] + local v + if journey.world_modifiers[modifier] >= data.max then + if data.dmin > 0 and counts[2] < limits[2] then + --at max, so we lower it as a positive modifier + v = math.floor(math.random(data.dmin, data.dmax) * -0.5) + counts[2] = counts[2] + 1 + modifiers[i] = {name = modifier, value = v, neg = false} + elseif data.dmin < 0 and counts[1] < limits[1] then + --at max, but it is good modifier, so lower it as negative modifier + v = math.floor(math.random(data.dmin, data.dmax)) + counts[1] = counts[1] + 1 + modifiers[i] = {name = modifier, value = v, neg = true} + end + elseif journey.world_modifiers[modifier] <= data.min then + if data.dmin < 0 and counts[1] < limits[1] then + --at min, but good to have it min, so we grow it as negative modifier + v = math.floor(math.random(data.dmin, data.dmax)) + counts[1] = counts[1] + 1 + modifiers[i] = {name = modifier, value = v, neg = true} + elseif data.dmin > 0 and counts[2] < limits[2] then + --at min, but min is bad, so we grow it as positive modifier + v = math.floor(math.random(data.dmin, data.dmax) * -0.5) + counts[2] = counts[2] + 1 + modifiers[i] = {name = modifier, value = v, neg = false} + end + else + --somewhere in middle, we first try to fill the positives then negatives. table is shuffled so it should be fine + if counts[2] < limits[2] then + v = math.floor(math.random(data.dmin, data.dmax) * -0.5) + counts[2] = counts[2] + 1 + modifiers[i] = {name = modifier, value = v, neg = false} + elseif counts[1] < limits[1] then + v = math.floor(math.random(data.dmin, data.dmax)) + counts[1] = counts[1] + 1 + modifiers[i] = {name = modifier, value = v, neg = true} + end + end + i = i + 1 + end + world_selector.bonus_goods = roll_bonus_goods(journey, world_selector.world_trait) + ::skip_reroll:: - table.insert(texts, rendering.draw_text{ - text = Constants.unique_world_traits[world_selector.world_trait].name, - surface = surface, - target = {position.x + Constants.world_selector_width * 0.5, position.y + y_modifier}, - color = {100, 0, 255, 255}, - scale = 1.25, - font = 'default-large-bold', - alignment = 'center', - scale_with_zoom = false - }) + table.insert( + texts, + rendering.draw_text { + text = Constants.unique_world_traits[world_selector.world_trait].name, + surface = surface, + target = {position.x + Constants.world_selector_width * 0.5, position.y + y_modifier}, + color = {100, 0, 255, 255}, + scale = 1.25, + font = 'default-large-bold', + alignment = 'center', + scale_with_zoom = false + } + ) - for k2, modifier in pairs(modifiers) do - y_modifier = y_modifier + 0.8 - local text = '' - if modifier.value > 0 then text = text .. '+' end - text = text .. modifier.value .. '% ' - text = text .. Constants.modifiers[modifier.name].name + for k2, modifier in pairs(modifiers) do + y_modifier = y_modifier + 0.8 + local text = '' + if modifier.value > 0 then + text = text .. '+' + end + text = text .. modifier.value .. '% ' + text = text .. Constants.modifiers[modifier.name].name - local color - if modifier.neg then - color = {200, 0, 0, 255} - else - color = {0, 200, 0, 255} - end + local color + if modifier.neg then + color = {200, 0, 0, 255} + else + color = {0, 200, 0, 255} + end - table.insert(texts, rendering.draw_text{ - text = text, - surface = surface, - target = {position.x + Constants.world_selector_width * 0.5, position.y + y_modifier}, - color = color, - scale = 1.25, - font = 'default-large', - alignment = 'center', - scale_with_zoom = false - }) - end + table.insert( + texts, + rendering.draw_text { + text = text, + surface = surface, + target = {position.x + Constants.world_selector_width * 0.5, position.y + y_modifier}, + color = color, + scale = 1.25, + font = 'default-large', + alignment = 'center', + scale_with_zoom = false + } + ) + end - y_modifier = y_modifier + 0.85 - table.insert(texts, rendering.draw_text{ - text = 'Fuel requirement +' .. world_selector.fuel_requirement, - surface = surface, - target = {position.x + Constants.world_selector_width * 0.5, position.y + y_modifier}, - color = {155, 155, 0, 255}, - scale = 1.25, - font = 'default-large', - alignment = 'center', - scale_with_zoom = false - }) - table.insert(texts, rendering.draw_sprite{ - sprite = 'item/uranium-fuel-cell', - surface = surface, - target = {position.x + Constants.world_selector_width * 0.5 + 3.7, position.y + y_modifier + 0.5}, - }) + y_modifier = y_modifier + 0.85 + table.insert( + texts, + rendering.draw_text { + text = 'Fuel requirement +' .. world_selector.fuel_requirement, + surface = surface, + target = {position.x + Constants.world_selector_width * 0.5, position.y + y_modifier}, + color = {155, 155, 0, 255}, + scale = 1.25, + font = 'default-large', + alignment = 'center', + scale_with_zoom = false + } + ) + table.insert( + texts, + rendering.draw_sprite { + sprite = 'item/uranium-fuel-cell', + surface = surface, + target = {position.x + Constants.world_selector_width * 0.5 + 3.7, position.y + y_modifier + 0.5} + } + ) - y_modifier = y_modifier + 1.1 - local x_modifier = -0.5 + y_modifier = y_modifier + 1.1 + local x_modifier = -0.5 - for k2, good in pairs(world_selector.bonus_goods) do - local render_id = rendering.draw_text{ - text = '+' .. good[2], - surface = surface, - target = {position.x + x_modifier, position.y + y_modifier}, - color = {200, 200, 0, 255}, - scale = 1.25, - font = 'default-large', - alignment = 'center', - scale_with_zoom = false - } - table.insert(texts, render_id) + for k2, good in pairs(world_selector.bonus_goods) do + local render_id = + rendering.draw_text { + text = '+' .. good[2], + surface = surface, + target = {position.x + x_modifier, position.y + y_modifier}, + color = {200, 200, 0, 255}, + scale = 1.25, + font = 'default-large', + alignment = 'center', + scale_with_zoom = false + } + table.insert(texts, render_id) - x_modifier = x_modifier + 0.95 - if good[2] >= 10 then x_modifier = x_modifier + 0.18 end - if good[2] >= 100 then x_modifier = x_modifier + 0.18 end + x_modifier = x_modifier + 0.95 + if good[2] >= 10 then + x_modifier = x_modifier + 0.18 + end + if good[2] >= 100 then + x_modifier = x_modifier + 0.18 + end - local render_id = rendering.draw_sprite{ - sprite = 'item/' .. good[1], - surface = surface, - target = {position.x + x_modifier, position.y + 0.5 + y_modifier}, - } - table.insert(texts, render_id) + local render_id = + rendering.draw_sprite { + sprite = 'item/' .. good[1], + surface = surface, + target = {position.x + x_modifier, position.y + 0.5 + y_modifier} + } + table.insert(texts, render_id) - x_modifier = x_modifier + 1.70 - end - end + x_modifier = x_modifier + 1.70 + end + end - destroy_teleporter(journey, game.surfaces.nauvis, Constants.mothership_teleporter_position) - destroy_teleporter(journey, surface, Constants.mothership_teleporter_position) - if journey.restart_from_scenario then - Public.restart_server(journey) - end - - Server.to_discord_embed('World ' .. journey.world_number + 1 .. ' selection has started!') - Public.set_minimum_to_vote(journey) - journey.importing = false + destroy_teleporter(journey, game.surfaces.nauvis, Constants.mothership_teleporter_position) + destroy_teleporter(journey, surface, Constants.mothership_teleporter_position) + if journey.restart_from_scenario then + Public.restart_server(journey) + end - journey.game_state = 'delete_nauvis_chunks' + Server.to_discord_embed('World ' .. journey.world_number + 1 .. ' selection has started!') + Public.set_minimum_to_vote(journey) + journey.importing = false + + journey.game_state = 'delete_nauvis_chunks' end function Public.delete_nauvis_chunks(journey) - local surface = game.surfaces.mothership - Public.teleport_players_to_mothership(journey) - draw_background(journey, surface) - if delete_nauvis_chunks(journey) then return end - for _, player in pairs(game.players) do - if player.gui.top.chunk_progress then player.gui.top.chunk_progress.destroy() end - end + local surface = game.surfaces.mothership + Public.teleport_players_to_mothership(journey) + draw_background(journey, surface) + if delete_nauvis_chunks(journey) then + return + end + for _, player in pairs(game.players) do + if player.gui.top.chunk_progress then + player.gui.top.chunk_progress.destroy() + end + end - journey.game_state = 'mothership_world_selection' + journey.game_state = 'mothership_world_selection' end function Public.reroll_worlds(journey) - local surface = game.surfaces.mothership - Public.teleport_players_to_mothership(journey) - draw_background(journey, surface) - animate_selectors(journey) - local reroll_selector_activation_level = get_activation_level(journey, surface, Constants.reroll_selector_area) - journey.reroll_selector.activation_level = reroll_selector_activation_level - for i = 1, 3, 1 do - local activation_level = get_activation_level(journey, surface, Constants.world_selector_areas[i]) - journey.world_selectors[i].activation_level = activation_level - end - if reroll_selector_activation_level > 1 then - journey.mothership_speed = journey.mothership_speed + 0.025 - if journey.mothership_speed > 4 then - journey.mothership_speed = 4 - clear_selectors(journey) - journey.mothership_cargo.satellite = journey.mothership_cargo.satellite - 1 - Public.draw_gui(journey) - table.insert(journey.mothership_messages, 'New lands have been discovered!') - journey.game_state = 'set_world_selectors' - end - else - journey.mothership_speed = journey.mothership_speed - 0.25 - if journey.mothership_speed < 0.35 then - table.insert(journey.mothership_messages, 'Aborting..') - journey.game_state = 'mothership_world_selection' - journey.mothership_speed = 0.35 - end - end + local surface = game.surfaces.mothership + Public.teleport_players_to_mothership(journey) + draw_background(journey, surface) + animate_selectors(journey) + local reroll_selector_activation_level = get_activation_level(journey, surface, Constants.reroll_selector_area) + journey.reroll_selector.activation_level = reroll_selector_activation_level + for i = 1, 3, 1 do + local activation_level = get_activation_level(journey, surface, Constants.world_selector_areas[i]) + journey.world_selectors[i].activation_level = activation_level + end + if reroll_selector_activation_level > 1 then + journey.mothership_speed = journey.mothership_speed + 0.025 + if journey.mothership_speed > 4 then + journey.mothership_speed = 4 + clear_selectors(journey) + journey.mothership_cargo.satellite = journey.mothership_cargo.satellite - 1 + Public.draw_gui(journey) + table.insert(journey.mothership_messages, 'New lands have been discovered!') + journey.game_state = 'set_world_selectors' + end + else + journey.mothership_speed = journey.mothership_speed - 0.25 + if journey.mothership_speed < 0.35 then + table.insert(journey.mothership_messages, 'Aborting..') + journey.game_state = 'mothership_world_selection' + journey.mothership_speed = 0.35 + end + end end function Public.importing_world(journey) - local surface = game.surfaces.mothership - Public.teleport_players_to_mothership(journey) - draw_background(journey, surface) - animate_selectors(journey) - clear_selectors(journey) - Public.update_tooltips(journey) - Public.draw_gui(journey) - table.insert(journey.mothership_messages, 'Restoring the last saved position...') - journey.game_state = 'set_world_selectors' + local surface = game.surfaces.mothership + Public.teleport_players_to_mothership(journey) + draw_background(journey, surface) + animate_selectors(journey) + clear_selectors(journey) + Public.update_tooltips(journey) + Public.draw_gui(journey) + table.insert(journey.mothership_messages, 'Restoring the last saved position...') + journey.game_state = 'set_world_selectors' end function Public.mothership_world_selection(journey) - Public.teleport_players_to_mothership(journey) - check_if_restarted(journey) - local surface = game.surfaces.mothership - local daytime = surface.daytime - daytime = daytime - 0.025 - if daytime < 0 then daytime = 0 end - surface.daytime = daytime + Public.teleport_players_to_mothership(journey) + check_if_restarted(journey) + local surface = game.surfaces.mothership + local daytime = surface.daytime + daytime = daytime - 0.025 + if daytime < 0 then + daytime = 0 + end + surface.daytime = daytime - local reroll_selector_activation_level = get_activation_level(journey, surface, Constants.reroll_selector_area) - journey.reroll_selector.activation_level = reroll_selector_activation_level + local reroll_selector_activation_level = get_activation_level(journey, surface, Constants.reroll_selector_area) + journey.reroll_selector.activation_level = reroll_selector_activation_level - if journey.emergency_triggered then - if not journey.emergency_selected then - journey.selected_world = math.random(1, 3) - table.insert(journey.mothership_messages, 'Emergency destination selected..') - journey.emergency_selected = true - end - else - journey.selected_world = false - for i = 1, 3, 1 do - local activation_level = get_activation_level(journey, surface, Constants.world_selector_areas[i]) - journey.world_selectors[i].activation_level = activation_level - if activation_level > 1 then - journey.selected_world = i - end - end - if reroll_selector_activation_level > 1 and journey.mothership_speed == 0.35 and journey.mothership_cargo.satellite > 0 then - journey.game_state = 'reroll_worlds' - table.insert(journey.mothership_messages, 'Dispatching satellite..') - return - end - end + if journey.emergency_triggered then + if not journey.emergency_selected then + journey.selected_world = math.random(1, 3) + table.insert(journey.mothership_messages, 'Emergency destination selected..') + journey.emergency_selected = true + end + else + journey.selected_world = false + for i = 1, 3, 1 do + local activation_level = get_activation_level(journey, surface, Constants.world_selector_areas[i]) + journey.world_selectors[i].activation_level = activation_level + if activation_level > 1 then + journey.selected_world = i + end + end + if reroll_selector_activation_level > 1 and journey.mothership_speed == 0.35 and journey.mothership_cargo.satellite > 0 then + journey.game_state = 'reroll_worlds' + table.insert(journey.mothership_messages, 'Dispatching satellite..') + return + end + end - if journey.selected_world then - if not journey.mothership_advancing_to_world then - table.insert(journey.mothership_messages, 'Advancing to selected world.') - journey.mothership_advancing_to_world = game.tick + math.random(60 * 45, 60 * 75) - else - local seconds_left = math.floor((journey.mothership_advancing_to_world - game.tick) / 60) - if seconds_left <= 0 then - journey.mothership_advancing_to_world = false - table.insert(journey.mothership_messages, 'Arriving at targeted destination!') - journey.game_state = 'mothership_arrives_at_world' - return - end - if seconds_left % 15 == 0 then table.insert(journey.mothership_messages, 'Estimated arrival in ' .. seconds_left .. ' seconds.') end - end + if journey.selected_world then + if not journey.mothership_advancing_to_world then + table.insert(journey.mothership_messages, 'Advancing to selected world.') + journey.mothership_advancing_to_world = game.tick + math.random(60 * 45, 60 * 75) + else + local seconds_left = math.floor((journey.mothership_advancing_to_world - game.tick) / 60) + if seconds_left <= 0 then + journey.mothership_advancing_to_world = false + table.insert(journey.mothership_messages, 'Arriving at targeted destination!') + journey.game_state = 'mothership_arrives_at_world' + return + end + if seconds_left % 15 == 0 then + table.insert(journey.mothership_messages, 'Estimated arrival in ' .. seconds_left .. ' seconds.') + end + end - journey.mothership_speed = journey.mothership_speed + 0.1 - if journey.mothership_speed > 4 then journey.mothership_speed = 4 end - else - if journey.mothership_advancing_to_world then - table.insert(journey.mothership_messages, 'Aborting travelling sequence.') - journey.mothership_advancing_to_world = false - end - journey.mothership_speed = journey.mothership_speed - 0.25 - if journey.mothership_speed < 0.35 then journey.mothership_speed = 0.35 end - end + journey.mothership_speed = journey.mothership_speed + 0.1 + if journey.mothership_speed > 4 then + journey.mothership_speed = 4 + end + else + if journey.mothership_advancing_to_world then + table.insert(journey.mothership_messages, 'Aborting travelling sequence.') + journey.mothership_advancing_to_world = false + end + journey.mothership_speed = journey.mothership_speed - 0.25 + if journey.mothership_speed < 0.35 then + journey.mothership_speed = 0.35 + end + end - draw_background(journey, surface) - animate_selectors(journey) - Public.update_tooltips(journey) + draw_background(journey, surface) + animate_selectors(journey) + Public.update_tooltips(journey) end function Public.mothership_arrives_at_world(journey) - local surface = game.surfaces.mothership + local surface = game.surfaces.mothership - Public.teleport_players_to_mothership(journey) + Public.teleport_players_to_mothership(journey) - if journey.mothership_speed == 0.15 then - for _ = 1, 16, 1 do table.insert(journey.mothership_messages, '') end - table.insert(journey.mothership_messages, '[img=item/uranium-fuel-cell] Fuel cells depleted ;_;') - for _ = 1, 16, 1 do table.insert(journey.mothership_messages, '') end - table.insert(journey.mothership_messages, 'Refuel via supply rocket required!') + if journey.mothership_speed == 0.15 then + for _ = 1, 16, 1 do + table.insert(journey.mothership_messages, '') + end + table.insert(journey.mothership_messages, '[img=item/uranium-fuel-cell] Fuel cells depleted ;_;') + for _ = 1, 16, 1 do + table.insert(journey.mothership_messages, '') + end + table.insert(journey.mothership_messages, 'Refuel via supply rocket required!') - for i = 1, 3, 1 do - journey.world_selectors[i].activation_level = 0 - end - animate_selectors(journey) + for i = 1, 3, 1 do + journey.world_selectors[i].activation_level = 0 + end + animate_selectors(journey) - journey.game_state = 'clear_modifiers' - else - journey.mothership_speed = journey.mothership_speed - 0.15 - end + journey.game_state = 'clear_modifiers' + else + journey.mothership_speed = journey.mothership_speed - 0.15 + end - if journey.mothership_speed < 0.15 then - journey.mothership_speed = 0.15 - end - journey.beacon_objective_resistance = 0.90 - (0.03 * journey.world_number) - journey.emergency_triggered = false - journey.emergency_selected = false - journey.import_checked = false - draw_background(journey, surface) - Public.update_tooltips(journey) + if journey.mothership_speed < 0.15 then + journey.mothership_speed = 0.15 + end + journey.beacon_objective_resistance = 0.90 - (0.03 * journey.world_number) + journey.emergency_triggered = false + journey.emergency_selected = false + journey.import_checked = false + draw_background(journey, surface) + Public.update_tooltips(journey) end function Public.clear_modifiers(journey) - local unique_modifier = Unique_modifiers[journey.world_trait] - local clear = unique_modifier.clear - if clear then clear(journey) end - journey.world_specials = {} - local force = game.forces.player - force.reset() - force.reset_technologies() - force.reset_technology_effects() - for a = 1, 7, 1 do force.technologies['refined-flammables-' .. a].enabled = false end - journey.game_state = 'create_the_world' - Public.update_tooltips(journey) + local unique_modifier = Unique_modifiers[journey.world_trait] + local clear = unique_modifier.clear + if clear then + clear(journey) + end + journey.world_specials = {} + local force = game.forces.player + force.reset() + force.reset_technologies() + force.reset_technology_effects() + for a = 1, 7, 1 do + force.technologies['refined-flammables-' .. a].enabled = false + end + journey.game_state = 'create_the_world' + Public.update_tooltips(journey) end function Public.create_the_world(journey) - local surface = game.surfaces.nauvis - local mgs = surface.map_gen_settings - mgs.seed = math.random(1, 4294967295) - mgs.terrain_segmentation = math.random(10, 20) * 0.1 - mgs.peaceful_mode = false + local surface = game.surfaces.nauvis + local mgs = surface.map_gen_settings + mgs.seed = math.random(1, 4294967295) + mgs.terrain_segmentation = math.random(10, 20) * 0.1 + mgs.peaceful_mode = false - local modifiers = journey.world_selectors[journey.selected_world].modifiers - for _, modifier in pairs(modifiers) do - local m = (100 + modifier.value) * 0.01 - local name = modifier.name - local extremes = {Constants.modifiers[name].min, Constants.modifiers[name].max} - journey.world_modifiers[name] = math.round(math.min(extremes[2], math.max(extremes[1], journey.world_modifiers[name] * m)) * 100000, 5) / 100000 - end - surface.map_gen_settings = mgs - journey.world_trait = journey.world_selectors[journey.selected_world].world_trait + local modifiers = journey.world_selectors[journey.selected_world].modifiers + for _, modifier in pairs(modifiers) do + local m = (100 + modifier.value) * 0.01 + local name = modifier.name + local extremes = {Constants.modifiers[name].min, Constants.modifiers[name].max} + journey.world_modifiers[name] = math.round(math.min(extremes[2], math.max(extremes[1], journey.world_modifiers[name] * m)) * 100000, 5) / 100000 + end + surface.map_gen_settings = mgs + journey.world_trait = journey.world_selectors[journey.selected_world].world_trait - local unique_modifier = Unique_modifiers[journey.world_trait] - local set_specials = unique_modifier.set_specials - if set_specials then set_specials(journey) end - set_map_modifiers(journey) - surface.clear(false) + local unique_modifier = Unique_modifiers[journey.world_trait] + local set_specials = unique_modifier.set_specials + if set_specials then + set_specials(journey) + end + set_map_modifiers(journey) + surface.clear(false) + journey.nauvis_chunk_positions = nil + journey.rocket_silos = {} + journey.mothership_cargo['uranium-fuel-cell'] = 0 + journey.world_number = journey.world_number + 1 + local max_satellites = math_floor(journey.world_number * 0.334) + 1 + if max_satellites > Constants.max_satellites then + max_satellites = Constants.max_satellites + end + journey.mothership_cargo_space['satellite'] = max_satellites + journey.mothership_cargo_space['uranium-fuel-cell'] = journey.mothership_cargo_space['uranium-fuel-cell'] + journey.world_selectors[journey.selected_world].fuel_requirement - journey.nauvis_chunk_positions = nil - journey.rocket_silos = {} - journey.mothership_cargo['uranium-fuel-cell'] = 0 - journey.world_number = journey.world_number + 1 - local max_satellites = math_floor(journey.world_number * 0.334) + 1 - if max_satellites > Constants.max_satellites then - max_satellites = Constants.max_satellites - end - journey.mothership_cargo_space['satellite'] = max_satellites - journey.mothership_cargo_space['uranium-fuel-cell'] = journey.mothership_cargo_space['uranium-fuel-cell'] + journey.world_selectors[journey.selected_world].fuel_requirement + game.forces.enemy.reset_evolution() - game.forces.enemy.reset_evolution() - - for _, good in pairs(journey.world_selectors[journey.selected_world].bonus_goods) do - if journey.bonus_goods[good[1]] then - journey.bonus_goods[good[1]] = journey.bonus_goods[good[1]] + good[2] - else - journey.bonus_goods[good[1]] = good[2] - end - end - journey.goods_to_dispatch = {} - for k, v in pairs(journey.bonus_goods) do table.insert(journey.goods_to_dispatch, {k, v}) end - table.shuffle_table(journey.goods_to_dispatch) - Public.update_tooltips(journey) - journey.game_state = 'wipe_offline_players' + for _, good in pairs(journey.world_selectors[journey.selected_world].bonus_goods) do + if journey.bonus_goods[good[1]] then + journey.bonus_goods[good[1]] = journey.bonus_goods[good[1]] + good[2] + else + journey.bonus_goods[good[1]] = good[2] + end + end + journey.goods_to_dispatch = {} + for k, v in pairs(journey.bonus_goods) do + table.insert(journey.goods_to_dispatch, {k, v}) + end + table.shuffle_table(journey.goods_to_dispatch) + Public.update_tooltips(journey) + journey.game_state = 'wipe_offline_players' end function Public.wipe_offline_players(journey) - remove_offline_players(96) - for _, player in pairs(game.players) do - if not player.connected then - player.force = game.forces.enemy - end - end - journey.game_state = 'set_unique_modifiers' + remove_offline_players(96) + for _, player in pairs(game.players) do + if not player.connected then + player.force = game.forces.enemy + end + end + journey.game_state = 'set_unique_modifiers' end function Public.notify_discord(journey) - if journey.disable_discord_notifications then - return - end - local caption = 'World ' .. journey.world_number .. ' | ' .. Constants.unique_world_traits[journey.world_trait].name - local modifier_message = '' - for _, mod in pairs(journey.world_selectors[journey.selected_world].modifiers) do - local sign = '' - if mod.value > 0 then sign = '+' end - modifier_message = modifier_message .. sign .. mod.value .. '% ' .. mod.name .. '\n' - end - local capsules = '' - for _, cap in pairs(journey.world_selectors[journey.selected_world].bonus_goods) do - capsules = capsules .. cap[2] .. 'x ' .. cap[1] .. '\n' - end - local message = { - title = 'World advanced', - description = 'Arriving at target destination!', - color = 'warning', - field1 = { - text1 = 'World level:', - text2 = caption, - inline = 'true' - }, - field2 = { - text1 = 'World description:', - text2 = Constants.unique_world_traits[journey.world_trait].desc, - inline = 'true' - }, - field3 = { - text1 = 'Satellites in mothership cargo:', - text2 = journey.mothership_cargo['satellite'] .. ' / ' .. journey.mothership_cargo_space['satellite'], - inline = 'false' - }, - field4 = { - text1 = 'Modifiers changed:', - text2 = modifier_message, - inline = 'false' - }, - field5 = { - text1 = 'Capsules gained:', - text2 = capsules, - inline = 'false' - } - } - Server.to_discord_embed_parsed(message) + if journey.disable_discord_notifications then + return + end + local caption = 'World ' .. journey.world_number .. ' | ' .. Constants.unique_world_traits[journey.world_trait].name + local modifier_message = '' + for _, mod in pairs(journey.world_selectors[journey.selected_world].modifiers) do + local sign = '' + if mod.value > 0 then + sign = '+' + end + modifier_message = modifier_message .. sign .. mod.value .. '% ' .. mod.name .. '\n' + end + local capsules = '' + for _, cap in pairs(journey.world_selectors[journey.selected_world].bonus_goods) do + capsules = capsules .. cap[2] .. 'x ' .. cap[1] .. '\n' + end + local message = { + title = 'World advanced', + description = 'Arriving at target destination!', + color = 'warning', + field1 = { + text1 = 'World level:', + text2 = caption, + inline = 'true' + }, + field2 = { + text1 = 'World description:', + text2 = Constants.unique_world_traits[journey.world_trait].desc, + inline = 'true' + }, + field3 = { + text1 = 'Satellites in mothership cargo:', + text2 = journey.mothership_cargo['satellite'] .. ' / ' .. journey.mothership_cargo_space['satellite'], + inline = 'false' + }, + field4 = { + text1 = 'Modifiers changed:', + text2 = modifier_message, + inline = 'false' + }, + field5 = { + text1 = 'Capsules gained:', + text2 = capsules, + inline = 'false' + } + } + Server.to_discord_embed_parsed(message) end - function Public.set_unique_modifiers(journey) - local unique_modifier = Unique_modifiers[journey.world_trait] - local on_world_start = unique_modifier.on_world_start - if on_world_start then on_world_start(journey) end - Public.update_tooltips(journey) - Public.draw_gui(journey) - Public.notify_discord(journey) - journey.game_state = 'place_teleporter_into_world' + local unique_modifier = Unique_modifiers[journey.world_trait] + local on_world_start = unique_modifier.on_world_start + if on_world_start then + on_world_start(journey) + end + Public.update_tooltips(journey) + Public.draw_gui(journey) + Public.notify_discord(journey) + journey.game_state = 'place_teleporter_into_world' end function Public.place_teleporter_into_world(journey) - local surface = game.surfaces.nauvis - surface.request_to_generate_chunks({x = 0, y = 0}, 3) - surface.force_generate_chunk_requests() - place_teleporter(journey, surface, Constants.mothership_teleporter_position, true) - journey.game_state = 'make_it_night' + local surface = game.surfaces.nauvis + surface.request_to_generate_chunks({x = 0, y = 0}, 3) + surface.force_generate_chunk_requests() + place_teleporter(journey, surface, Constants.mothership_teleporter_position, true) + journey.game_state = 'make_it_night' end function Public.make_it_night(journey) - draw_background(journey, game.surfaces.mothership) - local surface = game.surfaces.mothership - local daytime = surface.daytime - daytime = daytime + 0.02 - surface.daytime = daytime - if daytime > 0.5 then - clear_selectors(journey) - game.reset_time_played() - place_teleporter(journey, surface, Constants.mothership_teleporter_position, false) - table.insert(journey.mothership_messages, 'Teleporter deployed. [gps=' .. Constants.mothership_teleporter_position.x .. ',' .. Constants.mothership_teleporter_position.y .. ',mothership]') - journey.game_state = 'dispatch_goods' - end + draw_background(journey, game.surfaces.mothership) + local surface = game.surfaces.mothership + local daytime = surface.daytime + daytime = daytime + 0.02 + surface.daytime = daytime + if daytime > 0.5 then + clear_selectors(journey) + game.reset_time_played() + place_teleporter(journey, surface, Constants.mothership_teleporter_position, false) + table.insert(journey.mothership_messages, 'Teleporter deployed. [gps=' .. Constants.mothership_teleporter_position.x .. ',' .. Constants.mothership_teleporter_position.y .. ',mothership]') + journey.game_state = 'dispatch_goods' + end end function Public.dispatch_goods(journey) - draw_background(journey, game.surfaces.mothership) + draw_background(journey, game.surfaces.mothership) - if journey.characters_in_mothership == #game.connected_players then return end + if journey.characters_in_mothership == #game.connected_players then + return + end - local goods_to_dispatch = journey.goods_to_dispatch - local size_of_goods_to_dispatch = #goods_to_dispatch - if size_of_goods_to_dispatch == 0 then - for _ = 1, 30, 1 do table.insert(journey.mothership_messages, '') end - table.insert(journey.mothership_messages, 'Capsule storage depleted.') - for _ = 1, 30, 1 do table.insert(journey.mothership_messages, '') end - table.insert(journey.mothership_messages, 'Good luck on your adventure! ^.^') - journey.game_state = 'world' - return - end + local goods_to_dispatch = journey.goods_to_dispatch + local size_of_goods_to_dispatch = #goods_to_dispatch + if size_of_goods_to_dispatch == 0 then + for _ = 1, 30, 1 do + table.insert(journey.mothership_messages, '') + end + table.insert(journey.mothership_messages, 'Capsule storage depleted.') + for _ = 1, 30, 1 do + table.insert(journey.mothership_messages, '') + end + table.insert(journey.mothership_messages, 'Good luck on your adventure! ^.^') + journey.game_state = 'world' + return + end - if journey.dispatch_beacon and journey.dispatch_beacon.valid then return end + if journey.dispatch_beacon and journey.dispatch_beacon.valid then + return + end - local surface = game.surfaces.nauvis + local surface = game.surfaces.nauvis - if journey.dispatch_beacon_position then - local good = goods_to_dispatch[journey.dispatch_key] - surface.spill_item_stack(journey.dispatch_beacon_position, {name = good[1], count = good[2]}, true, nil, false) - table.remove(journey.goods_to_dispatch, journey.dispatch_key) - journey.dispatch_beacon = nil - journey.dispatch_beacon_position = nil - journey.dispatch_key = nil - return - end + if journey.dispatch_beacon_position then + local good = goods_to_dispatch[journey.dispatch_key] + surface.spill_item_stack(journey.dispatch_beacon_position, {name = good[1], count = good[2]}, true, nil, false) + table.remove(journey.goods_to_dispatch, journey.dispatch_key) + journey.dispatch_beacon = nil + journey.dispatch_beacon_position = nil + journey.dispatch_key = nil + return + end - local chunk = surface.get_random_chunk() - if math.abs(chunk.x) > 4 or math.abs(chunk.y) > 4 then return end + local chunk = surface.get_random_chunk() + if math.abs(chunk.x) > 4 or math.abs(chunk.y) > 4 then + return + end - local position = {x = chunk.x * 32 + math.random(0, 31), y = chunk.y * 32 + math.random(0, 31)} - position = surface.find_non_colliding_position('rocket-silo', position, 32, 1) - if not position then return end + local position = {x = chunk.x * 32 + math.random(0, 31), y = chunk.y * 32 + math.random(0, 31)} + position = surface.find_non_colliding_position('rocket-silo', position, 32, 1) + if not position then + return + end - journey.dispatch_beacon = surface.create_entity({name = 'stone-wall', position = position, force = 'neutral'}) - journey.dispatch_beacon.minable = false - journey.dispatch_beacon_position = {x = position.x, y = position.y} - journey.dispatch_key = math.random(1, size_of_goods_to_dispatch) + journey.dispatch_beacon = surface.create_entity({name = 'stone-wall', position = position, force = 'neutral'}) + journey.dispatch_beacon.minable = false + journey.dispatch_beacon_position = {x = position.x, y = position.y} + journey.dispatch_key = math.random(1, size_of_goods_to_dispatch) - local good = goods_to_dispatch[journey.dispatch_key] - table.insert(journey.mothership_messages, 'Capsule containing ' .. good[2] .. 'x [img=item/' .. good[1] .. '] dispatched. [gps=' .. position.x .. ',' .. position.y .. ',nauvis]') - if journey.announce_capsules then - Server.to_discord_embed('A capsule containing ' .. good[2] .. 'x ' .. good[1] .. ' was spotted at: x=' .. position.x .. ', y=' .. position.y .. '!') - end + local good = goods_to_dispatch[journey.dispatch_key] + table.insert(journey.mothership_messages, 'Capsule containing ' .. good[2] .. 'x [img=item/' .. good[1] .. '] dispatched. [gps=' .. position.x .. ',' .. position.y .. ',nauvis]') + if journey.announce_capsules then + Server.to_discord_embed('A capsule containing ' .. good[2] .. 'x ' .. good[1] .. ' was spotted at: x=' .. position.x .. ', y=' .. position.y .. '!') + end - surface.create_entity({name = 'artillery-projectile', position = {x = position.x - 256 + math.random(0, 512), y = position.y - 256}, target = position, speed = 0.2}) + surface.create_entity({name = 'artillery-projectile', position = {x = position.x - 256 + math.random(0, 512), y = position.y - 256}, target = position, speed = 0.2}) end function Public.world(journey) - if journey.mothership_cargo['uranium-fuel-cell'] then - if journey.mothership_cargo['uranium-fuel-cell'] >= journey.mothership_cargo_space['uranium-fuel-cell'] then - table.insert(journey.mothership_messages, '[img=item/uranium-fuel-cell] Refuel operation successful!! =^.^=') - Server.to_discord_embed('Refuel operation complete!') - journey.game_state = 'mothership_waiting_for_players' - end - end - draw_background(journey, game.surfaces.mothership) - if journey.speedrun.enabled then - local item = journey.speedrun.item - local time = math.round(journey.speedrun.time / 6) / 10 - if journey.mothership_cargo[item] and journey.mothership_cargo[item] >= journey.mothership_cargo_space[item] then - local amount = 6 - local brackets = {120, 120, 240, 480, 960, 1920} - local timer = time - for i = 1, 6, 1 do - if timer >= brackets[i] then - timer = timer - brackets[i] - amount = amount - 1 - else - break - end - end - table.insert(journey.mothership_messages, {'journey.message_delivery_done', item, time, amount}) - Server.to_discord_embed({'journey.message_delivery_done', item, time, amount}, true) - local bonus_goods = roll_bonus_goods(journey, 'resupply_station', amount) - for _, good in pairs(bonus_goods) do - if journey.bonus_goods[good[1]] then - journey.bonus_goods[good[1]] = journey.bonus_goods[good[1]] + good[2] - else - journey.bonus_goods[good[1]] = good[2] - end - table.insert(journey.mothership_messages, {'journey.message_delivered', good[1], good[2]}) - end - Public.update_tooltips(journey) - journey.speedrun.enabled = false - end - if game.tick % 60 == 0 then - journey.speedrun.time = journey.speedrun.time + 1 - time = math.round(journey.speedrun.time / 6) / 10 - local speedgoal = journey.mothership_cargo_space[item] or 1 - local value = (journey.mothership_cargo[item] or 0) / speedgoal - cargo_gui('journey_delivery', item, {'journey.tooltip_delivery', journey.mothership_cargo[item] or 0, speedgoal, time}, value) - end - end + if journey.mothership_cargo['uranium-fuel-cell'] then + if journey.mothership_cargo['uranium-fuel-cell'] >= journey.mothership_cargo_space['uranium-fuel-cell'] then + table.insert(journey.mothership_messages, '[img=item/uranium-fuel-cell] Refuel operation successful!! =^.^=') + Server.to_discord_embed('Refuel operation complete!') + journey.game_state = 'mothership_waiting_for_players' + end + end + draw_background(journey, game.surfaces.mothership) + if journey.speedrun.enabled then + local item = journey.speedrun.item + local time = math.round(journey.speedrun.time / 6) / 10 + if journey.mothership_cargo[item] and journey.mothership_cargo[item] >= journey.mothership_cargo_space[item] then + local amount = 6 + local brackets = {120, 120, 240, 480, 960, 1920} + local timer = time + for i = 1, 6, 1 do + if timer >= brackets[i] then + timer = timer - brackets[i] + amount = amount - 1 + else + break + end + end + table.insert(journey.mothership_messages, {'journey.message_delivery_done', item, time, amount}) + Server.to_discord_embed({'journey.message_delivery_done', item, time, amount}, true) + local bonus_goods = roll_bonus_goods(journey, 'resupply_station', amount) + for _, good in pairs(bonus_goods) do + if journey.bonus_goods[good[1]] then + journey.bonus_goods[good[1]] = journey.bonus_goods[good[1]] + good[2] + else + journey.bonus_goods[good[1]] = good[2] + end + table.insert(journey.mothership_messages, {'journey.message_delivered', good[1], good[2]}) + end + Public.update_tooltips(journey) + journey.speedrun.enabled = false + end + if game.tick % 60 == 0 then + journey.speedrun.time = journey.speedrun.time + 1 + time = math.round(journey.speedrun.time / 6) / 10 + local speedgoal = journey.mothership_cargo_space[item] or 1 + local value = (journey.mothership_cargo[item] or 0) / speedgoal + cargo_gui('journey_delivery', item, {'journey.tooltip_delivery', journey.mothership_cargo[item] or 0, speedgoal, time}, value) + end + end - if game.tick % 1800 ~= 0 then return end - for k, silo in pairs(journey.rocket_silos) do - if not silo or not silo.valid then - table.remove(journey.rocket_silos, k) - break - end - local inventory = silo.get_inventory(defines.inventory.rocket_silo_rocket) or {} - local slot = inventory[1] - if slot and slot.valid and slot.valid_for_read then - local name = slot.name - local count = slot.count - local needs = (journey.mothership_cargo_space[name] or 0) - (journey.mothership_cargo[name] or 0) - if needs > 0 and count >= math.min(game.item_prototypes[name].stack_size, needs) then - if silo.launch_rocket() then - table.insert(journey.mothership_messages, {'journey.message_rocket_launched', count, name, silo.position.x, silo.position.y}) - end - end - end - end + if game.tick % 1800 ~= 0 then + return + end + for k, silo in pairs(journey.rocket_silos) do + if not silo or not silo.valid then + table.remove(journey.rocket_silos, k) + break + end + local inventory = silo.get_inventory(defines.inventory.rocket_silo_rocket) or {} + local slot = inventory[1] + if slot and slot.valid and slot.valid_for_read then + local name = slot.name + local count = slot.count + local needs = (journey.mothership_cargo_space[name] or 0) - (journey.mothership_cargo[name] or 0) + if needs > 0 and count >= math.min(game.item_prototypes[name].stack_size, needs) then + if silo.launch_rocket() then + table.insert(journey.mothership_messages, {'journey.message_rocket_launched', count, name, silo.position.x, silo.position.y}) + end + end + end + end end function Public.mothership_waiting_for_players(journey) - if journey.characters_in_mothership > #game.connected_players * 0.5 then - journey.game_state = 'set_world_selectors' - Vacants.reset() - return - end + if journey.characters_in_mothership > #game.connected_players * 0.5 then + journey.game_state = 'set_world_selectors' + Vacants.reset() + return + end - if math.random(1, 2) == 1 then return end - local tick = game.tick % 3600 - if tick == 0 then - local messages = Constants.mothership_messages.waiting - table.insert(journey.mothership_messages, messages[math.random(1, #messages)]) - end + if math.random(1, 2) == 1 then + return + end + local tick = game.tick % 3600 + if tick == 0 then + local messages = Constants.mothership_messages.waiting + table.insert(journey.mothership_messages, messages[math.random(1, #messages)]) + end end function Public.teleporters(journey, player) - if not player.character then return end - if not player.character.valid then return end - local surface = player.surface - local tile = surface.get_tile(player.position) - if tile.name ~= Constants.teleporter_tile and tile.hidden_tile ~= Constants.teleporter_tile then return end - local base_position = {0,0} - if surface.index == 1 then - drop_player_items(journey, player) - local position = game.surfaces.mothership.find_non_colliding_position('character', base_position, 32, 0.5) - if position then - player.teleport(position, game.surfaces.mothership) - else - player.teleport(base_position, game.surfaces.mothership) - end - journey.characters_in_mothership = journey.characters_in_mothership + 1 - return - end - if surface.name == 'mothership' then - Public.clear_player(player) - local position = game.surfaces.nauvis.find_non_colliding_position('character', base_position, 32, 0.5) - if position then - player.teleport(position, game.surfaces.nauvis) - else - player.teleport(base_position, game.surfaces.nauvis) - end + if not player.character then + return + end + if not player.character.valid then + return + end + local surface = player.surface + local tile = surface.get_tile(player.position) + if tile.name ~= Constants.teleporter_tile and tile.hidden_tile ~= Constants.teleporter_tile then + return + end + local base_position = {0, 0} + if surface.index == 1 then + drop_player_items(journey, player) + local position = game.surfaces.mothership.find_non_colliding_position('character', base_position, 32, 0.5) + if position then + player.teleport(position, game.surfaces.mothership) + else + player.teleport(base_position, game.surfaces.mothership) + end + journey.characters_in_mothership = journey.characters_in_mothership + 1 + return + end + if surface.name == 'mothership' then + Public.clear_player(player) + local position = game.surfaces.nauvis.find_non_colliding_position('character', base_position, 32, 0.5) + if position then + player.teleport(position, game.surfaces.nauvis) + else + player.teleport(base_position, game.surfaces.nauvis) + end - journey.characters_in_mothership = journey.characters_in_mothership - 1 - return - end + journey.characters_in_mothership = journey.characters_in_mothership - 1 + return + end end function Public.deal_damage_to_beacon(journey, incoming_damage) - if journey.game_state ~= 'world' then return end - local resistance = journey.beacon_objective_resistance - journey.beacon_objective_health = math.floor(journey.beacon_objective_health - (incoming_damage * (1 - resistance))) - rendering.set_text(journey.beacon_objective_hp_label, {'journey.beacon_hp', journey.beacon_objective_health}) - if journey.beacon_objective_health < 5000 and game.tick > journey.mothership_messages_last_damage + 900 then --under 50%, once every 15 seconds max - table.insert(journey.mothership_messages, 'The personal teleporter is being damaged, preparing for emergency departure.') - journey.mothership_messages_last_damage = game.tick - end - if journey.beacon_objective_health <= 0 then - table.insert(journey.mothership_messages, 'Beaming everyone up, triggerring emergency departure.') - table.insert(journey.mothership_messages, '[img=item/nuclear-reactor] Emergency power plant burned down ;_;') - journey.mothership_cargo['nuclear-reactor'] = journey.mothership_cargo['nuclear-reactor'] - 30 - if journey.mothership_cargo['nuclear-reactor'] < 0 then - table.insert(journey.mothership_messages, 'Aborting, there is not enough emergency fuel. Shutting systems off...') - for _ = 1, #journey.mothership_messages, 1 do - Public.mothership_message_queue(journey) - end - Public.hard_reset(journey) - else - journey.emergency_triggered = true - journey.game_state = 'set_world_selectors' - Public.update_tooltips(journey) - Public.draw_gui(journey) - end - end + if journey.game_state ~= 'world' then + return + end + local resistance = journey.beacon_objective_resistance + journey.beacon_objective_health = math.floor(journey.beacon_objective_health - (incoming_damage * (1 - resistance))) + rendering.set_text(journey.beacon_objective_hp_label, {'journey.beacon_hp', journey.beacon_objective_health}) + if journey.beacon_objective_health < 5000 and game.tick > journey.mothership_messages_last_damage + 900 then --under 50%, once every 15 seconds max + table.insert(journey.mothership_messages, 'The personal teleporter is being damaged, preparing for emergency departure.') + journey.mothership_messages_last_damage = game.tick + end + if journey.beacon_objective_health <= 0 then + table.insert(journey.mothership_messages, 'Beaming everyone up, triggerring emergency departure.') + table.insert(journey.mothership_messages, '[img=item/nuclear-reactor] Emergency power plant burned down ;_;') + journey.mothership_cargo['nuclear-reactor'] = journey.mothership_cargo['nuclear-reactor'] - 30 + if journey.mothership_cargo['nuclear-reactor'] < 0 then + table.insert(journey.mothership_messages, 'Aborting, there is not enough emergency fuel. Shutting systems off...') + for _ = 1, #journey.mothership_messages, 1 do + Public.mothership_message_queue(journey) + end + Public.hard_reset(journey) + else + journey.emergency_triggered = true + journey.game_state = 'set_world_selectors' + Public.update_tooltips(journey) + Public.draw_gui(journey) + end + end end function Public.lure_biters(journey, position) - if journey.game_state ~= 'world' or not journey.beacon_objective.valid then return end - local beacon = journey.beacon_objective - local surface = beacon.surface - local biters = surface.find_entities_filtered{position = position or beacon.position, radius = 80, force = 'enemy', type = 'unit'} - if #biters > 0 then - for _, biter in pairs(biters) do - biter.set_command({type = defines.command.attack_area, destination = beacon.position, radius = 10, distraction = defines.distraction.by_anything}) - end - end - --return (#biters or 0) + if journey.game_state ~= 'world' or not journey.beacon_objective.valid then + return + end + local beacon = journey.beacon_objective + local surface = beacon.surface + local biters = surface.find_entities_filtered {position = position or beacon.position, radius = 80, force = 'enemy', type = 'unit'} + if #biters > 0 then + for _, biter in pairs(biters) do + biter.set_command({type = defines.command.attack_area, destination = beacon.position, radius = 10, distraction = defines.distraction.by_anything}) + end + end + --return (#biters or 0) end function Public.lure_far_biters(journey) - -- if journey.game_state ~= 'world' or not journey.beacon_objective.valid then return end - -- if journey.beacon_timer < journey.world_modifiers['beacon_irritation'] then - -- journey.beacon_timer = journey.beacon_timer + 10 - -- return - -- end - -- local surface = journey.beacon_objective.surface - -- local chunk_position = surface.get_random_chunk() - -- local lured = 0 - -- for _ = 1, 25, 1 do - -- lured = lured + Public.lure_biters(journey, {x = chunk_position.x * 32, y = chunk_position.y * 32}) - -- end - -- game.print('lured ' .. lured .. 'biters at tick ' .. game.tick) - -- journey.beacon_timer = journey.beacon_timer - lured + -- if journey.game_state ~= 'world' or not journey.beacon_objective.valid then return end + -- if journey.beacon_timer < journey.world_modifiers['beacon_irritation'] then + -- journey.beacon_timer = journey.beacon_timer + 10 + -- return + -- end + -- local surface = journey.beacon_objective.surface + -- local chunk_position = surface.get_random_chunk() + -- local lured = 0 + -- for _ = 1, 25, 1 do + -- lured = lured + Public.lure_biters(journey, {x = chunk_position.x * 32, y = chunk_position.y * 32}) + -- end + -- game.print('lured ' .. lured .. 'biters at tick ' .. game.tick) + -- journey.beacon_timer = journey.beacon_timer - lured end return Public diff --git a/maps/journey/unique_modifiers.lua b/maps/journey/unique_modifiers.lua index e0840951..d9ebb4c4 100644 --- a/maps/journey/unique_modifiers.lua +++ b/maps/journey/unique_modifiers.lua @@ -1,23 +1,37 @@ --luacheck: ignore 212/journey local Get_noise = require 'utils.get_noise' -local BiterRaffle = require 'functions.biter_raffle' -local LootRaffle = require 'functions.loot_raffle' +local BiterRaffle = require 'utils.functions.biter_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local math_random = math.random local math_abs = math.abs local math_floor = math.floor local math_sqrt = math.sqrt local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'} local size_of_rock_raffle = #rock_raffle -local ore_raffle = {} -for i = 1, 25, 1 do table.insert(ore_raffle, 'iron-ore') end -for i = 1, 17, 1 do table.insert(ore_raffle, 'copper-ore') end -for i = 1, 15, 1 do table.insert(ore_raffle, 'coal') end +local ore_raffle = {} +for i = 1, 25, 1 do + table.insert(ore_raffle, 'iron-ore') +end +for i = 1, 17, 1 do + table.insert(ore_raffle, 'copper-ore') +end +for i = 1, 15, 1 do + table.insert(ore_raffle, 'coal') +end local size_of_ore_raffle = #ore_raffle -local ore_raffle_2 = {} -for i = 1, 15, 1 do table.insert(ore_raffle_2, 'iron-ore') end -for i = 1, 9, 1 do table.insert(ore_raffle_2, 'copper-ore') end -for i = 1, 7, 1 do table.insert(ore_raffle_2, 'coal') end -for i = 1, 5, 1 do table.insert(ore_raffle_2, 'stone') end +local ore_raffle_2 = {} +for i = 1, 15, 1 do + table.insert(ore_raffle_2, 'iron-ore') +end +for i = 1, 9, 1 do + table.insert(ore_raffle_2, 'copper-ore') +end +for i = 1, 7, 1 do + table.insert(ore_raffle_2, 'coal') +end +for i = 1, 5, 1 do + table.insert(ore_raffle_2, 'stone') +end local size_of_ore_raffle_2 = #ore_raffle_2 local rock_yield = { ['rock-big'] = 1, @@ -33,14 +47,14 @@ local solid_tiles = { ['refined-hazard-concrete-right'] = true, ['stone-path'] = true, ['lab-dark-1'] = true, - ['lab-dark-2'] = true, + ['lab-dark-2'] = true } local wrecks = { 'crash-site-spaceship-wreck-big-1', 'crash-site-spaceship-wreck-big-2', 'crash-site-spaceship-wreck-medium-1', 'crash-site-spaceship-wreck-medium-2', - 'crash-site-spaceship-wreck-medium-3', + 'crash-site-spaceship-wreck-medium-3' } local size_of_wrecks = #wrecks @@ -66,7 +80,7 @@ Public.eternal_day = { clear = function(journey) local surface = game.surfaces.nauvis surface.freeze_daytime = false - end, + end } Public.eternal_night = { @@ -80,7 +94,7 @@ Public.eternal_night = { local surface = game.surfaces.nauvis surface.freeze_daytime = false surface.solar_power_multiplier = 1 - end, + end } Public.pitch_black = { @@ -98,35 +112,53 @@ Public.pitch_black = { surface.solar_power_multiplier = 1 surface.min_brightness = 0.15 surface.brightness_visual_weights = {0, 0, 0, 1} - end, + end } Public.matter_anomaly = { on_world_start = function(journey) local force = game.forces.player - for i = 1, 4, 1 do force.technologies['mining-productivity-' .. i].researched = true end - for i = 1, 6, 1 do force.technologies['mining-productivity-4'].researched = true end + for i = 1, 4, 1 do + force.technologies['mining-productivity-' .. i].researched = true + end + for i = 1, 6, 1 do + force.technologies['mining-productivity-4'].researched = true + end end, on_robot_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type == 'electric-turret' then entity.die() end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type == 'electric-turret' then + entity.die() + end end, on_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type == 'electric-turret' then entity.die() end - end, + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type == 'electric-turret' then + entity.die() + end + end } Public.quantum_anomaly = { on_world_start = function(journey) local force = game.forces.player - for i = 1, 6, 1 do force.technologies['research-speed-' .. i].researched = true end + for i = 1, 6, 1 do + force.technologies['research-speed-' .. i].researched = true + end journey.world_specials['technology_price_multiplier'] = 0.5 - end, + end } Public.mountainous = { @@ -136,8 +168,12 @@ Public.mountainous = { end, on_player_mined_entity = function(event) local entity = event.entity - if not entity.valid then return end - if not rock_yield[entity.name] then return end + if not entity.valid then + return + end + if not rock_yield[entity.name] then + return + end local surface = entity.surface event.buffer.clear() local ore = ore_raffle[math_random(1, size_of_ore_raffle)] @@ -167,52 +203,77 @@ Public.mountainous = { end end end - end, + end } Public.replicant_fauna = { on_entity_died = function(event) local entity = event.entity - if not entity.valid then return end + if not entity.valid then + return + end local cause = event.cause - if not cause then return end - if not cause.valid then return end - if cause.force.index == 2 then cause.surface.create_entity({name = BiterRaffle.roll('mixed', game.forces.enemy.evolution_factor), position = entity.position, force = 'enemy'}) end - end, + if not cause then + return + end + if not cause.valid then + return + end + if cause.force.index == 2 then + cause.surface.create_entity({name = BiterRaffle.roll('mixed', game.forces.enemy.evolution_factor), position = entity.position, force = 'enemy'}) + end + end } Public.tarball = { on_robot_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if tarball_minable[entity.type] then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if tarball_minable[entity.type] then + return + end entity.minable = false end, on_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if tarball_minable[entity.type] then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if tarball_minable[entity.type] then + return + end entity.minable = false end, on_chunk_generated = function(event, journey) - table.insert(journey.world_color_filters, rendering.draw_sprite( - { - sprite = 'tile/lab-dark-1', - x_scale = 32, - y_scale = 32, - target = event.area.left_top, - surface = event.surface, - tint = {r = 0.0, g = 0.0, b = 0.0, a = 0.45}, - render_layer = 'ground' - } - )) -end, -clear = function(journey) - for _, id in pairs(journey.world_color_filters) do rendering.destroy(id) end - journey.world_color_filters = {} -end, + table.insert( + journey.world_color_filters, + rendering.draw_sprite( + { + sprite = 'tile/lab-dark-1', + x_scale = 32, + y_scale = 32, + target = event.area.left_top, + surface = event.surface, + tint = {r = 0.0, g = 0.0, b = 0.0, a = 0.45}, + render_layer = 'ground' + } + ) + ) + end, + clear = function(journey) + for _, id in pairs(journey.world_color_filters) do + rendering.destroy(id) + end + journey.world_color_filters = {} + end } Public.swamps = { @@ -234,7 +295,9 @@ Public.swamps = { for y = 0, 31, 1 do local position = {x = left_top_x + x, y = left_top_y + y} local noise = Get_noise('journey_swamps', position, seed) - if noise > 0.45 or noise < -0.65 then table.insert(tiles, {name = 'water-shallow', position = {x = position.x, y = position.y}}) end + if noise > 0.45 or noise < -0.65 then + table.insert(tiles, {name = 'water-shallow', position = {x = position.x, y = position.y}}) + end end end surface.set_tiles(tiles, true, false, false, false) @@ -244,7 +307,7 @@ Public.swamps = { surface.create_entity({name = 'fish', position = tile.position}) end end - end, + end } Public.wasteland = { @@ -260,7 +323,9 @@ Public.wasteland = { table.insert(tiles, {name = 'deepwater-green', position = tile.position}) end surface.set_tiles(tiles, true, false, false, false) - if math_random(1, 3) ~= 1 then return end + if math_random(1, 3) ~= 1 then + return + end for _ = 1, math_random(0, 5), 1 do local name = wrecks[math_random(1, size_of_wrecks)] local position = surface.find_non_colliding_position(name, {left_top_x + math_random(0, 31), left_top_y + math_random(0, 31)}, 16, 1) @@ -270,7 +335,9 @@ Public.wasteland = { local slots = game.entity_prototypes[e.name].get_inventory_size(defines.inventory.chest) local blacklist = LootRaffle.get_tech_blacklist(0.2) local item_stacks = LootRaffle.roll(math_random(16, 64), slots, blacklist) - for _, item_stack in pairs(item_stacks) do e.insert(item_stack) end + for _, item_stack in pairs(item_stacks) do + e.insert(item_stack) + end end end end @@ -288,7 +355,7 @@ Public.wasteland = { local mgs = surface.map_gen_settings mgs.water = mgs.water - 1 surface.map_gen_settings = mgs - end, + end } Public.oceanic = { @@ -302,42 +369,65 @@ Public.oceanic = { end, on_robot_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type == 'fluid-turret' then entity.die() end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type == 'fluid-turret' then + entity.die() + end end, on_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type == 'fluid-turret' then entity.die() end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type == 'fluid-turret' then + entity.die() + end end, clear = function(journey) local surface = game.surfaces.nauvis local mgs = surface.map_gen_settings mgs.water = mgs.water - 6 surface.map_gen_settings = mgs - end, + end } Public.volcanic = { on_chunk_generated = function(event, journey) - table.insert(journey.world_color_filters, rendering.draw_sprite({ - sprite = 'tile/lab-dark-2', - x_scale = 32, - y_scale = 32, - target = event.area.left_top, - surface = event.surface, - tint = {r = 0.55, g = 0.0, b = 0.0, a = 0.25}, - render_layer = 'ground' - })) + table.insert( + journey.world_color_filters, + rendering.draw_sprite( + { + sprite = 'tile/lab-dark-2', + x_scale = 32, + y_scale = 32, + target = event.area.left_top, + surface = event.surface, + tint = {r = 0.55, g = 0.0, b = 0.0, a = 0.25}, + render_layer = 'ground' + } + ) + ) end, on_player_changed_position = function(event) local player = game.players[event.player_index] - if player.driving then return end + if player.driving then + return + end local surface = player.surface - if surface.index ~= 1 then return end - if solid_tiles[surface.get_tile(player.position).name] then return end + if surface.index ~= 1 then + return + end + if solid_tiles[surface.get_tile(player.position).name] then + return + end surface.create_entity({name = 'fire-flame', position = player.position}) end, on_world_start = function(journey) @@ -354,9 +444,11 @@ Public.volcanic = { end end, clear = function(journey) - for _, id in pairs(journey.world_color_filters) do rendering.destroy(id) end + for _, id in pairs(journey.world_color_filters) do + rendering.destroy(id) + end journey.world_color_filters = {} - end, + end } Public.chaotic_resources = { @@ -366,20 +458,25 @@ Public.chaotic_resources = { surface.create_entity({name = ore_raffle_2[math_random(1, size_of_ore_raffle_2)], position = ore.position, amount = ore.amount}) ore.destroy() end - end, + end } Public.infested = { on_chunk_generated = function(event, journey) - table.insert(journey.world_color_filters, rendering.draw_sprite({ - sprite = 'tile/lab-dark-2', - x_scale = 32, - y_scale = 32, - target = event.area.left_top, - surface = event.surface, - tint = {r = 0.8, g = 0.0, b = 0.8, a = 0.25}, - render_layer = 'ground' - })) + table.insert( + journey.world_color_filters, + rendering.draw_sprite( + { + sprite = 'tile/lab-dark-2', + x_scale = 32, + y_scale = 32, + target = event.area.left_top, + surface = event.surface, + tint = {r = 0.8, g = 0.0, b = 0.8, a = 0.25}, + render_layer = 'ground' + } + ) + ) end, set_specials = function(journey) journey.world_specials['trees_size'] = 4 @@ -387,111 +484,177 @@ Public.infested = { journey.world_specials['trees_frequency'] = 2 end, clear = function(journey) - for _, id in pairs(journey.world_color_filters) do rendering.destroy(id) end + for _, id in pairs(journey.world_color_filters) do + rendering.destroy(id) + end journey.world_color_filters = {} end, on_entity_died = function(event) local entity = event.entity - if not entity.valid then return end - if entity.force.index ~= 3 then return end - if entity.type ~= 'simple-entity' and entity.type ~= 'tree' then return end + if not entity.valid then + return + end + if entity.force.index ~= 3 then + return + end + if entity.type ~= 'simple-entity' and entity.type ~= 'tree' then + return + end entity.surface.create_entity({name = BiterRaffle.roll('mixed', game.forces.enemy.evolution_factor + 0.1), position = entity.position, force = 'enemy'}) end, on_player_mined_entity = function(event) - if math_random(1,2) == 1 then return end + if math_random(1, 2) == 1 then + return + end local entity = event.entity - if not entity.valid then return end - if entity.force.index ~= 3 then return end - if entity.type ~= 'simple-entity' and entity.type ~= 'tree' then return end + if not entity.valid then + return + end + if entity.force.index ~= 3 then + return + end + if entity.type ~= 'simple-entity' and entity.type ~= 'tree' then + return + end entity.surface.create_entity({name = BiterRaffle.roll('mixed', game.forces.enemy.evolution_factor + 0.1), position = entity.position, force = 'enemy'}) end, on_robot_mined_entity = function(event) local entity = event.entity - if not entity.valid then return end - if entity.force.index ~= 3 then return end - if entity.type ~= 'simple-entity' and entity.type ~= 'tree' then return end + if not entity.valid then + return + end + if entity.force.index ~= 3 then + return + end + if entity.type ~= 'simple-entity' and entity.type ~= 'tree' then + return + end entity.surface.create_entity({name = BiterRaffle.roll('mixed', game.forces.enemy.evolution_factor + 0.1), position = entity.position, force = 'enemy'}) - end, + end } Public.undead_plague = { on_entity_died = function(event) local entity = event.entity - if not entity.valid then return end - if entity.force.index ~= 2 then return end - if math_random(1,2) == 1 then return end - if entity.type ~= 'unit' then return end + if not entity.valid then + return + end + if entity.force.index ~= 2 then + return + end + if math_random(1, 2) == 1 then + return + end + if entity.type ~= 'unit' then + return + end entity.surface.create_entity({name = entity.name, position = entity.position, force = 'enemy'}) - end, + end } Public.low_mass = { on_world_start = function(journey) local force = game.forces.player force.character_running_speed_modifier = 0.5 - for i = 1, 6, 1 do force.technologies['worker-robots-speed-' .. i].researched = true end - end, + for i = 1, 6, 1 do + force.technologies['worker-robots-speed-' .. i].researched = true + end + end } Public.dense_atmosphere = { on_robot_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type == 'roboport' then entity.die() end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type == 'roboport' then + entity.die() + end end, on_built_entity = function(event) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end - if entity.type == 'roboport' then entity.die() end - end, + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end + if entity.type == 'roboport' then + entity.die() + end + end } local function update_lazy_bastard(journey, count) journey.lazy_bastard_machines = journey.lazy_bastard_machines + count local speed = journey.lazy_bastard_machines * -0.1 - if speed < -1 then speed = -1 end + if speed < -1 then + speed = -1 + end game.forces.player.manual_crafting_speed_modifier = speed end Public.lazy_bastard = { on_robot_built_entity = function(event, journey) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end if entity.type == 'assembling-machine' then update_lazy_bastard(journey, 1) end end, on_built_entity = function(event, journey) local entity = event.created_entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end if entity.type == 'assembling-machine' then update_lazy_bastard(journey, 1) end end, on_entity_died = function(event, journey) local entity = event.entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end if entity.type == 'assembling-machine' then update_lazy_bastard(journey, -1) end end, on_player_mined_entity = function(event, journey) local entity = event.entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end if entity.type == 'assembling-machine' then update_lazy_bastard(journey, -1) end end, on_robot_mined_entity = function(event, journey) local entity = event.entity - if not entity.valid then return end - if entity.surface.index ~= 1 then return end + if not entity.valid then + return + end + if entity.surface.index ~= 1 then + return + end if entity.type == 'assembling-machine' then update_lazy_bastard(journey, -1) end @@ -501,7 +664,7 @@ Public.lazy_bastard = { end, clear = function(journey) game.forces.player.manual_crafting_speed_modifier = 0 - end, + end } Public.ribbon = { @@ -509,8 +672,8 @@ Public.ribbon = { local surface = event.surface local left_top_x = event.area.left_top.x local left_top_y = event.area.left_top.y - if (left_top_x + left_top_y)^2 <= 256 then - local oils = surface.count_entities_filtered{name = 'crude-oil', position = {x = 0,y =0}, radius = 256} + if (left_top_x + left_top_y) ^ 2 <= 256 then + local oils = surface.count_entities_filtered {name = 'crude-oil', position = {x = 0, y = 0}, radius = 256} if math.random(1, 10 + oils * 10) == 1 then local pos = surface.find_non_colliding_position_in_box('oil-refinery', event.area, 0.1, true) if pos then @@ -531,7 +694,7 @@ Public.ribbon = { local mgs = surface.map_gen_settings mgs.height = nil surface.map_gen_settings = mgs - end, + end } Public.abandoned_library = { @@ -542,7 +705,7 @@ Public.abandoned_library = { clear = function(journey) game.permissions.get_group('Default').set_allows_action(defines.input_action.open_blueprint_library_gui, true) game.permissions.get_group('Default').set_allows_action(defines.input_action.import_blueprint_string, true) - end, + end } Public.railworld = { @@ -560,7 +723,7 @@ Public.railworld = { journey.world_specials['enemy_base_richness'] = 2 journey.world_specials['water'] = 1.5 journey.world_specials['starting_area'] = 3 - end, + end } local delivery_options = { @@ -584,7 +747,7 @@ Public.resupply_station = { journey.mothership_cargo_space[journey.speedrun.item] = nil journey.mothership_cargo[journey.speedrun.item] = 0 journey.speedrun.enabled = false - end, + end } Public.crazy_science = { @@ -604,8 +767,7 @@ Public.crazy_science = { journey.world_specials[name] = math.max(0.1, journey.world_specials[name] * 0.95) game.difficulty_settings.technology_price_multiplier = journey.world_modifiers[name] * (journey.world_specials[name] or 1) force.laboratory_productivity_bonus = math.max(0.1, force.laboratory_productivity_bonus * 0.95) - end, + end } - return Public diff --git a/maps/junkyard.lua b/maps/junkyard.lua index b74c6458..5c00212c 100644 --- a/maps/junkyard.lua +++ b/maps/junkyard.lua @@ -1,587 +1,613 @@ --luacheck: ignore --junkyard-- mewmew made this -- -require "modules.dynamic_landfill" -require "modules.satellite_score" -require "modules.mineable_wreckage_yields_scrap" -require "modules.rocks_heal_over_time" -require "modules.spawners_contain_biters" -require "modules.biters_yield_coins" +require 'modules.dynamic_landfill' +require 'modules.satellite_score' +require 'modules.mineable_wreckage_yields_scrap' +require 'modules.rocks_heal_over_time' +require 'modules.spawners_contain_biters' +require 'modules.biters_yield_coins' --require "maps.modules.fluids_are_explosive" --require "maps.modules.explosives_are_explosive" -require "modules.dangerous_nights" -require "modules.dangerous_goods" +require 'modules.dangerous_nights' +require 'modules.dangerous_goods' local Map = require 'modules.map_info' -local unearthing_worm = require "functions.unearthing_worm" -local unearthing_biters = require "functions.unearthing_biters" -local tick_tack_trap = require "functions.tick_tack_trap" -local create_entity_chain = require "functions.create_entity_chain" -local create_tile_chain = require "functions.create_tile_chain" +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' +local create_entity_chain = require 'utils.functions.create_entity_chain' +local create_tile_chain = require 'utils.functions.create_tile_chain' local simplex_noise = require 'utils.simplex_noise' simplex_noise = simplex_noise.d2 local event = require 'utils.event' local table_insert = table.insert local math_random = math.random -local map_functions = require "tools.map_functions" -local scrap = require "tools.scrap" +local map_functions = require 'utils.tools.map_functions' +local scrap = require 'utils.tools.scrap' local disabled_for_deconstruction = { - ["fish"] = true, - ["rock-huge"] = true, - ["rock-big"] = true, - ["sand-rock-big"] = true, - - ["crash-site-spaceship-wreck-small-1"] = true, - ["crash-site-spaceship-wreck-small-2"] = true, - ["crash-site-spaceship-wreck-small-3"] = true, - ["crash-site-spaceship-wreck-small-4"] = true, - ["crash-site-spaceship-wreck-small-5"] = true, - ["crash-site-spaceship-wreck-small-6"] = true, - } + ['fish'] = true, + ['rock-huge'] = true, + ['rock-big'] = true, + ['sand-rock-big'] = true, + ['crash-site-spaceship-wreck-small-1'] = true, + ['crash-site-spaceship-wreck-small-2'] = true, + ['crash-site-spaceship-wreck-small-3'] = true, + ['crash-site-spaceship-wreck-small-4'] = true, + ['crash-site-spaceship-wreck-small-5'] = true, + ['crash-site-spaceship-wreck-small-6'] = true +} local tile_replacements = { - ["grass-1"] = "dirt-7", - ["grass-2"] = "dirt-6", - ["grass-3"] = "dirt-5", - ["grass-4"] = "dirt-4" , - ["water"] = "water-green", - ["deepwater"] = "deepwater-green", - ["sand-1"] = "dirt-7", - ["sand-2"] = "dirt-6", - ["sand-3"] = "dirt-5" + ['grass-1'] = 'dirt-7', + ['grass-2'] = 'dirt-6', + ['grass-3'] = 'dirt-5', + ['grass-4'] = 'dirt-4', + ['water'] = 'water-green', + ['deepwater'] = 'deepwater-green', + ['sand-1'] = 'dirt-7', + ['sand-2'] = 'dirt-6', + ['sand-3'] = 'dirt-5' } local entity_replacements = { - ["tree-01"] = "dead-grey-trunk", - ["tree-02"] = "tree-06-brown", - ["tree-03"] = "dead-grey-trunk", - ["tree-04"] = "dry-hairy-tree", - ["tree-05"] = "dead-grey-trunk", - ["tree-06"] = "tree-06-brown", - ["tree-07"] = "dry-hairy-tree", - ["tree-08"] = "dead-grey-trunk", - ["tree-09"] = "tree-06-brown", - ["tree-02-red"] = "dry-tree", - --["tree-06-brown"] = "dirt", - ["tree-08-brown"] = "tree-06-brown", - ["tree-09-brown"] = "tree-06-brown", - ["tree-09-red"] = "tree-06-brown", - ["iron-ore"] = scrap.get_scrap_name(1), - ["copper-ore"] = scrap.get_scrap_name(2), - ["coal"] = scrap.get_scrap_name(3), - ["stone"] = scrap.get_scrap_name(4) + ['tree-01'] = 'dead-grey-trunk', + ['tree-02'] = 'tree-06-brown', + ['tree-03'] = 'dead-grey-trunk', + ['tree-04'] = 'dry-hairy-tree', + ['tree-05'] = 'dead-grey-trunk', + ['tree-06'] = 'tree-06-brown', + ['tree-07'] = 'dry-hairy-tree', + ['tree-08'] = 'dead-grey-trunk', + ['tree-09'] = 'tree-06-brown', + ['tree-02-red'] = 'dry-tree', + --["tree-06-brown"] = "dirt", + ['tree-08-brown'] = 'tree-06-brown', + ['tree-09-brown'] = 'tree-06-brown', + ['tree-09-red'] = 'tree-06-brown', + ['iron-ore'] = scrap.get_scrap_name(1), + ['copper-ore'] = scrap.get_scrap_name(2), + ['coal'] = scrap.get_scrap_name(3), + ['stone'] = scrap.get_scrap_name(4) } -local wrecks = {"big-ship-wreck-1", "big-ship-wreck-2", "big-ship-wreck-3"} +local wrecks = {'big-ship-wreck-1', 'big-ship-wreck-2', 'big-ship-wreck-3'} local scrap_buildings = { - "nuclear-reactor", - "centrifuge", - "beacon", - "chemical-plant", - "assembling-machine-1", - "assembling-machine-2", - "assembling-machine-3", - "oil-refinery", - "arithmetic-combinator", - "constant-combinator", - "decider-combinator", - "programmable-speaker", - "steam-turbine", - "steam-engine", - "chemical-plant", - "assembling-machine-1", - "assembling-machine-2", - "assembling-machine-3", - "oil-refinery", - "arithmetic-combinator", - "constant-combinator", - "decider-combinator", - "programmable-speaker", - "steam-turbine", - "steam-engine" + 'nuclear-reactor', + 'centrifuge', + 'beacon', + 'chemical-plant', + 'assembling-machine-1', + 'assembling-machine-2', + 'assembling-machine-3', + 'oil-refinery', + 'arithmetic-combinator', + 'constant-combinator', + 'decider-combinator', + 'programmable-speaker', + 'steam-turbine', + 'steam-engine', + 'chemical-plant', + 'assembling-machine-1', + 'assembling-machine-2', + 'assembling-machine-3', + 'oil-refinery', + 'arithmetic-combinator', + 'constant-combinator', + 'decider-combinator', + 'programmable-speaker', + 'steam-turbine', + 'steam-engine' } local function shuffle(tbl) - local size = #tbl - for i = size, 1, -1 do - local rand = math_random(size) - tbl[i], tbl[rand] = tbl[rand], tbl[i] - end - return tbl + local size = #tbl + for i = size, 1, -1 do + local rand = math_random(size) + tbl[i], tbl[rand] = tbl[rand], tbl[i] + end + return tbl end local function get_noise(name, pos) - local seed = game.surfaces[1].map_gen_settings.seed - local noise_seed_add = 25000 - seed = seed + noise_seed_add - if name == 1 then - local noise = {} - noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed) - seed = seed + noise_seed_add - noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed) - seed = seed + noise_seed_add - noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed) - seed = seed + noise_seed_add - noise[4] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed) - local noise = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11 - return noise - end + local seed = game.surfaces[1].map_gen_settings.seed + local noise_seed_add = 25000 + seed = seed + noise_seed_add + if name == 1 then + local noise = {} + noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed) + seed = seed + noise_seed_add + noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed) + seed = seed + noise_seed_add + noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed) + seed = seed + noise_seed_add + noise[4] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed) + local noise = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11 + return noise + end end local function create_shipwreck(surface, position) - local raffle = {} - local loot = { + local raffle = {} + local loot = { + {{name = 'iron-gear-wheel', count = math_random(80, 100)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, + {{name = 'copper-cable', count = math_random(100, 200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, + {{name = 'engine-unit', count = math_random(16, 32)}, weight = 2, evolution_min = 0.1, evolution_max = 0.5}, + {{name = 'electric-engine-unit', count = math_random(16, 32)}, weight = 2, evolution_min = 0.4, evolution_max = 0.8}, + {{name = 'battery', count = math_random(40, 80)}, weight = 2, evolution_min = 0.3, evolution_max = 0.8}, + {{name = 'advanced-circuit', count = math_random(40, 80)}, weight = 3, evolution_min = 0.4, evolution_max = 1}, + {{name = 'electronic-circuit', count = math_random(100, 200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4}, + {{name = 'processing-unit', count = math_random(30, 60)}, weight = 3, evolution_min = 0.7, evolution_max = 1}, + {{name = 'explosives', count = math_random(25, 50)}, weight = 1, evolution_min = 0.2, evolution_max = 0.6}, + {{name = 'lubricant-barrel', count = math_random(4, 10)}, weight = 1, evolution_min = 0.3, evolution_max = 0.5}, + {{name = 'rocket-fuel', count = math_random(4, 10)}, weight = 2, evolution_min = 0.3, evolution_max = 0.7}, + {{name = 'steel-plate', count = math_random(50, 100)}, weight = 2, evolution_min = 0.1, evolution_max = 0.3}, + {{name = 'nuclear-fuel', count = 1}, weight = 2, evolution_min = 0.7, evolution_max = 1}, + {{name = 'burner-inserter', count = math_random(4, 8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1}, + {{name = 'inserter', count = math_random(4, 8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4}, + {{name = 'long-handed-inserter', count = math_random(4, 8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4}, + {{name = 'fast-inserter', count = math_random(4, 8)}, weight = 3, evolution_min = 0.1, evolution_max = 1}, + {{name = 'filter-inserter', count = math_random(4, 8)}, weight = 1, evolution_min = 0.2, evolution_max = 1}, + {{name = 'stack-filter-inserter', count = math_random(2, 4)}, weight = 1, evolution_min = 0.4, evolution_max = 1}, + {{name = 'stack-inserter', count = math_random(2, 4)}, weight = 3, evolution_min = 0.3, evolution_max = 1}, + {{name = 'small-electric-pole', count = math_random(8, 16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, + {{name = 'medium-electric-pole', count = math_random(4, 8)}, weight = 3, evolution_min = 0.2, evolution_max = 1}, + {{name = 'wooden-chest', count = math_random(16, 24)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2}, + {{name = 'iron-chest', count = math_random(4, 8)}, weight = 3, evolution_min = 0.1, evolution_max = 0.4}, + {{name = 'steel-chest', count = math_random(4, 8)}, weight = 3, evolution_min = 0.3, evolution_max = 1}, + {{name = 'small-lamp', count = math_random(8, 16)}, weight = 3, evolution_min = 0.1, evolution_max = 0.3}, + {{name = 'rail', count = math_random(50, 75)}, weight = 3, evolution_min = 0.1, evolution_max = 0.6}, + {{name = 'assembling-machine-1', count = math_random(1, 2)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, + {{name = 'assembling-machine-2', count = math_random(1, 2)}, weight = 3, evolution_min = 0.2, evolution_max = 0.8}, + {{name = 'offshore-pump', count = 1}, weight = 2, evolution_min = 0.0, evolution_max = 0.1}, + --{{name = "beacon", count = 1}, weight = 3, evolution_min = 0.7, evolution_max = 1}, + --{{name = "boiler", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, + --{{name = "steam-engine", count = math_random(1,2)}, weight = 3, evolution_min = 0.0, evolution_max = 0.5}, + --{{name = "steam-turbine", count = math_random(1,2)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, + --{{name = "nuclear-reactor", count = 1}, weight = 2, evolution_min = 0.5, evolution_max = 1}, + --{{name = "centrifuge", count = math_random(1,2)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, + {{name = 'heat-pipe', count = math_random(8, 12)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, + --{{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, + {{name = 'arithmetic-combinator', count = math_random(8, 16)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + {{name = 'constant-combinator', count = math_random(8, 16)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + {{name = 'decider-combinator', count = math_random(8, 16)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + {{name = 'power-switch', count = math_random(2, 4)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + {{name = 'programmable-speaker', count = math_random(2, 4)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + {{name = 'green-wire', count = math_random(50, 100)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + {{name = 'red-wire', count = math_random(50, 100)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, + --{{name = "chemical-plant", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 1}, + {{name = 'burner-mining-drill', count = math_random(2, 4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2}, + {{name = 'electric-mining-drill', count = math_random(2, 4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.6}, + {{name = 'express-transport-belt', count = math_random(25, 75)}, weight = 3, evolution_min = 0.5, evolution_max = 1}, + {{name = 'express-underground-belt', count = math_random(4, 8)}, weight = 3, evolution_min = 0.5, evolution_max = 1}, + {{name = 'express-splitter', count = math_random(2, 4)}, weight = 3, evolution_min = 0.5, evolution_max = 1}, + {{name = 'fast-transport-belt', count = math_random(25, 75)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7}, + {{name = 'fast-underground-belt', count = math_random(4, 8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7}, + {{name = 'fast-splitter', count = math_random(2, 4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.3}, + {{name = 'transport-belt', count = math_random(25, 75)}, weight = 3, evolution_min = 0, evolution_max = 0.3}, + {{name = 'underground-belt', count = math_random(4, 8)}, weight = 3, evolution_min = 0, evolution_max = 0.3}, + {{name = 'splitter', count = math_random(2, 4)}, weight = 3, evolution_min = 0, evolution_max = 0.3}, + {{name = 'pipe', count = math_random(40, 50)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, + {{name = 'pipe-to-ground', count = math_random(8, 16)}, weight = 1, evolution_min = 0.2, evolution_max = 0.5}, + --{{name = "pumpjack", count = math_random(1,2)}, weight = 1, evolution_min = 0.3, evolution_max = 0.8}, + {{name = 'pump', count = math_random(1, 4)}, weight = 1, evolution_min = 0.3, evolution_max = 0.8}, + --{{name = "steel-furnace", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7}, + --{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1}, + --{{name = "radar", count = math_random(1,2)}, weight = 1, evolution_min = 0.1, evolution_max = 0.3}, + {{name = 'rail-signal', count = math_random(8, 16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8}, + {{name = 'rail-chain-signal', count = math_random(8, 16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8}, + {{name = 'stone-wall', count = math_random(25, 75)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5}, + {{name = 'gate', count = math_random(4, 8)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5}, + --{{name = "storage-tank", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 0.6}, + {{name = 'train-stop', count = math_random(1, 2)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7}, + {{name = 'express-loader', count = math_random(1, 2)}, weight = 1, evolution_min = 0.5, evolution_max = 1}, + {{name = 'fast-loader', count = math_random(1, 2)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7}, + {{name = 'loader', count = math_random(1, 2)}, weight = 1, evolution_min = 0.0, evolution_max = 0.5} + --{{name = "lab", count = math_random(2,4)}, weight = 2, evolution_min = 0.0, evolution_max = 0.1} + } - {{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, - {{name = "copper-cable", count = math_random(100,200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, - {{name = "engine-unit", count = math_random(16,32)}, weight = 2, evolution_min = 0.1, evolution_max = 0.5}, - {{name = "electric-engine-unit", count = math_random(16,32)}, weight = 2, evolution_min = 0.4, evolution_max = 0.8}, - {{name = "battery", count = math_random(40,80)}, weight = 2, evolution_min = 0.3, evolution_max = 0.8}, - {{name = "advanced-circuit", count = math_random(40,80)}, weight = 3, evolution_min = 0.4, evolution_max = 1}, - {{name = "electronic-circuit", count = math_random(100,200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4}, - {{name = "processing-unit", count = math_random(30,60)}, weight = 3, evolution_min = 0.7, evolution_max = 1}, - {{name = "explosives", count = math_random(25,50)}, weight = 1, evolution_min = 0.2, evolution_max = 0.6}, - {{name = "lubricant-barrel", count = math_random(4,10)}, weight = 1, evolution_min = 0.3, evolution_max = 0.5}, - {{name = "rocket-fuel", count = math_random(4,10)}, weight = 2, evolution_min = 0.3, evolution_max = 0.7}, - {{name = "steel-plate", count = math_random(50,100)}, weight = 2, evolution_min = 0.1, evolution_max = 0.3}, - {{name = "nuclear-fuel", count = 1}, weight = 2, evolution_min = 0.7, evolution_max = 1}, + local distance_to_center = math.sqrt(position.x ^ 2 + position.y ^ 2) + if distance_to_center < 1 then + distance_to_center = 0.1 + else + distance_to_center = distance_to_center / 2500 + end + if distance_to_center > 1 then + distance_to_center = 1 + end - {{name = "burner-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1}, - {{name = "inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4}, - {{name = "long-handed-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.4}, - {{name = "fast-inserter", count = math_random(4,8)}, weight = 3, evolution_min = 0.1, evolution_max = 1}, - {{name = "filter-inserter", count = math_random(4,8)}, weight = 1, evolution_min = 0.2, evolution_max = 1}, - {{name = "stack-filter-inserter", count = math_random(2,4)}, weight = 1, evolution_min = 0.4, evolution_max = 1}, - {{name = "stack-inserter", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 1}, - {{name = "small-electric-pole", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, - {{name = "medium-electric-pole", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 1}, - {{name = "wooden-chest", count = math_random(16,24)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2}, - {{name = "iron-chest", count = math_random(4,8)}, weight = 3, evolution_min = 0.1, evolution_max = 0.4}, - {{name = "steel-chest", count = math_random(4,8)}, weight = 3, evolution_min = 0.3, evolution_max = 1}, - {{name = "small-lamp", count = math_random(8,16)}, weight = 3, evolution_min = 0.1, evolution_max = 0.3}, - {{name = "rail", count = math_random(50,75)}, weight = 3, evolution_min = 0.1, evolution_max = 0.6}, - {{name = "assembling-machine-1", count = math_random(1,2)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, - {{name = "assembling-machine-2", count = math_random(1,2)}, weight = 3, evolution_min = 0.2, evolution_max = 0.8}, - {{name = "offshore-pump", count = 1}, weight = 2, evolution_min = 0.0, evolution_max = 0.1}, - --{{name = "beacon", count = 1}, weight = 3, evolution_min = 0.7, evolution_max = 1}, - --{{name = "boiler", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, - --{{name = "steam-engine", count = math_random(1,2)}, weight = 3, evolution_min = 0.0, evolution_max = 0.5}, - --{{name = "steam-turbine", count = math_random(1,2)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, - --{{name = "nuclear-reactor", count = 1}, weight = 2, evolution_min = 0.5, evolution_max = 1}, - --{{name = "centrifuge", count = math_random(1,2)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, - {{name = "heat-pipe", count = math_random(8,12)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, - --{{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, evolution_min = 0.5, evolution_max = 1}, - {{name = "arithmetic-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - {{name = "constant-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - {{name = "decider-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - {{name = "power-switch", count = math_random(2,4)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - {{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - {{name = "green-wire", count = math_random(50,100)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - {{name = "red-wire", count = math_random(50,100)}, weight = 1, evolution_min = 0.1, evolution_max = 1}, - --{{name = "chemical-plant", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 1}, - {{name = "burner-mining-drill", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2}, - {{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.6}, - {{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0.5, evolution_max = 1}, - {{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0.5, evolution_max = 1}, - {{name = "express-splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0.5, evolution_max = 1}, - {{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7}, - {{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7}, - {{name = "fast-splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.3}, - {{name = "transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0, evolution_max = 0.3}, - {{name = "underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0, evolution_max = 0.3}, - {{name = "splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0, evolution_max = 0.3}, - {{name = "pipe", count = math_random(40,50)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3}, - {{name = "pipe-to-ground", count = math_random(8,16)}, weight = 1, evolution_min = 0.2, evolution_max = 0.5}, - --{{name = "pumpjack", count = math_random(1,2)}, weight = 1, evolution_min = 0.3, evolution_max = 0.8}, - {{name = "pump", count = math_random(1,4)}, weight = 1, evolution_min = 0.3, evolution_max = 0.8}, - --{{name = "steel-furnace", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7}, - --{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1}, - --{{name = "radar", count = math_random(1,2)}, weight = 1, evolution_min = 0.1, evolution_max = 0.3}, - {{name = "rail-signal", count = math_random(8,16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8}, - {{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8}, - {{name = "stone-wall", count = math_random(25,75)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5}, - {{name = "gate", count = math_random(4,8)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5}, - --{{name = "storage-tank", count = math_random(2,4)}, weight = 3, evolution_min = 0.3, evolution_max = 0.6}, - {{name = "train-stop", count = math_random(1,2)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7}, - {{name = "express-loader", count = math_random(1,2)}, weight = 1, evolution_min = 0.5, evolution_max = 1}, - {{name = "fast-loader", count = math_random(1,2)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7}, - {{name = "loader", count = math_random(1,2)}, weight = 1, evolution_min = 0.0, evolution_max = 0.5} - --{{name = "lab", count = math_random(2,4)}, weight = 2, evolution_min = 0.0, evolution_max = 0.1} - } - - local distance_to_center = math.sqrt(position.x^2 + position.y^2) - if distance_to_center < 1 then - distance_to_center = 0.1 - else - distance_to_center = distance_to_center / 2500 - end - if distance_to_center > 1 then distance_to_center = 1 end - - for _, t in pairs (loot) do - for x = 1, t.weight, 1 do - if t.evolution_min <= distance_to_center and t.evolution_max >= distance_to_center then - table.insert(raffle, t[1]) - end - end - end - local e = surface.create_entity{name = wrecks[math_random(1,#wrecks)], position = position, force = "scrap"} - for x = 1, math_random(2,3), 1 do - local loot = raffle[math_random(1,#raffle)] - e.insert(loot) - end + for _, t in pairs(loot) do + for x = 1, t.weight, 1 do + if t.evolution_min <= distance_to_center and t.evolution_max >= distance_to_center then + table.insert(raffle, t[1]) + end + end + end + local e = surface.create_entity {name = wrecks[math_random(1, #wrecks)], position = position, force = 'scrap'} + for x = 1, math_random(2, 3), 1 do + local loot = raffle[math_random(1, #raffle)] + e.insert(loot) + end end local function secret_shop(pos, surface) - local secret_market_items = { - {price = {{"coin", math_random(30,60)}}, offer = {type = 'give-item', item = 'construction-robot'}}, - {price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'loader'}}, - {price = {{"coin", math_random(200,300)}}, offer = {type = 'give-item', item = 'fast-loader'}}, - {price = {{"coin", math_random(300,500)}}, offer = {type = 'give-item', item = 'express-loader'}}, - {price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'locomotive'}}, - {price = {{"coin", math_random(75,150)}}, offer = {type = 'give-item', item = 'cargo-wagon'}}, - {price = {{"coin", math_random(2,3)}}, offer = {type = 'give-item', item = 'rail'}}, - {price = {{"coin", math_random(4,12)}}, offer = {type = 'give-item', item = 'small-lamp'}}, - {price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'car'}}, - {price = {{"coin", math_random(300,600)}}, offer = {type = 'give-item', item = 'electric-furnace'}}, - {price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'effectivity-module'}}, - {price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'productivity-module'}}, - {price = {{"coin", math_random(80,160)}}, offer = {type = 'give-item', item = 'speed-module'}}, + local secret_market_items = { + {price = {{'coin', math_random(30, 60)}}, offer = {type = 'give-item', item = 'construction-robot'}}, + {price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'loader'}}, + {price = {{'coin', math_random(200, 300)}}, offer = {type = 'give-item', item = 'fast-loader'}}, + {price = {{'coin', math_random(300, 500)}}, offer = {type = 'give-item', item = 'express-loader'}}, + {price = {{'coin', math_random(100, 200)}}, offer = {type = 'give-item', item = 'locomotive'}}, + {price = {{'coin', math_random(75, 150)}}, offer = {type = 'give-item', item = 'cargo-wagon'}}, + {price = {{'coin', math_random(2, 3)}}, offer = {type = 'give-item', item = 'rail'}}, + {price = {{'coin', math_random(4, 12)}}, offer = {type = 'give-item', item = 'small-lamp'}}, + {price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'car'}}, + {price = {{'coin', math_random(300, 600)}}, offer = {type = 'give-item', item = 'electric-furnace'}}, + {price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'effectivity-module'}}, + {price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'productivity-module'}}, + {price = {{'coin', math_random(80, 160)}}, offer = {type = 'give-item', item = 'speed-module'}}, + {price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'wood', count = 50}}, + {price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}}, + {price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}}, + {price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'stone', count = 50}}, + {price = {{'coin', math_random(5, 10)}}, offer = {type = 'give-item', item = 'coal', count = 50}}, + {price = {{'coin', math_random(8, 16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}, + {price = {{'wood', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}}, + {price = {{'iron-ore', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}}, + {price = {{'copper-ore', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}}, + {price = {{'stone', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}}, + {price = {{'coal', math_random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}}, + {price = {{'uranium-ore', math_random(8, 10)}}, offer = {type = 'give-item', item = 'coin'}} + } + secret_market_items = shuffle(secret_market_items) - {price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'wood', count = 50}}, - {price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}}, - {price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}}, - {price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'stone', count = 50}}, - {price = {{"coin", math_random(5,10)}}, offer = {type = 'give-item', item = 'coal', count = 50}}, - {price = {{"coin", math_random(8,16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}}, + local market = surface.create_entity {name = 'market', position = pos, force = 'neutral'} + market.destructible = false - {price = {{'wood', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, - {price = {{'iron-ore', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, - {price = {{'copper-ore', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, - {price = {{'stone', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, - {price = {{'coal', math_random(10,12)}}, offer = {type = 'give-item', item = "coin"}}, - {price = {{'uranium-ore', math_random(8,10)}}, offer = {type = 'give-item', item = "coin"}} - } - secret_market_items = shuffle(secret_market_items) - - local market = surface.create_entity {name = "market", position = pos, force = "neutral"} - market.destructible = false - - for i = 1, math.random(6, 8), 1 do - market.add_market_item(secret_market_items[i]) - end + for i = 1, math.random(6, 8), 1 do + market.add_market_item(secret_market_items[i]) + end end local function place_random_scrap_entity(surface, position) - local r = math.random(1, 100) - if r < 15 then - local e = surface.create_entity({name = scrap_buildings[math.random(1, #scrap_buildings)], position = position, force = "scrap"}) - if e.name == "nuclear-reactor" then - create_entity_chain(surface, {name = "heat-pipe", position = position, force = "player"}, math_random(16,32), 25) - end - if e.name == "chemical-plant" or e.name == "steam-turbine" or e.name == "steam-engine" or e.name == "oil-refinery" then - create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(8,16), 25) - end - e.active = false - return - end - --if r < 25 then - -- local e = surface.create_entity({name = "substation", position = position, force = "scrap"}) - -- e.active = false - -- return - --end - --if r < 70 then - -- local e = surface.create_entity({name = "medium-electric-pole", position = position, force = "scrap"}) - -- e.active = false - -- return - --end - if r < 100 then - local e = surface.create_entity({name = "gun-turret", position = position, force = "scrap_defense"}) - e.insert({name = "piercing-rounds-magazine", count = math.random(8, 128)}) - return - end + local r = math.random(1, 100) + if r < 15 then + local e = surface.create_entity({name = scrap_buildings[math.random(1, #scrap_buildings)], position = position, force = 'scrap'}) + if e.name == 'nuclear-reactor' then + create_entity_chain(surface, {name = 'heat-pipe', position = position, force = 'player'}, math_random(16, 32), 25) + end + if e.name == 'chemical-plant' or e.name == 'steam-turbine' or e.name == 'steam-engine' or e.name == 'oil-refinery' then + create_entity_chain(surface, {name = 'pipe', position = position, force = 'player'}, math_random(8, 16), 25) + end + e.active = false + return + end + --if r < 25 then + -- local e = surface.create_entity({name = "substation", position = position, force = "scrap"}) + -- e.active = false + -- return + --end + --if r < 70 then + -- local e = surface.create_entity({name = "medium-electric-pole", position = position, force = "scrap"}) + -- e.active = false + -- return + --end + if r < 100 then + local e = surface.create_entity({name = 'gun-turret', position = position, force = 'scrap_defense'}) + e.insert({name = 'piercing-rounds-magazine', count = math.random(8, 128)}) + return + end - local e = surface.create_entity({name = "storage-tank", position = position, force = "scrap", direction = math.random(0, 3)}) - local fluids = {"crude-oil", "lubricant", "heavy-oil", "light-oil", "petroleum-gas", "sulfuric-acid", "water"} - e.fluidbox[1] = {name = fluids[math.random(1, #fluids)], amount = math.random(15000, 25000)} - create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(6,8), 1) - create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(6,8), 1) - create_entity_chain(surface, {name = "pipe", position = position, force = "player"}, math_random(15,30), 80) + local e = surface.create_entity({name = 'storage-tank', position = position, force = 'scrap', direction = math.random(0, 3)}) + local fluids = {'crude-oil', 'lubricant', 'heavy-oil', 'light-oil', 'petroleum-gas', 'sulfuric-acid', 'water'} + e.fluidbox[1] = {name = fluids[math.random(1, #fluids)], amount = math.random(15000, 25000)} + create_entity_chain(surface, {name = 'pipe', position = position, force = 'player'}, math_random(6, 8), 1) + create_entity_chain(surface, {name = 'pipe', position = position, force = 'player'}, math_random(6, 8), 1) + create_entity_chain(surface, {name = 'pipe', position = position, force = 'player'}, math_random(15, 30), 80) end local function create_inner_content(surface, pos, noise) - if math_random(1, 90000) == 1 then secret_shop(pos, surface) return end - if math_random(1, 102400) == 1 then - if noise < 0.3 or noise > -0.3 then - map_functions.draw_noise_entity_ring(surface, pos, "laser-turret", "scrap_defense", 0, 2) - map_functions.draw_noise_entity_ring(surface, pos, "accumulator", "scrap_defense", 2, 3) - map_functions.draw_noise_entity_ring(surface, pos, "substation", "scrap_defense", 3, 4) - map_functions.draw_noise_entity_ring(surface, pos, "solar-panel", "scrap_defense", 4, 6) - map_functions.draw_noise_entity_ring(surface, pos, "stone-wall", "scrap_defense", 6, 7) + if math_random(1, 90000) == 1 then + secret_shop(pos, surface) + return + end + if math_random(1, 102400) == 1 then + if noise < 0.3 or noise > -0.3 then + map_functions.draw_noise_entity_ring(surface, pos, 'laser-turret', 'scrap_defense', 0, 2) + map_functions.draw_noise_entity_ring(surface, pos, 'accumulator', 'scrap_defense', 2, 3) + map_functions.draw_noise_entity_ring(surface, pos, 'substation', 'scrap_defense', 3, 4) + map_functions.draw_noise_entity_ring(surface, pos, 'solar-panel', 'scrap_defense', 4, 6) + map_functions.draw_noise_entity_ring(surface, pos, 'stone-wall', 'scrap_defense', 6, 7) - create_tile_chain(surface, {name = "concrete", position = pos}, math_random(16, 32), 50) - create_tile_chain(surface, {name = "concrete", position = pos}, math_random(16, 32), 50) - create_tile_chain(surface, {name = "stone-path", position = pos}, math_random(16, 32), 50) - create_tile_chain(surface, {name = "stone-path", position = pos}, math_random(16, 32), 50) - --create_entity_chain(surface, {name = "laser-turret", position = pos, force = "scrap_defense"}, 1, 25) - --create_entity_chain(surface, {name = "accumulator", position = pos, force = "scrap_defense"}, math_random(2, 4), 1) - --create_entity_chain(surface, {name = "substation", position = pos, force = "scrap_defense"}, math_random(6, 8), 1) - -- create_entity_chain(surface, {name = "solar-panel", position = pos, force = "scrap_defense"}, math_random(16, 24), 1) - end - return - end - if math_random(1, 650) == 1 then - if surface.can_place_entity({name = "biter-spawner", position = pos}) then - local distance_to_center = pos.x ^ 2 + pos.y ^ 2 - if distance_to_center > 35000 then - surface.create_entity({name = "biter-spawner", position = pos}) - end - end - return - end + create_tile_chain(surface, {name = 'concrete', position = pos}, math_random(16, 32), 50) + create_tile_chain(surface, {name = 'concrete', position = pos}, math_random(16, 32), 50) + create_tile_chain(surface, {name = 'stone-path', position = pos}, math_random(16, 32), 50) + create_tile_chain(surface, {name = 'stone-path', position = pos}, math_random(16, 32), 50) + --create_entity_chain(surface, {name = "laser-turret", position = pos, force = "scrap_defense"}, 1, 25) + --create_entity_chain(surface, {name = "accumulator", position = pos, force = "scrap_defense"}, math_random(2, 4), 1) + --create_entity_chain(surface, {name = "substation", position = pos, force = "scrap_defense"}, math_random(6, 8), 1) + -- create_entity_chain(surface, {name = "solar-panel", position = pos, force = "scrap_defense"}, math_random(16, 24), 1) + end + return + end + if math_random(1, 650) == 1 then + if surface.can_place_entity({name = 'biter-spawner', position = pos}) then + local distance_to_center = pos.x ^ 2 + pos.y ^ 2 + if distance_to_center > 35000 then + surface.create_entity({name = 'biter-spawner', position = pos}) + end + end + return + end end local function process_entity(e) - if not e.valid then return end - if entity_replacements[e.name] then - if e.type == "tree" then - if math_random(1,2) == 1 then - e.surface.create_entity({name = entity_replacements[e.name], position = e.position}) - end - else - e.surface.create_entity({name = entity_replacements[e.name], position = e.position, force = "scrap"}) - end - e.destroy() - return - end + if not e.valid then + return + end + if entity_replacements[e.name] then + if e.type == 'tree' then + if math_random(1, 2) == 1 then + e.surface.create_entity({name = entity_replacements[e.name], position = e.position}) + end + else + e.surface.create_entity({name = entity_replacements[e.name], position = e.position, force = 'scrap'}) + end + e.destroy() + return + end - if e.type == "unit-spawner" then - local scraps = scrap.get_scraps() - for _, wreck in pairs (e.surface.find_entities_filtered({area = {{e.position.x - 4, e.position.y - 4},{e.position.x + 4, e.position.y + 4}}, name = scraps})) do - if wreck.valid then wreck.destroy() end - end - return - end + if e.type == 'unit-spawner' then + local scraps = scrap.get_scraps() + for _, wreck in pairs(e.surface.find_entities_filtered({area = {{e.position.x - 4, e.position.y - 4}, {e.position.x + 4, e.position.y + 4}}, name = scraps})) do + if wreck.valid then + wreck.destroy() + end + end + return + end end local function on_chunk_generated(event) - local surface = event.surface - local left_top = event.area.left_top - local tiles = {} - local entities = {} + local surface = event.surface + local left_top = event.area.left_top + local tiles = {} + local entities = {} - for x = 0, 31, 1 do - for y = 0, 31, 1 do - local tile_to_insert = false - local pos = {x = left_top.x + x, y = left_top.y + y} + for x = 0, 31, 1 do + for y = 0, 31, 1 do + local tile_to_insert = false + local pos = {x = left_top.x + x, y = left_top.y + y} - local tile = surface.get_tile(pos) - if tile_replacements[tile.name] then - table_insert(tiles, {name = tile_replacements[tile.name], position = pos}) - end + local tile = surface.get_tile(pos) + if tile_replacements[tile.name] then + table_insert(tiles, {name = tile_replacements[tile.name], position = pos}) + end - if not tile.collides_with("player-layer") then - local noise = get_noise(1, pos) - if noise > 0.43 or noise < -0.43 then - if math_random(1,3) ~= 1 then - scrap.create_scrap(surface, pos) - else - if math_random(1,512) == 1 then - create_shipwreck(surface, pos) - else - if math_random(1,512) == 1 then - --luacheck: ignore(surface, pos) - end - end - end - else - create_inner_content(surface, pos, noise) - end - end + if not tile.collides_with('player-layer') then + local noise = get_noise(1, pos) + if noise > 0.43 or noise < -0.43 then + if math_random(1, 3) ~= 1 then + scrap.create_scrap(surface, pos) + else + if math_random(1, 512) == 1 then + create_shipwreck(surface, pos) + else + if math_random(1, 512) == 1 then + --luacheck: ignore(surface, pos) + end + end + end + else + create_inner_content(surface, pos, noise) + end + end + end + end + surface.set_tiles(tiles, true) - end - end - surface.set_tiles(tiles, true) + for _, e in pairs(surface.find_entities_filtered({area = event.area})) do + process_entity(e) + end - for _, e in pairs(surface.find_entities_filtered({area = event.area})) do - process_entity(e) - end + if global.spawn_generated then + return + end + if left_top.x < 96 then + return + end + map_functions.draw_rainbow_patch_v2({x = 0, y = 0}, surface, 12, 2500) + local p = surface.find_non_colliding_position('character-corpse', {2, -2}, 32, 2) + local e = surface.create_entity({name = 'character-corpse', position = p}) + local scraps = scrap.get_scrap_true_array() - if global.spawn_generated then return end - if left_top.x < 96 then return end - map_functions.draw_rainbow_patch_v2({x = 0, y = 0}, surface, 12, 2500) - local p = surface.find_non_colliding_position("character-corpse", {2,-2}, 32, 2) - local e = surface.create_entity({name = "character-corpse", position = p}) - local scraps = scrap.get_scrap_true_array() - - for _, e in pairs (surface.find_entities_filtered({area = {{-50, -50},{50, 50}}})) do - local distance_to_center = math.sqrt(e.position.x^2 + e.position.y^2) - if e.valid then - if distance_to_center < 8 and scraps[e.name] and math_random(1,5) ~= 1 then - e.destroy() - end - end - if e.valid then - if distance_to_center < 30 and e.name == "gun-turret" then - e.destroy() - end - end - end - global.spawn_generated = true + for _, e in pairs(surface.find_entities_filtered({area = {{-50, -50}, {50, 50}}})) do + local distance_to_center = math.sqrt(e.position.x ^ 2 + e.position.y ^ 2) + if e.valid then + if distance_to_center < 8 and scraps[e.name] and math_random(1, 5) ~= 1 then + e.destroy() + end + end + if e.valid then + if distance_to_center < 30 and e.name == 'gun-turret' then + e.destroy() + end + end + end + global.spawn_generated = true end local function on_chunk_charted(event) - if not global.chunks_charted then global.chunks_charted = {} end - local surface = game.surfaces[event.surface_index] - local position = event.position - if global.chunks_charted[tostring(position.x) .. tostring(position.y)] then return end - global.chunks_charted[tostring(position.x) .. tostring(position.y)] = true + if not global.chunks_charted then + global.chunks_charted = {} + end + local surface = game.surfaces[event.surface_index] + local position = event.position + if global.chunks_charted[tostring(position.x) .. tostring(position.y)] then + return + end + global.chunks_charted[tostring(position.x) .. tostring(position.y)] = true - local decorative_names = {} - for k,v in pairs(game.decorative_prototypes) do - if v.autoplace_specification then - decorative_names[#decorative_names+1] = k - end - end - surface.regenerate_decorative(decorative_names, {position}) + local decorative_names = {} + for k, v in pairs(game.decorative_prototypes) do + if v.autoplace_specification then + decorative_names[#decorative_names + 1] = k + end + end + surface.regenerate_decorative(decorative_names, {position}) - if math_random(1, 16) ~= 1 then - return - end - local pos = {x = position.x * 32 + math_random(1,32), y = position.y * 32 + math_random(1,32)} - local noise = get_noise(1, pos) - if noise > 0.4 or noise < -0.4 then - return - end - local distance_to_center = math.sqrt(pos.x^2 + pos.y^2) - local size = 7 + math.floor(distance_to_center * 0.0075) - if size > 20 then - size = 20 - end - local amount = 500 + distance_to_center * 2 - map_functions.draw_rainbow_patch_v2(pos, surface, size, amount) + if math_random(1, 16) ~= 1 then + return + end + local pos = {x = position.x * 32 + math_random(1, 32), y = position.y * 32 + math_random(1, 32)} + local noise = get_noise(1, pos) + if noise > 0.4 or noise < -0.4 then + return + end + local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2) + local size = 7 + math.floor(distance_to_center * 0.0075) + if size > 20 then + size = 20 + end + local amount = 500 + distance_to_center * 2 + map_functions.draw_rainbow_patch_v2(pos, surface, size, amount) end local function on_marked_for_deconstruction(event) - if disabled_for_deconstruction[event.entity.name] then - event.entity.cancel_deconstruction(game.players[event.player_index].force.name) - end + if disabled_for_deconstruction[event.entity.name] then + event.entity.cancel_deconstruction(game.players[event.player_index].force.name) + end end local function on_player_joined_game(event) - local player = game.players[event.player_index] - if player.online_time == 0 then - player.insert({name = "pistol", count = 1}) - player.insert({name = "firearm-magazine", count = 16}) - end + local player = game.players[event.player_index] + if player.online_time == 0 then + player.insert({name = 'pistol', count = 1}) + player.insert({name = 'firearm-magazine', count = 16}) + end - if global.map_init_done then return end + if global.map_init_done then + return + end - game.forces["player"].technologies["optics"].researched = true + game.forces['player'].technologies['optics'].researched = true - game.surfaces["nauvis"].ticks_per_day = game.surfaces["nauvis"].ticks_per_day * 2 - game.surfaces["nauvis"].min_brightness = 0.08 - game.surfaces["nauvis"].daytime = 0.7 + game.surfaces['nauvis'].ticks_per_day = game.surfaces['nauvis'].ticks_per_day * 2 + game.surfaces['nauvis'].min_brightness = 0.08 + game.surfaces['nauvis'].daytime = 0.7 - game.create_force("scrap") - game.create_force("scrap_defense") - game.forces.player.set_friend('scrap', true) - game.forces.enemy.set_friend('scrap', true) - game.forces.scrap.set_friend('player', true) - game.forces.scrap.set_friend('enemy', true) - game.forces.scrap.share_chart = false - - game.forces.scrap_defense.set_friend("enemy",true) - game.forces.enemy.set_friend("scrap_defense", true) + game.create_force('scrap') + game.create_force('scrap_defense') + game.forces.player.set_friend('scrap', true) + game.forces.enemy.set_friend('scrap', true) + game.forces.scrap.set_friend('player', true) + game.forces.scrap.set_friend('enemy', true) + game.forces.scrap.share_chart = false - global.map_init_done = true + game.forces.scrap_defense.set_friend('enemy', true) + game.forces.enemy.set_friend('scrap_defense', true) + + global.map_init_done = true end local function on_force_created(event) - event.force.set_friend(game.forces.scrap, true) - game.forces.scrap.set_friend(event.force, true) - event.force.technologies["optics"].researched = true + event.force.set_friend(game.forces.scrap, true) + game.forces.scrap.set_friend(event.force, true) + event.force.technologies['optics'].researched = true end local function on_player_mined_entity(event) - local entity = event.entity - if not entity.valid then return end + local entity = event.entity + if not entity.valid then + return + end - local scraps = { - ["crash-site-spaceship-wreck-small-1"] = true, - ["crash-site-spaceship-wreck-small-2"] = true, - ["crash-site-spaceship-wreck-small-3"] = true, - ["crash-site-spaceship-wreck-small-4"] = true, - ["crash-site-spaceship-wreck-small-5"] = true, - ["crash-site-spaceship-wreck-small-6"] = true - } - - if scraps[entity.name] then - if math_random(1,40) == 1 then unearthing_biters(entity.surface, entity.position, math_random(4,12)) end - if math_random(1,80) == 1 then unearthing_worm(entity.surface, entity.position) end - if math_random(1,160) == 1 then tick_tack_trap(entity.surface, entity.position) end - end + local scraps = { + ['crash-site-spaceship-wreck-small-1'] = true, + ['crash-site-spaceship-wreck-small-2'] = true, + ['crash-site-spaceship-wreck-small-3'] = true, + ['crash-site-spaceship-wreck-small-4'] = true, + ['crash-site-spaceship-wreck-small-5'] = true, + ['crash-site-spaceship-wreck-small-6'] = true + } - if entity.force.name ~= "scrap" then return end - local positions = {} - local r = math.ceil(entity.prototype.max_health / 32) - for x = r * -1, r, 1 do - for y = r * -1, r, 1 do - positions[#positions + 1] = {x = entity.position.x + x, y = entity.position.y + y} - end - end - positions = shuffle(positions) - for i = 1, math.ceil(entity.prototype.max_health / 32), 1 do - if not positions[i] then - return - end - if math_random(1,3) ~= 1 then - unearthing_biters(entity.surface, positions[i], math_random(5,10)) - else - unearthing_worm(entity.surface, positions[i]) - end - end + if scraps[entity.name] then + if math_random(1, 40) == 1 then + unearthing_biters(entity.surface, entity.position, math_random(4, 12)) + end + if math_random(1, 80) == 1 then + unearthing_worm(entity.surface, entity.position) + end + if math_random(1, 160) == 1 then + tick_tack_trap(entity.surface, entity.position) + end + end + + if entity.force.name ~= 'scrap' then + return + end + local positions = {} + local r = math.ceil(entity.prototype.max_health / 32) + for x = r * -1, r, 1 do + for y = r * -1, r, 1 do + positions[#positions + 1] = {x = entity.position.x + x, y = entity.position.y + y} + end + end + positions = shuffle(positions) + for i = 1, math.ceil(entity.prototype.max_health / 32), 1 do + if not positions[i] then + return + end + if math_random(1, 3) ~= 1 then + unearthing_biters(entity.surface, positions[i], math_random(5, 10)) + else + unearthing_worm(entity.surface, positions[i]) + end + end end local function on_entity_died(event) - on_player_mined_entity(event) + on_player_mined_entity(event) end local function on_research_finished(event) - event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 300 + event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 300 end local on_init = function() -local T = Map.Pop_info() - T.main_caption = "J u n k y a r d" - T.sub_caption = " ..the scrap is your friend.." - T.text = table.concat({ - "Citizen Log #468-2A-3287, Freelancer Cole\n", - "\n", - "To whoever is reading this message,\n", - "i have most likely already left this doomed place, or... well..\n", - "\n", - "I am stranded on this foreign world since months and i have given up on fixing my ships transceiver.\n", - "Things aren't looking too good, i must admit.\n", - "The rust and devastation tells a story of an advanced civilization,\n", - "which seems to have evacuated their home long time ago.\n", - "\n", - "Any natural resources are rare and the ones worth while are too hard for me to reach.\n", - "Luckily, the wrecks yield all kinds of useful scraps, but also various dangers.\n", - "Almost lost half a leg some days ago while digging out a crate.\n", - "\n", - "The wildlife is extremely aggressive, especially at the time of night.\n", - "Most of these insect appearing like creatures seem to live underground.\n", - "Stay near your light sources, if you want to have a chance of surviving here!!\n", - "\n", - "I must make a move now, hopefully will find those missing parts.\n", - "\n", - "###Log End###" - }) - T.main_caption_color = {r = 150, g = 150, b = 0} - T.sub_caption_color = {r = 0, g = 150, b = 0} + local T = Map.Pop_info() + T.main_caption = 'J u n k y a r d' + T.sub_caption = ' ..the scrap is your friend..' + T.text = + table.concat( + { + 'Citizen Log #468-2A-3287, Freelancer Cole\n', + '\n', + 'To whoever is reading this message,\n', + 'i have most likely already left this doomed place, or... well..\n', + '\n', + 'I am stranded on this foreign world since months and i have given up on fixing my ships transceiver.\n', + "Things aren't looking too good, i must admit.\n", + 'The rust and devastation tells a story of an advanced civilization,\n', + 'which seems to have evacuated their home long time ago.\n', + '\n', + 'Any natural resources are rare and the ones worth while are too hard for me to reach.\n', + 'Luckily, the wrecks yield all kinds of useful scraps, but also various dangers.\n', + 'Almost lost half a leg some days ago while digging out a crate.\n', + '\n', + 'The wildlife is extremely aggressive, especially at the time of night.\n', + 'Most of these insect appearing like creatures seem to live underground.\n', + 'Stay near your light sources, if you want to have a chance of surviving here!!\n', + '\n', + 'I must make a move now, hopefully will find those missing parts.\n', + '\n', + '###Log End###' + } + ) + T.main_caption_color = {r = 150, g = 150, b = 0} + T.sub_caption_color = {r = 0, g = 150, b = 0} end event.on_init(on_init) diff --git a/maps/junkyard_pvp/main.lua b/maps/junkyard_pvp/main.lua index 49e4ae33..271f1c8f 100644 --- a/maps/junkyard_pvp/main.lua +++ b/maps/junkyard_pvp/main.lua @@ -9,7 +9,7 @@ require 'modules.rocks_heal_over_time' require 'maps.junkyard_pvp.share_chat' require 'modules.mineable_wreckage_yields_scrap' local Team = require 'maps.junkyard_pvp.team' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Map = require 'modules.map_info' local math_random = math.random local Public = {} diff --git a/maps/junkyard_pvp/terrain.lua b/maps/junkyard_pvp/terrain.lua index 43d9b2f2..9ffadccb 100644 --- a/maps/junkyard_pvp/terrain.lua +++ b/maps/junkyard_pvp/terrain.lua @@ -3,7 +3,7 @@ local math_abs = math.abs local math_random = math.random local math_floor = math.floor local Treasure = require 'maps.junkyard_pvp.treasure' -local Map_functions = require 'tools.map_functions' +local Map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'} local spawner_raffle = {'biter-spawner', 'biter-spawner', 'biter-spawner', 'spitter-spawner'} @@ -96,11 +96,7 @@ function Public.create_mirror_surface() end end end - for _, e in pairs( - surface.find_entities_filtered( - {area = {{cargo_wagon_position.x - r, cargo_wagon_position.y - r}, {cargo_wagon_position.x + r, cargo_wagon_position.y + r}}, force = {'neutral', 'enemy'}} - ) - ) do + for _, e in pairs(surface.find_entities_filtered({area = {{cargo_wagon_position.x - r, cargo_wagon_position.y - r}, {cargo_wagon_position.x + r, cargo_wagon_position.y + r}}, force = {'neutral', 'enemy'}})) do if math.sqrt(e.position.x ^ 2 + e.position.y ^ 2) < r then e.destroy() end diff --git a/maps/labyrinth.lua b/maps/labyrinth.lua index d3ae2b7e..15bd5c7a 100644 --- a/maps/labyrinth.lua +++ b/maps/labyrinth.lua @@ -8,11 +8,11 @@ require 'modules.satellite_score' local Event = require 'utils.event' local Server = require 'utils.server' local Global = require 'utils.global' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local Score = require 'utils.gui.score' local unique_rooms = require 'maps.labyrinth_unique_rooms' -local SoftReset = require 'functions.soft_reset' +local SoftReset = require 'utils.functions.soft_reset' local Autostash = require 'modules.autostash' local BottomFrame = require 'utils.gui.bottom_frame' local this = { @@ -1022,7 +1022,9 @@ end local function on_entity_died(event) local entity = event.entity - if not entity or not entity.valid then return end + if not entity or not entity.valid then + return + end local name = entity.name local position = entity.position local evolution = game.forces.enemy.evolution_factor @@ -1045,7 +1047,7 @@ local function on_entity_died(event) for _ = 1, math.random(t[2], t[3]), 1 do local p = surface.find_non_colliding_position(t[1], position, 6, 1) if p then - surface.create_entity{name = t[1], position = p} + surface.create_entity {name = t[1], position = p} end end end @@ -1235,7 +1237,9 @@ local loaders = { ['express-loader'] = true } local function on_built_entity(event) - if not event.created_entity or not event.created_entity.valid then return end + if not event.created_entity or not event.created_entity.valid then + return + end local get_score = Score.get_table().score_table local name = event.created_entity.name if inserters[name] then diff --git a/maps/lost_desert.lua b/maps/lost_desert.lua index 4f53f4f2..80ba5c4a 100644 --- a/maps/lost_desert.lua +++ b/maps/lost_desert.lua @@ -12,7 +12,7 @@ require 'modules.flashlight_toggle_button' local simplex_noise = require 'utils.simplex_noise'.d2 local event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local math_random = math.random require 'utils.table' diff --git a/maps/maze_challenge.lua b/maps/maze_challenge.lua index c73fcb5b..76013f58 100644 --- a/maps/maze_challenge.lua +++ b/maps/maze_challenge.lua @@ -1,5 +1,5 @@ --luacheck: ignore -require 'functions.maze' +require 'utils.functions.maze' local event = require 'utils.event' diff --git a/maps/minesweeper/functions.lua b/maps/minesweeper/functions.lua index 898138c6..cff32211 100644 --- a/maps/minesweeper/functions.lua +++ b/maps/minesweeper/functions.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Public = {} -local LootRaffle = require "functions.loot_raffle" +local LootRaffle = require "utils.functions.loot_raffle" local Get_noise = require "utils.get_noise" local safe_zone_radius = 16 diff --git a/maps/mountain_fortress.lua b/maps/mountain_fortress.lua index ee4693d7..8bcf0443 100644 --- a/maps/mountain_fortress.lua +++ b/maps/mountain_fortress.lua @@ -18,7 +18,7 @@ local difficulty_factor = 4 local event = require 'utils.event' local math_random = math.random local insert = table.insert -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise' local simplex_noise = simplex_noise.d2 diff --git a/maps/mountain_fortress_v2/main.lua b/maps/mountain_fortress_v2/main.lua index ba3610c2..4cc9ce7e 100644 --- a/maps/mountain_fortress_v2/main.lua +++ b/maps/mountain_fortress_v2/main.lua @@ -4,8 +4,8 @@ global.offline_loot = true local darkness = false -require 'functions.soft_reset' -require 'functions.basic_markets' +require 'utils.functions.soft_reset' +require 'utils.functions.basic_markets' local Gui = require 'utils.gui' local Map_score = require 'utils.gui.map_score' @@ -25,7 +25,7 @@ local Immersive_cargo_wagons = require 'modules.immersive_cargo_wagons.main' require 'maps.mountain_fortress_v2.flamethrower_nerf' local BiterRolls = require 'modules.wave_defense.biter_rolls' local BiterHealthBooster = require 'modules.biter_health_booster' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Pets = require 'modules.biter_pets' local Map = require 'modules.map_info' local WD = require 'modules.wave_defense.table' diff --git a/maps/mountain_fortress_v2/terrain.lua b/maps/mountain_fortress_v2/terrain.lua index 061606f0..89cd750a 100644 --- a/maps/mountain_fortress_v2/terrain.lua +++ b/maps/mountain_fortress_v2/terrain.lua @@ -2,7 +2,7 @@ local Biters = require 'modules.wave_defense.biter_rolls' local Immersive_cargo_wagons = require 'modules.immersive_cargo_wagons.main' local Treasure = require 'maps.mountain_fortress_v2.treasure' -local Market = require 'functions.basic_markets' +local Market = require 'utils.functions.basic_markets' local math_random = math.random local math_floor = math.floor local math_abs = math.abs diff --git a/maps/mountain_fortress_v2/treasure.lua b/maps/mountain_fortress_v2/treasure.lua index 55e86660..71da63ea 100644 --- a/maps/mountain_fortress_v2/treasure.lua +++ b/maps/mountain_fortress_v2/treasure.lua @@ -5,7 +5,7 @@ local math_random = math.random local math_floor = math.floor local math_abs = math.abs -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local blacklist = { ['cargo-wagon'] = true, diff --git a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua index 70ed1db8..4d0bcbc2 100644 --- a/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive/spawn_locomotive.lua @@ -1,7 +1,7 @@ local Public = require 'maps.mountain_fortress_v3.table' local ICW = require 'maps.mountain_fortress_v3.icw.main' local Task = require 'utils.task_token' -local MapFunctions = require 'tools.map_functions' +local MapFunctions = require 'utils.tools.map_functions' local random = math.random local floor = math.floor diff --git a/maps/mountain_fortress_v3/loot.lua b/maps/mountain_fortress_v3/loot.lua index b875b368..bfba0a06 100644 --- a/maps/mountain_fortress_v3/loot.lua +++ b/maps/mountain_fortress_v3/loot.lua @@ -1,4 +1,4 @@ -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local Public = require 'maps.mountain_fortress_v3.table' local random = math.random local abs = math.abs diff --git a/maps/mountain_race/terrain.lua b/maps/mountain_race/terrain.lua index 551ea830..34b96a05 100644 --- a/maps/mountain_race/terrain.lua +++ b/maps/mountain_race/terrain.lua @@ -3,7 +3,7 @@ local Public = {} local math_random = math.random local Immersive_cargo_wagons = require 'modules.immersive_cargo_wagons.main' local GetNoise = require 'utils.get_noise' -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local wagon_raffle = {'cargo-wagon', 'cargo-wagon', 'cargo-wagon', 'locomotive', 'fluid-wagon'} local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'} diff --git a/maps/native_war/main.lua b/maps/native_war/main.lua index b74074c7..9adb2068 100644 --- a/maps/native_war/main.lua +++ b/maps/native_war/main.lua @@ -10,7 +10,7 @@ local Team = require 'maps.native_war.team' local Terrain = require 'maps.native_war.terrain' local Init = require 'maps.native_war.init' local Settings = require 'maps.native_war.settings' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Map = require 'maps.native_war.map_info' local Team_manager = require 'maps.native_war.team_manager' local math_random = math.random diff --git a/maps/native_war/terrain.lua b/maps/native_war/terrain.lua index cbef8c86..c59cb296 100644 --- a/maps/native_war/terrain.lua +++ b/maps/native_war/terrain.lua @@ -1,7 +1,7 @@ --luacheck: ignore local math_abs = math.abs local math_random = math.random -local Map_functions = require 'tools.map_functions' +local Map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local Public = {} @@ -86,8 +86,7 @@ local function create_markets(surface) global.market1 = e local energy_source = {type = 'electric', buffer_capacity = '10GJ', usage_priority = 'tertiary', input_flow_limit = '1GW', output_flow_limit = '0W', drain = '0W'} - local eei = - surface.create_entity({type = 'electric-energy-interface', name = 'electric-energy-interface', energy_source = energy_source, position = {-200, -2}, force = 'west'}) + local eei = surface.create_entity({type = 'electric-energy-interface', name = 'electric-energy-interface', energy_source = energy_source, position = {-200, -2}, force = 'west'}) local ep = surface.create_entity({name = 'small-electric-pole', position = {-200, -5}, force = 'west'}) ep.destructible = false @@ -109,8 +108,7 @@ local function create_markets(surface) global.market = f local energy_source = {type = 'electric', buffer_capacity = '10GJ', usage_priority = 'tertiary', input_flow_limit = '1GW', output_flow_limit = '0W', drain = '0W'} - local eei2 = - surface.create_entity({type = 'electric-energy-interface', name = 'electric-energy-interface', energy_source = energy_source, position = {201, -2}, force = 'east'}) + local eei2 = surface.create_entity({type = 'electric-energy-interface', name = 'electric-energy-interface', energy_source = energy_source, position = {201, -2}, force = 'east'}) local ep2 = surface.create_entity({name = 'small-electric-pole', position = {200, -5}, force = 'east'}) ep2.destructible = false @@ -346,12 +344,7 @@ local function out_of_map_area(event) local p = {x = left_top.x + x, y = left_top.y + y} if is_out_of_map(p) then if - (p.x == -137 or p.x == -138 or p.x == -102 or p.x == -103 or p.x == -78 or p.x == -77 or p.x == -42 or p.x == -43 or p.x == -17 or p.x == -18 or p.x == 17 or - p.x == 18 or - p.x == 42 or - p.x == 43 or - p.x == 77 or - p.x == 78) and + (p.x == -137 or p.x == -138 or p.x == -102 or p.x == -103 or p.x == -78 or p.x == -77 or p.x == -42 or p.x == -43 or p.x == -17 or p.x == -18 or p.x == 17 or p.x == 18 or p.x == 42 or p.x == 43 or p.x == 77 or p.x == 78) and (p.y == -32 or p.y == -33 or p.y == -95 or p.y == -96) then surface.set_tiles({{name = 'hazard-concrete-right', position = p}}, true) @@ -436,11 +429,7 @@ local function out_of_map_area(event) e.minable = false end elseif - (p.x == 137 or p.x == 138 or p.x == 102 or p.x == 103 or p.x == 78 or p.x == 77 or p.x == 42 or p.x == 43 or p.x == 17 or p.x == 18 or p.x == -17 or p.x == -18 or - p.x == -42 or - p.x == -43 or - p.x == -77 or - p.x == -78) and + (p.x == 137 or p.x == 138 or p.x == 102 or p.x == 103 or p.x == 78 or p.x == 77 or p.x == 42 or p.x == 43 or p.x == 17 or p.x == 18 or p.x == -17 or p.x == -18 or p.x == -42 or p.x == -43 or p.x == -77 or p.x == -78) and (p.y == 32 or p.y == 33 or p.y == 95 or p.y == 96) then surface.set_tiles({{name = 'hazard-concrete-right', position = p}}, true) diff --git a/maps/nightfall.lua b/maps/nightfall.lua index 2dd2a009..75b7c88f 100644 --- a/maps/nightfall.lua +++ b/maps/nightfall.lua @@ -4,7 +4,7 @@ local event = require 'utils.event' local math_random = math.random local insert = table.insert -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise' local simplex_noise = simplex_noise.d2 require 'maps.nightfall_map_intro' @@ -420,14 +420,8 @@ local function generate_spawn_area(surface) for y = -160, 160, 1 do local pos = {x = x, y = y} if pos.x > fort_size * -1 and pos.x < fort_size and pos.y > fort_size * -1 and pos.y < fort_size then - if - pos.x > (fort_size - fort_wall_width) * -1 and pos.x < fort_size - fort_wall_width and pos.y > (fort_size - fort_wall_width) * -1 and - pos.y < fort_size - fort_wall_width - then - if - pos.x <= (fort_size - fort_wall_width * 2) * -1 or pos.x >= (fort_size - fort_wall_width * 2) or pos.y <= (fort_size - fort_wall_width * 2) * -1 or - pos.y >= (fort_size - fort_wall_width * 2) - then + if pos.x > (fort_size - fort_wall_width) * -1 and pos.x < fort_size - fort_wall_width and pos.y > (fort_size - fort_wall_width) * -1 and pos.y < fort_size - fort_wall_width then + if pos.x <= (fort_size - fort_wall_width * 2) * -1 or pos.x >= (fort_size - fort_wall_width * 2) or pos.y <= (fort_size - fort_wall_width * 2) * -1 or pos.y >= (fort_size - fort_wall_width * 2) then table.insert(turrets, {name = 'gun-turret', position = {x = pos.x, y = pos.y}, force = 'player'}) end end @@ -440,10 +434,7 @@ local function generate_spawn_area(surface) table.insert(tiles, {name = 'stone-path', position = {x = pos.x, y = pos.y}}) - if - pos.x <= (fort_size - fort_wall_width) * -1 or pos.x >= (fort_size - fort_wall_width) or pos.y <= (fort_size - fort_wall_width) * -1 or - pos.y >= (fort_size - fort_wall_width) - then + if pos.x <= (fort_size - fort_wall_width) * -1 or pos.x >= (fort_size - fort_wall_width) or pos.y <= (fort_size - fort_wall_width) * -1 or pos.y >= (fort_size - fort_wall_width) then if math_random(1, 3) ~= 1 then table.insert(entities, {name = 'stone-wall', position = {x = pos.x, y = pos.y}, force = 'player'}) end diff --git a/maps/overgrowth.lua b/maps/overgrowth.lua index 01a3518e..a49cf1bf 100644 --- a/maps/overgrowth.lua +++ b/maps/overgrowth.lua @@ -16,11 +16,11 @@ require 'modules.trees_randomly_die' require 'maps.overgrowth_map_info' -local Reset = require 'functions.soft_reset' -local kaboom = require 'functions.omegakaboom' +local Reset = require 'utils.functions.soft_reset' +local kaboom = require 'utils.functions.omegakaboom' local Difficulty = require 'modules.difficulty_vote' -local unearthing_biters = require 'functions.unearthing_biters' +local unearthing_biters = require 'utils.functions.unearthing_biters' local event = require 'utils.event' local math_random = math.random diff --git a/maps/pidgeotto/main.lua b/maps/pidgeotto/main.lua index caac57f1..9558f5dc 100644 --- a/maps/pidgeotto/main.lua +++ b/maps/pidgeotto/main.lua @@ -13,7 +13,7 @@ local Session = require 'utils.datastore.session_data' local Difficulty = require 'modules.difficulty_vote' local Map = require 'modules.map_info' local Event = require 'utils.event' -local Reset = require 'functions.soft_reset' +local Reset = require 'utils.functions.soft_reset' local Server = require 'utils.server' local Poll = require 'utils.gui.poll' local boss_biter = require 'maps.pidgeotto.boss_biters' diff --git a/maps/pidgeotto/terrain.lua b/maps/pidgeotto/terrain.lua index 2e59b8b6..fb441228 100644 --- a/maps/pidgeotto/terrain.lua +++ b/maps/pidgeotto/terrain.lua @@ -1,6 +1,6 @@ local Event = require 'utils.event' local Builder = require 'maps.pidgeotto.b' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise'.d2 local FDT = require 'maps.pidgeotto.table' local math_random = math.random diff --git a/maps/pirates/common.lua b/maps/pirates/common.lua index 3ce9a248..91bbab90 100644 --- a/maps/pirates/common.lua +++ b/maps/pirates/common.lua @@ -1,6 +1,5 @@ -- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates. - local Math = require 'maps.pirates.math' local Raffle = require 'maps.pirates.raffle' local Server = require 'utils.server' @@ -11,14 +10,13 @@ local _inspect = require 'utils.inspect'.inspect -- local IslandEnum = require 'maps.pirates.surfaces.islands.island_enum' -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' -- local simplex_noise = require 'utils.simplex_noise'.d2 -- local perlin_noise = require 'utils.perlin_noise' -- local Force_health_booster = require 'modules.force_health_booster' -- == Common variables and functions used throughout pirate ship files - local Public = {} Public.activeCrewsCap = 3 @@ -70,148 +68,152 @@ Public.lobby_force_name = 'player' -- Public.mainshop_rate_limit_ticks = 11 - function Public.ore_real_to_abstract(amount) - return amount/1800 + return amount / 1800 end function Public.ore_abstract_to_real(amount) - return Math.ceil(amount*1800) + return Math.ceil(amount * 1800) end -- 3000 oil resource is '1% yield' function Public.oil_real_to_abstract(amount) - return amount/(3000) + return amount / (3000) end function Public.oil_abstract_to_real(amount) - return Math.ceil(amount*3000) + return Math.ceil(amount * 3000) end function Public.difficulty_scale() - local memory = Memory.get_crew_memory() - if memory.overworldx > 0 then - return memory.difficulty - else - return 0.75 - end + local memory = Memory.get_crew_memory() + if memory.overworldx > 0 then + return memory.difficulty + else + return 0.75 + end +end +function Public.capacity() + return Memory.get_crew_memory().capacity end -function Public.capacity() return Memory.get_crew_memory().capacity end -- function Public.mode() return Memory.get_crew_memory().mode end -function Public.overworldx() return Memory.get_crew_memory().overworldx end -function Public.game_completion_progress() return Public.overworldx()/CoreData.victory_x end -function Public.game_completion_progress_capped() return Math.clamp(0, 1, Public.overworldx()/CoreData.victory_x) end +function Public.overworldx() + return Memory.get_crew_memory().overworldx +end +function Public.game_completion_progress() + return Public.overworldx() / CoreData.victory_x +end +function Public.game_completion_progress_capped() + return Math.clamp(0, 1, Public.overworldx() / CoreData.victory_x) +end function Public.capacity_scale() - local capacity = Public.capacity() - if not capacity then --e.g. for EE wattage on boats not owned by a crew - return 1 - elseif capacity <= 1 then - return 0.5 - elseif capacity <= 4 then - return 0.75 - elseif capacity <= 8 then - return 1 - elseif capacity <= 16 then - return 1.3 - else - return 1.5 - end + local capacity = Public.capacity() + if not capacity then --e.g. for EE wattage on boats not owned by a crew + return 1 + elseif capacity <= 1 then + return 0.5 + elseif capacity <= 4 then + return 0.75 + elseif capacity <= 8 then + return 1 + elseif capacity <= 16 then + return 1.3 + else + return 1.5 + end end function Public.activecrewcount() - local global_memory = Memory.get_global_memory() - local memory = Memory.get_crew_memory() - if not Public.is_id_valid(memory.id) then return 0 end + local global_memory = Memory.get_global_memory() + local memory = Memory.get_crew_memory() + if not Public.is_id_valid(memory.id) then + return 0 + end - local count = 0 - for _, id in pairs(memory.crewplayerindices) do - local player = game.players[id] - if player and player.valid and (not Utils.contains(global_memory.afk_player_indices, player.index)) and (not Utils.contains(memory.spectatorplayerindices, player.index)) then - count = count + 1 - end - end + local count = 0 + for _, id in pairs(memory.crewplayerindices) do + local player = game.players[id] + if player and player.valid and (not Utils.contains(global_memory.afk_player_indices, player.index)) and (not Utils.contains(memory.spectatorplayerindices, player.index)) then + count = count + 1 + end + end - return count + return count end - function Public.notify_game(message, color_override) - color_override = color_override or CoreData.colors.notify_game - game.print({"", '>> ', message}, color_override) + color_override = color_override or CoreData.colors.notify_game + game.print({'', '>> ', message}, color_override) end function Public.notify_lobby(message, color_override) - color_override = color_override or CoreData.colors.notify_lobby - game.forces[Public.lobby_force_name].print({"", '>> ', message}, color_override) + color_override = color_override or CoreData.colors.notify_lobby + game.forces[Public.lobby_force_name].print({'', '>> ', message}, color_override) end function Public.notify_force(force, message, color_override) - color_override = color_override or CoreData.colors.notify_force - force.print({"", '>> ', message}, color_override) + color_override = color_override or CoreData.colors.notify_force + force.print({'', '>> ', message}, color_override) end function Public.notify_force_light(force, message, color_override) - color_override = color_override or CoreData.colors.notify_force_light - force.print({"", '>> ', message}, color_override) + color_override = color_override or CoreData.colors.notify_force_light + force.print({'', '>> ', message}, color_override) end function Public.notify_force_error(force, message, color_override) - color_override = color_override or CoreData.colors.notify_error - force.print({"", '>> ', message}, color_override) - force.play_sound{path = "utility/cannot_build"} + color_override = color_override or CoreData.colors.notify_error + force.print({'', '>> ', message}, color_override) + force.play_sound {path = 'utility/cannot_build'} end function Public.notify_player_error(player, message, color_override) - color_override = color_override or CoreData.colors.notify_error - player.print({"", '## ', {'pirates.notify_whisper'}, ' ', message}, color_override) - player.play_sound{path = "utility/cannot_build"} + color_override = color_override or CoreData.colors.notify_error + player.print({'', '## ', {'pirates.notify_whisper'}, ' ', message}, color_override) + player.play_sound {path = 'utility/cannot_build'} end function Public.notify_player_expected(player, message, color_override) - color_override = color_override or CoreData.colors.notify_player_expected - player.print({"", '## ', {'pirates.notify_whisper'}, ' ', message}, color_override) + color_override = color_override or CoreData.colors.notify_player_expected + player.print({'', '## ', {'pirates.notify_whisper'}, ' ', message}, color_override) end function Public.notify_player_announce(player, message, color_override) - color_override = color_override or CoreData.colors.notify_player_announce - player.print({"", '## ', {'pirates.notify_whisper'}, ' ', message}, color_override) + color_override = color_override or CoreData.colors.notify_player_announce + player.print({'', '## ', {'pirates.notify_whisper'}, ' ', message}, color_override) end function Public.parrot_speak(force, message) - force.print({"", {'pirates.notify_parrot'}, ' ', message}, CoreData.colors.parrot) + force.print({'', {'pirates.notify_parrot'}, ' ', message}, CoreData.colors.parrot) - local memory = Memory.get_crew_memory() - Server.to_discord_embed_raw({"", '[' .. memory.name .. '] ', {'pirates.notify_parrot'}, ' ', message}, true) + local memory = Memory.get_crew_memory() + Server.to_discord_embed_raw({'', '[' .. memory.name .. '] ', {'pirates.notify_parrot'}, ' ', message}, true) end - function Public.flying_text(surface, position, text) - surface.create_entity( - { - name = 'flying-text', - position = {position.x - 0.7, position.y - 3.05}, - text = text, - } - ) + surface.create_entity( + { + name = 'flying-text', + position = {position.x - 0.7, position.y - 3.05}, + text = text + } + ) end - function Public.flying_text_small(surface, position, text) --differs just in the location of the text, more suitable for small things like '+' - surface.create_entity( - { - name = 'flying-text', - position = {position.x - 0.08, position.y - 1.5}, - -- position = {position.x - 0.06, position.y - 1.5}, - text = text, - } - ) + surface.create_entity( + { + name = 'flying-text', + position = {position.x - 0.08, position.y - 1.5}, + -- position = {position.x - 0.06, position.y - 1.5}, + text = text + } + ) end - - function Public.processed_loot_data(raw_data) - local ret = {} - for i = 1, #raw_data do - local loot_data_item = raw_data[i] - ret[#ret + 1] = { + local ret = {} + for i = 1, #raw_data do + local loot_data_item = raw_data[i] + ret[#ret + 1] = { weight = loot_data_item[1], game_completion_progress_min = loot_data_item[2], game_completion_progress_max = loot_data_item[3], @@ -221,8 +223,8 @@ function Public.processed_loot_data(raw_data) max_count = loot_data_item[7], map_subtype = loot_data_item[8] } - end - return ret + end + return ret end --=='raw' data is in the form e.g. @@ -232,1454 +234,1478 @@ end -- {20, 0, 1, false, 'flying-robot-frame', 20, 35}, -- } - - --@TODO: Replace this old function with the newer code in raffle.lua function Public.raffle_from_processed_loot_data(processed_loot_data, how_many, game_completion_progress) - local ret = {} + local ret = {} local loot_types, loot_weights = {}, {} for i = 1, #processed_loot_data, 1 do - local data = processed_loot_data[i] + local data = processed_loot_data[i] table.insert(loot_types, {['name'] = data.name, ['min_count'] = data.min_count, ['max_count'] = data.max_count}) - local destination = Public.current_destination() - if not (destination and destination.subtype and data.map_subtype and data.map_subtype == destination.subtype) then - if data.scaling then -- scale down weights away from the midpoint 'peak' (without changing the mean) - local midpoint = (data.game_completion_progress_max + data.game_completion_progress_min) / 2 - local difference = (data.game_completion_progress_max - data.game_completion_progress_min) - local w = 2 * data.weight * Math.max(0, 1 - (Math.abs(game_completion_progress - midpoint) / (difference / 2))) - table.insert(loot_weights, w) - else -- no scaling - if data.game_completion_progress_min <= game_completion_progress and data.game_completion_progress_max >= game_completion_progress then - table.insert(loot_weights, data.weight) - else - table.insert(loot_weights, 0) - end - end - end + local destination = Public.current_destination() + if not (destination and destination.subtype and data.map_subtype and data.map_subtype == destination.subtype) then + if data.scaling then -- scale down weights away from the midpoint 'peak' (without changing the mean) + local midpoint = (data.game_completion_progress_max + data.game_completion_progress_min) / 2 + local difference = (data.game_completion_progress_max - data.game_completion_progress_min) + local w = 2 * data.weight * Math.max(0, 1 - (Math.abs(game_completion_progress - midpoint) / (difference / 2))) + table.insert(loot_weights, w) + else -- no scaling + if data.game_completion_progress_min <= game_completion_progress and data.game_completion_progress_max >= game_completion_progress then + table.insert(loot_weights, data.weight) + else + table.insert(loot_weights, 0) + end + end + end end - for _ = 1, how_many do + for _ = 1, how_many do local loot = Raffle.raffle(loot_types, loot_weights) - if loot then - local low = Math.max(1, Math.ceil(loot.min_count)) - local high = Math.max(1, Math.ceil(loot.max_count)) - local _count = Math.random(low, high) - local lucky = Math.random(1, 220) - if lucky == 1 then --lucky - _count = _count * 3 - elseif lucky <= 12 then - _count = _count * 2 - end - ret[#ret + 1] = {name = loot.name, count = _count} - end + if loot then + local low = Math.max(1, Math.ceil(loot.min_count)) + local high = Math.max(1, Math.ceil(loot.max_count)) + local _count = Math.random(low, high) + local lucky = Math.random(1, 220) + if lucky == 1 then --lucky + _count = _count * 3 + elseif lucky <= 12 then + _count = _count * 2 + end + ret[#ret + 1] = {name = loot.name, count = _count} + end end - return ret + return ret end - - - - function Public.give(player, stacks, spill_position, short_form, spill_surface, flying_text_position) - -- stack elements of form {name = '', count = '', color = {r = , g = , b = }} - -- to just spill on the ground, pass player and nill and give a position and surface directly - spill_position = spill_position or player.position - spill_surface = spill_surface or player.surface - flying_text_position = flying_text_position or spill_position + -- stack elements of form {name = '', count = '', color = {r = , g = , b = }} + -- to just spill on the ground, pass player and nill and give a position and surface directly + spill_position = spill_position or player.position + spill_surface = spill_surface or player.surface + flying_text_position = flying_text_position or spill_position - local text1 = '' - local text2 = '' + local text1 = '' + local text2 = '' - local stacks2 = stacks - table.sort(stacks2, function(a,b) return a.name < b.name end) + local stacks2 = stacks + table.sort( + stacks2, + function(a, b) + return a.name < b.name + end + ) - if not (spill_surface and spill_surface.valid) then return end - local inv + if not (spill_surface and spill_surface.valid) then + return + end + local inv - if player then - inv = player.get_inventory(defines.inventory.character_main) - if not (inv and inv.valid) then return end - end + if player then + inv = player.get_inventory(defines.inventory.character_main) + if not (inv and inv.valid) then + return + end + end - for j = 1, #stacks2 do - local stack = stacks2[j] - local itemname, itemcount, flying_text_color = stack.name, stack.count or 1, stack.color or (CoreData.colors[stack.name] or {r = 1, g = 1, b = 1}) - local itemcount_remember = itemcount + for j = 1, #stacks2 do + local stack = stacks2[j] + local itemname, itemcount, flying_text_color = stack.name, stack.count or 1, stack.color or (CoreData.colors[stack.name] or {r = 1, g = 1, b = 1}) + local itemcount_remember = itemcount - if not itemname then return end + if not itemname then + return + end - if itemcount > 0 then - if player then - local a = inv.insert{name = itemname, count = itemcount} - itemcount = itemcount - a - if itemcount >= 50 then - for i = 1, Math.floor(itemcount / 50), 1 do - local e = spill_surface.create_entity{name = 'item-on-ground', position = spill_position, stack = {name = itemname, count = 50}} - if e and e.valid then - e.to_be_looted = true - end - itemcount = itemcount - 50 - end - end - if itemcount > 0 then - -- if itemcount < 5 then - -- spill_surface.spill_item_stack(spill_position, {name = itemname, count = itemcount}, true) - -- else - -- local e = spill_surface.create_entity{name = 'item-on-ground', position = spill_position, stack = {name = itemname, count = itemcount}} - -- if e and e.valid then - -- e.to_be_looted = true - -- end - -- end - spill_surface.spill_item_stack(spill_position, {name = itemname, count = itemcount}, true) - end - else - -- local e = spill_surface.create_entity{name = 'item-on-ground', position = spill_position, stack = {name = itemname, count = itemcount}} - -- if e and e.valid then - -- e.to_be_looted = true - -- end - spill_surface.spill_item_stack(spill_position, {name = itemname, count = itemcount}, true) - end - end + if itemcount > 0 then + if player then + local a = inv.insert {name = itemname, count = itemcount} + itemcount = itemcount - a + if itemcount >= 50 then + for i = 1, Math.floor(itemcount / 50), 1 do + local e = spill_surface.create_entity {name = 'item-on-ground', position = spill_position, stack = {name = itemname, count = 50}} + if e and e.valid then + e.to_be_looted = true + end + itemcount = itemcount - 50 + end + end + if itemcount > 0 then + -- if itemcount < 5 then + -- spill_surface.spill_item_stack(spill_position, {name = itemname, count = itemcount}, true) + -- else + -- local e = spill_surface.create_entity{name = 'item-on-ground', position = spill_position, stack = {name = itemname, count = itemcount}} + -- if e and e.valid then + -- e.to_be_looted = true + -- end + -- end + spill_surface.spill_item_stack(spill_position, {name = itemname, count = itemcount}, true) + end + else + -- local e = spill_surface.create_entity{name = 'item-on-ground', position = spill_position, stack = {name = itemname, count = itemcount}} + -- if e and e.valid then + -- e.to_be_looted = true + -- end + spill_surface.spill_item_stack(spill_position, {name = itemname, count = itemcount}, true) + end + end - if itemcount_remember >= 0 then - if short_form then - text1 = text1 .. '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. ']' .. '+' .. itemcount_remember .. '[/color]' - else - text1 = text1 .. '[color=1,1,1]' - text1 = text1 .. '+' - text1 = text1 .. itemcount_remember .. '[/color] [item=' .. itemname .. ']' - end - else - if short_form then - text1 = text1 .. '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. ']' .. '-' .. -itemcount_remember .. '[/color]' - else - text1 = text1 .. '[color=1,1,1]' - text1 = text1 .. '-' - text1 = text1 .. -itemcount_remember .. '[/color] [item=' .. itemname .. ']' - end - end + if itemcount_remember >= 0 then + if short_form then + text1 = text1 .. '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. ']' .. '+' .. itemcount_remember .. '[/color]' + else + text1 = text1 .. '[color=1,1,1]' + text1 = text1 .. '+' + text1 = text1 .. itemcount_remember .. '[/color] [item=' .. itemname .. ']' + end + else + if short_form then + text1 = text1 .. '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. ']' .. '-' .. -itemcount_remember .. '[/color]' + else + text1 = text1 .. '[color=1,1,1]' + text1 = text1 .. '-' + text1 = text1 .. -itemcount_remember .. '[/color] [item=' .. itemname .. ']' + end + end + if player and (not short_form) then + -- count total of that item they have: + local new_total_count = 0 - if player and (not short_form) then - -- count total of that item they have: - local new_total_count = 0 + local cursor_stack = player.cursor_stack + if cursor_stack and cursor_stack.valid_for_read and cursor_stack.name == itemname and cursor_stack.count and cursor_stack.count > 0 then + new_total_count = new_total_count + cursor_stack.count + end + if inv and inv.get_item_count(itemname) and inv.get_item_count(itemname) > 0 then + new_total_count = new_total_count + inv.get_item_count(itemname) + end - local cursor_stack = player.cursor_stack - if cursor_stack and cursor_stack.valid_for_read and cursor_stack.name == itemname and cursor_stack.count and cursor_stack.count > 0 then - new_total_count = new_total_count + cursor_stack.count - end - if inv and inv.get_item_count(itemname) and inv.get_item_count(itemname) > 0 then - new_total_count = new_total_count + inv.get_item_count(itemname) - end + if #stacks2 > 1 then + text2 = text2 .. '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. ']' .. new_total_count .. '[/color]' + else + text2 = '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. '](' .. new_total_count .. ')[/color]' + end + if j < #stacks2 then + text2 = text2 .. ', ' + end + end - if #stacks2 > 1 then - text2 = text2 .. '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. ']' .. new_total_count .. '[/color]' - else - text2 = '[color=' .. flying_text_color.r .. ',' .. flying_text_color.g .. ',' .. flying_text_color.b .. '](' .. new_total_count .. ')[/color]' - end - if j < #stacks2 then - text2 = text2 .. ', ' - end - end + if j < #stacks2 then + text1 = text1 .. ', ' + end + end - if j < #stacks2 then - text1 = text1 .. ', ' - end - end - - if text2 ~= '' then - if #stacks2 > 1 then - text2 = '(' .. text2 .. ')' - end - Public.flying_text(spill_surface, flying_text_position, text1 .. ' [font=count-font]' .. text2 .. '[/font]') - else - Public.flying_text(spill_surface, flying_text_position, text1) - end + if text2 ~= '' then + if #stacks2 > 1 then + text2 = '(' .. text2 .. ')' + end + Public.flying_text(spill_surface, flying_text_position, text1 .. ' [font=count-font]' .. text2 .. '[/font]') + else + Public.flying_text(spill_surface, flying_text_position, text1) + end end - - function Public.is_captain(player) - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - if memory.playerindex_captain and memory.playerindex_captain == player.index then - return true - else - return false - end + if memory.playerindex_captain and memory.playerindex_captain == player.index then + return true + else + return false + end end - function Public.is_officer(player_index) - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - if memory.officers_table and memory.officers_table[player_index] then - return true - else - return false - end + if memory.officers_table and memory.officers_table[player_index] then + return true + else + return false + end end -- lifted shamelessly from biter battles, since I haven't done balancing work on this: function Public.surplus_evo_biter_damage_modifier(surplus_evo) - return Math.floor(surplus_evo/2*1000)/1000 --is this floor needed? + return Math.floor(surplus_evo / 2 * 1000) / 1000 --is this floor needed? end -- function Public.surplus_evo_biter_health_fractional_modifier(surplus_evo) -- return surplus_evo*3 -- -- return Math.floor(surplus_evo*3*1000)/1000 -- end - function Public.set_biter_surplus_evo_modifiers() - local memory = Memory.get_crew_memory() - local enemy_force = memory.enemy_force + local memory = Memory.get_crew_memory() + local enemy_force = memory.enemy_force if not (memory.evolution_factor and enemy_force and enemy_force.valid) then return nil end - local surplus = memory.evolution_factor - 1 + local surplus = memory.evolution_factor - 1 - local damage_fractional_mod - -- local health_fractional_mod + local damage_fractional_mod + -- local health_fractional_mod - if surplus > 0 then - damage_fractional_mod = Public.surplus_evo_biter_damage_modifier(surplus) - -- health_fractional_mod = Public.surplus_evo_biter_health_fractional_modifier(surplus) - else - damage_fractional_mod = 0 - -- health_fractional_mod = 0 - end - enemy_force.set_ammo_damage_modifier('melee', damage_fractional_mod) - enemy_force.set_ammo_damage_modifier('biological', damage_fractional_mod) - enemy_force.set_ammo_damage_modifier('artillery-shell', damage_fractional_mod) - enemy_force.set_ammo_damage_modifier('flamethrower', damage_fractional_mod) + if surplus > 0 then + -- health_fractional_mod = Public.surplus_evo_biter_health_fractional_modifier(surplus) + damage_fractional_mod = Public.surplus_evo_biter_damage_modifier(surplus) + else + -- health_fractional_mod = 0 + damage_fractional_mod = 0 + end + enemy_force.set_ammo_damage_modifier('melee', damage_fractional_mod) + enemy_force.set_ammo_damage_modifier('biological', damage_fractional_mod) + enemy_force.set_ammo_damage_modifier('artillery-shell', damage_fractional_mod) + enemy_force.set_ammo_damage_modifier('flamethrower', damage_fractional_mod) - -- this event is behaving really weirdly, e.g. messing up samurai damage: - -- Force_health_booster.set_health_modifier(enemy_force.index, 1 + health_fractional_mod) + -- this event is behaving really weirdly, e.g. messing up samurai damage: + -- Force_health_booster.set_health_modifier(enemy_force.index, 1 + health_fractional_mod) end function Public.set_evo(evolution) - local memory = Memory.get_crew_memory() - memory.evolution_factor = evolution - if memory.enemy_force_name then - local ef = memory.enemy_force - if ef and ef.valid then - ef.evolution_factor = memory.evolution_factor - Public.set_biter_surplus_evo_modifiers() - end - end + local memory = Memory.get_crew_memory() + memory.evolution_factor = evolution + if memory.enemy_force_name then + local ef = memory.enemy_force + if ef and ef.valid then + ef.evolution_factor = memory.evolution_factor + Public.set_biter_surplus_evo_modifiers() + end + end end function Public.increment_evo(evolution) - local memory = Memory.get_crew_memory() - memory.evolution_factor = memory.evolution_factor + evolution - if memory.enemy_force_name then - local ef = memory.enemy_force - if ef and ef.valid then - ef.evolution_factor = memory.evolution_factor - Public.set_biter_surplus_evo_modifiers() - end - end + local memory = Memory.get_crew_memory() + memory.evolution_factor = memory.evolution_factor + evolution + if memory.enemy_force_name then + local ef = memory.enemy_force + if ef and ef.valid then + ef.evolution_factor = memory.evolution_factor + Public.set_biter_surplus_evo_modifiers() + end + end end - - function Public.current_destination() - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - if memory.currentdestination_index then - return memory.destinations[memory.currentdestination_index] - else - return CoreData.fallthrough_destination - end + if memory.currentdestination_index then + return memory.destinations[memory.currentdestination_index] + else + return CoreData.fallthrough_destination + end end - function Public.time_adjusted_departure_cost(cost) - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() + + local ret = cost + + -- 1.5s memoization since the gui update will call this function: + if (not memory.time_adjusted_departure_cost_memoized) or (memory.time_adjusted_departure_cost_memoized.tick < game.tick - 90) then + local destination = Public.current_destination() + local dynamic_data = destination.dynamic_data + local timer = dynamic_data.timer + local time_remaining = dynamic_data.time_remaining + + if timer and time_remaining and timer >= 0 and time_remaining >= 0 and destination.static_params.undock_cost_decreases == true then + local total_time = timer + time_remaining + local elapsed_fraction = timer / total_time + local cost_fraction = 1 - elapsed_fraction + + local new_cost = {} + for name, count in pairs(cost) do + if type(count) == 'number' then + -- new_cost[name] = Math.ceil(count * cost_fraction) + new_cost[name] = Math.floor(count * cost_fraction) + else + new_cost[name] = count + end + end + + ret = new_cost + end + + local resources_strings1 = '' + local j = 1 + for name, count in pairs(cost) do + if name ~= 'launch_rocket' then + if j > 1 then + resources_strings1 = resources_strings1 .. ', ' + end + resources_strings1 = resources_strings1 .. count .. ' [item=' .. name .. ']' + + j = j + 1 + end + end + local resources_strings2 = '' + j = 1 + for name, count in pairs(ret) do + if name ~= 'launch_rocket' then + if j > 1 then + resources_strings2 = resources_strings2 .. ', ' + end + resources_strings2 = resources_strings2 .. count .. ' [item=' .. name .. ']' + + j = j + 1 + end + end + + memory.time_adjusted_departure_cost_memoized = { + tick = game.tick, + cost = ret, + resources_strings = {resources_strings1, resources_strings2} + } + else + ret = memory.time_adjusted_departure_cost_memoized.cost + end - local ret = cost - - -- 1.5s memoization since the gui update will call this function: - if (not memory.time_adjusted_departure_cost_memoized) or (memory.time_adjusted_departure_cost_memoized.tick < game.tick - 90) then - local destination = Public.current_destination() - local dynamic_data = destination.dynamic_data - local timer = dynamic_data.timer - local time_remaining = dynamic_data.time_remaining - - if timer and time_remaining and timer >= 0 and time_remaining >= 0 and destination.static_params.undock_cost_decreases == true then - local total_time = timer + time_remaining - local elapsed_fraction = timer / total_time - local cost_fraction = 1 - elapsed_fraction - - local new_cost = {} - for name, count in pairs(cost) do - if type(count) == "number" then - new_cost[name] = Math.floor(count * cost_fraction) - -- new_cost[name] = Math.ceil(count * cost_fraction) - else - new_cost[name] = count - end - end - - ret = new_cost - end - - local resources_strings1 = '' - local j = 1 - for name, count in pairs(cost) do - if name ~= 'launch_rocket' then - if j > 1 then - resources_strings1 = resources_strings1 .. ', ' - end - resources_strings1 = resources_strings1 .. count .. ' [item=' .. name .. ']' - - j = j + 1 - end - end - local resources_strings2 = '' - j = 1 - for name, count in pairs(ret) do - if name ~= 'launch_rocket' then - if j > 1 then - resources_strings2 = resources_strings2 .. ', ' - end - resources_strings2 = resources_strings2 .. count .. ' [item=' .. name .. ']' - - j = j + 1 - end - end - - memory.time_adjusted_departure_cost_memoized = { - tick = game.tick, - cost = ret, - resources_strings = {resources_strings1, resources_strings2} - } - else - ret = memory.time_adjusted_departure_cost_memoized.cost - end - - return ret -end - - -function Public.time_adjusted_departure_cost_resources_strings(memory) - -- written to be efficient... only called in the gui after Public.time_adjusted_departure_cost() - - return memory.time_adjusted_departure_cost_memoized.resources_strings -end - - -function Public.query_can_pay_cost_to_leave() - local memory = Memory.get_crew_memory() - local boat = memory.boat - local destination = Public.current_destination() - if not (boat and destination) then return end - - local cost = destination.static_params.base_cost_to_undock - if not cost then return true end - - local adjusted_cost = Public.time_adjusted_departure_cost(cost) - - local can_leave = true - for name, count in pairs(adjusted_cost) do - if name == 'launch_rocket' and count == true then - if not destination.dynamic_data.rocketlaunched then - can_leave = false - end - else - local stored = (memory.boat.stored_resources and memory.boat.stored_resources[name]) or 0 - if stored < count then - can_leave = false - end - end - end - - return can_leave -end - - - --- This function assumes you're placing obstacle boxes in the hold -function Public.surface_place_random_obstacle_boxes(surface, center, width, height, spacing_entity, box_size_table, contents) - contents = contents or {} - - local memory = Memory.get_crew_memory() - if not surface then return end - - local function boxposition() - local p1 = {x = center.x - width/2 + Math.random(Math.ceil(width)), y = center.y - height/2 + Math.random(Math.ceil(height))} - local p2 = surface.find_non_colliding_position(spacing_entity, p1, 32, 2, true) or p1 - return {x = p2.x, y = p2.y} - end - - local placed = 0 - for size, count in pairs(box_size_table) do - if count >= 1 then - for i = 1, count do - placed = placed + 1 - local p = boxposition() - for j = 1, size^2 do - local p2 = surface.find_non_colliding_position('wooden-chest', p, 5, 0.1, true) or p - local e = surface.create_entity{name = 'wooden-chest', position = p2, force = memory.force_name, create_build_effect_smoke = false} - memory.hold_surface_destroyable_wooden_chests[e.unit_number] = e - e.destructible = false - e.minable = false - e.rotatable = false - if contents[placed] and j==1 then - local inventory = e.get_inventory(defines.inventory.chest) - for name, count2 in pairs(contents[placed]) do - inventory.insert{name = name, count = count2} - end - end - end - end - end - end -end - - - -function Public.update_boat_stored_resources() - local memory = Memory.get_crew_memory() - local boat = memory.boat - if not boat.stored_resources then return end - local input_chests = boat.input_chests - - if not input_chests then return end - - for i, chest in ipairs(input_chests) do - if i>1 and CoreData.cost_items[i-1] then - local inv = chest.get_inventory(defines.inventory.chest) - local contents = inv.get_contents() - - local item_type = CoreData.cost_items[i-1].name - local count = contents[item_type] or 0 - - boat.stored_resources[item_type] = count - end - end -end - - - -function Public.spend_stored_resources(to_spend) - to_spend = to_spend or {} - local memory = Memory.get_crew_memory() - local boat = memory.boat - if not memory.boat.stored_resources then return end - local input_chests = boat.input_chests - - if not input_chests then return end - - for i, chest in ipairs(input_chests) do - if i>1 then - local inv = chest.get_inventory(defines.inventory.chest) - local item_type = CoreData.cost_items[i-1].name - local to_spend_i = to_spend[item_type] or 0 - - if to_spend_i > 0 then - inv.remove{name = item_type, count = to_spend_i} - end - end - end - - Public.update_boat_stored_resources() -end - -function Public.consume_undock_cost_resources() - local destination = Public.current_destination() - local cost = destination.static_params.base_cost_to_undock - - if cost then - local adjusted_cost = Public.time_adjusted_departure_cost(cost) - - Public.spend_stored_resources(adjusted_cost) - end -end - -function Public.new_healthbar(text, target_entity, max_health, optional_id, health, size, extra_offset, location_override) - health = health or max_health - size = size or 0.5 - text = text or false - extra_offset = extra_offset or 0 - location_override = location_override or Memory.get_crew_memory() - - local render1 = rendering.draw_sprite( - { - sprite = 'virtual-signal/signal-white', - tint = {0, 200, 0}, - x_scale = size * 15, - y_scale = size, - render_layer = 'light-effect', - target = target_entity, - target_offset = {0, -2.5 + extra_offset}, - surface = target_entity.surface, - } - ) - local render2 - if text then - render2 = rendering.draw_text( - { - color = {255, 255, 255}, - scale = 1.2 + size*2, - render_layer = 'light-effect', - target = target_entity, - target_offset = {0, -3.6 - size*0.6 + extra_offset}, - surface = target_entity.surface, - alignment = 'center', - } - ) - end - - local new_healthbar = { - health = health, - max_health = max_health, - size = size, - extra_offset = extra_offset, - render1 = render1, - render2 = render2, - id = optional_id, - } - - if not location_override.healthbars then location_override.healthbars = {} end - location_override.healthbars[target_entity.unit_number] = new_healthbar - - Public.update_healthbar_rendering(new_healthbar, health) - - return new_healthbar -end - -function Public.transfer_healthbar(old_unit_number, new_entity, location_override) - location_override = location_override or Memory.get_crew_memory() - if not location_override.healthbars then return end - - local old_healthbar = location_override.healthbars[old_unit_number] - -- local new_unit_number = new_entity.unit_number - - -- if new_surface_bool then - -- Public.new_healthbar(old_healthbar.render2, new_entity, old_healthbar.max_health, old_healthbar.id, old_healthbar.health, rendering.get_y_scale(old_healthbar.render1)) - -- else - -- rendering.set_target(old_healthbar.render1, new_entity) - -- if old_healthbar.render2 then - -- rendering.set_target(old_healthbar.render2, new_entity) - -- end - -- memory.healthbars[new_unit_number] = old_healthbar - -- end - - Public.new_healthbar(old_healthbar.render2, new_entity, old_healthbar.max_health, old_healthbar.id, old_healthbar.health, old_healthbar.size, old_healthbar.extra_offset, location_override) - - if rendering.is_valid(old_healthbar.render1) then - rendering.destroy(old_healthbar.render1) - end - if old_healthbar.render2 and rendering.is_valid(old_healthbar.render2) then - rendering.destroy(old_healthbar.render2) - end - - location_override.healthbars[old_unit_number] = nil -end - -function Public.entity_damage_healthbar(entity, damage, location_override) - location_override = location_override or Memory.get_crew_memory() - - if not (location_override.healthbars) then return nil end - - local unit_number = entity.unit_number - local healthbar = location_override.healthbars[unit_number] - if not healthbar then return nil end - - local new_health = healthbar.health - damage - healthbar.health = new_health - Public.update_healthbar_rendering(healthbar, new_health) - - if entity and entity.valid then - entity.health = entity.prototype.max_health - end - - if healthbar.health > healthbar.max_health then - healthbar.health = healthbar.max_health - end - - local final_health = healthbar.health - - if healthbar.health <= 0 then - location_override.healthbars[unit_number] = nil - end - - return final_health -end - -function Public.update_healthbar_rendering(new_healthbar, health) - local max_health = new_healthbar.max_health - local render1 = new_healthbar.render1 - local render2 = new_healthbar.render2 - - if health > 0 then - local m = health / max_health - local x_scale = rendering.get_y_scale(render1) * 15 - rendering.set_x_scale(render1, x_scale * m) - rendering.set_color(render1, {Math.floor(255 - 255 * m), Math.floor(200 * m), 0}) - - if render2 then - rendering.set_text(render2, string.format('HP: %d/%d',Math.ceil(health),Math.ceil(max_health))) - end - else - rendering.destroy(render1) - if render2 then - rendering.destroy(render2) - end - end -end - -function Public.spawner_count(surface) - local memory = Memory.get_crew_memory() - - local spawners = surface.find_entities_filtered({type = 'unit-spawner', force = memory.enemy_force_name}) - return #spawners or 0 -end - - - -function Public.create_poison_clouds(surface, position) - - local random_angles = {Math.rad(Math.random(359)), Math.rad(Math.random(359))} - - surface.create_entity({name = 'poison-cloud', position = {x = position.x, y = position.y}}) - surface.create_entity({name = 'poison-cloud', position = {x = position.x + 12 * Math.cos(random_angles[1]), y = position.y + 12 * Math.sin(random_angles[1])}}) - surface.create_entity({name = 'poison-cloud', position = {x = position.x + 12 * Math.cos(random_angles[2]), y = position.y + 12 * Math.sin(random_angles[2])}}) -end - - -function Public.crew_get_crew_members() - local memory = Memory.get_crew_memory() - if not Public.is_id_valid(memory.id) then return {} end - - local playerlist = {} - for _, id in pairs(memory.crewplayerindices) do - local player = game.players[id] - if player and player.valid then playerlist[#playerlist + 1] = player end - end - return playerlist -end - - -function Public.crew_get_crew_members_and_spectators() - local memory = Memory.get_crew_memory() - if not Public.is_id_valid(memory.id) then - return {} - end - - local playerlist = {} - for _, id in pairs(memory.crewplayerindices) do - local player = game.players[id] - if player and player.valid then playerlist[#playerlist + 1] = player end - end - for _, id in pairs(memory.spectatorplayerindices) do - local player = game.players[id] - if player and player.valid then playerlist[#playerlist + 1] = player end - end - return playerlist -end - -function Public.is_spectator(player) - local global_memory = Memory.get_global_memory() - local previous_id = global_memory.working_id - - local player_crew_id = Public.get_id_from_force_name(player.force.name) - if not player_crew_id then - return false - end - - Memory.set_working_id(player_crew_id) - local memory = Memory.get_crew_memory() - - local spectating = false - for _, playerindex in pairs(memory.spectatorplayerindices) do - if player.index == playerindex then - spectating = true - break - end - end - - Memory.set_working_id(previous_id) - return spectating -end - - - - -function Public.crew_get_nonafk_crew_members() - local global_memory = Memory.get_global_memory() - local memory = Memory.get_crew_memory() - if not Public.is_id_valid(memory.id) then return {} end - - local playerlist = {} - for _, id in pairs(memory.crewplayerindices) do - local player = game.players[id] - if player and player.valid and not Utils.contains(global_memory.afk_player_indices, player.index) then - playerlist[#playerlist + 1] = player - end - end - - return playerlist -end - -function Public.crew_get_non_afk_officers() - local officers = {} - - local members = Public.crew_get_nonafk_crew_members() - for _, player in pairs(members) do - if Public.is_officer(player.index) then - officers[#officers + 1] = player - end - end - - return officers -end - - -function Public.destroy_decoratives_in_area(surface, area, offset) - local area2 = {{area[1][1] + offset.x, area[1][2] + offset.y}, {area[2][1] + offset.x, area[2][2] + offset.y}} - - surface.destroy_decoratives{area = area2} -end - -function Public.can_place_silo_setup(surface, p, points_to_avoid, silo_count, generous, build_check_type_name) - - -- game.print('checking silo pos: ' .. p.x .. ', ' .. p.y) - - points_to_avoid = points_to_avoid or {} - - Public.ensure_chunks_at(surface, p, 0.2) - - build_check_type_name = build_check_type_name or 'manual' - local build_check_type = defines.build_check_type[build_check_type_name] - local s = true - local allowed = true - for i=1,silo_count do - local pos = {x = p.x + 9 * (i-1), y = p.y} - s = (surface.can_place_entity{name = 'rocket-silo', position = pos, build_check_type = build_check_type} or (generous and i>2)) and s - - for _, pa in pairs(points_to_avoid) do - if Math.distance({x = pa.x, y = pa.y}, pos) < pa.r then - allowed = false - break - end - end - end - - return s and allowed -end - -function Public.ensure_chunks_at(surface, pos, radius) --WARNING: THIS DOES NOT PLAY NICELY WITH DELAYED TASKS. log(_inspect{global_memory.working_id}) was observed to vary before and after this function. - -- local global_memory = Memory.get_global_memory() - if surface and surface.valid then - surface.request_to_generate_chunks(pos, radius) - surface.force_generate_chunk_requests() --WARNING: THIS DOES NOT PLAY NICELY WITH DELAYED TASKS. log(_inspect{global_memory.working_id}) was observed to vary before and after this function. - end - - -end - - -function Public.default_map_gen_settings(width, height, seed) - width = width or 512 - height = height or 512 - seed = seed or Math.random(1, 1000000) - - local map_gen_settings = { - ['seed'] = seed, - ['width'] = width, - ['height'] = height, - ['water'] = 0, - --FIXME: Back when this was at x=2000, a crash was caused once by a player spawning at x=2000. So there will be a crash in future under unknown circumstances if there is no space at x=0,y=0. - ['starting_points'] = {{x = 0, y = 0}}, - ['cliff_settings'] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, - ['default_enable_all_autoplace_controls'] = true, - ['autoplace_settings'] = { - ['entity'] = {treat_missing_as_default = false}, - ['tile'] = {treat_missing_as_default = true}, - ['decorative'] = {treat_missing_as_default = true}, - }, - ['property_expression_names'] = {}, - } - - return map_gen_settings -end - - -function Public.build_from_blueprint(bp_string, surface, pos, force, flipped) - flipped = flipped or false - - local bp_entity = game.surfaces['nauvis'].create_entity{name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} - bp_entity.stack.import_stack(bp_string) - - local direction = flipped and defines.direction.south or defines.direction.north - - local entities = bp_entity.stack.build_blueprint{surface = surface, force = force, position = {x = pos.x, y = pos.y}, force_build = true, skip_fog_of_war = false, direction = direction} - - bp_entity.destroy() - - local rev_entities = {} - for _, e in pairs(entities) do - if e and e.valid then - local _collisions, revived_entity = e.silent_revive() - rev_entities[#rev_entities + 1] = revived_entity - end - end - - -- once again, to revive wagons: - for _, e in pairs(entities) do - if e and e.valid and e.type and e.type == 'entity-ghost' then - local _collisions, revived_entity = e.silent_revive() - rev_entities[#rev_entities + 1] = revived_entity - - if revived_entity and revived_entity.valid and revived_entity.name == 'locomotive' then - revived_entity.color = {255, 106, 52} - revived_entity.get_inventory(defines.inventory.fuel).insert({name = 'wood', count = 16}) - revived_entity.operable = false - end - end - end - - return rev_entities -end - -function Public.build_small_loco(surface, pos, force, color) - local p1 = {x = pos.x, y = pos.y} - local p2 = {x = pos.x, y = pos.y -2} - local p3 = {x = pos.x, y = pos.y + 2} - local es = {} - es[1] = surface.create_entity({name = 'straight-rail', position = p1, force = force, create_build_effect_smoke = false}) - es[2] = surface.create_entity({name = 'straight-rail', position = p2, force = force, create_build_effect_smoke = false}) - es[3] = surface.create_entity({name = 'straight-rail', position = p3, force = force, create_build_effect_smoke = false}) - es[4] = surface.create_entity({name = 'locomotive', position = p1, force = force, create_build_effect_smoke = false}) - for _, e in pairs(es) do - if e and e.valid then - e.destructible = false - e.minable = false - e.rotatable = false - e.operable = false - end - end - if es[4] and es[4].valid then - es[4].color = color - es[4].get_inventory(defines.inventory.fuel).insert({name = 'wood', count = 16}) - end -end - -function Public.add_tiles_from_blueprint(tilesTable, bp_string, tile_name, offset) - - local bp_entity = game.surfaces['nauvis'].create_entity{name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} - bp_entity.stack.import_stack(bp_string) - - local bp_tiles = bp_entity.stack.get_blueprint_tiles() - - if bp_tiles then - for _, tile in pairs(bp_tiles) do - tilesTable[#tilesTable + 1] = {name = tile_name, position = {x = tile.position.x + offset.x, y = tile.position.y + offset.y}} - end - end - - bp_entity.destroy() - - return tilesTable -end - -function Public.tile_positions_from_blueprint(bp_string, offset) - -- May '22 change: There seems to be a base game bug(?) which causes the tiles to be offset. We now correct for that (with ` - (max_x - min_x)/2` and ` - (max_y - min_y)/2`). - - local bp_entity = game.surfaces['nauvis'].create_entity{name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} - bp_entity.stack.import_stack(bp_string) - - local bp_tiles = bp_entity.stack.get_blueprint_tiles() - - - local min_x - local min_y - local max_x - local max_y - - local positions = {} - if bp_tiles then - for _, tile in pairs(bp_tiles) do - positions[#positions + 1] = {x = tile.position.x, y = tile.position.y} - if not min_x or tile.position.x < min_x then - min_x = tile.position.x - end - if not min_y or tile.position.y < min_y then - min_y = tile.position.y - end - if not max_x or tile.position.x > max_x then - max_x = tile.position.x - end - if not max_y or tile.position.y > max_y then - max_y = tile.position.y - end - end - end - - if min_x and min_y and max_x and max_y then - for _, pos in pairs(positions) do - pos.x = pos.x - (max_x - min_x)/2 + offset.x - pos.y = pos.y - (max_y - min_y)/2 + offset.y - end - end - - bp_entity.destroy() - - return positions -end - -function Public.tile_positions_from_blueprint_arrayform(bp_string, offset) - -- does not include the above May '22 fix yet, so may give different results - - local bp_entity = game.surfaces['nauvis'].create_entity{name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} - bp_entity.stack.import_stack(bp_string) - - local bp_tiles = bp_entity.stack.get_blueprint_tiles() - - local positions = {} - if bp_tiles then - for _, tile in pairs(bp_tiles) do - local x = tile.position.x+ offset.x - local y = tile.position.y + offset.y - if not positions[x] then positions[x] = {} end - positions[x][y] = true - end - end - - bp_entity.destroy() - - return positions -end - -function Public.entity_positions_from_blueprint(bp_string, offset) - - local bp_entity = game.surfaces['nauvis'].create_entity{name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} - bp_entity.stack.import_stack(bp_string) - - local es = bp_entity.stack.get_blueprint_entities() - - local positions = {} - if es then - for _, e in pairs(es) do - positions[#positions + 1] = {x = e.position.x + offset.x, y = e.position.y + offset.y} - end - end - - bp_entity.destroy() - - return positions -end - -function Public.get_random_unit_type(evolution) - -- designed to approximate https://wiki.factorio.com/Enemies - local r = Math.random() - - if Math.random(5) == 1 then - if r < 1 - 1/0.15*(evolution - 0.25) then - return 'small-biter' - elseif r < 1 - 1/0.3*(evolution - 0.4) then - return 'small-spitter' - elseif r < 1 - 0.85/0.5*(evolution - 0.5) then - return 'medium-spitter' - elseif r < 1 - 0.4/0.1*(evolution - 0.9) then - return 'big-spitter' - else - return 'behemoth-spitter' - end - else - if r < 1 - 1/0.4*(evolution - 0.2) then - return 'small-biter' - elseif r < 1 - 0.8/0.5*(evolution - 0.5) then - return 'medium-biter' - elseif r < 1 - 0.4/0.1*(evolution - 0.9) then - return 'big-biter' - else - return 'behemoth-biter' - end - end -end - -function Public.get_random_biter_type(evolution) - -- designed to approximate https://wiki.factorio.com/Enemies - local r = Math.random() - - if r < 1 - 1/0.4*(evolution - 0.2) then - return 'small-biter' - elseif r < 1 - 0.8/0.5*(evolution - 0.5) then - return 'medium-biter' - elseif r < 1 - 0.4/0.1*(evolution - 0.9) then - return 'big-biter' - else - return 'behemoth-biter' - end -end - -function Public.get_random_spitter_type(evolution) - -- designed to approximate https://wiki.factorio.com/Enemies - local r = Math.random() - - if r < 1 - 1/0.3*(evolution - 0.4) then - return 'small-spitter' - elseif r < 1 - 0.85/0.5*(evolution - 0.5) then - return 'medium-spitter' - elseif r < 1 - 0.4/0.1*(evolution - 0.9) then - return 'big-spitter' - else - return 'behemoth-spitter' - end -end - -function Public.get_random_worm_type(evolution) - -- custom - local r = Math.random() - - if r < 1 - 1/0.7*(evolution + 0.1) then - return 'small-worm-turret' - elseif r < 1 - 0.75/0.75*(evolution - 0.25) then - return 'medium-worm-turret' - elseif r < 1 - 0.4/0.4*(evolution - 0.6) then - return 'big-worm-turret' - else - return 'behemoth-worm-turret' - end -end - -function Public.maximumUnitPollutionCost(evolution) - if evolution < 0.2 then return 4 - elseif evolution < 0.5 then return 20 - elseif evolution < 0.9 then return 80 - else return 400 - end -end - -function Public.averageUnitPollutionCost(evolution) - - local sum_biters = 0 - local f1 = Math.slopefromto(1 - 1/0.4*(evolution - 0.2), 0, 1) - local f2 = Math.slopefromto(1 - 0.8/0.5*(evolution - 0.5), 0, 1) - local f3 = Math.slopefromto(1 - 0.4/0.1*(evolution - 0.9), 0, 1) - sum_biters = sum_biters + 4 * f1 - sum_biters = sum_biters + 20 * (f2 - f1) - sum_biters = sum_biters + 80 * (f3 - f2) - sum_biters = sum_biters + 400 * (1 - f3) - - local sum_spitters = 0 - local g1 = Math.slopefromto(1 - 1/0.15*(evolution - 0.25), 0, 1) - local g2 = Math.slopefromto(1 - 1/0.3*(evolution - 0.4), 0, 1) - local g3 = Math.slopefromto(1 - 0.85/0.5*(evolution - 0.5), 0, 1) - local g4 = Math.slopefromto(1 - 0.4/0.1*(evolution - 0.9), 0, 1) - sum_spitters = sum_spitters + 4 * g1 - sum_spitters = sum_spitters + 4 * (g2 - g1) - sum_spitters = sum_spitters + 12 * (g3 - g2) - sum_spitters = sum_spitters + 30 * (g4 - g3) - sum_spitters = sum_spitters + 200 * (1 - g4) - - return (5 * sum_biters + sum_spitters)/6 -end - -function Public.orthog_positions_in_orthog_area(area) - local positions = {} - for y = area[1][2] + 0.5, area[2][2] - 0.5, 1 do - for x = area[1][1] + 0.5, area[2][1] - 0.5, 1 do - positions[#positions + 1] = {x = x, y = y} - end - end - return positions -end - -function Public.tileslist_add_area_offset(tiles_list_to_add_to, area, offset, tile_type) - for _, p in pairs(Public.orthog_positions_in_orthog_area(area)) do - tiles_list_to_add_to[#tiles_list_to_add_to + 1] = {name = tile_type, position = {x = offset.x + p.x, y = offset.y + p.y}} - end -end - -function Public.central_positions_within_area(area, offset) - local offsetx = offset.x or 0 - local offsety = offset.y or 0 - local xr1, xr2, yr1, yr2 = offsetx + Math.ceil(area[1][1] - 0.5), offsetx + Math.floor(area[2][1] + 0.5), offsety + Math.ceil(area[1][2] - 0.5), offsety + Math.floor(area[2][2] + 0.5) - - local positions = {} - for y = yr1 + 0.5, yr2 - 0.5, 1 do - for x = xr1 + 0.5, xr2 - 0.5, 1 do - positions[#positions + 1] = {x = x, y = y} - end - end - return positions -end - -function Public.tiles_from_area(tiles_list_to_add_to, area, offset, tile_type) - for _, p in pairs(Public.central_positions_within_area(area, offset)) do - tiles_list_to_add_to[#tiles_list_to_add_to + 1] = {name = tile_type, position = {x = p.x, y = p.y}} - end -end - -function Public.tiles_horizontally_flipped(tiles, x_to_flip_about) - local tiles2 = {} - for _, t in pairs(tiles) do - local t2 = Utils.deepcopy(t) - t2.position = {x = 2 * x_to_flip_about - t2.position.x, y = t2.position.y} - tiles2[#tiles2 + 1] = t2 - end - return tiles2 -end - - -function Public.validate_player(player) - if player and player.valid and player.connected and game.players[player.name] then - return true - else - if _DEBUG then - log('player validation fail: ' .. (player.name or 'noname')) - end - return false - end -end - - -function Public.validate_player_and_character(player) - local ret = Public.validate_player(player) - ret = ret and player.character and player.character.valid return ret end +function Public.time_adjusted_departure_cost_resources_strings(memory) + -- written to be efficient... only called in the gui after Public.time_adjusted_departure_cost() + + return memory.time_adjusted_departure_cost_memoized.resources_strings +end + +function Public.query_can_pay_cost_to_leave() + local memory = Memory.get_crew_memory() + local boat = memory.boat + local destination = Public.current_destination() + if not (boat and destination) then + return + end + + local cost = destination.static_params.base_cost_to_undock + if not cost then + return true + end + + local adjusted_cost = Public.time_adjusted_departure_cost(cost) + + local can_leave = true + for name, count in pairs(adjusted_cost) do + if name == 'launch_rocket' and count == true then + if not destination.dynamic_data.rocketlaunched then + can_leave = false + end + else + local stored = (memory.boat.stored_resources and memory.boat.stored_resources[name]) or 0 + if stored < count then + can_leave = false + end + end + end + + return can_leave +end + +-- This function assumes you're placing obstacle boxes in the hold +function Public.surface_place_random_obstacle_boxes(surface, center, width, height, spacing_entity, box_size_table, contents) + contents = contents or {} + + local memory = Memory.get_crew_memory() + if not surface then + return + end + + local function boxposition() + local p1 = {x = center.x - width / 2 + Math.random(Math.ceil(width)), y = center.y - height / 2 + Math.random(Math.ceil(height))} + local p2 = surface.find_non_colliding_position(spacing_entity, p1, 32, 2, true) or p1 + return {x = p2.x, y = p2.y} + end + + local placed = 0 + for size, count in pairs(box_size_table) do + if count >= 1 then + for i = 1, count do + placed = placed + 1 + local p = boxposition() + for j = 1, size ^ 2 do + local p2 = surface.find_non_colliding_position('wooden-chest', p, 5, 0.1, true) or p + local e = surface.create_entity {name = 'wooden-chest', position = p2, force = memory.force_name, create_build_effect_smoke = false} + memory.hold_surface_destroyable_wooden_chests[e.unit_number] = e + e.destructible = false + e.minable = false + e.rotatable = false + if contents[placed] and j == 1 then + local inventory = e.get_inventory(defines.inventory.chest) + for name, count2 in pairs(contents[placed]) do + inventory.insert {name = name, count = count2} + end + end + end + end + end + end +end + +function Public.update_boat_stored_resources() + local memory = Memory.get_crew_memory() + local boat = memory.boat + if not boat.stored_resources then + return + end + local input_chests = boat.input_chests + + if not input_chests then + return + end + + for i, chest in ipairs(input_chests) do + if i > 1 and CoreData.cost_items[i - 1] then + local inv = chest.get_inventory(defines.inventory.chest) + local contents = inv.get_contents() + + local item_type = CoreData.cost_items[i - 1].name + local count = contents[item_type] or 0 + + boat.stored_resources[item_type] = count + end + end +end + +function Public.spend_stored_resources(to_spend) + to_spend = to_spend or {} + local memory = Memory.get_crew_memory() + local boat = memory.boat + if not memory.boat.stored_resources then + return + end + local input_chests = boat.input_chests + + if not input_chests then + return + end + + for i, chest in ipairs(input_chests) do + if i > 1 then + local inv = chest.get_inventory(defines.inventory.chest) + local item_type = CoreData.cost_items[i - 1].name + local to_spend_i = to_spend[item_type] or 0 + + if to_spend_i > 0 then + inv.remove {name = item_type, count = to_spend_i} + end + end + end + + Public.update_boat_stored_resources() +end + +function Public.consume_undock_cost_resources() + local destination = Public.current_destination() + local cost = destination.static_params.base_cost_to_undock + + if cost then + local adjusted_cost = Public.time_adjusted_departure_cost(cost) + + Public.spend_stored_resources(adjusted_cost) + end +end + +function Public.new_healthbar(text, target_entity, max_health, optional_id, health, size, extra_offset, location_override) + health = health or max_health + size = size or 0.5 + text = text or false + extra_offset = extra_offset or 0 + location_override = location_override or Memory.get_crew_memory() + + local render1 = + rendering.draw_sprite( + { + sprite = 'virtual-signal/signal-white', + tint = {0, 200, 0}, + x_scale = size * 15, + y_scale = size, + render_layer = 'light-effect', + target = target_entity, + target_offset = {0, -2.5 + extra_offset}, + surface = target_entity.surface + } + ) + local render2 + if text then + render2 = + rendering.draw_text( + { + color = {255, 255, 255}, + scale = 1.2 + size * 2, + render_layer = 'light-effect', + target = target_entity, + target_offset = {0, -3.6 - size * 0.6 + extra_offset}, + surface = target_entity.surface, + alignment = 'center' + } + ) + end + + local new_healthbar = { + health = health, + max_health = max_health, + size = size, + extra_offset = extra_offset, + render1 = render1, + render2 = render2, + id = optional_id + } + + if not location_override.healthbars then + location_override.healthbars = {} + end + location_override.healthbars[target_entity.unit_number] = new_healthbar + + Public.update_healthbar_rendering(new_healthbar, health) + + return new_healthbar +end + +function Public.transfer_healthbar(old_unit_number, new_entity, location_override) + location_override = location_override or Memory.get_crew_memory() + if not location_override.healthbars then + return + end + + local old_healthbar = location_override.healthbars[old_unit_number] + -- local new_unit_number = new_entity.unit_number + + -- if new_surface_bool then + -- Public.new_healthbar(old_healthbar.render2, new_entity, old_healthbar.max_health, old_healthbar.id, old_healthbar.health, rendering.get_y_scale(old_healthbar.render1)) + -- else + -- rendering.set_target(old_healthbar.render1, new_entity) + -- if old_healthbar.render2 then + -- rendering.set_target(old_healthbar.render2, new_entity) + -- end + -- memory.healthbars[new_unit_number] = old_healthbar + -- end + + Public.new_healthbar(old_healthbar.render2, new_entity, old_healthbar.max_health, old_healthbar.id, old_healthbar.health, old_healthbar.size, old_healthbar.extra_offset, location_override) + + if rendering.is_valid(old_healthbar.render1) then + rendering.destroy(old_healthbar.render1) + end + if old_healthbar.render2 and rendering.is_valid(old_healthbar.render2) then + rendering.destroy(old_healthbar.render2) + end + + location_override.healthbars[old_unit_number] = nil +end + +function Public.entity_damage_healthbar(entity, damage, location_override) + location_override = location_override or Memory.get_crew_memory() + + if not (location_override.healthbars) then + return nil + end + + local unit_number = entity.unit_number + local healthbar = location_override.healthbars[unit_number] + if not healthbar then + return nil + end + + local new_health = healthbar.health - damage + healthbar.health = new_health + Public.update_healthbar_rendering(healthbar, new_health) + + if entity and entity.valid then + entity.health = entity.prototype.max_health + end + + if healthbar.health > healthbar.max_health then + healthbar.health = healthbar.max_health + end + + local final_health = healthbar.health + + if healthbar.health <= 0 then + location_override.healthbars[unit_number] = nil + end + + return final_health +end + +function Public.update_healthbar_rendering(new_healthbar, health) + local max_health = new_healthbar.max_health + local render1 = new_healthbar.render1 + local render2 = new_healthbar.render2 + + if health > 0 then + local m = health / max_health + local x_scale = rendering.get_y_scale(render1) * 15 + rendering.set_x_scale(render1, x_scale * m) + rendering.set_color(render1, {Math.floor(255 - 255 * m), Math.floor(200 * m), 0}) + + if render2 then + rendering.set_text(render2, string.format('HP: %d/%d', Math.ceil(health), Math.ceil(max_health))) + end + else + rendering.destroy(render1) + if render2 then + rendering.destroy(render2) + end + end +end + +function Public.spawner_count(surface) + local memory = Memory.get_crew_memory() + + local spawners = surface.find_entities_filtered({type = 'unit-spawner', force = memory.enemy_force_name}) + return #spawners or 0 +end + +function Public.create_poison_clouds(surface, position) + local random_angles = {Math.rad(Math.random(359)), Math.rad(Math.random(359))} + + surface.create_entity({name = 'poison-cloud', position = {x = position.x, y = position.y}}) + surface.create_entity({name = 'poison-cloud', position = {x = position.x + 12 * Math.cos(random_angles[1]), y = position.y + 12 * Math.sin(random_angles[1])}}) + surface.create_entity({name = 'poison-cloud', position = {x = position.x + 12 * Math.cos(random_angles[2]), y = position.y + 12 * Math.sin(random_angles[2])}}) +end + +function Public.crew_get_crew_members() + local memory = Memory.get_crew_memory() + if not Public.is_id_valid(memory.id) then + return {} + end + + local playerlist = {} + for _, id in pairs(memory.crewplayerindices) do + local player = game.players[id] + if player and player.valid then + playerlist[#playerlist + 1] = player + end + end + return playerlist +end + +function Public.crew_get_crew_members_and_spectators() + local memory = Memory.get_crew_memory() + if not Public.is_id_valid(memory.id) then + return {} + end + + local playerlist = {} + for _, id in pairs(memory.crewplayerindices) do + local player = game.players[id] + if player and player.valid then + playerlist[#playerlist + 1] = player + end + end + for _, id in pairs(memory.spectatorplayerindices) do + local player = game.players[id] + if player and player.valid then + playerlist[#playerlist + 1] = player + end + end + return playerlist +end + +function Public.is_spectator(player) + local global_memory = Memory.get_global_memory() + local previous_id = global_memory.working_id + + local player_crew_id = Public.get_id_from_force_name(player.force.name) + if not player_crew_id then + return false + end + + Memory.set_working_id(player_crew_id) + local memory = Memory.get_crew_memory() + + local spectating = false + for _, playerindex in pairs(memory.spectatorplayerindices) do + if player.index == playerindex then + spectating = true + break + end + end + + Memory.set_working_id(previous_id) + return spectating +end + +function Public.crew_get_nonafk_crew_members() + local global_memory = Memory.get_global_memory() + local memory = Memory.get_crew_memory() + if not Public.is_id_valid(memory.id) then + return {} + end + + local playerlist = {} + for _, id in pairs(memory.crewplayerindices) do + local player = game.players[id] + if player and player.valid and not Utils.contains(global_memory.afk_player_indices, player.index) then + playerlist[#playerlist + 1] = player + end + end + + return playerlist +end + +function Public.crew_get_non_afk_officers() + local officers = {} + + local members = Public.crew_get_nonafk_crew_members() + for _, player in pairs(members) do + if Public.is_officer(player.index) then + officers[#officers + 1] = player + end + end + + return officers +end + +function Public.destroy_decoratives_in_area(surface, area, offset) + local area2 = {{area[1][1] + offset.x, area[1][2] + offset.y}, {area[2][1] + offset.x, area[2][2] + offset.y}} + + surface.destroy_decoratives {area = area2} +end + +function Public.can_place_silo_setup(surface, p, points_to_avoid, silo_count, generous, build_check_type_name) + -- game.print('checking silo pos: ' .. p.x .. ', ' .. p.y) + + points_to_avoid = points_to_avoid or {} + + Public.ensure_chunks_at(surface, p, 0.2) + + build_check_type_name = build_check_type_name or 'manual' + local build_check_type = defines.build_check_type[build_check_type_name] + local s = true + local allowed = true + for i = 1, silo_count do + local pos = {x = p.x + 9 * (i - 1), y = p.y} + s = (surface.can_place_entity {name = 'rocket-silo', position = pos, build_check_type = build_check_type} or (generous and i > 2)) and s + + for _, pa in pairs(points_to_avoid) do + if Math.distance({x = pa.x, y = pa.y}, pos) < pa.r then + allowed = false + break + end + end + end + + return s and allowed +end + +function Public.ensure_chunks_at(surface, pos, radius) --WARNING: THIS DOES NOT PLAY NICELY WITH DELAYED TASKS. log(_inspect{global_memory.working_id}) was observed to vary before and after this function. + -- local global_memory = Memory.get_global_memory() + if surface and surface.valid then + surface.request_to_generate_chunks(pos, radius) + surface.force_generate_chunk_requests() --WARNING: THIS DOES NOT PLAY NICELY WITH DELAYED TASKS. log(_inspect{global_memory.working_id}) was observed to vary before and after this function. + end +end + +function Public.default_map_gen_settings(width, height, seed) + width = width or 512 + height = height or 512 + seed = seed or Math.random(1, 1000000) + + local map_gen_settings = { + ['seed'] = seed, + ['width'] = width, + ['height'] = height, + ['water'] = 0, + --FIXME: Back when this was at x=2000, a crash was caused once by a player spawning at x=2000. So there will be a crash in future under unknown circumstances if there is no space at x=0,y=0. + ['starting_points'] = {{x = 0, y = 0}}, + ['cliff_settings'] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}, + ['default_enable_all_autoplace_controls'] = true, + ['autoplace_settings'] = { + ['entity'] = {treat_missing_as_default = false}, + ['tile'] = {treat_missing_as_default = true}, + ['decorative'] = {treat_missing_as_default = true} + }, + ['property_expression_names'] = {} + } + + return map_gen_settings +end + +function Public.build_from_blueprint(bp_string, surface, pos, force, flipped) + flipped = flipped or false + + local bp_entity = game.surfaces['nauvis'].create_entity {name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} + bp_entity.stack.import_stack(bp_string) + + local direction = flipped and defines.direction.south or defines.direction.north + + local entities = bp_entity.stack.build_blueprint {surface = surface, force = force, position = {x = pos.x, y = pos.y}, force_build = true, skip_fog_of_war = false, direction = direction} + + bp_entity.destroy() + + local rev_entities = {} + for _, e in pairs(entities) do + if e and e.valid then + local _collisions, revived_entity = e.silent_revive() + rev_entities[#rev_entities + 1] = revived_entity + end + end + + -- once again, to revive wagons: + for _, e in pairs(entities) do + if e and e.valid and e.type and e.type == 'entity-ghost' then + local _collisions, revived_entity = e.silent_revive() + rev_entities[#rev_entities + 1] = revived_entity + + if revived_entity and revived_entity.valid and revived_entity.name == 'locomotive' then + revived_entity.color = {255, 106, 52} + revived_entity.get_inventory(defines.inventory.fuel).insert({name = 'wood', count = 16}) + revived_entity.operable = false + end + end + end + + return rev_entities +end + +function Public.build_small_loco(surface, pos, force, color) + local p1 = {x = pos.x, y = pos.y} + local p2 = {x = pos.x, y = pos.y - 2} + local p3 = {x = pos.x, y = pos.y + 2} + local es = {} + es[1] = surface.create_entity({name = 'straight-rail', position = p1, force = force, create_build_effect_smoke = false}) + es[2] = surface.create_entity({name = 'straight-rail', position = p2, force = force, create_build_effect_smoke = false}) + es[3] = surface.create_entity({name = 'straight-rail', position = p3, force = force, create_build_effect_smoke = false}) + es[4] = surface.create_entity({name = 'locomotive', position = p1, force = force, create_build_effect_smoke = false}) + for _, e in pairs(es) do + if e and e.valid then + e.destructible = false + e.minable = false + e.rotatable = false + e.operable = false + end + end + if es[4] and es[4].valid then + es[4].color = color + es[4].get_inventory(defines.inventory.fuel).insert({name = 'wood', count = 16}) + end +end + +function Public.add_tiles_from_blueprint(tilesTable, bp_string, tile_name, offset) + local bp_entity = game.surfaces['nauvis'].create_entity {name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} + bp_entity.stack.import_stack(bp_string) + + local bp_tiles = bp_entity.stack.get_blueprint_tiles() + + if bp_tiles then + for _, tile in pairs(bp_tiles) do + tilesTable[#tilesTable + 1] = {name = tile_name, position = {x = tile.position.x + offset.x, y = tile.position.y + offset.y}} + end + end + + bp_entity.destroy() + + return tilesTable +end + +function Public.tile_positions_from_blueprint(bp_string, offset) + -- May '22 change: There seems to be a base game bug(?) which causes the tiles to be offset. We now correct for that (with ` - (max_x - min_x)/2` and ` - (max_y - min_y)/2`). + + local bp_entity = game.surfaces['nauvis'].create_entity {name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} + bp_entity.stack.import_stack(bp_string) + + local bp_tiles = bp_entity.stack.get_blueprint_tiles() + + local min_x + local min_y + local max_x + local max_y + + local positions = {} + if bp_tiles then + for _, tile in pairs(bp_tiles) do + positions[#positions + 1] = {x = tile.position.x, y = tile.position.y} + if not min_x or tile.position.x < min_x then + min_x = tile.position.x + end + if not min_y or tile.position.y < min_y then + min_y = tile.position.y + end + if not max_x or tile.position.x > max_x then + max_x = tile.position.x + end + if not max_y or tile.position.y > max_y then + max_y = tile.position.y + end + end + end + + if min_x and min_y and max_x and max_y then + for _, pos in pairs(positions) do + pos.x = pos.x - (max_x - min_x) / 2 + offset.x + pos.y = pos.y - (max_y - min_y) / 2 + offset.y + end + end + + bp_entity.destroy() + + return positions +end + +function Public.tile_positions_from_blueprint_arrayform(bp_string, offset) + -- does not include the above May '22 fix yet, so may give different results + + local bp_entity = game.surfaces['nauvis'].create_entity {name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} + bp_entity.stack.import_stack(bp_string) + + local bp_tiles = bp_entity.stack.get_blueprint_tiles() + + local positions = {} + if bp_tiles then + for _, tile in pairs(bp_tiles) do + local x = tile.position.x + offset.x + local y = tile.position.y + offset.y + if not positions[x] then + positions[x] = {} + end + positions[x][y] = true + end + end + + bp_entity.destroy() + + return positions +end + +function Public.entity_positions_from_blueprint(bp_string, offset) + local bp_entity = game.surfaces['nauvis'].create_entity {name = 'item-on-ground', position = {x = 158.5, y = 158.5}, stack = 'blueprint'} + bp_entity.stack.import_stack(bp_string) + + local es = bp_entity.stack.get_blueprint_entities() + + local positions = {} + if es then + for _, e in pairs(es) do + positions[#positions + 1] = {x = e.position.x + offset.x, y = e.position.y + offset.y} + end + end + + bp_entity.destroy() + + return positions +end + +function Public.get_random_unit_type(evolution) + -- designed to approximate https://wiki.factorio.com/Enemies + local r = Math.random() + + if Math.random(5) == 1 then + if r < 1 - 1 / 0.15 * (evolution - 0.25) then + return 'small-biter' + elseif r < 1 - 1 / 0.3 * (evolution - 0.4) then + return 'small-spitter' + elseif r < 1 - 0.85 / 0.5 * (evolution - 0.5) then + return 'medium-spitter' + elseif r < 1 - 0.4 / 0.1 * (evolution - 0.9) then + return 'big-spitter' + else + return 'behemoth-spitter' + end + else + if r < 1 - 1 / 0.4 * (evolution - 0.2) then + return 'small-biter' + elseif r < 1 - 0.8 / 0.5 * (evolution - 0.5) then + return 'medium-biter' + elseif r < 1 - 0.4 / 0.1 * (evolution - 0.9) then + return 'big-biter' + else + return 'behemoth-biter' + end + end +end + +function Public.get_random_biter_type(evolution) + -- designed to approximate https://wiki.factorio.com/Enemies + local r = Math.random() + + if r < 1 - 1 / 0.4 * (evolution - 0.2) then + return 'small-biter' + elseif r < 1 - 0.8 / 0.5 * (evolution - 0.5) then + return 'medium-biter' + elseif r < 1 - 0.4 / 0.1 * (evolution - 0.9) then + return 'big-biter' + else + return 'behemoth-biter' + end +end + +function Public.get_random_spitter_type(evolution) + -- designed to approximate https://wiki.factorio.com/Enemies + local r = Math.random() + + if r < 1 - 1 / 0.3 * (evolution - 0.4) then + return 'small-spitter' + elseif r < 1 - 0.85 / 0.5 * (evolution - 0.5) then + return 'medium-spitter' + elseif r < 1 - 0.4 / 0.1 * (evolution - 0.9) then + return 'big-spitter' + else + return 'behemoth-spitter' + end +end + +function Public.get_random_worm_type(evolution) + -- custom + local r = Math.random() + + if r < 1 - 1 / 0.7 * (evolution + 0.1) then + return 'small-worm-turret' + elseif r < 1 - 0.75 / 0.75 * (evolution - 0.25) then + return 'medium-worm-turret' + elseif r < 1 - 0.4 / 0.4 * (evolution - 0.6) then + return 'big-worm-turret' + else + return 'behemoth-worm-turret' + end +end + +function Public.maximumUnitPollutionCost(evolution) + if evolution < 0.2 then + return 4 + elseif evolution < 0.5 then + return 20 + elseif evolution < 0.9 then + return 80 + else + return 400 + end +end + +function Public.averageUnitPollutionCost(evolution) + local sum_biters = 0 + local f1 = Math.slopefromto(1 - 1 / 0.4 * (evolution - 0.2), 0, 1) + local f2 = Math.slopefromto(1 - 0.8 / 0.5 * (evolution - 0.5), 0, 1) + local f3 = Math.slopefromto(1 - 0.4 / 0.1 * (evolution - 0.9), 0, 1) + sum_biters = sum_biters + 4 * f1 + sum_biters = sum_biters + 20 * (f2 - f1) + sum_biters = sum_biters + 80 * (f3 - f2) + sum_biters = sum_biters + 400 * (1 - f3) + + local sum_spitters = 0 + local g1 = Math.slopefromto(1 - 1 / 0.15 * (evolution - 0.25), 0, 1) + local g2 = Math.slopefromto(1 - 1 / 0.3 * (evolution - 0.4), 0, 1) + local g3 = Math.slopefromto(1 - 0.85 / 0.5 * (evolution - 0.5), 0, 1) + local g4 = Math.slopefromto(1 - 0.4 / 0.1 * (evolution - 0.9), 0, 1) + sum_spitters = sum_spitters + 4 * g1 + sum_spitters = sum_spitters + 4 * (g2 - g1) + sum_spitters = sum_spitters + 12 * (g3 - g2) + sum_spitters = sum_spitters + 30 * (g4 - g3) + sum_spitters = sum_spitters + 200 * (1 - g4) + + return (5 * sum_biters + sum_spitters) / 6 +end + +function Public.orthog_positions_in_orthog_area(area) + local positions = {} + for y = area[1][2] + 0.5, area[2][2] - 0.5, 1 do + for x = area[1][1] + 0.5, area[2][1] - 0.5, 1 do + positions[#positions + 1] = {x = x, y = y} + end + end + return positions +end + +function Public.tileslist_add_area_offset(tiles_list_to_add_to, area, offset, tile_type) + for _, p in pairs(Public.orthog_positions_in_orthog_area(area)) do + tiles_list_to_add_to[#tiles_list_to_add_to + 1] = {name = tile_type, position = {x = offset.x + p.x, y = offset.y + p.y}} + end +end + +function Public.central_positions_within_area(area, offset) + local offsetx = offset.x or 0 + local offsety = offset.y or 0 + local xr1, xr2, yr1, yr2 = offsetx + Math.ceil(area[1][1] - 0.5), offsetx + Math.floor(area[2][1] + 0.5), offsety + Math.ceil(area[1][2] - 0.5), offsety + Math.floor(area[2][2] + 0.5) + + local positions = {} + for y = yr1 + 0.5, yr2 - 0.5, 1 do + for x = xr1 + 0.5, xr2 - 0.5, 1 do + positions[#positions + 1] = {x = x, y = y} + end + end + return positions +end + +function Public.tiles_from_area(tiles_list_to_add_to, area, offset, tile_type) + for _, p in pairs(Public.central_positions_within_area(area, offset)) do + tiles_list_to_add_to[#tiles_list_to_add_to + 1] = {name = tile_type, position = {x = p.x, y = p.y}} + end +end + +function Public.tiles_horizontally_flipped(tiles, x_to_flip_about) + local tiles2 = {} + for _, t in pairs(tiles) do + local t2 = Utils.deepcopy(t) + t2.position = {x = 2 * x_to_flip_about - t2.position.x, y = t2.position.y} + tiles2[#tiles2 + 1] = t2 + end + return tiles2 +end + +function Public.validate_player(player) + if player and player.valid and player.connected and game.players[player.name] then + return true + else + if _DEBUG then + log('player validation fail: ' .. (player.name or 'noname')) + end + return false + end +end + +function Public.validate_player_and_character(player) + local ret = Public.validate_player(player) + ret = ret and player.character and player.character.valid + return ret +end -- Players complained that when "all_items" is false, the items dissapear (perhaps code sending items from dead character to cabin is wrong?). function Public.send_important_items_from_player_to_crew(player, all_items) - local player_inv = {} - player_inv[1] = game.players[player.index].get_inventory(defines.inventory.character_main) - player_inv[2] = game.players[player.index].get_inventory(defines.inventory.character_armor) - player_inv[3] = game.players[player.index].get_inventory(defines.inventory.character_guns) - player_inv[4] = game.players[player.index].get_inventory(defines.inventory.character_ammo) - player_inv[5] = game.players[player.index].get_inventory(defines.inventory.character_trash) + local player_inv = {} + player_inv[1] = game.players[player.index].get_inventory(defines.inventory.character_main) + player_inv[2] = game.players[player.index].get_inventory(defines.inventory.character_armor) + player_inv[3] = game.players[player.index].get_inventory(defines.inventory.character_guns) + player_inv[4] = game.players[player.index].get_inventory(defines.inventory.character_ammo) + player_inv[5] = game.players[player.index].get_inventory(defines.inventory.character_trash) - local any = false + local any = false - for ii = 1, 5, 1 do - if player_inv[ii].valid then - -- local to_keep = {} - local to_remove = {} - for iii = 1, #player_inv[ii], 1 do - -- local item_stack = player_inv[ii][iii] --don't do this as LuaItemStack is a reference! - if player_inv[ii] and player_inv[ii][iii].valid and player_inv[ii][iii].valid_for_read then - if all_items or (player_inv[ii][iii].name and Utils.contains(Public.logout_unprotected_items, player_inv[ii][iii].name)) then - to_remove[#to_remove + 1] = player_inv[ii][iii] - any = true - -- else - -- to_keep[#to_keep + 1] = Utils.deepcopy(player_inv[ii][iii]) - end - end - end + for ii = 1, 5, 1 do + if player_inv[ii].valid then + -- local to_keep = {} + local to_remove = {} + for iii = 1, #player_inv[ii], 1 do + -- local item_stack = player_inv[ii][iii] --don't do this as LuaItemStack is a reference! + if player_inv[ii] and player_inv[ii][iii].valid and player_inv[ii][iii].valid_for_read then + if all_items or (player_inv[ii][iii].name and Utils.contains(Public.logout_unprotected_items, player_inv[ii][iii].name)) then + to_remove[#to_remove + 1] = player_inv[ii][iii] + any = true + -- else + -- to_keep[#to_keep + 1] = Utils.deepcopy(player_inv[ii][iii]) + end + end + end - if #to_remove > 0 then - for iii = 1, #to_remove, 1 do - if to_remove[iii].valid_for_read then - -- Public.give_items_to_crew{{name = to_remove[iii].name, count = to_remove[iii].count}} - Public.give_items_to_crew(to_remove[iii]) - to_remove[iii].clear() - end - end - -- clear and move over from to_keep if necessary? - end - end - end + if #to_remove > 0 then + for iii = 1, #to_remove, 1 do + if to_remove[iii].valid_for_read then + -- Public.give_items_to_crew{{name = to_remove[iii].name, count = to_remove[iii].count}} + Public.give_items_to_crew(to_remove[iii]) + to_remove[iii].clear() + end + end + -- clear and move over from to_keep if necessary? + end + end + end - return any + return any end function Public.temporarily_store_logged_off_character_items(player) - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - memory.temporarily_logged_off_characters_items[player.index] = game.create_inventory(150) - local temp_inv = memory.temporarily_logged_off_characters_items[player.index] + memory.temporarily_logged_off_characters_items[player.index] = game.create_inventory(150) + local temp_inv = memory.temporarily_logged_off_characters_items[player.index] - local player_inv = {} - player_inv[1] = game.players[player.index].get_inventory(defines.inventory.character_main) - player_inv[2] = game.players[player.index].get_inventory(defines.inventory.character_armor) - player_inv[3] = game.players[player.index].get_inventory(defines.inventory.character_guns) - player_inv[4] = game.players[player.index].get_inventory(defines.inventory.character_ammo) - player_inv[5] = game.players[player.index].get_inventory(defines.inventory.character_trash) + local player_inv = {} + player_inv[1] = game.players[player.index].get_inventory(defines.inventory.character_main) + player_inv[2] = game.players[player.index].get_inventory(defines.inventory.character_armor) + player_inv[3] = game.players[player.index].get_inventory(defines.inventory.character_guns) + player_inv[4] = game.players[player.index].get_inventory(defines.inventory.character_ammo) + player_inv[5] = game.players[player.index].get_inventory(defines.inventory.character_trash) - for ii = 1, 5, 1 do - if player_inv[ii].valid then - for iii = 1, #player_inv[ii], 1 do - if player_inv[ii] and player_inv[ii][iii].valid and player_inv[ii][iii].valid_for_read then - temp_inv.insert(player_inv[ii][iii]) - player_inv[ii][iii].clear() - end - end - end - end + for ii = 1, 5, 1 do + if player_inv[ii].valid then + for iii = 1, #player_inv[ii], 1 do + if player_inv[ii] and player_inv[ii][iii].valid and player_inv[ii][iii].valid_for_read then + temp_inv.insert(player_inv[ii][iii]) + player_inv[ii][iii].clear() + end + end + end + end end function Public.give_back_items_to_temporarily_logged_off_player(player) - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - if not memory.temporarily_logged_off_characters_items[player.index] then - return - end + if not memory.temporarily_logged_off_characters_items[player.index] then + return + end - local temp_inv = memory.temporarily_logged_off_characters_items[player.index] + local temp_inv = memory.temporarily_logged_off_characters_items[player.index] - for i = 1, #temp_inv, 1 do - if temp_inv and temp_inv[i].valid and temp_inv[i].valid_for_read then - player.insert(temp_inv[i]) - end - end + for i = 1, #temp_inv, 1 do + if temp_inv and temp_inv[i].valid and temp_inv[i].valid_for_read then + player.insert(temp_inv[i]) + end + end - temp_inv.destroy() - memory.temporarily_logged_off_characters_items[player.index] = nil + temp_inv.destroy() + memory.temporarily_logged_off_characters_items[player.index] = nil end function Public.give_items_to_crew(items) - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - local boat = memory.boat - if not boat then return end - local surface_name = boat.surface_name - if not surface_name then return end - local surface = game.surfaces[surface_name] - if not (surface and surface.valid) then return end - local chest, chest2 + local boat = memory.boat + if not boat then + return + end + local surface_name = boat.surface_name + if not surface_name then + return + end + local surface = game.surfaces[surface_name] + if not (surface and surface.valid) then + return + end + local chest, chest2 - if items.name and items.name == 'coin' then - chest = boat.backup_output_chest - if not (chest and chest.valid) then return end - chest2 = boat.output_chest - if not (chest2 and chest2.valid) then return end - else - chest = boat.output_chest - if not (chest and chest.valid) then return end - chest2 = boat.backup_output_chest - if not (chest2 and chest2.valid) then return end - end + if items.name and items.name == 'coin' then + chest = boat.backup_output_chest + if not (chest and chest.valid) then + return + end + chest2 = boat.output_chest + if not (chest2 and chest2.valid) then + return + end + else + chest = boat.output_chest + if not (chest and chest.valid) then + return + end + chest2 = boat.backup_output_chest + if not (chest2 and chest2.valid) then + return + end + end - local inventory = chest.get_inventory(defines.inventory.chest) + local inventory = chest.get_inventory(defines.inventory.chest) - if items.name then --1 item - if not (items.count and items.count>0) then return end - local inserted = inventory.insert(items) - if items.count - inserted > 0 then - local inventory2 = chest2.get_inventory(defines.inventory.chest) - local i2 = Utils.deepcopy(items) - if i2.name then - i2.count = items.count - inserted - local inserted2 = inventory2.insert(i2) - if items.count - inserted - inserted2 > 0 then - local force = memory.force - if not (force and force.valid) then return end - Public.notify_force(force, 'Warning: captain\'s cabin chests are full!') - end - else - if _DEBUG then - log('give_items_to_crew: i2.name is nil. _inspect:') - log(_inspect(items)) - log(_inspect(i2)) - end - end - end - else - for _, i in pairs(items) do - if not (i.count and i.count>0) then return end - local inserted = inventory.insert(i) - if i.count - inserted > 0 then - local inventory2 = chest2.get_inventory(defines.inventory.chest) - local i2 = Utils.deepcopy(i) - i2.count = i.count - inserted - local inserted2 = inventory2.insert(i2) - if i.count - inserted - inserted2 > 0 then - local force = memory.force - if not (force and force.valid) then return end - Public.notify_force(force, 'Warning: captain\'s cabin chests are full!') - end - end - end - end + if items.name then --1 item + if not (items.count and items.count > 0) then + return + end + local inserted = inventory.insert(items) + if items.count - inserted > 0 then + local inventory2 = chest2.get_inventory(defines.inventory.chest) + local i2 = Utils.deepcopy(items) + if i2.name then + i2.count = items.count - inserted + local inserted2 = inventory2.insert(i2) + if items.count - inserted - inserted2 > 0 then + local force = memory.force + if not (force and force.valid) then + return + end + Public.notify_force(force, "Warning: captain's cabin chests are full!") + end + else + if _DEBUG then + log('give_items_to_crew: i2.name is nil. _inspect:') + log(_inspect(items)) + log(_inspect(i2)) + end + end + end + else + for _, i in pairs(items) do + if not (i.count and i.count > 0) then + return + end + local inserted = inventory.insert(i) + if i.count - inserted > 0 then + local inventory2 = chest2.get_inventory(defines.inventory.chest) + local i2 = Utils.deepcopy(i) + i2.count = i.count - inserted + local inserted2 = inventory2.insert(i2) + if i.count - inserted - inserted2 > 0 then + local force = memory.force + if not (force and force.valid) then + return + end + Public.notify_force(force, "Warning: captain's cabin chests are full!") + end + end + end + end end - function Public.version_to_array(v) - local vArray = {} - if type(v) == 'number' then --this is a legacy form - local vs = tostring(v) - for i = 1, string.len(vs) do - local char = vs:sub(i, i) - if i ~= 2 then - vArray[#vArray+1] = char - end - end - else - for i = 1, string.len(v) do - local char = v:sub(i, i) - if char ~= '.' then - vArray[#vArray+1] = char - end - end - end + local vArray = {} + if type(v) == 'number' then --this is a legacy form + local vs = tostring(v) + for i = 1, string.len(vs) do + local char = vs:sub(i, i) + if i ~= 2 then + vArray[#vArray + 1] = char + end + end + else + for i = 1, string.len(v) do + local char = v:sub(i, i) + if char ~= '.' then + vArray[#vArray + 1] = char + end + end + end - return vArray + return vArray end - function Public.version_greater_than(v1, v2) - local v1Array = Public.version_to_array(v1) - local v2Array = Public.version_to_array(v2) + local v1Array = Public.version_to_array(v1) + local v2Array = Public.version_to_array(v2) - for i = 1, math.max(#v1Array, #v2Array) do - local v1i = tonumber(v1Array[i]) - local v2i = tonumber(v2Array[i]) - if v1i ~= nil and v2i ~= nil then - if v1i < v2i then - return false - elseif v1i > v2i then - return true - end - elseif v1i == nil then - return false - else - return true - end - end + for i = 1, math.max(#v1Array, #v2Array) do + local v1i = tonumber(v1Array[i]) + local v2i = tonumber(v2Array[i]) + if v1i ~= nil and v2i ~= nil then + if v1i < v2i then + return false + elseif v1i > v2i then + return true + end + elseif v1i == nil then + return false + else + return true + end + end end - - function Public.init_game_settings(technology_price_multiplier) + --== Tuned for Pirate Ship ==-- - --== Tuned for Pirate Ship ==-- + global.friendly_fire_history = {} + global.landfill_history = {} + global.mining_history = {} - global.friendly_fire_history = {} - global.landfill_history = {} - global.mining_history = {} + game.difficulty_settings.technology_price_multiplier = technology_price_multiplier - game.difficulty_settings.technology_price_multiplier = technology_price_multiplier + game.map_settings.enemy_evolution.pollution_factor = 0 + game.map_settings.enemy_evolution.time_factor = 0 + game.map_settings.enemy_evolution.destroy_factor = 0 - game.map_settings.enemy_evolution.pollution_factor = 0 - game.map_settings.enemy_evolution.time_factor = 0 - game.map_settings.enemy_evolution.destroy_factor = 0 + game.map_settings.unit_group.min_group_gathering_time = 60 * 5 + game.map_settings.unit_group.max_group_gathering_time = 60 * 210 + game.map_settings.unit_group.max_wait_time_for_late_members = 60 * 15 + game.map_settings.unit_group.member_disown_distance = 5000 + game.map_settings.unit_group.max_group_radius = 70 + game.map_settings.unit_group.min_group_radius = 0.5 --seems to govern biter 'attack area' stopping distance - game.map_settings.unit_group.min_group_gathering_time = 60 * 5 - game.map_settings.unit_group.max_group_gathering_time = 60 * 210 - game.map_settings.unit_group.max_wait_time_for_late_members = 60 * 15 - game.map_settings.unit_group.member_disown_distance = 5000 - game.map_settings.unit_group.max_group_radius = 70 - game.map_settings.unit_group.min_group_radius = 0.5 --seems to govern biter 'attack area' stopping distance + -- (0,2) for a symmetric search: + game.map_settings.path_finder.goal_pressure_ratio = -0.1 --small pressure for stupid paths + game.map_settings.path_finder.fwd2bwd_ratio = 2 -- on experiments I found that this value was symmetric, despite the vanilla game comments saying it is 1... + game.map_settings.max_failed_behavior_count = 2 + game.map_settings.path_finder.max_work_done_per_tick = 20000 + game.map_settings.path_finder.short_cache_min_algo_steps_to_cache = 100 + game.map_settings.path_finder.cache_accept_path_start_distance_ratio = 0.1 - -- (0,2) for a symmetric search: - game.map_settings.path_finder.goal_pressure_ratio = -0.1 --small pressure for stupid paths - game.map_settings.path_finder.fwd2bwd_ratio = 2 -- on experiments I found that this value was symmetric, despite the vanilla game comments saying it is 1... - game.map_settings.max_failed_behavior_count = 2 - game.map_settings.path_finder.max_work_done_per_tick = 20000 - game.map_settings.path_finder.short_cache_min_algo_steps_to_cache = 100 - game.map_settings.path_finder.cache_accept_path_start_distance_ratio = 0.1 + game.map_settings.enemy_expansion.enabled = true + -- faster expansion: + -- game.map_settings.enemy_expansion.min_expansion_cooldown = 4 * 3600 + -- game.map_settings.enemy_expansion.max_expansion_cooldown = 30 * 3600 + -- slowed down due to the effect on single-player games: + game.map_settings.enemy_expansion.min_expansion_cooldown = 6 * 3600 + game.map_settings.enemy_expansion.max_expansion_cooldown = 45 * 3600 + game.map_settings.enemy_expansion.settler_group_max_size = 24 + game.map_settings.enemy_expansion.settler_group_min_size = 6 + -- maybe should be 3.5 if possible: + game.map_settings.enemy_expansion.max_expansion_distance = 4 + -- could turn off default AI attacks: + game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 1 + -- + game.map_settings.pollution.enabled = true + game.map_settings.pollution.expected_max_per_chunk = 120 + game.map_settings.pollution.min_to_show_per_chunk = 10 + game.map_settings.pollution.min_pollution_to_damage_trees = 20 + game.map_settings.pollution.pollution_per_tree_damage = 0.2 + game.map_settings.pollution.max_pollution_to_restore_trees = 0.04 + game.map_settings.pollution.pollution_restored_per_tree_damage = 0.01 + game.map_settings.pollution.pollution_with_max_forest_damage = 80 + game.map_settings.pollution.ageing = 0.1 - game.map_settings.enemy_expansion.enabled = true - -- faster expansion: - -- game.map_settings.enemy_expansion.min_expansion_cooldown = 4 * 3600 - -- game.map_settings.enemy_expansion.max_expansion_cooldown = 30 * 3600 - -- slowed down due to the effect on single-player games: - game.map_settings.enemy_expansion.min_expansion_cooldown = 6 * 3600 - game.map_settings.enemy_expansion.max_expansion_cooldown = 45 * 3600 - game.map_settings.enemy_expansion.settler_group_max_size = 24 - game.map_settings.enemy_expansion.settler_group_min_size = 6 - -- maybe should be 3.5 if possible: - game.map_settings.enemy_expansion.max_expansion_distance = 4 - - -- could turn off default AI attacks: - game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 1 - -- - game.map_settings.pollution.enabled = true - game.map_settings.pollution.expected_max_per_chunk = 120 - game.map_settings.pollution.min_to_show_per_chunk = 10 - game.map_settings.pollution.min_pollution_to_damage_trees = 20 - game.map_settings.pollution.pollution_per_tree_damage = 0.2 - game.map_settings.pollution.max_pollution_to_restore_trees = 0.04 - game.map_settings.pollution.pollution_restored_per_tree_damage = 0.01 - game.map_settings.pollution.pollution_with_max_forest_damage = 80 - game.map_settings.pollution.ageing = 0.1 - - game.map_settings.pollution.diffusion_ratio = 0.035 - -- - -- game.forces.neutral.character_inventory_slots_bonus = 500 - game.forces.enemy.evolution_factor = 0 + game.map_settings.pollution.diffusion_ratio = 0.035 + -- + -- game.forces.neutral.character_inventory_slots_bonus = 500 + game.forces.enemy.evolution_factor = 0 end -- prefer memory.force_name if possible function Public.get_crew_force_name(id) - return string.format('crew-%03d', id) + return string.format('crew-%03d', id) end -- prefer memory.enemy_force_name if possible function Public.get_enemy_force_name(id) - return string.format('enemy-%03d', id) + return string.format('enemy-%03d', id) end -- prefer memory.ancient_friendly_force_name if possible function Public.get_ancient_friendly_force_name(id) - return string.format('ancient-friendly-%03d', id) + return string.format('ancient-friendly-%03d', id) end -- prefer memory.ancient_enemy_force_name if possible function Public.get_ancient_hostile_force_name(id) - return string.format('ancient-hostile-%03d', id) + return string.format('ancient-hostile-%03d', id) end function Public.get_id_from_force_name(force_name) - return tonumber(string.sub(force_name, -3, -1)) or nil + return tonumber(string.sub(force_name, -3, -1)) or nil end function Public.is_id_valid(id) - if id and id ~= 0 then - return true - else - return false - end + if id and id ~= 0 then + return true + else + return false + end end -- NOTE: Items here are either unobtainable or hard to find/get -- Connected with crew.lua recipe and technology disables function Public.get_item_blacklist(tier) local blacklist = LootRaffle.get_tech_blacklist(tier) - blacklist['landfill'] = true - blacklist['locomotive'] = true - blacklist['cargo-wagon'] = true - blacklist['fluid-wagon'] = true - blacklist['train-stop'] = true - blacklist['rail-signal'] = true - blacklist['rail-chain-signal'] = true - -- blacklist['tank'] = true - -- blacklist['cannon-shell'] = true - -- blacklist['explosive-cannon-shell'] = true - -- blacklist['speed-module-3'] = true - -- blacklist['productivity-module-3'] = true - -- blacklist['effectivity-module-3'] = true - -- blacklist['space-science-pack'] = true - -- blacklist['rocket-control-unit'] = true - blacklist['artillery-wagon'] = true - blacklist['artillery-turret'] = true - blacklist['artillery-targeting-remote'] = true - -- blacklist['uranium-cannon-shell'] = true - -- blacklist['explosive-uranium-cannon-shell'] = true - blacklist['satellite'] = true - blacklist['rocket-silo'] = true - -- blacklist['destroyer-capsule'] = true - -- blacklist['spidertron'] = true - blacklist['discharge-defense-remote'] = true - blacklist['discharge-defense-equipment'] = true - blacklist['loader'] = true - blacklist['fast-loader'] = true + blacklist['landfill'] = true + blacklist['locomotive'] = true + blacklist['cargo-wagon'] = true + blacklist['fluid-wagon'] = true + blacklist['train-stop'] = true + blacklist['rail-signal'] = true + blacklist['rail-chain-signal'] = true + -- blacklist['tank'] = true + -- blacklist['cannon-shell'] = true + -- blacklist['explosive-cannon-shell'] = true + -- blacklist['speed-module-3'] = true + -- blacklist['productivity-module-3'] = true + -- blacklist['effectivity-module-3'] = true + -- blacklist['space-science-pack'] = true + -- blacklist['rocket-control-unit'] = true + blacklist['artillery-wagon'] = true + blacklist['artillery-turret'] = true + blacklist['artillery-targeting-remote'] = true + -- blacklist['uranium-cannon-shell'] = true + -- blacklist['explosive-uranium-cannon-shell'] = true + blacklist['satellite'] = true + blacklist['rocket-silo'] = true + -- blacklist['destroyer-capsule'] = true + -- blacklist['spidertron'] = true + blacklist['discharge-defense-remote'] = true + blacklist['discharge-defense-equipment'] = true + blacklist['loader'] = true + blacklist['fast-loader'] = true blacklist['express-loader'] = true - -- blacklist['land-mine'] = true - blacklist['wood'] = true -- too easy to acquire + -- blacklist['land-mine'] = true + blacklist['wood'] = true -- too easy to acquire - blacklist['speed-module-2'] = true - blacklist['speed-module-3'] = true + blacklist['speed-module-2'] = true + blacklist['speed-module-3'] = true return blacklist end @@ -1688,15 +1714,17 @@ end -- scale: final result of formula with tier scaled -- tech_tier: float in range [0; 1]; 1 = everything unlocked function Public.pick_random_price(tier, scale, tech_tier) - if tier < 0 or scale < 0 then return end + if tier < 0 or scale < 0 then + return + end - local item_stacks = LootRaffle.roll(math.floor(scale * (tier ^ 2 + 10 * tier)), 20, Public.get_item_blacklist(tech_tier)) - local price = {} - for _, item_stack in pairs(item_stacks) do - price[#price+1] = {name = item_stack.name, amount = item_stack.count} - end + local item_stacks = LootRaffle.roll(math.floor(scale * (tier ^ 2 + 10 * tier)), 20, Public.get_item_blacklist(tech_tier)) + local price = {} + for _, item_stack in pairs(item_stacks) do + price[#price + 1] = {name = item_stack.name, amount = item_stack.count} + end - return price + return price end -- This method should exist in table but it doesn't for some reason on comfy repo so I copied it to here @@ -1717,113 +1745,126 @@ end -- Used to connect multi-surface poles function Public.force_connect_poles(pole1, pole2) - if not pole1 then return end - if not pole1.valid then return end - if not pole2 then return end - if not pole2.valid then return end + if not pole1 then + return + end + if not pole1.valid then + return + end + if not pole2 then + return + end + if not pole2.valid then + return + end - -- force connections for testing (by placing many poles around the substations) - -- for _, e in pairs(pole1.surface.find_entities_filtered{type="electric-pole", position = pole1.position, radius = 10}) do - -- pole1.connect_neighbour(e) - -- end + -- force connections for testing (by placing many poles around the substations) + -- for _, e in pairs(pole1.surface.find_entities_filtered{type="electric-pole", position = pole1.position, radius = 10}) do + -- pole1.connect_neighbour(e) + -- end - -- for _, e in pairs(pole2.surface.find_entities_filtered{type="electric-pole", position = pole2.position, radius = 10}) do - -- pole2.connect_neighbour(e) - -- end + -- for _, e in pairs(pole2.surface.find_entities_filtered{type="electric-pole", position = pole2.position, radius = 10}) do + -- pole2.connect_neighbour(e) + -- end - -- NOTE: "connect_neighbour" returns false when the entities are already connected as well - pole1.disconnect_neighbour(pole2) - local success = pole1.connect_neighbour(pole2) - if success then return end + -- NOTE: "connect_neighbour" returns false when the entities are already connected as well + pole1.disconnect_neighbour(pole2) + local success = pole1.connect_neighbour(pole2) + if success then + return + end - local pole1_neighbours = pole1.neighbours['copper'] - local pole2_neighbours = pole2.neighbours['copper'] + local pole1_neighbours = pole1.neighbours['copper'] + local pole2_neighbours = pole2.neighbours['copper'] - -- try avoiding disconnecting more poles than needed - local disconnect_from_pole1 = false - local disconnect_from_pole2 = false + -- try avoiding disconnecting more poles than needed + local disconnect_from_pole1 = false + local disconnect_from_pole2 = false - if #pole1_neighbours >= #pole2_neighbours then - disconnect_from_pole1 = true - end + if #pole1_neighbours >= #pole2_neighbours then + disconnect_from_pole1 = true + end - if #pole2_neighbours >= #pole1_neighbours then - disconnect_from_pole2 = true - end + if #pole2_neighbours >= #pole1_neighbours then + disconnect_from_pole2 = true + end - if disconnect_from_pole1 then - -- Prioritise disconnecting last connections as those are most likely redundant (at least for holds, although even then it's not always the case) - for i = #pole1_neighbours, 1, -1 do - local e = pole1_neighbours[i] - -- only disconnect poles from same surface - if e and e.valid and e.surface.name == pole1.surface.name then - pole1.disconnect_neighbour(e) - break - end - end - end + if disconnect_from_pole1 then + -- Prioritise disconnecting last connections as those are most likely redundant (at least for holds, although even then it's not always the case) + for i = #pole1_neighbours, 1, -1 do + local e = pole1_neighbours[i] + -- only disconnect poles from same surface + if e and e.valid and e.surface.name == pole1.surface.name then + pole1.disconnect_neighbour(e) + break + end + end + end - if disconnect_from_pole2 then - -- Prioritise disconnecting last connections as those are most likely redundant (at least for holds, although even then it's not always the case) - for i = #pole2_neighbours, 1, -1 do - local e = pole2_neighbours[i] - -- only disconnect poles from same surface - if e and e.valid and e.surface.name == pole2.surface.name then - pole2.disconnect_neighbour(e) - break - end - end - end + if disconnect_from_pole2 then + -- Prioritise disconnecting last connections as those are most likely redundant (at least for holds, although even then it's not always the case) + for i = #pole2_neighbours, 1, -1 do + local e = pole2_neighbours[i] + -- only disconnect poles from same surface + if e and e.valid and e.surface.name == pole2.surface.name then + pole2.disconnect_neighbour(e) + break + end + end + end - local success2 = pole1.connect_neighbour(pole2) - if not success2 then - -- This can happen if in future pole reach connection limit(5) with poles from other surfaces - log("Error: power fix didn't work") - end + local success2 = pole1.connect_neighbour(pole2) + if not success2 then + -- This can happen if in future pole reach connection limit(5) with poles from other surfaces + log("Error: power fix didn't work") + end end - -- position here refers to middle position function Public.delete_entities(surface, position, width, height) - local area = {left_top = {position.x - width/2, position.y - height/2}, right_bottom = {position.x + width/2 + 0.5, position.y + height/2 + 0.5}} - surface.destroy_decoratives{area = area} - local existing = surface.find_entities_filtered{area = area} - if not existing then return end + local area = {left_top = {position.x - width / 2, position.y - height / 2}, right_bottom = {position.x + width / 2 + 0.5, position.y + height / 2 + 0.5}} + surface.destroy_decoratives {area = area} + local existing = surface.find_entities_filtered {area = area} + if not existing then + return + end - for _, e in pairs(existing) do - if not (e.name == 'iron-ore' or e.name == 'copper-ore' or e.name == 'stone' or e.name == 'uranium-ore' or e.name == 'crude-oil') then - if not (e.name == 'rocket-silo') then - e.destroy() - end - end - end + for _, e in pairs(existing) do + if not (e.name == 'iron-ore' or e.name == 'copper-ore' or e.name == 'stone' or e.name == 'uranium-ore' or e.name == 'crude-oil') then + if not (e.name == 'rocket-silo') then + e.destroy() + end + end + end end function Public.replace_unwalkable_tiles(surface, position, width, height) - local area = {left_top = {position.x - width/2, position.y - height/2}, right_bottom = {position.x + width/2 + 0.5, position.y + height/2 + 0.5}} - local existing = surface.find_tiles_filtered{area = area, collision_mask = "water-tile"} - if not existing then return end + local area = {left_top = {position.x - width / 2, position.y - height / 2}, right_bottom = {position.x + width / 2 + 0.5, position.y + height / 2 + 0.5}} + local existing = surface.find_tiles_filtered {area = area, collision_mask = 'water-tile'} + if not existing then + return + end - local tiles = {} + local tiles = {} - for _, t in pairs(existing) do - tiles[#tiles + 1] = {name = "landfill", position = t.position} - end + for _, t in pairs(existing) do + tiles[#tiles + 1] = {name = 'landfill', position = t.position} + end - if #tiles > 0 then - surface.set_tiles(tiles, true) - end + if #tiles > 0 then + surface.set_tiles(tiles, true) + end end function Public.get_valid_spawners(surface) - local memory = Memory.get_crew_memory() - local destination = Public.current_destination() + local memory = Memory.get_crew_memory() + local destination = Public.current_destination() local spawners = surface.find_entities_filtered({type = 'unit-spawner', force = memory.enemy_force_name}) local boat_spawners = {} - if destination.dynamic_data.enemyboats and #destination.dynamic_data.enemyboats > 0 then + if destination.dynamic_data.enemyboats and #destination.dynamic_data.enemyboats > 0 then for i = 1, #destination.dynamic_data.enemyboats do local eb = destination.dynamic_data.enemyboats[i] if eb.spawner and eb.spawner.valid then @@ -1852,73 +1893,84 @@ function Public.get_valid_spawners(surface) end function Public.get_random_valid_spawner(surface) - local spawners = Public.get_valid_spawners(surface) - if #spawners == 0 then return end + if #spawners == 0 then + return + end - return spawners[Math.random(#spawners)] + return spawners[Math.random(#spawners)] end -- @TODO move this somewhere else, so that health multiplier formula can be put to balance function Public.try_make_biter_elite(entity) - if not (entity and entity.valid) then return end + if not (entity and entity.valid) then + return + end - local memory = Memory.get_crew_memory() + local memory = Memory.get_crew_memory() - local difficulty_index = CoreData.get_difficulty_option_from_value(memory.difficulty) - if difficulty_index < 3 and Public.overworldx() < 800 then return end + local difficulty_index = CoreData.get_difficulty_option_from_value(memory.difficulty) + if difficulty_index < 3 and Public.overworldx() < 800 then + return + end - if Public.overworldx() == 0 then return end + if Public.overworldx() == 0 then + return + end - -- chance to turn biter elite - if Math.random(1, 8) ~= 1 then return end + -- chance to turn biter elite + if Math.random(1, 8) ~= 1 then + return + end - local health_multiplier + local health_multiplier - if difficulty_index <= 3 then - health_multiplier = 5 - else - health_multiplier = 10 - end + if difficulty_index <= 3 then + health_multiplier = 5 + else + health_multiplier = 10 + end - -- 1000 leagues = 1x - -- 2000 leagues = 2x - -- 3000 leagues = 4x - -- etc. - if Public.overworldx() > 1000 then - health_multiplier = health_multiplier * 2 ^ ((Public.overworldx() - 1000) / 1000) - end + -- 1000 leagues = 1x + -- 2000 leagues = 2x + -- 3000 leagues = 4x + -- etc. + if Public.overworldx() > 1000 then + health_multiplier = health_multiplier * 2 ^ ((Public.overworldx() - 1000) / 1000) + end - local max_hp = Math.ceil(entity.prototype.max_health * health_multiplier) - Public.new_healthbar(false, entity, max_hp, nil, max_hp, 0.4, -1) + local max_hp = Math.ceil(entity.prototype.max_health * health_multiplier) + Public.new_healthbar(false, entity, max_hp, nil, max_hp, 0.4, -1) - local elite_biters = memory.elite_biters - if elite_biters then - elite_biters[entity.unit_number] = entity - end + local elite_biters = memory.elite_biters + if elite_biters then + elite_biters[entity.unit_number] = entity + end end -- This function is meant to handle damage adjustment cases that automatically damages/heals either entity or its virtual health. -- NOTE: This is only meant for hostile entities (for now at least), as friendly units with healthbars are more difficult to handle -- NOTE: "damage" can also be negative, which will heal the entity (but not past maximum health) function Public.damage_hostile_entity(entity, damage) - if not (entity and entity.valid) then return end + if not (entity and entity.valid) then + return + end - local remaining_health = Public.entity_damage_healthbar(entity, damage) + local remaining_health = Public.entity_damage_healthbar(entity, damage) - -- Does entity have virtual healthbar - if remaining_health then - if remaining_health <= 0 then - entity.die() - end - else -- Not, so treat it as simple entity - -- Note: According to docs, health is automatically clamped to [0, max_health] so we don't need to do it - entity.health = entity.health - damage - if entity.health <= 0 then - entity.die() - end - end + -- Does entity have virtual healthbar + if remaining_health then + if remaining_health <= 0 then + entity.die() + end + else -- Not, so treat it as simple entity + -- Note: According to docs, health is automatically clamped to [0, max_health] so we don't need to do it + entity.health = entity.health - damage + if entity.health <= 0 then + entity.die() + end + end end -return Public \ No newline at end of file +return Public diff --git a/maps/planet_prison.lua b/maps/planet_prison.lua index c7557da5..02c85d4f 100644 --- a/maps/planet_prison.lua +++ b/maps/planet_prison.lua @@ -6,7 +6,7 @@ local Session = require 'utils.datastore.session_data' local Event = require 'utils.event' local Freeplay = require 'utils.freeplay' local Server = require 'utils.server' -local MapFuntions = require 'tools.map_functions' +local MapFuntions = require 'utils.tools.map_functions' local CommonFunctions = require 'utils.common' local LayersFunctions = require 'maps.planet_prison.mod.layers' local AIFunctions = require 'maps.planet_prison.ai' diff --git a/maps/railway_troopers_v2/main.lua b/maps/railway_troopers_v2/main.lua index fd6ff5b7..f54ba0ef 100644 --- a/maps/railway_troopers_v2/main.lua +++ b/maps/railway_troopers_v2/main.lua @@ -14,7 +14,7 @@ local difficulties_votes = { local Get_noise = require 'utils.get_noise' local Immersive_cargo_wagons = require 'modules.immersive_cargo_wagons.main' -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local map_height = 64 diff --git a/maps/rainbow_road.lua b/maps/rainbow_road.lua index d54e0c9e..f0bf5b87 100644 --- a/maps/rainbow_road.lua +++ b/maps/rainbow_road.lua @@ -1,8 +1,8 @@ --luacheck: ignore local event = require 'utils.event' local simplex_noise = require 'utils.simplex_noise'.d2 -local rainbow_colors = require 'tools.rainbow_colors' -local map_functions = require 'tools.map_functions' +local rainbow_colors = require 'utils.tools.rainbow_colors' +local map_functions = require 'utils.tools.map_functions' require 'modules.satellite_score' local ore_spawn_raffle = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'copper-ore', 'coal', 'coal', 'coal', 'stone', 'uranium-ore', 'crude-oil'} diff --git a/maps/rivers.lua b/maps/rivers.lua index ee6ced38..7fe3bb61 100644 --- a/maps/rivers.lua +++ b/maps/rivers.lua @@ -10,7 +10,7 @@ local event = require 'utils.event' local table_insert = table.insert local math_random = math.random local simplex_noise = require 'utils.simplex_noise'.d2 -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local disabled_for_deconstruction = { ['fish'] = true diff --git a/maps/rocky_waste.lua b/maps/rocky_waste.lua index 724800e3..210d0409 100644 --- a/maps/rocky_waste.lua +++ b/maps/rocky_waste.lua @@ -163,8 +163,8 @@ local function on_player_joined_game(event) end end -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' local function on_player_mined_entity(event) local entity = event.entity diff --git a/maps/scrap_railworld.lua b/maps/scrap_railworld.lua index d037e459..750b2669 100644 --- a/maps/scrap_railworld.lua +++ b/maps/scrap_railworld.lua @@ -2,7 +2,7 @@ require 'modules.no_deconstruction_of_neutral_entities' require 'modules.satellite_score' require 'modules.mineable_wreckage_yields_scrap' -local LootRaffle = require 'functions.loot_raffle' +local LootRaffle = require 'utils.functions.loot_raffle' local Get_noise = require 'utils.get_noise' local math_random = math.random local math_floor = math.floor diff --git a/maps/scrap_towny_ffa/nauvis.lua b/maps/scrap_towny_ffa/nauvis.lua index 89fa0837..d9322163 100644 --- a/maps/scrap_towny_ffa/nauvis.lua +++ b/maps/scrap_towny_ffa/nauvis.lua @@ -1,7 +1,7 @@ local Event = require 'utils.event' local Server = require 'utils.server' local ScenarioTable = require 'maps.scrap_towny_ffa.table' -local SoftReset = require 'functions.soft_reset' +local SoftReset = require 'utils.functions.soft_reset' local Token = require 'utils.token' local math_random = math.random diff --git a/maps/scrap_towny_ffa/trap.lua b/maps/scrap_towny_ffa/trap.lua index 57124006..d4ff3957 100644 --- a/maps/scrap_towny_ffa/trap.lua +++ b/maps/scrap_towny_ffa/trap.lua @@ -2,9 +2,9 @@ local Event = require 'utils.event' local Evolution = require 'maps.scrap_towny_ffa.evolution' local Town_center = require 'maps.scrap_towny_ffa.town_center' local Scrap = require 'maps.scrap_towny_ffa.scrap' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' -local tick_tack_trap = require 'functions.tick_tack_trap' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' local math_random = math.random diff --git a/maps/spiral_troopers.lua b/maps/spiral_troopers.lua index 0de0dbe1..ff4502b5 100644 --- a/maps/spiral_troopers.lua +++ b/maps/spiral_troopers.lua @@ -6,7 +6,7 @@ require 'modules.dynamic_landfill' require 'modules.spawners_contain_biters' require 'modules.satellite_score' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' --require "rewards" local function shuffle(tbl) @@ -627,8 +627,7 @@ local function on_entity_died(event) end if entity_drop_amount[event.entity.name] then if game.forces.enemy.evolution_factor < 0.5 then - local amount = - math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high) * (0.5 - game.forces.enemy.evolution_factor) * 2, 0) + local amount = math.ceil(math.random(entity_drop_amount[event.entity.name].low, entity_drop_amount[event.entity.name].high) * (0.5 - game.forces.enemy.evolution_factor) * 2, 0) event.entity.surface.spill_item_stack(event.entity.position, {name = ore_spill_raffle[math.random(1, #ore_spill_raffle)], count = amount}, true) end end diff --git a/maps/spooky_forest.lua b/maps/spooky_forest.lua index 46174b2e..071b05cb 100644 --- a/maps/spooky_forest.lua +++ b/maps/spooky_forest.lua @@ -18,9 +18,9 @@ require 'modules.rocks_broken_paint_tiles' require 'modules.rpg' require 'modules.hunger' -local shapes = require 'tools.shapes' +local shapes = require 'utils.tools.shapes' local event = require 'utils.event' -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise' simplex_noise = simplex_noise.d2 diff --git a/maps/stone_maze/1x1_rooms.lua b/maps/stone_maze/1x1_rooms.lua index 542c4f72..cbc37085 100644 --- a/maps/stone_maze/1x1_rooms.lua +++ b/maps/stone_maze/1x1_rooms.lua @@ -1,5 +1,5 @@ --luacheck: ignore -local Basic_markets = require 'functions.basic_markets' +local Basic_markets = require 'utils.functions.basic_markets' local Biter_pets = require 'modules.biter_pets' local get_noise = require 'maps.stone_maze.noise' diff --git a/maps/stone_maze/2x2_rooms.lua b/maps/stone_maze/2x2_rooms.lua index 420631d1..34f9206e 100644 --- a/maps/stone_maze/2x2_rooms.lua +++ b/maps/stone_maze/2x2_rooms.lua @@ -1,5 +1,5 @@ --luacheck: ignore -local Basic_markets = require 'functions.basic_markets' +local Basic_markets = require 'utils.functions.basic_markets' local get_noise = require 'maps.stone_maze.noise' local room = {} diff --git a/maps/stone_maze/main.lua b/maps/stone_maze/main.lua index 184f4bd4..67b02d87 100644 --- a/maps/stone_maze/main.lua +++ b/maps/stone_maze/main.lua @@ -9,7 +9,7 @@ require 'modules.hunger' require 'modules.no_turrets' --essentials -require 'functions.maze' +require 'utils.functions.maze' require 'modules.biters_yield_coins' require 'modules.rocks_yield_ore' require 'modules.mineable_wreckage_yields_scrap' @@ -35,7 +35,7 @@ local multirooms = {} multirooms['2x2'] = require 'maps.stone_maze.2x2_rooms' multirooms['3x3'] = require 'maps.stone_maze.3x3_rooms' -map_functions = require 'tools.map_functions' +map_functions = require 'utils.tools.map_functions' grid_size = 24 --manual_mining_speed_modifier = 1 main_ground_tile = 'dirt-3' @@ -76,8 +76,7 @@ local function draw_depth_gui() if player.gui.top.evolution_gui then player.gui.top.evolution_gui.destroy() end - local element = - player.gui.top.add({type = 'sprite-button', name = 'evolution_gui', caption = 'Depth: ' .. global.maze_depth, tooltip = 'Delve deep and face increased dangers.'}) + local element = player.gui.top.add({type = 'sprite-button', name = 'evolution_gui', caption = 'Depth: ' .. global.maze_depth, tooltip = 'Delve deep and face increased dangers.'}) local style = element.style style.minimal_height = 38 style.maximal_height = 38 diff --git a/maps/stoneblock.lua b/maps/stoneblock.lua index 17942682..e8959d98 100644 --- a/maps/stoneblock.lua +++ b/maps/stoneblock.lua @@ -20,7 +20,7 @@ require 'modules.evolution_extended' local event = require 'utils.event' local math_random = math.random local insert = table.insert -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise' local simplex_noise = simplex_noise.d2 diff --git a/maps/tank_battles_old.lua b/maps/tank_battles_old.lua index c62a4c3e..8ab6f19f 100644 --- a/maps/tank_battles_old.lua +++ b/maps/tank_battles_old.lua @@ -4,7 +4,7 @@ local event = require 'utils.event' local table_insert = table.insert local math_random = math.random -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local arena_size = 160 local function shuffle(tbl) diff --git a/maps/tank_conquest/tank_conquest.lua b/maps/tank_conquest/tank_conquest.lua index 6a14b259..420af4c9 100644 --- a/maps/tank_conquest/tank_conquest.lua +++ b/maps/tank_conquest/tank_conquest.lua @@ -118,7 +118,7 @@ local table_of_slots = { local table_of_ores = {'iron-ore', 'copper-ore', 'stone', 'coal'} -local map_functions = require 'tools.map_functions' +local map_functions = require 'utils.tools.map_functions' local event = require 'utils.event' @@ -457,8 +457,7 @@ function draw_gui_status(player) element_label.style.font_color = table_of_colors.white - local element_label = - element_frame.add({type = 'label', caption = math.floor(global.table_of_properties[global.table_of_properties[player.force.name].enemy].available_tickets)}) + local element_label = element_frame.add({type = 'label', caption = math.floor(global.table_of_properties[global.table_of_properties[player.force.name].enemy].available_tickets)}) element_label.style.left_padding = 20 @@ -836,10 +835,7 @@ function create_a_base(force_name, base_position) end if - object.name == 'infinity-chest' or object.name == 'substation' or object.name == 'big-electric-pole' or object.name == 'medium-electric-pole' or - object.name == 'inserter' or - object.name == 'accumulator' or - object.name == 'solar-panel' or + object.name == 'infinity-chest' or object.name == 'substation' or object.name == 'big-electric-pole' or object.name == 'medium-electric-pole' or object.name == 'inserter' or object.name == 'accumulator' or object.name == 'solar-panel' or object.name == 'gun-turret' then entity.destructible = false @@ -896,14 +892,11 @@ function create_a_spot(spot_name, spot_position, spot_blueprint) } ) - local draw_spot_force = - rendering.draw_text({text = spot.force.name, surface = surface, target = {spot.position.x, spot.position.y + 0.5}, color = spot.color, scale = 5, alignment = 'center'}) + local draw_spot_force = rendering.draw_text({text = spot.force.name, surface = surface, target = {spot.position.x, spot.position.y + 0.5}, color = spot.color, scale = 5, alignment = 'center'}) - local draw_spot_value = - rendering.draw_text({text = spot.value, surface = surface, target = {spot.position.x, spot.position.y - 4}, color = spot.color, scale = 5, alignment = 'center'}) + local draw_spot_value = rendering.draw_text({text = spot.value, surface = surface, target = {spot.position.x, spot.position.y - 4}, color = spot.color, scale = 5, alignment = 'center'}) - local draw_spot_name = - rendering.draw_text({text = spot.name, surface = surface, target = {spot.position.x, spot.position.y - 2}, color = spot.color, scale = 5, alignment = 'center'}) + local draw_spot_name = rendering.draw_text({text = spot.name, surface = surface, target = {spot.position.x, spot.position.y - 2}, color = spot.color, scale = 5, alignment = 'center'}) local table_of_drawings = {name = draw_spot_name, value = draw_spot_value, force = draw_spot_force, border = draw_spot_border} @@ -957,10 +950,7 @@ function create_a_spot(spot_name, spot_position, spot_blueprint) table.insert(table_of_entities, entity) end - table.insert( - global.table_of_spots, - {properties = table_of_properties, drawings = table_of_drawings, players = table_of_players, positions = table_of_positions, entities = table_of_entities} - ) + table.insert(global.table_of_spots, {properties = table_of_properties, drawings = table_of_drawings, players = table_of_players, positions = table_of_positions, entities = table_of_entities}) end function create_a_point_of_interest(poi_blueprint, poi_position) @@ -1139,10 +1129,7 @@ function event_on_click_join(player) -- draw_gui_spawn( player ) -- only for tests for _, spot in pairs(global.table_of_spots) do - player.force.chart( - game.surfaces.tank_conquest, - {{x = spot.properties.position.x - 10, y = spot.properties.position.y - 10}, {x = spot.properties.position.x + 10, y = spot.properties.position.y + 10}} - ) + player.force.chart(game.surfaces.tank_conquest, {{x = spot.properties.position.x - 10, y = spot.properties.position.y - 10}, {x = spot.properties.position.x + 10, y = spot.properties.position.y + 10}}) end game.print(player.name .. ' joined ' .. global.table_of_properties[player.force.name].icon) @@ -1240,10 +1227,7 @@ local function on_tick(event) for _, player in pairs(game.connected_players) do if player.force.name == spot.properties.force.name and spot.properties.value > 0 then - player.force.chart( - game.surfaces.tank_conquest, - {{x = spot.properties.position.x - 10, y = spot.properties.position.y - 10}, {x = spot.properties.position.x + 10, y = spot.properties.position.y + 10}} - ) + player.force.chart(game.surfaces.tank_conquest, {{x = spot.properties.position.x - 10, y = spot.properties.position.y - 10}, {x = spot.properties.position.x + 10, y = spot.properties.position.y + 10}}) end end @@ -1294,10 +1278,7 @@ local function on_tick(event) global.table_of_properties.countdown_in_seconds = global.table_of_properties.countdown_in_seconds - 1 end - if - global.table_of_properties.countdown_in_seconds < 0 or global.table_of_properties.force_player_one.available_tickets < 0 or - global.table_of_properties.force_player_two.available_tickets < 0 - then + if global.table_of_properties.countdown_in_seconds < 0 or global.table_of_properties.force_player_one.available_tickets < 0 or global.table_of_properties.force_player_two.available_tickets < 0 then if global.table_of_properties.force_player_one.available_tickets == global.table_of_properties.force_player_two.available_tickets then game.print('The battle is over. The round ended in a draw.') elseif global.table_of_properties.force_player_one.available_tickets > global.table_of_properties.force_player_two.available_tickets then @@ -1493,23 +1474,11 @@ local function on_tick(event) if game.surfaces.tank_conquest ~= nil and #game.connected_players and #global.table_of_spots then for _, player in pairs(game.connected_players) do for _, spot in pairs(global.table_of_spots) do - if - player.force.is_chunk_charted( - game.surfaces.tank_conquest, - {x = math.floor(spot.properties.position.x / 32), y = math.floor(spot.properties.position.y / 32)} - ) - then - local chart_tags = - player.force.find_chart_tags( - game.surfaces.tank_conquest, - {{spot.properties.position.x - 1, spot.properties.position.y - 1}, {spot.properties.position.x + 1, spot.properties.position.y + 1}} - ) + if player.force.is_chunk_charted(game.surfaces.tank_conquest, {x = math.floor(spot.properties.position.x / 32), y = math.floor(spot.properties.position.y / 32)}) then + local chart_tags = player.force.find_chart_tags(game.surfaces.tank_conquest, {{spot.properties.position.x - 1, spot.properties.position.y - 1}, {spot.properties.position.x + 1, spot.properties.position.y + 1}}) if #chart_tags == 0 then - player.force.add_chart_tag( - game.surfaces.tank_conquest, - {icon = {type = 'virtual', name = 'signal-' .. spot.properties.name}, position = spot.properties.position} - ) + player.force.add_chart_tag(game.surfaces.tank_conquest, {icon = {type = 'virtual', name = 'signal-' .. spot.properties.name}, position = spot.properties.position}) end end end @@ -1712,10 +1681,7 @@ local function on_player_changed_position(event) end for _, position in pairs(spot_item.positions) do - if - math.floor(player.position.x) == position.x and math.floor(player.position.y) == position.y or - math.ceil(player.position.x) == position.x and math.ceil(player.position.y) == position.y - then + if math.floor(player.position.x) == position.x and math.floor(player.position.y) == position.y or math.ceil(player.position.x) == position.x and math.ceil(player.position.y) == position.y then if global.table_of_spots[spot_index].players[player.index] == nil then global.table_of_spots[spot_index].players[player.index] = player @@ -1805,16 +1771,12 @@ local function on_player_died(event) if event.cause and event.cause.valid then if event.cause.name == 'character' then - player_death_message = - global.table_of_properties[player.force.name].icon .. - ' ' .. player.name .. ' was killed by ' .. global.table_of_properties[event.cause.player.force.name].icon .. ' ' .. event.cause.player.name .. '.' + player_death_message = global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ' was killed by ' .. global.table_of_properties[event.cause.player.force.name].icon .. ' ' .. event.cause.player.name .. '.' elseif event.cause.name == 'car' or event.cause.name == 'tank' or event.cause.name == 'train' then local driver = event.cause.get_driver() if driver.player then - player_death_message = - global.table_of_properties[player.force.name].icon .. - ' ' .. player.name .. ' was killed with a vehicle by ' .. global.table_of_properties[driver.player.force.name].icon .. ' ' .. driver.player.name .. '.' + player_death_message = global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ' was killed with a vehicle by ' .. global.table_of_properties[driver.player.force.name].icon .. ' ' .. driver.player.name .. '.' else player_death_message = global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ' was killed by run over.' end diff --git a/maps/territorial_control.lua b/maps/territorial_control.lua index 722b3b17..4b8ee2b9 100644 --- a/maps/territorial_control.lua +++ b/maps/territorial_control.lua @@ -15,12 +15,12 @@ require 'modules.rocks_yield_ore' require 'modules.biters_yield_coins' require 'modules.mineable_wreckage_yields_scrap' -local shapes = require 'tools.shapes' +local shapes = require 'utils.tools.shapes' local Event = require 'utils.event' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' -local tick_tack_trap = require 'functions.tick_tack_trap' -local map_functions = require 'tools.map_functions' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' +local tick_tack_trap = require 'utils.functions.tick_tack_trap' +local map_functions = require 'utils.tools.map_functions' local simplex_noise = require 'utils.simplex_noise' simplex_noise = simplex_noise.d2 diff --git a/maps/tetris/main.lua b/maps/tetris/main.lua index c9f1aca5..ed7fc327 100644 --- a/maps/tetris/main.lua +++ b/maps/tetris/main.lua @@ -5,7 +5,7 @@ local event = require 'utils.event' local bricks = require 'maps.tetris.bricks' -local connect_belts = require 'functions.connect_belts' +local connect_belts = require 'utils.functions.connect_belts' local playfield_left_top = {x = -17, y = -18} local playfield_width = 12 @@ -219,10 +219,7 @@ local function add_score_points(amount) end local function move_lines_down(surface, y) - local entities = - surface.find_entities_filtered( - {area = {{playfield_area.left_top.x, playfield_area.left_top.y}, {playfield_area.left_top.x + playfield_width + 1, playfield_area.left_top.y + y + 1}}, force = 'enemy'} - ) + local entities = surface.find_entities_filtered({area = {{playfield_area.left_top.x, playfield_area.left_top.y}, {playfield_area.left_top.x + playfield_width + 1, playfield_area.left_top.y + y + 1}}, force = 'enemy'}) for _, e in pairs(entities) do if e.valid then e.clone {position = {e.position.x, e.position.y + 1}, surface = surface, force = 'enemy'} @@ -419,14 +416,7 @@ local function move(surface, item) return end for k, p in pairs(global.active_brick.positions) do - if - not global.tetris_grid[ - coord_string( - math.floor(global.active_brick.positions[k].x + move_translations[item][1]), - math.floor(global.active_brick.positions[k].y + move_translations[item][2]) - ) - ] - then + if not global.tetris_grid[coord_string(math.floor(global.active_brick.positions[k].x + move_translations[item][1]), math.floor(global.active_brick.positions[k].y + move_translations[item][2]))] then return end end diff --git a/modules/dangerous_nights.lua b/modules/dangerous_nights.lua index 60c131d5..e141403e 100644 --- a/modules/dangerous_nights.lua +++ b/modules/dangerous_nights.lua @@ -2,8 +2,8 @@ local Event = require 'utils.event' -local unearthing_worm = require 'functions.unearthing_worm' -local unearthing_biters = require 'functions.unearthing_biters' +local unearthing_worm = require 'utils.functions.unearthing_worm' +local unearthing_biters = require 'utils.functions.unearthing_biters' local immune_tiles = { ['concrete'] = true, @@ -33,9 +33,7 @@ local function on_player_changed_position(event) return end - for _, lamp in pairs( - player.surface.find_entities_filtered({area = {{player.position.x - 18, player.position.y - 18}, {player.position.x + 18, player.position.y + 18}}, name = 'small-lamp'}) - ) do + for _, lamp in pairs(player.surface.find_entities_filtered({area = {{player.position.x - 18, player.position.y - 18}, {player.position.x + 18, player.position.y + 18}}, name = 'small-lamp'})) do local circuit = lamp.get_or_create_control_behavior() if circuit then if lamp.energy > 25 and circuit.disabled == false then diff --git a/modules/towny/main.lua b/modules/towny/main.lua index 16f329be..6b1a4755 100644 --- a/modules/towny/main.lua +++ b/modules/towny/main.lua @@ -2,7 +2,7 @@ --[[ Exchange Strings: -for "terrain_layouts.scrap_01" +for "utils.terrain_layouts.scrap_01" >>>eNpjYBBiEGQAgwYHBgYHBw6W5PzEHAaGA0Begz2I5krOLyhIL dLNL0pFFuZMLipNSdXNz0RVnJqXmlupm5RYnAoRgmCOzKL8PHQTW ItL8vNQRUqKUlOLQazVq1bZgUS5S4sS8zJLc9H1MjCeOHC8uKFFj diff --git a/utils/antigrief.lua b/utils/antigrief.lua index ca16b8c2..a1053088 100644 --- a/utils/antigrief.lua +++ b/utils/antigrief.lua @@ -9,7 +9,7 @@ local Utils = require 'utils.core' local Color = require 'utils.color_presets' local Server = require 'utils.server' local Jail = require 'utils.datastore.jail_data' -local FancyTime = require 'tools.fancy_time' +local FancyTime = require 'utils.tools.fancy_time' local Task = require 'utils.task' local Token = require 'utils.token' local Discord = require 'utils.discord_handler' diff --git a/functions/basic_markets.lua b/utils/functions/basic_markets.lua similarity index 100% rename from functions/basic_markets.lua rename to utils/functions/basic_markets.lua diff --git a/functions/biter_raffle.lua b/utils/functions/biter_raffle.lua similarity index 100% rename from functions/biter_raffle.lua rename to utils/functions/biter_raffle.lua diff --git a/functions/boss_unit.lua b/utils/functions/boss_unit.lua similarity index 100% rename from functions/boss_unit.lua rename to utils/functions/boss_unit.lua diff --git a/functions/connect_belts.lua b/utils/functions/connect_belts.lua similarity index 100% rename from functions/connect_belts.lua rename to utils/functions/connect_belts.lua diff --git a/functions/create_entity_chain.lua b/utils/functions/create_entity_chain.lua similarity index 100% rename from functions/create_entity_chain.lua rename to utils/functions/create_entity_chain.lua diff --git a/functions/create_tile_chain.lua b/utils/functions/create_tile_chain.lua similarity index 100% rename from functions/create_tile_chain.lua rename to utils/functions/create_tile_chain.lua diff --git a/functions/loot_raffle.lua b/utils/functions/loot_raffle.lua similarity index 100% rename from functions/loot_raffle.lua rename to utils/functions/loot_raffle.lua diff --git a/functions/maze.lua b/utils/functions/maze.lua similarity index 100% rename from functions/maze.lua rename to utils/functions/maze.lua diff --git a/functions/noise_vector_path.lua b/utils/functions/noise_vector_path.lua similarity index 100% rename from functions/noise_vector_path.lua rename to utils/functions/noise_vector_path.lua diff --git a/functions/omegakaboom.lua b/utils/functions/omegakaboom.lua similarity index 100% rename from functions/omegakaboom.lua rename to utils/functions/omegakaboom.lua diff --git a/functions/room_generator.lua b/utils/functions/room_generator.lua similarity index 100% rename from functions/room_generator.lua rename to utils/functions/room_generator.lua diff --git a/functions/soft_reset.lua b/utils/functions/soft_reset.lua similarity index 100% rename from functions/soft_reset.lua rename to utils/functions/soft_reset.lua diff --git a/functions/tick_tack_trap.lua b/utils/functions/tick_tack_trap.lua similarity index 100% rename from functions/tick_tack_trap.lua rename to utils/functions/tick_tack_trap.lua diff --git a/functions/unearthing_biters.lua b/utils/functions/unearthing_biters.lua similarity index 100% rename from functions/unearthing_biters.lua rename to utils/functions/unearthing_biters.lua diff --git a/functions/unearthing_worm.lua b/utils/functions/unearthing_worm.lua similarity index 100% rename from functions/unearthing_worm.lua rename to utils/functions/unearthing_worm.lua diff --git a/utils/gui/admin.lua b/utils/gui/admin.lua index 97758f16..7d7e9d78 100644 --- a/utils/gui/admin.lua +++ b/utils/gui/admin.lua @@ -498,6 +498,7 @@ local function create_admin_panel(data) end end + local listable_players = frame.add({type = 'checkbox', name = 'admin_listable_players', caption = 'Toggle between all players or connected players.', state = false}) local drop_down = frame.add({type = 'drop-down', name = 'admin_player_select', items = player_names, selected_index = selected_index}) drop_down.style.minimal_width = 326 drop_down.style.right_padding = 12 diff --git a/terrain_layouts/biters_and_resources_east.lua b/utils/terrain_layouts/biters_and_resources_east.lua similarity index 100% rename from terrain_layouts/biters_and_resources_east.lua rename to utils/terrain_layouts/biters_and_resources_east.lua diff --git a/terrain_layouts/caves.lua b/utils/terrain_layouts/caves.lua similarity index 100% rename from terrain_layouts/caves.lua rename to utils/terrain_layouts/caves.lua diff --git a/terrain_layouts/cone_to_east.lua b/utils/terrain_layouts/cone_to_east.lua similarity index 100% rename from terrain_layouts/cone_to_east.lua rename to utils/terrain_layouts/cone_to_east.lua diff --git a/terrain_layouts/scrap_01.lua b/utils/terrain_layouts/scrap_01.lua similarity index 100% rename from terrain_layouts/scrap_01.lua rename to utils/terrain_layouts/scrap_01.lua diff --git a/terrain_layouts/scrap_02.lua b/utils/terrain_layouts/scrap_02.lua similarity index 100% rename from terrain_layouts/scrap_02.lua rename to utils/terrain_layouts/scrap_02.lua diff --git a/terrain_layouts/tree_01.lua b/utils/terrain_layouts/tree_01.lua similarity index 97% rename from terrain_layouts/tree_01.lua rename to utils/terrain_layouts/tree_01.lua index 5c0be7db..dbe9108e 100644 --- a/terrain_layouts/tree_01.lua +++ b/utils/terrain_layouts/tree_01.lua @@ -3,7 +3,7 @@ local math_random = math.random local table_insert = table.insert local table_remove = table.remove -local NoiseVector = require 'functions.noise_vector_path' +local NoiseVector = require 'utils.functions.noise_vector_path' local function get_vector() local x = 1000 - math_random(0, 2000) diff --git a/terrain_layouts/watery_world.lua b/utils/terrain_layouts/watery_world.lua similarity index 100% rename from terrain_layouts/watery_world.lua rename to utils/terrain_layouts/watery_world.lua diff --git a/terrain_layouts/winter.lua b/utils/terrain_layouts/winter.lua similarity index 100% rename from terrain_layouts/winter.lua rename to utils/terrain_layouts/winter.lua diff --git a/tools/cheat_mode.lua b/utils/tools/cheat_mode.lua similarity index 100% rename from tools/cheat_mode.lua rename to utils/tools/cheat_mode.lua diff --git a/tools/fancy_time.lua b/utils/tools/fancy_time.lua similarity index 100% rename from tools/fancy_time.lua rename to utils/tools/fancy_time.lua diff --git a/tools/map_functions.lua b/utils/tools/map_functions.lua similarity index 100% rename from tools/map_functions.lua rename to utils/tools/map_functions.lua diff --git a/tools/map_intro.lua b/utils/tools/map_intro.lua similarity index 100% rename from tools/map_intro.lua rename to utils/tools/map_intro.lua diff --git a/tools/map_pregen.lua b/utils/tools/map_pregen.lua similarity index 100% rename from tools/map_pregen.lua rename to utils/tools/map_pregen.lua diff --git a/tools/rainbow_colors.lua b/utils/tools/rainbow_colors.lua similarity index 100% rename from tools/rainbow_colors.lua rename to utils/tools/rainbow_colors.lua diff --git a/tools/scrap.lua b/utils/tools/scrap.lua similarity index 100% rename from tools/scrap.lua rename to utils/tools/scrap.lua diff --git a/tools/shapes.lua b/utils/tools/shapes.lua similarity index 100% rename from tools/shapes.lua rename to utils/tools/shapes.lua