mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
Fix restart bottlenecks (#1428)
This commit is contained in:
parent
23dd8f5bf7
commit
eefc8da5f9
@ -2,13 +2,12 @@ local Color = require 'resources.color_presets'
|
||||
local EnemyTurret = require 'features.enemy_turret'
|
||||
local math = require 'utils.math'
|
||||
local PriceRaffle = require 'features.price_raffle'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local Table = require 'utils.table'
|
||||
local Toast = require 'features.gui.toast'
|
||||
local Token = require 'utils.token'
|
||||
local Debug = require 'map_gen.maps.frontier.shared.debug'
|
||||
local Public = require 'map_gen.maps.frontier.shared.core'
|
||||
local this = Public.get()
|
||||
|
||||
local register_on_entity_destroyed = script.register_on_entity_destroyed
|
||||
local math_ceil = math.ceil
|
||||
local math_clamp = math.clamp
|
||||
@ -53,7 +52,7 @@ Enemy.commands = {
|
||||
distraction = defines.distraction.by_enemy
|
||||
}
|
||||
unit_group.start_moving()
|
||||
if this._DEBUG_AI then
|
||||
if Public.get()._DEBUG_AI then
|
||||
Debug.print_admins(string.format('AI [id=%d] | cmd: MOVE [gps=%.2f,%.2f,%s]', unit_group.group_number, position.x, position.y, unit_group.surface.name), Color.dark_gray)
|
||||
end
|
||||
end,
|
||||
@ -72,7 +71,7 @@ Enemy.commands = {
|
||||
distraction = defines.distraction.by_enemy
|
||||
}
|
||||
unit_group.start_moving()
|
||||
if this._DEBUG_AI then
|
||||
if Public.get()._DEBUG_AI then
|
||||
Debug.print_admins(string.format('AI [id=%d] | cmd: SCOUT [gps=%.2f,%.2f,%s]', unit_group.group_number, position.x, position.y, unit_group.surface.name), Color.dark_gray)
|
||||
end
|
||||
end,
|
||||
@ -89,7 +88,7 @@ Enemy.commands = {
|
||||
target = target,
|
||||
distraction = defines.distraction.by_damage
|
||||
}
|
||||
if this._DEBUG_AI then
|
||||
if Public.get()._DEBUG_AI then
|
||||
Debug.print_admins(string.format('AI [id=%d] | cmd: ATTACK [gps=%.2f,%.2f,%s] (type = %s)', unit_group.group_number, target.position.x, target.position.y, unit_group.surface.name, target.type), Color.dark_gray)
|
||||
end
|
||||
end
|
||||
@ -104,6 +103,7 @@ Enemy.stages = {
|
||||
}
|
||||
|
||||
function Enemy.ai_take_control(unit_group)
|
||||
local this = Public.get()
|
||||
if not this.unit_groups[unit_group.group_number] then
|
||||
this.unit_groups[unit_group.group_number] = {
|
||||
unit_group = unit_group
|
||||
@ -130,6 +130,7 @@ function Enemy.ai_processor(unit_group, result)
|
||||
return
|
||||
end
|
||||
|
||||
local this = Public.get()
|
||||
local data = this.unit_groups[unit_group.group_number]
|
||||
if not data then
|
||||
return
|
||||
@ -186,10 +187,11 @@ function Enemy.ai_processor(unit_group, result)
|
||||
end
|
||||
|
||||
function Enemy.spawn_enemy_wave(position)
|
||||
local surface = RS.get_surface()
|
||||
local surface = Public.surface()
|
||||
local find_position = surface.find_non_colliding_position
|
||||
local spawn = surface.create_entity
|
||||
local current_tick = game.tick
|
||||
local this = Public.get()
|
||||
|
||||
local unit_group = surface.create_unit_group { position = position, force = 'enemy' }
|
||||
|
||||
@ -239,6 +241,7 @@ Enemy.spawn_enemy_wave_token = Token.register(Enemy.spawn_enemy_wave)
|
||||
|
||||
function Enemy.on_enemy_died(entity)
|
||||
local uid = entity.unit_number
|
||||
local this = Public.get()
|
||||
local data = this.invincible[uid]
|
||||
if not data then
|
||||
return
|
||||
@ -270,7 +273,7 @@ end
|
||||
|
||||
function Enemy.on_spawner_died(event)
|
||||
local entity = event.entity
|
||||
|
||||
local this = Public.get()
|
||||
local budget = this.loot_budget + entity.position.x * 2.75
|
||||
budget = budget * math_random(25, 175) * 0.01
|
||||
|
||||
@ -300,6 +303,7 @@ function Enemy.on_spawner_died(event)
|
||||
end
|
||||
|
||||
function Enemy.spawn_turret_outpost(position)
|
||||
local this = Public.get()
|
||||
if position.x < this.right_boundary * 32 + this.wall_width then
|
||||
return
|
||||
end
|
||||
@ -309,7 +313,7 @@ function Enemy.spawn_turret_outpost(position)
|
||||
return
|
||||
end
|
||||
|
||||
local surface = RS.get_surface()
|
||||
local surface = Public.surface()
|
||||
|
||||
if Public.ESCAPE_PLAYER then
|
||||
for _, player in pairs(surface.find_entities_filtered{type = 'character'}) do
|
||||
@ -361,19 +365,19 @@ function Enemy.start_tracking(entity)
|
||||
end
|
||||
|
||||
register_on_entity_destroyed(entity)
|
||||
this.target_entities[entity.unit_number] = entity
|
||||
Public.get().target_entities[entity.unit_number] = entity
|
||||
end
|
||||
|
||||
function Enemy.stop_tracking(entity)
|
||||
this.target_entities[entity.unit_number] = nil
|
||||
Public.get().target_entities[entity.unit_number] = nil
|
||||
end
|
||||
|
||||
function Enemy.get_target()
|
||||
return Table.get_random_dictionary_entry(this.target_entities, false)
|
||||
return Table.get_random_dictionary_entry(Public.get().target_entities, false)
|
||||
end
|
||||
|
||||
function Enemy.nuclear_explosion(position)
|
||||
RS.get_surface().create_entity {
|
||||
Public.surface().create_entity {
|
||||
name = 'atomic-rocket',
|
||||
position = position,
|
||||
force = 'enemy',
|
||||
|
@ -1,6 +1,5 @@
|
||||
local Config = global.config
|
||||
local Public = require 'map_gen.maps.frontier.shared.core'
|
||||
local this = Public.get()
|
||||
|
||||
local Lobby = {}
|
||||
|
||||
@ -40,7 +39,7 @@ function Lobby.teleport_from(player, destination)
|
||||
player.insert(stack)
|
||||
end
|
||||
end
|
||||
local surface = this.surface
|
||||
local surface = Public.surface()
|
||||
local position = surface.find_non_colliding_position('character', destination or {0, 0}, 0, 0.2)
|
||||
player.teleport(position, surface, true)
|
||||
end
|
||||
@ -61,18 +60,34 @@ function Lobby.on_chunk_generated(event)
|
||||
local area = event.area
|
||||
local surface = event.surface
|
||||
|
||||
if surface.name ~= Lobby.name then
|
||||
return
|
||||
end
|
||||
|
||||
surface.build_checkerboard(area)
|
||||
for _, e in pairs(surface.find_entities_filtered{ area = area }) do
|
||||
if e.type ~= 'character' then
|
||||
e.destroy()
|
||||
end
|
||||
end
|
||||
|
||||
local lt = area.left_top
|
||||
local w, h = Lobby.mgs.width / 2, Lobby.mgs.height / 2
|
||||
local tiles = {}
|
||||
for x = lt.x, lt.x + 31 do
|
||||
for y = lt.y, lt.y + 31 do
|
||||
if x > w or x < -w or y > h or y < -h then
|
||||
tiles[#tiles +1] = {name = 'out-of-map', position = { x = x, y = y }}
|
||||
end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, false)
|
||||
end
|
||||
|
||||
function Lobby.on_init()
|
||||
local surface = Lobby.get_surface()
|
||||
surface.map_gen_settings = Lobby.mgs
|
||||
Lobby.on_chunk_generated({ area = {left_top = {-64, -64}, right_bottom = {64, 64}}, surface = surface })
|
||||
Lobby.on_chunk_generated({ area = {left_top = { x = -Lobby.mgs.width, y = -Lobby.mgs.height }, right_bottom = { x = Lobby.mgs.width, y = Lobby.mgs.height }}, surface = surface })
|
||||
end
|
||||
|
||||
return Lobby
|
||||
|
@ -1,9 +1,7 @@
|
||||
local math = require 'utils.math'
|
||||
local PriceRaffle = require 'features.price_raffle'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local Table = require 'utils.table'
|
||||
local Public = require 'map_gen.maps.frontier.shared.core'
|
||||
local this = Public.get()
|
||||
local math_ceil = math.ceil
|
||||
local math_clamp = math.clamp
|
||||
local math_min = math.min
|
||||
@ -17,6 +15,7 @@ Market.cheap_items = {}
|
||||
Market.expensive_items = {}
|
||||
|
||||
do
|
||||
local this = Public.get()
|
||||
local market_items = PriceRaffle.get_items_worth()
|
||||
for k, _ in pairs(this.banned_items) do
|
||||
market_items[k] = nil
|
||||
@ -38,6 +37,7 @@ do
|
||||
end
|
||||
|
||||
function Market.spawn_exchange_market(position)
|
||||
local this = Public.get()
|
||||
if position.x < this.left_boundary * 32 + this.wall_width then
|
||||
return
|
||||
end
|
||||
@ -46,7 +46,7 @@ function Market.spawn_exchange_market(position)
|
||||
return
|
||||
end
|
||||
|
||||
local surface = RS.get_surface()
|
||||
local surface = Public.surface()
|
||||
local market = surface.create_entity {
|
||||
name = 'market',
|
||||
position = position,
|
||||
|
@ -1,6 +1,5 @@
|
||||
local Color = require 'resources.color_presets'
|
||||
local math = require 'utils.math'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local Sounds = require 'utils.sounds'
|
||||
local Token = require 'utils.token'
|
||||
@ -8,7 +7,6 @@ local Task = require 'utils.task'
|
||||
local Public = require 'map_gen.maps.frontier.shared.core'
|
||||
local Enemy = require 'map_gen.maps.frontier.modules.enemy'
|
||||
local Terrain = require 'map_gen.maps.frontier.modules.terrain'
|
||||
local this = Public.get()
|
||||
local math_abs = math.abs
|
||||
local math_ceil = math.ceil
|
||||
local math_clamp = math.clamp
|
||||
@ -110,7 +108,8 @@ end
|
||||
RocketSilo.bard_message_token = Token.register(RocketSilo.bard_message)
|
||||
|
||||
function RocketSilo.move_silo(position)
|
||||
local surface = RS.get_surface()
|
||||
local this = Public.get()
|
||||
local surface = Public.surface()
|
||||
local old_silo = this.rocket_silo
|
||||
local old_position = old_silo and old_silo.position or { x = 0, y = 0 }
|
||||
local new_silo
|
||||
@ -198,6 +197,7 @@ end
|
||||
RocketSilo.move_silo_token = Token.register(RocketSilo.move_silo)
|
||||
|
||||
function RocketSilo.compute_silo_coordinates(step)
|
||||
local this = Public.get()
|
||||
this.move_buffer = this.move_buffer + (step or 0)
|
||||
|
||||
if this.x + this.move_buffer > this.max_distance then
|
||||
@ -237,20 +237,16 @@ function RocketSilo.compute_silo_coordinates(step)
|
||||
end
|
||||
|
||||
function RocketSilo.reveal_spawn_area()
|
||||
local surface = RS.get_surface()
|
||||
local far_left, far_right = this.kraken_distance + this.left_boundary * 32 + 1, this.right_boundary * 32 + this.wall_width
|
||||
surface.request_to_generate_chunks({ x = 0, y = 0 }, math.ceil(math_max(far_left, far_right, this.height * 32) / 32))
|
||||
local surface = Public.surface()
|
||||
surface.request_to_generate_chunks({ x = 0, y = 0 }, 1)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
RocketSilo.compute_silo_coordinates(this.silo_starting_x + math_random(100))
|
||||
RocketSilo.compute_silo_coordinates(Public.get().silo_starting_x + math_random(100))
|
||||
RocketSilo.move_silo()
|
||||
Terrain.create_wall(this.right_boundary * 32, this.wall_width)
|
||||
|
||||
game.forces.player.chart(surface, { { -far_left - 32, -this.height * 16 }, { far_right + 32, this.height * 16 } })
|
||||
end
|
||||
|
||||
function RocketSilo.set_game_state(player_won)
|
||||
this.scenario_finished = true
|
||||
Public.get().scenario_finished = true
|
||||
game.set_game_state {
|
||||
game_finished = true,
|
||||
player_won = player_won or false,
|
||||
@ -280,6 +276,7 @@ function RocketSilo.on_game_started()
|
||||
ms.pollution.diffusion_ratio = 0.04 -- 0.02
|
||||
ms.pollution.enemy_attack_pollution_consumption_modifier = 0.5 --1
|
||||
|
||||
local this = Public.get()
|
||||
this.rounds = this.rounds + 1
|
||||
this.kraken_contributors = {}
|
||||
this.death_contributions = {}
|
||||
@ -321,10 +318,10 @@ RocketSilo.restart_game_token = Token.register(function()
|
||||
end)
|
||||
|
||||
function RocketSilo.on_game_finished()
|
||||
this.lobby_enabled = true
|
||||
Public.get().lobby_enabled = true
|
||||
game.print({'frontier.map_setup'})
|
||||
|
||||
local surface = RS.get_surface()
|
||||
local surface = Public.surface()
|
||||
surface.clear(true)
|
||||
local mgs = table.deepcopy(surface.map_gen_settings)
|
||||
mgs.seed = mgs.seed + 1e4
|
||||
@ -341,6 +338,7 @@ function RocketSilo.on_rocket_launched(event)
|
||||
return
|
||||
end
|
||||
|
||||
local this = Public.get()
|
||||
if this.scenario_finished then
|
||||
return
|
||||
end
|
||||
|
@ -2,14 +2,12 @@ local Color = require 'resources.color_presets'
|
||||
local Gui = require 'utils.gui'
|
||||
local math = require 'utils.math'
|
||||
local PriceRaffle = require 'features.price_raffle'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local Table = require 'utils.table'
|
||||
local Toast = require 'features.gui.toast'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local Public = require 'map_gen.maps.frontier.shared.core'
|
||||
local this = Public.get()
|
||||
local math_floor = math.floor
|
||||
local math_random = math.random
|
||||
|
||||
@ -57,9 +55,9 @@ SpawnShop.upgrades = {
|
||||
}
|
||||
|
||||
function SpawnShop.add_render()
|
||||
local e = this.spawn_shop
|
||||
local e = Public.get().spawn_shop
|
||||
rendering.draw_sprite {
|
||||
sprite = 'achievement/lazy-bastard',--'file/graphics/neon_lightning.png', --TODO: add compatibility
|
||||
sprite = script.active_mods['redmew-data'] and 'neon-lightning' or 'achievement/lazy-bastard',
|
||||
x_scale = 0.8,
|
||||
y_scale = 0.8,
|
||||
target = e,
|
||||
@ -75,7 +73,7 @@ end
|
||||
SpawnShop.add_render_token = Token.register(SpawnShop.add_render)
|
||||
|
||||
function SpawnShop.on_game_started()
|
||||
local surface = RS.get_surface()
|
||||
local surface = Public.surface()
|
||||
local position = surface.find_non_colliding_position('market', {0, 0}, 32, 0.5, true)
|
||||
local shop = surface.create_entity {
|
||||
name = 'market',
|
||||
@ -86,7 +84,7 @@ function SpawnShop.on_game_started()
|
||||
raise_built = false,
|
||||
}
|
||||
shop.minable = false
|
||||
this.spawn_shop = shop
|
||||
Public.get().spawn_shop = shop
|
||||
Task.set_timeout(1, SpawnShop.add_render_token)
|
||||
SpawnShop.refresh_all_prices(false)
|
||||
end
|
||||
@ -98,6 +96,8 @@ function SpawnShop.draw_gui(player)
|
||||
return
|
||||
end
|
||||
|
||||
local this = Public.get()
|
||||
|
||||
frame = player.gui.screen.add { type = 'frame', name = SpawnShop.main_frame_name, direction = 'vertical' }
|
||||
Gui.set_style(frame, {
|
||||
horizontally_stretchable = true,
|
||||
@ -223,7 +223,7 @@ function SpawnShop.destroy_gui(player)
|
||||
local frame = player.gui.screen[SpawnShop.main_frame_name]
|
||||
if frame then
|
||||
frame.destroy()
|
||||
this.spawn_shop_players_in_gui_view[player.index] = nil
|
||||
Public.get().spawn_shop_players_in_gui_view[player.index] = nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -247,6 +247,7 @@ function SpawnShop.refresh_price(id)
|
||||
return
|
||||
end
|
||||
|
||||
local this = Public.get()
|
||||
local nominal_cost = math_floor(Public.VALUE_7_PACKS * Public.PROD_PENALTY * upgrade.packs)
|
||||
local item_stacks = PriceRaffle.roll(nominal_cost, 5, this.banned_items)
|
||||
if this._DEBUG_SHOP then
|
||||
@ -278,6 +279,7 @@ function SpawnShop.refresh_all_prices(by_request)
|
||||
end
|
||||
|
||||
function SpawnShop.earn_coin()
|
||||
local this = Public.get()
|
||||
this.spawn_shop_funds = this.spawn_shop_funds + 1
|
||||
ScoreTracker.change_for_global(Public.scores.shop_funds.name, 1)
|
||||
Toast.toast_all_players(20, {'frontier.earn_coin'})
|
||||
@ -288,7 +290,7 @@ function SpawnShop.can_purchase(player, id)
|
||||
return false
|
||||
end
|
||||
|
||||
local data = this.spawn_shop_upgrades[id]
|
||||
local data = Public.get().spawn_shop_upgrades[id]
|
||||
if not (data and data.price) then
|
||||
return false
|
||||
end
|
||||
@ -329,7 +331,7 @@ function SpawnShop.on_player_purchase(player, id)
|
||||
return
|
||||
end
|
||||
|
||||
local data = this.spawn_shop_upgrades[id]
|
||||
local data = Public.get().spawn_shop_upgrades[id]
|
||||
if not (data and data.price) then
|
||||
return
|
||||
end
|
||||
@ -352,6 +354,7 @@ function SpawnShop.on_player_purchase(player, id)
|
||||
end
|
||||
|
||||
function SpawnShop.on_player_refresh(player)
|
||||
local this = Public.get()
|
||||
this.spawn_shop_funds = this.spawn_shop_funds - 1
|
||||
ScoreTracker.change_for_global(Public.scores.shop_funds.name, -1)
|
||||
player.print('[color=orange][Bard][/color] ' .. bard_refresh_messages[math_random(#bard_refresh_messages)], { sound_path = 'utility/scenario_message', color = Color.dark_grey })
|
||||
|
@ -2,15 +2,18 @@ local b = require 'map_gen.shared.builders'
|
||||
local math = require 'utils.math'
|
||||
local MGSP = require 'resources.map_gen_settings'
|
||||
local Noise = require 'map_gen.shared.simplex_noise'
|
||||
local Queue = require 'utils.queue'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local Public = require 'map_gen.maps.frontier.shared.core'
|
||||
local this = Public.get()
|
||||
local math_abs = math.abs
|
||||
local math_clamp = math.clamp
|
||||
local math_floor = math.floor
|
||||
local math_max = math.max
|
||||
local math_min = math.min
|
||||
local math_random = math.random
|
||||
local q_size = Queue.size
|
||||
local q_push = Queue.push
|
||||
local q_pop = Queue.pop
|
||||
local simplex = Noise.d2
|
||||
|
||||
local autoplace_controls = {
|
||||
@ -45,7 +48,7 @@ RS.set_map_gen_settings({
|
||||
{
|
||||
autoplace_controls = autoplace_controls,
|
||||
cliff_settings = { name = 'cliff', cliff_elevation_0 = 20, cliff_elevation_interval = 40, richness = 0.8 },
|
||||
height = this.height * 32,
|
||||
height = Public.get().height * 32,
|
||||
property_expression_names = {
|
||||
['control-setting:aux:frequency:multiplier'] = '1.333333',
|
||||
['control-setting:moisture:bias'] = '-0.250000',
|
||||
@ -60,18 +63,51 @@ RS.set_map_gen_settings({
|
||||
local Terrain = {}
|
||||
|
||||
function Terrain.get_map()
|
||||
local map, water, green_water
|
||||
local map
|
||||
local this = Public.get()
|
||||
|
||||
local bounds = function(x, y)
|
||||
return x > (-this.left_boundary * 32 - 320) and not ((y < -this.height * 16) or (y > this.height * 16))
|
||||
end
|
||||
local water = function(x, y)
|
||||
if x < -this.left_boundary * 32 then
|
||||
return bounds(x, y) and 'water'
|
||||
end
|
||||
end
|
||||
local green_water = function(x, y)
|
||||
if math_floor(x) == -(this.kraken_distance + this.left_boundary * 32 + 1) then
|
||||
return bounds(x, y) and 'deepwater-green'
|
||||
end
|
||||
end
|
||||
local spawn = function(x, _)
|
||||
return x >= -this.left_boundary * 32 and x < this.right_boundary * 32 + 96
|
||||
end
|
||||
spawn = b.remove_map_gen_entities_by_filter(spawn, { force = 'enemy' })
|
||||
local wall_tile = function(x, _)
|
||||
if x >= this.right_boundary * 32 - 1 and x <= this.right_boundary * 32 + this.wall_width + 1 then
|
||||
return 'concrete'
|
||||
elseif x >= this.right_boundary * 32 - 4 and x <= this.right_boundary * 32 + this.wall_width + 4 then
|
||||
return 'hazard-concrete-left'
|
||||
end
|
||||
end
|
||||
local wall = function(x, y)
|
||||
if x >= this.right_boundary * 32 and x < this.right_boundary * 32 + this.wall_width then
|
||||
return {
|
||||
name = 'stone-wall',
|
||||
position = { x = x , y = y },
|
||||
force = 'player',
|
||||
move_stuck_players = true,
|
||||
}
|
||||
end
|
||||
end
|
||||
wall = b.remove_map_gen_entities_by_filter(wall, { type = {'tree', 'simple-entity', 'cliff' } })
|
||||
|
||||
water = b.change_tile(bounds, true, 'water')
|
||||
water = b.fish(water, 0.075)
|
||||
|
||||
green_water = b.change_tile(bounds, true, 'deepwater-green')
|
||||
|
||||
map = b.choose(function(x) return x < -this.left_boundary * 32 end, water, bounds)
|
||||
map = b.choose(function(x) return math_floor(x) == -(this.kraken_distance + this.left_boundary * 32 + 1) end, green_water, map)
|
||||
map = b.add(water, bounds)
|
||||
map = b.add(green_water, map)
|
||||
map = b.fish(map, 0.075)
|
||||
map = b.add(spawn, map)
|
||||
map = b.apply_entity(map, wall)
|
||||
map = b.overlay_tile_land(map, wall_tile)
|
||||
return map
|
||||
end
|
||||
|
||||
@ -88,6 +124,7 @@ function Terrain.noise_pattern(position, seed)
|
||||
end
|
||||
|
||||
function Terrain.mixed_resources(surface, area)
|
||||
local this = Public.get()
|
||||
local left_top = { x = math_max(area.left_top.x, this.right_boundary * 32), y = area.left_top.y }
|
||||
local right_bottom = area.right_bottom
|
||||
if left_top.x >= right_bottom.x then
|
||||
@ -119,9 +156,9 @@ function Terrain.mixed_resources(surface, area)
|
||||
local position = { x = left_top.x + x, y = left_top.y + y }
|
||||
if can_place_entity({ name = 'iron-ore', position = position }) then
|
||||
local noise = Terrain.noise_pattern(position, seed)
|
||||
if math_abs(noise) > 0.67 then
|
||||
if math_abs(noise) > 0.77 then
|
||||
local idx = math_floor(noise * 25 + math_abs(position.x) * 0.05) % #mixed_ores + 1
|
||||
local amount = this.ore_base_quantity * chunks * 5
|
||||
local amount = this.ore_base_quantity * chunks * 35 + math_random(100)
|
||||
if clear_ore(position) then
|
||||
create_entity({ name = mixed_ores[idx], position = position, amount = amount })
|
||||
end
|
||||
@ -131,15 +168,8 @@ function Terrain.mixed_resources(surface, area)
|
||||
end
|
||||
end
|
||||
|
||||
function Terrain.clear_enemies_inside_wall(surface, area)
|
||||
if area.right_bottom.x < (this.right_boundary * 32 + 96) then
|
||||
for _, entity in pairs(surface.find_entities_filtered { area = area, force = 'enemy' }) do
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Terrain.scale_resource_richness(surface, area)
|
||||
local this = Public.get()
|
||||
for _, resource in pairs(surface.find_entities_filtered { area = area, type = 'resource' }) do
|
||||
if resource.position.x > this.right_boundary * 32 then
|
||||
local chunks = math.clamp(math_abs((resource.position.x - this.right_boundary * 32) / this.ore_chunk_scale), 1, 100)
|
||||
@ -161,6 +191,7 @@ function Terrain.scale_resource_richness(surface, area)
|
||||
end
|
||||
|
||||
function Terrain.rich_rocks(surface, area)
|
||||
local this = Public.get()
|
||||
local left_top = { x = math_max(area.left_top.x, this.right_boundary * 32), y = area.left_top.y }
|
||||
local right_bottom = area.right_bottom
|
||||
if left_top.x >= right_bottom.x then
|
||||
@ -212,37 +243,33 @@ function Terrain.set_silo_tiles(entity)
|
||||
entity.surface.set_tiles(tiles, true)
|
||||
end
|
||||
|
||||
function Terrain.create_wall(x, w)
|
||||
local surface = RS.get_surface()
|
||||
local area = { { x, -this.height * 16 }, { x + w, this.height * 16 } }
|
||||
for _, entity in pairs(surface.find_entities_filtered { area = area, collision_mask = 'player-layer' }) do
|
||||
entity.destroy()
|
||||
end
|
||||
function Terrain.queue_reveal_map()
|
||||
local this = Public.get()
|
||||
local chart_queue = this.chart_queue
|
||||
-- important to flush the queue upon resetting a map or chunk requests from previous maps could overlap
|
||||
Queue.clear(chart_queue)
|
||||
local size = math_max(this.left_boundary, this.right_boundary, this.height / 2) * 32 + 96
|
||||
for x = 16, size, 32 do
|
||||
for y = 16, size, 32 do
|
||||
q_push(chart_queue, {{-x, -y}, {-x, -y}})
|
||||
q_push(chart_queue, {{ x, -y}, { x, -y}})
|
||||
q_push(chart_queue, {{-x, y}, {-x, y}})
|
||||
q_push(chart_queue, {{ x, y}, { x, y}})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for y = -this.height * 16, this.height * 16 do
|
||||
for j = 0, w - 1 do
|
||||
local e = surface.create_entity {
|
||||
name = 'stone-wall',
|
||||
position = { x + j, y },
|
||||
force = 'player',
|
||||
move_stuck_players = true,
|
||||
}
|
||||
e.destructible = this.wall_vulnerability
|
||||
end
|
||||
end
|
||||
function Terrain.pop_chunk_request(max_requests)
|
||||
max_requests = max_requests or 1
|
||||
local this = Public.get()
|
||||
local chart_queue = this.chart_queue
|
||||
local surface = Public.surface()
|
||||
local players = game.forces.player
|
||||
|
||||
local tiles = {}
|
||||
for j = -4, w - 1 + 4 do
|
||||
for y = -this.height * 16, this.height * 16 do
|
||||
tiles[#tiles +1] = { name = 'hazard-concrete-left', position = { x = x + j, y = y }}
|
||||
end
|
||||
end
|
||||
for j = -1, w do
|
||||
for y = -this.height * 16, this.height * 16 do
|
||||
tiles[#tiles +1] = { name = 'concrete', position = { x = x + j, y = y }}
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
while max_requests > 0 and q_size(chart_queue) > 0 do
|
||||
players.chart(surface, q_pop(chart_queue))
|
||||
max_requests = max_requests - 1
|
||||
end
|
||||
end
|
||||
|
||||
return Terrain
|
||||
|
@ -13,7 +13,6 @@ local Market = require 'map_gen.maps.frontier.modules.market'
|
||||
local RocketSilo = require 'map_gen.maps.frontier.modules.rocket_silo'
|
||||
local SpawnShop = require 'map_gen.maps.frontier.modules.spawn_shop'
|
||||
local Terrain = require 'map_gen.maps.frontier.modules.terrain'
|
||||
local this = Public.get()
|
||||
local math_random = math.random
|
||||
|
||||
--[[
|
||||
@ -92,19 +91,30 @@ local function on_init()
|
||||
Lobby.on_init()
|
||||
RocketSilo.on_game_started()
|
||||
RocketSilo.reveal_spawn_area()
|
||||
Terrain.queue_reveal_map()
|
||||
SpawnShop.on_game_started()
|
||||
|
||||
this.lobby_enabled = false
|
||||
Public.get().lobby_enabled = false
|
||||
Lobby.teleport_all_from()
|
||||
end
|
||||
Event.on_init(on_init)
|
||||
|
||||
local function on_tick()
|
||||
local tick = game.tick
|
||||
|
||||
if (tick - 1) % 90 == 0 then
|
||||
Terrain.pop_chunk_request(24)
|
||||
end
|
||||
end
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
||||
local function on_game_started()
|
||||
RocketSilo.on_game_started()
|
||||
RocketSilo.reveal_spawn_area()
|
||||
Terrain.queue_reveal_map()
|
||||
SpawnShop.on_game_started()
|
||||
|
||||
this.lobby_enabled = false
|
||||
Public.get().lobby_enabled = false
|
||||
Lobby.teleport_all_from()
|
||||
end
|
||||
Event.add(Public.events.on_game_started, on_game_started)
|
||||
@ -124,7 +134,7 @@ local function on_player_created(event)
|
||||
return
|
||||
end
|
||||
|
||||
if this.lobby_enabled then
|
||||
if Public.get().lobby_enabled then
|
||||
Lobby.teleport_to(player)
|
||||
end
|
||||
end
|
||||
@ -138,13 +148,10 @@ local function on_chunk_generated(event)
|
||||
Lobby.on_chunk_generated(event)
|
||||
end
|
||||
|
||||
if surface.name ~= this.surface.name then
|
||||
if surface.name ~= Public.surface().name then
|
||||
return
|
||||
end
|
||||
|
||||
-- kill off biters inside the wall
|
||||
Terrain.clear_enemies_inside_wall(surface, area)
|
||||
|
||||
-- scale freshly generated ore by a scale factor
|
||||
Terrain.scale_resource_richness(surface, area)
|
||||
|
||||
@ -208,6 +215,7 @@ local function on_player_died(event)
|
||||
return
|
||||
end
|
||||
|
||||
local this = Public.get()
|
||||
if this.rockets_per_death <= 0 then
|
||||
return
|
||||
end
|
||||
@ -231,6 +239,7 @@ local function on_player_changed_position(event)
|
||||
return
|
||||
end
|
||||
|
||||
local this = Public.get()
|
||||
if player.position.x < (-this.left_boundary * 32 - this.kraken_distance) then
|
||||
local player_name = 'a player'
|
||||
if player.character ~= nil then
|
||||
@ -288,7 +297,7 @@ Event.add(defines.events.on_entity_destroyed, on_entity_destroyed)
|
||||
|
||||
local function on_ai_command_completed(event)
|
||||
if not event.was_distracted then
|
||||
local data = this.unit_groups[event.unit_number]
|
||||
local data = Public.get().unit_groups[event.unit_number]
|
||||
if data and data.unit_group and data.unit_group.valid then
|
||||
Enemy.ai_processor(data.unit_group, event.result)
|
||||
end
|
||||
@ -311,7 +320,7 @@ local function on_gui_opened(event)
|
||||
return
|
||||
end
|
||||
|
||||
if entity.unit_number == this.spawn_shop.unit_number then
|
||||
if entity.unit_number == Public.get().spawn_shop.unit_number then
|
||||
SpawnShop.draw_gui(player)
|
||||
end
|
||||
end
|
||||
@ -364,7 +373,7 @@ Command.add('ping-silo',
|
||||
allowed_by_server = true
|
||||
},
|
||||
function(_, player)
|
||||
local surface = this.surface
|
||||
local surface = Public.surface()
|
||||
local msg = '[color=blue][Mapkeeper][/color] Here you\'ll find a silo:'
|
||||
local silos = surface.find_entities_filtered { name = 'rocket-silo' }
|
||||
for _, s in pairs(silos) do
|
||||
@ -385,6 +394,7 @@ Command.add('toggle-debug-ai',
|
||||
required_rank = Ranks.admin,
|
||||
},
|
||||
function()
|
||||
local this = Public.get()
|
||||
this._DEBUG_AI = not this._DEBUG_AI
|
||||
end
|
||||
)
|
||||
@ -396,6 +406,7 @@ Command.add('toggle-debug-shop',
|
||||
required_rank = Ranks.admin,
|
||||
},
|
||||
function()
|
||||
local this = Public.get()
|
||||
this._DEBUG_SHOP = not this._DEBUG_SHOP
|
||||
end
|
||||
)
|
||||
@ -407,7 +418,7 @@ Command.add('print-global',
|
||||
required_rank = Ranks.admin,
|
||||
},
|
||||
function(_, player)
|
||||
player.print(serpent.line(this))
|
||||
player.print(serpent.line(Public.get()))
|
||||
end
|
||||
)
|
||||
|
||||
@ -418,7 +429,7 @@ Command.add('log-global',
|
||||
required_rank = Ranks.admin,
|
||||
},
|
||||
function()
|
||||
Debug.log(this)
|
||||
Debug.log(Public.get())
|
||||
end
|
||||
)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Queue = require 'utils.queue'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
|
||||
local Public = {}
|
||||
@ -21,13 +22,13 @@ Public.PROD_PENALTY = 1.2 * 1.4^5
|
||||
local this = {
|
||||
rounds = 0,
|
||||
-- Map gen
|
||||
chart_queue = Queue.new(),
|
||||
silo_starting_x = 1700,
|
||||
|
||||
height = 36, -- in chunks, height of the ribbon world
|
||||
left_boundary = 8, -- in chunks, distance to water body
|
||||
right_boundary = 11, -- in chunks, distance to wall/biter presence
|
||||
wall_width = 5, -- in tiles
|
||||
wall_vulnerability = true,
|
||||
rock_richness = 1, -- how many rocks/chunk
|
||||
|
||||
ore_base_quantity = 11, -- base ore quantity, everything is scaled up from this
|
||||
@ -86,14 +87,14 @@ local this = {
|
||||
spawn_shop_upgrades = {},
|
||||
}
|
||||
|
||||
Global.register_init(
|
||||
this,
|
||||
function() this.surface = RS.get_surface() end,
|
||||
function(tbl) this = tbl end
|
||||
)
|
||||
Global.register(this, function(tbl) this = tbl end)
|
||||
|
||||
function Public.get()
|
||||
return this
|
||||
end
|
||||
|
||||
function Public.surface()
|
||||
return RS.get_surface()
|
||||
end
|
||||
|
||||
return Public
|
||||
|
@ -74,4 +74,11 @@ function Queue.pairs(queue)
|
||||
end
|
||||
end
|
||||
|
||||
function Queue.clear(queue)
|
||||
for k, _ in pairs(queue) do
|
||||
queue[k] = nil
|
||||
end
|
||||
queue._head, queue._tail = 1, 1
|
||||
end
|
||||
|
||||
return Queue
|
||||
|
Loading…
Reference in New Issue
Block a user