mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-26 22:56:43 +02:00
wip
This commit is contained in:
parent
6534e4412d
commit
ab180dde94
9
maps/cave_miner_v2/functions.lua
Normal file
9
maps/cave_miner_v2/functions.lua
Normal file
@ -0,0 +1,9 @@
|
||||
local Public = {}
|
||||
|
||||
function Public.spawn_player(player)
|
||||
if player.character then return end
|
||||
player.create_character()
|
||||
player.teleport({0,0}, player.surface)
|
||||
end
|
||||
|
||||
return Public
|
91
maps/cave_miner_v2/main.lua
Normal file
91
maps/cave_miner_v2/main.lua
Normal file
@ -0,0 +1,91 @@
|
||||
local Event = require 'utils.event'
|
||||
local Terrain = require 'maps.cave_miner_v2.terrain'
|
||||
local Functions = require 'maps.cave_miner_v2.functions'
|
||||
local Global = require 'utils.global'
|
||||
local Server = require 'utils.server'
|
||||
|
||||
local math_floor = math.floor
|
||||
|
||||
local cave_miner = {}
|
||||
Global.register(
|
||||
cave_miner,
|
||||
function(tbl)
|
||||
cave_miner = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
local tick = game.ticks_played
|
||||
if tick == 0 then
|
||||
if player.character and player.character.valid then
|
||||
player.character.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not player.character then return end
|
||||
if not player.character.valid then return end
|
||||
Terrain.reveal(game.surfaces.nauvis, game.surfaces.cave_miner_source, {x = math_floor(player.position.x), y = math_floor(player.position.y)}, 8)
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
local surface = event.surface
|
||||
if surface.index == 1 then
|
||||
Terrain.out_of_map(event)
|
||||
return
|
||||
end
|
||||
if surface.name == "cave_miner_source" then
|
||||
Terrain.generate_cave(event)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function init(cave_miner)
|
||||
local tick = game.ticks_played
|
||||
if tick % 60 ~= 0 then return end
|
||||
Terrain.roll_source_surface()
|
||||
|
||||
game.forces.player.manual_mining_speed_modifier = cave_miner.mining_speed_bonus
|
||||
|
||||
cave_miner.gamestate = "spawn_players"
|
||||
end
|
||||
|
||||
local function spawn_players(cave_miner)
|
||||
local tick = game.ticks_played
|
||||
if tick % 60 ~= 0 then return end
|
||||
Terrain.reveal(game.surfaces.nauvis, game.surfaces.cave_miner_source, {x = 0, y = 0}, 8)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
Functions.spawn_player(player)
|
||||
end
|
||||
cave_miner.gamestate = "game_in_progress"
|
||||
end
|
||||
|
||||
local function game_in_progress(cave_miner)
|
||||
local tick = game.ticks_played
|
||||
if tick % 60 ~= 0 then return end
|
||||
end
|
||||
|
||||
local gamestates = {
|
||||
["init"] = init,
|
||||
["spawn_players"] = spawn_players,
|
||||
["game_in_progress"] = game_in_progress,
|
||||
}
|
||||
|
||||
local function on_tick()
|
||||
gamestates[cave_miner.gamestate](cave_miner)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
cave_miner.reset_counter = 0
|
||||
cave_miner.gamestate = "init"
|
||||
cave_miner.mining_speed_bonus = 100
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
100
maps/cave_miner_v2/terrain.lua
Normal file
100
maps/cave_miner_v2/terrain.lua
Normal file
@ -0,0 +1,100 @@
|
||||
local Public = {}
|
||||
|
||||
local GetNoise = require "utils.get_noise"
|
||||
|
||||
function Public.roll_source_surface()
|
||||
local map_gen_settings = {
|
||||
["water"] = 0,
|
||||
["starting_area"] = 1,
|
||||
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
|
||||
["default_enable_all_autoplace_controls"] = false,
|
||||
["autoplace_settings"] = {
|
||||
["entity"] = {treat_missing_as_default = false},
|
||||
["tile"] = {treat_missing_as_default = false},
|
||||
["decorative"] = {treat_missing_as_default = false},
|
||||
},
|
||||
autoplace_controls = {
|
||||
["coal"] = {frequency = 0, size = 0, richness = 0},
|
||||
["stone"] = {frequency = 0, size = 0, richness = 0},
|
||||
["copper-ore"] = {frequency = 0, size = 0, richness = 0},
|
||||
["iron-ore"] = {frequency = 0, size = 0, richness = 0},
|
||||
["uranium-ore"] = {frequency = 0, size = 0, richness = 0},
|
||||
["crude-oil"] = {frequency = 0, size = 0, richness = 0},
|
||||
["trees"] = {frequency = 0, size = 0, richness = 0},
|
||||
["enemy-base"] = {frequency = 0, size = 0, richness = 0}
|
||||
},
|
||||
}
|
||||
local surface = game.create_surface("cave_miner_source", map_gen_settings)
|
||||
surface.request_to_generate_chunks({x = 0, y = 0}, 2)
|
||||
surface.force_generate_chunk_requests()
|
||||
end
|
||||
|
||||
function Public.out_of_map(event)
|
||||
local left_top_x = event.area.left_top.x
|
||||
local left_top_y = event.area.left_top.y
|
||||
local tiles = {}
|
||||
local i = 0
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
i = i + 1
|
||||
tiles[i] = {name = "out-of-map", position = {left_top_x + x, left_top_y + y}}
|
||||
end
|
||||
end
|
||||
event.surface.set_tiles(tiles, false)
|
||||
end
|
||||
|
||||
function Public.reveal(surface, source_surface, position, brushsize)
|
||||
local tile = source_surface.get_tile(position)
|
||||
if tile.name == "lab-dark-1" then return end
|
||||
local tiles = {}
|
||||
local i = 0
|
||||
local brushsize_square = brushsize ^ 2
|
||||
for _, tile in pairs(source_surface.find_tiles_filtered({area = {{position.x - brushsize, position.y - brushsize}, {position.x + brushsize, position.y + brushsize}}})) do
|
||||
local tile_position = tile.position
|
||||
if tile.name ~= "lab-dark-1" and surface.get_tile(tile_position).name ~= tile.name and (position.x - tile_position.x) ^ 2 + (position.y - tile_position.y) ^ 2 < brushsize_square then
|
||||
i = i + 1
|
||||
tiles[i] = {name = tile.name, position = tile.position}
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
|
||||
for _, entity in pairs(source_surface.find_entities_filtered({area = {{position.x - brushsize, position.y - brushsize}, {position.x + brushsize, position.y + brushsize}}})) do
|
||||
local entity_position = entity.position
|
||||
if (position.x - entity_position.x) ^ 2 + (position.y - entity_position.y) ^ 2 < brushsize_square then
|
||||
entity.clone({position = entity_position, surface = surface})
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
|
||||
source_surface.set_tiles({{name = "lab-dark-1", position = position}}, true)
|
||||
source_surface.request_to_generate_chunks(position, 2)
|
||||
end
|
||||
|
||||
function Public.generate_cave(event)
|
||||
local surface = event.surface
|
||||
local left_top_x = event.area.left_top.x
|
||||
local left_top_y = event.area.left_top.y
|
||||
local seed = surface.map_gen_settings.seed
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local position = {x = left_top_x + x, y = left_top_y + y}
|
||||
local noise = GetNoise("decoratives", position, seed)
|
||||
if math.random(1, 3) > 1 and math.abs(noise) > 0.2 then surface.create_entity({name = "rock-big", position = position}) end
|
||||
end
|
||||
end
|
||||
|
||||
local tiles = {}
|
||||
local i = 0
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
i = i + 1
|
||||
tiles[i] = {name = "dirt-7", position = {left_top_x + x, left_top_y + y}}
|
||||
end
|
||||
end
|
||||
event.surface.set_tiles(tiles, false)
|
||||
|
||||
|
||||
end
|
||||
|
||||
return Public
|
Loading…
Reference in New Issue
Block a user