1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-04-11 11:21:54 +02:00

map_functions > draw random rainbow ore patch

This commit is contained in:
MewMew 2019-02-04 23:09:58 +01:00
parent 052ccaa37d
commit 6b81ee2be7
5 changed files with 119 additions and 88 deletions

View File

@ -36,14 +36,14 @@ require "score"
--require "maps.atoll"
--require "maps.tank_battles"
--require "maps.spiral_troopers"
require "maps.fish_defender"
--require "maps.fish_defender"
--require "maps.crossing"
--require "maps.anarchy"
--require "maps.railworld"
--require "maps.spaghettorio"
--require "maps.deep_jungle"
--require "maps.lost_desert"
--require "maps.empty_map"
require "maps.empty_map"
--require "maps.custom_start"
-----------------------------

View File

@ -1,9 +1,9 @@
--deep jungle-- mewmew made this --
local chunk_loader = require "maps.tools.lazy_chunk_loader"
local map_functions = require "maps.tools.map_functions"
local simplex_noise = require 'utils.simplex_noise'
simplex_noise = simplex_noise.d2
local event = require 'utils.event'
local math_random = math.random
local function treasure_chest(position)
local p = game.surfaces["deep_jungle"].find_non_colliding_position("wooden-chest",position, 2,0.5)
@ -11,43 +11,43 @@ local function treasure_chest(position)
treasure_chest_raffle_table = {}
treasure_chest_loot_weights = {}
table.insert(treasure_chest_loot_weights, {{name = 'iron-gear-wheel', count = math.random(16,48)},10})
table.insert(treasure_chest_loot_weights, {{name = 'coal', count = math.random(16,48)},2})
table.insert(treasure_chest_loot_weights, {{name = 'copper-cable', count = math.random(64,128)},10})
table.insert(treasure_chest_loot_weights, {{name = 'inserter', count = math.random(8,16)},4})
table.insert(treasure_chest_loot_weights, {{name = 'fast-inserter', count = math.random(4,8)},3})
table.insert(treasure_chest_loot_weights, {{name = 'stack-filter-inserter', count = math.random(2,4)},1})
table.insert(treasure_chest_loot_weights, {{name = 'stack-inserter', count = math.random(2,4)},1})
table.insert(treasure_chest_loot_weights, {{name = 'burner-inserter', count = math.random(16,32)},6})
table.insert(treasure_chest_loot_weights, {{name = 'electric-engine-unit', count = math.random(1,16)},3})
table.insert(treasure_chest_loot_weights, {{name = 'engine-unit', count = math.random(1,16)},3})
table.insert(treasure_chest_loot_weights, {{name = 'rocket-fuel', count = math.random(1,5)},3})
table.insert(treasure_chest_loot_weights, {{name = 'empty-barrel', count = math.random(1,10)},7})
table.insert(treasure_chest_loot_weights, {{name = 'lubricant-barrel', count = math.random(1,10)},3})
table.insert(treasure_chest_loot_weights, {{name = 'crude-oil-barrel', count = math.random(1,10)},3})
table.insert(treasure_chest_loot_weights, {{name = 'iron-stick', count = math.random(1,100)},8})
table.insert(treasure_chest_loot_weights, {{name = "small-electric-pole", count = math.random(8,32)},9})
table.insert(treasure_chest_loot_weights, {{name = "firearm-magazine", count = math.random(16,48)},8})
table.insert(treasure_chest_loot_weights, {{name = 'grenade', count = math.random(16,32)},5})
table.insert(treasure_chest_loot_weights, {{name = 'land-mine', count = math.random(24,48)},5})
table.insert(treasure_chest_loot_weights, {{name = 'iron-gear-wheel', count = math_random(16,48)},10})
table.insert(treasure_chest_loot_weights, {{name = 'coal', count = math_random(16,48)},2})
table.insert(treasure_chest_loot_weights, {{name = 'copper-cable', count = math_random(64,128)},10})
table.insert(treasure_chest_loot_weights, {{name = 'inserter', count = math_random(8,16)},4})
table.insert(treasure_chest_loot_weights, {{name = 'fast-inserter', count = math_random(4,8)},3})
table.insert(treasure_chest_loot_weights, {{name = 'stack-filter-inserter', count = math_random(2,4)},1})
table.insert(treasure_chest_loot_weights, {{name = 'stack-inserter', count = math_random(2,4)},1})
table.insert(treasure_chest_loot_weights, {{name = 'burner-inserter', count = math_random(16,32)},6})
table.insert(treasure_chest_loot_weights, {{name = 'electric-engine-unit', count = math_random(1,16)},3})
table.insert(treasure_chest_loot_weights, {{name = 'engine-unit', count = math_random(1,16)},3})
table.insert(treasure_chest_loot_weights, {{name = 'rocket-fuel', count = math_random(1,5)},3})
table.insert(treasure_chest_loot_weights, {{name = 'empty-barrel', count = math_random(1,10)},7})
table.insert(treasure_chest_loot_weights, {{name = 'lubricant-barrel', count = math_random(1,10)},3})
table.insert(treasure_chest_loot_weights, {{name = 'crude-oil-barrel', count = math_random(1,10)},3})
table.insert(treasure_chest_loot_weights, {{name = 'iron-stick', count = math_random(1,100)},8})
table.insert(treasure_chest_loot_weights, {{name = "small-electric-pole", count = math_random(8,32)},9})
table.insert(treasure_chest_loot_weights, {{name = "firearm-magazine", count = math_random(16,48)},8})
table.insert(treasure_chest_loot_weights, {{name = 'grenade', count = math_random(16,32)},5})
table.insert(treasure_chest_loot_weights, {{name = 'land-mine', count = math_random(24,48)},5})
table.insert(treasure_chest_loot_weights, {{name = 'light-armor', count = 1},1})
table.insert(treasure_chest_loot_weights, {{name = 'heavy-armor', count = 1},2})
table.insert(treasure_chest_loot_weights, {{name = 'pipe', count = math.random(10,100)},6})
table.insert(treasure_chest_loot_weights, {{name = 'pipe', count = math_random(10,100)},6})
table.insert(treasure_chest_loot_weights, {{name = 'wooden-chest', count = 1},1})
table.insert(treasure_chest_loot_weights, {{name = 'burner-mining-drill', count = 1},1})
table.insert(treasure_chest_loot_weights, {{name = 'iron-axe', count = 1},1})
table.insert(treasure_chest_loot_weights, {{name = 'steel-axe', count = 1},3})
table.insert(treasure_chest_loot_weights, {{name = 'raw-wood', count = math.random(5,50)},2})
table.insert(treasure_chest_loot_weights, {{name = 'sulfur', count = math.random(20,50)},7})
table.insert(treasure_chest_loot_weights, {{name = 'explosives', count = math.random(20,50)},6})
table.insert(treasure_chest_loot_weights, {{name = 'raw-wood', count = math_random(5,50)},2})
table.insert(treasure_chest_loot_weights, {{name = 'sulfur', count = math_random(20,50)},7})
table.insert(treasure_chest_loot_weights, {{name = 'explosives', count = math_random(20,50)},6})
table.insert(treasure_chest_loot_weights, {{name = 'shotgun', count = 1},2})
table.insert(treasure_chest_loot_weights, {{name = 'stone-brick', count = math.random(80,100)},4})
table.insert(treasure_chest_loot_weights, {{name = 'small-lamp', count = math.random(3,10)},4})
table.insert(treasure_chest_loot_weights, {{name = 'rail', count = math.random(32,100)},4})
table.insert(treasure_chest_loot_weights, {{name = 'coin', count = math.random(32,100)},1})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-1', count = math.random(1,4)},2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-2', count = math.random(1,3)},2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-3', count = math.random(1,2)},1})
table.insert(treasure_chest_loot_weights, {{name = 'stone-brick', count = math_random(80,100)},4})
table.insert(treasure_chest_loot_weights, {{name = 'small-lamp', count = math_random(3,10)},4})
table.insert(treasure_chest_loot_weights, {{name = 'rail', count = math_random(32,100)},4})
table.insert(treasure_chest_loot_weights, {{name = 'coin', count = math_random(32,100)},1})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-1', count = math_random(1,4)},2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-2', count = math_random(1,3)},2})
table.insert(treasure_chest_loot_weights, {{name = 'assembling-machine-3', count = math_random(1,2)},1})
for _, t in pairs (treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
table.insert(treasure_chest_raffle_table, t[1])
@ -58,8 +58,8 @@ local function treasure_chest(position)
local e = game.surfaces["deep_jungle"].create_entity {name="wooden-chest",position=p, force="player"}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math.random(3,7), 1 do
local loot = treasure_chest_raffle_table[math.random(1,#treasure_chest_raffle_table)]
for x = 1, math_random(3,7), 1 do
local loot = treasure_chest_raffle_table[math_random(1,#treasure_chest_raffle_table)]
i.insert(loot)
end
end
@ -71,20 +71,20 @@ local function rare_treasure_chest(position)
local rare_treasure_chest_raffle_table = {}
local rare_treasure_chest_loot_weights = {}
table.insert(rare_treasure_chest_loot_weights, {{name = 'combat-shotgun', count = 1},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket-launcher', count = 1},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'modular-armor', count = 1},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'power-armor', count = 1},1})
table.insert(rare_treasure_chest_loot_weights, {{name = 'uranium-rounds-magazine', count = math.random(16,48)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = math.random(64,128)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'uranium-rounds-magazine', count = math_random(16,48)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = math_random(64,128)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'railgun', count = 1},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'railgun-dart', count = math.random(16,48)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'railgun-dart', count = math_random(16,48)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'exoskeleton-equipment', count = 1},2})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = math.random(8,16)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = math.random(4,8)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = math.random(4,8)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = math_random(8,16)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = math_random(4,8)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = math_random(4,8)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'atomic-bomb', count = 1},1})
for _, t in pairs (rare_treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
@ -95,8 +95,8 @@ local function rare_treasure_chest(position)
local e = game.surfaces["deep_jungle"].create_entity {name="steel-chest",position=p, force="player"}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math.random(2,3), 1 do
local loot = rare_treasure_chest_raffle_table[math.random(1,#rare_treasure_chest_raffle_table)]
for x = 1, math_random(2,3), 1 do
local loot = rare_treasure_chest_raffle_table[math_random(1,#rare_treasure_chest_raffle_table)]
i.insert(loot)
end
end
@ -163,16 +163,14 @@ end
local worm_raffle = {"small-worm-turret", "small-worm-turret", "small-worm-turret", "medium-worm-turret", "medium-worm-turret", "big-worm-turret"}
local rock_raffle = {"sand-rock-big","sand-rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
chunk_loader.add(function(chunk_piece)
local function on_chunk_generated(event)
local surface = game.surfaces["deep_jungle"]
if chunk_piece[2] ~= surface.index then return end
local chunk_piece_position = chunk_piece[1]
local chunk_pos_x = chunk_piece_position.x
local chunk_pos_y = chunk_piece_position.y
local area = {
left_top = {x = chunk_piece_position.x, y = chunk_piece_position.y},
right_bottom = {x = chunk_piece_position.x + 8, y = chunk_piece_position.y + 8}
}
if event.surface.name ~= surface.name then return end
local chunk_pos_x = event.area.left_top.x
local chunk_pos_y = event.area.left_top.y
local tiles = {}
local entities_to_place = {
rocks = {},
@ -184,8 +182,8 @@ chunk_loader.add(function(chunk_piece)
rare_treasure_chests = {}
}
local decoratives = {}
local math_random = math.random
local entities = surface.find_entities(area)
local entities = surface.find_entities(event.area)
for _, e in pairs(entities) do
if e.type == "tree" or e.force.name == "enemy" then
e.destroy()
@ -193,12 +191,11 @@ chunk_loader.add(function(chunk_piece)
end
local tile_to_insert = false
for x = 0, 7, 1 do
for y = 0, 7, 1 do
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos_x = chunk_pos_x + x
local pos_y = chunk_pos_y + y
local pos = {x = pos_x, y = pos_y}
local tile_distance_to_center = pos_x^2 + pos_y^2
local pos = {x = pos_x, y = pos_y}
tile_to_insert = false
local noise_3 = get_noise(3, pos)
@ -212,7 +209,7 @@ chunk_loader.add(function(chunk_piece)
if math_random(1,40) == 1 then table.insert(entities_to_place.fish, pos) end
end
else
local tile_distance_to_center = pos_x^2 + pos_y^2
local noise_1 = get_noise(1, pos)
local noise_2 = get_noise(2, pos)
local noise_4 = get_noise(4, pos)
@ -300,11 +297,11 @@ chunk_loader.add(function(chunk_piece)
end
end
for _, p in pairs(entities_to_place.worms) do
local e = worm_raffle[math.random(1,#worm_raffle)]
local e = worm_raffle[math_random(1,#worm_raffle)]
if surface.can_place_entity({name=e, position=p}) then surface.create_entity {name=e, position=p} end
end
for _, p in pairs(entities_to_place.rocks) do
local e = rock_raffle[math.random(1,#rock_raffle)]
local e = rock_raffle[math_random(1,#rock_raffle)]
surface.create_entity {name=e, position=p}
end
for _, p in pairs(entities_to_place.trees) do
@ -319,9 +316,8 @@ chunk_loader.add(function(chunk_piece)
for _, p in pairs(entities_to_place.fish) do
surface.create_entity {name="fish",position=p}
end
return true
end
)
local function on_player_joined_game(event)
local player = game.players[event.player_index]
@ -331,11 +327,11 @@ local function on_player_joined_game(event)
map_gen_settings.water = "none"
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = "normal", size = "normal", richness = "normal"},
["stone"] = {frequency = "normal", size = "normal", richness = "normal"},
["copper-ore"] = {frequency = "normal", size = "normal", richness = "normal"},
["iron-ore"] = {frequency = "normal", size = "normal", richness = "normal"},
["crude-oil"] = {frequency = "normal", size = "normal", richness = "normal"},
["coal"] = {frequency = "high", size = "big", richness = "normal"},
["stone"] = {frequency = "high", size = "big", richness = "normal"},
["copper-ore"] = {frequency = "high", size = "big", richness = "normal"},
["iron-ore"] = {frequency = "high", size = "big", richness = "normal"},
["crude-oil"] = {frequency = "high", size = "big", richness = "normal"},
["trees"] = {frequency = "none", size = "none", richness = "none"},
["enemy-base"] = {frequency = "none", size = "none", richness = "none"},
--["grass"] = {frequency = "none", size = "none", richness = "none"},
@ -346,7 +342,7 @@ local function on_player_joined_game(event)
game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.create_surface("deep_jungle", map_gen_settings)
game.forces["player"].set_spawn_position({0,0},game.surfaces["deep_jungle"])
global.map_init_done = true
global.map_init_done = true
end
local surface = game.surfaces["deep_jungle"]
if player.online_time < 5 and surface.is_chunk_generated({0,0}) then
@ -356,14 +352,13 @@ local function on_player_joined_game(event)
player.teleport({0,0}, "deep_jungle")
end
end
if player.online_time < 10 then
player.insert {name = 'submachine-gun', count = 1}
player.insert {name = 'raw-fish', count = 12}
player.insert {name = 'firearm-magazine', count = 32}
player.insert {name = 'steel-axe', count = 1}
player.insert {name = 'light-armor', count = 1}
end
end
end
local function on_marked_for_deconstruction(event)
@ -374,7 +369,7 @@ end
local function on_entity_died(event)
if event.entity.type == "tree" then
if math.random(1,6) == 1 then
if math_random(1,6) == 1 then
local surface = game.surfaces["deep_jungle"]
local p = surface.find_non_colliding_position("small-biter" , event.entity.position, 2, 0.5)
if p then surface.create_entity {name="small-biter", position=event.entity.position} end
@ -402,6 +397,7 @@ function cheat_mode()
end
end
event.add(defines.events.on_chunk_generated, on_chunk_generated)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -1,7 +1,6 @@
-- just an empty map
-- just an empty map for testing thingies
local event = require 'utils.event'
local map_functions = require "maps.tools.map_functions"
function dump_boom_layout()
local surface = game.surfaces["empty_map"]
@ -58,6 +57,10 @@ local function on_chunk_generated(event)
end
end
surface.set_tiles(tiles,true)
if chunk_pos_x % 96 ~= 0 then return end
if chunk_pos_y % 96 ~= 0 then return end
map_functions.draw_rainbow_patch({x = chunk_pos_x, y = chunk_pos_y}, surface, 28, 1000)
end
local function on_player_joined_game(event)
@ -85,7 +88,8 @@ local function on_player_joined_game(event)
game.forces["player"].set_spawn_position({0,0},game.surfaces["empty_map"])
local surface = game.surfaces["empty_map"]
--create_cluster("crude-oil", {x=0,y=0}, 5, surface, 10, math.random(300000,400000))
--local radius = 512
--game.forces.player.chart(surface, {{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
global.map_init_done = true
end
local surface = game.surfaces["empty_map"]

View File

@ -405,9 +405,12 @@ local function wake_up_idle_biters(surface)
end
end
local nearest_player_unit = surface.find_nearest_enemy{position={256, 0}, max_distance=512, force="enemy"}
if not nearest_player_unit then return end
for y = -256, 256, 32 do
local units = surface.find_entities_filtered({type = "unit", area = {{192, y},{360, y + 32}}})
local unit_group = surface.create_unit_group({position = {x = 160, y = math.floor(y / 2)}})
local units = surface.find_entities_filtered({type = "unit", area = {{64, y},{360, y + 32}}})
local unit_group = surface.create_unit_group({position = {x = nearest_player_unit.position.x + 32, y = math.floor(y / 2)}})
for _, unit in pairs(units) do
unit_group.add_member(unit)
end
@ -478,7 +481,7 @@ local function biter_attack_wave()
local surface = game.surfaces["fish_defender"]
clear_corpses(surface)
wake_up_idle_biters(surface)
--wake_up_idle_biters(surface)
if surface.count_entities_filtered({type = "unit", area = {{-128,-256},{360, 256}}}) > biter_count_limit then
game.print("Biter limit reached, wave delayed.", {r = 0.7, g = 0.1, b = 0.1})
@ -852,11 +855,11 @@ local function on_entity_died(event)
local surface = event.entity.surface
--if math_random(1, worm_chance) ~= 1 then
if math_random(1, 2) == 1 then
if math_random(1, 16) == 1 then
local p = surface.find_non_colliding_position("big-biter", event.entity.position, 3, 0.5)
if p then surface.create_entity {name = "big-biter", position = p} end
end
for i = 1, math_random(1, 3), 1 do
for i = 1, math_random(1, 2), 1 do
local p = surface.find_non_colliding_position("medium-biter", event.entity.position, 3, 0.5)
if p then surface.create_entity {name = "medium-biter", position = p} end
end

View File

@ -4,6 +4,36 @@ local f = {}
local math_random = math.random
local insert = table.insert
f.draw_rainbow_patch = function(position, surface, radius, richness)
if not position then return end
if not surface then return end
if not radius then return end
if not richness then return end
local modifier_1 = math_random(3,7)
local modifier_2 = math_random(1,10) * 0.005
local modifier_3 = math_random(1,10) * 0.05
local modifier_4 = math_random(5,30) * 0.01
local seed = game.surfaces[1].map_gen_settings.seed
local ores = {"stone", "coal", "iron-ore", "copper-ore"}
local richness_part = richness / (radius * 2)
for y = radius * -3, radius * 3, 1 do
for x = radius * -3, radius * 3, 1 do
local pos = {x = x + position.x, y = y + position.y}
local noise = simplex_noise(pos.x * modifier_2, pos.y * modifier_2, seed) + simplex_noise(pos.x * modifier_3, pos.y * modifier_3, seed) * modifier_4
local distance_to_center = math.sqrt(x^2 + y^2)
local ore = ores[(math.ceil(noise * modifier_1) % 4) + 1]
local amount = richness - richness_part * distance_to_center
if amount > 1 then
if surface.can_place_entity({name = ore, position = pos, amount = amount}) then
if distance_to_center + (noise * radius * 0.5) < radius then
surface.create_entity{name = ore, position = pos, amount = amount}
end
end
end
end
end
end
f.draw_entity_circle = function(position, name, surface, radius, check_collision, amount)
if not position then return end
if not name then return end
@ -38,9 +68,7 @@ f.draw_noise_tile_circle = function(position, name, surface, radius)
if not position then return end
if not name then return end
if not surface then return end
if not radius then return end
local math_random = math.random
local insert = table.insert
if not radius then return end
local noise_seed_add = 25000
local tiles = {}
for y = radius * -2, radius * 2, 1 do