1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

map now collapses

This commit is contained in:
MewMew 2019-11-14 17:54:28 +01:00
parent dc5e9e696c
commit d85f7cfc22
3 changed files with 82 additions and 42 deletions

View File

@ -3,9 +3,19 @@ local simplex_noise = require "utils.simplex_noise".d2
local math_random = math.random
local math_abs = math.abs
local math_sqrt = math.sqrt
local level_depth = require "maps.mountain_fortress_v2.terrain"
local math_floor = math.floor
local table_remove = table.remove
local table_insert = table.insert
local tile_conversion = {
["concrete"] = "stone-path",
["hazard-concrete-left"] = "stone-path",
["hazard-concrete-right"] = "stone-path",
["refined-concrete"] = "concrete",
["refined-hazard-concrete-left"] = "hazard-concrete-left",
["refined-hazard-concrete-right"] = "hazard-concrete-right",
["stone-path"] = "landfill",
}
local function get_collapse_vectors(radius)
local vectors = {}
@ -14,7 +24,7 @@ local function get_collapse_vectors(radius)
local seed = math_random(1, 9999999)
for x = radius * -1, radius, 1 do
for y = radius * -1, radius, 1 do
local noise = math_abs(simplex_noise(x * m, y * m, seed) * radius * 1.5)
local noise = math_abs(simplex_noise(x * m, y * m, seed) * radius * 1.3)
local d = math_sqrt(x ^ 2 + y ^ 2)
if d + noise < radius then
vectors[i] = {x, y}
@ -25,8 +35,32 @@ local function get_collapse_vectors(radius)
return vectors
end
local function get_position()
local position = {x = 0, y = 64}
local function set_x_positions()
local x_positions = global.map_collapse.x_positions
for x = level_depth * -1, level_depth, 1 do
table_insert(x_positions, x)
end
table.shuffle_table(x_positions)
end
local function get_position(surface)
local x_positions = global.map_collapse.x_positions
if #x_positions == 0 then set_x_positions() end
local x = x_positions[1]
local position = false
for y = 256, -100000, -1 do
y = y + math_random(1, 8)
local tile = surface.get_tile({x, y})
if tile.valid then
if tile.name ~= "out-of-map" then
position = {x = x, y = y}
break
end
else
y = y + 96
end
end
table_remove(x_positions, 1)
return position
end
@ -53,7 +87,7 @@ local function set_collapse_tiles(surface, position, vectors)
for _, vector in pairs(vectors) do
local position = {x = position.x + vector[1], y = position.y + vector[2]}
local tile = surface.get_tile(position)
if tile then
if tile.valid then
tiles[i] = tile
i = i + 1
end
@ -62,31 +96,38 @@ local function set_collapse_tiles(surface, position, vectors)
table_insert(global.map_collapse.processing, sorted_tiles)
end
local function collapse_map()
local surface = game.surfaces[global.active_surface_index]
local vectors = get_collapse_vectors(math_random(8, 24))
local position = get_position(surface)
if not position then return end
game.forces.player.chart(surface, {{position.x - 31, position.y - 31},{position.x + 31, position.y + 31}})
set_collapse_tiles(surface, position, vectors)
end
function Public.process()
if not global.map_collapse then return end
local processing = global.map_collapse.processing
if #processing == 0 then return end
if #processing == 0 then collapse_map() return end
local surface = game.surfaces[global.active_surface_index]
for k1, tile_set in pairs(processing) do
for k2, tile in pairs(tile_set) do
surface.set_tiles({{name = "out-of-map", position = tile.position}}, true)
local conversion_tile = tile_conversion[tile.name]
if conversion_tile then
surface.set_tiles({{name = conversion_tile, position = tile.position}}, true)
surface.create_trivial_smoke({name="train-smoke", position = tile.position})
else
surface.set_tiles({{name = "out-of-map", position = tile.position}}, true)
end
table_remove(tile_set, k2)
break
end
if #tile_set == 0 then table_remove(processing, k1) end
break
end
end
function collapse_map()
local surface = game.surfaces[global.active_surface_index]
local vectors = get_collapse_vectors(20)
set_collapse_tiles(surface, get_position(), vectors)
end
function Public.init()
global.map_collapse = {}
global.map_collapse.last_position = "mew"
global.map_collapse.x_positions = {}
global.map_collapse.processing = {}
end

