mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-30 23:17:53 +02:00
mtn fortress tweaks and wd gui fix
This commit is contained in:
parent
ba75be24a0
commit
41f49ad943
@ -76,31 +76,46 @@ local function do_refill_turrets()
|
||||
end
|
||||
end
|
||||
|
||||
local function turret_died(event)
|
||||
local entity = event.entity
|
||||
if not entity or not entity.valid then
|
||||
return
|
||||
end
|
||||
-- local function turret_died(event)
|
||||
-- local entity = event.entity
|
||||
-- if not entity or not entity.valid then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
local number = entity.unit_number
|
||||
if not number then
|
||||
return
|
||||
end
|
||||
-- local number = entity.unit_number
|
||||
-- if not number then
|
||||
-- return
|
||||
-- end
|
||||
-- local power_sources = this.power_sources
|
||||
|
||||
-- local ps_data = power_sources[number]
|
||||
-- if ps_data then
|
||||
-- power_sources[number] = nil
|
||||
|
||||
-- --[[ local ps_entity = ps_data.entity
|
||||
-- local ps_pole = ps_data.pole ]]
|
||||
-- if ps_data and ps_data.valid then
|
||||
-- ps_data.destroy()
|
||||
-- end
|
||||
|
||||
-- --[[ if ps_pole and ps_pole.valid then
|
||||
-- ps_pole.destroy()
|
||||
-- end ]]
|
||||
-- end
|
||||
-- end
|
||||
|
||||
local function do_turret_energy()
|
||||
local power_sources = this.power_sources
|
||||
|
||||
local ps_data = power_sources[number]
|
||||
if ps_data then
|
||||
power_sources[number] = nil
|
||||
|
||||
local ps_entity = ps_data.entity
|
||||
local ps_pole = ps_data.pole
|
||||
|
||||
if ps_entity and ps_entity.valid then
|
||||
ps_entity.destroy()
|
||||
for index = 1, #power_sources do
|
||||
local ps_data = power_sources[index]
|
||||
if not (ps_data or ps_data.valid) then
|
||||
fast_remove(power_sources, index)
|
||||
return
|
||||
end
|
||||
|
||||
if ps_pole and ps_pole.valid then
|
||||
ps_pole.destroy()
|
||||
if ps_data and ps_data.valid then
|
||||
ps_data.energy = 0xfffff
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -454,9 +469,9 @@ Public.power_source_callback =
|
||||
Token.register(
|
||||
function(turret, data)
|
||||
local power_sources = this.power_sources
|
||||
local callback_data = data.callback_data
|
||||
-- local callback_data = data.callback_data
|
||||
|
||||
local power_source = turret.surface.create_entity {name = 'hidden-electric-energy-interface', position = turret.position}
|
||||
--[[ local power_source = turret.surface.create_entity {name = 'hidden-electric-energy-interface', position = turret.position}
|
||||
power_source.electric_buffer_size = callback_data.buffer_size
|
||||
power_source.power_production = callback_data.power_production
|
||||
power_source.destructible = false
|
||||
@ -466,9 +481,8 @@ Public.power_source_callback =
|
||||
position = {x = turret.position.x, y = turret.position.y}
|
||||
}
|
||||
power_pole.destructible = false
|
||||
power_pole.disconnect_neighbour()
|
||||
|
||||
power_sources[turret.unit_number] = {entity = power_source, pole = power_pole}
|
||||
power_pole.disconnect_neighbour() ]]
|
||||
power_sources[#power_sources + 1] = turret
|
||||
end
|
||||
)
|
||||
|
||||
@ -633,7 +647,8 @@ function Public.reset_table()
|
||||
end
|
||||
|
||||
Event.on_nth_tick(10, tick)
|
||||
Event.on_nth_tick(5, do_turret_energy)
|
||||
--Event.add(defines.events.on_tick, tick)
|
||||
Event.add(defines.events.on_entity_died, turret_died)
|
||||
-- Event.add(defines.events.on_entity_died, turret_died)
|
||||
|
||||
return Public
|
||||
|
@ -786,67 +786,10 @@ local function move_room_to_train(icw, train, wagon)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_connected_rolling_stock(entity, direction, carriages)
|
||||
--thanks Boskid
|
||||
local first_stock, second_stock
|
||||
for k, v in pairs(carriages) do
|
||||
if v == entity then
|
||||
first_stock = carriages[k - 1]
|
||||
second_stock = carriages[k + 1]
|
||||
break
|
||||
end
|
||||
end
|
||||
if not first_stock then
|
||||
first_stock, second_stock = second_stock, nil
|
||||
end
|
||||
if not first_stock then
|
||||
return nil
|
||||
end
|
||||
|
||||
local angle =
|
||||
math.atan2(-(entity.position.x - first_stock.position.x), entity.position.y - first_stock.position.y) / (2 * math.pi) -
|
||||
entity.orientation
|
||||
if direction == defines.rail_direction.back then
|
||||
angle = angle + 0.5
|
||||
end
|
||||
while angle < -0.5 do
|
||||
angle = angle + 1
|
||||
end
|
||||
while angle > 0.5 do
|
||||
angle = angle - 1
|
||||
end
|
||||
local connected_stock
|
||||
if angle > -0.25 and angle < 0.25 then
|
||||
connected_stock = first_stock
|
||||
else
|
||||
connected_stock = second_stock
|
||||
end
|
||||
if not connected_stock then
|
||||
return nil
|
||||
end
|
||||
|
||||
angle =
|
||||
math.atan2(-(connected_stock.position.x - entity.position.x), connected_stock.position.y - entity.position.y) / (2 * math.pi) -
|
||||
connected_stock.orientation
|
||||
while angle < -0.5 do
|
||||
angle = angle + 1
|
||||
end
|
||||
while angle > 0.5 do
|
||||
angle = angle - 1
|
||||
end
|
||||
local joint_of_connected_stock
|
||||
if angle > -0.25 and angle < 0.25 then
|
||||
joint_of_connected_stock = defines.rail_direction.front
|
||||
else
|
||||
joint_of_connected_stock = defines.rail_direction.back
|
||||
end
|
||||
return connected_stock, joint_of_connected_stock
|
||||
end
|
||||
|
||||
function Public.construct_train(icw, locomotive, carriages)
|
||||
for i, carriage in pairs(carriages) do
|
||||
if carriage == locomotive then
|
||||
local stock = get_connected_rolling_stock(locomotive, defines.rail_direction.front, carriages)
|
||||
local stock = locomotive.get_connected_rolling_stock(defines.rail_direction.front)
|
||||
if stock ~= carriages[i - 1] then
|
||||
local n = 1
|
||||
local m = #carriages
|
||||
|
@ -723,8 +723,10 @@ local function slider_changed(event)
|
||||
return
|
||||
end
|
||||
slider_value = ceil(slider_value)
|
||||
players[player.index].data.text_input.text = slider_value
|
||||
redraw_market_items(players[player.index].data.item_frame, player, players[player.index].data.search_text)
|
||||
if players[player.index] and players[player.index].data and players[player.index].data.text_input then
|
||||
players[player.index].data.text_input.text = slider_value
|
||||
redraw_market_items(players[player.index].data.item_frame, player, players[player.index].data.search_text)
|
||||
end
|
||||
end
|
||||
|
||||
local function text_changed(event)
|
||||
|
@ -797,6 +797,8 @@ local set_spawn_position = function()
|
||||
end
|
||||
local l = locomotive.position
|
||||
|
||||
local retries = 0
|
||||
|
||||
local function check_tile(surface, tile, tbl, inc)
|
||||
if not (surface and surface.valid) then
|
||||
return false
|
||||
@ -829,11 +831,8 @@ local set_spawn_position = function()
|
||||
if spawn_near_collapse.active then
|
||||
local collapse_position = surface.find_non_colliding_position('small-biter', collapse_pos, 32, 2)
|
||||
local sizeof = locomotive_positions.tbl[total_pos - total_pos + 1]
|
||||
local get_tile = surface.get_tile(sizeof)
|
||||
if get_tile.valid and get_tile.name == 'out-of-map' then
|
||||
remove(locomotive_positions.tbl, total_pos - total_pos + 1)
|
||||
if check_tile(surface, sizeof, locomotive_positions.tbl, total_pos) then
|
||||
retries = retries + 1
|
||||
|
||||
if retries == 2 then
|
||||
goto continue
|
||||
end
|
||||
@ -848,9 +847,13 @@ local set_spawn_position = function()
|
||||
if total_pos > spawn_near_collapse.total_pos then
|
||||
if l_y - t_y <= spawn_near_collapse.compare then
|
||||
if locomotive_position then
|
||||
if oom then
|
||||
if check_tile(surface, sizeof, locomotive_positions.tbl, total_pos) then
|
||||
debug_str('total_pos was higher - found oom')
|
||||
return
|
||||
retries = retries + 1
|
||||
if retries == 2 then
|
||||
goto continue
|
||||
end
|
||||
goto retry
|
||||
end
|
||||
debug_str('total_pos was higher - spawning at locomotive_position')
|
||||
WD.set_spawn_position(locomotive_position)
|
||||
|
@ -16,9 +16,11 @@ local function create_gui(player)
|
||||
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
|
||||
|
||||
local progressbar = frame.add({type = 'progressbar', name = 'progressbar', value = 0})
|
||||
progressbar.style = 'achievement_progressbar'
|
||||
progressbar.style.minimal_width = 96
|
||||
progressbar.style.maximal_width = 96
|
||||
progressbar.style.top_padding = 10
|
||||
progressbar.style.padding = -1
|
||||
progressbar.style.top_padding = 1
|
||||
|
||||
local line = frame.add({type = 'line', direction = 'vertical'})
|
||||
line.style.left_padding = 4
|
||||
|
Loading…
Reference in New Issue
Block a user