mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-26 22:56:43 +02:00
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
This commit is contained in:
parent
eba6e052d2
commit
358160c247
@ -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
|
||||
|
@ -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 = {}
|
||||
|
@ -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' }
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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]
|
||||
|
@ -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 = {}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = {}
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = {
|
||||
|
@ -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'
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 = {
|
||||
|
@ -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' }
|
||||
|
@ -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 }
|
||||
|
@ -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'
|
||||
|
@ -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')
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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'
|
||||
|
@ -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 = {
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
||||
|
@ -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
|
||||
|
@ -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}},
|
||||
|
@ -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 }
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
@ -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 = {
|
||||
|
@ -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'
|
||||
|
@ -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 = {
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
|
@ -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
|
@ -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
|
1754
utils/math/geometry.lua
Normal file
1754
utils/math/geometry.lua
Normal file
File diff suppressed because it is too large
Load Diff
160
utils/math/get_noise.lua
Normal file
160
utils/math/get_noise.lua
Normal file
@ -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
|
149
utils/math/get_perlin.lua
Normal file
149
utils/math/get_perlin.lua
Normal file
@ -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
|
35
utils/math/math.lua
Normal file
35
utils/math/math.lua
Normal file
@ -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
|
400
utils/math/perlin_noise.lua
Normal file
400
utils/math/perlin_noise.lua
Normal file
@ -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
|
93
utils/math/raffle.lua
Normal file
93
utils/math/raffle.lua
Normal file
@ -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
|
112
utils/math/stats.lua
Normal file
112
utils/math/stats.lua
Normal file
@ -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
|
@ -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
|
112
utils/stats.lua
112
utils/stats.lua
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user