1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00

Merge pull request #100 from ComfyFactory/tweaks

Refactor of some code.
This commit is contained in:
Gerkiz 2021-07-23 16:39:56 +02:00 committed by GitHub
commit 42e7496322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 197 additions and 155 deletions

View File

@ -110,7 +110,6 @@ local function create_frame(player, alignment, location, portable)
if portable then
frame.caption = ''
end
global.frame = frame
local inner_frame =
frame.add {

View File

@ -28,17 +28,34 @@ local wintery_type = {
-- Set to false by modules that want to control the on_chunk_generated event themselves.
Public.enable_register_events = true
-- Simple "loop" that is UPS friendly.
local function get_position(data)
data.yv = data.yv + 1
if data.yv == 32 then
if data.xv == 32 then
data.xv = 0
end
if data.yv == 32 then
data.yv = 0
end
data.xv = data.xv + 1
end
data.position = {x = data.top_x + data.xv, y = data.top_y + data.yv}
end
local function do_tile_inner(tiles, tile, pos)
if type(tile) == 'string' then
tiles[#tiles + 1] = {name = tile, position = pos}
end
end
local function do_tile(y, x, data, shape)
local function do_tile(x, y, data, shape)
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)
local tile = shape(data)
if type(tile) == 'table' then
do_tile_inner(data.tiles, tile.tile, pos)
@ -110,8 +127,10 @@ local function do_row(row, data, shape)
data.x = x
local pos = {data.x, data.y}
get_position(data)
-- local coords need to be 'centered' to allow for correct rotation and scaling.
local tile = shape(x + 0.5, y + 0.5, data)
local tile = shape(data)
if type(tile) == 'table' then
do_tile_inner(tiles, tile.tile, pos)
@ -419,7 +438,8 @@ local function map_gen_action(data)
repeat
count = count - 1
do_tile(y, x, data, shape)
get_position(data)
do_tile(x, y, data, shape)
x = x + 1
@ -494,7 +514,7 @@ function Public.schedule_chunk(event)
local area = event.area
local data = {
yv = -1,
yv = -0,
xv = 0,
y = 0,
x = area.left_top.x,

View File

@ -203,6 +203,56 @@ function Public.add_player_to_permission_group(player, group, forced)
local session = Session.get_session_table()
local AG = Antigrief.get()
if not game.permissions.get_group('locomotive') then
local locomotive_group = game.permissions.create_group('locomotive')
locomotive_group.set_allows_action(defines.input_action.cancel_craft, false)
locomotive_group.set_allows_action(defines.input_action.edit_permission_group, false)
locomotive_group.set_allows_action(defines.input_action.import_permissions_string, false)
locomotive_group.set_allows_action(defines.input_action.delete_permission_group, false)
locomotive_group.set_allows_action(defines.input_action.add_permission_group, false)
locomotive_group.set_allows_action(defines.input_action.admin_action, false)
locomotive_group.set_allows_action(defines.input_action.drop_item, false)
locomotive_group.set_allows_action(defines.input_action.deconstruct, false)
local default_group = game.permissions.get_group('Default')
default_group.set_allows_action(defines.input_action.deconstruct, false)
end
if not game.permissions.get_group('plebs') then
local plebs_group = game.permissions.create_group('plebs')
plebs_group.set_allows_action(defines.input_action.edit_permission_group, false)
plebs_group.set_allows_action(defines.input_action.import_permissions_string, false)
plebs_group.set_allows_action(defines.input_action.delete_permission_group, false)
plebs_group.set_allows_action(defines.input_action.add_permission_group, false)
plebs_group.set_allows_action(defines.input_action.admin_action, false)
plebs_group.set_allows_action(defines.input_action.deconstruct, false)
end
if not game.permissions.get_group('not_trusted') then
local not_trusted = game.permissions.create_group('not_trusted')
not_trusted.set_allows_action(defines.input_action.cancel_craft, false)
not_trusted.set_allows_action(defines.input_action.edit_permission_group, false)
not_trusted.set_allows_action(defines.input_action.import_permissions_string, false)
not_trusted.set_allows_action(defines.input_action.delete_permission_group, false)
not_trusted.set_allows_action(defines.input_action.add_permission_group, false)
not_trusted.set_allows_action(defines.input_action.admin_action, false)
not_trusted.set_allows_action(defines.input_action.drop_item, false)
not_trusted.set_allows_action(defines.input_action.disconnect_rolling_stock, false)
not_trusted.set_allows_action(defines.input_action.connect_rolling_stock, false)
not_trusted.set_allows_action(defines.input_action.open_train_gui, false)
not_trusted.set_allows_action(defines.input_action.open_train_station_gui, false)
not_trusted.set_allows_action(defines.input_action.open_trains_gui, false)
not_trusted.set_allows_action(defines.input_action.change_train_stop_station, false)
not_trusted.set_allows_action(defines.input_action.change_train_wait_condition, false)
not_trusted.set_allows_action(defines.input_action.change_train_wait_condition_data, false)
not_trusted.set_allows_action(defines.input_action.drag_train_schedule, false)
not_trusted.set_allows_action(defines.input_action.drag_train_wait_condition, false)
not_trusted.set_allows_action(defines.input_action.go_to_train_station, false)
not_trusted.set_allows_action(defines.input_action.remove_train_station, false)
not_trusted.set_allows_action(defines.input_action.set_trains_limit, false)
not_trusted.set_allows_action(defines.input_action.set_train_stopped, false)
not_trusted.set_allows_action(defines.input_action.deconstruct, false)
end
if not AG.enabled then
local default_group = game.permissions.get_group('Default')
default_group.add_player(player)
@ -236,51 +286,6 @@ function Public.add_player_to_permission_group(player, group, forced)
return
end
if not game.permissions.get_group('locomotive') then
local locomotive_group = game.permissions.create_group('locomotive')
locomotive_group.set_allows_action(defines.input_action.cancel_craft, false)
locomotive_group.set_allows_action(defines.input_action.edit_permission_group, false)
locomotive_group.set_allows_action(defines.input_action.import_permissions_string, false)
locomotive_group.set_allows_action(defines.input_action.delete_permission_group, false)
locomotive_group.set_allows_action(defines.input_action.add_permission_group, false)
locomotive_group.set_allows_action(defines.input_action.admin_action, false)
locomotive_group.set_allows_action(defines.input_action.drop_item, false)
end
if not game.permissions.get_group('plebs') then
local plebs_group = game.permissions.create_group('plebs')
plebs_group.set_allows_action(defines.input_action.edit_permission_group, false)
plebs_group.set_allows_action(defines.input_action.import_permissions_string, false)
plebs_group.set_allows_action(defines.input_action.delete_permission_group, false)
plebs_group.set_allows_action(defines.input_action.add_permission_group, false)
plebs_group.set_allows_action(defines.input_action.admin_action, false)
end
if not game.permissions.get_group('not_trusted') then
local not_trusted = game.permissions.create_group('not_trusted')
not_trusted.set_allows_action(defines.input_action.cancel_craft, false)
not_trusted.set_allows_action(defines.input_action.edit_permission_group, false)
not_trusted.set_allows_action(defines.input_action.import_permissions_string, false)
not_trusted.set_allows_action(defines.input_action.delete_permission_group, false)
not_trusted.set_allows_action(defines.input_action.add_permission_group, false)
not_trusted.set_allows_action(defines.input_action.admin_action, false)
not_trusted.set_allows_action(defines.input_action.drop_item, false)
not_trusted.set_allows_action(defines.input_action.disconnect_rolling_stock, false)
not_trusted.set_allows_action(defines.input_action.connect_rolling_stock, false)
not_trusted.set_allows_action(defines.input_action.open_train_gui, false)
not_trusted.set_allows_action(defines.input_action.open_train_station_gui, false)
not_trusted.set_allows_action(defines.input_action.open_trains_gui, false)
not_trusted.set_allows_action(defines.input_action.change_train_stop_station, false)
not_trusted.set_allows_action(defines.input_action.change_train_wait_condition, false)
not_trusted.set_allows_action(defines.input_action.change_train_wait_condition_data, false)
not_trusted.set_allows_action(defines.input_action.drag_train_schedule, false)
not_trusted.set_allows_action(defines.input_action.drag_train_wait_condition, false)
not_trusted.set_allows_action(defines.input_action.go_to_train_station, false)
not_trusted.set_allows_action(defines.input_action.remove_train_station, false)
not_trusted.set_allows_action(defines.input_action.set_trains_limit, false)
not_trusted.set_allows_action(defines.input_action.set_train_stopped, false)
end
if enable_permission_group_disconnect then
local locomotive_group = game.permissions.get_group('locomotive')
local plebs_group = game.permissions.get_group('plebs')

View File

@ -180,6 +180,7 @@ function Public.reset_map()
JailData.reset_vote_table()
Explosives.set_surface_whitelist({[surface.name] = true})
Explosives.check_growth_below_void(true)
game.forces.player.set_spawn_position({-27, 25}, surface)
game.forces.player.manual_mining_speed_modifier = 0
@ -471,8 +472,8 @@ local on_init = function()
local this = WPT.get()
Public.reset_map()
game.map_settings.path_finder.general_entity_collision_penalty = 1 -- Recommended value
game.map_settings.path_finder.general_entity_subsequent_collision_penalty = 1 -- Recommended value
game.map_settings.path_finder.general_entity_collision_penalty = 10 -- Recommended value
game.map_settings.path_finder.general_entity_subsequent_collision_penalty = 3 -- Recommended value
local tooltip = {
[1] = ({'main.diff_tooltip', '0', '0.5', '0.15', '0.15', '1', '12', '50', '10000', '100%', '15', '10'}),

View File

@ -18,7 +18,7 @@ Global.register(
)
Public.level_depth = 704
Public.level_width = 512
Public.level_width = 524
Public.pickaxe_upgrades = {
'Wood',

View File

@ -221,22 +221,6 @@ local function get_oil_amount(p)
return (abs(p.y) * 200 + 10000) * random(75, 125) * 0.01
end
function Public.increment_value(tbl)
tbl.yv = tbl.yv + 1
if tbl.yv == 32 then
if tbl.xv == 32 then
tbl.xv = 0
end
if tbl.yv == 32 then
tbl.yv = 0
end
tbl.xv = tbl.xv + 1
end
return tbl.xv, tbl.yv
end
local function spawn_turret(entities, p, probability)
entities[#entities + 1] = {
name = turret_list[probability].name,
@ -248,7 +232,7 @@ local function spawn_turret(entities, p, probability)
}
end
local function wall(data)
local function wall(p, data)
local tiles = data.tiles
local entities = data.entities
local surface = data.surface
@ -256,10 +240,8 @@ local function wall(data)
local stone_wall = {callback = Functions.disable_minable_callback}
local enable_arties = WPT.get('enable_arties')
local x, y = Public.increment_value(data)
local seed = data.seed
local p = {x = x + data.top_x, y = y + data.top_y}
local y = data.yv
local small_caves = get_perlin('small_caves', p, seed + 204000)
local cave_ponds = get_perlin('cave_rivers', p, seed + 120400)
@ -2278,7 +2260,7 @@ local function is_out_of_map(p)
return true
end
local function process_bits(x, y, data)
local function process_bits(p, data)
local levels = Public.levels
local left_top_y = data.area.left_top.y
local index = floor((abs(left_top_y / Public.level_depth)) % 22) + 1
@ -2289,17 +2271,18 @@ local function process_bits(x, y, data)
local void_or_tile = WPT.get('void_or_tile')
local x = p.x
local y = p.y
process_level(x, y, data, void_or_tile)
end
local function border_chunk(data)
local function border_chunk(p, data)
local entities = data.entities
local decoratives = data.decoratives
local tiles = data.tiles
local x, y = Public.increment_value(data)
local pos = {x = x + data.top_x, y = y + data.top_y}
local pos = p
if random(1, ceil(pos.y + pos.y) + 64) == 1 then
entities[#entities + 1] = {name = trees[random(1, #trees)], position = pos}
@ -2317,30 +2300,29 @@ local function border_chunk(data)
if random(1, ceil(pos.y + pos.y) + 32) == 1 then
entities[#entities + 1] = {name = scrap_mineable_entities[random(1, scrap_mineable_entities_index)], position = pos, force = 'neutral'}
end
if random(1, pos.y + 2) == 1 then
decoratives[#decoratives + 1] = {
name = 'rock-small',
position = pos,
amount = random(1, 1 + ceil(20 - y / 2))
amount = random(1, 32)
}
end
if random(1, pos.y + 2) == 1 then
decoratives[#decoratives + 1] = {
name = 'rock-tiny',
position = pos,
amount = random(1, 1 + ceil(20 - y / 2))
amount = random(1, 32)
}
end
end
end
local function biter_chunk(data)
local function biter_chunk(p, data)
local surface = data.surface
local entities = data.entities
local tile_positions = {}
local x, y = Public.increment_value(data)
local p = {x = x + data.top_x, y = y + data.top_y}
tile_positions[#tile_positions + 1] = p
local disable_spawners = {
@ -2375,18 +2357,15 @@ local function biter_chunk(data)
end
end
local function out_of_map(x, y, data)
local function out_of_map(p, data)
local tiles = data.tiles
local p = {x = x, y = y}
tiles[#tiles + 1] = {name = 'out-of-map', position = p}
end
function Public.heavy_functions(x, y, data)
function Public.heavy_functions(data)
local top_y = data.top_y
local surface = data.surface
local p = {x = data.x, y = data.y}
local p = data.position
local get_tile = surface.get_tile(p)
local map_name = 'mountain_fortress_v3'
@ -2405,28 +2384,23 @@ function Public.heavy_functions(x, y, data)
if top_y % Public.level_depth == 0 and top_y < 0 then
WPT.set().left_top = data.left_top
wall(data)
return
return wall(p, data)
end
if top_y < 0 then
process_bits(x, y, data)
return
return process_bits(p, data)
end
if top_y > 120 then
out_of_map(x, y, data)
return
return out_of_map(p, data)
end
if top_y > 75 then
biter_chunk(data)
return
return biter_chunk(p, data)
end
if top_y >= 0 then
border_chunk(data)
return
return border_chunk(p, data)
end
end

View File

@ -1,6 +1,6 @@
local function draw_map_tag(surface, force, position, name)
local t = force.add_chart_tag(surface, {icon = {type = 'item', name = 'heavy-armor'}, position = position, text = ' '})
if name then
if t and name then
t.last_user = name
end
end

View File

@ -1,10 +1,16 @@
local Public = {}
local Global = require 'utils.global'
local explosives = {}
local Collapse = require 'modules.collapse'
local this = {
explosives = {},
settings = {
check_growth_below_void = false
}
}
Global.register(
explosives,
this,
function(tbl)
explosives = tbl
this = tbl
end
)
@ -28,6 +34,29 @@ local function pos_to_key(position)
return tostring(position.x .. '_' .. position.y)
end
local function check_y_pos(position)
if not this.settings.check_growth_below_void then
return false
end
if not position or not position.y then
return false
end
local collapse_pos = Collapse.get_position()
local radius = 50
local dy = position.y - collapse_pos.y
if dy ^ 2 < radius ^ 2 then
return true
end
if position.y >= collapse_pos.y then
return true
else
return false
end
end
local function get_explosion_name(health)
if health < 2500 then
return 'explosion'
@ -42,13 +71,13 @@ local function cell_birth(surface_index, origin_position, origin_tick, position,
local key = pos_to_key(position)
--Merge cells that are overlapping.
if explosives.cells[key] then
explosives.cells[key].health = explosives.cells[key].health + health
if this.explosives.cells[key] then
this.explosives.cells[key].health = this.explosives.cells[key].health + health
return
end
--Spawn new cell.
explosives.cells[key] = {
this.explosives.cells[key] = {
surface_index = surface_index,
origin_position = origin_position,
origin_tick = origin_tick,
@ -59,15 +88,15 @@ local function cell_birth(surface_index, origin_position, origin_tick, position,
end
local function grow_cell(cell)
shuffle_table(explosives.vectors)
shuffle_table(this.explosives.vectors)
local radius = math_floor((game.tick - cell.origin_tick) / 9) + 2
local positions = {}
for i = 1, 4, 1 do
local position = {
x = cell.position.x + explosives.vectors[i][1],
y = cell.position.y + explosives.vectors[i][2]
x = cell.position.x + this.explosives.vectors[i][1],
y = cell.position.y + this.explosives.vectors[i][2]
}
if not explosives.cells[pos_to_key(position)] then
if not this.explosives.cells[pos_to_key(position)] then
local distance = math_sqrt((cell.origin_position.x - position.x) ^ 2 + (cell.origin_position.y - position.y) ^ 2)
if distance < radius then
positions[#positions + 1] = position
@ -77,18 +106,18 @@ local function grow_cell(cell)
if #positions == 0 then
positions[#positions + 1] = {
x = cell.position.x + explosives.vectors[1][1],
y = cell.position.y + explosives.vectors[1][2]
x = cell.position.x + this.explosives.vectors[1][1],
y = cell.position.y + this.explosives.vectors[1][2]
}
end
local new_cell_health = math_round(cell.health / #positions, 3) - explosives.damage_decay
local new_cell_health = math_round(cell.health / #positions, 3) - this.explosives.damage_decay
--[[
if new_cell_health > 0 then
explosives.cells_damage_dealt = explosives.cells_damage_dealt + damage_decay * #positions
this.explosives.cells_damage_dealt = this.explosives.cells_damage_dealt + damage_decay * #positions
else
explosives.cells_damage_dealt = explosives.cells_damage_dealt + (new_cell_health + damage_decay) * #positions
this.explosives.cells_damage_dealt = this.explosives.cells_damage_dealt + (new_cell_health + damage_decay) * #positions
end
]]
if new_cell_health <= 0 then
@ -114,7 +143,7 @@ local function damage_entity(entity, cell)
return true
end
if explosives.whitelist_entity[entity.name] then
if this.explosives.whitelist_entity[entity.name] then
return true
end
@ -166,20 +195,20 @@ local function damage_area(cell)
end
local tile = surface.get_tile(cell.position)
if explosives.destructible_tiles[tile.name] then
if this.explosives.destructible_tiles[tile.name] then
local key = pos_to_key(tile.position)
if not explosives.tiles[key] then
explosives.tiles[key] = explosives.destructible_tiles[tile.name]
if not this.explosives.tiles[key] then
this.explosives.tiles[key] = this.explosives.destructible_tiles[tile.name]
end
if cell.health > explosives.tiles[key] then
cell.health = cell.health - explosives.tiles[key]
explosives.tiles[key] = nil
if cell.health > this.explosives.tiles[key] then
cell.health = cell.health - this.explosives.tiles[key]
this.explosives.tiles[key] = nil
if math_abs(tile.position.y) < surface.map_gen_settings.height * 0.5 and math_abs(tile.position.x) < surface.map_gen_settings.width * 0.5 then
surface.set_tiles({{name = 'landfill', position = tile.position}}, true)
end
else
explosives.tiles[key] = explosives.tiles[key] - cell.health
this.explosives.tiles[key] = this.explosives.tiles[key] - cell.health
return
end
end
@ -195,14 +224,14 @@ local function life_cycle(cell)
end
local function tick()
for key, cell in pairs(explosives.cells) do
for key, cell in pairs(this.explosives.cells) do
if cell.spawn_tick < game.tick then
life_cycle(cell)
explosives.cells[key] = nil
this.explosives.cells[key] = nil
end
end
if game.tick % 216000 == 0 then
explosives.tiles = {}
this.explosives.tiles = {}
end
end
@ -214,8 +243,8 @@ local function on_entity_died(event)
if not valid_container_types[entity.type] then
return
end
if explosives.surface_whitelist then
if not explosives.surface_whitelist[entity.surface.name] then
if this.explosives.surface_whitelist then
if not this.explosives.surface_whitelist[entity.surface.name] then
return
end
end
@ -234,12 +263,17 @@ local function on_entity_died(event)
return
end
local below_void = check_y_pos(entity.position)
if below_void then
return
end
cell_birth(
entity.surface.index,
{x = entity.position.x, y = entity.position.y},
game.tick,
{x = entity.position.x, y = entity.position.y},
amount * explosives.damage_per_explosive
amount * this.explosives.damage_per_explosive
)
end
@ -250,8 +284,8 @@ function Public.detonate_chest(entity)
if not valid_container_types[entity.type] then
return false
end
if explosives.surface_whitelist then
if not explosives.surface_whitelist[entity.surface.name] then
if this.explosives.surface_whitelist then
if not this.explosives.surface_whitelist[entity.surface.name] then
return false
end
end
@ -270,52 +304,61 @@ function Public.detonate_chest(entity)
return false
end
local below_void = check_y_pos(entity.position)
if below_void then
return
end
cell_birth(
entity.surface.index,
{x = entity.position.x, y = entity.position.y},
game.tick,
{x = entity.position.x, y = entity.position.y},
amount * explosives.damage_per_explosive
amount * this.explosives.damage_per_explosive
)
return true
end
function Public.reset()
explosives.cells = {}
explosives.tiles = {}
if not explosives.vectors then
explosives.vectors = {{density, 0}, {density * -1, 0}, {0, density}, {0, density * -1}}
this.explosives.cells = {}
this.explosives.tiles = {}
if not this.explosives.vectors then
this.explosives.vectors = {{density, 0}, {density * -1, 0}, {0, density}, {0, density * -1}}
end
if not explosives.damage_per_explosive then
explosives.damage_per_explosive = 500
if not this.explosives.damage_per_explosive then
this.explosives.damage_per_explosive = 500
end
if not explosives.damage_decay then
explosives.damage_decay = 10
if not this.explosives.damage_decay then
this.explosives.damage_decay = 10
end
if not explosives.destructible_tiles then
explosives.destructible_tiles = {}
if not this.explosives.destructible_tiles then
this.explosives.destructible_tiles = {}
end
if not explosives.whitelist_entity then
explosives.whitelist_entity = {}
if not this.explosives.whitelist_entity then
this.explosives.whitelist_entity = {}
end
end
function Public.set_destructible_tile(tile_name, health)
explosives.destructible_tiles[tile_name] = health
this.explosives.destructible_tiles[tile_name] = health
end
function Public.set_whitelist_entity(entity)
if entity then
explosives.whitelist_entity[entity] = true
this.explosives.whitelist_entity[entity] = true
end
end
function Public.set_surface_whitelist(list)
explosives.surface_whitelist = list
this.explosives.surface_whitelist = list
end
function Public.get_table()
return explosives
return this.explosives
end
function Public.check_growth_below_void(value)
this.settings.check_growth_below_void = value or false
end
local function on_init()

View File

@ -481,12 +481,12 @@ function Public.update_player_stats(player)
local magic = rpg_t.magicka - 10
local v = magic * 0.22
P.update_single_modifier(player, 'character_build_distance_bonus', 'rpg', math.min(60, math.round(v * 0.25, 3)))
P.update_single_modifier(player, 'character_item_drop_distance_bonus', 'rpg', math.min(60, math.round(v * 0.25, 3)))
P.update_single_modifier(player, 'character_reach_distance_bonus', 'rpg', math.min(60, math.round(v * 0.25, 3)))
P.update_single_modifier(player, 'character_loot_pickup_distance_bonus', 'rpg', math.min(20, math.round(v * 0.22, 3)))
P.update_single_modifier(player, 'character_item_pickup_distance_bonus', 'rpg', math.min(20, math.round(v * 0.25, 3)))
P.update_single_modifier(player, 'character_resource_reach_distance_bonus', 'rpg', math.min(20, math.round(v * 0.15, 3)))
P.update_single_modifier(player, 'character_build_distance_bonus', 'rpg', math.min(60, math.round(v * 0.12, 3)))
P.update_single_modifier(player, 'character_item_drop_distance_bonus', 'rpg', math.min(60, math.round(v * 0.05, 3)))
P.update_single_modifier(player, 'character_reach_distance_bonus', 'rpg', math.min(60, math.round(v * 0.12, 3)))
P.update_single_modifier(player, 'character_loot_pickup_distance_bonus', 'rpg', math.min(20, math.round(v * 0.12, 3)))
P.update_single_modifier(player, 'character_item_pickup_distance_bonus', 'rpg', math.min(20, math.round(v * 0.12, 3)))
P.update_single_modifier(player, 'character_resource_reach_distance_bonus', 'rpg', math.min(20, math.round(v * 0.05, 3)))
if rpg_t.mana_max >= rpg_extra.mana_limit then
rpg_t.mana_max = rpg_extra.mana_limit
else