1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-05-13 21:56:29 +02:00

3x3 rooms

This commit is contained in:
MewMew 2019-05-29 14:47:53 +02:00
parent 5ae78afc00
commit 631d0dc543
5 changed files with 252 additions and 45 deletions

View File

@ -4,6 +4,60 @@ room.empty = function(surface, cell_left_top, direction)
end
room.single_worm = function(surface, cell_left_top, direction)
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
surface.create_entity({name = get_worm(), position = {x = left_top.x + grid_size * 0.5, y = left_top.y + grid_size * 0.5}, force = "enemy"})
end
room.single_nest = function(surface, cell_left_top, direction)
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
if math.random(1,4) == 1 then
surface.create_entity({name = "spitter-spawner", position = {x = left_top.x + grid_size * 0.5, y = left_top.y + grid_size * 0.5}, force = "enemy"})
else
surface.create_entity({name = "biter-spawner", position = {x = left_top.x + grid_size * 0.5, y = left_top.y + grid_size * 0.5}, force = "enemy"})
end
end
room.biters = function(surface, cell_left_top, direction)
local amount = math.random(1, math.floor(1 + (global.maze_depth * 0.25)))
local tile_positions = {}
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
for x = 0.5, grid_size - 0.5, 1 do
for y = 0.5, grid_size - 0.5, 1 do
local pos = {left_top.x + x, left_top.y + y}
tile_positions[#tile_positions + 1] = pos
end
end
table.shuffle_table(tile_positions)
for _, pos in pairs(tile_positions) do
surface.create_entity({name = get_biter(), position = pos, force = "enemy"})
amount = amount - 1
if amount < 1 then break end
end
end
room.spitters = function(surface, cell_left_top, direction)
local amount = math.random(1, math.floor(1 + (global.maze_depth * 0.25)))
local tile_positions = {}
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
for x = 0.5, grid_size - 0.5, 1 do
for y = 0.5, grid_size - 0.5, 1 do
local pos = {left_top.x + x, left_top.y + y}
tile_positions[#tile_positions + 1] = pos
end
end
table.shuffle_table(tile_positions)
for _, pos in pairs(tile_positions) do
surface.create_entity({name = get_spitter(), position = pos, force = "enemy"})
amount = amount - 1
if amount < 1 then break end
end
end
room.checkerboard_ore = function(surface, cell_left_top, direction)
local ores = {"coal", "iron-ore", "copper-ore", "stone"}
table.shuffle_table(ores)
@ -125,20 +179,25 @@ room.pond = function(surface, cell_left_top, direction)
end
end
local room_weights = {
--{func = room.tons_of_trees, weight = 25},
--{func = room.lots_of_rocks, weight = 50},
--{func = room.tons_of_rocks, weight = 25},
{func = room.quad_rocks, weight = 5},
--{func = room.three_rocks, weight = 5},
local room_weights = {
--{func = room.biters, weight = 25},
--{func = room.spitters, weight = 15},
--{func = room.single_worm, weight = 15},
--{func = room.single_nest, weight = 8},
--{func = room.tons_of_trees, weight = 15},
--{func = room.lots_of_rocks, weight = 25},
--{func = room.tons_of_rocks, weight = 15},
{func = room.quad_rocks, weight = 10},
{func = room.three_rocks, weight = 3},
{func = room.single_rock, weight = 10},
{func = room.checkerboard_ore, weight = 5},
--{func = room.some_scrap, weight = 10},
{func = room.lots_of_scrap, weight = 5},
--{func = room.tons_of_scrap, weight = 2},
{func = room.empty, weight = 15},
{func = room.empty, weight = 1},
{func = room.pond, weight = 10}
}

View File

@ -92,9 +92,8 @@ room.minefield_chest = function(surface, cell_left_top, direction)
end
local room_weights = {
{func = room.circle_pond_with_trees, weight = 25},
{func = room.scrapyard, weight = 125},
{func = room.circle_pond_with_trees, weight = 25},
{func = room.scrapyard, weight = 10},
{func = room.stone_block, weight = 25},
{func = room.minefield_chest, weight = 5},
{func = room.checkerboard_ore, weight = 10},

View File

@ -0,0 +1,59 @@
local room = {}
room.empty = function(surface, cell_left_top, direction)
end
room.stone_block = function(surface, cell_left_top, direction)
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
for x = 2.5, grid_size * 3 - 2.5, 1 do
for y = 2.5, grid_size * 3 - 2.5, 1 do
local pos = {left_top.x + x, left_top.y + y}
if math.random(1,6) ~= 1 then surface.create_entity({name = rock_raffle[math.random(1, #rock_raffle)], position = pos, force = "neutral"}) end
end
end
end
room.nine_nests = function(surface, cell_left_top, direction)
local left_top = {x = cell_left_top.x * grid_size, y = cell_left_top.y * grid_size}
local tree = tree_raffle[math.random(1, #tree_raffle)]
for x = 0, grid_size * 3 - 1, 1 do
for y = 0, grid_size * 3 - 1, 1 do
local pos = {left_top.x + x, left_top.y + y}
if x <= 1 or x >= grid_size * 3 - 2 or y <= 1 or y >= grid_size * 3 - 2 then
surface.create_entity({name = tree, position = pos, force = "neutral"})
end
end
end
if global.maze_depth < 50 then
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.5, left_top.y + grid_size * 3 * 0.5}, force = "enemy"})
return
end
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.25, left_top.y + grid_size * 3 * 0.25}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.5, left_top.y + grid_size * 3 * 0.25}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.75, left_top.y + grid_size * 3 * 0.25}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.25, left_top.y + grid_size * 3 * 0.5}, force = "enemy"})
surface.create_entity({name = "spitter-spawner", position = {left_top.x + grid_size * 3 * 0.5, left_top.y + grid_size * 3 * 0.5}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.75, left_top.y + grid_size * 3 * 0.5}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.25, left_top.y + grid_size * 3 * 0.75}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.5, left_top.y + grid_size * 3 * 0.75}, force = "enemy"})
surface.create_entity({name = "biter-spawner", position = {left_top.x + grid_size * 3 * 0.75, left_top.y + grid_size * 3 * 0.75}, force = "enemy"})
end
local room_weights = {
{func = room.stone_block, weight = 25},
{func = room.nine_nests, weight = 15},
{func = room.empty, weight = 1}
}
local room_shuffle = {}
for _, r in pairs(room_weights) do
for c = 1, r.weight, 1 do
room_shuffle[#room_shuffle + 1] = r.func
end
end
return room_shuffle

View File

@ -0,0 +1,66 @@
function get_biter()
local max_chance = 0
for i = 1, 4, 1 do
max_chance = max_chance + global.enemy_appearances[i].chance
end
local r = math.random(1, max_chance)
local current_chance = 0
for i = 1, 4, 1 do
current_chance = current_chance + global.enemy_appearances[i].chance
if r <= current_chance then return global.enemy_appearances[i].biter end
end
end
function get_spitter()
local max_chance = 0
for i = 1, 4, 1 do
max_chance = max_chance + global.enemy_appearances[i].chance
end
local r = math.random(1, max_chance)
local current_chance = 0
for i = 1, 4, 1 do
current_chance = current_chance + global.enemy_appearances[i].chance
if r <= current_chance then return global.enemy_appearances[i].spitter end
end
end
function get_worm()
local max_chance = 0
for i = 1, 4, 1 do
max_chance = max_chance + global.enemy_appearances[i].chance
end
local r = math.random(1, max_chance)
local current_chance = 0
for i = 1, 4, 1 do
current_chance = current_chance + global.enemy_appearances[i].chance
if r <= current_chance then return global.enemy_appearances[i].worm end
end
end
function get_ammo()
local max_chance = 0
for i = 1, 4, 1 do
max_chance = max_chance + global.enemy_appearances[i].chance
end
local r = math.random(1, max_chance)
local current_chance = 0
for i = 1, 4, 1 do
current_chance = current_chance + global.enemy_appearances[i].chance
if r <= current_chance then return global.enemy_appearances[i].ammo end
end
end
function ore_market(surface, position)
local market = surface.create_entity({name = "market", position = position, force = "neutral"})
market.destructible = false
market.add_market_item({price = {{"coin", 5}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}})
market.add_market_item({price = {{"coin", 5}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}})
market.add_market_item({price = {{"coin", 5}}, offer = {type = 'give-item', item = 'stone', count = 50}})
market.add_market_item({price = {{"coin", 5}}, offer = {type = 'give-item', item = 'coal', count = 50}})
market.add_market_item({price = {{"coin", 5}}, offer = {type = 'give-item', item = 'uranium-ore', count = 25}})
market.add_market_item({price = {{'iron-ore', 50}}, offer = {type = 'give-item', item = "coin", count = 5}})
market.add_market_item({price = {{'copper-ore', 50}}, offer = {type = 'give-item', item = "coin", count = 5}})
market.add_market_item({price = {{'stone', 50}}, offer = {type = 'give-item', item = "coin", count = 5}})
market.add_market_item({price = {{'coal', 50}}, offer = {type = 'give-item', item = "coin", count = 5}})
market.add_market_item({price = {{'uranium-ore', 25}}, offer = {type = 'give-item', item = "coin", count = 5}})
end

View File

@ -2,6 +2,7 @@
require "modules.satellite_score"
require "modules.dynamic_landfill"
require "modules.dangerous_goods"
require "modules.spawners_contain_biters"
--essentials
require "modules.biters_yield_coins"
@ -10,6 +11,8 @@ require "modules.mineable_wreckage_yields_scrap"
require "modules.biter_evasion_hp_increaser"
require 'utils.table'
require 'maps.stone_maze.global_functions'
local event = require 'utils.event'
local table_insert = table.insert
local math_random = math.random
@ -17,6 +20,7 @@ local math_random = math.random
local rooms_1x1 = require 'maps.stone_maze.1x1_rooms'
local multirooms = {}
multirooms["2x2"] = require 'maps.stone_maze.2x2_rooms'
multirooms["3x3"] = require 'maps.stone_maze.3x3_rooms'
map_functions = require "tools.map_functions"
grid_size = 8
@ -30,25 +34,6 @@ local visited_tile_translation = {
["grass-2"] = "grass-1"
}
global.biters = {
{"small-biter", chance = 100 - math.floor(global.maze_depth * 0.2)},
{"medium-biter", chance = 1 + math.floor(global.maze_depth * 0.2)},
{"big-biter", chance = 0},
{"behemoth-biter", chance = 0},
}
function get_biter()
end
function get_spitter()
end
function get_worm()
end
function get_ammo()
end
local function draw_depth_gui()
for _, player in pairs(game.connected_players) do
if player.gui.top.evolution_gui then player.gui.top.evolution_gui.destroy() end
@ -68,17 +53,16 @@ end
local function increase_depth()
global.maze_depth = global.maze_depth + 1
global.biter_evasion_health_increase_factor = 1 + (global.maze_depth * 0.001)
global.biter_evasion_health_increase_factor = 1 + (global.maze_depth * 0.0025)
draw_depth_gui()
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.online_time == 0 then
player.insert{name = 'landfill', count = 200}
player.insert{name = 'iron-plate', count = 32}
player.insert{name = 'iron-gear-wheel', count = 16}
end
global.enemy_appearances[2].chance = global.enemy_appearances[2].chance + 0.2
if global.maze_depth > 250 then global.enemy_appearances[3].chance = global.enemy_appearances[3].chance + 0.5 end
if global.maze_depth > 500 then global.enemy_appearances[4].chance = global.enemy_appearances[4].chance + 1 end
local evo = global.maze_depth * 0.001
if evo > 1 then evo = 1 end
game.forces.enemy.evolution_factor = evo
end
local function coord_to_string(pos)
@ -96,7 +80,15 @@ local cells = {
["0_-1"] = {{-1, -1}, {0, -1}},
["0_1"] = {{0, 0}, {-1, 0}},
["-1_0"] = {{-1, -1}, {-1, 0}},
["1_0"] = {{0, 0}, {0, -1}},
["1_0"] = {{0, 0}, {0, -1}}
},
["3x3"] = {
size_x = 3,
size_y = 3,
["0_-1"] = {{-2, -2}, {-1, -2}, {0, -2}},
["0_1"] = {{0, 0}, {-1, 0}, {-2, 0}},
["-1_0"] = {{-2, -2}, {-2, -1}, {-2, 0}},
["1_0"] = {{0, 0}, {0, -1}, {0, -2}}
}
}
@ -130,6 +122,12 @@ end
local function set_visted_cell_tiles(surface, cell_position)
local left_top = {x = cell_position.x * grid_size, y = cell_position.y * grid_size}
local remnants = {}
for _, e in pairs(surface.find_entities_filtered({type = "corpse", area = {{left_top.x, left_top.y},{left_top.x + grid_size, left_top.y + grid_size}}})) do
remnants[#remnants] = {name = e.name, position = e.position, direction = e.direction}
end
for x = 0, grid_size - 1, 1 do
for y = 0, grid_size - 1, 1 do
local pos = {left_top.x + x, left_top.y + y}
@ -139,6 +137,10 @@ local function set_visted_cell_tiles(surface, cell_position)
end
end
end
for _, e in pairs(remnants) do
surface.create_entity({name = e.name, position = e.position, direction = e.direction})
end
end
local function can_multicell_expand(cell_position, direction, cell_type)
@ -179,12 +181,12 @@ local function can_1x1_expand(cell_position, direction)
end
local multi_cell_chances = {
{"2x2"},
"3x3", "2x2", "2x2", "2x2"
}
local function set_cell(surface, cell_position, direction)
local multi_cell_type = "2x2"
local multi_cell_type = multi_cell_chances[math_random(1, #multi_cell_chances)]
if math_random(1,3) == 1 then
local cell_left_top = can_multicell_expand(cell_position, direction, multi_cell_type)
@ -271,9 +273,13 @@ local function on_chunk_generated(event)
local tile_name = "out-of-map"
if x < grid_size and y < grid_size then tile_name = "dirt-7" end
local p = {x = left_top.x + x, y = left_top.y + y}
surface.set_tiles({{name = tile_name, position = p}}, true)
surface.set_tiles({{name = tile_name, position = p}}, true)
end
end
for _, e in pairs(surface.find_entities_filtered({force = "neutral"})) do
e.destroy()
end
ore_market(surface, {x = grid_size * 0.4, y = grid_size * 0.4})
init_cell({0,0})
global.maze_cells[coord_to_string({0,0})].occupied = true
return
@ -287,10 +293,28 @@ local function on_chunk_generated(event)
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.online_time == 0 then
player.insert{name = 'iron-plate', count = 32}
player.insert{name = 'iron-gear-wheel', count = 16}
player.insert{name = 'submachine-gun', count = 1}
player.insert{name = 'uranium-rounds-magazine', count = 128}
player.insert{name = 'firearm-magazine', count = 64}
end
end
local function on_init(event)
global.maze_cells = {}
global.maze_depth = 0
game.forces["player"].set_spawn_position({x = grid_size * 0.5, y = grid_size * 0.5}, game.surfaces.nauvis)
global.enemy_appearances = {
{biter = "small-biter", spitter = "small-spitter", worm = "small-worm-turret", ammo = "firearm-magazine", chance = 100},
{biter = "medium-biter", spitter = "medium-spitter", worm = "medium-worm-turret", ammo = "piercing-rounds-magazine", chance = 0},
{biter = "big-biter", spitter = "big-spitter", worm = "big-worm-turret", ammo = "uranium-rounds-magazine", chance = 0},
{biter = "behemoth-biter", spitter = "behemoth-spitter", worm = "behemoth-worm-turret", ammo = "uranium-rounds-magazine", chance = 0}
}
game.forces["player"].set_spawn_position({x = grid_size * 0.5, y = grid_size * 0.75}, game.surfaces.nauvis)
end
event.on_init(on_init)