1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-17 20:58:13 +02:00

hardmode on

This commit is contained in:
Gerkiz 2019-11-07 21:24:58 +01:00
parent 2900491bc8
commit 9866e88fd8
4 changed files with 583 additions and 128 deletions

View File

@ -1,7 +1,7 @@
local Public = {}
local math_random = math.random
function Public.create_loot(surface, position, chest)
function Public.add(surface, position, chest)
local chest_raffle = {}
local chest_loot = {
{{name = "submachine-gun", count = math_random(1,3)}, weight = 3, d_min = 0.0, d_max = 0.1},
@ -154,7 +154,7 @@ function Public.create_loot(surface, position, chest)
end
end
local e = surface.create_entity({name = chest, position=position, force="neutral"})
local e = surface.create_entity({name = chest, position=position, force="scrap"})
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(2,6), 1 do

View File

@ -1,10 +1,11 @@
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.mineable_wreckage_yields_ores"
require "modules.mineable_wreckage_yields_scrap"
require "modules.rocks_heal_over_time"
require "modules.rocks_yield_ore_veins"
require "modules.spawners_contain_biters"
require "modules.biters_yield_coins"
require "modules.explosives"
require "modules.dangerous_goods"
require "modules.wave_defense.main"
@ -13,7 +14,8 @@ local Map = require 'modules.map_info'
local RPG = require 'modules.rpg'
local Reset = require "functions.soft_reset"
local BiterRolls = require "modules.wave_defense.biter_rolls"
local unearthing_worm = require "functions.unearthing_worm"
local unearthing_biters = require "functions.unearthing_biters"
local Loot = require 'maps.scrapyard.loot'
local Pets = require "modules.biter_pets"
local Modifier = require "player_modifiers"
@ -35,6 +37,15 @@ local treasure_chest_messages = {
"We has found the precious!",
}
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math_random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
function Public.reset_map()
global.spawn_generated = false
local wave_defense_table = WD.get_table()
@ -187,12 +198,36 @@ function Public.reset_map()
wave_defense_table.game_lost = false
wave_defense_table.spawn_position = {x=0,y=220}
game.forces.player.set_friend('scrap', true)
game.forces.enemy.set_friend('scrap', true)
game.forces.scrap.set_friend('player', true)
game.forces.scrap.set_friend('enemy', true)
game.forces.scrap.share_chart = false
global.explosion_cells_destructible_tiles = {
["out-of-map"] = 1500,
["water"] = 1000,
["water-green"] = 1000,
["deepwater-green"] = 1000,
["deepwater"] = 1000,
["water-shallow"] = 1000,
}
surface.create_entity({name = "electric-beam", position = {-96, 190}, source = {-96, 190}, target = {96,190}})
surface.create_entity({name = "electric-beam", position = {-96, 190}, source = {-96, 190}, target = {96,190}})
RPG.rpg_reset_all_players()
end
local function set_difficulty()
local wave_defense_table = WD.get_table()
wave_defense_table.threat_gain_multiplier = 2 + #game.connected_players * 0.1
--20 Players for fastest wave_interval
wave_defense_table.wave_interval = 3600 - #game.connected_players * 90
if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end
end
local function protect_train(event)
if event.entity.force.index ~= 1 then return end --Player Force
if event.entity == global.locomotive_cargo then
@ -208,7 +243,9 @@ end
local function on_player_changed_position(event)
local player = game.players[event.player_index]
local surface = game.surfaces[global.active_surface_index]
if player.position.y < 20 then Terrain.reveal(player) end
if player.position.x >= 960 then return end
if player.position.x <= -960 then return end
if player.position.y < 5 then Terrain.reveal(player, event) end
if player.position.y >= 190 then
player.teleport({player.position.x, player.position.y - 1}, surface)
player.print("The forcefield does not approve.",{r=0.98, g=0.66, b=0.22})
@ -226,10 +263,15 @@ local function on_marked_for_deconstruction(event)
end
end
local function on_player_left_game(event)
set_difficulty()
end
local function on_player_joined_game(event)
local surface = game.surfaces[global.active_surface_index]
local player = game.players[event.player_index]
set_difficulty(event)
if player.surface.index ~= global.active_surface_index then
player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 3, 0,5), surface)
@ -277,11 +319,19 @@ local function hidden_treasure(event)
Loot.create_loot(event.entity.surface, event.entity.position, "wooden-chest")
end
local function biters_chew_rocks_faster(event)
if event.entity.force.index ~= 3 then return end --Neutral Force
if not event.cause then return end
if not event.cause.valid then return end
if event.cause.force.index ~= 2 then return end --Enemy Force
event.entity.health = event.entity.health - event.final_damage_amount * 2.5
end
local function give_coin(player)
player.insert({name = "coin", count = 1})
end
local function on_player_mined_entity(event)
local entity = event.entity
local player = game.players[event.player_index]
@ -311,11 +361,29 @@ local function on_player_mined_entity(event)
end
if entity.force.name ~= "scrap" then return end
local positions = {}
local r = math.ceil(entity.prototype.max_health / 32)
for x = r * -1, r, 1 do
for y = r * -1, r, 1 do
positions[#positions + 1] = {x = entity.position.x + x, y = entity.position.y + y}
end
end
positions = shuffle(positions)
for i = 1, math.ceil(entity.prototype.max_health / 32), 1 do
if not positions[i] then return end
if math_random(1,3) ~= 1 then
unearthing_biters(entity.surface, positions[i], math_random(5,10))
else
unearthing_worm(entity.surface, positions[i])
end
end
end
local function on_entity_damaged(event)
if not event.entity.valid then return end
protect_train(event)
if not event.entity.health then return end
biters_chew_rocks_faster(event)
end
local function on_entity_died(event)
@ -326,7 +394,7 @@ local function on_entity_died(event)
end
if event.entity == global.locomotive_cargo then
game.print("Fools! The cargo was destroyed!")
game.print("The cargo was destroyed!")
wave_defense_table.game_lost = true
wave_defense_table.target = nil
global.game_reset_tick = game.tick + 1800
@ -359,6 +427,13 @@ local function on_research_finished(event)
end
local on_init = function()
game.create_force("scrap")
game.create_force("scrap_defense")
game.forces.player.set_friend('scrap', true)
game.forces.enemy.set_friend('scrap', true)
game.forces.scrap.set_friend('player', true)
game.forces.scrap.set_friend('enemy', true)
game.forces.scrap.share_chart = false
Public.reset_map()
local T = Map.Pop_info()
T.main_caption = "S c r a p y a r d"
@ -377,13 +452,6 @@ local on_init = function()
})
T.main_caption_color = {r = 150, g = 150, b = 0}
T.sub_caption_color = {r = 0, g = 150, b = 0}
game.create_force("scrap")
game.create_force("scrap_defense")
game.forces.player.set_friend('scrap', true)
game.forces.enemy.set_friend('scrap', true)
game.forces.scrap.set_friend('player', true)
game.forces.scrap.set_friend('enemy', true)
game.forces.scrap.share_chart = false
end
@ -392,6 +460,7 @@ Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_left_game, on_player_left_game)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_player_changed_position, on_player_changed_position)

