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

lumberjack updates

This commit is contained in:
Gerkiz 2020-05-10 15:43:25 +02:00
parent 0ee4d245cd
commit c3af9b92db
13 changed files with 1188 additions and 175 deletions

View File

@ -1,5 +1,8 @@
local Color = require 'utils.color_presets'
local WPT = require 'maps.lumberjack.table'
local Task = require 'utils.task'
local grandmaster = '[color=blue]Grandmaster:[/color]'
commands.add_command(
'rainbow_mode',
@ -22,13 +25,36 @@ commands.add_command(
end
)
commands.add_command(
'reset_game',
'Usable only for admins - resets the game!',
function()
local p
local player = game.player
local reset_map = require 'maps.lumberjack.main'.reset_map
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("[ERROR] You're not admin!", Color.fail)
return
end
else
p = log
end
end
game.print(grandmaster .. ' ' .. player.name .. ', has reset the game!', {r = 0.98, g = 0.66, b = 0.22})
reset_map()
end
)
if _DEBUG then
commands.add_command(
'reset_game',
'Debug only, reset the game!',
'get_queue_speed',
'Debug only, return the current task queue speed!',
function()
local reset_map = require 'maps.lumberjack.main'.reset_map
local player = game.player
if player then
@ -38,7 +64,7 @@ if _DEBUG then
end
end
end
reset_map()
game.print(Task.get_queue_speed())
end
)
end

View File

@ -0,0 +1,429 @@
local Task = require 'utils.task'
local Token = require 'utils.token'
local Event = require 'utils.event'
local insert = table.insert
local tiles_per_tick
local regen_decoratives
local surfaces = {}
local total_calls
local Public = {}
-- Set to false by modules that want to control the on_chunk_generated event themselves.
Public.enable_register_events = true
local function do_tile_inner(tiles, tile, pos)
if type(tile) == 'string' then
insert(tiles, {name = tile, position = pos})
end
end
local function do_tile(y, x, data, shape)
if not data.surface.valid then
return
end
local pos = {x, y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(x + 0.5, y + 0.5, data)
if type(tile) == 'table' then
do_tile_inner(data.tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
insert(data.hidden_tiles, {tile = hidden_tile, position = pos})
end
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
insert(data.entities, entity)
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
insert(data.decoratives, decorative)
end
end
local markets = tile.markets
if markets then
for _, t in ipairs(markets) do
if not t.position then
t.position = pos
end
insert(data.markets, t)
end
end
local treasure = tile.treasure
if treasure then
for _, t in ipairs(treasure) do
if not t.position then
t.position = pos
end
insert(data.treasure, t)
end
end
else
do_tile_inner(data.tiles, tile, pos)
end
end
local function do_row(row, data, shape)
if not data.surface.valid then
return
end
local y = data.top_y + row
local top_x = data.top_x
local tiles = data.tiles
data.y = y
for x = top_x, top_x + 31 do
data.x = x
local pos = {data.x, data.y}
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(x + 0.5, y + 0.5, data)
if type(tile) == 'table' then
do_tile_inner(tiles, tile.tile, pos)
local hidden_tile = tile.hidden_tile
if hidden_tile then
insert(data.hidden_tiles, {tile = hidden_tile, position = pos})
end
local entities = tile.entities
if entities then
for _, entity in ipairs(entities) do
if not entity.position then
entity.position = pos
end
insert(data.entities, entity)
end
end
local decoratives = tile.decoratives
if decoratives then
for _, decorative in ipairs(decoratives) do
if not decorative.position then
decorative.position = pos
end
insert(data.decoratives, decorative)
end
end
local markets = tile.markets
if markets then
for _, t in ipairs(markets) do
if not t.position then
t.position = pos
end
insert(data.markets, t)
end
end
local treasure = tile.treasure
if treasure then
for _, t in ipairs(treasure) do
if not t.position then
t.position = pos
end
insert(data.treasure, t)
end
end
else
do_tile_inner(tiles, tile, pos)
end
end
end
local function do_place_tiles(data)
if not data.surface.valid then
return
end
data.surface.set_tiles(data.tiles, true)
end
local function do_place_hidden_tiles(data)
if not data.surface.valid then
return
end
local surface = data.surface
for _, t in ipairs(data.hidden_tiles) do
surface.set_hidden_tile(t.position, t.tile)
end
end
local function do_place_decoratives(data)
if not data.surface.valid then
return
end
if regen_decoratives then
data.surface.regenerate_decorative(nil, {{data.top_x / 32, data.top_y / 32}})
end
local dec = data.decoratives
if #dec > 0 then
data.surface.create_decoratives({check_collision = true, decoratives = dec})
end
end
local function do_place_entities(data)
if not data.surface.valid then
return
end
local surface = data.surface
local ev
for _, e in ipairs(data.entities) do
if not e.active and not e.destructible then
ev = surface.create_entity(e)
ev.destructible = false
ev.active = false
elseif not e.destructible then
ev = surface.create_entity(e)
ev.destructible = false
elseif not e.active then
ev = surface.create_entity(e)
ev.active = false
else
local entity = surface.create_entity(e)
if entity and e.callback then
local callback = Token.get(e.callback)
callback(entity, e.data)
end
end
end
end
local function run_chart_update(data)
if not data.surface.valid then
return
end
local x = data.top_x / 32
local y = data.top_y / 32
if game.forces.player.is_chunk_charted(data.surface, {x, y}) then
-- Don't use full area, otherwise adjacent chunks get charted
game.forces.player.chart(
data.surface,
{
{data.top_x, data.top_y},
{data.top_x + 1, data.top_y + 1}
}
)
end
end
local function map_gen_action(data)
local state = data.y
if state < 32 then
if not data.surface.valid then
return
end
local shape = surfaces[data.surface.name]
if shape == nil then
return false
end
local count = tiles_per_tick
local y = state + data.top_y
local x = data.x
local max_x = data.top_x + 32
data.y = y
repeat
count = count - 1
do_tile(y, x, data, shape)
x = x + 1
if x == max_x then
y = y + 1
if y == data.top_y + 32 then
break
end
x = data.top_x
data.y = y
end
data.x = x
until count == 0
data.y = y - data.top_y
return true
elseif state == 32 then
do_place_tiles(data)
data.y = 33
return true
elseif state == 33 then
do_place_hidden_tiles(data)
data.y = 34
return true
elseif state == 34 then
do_place_entities(data)
data.y = 35
return true
elseif state == 35 then
do_place_decoratives(data)
data.y = 36
return true
elseif state == 36 then
run_chart_update(data)
return false
end
end
local map_gen_action_token = Token.register(map_gen_action)
--- Adds generation of a Chunk of the map to the queue
-- @param event <table> the event table from on_chunk_generated
function Public.schedule_chunk(event)
local surface = event.surface
local shape = surfaces[surface.name]
local str = surface.name
if string.sub(event.surface.name, 0, #str) ~= surface.name then
return
end
if not shape then
return
end
local area = event.area
local data = {
y = 0,
x = area.left_top.x,
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
decoratives = {},
markets = {},
treasure = {}
}
if not data.surface.valid then
return
end
Task.queue_task(map_gen_action_token, data, total_calls)
end
--- Generates a Chunk of map when called
-- @param event <table> the event table from on_chunk_generated
function Public.do_chunk(event)
local surface = event.surface
local shape = surfaces[surface.name]
local str = surface.name
if string.sub(event.surface.name, 0, #str) ~= surface.name then
return
end
if not shape then
return
end
local area = event.area
local data = {
area = area,
top_x = area.left_top.x,
top_y = area.left_top.y,
surface = surface,
tiles = {},
hidden_tiles = {},
entities = {},
decoratives = {},
markets = {},
treasure = {}
}
if not data.surface.valid then
return
end
for row = 0, 31 do
do_row(row, data, shape)
end
do_place_tiles(data)
do_place_hidden_tiles(data)
do_place_entities(data)
do_place_decoratives(data)
end
--- Sets the variables for the generate functions, should only be called from map_loader
-- @param args <table>
function Public.init(args)
tiles_per_tick = args.tiles_per_tick or 32
regen_decoratives = args.regen_decoratives or false
for surface_name, shape in pairs(args.surfaces or {}) do
surfaces[surface_name] = shape
end
total_calls = math.ceil(1024 / tiles_per_tick) + 5
end
local do_chunk = Public.do_chunk
local schedule_chunk = Public.schedule_chunk
local function on_chunk(event)
if event.tick == 0 then
do_chunk(event)
else
schedule_chunk(event)
end
end
--- Registers the event to generate our map when Chunks are generated, should only be called from map_loader
function Public.register()
if not Public.enable_register_events then
return
end
if _DEBUG then
Event.add(defines.events.on_chunk_generated, do_chunk)
else
Event.add(defines.events.on_chunk_generated, on_chunk)
end
end
--- Returns the surfaces that the generate functions will act on
-- Warning! Changing this table after on_init or on_load has run will cause desyncs!
-- @return dictionary of surface_name -> shape function
function Public.get_surfaces()
if _LIFECYCLE == 8 then
error('Calling Generate.get_surfaces after on_init() or on_load() has run is a desync risk.', 2)
end
return surfaces
end
return Public

View File

@ -70,8 +70,8 @@ local function update_gui(player)
gui.global_pool.tooltip = 'Get this number over 5k to get some of this mad XP! \\o/'
end
gui.scrap_mined.caption = ' [img=entity.tree-01]: ' .. format_number(st.mined_scrap, true)
gui.scrap_mined.tooltip = 'Amount of trees harvested.'
gui.scrap_mined.caption = ' [img=entity.tree-01][img=entity.rock-huge]: ' .. format_number(st.mined_scrap, true)
gui.scrap_mined.tooltip = 'Amount of trees/rocks harvested.'
gui.biters_killed.caption = ' [img=entity.small-biter]: ' .. format_number(st.biters_killed, true)
gui.biters_killed.tooltip = 'Amount of biters killed.'

View File

@ -4,6 +4,7 @@ local Constants = require 'maps.lumberjack.icw.constants'
local table_insert = table.insert
local table_remove = table.remove
local math_round = math.round
local math_random = math.random
function Public.request_reconstruction(icw)
@ -19,6 +20,17 @@ local function delete_empty_surfaces(icw)
end
end
local function kick_players_out_of_vehicles(wagon)
for _, player in pairs(game.connected_players) do
local character = player.character
if character and character.valid and character.driving then
if wagon.surface == player.surface then
character.driving = false
end
end
end
end
local function connect_power_pole(entity, wagon_area_left_top_y)
local surface = entity.surface
local max_wire_distance = entity.prototype.max_wire_distance
@ -35,6 +47,13 @@ local function connect_power_pole(entity, wagon_area_left_top_y)
end
local function equal_fluid(source_tank, target_tank)
if not source_tank.valid then
return
end
if not target_tank.valid then
return
end
local source_fluid = source_tank.fluidbox[1]
if not source_fluid then
return
@ -223,6 +242,8 @@ local function get_player_data(icw, player)
end
icw.players[player.index] = {
surface = 1,
fallback_surface = 1,
zoom = 0.30,
map_size = 360
}
@ -242,6 +263,7 @@ function Public.kill_wagon(icw, entity)
end
local wagon = icw.wagons[entity.unit_number]
local surface = wagon.surface
kick_players_out_of_vehicles(wagon)
kill_wagon_doors(icw, wagon)
for _, e in pairs(surface.find_entities_filtered({area = wagon.area})) do
if e.name == 'character' and e.player then
@ -298,9 +320,9 @@ function Public.create_wagon_room(icw, wagon)
local area = wagon.area
local main_tile_name = 'tutorial-grid'
--if wagon.entity.type == "locomotive" then
-- main_tile_name = "lab-dark-2"
--end
if wagon.entity.type == 'locomotive' then
main_tile_name = 'black-refined-concrete'
end
local tiles = {}
for x = -3, 2, 1 do
@ -321,16 +343,23 @@ function Public.create_wagon_room(icw, wagon)
end
end
local fishes = {}
if wagon.entity.type == 'locomotive' then
for x = -3, 2, 1 do
for y = 10, 12, 1 do
table_insert(tiles, {name = 'water', position = {x, y}})
table_insert(fishes, {name = 'fish', position = {x, y}})
end
end
end
surface.set_tiles(tiles, true)
for _, fish in pairs(fishes) do
surface.create_entity(fish)
end
construct_wagon_doors(icw, wagon)
if wagon.entity.type == 'fluid-wagon' then
@ -477,6 +506,9 @@ function Public.use_cargo_wagon_door(icw, player, door)
return
end
player_data.fallback_surface = wagon.entity.surface.index
player_data.fallback_position = {wagon.entity.position.x, wagon.entity.position.y}
if wagon.entity.surface.name ~= player.surface.name then
local surface = wagon.entity.surface
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
@ -494,6 +526,7 @@ function Public.use_cargo_wagon_door(icw, player, door)
player.teleport(position, surface)
Public.kill_minimap(player)
end
player_data.surface = surface.index
else
local surface = wagon.surface
local area = wagon.area
@ -510,6 +543,7 @@ function Public.use_cargo_wagon_door(icw, player, door)
else
player.teleport(position, surface)
end
player_data.surface = surface.index
end
end
@ -537,8 +571,7 @@ local function move_room_to_train(icw, train, wagon)
return
end
kill_wagon_doors(icw, wagon)
kick_players_out_of_vehicles(wagon)
local player_positions = {}
for _, e in pairs(wagon.surface.find_entities_filtered({name = 'character', area = wagon.area})) do
local player = e.player
@ -551,6 +584,8 @@ local function move_room_to_train(icw, train, wagon)
end
end
kill_wagon_doors(icw, wagon)
wagon.surface.clone_area(
{
source_area = wagon.area,

View File

@ -422,10 +422,10 @@ function Public.locomotive_spawn(surface, position)
this.locomotive_cargo.minable = false
this.locomotive_cargo.operable = true
local t = ICW.register_wagon(this.locomotive)
local c = ICW.register_wagon(this.locomotive_cargo)
t.entity_count = 999
c.entity_count = 999
local locomotive = ICW.register_wagon(this.locomotive)
local wagon = ICW.register_wagon(this.locomotive_cargo)
locomotive.entity_count = 999
wagon.entity_count = 999
end
function Public.inside(pos, area)

View File

@ -23,10 +23,10 @@ end
function Public.get_items()
local this = WPT.get_table()
local threat_cost = 50000 * (1 + this.train_upgrades)
local energy_cost = 50000 * (1 + this.train_upgrades)
local health_cost = 50000 * (1 + this.train_upgrades)
local aura_cost = 50000 * (1 + this.train_upgrades)
local threat_cost = 15000 * (1 + this.train_upgrades)
local energy_cost = 15000 * (1 + this.train_upgrades)
local health_cost = 15000 * (1 + this.train_upgrades)
local aura_cost = 15000 * (1 + this.train_upgrades)
local items = {
['clear_threat_level'] = {
@ -67,14 +67,29 @@ function Public.get_items()
price = 250,
tooltip = '[Terrain Reveal]:\nAllows the player to reveal terrain for a short amount of time.',
sprite = 'item/computer',
enabled = false
},
['purge_darkness'] = {
stack = 1,
value = 'coin',
price = 1550,
tooltip = "[Darkness]:\nPay the Sun Gods some coins and they'll reward you handsomely.",
sprite = 'item/computer',
enabled = true
},
['small-lamp'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Small Lamp'},
['land-mine'] = {stack = 1, value = 'coin', price = 25, tooltip = 'Land Mine'},
['raw-fish'] = {stack = 2, value = 'coin', price = 25, tooltip = 'Raw Fish'},
['firearm-magazine'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Firearm Magazine'},
['loader'] = {stack = 1, value = 'coin', price = 150, tooltip = 'Loader'},
['fast-loader'] = {stack = 1, value = 'coin', price = 300, tooltip = 'Fast Loader'}
['small-lamp'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Small Sunlight'},
['wood'] = {stack = 50, value = 'coin', price = 12, tooltip = 'Some fine Wood'},
['land-mine'] = {stack = 1, value = 'coin', price = 25, tooltip = 'Land Boom Danger'},
['raw-fish'] = {stack = 1, value = 'coin', price = 4, tooltip = 'Flappy Fish'},
['firearm-magazine'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Firearm Pew'},
['crude-oil-barrel'] = {stack = 1, value = 'coin', price = 8, tooltip = 'Crude Oil Flame'},
['loader'] = {stack = 1, value = 'coin', price = 150, tooltip = 'Ground Inserter.'},
['fast-loader'] = {
stack = 1,
value = 'coin',
price = 300,
tooltip = 'Ground Fast Inserter'
}
}
return items
@ -538,6 +553,35 @@ local function gui_click(event)
return
end
if name == 'purge_darkness' then
if not this.freeze_daytime then
return player.print(
grandmaster .. ' ' .. player.name .. ", it's already sunlight!",
{r = 0.98, g = 0.66, b = 0.22}
)
end
game.print(
grandmaster .. ' ' .. player.name .. ' has paid the Sun Gods some coins for sunlight!',
{r = 0.98, g = 0.66, b = 0.22}
)
local surface = game.surfaces[this.active_surface_index]
game.print(grandmaster .. ' Sunlight, finally!', {r = 0.98, g = 0.66, b = 0.22})
surface.min_brightness = 1
surface.brightness_visual_weights = {1, 0, 0, 0}
surface.daytime = 1
surface.freeze_daytime = false
surface.solar_power_multiplier = 1
this.freeze_daytime = false
player.remove_item({name = item.value, count = cost})
redraw_market_items(data.item_frame, player, data.search_text)
redraw_coins_left(data.coins_left, player)
return
end
if player_item_count >= cost then
if player.can_insert({name = name, count = item_count}) then
player.play_sound({path = 'entity-close/stone-furnace', volume_modifier = 0.65})

View File

@ -28,7 +28,7 @@ local ICW = require 'maps.lumberjack.icw.main'
local WD = require 'modules.wave_defense.table'
local Map = require 'modules.map_info'
local RPG = require 'maps.lumberjack.rpg'
local Reset = require 'functions.soft_reset'
local Reset = require 'maps.lumberjack.soft_reset'
local Terrain = require 'maps.lumberjack.terrain'
local Event = require 'utils.event'
local WPT = require 'maps.lumberjack.table'
@ -38,12 +38,15 @@ local Score = require 'comfy_panel.score'
local Poll = require 'comfy_panel.poll'
local Collapse = require 'modules.collapse'
local Balance = require 'maps.lumberjack.balance'
local shape = require 'maps.lumberjack.terrain'.heavy_functions
local Generate = require 'maps.lumberjack.generate'
local Task = require 'utils.task'
local Public = {}
local math_random = math.random
local math_floor = math.floor
WPT.init({train_reveal = true, energy_shared = true})
WPT.init({train_reveal = false, energy_shared = true, reveal_normally = true})
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
local colors = {
@ -63,9 +66,15 @@ local disabled_tiles = {
local grandmaster = '[color=blue]Grandmaster:[/color]'
local function create_forces_and_disable_tech()
game.create_force('defenders')
game.create_force('lumber_defense')
if not game.forces.defenders then
game.create_force('defenders')
end
if not game.forces.lumber_defense then
game.create_force('lumber_defense')
end
game.forces.defenders.share_chart = false
game.forces.player.set_friend('defenders', true)
game.forces.lumber_defense.set_friend('player', false)
game.forces.enemy.set_friend('defenders', true)
game.forces.enemy.set_friend('lumber_defense', true)
game.forces.defenders.set_friend('player', true)
@ -117,12 +126,12 @@ function Public.reset_map()
create_forces_and_disable_tech()
WPT.reset_table()
wave_defense_table.math = 8
if not this.train_reveal then
if not this.train_reveal and not this.reveal_normally then
this.revealed_spawn = game.tick + 100
end
local map_gen_settings = {
['seed'] = math_random(1, 1000000),
['seed'] = math_random(10000, 99999),
['water'] = 0.001,
['starting_area'] = 1,
['cliff_settings'] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
@ -305,6 +314,17 @@ function Public.reset_map()
alignment = 'center',
scale_with_zoom = false
}
local surfaces = {
[surface.name] = shape
}
Generate.init({surfaces = surfaces, regen_decoratives = true, tiles_per_tick = 32})
Task.reset_queue()
Task.reset_primitives()
Task.start_queue()
Task.set_queue_speed(10)
this.chunk_load_tick = game.tick + 500
end
local function change_tile(surface, pos, steps)
@ -344,7 +364,7 @@ local function on_player_changed_position(event)
end
::continue::
if
not this.train_reveal or
not this.train_reveal and not this.reveal_normally or
this.players[player.index].start_tick and game.tick - this.players[player.index].start_tick < 6400
then
if position.y < 5 then
@ -385,9 +405,9 @@ local function on_player_joined_game(event)
end
if not this.players[player.index].first_join then
player.print(grandmaster .. ' Greetings, newly joined ' .. player.name .. '!', {r = 1, g = 0.5, b = 0.1})
player.print(grandmaster .. ' Please read the map info.', {r = 1, g = 0.5, b = 0.1})
player.print(grandmaster .. ' Guide the choo through the black mist.', {r = 1, g = 0.5, b = 0.1})
player.print(grandmaster .. ' Greetings, newly joined ' .. player.name .. '!', {r = 0.98, g = 0.66, b = 0.22})
player.print(grandmaster .. ' Please read the map info.', {r = 0.98, g = 0.66, b = 0.22})
player.print(grandmaster .. ' Guide the choo through the black mist.', {r = 0.98, g = 0.66, b = 0.22})
player.print(grandmaster .. ' To disable rainbow mode, type in console: /rainbow_mode', Color.info)
this.players[player.index].first_join = true
end
@ -499,15 +519,15 @@ local function darkness(data)
local rnd = math.random
local this = data.this
local surface = data.surface
if rnd(1, 32) == 1 then
if rnd(1, 24) == 1 then
if not this.freeze_daytime then
return
end
game.print(grandmaster .. ' Sunlight, finally!', {r = 1, g = 0.5, b = 0.1})
game.print(grandmaster .. ' Sunlight, finally!', {r = 0.98, g = 0.66, b = 0.22})
surface.min_brightness = 1
surface.brightness_visual_weights = {1, 0, 0, 0}
surface.daytime = 1
surface.freeze_daytime = true
surface.freeze_daytime = false
surface.solar_power_multiplier = 1
this.freeze_daytime = false
return
@ -515,8 +535,8 @@ local function darkness(data)
if this.freeze_daytime then
return
end
game.print(grandmaster .. ' Darkness has surrounded us!', {r = 1, g = 0.5, b = 0.1})
game.print(grandmaster .. ' Builds some lamps!', {r = 1, g = 0.5, b = 0.1})
game.print(grandmaster .. ' Darkness has surrounded us!', {r = 0.98, g = 0.66, b = 0.22})
game.print(grandmaster .. ' Builds some lamps!', {r = 0.98, g = 0.66, b = 0.22})
surface.min_brightness = 0
surface.brightness_visual_weights = {0.90, 0.90, 0.90}
surface.daytime = 0.42
@ -528,7 +548,7 @@ local function darkness(data)
end
local function transfer_pollution(data)
local surface = data.surface
local surface = data.loco_surface
local this = data.this
if not surface then
return
@ -539,8 +559,8 @@ local function transfer_pollution(data)
end
local tick_minute_functions = {
[300 * 3 + 30 * 1] = darkness,
[300 * 3 + 30 * 0] = transfer_pollution
[300 * 3 + 30 * 6] = darkness,
[300 * 3 + 30 * 6] = transfer_pollution
}
local on_tick = function()
@ -550,13 +570,17 @@ local on_tick = function()
local tick = game.tick
local status = Collapse.start_now()
local key = tick % 3600
local data = {
this = this,
surface = surface
}
local unit_surface = this.locomotive.unit_number
local icw_table = ICW.get_table()
if not this.locomotive.valid then
Entities.loco_died()
end
local data = {
this = this,
surface = surface,
loco_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
}
if status == true then
goto continue
end
@ -594,6 +618,13 @@ local on_tick = function()
end
return
end
if this.chunk_load_tick then
if this.chunk_load_tick < game.tick then
this.chunk_load_tick = nil
Task.set_queue_speed(1)
end
end
end
local on_init = function()
@ -601,7 +632,6 @@ local on_init = function()
global.custom_highscore.description = 'Wagon distance reached:'
game.forces.defenders.share_chart = false
global.rocks_yield_ore_maximum_amount = 500
global.rocks_yield_ore_base_amount = 50
global.rocks_yield_ore_distance_modifier = 0.025
@ -644,6 +674,8 @@ local on_init = function()
Explosives.set_destructible_tile('deepwater-green', 1000)
Explosives.set_destructible_tile('deepwater', 1000)
Explosives.set_destructible_tile('water-shallow', 1000)
Generate.register()
end
Event.on_nth_tick(10, on_tick)

View File

@ -62,10 +62,8 @@ local function ore_yield_amounts()
['tree-04'] = 1,
['tree-05'] = 1,
['tree-06'] = 1,
['tree-06-brown'] = 1,
['tree-07'] = 1,
['tree-08'] = 1,
['tree-08-brown'] = 1,
['tree-08-red'] = 1,
['tree-09'] = 1,
['tree-09-brown'] = 1,
@ -76,7 +74,7 @@ end
local tree_raffle_ores = {}
for _, t in pairs(mining_chances_ores()) do
for x = 1, t.chance, 1 do
for _ = 1, t.chance, 1 do
table.insert(tree_raffle_ores, t.name)
end
end
@ -120,16 +118,30 @@ local function tree_randomness(data)
local entity = data.entity
local player = data.player
local tree
local tree_amount
if not ore_yield_amounts()[entity.name] then
tree = 'wood'
data.tree = tree
tree_amount = 2
goto continue
end
tree = tree_raffle_ores[math.random(1, size_of_ore_raffle)]
data.tree = tree
local tree_amount = get_amount(data)
tree_amount = get_amount(data)
::continue::
local position = {x = entity.position.x, y = entity.position.y}
if tree_amount > max_spill then
if tree == 'tree' then
tree = 'wood'
end
player.surface.spill_item_stack(position, {name = tree, count = max_spill}, true)
tree_amount = tree_amount - max_spill
local inserted_count = player.insert({name = tree, count = tree_amount})

View File

@ -1,8 +1,3 @@
-- unload the normal player list
if package.loaded['comfy_panel.player_list'] then
package.unload = 'comfy_panel.player_list'
end
local Event = require 'utils.event'
local play_time = require 'utils.session_data'
local Tabs = require 'comfy_panel.main'

View File

@ -0,0 +1,89 @@
local Server = require 'utils.server'
local Modifers = require 'player_modifiers'
local WPT = require 'maps.lumberjack.table'
local grandmaster = '[color=blue]Grandmaster:[/color]'
local Public = {}
local function reset_forces(new_surface, old_surface)
for _, f in pairs(game.forces) do
local spawn = {
x = game.forces.player.get_spawn_position(old_surface).x,
y = game.forces.player.get_spawn_position(old_surface).y
}
f.reset()
f.reset_evolution()
f.set_spawn_position(spawn, new_surface)
end
end
local function teleport_players(surface)
game.forces.player.set_spawn_position({0, 21}, surface)
for _, player in pairs(game.connected_players) do
player.teleport(
surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5),
surface
)
end
end
local function equip_players(player_starting_items)
for k, player in pairs(game.connected_players) do
if player.character then
player.character.destroy()
end
player.character = nil
player.set_controller({type = defines.controllers.god})
player.create_character()
for item, amount in pairs(player_starting_items) do
player.insert({name = item, count = amount})
end
Modifers.update_player_modifiers(player)
end
end
function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items)
local this = WPT.get_table()
if not this.soft_reset_counter then
this.soft_reset_counter = 0
end
if not this.original_surface_name then
this.original_surface_name = old_surface.name
end
this.soft_reset_counter = this.soft_reset_counter + 1
local new_surface =
game.create_surface(this.original_surface_name .. '_' .. tostring(this.soft_reset_counter), map_gen_settings)
new_surface.request_to_generate_chunks({0, 0}, 0.5)
new_surface.force_generate_chunk_requests()
reset_forces(new_surface, old_surface)
teleport_players(new_surface)
equip_players(player_starting_items)
game.delete_surface(old_surface)
local message = table.concat({grandmaster .. ' Welcome to ', this.original_surface_name, '!'})
if this.soft_reset_counter > 1 then
message =
table.concat(
{
grandmaster,
' The world has been reshaped, welcome to ',
this.original_surface_name,
' number ',
tostring(this.soft_reset_counter),
'!'
}
)
end
game.print(message, {r = 0.98, g = 0.66, b = 0.22})
Server.to_discord_embed(message)
return new_surface
end
return Public

View File

@ -4,7 +4,8 @@ local Event = require 'utils.event'
local this = {
train_reveal = true,
energy_shared = true
energy_shared = true,
reveal_normally = false
}
local Public = {}
@ -42,6 +43,7 @@ function Public.reset_table()
this.mined_scrap = 0
this.biters_killed = 0
this.locomotive_xp_aura = 40
this.randomness = 0
end
function Public.get_table()
@ -52,6 +54,7 @@ function Public.init(args)
if args then
this.train_reveal = args.train_reveal
this.energy_shared = args.energy_shared
this.reveal_normally = args.reveal_normally
else
return error('Not a valid init argument', 2)
end

View File

@ -10,6 +10,7 @@ local WPT = require 'maps.lumberjack.table'
local shapes = require 'tools.shapes'
local Loot = require 'maps.lumberjack.loot'
local get_noise = require 'utils.get_noise'
local simplex_noise = require 'utils.simplex_noise'.d2
local Public = {}
@ -88,27 +89,59 @@ local scrap_buildings = {
'steam-turbine',
'steam-engine'
}
local decos_inside_forest = {'brown-asterisk', 'brown-asterisk', 'brown-carpet-grass', 'brown-hairy-grass'}
local spawner_raffle = {'biter-spawner', 'biter-spawner', 'biter-spawner', 'spitter-spawner'}
local trees = {'dead-grey-trunk', 'dead-grey-trunk', 'dry-tree'}
local trees_terrain = {
'tree-01',
'tree-01',
'tree-02',
'tree-02-red',
'tree-02-red',
'tree-03',
'tree-03',
'tree-04',
'tree-04',
'tree-05',
'tree-05',
'tree-06',
'tree-06-brown',
'tree-06',
'tree-07',
'tree-07',
'tree-08',
'tree-08-brown',
'tree-08',
'tree-08-red',
'tree-08-red',
'tree-09',
'tree-09-brown',
'tree-09-red'
}
local size_of_terrain = #trees_terrain
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}
}
}
local function get_forest_noise(name, pos, seed)
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
end
local function place_wagon(data)
local surface = data.surface
local left_top = data.left_top
@ -181,7 +214,15 @@ local function place_random_scrap_entity(surface, position)
return
end
if r < 75 then
local e = surface.create_entity({name = 'gun-turret', position = position, force = 'lumber_defense'})
local e =
surface.create_entity(
{
name = 'gun-turret',
position = position,
force = 'lumber_defense',
destructible = true
}
)
if math_abs(position.y) < Public.level_depth * 2.5 then
e.insert({name = 'piercing-rounds-magazine', count = math_random(64, 128)})
else
@ -223,7 +264,66 @@ local function get_oil_amount(p)
return (math_abs(p.y) * 200 + 10000) * math_random(75, 125) * 0.01
end
local function forest_look(data)
local p = data.p
local surface = data.surface
local seed = data.seed
local entities = data.entities
local noise_forest_location = get_forest_noise('forest_location', p, seed)
if noise_forest_location > 0.095 then
if noise_forest_location > 0.6 then
if math_random(1, 100) > 42 then
entities[#entities + 1] = {name = 'tree-08-brown', position = p}
end
else
if math_random(1, 100) > 42 then
entities[#entities + 1] = {name = 'tree-01', position = p}
end
end
surface.create_decoratives(
{
check_collision = false,
decoratives = {
{
name = decos_inside_forest[math_random(1, #decos_inside_forest)],
position = p,
amount = math_random(1, 2)
}
}
}
)
return
end
if noise_forest_location < -0.095 then
if noise_forest_location < -0.6 then
if math_random(1, 100) > 42 then
entities[#entities + 1] = {name = 'tree-04', position = p}
end
else
if math_random(1, 100) > 42 then
entities[#entities + 1] = {name = 'tree-02-red', position = p}
end
end
surface.create_decoratives(
{
check_collision = false,
decoratives = {
{
name = decos_inside_forest[math_random(1, #decos_inside_forest)],
position = p,
amount = math_random(1, 2)
}
}
}
)
return
end
end
local function wall(data)
local this = data.this
local surface = data.surface
local left_top = data.left_top
local seed = data.seed
@ -242,13 +342,27 @@ local function wall(data)
else
surface.set_tiles({{name = 'dirt-7', position = p}})
if math_random(1, 5) ~= 1 then
surface.create_entity({name = trees_terrain[math_random(1, #trees_terrain)], position = p})
surface.create_entity(
{
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
)
end
end
else
surface.set_tiles({{name = 'dirt-7', position = p}})
if surface.can_place_entity({name = 'stone-wall', position = p, force = 'lumber_defense'}) then
if
surface.can_place_entity(
{
name = 'stone-wall',
position = p,
force = 'lumber_defense',
destructible = true
}
)
then
if math_random(1, 512) == 1 and y > 3 and y < 28 then
if math_random(1, 2) == 1 then
Loot.add(surface, p, 'wooden-chest')
@ -261,7 +375,12 @@ local function wall(data)
if math_random(1, y + 1) == 1 then
local e =
surface.create_entity(
{name = 'stone-wall', position = p, force = 'lumber_defense'}
{
name = 'stone-wall',
position = p,
force = 'lumber_defense',
destructible = true
}
)
e.minable = false
end
@ -269,7 +388,12 @@ local function wall(data)
if math_random(1, 32 - y) == 1 then
local e =
surface.create_entity(
{name = 'stone-wall', position = p, force = 'lumber_defense'}
{
name = 'stone-wall',
position = p,
force = 'lumber_defense',
destructible = true
}
)
e.minable = false
end
@ -283,17 +407,48 @@ local function wall(data)
end
if math_random(1, 16) == 1 then
if surface.can_place_entity({name = 'small-worm-turret', position = p, force = 'lumber_defense'}) then
if
surface.can_place_entity(
{
name = 'small-worm-turret',
position = p,
force = 'lumber_defense',
destructible = true
}
)
then
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
surface.create_entity(
{name = Biters.wave_defense_roll_worm_name(), position = p, force = 'lumber_defense'}
{
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense',
destructible = true
}
)
end
end
if math_random(1, 32) == 1 then
if surface.can_place_entity({name = 'gun-turret', position = p, force = 'lumber_defense'}) then
local e = surface.create_entity({name = 'gun-turret', position = p, force = 'lumber_defense'})
if
surface.can_place_entity(
{
name = 'gun-turret',
position = p,
force = 'lumber_defense',
destructible = true
}
)
then
local e =
surface.create_entity(
{
name = 'gun-turret',
position = p,
force = 'lumber_defense',
destructible = true
}
)
if math_abs(p.y) < Public.level_depth * 2.5 then
e.insert({name = 'piercing-rounds-magazine', count = math_random(64, 128)})
else
@ -307,6 +462,7 @@ local function wall(data)
end
local function process_level_9_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -322,7 +478,17 @@ local function process_level_9_position(data)
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
local no_rocks_2 = get_noise('no_rocks_2', p, seed)
if math_random(1, 2) == 1 and no_rocks_2 > -0.5 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
forest_look(data)
end
if math_random(1, 1024) == 1 then
treasure[#treasure + 1] = p
@ -333,7 +499,8 @@ local function process_level_9_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
return
@ -367,6 +534,7 @@ local function process_level_9_position(data)
end
local function process_level_8_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -391,12 +559,20 @@ local function process_level_8_position(data)
if scrapyard < -0.25 or scrapyard > 0.25 then
if math_random(1, 256) == 1 then
entities[#entities + 1] = {name = 'gun-turret', position = p, force = 'lumber_defense'}
entities[#entities + 1] = {
name = 'gun-turret',
position = p,
force = 'lumber_defense',
destructible = true
}
end
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if scrapyard < -0.55 or scrapyard > 0.55 then
if math_random(1, 2) == 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
end
return
end
@ -407,23 +583,33 @@ local function process_level_8_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
if math_random(1, 96) == 1 then
entities[#entities + 1] = {
name = scrap_entities[math_random(1, scrap_entities_index)],
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
if math_random(1, 5) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
end
if math_random(1, 256) == 1 then
create_inner_content(surface, p, scrapyard)
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'lumber_defense'}
entities[#entities + 1] = {
name = 'land-mine',
position = p,
force = 'lumber_defense',
destructible = true
}
end
return
end
@ -442,10 +628,14 @@ local function process_level_8_position(data)
local large_caves = get_noise('large_caves', p, seed)
if scrapyard > -0.15 and scrapyard < 0.15 then
if math_floor(large_caves * 10) % 4 < 3 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if math_random(1, 2) == 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
forest_look(data)
return
end
end
@ -456,11 +646,17 @@ local function process_level_8_position(data)
tiles[#tiles + 1] = {name = 'stone-path', position = p}
if math_random(1, 256) == 1 then
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'lumber_defense'}
entities[#entities + 1] = {
name = 'land-mine',
position = p,
force = 'lumber_defense',
destructible = true
}
end
end
local function process_level_7_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -555,16 +751,21 @@ local function process_level_7_position(data)
end
end
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if math_random(1, 100) > 15 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
end
if math_random(1, 256) == 1 then
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
forest_look(data)
end
local function process_level_6_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -582,7 +783,10 @@ local function process_level_6_position(data)
treasure[#treasure + 1] = p
end
if math_random(1, 3) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
end
return
end
@ -598,7 +802,8 @@ local function process_level_6_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
return
@ -617,20 +822,23 @@ local function process_level_6_position(data)
return
end
if noise_cave_ponds > 0.25 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
if math_random(1, 512) == 1 then
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
if math_random(1, 2) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
return
forest_look(data)
end
end
end
local function process_level_5_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -648,7 +856,10 @@ local function process_level_5_position(data)
treasure[#treasure + 1] = p
end
if math_random(1, 3) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
end
return
end
@ -664,7 +875,8 @@ local function process_level_5_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
return
@ -683,20 +895,23 @@ local function process_level_5_position(data)
return
end
if noise_cave_ponds > 0.25 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
if math_random(1, 512) == 1 then
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
if math_random(1, 2) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
return
forest_look(data)
end
end
end
local function process_level_4_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -735,7 +950,8 @@ local function process_level_4_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
if math_random(1, 1024) == 1 then
@ -747,7 +963,10 @@ local function process_level_4_position(data)
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
if math_random(1, 3) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
end
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
@ -771,7 +990,10 @@ local function process_level_4_position(data)
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = colors[math_random(1, #colors)].. "-refined-concrete", position = p}
if math_random(1, 5) > 1 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
end
if math_random(1, 1024) == 1 then
treasure[#treasure + 1] = p
@ -794,16 +1016,19 @@ local function process_level_4_position(data)
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
if math_random(1, 100) > 30 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
return
forest_look(data)
end
end
local function process_level_3_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -822,7 +1047,10 @@ local function process_level_3_position(data)
if noise_cave_ponds > -0.79 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
entities[#entities + 1] = {
name = trees_terrain[math_floor(this.randomness * 0.5) % size_of_terrain + 1],
position = p
}
else
tiles[#tiles + 1] = {name = 'grass-' .. math_floor(noise_cave_ponds * 32) % 3 + 1, position = p}
if math_random(1, 32) == 1 then
@ -900,7 +1128,8 @@ local function process_level_3_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
if math_random(1, 512) == 1 then
@ -927,19 +1156,19 @@ local function process_level_3_position(data)
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
if math_random(1, 2048) == 1 then
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
if math_random(1, 100) > 30 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
end
return
forest_look(data)
end
end
local function process_level_2_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -1020,7 +1249,8 @@ local function process_level_2_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
if math_random(1, 64) == 1 then
@ -1044,19 +1274,19 @@ local function process_level_2_position(data)
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
if math_random(1, 2048) == 1 then
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
if math_random(1, 100) > 30 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
end
return
forest_look(data)
end
end
local function process_level_1_position(data)
local this = data.this
local surface = data.surface
local p = data.p
local seed = data.seed
@ -1137,7 +1367,8 @@ local function process_level_1_position(data)
entities[#entities + 1] = {
name = Biters.wave_defense_roll_worm_name(),
position = p,
force = 'lumber_defense'
force = 'lumber_defense',
destructible = true
}
end
if math_random(1, 1024) == 1 then
@ -1153,6 +1384,7 @@ local function process_level_1_position(data)
--Main Terrain
local no_rocks_2 = get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.70 or no_rocks_2 < -0.70 then
--tiles[#tiles + 1] = {name = more_colors[math_random(1, #more_colors)].. "-refined-concrete", position = p}
tiles[#tiles + 1] = {name = 'dirt-' .. math_floor(no_rocks_2 * 8) % 2 + 5, position = p}
@ -1168,16 +1400,14 @@ local function process_level_1_position(data)
if math_random(1, 2048) == 1 then
treasure[#treasure + 1] = p
end
--tiles[#tiles + 1] = {name = colors[math_random(1, #colors)].. "-refined-concrete", position = p}
--tiles[#tiles + 1] = {name = 'dirt-7', position = p}
tiles[#tiles + 1] = {name = 'stone-path', position = p}
tiles[#tiles + 1] = {name = 'grass-1', position = p}
if math_random(1, 4028) == 1 then
place_random_scrap_entity(surface, p)
end
if math_random(1, 100) > 30 then
entities[#entities + 1] = {name = trees_terrain[math_random(1, #trees_terrain)], position = p}
end
forest_look(data)
end
Public.levels = {
@ -1193,6 +1423,66 @@ Public.levels = {
--process_level_10_position,
}
local entity_functions = {
['turret'] = function(surface, entity)
surface.create_entity(entity)
end,
['simple-entity'] = function(surface, entity)
surface.create_entity(entity)
end,
['ammo-turret'] = function(surface, entity)
local e = surface.create_entity(entity)
e.insert({name = 'uranium-rounds-magazine', count = math_random(16, 64)})
end,
['container'] = function(surface, entity)
Loot.add(surface, entity.position, entity.name)
end
}
local function is_out_of_map(p)
if p.x < 196 and p.x >= -196 then
return
end
if p.y * 0.5 >= math_abs(p.x) then
return
end
if p.y * -0.5 > math_abs(p.x) then
return
end
return true
end
local function process_bits(_, _, data)
local surface = data.surface
local left_top_y = data.area.left_top.y
local seed = data.seed
local tiles = data.tiles
local entities = data.entities
local markets = data.markets
local treasure = data.treasure
local index = math_floor((math_abs(left_top_y / Public.level_depth)) % 11) + 1
local process_level = Public.levels[index]
if not process_level then
process_level = Public.levels[#Public.levels]
end
local pos = {x = data.x, y = data.y}
local d = {
tiles = tiles,
entities = entities,
markets = markets,
treasure = treasure,
p = pos,
surface = surface,
seed = seed
}
if not is_out_of_map(pos) then
process_level(d)
end
end
function Public.reveal_train(data)
local position = data.position
local surface = data.surface
@ -1221,13 +1511,7 @@ function Public.reveal_train(data)
if #data.tiles > 0 then
surface.set_tiles(data.tiles, true)
end
for _, entity in pairs(data.entities) do
if surface.can_place_entity(entity) and entity == 'biter-spawner' or entity == 'spitter-spawner' then
surface.create_entity(entity)
else
surface.create_entity(entity)
end
end
if #data.markets > 0 then
local pos = data.markets[math_random(1, #data.markets)]
if
@ -1245,6 +1529,16 @@ function Public.reveal_train(data)
local name = 'steel-chest'
Loot.add(surface, p, name)
end
for _, entity in pairs(data.entities) do
if entity_functions[game.entity_prototypes[entity.name].type] then
entity_functions[game.entity_prototypes[entity.name].type](surface, entity)
else
if surface.can_place_entity(entity) then
surface.create_entity(entity)
end
end
end
end
function Public.reveal_normally(data)
@ -1267,13 +1561,7 @@ function Public.reveal_normally(data)
if #data.tiles > 0 then
surface.set_tiles(data.tiles, true)
end
for _, entity in pairs(data.entities) do
if surface.can_place_entity(entity) and entity == 'biter-spawner' or entity == 'spitter-spawner' then
surface.create_entity(entity)
else
surface.create_entity(entity)
end
end
if #data.markets > 0 then
local pos = data.markets[math_random(1, #data.markets)]
if
@ -1291,6 +1579,15 @@ function Public.reveal_normally(data)
local name = 'steel-chest'
Loot.add(surface, p, name)
end
for _, entity in pairs(data.entities) do
if entity_functions[game.entity_prototypes[entity.name].type] then
entity_functions[game.entity_prototypes[entity.name].type](surface, entity)
else
if surface.can_place_entity(entity) then
surface.create_entity(entity)
end
end
end
end
function Public.reveal_player(player)
@ -1306,7 +1603,8 @@ function Public.reveal_player(player)
tiles = {},
entities = {},
markets = {},
treasure = {}
treasure = {},
this = this
}
local level_index = math_floor((math_abs(position.y / Public.level_depth)) % 9) + 1
@ -1325,13 +1623,7 @@ function Public.reveal_player(player)
if #data.tiles > 0 then
surface.set_tiles(data.tiles, true)
end
for _, entity in pairs(data.entities) do
if surface.can_place_entity(entity) and entity == 'biter-spawner' or entity == 'spitter-spawner' then
surface.create_entity(entity)
else
surface.create_entity(entity)
end
end
if #data.markets > 0 then
local pos = data.markets[math_random(1, #data.markets)]
if
@ -1349,19 +1641,15 @@ function Public.reveal_player(player)
local name = 'steel-chest'
Loot.add(surface, p, name)
end
end
local function is_out_of_map(p)
if p.x < 196 and p.x >= -196 then
return
for _, entity in pairs(data.entities) do
if entity_functions[game.entity_prototypes[entity.name].type] then
entity_functions[game.entity_prototypes[entity.name].type](surface, entity)
else
if surface.can_place_entity(entity) then
surface.create_entity(entity)
end
end
end
if p.y * 0.5 >= math_abs(p.x) then
return
end
if p.y * -0.5 > math_abs(p.x) then
return
end
return true
end
local function border_chunk(data)
@ -1559,7 +1847,7 @@ local function on_chunk_generated(event)
game.forces.player.chart(surface, {{left_top.x, left_top.y}, {left_top.x + 31, left_top.y + 31}})
end
if not this.train_reveal then
if not this.train_reveal and not this.reveal_normally then
if this.revealed_spawn > game.tick then
Public.reveal_train(data)
end
@ -1581,23 +1869,60 @@ local function on_chunk_generated(event)
if left_top.y > 210 then
biter_chunk(data)
end
if left_top.y >= 10 then
if left_top.y >= 0 then
border_chunk(data)
end
if left_top.y < 0 and left_top.y > -50 then
Public.reveal_normally(data)
end
if left_top.y < -50 then
process(data)
if not this.reveal_normally then
process(data)
end
if math_random(1, chance_for_wagon_spawn) == 1 then
place_wagon(data)
end
end
local p = this.locomotive.position
for _, entity in pairs(
surface.find_entities_filtered({area = {{p.x - 10, p.y - 10}, {p.x + 10, p.y + 10}}, type = 'simple-entity'})
) do
entity.destroy()
end
out_of_map_area(data)
end
function Public.heavy_functions(x, y, data)
local this = WPT.get_table()
local area = data.area
data.seed = data.surface.map_gen_settings.seed
local top_y = area.left_top.y
local top_x = area.left_top.x
if top_x >= Public.level_depth * 0.5 then
return
end
if top_x < Public.level_depth * -0.5 then
return
end
if top_y > 268 then
return
end
if top_y % Public.level_depth == 0 and top_y < 0 then
return
end
if this.reveal_normally then
if top_y < 0 then
process_bits(x, y, data)
end
elseif top_y < 0 and top_y > -50 then
process_bits(x, y, data)
end
end
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
return Public

View File

@ -149,6 +149,29 @@ function Task.set_queue_speed(value)
primitives.task_queue_speed = value
end
function Task.start_queue()
if task_queue._tail == 0 then
task_queue._tail = 1
end
end
function Task.reset_queue()
if #task_queue > 50 then
task_queue = {
_head = 1,
_tail = 0
}
end
end
function Task.reset_primitives()
primitives = {
next_async_callback_time = -1,
total_task_weight = 0,
task_queue_speed = 1,
task_per_tick = 1
}
end
Event.add(defines.events.on_tick, on_tick)
return Task