1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00
ComfyFactorio/maps/choppy.lua

425 lines
14 KiB
Lua
Raw Normal View History

2021-03-24 21:14:55 +02:00
--luacheck: ignore
2019-03-10 22:34:02 +02:00
--choppy-- mewmew made this --
2021-03-24 17:46:00 +02:00
require 'modules.dynamic_landfill'
require 'modules.satellite_score'
require 'modules.spawners_contain_biters'
local Map = require 'modules.map_info'
2024-01-28 21:42:28 +02:00
local unearthing_worm = require 'utils.functions.unearthing_worm'
local unearthing_biters = require 'utils.functions.unearthing_biters'
local tick_tack_trap = require 'utils.functions.tick_tack_trap'
local create_entity_chain = require 'utils.functions.create_entity_chain'
local create_tile_chain = require 'utils.functions.create_tile_chain'
2019-03-10 22:34:02 +02:00
2019-06-11 14:31:00 +02:00
local simplex_noise = require 'utils.simplex_noise'.d2
local event = require 'utils.event'
2019-03-10 22:34:02 +02:00
local table_insert = table.insert
local math_random = math.random
2024-01-28 21:42:28 +02:00
local map_functions = require 'utils.tools.map_functions'
2019-03-10 22:34:02 +02:00
local disabled_for_deconstruction = {
2021-03-24 17:46:00 +02:00
['fish'] = true,
2024-09-25 23:25:57 +02:00
['huge-rock'] = true,
['big-rock'] = true,
['big-sand-rock'] = true,
2021-03-24 17:46:00 +02:00
['mineable-wreckage'] = true
}
2019-03-10 22:34:02 +02:00
local tile_replacements = {
2021-03-24 17:46:00 +02:00
['dirt-1'] = 'grass-1',
['dirt-2'] = 'grass-2',
['dirt-3'] = 'grass-3',
['dirt-4'] = 'grass-4',
['dirt-5'] = 'grass-1',
['sand-1'] = 'grass-1',
['sand-2'] = 'grass-2',
['sand-3'] = 'grass-3',
['dry-dirt'] = 'grass-2',
['red-desert-0'] = 'grass-1',
['red-desert-1'] = 'grass-2',
['red-desert-2'] = 'grass-3',
['red-desert-3'] = 'grass-4'
2019-03-10 22:34:02 +02:00
}
2019-06-11 14:31:00 +02:00
2024-09-25 23:25:57 +02:00
local rocks = { 'big-rock', 'big-rock', 'huge-rock' }
2021-03-24 17:46:00 +02:00
local decos = {
'green-hairy-grass',
'green-hairy-grass',
'green-hairy-grass',
'green-hairy-grass',
'green-hairy-grass',
'green-hairy-grass',
'green-carpet-grass',
'green-carpet-grass',
'green-pita'
}
local decos_inside_forest = { 'brown-asterisk', 'brown-asterisk', 'brown-carpet-grass', 'brown-hairy-grass' }
2019-06-11 14:31:00 +02:00
local noises = {
['forest_location'] = { { modifier = 0.006, weight = 1 }, { modifier = 0.01, weight = 0.25 }, { modifier = 0.05, weight = 0.15 }, { modifier = 0.1, weight = 0.05 } },
['forest_density'] = { { modifier = 0.01, weight = 1 }, { modifier = 0.05, weight = 0.5 }, { modifier = 0.1, weight = 0.025 } }
2019-06-11 14:31:00 +02:00
}
local function get_noise(name, pos, seed)
2021-03-24 17:46:00 +02:00
local noise = 0
for _, n in pairs(noises[name]) do
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
seed = seed + 10000
end
return noise
2019-06-11 14:31:00 +02:00
end
2019-03-10 22:34:02 +02:00
local function shuffle(tbl)
2021-03-24 17:46:00 +02:00
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
2019-03-10 22:34:02 +02:00
end
2019-06-16 15:27:08 +02:00
local entities_to_convert = {
2021-03-24 17:46:00 +02:00
['coal'] = true,
['copper-ore'] = true,
['iron-ore'] = true,
['uranium-ore'] = true,
['stone'] = true,
['angels-ore1'] = true,
['angels-ore2'] = true,
['angels-ore3'] = true,
['angels-ore4'] = true,
['angels-ore5'] = true,
['angels-ore6'] = true,
['thorium-ore'] = true
2019-06-16 15:27:08 +02:00
}
local trees_to_remove = {
2021-03-24 17:46:00 +02:00
['dead-dry-hairy-tree'] = true,
['dead-grey-trunk'] = true,
['dead-tree-desert'] = true,
['dry-hairy-tree'] = true,
['dry-tree'] = true,
['tree-01'] = true,
['tree-02'] = true,
['tree-02-red'] = true,
['tree-03'] = true,
['tree-04'] = true,
['tree-05'] = true,
['tree-06'] = true,
['tree-06-brown'] = true,
['tree-07'] = true,
['tree-08'] = true,
['tree-08-brown'] = true,
['tree-08-red'] = true,
['tree-09'] = true,
['tree-09-brown'] = true,
['tree-09-red'] = true
2019-06-16 15:27:08 +02:00
}
2019-03-10 22:34:02 +02:00
local function process_entity(e)
2021-03-24 17:46:00 +02:00
if not e.valid then
return
end
if trees_to_remove[e.name] then
e.destroy()
return
end
if entities_to_convert[e.name] then
if math_random(1, 100) > 33 then
e.surface.create_entity({ name = rocks[math_random(1, #rocks)], position = e.position })
2021-03-24 17:46:00 +02:00
end
e.destroy()
return
end
2019-03-10 22:34:02 +02:00
end
2019-06-11 14:31:00 +02:00
local function process_tile(surface, pos, tile, seed)
2024-09-25 18:00:40 +02:00
if tile.collides_with('player') then
2021-03-24 17:46:00 +02:00
return
end
if not surface.can_place_entity({ name = 'tree-01', position = pos }) then
2021-03-24 17:46:00 +02:00
return
end
if math_random(1, 100000) == 1 then
local wrecks = { 'big-ship-wreck-1', 'big-ship-wreck-2', 'big-ship-wreck-3' }
local e = surface.create_entity { name = wrecks[math_random(1, #wrecks)], position = pos, force = 'neutral' }
e.insert({ name = 'raw-fish', count = math_random(3, 25) })
2021-03-24 17:46:00 +02:00
if math_random(1, 3) == 1 then
e.insert({ name = 'wood', count = math_random(11, 44) })
2021-03-24 17:46:00 +02:00
end
end
local noise_forest_location = get_noise('forest_location', pos, seed)
--local r = math.ceil(math.abs(get_noise("forest_density", pos, seed + 4096)) * 10)
--local r = 5 - math.ceil(math.abs(noise_forest_location) * 3)
--r = 2
if noise_forest_location > 0.095 then
if noise_forest_location > 0.6 then
if math_random(1, 100) > 42 then
surface.create_entity({ name = 'tree-08-brown', position = pos })
2021-03-24 17:46:00 +02:00
end
else
if math_random(1, 100) > 42 then
surface.create_entity({ name = 'tree-01', position = pos })
2021-03-24 17:46:00 +02:00
end
end
surface.create_decoratives({ check_collision = false, decoratives = { { name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2) } } })
2021-03-24 17:46:00 +02:00
return
end
if noise_forest_location < -0.095 then
if noise_forest_location < -0.6 then
if math_random(1, 100) > 42 then
surface.create_entity({ name = 'tree-04', position = pos })
2021-03-24 17:46:00 +02:00
end
else
if math_random(1, 100) > 42 then
surface.create_entity({ name = 'tree-02-red', position = pos })
2021-03-24 17:46:00 +02:00
end
end
surface.create_decoratives({ check_collision = false, decoratives = { { name = decos_inside_forest[math_random(1, #decos_inside_forest)], position = pos, amount = math_random(1, 2) } } })
2021-03-24 17:46:00 +02:00
return
end
surface.create_decoratives({ check_collision = false, decoratives = { { name = decos[math_random(1, #decos)], position = pos, amount = math_random(1, 2) } } })
2019-06-11 14:31:00 +02:00
end
2019-03-10 22:34:02 +02:00
local function on_chunk_generated(event)
2021-03-24 17:46:00 +02:00
local surface = event.surface
local left_top = event.area.left_top
local tiles = {}
local entities = {}
local seed = game.surfaces[1].map_gen_settings.seed
--surface.destroy_decoratives({area = event.area})
for _, e in pairs(surface.find_entities_filtered({ area = event.area })) do
2021-03-24 17:46:00 +02:00
process_entity(e)
end
for x = 0.5, 31.5, 1 do
for y = 0.5, 31.5, 1 do
local tile_to_insert = false
local pos = { x = left_top.x + x, y = left_top.y + y }
2021-03-24 17:46:00 +02:00
local tile = surface.get_tile(pos)
if tile_replacements[tile.name] then
table_insert(tiles, { name = tile_replacements[tile.name], position = pos })
2021-03-24 17:46:00 +02:00
end
process_tile(surface, pos, tile, seed)
end
end
surface.set_tiles(tiles, true)
for _, e in pairs(surface.find_entities_filtered({ area = event.area, type = 'unit-spawner' })) do
for _, entity in pairs(e.surface.find_entities_filtered({ area = { { e.position.x - 7, e.position.y - 7 }, { e.position.x + 7, e.position.y + 7 } }, force = 'neutral' })) do
2021-03-24 17:46:00 +02:00
if entity.valid then
entity.destroy()
end
end
end
if storage.spawn_generated then
2021-03-24 17:46:00 +02:00
return
end
if left_top.x < 96 then
return
end
for _, e in pairs(surface.find_entities_filtered({ area = { { -50, -50 }, { 50, 50 } } })) do
2021-03-24 17:46:00 +02:00
local distance_to_center = math.sqrt(e.position.x ^ 2 + e.position.y ^ 2)
if e.valid then
if distance_to_center < 8 and e.type == 'tree' and math_random(1, 5) ~= 1 then
e.destroy()
end
end
end
storage.spawn_generated = true
2019-03-10 22:34:02 +02:00
end
local function on_marked_for_deconstruction(event)
2021-03-24 17:46:00 +02:00
if disabled_for_deconstruction[event.entity.name] then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
if event.entity.type == 'tree' then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
2019-03-10 22:34:02 +02:00
end
local function on_player_joined_game(event)
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
if player.online_time == 0 then
player.insert({ name = 'pistol', count = 1 })
player.insert({ name = 'firearm-magazine', count = 8 })
2021-03-24 17:46:00 +02:00
end
if storage.map_init_done then
2021-03-24 17:46:00 +02:00
return
end
--game.map_settings.pollution.min_pollution_to_damage_trees = 1000000
--game.map_settings.pollution.pollution_per_tree_damage = 0
--game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.surfaces['nauvis'].ticks_per_day = game.surfaces['nauvis'].ticks_per_day * 2
storage.entity_yield = {
['tree-01'] = { 'iron-ore' },
['tree-02-red'] = { 'copper-ore' },
['tree-04'] = { 'coal' },
['tree-08-brown'] = { 'stone' },
2024-09-25 23:25:57 +02:00
['big-rock'] = { 'uranium-ore' },
['huge-rock'] = { 'uranium-ore' }
2021-03-24 17:46:00 +02:00
}
2024-09-25 16:38:14 +02:00
if prototypes.item['angels-ore1'] then
storage.entity_yield['tree-01'] = { 'angels-ore1', 'angels-ore2' }
storage.entity_yield['tree-02-red'] = { 'angels-ore5', 'angels-ore6' }
storage.entity_yield['tree-04'] = { 'coal' }
storage.entity_yield['tree-08-brown'] = { 'angels-ore3', 'angels-ore4' }
2021-03-24 17:46:00 +02:00
else
game.map_settings.pollution.ageing = 0
end
2024-09-25 16:38:14 +02:00
if prototypes.item['thorium-ore'] then
2024-09-25 23:25:57 +02:00
storage.entity_yield['big-rock'] = { 'uranium-ore', 'thorium-ore' }
storage.entity_yield['huge-rock'] = { 'uranium-ore', 'thorium-ore' }
2021-03-24 17:46:00 +02:00
end
storage.map_init_done = true
end
2019-03-10 22:34:02 +02:00
local function get_amount(entity)
2021-03-24 17:46:00 +02:00
local distance_to_center = math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2)
local amount = 25 + (distance_to_center * 0.1)
if amount > 1000 then
amount = 1000
end
amount = math.random(math.ceil(amount * 0.5), math.ceil(amount * 1.5))
return amount
2019-03-10 22:34:02 +02:00
end
2019-05-24 21:01:44 +02:00
local function trap(entity)
2021-03-24 17:46:00 +02:00
if math_random(1, 1024) == 1 then
tick_tack_trap(entity.surface, entity.position)
return
end
if math_random(1, 256) == 1 then
unearthing_worm(entity.surface, entity.position)
end
if math_random(1, 128) == 1 then
unearthing_biters(entity.surface, entity.position, math_random(4, 8))
end
2019-03-10 22:34:02 +02:00
end
local function on_player_mined_entity(event)
2021-03-24 17:46:00 +02:00
local entity = event.entity
if not entity.valid then
return
end
if entity.type == 'tree' then
trap(entity)
end
if storage.entity_yield[entity.name] then
2021-03-24 17:46:00 +02:00
if event.buffer then
event.buffer.clear()
end
if not event.player_index then
return
end
local amount = get_amount(entity)
local second_item_amount = math_random(2, 5)
local second_item = 'wood'
if entity.type == 'simple-entity' then
amount = amount * 2
second_item_amount = math_random(8, 16)
second_item = 'stone'
end
local main_item = storage.entity_yield[entity.name][math_random(1, #storage.entity_yield[entity.name])]
2021-03-24 17:46:00 +02:00
entity.surface.create_entity(
{
name = 'flying-text',
position = entity.position,
text = '+' .. amount .. ' [item=' .. main_item .. '] +' .. second_item_amount .. ' [item=' .. second_item .. ']',
color = { r = 0.8, g = 0.8, b = 0.8 }
2021-03-24 17:46:00 +02:00
}
)
local player = game.players[event.player_index]
local inserted_count = player.insert({ name = main_item, count = amount })
2021-03-24 17:46:00 +02:00
amount = amount - inserted_count
if amount > 0 then
entity.surface.spill_item_stack(entity.position, { name = main_item, count = amount }, true)
2021-03-24 17:46:00 +02:00
end
local inserted_count = player.insert({ name = second_item, count = second_item_amount })
2021-03-24 17:46:00 +02:00
second_item_amount = second_item_amount - inserted_count
if second_item_amount > 0 then
entity.surface.spill_item_stack(entity.position, { name = second_item, count = second_item_amount }, true)
2021-03-24 17:46:00 +02:00
end
end
2019-03-10 22:34:02 +02:00
end
local function on_research_finished(event)
2021-03-24 17:46:00 +02:00
event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 500
if not event.research.force.technologies['steel-axe'].researched then
return
end
event.research.force.manual_mining_speed_modifier = 1 + game.forces.player.mining_drill_productivity_bonus * 2
2019-03-10 22:34:02 +02:00
end
local function on_entity_died(event)
2021-03-24 17:46:00 +02:00
on_player_mined_entity(event)
if not event.entity.valid then
return
end
if event.entity.type == 'tree' then
for _, entity in pairs(event.entity.surface.find_entities_filtered({ area = { { event.entity.position.x - 4, event.entity.position.y - 4 }, { event.entity.position.x + 4, event.entity.position.y + 4 } }, name = 'fire-flame-on-tree' })) do
2021-03-24 17:46:00 +02:00
if entity.valid then
entity.destroy()
end
end
end
2019-03-10 22:34:02 +02:00
end
2019-10-28 18:38:36 +02:00
local on_init = function ()
2021-03-24 17:46:00 +02:00
local T = Map.Pop_info()
T.main_caption = 'Choppy'
T.sub_caption = ''
T.text =
[[
You are a lumberjack with a passion to chop.
Different kinds of trees, yield different kinds of ore and wood.
2019-10-28 18:38:36 +02:00
Yes, they seem to draw minerals out of the ground and manifesting it as "fruit".
Their yield increases with distance. Mining Productivity Research will increase chopping speed and backpack size.
2019-10-28 18:38:36 +02:00
Beware, sometimes there are some bugs hiding underneath the trees.
Even dangerous traps have been encountered before.
2019-10-28 18:38:36 +02:00
Also, these mysterious ore trees don't burn very well, so do not worry if some of them catch on fire.
2019-10-28 18:38:36 +02:00
Choppy Choppy Wood
]]
T.main_caption_color = { r = 0, g = 120, b = 0 }
T.sub_caption_color = { r = 255, g = 0, b = 255 }
2019-10-28 18:38:36 +02:00
end
event.on_init(on_init)
2019-03-10 22:34:02 +02:00
event.add(defines.events.on_research_finished, on_research_finished)
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_mined_entity, on_player_mined_entity)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_chunk_generated, on_chunk_generated)