View File

@ -10,7 +10,7 @@ local function shuffle(tbl)
return tbl
end
function Public.secret_shop(pos, surface)
function Public.add(pos, surface)
local secret_market_items = {
{price = {{"coin", math_random(30,60)}}, offer = {type = 'give-item', item = 'construction-robot'}},
{price = {{"coin", math_random(100,200)}}, offer = {type = 'give-item', item = 'loader'}},
@ -42,7 +42,7 @@ function Public.secret_shop(pos, surface)
}
secret_market_items = shuffle(secret_market_items)
local market = surface.create_entity {name = "market", position = pos}
local market = surface.create_entity {name = "market", position = pos, force = "scrap"}
market.destructible = false
for i = 1, math_random(6, 8), 1 do

View File

@ -1,5 +1,6 @@
local Biters = require 'modules.wave_defense.biter_rolls'
local Event = require 'utils.event'
local Market = require 'maps.scrapyard.market'
local Market = require 'functions.basic_markets'
local create_entity_chain = require "functions.create_entity_chain"
local create_tile_chain = require "functions.create_tile_chain"
local simplex_noise = require 'utils.simplex_noise'.d2
@ -11,63 +12,51 @@ local math_random = math.random
local math_floor = math.floor
local math_abs = math.abs
local uncover_radius = 10
local level_depth = 960
local worm_level_modifier = 0.18
local rock_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
local enemies = {"small-biter", "medium-biter", "small-spitter", "small-worm-turret", "medium-spitter", "medium-worm-turret", "big-biter", "big-spitter", "big-worm-turret", "behemoth-biter", "behemoth-spitter"}
local scrap_buildings = {"nuclear-reactor", "centrifuge", "beacon", "chemical-plant", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3", "oil-refinery", "arithmetic-combinator", "constant-combinator", "decider-combinator", "programmable-speaker", "steam-turbine", "steam-engine", "chemical-plant", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3", "oil-refinery", "arithmetic-combinator", "constant-combinator", "decider-combinator", "programmable-speaker", "steam-turbine", "steam-engine"}
local trees = {"dead-grey-trunk", "dead-grey-trunk", "dry-tree"}
local worm_raffle_table = {
[1] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret"},
[2] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret"},
[3] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret"},
[4] = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret"},
[5] = {"small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"},
[6] = {"small-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"},
[7] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret"},
[8] = {"medium-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"},
[9] = {"medium-worm-turret", "medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"},
[10] = {"medium-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret", "big-worm-turret"}
}
local noises = {
["no_rocks"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
["no_rocks_2"] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}},
["large_caves"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
["small_caves"] = {{modifier = 0.008, weight = 1}, {modifier = 0.03, weight = 0.15}, {modifier = 0.25, weight = 0.05}},
["small_caves_2"] = {{modifier = 0.009, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.25, weight = 0.05}},
["cave_ponds"] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}},
["cave_rivers"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.25}, {modifier = 0.05, weight = 0.01}},
["cave_rivers_2"] = {{modifier = 0.003, weight = 1}, {modifier = 0.01, weight = 0.21}, {modifier = 0.05, weight = 0.01}},
["cave_rivers_3"] = {{modifier = 0.002, weight = 1}, {modifier = 0.01, weight = 0.15}, {modifier = 0.05, weight = 0.01}},
["cave_rivers_4"] = {{modifier = 0.001, weight = 1}, {modifier = 0.01, weight = 0.11}, {modifier = 0.05, weight = 0.01}},
["scrapyard"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.35}, {modifier = 0.05, weight = 0.23}, {modifier = 0.1, weight = 0.11}},
}
local Public = {}
local function get_noise(name, pos)
local seed = game.surfaces[global.active_surface_index].map_gen_settings.seed
local noise_seed_add = 25000
seed = seed + noise_seed_add
if name == 1 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
seed = seed + noise_seed_add
noise[4] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local sum = noise[1] + noise[2] * 0.35 + noise[3] * 0.23 + noise[4] * 0.11
return sum
elseif name == 2 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
local sum = noise[1]
return sum
elseif name == 3 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local sum = noise[1]
return sum
elseif name == 4 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.1, pos.y * 0.1, seed)
local sum = noise[1]
return sum
elseif name == 5 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.045, pos.y * 0.045, seed)
local sum = noise[1]
return sum
elseif name == 6 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.02, pos.y * 0.02, seed)
local sum = noise[1]
return sum
elseif name == 7 then
local noise = {}
noise[1] = simplex_noise(pos.x * 0.005, pos.y * 0.005, seed)
seed = seed + noise_seed_add
noise[2] = simplex_noise(pos.x * 0.01, pos.y * 0.01, seed)
seed = seed + noise_seed_add
noise[3] = simplex_noise(pos.x * 0.05, pos.y * 0.05, seed)
local sum = noise[1] + noise[2] + noise[3]
return sum
local function get_noise(name, pos, seed)
local noise = 0
local d = 0
for _, n in pairs(noises[name]) do
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
d = d + n.weight
seed = seed + 10000
end
noise = noise / d
return noise
end
local function place_random_scrap_entity(surface, position)
@ -83,7 +72,7 @@ local function place_random_scrap_entity(surface, position)
e.active = false
return
end
if r < 100 then
if r < 75 then
local e = surface.create_entity({name = "gun-turret", position = position, force = "scrap_defense"})
e.insert({name = "piercing-rounds-magazine", count = math_random(8, 128)})
return
@ -115,8 +104,8 @@ local function create_inner_content(surface, pos, noise)
end
end
local function get_noise_tile(pos)
local noise = get_noise(1, pos)
local function get_noise_tile(pos, seed)
local noise = get_noise("no_rocks", pos, seed)
local tile_name
if noise > 0 then
@ -128,11 +117,11 @@ local function get_noise_tile(pos)
tile_name = "dirt-3"
end
local noise2 = get_noise(2, pos)
local noise2 = get_noise("cave_ponds", pos, seed)
if noise2 > 0.71 then
tile_name = "water"
tile_name = "water-green"
if noise > 0.78 then
tile_name = "deepwater"
tile_name = "deepwater-green"
end
end
@ -143,19 +132,22 @@ local function get_noise_tile(pos)
return tile_name
end
local function get_entity(pos)
local noise = get_noise(5, pos)
local function get_entity(pos, seed)
local noise = get_noise("small_caves", pos, seed)
local entity_name = false
if noise > 0 then
if math_random(1, 50) ~= 1 then
if math_random(1, 1000) ~= 1 then
--entity_name = trees[math_random(1, #trees)]
if math_random(1,128) == 1 then
entity_name = trees[math_random(1, #trees)]
end
if noise > 0.6 then
entity_name = rock_raffle[math_random(1, #rock_raffle)]
if math_random(1, 24) == 1 then
if pos.x > 32 or pos.x < -32 or pos.y > 32 or pos.y < -32 then
local e = math.ceil(game.forces.enemy.evolution_factor*10)
if e < 1 then e = 1 end
entity_name = enemies[e][math_random(1, #enemies[e])]
entity_name = worm_raffle_table[e][math_random(1, #worm_raffle_table[e])]
end
end
end
@ -166,7 +158,7 @@ local function get_entity(pos)
end
if math_random(1, 128) == 1 then
local noise_spawners = get_noise(6, pos)
local noise_spawners = get_noise("small_caves_2", pos, seed)
if noise_spawners > 0.25 and pos.x^2 + pos.y^2 > 3000 then
entity_name = "biter-spawner"
if math_random(1,5) == 1 then
@ -178,61 +170,39 @@ local function get_entity(pos)
return entity_name
end
function Public.reveal(player)
local position = player.position
local surface = player.surface
local function get_oil_amount(p)
return (math_abs(p.y) * 200 + 10000) * math_random(75, 125) * 0.01
end
local function uncover_map(surface, position, radius_min, radius_max, seed, markets)
local circles = shapes.circles
local reveal_area = {}
local tiles = {}
local fishes = {}
local entities = {}
for r = uncover_radius -1, uncover_radius, 1 do
for _, v in pairs(circles[r]) do
local pos = {x = position.x + v.x, y = position.y + v.y}
for r = radius_min, radius_max, 1 do
for _, position_modifier in pairs(circles[r]) do
local pos = {x = position.x + position_modifier.x, y = position.y + position_modifier.y}
if surface.get_tile(pos).name == "out-of-map" then
local rivers = get_noise(7, pos)
local noise = get_noise(1, pos)
local noise2 = get_noise(2, pos)
local distance_to_center = math.sqrt(pos.x^2 + pos.y^2)
insert(tiles, {name = "dirt-" .. math_random(1, 7), position = pos})
if distance_to_center < 40 then
insert(tiles, {name = "dirt-" .. math_random(1, 7), position = pos})
local tile_name = get_noise_tile(pos, seed)
insert(tiles, {name = tile_name, position = pos})
if tile_name == "water" or tile_name == "deepwater" or tile_name == "water-green" then
if math_random(1, 24) == 1 then insert(fishes, pos) end
else
if noise > 0.43 or noise < -0.43 then
if math_random(1,4) ~= 1 then
insert(entities, {name = "mineable-wreckage", position = pos})
else
if math_random(1,256) == 1 then
Loot.create_loot(surface, pos, "wooden-chest")
else
if math_random(1,512) == 1 then
place_random_scrap_entity(surface, pos)
end
local entity = get_entity(pos, seed)
if entity then
if entity == "market" then
local area = {{pos.x - 64, pos.y - 64}, {pos.x + 64, pos.y + 64}}
if surface.count_entities_filtered({name = "market", area = area}) == 0 then
if math_random(1,32) == 1 then markets[#markets + 1] = pos end
end
end
elseif noise2 > 0.25 or noise2 < -0.25 then
create_inner_content(surface, pos, noise)
local tile_name = get_noise_tile(pos)
insert(tiles, {name = tile_name, position = pos})
if rivers < -0.3 then insert(tiles, {name = "water-shallow", position = pos}) end
if tile_name == "water" or tile_name == "deepwater" or tile_name == "water-green" then
if math_random(1, 24) == 1 then insert(fishes, pos) end
else
local entity = get_entity(pos)
if entity then
if entity == "market" then
local area = {{pos.x - 64, pos.y - 64}, {pos.x + 64, pos.y + 64}}
if surface.count_entities_filtered({name = "market", area = area}) == 0 then
Market.secret_shop(pos, surface)
end
elseif math_floor(distance_to_center) > tonumber(128) then
if entity == "biter-spawner" or entity == "spitter-spawner" then
local area = {{pos.x - 16, pos.y - 16}, {pos.x + 16, pos.y + 16}}
if surface.count_entities_filtered({name = "biter-spawner", area = area}) == 0 then
insert(entities, {name = entity, position = pos})
end
end
if entity == "biter-spawner" or entity == "spitter-spawner" then
local area = {{pos.x - 4, pos.y - 4}, {pos.x + 4, pos.y + 4}}
if surface.count_entities_filtered({name = "biter-spawner", area = area}) == 0 then
insert(entities, {name = entity, position = pos})
end
else
insert(entities, {name = entity, position = pos})
end
end
end
@ -240,15 +210,412 @@ function Public.reveal(player)
end
end
end
if #tiles > 0 then
surface.set_tiles(tiles, true)
end
for _, fish in pairs(fishes) do
surface.create_entity({name = "fish", position = fish})
end
for _, entity in pairs(entities) do
if surface.can_place_entity(entity) and entity == "biter-spawner" or entity == "spitter-spawner" then
surface.create_entity(entity)
else
surface.create_entity(entity)
end
end
end
local function wall(surface, left_top, seed)
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
local small_caves = get_noise("small_caves", p, seed)
local cave_ponds = get_noise("cave_rivers", p, seed + 100000)
if y > 9 + cave_ponds * 6 and y < 23 + small_caves * 6 then
if small_caves > 0.05 or cave_ponds > 0.05 then
surface.set_tiles({{name = "deepwater", position = p}})
if math_random(1,48) == 1 then surface.create_entity({name = "fish", position = p}) end
else
surface.set_tiles({{name = "dirt-7", position = p}})
if math_random(1, 5) ~= 1 then
surface.create_entity({name = "mineable-wreckage", position = p})
end
end
else
surface.set_tiles({{name = "dirt-7", position = p}})
if surface.can_place_entity({name = "stone-wall", position = p, force = "enemy"}) then
if math_random(1,512) == 1 and y > 3 and y < 28 then
if math_random(1, 2) == 1 then
Loot.add(surface, p, "wooden-chest")
else
Loot.add(surface, p, "iron-chest")
end
else
if y < 5 or y > 26 then
if y <= 15 then
if math_random(1, y + 1) == 1 then
local e = surface.create_entity({name = "stone-wall", position = p, force = "player"})
e.minable = false
end
else
if math_random(1, 32 - y) == 1 then
local e = surface.create_entity({name = "stone-wall", position = p, force = "player"})
e.minable = false
end
end
end
end
end
if math_random(1,512) == 1 then
place_random_scrap_entity(surface, p)
end
if math_random(1, 16) == 1 then
if surface.can_place_entity({name = "small-worm-turret", position = p, force = "enemy"}) then
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
surface.create_entity({name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"})
end
end
if math_random(1, 32) == 1 then
if surface.can_place_entity({name = "gun-turret", position = p, force = "enemy"}) then
local e = surface.create_entity({name = "gun-turret", position = p, force = "enemy"})
if math_abs(p.y) < level_depth * 2.5 then
e.insert({name = "piercing-rounds-magazine", count = math_random(64, 128)})
else
e.insert({name = "uranium-rounds-magazine", count = math_random(64, 128)})
end
end
end
end
end
end
end
local function process_level_3_position(surface, p, seed, tiles, entities, fishes, reveal_area, markets, treasure)
local small_caves = get_noise("small_caves", p, seed + 50000)
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)
--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, #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 markets[#markets + 1] = p end
if math_random(1,16) == 1 then entities[#entities + 1] = {name = trees[math_random(1, #trees)], position=p} end
end
return
end
if noise_large_caves > -0.2 and noise_large_caves < 0.2 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 entities[#entities + 1] = {name="fish", position=p} end
return
end
--Chasms
if noise_cave_ponds < 0.12 and noise_cave_ponds > -0.12 then
if small_caves > 0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
end
--Rivers
local cave_rivers = get_noise("cave_rivers", p, seed + 100000)
if cave_rivers < 0.014 and cave_rivers > -0.014 then
if noise_cave_ponds > 0.2 then
tiles[#tiles + 1] = {name = "water-shallow", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
end
local cave_rivers_2 = get_noise("cave_rivers_2", p, seed)
if cave_rivers_2 < 0.024 and cave_rivers_2 > -0.024 then
if noise_cave_ponds < 0.5 then
tiles[#tiles + 1] = {name = "water", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
end
if noise_cave_ponds > 0.775 then
tiles[#tiles + 1] = {name = "dirt-" .. math_random(4, 6), position = p}
return
end
local no_rocks = get_noise("no_rocks", p, seed + 25000)
--Worm oil Zones
if no_rocks < 0.15 and no_rocks > -0.15 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 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)
create_inner_content(surface, p, noise_cave_ponds)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
if math_random(1,64) == 1 then entities[#entities + 1] = {name = trees[math_random(1, #trees)], position=p} end
return
end
end
--Main 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 treasure[#treasure + 1] = p end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,2048) == 1 then place_random_scrap_entity(surface, p) end
if math_random(1,100) > 30 then entities[#entities + 1] = {name = "mineable-wreckage", position = p} end
return
end
tiles[#tiles + 1] = {name = "out-of-map", position = p}
end
local function process_level_2_position(surface, pos, seed, tiles, entities, fishes, reveal_area, markets, treasure)
local small_caves = get_noise("small_caves", pos, seed)
local noise_large_caves = get_noise("large_caves", pos, seed)
if noise_large_caves > -0.75 and noise_large_caves < 0.75 then
local noise_cave_ponds = get_noise("cave_ponds", pos, seed)
--Chasms
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.32 then
tiles[#tiles + 1] = {name = "out-of-map", position = pos}
return
end
if small_caves < -0.32 then
tiles[#tiles + 1] = {name = "out-of-map", position = pos}
return
end
end
--Green Water Ponds
if noise_cave_ponds > 0.80 then
tiles[#tiles + 1] = {name = "deepwater-green", position = pos}
if math_random(1,16) == 1 then entities[#entities + 1] = {name="fish", position=pos} end
return
end
--Rivers
local cave_rivers = get_noise("cave_rivers", pos, seed + 100000)
if cave_rivers < 0.027 and cave_rivers > -0.027 then
if noise_cave_ponds < 0.1 then
tiles[#tiles + 1] = {name = "water-shallow", position = pos}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=pos} end
return
end
end
if noise_cave_ponds > 0.76 then
tiles[#tiles + 1] = {name = "dirt-" .. math_random(4, 6), position = pos}
return
end
--Market Spots
if noise_cave_ponds < -0.80 then
create_inner_content(surface, pos, noise_cave_ponds)
tiles[#tiles + 1] = {name = "grass-" .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = pos}
if math_random(1,32) == 1 then markets[#markets + 1] = pos end
if math_random(1,16) == 1 then entities[#entities + 1] = {name = trees[math_random(1, #trees)], position=pos} end
return
end
local no_rocks = get_noise("no_rocks", pos, seed + 25000)
--Worm oil Zones
if no_rocks < 0.15 and no_rocks > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = "dirt-" .. math_floor(noise_cave_ponds * 32) % 7 + 1, position = pos}
if math_random(1,450) == 1 then entities[#entities + 1] = {name = "crude-oil", position = pos, amount = get_oil_amount(pos)} end
if math_random(1,64) == 1 then
Biters.wave_defense_set_worm_raffle(math_abs(pos.y) * worm_level_modifier)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = pos, force = "enemy"}
end
if math_random(1,64) == 1 then entities[#entities + 1] = {name = trees[math_random(1, #trees)], position=pos} end
return
end
end
--Main Terrain
local no_rocks_2 = get_noise("no_rocks_2", pos, 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 = pos}
if math_random(1,512) == 1 then treasure[#treasure + 1] = pos end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = pos end
tiles[#tiles + 1] = {name = "dirt-7", position = pos}
if math_random(1,2048) == 1 then place_random_scrap_entity(surface, pos) end
if math_random(1,100) > 30 then entities[#entities + 1] = {name = "mineable-wreckage", position = pos} end
return
end
tiles[#tiles + 1] = {name = "out-of-map", position = pos}
end
local function process_level_1_position(surface, p, seed, tiles, entities, fishes, reveal_area, markets, treasure)
local small_caves = get_noise("small_caves", p, seed)
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
if noise_cave_ponds < 0.12 and noise_cave_ponds > -0.12 then
if small_caves > 0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.55 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
end
--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 entities[#entities + 1] = {name="fish", position=p} end
return
end
--Rivers
local cave_rivers = get_noise("cave_rivers", p, seed + 100000)
if cave_rivers < 0.024 and cave_rivers > -0.024 then
if noise_cave_ponds > 0 then
tiles[#tiles + 1] = {name = "water-shallow", position = p}
if math_random(1,64) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
end
if noise_cave_ponds > 0.76 then
tiles[#tiles + 1] = {name = "dirt-" .. math_random(4, 6), position = p}
return
end
--Market Spots
if noise_cave_ponds < -0.75 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 = trees[math_random(1, #trees)], position=p} end
create_inner_content(surface, p, noise_cave_ponds)
return
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.08 and no_rocks > -0.08 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,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)
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = "enemy"}
end
if math_random(1,1024) == 1 then treasure[#treasure + 1] = p end
if math_random(1,64) == 1 then entities[#entities + 1] = {name = "dead-tree-desert", position=p} end
return
end
end
end
--Main Terrain
local no_rocks_2 = get_noise("no_rocks_2", p, seed + 75000)
if no_rocks_2 > 0.70 or no_rocks_2 < -0.70 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 = "dead-tree-desert", position=p} end
if math_random(1,512) == 1 then treasure[#treasure + 1] = p end
return
end
if math_random(1,2048) == 1 then treasure[#treasure + 1] = p end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,2048) == 1 then place_random_scrap_entity(surface, p) end
if math_random(1,100) > 30 then entities[#entities + 1] = {name = "mineable-wreckage", position = p} end
end
local levels = {
process_level_1_position,
process_level_2_position,
process_level_3_position,
--process_level_4_position,
--process_level_5_position,
--process_level_6_position,
--process_level_7_position,
--process_level_8_position,
--process_level_9_position,
--process_level_10_position,
}
function Public.reveal(player)
local seed = game.surfaces[global.active_surface_index].map_gen_settings.seed
local position = player.position
local surface = player.surface
local circles = shapes.circles
local reveal_area = {}
local tiles = {}
local fishes = {}
local entities = {}
local markets = {}
local treasure = {}
local process_level = levels[math_floor(math_abs(position.y) / level_depth) + 1]
if not process_level then process_level = levels[#levels] end
for r = uncover_radius -1, uncover_radius, 1 do
for _, v in pairs(circles[r]) do
local pos = {x = position.x + v.x, y = position.y + v.y}
if surface.get_tile(pos).name == "out-of-map" then
insert(tiles, {name = "dirt-" .. math_random(1, 7), position = pos})
process_level(surface, pos, seed, tiles, entities, fishes, reveal_area, markets, treasure)
end
end
end
if #tiles > 0 then
surface.set_tiles(tiles, true)
end
for _, entity in pairs(entities) do
surface.create_entity(entity)
if surface.can_place_entity(entity) and entity == "biter-spawner" or entity == "spitter-spawner" then
surface.create_entity(entity)
else
surface.create_entity(entity)
end
end
if #markets > 0 then
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}}, name = "market", limit = 1} == 0 then
local market = Market.mountain_market(surface, pos, math_abs(pos.y) * 0.004)
market.destructible = false
end
end
for _, p in pairs(treasure) do
local name = "wooden-chest"
if math_random(1, 6) == 1 then name = "iron-chest" end
Loot.add(surface, p, name)
end
for _, pos in pairs(reveal_area) do
Public.reveal(surface, pos, 1, 16)
uncover_map(surface, pos, 1, 18, seed)
end
for _, fish in pairs(fishes) do
surface.create_entity({name = "fish", position = fish})
@ -292,6 +659,15 @@ local function is_out_of_map(p)
end
local function border_chunk(surface, left_top)
for x = 0, 31, 1 do
for y = 5, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
if math_random(1, math.ceil(pos.y + pos.y) + 64) == 1 then
surface.create_entity({name = trees[math_random(1, #trees)], position = pos})
end
end
end
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
@ -322,6 +698,9 @@ local function border_chunk(surface, left_top)
name = "wall-remnants", position = pos, amount = math_random(1, 1 + math.ceil(20 - y / 2))
}
end
if math_random(1, math.ceil(pos.y + pos.y) + 32) == 1 then
surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = pos})
end
end
end
end
@ -340,7 +719,7 @@ local function replace_water(surface, left_top)
end
end
local function process(surface, left_top)
local function process(surface, left_top, seed)
local position_left_top = left_top
local tiles = {}
for x = 0, 31, 1 do
@ -377,7 +756,7 @@ local function process(surface, left_top)
if math_random(1, 16) ~= 1 then return end
local pos = {x = position_left_top.x * 32 + math_random(1,32), y = position_left_top.y * 32 + math_random(1,32)}
local noise = get_noise(1, pos)
local noise = get_noise("no_rocks", pos, seed)
if noise > 0.4 or noise < -0.4 then return end
local distance_to_center = math.sqrt(pos.x^2 + pos.y^2)
local size = 7 + math.floor(distance_to_center * 0.0075)
@ -434,6 +813,13 @@ local function on_chunk_generated(event)
local position_left_top = event.area.left_top
generate_spawn_area(surface, position_left_top)
if left_top.y % level_depth == 0 and left_top.y < 0 and left_top.y > level_depth * -10 then wall(surface, left_top, surface.map_gen_settings.seed) return end
if left_top.y > 32 then game.forces.player.chart(surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}}) end
if left_top.y == -128 and left_top.x == -128 then
local p = global.locomotive.position
for _, entity in pairs(surface.find_entities_filtered({area = {{p.x - 3, p.y - 4},{p.x + 3, p.y + 10}}, type = "simple-entity"})) do entity.destroy() end
end
if left_top.y >= 0 then replace_water(surface, left_top) end
if left_top.y > 210 then biter_chunk(surface, left_top) end
if left_top.y >= 0 then border_chunk(surface, left_top) end