diff --git a/.luacheckrc b/.luacheckrc index 8bc150f1..773cd8f7 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -220,6 +220,12 @@ stds.factorio_control = { fields = {'print'} }, + commands = { + fields = { + 'add_command' + } + }, + rendering = { other_fields = false, read_only = true, @@ -342,6 +348,7 @@ stds.factorio_control = { "json_to_table", "kick_player", "merge_forces", + "pollution_statistics", "mute_player", "play_sound", "print", @@ -359,6 +366,7 @@ stds.factorio_control = { "show_message_dialog", "table_to_json", "take_screenshot", + "take_technology_screenshot", "unban_player", "unmute_player", @@ -1259,6 +1267,8 @@ stds.factorio_defines = { 'quick_bar_pick_slot', 'quick_bar_set_selected_page', 'quick_bar_set_slot', + 'flush_opened_entity_fluid', + 'flush_opened_entity_specific_fluid', 'remove_cables', 'remove_train_station', 'reset_assembling_machine', diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index c006c3fe..63452cd3 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -64,6 +64,11 @@ map_info_main_caption=M O U N T A I N F O R T R E S S map_info_sub_caption= ..diggy diggy choo choo.. map_info_text=The biters have catched the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research, will overhaul your mining equipment,\nreinforcing your pickaxe as well as increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nSome explosives may cause parts of the ceiling to crumble, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nYou may find some supply goods, if you enter the wagon.\nGood luck on your journey! +[mountain_fortress_v3] +map_info_main_caption=M O U N T A I N F O R T R E S S V3 +map_info_sub_caption= ..diggy diggy choo choo.. +map_info_text=The biters have catched the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research, will overhaul your mining equipment,\nreinforcing your pickaxe as well as increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause parts of the ceiling to crumble, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nYou may find some supply goods, if you enter the wagon.\n\nRandom buildings that generate resources can be found throughout the world.\n\nGood luck on your journey! + [chronosphere] map_info_main_caption=C H R O N O S P H E R E map_info_sub_caption= ..Comfylatron gone wild.. diff --git a/maps/mountain_fortress_v3/balance.lua b/maps/mountain_fortress_v3/balance.lua index 6b955eda..599bc342 100644 --- a/maps/mountain_fortress_v3/balance.lua +++ b/maps/mountain_fortress_v3/balance.lua @@ -1,6 +1,8 @@ local Event = require 'utils.event' local Difficulty = require 'modules.difficulty_vote' + local Public = {} + Public.events = {breached_wall = Event.generate_event_name('breached_wall')} function Public.init_enemy_weapon_damage() @@ -35,8 +37,6 @@ function Public.init_enemy_weapon_damage() end local function enemy_weapon_damage() - local Diff = Difficulty.get() - local e = game.forces.enemy local data = { @@ -58,7 +58,7 @@ local function enemy_weapon_damage() } for k, v in pairs(data) do - local new = Diff.difficulty_vote_value * v + local new = Difficulty.get().difficulty_vote_value * v local e_old = e.get_ammo_damage_modifier(k) diff --git a/maps/mountain_fortress_v3/biter_pets.lua b/maps/mountain_fortress_v3/biter_pets.lua index 54db27cb..6ea344d7 100644 --- a/maps/mountain_fortress_v3/biter_pets.lua +++ b/maps/mountain_fortress_v3/biter_pets.lua @@ -1,6 +1,5 @@ local WPT = require 'maps.mountain_fortress_v3.table' -local math_random = math.random local nom_msg = {'munch', 'munch', 'yum'} local Public = {} @@ -10,8 +9,8 @@ local function feed_floaty_text(unit) { name = 'flying-text', position = unit.position, - text = nom_msg[math_random(1, #nom_msg)], - color = {math_random(50, 100), 0, 255} + text = nom_msg[math.random(1, #nom_msg)], + color = {math.random(50, 100), 0, 255} } ) end @@ -21,11 +20,11 @@ local function floaty_hearts(entity, c) local b = 1.35 for a = 1, c, 1 do local p = { - (position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), - position.y + (b * -1 + math_random(0, b * 20) * 0.1) + (position.x + 0.4) + (b * -1 + math.random(0, b * 20) * 0.1), + position.y + (b * -1 + math.random(0, b * 20) * 0.1) } entity.surface.create_entity( - {name = 'flying-text', position = p, text = '♥', color = {math_random(150, 255), 0, 255}} + {name = 'flying-text', position = p, text = '♥', color = {math.random(150, 255), 0, 255}} ) end end @@ -69,7 +68,7 @@ local function feed_pet(unit) end unit.health = unit.health + 8 + math.floor(unit.prototype.max_health * 0.05) feed_floaty_text(unit) - floaty_hearts(unit, math_random(1, 2)) + floaty_hearts(unit, math.random(1, 2)) return true end @@ -94,7 +93,7 @@ function Public.biter_pets_tame_unit(player, unit, forced) end if not forced then - if math_random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then + if math.random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then feed_floaty_text(unit) return true end @@ -151,7 +150,7 @@ end local function on_player_changed_position(event) local this = WPT.get() - if math_random(1, 100) ~= 1 then + if math.random(1, 100) ~= 1 then return end local player = game.players[event.player_index] diff --git a/maps/mountain_fortress_v3/commands.lua b/maps/mountain_fortress_v3/commands.lua index 1a2e4f05..bfcf44e7 100644 --- a/maps/mountain_fortress_v3/commands.lua +++ b/maps/mountain_fortress_v3/commands.lua @@ -1,5 +1,6 @@ local Color = require 'utils.color_presets' local Task = require 'utils.task' +local Server = require 'utils.server' local WPT = require 'maps.mountain_fortress_v3.table' local mapkeeper = '[color=blue]Mapkeeper:[/color]' @@ -24,10 +25,10 @@ commands.add_command( local reset_map = require 'maps.mountain_fortress_v3.main'.reset_map local param = cmd.parameter - if param == 'restart' or param == 'shutdown' or param == 'reset' then + if param == 'restart' or param == 'shutdown' or param == 'reset' or param == 'restartnow' then goto continue else - p('[ERROR] Arguments are restart or shutdown or reset.') + p('[ERROR] Arguments are:\nrestart\nshutdown\nreset\nrestartnow') return end @@ -58,6 +59,11 @@ commands.add_command( p('[WARNING] Soft-reset is disabled! Server will restart from scenario.') return end + elseif param == 'restartnow' then + this.reset_are_you_sure = nil + p(player.name .. ' has restarted the game.') + Server.start_scenario('Mountain_Fortress_v3') + return elseif param == 'shutdown' then if this.shutdown then this.reset_are_you_sure = nil diff --git a/maps/mountain_fortress_v3/entities.lua b/maps/mountain_fortress_v3/entities.lua index 55b24e00..f65837c2 100644 --- a/maps/mountain_fortress_v3/entities.lua +++ b/maps/mountain_fortress_v3/entities.lua @@ -21,9 +21,6 @@ local WD = require 'modules.wave_defense.table' -- module local Public = {} -local math_random = math.random -local math_floor = math.floor -local math_abs = math.abs --local raise_event = script.raise_event local mapkeeper = '[color=blue]Mapkeeper:[/color]\n' @@ -94,7 +91,7 @@ local function set_objective_health(final_damage_amount) return end - this.locomotive_health = math_floor(this.locomotive_health - final_damage_amount) + this.locomotive_health = math.floor(this.locomotive_health - final_damage_amount) if this.locomotive_health > this.locomotive_max_health then this.locomotive_health = this.locomotive_max_health end @@ -152,9 +149,9 @@ end local function hidden_biter(entity) local surface = entity.surface - local h = math_floor(math_abs(entity.position.y)) + local h = math.floor(math.abs(entity.position.y)) local m = 1 / Terrain.level_depth - local count = math_floor(math_random(0, h + Terrain.level_depth) * m) + 1 + local count = math.floor(math.random(0, h + Terrain.level_depth) * m) + 1 local position = surface.find_non_colliding_position('small-biter', entity.position, 16, 0.5) if not position then position = entity.position @@ -164,13 +161,13 @@ local function hidden_biter(entity) for _ = 1, count, 1 do local unit - if math_random(1, 3) == 1 then + if math.random(1, 3) == 1 then unit = surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = position}) else unit = surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = position}) end - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then BiterHealthBooster.add_boss_unit(unit, m * h * 5 + 1, 0.38) end end @@ -182,12 +179,12 @@ local function hidden_worm(entity) end local function hidden_biter_pet(event) - if math_random(1, 2048) ~= 1 then + if math.random(1, 2048) ~= 1 then return end BiterRolls.wave_defense_set_unit_raffle(math.sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.25) local unit - if math_random(1, 3) == 1 then + if math.random(1, 3) == 1 then unit = event.entity.surface.create_entity( {name = BiterRolls.wave_defense_roll_spitter_name(), position = event.entity.position} @@ -244,13 +241,13 @@ local function angry_tree(entity, cause) if math.abs(entity.position.y) < Terrain.level_depth then return end - if math_random(1, 4) == 1 then + if math.random(1, 4) == 1 then hidden_biter(entity) end - if math_random(1, 8) == 1 then + if math.random(1, 8) == 1 then hidden_worm(entity) end - if math_random(1, 16) ~= 1 then + if math.random(1, 16) ~= 1 then return end local position = false @@ -260,12 +257,12 @@ local function angry_tree(entity, cause) end end if not position then - position = {entity.position.x + (-20 + math_random(0, 40)), entity.position.y + (-20 + math_random(0, 40))} + position = {entity.position.x + (-20 + math.random(0, 40)), entity.position.y + (-20 + math.random(0, 40))} end entity.surface.create_entity( { - name = projectiles[math_random(1, 5)], + name = projectiles[math.random(1, 5)], position = entity.position, force = 'neutral', source = entity.position, @@ -336,7 +333,7 @@ local function on_player_mined_entity(event) entity.destroy() return end - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then Traps(entity.surface, entity.position) return end @@ -385,7 +382,7 @@ end local function get_damage(event) local entity = event.entity - local damage = event.original_damage_amount + event.original_damage_amount * math_random(1, 100) + local damage = event.original_damage_amount + event.original_damage_amount * math.random(1, 100) if entity.prototype.resistances then if entity.prototype.resistances.physical then damage = damage - entity.prototype.resistances.physical.decrease @@ -412,7 +409,7 @@ local function kaboom(entity, target, damage) { name = 'flying-text', position = {entity.position.x + base_vector[1] * 0.5, entity.position.y + base_vector[2] * 0.5}, - text = msg[math_random(1, #msg)], + text = msg[math.random(1, #msg)], color = {255, 0, 0} } ) @@ -435,12 +432,12 @@ local function kaboom(entity, target, damage) end end - vector[1] = vector[1] * 1.5 - vector[2] = vector[2] * 1.5 + vector[1] = vector[1] * 1.6 + vector[2] = vector[2] * 1.6 - local a = 0.25 + local a = 0.30 - for i = 1, 16, 1 do + for i = 1, 8, 1 do for x = i * -1 * a, i * a, 1 do for y = i * -1 * a, i * a, 1 do local p = {entity.position.x + x + vector[1] * i, entity.position.y + y + vector[2] * i} @@ -489,12 +486,8 @@ local function boss_puncher(event) return end - local wd = WD.get_table() - if wd.boss_wave_warning or wd.wave_number >= 1000 then - if math_random(1, 10) == 1 then - kaboom(cause, entity, get_damage(event)) - end - return + if math.random(1, 10) == 1 then + kaboom(cause, entity, get_damage(event)) end end @@ -511,8 +504,16 @@ local function on_entity_damaged(event) protect_entities(event) biters_chew_rocks_faster(event) - if math_random(0, 512) == 1 then - boss_puncher(event) + local wave_number = WD.get_wave() + local boss_wave_warning = WD.alert_boss_wave() + local much_time = WPT.get('much_time') + + if much_time then + if boss_wave_warning or wave_number >= 1500 then + if math.random(0, 512) == 1 then + boss_puncher(event) + end + end end end @@ -602,7 +603,7 @@ local function on_entity_died(event) hidden_biter(event.entity) return end - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then Traps(entity.surface, entity.position) return end @@ -629,7 +630,7 @@ function Public.set_scores() if not loco.valid then return end - local score = math_floor(loco.position.y * -1) + local score = math.floor(loco.position.y * -1) for _, player in pairs(game.connected_players) do if score > Map_score.get_score(player) then Map_score.set_score(player, score) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 674ec1c4..b47fb026 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1,4 +1,5 @@ local Token = require 'utils.token' +local Task = require 'utils.task' local ICW = require 'maps.mountain_fortress_v3.icw.main' local WPT = require 'maps.mountain_fortress_v3.table' local Event = require 'utils.event' @@ -8,6 +9,8 @@ local Public = {} local magic_crafters_per_tick = 3 local magic_fluid_crafters_per_tick = 8 local floor = math.floor +local round = math.round +local table_shuffle_table = table.shuffle_table local function fast_remove(tbl, index) local count = #tbl @@ -171,6 +174,52 @@ local function do_magic_fluid_crafters() magic_fluid_crafters.index = index end +local function add_magic_crafter_output(entity, output, distance) + local magic_fluid_crafters = WPT.get('magic_fluid_crafters') + local magic_crafters = WPT.get('magic_crafters') + local rate = output.min_rate + output.distance_factor * distance + + local fluidbox_index = output.fluidbox_index + local data = { + entity = entity, + last_tick = game.tick, + base_rate = rate, + rate = rate, + item = output.item, + fluidbox_index = fluidbox_index + } + + if fluidbox_index then + magic_fluid_crafters[#magic_fluid_crafters + 1] = data + else + magic_crafters[#magic_crafters + 1] = data + end +end + +function roll(budget, item_name) + if not budget then + return + end + + budget = math.floor(budget) + if budget == 0 then + return + end + + local final_stack_set + local final_stack_set_worth = 0 + + for _ = 1, 5, 1 do + local item_stack_set, item_stack_set_worth = roll_item_stacks(budget, item_name) + if item_stack_set_worth > final_stack_set_worth or item_stack_set_worth == budget then + final_stack_set = item_stack_set + final_stack_set_worth = item_stack_set_worth + end + end + + return final_stack_set +end + local function tick() do_refill_turrets() do_magic_crafters() @@ -180,64 +229,82 @@ end Public.deactivate_callback = Token.register( function(entity) - entity.active = false - entity.operable = false - entity.destructible = false + if entity and entity.valid then + entity.active = false + entity.operable = false + entity.destructible = false + end end ) Public.neutral_force = Token.register( function(entity) - entity.force = 'neutral' + if entity and entity.valid then + entity.force = 'neutral' + end end ) Public.enemy_force = Token.register( function(entity) - entity.force = 'enemy' + if entity and entity.valid then + entity.force = 'enemy' + end end ) Public.active_not_destructible_callback = Token.register( function(entity) - entity.active = true - entity.operable = false - entity.destructible = false + if entity and entity.valid then + entity.active = true + entity.operable = false + entity.destructible = false + end end ) Public.disable_minable_callback = Token.register( function(entity) - entity.minable = false + if entity and entity.valid then + entity.minable = false + end end ) Public.disable_minable_and_ICW_callback = Token.register( function(entity) - entity.minable = false - local wagon = ICW.register_wagon(entity, true) - wagon.entity_count = 999 + if entity and entity.valid then + entity.minable = false + local wagon = ICW.register_wagon(entity, true) + wagon.entity_count = 999 + end end ) Public.disable_destructible_callback = Token.register( function(entity) - entity.destructible = false + if entity and entity.valid then + entity.destructible = false + end end ) Public.disable_active_callback = Token.register( function(entity) - entity.active = false + if entity and entity.valid then + entity.active = false + end end ) +local disable_active_callback = Public.disable_active_callback + Public.refill_turret_callback = Token.register( function(turret, data) @@ -283,6 +350,152 @@ Public.power_source_callback = end ) +Public.magic_item_crafting_callback = + Token.register( + function(entity, data) + local callback_data = data.callback_data + + entity.minable = false + entity.destructible = false + entity.operable = false + + local recipe = callback_data.recipe + if recipe then + entity.set_recipe(recipe) + else + local furance_item = callback_data.furance_item + if furance_item then + local inv = entity.get_inventory(2) -- defines.inventory.furnace_source + inv.insert(furance_item) + end + end + + local p = entity.position + local x, y = p.x, p.y + local distance = math.sqrt(x * x + y * y) + + local output = callback_data.output + if #output == 0 then + add_magic_crafter_output(entity, output, distance) + else + for i = 1, #output do + local o = output[i] + add_magic_crafter_output(entity, o, distance) + end + end + + if not callback_data.keep_active then + Task.set_timeout_in_ticks(2, disable_active_callback, entity) -- causes problems with refineries. + end + end +) + +Public.magic_item_crafting_callback_weighted = + Token.register( + function(entity, data) + local callback_data = data.callback_data + + entity.minable = false + entity.destructible = false + entity.operable = false + + local weights = callback_data.weights + local loot = callback_data.loot + + local p = entity.position + + local i = math.random() * weights.total + + local index = table.binary_search(weights, i) + if (index < 0) then + index = bit32.bnot(index) + end + + local stack = loot[index].stack + if not stack then + return + end + + local recipe = stack.recipe + if recipe then + entity.set_recipe(recipe) + else + local furance_item = stack.furance_item + if furance_item then + local inv = entity.get_inventory(2) -- defines.inventory.furnace_source + inv.insert(furance_item) + end + end + + local x, y = p.x, p.y + local distance = math.sqrt(x * x + y * y) + + local output = stack.output + if #output == 0 then + add_magic_crafter_output(entity, output, distance) + else + for o_i = 1, #output do + local o = output[o_i] + add_magic_crafter_output(entity, o, distance) + end + end + + if not callback_data.keep_active then + Task.set_timeout_in_ticks(2, disable_active_callback, entity) -- causes problems with refineries. + end + end +) + +function Public.prepare_weighted_loot(loot) + local total = 0 + local weights = {} + + for i = 1, #loot do + local v = loot[i] + total = total + v.weight + weights[#weights + 1] = total + end + + weights.total = total + + return weights +end + +function Public.do_random_loot(entity, weights, loot) + if not entity.valid then + return + end + + entity.operable = false + --entity.destructible = false + + local i = math.random() * weights.total + + local index = table.binary_search(weights, i) + if (index < 0) then + index = bit32.bnot(index) + end + + local stack = loot[index].stack + if not stack then + return + end + + local df = stack.distance_factor + local count + if df then + local p = entity.position + local x, y = p.x, p.y + local d = math.sqrt(x * x + y * y) + + count = stack.count + d * df + else + count = stack.count + end + + entity.insert {name = stack.name, count = count} +end + Public.firearm_magazine_ammo = {name = 'firearm-magazine', count = 200} Public.piercing_rounds_magazine_ammo = {name = 'piercing-rounds-magazine', count = 200} Public.uranium_rounds_magazine_ammo = {name = 'uranium-rounds-magazine', count = 200} @@ -290,7 +503,7 @@ Public.light_oil_ammo = {name = 'light-oil', amount = 100} Public.artillery_shell_ammo = {name = 'artillery-shell', count = 15} Public.laser_turrent_power_source = {buffer_size = 2400000, power_production = 40000} -Event.on_nth_tick(20, tick) +Event.on_nth_tick(10, tick) --Event.add(defines.events.on_tick, tick) Event.add(defines.events.on_entity_died, turret_died) diff --git a/maps/mountain_fortress_v3/generate.lua b/maps/mountain_fortress_v3/generate.lua index 1b45044b..cba400c7 100644 --- a/maps/mountain_fortress_v3/generate.lua +++ b/maps/mountain_fortress_v3/generate.lua @@ -44,6 +44,16 @@ local function do_tile(y, x, data, shape) end end + local buildings = tile.buildings + if buildings then + for _, entity in pairs(buildings) do + if not entity.position then + entity.position = pos + end + data.buildings[#data.buildings + 1] = entity + end + end + local decoratives = tile.decoratives if decoratives then for _, decorative in pairs(decoratives) do @@ -106,6 +116,16 @@ local function do_row(row, data, shape) end end + local buildings = tile.buildings + if buildings then + for _, entity in pairs(buildings) do + if not entity.position then + entity.position = pos + end + data.buildings[#data.buildings + 1] = entity + end + end + local decoratives = tile.decoratives if decoratives then for _, decorative in pairs(decoratives) do @@ -148,14 +168,13 @@ local function do_place_treasure(data) local surface = data.surface local treasure = data.treasure - local rnd = math.random if #treasure == 0 then return end for _, e in pairs(data.treasure) do - if rnd(1, 6) == 1 then + if math.random(1, 6) == 1 then e.chest = 'iron-chest' end Loot.add(surface, e.position, e.chest) @@ -169,14 +188,12 @@ local function do_place_markets(data) local markets = data.markets local surface = data.surface - local rnd = math.random - local abs = math.abs if #markets == 0 then return end - local pos = markets[rnd(1, #markets)] + local pos = markets[math.random(1, #markets)] if surface.count_entities_filtered { area = {{pos.x - 96, pos.y - 96}, {pos.x + 96, pos.y + 96}}, @@ -184,7 +201,7 @@ local function do_place_markets(data) limit = 1 } == 0 then - local market = Market.mountain_market(surface, pos, abs(pos.y) * 0.004) + local market = Market.mountain_market(surface, pos, math.abs(pos.y) * 0.004) market.destructible = false end end @@ -212,6 +229,51 @@ local function do_place_decoratives(data) end end +local function do_place_buildings(data) + if not data.surface.valid then + return + end + + local surface = data.surface + local entity + local callback + + for _, e in pairs(data.buildings) do + if e.e_type then + local p = e.position + if + surface.count_entities_filtered { + area = {{p.x - 32, p.y - 32}, {p.x + 32, p.y + 32}}, + type = e.e_type, + limit = 1 + } == 0 + then + entity = surface.create_entity(e) + if entity and e.direction then + entity.direction = e.direction + end + if entity and e.force then + entity.force = e.force + end + if entity and e.callback then + local c = e.callback.callback + if not c then + return + end + local d = {callback_data = e.callback.data} + if not d then + callback = Token.get(c) + callback(entity) + return + end + callback = Token.get(c) + callback(entity, d) + end + end + end + end +end + local function do_place_entities(data) if not data.surface.valid then return @@ -342,18 +404,22 @@ local function map_gen_action(data) data.y = 34 return true elseif state == 34 then - do_place_markets(data) + do_place_buildings(data) data.y = 35 return true elseif state == 35 then - do_place_treasure(data) + do_place_markets(data) data.y = 36 return true elseif state == 36 then - do_place_decoratives(data) + do_place_treasure(data) data.y = 37 return true elseif state == 37 then + do_place_decoratives(data) + data.y = 38 + return true + elseif state == 38 then run_chart_update(data) return false end @@ -392,6 +458,7 @@ function Public.schedule_chunk(event) surface = surface, tiles = {}, entities = {}, + buildings = {}, decoratives = {}, markets = {}, treasure = {} @@ -429,6 +496,7 @@ function Public.do_chunk(event) surface = surface, tiles = {}, entities = {}, + buildings = {}, decoratives = {}, markets = {}, treasure = {} @@ -444,6 +512,7 @@ function Public.do_chunk(event) do_place_tiles(data) do_place_entities(data) + do_place_buildings(data) do_place_decoratives(data) do_place_markets(data) do_place_treasure(data) diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index 77725f2a..23ec028c 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -2,7 +2,6 @@ local Event = require 'utils.event' local RPG = require 'maps.mountain_fortress_v3.rpg' local WPT = require 'maps.mountain_fortress_v3.table' local Gui = require 'utils.gui' -local floor = math.floor local format_number = require 'util'.format_number local Public = {} @@ -265,9 +264,9 @@ function Public.update_gui(player) gui.global_pool.caption = 'XP: 0' gui.global_pool.tooltip = 'Dig, handcraft or run to increase the pool!' elseif rpg_extra.global_pool >= 0 then - gui.global_pool.caption = 'XP: ' .. format_number(floor(rpg_extra.global_pool), true) + gui.global_pool.caption = 'XP: ' .. format_number(math.floor(rpg_extra.global_pool), true) gui.global_pool.tooltip = - 'Amount of XP that is stored inside the global xp pool.\nRaw Value: ' .. floor(rpg_extra.global_pool) + 'Amount of XP that is stored inside the global xp pool.\nRaw Value: ' .. math.floor(rpg_extra.global_pool) end gui.scrap_mined.caption = ' [img=entity.tree-01][img=entity.rock-huge]: ' .. format_number(this.mined_scrap, true) diff --git a/maps/mountain_fortress_v3/icw/functions.lua b/maps/mountain_fortress_v3/icw/functions.lua index 5535bf50..66b629c6 100644 --- a/maps/mountain_fortress_v3/icw/functions.lua +++ b/maps/mountain_fortress_v3/icw/functions.lua @@ -3,9 +3,6 @@ local Public = {} local Constants = require 'maps.mountain_fortress_v3.icw.constants' local ICW = require 'maps.mountain_fortress_v3.icw.table' -local table_insert = table.insert -local table_remove = table.remove - function Public.request_reconstruction(icw) icw.rebuild_tick = game.tick + 30 end @@ -24,7 +21,7 @@ local function delete_empty_surfaces(icw) for k, surface in pairs(icw.surfaces) do if not icw.trains[tonumber(surface.name)] then game.delete_surface(surface) - table_remove(icw.surfaces, k) + icw.surfaces[k] = nil end end end @@ -99,6 +96,10 @@ local function equal_fluid(source_tank, target_tank) end local function divide_fluid(wagon, storage_tank) + if not validate_entity(wagon.entity) then + return + end + local fluid_wagon = wagon.entity equal_fluid(fluid_wagon, storage_tank) equal_fluid(storage_tank, fluid_wagon) @@ -135,7 +136,7 @@ local function input_cargo(wagon, chest) end local wagon_entity = wagon.entity - if not wagon_entity.valid then + if not validate_entity(wagon_entity) then wagon.transfer_entities = nil return end @@ -171,15 +172,10 @@ local function input_cargo(wagon, chest) end local function output_cargo(wagon, passive_chest) - if not wagon.entity then - return - end - if not wagon.entity.valid then - return - end - if not passive_chest.valid then + if not validate_entity(wagon.entity) then return end + if not passive_chest.valid then return end @@ -229,6 +225,9 @@ local function get_wagon_for_entity(icw, entity) end local function kill_wagon_doors(icw, wagon) + if not validate_entity(wagon.entity) then + return + end for k, e in pairs(wagon.doors) do icw.doors[e.unit_number] = nil e.destroy() @@ -255,7 +254,7 @@ local function construct_wagon_doors(icw, wagon) e.minable = false e.operable = false icw.doors[e.unit_number] = wagon.entity.unit_number - table_insert(wagon.doors, e) + wagon.doors[#wagon.doors + 1] = e end end @@ -311,7 +310,7 @@ function Public.kill_wagon(icw, entity) end Public.kill_minimap(e.player) else - e.die() + e.destroy() recreate_players() end end @@ -348,7 +347,7 @@ function Public.create_room_surface(icw, unit_number) for _, tile in pairs(surface.find_tiles_filtered({area = {{-2, -2}, {2, 2}}})) do surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true) end - table_insert(icw.surfaces, surface) + icw.surfaces[#icw.surfaces + 1] = surface return surface end @@ -363,20 +362,20 @@ function Public.create_wagon_room(icw, wagon) local tiles = {} for x = -3, 2, 1 do - table_insert(tiles, {name = 'hazard-concrete-right', position = {x, area.left_top.y}}) - table_insert(tiles, {name = 'hazard-concrete-right', position = {x, area.right_bottom.y - 1}}) + tiles[#tiles + 1] = {name = 'hazard-concrete-right', position = {x, area.left_top.y}} + tiles[#tiles + 1] = {name = 'hazard-concrete-right', position = {x, area.right_bottom.y - 1}} end for x = area.left_top.x, area.right_bottom.x - 1, 1 do for y = area.left_top.y + 2, area.right_bottom.y - 3, 1 do - table_insert(tiles, {name = main_tile_name, position = {x, y}}) + tiles[#tiles + 1] = {name = main_tile_name, position = {x, y}} end end for x = -3, 2, 1 do for y = 1, 3, 1 do - table_insert(tiles, {name = main_tile_name, position = {x, y}}) + tiles[#tiles + 1] = {name = main_tile_name, position = {x, y}} end for y = area.right_bottom.y - 4, area.right_bottom.y - 2, 1 do - table_insert(tiles, {name = main_tile_name, position = {x, y}}) + tiles[#tiles + 1] = {name = main_tile_name, position = {x, y}} end end @@ -385,8 +384,8 @@ function Public.create_wagon_room(icw, wagon) if wagon.entity.type == 'locomotive' then for x = -3, 2, 1 do for y = 10, 12, 1 do - table_insert(tiles, {name = 'water', position = {x, y}}) - table_insert(fishes, {name = 'fish', position = {x, y}}) + tiles[#tiles + 1] = {name = 'water', position = {x, y}} + fishes[#fishes + 1] = {name = 'fish', position = {x, y}} end end end @@ -702,8 +701,7 @@ local function move_room_to_train(icw, train, wagon) if not wagon then return end - - table_insert(train.wagons, wagon.entity.unit_number) + train.wagons[#train.wagons + 1] = wagon.entity.unit_number local destination_area = { left_top = {x = wagon.area.left_top.x, y = train.top_y}, @@ -775,7 +773,7 @@ local function move_room_to_train(icw, train, wagon) for _, e in pairs(wagon.surface.find_entities_filtered({area = wagon.area, force = 'neutral'})) do if transfer_functions[e.name] then - table_insert(wagon.transfer_entities, e) + wagon.transfer_entities[#wagon.transfer_entities + 1] = e end end end @@ -798,7 +796,7 @@ end function Public.reconstruct_all_trains(icw) icw.trains = {} for unit_number, wagon in pairs(icw.wagons) do - if not wagon.entity or not wagon.entity.valid then + if not validate_entity(wagon.entity) then icw.wagons[unit_number] = nil Public.request_reconstruction(icw) return @@ -817,14 +815,10 @@ end function Public.item_transfer(icw) for _, wagon in pairs(icw.wagons) do - if not wagon and not wagon.valid then + if not validate_entity(wagon.entity) then return end if wagon.transfer_entities then - if not wagon and not wagon.valid then - return - end - for k, e in pairs(wagon.transfer_entities) do transfer_functions[e.name](wagon, e) end diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 5263e6b9..4e36cc8b 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -9,11 +9,7 @@ local Alert = require 'utils.alert' local format_number = require 'util'.format_number local Public = {} -local random = math.random -local rad = math.rad local concat = table.concat -local cos = math.cos -local sin = math.sin local shopkeeper = '[color=blue]Shopkeeper:[/color]\n' @@ -189,10 +185,10 @@ local function create_poison_cloud(position) local surface = game.surfaces[active_surface_index] local random_angles = { - rad(random(359)), - rad(random(359)), - rad(random(359)), - rad(random(359)) + math.rad(math.random(359)), + math.rad(math.random(359)), + math.rad(math.random(359)), + math.rad(math.random(359)) } surface.create_entity({name = 'poison-cloud', position = {x = position.x, y = position.y}}) @@ -200,8 +196,8 @@ local function create_poison_cloud(position) { name = 'poison-cloud', position = { - x = position.x + 12 * cos(random_angles[1]), - y = position.y + 12 * sin(random_angles[1]) + x = position.x + 12 * math.cos(random_angles[1]), + y = position.y + 12 * math.sin(random_angles[1]) } } ) @@ -209,8 +205,8 @@ local function create_poison_cloud(position) { name = 'poison-cloud', position = { - x = position.x + 12 * cos(random_angles[2]), - y = position.y + 12 * sin(random_angles[2]) + x = position.x + 12 * math.cos(random_angles[2]), + y = position.y + 12 * math.sin(random_angles[2]) } } ) @@ -218,8 +214,8 @@ local function create_poison_cloud(position) { name = 'poison-cloud', position = { - x = position.x + 12 * cos(random_angles[3]), - y = position.y + 12 * sin(random_angles[3]) + x = position.x + 12 * math.cos(random_angles[3]), + y = position.y + 12 * math.sin(random_angles[3]) } } ) @@ -227,8 +223,8 @@ local function create_poison_cloud(position) { name = 'poison-cloud', position = { - x = position.x + 12 * cos(random_angles[4]), - y = position.y + 12 * sin(random_angles[4]) + x = position.x + 12 * math.cos(random_angles[4]), + y = position.y + 12 * math.sin(random_angles[4]) } } ) @@ -854,7 +850,7 @@ local function create_market(data, rebuild) } local e = loco_surface.create_entity( - {name = biters[random(1, 4)], position = position, force = 'player', create_build_effect_smoke = false} + {name = biters[math.random(1, 4)], position = position, force = 'player', create_build_effect_smoke = false} ) e.ai_settings.allow_destroy_when_commands_fail = false e.ai_settings.allow_try_return_to_spawner = false @@ -924,7 +920,7 @@ local function tick() Public.boost_players_around_train() end - if ticker % 600 == 0 then + if ticker % 2500 == 0 then Public.transfer_pollution() end @@ -1155,15 +1151,13 @@ function Public.transfer_pollution() local active_surface_index = WPT.get('active_surface_index') local icw_locomotive = WPT.get('icw_locomotive') local surface = icw_locomotive.surface - local Diff = Difficulty.get() - if not surface then return end local total_interior_pollution = surface.get_total_pollution() - local pollution = surface.get_total_pollution() * (3 / (4 / 3 + 1)) * Diff.difficulty_vote_value + local pollution = surface.get_total_pollution() * (3 / (4 / 3 + 1)) * Difficulty.get().difficulty_vote_value game.surfaces[active_surface_index].pollute(locomotive.position, pollution) game.pollution_statistics.on_flow('locomotive', pollution - total_interior_pollution) surface.clear_pollution() @@ -1179,9 +1173,9 @@ function Public.enable_poison_defense() end local pos = locomotive.position create_poison_cloud({x = pos.x, y = pos.y}) - if random(1, 3) == 1 then - local random_angles = {rad(random(359))} - create_poison_cloud({x = pos.x + 24 * cos(random_angles[1]), y = pos.y + -24 * sin(random_angles[1])}) + if math.random(1, 3) == 1 then + local random_angles = {math.rad(math.random(359))} + create_poison_cloud({x = pos.x + 24 * math.cos(random_angles[1]), y = pos.y + -24 * math.sin(random_angles[1])}) end end diff --git a/maps/mountain_fortress_v3/loot.lua b/maps/mountain_fortress_v3/loot.lua index 013186bd..f9ccff25 100644 --- a/maps/mountain_fortress_v3/loot.lua +++ b/maps/mountain_fortress_v3/loot.lua @@ -1,9 +1,6 @@ local LootRaffle = require 'functions.loot_raffle' local Public = {} -local math_random = math.random -local math_abs = math.abs -local math_floor = math.floor local blacklist = { ['atomic-bomb'] = true, @@ -14,19 +11,19 @@ local blacklist = { } function Public.add(surface, position, chest) - local budget = 48 + math_abs(position.y) * 1.75 - budget = budget * math_random(25, 175) * 0.01 + local budget = 48 + math.abs(position.y) * 1.75 + budget = budget * math.random(25, 175) * 0.01 - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then budget = budget * 4 - chest = 'crash-site-chest-' .. math_random(1, 2) + chest = 'crash-site-chest-' .. math.random(1, 2) end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then budget = budget * 4 - chest = 'crash-site-chest-' .. math_random(1, 2) + chest = 'crash-site-chest-' .. math.random(1, 2) end - budget = math_floor(budget) + 1 + budget = math.floor(budget) + 1 local item_stacks = LootRaffle.roll(budget, 8, blacklist) local container = surface.create_entity({name = chest, position = position, force = 'neutral'}) @@ -36,8 +33,8 @@ function Public.add(surface, position, chest) container.minable = false for _ = 1, 3, 1 do - if math_random(1, 8) == 1 then - container.insert({name = 'explosives', count = math_random(25, 50)}) + if math.random(1, 8) == 1 then + container.insert({name = 'explosives', count = math.random(25, 50)}) else break end @@ -45,19 +42,19 @@ function Public.add(surface, position, chest) end function Public.add_rare(surface, position, chest, magic) - local budget = magic * 48 + math_abs(position.y) * 1.75 - budget = budget * math_random(25, 175) * 0.01 + local budget = magic * 48 + math.abs(position.y) * 1.75 + budget = budget * math.random(25, 175) * 0.01 - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then budget = budget * 6 - chest = 'crash-site-chest-' .. math_random(1, 2) + chest = 'crash-site-chest-' .. math.random(1, 2) end - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then budget = budget * 6 - chest = 'crash-site-chest-' .. math_random(1, 2) + chest = 'crash-site-chest-' .. math.random(1, 2) end - budget = math_floor(budget) + 1 + budget = math.floor(budget) + 1 local item_stacks = LootRaffle.roll(budget, 8, blacklist) local container = surface.create_entity({name = chest, position = position, force = 'neutral'}) @@ -67,8 +64,8 @@ function Public.add_rare(surface, position, chest, magic) container.minable = false for _ = 1, 3, 1 do - if math_random(1, 8) == 1 then - container.insert({name = 'explosives', count = math_random(25, 50)}) + if math.random(1, 8) == 1 then + container.insert({name = 'explosives', count = math.random(25, 50)}) else break end diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 5a8b12ca..a119deef 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -1,12 +1,9 @@ require 'maps.mountain_fortress_v3.generate' require 'maps.mountain_fortress_v3.commands' require 'maps.mountain_fortress_v3.breached_wall' --- require 'maps.mountain_fortress_v3.nightfall' --- require 'maps.mountain_fortress_v3.void_away' require 'modules.dynamic_landfill' require 'modules.shotgun_buff' -require 'modules.rocks_heal_over_time' require 'modules.no_deconstruction_of_neutral_entities' require 'modules.rocks_yield_ore_veins' require 'modules.spawners_contain_biters' @@ -61,7 +58,9 @@ local collapse_kill = { ['artillery-turret'] = true, ['landmine'] = true, ['locomotive'] = true, - ['cargo-wagon'] = true + ['cargo-wagon'] = true, + ['assembling-machine'] = true, + ['furnace'] = true }, enabled = true } @@ -266,7 +265,7 @@ function Public.reset_map() wave_defense_table.game_lost = false wave_defense_table.spawn_position = {x = 0, y = 100} WD.alert_boss_wave(true) - WD.clear_corpses(true) + WD.clear_corpses(false) set_difficulty() @@ -344,8 +343,8 @@ local on_player_joined_game = function(event) ) else local p = {x = player.position.x, y = player.position.y} - local oom = surface.get_tile(p).name == 'out-of-map' - if oom then + local get_tile = surface.get_tile(p) + if get_tile.valid and get_tile.name == 'out-of-map' then player.teleport( surface.find_non_colliding_position( 'character', @@ -616,7 +615,7 @@ local on_init = function() this.rocks_yield_ore_distance_modifier = 0.025 local T = Map.Pop_info() - T.localised_category = 'mountain_fortress' + T.localised_category = 'mountain_fortress_v3' T.main_caption_color = {r = 150, g = 150, b = 0} T.sub_caption_color = {r = 0, g = 150, b = 0} diff --git a/maps/mountain_fortress_v3/mining.lua b/maps/mountain_fortress_v3/mining.lua index ddc04633..5bf8696a 100644 --- a/maps/mountain_fortress_v3/mining.lua +++ b/maps/mountain_fortress_v3/mining.lua @@ -3,9 +3,6 @@ local WPT = require 'maps.mountain_fortress_v3.table' local Public = {} local max_spill = 60 -local math_random = math.random -local math_floor = math.floor -local math_sqrt = math.sqrt local valid_rocks = { ['sand-rock-big'] = true, @@ -28,8 +25,8 @@ local particles = { } local function create_particles(surface, name, position, amount, cause_position) - local d1 = (-100 + math_random(0, 200)) * 0.0004 - local d2 = (-100 + math_random(0, 200)) * 0.0004 + local d1 = (-100 + math.random(0, 200)) * 0.0004 + local d2 = (-100 + math.random(0, 200)) * 0.0004 if cause_position then d1 = (cause_position.x - position.x) * 0.025 @@ -37,7 +34,7 @@ local function create_particles(surface, name, position, amount, cause_position) end for i = 1, amount, 1 do - local m = math_random(4, 10) + local m = math.random(4, 10) local m2 = m * 0.005 surface.create_particle( @@ -48,8 +45,8 @@ local function create_particles(surface, name, position, amount, cause_position) vertical_speed = 0.130, height = 0, movement = { - (m2 - (math_random(0, m) * 0.01)) + d1, - (m2 - (math_random(0, m) * 0.01)) + d2 + (m2 - (math.random(0, m) * 0.01)) + d1, + (m2 - (math.random(0, m) * 0.01)) + d2 } } ) @@ -97,7 +94,7 @@ local size_of_ore_raffle = #harvest_raffle_ores local function get_amount(data) local entity = data.entity local this = data.this - local distance_to_center = math_floor(math_sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) + local distance_to_center = math.floor(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) local type_modifier local amount local second_amount @@ -123,7 +120,7 @@ local function get_amount(data) type_modifier = rock_yield[entity.name] or type_modifier amount = base_amount + (distance_to_center * distance_modifier) - second_amount = math_floor((second_base_amount + (distance_to_center * distance_modifier)) / 3) + second_amount = math.floor((second_base_amount + (distance_to_center * distance_modifier)) / 3) if amount > maximum_amount then amount = maximum_amount end @@ -131,9 +128,9 @@ local function get_amount(data) second_amount = maximum_amount end - local m = (70 + math_random(0, 60)) * 0.01 + local m = (70 + math.random(0, 60)) * 0.01 - amount = math_floor(amount * type_modifier * m * 0.7) + amount = math.floor(amount * type_modifier * m * 0.7) return amount, second_amount end @@ -147,7 +144,7 @@ function Public.entity_died_randomness(data) local position = {x = entity.position.x, y = entity.position.y} - surface.spill_item_stack(position, {name = harvest, count = math_random(1, 5)}, true) + surface.spill_item_stack(position, {name = harvest, count = math.random(1, 5)}, true) local particle = particles[harvest] create_particles(surface, particle, position, 64, {x = entity.position.x, y = entity.position.y}) end @@ -177,14 +174,14 @@ local function randomness(data) if fullness >= fullness_limit then if player.character then - player.character.health = player.character.health - math_random(50, 100) + player.character.health = player.character.health - math.random(50, 100) player.character.surface.create_entity({name = 'water-splash', position = player.position}) local messages = { 'Ouch.. That hurt! Better be careful now.', 'Just a fleshwound.', 'Better keep those hands to yourself or you might loose them.' } - player.print(messages[math_random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0}) + player.print(messages[math.random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0}) if player.character.health <= 0 then player.character.die('enemy') game.print(player.name .. ' should have emptied their pockets.', {r = 0.75, g = 0.0, b = 0.0}) diff --git a/maps/mountain_fortress_v3/nightfall.lua b/maps/mountain_fortress_v3/nightfall.lua deleted file mode 100644 index 9501c3d1..00000000 --- a/maps/mountain_fortress_v3/nightfall.lua +++ /dev/null @@ -1,244 +0,0 @@ -local Event = require 'utils.event' -local Alert = require 'utils.alert' -local WPT = require 'maps.mountain_fortress_v3.table' -local random = math.random - -local shuffle = function(tbl) - local size = #tbl - for i = size, 1, -1 do - local rand = random(size) - tbl[i], tbl[rand] = tbl[rand], tbl[i] - end - return tbl -end - -local create_time_gui = function(player) - local this = WPT.get() - if player.gui.top['time_gui'] then - player.gui.top['time_gui'].destroy() - end - local frame = player.gui.top.add({type = 'frame', name = 'time_gui'}) - frame.style.maximal_height = 38 - - local night_count = 0 - if this.night_count then - night_count = this.night_count - end - - local label = frame.add({type = 'label', caption = 'Night: ' .. night_count}) - label.style.font_color = {r = 0.75, g = 0.0, b = 0.25} - label.style.font = 'default-listbox' - label.style.left_padding = 4 - label.style.right_padding = 4 - label.style.minimal_width = 50 -end - -local set_daytime_modifiers = function() - if game.map_settings.enemy_expansion.enabled == false then - return - end - - game.map_settings.enemy_expansion.enabled = false -end - -local nightfall_messages = { - 'Night is falling.', - 'It is getting dark.', - 'They are becoming restless.' -} - -local set_nighttime_modifiers = function(surface) - if game.map_settings.enemy_expansion.enabled == true then - return - end - local this = WPT.get() - - if not this.night_count then - --this.splice_modifier = 1 - this.night_count = 1 - else - --if game.forces["enemy"].evolution_factor > 0.25 then - --this.splice_modifier = this.splice_modifier + 0.05 - --if this.splice_modifier > 4 then this.splice_modifier = 4 end - --end - this.night_count = this.night_count + 1 - end - - for _, player in pairs(game.connected_players) do - create_time_gui(player) - local message = nightfall_messages[random(1, #nightfall_messages)] - Alert.alert_player_warning(player, 10, message, {r = 150, g = 0, b = 0}) - end - - game.map_settings.enemy_expansion.enabled = true - - local max_expansion_distance = math.ceil(this.night_count / 3) - if max_expansion_distance > 20 then - max_expansion_distance = 20 - end - game.map_settings.enemy_expansion.max_expansion_distance = max_expansion_distance - - local settler_group_min_size = math.ceil(this.night_count / 6) - if settler_group_min_size > 20 then - settler_group_min_size = 20 - end - game.map_settings.enemy_expansion.settler_group_min_size = settler_group_min_size - - local settler_group_max_size = math.ceil(this.night_count / 3) - if settler_group_max_size > 50 then - settler_group_max_size = 50 - end - game.map_settings.enemy_expansion.settler_group_max_size = settler_group_max_size - - local min_expansion_cooldown = 54000 - this.night_count * 540 - if min_expansion_cooldown < 3600 then - min_expansion_cooldown = 3600 - end - game.map_settings.enemy_expansion.min_expansion_cooldown = min_expansion_cooldown - - local max_expansion_cooldown = 108000 - this.night_count * 1080 - if max_expansion_cooldown < 3600 then - max_expansion_cooldown = 3600 - end - game.map_settings.enemy_expansion.max_expansion_cooldown = max_expansion_cooldown -end - -local get_spawner = function(surface) - local this = WPT.get() - local spawners = {} - for r = 512, 51200, 512 do - spawners = surface.find_entities_filtered({type = 'unit-spawner', area = {{0 - r, 0 - r}, {0 + r, 0 + r}}}) - if #spawners > 16 then - break - end - end - - if not spawners[1] then - return false - end - spawners = shuffle(spawners) - - if not this.last_spawners then - this.last_spawners = {{x = spawners[1].position.x, y = spawners[1].position.y}} - return spawners[1] - end - - for i = 1, #spawners, 1 do - local spawner_valid = true - for i2 = #this.last_spawners, #this.last_spawners - 4, -1 do - if i2 < 1 then - break - end - local distance = - math.sqrt( - (spawners[i].position.x - this.last_spawners[i2].x) ^ 2 + - (spawners[i].position.y - this.last_spawners[i2].y) ^ 2 - ) - if distance < 200 then - spawner_valid = false - break - end - end - if spawner_valid then - this.last_spawners[#this.last_spawners + 1] = {x = spawners[i].position.x, y = spawners[i].position.y} - if #this.last_spawners > 8 then - this.last_spawners[#this.last_spawners - 8] = nil - end - return spawners[i] - end - end - - return false -end - -local send_attack_group = function(surface) - local spawner = get_spawner(surface) - if not spawner then - game.print('it failed') - return false - end - local this = WPT.get() - - local biters = surface.find_enemy_units(spawner.position, 128, 'player') - if not biters[1] then - game.print('no biters') - return - end - - biters = shuffle(biters) - - local pos = surface.find_non_colliding_position('rocket-silo', spawner.position, 64, 1) - if not pos then - game.print('no pos') - return - end - - local unit_group = surface.create_unit_group({position = pos, force = 'enemy'}) - - local group_size = 6 + (this.night_count * 6) - if group_size > 200 then - group_size = 200 - end - - for i = 1, group_size, 1 do - if not biters[i] then - break - end - unit_group.add_member(biters[i]) - end - - if this.locomotive.valid then - unit_group.set_command( - { - type = defines.command.compound, - structure_type = defines.compound_command.return_last, - commands = { - { - type = defines.command.attack_area, - destination = {x = 0, y = 0}, - radius = 48, - distraction = defines.distraction.by_anything - }, - { - type = defines.command.attack, - target = this.locomotive, - distraction = defines.distraction.by_enemy - } - } - } - ) - else - unit_group.set_command( - { - type = defines.command.compound, - structure_type = defines.compound_command.return_last, - commands = { - { - type = defines.command.attack_area, - destination = {x = 0, y = 0}, - radius = 48, - distraction = defines.distraction.by_anything - } - } - } - ) - end -end - -local on_tick = function() - if game.tick % 600 ~= 0 then - return - end - local this = WPT.get() - local surface = game.surfaces[this.active_surface_index] - if surface.daytime > 0.25 and surface.daytime < 0.75 then - set_nighttime_modifiers(surface) - if surface.daytime < 0.65 then - send_attack_group(surface) - end - else - set_daytime_modifiers() - end -end - -Event.on_nth_tick(10, on_tick) diff --git a/maps/mountain_fortress_v3/resource_generator.lua b/maps/mountain_fortress_v3/resource_generator.lua new file mode 100644 index 00000000..205fa5f3 --- /dev/null +++ b/maps/mountain_fortress_v3/resource_generator.lua @@ -0,0 +1,283 @@ +local Functions = require 'maps.mountain_fortress_v3.functions' + +local types = { + 'assembling-machine', + 'furnace' +} + +local science_loot = { + { + stack = { + recipe = 'automation-science-pack', + output = {item = 'automation-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 5 / 60 / 512} + }, + weight = 4 + }, + { + stack = { + recipe = 'logistic-science-pack', + output = {item = 'logistic-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 15 / 60 / 512} + }, + weight = 2 + }, + { + stack = { + recipe = 'military-science-pack', + output = {item = 'military-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 25 / 60 / 512} + }, + weight = 1 + }, + { + stack = { + recipe = 'chemical-science-pack', + output = {item = 'chemical-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 33 / 60 / 512} + }, + weight = 0.20 + }, + { + stack = { + recipe = 'production-science-pack', + output = {item = 'production-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 45 / 60 / 512} + }, + weight = 0.10 + }, + { + stack = { + recipe = 'utility-science-pack', + output = {item = 'utility-science-pack', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 55 / 60 / 512} + }, + weight = 0.010 + } +} + +local ammo_loot = { + { + stack = { + recipe = 'piercing-rounds-magazine', + output = {item = 'piercing-rounds-magazine', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 10 / 60 / 512} + }, + weight = 1 + }, + { + stack = { + recipe = 'firearm-magazine', + output = {item = 'firearm-magazine', min_rate = 1 / 4 / 60, distance_factor = 1 / 4 / 60 / 512} + }, + weight = 4 + }, + { + stack = { + recipe = 'shotgun-shell', + output = {item = 'shotgun-shell', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 6 / 60 / 512} + }, + weight = 4 + }, + { + stack = { + recipe = 'uranium-rounds-magazine', + output = {item = 'uranium-rounds-magazine', min_rate = 0.1 / 8 / 60, distance_factor = 1 / 25 / 60 / 512} + }, + weight = 0.25 + } +} + +local resource_loot = { + { + stack = { + recipe = 'stone-wall', + output = {item = 'stone-wall', min_rate = 1 / 4 / 60, distance_factor = 1 / 8 / 60 / 512} + }, + weight = 1 + }, + { + stack = { + recipe = 'iron-gear-wheel', + output = {item = 'iron-gear-wheel', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + }, + weight = 4 + } +} + +local furnace_loot = { + { + stack = { + furance_item = 'iron-plate', + output = {item = 'iron-plate', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + }, + weight = 4 + }, + { + stack = { + furance_item = 'copper-plate', + output = {item = 'copper-plate', min_rate = 1 / 4 / 60, distance_factor = 1 / 6 / 60 / 512} + }, + weight = 4 + }, + { + stack = { + furance_item = 'steel-plate', + output = {item = 'steel-plate', min_rate = 0.5 / 8 / 60, distance_factor = 1 / 25 / 60 / 512} + }, + weight = 1 + } +} + +local science_weights = Functions.prepare_weighted_loot(science_loot) +local building_weights = Functions.prepare_weighted_loot(ammo_loot) +local resource_weights = Functions.prepare_weighted_loot(resource_loot) +local furnace_weights = Functions.prepare_weighted_loot(furnace_loot) + +local science_callback = { + callback = Functions.magic_item_crafting_callback_weighted, + data = { + loot = science_loot, + weights = science_weights + } +} + +local building_callback = { + callback = Functions.magic_item_crafting_callback_weighted, + data = { + loot = ammo_loot, + weights = building_weights + } +} + +local resource_callback = { + callback = Functions.magic_item_crafting_callback_weighted, + data = { + loot = resource_loot, + weights = resource_weights + } +} + +local furnace_callback = { + callback = Functions.magic_item_crafting_callback_weighted, + data = { + loot = furnace_loot, + weights = furnace_weights + } +} + +local science_list = { + [1] = {name = 'assembling-machine-1', callback = science_callback}, + [2] = {name = 'assembling-machine-2', callback = science_callback}, + [3] = {name = 'assembling-machine-3', callback = science_callback} +} + +local ammo_list = { + [1] = {name = 'assembling-machine-1', callback = building_callback}, + [2] = {name = 'assembling-machine-2', callback = building_callback}, + [3] = {name = 'assembling-machine-3', callback = building_callback} +} + +local resource_list = { + [1] = {name = 'assembling-machine-1', callback = resource_callback}, + [2] = {name = 'assembling-machine-2', callback = resource_callback}, + [3] = {name = 'assembling-machine-3', callback = resource_callback} +} + +local furnace_list = { + [1] = {name = 'stone-furnace', callback = furnace_callback}, + [2] = {name = 'steel-furnace', callback = furnace_callback}, + [3] = {name = 'electric-furnace', callback = furnace_callback} +} + +local function spawn_science_buildings(entities, p, probability) + entities[#entities + 1] = { + name = science_list[probability].name, + position = p, + force = 'player', + callback = science_list[probability].callback, + collision = true, + e_type = types + } +end + +local function spawn_ammo_building(entities, p, probability) + entities[#entities + 1] = { + name = ammo_list[probability].name, + position = p, + force = 'player', + callback = ammo_list[probability].callback, + collision = true, + e_type = types + } +end + +local function spawn_resource_building(entities, p, probability) + entities[#entities + 1] = { + name = resource_list[probability].name, + position = p, + force = 'player', + callback = resource_list[probability].callback, + collision = true, + e_type = types + } +end + +local function spawn_furnace_building(entities, p, probability) + entities[#entities + 1] = { + name = furnace_list[probability].name, + position = p, + force = 'player', + callback = furnace_list[probability].callback, + collision = true, + e_type = types + } +end + +local buildings = { + [1] = spawn_ammo_building, + [2] = spawn_resource_building, + [3] = spawn_furnace_building, + [4] = spawn_science_buildings +} + +local function spawn_random_buildings(entities, p, depth) + local randomizer = math.random(1, #buildings) + local low = math.random(1, 2) + local medium = math.random(2, 3) + local high = 3 + + if math.abs(p.y) < depth * 1.5 then + if math.random(1, 16) == 1 then + return buildings[randomizer](entities, p, low) + else + return buildings[randomizer](entities, p, low) + end + elseif math.abs(p.y) < depth * 2.5 then + if math.random(1, 8) == 1 then + return buildings[randomizer](entities, p, medium) + else + return buildings[randomizer](entities, p, medium) + end + elseif math.abs(p.y) < depth * 3.5 then + if math.random(1, 4) == 1 then + return buildings[randomizer](entities, p, high) + else + return buildings[randomizer](entities, p, medium) + end + elseif math.abs(p.y) < depth * 4.5 then + if math.random(1, 4) == 1 then + return buildings[randomizer](entities, p, high) + else + return buildings[randomizer](entities, p, high) + end + elseif math.abs(p.y) < depth * 5.5 then + if math.random(1, 4) == 1 then + return buildings[randomizer](entities, p, high) + elseif math.random(1, 2) == 1 then + return buildings[randomizer](entities, p, high) + elseif math.random(1, 8) == 1 then + return buildings[randomizer](entities, p, high) + end + end + if math.abs(p.y) > depth * 5.5 then + if math.random(1, 32) == 1 then + return buildings[randomizer](entities, p, medium) + end + end +end + +return spawn_random_buildings diff --git a/maps/mountain_fortress_v3/rpg.lua b/maps/mountain_fortress_v3/rpg.lua index d8ef39e0..6ec46287 100644 --- a/maps/mountain_fortress_v3/rpg.lua +++ b/maps/mountain_fortress_v3/rpg.lua @@ -9,10 +9,6 @@ local WD = require 'modules.wave_defense.table' local points_per_level = 5 -local math_floor = math.floor -local math_random = math.random -local math_sqrt = math.sqrt -local math_round = math.round local nth_tick = 18001 local visuals_delay = 1800 local level_up_floating_text_color = {0, 205, 0} @@ -170,11 +166,11 @@ local function level_up_effects(player) local b = 0.75 for a = 1, 5, 1 do local p = { - (position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), - position.y + (b * -1 + math_random(0, b * 20) * 0.1) + (position.x + 0.4) + (b * -1 + math.random(0, b * 20) * 0.1), + position.y + (b * -1 + math.random(0, b * 20) * 0.1) } player.surface.create_entity( - {name = 'flying-text', position = p, text = '✚', color = {255, math_random(0, 100), 0}} + {name = 'flying-text', position = p, text = '✚', color = {255, math.random(0, 100), 0}} ) end player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.40} @@ -188,11 +184,11 @@ local function xp_effects(player) local b = 0.75 for a = 1, 5, 1 do local p = { - (position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), - position.y + (b * -1 + math_random(0, b * 20) * 0.1) + (position.x + 0.4) + (b * -1 + math.random(0, b * 20) * 0.1), + position.y + (b * -1 + math.random(0, b * 20) * 0.1) } player.surface.create_entity( - {name = 'flying-text', position = p, text = '✚', color = {255, math_random(0, 100), 0}} + {name = 'flying-text', position = p, text = '✚', color = {255, math.random(0, 100), 0}} ) end player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.40} @@ -512,18 +508,18 @@ local function draw_gui(player, forced) add_gui_description(tt, ' ', w0) add_gui_description(tt, 'MINING\nSPEED', w1) value = - math_round((player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100) .. + math.round((player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100) .. '%' add_gui_stat(tt, value, w2) add_gui_description(tt, ' ', w0) add_gui_description(tt, 'SLOT\nBONUS', w1) - value = '+ ' .. math_round(player.force.character_inventory_slots_bonus + player.character_inventory_slots_bonus) + value = '+ ' .. math.round(player.force.character_inventory_slots_bonus + player.character_inventory_slots_bonus) add_gui_stat(tt, value, w2) add_gui_description(tt, ' ', w0) add_gui_description(tt, 'MELEE\nDAMAGE', w1) - value = math_round(100 * (1 + get_melee_modifier(player))) .. '%' + value = math.round(100 * (1 + get_melee_modifier(player))) .. '%' e = add_gui_stat(tt, value, w2) e.tooltip = 'Life on-hit: ' .. get_life_on_hit(player) .. '\nOne punch chance: ' .. get_one_punch_chance(player) .. '%' @@ -560,14 +556,14 @@ local function draw_gui(player, forced) add_gui_description(tt, ' ', w0) add_gui_description(tt, 'CRAFTING\nSPEED', w1) value = - math_round((player.force.manual_crafting_speed_modifier + player.character_crafting_speed_modifier + 1) * 100) .. + math.round((player.force.manual_crafting_speed_modifier + player.character_crafting_speed_modifier + 1) * 100) .. '%' add_gui_stat(tt, value, w2) add_gui_description(tt, ' ', w0) add_gui_description(tt, 'RUNNING\nSPEED', w1) value = - math_round((player.force.character_running_speed_modifier + player.character_running_speed_modifier + 1) * 100) .. + math.round((player.force.character_running_speed_modifier + player.character_running_speed_modifier + 1) * 100) .. '%' add_gui_stat(tt, value, w2) @@ -580,7 +576,7 @@ local function draw_gui(player, forced) add_gui_description(tt, ' ', w0) add_gui_description(tt, 'HEALTH\nBONUS', w1) - value = '+ ' .. math_round((player.force.character_health_bonus + player.character_health_bonus)) + value = '+ ' .. math.round((player.force.character_health_bonus + player.character_health_bonus)) e = add_gui_stat(tt, value, w2) e.tooltip = 'Health regen bonus: ' .. get_heal_modifier(player) @@ -677,9 +673,9 @@ local function global_pool(players, count) return end - local pool = math_floor(rpg_extra.global_pool) + local pool = math.floor(rpg_extra.global_pool) - local random_amount = math_random(5000, 10000) + local random_amount = math.random(5000, 10000) if pool <= random_amount then return @@ -879,8 +875,7 @@ local function on_entity_died(event) end if rpg_xp_yield['big-biter'] <= 16 then - local wd = WD.get_table() - local wave_number = wd.wave_number + local wave_number = WD.get_wave() if wave_number >= 1000 then rpg_xp_yield['big-biter'] = 16 rpg_xp_yield['behemoth-biter'] = 64 @@ -1101,7 +1096,7 @@ local function on_entity_damaged(event) end --Cause a one punch. - if math_random(0, 999) < get_one_punch_chance(event.cause.player) * 10 then + if math.random(0, 999) < get_one_punch_chance(event.cause.player) * 10 then one_punch(event.cause, event.entity, damage) if event.entity.valid then event.entity.die(event.entity.force.name, event.cause) @@ -1110,8 +1105,8 @@ local function on_entity_damaged(event) end --Floating messages and particle effects. - if math_random(1, 7) == 1 then - damage = damage * math_random(250, 350) * 0.01 + if math.random(1, 7) == 1 then + damage = damage * math.random(250, 350) * 0.01 event.cause.surface.create_entity( { name = 'flying-text', @@ -1122,7 +1117,7 @@ local function on_entity_damaged(event) ) event.cause.surface.create_entity({name = 'blood-explosion-huge', position = event.entity.position}) else - damage = damage * math_random(100, 125) * 0.01 + damage = damage * math.random(100, 125) * 0.01 event.cause.player.create_local_flying_text( { text = math.floor(damage), @@ -1161,7 +1156,7 @@ local function on_entity_damaged(event) end local function on_player_repaired_entity(event) - if math_random(1, 4) ~= 1 then + if math.random(1, 4) ~= 1 then return end @@ -1213,7 +1208,7 @@ local function on_player_changed_position(event) return end - if math_random(1, 64) ~= 1 then + if math.random(1, 64) ~= 1 then return end if not player.character then @@ -1253,7 +1248,7 @@ local function on_pre_player_mined_item(event) rpg_t[player.index].last_mined_entity_position.x = entity.position.x rpg_t[player.index].last_mined_entity_position.y = entity.position.y - local distance_multiplier = math_floor(math_sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) * 0.0005 + 1 + local distance_multiplier = math.floor(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)) * 0.0005 + 1 local xp_amount if entity.type == 'resource' then @@ -1278,7 +1273,7 @@ local function on_player_crafted_item(event) return end - local amount = 0.30 * math_random(1, 2) + local amount = 0.30 * math.random(1, 2) Public.gain_xp(player, event.recipe.energy * amount) end @@ -1436,7 +1431,7 @@ function Public.gain_xp(player, amount, added_to_pool, text) Public.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount) local fee = add_to_global_pool(amount) Public.debug_log('RPG - ' .. player.name .. ' got fee: ' .. fee) - amount = math_round(amount, 3) - fee + amount = math.round(amount, 3) - fee Public.debug_log('RPG - ' .. player.name .. ' got after fee: ' .. amount) else Public.debug_log('RPG - ' .. player.name .. ' got org xp: ' .. amount) @@ -1464,9 +1459,9 @@ function Public.gain_xp(player, amount, added_to_pool, text) end if text then - text_to_draw = '+' .. math_floor(amount) .. ' xp' + text_to_draw = '+' .. math.floor(amount) .. ' xp' else - text_to_draw = '+' .. math_floor(rpg_t[player.index].xp_since_last_floaty_text) .. ' xp' + text_to_draw = '+' .. math.floor(rpg_t[player.index].xp_since_last_floaty_text) .. ' xp' end player.create_local_flying_text { diff --git a/maps/mountain_fortress_v3/table.lua b/maps/mountain_fortress_v3/table.lua index e7684349..3efe363e 100644 --- a/maps/mountain_fortress_v3/table.lua +++ b/maps/mountain_fortress_v3/table.lua @@ -87,6 +87,7 @@ function Public.reset_table() y = 0 } this.traps = {} + this.much_time = true end function Public.get(key) diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index 24c639df..8c229701 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -1,20 +1,18 @@ local Event = require 'utils.event' local Biters = require 'modules.wave_defense.biter_rolls' local Functions = require 'maps.mountain_fortress_v3.functions' +local Generate_resources = require 'maps.mountain_fortress_v3.resource_generator' local WPT = require 'maps.mountain_fortress_v3.table' local get_noise = require 'utils.get_noise' local Public = {} -local math_random = math.random -local math_floor = math.floor -local math_abs = math.abs Public.level_depth = 704 Public.level_width = 512 local worm_level_modifier = 0.19 local average_number_of_wagons_per_level = 2 local chunks_per_level = ((Public.level_depth - 32) / 32) ^ 2 -local chance_for_wagon_spawn = math_floor(chunks_per_level / average_number_of_wagons_per_level) +local chance_for_wagon_spawn = math.floor(chunks_per_level / average_number_of_wagons_per_level) local wagon_raffle = {'cargo-wagon', 'cargo-wagon', 'cargo-wagon', 'locomotive', 'fluid-wagon'} local rock_raffle = { @@ -54,18 +52,26 @@ local scrap_entities = { 'crash-site-chest-1', 'crash-site-chest-2' } + local scrap_entities_index = #scrap_entities local spawner_raffle = {'biter-spawner', 'biter-spawner', 'biter-spawner', 'spitter-spawner'} local trees = {'dead-grey-trunk', 'dead-grey-trunk', 'dry-tree'} +local firearm_magazine_ammo = Functions.firearm_magazine_ammo +local piercing_rounds_magazine_ammo = Functions.piercing_rounds_magazine_ammo +local uranium_rounds_magazine_ammo = Functions.uranium_rounds_magazine_ammo +local laser_turrent_power_source = Functions.laser_turrent_power_source +local light_oil_ammo = Functions.light_oil_ammo +local artillery_shell_ammo = Functions.artillery_shell_ammo + local callback = { - [1] = {callback = Functions.refill_turret_callback, data = Functions.firearm_magazine_ammo}, - [2] = {callback = Functions.refill_turret_callback, data = Functions.piercing_rounds_magazine_ammo}, - [3] = {callback = Functions.refill_turret_callback, data = Functions.uranium_rounds_magazine_ammo}, - [4] = {callback = Functions.power_source_callback, data = Functions.laser_turrent_power_source}, - [5] = {callback = Functions.refill_liquid_turret_callback, data = Functions.light_oil_ammo}, - [6] = {callback = Functions.refill_turret_callback, data = Functions.artillery_shell_ammo} + [1] = {callback = Functions.refill_turret_callback, data = firearm_magazine_ammo}, + [2] = {callback = Functions.refill_turret_callback, data = piercing_rounds_magazine_ammo}, + [3] = {callback = Functions.refill_turret_callback, data = uranium_rounds_magazine_ammo}, + [4] = {callback = Functions.power_source_callback, data = laser_turrent_power_source}, + [5] = {callback = Functions.refill_liquid_turret_callback, data = light_oil_ammo}, + [6] = {callback = Functions.refill_turret_callback, data = artillery_shell_ammo} } local turret_list = { @@ -78,7 +84,7 @@ local turret_list = { } local function place_wagon(data) - if math_random(1, 1500) ~= 1 then + if math.random(1, 1500) ~= 1 then return end local surface = data.surface @@ -86,17 +92,17 @@ local function place_wagon(data) local entities = data.entities local top_x = data.top_x local top_y = data.top_y - local position = {x = top_x + math_random(4, 12) * 2, y = top_y + math_random(4, 12) * 2} + local position = {x = top_x + math.random(4, 12) * 2, y = top_y + math.random(4, 12) * 2} local wagon_mineable = { callback = Functions.disable_minable_and_ICW_callback } local location local direction - local r1 = math_random(2, 4) * 2 - local r2 = math_random(2, 4) * 2 + local r1 = math.random(2, 4) * 2 + local r2 = math.random(2, 4) * 2 - if math_random(1, 2) == 1 then + if math.random(1, 2) == 1 then location = surface.find_tiles_filtered({area = {{position.x, position.y - r1}, {position.x + 2, position.y + r2}}}) direction = 0 @@ -126,7 +132,7 @@ local function place_wagon(data) table.insert( entities, { - name = wagon_raffle[math_random(1, #wagon_raffle)], + name = wagon_raffle[math.random(1, #wagon_raffle)], position = position, force = 'player', callback = wagon_mineable @@ -136,7 +142,7 @@ local function place_wagon(data) end local function get_oil_amount(p) - return (math_abs(p.y) * 200 + 10000) * math_random(75, 125) * 0.01 + return (math.abs(p.y) * 200 + 10000) * math.random(75, 125) * 0.01 end function Public.increment_value(tbl) @@ -186,7 +192,7 @@ local function wall(data) tiles[#tiles + 1] = {name = 'water', position = p} else tiles[#tiles + 1] = {name = 'water-shallow', position = p} - if math_random(1, 32) == 1 then + if math.random(1, 32) == 1 then entities[#entities + 1] = { name = 'land-mine', position = p, @@ -194,15 +200,15 @@ local function wall(data) } end end - if math_random(1, 48) == 1 then + if math.random(1, 48) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end else tiles[#tiles + 1] = {name = 'tutorial-grid', position = p} - if math_random(1, 5) ~= 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} - if math_random(1, 32) == 1 then + if math.random(1, 5) ~= 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, #rock_raffle)], position = p} + if math.random(1, 32) == 1 then entities[#entities + 1] = { name = 'land-mine', position = p, @@ -223,8 +229,8 @@ local function wall(data) } ) then - if math_random(1, 512) == 1 and y > 3 and y < 28 then - if math_random(1, 2) == 1 then + if math.random(1, 512) == 1 and y > 3 and y < 28 then + if math.random(1, 2) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} else treasure[#treasure + 1] = {position = p, chest = 'steel-chest'} @@ -232,7 +238,7 @@ local function wall(data) else if y < 4 or y > 25 then if y <= 24 then - if math_random(1, y + 1) == 1 then + if math.random(1, y + 1) == 1 then entities[#entities + 1] = { name = 'stone-wall', position = p, @@ -241,7 +247,7 @@ local function wall(data) } end else - if math_random(1, 32 - y) == 1 then + if math.random(1, 32 - y) == 1 then entities[#entities + 1] = { name = 'stone-wall', position = p, @@ -254,7 +260,7 @@ local function wall(data) end end - if math_random(1, 48) == 1 then + if math.random(1, 48) == 1 then if surface.can_place_entity( { @@ -264,7 +270,7 @@ local function wall(data) } ) then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = { name = Biters.wave_defense_roll_worm_name(), position = p, @@ -273,41 +279,41 @@ local function wall(data) end end - if math_random(1, 48) == 1 then - if math_abs(p.y) < Public.level_depth * 1.5 then - if math_random(1, 16) == 1 then + if math.random(1, 48) == 1 then + if math.abs(p.y) < Public.level_depth * 1.5 then + if math.random(1, 16) == 1 then spawn_turret(entities, p, 1) else spawn_turret(entities, p, 2) end - elseif math_abs(p.y) < Public.level_depth * 2.5 then - if math_random(1, 8) == 1 then + elseif math.abs(p.y) < Public.level_depth * 2.5 then + if math.random(1, 8) == 1 then spawn_turret(entities, p, 3) end - elseif math_abs(p.y) < Public.level_depth * 3.5 then - if math_random(1, 4) == 1 then + elseif math.abs(p.y) < Public.level_depth * 3.5 then + if math.random(1, 4) == 1 then spawn_turret(entities, p, 4) else spawn_turret(entities, p, 3) end - elseif math_abs(p.y) < Public.level_depth * 4.5 then - if math_random(1, 4) == 1 then + elseif math.abs(p.y) < Public.level_depth * 4.5 then + if math.random(1, 4) == 1 then spawn_turret(entities, p, 4) else spawn_turret(entities, p, 5) end - elseif math_abs(p.y) < Public.level_depth * 5.5 then - if math_random(1, 4) == 1 then + elseif math.abs(p.y) < Public.level_depth * 5.5 then + if math.random(1, 4) == 1 then spawn_turret(entities, p, 4) - elseif math_random(1, 2) == 1 then + elseif math.random(1, 2) == 1 then spawn_turret(entities, p, 5) - elseif math_random(1, 8) == 1 then + elseif math.random(1, 8) == 1 then spawn_turret(entities, p, 6) end end - elseif math_abs(p.y) > Public.level_depth * 5.5 then - if math_random(1, 32) == 1 then - spawn_turret(entities, p, math_random(3, 6)) + elseif math.abs(p.y) > Public.level_depth * 5.5 then + if math.random(1, 32) == 1 then + spawn_turret(entities, p, math.random(3, 6)) end end end @@ -318,55 +324,64 @@ local function process_level_13_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local treasure = data.treasure local small_caves = get_noise('small_caves', p, seed) local noise_cave_ponds = get_noise('cave_ponds', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 70000) if small_caves > -0.22 and small_caves < 0.22 then tiles[#tiles + 1] = {name = 'dirt-3', position = p} - if math_random(1, 768) == 1 then + if math.random(1, 768) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end if small_caves < -0.35 or small_caves > 0.35 then tiles[#tiles + 1] = {name = 'deepwater-green', position = p} - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end - if math_random(1, 128) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 128) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then spawn_turret(entities, p, 4) end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + if small_caves > -0.40 and small_caves < 0.40 then if noise_cave_ponds > 0.35 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_random(1, 4), position = p} - if math_random(1, 256) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.random(1, 4), position = p} + if math.random(1, 256) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end return end if noise_cave_ponds > 0.25 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end @@ -380,21 +395,23 @@ local function process_level_12_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure local noise_1 = get_noise('small_caves', p, seed) local noise_2 = get_noise('no_rocks_2', p, seed + 20000) + local smol_areas = get_noise('smol_areas', p, seed + 60000) if noise_1 > 0.65 then - if math_random(1, 100) > 88 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 100) > 88 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} else - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end end - if math_random(1, 48) == 1 then + if math.random(1, 48) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -402,8 +419,8 @@ local function process_level_12_position(x, y, data) if noise_1 < -0.72 then tiles[#tiles + 1] = {name = 'lab-dark-2', position = p} - if math_random(1, 100) > 88 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 100) > 88 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end return end @@ -411,10 +428,10 @@ local function process_level_12_position(x, y, data) if noise_1 > -0.30 and noise_1 < 0.30 then if noise_1 > -0.14 and noise_1 < 0.14 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end else @@ -423,23 +440,30 @@ local function process_level_12_position(x, y, data) return end - if math_random(1, 64) == 1 and noise_2 > 0.65 then - if math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'stone', position = p, amount = math_abs(p.y) + 1} - elseif math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'iron-ore', position = p, amount = math_abs(p.y) + 1} - elseif math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'copper-ore', position = p, amount = math_abs(p.y) + 1} - elseif math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'coal', position = p, amount = math_abs(p.y) + 1} + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) end end - if math_random(1, 8192) == 1 then + + if math.random(1, 64) == 1 and noise_2 > 0.65 then + if math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'stone', position = p, amount = math.abs(p.y) + 1} + elseif math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'iron-ore', position = p, amount = math.abs(p.y) + 1} + elseif math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'copper-ore', position = p, amount = math.abs(p.y) + 1} + elseif math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'coal', position = p, amount = math.abs(p.y) + 1} + end + end + if math.random(1, 8192) == 1 then markets[#markets + 1] = p end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then entities[#entities + 1] = { - name = 'crash-site-chest-' .. math_random(1, 2), + name = 'crash-site-chest-' .. math.random(1, 2), position = p, force = 'neutral' } @@ -453,15 +477,17 @@ local function process_level_11_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure local noise_1 = get_noise('small_caves', p, seed) local noise_2 = get_noise('no_rocks_2', p, seed + 10000) + local smol_areas = get_noise('smol_areas', p, seed + 50000) if noise_1 > 0.7 then tiles[#tiles + 1] = {name = 'water', position = p} - if math_random(1, 48) == 1 then + if math.random(1, 48) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -469,17 +495,17 @@ local function process_level_11_position(x, y, data) if noise_1 < -0.72 then tiles[#tiles + 1] = {name = 'lab-dark-1', position = p} - entities[#entities + 1] = {name = 'uranium-ore', position = p, amount = math_abs(p.y) + 1 * 3} + entities[#entities + 1] = {name = 'uranium-ore', position = p, amount = math.abs(p.y) + 1 * 3} return end if noise_1 > -0.30 and noise_1 < 0.30 then if noise_1 > -0.14 and noise_1 < 0.14 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end else @@ -488,15 +514,22 @@ local function process_level_11_position(x, y, data) return end - if math_random(1, 64) == 1 and noise_2 > 0.65 then + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + + if math.random(1, 64) == 1 and noise_2 > 0.65 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 8192) == 1 then + if math.random(1, 8192) == 1 then markets[#markets + 1] = p end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then entities[#entities + 1] = { - name = 'crash-site-chest-' .. math_random(1, 2), + name = 'crash-site-chest-' .. math.random(1, 2), position = p, force = 'neutral' } @@ -510,13 +543,15 @@ local function process_level_10_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local treasure = data.treasure local scrapyard = get_noise('scrapyard', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 45000) if scrapyard < -0.70 or scrapyard > 0.70 then tiles[#tiles + 1] = {name = 'grass-3', position = p} - if math_random(1, 40) == 1 then + if math.random(1, 40) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return @@ -526,31 +561,39 @@ local function process_level_10_position(x, y, data) tiles[#tiles + 1] = {name = 'water-green', position = p} return end - if math_abs(scrapyard) > 0.40 and math_abs(scrapyard) < 0.65 then - if math_random(1, 64) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + + if math.abs(scrapyard) > 0.40 and math.abs(scrapyard) < 0.65 then + if math.random(1, 64) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end tiles[#tiles + 1] = {name = 'water-mud', position = p} return end - if math_abs(scrapyard) > 0.25 and math_abs(scrapyard) < 0.40 then - if math_random(1, 128) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.abs(scrapyard) > 0.25 and math.abs(scrapyard) < 0.40 then + if math.random(1, 128) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then spawn_turret(entities, p, 4) end tiles[#tiles + 1] = {name = 'water-shallow', position = p} return end if scrapyard > -0.15 and scrapyard < 0.15 then - if math_random(1, 100) > 88 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 100) > 88 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} else - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end end tiles[#tiles + 1] = {name = 'dirt-6', position = p} @@ -564,51 +607,60 @@ local function process_level_9_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure - local maze_p = {x = math_floor(p.x - p.x % 10), y = math_floor(p.y - p.y % 10)} + local maze_p = {x = math.floor(p.x - p.x % 10), y = math.floor(p.y - p.y % 10)} local maze_noise = get_noise('no_rocks_2', maze_p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 40000) if maze_noise > -0.35 and maze_noise < 0.35 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} local no_rocks_2 = get_noise('no_rocks_2', p, seed) - if math_random(1, 2) == 1 and no_rocks_2 > -0.5 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 and no_rocks_2 > -0.5 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 256) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 256) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end return end if maze_noise > 0 and maze_noise < 0.45 then - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then markets[#markets + 1] = p end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + if maze_noise < -0.5 or maze_noise > 0.5 then tiles[#tiles + 1] = {name = 'deepwater', position = p} - if math_random(1, 96) == 1 then + if math.random(1, 96) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return end tiles[#tiles + 1] = {name = 'water', position = p} - if math_random(1, 96) == 1 then + if math.random(1, 96) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end end @@ -619,8 +671,10 @@ local function process_level_8_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local scrapyard = get_noise('scrapyard', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 35000) --Chasms local noise_cave_ponds = get_noise('cave_ponds', p, seed) @@ -638,8 +692,8 @@ local function process_level_8_position(x, y, data) end if scrapyard < -0.25 or scrapyard > 0.25 then - if math_random(1, 256) == 1 then - if math_random(1, 8) == 1 then + if math.random(1, 256) == 1 then + if math.random(1, 8) == 1 then spawn_turret(entities, p, 3) else spawn_turret(entities, p, 4) @@ -647,27 +701,27 @@ local function process_level_8_position(x, y, data) end tiles[#tiles + 1] = {name = 'dirt-7', position = p} if scrapyard < -0.55 or scrapyard > 0.55 then - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end if scrapyard < -0.28 or scrapyard > 0.28 then - if math_random(1, 128) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 128) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end - if math_random(1, 96) == 1 then + if math.random(1, 96) == 1 then entities[#entities + 1] = { - name = scrap_entities[math_random(1, scrap_entities_index)], + name = scrap_entities[math.random(1, scrap_entities_index)], position = p, force = 'enemy' } end - if math_random(1, 5) > 1 then + if math.random(1, 5) > 1 then entities[#entities + 1] = {name = 'mineable-wreckage', position = p} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then entities[#entities + 1] = {name = 'land-mine', position = p, force = 'enemy'} end return @@ -678,29 +732,36 @@ local function process_level_8_position(x, y, data) local cave_ponds = get_noise('cave_ponds', p, seed) if cave_ponds < -0.6 and scrapyard > -0.2 and scrapyard < 0.2 then tiles[#tiles + 1] = {name = 'deepwater-green', position = p} - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + local large_caves = get_noise('large_caves', p, seed) if scrapyard > -0.15 and scrapyard < 0.15 then - if math_floor(large_caves * 10) % 4 < 3 then + if math.floor(large_caves * 10) % 4 < 3 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end end - if math_random(1, 64) == 1 and cave_ponds > 0.6 then + if math.random(1, 64) == 1 and cave_ponds > 0.6 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end tiles[#tiles + 1] = {name = 'stone-path', position = p} - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then entities[#entities + 1] = {name = 'land-mine', position = p, force = 'enemy'} end end @@ -710,16 +771,18 @@ local function process_level_7_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure local cave_rivers_3 = get_noise('cave_rivers_3', p, seed) local cave_rivers_4 = get_noise('cave_rivers_4', p, seed + 50000) local no_rocks_2 = get_noise('no_rocks_2', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 30000) if cave_rivers_3 > -0.025 and cave_rivers_3 < 0.025 and no_rocks_2 > -0.6 then tiles[#tiles + 1] = {name = 'water', position = p} - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -727,57 +790,64 @@ local function process_level_7_position(x, y, data) if cave_rivers_4 > -0.025 and cave_rivers_4 < 0.025 and no_rocks_2 > -0.6 then tiles[#tiles + 1] = {name = 'water', position = p} - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + local noise_ores = get_noise('no_rocks_2', p, seed + 25000) if cave_rivers_3 > -0.20 and cave_rivers_3 < 0.20 then - tiles[#tiles + 1] = {name = 'grass-' .. math_floor(cave_rivers_3 * 32) % 3 + 1, position = p} + tiles[#tiles + 1] = {name = 'grass-' .. math.floor(cave_rivers_3 * 32) % 3 + 1, position = p} if cave_rivers_3 > -0.10 and cave_rivers_3 < 0.10 then - if math_random(1, 8) == 1 and no_rocks_2 > -0.25 then + if math.random(1, 8) == 1 and no_rocks_2 > -0.25 then entities[#entities + 1] = {name = 'tree-01', position = p} end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then markets[#markets + 1] = p end if noise_ores < -0.5 and no_rocks_2 > -0.6 then if cave_rivers_3 > 0 and cave_rivers_3 < 0.07 then - entities[#entities + 1] = {name = 'iron-ore', position = p, amount = math_abs(p.y) + 1} + entities[#entities + 1] = {name = 'iron-ore', position = p, amount = math.abs(p.y) + 1} end end end - if math_random(1, 64) == 1 and no_rocks_2 > 0.7 then + if math.random(1, 64) == 1 and no_rocks_2 > 0.7 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return end if cave_rivers_4 > -0.20 and cave_rivers_4 < 0.20 then - tiles[#tiles + 1] = {name = 'grass-' .. math_floor(cave_rivers_4 * 32) % 3 + 1, position = p} + tiles[#tiles + 1] = {name = 'grass-' .. math.floor(cave_rivers_4 * 32) % 3 + 1, position = p} if cave_rivers_4 > -0.10 and cave_rivers_4 < 0.10 then - if math_random(1, 8) == 1 and no_rocks_2 > -0.25 then + if math.random(1, 8) == 1 and no_rocks_2 > -0.25 then entities[#entities + 1] = {name = 'tree-02', position = p} end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then markets[#markets + 1] = p end if noise_ores < -0.5 and no_rocks_2 > -0.6 then if cave_rivers_4 > 0 and cave_rivers_4 < 0.07 then - entities[#entities + 1] = {name = 'copper-ore', position = p, amount = math_abs(p.y) + 1} + entities[#entities + 1] = {name = 'copper-ore', position = p, amount = math.abs(p.y) + 1} end end end - if math_random(1, 64) == 1 and no_rocks_2 > 0.7 then + if math.random(1, 64) == 1 and no_rocks_2 > 0.7 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return @@ -799,11 +869,18 @@ local function process_level_7_position(x, y, data) end end - tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 100) > 15 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end end - if math_random(1, 256) == 1 then + + tiles[#tiles + 1] = {name = 'dirt-7', position = p} + if math.random(1, 100) > 15 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} + end + if math.random(1, 256) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end end @@ -813,11 +890,13 @@ local function process_level_6_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure local large_caves = get_noise('large_caves', p, seed) local cave_rivers = get_noise('cave_rivers', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 25000) --Chasms local noise_cave_ponds = get_noise('cave_ponds', p, seed) @@ -836,35 +915,42 @@ local function process_level_6_position(x, y, data) if large_caves > -0.03 and large_caves < 0.03 and cave_rivers < 0.25 then tiles[#tiles + 1] = {name = 'water-green', position = p} - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return end - if cave_rivers > -0.1 and cave_rivers < 0.1 then - if math_random(1, 36) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) end - if math_random(1, 128) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + end + + if cave_rivers > -0.1 and cave_rivers < 0.1 then + if math.random(1, 36) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} + end + if math.random(1, 128) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then spawn_turret(entities, p, 4) end else tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 100) > 15 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 100) > 15 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 4096) == 1 then + if math.random(1, 4096) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 8096) == 1 then + if math.random(1, 8096) == 1 then markets[#markets + 1] = p end end @@ -875,55 +961,64 @@ local function process_level_5_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local treasure = data.treasure local small_caves = get_noise('small_caves', p, seed) local noise_cave_ponds = get_noise('cave_ponds', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 20000) if small_caves > -0.24 and small_caves < 0.24 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 768) == 1 then + if math.random(1, 768) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end if small_caves < -0.50 or small_caves > 0.50 then tiles[#tiles + 1] = {name = 'deepwater-green', position = p} - if math_random(1, 128) == 1 then + if math.random(1, 128) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end - if math_random(1, 128) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 128) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then spawn_turret(entities, p, 4) end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + if small_caves > -0.40 and small_caves < 0.40 then if noise_cave_ponds > 0.35 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_random(1, 4), position = p} - if math_random(1, 256) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.random(1, 4), position = p} + if math.random(1, 256) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end return end if noise_cave_ponds > 0.25 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end end end @@ -936,48 +1031,50 @@ local function process_level_4_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure local noise_large_caves = get_noise('large_caves', p, seed) local noise_cave_ponds = get_noise('cave_ponds', p, seed) local small_caves = get_noise('small_caves', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 15000) - if math_abs(noise_large_caves) > 0.7 then + if math.abs(noise_large_caves) > 0.7 then tiles[#tiles + 1] = {name = 'water', position = p} - if math_random(1, 16) == 1 then + if math.random(1, 16) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return end - if math_abs(noise_large_caves) > 0.6 then - if math_random(1, 16) == 1 then + if math.abs(noise_large_caves) > 0.6 then + if math.random(1, 16) == 1 then entities[#entities + 1] = {name = 'tree-02', position = p} end - if math_random(1, 32) == 1 then + if math.random(1, 32) == 1 then markets[#markets + 1] = p end end - if math_abs(noise_large_caves) > 0.5 then + if math.abs(noise_large_caves) > 0.5 then tiles[#tiles + 1] = {name = 'grass-2', position = p} - if math_random(1, 620) == 1 then + if math.random(1, 620) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 384) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 384) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'} end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return end - if math_abs(noise_large_caves) > 0.475 then + if math.abs(noise_large_caves) > 0.475 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return @@ -998,32 +1095,39 @@ local function process_level_4_position(x, y, data) if small_caves > -0.15 and small_caves < 0.15 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 2) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 2) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + if noise_large_caves > -0.2 and noise_large_caves < 0.2 then --Main Rock Terrain local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} - if math_random(1, 512) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 100) > 30 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 100) > 30 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end @@ -1036,6 +1140,7 @@ local function process_level_3_position(x, y, data) local seed = data.seed local tiles = data.tiles local entities = data.entities + local buildings = data.buildings local markets = data.markets local treasure = data.treasure @@ -1043,29 +1148,37 @@ local function process_level_3_position(x, y, data) local small_caves_2 = get_noise('small_caves_2', p, seed + 70000) local noise_large_caves = get_noise('large_caves', p, seed + 60000) local noise_cave_ponds = get_noise('cave_ponds', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 60000) --Market Spots if noise_cave_ponds < -0.77 then if noise_cave_ponds > -0.79 then tiles[#tiles + 1] = {name = 'dirt-7', position = p} - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} else - tiles[#tiles + 1] = {name = 'grass-' .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p} - if math_random(1, 32) == 1 then + tiles[#tiles + 1] = {name = 'grass-' .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p} + if math.random(1, 32) == 1 then markets[#markets + 1] = p end - if math_random(1, 16) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 16) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + if noise_large_caves > -0.15 and noise_large_caves < 0.15 or small_caves_2 > 0 then --Green Water Ponds if noise_cave_ponds > 0.80 then tiles[#tiles + 1] = {name = 'deepwater-green', position = p} - if math_random(1, 16) == 1 then + if math.random(1, 16) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1091,7 +1204,7 @@ local function process_level_3_position(x, y, data) if cave_rivers < 0.024 and cave_rivers > -0.024 then if noise_cave_ponds > 0.2 then tiles[#tiles + 1] = {name = 'water-shallow', position = p} - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1101,7 +1214,7 @@ local function process_level_3_position(x, y, data) if cave_rivers_2 < 0.024 and cave_rivers_2 > -0.024 then if noise_cave_ponds < 0.4 then tiles[#tiles + 1] = {name = 'water-shallow', position = p} - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1109,7 +1222,7 @@ local function process_level_3_position(x, y, data) end if noise_cave_ponds > 0.725 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_random(4, 6), position = p} + tiles[#tiles + 1] = {name = 'dirt-' .. math.random(4, 6), position = p} return end @@ -1117,25 +1230,25 @@ local function process_level_3_position(x, y, data) --Worm oil Zones if no_rocks < 0.20 and no_rocks > -0.20 then if small_caves > 0.35 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p} - if math_random(1, 320) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p} + if math.random(1, 320) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 50) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 50) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = { name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy' } end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then spawn_turret(entities, p, 3) end - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then entities[#entities + 1] = {name = 'dead-tree-desert', position = p} end return @@ -1145,19 +1258,19 @@ local function process_level_3_position(x, y, data) --Main Rock Terrain local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} - if math_random(1, 512) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 100) > 30 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 100) > 30 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end @@ -1169,12 +1282,14 @@ local function process_level_2_position(x, y, data) local p = {x = x, y = y} local seed = data.seed local tiles = data.tiles + local buildings = data.buildings local entities = data.entities local markets = data.markets local treasure = data.treasure local small_caves = get_noise('small_caves', p, seed) local noise_large_caves = get_noise('large_caves', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 15000) if noise_large_caves > -0.75 and noise_large_caves < 0.75 then local noise_cave_ponds = get_noise('cave_ponds', p, seed) @@ -1195,7 +1310,7 @@ local function process_level_2_position(x, y, data) --Green Water Ponds if noise_cave_ponds > 0.80 then tiles[#tiles + 1] = {name = 'deepwater-green', position = p} - if math_random(1, 16) == 1 then + if math.random(1, 16) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1206,7 +1321,7 @@ local function process_level_2_position(x, y, data) if cave_rivers < 0.037 and cave_rivers > -0.037 then if noise_cave_ponds < 0.1 then tiles[#tiles + 1] = {name = 'water-shallow', position = p} - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1214,45 +1329,52 @@ local function process_level_2_position(x, y, data) end if noise_cave_ponds > 0.66 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_random(4, 6), position = p} + tiles[#tiles + 1] = {name = 'dirt-' .. math.random(4, 6), position = p} return end --Market Spots if noise_cave_ponds < -0.80 then - tiles[#tiles + 1] = {name = 'grass-' .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p} - if math_random(1, 32) == 1 then + tiles[#tiles + 1] = {name = 'grass-' .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p} + if math.random(1, 32) == 1 then markets[#markets + 1] = p end - if math_random(1, 16) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 16) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + local no_rocks = get_noise('no_rocks', p, seed + 25000) --Worm oil Zones if no_rocks < 0.20 and no_rocks > -0.20 then if small_caves > 0.30 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p} - if math_random(1, 450) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p} + if math.random(1, 450) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 64) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 64) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = { name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy' } end - if math_random(1, 256) == 1 then + if math.random(1, 256) == 1 then spawn_turret(entities, p, 2) end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then entities[#entities + 1] = {name = 'dead-tree-desert', position = p} end return @@ -1262,19 +1384,19 @@ local function process_level_2_position(x, y, data) --Main Rock Terrain local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} - if math_random(1, 512) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end return end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'wooden-chest'} end tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 100) > 25 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 100) > 25 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end return end @@ -1285,14 +1407,15 @@ end local function process_level_1_position(x, y, data) local p = {x = x, y = y} local seed = data.seed + local buildings = data.buildings local tiles = data.tiles local entities = data.entities local markets = data.markets local treasure = data.treasure local small_caves = get_noise('small_caves', p, seed) - local noise_cave_ponds = get_noise('cave_ponds', p, seed) + local smol_areas = get_noise('smol_areas', p, seed + 50000) --Chasms if noise_cave_ponds < 0.111 and noise_cave_ponds > -0.112 then @@ -1309,7 +1432,7 @@ local function process_level_1_position(x, y, data) --Water Ponds if noise_cave_ponds > 0.810 then tiles[#tiles + 1] = {name = 'deepwater', position = p} - if math_random(1, 16) == 1 then + if math.random(1, 16) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1320,7 +1443,7 @@ local function process_level_1_position(x, y, data) if cave_rivers < 0.042 and cave_rivers > -0.042 then if noise_cave_ponds > 0 then tiles[#tiles + 1] = {name = 'water-shallow', position = p} - if math_random(1, 64) == 1 then + if math.random(1, 64) == 1 then entities[#entities + 1] = {name = 'fish', position = p} end return @@ -1328,40 +1451,47 @@ local function process_level_1_position(x, y, data) end if noise_cave_ponds > 0.74 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_random(4, 6), position = p} + tiles[#tiles + 1] = {name = 'dirt-' .. math.random(4, 6), position = p} tiles[#tiles + 1] = {name = 'grass-1', position = p} if cave_rivers < -0.502 then tiles[#tiles + 1] = {name = 'refined-hazard-concrete-right', position = p} end - if math_random(1, 64) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 64) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end return end --Market Spots if noise_cave_ponds < -0.74 then - tiles[#tiles + 1] = {name = 'grass-' .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p} - if math_random(1, 32) == 1 then + tiles[#tiles + 1] = {name = 'grass-' .. math.floor(noise_cave_ponds * 32) % 3 + 1, position = p} + if math.random(1, 32) == 1 then markets[#markets + 1] = p end - if math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end return end + --Resource Spots + if smol_areas < -0.72 then + if math.random(1, 8) == 1 then + Generate_resources(buildings, p, Public.level_depth) + end + end + local no_rocks = get_noise('no_rocks', p, seed + 25000) --Worm oil Zones if p.y < -64 + noise_cave_ponds * 10 then if no_rocks < 0.12 and no_rocks > -0.12 then if small_caves > 0.30 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = p} - if math_random(1, 450) == 1 then + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(noise_cave_ponds * 32) % 7 + 1, position = p} + if math.random(1, 450) == 1 then entities[#entities + 1] = {name = 'crude-oil', position = p, amount = get_oil_amount(p)} end - if math_random(1, 96) == 1 then - Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier) + if math.random(1, 96) == 1 then + Biters.wave_defense_set_worm_raffle(math.abs(p.y) * worm_level_modifier) entities[#entities + 1] = { name = Biters.wave_defense_roll_worm_name(), position = p, @@ -1369,11 +1499,11 @@ local function process_level_1_position(x, y, data) } end - if math_random(1, 1024) == 1 then + if math.random(1, 1024) == 1 then treasure[#treasure + 1] = {position = p, chest = 'iron-chest'} end - if math_random(1, 64) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + if math.random(1, 64) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end return end @@ -1383,22 +1513,22 @@ local function process_level_1_position(x, y, data) --Main Rock Terrain local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000) if no_rocks_2 > 0.66 or no_rocks_2 < -0.66 then - tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p} - if math_random(1, 32) == 1 then - entities[#entities + 1] = {name = 'tree-0' .. math_random(1, 9), position = p} + tiles[#tiles + 1] = {name = 'dirt-' .. math.floor(no_rocks_2 * 8) % 2 + 5, position = p} + if math.random(1, 32) == 1 then + entities[#entities + 1] = {name = 'tree-0' .. math.random(1, 9), position = p} end - if math_random(1, 512) == 1 then + if math.random(1, 512) == 1 then treasure[#treasure + 1] = {position = p, chest = 'iron-chest'} end return end - if math_random(1, 2048) == 1 then + if math.random(1, 2048) == 1 then treasure[#treasure + 1] = {position = p, chest = 'iron-chest'} end tiles[#tiles + 1] = {name = 'dirt-7', position = p} - if math_random(1, 100) > 25 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, size_of_rock_raffle)], position = p} + if math.random(1, 100) > 25 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, size_of_rock_raffle)], position = p} end end @@ -1427,7 +1557,7 @@ end local function process_bits(x, y, data) local left_top_y = data.area.left_top.y - local index = math_floor((math_abs(left_top_y / Public.level_depth)) % 13) + 1 + local index = math.floor((math.abs(left_top_y / Public.level_depth)) % 13) + 1 local process_level = Public.levels[index] if not process_level then process_level = Public.levels[#Public.levels] @@ -1447,25 +1577,25 @@ local function border_chunk(data) local pos = {x = x + data.top_x, y = y + data.top_y} - if math_random(1, math.ceil(pos.y + pos.y) + 64) == 1 then - entities[#entities + 1] = {name = trees[math_random(1, #trees)], position = pos} + if math.random(1, math.ceil(pos.y + pos.y) + 64) == 1 then + entities[#entities + 1] = {name = trees[math.random(1, #trees)], position = pos} end if not is_out_of_map(pos) then - if math_random(1, math.ceil(pos.y + pos.y) + 32) == 1 then - entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = pos} + if math.random(1, math.ceil(pos.y + pos.y) + 32) == 1 then + entities[#entities + 1] = {name = rock_raffle[math.random(1, #rock_raffle)], position = pos} end - if math_random(1, pos.y + 2) == 1 then + if math.random(1, pos.y + 2) == 1 then decoratives[#decoratives + 1] = { name = 'rock-small', position = pos, - amount = math_random(1, 1 + math.ceil(20 - y / 2)) + amount = math.random(1, 1 + math.ceil(20 - y / 2)) } end - if math_random(1, pos.y + 2) == 1 then + if math.random(1, pos.y + 2) == 1 then decoratives[#decoratives + 1] = { name = 'rock-tiny', position = pos, - amount = math_random(1, 1 + math.ceil(20 - y / 2)) + amount = math.random(1, 1 + math.ceil(20 - y / 2)) } end end @@ -1495,10 +1625,10 @@ local function biter_chunk(data) if math.random(1, 128) == 1 then local position = - surface.find_non_colliding_position('biter-spawner', tile_positions[math_random(1, #tile_positions)], 16, 2) + surface.find_non_colliding_position('biter-spawner', tile_positions[math.random(1, #tile_positions)], 16, 2) if position then entities[#entities + 1] = { - name = spawner_raffle[math_random(1, #spawner_raffle)], + name = spawner_raffle[math.random(1, #spawner_raffle)], position = position, force = 'enemy', callback = disable_spawners @@ -1510,7 +1640,7 @@ local function biter_chunk(data) local position = surface.find_non_colliding_position( 'big-worm-turret', - tile_positions[math_random(1, #tile_positions)], + tile_positions[math.random(1, #tile_positions)], 16, 2 ) @@ -1538,7 +1668,7 @@ function Public.heavy_functions(x, y, data) local top_y = data.top_y local surface = data.surface local p = {x = data.x, y = data.y} - local oom = surface.get_tile(p).name == 'out-of-map' + local get_tile = surface.get_tile(p) local map_name = 'mountain_fortress_v3' @@ -1549,7 +1679,8 @@ function Public.heavy_functions(x, y, data) if not data.seed then data.seed = data.surface.map_gen_settings.seed end - if oom then + + if get_tile.valid and get_tile.name == 'out-of-map' then return end @@ -1572,7 +1703,7 @@ function Public.heavy_functions(x, y, data) if top_y < 0 then process_bits(x, y, data) - if math_random(1, chance_for_wagon_spawn) == 1 then + if math.random(1, chance_for_wagon_spawn) == 1 then place_wagon(data) end return diff --git a/maps/mountain_fortress_v3/traps.lua b/maps/mountain_fortress_v3/traps.lua index 7babee93..3c5b3085 100644 --- a/maps/mountain_fortress_v3/traps.lua +++ b/maps/mountain_fortress_v3/traps.lua @@ -16,8 +16,8 @@ local kaboom_weights = { local kabooms = {} for _, t in pairs(kaboom_weights) do - for x = 1, t.chance, 1 do - table.insert(kabooms, t.name) + for _ = 1, t.chance, 1 do + kabooms[#kabooms + 1] = t.name end end diff --git a/maps/mountain_fortress_v3/void_away.lua b/maps/mountain_fortress_v3/void_away.lua deleted file mode 100644 index 9147e6f2..00000000 --- a/maps/mountain_fortress_v3/void_away.lua +++ /dev/null @@ -1,49 +0,0 @@ -local Event = require 'utils.event' -local random = math.random - -local function void_replace_tiles_in_chunk(event) - local surface = event.surface - local map_name = 'mountain_fortress_v3' - - if string.sub(surface.name, 0, #map_name) ~= map_name then - return - end - local area = event.area - local top_x = area.left_top.x - local top_y = area.left_top.y - local bottom_x = area.right_bottom.x - local bottom_y = area.right_bottom.y - local tiles = {} - if top_x > -33 and bottom_x < 1 and top_y > -33 and bottom_y < 1 then - return - end - for i = top_y, bottom_y do - for j = top_x, bottom_x do - if (random(100) < global.void.tile_chance) then - if (random(100) > global.void.void_chance) then - table.insert(tiles, {name = 'water', position = {j, i}}) - else - table.insert(tiles, {name = 'out-of-map', position = {j, i}}) - end - end - end - end - surface.set_tiles(tiles) -end - -Event.add( - defines.events.on_chunk_generated, - function(event) - void_replace_tiles_in_chunk(event) - end -) - -Event.on_init( - function() - global.void = global.void or {} - global.void.seed = 1 - global.void.tile_chance = 7 - global.void.void_chance = 90 - global.void_module.seed = random(1, 999999) - end -) diff --git a/utils/get_noise.lua b/utils/get_noise.lua index 4736531e..1678bf8b 100644 --- a/utils/get_noise.lua +++ b/utils/get_noise.lua @@ -9,6 +9,7 @@ local noises = { }, ['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},