View File

@ -23,7 +23,7 @@ function Public.locomotive_spawn(surface, position)
end
local function fish_tag()
function Public.fish_tag()
if not global.locomotive_cargo then return end
if not global.locomotive_cargo.valid then return end
if not global.locomotive_cargo.surface then return end
@ -58,7 +58,7 @@ local function remove_acceleration()
global.locomotive_driver = nil
end
]]
local function set_player_spawn_and_refill_fish()
function Public.set_player_spawn_and_refill_fish()
if not global.locomotive_cargo then return end
if not global.locomotive_cargo.valid then return end
global.locomotive_cargo.health = global.locomotive_cargo.health + 6
@ -68,26 +68,4 @@ local function set_player_spawn_and_refill_fish()
game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface)
end
local function tick()
if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish()
end
if global.game_reset_tick then
if global.game_reset_tick < game.tick then
global.game_reset_tick = nil
require "maps.mountain_fortress_v2.main".reset_map()
end
return
end
fish_tag()
--accelerate()
else
--remove_acceleration()
end
end
local event = require 'utils.event'
event.on_nth_tick(5, tick)
return Public

View File

@ -14,6 +14,7 @@ require "modules.rocks_broken_paint_tiles"
require "modules.rocks_heal_over_time"
require "modules.rocks_yield_ore_veins"
local level_depth = require "maps.mountain_fortress_v2.terrain"
local Collapse = require "maps.mountain_fortress_v2.collapse"
require "maps.mountain_fortress_v2.flamethrower_nerf"
local BiterRolls = require "modules.wave_defense.biter_rolls"
local Reset = require "functions.soft_reset"
@ -21,7 +22,7 @@ local Pets = require "modules.biter_pets"
local Map = require "modules.map_info"
local WD = require "modules.wave_defense.table"
local Treasure = require "maps.mountain_fortress_v2.treasure"
local Locomotive = require "maps.mountain_fortress_v2.locomotive".locomotive_spawn
local Locomotive = require "maps.mountain_fortress_v2.locomotive"
local Modifier = require "player_modifiers"
local math_random = math.random
local Public = {}
@ -85,7 +86,7 @@ function Public.reset_map()
game.forces.player.technologies["railway"].researched = true
game.forces.player.set_spawn_position({-2, 16}, surface)
Locomotive(surface, {x = 0, y = 16})
Locomotive.locomotive_spawn(surface, {x = 0, y = 16})
WD.reset_wave_defense()
wave_defense_table.surface_index = global.active_surface_index
@ -93,7 +94,9 @@ function Public.reset_map()
wave_defense_table.nest_building_density = 32
wave_defense_table.game_lost = false
--RPG.rpg_reset_all_players()
Collapse.init()
RPG.rpg_reset_all_players()
end
local function protect_train(event)
@ -293,6 +296,23 @@ local function on_player_left_game(event)
set_difficulty()
end
local function tick()
if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then
Locomotive.set_player_spawn_and_refill_fish()
end
if global.game_reset_tick then
if global.game_reset_tick < game.tick then
global.game_reset_tick = nil
require "maps.mountain_fortress_v2.main".reset_map()
end
return
end
Locomotive.fish_tag()
end
Collapse.process()
end
local function on_init()
local T = Map.Pop_info()
T.main_caption = "M O U N T A I N F O R T R E S S"
@ -331,6 +351,7 @@ end
local event = require 'utils.event'
event.on_init(on_init)
event.on_nth_tick(2, tick)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_player_joined_game, on_player_joined_game)