From 358160c247e13ebb0c0a846a0d3e024d722cfdd6 Mon Sep 17 00:00:00 2001 From: danielmartin0 Date: Tue, 1 Oct 2024 15:46:06 +0100 Subject: [PATCH] v1 Revert "Fix 'player' shadowing in flying_texts.lua" This reverts commit 40805e68e3c0bf588b40f510d5c32b66ecca4717. Fix 'player' shadowing in flying_texts.lua all_central_positions_within_area utils/math/raffle --- maps/atoll.lua | 2 +- maps/biter_battles/biter_battles_terrain.lua | 2 +- maps/biter_battles_v2/terrain.lua | 4 +- maps/biter_hatchery/terrain.lua | 2 +- maps/cave_choppy/forest_world.lua | 2 +- maps/cave_choppy/main.lua | 2 +- maps/cave_miner.lua | 2 +- maps/cave_miner_v2/functions.lua | 2 +- maps/cave_miner_v2/terrain.lua | 2 +- maps/choppy.lua | 2 +- maps/choppy_dx.lua | 2 +- maps/chronosphere/ores.lua | 2 +- maps/chronosphere/world_functions.lua | 2 +- maps/chronosphere/worlds/fishmarket.lua | 2 +- maps/crab_defender/b.lua | 2 +- maps/crab_defender/terrain.lua | 2 +- maps/cratewood_forest.lua | 2 +- maps/crossing.lua | 2 +- maps/deep_jungle/terrain.lua | 2 +- maps/desert_oasis.lua | 2 +- maps/dungeons/biome_desert.lua | 2 +- maps/dungeons/biome_dirtlands.lua | 2 +- maps/dungeons/biome_grasslands.lua | 2 +- maps/dungeons/biome_rainbow.lua | 2 +- maps/dungeons/functions.lua | 2 +- maps/dungeons/main.lua | 2 +- maps/dungeons/tiered_dungeon.lua | 2 +- maps/expanse/main.lua | 2 +- maps/fish_defender/terrain.lua | 2 +- maps/fish_defender_v2/b.lua | 2 +- maps/fish_defender_v2/terrain.lua | 2 +- maps/hedge_maze.lua | 2 +- maps/island_troopers/terrain.lua | 2 +- maps/journey/functions.lua | 2 +- maps/journey/unique_modifiers.lua | 2 +- maps/junkyard.lua | 2 +- maps/junkyard_pvp/terrain.lua | 2 +- maps/labyrinth.lua | 2 +- maps/lost.lua | 2 +- maps/lost_desert.lua | 2 +- maps/minesweeper/functions.lua | 2 +- maps/mountain_fortress.lua | 2 +- maps/mountain_fortress_v2/collapse.lua | 2 +- maps/mountain_fortress_v2/terrain.lua | 2 +- maps/mountain_fortress_v3/get_perlin.lua | 2 +- maps/mountain_race/terrain.lua | 2 +- maps/native_war/terrain.lua | 2 +- maps/nightfall.lua | 2 +- maps/pirates/ai.lua | 6 +- maps/pirates/commands.lua | 2 +- maps/pirates/common.lua | 20 +- maps/pirates/ores.lua | 8 +- maps/pirates/quest.lua | 4 +- maps/pirates/raffle.lua | 180 -- .../quest_structures/furnace1/furnace1.lua | 122 +- .../quest_structures/market1/market1.lua | 118 +- .../surfaces/islands/cave/cave_source.lua | 2 +- maps/pirates/surfaces/islands/maze/maze.lua | 6 +- maps/pirates/utils_local.lua | 4 +- maps/pitch_black/blood_moon.lua | 2 +- maps/quarters.lua | 2 +- maps/railway_troopers_v2/main.lua | 2 +- maps/rainbow_road.lua | 2 +- maps/rivers.lua | 2 +- maps/rocky_waste.lua | 2 +- maps/scrap_railworld.lua | 2 +- maps/scrap_towny_ffa/terrain.lua | 4 +- maps/spaghettorio.lua | 2 +- maps/spooky_forest.lua | 2 +- maps/stone_maze/noise.lua | 2 +- maps/stoneblock.lua | 2 +- maps/tank_battles.lua | 2 +- maps/territorial_control.lua | 2 +- maps/wave_of_death/terrain.lua | 2 +- maps/wip/func.lua | 2 +- modules/evolution_extended.lua | 2 +- modules/ores_are_mixed.lua | 2 +- utils/functions/noise_vector_path.lua | 2 +- utils/get_noise.lua | 142 -- utils/get_perlin.lua | 135 -- utils/math/geometry.lua | 1754 +++++++++++++++++ utils/math/get_noise.lua | 160 ++ utils/math/get_perlin.lua | 149 ++ utils/math/math.lua | 35 + utils/math/perlin_noise.lua | 400 ++++ utils/math/raffle.lua | 93 + utils/{ => math}/simplex_noise.lua | 0 utils/math/stats.lua | 112 ++ utils/perlin_noise.lua | 392 ---- utils/stats.lua | 112 -- utils/table.lua | 2 +- utils/terrain_layouts/caves.lua | 2 +- utils/terrain_layouts/scrap_01.lua | 2 +- utils/terrain_layouts/scrap_02.lua | 2 +- utils/terrain_layouts/watery_world.lua | 2 +- utils/tools/map_functions.lua | 2 +- 96 files changed, 2914 insertions(+), 1192 deletions(-) delete mode 100644 maps/pirates/raffle.lua delete mode 100644 utils/get_noise.lua delete mode 100644 utils/get_perlin.lua create mode 100644 utils/math/geometry.lua create mode 100644 utils/math/get_noise.lua create mode 100644 utils/math/get_perlin.lua create mode 100644 utils/math/math.lua create mode 100644 utils/math/perlin_noise.lua create mode 100644 utils/math/raffle.lua rename utils/{ => math}/simplex_noise.lua (100%) create mode 100644 utils/math/stats.lua delete mode 100644 utils/perlin_noise.lua delete mode 100644 utils/stats.lua diff --git a/maps/atoll.lua b/maps/atoll.lua index 4d22299d..1665de12 100644 --- a/maps/atoll.lua +++ b/maps/atoll.lua @@ -3,7 +3,7 @@ require 'modules.spawners_contain_biters' require 'modules.surrounded_by_worms' -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' simplex_noise = simplex_noise.d2 local Event = require 'utils.event' local table_insert = table.insert diff --git a/maps/biter_battles/biter_battles_terrain.lua b/maps/biter_battles/biter_battles_terrain.lua index 21af534f..3b8e4330 100644 --- a/maps/biter_battles/biter_battles_terrain.lua +++ b/maps/biter_battles/biter_battles_terrain.lua @@ -1,5 +1,5 @@ --luacheck:ignore -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' local simplex_noise = simplex_noise.d2 local event = require 'utils.event' local biter_battles_terrain = {} diff --git a/maps/biter_battles_v2/terrain.lua b/maps/biter_battles_v2/terrain.lua index 5167eee8..7b10d1eb 100644 --- a/maps/biter_battles_v2/terrain.lua +++ b/maps/biter_battles_v2/terrain.lua @@ -10,8 +10,8 @@ local math_random = math.random local math_abs = math.abs local math_sqrt = math.sqrt -local GetNoise = require 'utils.get_noise' -local simplex_noise = require 'utils.simplex_noise'.d2 +local GetNoise = require 'utils.math.get_noise' +local simplex_noise = require 'utils.math.simplex_noise'.d2 local spawn_circle_size = 39 local ores = { 'copper-ore', 'iron-ore', 'stone', 'coal' } local rocks = { 'big-sand-rock', 'big-sand-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'huge-rock' } diff --git a/maps/biter_hatchery/terrain.lua b/maps/biter_hatchery/terrain.lua index 21467fa4..fbc93f39 100644 --- a/maps/biter_hatchery/terrain.lua +++ b/maps/biter_hatchery/terrain.lua @@ -1,7 +1,7 @@ --luacheck: ignore local math_abs = math.abs local math_random = math.random -local GetNoise = require 'utils.get_noise' +local GetNoise = require 'utils.math.get_noise' local Public = {} local hatchery_position = { x = 192, y = 0 } diff --git a/maps/cave_choppy/forest_world.lua b/maps/cave_choppy/forest_world.lua index 02b8ac06..e830b269 100644 --- a/maps/cave_choppy/forest_world.lua +++ b/maps/cave_choppy/forest_world.lua @@ -11,7 +11,7 @@ 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 Simplex = require 'utils.math.simplex_noise'.d2 local Event = require 'utils.event' local table_insert = table.insert local math_random = math.random diff --git a/maps/cave_choppy/main.lua b/maps/cave_choppy/main.lua index 133a2143..b561dcbc 100644 --- a/maps/cave_choppy/main.lua +++ b/maps/cave_choppy/main.lua @@ -7,7 +7,7 @@ require 'modules.rocks_broken_paint_tiles' require 'cave_miner_kaboomsticks' local enable_fishbank_terminal = true -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Event = require 'utils.event' local Module = require 'infinity_chest' local market_items = require 'cave_miner_market_items' diff --git a/maps/cave_miner.lua b/maps/cave_miner.lua index b77906cb..66635db9 100644 --- a/maps/cave_miner.lua +++ b/maps/cave_miner.lua @@ -12,7 +12,7 @@ require 'modules.rpg' local Hunger = require 'modules.hunger' local enable_fishbank_terminal = false -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' local market_items = require 'maps.cave_miner_market_items' local math_random = math.random diff --git a/maps/cave_miner_v2/functions.lua b/maps/cave_miner_v2/functions.lua index cf4863ac..ddc5926d 100644 --- a/maps/cave_miner_v2/functions.lua +++ b/maps/cave_miner_v2/functions.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Public = {} -local GetNoise = require 'utils.get_noise' +local GetNoise = require 'utils.math.get_noise' local Constants = require 'maps.cave_miner_v2.constants' local BiterRaffle = require 'utils.functions.biter_raffle' local LootRaffle = require 'utils.functions.loot_raffle' diff --git a/maps/cave_miner_v2/terrain.lua b/maps/cave_miner_v2/terrain.lua index 13269fb3..128398fa 100644 --- a/maps/cave_miner_v2/terrain.lua +++ b/maps/cave_miner_v2/terrain.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Public = {} -local GetNoise = require 'utils.get_noise' +local GetNoise = require 'utils.math.get_noise' local Functions = require 'maps.cave_miner_v2.functions' local Market = require 'maps.cave_miner_v2.market' diff --git a/maps/choppy.lua b/maps/choppy.lua index db9cc874..81071aa9 100644 --- a/maps/choppy.lua +++ b/maps/choppy.lua @@ -11,7 +11,7 @@ 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 simplex_noise = require 'utils.math.simplex_noise'.d2 local event = require 'utils.event' local table_insert = table.insert local math_random = math.random diff --git a/maps/choppy_dx.lua b/maps/choppy_dx.lua index 24525579..a735f34a 100644 --- a/maps/choppy_dx.lua +++ b/maps/choppy_dx.lua @@ -16,7 +16,7 @@ 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 simplex_noise = require 'utils.math.simplex_noise'.d2 local Event = require 'utils.event' local math_random = math.random diff --git a/maps/chronosphere/ores.lua b/maps/chronosphere/ores.lua index 257b7641..1a177791 100644 --- a/maps/chronosphere/ores.lua +++ b/maps/chronosphere/ores.lua @@ -1,7 +1,7 @@ local Chrono_table = require 'maps.chronosphere.table' local Raffle = require 'maps.chronosphere.raffles' local Public = {} -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local math_random = math.random local math_floor = math.floor local math_ceil = math.ceil diff --git a/maps/chronosphere/world_functions.lua b/maps/chronosphere/world_functions.lua index cb019641..da7ac310 100644 --- a/maps/chronosphere/world_functions.lua +++ b/maps/chronosphere/world_functions.lua @@ -1,5 +1,5 @@ local Treasure = require 'maps.chronosphere.treasure' -local Simplex_noise = require 'utils.simplex_noise'.d2 +local Simplex_noise = require 'utils.math.simplex_noise'.d2 local Raffle = require 'maps.chronosphere.raffles' local Chrono_table = require 'maps.chronosphere.table' local Blueprints = require 'maps.chronosphere.worlds.blueprints' diff --git a/maps/chronosphere/worlds/fishmarket.lua b/maps/chronosphere/worlds/fishmarket.lua index 065c4bb5..41f8e8a0 100644 --- a/maps/chronosphere/worlds/fishmarket.lua +++ b/maps/chronosphere/worlds/fishmarket.lua @@ -5,7 +5,7 @@ local Balance = require 'maps.chronosphere.balance' local Functions = require 'maps.chronosphere.world_functions' local Raffle = require 'maps.chronosphere.raffles' local Specials = require 'maps.chronosphere.terrain_specials' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Difficulty = require 'modules.difficulty_vote' local function roll_biters(p, biters, entities) diff --git a/maps/crab_defender/b.lua b/maps/crab_defender/b.lua index c90dc26e..1c235407 100644 --- a/maps/crab_defender/b.lua +++ b/maps/crab_defender/b.lua @@ -1,4 +1,4 @@ -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local map_data = require 'maps.crab_defender.map' local random = math.random diff --git a/maps/crab_defender/terrain.lua b/maps/crab_defender/terrain.lua index cd7a1971..833b0984 100644 --- a/maps/crab_defender/terrain.lua +++ b/maps/crab_defender/terrain.lua @@ -1,7 +1,7 @@ local Event = require 'utils.event' local Builder = require 'maps.crab_defender.b' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local FDT = require 'maps.crab_defender.table' local math_random = math.random local math_abs = math.abs diff --git a/maps/cratewood_forest.lua b/maps/cratewood_forest.lua index 1ce09813..209ed4b0 100644 --- a/maps/cratewood_forest.lua +++ b/maps/cratewood_forest.lua @@ -1,6 +1,6 @@ --luacheck: ignore local event = require 'utils.event' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 require 'modules.satellite_score' require 'modules.biter_noms_you' require 'modules.dangerous_goods' diff --git a/maps/crossing.lua b/maps/crossing.lua index 1ae1ecf8..9e331dec 100644 --- a/maps/crossing.lua +++ b/maps/crossing.lua @@ -2,7 +2,7 @@ local Event = require 'utils.event' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local function on_player_joined_game(event) local player = game.players[event.player_index] diff --git a/maps/deep_jungle/terrain.lua b/maps/deep_jungle/terrain.lua index e3b1b960..975bcd06 100644 --- a/maps/deep_jungle/terrain.lua +++ b/maps/deep_jungle/terrain.lua @@ -1,4 +1,4 @@ -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' local random = math.random local Public = {} diff --git a/maps/desert_oasis.lua b/maps/desert_oasis.lua index 9e441738..ee97b590 100644 --- a/maps/desert_oasis.lua +++ b/maps/desert_oasis.lua @@ -4,7 +4,7 @@ require 'modules.thirst' local Map_info = require 'modules.map_info' -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local table_insert = table.insert local math_random = math.random local math_floor = math.floor diff --git a/maps/dungeons/biome_desert.lua b/maps/dungeons/biome_desert.lua index e60a4ed9..4cce54d1 100644 --- a/maps/dungeons/biome_desert.lua +++ b/maps/dungeons/biome_desert.lua @@ -1,5 +1,5 @@ local Functions = require 'maps.dungeons.functions' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local DungeonsTable = require 'maps.dungeons.table' local table_shuffle_table = table.shuffle_table diff --git a/maps/dungeons/biome_dirtlands.lua b/maps/dungeons/biome_dirtlands.lua index 970a06f3..89319d3b 100644 --- a/maps/dungeons/biome_dirtlands.lua +++ b/maps/dungeons/biome_dirtlands.lua @@ -1,5 +1,5 @@ local Functions = require 'maps.dungeons.functions' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local DungeonsTable = require 'maps.dungeons.table' local table_shuffle_table = table.shuffle_table diff --git a/maps/dungeons/biome_grasslands.lua b/maps/dungeons/biome_grasslands.lua index 568edf28..4ac9e071 100644 --- a/maps/dungeons/biome_grasslands.lua +++ b/maps/dungeons/biome_grasslands.lua @@ -1,5 +1,5 @@ local Functions = require 'maps.dungeons.functions' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local DungeonsTable = require 'maps.dungeons.table' local table_shuffle_table = table.shuffle_table diff --git a/maps/dungeons/biome_rainbow.lua b/maps/dungeons/biome_rainbow.lua index fbcec842..c5effb11 100644 --- a/maps/dungeons/biome_rainbow.lua +++ b/maps/dungeons/biome_rainbow.lua @@ -1,5 +1,5 @@ local Functions = require 'maps.dungeons.functions' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local table_shuffle_table = table.shuffle_table local table_insert = table.insert diff --git a/maps/dungeons/functions.lua b/maps/dungeons/functions.lua index f677e76a..d2ed1c09 100644 --- a/maps/dungeons/functions.lua +++ b/maps/dungeons/functions.lua @@ -9,7 +9,7 @@ local EVOLUTION_PER_FLOOR = 0.06 local BiterRaffle = require 'utils.functions.biter_raffle' local LootRaffle = require 'utils.functions.loot_raffle' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local DungeonsTable = require 'maps.dungeons.table' local table_shuffle_table = table.shuffle_table diff --git a/maps/dungeons/main.lua b/maps/dungeons/main.lua index 3b378c0d..eb5b7fee 100644 --- a/maps/dungeons/main.lua +++ b/maps/dungeons/main.lua @@ -9,7 +9,7 @@ require 'modules.rpg' local BiterHealthBooster = require 'modules.biter_health_booster' local BiterRaffle = require 'utils.functions.biter_raffle' local Functions = require 'maps.dungeons.functions' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local DungeonsTable = require 'maps.dungeons.table' local Biomes = {} diff --git a/maps/dungeons/tiered_dungeon.lua b/maps/dungeons/tiered_dungeon.lua index d699a37b..bdb68604 100644 --- a/maps/dungeons/tiered_dungeon.lua +++ b/maps/dungeons/tiered_dungeon.lua @@ -13,7 +13,7 @@ local RPG = require 'modules.rpg.main' local BiterHealthBooster = require 'modules.biter_health_booster_v2' local BiterRaffle = require 'utils.functions.biter_raffle' local Functions = require 'maps.dungeons.functions' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local Alert = require 'utils.alert' local Research = require 'maps.dungeons.research' local DungeonsTable = require 'maps.dungeons.table' diff --git a/maps/expanse/main.lua b/maps/expanse/main.lua index 212527f9..6b3da960 100644 --- a/maps/expanse/main.lua +++ b/maps/expanse/main.lua @@ -9,7 +9,7 @@ require 'modules.backpack_research' local Event = require 'utils.event' local Functions = require 'maps.expanse.functions' -local GetNoise = require 'utils.get_noise' +local GetNoise = require 'utils.math.get_noise' local Global = require 'utils.global' local Map_info = require 'modules.map_info' local Gui = require 'utils.gui' diff --git a/maps/fish_defender/terrain.lua b/maps/fish_defender/terrain.lua index 12f2f8e6..fa04f4b2 100644 --- a/maps/fish_defender/terrain.lua +++ b/maps/fish_defender/terrain.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Event = require 'utils.event' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local FDT = require 'maps.fish_defender.table' local math_random = math.random local math_abs = math.abs diff --git a/maps/fish_defender_v2/b.lua b/maps/fish_defender_v2/b.lua index a2606a8a..b58e088e 100644 --- a/maps/fish_defender_v2/b.lua +++ b/maps/fish_defender_v2/b.lua @@ -1,4 +1,4 @@ -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 -- local map_data = require 'maps.fish_defender_v2.fish_defender_layout' local map_data = require 'maps.fish_defender_v2.map' local Public = require 'maps.fish_defender_v2.table' diff --git a/maps/fish_defender_v2/terrain.lua b/maps/fish_defender_v2/terrain.lua index 7c410382..c8fb0345 100644 --- a/maps/fish_defender_v2/terrain.lua +++ b/maps/fish_defender_v2/terrain.lua @@ -1,6 +1,6 @@ local Event = require 'utils.event' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Public = require 'maps.fish_defender_v2.table' local Task = require 'utils.task' local Token = require 'utils.token' diff --git a/maps/hedge_maze.lua b/maps/hedge_maze.lua index 309a7357..52931162 100644 --- a/maps/hedge_maze.lua +++ b/maps/hedge_maze.lua @@ -8,7 +8,7 @@ require 'modules.spawners_contain_biters' local event = require 'utils.event' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local math_random = math.random local labyrinth_cell_size = 16 --valid values are 2, 4, 8, 16, 32 diff --git a/maps/island_troopers/terrain.lua b/maps/island_troopers/terrain.lua index c4a8b2ed..2d16f50d 100644 --- a/maps/island_troopers/terrain.lua +++ b/maps/island_troopers/terrain.lua @@ -1,6 +1,6 @@ --luacheck: ignore local math_random = math.random -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local NoiseVectors = require 'utils.functions.noise_vector_path' local Enemies = require 'maps.island_troopers.enemies' local ShoppingChests = require 'modules.shopping_chests' diff --git a/maps/journey/functions.lua b/maps/journey/functions.lua index 76b3230e..cc0fa633 100644 --- a/maps/journey/functions.lua +++ b/maps/journey/functions.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Map_functions = require 'utils.tools.map_functions' local Server = require 'utils.server' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local Autostash = require 'modules.autostash' local Misc = require 'utils.commands.misc' local BottomFrame = require 'utils.gui.bottom_frame' diff --git a/maps/journey/unique_modifiers.lua b/maps/journey/unique_modifiers.lua index 79840237..9553fdd3 100644 --- a/maps/journey/unique_modifiers.lua +++ b/maps/journey/unique_modifiers.lua @@ -1,5 +1,5 @@ --luacheck: ignore 212/journey -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local BiterRaffle = require 'utils.functions.biter_raffle' local LootRaffle = require 'utils.functions.loot_raffle' local math_random = math.random diff --git a/maps/junkyard.lua b/maps/junkyard.lua index dee813d3..43c2dc25 100644 --- a/maps/junkyard.lua +++ b/maps/junkyard.lua @@ -19,7 +19,7 @@ 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' +local simplex_noise = require 'utils.math.simplex_noise' simplex_noise = simplex_noise.d2 local event = require 'utils.event' local table_insert = table.insert diff --git a/maps/junkyard_pvp/terrain.lua b/maps/junkyard_pvp/terrain.lua index 1b48f4c0..1aab169a 100644 --- a/maps/junkyard_pvp/terrain.lua +++ b/maps/junkyard_pvp/terrain.lua @@ -4,7 +4,7 @@ local math_random = math.random local math_floor = math.floor local Treasure = require 'maps.junkyard_pvp.treasure' local Map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local rock_raffle = { 'big-sand-rock', 'big-sand-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'huge-rock' } local spawner_raffle = { 'biter-spawner', 'biter-spawner', 'biter-spawner', 'spitter-spawner' } local noises = { diff --git a/maps/labyrinth.lua b/maps/labyrinth.lua index 23cee9f6..84c9d905 100644 --- a/maps/labyrinth.lua +++ b/maps/labyrinth.lua @@ -9,7 +9,7 @@ local Event = require 'utils.event' local Server = require 'utils.server' local Global = require 'utils.global' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Score = require 'utils.gui.score' local unique_rooms = require 'maps.labyrinth_unique_rooms' local SoftReset = require 'utils.functions.soft_reset' diff --git a/maps/lost.lua b/maps/lost.lua index 5a4d910c..3f36c1d7 100644 --- a/maps/lost.lua +++ b/maps/lost.lua @@ -8,7 +8,7 @@ require 'modules.spawners_contain_biters' local event = require 'utils.event' local table_insert = table.insert local math_random = math.random -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local disabled_for_deconstruction = { ['fish'] = true, diff --git a/maps/lost_desert.lua b/maps/lost_desert.lua index 643e34d3..5502aef5 100644 --- a/maps/lost_desert.lua +++ b/maps/lost_desert.lua @@ -10,7 +10,7 @@ require 'modules.spawners_contain_acid' require 'modules.satellite_score' require 'modules.flashlight_toggle_button' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local event = require 'utils.event' local map_functions = require 'utils.tools.map_functions' local math_random = math.random diff --git a/maps/minesweeper/functions.lua b/maps/minesweeper/functions.lua index cff32211..23dafdeb 100644 --- a/maps/minesweeper/functions.lua +++ b/maps/minesweeper/functions.lua @@ -2,7 +2,7 @@ local Public = {} local LootRaffle = require "utils.functions.loot_raffle" -local Get_noise = require "utils.get_noise" +local Get_noise = require "utils.math.get_noise" local safe_zone_radius = 16 diff --git a/maps/mountain_fortress.lua b/maps/mountain_fortress.lua index 3753248f..3ada2dc4 100644 --- a/maps/mountain_fortress.lua +++ b/maps/mountain_fortress.lua @@ -19,7 +19,7 @@ local event = require 'utils.event' local math_random = math.random local insert = table.insert local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' local simplex_noise = simplex_noise.d2 local spawn_point = { x = 0, y = 2 } diff --git a/maps/mountain_fortress_v2/collapse.lua b/maps/mountain_fortress_v2/collapse.lua index 18f67d13..198a80b8 100644 --- a/maps/mountain_fortress_v2/collapse.lua +++ b/maps/mountain_fortress_v2/collapse.lua @@ -1,6 +1,6 @@ --luacheck: ignore local Public = {} -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local math_random = math.random local math_abs = math.abs local math_sqrt = math.sqrt diff --git a/maps/mountain_fortress_v2/terrain.lua b/maps/mountain_fortress_v2/terrain.lua index f47d2259..f229f248 100644 --- a/maps/mountain_fortress_v2/terrain.lua +++ b/maps/mountain_fortress_v2/terrain.lua @@ -6,7 +6,7 @@ local Market = require 'utils.functions.basic_markets' local math_random = math.random local math_floor = math.floor local math_abs = math.abs -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local rock_raffle = { 'big-sand-rock', 'big-sand-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'big-rock', 'huge-rock' } local wagon_raffle = { 'cargo-wagon', 'cargo-wagon', 'cargo-wagon', 'locomotive', 'fluid-wagon' } local size_of_rock_raffle = #rock_raffle diff --git a/maps/mountain_fortress_v3/get_perlin.lua b/maps/mountain_fortress_v3/get_perlin.lua index b7d5e961..20a4c514 100644 --- a/maps/mountain_fortress_v3/get_perlin.lua +++ b/maps/mountain_fortress_v3/get_perlin.lua @@ -1,5 +1,5 @@ local Public = require 'maps.mountain_fortress_v3.table' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 --add or use noise templates from here local noises = { diff --git a/maps/mountain_race/terrain.lua b/maps/mountain_race/terrain.lua index 63252164..afde5a7a 100644 --- a/maps/mountain_race/terrain.lua +++ b/maps/mountain_race/terrain.lua @@ -2,7 +2,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 GetNoise = require 'utils.math.get_noise' local LootRaffle = require 'utils.functions.loot_raffle' local wagon_raffle = { 'cargo-wagon', 'cargo-wagon', 'cargo-wagon', 'locomotive', 'fluid-wagon' } diff --git a/maps/native_war/terrain.lua b/maps/native_war/terrain.lua index 98e73c94..019cc6d4 100644 --- a/maps/native_war/terrain.lua +++ b/maps/native_war/terrain.lua @@ -2,7 +2,7 @@ local math_abs = math.abs local math_random = math.random local Map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Public = {} local hatchery_position = { x = 200, y = 0 } diff --git a/maps/nightfall.lua b/maps/nightfall.lua index a834c19f..96d9ae8b 100644 --- a/maps/nightfall.lua +++ b/maps/nightfall.lua @@ -5,7 +5,7 @@ local event = require 'utils.event' local math_random = math.random local insert = table.insert local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' local simplex_noise = simplex_noise.d2 require 'maps.nightfall_map_intro' require 'modules.splice_double' diff --git a/maps/pirates/ai.lua b/maps/pirates/ai.lua index eee437ba..80b228b1 100644 --- a/maps/pirates/ai.lua +++ b/maps/pirates/ai.lua @@ -5,9 +5,9 @@ local Balance = require('maps.pirates.balance') local Common = require('maps.pirates.common') local CoreData = require('maps.pirates.coredata') -- local Utils = require 'maps.pirates.utils_local' -local Math = require('maps.pirates.math') -local Raffle = require('maps.pirates.raffle') -local _inspect = require('utils.inspect').inspect +local Math = require 'maps.pirates.math' +local Raffle = require 'utils.math.raffle' +local _inspect = require 'utils.inspect'.inspect -- local Structures = require 'maps.pirates.structures.structures' local Boats = require('maps.pirates.structures.boats.boats') diff --git a/maps/pirates/commands.lua b/maps/pirates/commands.lua index 9c5a0246..88df7ccd 100644 --- a/maps/pirates/commands.lua +++ b/maps/pirates/commands.lua @@ -25,7 +25,7 @@ local Upgrades = require('maps.pirates.shop.boat_upgrades') local Effects = require('maps.pirates.effects') local Kraken = require('maps.pirates.surfaces.sea.kraken') local _inspect = require('utils.inspect').inspect -local simplex_noise = require('utils.simplex_noise').d2 +local simplex_noise = require('utils.math.simplex_noise').d2 local Token = require('utils.token') local Task = require('utils.task') local Highscore = require('maps.pirates.highscore') diff --git a/maps/pirates/common.lua b/maps/pirates/common.lua index 981d73b0..853fe70b 100644 --- a/maps/pirates/common.lua +++ b/maps/pirates/common.lua @@ -1,18 +1,18 @@ -- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/ComfyFactory/ComfyFactorio and https://github.com/danielmartin0/ComfyFactorio-Pirates. -local Math = require('maps.pirates.math') -local Raffle = require('maps.pirates.raffle') -local Server = require('utils.server') -local Utils = require('maps.pirates.utils_local') -local CoreData = require('maps.pirates.coredata') -local Memory = require('maps.pirates.memory') -local _inspect = require('utils.inspect').inspect +local Math = require 'maps.pirates.math' +local Raffle = require 'utils.math.raffle' +local Server = require 'utils.server' +local Utils = require 'maps.pirates.utils_local' +local CoreData = require 'maps.pirates.coredata' +local Memory = require 'maps.pirates.memory' +local _inspect = require 'utils.inspect'.inspect -- local IslandEnum = require 'maps.pirates.surfaces.islands.island_enum' -local LootRaffle = require('utils.functions.loot_raffle') --- local simplex_noise = require 'utils.simplex_noise'.d2 --- local perlin_noise = require 'utils.perlin_noise' +local LootRaffle = require 'utils.functions.loot_raffle' +-- local simplex_noise = require 'utils.math.simplex_noise'.d2 +-- local perlin_noise = require 'utils.math.perlin_noise' -- local Force_health_booster = require 'modules.force_health_booster' -- == Common variables and functions used throughout pirate ship files diff --git a/maps/pirates/ores.lua b/maps/pirates/ores.lua index 1d938d1a..0e793edf 100644 --- a/maps/pirates/ores.lua +++ b/maps/pirates/ores.lua @@ -3,12 +3,12 @@ local Balance = require('maps.pirates.balance') -- local Memory = require 'maps.pirates.memory' local Math = require('maps.pirates.math') -local Raffle = require('maps.pirates.raffle') +local Raffle = require 'utils.math.raffle' local CoreData = require('maps.pirates.coredata') local _inspect = require('utils.inspect').inspect local Common = require('maps.pirates.common') local Utils = require('maps.pirates.utils_local') -local simplex_noise = require('utils.simplex_noise').d2 +local simplex_noise = require('utils.math.simplex_noise').d2 -- local Public = {} @@ -42,7 +42,7 @@ function Public.try_give_ore(player, realp, source_name) if Utils.length(choices_to_prioitise) > 0 then choice = choices_to_prioitise[Math.random(Utils.length(choices_to_prioitise))] else - choice = Raffle.raffle2(choices_possible) + choice = Raffle.raffle(choices_possible) end if not choice then @@ -104,7 +104,7 @@ function Public.try_ore_spawn(surface, realp, source_name, density_bonus, from_t if Utils.length(choices_to_prioitise) > 0 then choice = choices_to_prioitise[Math.random(Utils.length(choices_to_prioitise))] else - choice = Raffle.raffle2(choices_possible) + choice = Raffle.raffle(choices_possible) end local placed diff --git a/maps/pirates/quest.lua b/maps/pirates/quest.lua index 12aea264..a6ada31a 100644 --- a/maps/pirates/quest.lua +++ b/maps/pirates/quest.lua @@ -5,8 +5,8 @@ local Memory = require('maps.pirates.memory') local Balance = require('maps.pirates.balance') local Common = require('maps.pirates.common') -- local Utils = require 'maps.pirates.utils_local' -local Math = require('maps.pirates.math') -local Raffle = require('maps.pirates.raffle') +local Math = require 'maps.pirates.math' +local Raffle = require 'utils.math.raffle' -- local Loot = require 'maps.pirates.loot' -- local CoreData = require 'maps.pirates.coredata' local IslandEnum = require('maps.pirates.surfaces.islands.island_enum') diff --git a/maps/pirates/raffle.lua b/maps/pirates/raffle.lua deleted file mode 100644 index ca6da3ed..00000000 --- a/maps/pirates/raffle.lua +++ /dev/null @@ -1,180 +0,0 @@ --- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/ComfyFactory/ComfyFactorio and https://github.com/danielmartin0/ComfyFactorio-Pirates. - -local Math = require('maps.pirates.math') - -local Public = {} - --- Returns random value from values, with given probability weights. Both table parameters are expected to be arrays. --- NOTE: This function: --- - MAY return random equally distributed item from "values" when there is at least 1 weight <= 0 and --- - WILL with all weights <= 0 -function Public.raffle(values, weights) --arguments of the form {[a] = A, [b] = B, ...} and {[a] = a_weight, [b] = b_weight, ...} or just {a,b,c,...} and {1,2,3...} - local total_weight = 0 - for k, w in pairs(weights) do - assert(values[k]) - if w > 0 then - total_weight = total_weight + w - end - -- negative weights treated as zero - end - - -- Fallback case - if total_weight <= 0 then - local index = Math.random(1, table_size(values)) - return values[index] - end - - local cumulative_probability = 0 - local rng = Math.random() - for k, v in pairs(values) do - assert(weights[k]) - cumulative_probability = cumulative_probability + (weights[k] / total_weight) - if rng <= cumulative_probability then - return v - end - end - - -- Fallback case - local index = Math.random(1, table_size(values)) - return values[index] -end - --- Returns random key from table, with given probability values. Works with all types of keys. --- NOTE: This function: --- - MAY return random equally distributed item from "values" when there is at least 1 weight <= 0 and --- - WILL with all weights <= 0 -function Public.raffle2(table) --arguments of the form {v1 = w1, v2 = w2, ...} - local total_weight = 0 - for _, w in pairs(table) do - if w > 0 then - total_weight = total_weight + w - end - -- negative weights treated as zero - end - - -- Fallback case - if total_weight <= 0 then - local index = Math.random(1, table_size(table)) - for k, _ in pairs(table) do - if index == 1 then - return k - end - - index = index - 1 - end - end - - local cumulative_probability = 0 - local rng = Math.random() - for k, w in pairs(table) do - cumulative_probability = cumulative_probability + w / total_weight - if rng <= cumulative_probability then - return k - end - end - - -- Fallback case - local index = Math.random(1, table_size(table)) - for k, _ in pairs(table) do - if index == 1 then - return k - end - - index = index - 1 - end -end - ---==thesixthroc's Lambda Raffles - --- This file provides a one-parameter family of raffles called 'Lambda raffles'. When you want to roll the raffle, you also provide a parameter 'lambda', and the raffle weights vary with lambda in a specified way. For example, the parameter could be the game completion progress, and the raffle could produce certain items only in the late game. - -function Public.LambdaRaffle(data, lambda, extraConditionParameter) - -- example_argument = { - -- ['iron-stick'] = { - -- overallWeight = 1, - -- minLambda = 0, - -- maxLambda = 0.5, - -- shape = 'uniform', -- a uniform raffle weight of 1, if lambda is between 0 and 1 - -- }, - -- ['coal'] = { - -- overallWeight = 3, - -- minLambda = 0, - -- maxLambda = 0.5, - -- shape = 'density', -- a uniform raffle weight of 6, if lambda is between 0 and 1 - -- }, - -- ['copper-wire'] = { - -- overallWeight = 1, - -- minLambda = 0, - -- maxLambda = 1, - -- shape = 'bump', -- the raffle weight is a ⋀ shape, going from (0, 0) to (0.5, 2) to (1, 0) - -- condition = function(x) return x == 'copperIsland' end, --this optional key performs a check on extraConditionParameter to see whether this raffle value should be included at all - -- }, - -- } - local raffle = {} - - for k, v in pairs(data) do - if (not v.shape) or (v.shape == 'uniform' or v.shape == 'flat') then - if (not v.minLambda) or (lambda >= v.minLambda) then - if (not v.maxLambda) or (lambda <= v.maxLambda) then - if (not v.condition) or (extraConditionParameter and v.condition(extraConditionParameter)) then - raffle[k] = v.overallWeight - end - end - end - elseif v.shape == 'density' then - if - v.minLambda - and v.maxLambda - and v.maxLambda ~= v.minLambda - and lambda >= v.minLambda - and lambda <= v.maxLambda - then - if (not v.condition) or (extraConditionParameter and v.condition(extraConditionParameter)) then - raffle[k] = v.overallWeight / (v.maxLambda - v.minLambda) - end - end - elseif v.shape == 'bump' then - if v.minLambda and v.maxLambda and lambda >= v.minLambda and lambda <= v.maxLambda then - if (not v.condition) or (extraConditionParameter and v.condition(extraConditionParameter)) then - if v.minLambda == v.maxLambda and lambda == v.minLambda then - raffle[k] = v.overallWeight - else - local midpoint = (v.minLambda + v.maxLambda) / 2 - local peak = 2 * v.overallWeight - local slope = peak / ((v.maxLambda - v.minLambda) / 2) - local difference = Math.abs(lambda - midpoint) - raffle[k] = peak * (1 - difference * slope) - end - end - end - end - end - - return Public.raffle2(raffle) -end - --- a function that accepts more abbreviated raffle data: -function Public.LambdaRaffleFromAbbreviatedData(abbreviatedData, lambda, extraConditionParameter) - -- example_argument = { - -- ['iron-stick'] = { - -- 1, 0, 1, 'uniform' - -- }, - -- ['copper-plate'] = { - -- 1, 0, 1, 'uniform', function(x) return x == 'copperIsland' end - -- }, - -- } - - local data = {} - for k, v in pairs(abbreviatedData) do - data[k] = { - overallWeight = v[1], - minLambda = v[2], - maxLambda = v[3], - shape = v[4], - condition = v[4], - } - end - return Public.LambdaRaffle(data, lambda, extraConditionParameter) -end - -return Public diff --git a/maps/pirates/structures/quest_structures/furnace1/furnace1.lua b/maps/pirates/structures/quest_structures/furnace1/furnace1.lua index 661c772b..6f7f1f3f 100644 --- a/maps/pirates/structures/quest_structures/furnace1/furnace1.lua +++ b/maps/pirates/structures/quest_structures/furnace1/furnace1.lua @@ -9,10 +9,11 @@ local Common = require('maps.pirates.common') local _inspect = require('utils.inspect').inspect -- -- local SurfacesCommon = require 'maps.pirates.surfaces.common' -local Raffle = require('maps.pirates.raffle') -local ShopCovered = require('maps.pirates.shop.covered') -local Classes = require('maps.pirates.roles.classes') -local Loot = require('maps.pirates.loot') +local Raffle = require 'utils.math.raffle' +local ShopCovered = require 'maps.pirates.shop.covered' +local Classes = require 'maps.pirates.roles.classes' +local Loot = require 'maps.pirates.loot' + local Public = {} Public.Data = require('maps.pirates.structures.quest_structures.furnace1.data') @@ -206,9 +207,9 @@ end Public.entry_price_data_raw = { -- choose things which make interesting minifactories ['electric-mining-drill'] = { - overallWeight = 1, - minLambda = -0.1, - maxLambda = 0.6, + overall_weight = 1, + min_param = -0.1, + max_param = 0.6, shape = 'bump', enabled = true, base_amount = 600, @@ -216,9 +217,9 @@ Public.entry_price_data_raw = { -- choose things which make interesting minifact batchRawMaterials = { ['iron-plate'] = 46, ['copper-plate'] = 9 }, }, ['fast-splitter'] = { - overallWeight = 1, - minLambda = 0.1, - maxLambda = 0.6, + overall_weight = 1, + min_param = 0.1, + max_param = 0.6, shape = 'bump', enabled = true, base_amount = 300, @@ -226,9 +227,9 @@ Public.entry_price_data_raw = { -- choose things which make interesting minifact batchRawMaterials = { ['iron-plate'] = 92, ['copper-plate'] = 45 }, }, ['assembling-machine-1'] = { - overallWeight = 1, - minLambda = -0.2, - maxLambda = 0.6, + overall_weight = 1, + min_param = -0.2, + max_param = 0.6, shape = 'bump', enabled = true, base_amount = 600, @@ -236,39 +237,36 @@ Public.entry_price_data_raw = { -- choose things which make interesting minifact batchRawMaterials = { ['iron-plate'] = 44, ['copper-plate'] = 9 }, }, ['programmable-speaker'] = { - overallWeight = 1, - minLambda = 0.1, - maxLambda = 0.7, - shape = 'density', + overall_weight = 1.67, + min_param = 0.1, + max_param = 0.7, enabled = true, base_amount = 450, itemBatchSize = 2, batchRawMaterials = { ['iron-plate'] = 18, ['copper-plate'] = 17 }, }, ['pump'] = { - overallWeight = 1, - minLambda = 0.2, - maxLambda = 0.9, - shape = 'density', + overall_weight = 1.25, + min_param = 0.2, + max_param = 0.9, enabled = true, base_amount = 250, itemBatchSize = 1, batchRawMaterials = { ['iron-plate'] = 15 }, }, ['grenade'] = { - overallWeight = 1, - minLambda = 0.1, - maxLambda = 0.7, - shape = 'density', + overall_weight = 1.1, + min_param = 0.1, + max_param = 0.7, enabled = true, base_amount = 500, itemBatchSize = 1, batchRawMaterials = { ['iron-plate'] = 5, ['coal'] = 10 }, }, ['assembling-machine-2'] = { - overallWeight = 1, - minLambda = 0.3, - maxLambda = 1.5, + overall_weight = 1, + min_param = 0.3, + max_param = 1.5, shape = 'bump', enabled = true, base_amount = 200, @@ -276,90 +274,72 @@ Public.entry_price_data_raw = { -- choose things which make interesting minifact batchRawMaterials = { ['iron-plate'] = 160, ['copper-plate'] = 18 }, }, ['pumpjack'] = { - overallWeight = 1, - minLambda = 0.4, - maxLambda = 1.5, - shape = 'density', + overall_weight = 1.7, + min_param = 0.4, + max_param = 1.5, enabled = true, base_amount = 120, itemBatchSize = 2, batchRawMaterials = { ['iron-plate'] = 120, ['copper-plate'] = 15 }, }, ['oil-refinery'] = { - overallWeight = 1, - minLambda = 0.4, - maxLambda = 2, - shape = 'density', + overall_weight = 1.7, + min_param = 0.4, + max_param = 2, enabled = true, base_amount = 70, itemBatchSize = 1, batchRawMaterials = { ['iron-plate'] = 115, ['copper-plate'] = 15, ['stone-brick'] = 10 }, }, ['chemical-plant'] = { - overallWeight = 1, - minLambda = 0.4, - maxLambda = 1.5, - shape = 'density', + overall_weight = 1.7, + min_param = 0.4, + max_param = 1.5, enabled = true, base_amount = 150, itemBatchSize = 2, batchRawMaterials = { ['iron-plate'] = 90, ['copper-plate'] = 15 }, }, ['solar-panel'] = { - overallWeight = 1, - minLambda = 0.3, - maxLambda = 1.2, - shape = 'density', + overall_weight = 1.43, + min_param = 0.3, + max_param = 1.2, enabled = true, base_amount = 150, itemBatchSize = 2, batchRawMaterials = { ['iron-plate'] = 80, ['copper-plate'] = 55 }, }, - -- ['land-mine'] = { - -- overallWeight = 1, - -- minLambda = 0.4, - -- maxLambda = 1.5, - -- shape = 'density', - -- enabled = true, - -- base_amount = 1000, - -- itemBatchSize = 4, - -- batchRawMaterials = {['iron-plate'] = 5, ['coal'] = 1, ['sulfur'] = 1}, - -- }, ['cluster-grenade'] = { - overallWeight = 1, - minLambda = 0.6, - maxLambda = 2, - shape = 'density', + overall_weight = 2.5, + min_param = 0.6, + max_param = 2, enabled = true, base_amount = 120, itemBatchSize = 2, batchRawMaterials = { ['iron-plate'] = 120, ['coal'] = 145, ['sulfur'] = 5 }, }, ['car'] = { - overallWeight = 1, - minLambda = 0.4, - maxLambda = 1.5, - shape = 'density', + overall_weight = 1.67, + min_param = 0.4, + max_param = 1.5, enabled = true, base_amount = 90, itemBatchSize = 1, batchRawMaterials = { ['iron-plate'] = 117 }, }, ['defender-capsule'] = { - overallWeight = 1, - minLambda = 0.4, - maxLambda = 1.5, - shape = 'density', + overall_weight = 1.67, + min_param = 0.4, + max_param = 1.5, enabled = true, base_amount = 150, itemBatchSize = 2, batchRawMaterials = { ['iron-plate'] = 72, ['copper-plate'] = 39 }, }, ['express-transport-belt'] = { - overallWeight = 1, - minLambda = 0.6, - maxLambda = 1.5, - shape = 'density', + overall_weight = 2.5, + min_param = 0.6, + max_param = 1.5, enabled = true, base_amount = 150, itemBatchSize = 10, @@ -370,7 +350,7 @@ Public.entry_price_data_raw = { -- choose things which make interesting minifact function Public.entry_price() local lambda = Math.clamp(0, 1, Math.sloped(Common.difficulty_scale(), 0.4) * Common.game_completion_progress()) - local item = Raffle.LambdaRaffle(Public.entry_price_data_raw, lambda) + local item = Raffle.raffle_with_parameter(lambda, Public.entry_price_data_raw) if not item then item = Common.get_random_dictionary_entry(Public.entry_price_data_raw, true) diff --git a/maps/pirates/structures/quest_structures/market1/market1.lua b/maps/pirates/structures/quest_structures/market1/market1.lua index ab169efe..82496836 100644 --- a/maps/pirates/structures/quest_structures/market1/market1.lua +++ b/maps/pirates/structures/quest_structures/market1/market1.lua @@ -9,10 +9,10 @@ local Common = require('maps.pirates.common') local _inspect = require('utils.inspect').inspect -- -- local SurfacesCommon = require 'maps.pirates.surfaces.common' -local Raffle = require('maps.pirates.raffle') -local ShopCovered = require('maps.pirates.shop.covered') -local Classes = require('maps.pirates.roles.classes') -local Loot = require('maps.pirates.loot') +local Raffle = require 'utils.math.raffle' +local ShopCovered = require 'maps.pirates.shop.covered' +local Classes = require 'maps.pirates.roles.classes' +local Loot = require 'maps.pirates.loot' local Public = {} Public.Data = require('maps.pirates.structures.quest_structures.market1.data') @@ -213,145 +213,145 @@ Public.entry_price_data_raw = { -- choose things that are easy to make at outposts -- if the prices are too high, players will accidentally throw too much in when they can't do it ['iron-stick'] = { - overallWeight = 1, - minLambda = 0, - maxLambda = 0.4, + overall_weight = 1, + min_param = 0, + max_param = 0.4, shape = false, base_amount = 1500, raw_materials = { { name = 'iron-plate', count = 750 } }, }, ['copper-cable'] = { - overallWeight = 0.85, - minLambda = 0, - maxLambda = 0.4, + overall_weight = 0.85, + min_param = 0, + max_param = 0.4, shape = false, base_amount = 1500, raw_materials = { { name = 'copper-plate', count = 750 } }, }, ['small-electric-pole'] = { - overallWeight = 1, - minLambda = 0, - maxLambda = 0.3, + overall_weight = 1, + min_param = 0, + max_param = 0.3, shape = false, base_amount = 450, raw_materials = { { name = 'copper-plate', count = 900 } }, }, ['assembling-machine-1'] = { - overallWeight = 1, - minLambda = 0.1, - maxLambda = 0.6, + overall_weight = 1, + min_param = 0.1, + max_param = 0.6, shape = false, base_amount = 80, raw_materials = { { name = 'iron-plate', count = 1760 }, { name = 'copper-plate', count = 360 } }, }, ['burner-mining-drill'] = { - overallWeight = 0.25, - minLambda = 0.1, - maxLambda = 0.4, + overall_weight = 0.25, + min_param = 0.1, + max_param = 0.4, shape = false, base_amount = 150, raw_materials = { { name = 'iron-plate', count = 1350 } }, }, ['burner-inserter'] = { - overallWeight = 0.75, - minLambda = 0, - maxLambda = 0.3, + overall_weight = 0.75, + min_param = 0, + max_param = 0.3, shape = false, base_amount = 300, raw_materials = { { name = 'iron-plate', count = 900 } }, }, ['small-lamp'] = { - overallWeight = 1, - minLambda = 0.05, - maxLambda = 0.4, + overall_weight = 1, + min_param = 0.05, + max_param = 0.4, shape = false, base_amount = 300, raw_materials = { { name = 'iron-plate', count = 600 }, { name = 'copper-plate', count = 900 } }, }, ['firearm-magazine'] = { - overallWeight = 1, - minLambda = 0, - maxLambda = 0.4, + overall_weight = 1, + min_param = 0, + max_param = 0.4, shape = false, base_amount = 700, raw_materials = { { name = 'iron-plate', count = 2800 } }, }, ['constant-combinator'] = { - overallWeight = 0.6, - minLambda = 0, - maxLambda = 0.4, + overall_weight = 0.6, + min_param = 0, + max_param = 0.4, shape = false, base_amount = 276, raw_materials = { { name = 'iron-plate', count = 552 }, { name = 'copper-plate', count = 1518 } }, }, ['stone-furnace'] = { - overallWeight = 1, - minLambda = 0, - maxLambda = 0.4, + overall_weight = 1, + min_param = 0, + max_param = 0.4, shape = false, base_amount = 250, raw_materials = { { name = 'stone', count = 1250 } }, }, ['wooden-chest'] = { - overallWeight = 0.5, - minLambda = 0, - maxLambda = 0.4, + overall_weight = 0.5, + min_param = 0, + max_param = 0.4, shape = false, base_amount = 400, raw_materials = {}, }, ['iron-chest'] = { - overallWeight = 0.5, - minLambda = 0.1, - maxLambda = 0.5, + overall_weight = 0.5, + min_param = 0.1, + max_param = 0.5, shape = false, base_amount = 250, raw_materials = { { name = 'iron-plate', count = 2000 } }, }, ['steel-chest'] = { - overallWeight = 0.5, - minLambda = 0.2, - maxLambda = 1, + overall_weight = 0.5, + min_param = 0.2, + max_param = 1, shape = false, base_amount = 125, raw_materials = { { name = 'steel-plate', count = 1000 } }, }, ['rail'] = { - overallWeight = 1, - minLambda = 0.2, - maxLambda = 1, + overall_weight = 1, + min_param = 0.2, + max_param = 1, shape = false, base_amount = 400, raw_materials = { { name = 'iron-plate', count = 1100 } }, }, ['plastic-bar'] = { - overallWeight = 1, - minLambda = 0.3, - maxLambda = 1, + overall_weight = 1, + min_param = 0.3, + max_param = 1, shape = false, base_amount = 400, raw_materials = { { name = 'coal', count = 200 }, { name = 'petroleum-gas-barrel', count = 80 } }, }, ['sulfur'] = { - overallWeight = 1, - minLambda = 0.3, - maxLambda = 1, + overall_weight = 1, + min_param = 0.3, + max_param = 1, shape = false, base_amount = 400, raw_materials = { { name = 'petroleum-gas-barrel', count = 120 } }, }, ['electronic-circuit'] = { - overallWeight = 1, - minLambda = 0.1, - maxLambda = 0.5, + overall_weight = 1, + min_param = 0.1, + max_param = 0.5, shape = false, base_amount = 700, raw_materials = { { name = 'iron-plate', count = 700 }, { name = 'copper-plate', count = 1050 } }, }, ['advanced-circuit'] = { - overallWeight = 1, - minLambda = 0.4, - maxLambda = 1, + overall_weight = 1, + min_param = 0.4, + max_param = 1, shape = false, base_amount = 180, raw_materials = { @@ -365,7 +365,7 @@ Public.entry_price_data_raw = { function Public.entry_price() local lambda = Math.clamp(0, 1, Math.sloped(Common.difficulty_scale(), 0.4) * Common.game_completion_progress()) - local item = Raffle.LambdaRaffle(Public.entry_price_data_raw, lambda) + local item = Raffle.raffle_with_parameter(lambda, Public.entry_price_data_raw) if not item then item = Common.get_random_dictionary_entry(Public.entry_price_data_raw, true) diff --git a/maps/pirates/surfaces/islands/cave/cave_source.lua b/maps/pirates/surfaces/islands/cave/cave_source.lua index eb52c257..51426625 100644 --- a/maps/pirates/surfaces/islands/cave/cave_source.lua +++ b/maps/pirates/surfaces/islands/cave/cave_source.lua @@ -4,7 +4,7 @@ local Memory = require('maps.pirates.memory') local Math = require('maps.pirates.math') local Common = require('maps.pirates.common') local IslandsCommon = require('maps.pirates.surfaces.islands.common') -local GetNoise = require('utils.get_noise') +local GetNoise = require('utils.math.get_noise') local BoatData = require('maps.pirates.structures.boats.sloop.data') local Balance = require('maps.pirates.balance') local ShopCovered = require('maps.pirates.shop.covered') diff --git a/maps/pirates/surfaces/islands/maze/maze.lua b/maps/pirates/surfaces/islands/maze/maze.lua index 1cfd2073..6fcd1cfd 100644 --- a/maps/pirates/surfaces/islands/maze/maze.lua +++ b/maps/pirates/surfaces/islands/maze/maze.lua @@ -1,8 +1,8 @@ -- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/ComfyFactory/ComfyFactorio and https://github.com/danielmartin0/ComfyFactorio-Pirates. -- local Memory = require 'maps.pirates.memory' -local Math = require('maps.pirates.math') -local Raffle = require('maps.pirates.raffle') +local Math = require 'maps.pirates.math' +local Raffle = require 'utils.math.raffle' -- local Balance = require 'maps.pirates.balance' local Structures = require('maps.pirates.structures.structures') -- local Common = require 'maps.pirates.common' @@ -193,7 +193,7 @@ local function free_labyrinth_cell_type(args) end if not type then - type = Raffle.raffle2(free_labyrinth_cell_raffle) + type = Raffle.raffle(free_labyrinth_cell_raffle) cell_types[tostring(reduced_p.x) .. '_' .. tostring(reduced_p.y)] = type end diff --git a/maps/pirates/utils_local.lua b/maps/pirates/utils_local.lua index 08e22da5..c288491d 100644 --- a/maps/pirates/utils_local.lua +++ b/maps/pirates/utils_local.lua @@ -2,8 +2,8 @@ local Math = require('maps.pirates.math') -- local _inspect = require 'utils.inspect'.inspect -local simplex_noise = require('utils.simplex_noise').d2 --rms ~ 0.1925 --- local perlin_noise = require 'utils.perlin_noise' +local simplex_noise = require('utils.math.simplex_noise').d2 --rms ~ 0.1925 +-- local perlin_noise = require 'utils.math.perlin_noise' -- local Memory = require 'maps.pirates.memory' -- local CoreData = require 'maps.pirates.coredata' local NoisePregen = require('maps.pirates.noise_pregen.noise_pregen') diff --git a/maps/pitch_black/blood_moon.lua b/maps/pitch_black/blood_moon.lua index ebaa213c..b7a62d58 100644 --- a/maps/pitch_black/blood_moon.lua +++ b/maps/pitch_black/blood_moon.lua @@ -1,6 +1,6 @@ local Public = {} -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local math_abs = math.abs local math_round = math.round diff --git a/maps/quarters.lua b/maps/quarters.lua index 6ee8db21..70a793d4 100644 --- a/maps/quarters.lua +++ b/maps/quarters.lua @@ -3,7 +3,7 @@ require 'modules.mineable_wreckage_yields_scrap' require 'modules.wave_defense.main' local Map = require 'modules.map_info' local WD = require 'modules.wave_defense.table' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local spawn_size = 96 local wall_thickness = 3 local small_scraps = { diff --git a/maps/railway_troopers_v2/main.lua b/maps/railway_troopers_v2/main.lua index 5502b49a..0552f369 100644 --- a/maps/railway_troopers_v2/main.lua +++ b/maps/railway_troopers_v2/main.lua @@ -12,7 +12,7 @@ local difficulties_votes = { [7] = 1 } -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local Immersive_cargo_wagons = require 'modules.immersive_cargo_wagons.main' local LootRaffle = require 'utils.functions.loot_raffle' diff --git a/maps/rainbow_road.lua b/maps/rainbow_road.lua index 012c681d..9ca8adb5 100644 --- a/maps/rainbow_road.lua +++ b/maps/rainbow_road.lua @@ -1,6 +1,6 @@ --luacheck: ignore local event = require 'utils.event' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local rainbow_colors = require 'utils.tools.rainbow_colors' local map_functions = require 'utils.tools.map_functions' require 'modules.satellite_score' diff --git a/maps/rivers.lua b/maps/rivers.lua index e1e8d928..22828a78 100644 --- a/maps/rivers.lua +++ b/maps/rivers.lua @@ -9,7 +9,7 @@ require 'modules.rocks_yield_ore' local event = require 'utils.event' local table_insert = table.insert local math_random = math.random -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local map_functions = require 'utils.tools.map_functions' local disabled_for_deconstruction = { diff --git a/maps/rocky_waste.lua b/maps/rocky_waste.lua index 86b2b63f..cec1205c 100644 --- a/maps/rocky_waste.lua +++ b/maps/rocky_waste.lua @@ -1,6 +1,6 @@ --luacheck: ignore local event = require 'utils.event' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 require 'modules.satellite_score' require 'modules.biter_noms_you' require 'modules.dangerous_goods' diff --git a/maps/scrap_railworld.lua b/maps/scrap_railworld.lua index 4228e017..b004100c 100644 --- a/maps/scrap_railworld.lua +++ b/maps/scrap_railworld.lua @@ -3,7 +3,7 @@ require 'modules.satellite_score' require 'modules.mineable_wreckage_yields_scrap' local LootRaffle = require 'utils.functions.loot_raffle' -local Get_noise = require 'utils.get_noise' +local Get_noise = require 'utils.math.get_noise' local math_random = math.random local math_floor = math.floor local math_abs = math.abs diff --git a/maps/scrap_towny_ffa/terrain.lua b/maps/scrap_towny_ffa/terrain.lua index 1f9a28ab..88db7a13 100644 --- a/maps/scrap_towny_ffa/terrain.lua +++ b/maps/scrap_towny_ffa/terrain.lua @@ -1,8 +1,8 @@ local Event = require 'utils.event' -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local ScenarioTable = require 'maps.scrap_towny_ffa.table' local Scrap = require 'maps.scrap_towny_ffa.scrap' -local get_perlin = require 'utils.get_perlin' +local get_perlin = require 'utils.math.get_perlin' local table_insert = table.insert local math_random = math.random diff --git a/maps/spaghettorio.lua b/maps/spaghettorio.lua index 618f880c..c57e14be 100644 --- a/maps/spaghettorio.lua +++ b/maps/spaghettorio.lua @@ -1,7 +1,7 @@ --luacheck: ignore --spaghettorio-- mewmew made this -- inspired by redlabel -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' simplex_noise = simplex_noise.d2 local event = require 'utils.event' diff --git a/maps/spooky_forest.lua b/maps/spooky_forest.lua index de3d00fe..6d7323c2 100644 --- a/maps/spooky_forest.lua +++ b/maps/spooky_forest.lua @@ -21,7 +21,7 @@ require 'modules.hunger' local shapes = require 'utils.tools.shapes' local event = require 'utils.event' local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' simplex_noise = simplex_noise.d2 local math_random = math.random diff --git a/maps/stone_maze/noise.lua b/maps/stone_maze/noise.lua index 3de0206c..89170891 100644 --- a/maps/stone_maze/noise.lua +++ b/maps/stone_maze/noise.lua @@ -1,4 +1,4 @@ -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local noises = { ['trees_01'] = {{modifier = 0.03, weight = 1}, {modifier = 0.05, weight = 0.3}, {modifier = 0.1, weight = 0.05}}, diff --git a/maps/stoneblock.lua b/maps/stoneblock.lua index bc97639b..96717c98 100644 --- a/maps/stoneblock.lua +++ b/maps/stoneblock.lua @@ -21,7 +21,7 @@ local event = require 'utils.event' local math_random = math.random local insert = table.insert local map_functions = require 'utils.tools.map_functions' -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' local simplex_noise = simplex_noise.d2 local spawn_point = { x = 0, y = 2 } diff --git a/maps/tank_battles.lua b/maps/tank_battles.lua index 9942fd42..08332ce0 100644 --- a/maps/tank_battles.lua +++ b/maps/tank_battles.lua @@ -3,7 +3,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Core = require 'utils.core' local Server = require 'utils.server' local Map = require 'modules.map_info' diff --git a/maps/territorial_control.lua b/maps/territorial_control.lua index 231e2e72..0397d9be 100644 --- a/maps/territorial_control.lua +++ b/maps/territorial_control.lua @@ -21,7 +21,7 @@ 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' +local simplex_noise = require 'utils.math.simplex_noise' simplex_noise = simplex_noise.d2 local math_random = math.random diff --git a/maps/wave_of_death/terrain.lua b/maps/wave_of_death/terrain.lua index 334ced6f..361b7f01 100644 --- a/maps/wave_of_death/terrain.lua +++ b/maps/wave_of_death/terrain.lua @@ -1,5 +1,5 @@ --luacheck: ignore -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local math_random = math.random local wod_logo_tiles = require 'maps.wave_of_death.logo' local noises = { diff --git a/maps/wip/func.lua b/maps/wip/func.lua index 0dcb7bdd..e643d256 100644 --- a/maps/wip/func.lua +++ b/maps/wip/func.lua @@ -1,7 +1,7 @@ --luacheck: ignore local Event = require 'utils.event' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local NoiseVectors = require 'utils.functions.noise_vector_path' local MapFunctions = require 'utils.tools.map_functions' local Scheduler = require 'utils.scheduler' diff --git a/modules/evolution_extended.lua b/modules/evolution_extended.lua index 67a419ef..9868c4e8 100644 --- a/modules/evolution_extended.lua +++ b/modules/evolution_extended.lua @@ -3,7 +3,7 @@ require 'modules.biter_evasion_hp_increaser' local Event = require 'utils.event' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local gui_refreshrate = 900 local evo_gains = { diff --git a/modules/ores_are_mixed.lua b/modules/ores_are_mixed.lua index c334b323..dd4c9a18 100644 --- a/modules/ores_are_mixed.lua +++ b/modules/ores_are_mixed.lua @@ -1,5 +1,5 @@ local Event = require 'utils.event' -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local ore_raffle = { 'iron-ore', 'iron-ore', diff --git a/utils/functions/noise_vector_path.lua b/utils/functions/noise_vector_path.lua index e29a6054..debd0947 100644 --- a/utils/functions/noise_vector_path.lua +++ b/utils/functions/noise_vector_path.lua @@ -1,6 +1,6 @@ --draws lines modified by noise -- mewmew -local simplex_noise = require 'utils.simplex_noise'.d2 +local simplex_noise = require 'utils.math.simplex_noise'.d2 local Public = {} local function get_brush(size) diff --git a/utils/get_noise.lua b/utils/get_noise.lua deleted file mode 100644 index b8b06e59..00000000 --- a/utils/get_noise.lua +++ /dev/null @@ -1,142 +0,0 @@ -local simplex_noise = require 'utils.simplex_noise'.d2 - ---add or use noise templates from here -local noises = { - ['bb_biterland'] = { - {modifier = 0.001, weight = 1}, - {modifier = 0.01, weight = 0.35}, - {modifier = 0.1, weight = 0.015} - }, - ['bb_ore'] = {{modifier = 0.0042, weight = 1}, {modifier = 0.031, weight = 0.08}, {modifier = 0.1, weight = 0.025}}, - ['cave_ponds'] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}}, - ['smol_areas'] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.02}, {modifier = 0.1, weight = 0.03}}, - ['cave_worms'] = {{modifier = 0.001, weight = 1}, {modifier = 0.1, weight = 0.06}}, - ['cave_rivers'] = { - {modifier = 0.005, weight = 1}, - {modifier = 0.01, weight = 0.25}, - {modifier = 0.05, weight = 0.01} - }, - ['cave_rivers_2'] = { - {modifier = 0.003, weight = 1}, - {modifier = 0.01, weight = 0.21}, - {modifier = 0.05, weight = 0.01} - }, - ['cave_rivers_3'] = { - {modifier = 0.002, weight = 1}, - {modifier = 0.01, weight = 0.15}, - {modifier = 0.05, weight = 0.01} - }, - ['cave_rivers_4'] = { - {modifier = 0.001, weight = 1}, - {modifier = 0.01, weight = 0.11}, - {modifier = 0.05, weight = 0.01} - }, - ['decoratives'] = {{modifier = 0.03, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.1, weight = 0.05}}, - ['dungeons'] = {{modifier = 0.0025, weight = 1}, {modifier = 0.005, weight = 0.25}}, - ['dungeon_sewer'] = { - {modifier = 0.0005, weight = 1}, - {modifier = 0.005, weight = 0.015}, - {modifier = 0.025, weight = 0.0015} - }, - ['large_caves'] = { - {modifier = 0.0033, weight = 1}, - {modifier = 0.01, weight = 0.22}, - {modifier = 0.05, weight = 0.05}, - {modifier = 0.1, weight = 0.04} - }, - ['n1'] = {{modifier = 0.0001, weight = 1}}, - ['n2'] = {{modifier = 0.001, weight = 1}}, - ['n3'] = {{modifier = 0.01, weight = 1}}, - ['n4'] = {{modifier = 0.1, weight = 1}}, - ['n5'] = {{modifier = 0.07, weight = 1}}, - ['watery_world'] = { - {modifier = 0.0007, weight = 1}, - {modifier = 0.01, weight = 0.02}, - {modifier = 0.1, weight = 0.005} - }, - ['no_rocks'] = { - {modifier = 0.0033, weight = 1}, - {modifier = 0.01, weight = 0.22}, - {modifier = 0.05, weight = 0.05}, - {modifier = 0.1, weight = 0.04} - }, - ['no_rocks_2'] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}}, - ['oasis'] = { - {modifier = 0.0015, weight = 1}, - {modifier = 0.0025, weight = 0.5}, - {modifier = 0.01, weight = 0.15}, - {modifier = 0.1, weight = 0.017} - }, - ['scrapyard'] = { - {modifier = 0.005, weight = 1}, - {modifier = 0.01, weight = 0.35}, - {modifier = 0.05, weight = 0.23}, - {modifier = 0.1, weight = 0.11} - }, - ['big_cave'] = { - {modifier = 0.003, weight = 1}, - {modifier = 0.02, weight = 0.05}, - {modifier = 0.15, weight = 0.02} - }, - ['small_caves'] = { - {modifier = 0.008, weight = 1}, - {modifier = 0.03, weight = 0.15}, - {modifier = 0.25, weight = 0.05} - }, - ['small_caves_2'] = { - {modifier = 0.009, weight = 1}, - {modifier = 0.05, weight = 0.25}, - {modifier = 0.25, weight = 0.05} - }, - ['forest_location'] = { - {modifier = 0.006, weight = 1}, - {modifier = 0.01, weight = 0.25}, - {modifier = 0.05, weight = 0.15}, - {modifier = 0.1, weight = 0.05} - }, - ['forest_density'] = { - {modifier = 0.01, weight = 1}, - {modifier = 0.05, weight = 0.5}, - {modifier = 0.1, weight = 0.025} - }, - ['cave_miner_01'] = { - {modifier = 0.0015, weight = 1}, - {modifier = 0.0030, weight = 0.15}, - {modifier = 0.0100, weight = 0.025}, - {modifier = 0.1000, weight = 0.01} - }, - ['cave_miner_02'] = { - {modifier = 0.006, weight = 1}, - {modifier = 0.02, weight = 0.15}, - {modifier = 0.25, weight = 0.025} - }, - ['cm_ponds'] = {{modifier = 0.025, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.1, weight = 0.05}}, - ['cm_ocean'] = { - {modifier = 0.002, weight = 1}, - {modifier = 0.004, weight = 1}, - {modifier = 0.02, weight = 0.05} - }, - ['scrap_towny_ffa'] = { - {modifier = 0.005, weight = 1}, - {modifier = 0.025, weight = 0.25}, - {modifier = 0.1, weight = 0.125}, - {modifier = 0.01, weight = 0.025} - }, - ['journey_swamps'] = {{modifier = 0.02, weight = 1}, {modifier = 0.04, weight = 0.35}, {modifier = 0.1, weight = 0.08}} -} - ---returns a float number between -1 and 1 -local function get_noise(name, pos, seed) - local noise = 0 - local d = 0 - for i = 1, #noises[name] do - local mod = noises[name] - noise = noise + simplex_noise(pos.x * mod[i].modifier, pos.y * mod[i].modifier, seed) * mod[i].weight - d = d + mod[i].weight - seed = seed + 10000 - end - noise = noise / d - return noise -end - -return get_noise diff --git a/utils/get_perlin.lua b/utils/get_perlin.lua deleted file mode 100644 index 6253edb7..00000000 --- a/utils/get_perlin.lua +++ /dev/null @@ -1,135 +0,0 @@ -local simplex_noise = require 'utils.simplex_noise'.d2 - ---add or use noise templates from here -local noises = { - ['bb_biterland'] = { - {modifier = 0.001, weight = 1}, - {modifier = 0.01, weight = 0.35}, - {modifier = 0.1, weight = 0.015} - }, - ['bb_ore'] = {{modifier = 0.0042, weight = 1}, {modifier = 0.031, weight = 0.08}, {modifier = 0.1, weight = 0.025}}, - ['cave_ponds'] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}}, - ['smol_areas'] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.02}, {modifier = 0.1, weight = 0.03}}, - ['cave_worms'] = {{modifier = 0.001, weight = 1}, {modifier = 0.1, weight = 0.06}}, - ['cave_rivers'] = { - {modifier = 0.005, weight = 1}, - {modifier = 0.01, weight = 0.25}, - {modifier = 0.05, weight = 0.01} - }, - ['cave_rivers_2'] = { - {modifier = 0.003, weight = 1}, - {modifier = 0.01, weight = 0.21}, - {modifier = 0.05, weight = 0.01} - }, - ['cave_rivers_3'] = { - {modifier = 0.002, weight = 1}, - {modifier = 0.01, weight = 0.15}, - {modifier = 0.05, weight = 0.01} - }, - ['cave_rivers_4'] = { - {modifier = 0.001, weight = 1}, - {modifier = 0.01, weight = 0.11}, - {modifier = 0.05, weight = 0.01} - }, - ['decoratives'] = {{modifier = 0.03, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.1, weight = 0.05}}, - ['dungeons'] = {{modifier = 0.0025, weight = 1}, {modifier = 0.005, weight = 0.25}}, - ['dungeon_sewer'] = { - {modifier = 0.0005, weight = 1}, - {modifier = 0.005, weight = 0.015}, - {modifier = 0.025, weight = 0.0015} - }, - ['large_caves'] = { - {modifier = 0.0033, weight = 1}, - {modifier = 0.01, weight = 0.22}, - {modifier = 0.05, weight = 0.05}, - {modifier = 0.1, weight = 0.04} - }, - ['n1'] = {{modifier = 0.0001, weight = 1}}, - ['n2'] = {{modifier = 0.001, weight = 1}}, - ['n3'] = {{modifier = 0.01, weight = 1}}, - ['n4'] = {{modifier = 0.1, weight = 1}}, - ['n5'] = {{modifier = 0.07, weight = 1}}, - ['watery_world'] = { - {modifier = 0.0007, weight = 1}, - {modifier = 0.01, weight = 0.02}, - {modifier = 0.1, weight = 0.005} - }, - ['no_rocks'] = { - {modifier = 0.0033, weight = 1}, - {modifier = 0.01, weight = 0.22}, - {modifier = 0.05, weight = 0.05}, - {modifier = 0.1, weight = 0.04} - }, - ['no_rocks_2'] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}}, - ['oasis'] = { - {modifier = 0.0015, weight = 1}, - {modifier = 0.0025, weight = 0.5}, - {modifier = 0.01, weight = 0.15}, - {modifier = 0.1, weight = 0.017} - }, - ['scrapyard'] = { - {modifier = 0.005, weight = 1}, - {modifier = 0.01, weight = 0.35}, - {modifier = 0.05, weight = 0.23}, - {modifier = 0.1, weight = 0.11} - }, - ['big_cave'] = { - {modifier = 0.003, weight = 1}, - {modifier = 0.02, weight = 0.05}, - {modifier = 0.15, weight = 0.02} - }, - ['small_caves'] = { - {modifier = 0.008, weight = 1}, - {modifier = 0.03, weight = 0.15}, - {modifier = 0.25, weight = 0.05} - }, - ['small_caves_2'] = { - {modifier = 0.009, weight = 1}, - {modifier = 0.05, weight = 0.25}, - {modifier = 0.25, weight = 0.05} - }, - ['forest_location'] = { - {modifier = 0.006, weight = 1}, - {modifier = 0.01, weight = 0.25}, - {modifier = 0.05, weight = 0.15}, - {modifier = 0.1, weight = 0.05} - }, - ['forest_density'] = { - {modifier = 0.01, weight = 1}, - {modifier = 0.05, weight = 0.5}, - {modifier = 0.1, weight = 0.025} - }, - ['cave_miner_01'] = { - {modifier = 0.002, weight = 1}, - {modifier = 0.003, weight = 0.5}, - {modifier = 0.01, weight = 0.01}, - {modifier = 0.1, weight = 0.015} - }, - ['cave_miner_02'] = { - {modifier = 0.006, weight = 1}, - {modifier = 0.02, weight = 0.15}, - {modifier = 0.25, weight = 0.025} - }, - ['cm_ponds'] = {{modifier = 0.025, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.1, weight = 0.05}}, - ['cm_ocean'] = { - {modifier = 0.002, weight = 1}, - {modifier = 0.004, weight = 1}, - {modifier = 0.02, weight = 0.05} - } -} - ---returns a float number between -1 and 1 -local function get_noise(name, pos, seed) - local noise = 0 - local d = 0 - for i = 1, #noises[name] do - local mod = noises[name] - noise = noise + simplex_noise(pos.x * mod[i].modifier, pos.y * mod[i].modifier, seed, 0xF) * mod[i].weight - d = d + mod[i].weight - seed = seed + seed / seed - end - noise = noise / d - return noise -end - -return get_noise diff --git a/utils/math/geometry.lua b/utils/math/geometry.lua new file mode 100644 index 00000000..eb4c80b0 --- /dev/null +++ b/utils/math/geometry.lua @@ -0,0 +1,1754 @@ +local Public = {} + +function Public.snap_to_grid(point) + return { x = Public.ceil(point.x), y = Public.ceil(point.x) } +end + +-- Given an area marked by integer coordinates, returns an array of all the half-integer positions bounded by that area. Useful for constructing tiles. +function Public.all_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 + +-- *** *** -- +--*** VECTORS ***-- +-- *** *** -- + +function Public.vector_length(vec) + return Public.sqrt(vec.x * vec.x + vec.y * vec.y) +end + +function Public.vector_sum(vec1, vec2) + return { x = vec1.x + vec2.x, y = vec1.y + vec2.y } +end + +function Public.vector_distance(vec1, vec2) + local vecx = vec2.x - vec1.x + local vecy = vec2.y - vec1.y + return Public.sqrt(vecx * vecx + vecy * vecy) +end + +-- normalises vector to unit vector (length 1) +-- if vector length is 0, returns {x = 0, y = 1} vector +function Public.vector_norm(vec) + local vec_copy = { x = vec.x, y = vec.y } + local vec_length = Public.sqrt(vec_copy.x ^ 2 + vec_copy.y ^ 2) + if vec_length == 0 then + vec_copy.x = 0 + vec_copy.y = 1 + else + vec_copy.x = vec_copy.x / vec_length + vec_copy.y = vec_copy.y / vec_length + end + return { x = vec_copy.x, y = vec_copy.y } +end + +-- Returns vector in random direction. +-- scalar: returned vector length. If nil, 1 will be chosen. +function Public.random_vector(scalar) + scalar = scalar or 1 + local random_angle = Public.random_float_in_range(0, 2 * Public.pi) + return { + x = Public.cos(random_angle) * scalar, + y = Public.sin(random_angle) * scalar, + } +end + +Public.points_in_m20t20_squared_sorted_by_distance_to_origin = { + { 0, 0 }, + { 1, 0 }, + { 0, 1 }, + { 0, -1 }, + { -1, 0 }, + { 1, 1 }, + { 1, -1 }, + { -1, 1 }, + { -1, -1 }, + { 2, 0 }, + { 0, 2 }, + { 0, -2 }, + { -2, 0 }, + { 2, 1 }, + { 2, -1 }, + { 1, 2 }, + { 1, -2 }, + { -1, 2 }, + { -1, -2 }, + { -2, 1 }, + { -2, -1 }, + { 2, 2 }, + { 2, -2 }, + { -2, 2 }, + { -2, -2 }, + { 3, 0 }, + { 0, 3 }, + { 0, -3 }, + { -3, 0 }, + { 3, 1 }, + { 3, -1 }, + { 1, 3 }, + { 1, -3 }, + { -1, 3 }, + { -1, -3 }, + { -3, 1 }, + { -3, -1 }, + { 3, 2 }, + { 3, -2 }, + { 2, 3 }, + { 2, -3 }, + { -2, 3 }, + { -2, -3 }, + { -3, 2 }, + { -3, -2 }, + { 4, 0 }, + { 0, 4 }, + { 0, -4 }, + { -4, 0 }, + { 4, 1 }, + { 4, -1 }, + { 1, 4 }, + { 1, -4 }, + { -1, 4 }, + { -1, -4 }, + { -4, 1 }, + { -4, -1 }, + { 3, 3 }, + { 3, -3 }, + { -3, 3 }, + { -3, -3 }, + { 4, 2 }, + { 4, -2 }, + { 2, 4 }, + { 2, -4 }, + { -2, 4 }, + { -2, -4 }, + { -4, 2 }, + { -4, -2 }, + { 5, 0 }, + { 4, 3 }, + { 4, -3 }, + { 3, 4 }, + { 3, -4 }, + { 0, 5 }, + { 0, -5 }, + { -3, 4 }, + { -3, -4 }, + { -4, 3 }, + { -4, -3 }, + { -5, 0 }, + { 5, 1 }, + { 5, -1 }, + { 1, 5 }, + { 1, -5 }, + { -1, 5 }, + { -1, -5 }, + { -5, 1 }, + { -5, -1 }, + { 5, 2 }, + { 5, -2 }, + { 2, 5 }, + { 2, -5 }, + { -2, 5 }, + { -2, -5 }, + { -5, 2 }, + { -5, -2 }, + { 4, 4 }, + { 4, -4 }, + { -4, 4 }, + { -4, -4 }, + { 5, 3 }, + { 5, -3 }, + { 3, 5 }, + { 3, -5 }, + { -3, 5 }, + { -3, -5 }, + { -5, 3 }, + { -5, -3 }, + { 6, 0 }, + { 0, 6 }, + { 0, -6 }, + { -6, 0 }, + { 6, 1 }, + { 6, -1 }, + { 1, 6 }, + { 1, -6 }, + { -1, 6 }, + { -1, -6 }, + { -6, 1 }, + { -6, -1 }, + { 6, 2 }, + { 6, -2 }, + { 2, 6 }, + { 2, -6 }, + { -2, 6 }, + { -2, -6 }, + { -6, 2 }, + { -6, -2 }, + { 5, 4 }, + { 5, -4 }, + { 4, 5 }, + { 4, -5 }, + { -4, 5 }, + { -4, -5 }, + { -5, 4 }, + { -5, -4 }, + { 6, 3 }, + { 6, -3 }, + { 3, 6 }, + { 3, -6 }, + { -3, 6 }, + { -3, -6 }, + { -6, 3 }, + { -6, -3 }, + { 7, 0 }, + { 0, 7 }, + { 0, -7 }, + { -7, 0 }, + { 7, 1 }, + { 7, -1 }, + { 5, 5 }, + { 5, -5 }, + { 1, 7 }, + { 1, -7 }, + { -1, 7 }, + { -1, -7 }, + { -5, 5 }, + { -5, -5 }, + { -7, 1 }, + { -7, -1 }, + { 6, 4 }, + { 6, -4 }, + { 4, 6 }, + { 4, -6 }, + { -4, 6 }, + { -4, -6 }, + { -6, 4 }, + { -6, -4 }, + { 7, 2 }, + { 7, -2 }, + { 2, 7 }, + { 2, -7 }, + { -2, 7 }, + { -2, -7 }, + { -7, 2 }, + { -7, -2 }, + { 7, 3 }, + { 7, -3 }, + { 3, 7 }, + { 3, -7 }, + { -3, 7 }, + { -3, -7 }, + { -7, 3 }, + { -7, -3 }, + { 6, 5 }, + { 6, -5 }, + { 5, 6 }, + { 5, -6 }, + { -5, 6 }, + { -5, -6 }, + { -6, 5 }, + { -6, -5 }, + { 8, 0 }, + { 0, 8 }, + { 0, -8 }, + { -8, 0 }, + { 8, 1 }, + { 8, -1 }, + { 7, 4 }, + { 7, -4 }, + { 4, 7 }, + { 4, -7 }, + { 1, 8 }, + { 1, -8 }, + { -1, 8 }, + { -1, -8 }, + { -4, 7 }, + { -4, -7 }, + { -7, 4 }, + { -7, -4 }, + { -8, 1 }, + { -8, -1 }, + { 8, 2 }, + { 8, -2 }, + { 2, 8 }, + { 2, -8 }, + { -2, 8 }, + { -2, -8 }, + { -8, 2 }, + { -8, -2 }, + { 6, 6 }, + { 6, -6 }, + { -6, 6 }, + { -6, -6 }, + { 8, 3 }, + { 8, -3 }, + { 3, 8 }, + { 3, -8 }, + { -3, 8 }, + { -3, -8 }, + { -8, 3 }, + { -8, -3 }, + { 7, 5 }, + { 7, -5 }, + { 5, 7 }, + { 5, -7 }, + { -5, 7 }, + { -5, -7 }, + { -7, 5 }, + { -7, -5 }, + { 8, 4 }, + { 8, -4 }, + { 4, 8 }, + { 4, -8 }, + { -4, 8 }, + { -4, -8 }, + { -8, 4 }, + { -8, -4 }, + { 9, 0 }, + { 0, 9 }, + { 0, -9 }, + { -9, 0 }, + { 9, 1 }, + { 9, -1 }, + { 1, 9 }, + { 1, -9 }, + { -1, 9 }, + { -1, -9 }, + { -9, 1 }, + { -9, -1 }, + { 9, 2 }, + { 9, -2 }, + { 7, 6 }, + { 7, -6 }, + { 6, 7 }, + { 6, -7 }, + { 2, 9 }, + { 2, -9 }, + { -2, 9 }, + { -2, -9 }, + { -6, 7 }, + { -6, -7 }, + { -7, 6 }, + { -7, -6 }, + { -9, 2 }, + { -9, -2 }, + { 8, 5 }, + { 8, -5 }, + { 5, 8 }, + { 5, -8 }, + { -5, 8 }, + { -5, -8 }, + { -8, 5 }, + { -8, -5 }, + { 9, 3 }, + { 9, -3 }, + { 3, 9 }, + { 3, -9 }, + { -3, 9 }, + { -3, -9 }, + { -9, 3 }, + { -9, -3 }, + { 9, 4 }, + { 9, -4 }, + { 4, 9 }, + { 4, -9 }, + { -4, 9 }, + { -4, -9 }, + { -9, 4 }, + { -9, -4 }, + { 7, 7 }, + { 7, -7 }, + { -7, 7 }, + { -7, -7 }, + { 10, 0 }, + { 8, 6 }, + { 8, -6 }, + { 6, 8 }, + { 6, -8 }, + { 0, 10 }, + { 0, -10 }, + { -6, 8 }, + { -6, -8 }, + { -8, 6 }, + { -8, -6 }, + { -10, 0 }, + { 10, 1 }, + { 10, -1 }, + { 1, 10 }, + { 1, -10 }, + { -1, 10 }, + { -1, -10 }, + { -10, 1 }, + { -10, -1 }, + { 10, 2 }, + { 10, -2 }, + { 2, 10 }, + { 2, -10 }, + { -2, 10 }, + { -2, -10 }, + { -10, 2 }, + { -10, -2 }, + { 9, 5 }, + { 9, -5 }, + { 5, 9 }, + { 5, -9 }, + { -5, 9 }, + { -5, -9 }, + { -9, 5 }, + { -9, -5 }, + { 10, 3 }, + { 10, -3 }, + { 3, 10 }, + { 3, -10 }, + { -3, 10 }, + { -3, -10 }, + { -10, 3 }, + { -10, -3 }, + { 8, 7 }, + { 8, -7 }, + { 7, 8 }, + { 7, -8 }, + { -7, 8 }, + { -7, -8 }, + { -8, 7 }, + { -8, -7 }, + { 10, 4 }, + { 10, -4 }, + { 4, 10 }, + { 4, -10 }, + { -4, 10 }, + { -4, -10 }, + { -10, 4 }, + { -10, -4 }, + { 9, 6 }, + { 9, -6 }, + { 6, 9 }, + { 6, -9 }, + { -6, 9 }, + { -6, -9 }, + { -9, 6 }, + { -9, -6 }, + { 11, 0 }, + { 0, 11 }, + { 0, -11 }, + { -11, 0 }, + { 11, 1 }, + { 11, -1 }, + { 1, 11 }, + { 1, -11 }, + { -1, 11 }, + { -1, -11 }, + { -11, 1 }, + { -11, -1 }, + { 11, 2 }, + { 11, -2 }, + { 10, 5 }, + { 10, -5 }, + { 5, 10 }, + { 5, -10 }, + { 2, 11 }, + { 2, -11 }, + { -2, 11 }, + { -2, -11 }, + { -5, 10 }, + { -5, -10 }, + { -10, 5 }, + { -10, -5 }, + { -11, 2 }, + { -11, -2 }, + { 8, 8 }, + { 8, -8 }, + { -8, 8 }, + { -8, -8 }, + { 11, 3 }, + { 11, -3 }, + { 9, 7 }, + { 9, -7 }, + { 7, 9 }, + { 7, -9 }, + { 3, 11 }, + { 3, -11 }, + { -3, 11 }, + { -3, -11 }, + { -7, 9 }, + { -7, -9 }, + { -9, 7 }, + { -9, -7 }, + { -11, 3 }, + { -11, -3 }, + { 10, 6 }, + { 10, -6 }, + { 6, 10 }, + { 6, -10 }, + { -6, 10 }, + { -6, -10 }, + { -10, 6 }, + { -10, -6 }, + { 11, 4 }, + { 11, -4 }, + { 4, 11 }, + { 4, -11 }, + { -4, 11 }, + { -4, -11 }, + { -11, 4 }, + { -11, -4 }, + { 12, 0 }, + { 0, 12 }, + { 0, -12 }, + { -12, 0 }, + { 12, 1 }, + { 12, -1 }, + { 9, 8 }, + { 9, -8 }, + { 8, 9 }, + { 8, -9 }, + { 1, 12 }, + { 1, -12 }, + { -1, 12 }, + { -1, -12 }, + { -8, 9 }, + { -8, -9 }, + { -9, 8 }, + { -9, -8 }, + { -12, 1 }, + { -12, -1 }, + { 11, 5 }, + { 11, -5 }, + { 5, 11 }, + { 5, -11 }, + { -5, 11 }, + { -5, -11 }, + { -11, 5 }, + { -11, -5 }, + { 12, 2 }, + { 12, -2 }, + { 2, 12 }, + { 2, -12 }, + { -2, 12 }, + { -2, -12 }, + { -12, 2 }, + { -12, -2 }, + { 10, 7 }, + { 10, -7 }, + { 7, 10 }, + { 7, -10 }, + { -7, 10 }, + { -7, -10 }, + { -10, 7 }, + { -10, -7 }, + { 12, 3 }, + { 12, -3 }, + { 3, 12 }, + { 3, -12 }, + { -3, 12 }, + { -3, -12 }, + { -12, 3 }, + { -12, -3 }, + { 11, 6 }, + { 11, -6 }, + { 6, 11 }, + { 6, -11 }, + { -6, 11 }, + { -6, -11 }, + { -11, 6 }, + { -11, -6 }, + { 12, 4 }, + { 12, -4 }, + { 4, 12 }, + { 4, -12 }, + { -4, 12 }, + { -4, -12 }, + { -12, 4 }, + { -12, -4 }, + { 9, 9 }, + { 9, -9 }, + { -9, 9 }, + { -9, -9 }, + { 10, 8 }, + { 10, -8 }, + { 8, 10 }, + { 8, -10 }, + { -8, 10 }, + { -8, -10 }, + { -10, 8 }, + { -10, -8 }, + { 13, 0 }, + { 12, 5 }, + { 12, -5 }, + { 5, 12 }, + { 5, -12 }, + { 0, 13 }, + { 0, -13 }, + { -5, 12 }, + { -5, -12 }, + { -12, 5 }, + { -12, -5 }, + { -13, 0 }, + { 13, 1 }, + { 13, -1 }, + { 11, 7 }, + { 11, -7 }, + { 7, 11 }, + { 7, -11 }, + { 1, 13 }, + { 1, -13 }, + { -1, 13 }, + { -1, -13 }, + { -7, 11 }, + { -7, -11 }, + { -11, 7 }, + { -11, -7 }, + { -13, 1 }, + { -13, -1 }, + { 13, 2 }, + { 13, -2 }, + { 2, 13 }, + { 2, -13 }, + { -2, 13 }, + { -2, -13 }, + { -13, 2 }, + { -13, -2 }, + { 13, 3 }, + { 13, -3 }, + { 3, 13 }, + { 3, -13 }, + { -3, 13 }, + { -3, -13 }, + { -13, 3 }, + { -13, -3 }, + { 12, 6 }, + { 12, -6 }, + { 6, 12 }, + { 6, -12 }, + { -6, 12 }, + { -6, -12 }, + { -12, 6 }, + { -12, -6 }, + { 10, 9 }, + { 10, -9 }, + { 9, 10 }, + { 9, -10 }, + { -9, 10 }, + { -9, -10 }, + { -10, 9 }, + { -10, -9 }, + { 13, 4 }, + { 13, -4 }, + { 11, 8 }, + { 11, -8 }, + { 8, 11 }, + { 8, -11 }, + { 4, 13 }, + { 4, -13 }, + { -4, 13 }, + { -4, -13 }, + { -8, 11 }, + { -8, -11 }, + { -11, 8 }, + { -11, -8 }, + { -13, 4 }, + { -13, -4 }, + { 12, 7 }, + { 12, -7 }, + { 7, 12 }, + { 7, -12 }, + { -7, 12 }, + { -7, -12 }, + { -12, 7 }, + { -12, -7 }, + { 13, 5 }, + { 13, -5 }, + { 5, 13 }, + { 5, -13 }, + { -5, 13 }, + { -5, -13 }, + { -13, 5 }, + { -13, -5 }, + { 14, 0 }, + { 0, 14 }, + { 0, -14 }, + { -14, 0 }, + { 14, 1 }, + { 14, -1 }, + { 1, 14 }, + { 1, -14 }, + { -1, 14 }, + { -1, -14 }, + { -14, 1 }, + { -14, -1 }, + { 14, 2 }, + { 14, -2 }, + { 10, 10 }, + { 10, -10 }, + { 2, 14 }, + { 2, -14 }, + { -2, 14 }, + { -2, -14 }, + { -10, 10 }, + { -10, -10 }, + { -14, 2 }, + { -14, -2 }, + { 11, 9 }, + { 11, -9 }, + { 9, 11 }, + { 9, -11 }, + { -9, 11 }, + { -9, -11 }, + { -11, 9 }, + { -11, -9 }, + { 14, 3 }, + { 14, -3 }, + { 13, 6 }, + { 13, -6 }, + { 6, 13 }, + { 6, -13 }, + { 3, 14 }, + { 3, -14 }, + { -3, 14 }, + { -3, -14 }, + { -6, 13 }, + { -6, -13 }, + { -13, 6 }, + { -13, -6 }, + { -14, 3 }, + { -14, -3 }, + { 12, 8 }, + { 12, -8 }, + { 8, 12 }, + { 8, -12 }, + { -8, 12 }, + { -8, -12 }, + { -12, 8 }, + { -12, -8 }, + { 14, 4 }, + { 14, -4 }, + { 4, 14 }, + { 4, -14 }, + { -4, 14 }, + { -4, -14 }, + { -14, 4 }, + { -14, -4 }, + { 13, 7 }, + { 13, -7 }, + { 7, 13 }, + { 7, -13 }, + { -7, 13 }, + { -7, -13 }, + { -13, 7 }, + { -13, -7 }, + { 14, 5 }, + { 14, -5 }, + { 11, 10 }, + { 11, -10 }, + { 10, 11 }, + { 10, -11 }, + { 5, 14 }, + { 5, -14 }, + { -5, 14 }, + { -5, -14 }, + { -10, 11 }, + { -10, -11 }, + { -11, 10 }, + { -11, -10 }, + { -14, 5 }, + { -14, -5 }, + { 15, 0 }, + { 12, 9 }, + { 12, -9 }, + { 9, 12 }, + { 9, -12 }, + { 0, 15 }, + { 0, -15 }, + { -9, 12 }, + { -9, -12 }, + { -12, 9 }, + { -12, -9 }, + { -15, 0 }, + { 15, 1 }, + { 15, -1 }, + { 1, 15 }, + { 1, -15 }, + { -1, 15 }, + { -1, -15 }, + { -15, 1 }, + { -15, -1 }, + { 15, 2 }, + { 15, -2 }, + { 2, 15 }, + { 2, -15 }, + { -2, 15 }, + { -2, -15 }, + { -15, 2 }, + { -15, -2 }, + { 14, 6 }, + { 14, -6 }, + { 6, 14 }, + { 6, -14 }, + { -6, 14 }, + { -6, -14 }, + { -14, 6 }, + { -14, -6 }, + { 13, 8 }, + { 13, -8 }, + { 8, 13 }, + { 8, -13 }, + { -8, 13 }, + { -8, -13 }, + { -13, 8 }, + { -13, -8 }, + { 15, 3 }, + { 15, -3 }, + { 3, 15 }, + { 3, -15 }, + { -3, 15 }, + { -3, -15 }, + { -15, 3 }, + { -15, -3 }, + { 15, 4 }, + { 15, -4 }, + { 4, 15 }, + { 4, -15 }, + { -4, 15 }, + { -4, -15 }, + { -15, 4 }, + { -15, -4 }, + { 11, 11 }, + { 11, -11 }, + { -11, 11 }, + { -11, -11 }, + { 12, 10 }, + { 12, -10 }, + { 10, 12 }, + { 10, -12 }, + { -10, 12 }, + { -10, -12 }, + { -12, 10 }, + { -12, -10 }, + { 14, 7 }, + { 14, -7 }, + { 7, 14 }, + { 7, -14 }, + { -7, 14 }, + { -7, -14 }, + { -14, 7 }, + { -14, -7 }, + { 15, 5 }, + { 15, -5 }, + { 13, 9 }, + { 13, -9 }, + { 9, 13 }, + { 9, -13 }, + { 5, 15 }, + { 5, -15 }, + { -5, 15 }, + { -5, -15 }, + { -9, 13 }, + { -9, -13 }, + { -13, 9 }, + { -13, -9 }, + { -15, 5 }, + { -15, -5 }, + { 16, 0 }, + { 0, 16 }, + { 0, -16 }, + { -16, 0 }, + { 16, 1 }, + { 16, -1 }, + { 1, 16 }, + { 1, -16 }, + { -1, 16 }, + { -1, -16 }, + { -16, 1 }, + { -16, -1 }, + { 16, 2 }, + { 16, -2 }, + { 14, 8 }, + { 14, -8 }, + { 8, 14 }, + { 8, -14 }, + { 2, 16 }, + { 2, -16 }, + { -2, 16 }, + { -2, -16 }, + { -8, 14 }, + { -8, -14 }, + { -14, 8 }, + { -14, -8 }, + { -16, 2 }, + { -16, -2 }, + { 15, 6 }, + { 15, -6 }, + { 6, 15 }, + { 6, -15 }, + { -6, 15 }, + { -6, -15 }, + { -15, 6 }, + { -15, -6 }, + { 16, 3 }, + { 16, -3 }, + { 12, 11 }, + { 12, -11 }, + { 11, 12 }, + { 11, -12 }, + { 3, 16 }, + { 3, -16 }, + { -3, 16 }, + { -3, -16 }, + { -11, 12 }, + { -11, -12 }, + { -12, 11 }, + { -12, -11 }, + { -16, 3 }, + { -16, -3 }, + { 13, 10 }, + { 13, -10 }, + { 10, 13 }, + { 10, -13 }, + { -10, 13 }, + { -10, -13 }, + { -13, 10 }, + { -13, -10 }, + { 16, 4 }, + { 16, -4 }, + { 4, 16 }, + { 4, -16 }, + { -4, 16 }, + { -4, -16 }, + { -16, 4 }, + { -16, -4 }, + { 15, 7 }, + { 15, -7 }, + { 7, 15 }, + { 7, -15 }, + { -7, 15 }, + { -7, -15 }, + { -15, 7 }, + { -15, -7 }, + { 14, 9 }, + { 14, -9 }, + { 9, 14 }, + { 9, -14 }, + { -9, 14 }, + { -9, -14 }, + { -14, 9 }, + { -14, -9 }, + { 16, 5 }, + { 16, -5 }, + { 5, 16 }, + { 5, -16 }, + { -5, 16 }, + { -5, -16 }, + { -16, 5 }, + { -16, -5 }, + { 12, 12 }, + { 12, -12 }, + { -12, 12 }, + { -12, -12 }, + { 17, 0 }, + { 15, 8 }, + { 15, -8 }, + { 8, 15 }, + { 8, -15 }, + { 0, 17 }, + { 0, -17 }, + { -8, 15 }, + { -8, -15 }, + { -15, 8 }, + { -15, -8 }, + { -17, 0 }, + { 17, 1 }, + { 17, -1 }, + { 13, 11 }, + { 13, -11 }, + { 11, 13 }, + { 11, -13 }, + { 1, 17 }, + { 1, -17 }, + { -1, 17 }, + { -1, -17 }, + { -11, 13 }, + { -11, -13 }, + { -13, 11 }, + { -13, -11 }, + { -17, 1 }, + { -17, -1 }, + { 16, 6 }, + { 16, -6 }, + { 6, 16 }, + { 6, -16 }, + { -6, 16 }, + { -6, -16 }, + { -16, 6 }, + { -16, -6 }, + { 17, 2 }, + { 17, -2 }, + { 2, 17 }, + { 2, -17 }, + { -2, 17 }, + { -2, -17 }, + { -17, 2 }, + { -17, -2 }, + { 14, 10 }, + { 14, -10 }, + { 10, 14 }, + { 10, -14 }, + { -10, 14 }, + { -10, -14 }, + { -14, 10 }, + { -14, -10 }, + { 17, 3 }, + { 17, -3 }, + { 3, 17 }, + { 3, -17 }, + { -3, 17 }, + { -3, -17 }, + { -17, 3 }, + { -17, -3 }, + { 17, 4 }, + { 17, -4 }, + { 16, 7 }, + { 16, -7 }, + { 7, 16 }, + { 7, -16 }, + { 4, 17 }, + { 4, -17 }, + { -4, 17 }, + { -4, -17 }, + { -7, 16 }, + { -7, -16 }, + { -16, 7 }, + { -16, -7 }, + { -17, 4 }, + { -17, -4 }, + { 15, 9 }, + { 15, -9 }, + { 9, 15 }, + { 9, -15 }, + { -9, 15 }, + { -9, -15 }, + { -15, 9 }, + { -15, -9 }, + { 13, 12 }, + { 13, -12 }, + { 12, 13 }, + { 12, -13 }, + { -12, 13 }, + { -12, -13 }, + { -13, 12 }, + { -13, -12 }, + { 17, 5 }, + { 17, -5 }, + { 5, 17 }, + { 5, -17 }, + { -5, 17 }, + { -5, -17 }, + { -17, 5 }, + { -17, -5 }, + { 14, 11 }, + { 14, -11 }, + { 11, 14 }, + { 11, -14 }, + { -11, 14 }, + { -11, -14 }, + { -14, 11 }, + { -14, -11 }, + { 16, 8 }, + { 16, -8 }, + { 8, 16 }, + { 8, -16 }, + { -8, 16 }, + { -8, -16 }, + { -16, 8 }, + { -16, -8 }, + { 18, 0 }, + { 0, 18 }, + { 0, -18 }, + { -18, 0 }, + { 18, 1 }, + { 18, -1 }, + { 17, 6 }, + { 17, -6 }, + { 15, 10 }, + { 15, -10 }, + { 10, 15 }, + { 10, -15 }, + { 6, 17 }, + { 6, -17 }, + { 1, 18 }, + { 1, -18 }, + { -1, 18 }, + { -1, -18 }, + { -6, 17 }, + { -6, -17 }, + { -10, 15 }, + { -10, -15 }, + { -15, 10 }, + { -15, -10 }, + { -17, 6 }, + { -17, -6 }, + { -18, 1 }, + { -18, -1 }, + { 18, 2 }, + { 18, -2 }, + { 2, 18 }, + { 2, -18 }, + { -2, 18 }, + { -2, -18 }, + { -18, 2 }, + { -18, -2 }, + { 18, 3 }, + { 18, -3 }, + { 3, 18 }, + { 3, -18 }, + { -3, 18 }, + { -3, -18 }, + { -18, 3 }, + { -18, -3 }, + { 16, 9 }, + { 16, -9 }, + { 9, 16 }, + { 9, -16 }, + { -9, 16 }, + { -9, -16 }, + { -16, 9 }, + { -16, -9 }, + { 17, 7 }, + { 17, -7 }, + { 13, 13 }, + { 13, -13 }, + { 7, 17 }, + { 7, -17 }, + { -7, 17 }, + { -7, -17 }, + { -13, 13 }, + { -13, -13 }, + { -17, 7 }, + { -17, -7 }, + { 18, 4 }, + { 18, -4 }, + { 14, 12 }, + { 14, -12 }, + { 12, 14 }, + { 12, -14 }, + { 4, 18 }, + { 4, -18 }, + { -4, 18 }, + { -4, -18 }, + { -12, 14 }, + { -12, -14 }, + { -14, 12 }, + { -14, -12 }, + { -18, 4 }, + { -18, -4 }, + { 15, 11 }, + { 15, -11 }, + { 11, 15 }, + { 11, -15 }, + { -11, 15 }, + { -11, -15 }, + { -15, 11 }, + { -15, -11 }, + { 18, 5 }, + { 18, -5 }, + { 5, 18 }, + { 5, -18 }, + { -5, 18 }, + { -5, -18 }, + { -18, 5 }, + { -18, -5 }, + { 17, 8 }, + { 17, -8 }, + { 8, 17 }, + { 8, -17 }, + { -8, 17 }, + { -8, -17 }, + { -17, 8 }, + { -17, -8 }, + { 16, 10 }, + { 16, -10 }, + { 10, 16 }, + { 10, -16 }, + { -10, 16 }, + { -10, -16 }, + { -16, 10 }, + { -16, -10 }, + { 18, 6 }, + { 18, -6 }, + { 6, 18 }, + { 6, -18 }, + { -6, 18 }, + { -6, -18 }, + { -18, 6 }, + { -18, -6 }, + { 19, 0 }, + { 0, 19 }, + { 0, -19 }, + { -19, 0 }, + { 19, 1 }, + { 19, -1 }, + { 1, 19 }, + { 1, -19 }, + { -1, 19 }, + { -1, -19 }, + { -19, 1 }, + { -19, -1 }, + { 19, 2 }, + { 19, -2 }, + { 14, 13 }, + { 14, -13 }, + { 13, 14 }, + { 13, -14 }, + { 2, 19 }, + { 2, -19 }, + { -2, 19 }, + { -2, -19 }, + { -13, 14 }, + { -13, -14 }, + { -14, 13 }, + { -14, -13 }, + { -19, 2 }, + { -19, -2 }, + { 15, 12 }, + { 15, -12 }, + { 12, 15 }, + { 12, -15 }, + { -12, 15 }, + { -12, -15 }, + { -15, 12 }, + { -15, -12 }, + { 19, 3 }, + { 19, -3 }, + { 17, 9 }, + { 17, -9 }, + { 9, 17 }, + { 9, -17 }, + { 3, 19 }, + { 3, -19 }, + { -3, 19 }, + { -3, -19 }, + { -9, 17 }, + { -9, -17 }, + { -17, 9 }, + { -17, -9 }, + { -19, 3 }, + { -19, -3 }, + { 18, 7 }, + { 18, -7 }, + { 7, 18 }, + { 7, -18 }, + { -7, 18 }, + { -7, -18 }, + { -18, 7 }, + { -18, -7 }, + { 19, 4 }, + { 19, -4 }, + { 16, 11 }, + { 16, -11 }, + { 11, 16 }, + { 11, -16 }, + { 4, 19 }, + { 4, -19 }, + { -4, 19 }, + { -4, -19 }, + { -11, 16 }, + { -11, -16 }, + { -16, 11 }, + { -16, -11 }, + { -19, 4 }, + { -19, -4 }, + { 19, 5 }, + { 19, -5 }, + { 5, 19 }, + { 5, -19 }, + { -5, 19 }, + { -5, -19 }, + { -19, 5 }, + { -19, -5 }, + { 18, 8 }, + { 18, -8 }, + { 8, 18 }, + { 8, -18 }, + { -8, 18 }, + { -8, -18 }, + { -18, 8 }, + { -18, -8 }, + { 17, 10 }, + { 17, -10 }, + { 10, 17 }, + { 10, -17 }, + { -10, 17 }, + { -10, -17 }, + { -17, 10 }, + { -17, -10 }, + { 14, 14 }, + { 14, -14 }, + { -14, 14 }, + { -14, -14 }, + { 15, 13 }, + { 15, -13 }, + { 13, 15 }, + { 13, -15 }, + { -13, 15 }, + { -13, -15 }, + { -15, 13 }, + { -15, -13 }, + { 19, 6 }, + { 19, -6 }, + { 6, 19 }, + { 6, -19 }, + { -6, 19 }, + { -6, -19 }, + { -19, 6 }, + { -19, -6 }, + { 20, 0 }, + { 16, 12 }, + { 16, -12 }, + { 12, 16 }, + { 12, -16 }, + { 0, 20 }, + { 0, -20 }, + { -12, 16 }, + { -12, -16 }, + { -16, 12 }, + { -16, -12 }, + { -20, 0 }, + { 20, 1 }, + { 20, -1 }, + { 1, 20 }, + { 1, -20 }, + { -1, 20 }, + { -1, -20 }, + { -20, 1 }, + { -20, -1 }, + { 20, 2 }, + { 20, -2 }, + { 2, 20 }, + { 2, -20 }, + { -2, 20 }, + { -2, -20 }, + { -20, 2 }, + { -20, -2 }, + { 18, 9 }, + { 18, -9 }, + { 9, 18 }, + { 9, -18 }, + { -9, 18 }, + { -9, -18 }, + { -18, 9 }, + { -18, -9 }, + { 20, 3 }, + { 20, -3 }, + { 3, 20 }, + { 3, -20 }, + { -3, 20 }, + { -3, -20 }, + { -20, 3 }, + { -20, -3 }, + { 19, 7 }, + { 19, -7 }, + { 17, 11 }, + { 17, -11 }, + { 11, 17 }, + { 11, -17 }, + { 7, 19 }, + { 7, -19 }, + { -7, 19 }, + { -7, -19 }, + { -11, 17 }, + { -11, -17 }, + { -17, 11 }, + { -17, -11 }, + { -19, 7 }, + { -19, -7 }, + { 20, 4 }, + { 20, -4 }, + { 4, 20 }, + { 4, -20 }, + { -4, 20 }, + { -4, -20 }, + { -20, 4 }, + { -20, -4 }, + { 15, 14 }, + { 15, -14 }, + { 14, 15 }, + { 14, -15 }, + { -14, 15 }, + { -14, -15 }, + { -15, 14 }, + { -15, -14 }, + { 18, 10 }, + { 18, -10 }, + { 10, 18 }, + { 10, -18 }, + { -10, 18 }, + { -10, -18 }, + { -18, 10 }, + { -18, -10 }, + { 20, 5 }, + { 20, -5 }, + { 19, 8 }, + { 19, -8 }, + { 16, 13 }, + { 16, -13 }, + { 13, 16 }, + { 13, -16 }, + { 8, 19 }, + { 8, -19 }, + { 5, 20 }, + { 5, -20 }, + { -5, 20 }, + { -5, -20 }, + { -8, 19 }, + { -8, -19 }, + { -13, 16 }, + { -13, -16 }, + { -16, 13 }, + { -16, -13 }, + { -19, 8 }, + { -19, -8 }, + { -20, 5 }, + { -20, -5 }, + { 17, 12 }, + { 17, -12 }, + { 12, 17 }, + { 12, -17 }, + { -12, 17 }, + { -12, -17 }, + { -17, 12 }, + { -17, -12 }, + { 20, 6 }, + { 20, -6 }, + { 6, 20 }, + { 6, -20 }, + { -6, 20 }, + { -6, -20 }, + { -20, 6 }, + { -20, -6 }, + { 19, 9 }, + { 19, -9 }, + { 9, 19 }, + { 9, -19 }, + { -9, 19 }, + { -9, -19 }, + { -19, 9 }, + { -19, -9 }, + { 18, 11 }, + { 18, -11 }, + { 11, 18 }, + { 11, -18 }, + { -11, 18 }, + { -11, -18 }, + { -18, 11 }, + { -18, -11 }, + { 20, 7 }, + { 20, -7 }, + { 7, 20 }, + { 7, -20 }, + { -7, 20 }, + { -7, -20 }, + { -20, 7 }, + { -20, -7 }, + { 15, 15 }, + { 15, -15 }, + { -15, 15 }, + { -15, -15 }, + { 16, 14 }, + { 16, -14 }, + { 14, 16 }, + { 14, -16 }, + { -14, 16 }, + { -14, -16 }, + { -16, 14 }, + { -16, -14 }, + { 17, 13 }, + { 17, -13 }, + { 13, 17 }, + { 13, -17 }, + { -13, 17 }, + { -13, -17 }, + { -17, 13 }, + { -17, -13 }, + { 19, 10 }, + { 19, -10 }, + { 10, 19 }, + { 10, -19 }, + { -10, 19 }, + { -10, -19 }, + { -19, 10 }, + { -19, -10 }, + { 20, 8 }, + { 20, -8 }, + { 8, 20 }, + { 8, -20 }, + { -8, 20 }, + { -8, -20 }, + { -20, 8 }, + { -20, -8 }, + { 18, 12 }, + { 18, -12 }, + { 12, 18 }, + { 12, -18 }, + { -12, 18 }, + { -12, -18 }, + { -18, 12 }, + { -18, -12 }, + { 20, 9 }, + { 20, -9 }, + { 16, 15 }, + { 16, -15 }, + { 15, 16 }, + { 15, -16 }, + { 9, 20 }, + { 9, -20 }, + { -9, 20 }, + { -9, -20 }, + { -15, 16 }, + { -15, -16 }, + { -16, 15 }, + { -16, -15 }, + { -20, 9 }, + { -20, -9 }, + { 19, 11 }, + { 19, -11 }, + { 11, 19 }, + { 11, -19 }, + { -11, 19 }, + { -11, -19 }, + { -19, 11 }, + { -19, -11 }, + { 17, 14 }, + { 17, -14 }, + { 14, 17 }, + { 14, -17 }, + { -14, 17 }, + { -14, -17 }, + { -17, 14 }, + { -17, -14 }, + { 18, 13 }, + { 18, -13 }, + { 13, 18 }, + { 13, -18 }, + { -13, 18 }, + { -13, -18 }, + { -18, 13 }, + { -18, -13 }, + { 20, 10 }, + { 20, -10 }, + { 10, 20 }, + { 10, -20 }, + { -10, 20 }, + { -10, -20 }, + { -20, 10 }, + { -20, -10 }, + { 19, 12 }, + { 19, -12 }, + { 12, 19 }, + { 12, -19 }, + { -12, 19 }, + { -12, -19 }, + { -19, 12 }, + { -19, -12 }, + { 16, 16 }, + { 16, -16 }, + { -16, 16 }, + { -16, -16 }, + { 17, 15 }, + { 17, -15 }, + { 15, 17 }, + { 15, -17 }, + { -15, 17 }, + { -15, -17 }, + { -17, 15 }, + { -17, -15 }, + { 18, 14 }, + { 18, -14 }, + { 14, 18 }, + { 14, -18 }, + { -14, 18 }, + { -14, -18 }, + { -18, 14 }, + { -18, -14 }, + { 20, 11 }, + { 20, -11 }, + { 11, 20 }, + { 11, -20 }, + { -11, 20 }, + { -11, -20 }, + { -20, 11 }, + { -20, -11 }, + { 19, 13 }, + { 19, -13 }, + { 13, 19 }, + { 13, -19 }, + { -13, 19 }, + { -13, -19 }, + { -19, 13 }, + { -19, -13 }, + { 20, 12 }, + { 20, -12 }, + { 12, 20 }, + { 12, -20 }, + { -12, 20 }, + { -12, -20 }, + { -20, 12 }, + { -20, -12 }, + { 17, 16 }, + { 17, -16 }, + { 16, 17 }, + { 16, -17 }, + { -16, 17 }, + { -16, -17 }, + { -17, 16 }, + { -17, -16 }, + { 18, 15 }, + { 18, -15 }, + { 15, 18 }, + { 15, -18 }, + { -15, 18 }, + { -15, -18 }, + { -18, 15 }, + { -18, -15 }, + { 19, 14 }, + { 19, -14 }, + { 14, 19 }, + { 14, -19 }, + { -14, 19 }, + { -14, -19 }, + { -19, 14 }, + { -19, -14 }, + { 20, 13 }, + { 20, -13 }, + { 13, 20 }, + { 13, -20 }, + { -13, 20 }, + { -13, -20 }, + { -20, 13 }, + { -20, -13 }, + { 17, 17 }, + { 17, -17 }, + { -17, 17 }, + { -17, -17 }, + { 18, 16 }, + { 18, -16 }, + { 16, 18 }, + { 16, -18 }, + { -16, 18 }, + { -16, -18 }, + { -18, 16 }, + { -18, -16 }, + { 19, 15 }, + { 19, -15 }, + { 15, 19 }, + { 15, -19 }, + { -15, 19 }, + { -15, -19 }, + { -19, 15 }, + { -19, -15 }, + { 20, 14 }, + { 20, -14 }, + { 14, 20 }, + { 14, -20 }, + { -14, 20 }, + { -14, -20 }, + { -20, 14 }, + { -20, -14 }, + { 18, 17 }, + { 18, -17 }, + { 17, 18 }, + { 17, -18 }, + { -17, 18 }, + { -17, -18 }, + { -18, 17 }, + { -18, -17 }, + { 19, 16 }, + { 19, -16 }, + { 16, 19 }, + { 16, -19 }, + { -16, 19 }, + { -16, -19 }, + { -19, 16 }, + { -19, -16 }, + { 20, 15 }, + { 20, -15 }, + { 15, 20 }, + { 15, -20 }, + { -15, 20 }, + { -15, -20 }, + { -20, 15 }, + { -20, -15 }, + { 18, 18 }, + { 18, -18 }, + { -18, 18 }, + { -18, -18 }, + { 19, 17 }, + { 19, -17 }, + { 17, 19 }, + { 17, -19 }, + { -17, 19 }, + { -17, -19 }, + { -19, 17 }, + { -19, -17 }, + { 20, 16 }, + { 20, -16 }, + { 16, 20 }, + { 16, -20 }, + { -16, 20 }, + { -16, -20 }, + { -20, 16 }, + { -20, -16 }, + { 19, 18 }, + { 19, -18 }, + { 18, 19 }, + { 18, -19 }, + { -18, 19 }, + { -18, -19 }, + { -19, 18 }, + { -19, -18 }, + { 20, 17 }, + { 20, -17 }, + { 17, 20 }, + { 17, -20 }, + { -17, 20 }, + { -17, -20 }, + { -20, 17 }, + { -20, -17 }, + { 19, 19 }, + { 19, -19 }, + { -19, 19 }, + { -19, -19 }, + { 20, 18 }, + { 20, -18 }, + { 18, 20 }, + { 18, -20 }, + { -18, 20 }, + { -18, -20 }, + { -20, 18 }, + { -20, -18 }, + { 20, 19 }, + { 20, -19 }, + { 19, 20 }, + { 19, -20 }, + { -19, 20 }, + { -19, -20 }, + { -20, 19 }, + { -20, -19 }, + { 20, 20 }, + { 20, -20 }, + { -20, 20 }, + { -20, -20 }, +} + +return Public diff --git a/utils/math/get_noise.lua b/utils/math/get_noise.lua new file mode 100644 index 00000000..ad5fd690 --- /dev/null +++ b/utils/math/get_noise.lua @@ -0,0 +1,160 @@ +local simplex_noise = require('utils.math.simplex_noise').d2 + +--add or use noise templates from here +local noises = { + ['bb_biterland'] = { + { modifier = 0.001, weight = 1 }, + { modifier = 0.01, weight = 0.35 }, + { modifier = 0.1, weight = 0.015 }, + }, + ['bb_ore'] = { + { modifier = 0.0042, weight = 1 }, + { modifier = 0.031, weight = 0.08 }, + { modifier = 0.1, weight = 0.025 }, + }, + ['cave_ponds'] = { { modifier = 0.01, weight = 1 }, { modifier = 0.1, weight = 0.06 } }, + ['smol_areas'] = { { modifier = 0.01, weight = 1 }, { modifier = 0.1, weight = 0.02 }, { + modifier = 0.1, + weight = 0.03, + } }, + ['cave_worms'] = { { modifier = 0.001, weight = 1 }, { modifier = 0.1, weight = 0.06 } }, + ['cave_rivers'] = { + { modifier = 0.005, weight = 1 }, + { modifier = 0.01, weight = 0.25 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['cave_rivers_2'] = { + { modifier = 0.003, weight = 1 }, + { modifier = 0.01, weight = 0.21 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['cave_rivers_3'] = { + { modifier = 0.002, weight = 1 }, + { modifier = 0.01, weight = 0.15 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['cave_rivers_4'] = { + { modifier = 0.001, weight = 1 }, + { modifier = 0.01, weight = 0.11 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['decoratives'] = { + { modifier = 0.03, weight = 1 }, + { modifier = 0.05, weight = 0.25 }, + { modifier = 0.1, weight = 0.05 }, + }, + ['dungeons'] = { { modifier = 0.0025, weight = 1 }, { modifier = 0.005, weight = 0.25 } }, + ['dungeon_sewer'] = { + { modifier = 0.0005, weight = 1 }, + { modifier = 0.005, weight = 0.015 }, + { modifier = 0.025, weight = 0.0015 }, + }, + ['large_caves'] = { + { modifier = 0.0033, weight = 1 }, + { modifier = 0.01, weight = 0.22 }, + { modifier = 0.05, weight = 0.05 }, + { modifier = 0.1, weight = 0.04 }, + }, + ['n1'] = { { modifier = 0.0001, weight = 1 } }, + ['n2'] = { { modifier = 0.001, weight = 1 } }, + ['n3'] = { { modifier = 0.01, weight = 1 } }, + ['n4'] = { { modifier = 0.1, weight = 1 } }, + ['n5'] = { { modifier = 0.07, weight = 1 } }, + ['watery_world'] = { + { modifier = 0.0007, weight = 1 }, + { modifier = 0.01, weight = 0.02 }, + { modifier = 0.1, weight = 0.005 }, + }, + ['no_rocks'] = { + { modifier = 0.0033, weight = 1 }, + { modifier = 0.01, weight = 0.22 }, + { modifier = 0.05, weight = 0.05 }, + { modifier = 0.1, weight = 0.04 }, + }, + ['no_rocks_2'] = { { modifier = 0.013, weight = 1 }, { modifier = 0.1, weight = 0.1 } }, + ['oasis'] = { + { modifier = 0.0015, weight = 1 }, + { modifier = 0.0025, weight = 0.5 }, + { modifier = 0.01, weight = 0.15 }, + { modifier = 0.1, weight = 0.017 }, + }, + ['scrapyard'] = { + { modifier = 0.005, weight = 1 }, + { modifier = 0.01, weight = 0.35 }, + { modifier = 0.05, weight = 0.23 }, + { modifier = 0.1, weight = 0.11 }, + }, + ['big_cave'] = { + { modifier = 0.003, weight = 1 }, + { modifier = 0.02, weight = 0.05 }, + { modifier = 0.15, weight = 0.02 }, + }, + ['small_caves'] = { + { modifier = 0.008, weight = 1 }, + { modifier = 0.03, weight = 0.15 }, + { modifier = 0.25, weight = 0.05 }, + }, + ['small_caves_2'] = { + { modifier = 0.009, weight = 1 }, + { modifier = 0.05, weight = 0.25 }, + { modifier = 0.25, weight = 0.05 }, + }, + ['forest_location'] = { + { modifier = 0.006, weight = 1 }, + { modifier = 0.01, weight = 0.25 }, + { modifier = 0.05, weight = 0.15 }, + { modifier = 0.1, weight = 0.05 }, + }, + ['forest_density'] = { + { modifier = 0.01, weight = 1 }, + { modifier = 0.05, weight = 0.5 }, + { modifier = 0.1, weight = 0.025 }, + }, + ['cave_miner_01'] = { + { modifier = 0.0015, weight = 1 }, + { modifier = 0.0030, weight = 0.15 }, + { modifier = 0.0100, weight = 0.025 }, + { modifier = 0.1000, weight = 0.01 }, + }, + ['cave_miner_02'] = { + { modifier = 0.006, weight = 1 }, + { modifier = 0.02, weight = 0.15 }, + { modifier = 0.25, weight = 0.025 }, + }, + ['cm_ponds'] = { { modifier = 0.025, weight = 1 }, { modifier = 0.05, weight = 0.25 }, { + modifier = 0.1, + weight = 0.05, + } }, + ['cm_ocean'] = { + { modifier = 0.002, weight = 1 }, + { modifier = 0.004, weight = 1 }, + { modifier = 0.02, weight = 0.05 }, + }, + ['scrap_towny_ffa'] = { + { modifier = 0.005, weight = 1 }, + { modifier = 0.025, weight = 0.25 }, + { modifier = 0.1, weight = 0.125 }, + { modifier = 0.01, weight = 0.025 }, + }, + ['journey_swamps'] = { + { modifier = 0.02, weight = 1 }, + { modifier = 0.04, weight = 0.35 }, + { modifier = 0.1, weight = 0.08 }, + }, +} + +--returns a float number between -1 and 1 +local function get_noise(name, pos, seed) + local noise = 0 + local d = 0 + for i = 1, #noises[name] do + local mod = noises[name] + noise = noise + simplex_noise(pos.x * mod[i].modifier, pos.y * mod[i].modifier, seed) * mod[i].weight + d = d + mod[i].weight + seed = seed + 10000 + end + noise = noise / d + return noise +end + +return get_noise diff --git a/utils/math/get_perlin.lua b/utils/math/get_perlin.lua new file mode 100644 index 00000000..ec6b39e3 --- /dev/null +++ b/utils/math/get_perlin.lua @@ -0,0 +1,149 @@ +local simplex_noise = require('utils.math.simplex_noise').d2 + +--add or use noise templates from here +local noises = { + ['bb_biterland'] = { + { modifier = 0.001, weight = 1 }, + { modifier = 0.01, weight = 0.35 }, + { modifier = 0.1, weight = 0.015 }, + }, + ['bb_ore'] = { + { modifier = 0.0042, weight = 1 }, + { modifier = 0.031, weight = 0.08 }, + { modifier = 0.1, weight = 0.025 }, + }, + ['cave_ponds'] = { { modifier = 0.01, weight = 1 }, { modifier = 0.1, weight = 0.06 } }, + ['smol_areas'] = { { modifier = 0.01, weight = 1 }, { modifier = 0.1, weight = 0.02 }, { + modifier = 0.1, + weight = 0.03, + } }, + ['cave_worms'] = { { modifier = 0.001, weight = 1 }, { modifier = 0.1, weight = 0.06 } }, + ['cave_rivers'] = { + { modifier = 0.005, weight = 1 }, + { modifier = 0.01, weight = 0.25 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['cave_rivers_2'] = { + { modifier = 0.003, weight = 1 }, + { modifier = 0.01, weight = 0.21 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['cave_rivers_3'] = { + { modifier = 0.002, weight = 1 }, + { modifier = 0.01, weight = 0.15 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['cave_rivers_4'] = { + { modifier = 0.001, weight = 1 }, + { modifier = 0.01, weight = 0.11 }, + { modifier = 0.05, weight = 0.01 }, + }, + ['decoratives'] = { + { modifier = 0.03, weight = 1 }, + { modifier = 0.05, weight = 0.25 }, + { modifier = 0.1, weight = 0.05 }, + }, + ['dungeons'] = { { modifier = 0.0025, weight = 1 }, { modifier = 0.005, weight = 0.25 } }, + ['dungeon_sewer'] = { + { modifier = 0.0005, weight = 1 }, + { modifier = 0.005, weight = 0.015 }, + { modifier = 0.025, weight = 0.0015 }, + }, + ['large_caves'] = { + { modifier = 0.0033, weight = 1 }, + { modifier = 0.01, weight = 0.22 }, + { modifier = 0.05, weight = 0.05 }, + { modifier = 0.1, weight = 0.04 }, + }, + ['n1'] = { { modifier = 0.0001, weight = 1 } }, + ['n2'] = { { modifier = 0.001, weight = 1 } }, + ['n3'] = { { modifier = 0.01, weight = 1 } }, + ['n4'] = { { modifier = 0.1, weight = 1 } }, + ['n5'] = { { modifier = 0.07, weight = 1 } }, + ['watery_world'] = { + { modifier = 0.0007, weight = 1 }, + { modifier = 0.01, weight = 0.02 }, + { modifier = 0.1, weight = 0.005 }, + }, + ['no_rocks'] = { + { modifier = 0.0033, weight = 1 }, + { modifier = 0.01, weight = 0.22 }, + { modifier = 0.05, weight = 0.05 }, + { modifier = 0.1, weight = 0.04 }, + }, + ['no_rocks_2'] = { { modifier = 0.013, weight = 1 }, { modifier = 0.1, weight = 0.1 } }, + ['oasis'] = { + { modifier = 0.0015, weight = 1 }, + { modifier = 0.0025, weight = 0.5 }, + { modifier = 0.01, weight = 0.15 }, + { modifier = 0.1, weight = 0.017 }, + }, + ['scrapyard'] = { + { modifier = 0.005, weight = 1 }, + { modifier = 0.01, weight = 0.35 }, + { modifier = 0.05, weight = 0.23 }, + { modifier = 0.1, weight = 0.11 }, + }, + ['big_cave'] = { + { modifier = 0.003, weight = 1 }, + { modifier = 0.02, weight = 0.05 }, + { modifier = 0.15, weight = 0.02 }, + }, + ['small_caves'] = { + { modifier = 0.008, weight = 1 }, + { modifier = 0.03, weight = 0.15 }, + { modifier = 0.25, weight = 0.05 }, + }, + ['small_caves_2'] = { + { modifier = 0.009, weight = 1 }, + { modifier = 0.05, weight = 0.25 }, + { modifier = 0.25, weight = 0.05 }, + }, + ['forest_location'] = { + { modifier = 0.006, weight = 1 }, + { modifier = 0.01, weight = 0.25 }, + { modifier = 0.05, weight = 0.15 }, + { modifier = 0.1, weight = 0.05 }, + }, + ['forest_density'] = { + { modifier = 0.01, weight = 1 }, + { modifier = 0.05, weight = 0.5 }, + { modifier = 0.1, weight = 0.025 }, + }, + ['cave_miner_01'] = { + { modifier = 0.002, weight = 1 }, + { modifier = 0.003, weight = 0.5 }, + { modifier = 0.01, weight = 0.01 }, + { modifier = 0.1, weight = 0.015 }, + }, + ['cave_miner_02'] = { + { modifier = 0.006, weight = 1 }, + { modifier = 0.02, weight = 0.15 }, + { modifier = 0.25, weight = 0.025 }, + }, + ['cm_ponds'] = { { modifier = 0.025, weight = 1 }, { modifier = 0.05, weight = 0.25 }, { + modifier = 0.1, + weight = 0.05, + } }, + ['cm_ocean'] = { + { modifier = 0.002, weight = 1 }, + { modifier = 0.004, weight = 1 }, + { modifier = 0.02, weight = 0.05 }, + }, +} + +--returns a float number between -1 and 1 +local function get_noise(name, pos, seed) + local noise = 0 + local d = 0 + for i = 1, #noises[name] do + local mod = noises[name] + noise = noise + simplex_noise(pos.x * mod[i].modifier, pos.y * mod[i].modifier, seed, 0xF) * mod[i].weight + d = d + mod[i].weight + seed = seed + seed / seed + end + noise = noise / d + return noise +end + +return get_noise diff --git a/utils/math/math.lua b/utils/math/math.lua new file mode 100644 index 00000000..be33a58c --- /dev/null +++ b/utils/math/math.lua @@ -0,0 +1,35 @@ +local Public = {} + +-- Using localized math functions is better for performance reasons: +Public.random = math.random +Public.randomseed = math.randomseed +Public.sqrt = math.sqrt +Public.min = math.min +Public.max = math.max +Public.rad = math.rad +Public.floor = math.floor +Public.abs = math.abs +Public.ceil = math.ceil +Public.log = math.log +Public.atan = math.atan +Public.sin = math.sin +Public.cos = math.cos +Public.pi = math.pi +Public.deg = math.deg +Public.round = math.round + +function Public.clamp(min, max, number) + if number < min then + return min + elseif number > max then + return max + else + return number + end +end + +function Public.sgn(number) + return number > 0 and 1 or (number == 0 and 0 or -1) +end + +return Public diff --git a/utils/math/perlin_noise.lua b/utils/math/perlin_noise.lua new file mode 100644 index 00000000..b8e20e39 --- /dev/null +++ b/utils/math/perlin_noise.lua @@ -0,0 +1,400 @@ +local band = bit32.band +local floor = math.floor +local Perlin = {} +local p = {} + +-- Hash lookup table as defined by Ken Perlin +-- This is a randomly arranged array of all numbers from 0-255 inclusive +local permutation = { + 151, + 160, + 137, + 91, + 90, + 15, + 131, + 13, + 201, + 95, + 96, + 53, + 194, + 233, + 7, + 225, + 140, + 36, + 103, + 30, + 69, + 142, + 8, + 99, + 37, + 240, + 21, + 10, + 23, + 190, + 6, + 148, + 247, + 120, + 234, + 75, + 0, + 26, + 197, + 62, + 94, + 252, + 219, + 203, + 117, + 35, + 11, + 32, + 57, + 177, + 33, + 88, + 237, + 149, + 56, + 87, + 174, + 20, + 125, + 136, + 171, + 168, + 68, + 175, + 74, + 165, + 71, + 134, + 139, + 48, + 27, + 166, + 77, + 146, + 158, + 231, + 83, + 111, + 229, + 122, + 60, + 211, + 133, + 230, + 220, + 105, + 92, + 41, + 55, + 46, + 245, + 40, + 244, + 102, + 143, + 54, + 65, + 25, + 63, + 161, + 1, + 216, + 80, + 73, + 209, + 76, + 132, + 187, + 208, + 89, + 18, + 169, + 200, + 196, + 135, + 130, + 116, + 188, + 159, + 86, + 164, + 100, + 109, + 198, + 173, + 186, + 3, + 64, + 52, + 217, + 226, + 250, + 124, + 123, + 5, + 202, + 38, + 147, + 118, + 126, + 255, + 82, + 85, + 212, + 207, + 206, + 59, + 227, + 47, + 16, + 58, + 17, + 182, + 189, + 28, + 42, + 223, + 183, + 170, + 213, + 119, + 248, + 152, + 2, + 44, + 154, + 163, + 70, + 221, + 153, + 101, + 155, + 167, + 43, + 172, + 9, + 129, + 22, + 39, + 253, + 19, + 98, + 108, + 110, + 79, + 113, + 224, + 232, + 178, + 185, + 112, + 104, + 218, + 246, + 97, + 228, + 251, + 34, + 242, + 193, + 238, + 210, + 144, + 12, + 191, + 179, + 162, + 241, + 81, + 51, + 145, + 235, + 249, + 14, + 239, + 107, + 49, + 192, + 214, + 31, + 181, + 199, + 106, + 157, + 184, + 84, + 204, + 176, + 115, + 121, + 50, + 45, + 127, + 4, + 150, + 254, + 138, + 236, + 205, + 93, + 222, + 114, + 67, + 29, + 24, + 72, + 243, + 141, + 128, + 195, + 78, + 66, + 215, + 61, + 156, + 180, +} + +-- p is used to hash unit cube coordinates to [0, 255] +for i = 0, 255 do + -- Convert to 0 based index table + p[i] = permutation[i + 1] + -- Repeat the array to avoid buffer overflow in hash function + p[i + 256] = permutation[i + 1] +end + +-- Gradient function finds dot product between pseudorandom gradient vector +-- and the vector from input coordinate to a unit cube vertex +local dot_product = { + [0x0] = function(x, y) + return x + y + end, + [0x1] = function(x, y) + return -x + y + end, + [0x2] = function(x, y) + return x - y + end, + [0x3] = function(x, y) + return -x - y + end, + [0x4] = function(x, z) + return x + z + end, + [0x5] = function(x, z) + return -x + z + end, + [0x6] = function(x, z) + return x - z + end, + [0x7] = function(x, z) + return -x - z + end, + [0x8] = function(y, z) + return y + z + end, + [0x9] = function(y, z) + return -y + z + end, + [0xA] = function(y, z) + return y - z + end, + [0xB] = function(y, z) + return -y - z + end, + [0xC] = function(x, y) + return y + x + end, + [0xD] = function(y, z) + return -y + z + end, + [0xE] = function(x, y) + return y - x + end, + [0xF] = function(y, z) + return -y - z + end, +} +local function grad(hash, x, y, bit) + bit = bit or 1 + return dot_product[band(hash, bit)](x, y) +end + +-- Fade function is used to smooth final output +local function fade(t) + return t * t * t * (t * (t * 6 - 15) + 10) +end + +local function lerp(t, a, bs) + return a + t * (bs - a) +end + +-- Return range: [-1, 1] +function Perlin.noise(x, y, z, bit) + y = y or 0 + z = z or 0 + + -- This prevents integer inputs returning 0, which casues 'straight line' artifacts. + x = x - 0.55077056353912 + y = y - 0.131357755512 + z = z - 0.20474238274619 + + -- Calculate the "unit cube" that the point asked will be located in + local xi = band(floor(x), 255) + local yi = band(floor(y), 255) + local zi = band(floor(z), 255) + + -- Next we calculate the location (from 0 to 1) in that cube + x = x - floor(x) + y = y - floor(y) + z = z - floor(z) + + -- We also fade the location to smooth the result + local u = fade(x) + local v = fade(y) + local w = fade(z) + + -- Hash all 8 unit cube coordinates surrounding input coordinate + local A, AA, AB, AAA, ABA, AAB, ABB, B, BA, BB, BAA, BBA, BAB, BBB + A = p[xi] + yi + AA = p[A] + zi + AB = p[A + 1] + zi + AAA = p[AA] + ABA = p[AB] + AAB = p[AA + 1] + ABB = p[AB + 1] + + B = p[xi + 1] + yi + BA = p[B] + zi + BB = p[B + 1] + zi + BAA = p[BA] + BBA = p[BB] + BAB = p[BA + 1] + BBB = p[BB + 1] + + -- Take the weighted average between all 8 unit cube coordinates + return lerp( + w, + lerp( + v, + lerp(u, grad(AAA, x, y, bit), grad(BAA, x - 1, y, bit)), + lerp(u, grad(ABA, x, y - 1, bit), grad(BBA, x - 1, y - 1, bit)) + ), + lerp( + v, + lerp(u, grad(AAB, x, y, bit), grad(BAB, x - 1, y, bit)), + lerp(u, grad(ABB, x, y - 1, bit), grad(BBB, x - 1, y - 1, bit)) + ) + ) +end + +return Perlin diff --git a/utils/math/raffle.lua b/utils/math/raffle.lua new file mode 100644 index 00000000..55063fb4 --- /dev/null +++ b/utils/math/raffle.lua @@ -0,0 +1,93 @@ +local Math = require('maps.spaghetti_wars.math') + +local Public = {} + +-- A weighted random choice amongst several options. +-- Arguments can be provided EITHER as {o1, o2, ...}, {v1, v2, ...} OR as simply {o1 = w1, o2 = w2, o3 = w3} in the first argument. +function Public.raffle(arg1, arg2) + local options, weights_table + local total_weight = 0 + + if arg2 then + options = arg1 + weights_table = arg2 + for _, weight in ipairs(weights_table) do + if weight > 0 then + total_weight = total_weight + weight + end + -- negative weights treated as zero + end + else + options = {} + weights_table = {} + for option, weight in pairs(arg1) do + arg1.insert(options, option) + arg1.insert(weights_table, weight) + if weight > 0 then + total_weight = total_weight + weight + end + -- negative weights treated as zero + end + end + + -- Fallback: All weights are zero/negative + if total_weight <= 0 then + return options[Math.random(1, #options)] + end + + local cumulative_probability = 0 + local rng = Math.random() + for i, option in ipairs(options) do + local weight = weights_table[i] + cumulative_probability = cumulative_probability + weight / total_weight + if rng <= cumulative_probability then + return option + end + end + + -- Fallback: Unlikely case of floating point error: + return options[Math.random(1, #options)] +end + +-- A slightly more sophisticated raffle, taking a parameter which is used to vary the weights according to some rule. For example, the raffle could depend on the game completion progress. +-- +---@param parameter number The parameter value to use for the raffle. +---@param data table Table with key-value pairs of the form option = {overall_weight, min_param, max_param, shape}, where: +--- - overall_weight: The weight of the option in the raffle. +--- - min_param: The minimum value of the parameter for which the option is eligible. +--- - max_param: The maximum value of the parameter for which the option is eligible. +--- - shape: An optional parameter for the shape of the weight curve with respect to the parameter. Defaults to 'flat', in which case the weight will be overall_weight as long as the parameter is within the range [min_param, max_param]. If 'bump', the weight is triangle-shaped: it has a peak of 2 * overall_weight at the midpoint of the range, and is zero at either end. +function Public.raffle_with_parameter(parameter, data) + local raffle = {} + + for option, weight_data in pairs(data) do + local overall_weight = weight_data.overall_weight or weight_data[1] + local min_param = weight_data.min_param or weight_data[2] + local max_param = weight_data.max_param or weight_data[3] + local shape = weight_data.shape or weight_data[4] or 'flat' + + if shape == 'flat' then + if (not min_param) or (parameter >= min_param) then + if (not max_param) or (parameter <= max_param) then + raffle[option] = overall_weight + end + end + elseif shape == 'bump' then + if min_param and max_param and parameter >= min_param and parameter <= max_param then + if min_param == max_param and parameter == min_param then + raffle[option] = overall_weight + else + local midpoint = (min_param + max_param) / 2 + local peak = 2 * overall_weight + local slope = peak / ((max_param - min_param) / 2) + local difference = Math.abs(parameter - midpoint) + raffle[option] = peak * (1 - difference * slope) + end + end + end + end + + return Public.raffle(raffle) +end + +return Public diff --git a/utils/simplex_noise.lua b/utils/math/simplex_noise.lua similarity index 100% rename from utils/simplex_noise.lua rename to utils/math/simplex_noise.lua diff --git a/utils/math/stats.lua b/utils/math/stats.lua new file mode 100644 index 00000000..93ba17a8 --- /dev/null +++ b/utils/math/stats.lua @@ -0,0 +1,112 @@ +local Public = {} + +-- Get the mean value of a table +function Public.mean(t) + local sum = 0 + local count = 0 + + for k, v in pairs(t) do + if type(v) == 'number' then + sum = sum + v + count = count + 1 + end + end + + return (sum / count) +end + +-- Get the mode of a table. Returns a table of values. +-- Works on anything (not just numbers). +function Public.mode(t) + local counts = {} + + for k, v in pairs(t) do + if counts[v] == nil then + counts[v] = 1 + else + counts[v] = counts[v] + 1 + end + end + + local biggestCount = 0 + + for k, v in pairs(counts) do + if v > biggestCount then + biggestCount = v + end + end + + local temp = {} + + for k, v in pairs(counts) do + if v == biggestCount then + table.insert(temp, k) + end + end + + return temp +end + +-- Get the median of a table. +function Public.median(t) + local temp = {} + + -- deep copy table so that when we sort it, the original is unchanged + -- also weed out any non numbers + for k, v in pairs(t) do + if type(v) == 'number' then + table.insert(temp, v) + end + end + + table.sort(temp) + + -- If we have an even number of table elements or odd. + if math.fmod(#temp, 2) == 0 then + -- return mean value of middle two elements + return (temp[#temp / 2] + temp[(#temp / 2) + 1]) / 2 + else + -- return middle element + return temp[math.ceil(#temp / 2)] + end +end + +-- Get the standard deviation of a table +function Public.standardDeviation(t) + local m + local vm + local sum = 0 + local count = 0 + local result + + m = Public.mean(t) + + for k, v in pairs(t) do + if type(v) == 'number' then + vm = v - m + sum = sum + (vm * vm) + count = count + 1 + end + end + + result = math.sqrt(sum / (count - 1)) + + return result +end + +-- Get the max and min for a table +function Public.maxmin(t) + local max = -math.huge + local min = math.huge + + for k, v in pairs(t) do + if type(v) == 'number' then + max = math.max(max, v) + min = math.min(min, v) + end + end + + return max, min +end + +return Public diff --git a/utils/perlin_noise.lua b/utils/perlin_noise.lua deleted file mode 100644 index 0b88e08d..00000000 --- a/utils/perlin_noise.lua +++ /dev/null @@ -1,392 +0,0 @@ -local band = bit32.band -local floor = math.floor -local Perlin = {} -local p = {} - --- Hash lookup table as defined by Ken Perlin --- This is a randomly arranged array of all numbers from 0-255 inclusive -local permutation = { - 151, - 160, - 137, - 91, - 90, - 15, - 131, - 13, - 201, - 95, - 96, - 53, - 194, - 233, - 7, - 225, - 140, - 36, - 103, - 30, - 69, - 142, - 8, - 99, - 37, - 240, - 21, - 10, - 23, - 190, - 6, - 148, - 247, - 120, - 234, - 75, - 0, - 26, - 197, - 62, - 94, - 252, - 219, - 203, - 117, - 35, - 11, - 32, - 57, - 177, - 33, - 88, - 237, - 149, - 56, - 87, - 174, - 20, - 125, - 136, - 171, - 168, - 68, - 175, - 74, - 165, - 71, - 134, - 139, - 48, - 27, - 166, - 77, - 146, - 158, - 231, - 83, - 111, - 229, - 122, - 60, - 211, - 133, - 230, - 220, - 105, - 92, - 41, - 55, - 46, - 245, - 40, - 244, - 102, - 143, - 54, - 65, - 25, - 63, - 161, - 1, - 216, - 80, - 73, - 209, - 76, - 132, - 187, - 208, - 89, - 18, - 169, - 200, - 196, - 135, - 130, - 116, - 188, - 159, - 86, - 164, - 100, - 109, - 198, - 173, - 186, - 3, - 64, - 52, - 217, - 226, - 250, - 124, - 123, - 5, - 202, - 38, - 147, - 118, - 126, - 255, - 82, - 85, - 212, - 207, - 206, - 59, - 227, - 47, - 16, - 58, - 17, - 182, - 189, - 28, - 42, - 223, - 183, - 170, - 213, - 119, - 248, - 152, - 2, - 44, - 154, - 163, - 70, - 221, - 153, - 101, - 155, - 167, - 43, - 172, - 9, - 129, - 22, - 39, - 253, - 19, - 98, - 108, - 110, - 79, - 113, - 224, - 232, - 178, - 185, - 112, - 104, - 218, - 246, - 97, - 228, - 251, - 34, - 242, - 193, - 238, - 210, - 144, - 12, - 191, - 179, - 162, - 241, - 81, - 51, - 145, - 235, - 249, - 14, - 239, - 107, - 49, - 192, - 214, - 31, - 181, - 199, - 106, - 157, - 184, - 84, - 204, - 176, - 115, - 121, - 50, - 45, - 127, - 4, - 150, - 254, - 138, - 236, - 205, - 93, - 222, - 114, - 67, - 29, - 24, - 72, - 243, - 141, - 128, - 195, - 78, - 66, - 215, - 61, - 156, - 180 -} - --- p is used to hash unit cube coordinates to [0, 255] -for i = 0, 255 do - -- Convert to 0 based index table - p[i] = permutation[i + 1] - -- Repeat the array to avoid buffer overflow in hash function - p[i + 256] = permutation[i + 1] -end - --- Gradient function finds dot product between pseudorandom gradient vector --- and the vector from input coordinate to a unit cube vertex -local dot_product = { - [0x0] = function(x, y) - return x + y - end, - [0x1] = function(x, y) - return -x + y - end, - [0x2] = function(x, y) - return x - y - end, - [0x3] = function(x, y) - return -x - y - end, - [0x4] = function(x, z) - return x + z - end, - [0x5] = function(x, z) - return -x + z - end, - [0x6] = function(x, z) - return x - z - end, - [0x7] = function(x, z) - return -x - z - end, - [0x8] = function(y, z) - return y + z - end, - [0x9] = function(y, z) - return -y + z - end, - [0xA] = function(y, z) - return y - z - end, - [0xB] = function(y, z) - return -y - z - end, - [0xC] = function(x, y) - return y + x - end, - [0xD] = function(y, z) - return -y + z - end, - [0xE] = function(x, y) - return y - x - end, - [0xF] = function(y, z) - return -y - z - end -} -local function grad(hash, x, y, bit) - bit = bit or 1 - return dot_product[band(hash, bit)](x, y) -end - --- Fade function is used to smooth final output -local function fade(t) - return t * t * t * (t * (t * 6 - 15) + 10) -end - -local function lerp(t, a, bs) - return a + t * (bs - a) -end - --- Return range: [-1, 1] -function Perlin.noise(x, y, z, bit) - y = y or 0 - z = z or 0 - - -- This prevents integer inputs returning 0, which casues 'straight line' artifacts. - x = x - 0.55077056353912 - y = y - 0.131357755512 - z = z - 0.20474238274619 - - -- Calculate the "unit cube" that the point asked will be located in - local xi = band(floor(x), 255) - local yi = band(floor(y), 255) - local zi = band(floor(z), 255) - - -- Next we calculate the location (from 0 to 1) in that cube - x = x - floor(x) - y = y - floor(y) - z = z - floor(z) - - -- We also fade the location to smooth the result - local u = fade(x) - local v = fade(y) - local w = fade(z) - - -- Hash all 8 unit cube coordinates surrounding input coordinate - local A, AA, AB, AAA, ABA, AAB, ABB, B, BA, BB, BAA, BBA, BAB, BBB - A = p[xi] + yi - AA = p[A] + zi - AB = p[A + 1] + zi - AAA = p[AA] - ABA = p[AB] - AAB = p[AA + 1] - ABB = p[AB + 1] - - B = p[xi + 1] + yi - BA = p[B] + zi - BB = p[B + 1] + zi - BAA = p[BA] - BBA = p[BB] - BAB = p[BA + 1] - BBB = p[BB + 1] - - -- Take the weighted average between all 8 unit cube coordinates - return lerp( - w, - lerp(v, lerp(u, grad(AAA, x, y, bit), grad(BAA, x - 1, y, bit)), lerp(u, grad(ABA, x, y - 1, bit), grad(BBA, x - 1, y - 1, bit))), - lerp(v, lerp(u, grad(AAB, x, y, bit), grad(BAB, x - 1, y, bit)), lerp(u, grad(ABB, x, y - 1, bit), grad(BBB, x - 1, y - 1, bit))) - ) -end - -return Perlin diff --git a/utils/stats.lua b/utils/stats.lua deleted file mode 100644 index 0b6b8ad6..00000000 --- a/utils/stats.lua +++ /dev/null @@ -1,112 +0,0 @@ -local Public = {} - --- Get the mean value of a table -function Public.mean(t) - local sum = 0 - local count = 0 - - for k, v in pairs(t) do - if type(v) == 'number' then - sum = sum + v - count = count + 1 - end - end - - return (sum / count) -end - --- Get the mode of a table. Returns a table of values. --- Works on anything (not just numbers). -function Public.mode(t) - local counts = {} - - for k, v in pairs(t) do - if counts[v] == nil then - counts[v] = 1 - else - counts[v] = counts[v] + 1 - end - end - - local biggestCount = 0 - - for k, v in pairs(counts) do - if v > biggestCount then - biggestCount = v - end - end - - local temp = {} - - for k, v in pairs(counts) do - if v == biggestCount then - table.insert(temp, k) - end - end - - return temp -end - --- Get the median of a table. -function Public.median(t) - local temp = {} - - -- deep copy table so that when we sort it, the original is unchanged - -- also weed out any non numbers - for k, v in pairs(t) do - if type(v) == 'number' then - table.insert(temp, v) - end - end - - table.sort(temp) - - -- If we have an even number of table elements or odd. - if math.fmod(#temp, 2) == 0 then - -- return mean value of middle two elements - return (temp[#temp / 2] + temp[(#temp / 2) + 1]) / 2 - else - -- return middle element - return temp[math.ceil(#temp / 2)] - end -end - --- Get the standard deviation of a table -function Public.standardDeviation(t) - local m - local vm - local sum = 0 - local count = 0 - local result - - m = Public.mean(t) - - for k, v in pairs(t) do - if type(v) == 'number' then - vm = v - m - sum = sum + (vm * vm) - count = count + 1 - end - end - - result = math.sqrt(sum / (count - 1)) - - return result -end - --- Get the max and min for a table -function Public.maxmin(t) - local max = -math.huge - local min = math.huge - - for k, v in pairs(t) do - if type(v) == 'number' then - max = math.max(max, v) - min = math.min(min, v) - end - end - - return max, min -end - -return Public diff --git a/utils/table.lua b/utils/table.lua index 60906d3c..e3bdda55 100644 --- a/utils/table.lua +++ b/utils/table.lua @@ -1,6 +1,6 @@ ---@diagnostic disable: undefined-field --luacheck: globals table -local Stats = require 'utils.stats' +local Stats = require 'utils.math.stats' local Utils = require 'utils.utils' local random = math.random local floor = math.floor diff --git a/utils/terrain_layouts/caves.lua b/utils/terrain_layouts/caves.lua index 5196847c..c24b488c 100644 --- a/utils/terrain_layouts/caves.lua +++ b/utils/terrain_layouts/caves.lua @@ -21,7 +21,7 @@ require 'modules.rocks_heal_over_time' require 'modules.rocks_yield_ore_veins' require 'modules.no_deconstruction_of_neutral_entities' -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local Player_modifiers = require 'utils.player_modifiers' local math_random = math.random local math_floor = math.floor diff --git a/utils/terrain_layouts/scrap_01.lua b/utils/terrain_layouts/scrap_01.lua index 0e43da36..0c34b529 100644 --- a/utils/terrain_layouts/scrap_01.lua +++ b/utils/terrain_layouts/scrap_01.lua @@ -1,7 +1,7 @@ require 'modules.mineable_wreckage_yields_scrap' require 'modules.no_deconstruction_of_neutral_entities' -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local math_random = math.random local math_floor = math.floor local math_abs = math.abs diff --git a/utils/terrain_layouts/scrap_02.lua b/utils/terrain_layouts/scrap_02.lua index 2bd6b3ae..f43848ad 100644 --- a/utils/terrain_layouts/scrap_02.lua +++ b/utils/terrain_layouts/scrap_02.lua @@ -1,6 +1,6 @@ require 'modules.no_deconstruction_of_neutral_entities' -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local math_random = math.random local math_floor = math.floor local math_abs = math.abs diff --git a/utils/terrain_layouts/watery_world.lua b/utils/terrain_layouts/watery_world.lua index f235c905..76ddb5fe 100644 --- a/utils/terrain_layouts/watery_world.lua +++ b/utils/terrain_layouts/watery_world.lua @@ -13,7 +13,7 @@ SdABNhCuMsYIUyHfgdGB3mYrCRCCVC/EQOyG1IQPjwJs/Ywkv1oD sGMCGR/oImoOGCJBi6QhSlw4gUz3DXA8LzADuM5zHdgZAYxQKq+A MUgPEjihRgFoQUcmBkQAJi8BPc6XQMAy367Og==<<< ]] -local get_noise = require 'utils.get_noise' +local get_noise = require 'utils.math.get_noise' local math_random = math.random local math_floor = math.floor local math_abs = math.abs diff --git a/utils/tools/map_functions.lua b/utils/tools/map_functions.lua index 286baa26..f0a883e0 100644 --- a/utils/tools/map_functions.lua +++ b/utils/tools/map_functions.lua @@ -1,4 +1,4 @@ -local simplex_noise = require 'utils.simplex_noise' +local simplex_noise = require 'utils.math.simplex_noise' simplex_noise = simplex_noise.d2 local f = {} local math_random = math.random