mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Fix Rocket Control
This commit is contained in:
@@ -59,8 +59,8 @@ Storage.register({
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- Gets the silo data for a given silo entity
|
--- Gets the silo data for a given silo entity
|
||||||
-- @tparam LuaEntity silo the rocket silo entity
|
--- @param silo LuaEntity Rocket silo entity
|
||||||
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
|
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
|
||||||
function Rockets.get_silo_data(silo)
|
function Rockets.get_silo_data(silo)
|
||||||
local position = silo.position
|
local position = silo.position
|
||||||
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
|
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
|
||||||
@@ -68,30 +68,30 @@ function Rockets.get_silo_data(silo)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the silo data for a given silo entity
|
--- Gets the silo data for a given silo entity
|
||||||
-- @tparam string silo_name the silo name that is stored in its data
|
--- @param silo_name string Silo name that is stored in its data
|
||||||
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
|
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
|
||||||
function Rockets.get_silo_data_by_name(silo_name)
|
function Rockets.get_silo_data_by_name(silo_name)
|
||||||
return rocket_silos[silo_name]
|
return rocket_silos[silo_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the silo entity from its silo name, reverse to get_silo_data
|
--- Gets the silo entity from its silo name, reverse to get_silo_data
|
||||||
-- @tparam string silo_name the silo name that is stored in its data
|
--- @param silo_name string Silo name that is stored in its data
|
||||||
-- @treturn LuaEntity the rocket silo entity
|
--- @return LuaEntity # Rocket silo entity
|
||||||
function Rockets.get_silo_entity(silo_name)
|
function Rockets.get_silo_entity(silo_name)
|
||||||
local data = rocket_silos[silo_name]
|
local data = rocket_silos[silo_name]
|
||||||
return data.entity
|
return data.entity
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the rocket stats for a force
|
--- Gets the rocket stats for a force
|
||||||
-- @tparam string force_name the name of the force to get the stats for
|
--- @param force_name string Name of the force to get the stats for
|
||||||
-- @treturn table the table of stats for the force
|
--- @return table # Stats for the force
|
||||||
function Rockets.get_stats(force_name)
|
function Rockets.get_stats(force_name)
|
||||||
return rocket_stats[force_name] or {}
|
return rocket_stats[force_name] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets all the rocket silos that belong to a force
|
--- Gets all the rocket silos that belong to a force
|
||||||
-- @tparam string force_name the name of the force to get the silos for
|
--- @param force_name string Name of the force to get the silos for
|
||||||
-- @treturn table an array of silo data that all belong to this force
|
--- @return table # Array of silo data that all belong to this force
|
||||||
function Rockets.get_silos(force_name)
|
function Rockets.get_silos(force_name)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for _, silo_data in pairs(rocket_silos) do
|
for _, silo_data in pairs(rocket_silos) do
|
||||||
@@ -104,23 +104,23 @@ function Rockets.get_silos(force_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the launch time of a given rocket, due to cleaning not all counts are valid
|
--- Gets the launch time of a given rocket, due to cleaning not all counts are valid
|
||||||
-- @tparam string force_name the name of the force to get the count for
|
--- @param force_name string Name of the force to get the count for
|
||||||
-- @tparam number rocket_number the number of the rocket to get the launch time for
|
--- @param rocket_number number Number of the rocket to get the launch time for
|
||||||
-- @treturn number the game tick that the rocket was lanuched on
|
--- @return number? # Game tick that the rocket was launched on
|
||||||
function Rockets.get_rocket_time(force_name, rocket_number)
|
function Rockets.get_rocket_time(force_name, rocket_number)
|
||||||
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
|
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the number of rockets that a force has launched
|
--- Gets the number of rockets that a force has launched
|
||||||
-- @tparam string force_name the name of the force to get the count for
|
--- @param force_name string the name of the force to get the count for
|
||||||
-- @treturn number the number of rockets that the force has launched
|
--- @return number # Number of rockets that the force has launched
|
||||||
function Rockets.get_rocket_count(force_name)
|
function Rockets.get_rocket_count(force_name)
|
||||||
local force = game.forces[force_name]
|
local force = game.forces[force_name]
|
||||||
return force.rockets_launched
|
return force.rockets_launched
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the total number of rockets launched by all forces
|
--- Gets the total number of rockets launched by all forces
|
||||||
-- @treturn number the total number of rockets launched this game
|
--- @return number # Total number of rockets launched this game
|
||||||
function Rockets.get_game_rocket_count()
|
function Rockets.get_game_rocket_count()
|
||||||
local rtn = 0
|
local rtn = 0
|
||||||
for _, force in pairs(game.forces) do
|
for _, force in pairs(game.forces) do
|
||||||
@@ -131,9 +131,9 @@ function Rockets.get_game_rocket_count()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the rolling average time to launch a rocket
|
--- Gets the rolling average time to launch a rocket
|
||||||
-- @tparam string force_name the name of the force to get the average for
|
--- @param force_name string Name of the force to get the average for
|
||||||
-- @tparam number count the distance to get the rolling average over
|
--- @param count number Distance to get the rolling average over
|
||||||
-- @treturn number the number of ticks required to launch one rocket
|
--- @return number # Number of ticks required to launch one rocket
|
||||||
function Rockets.get_rolling_average(force_name, count)
|
function Rockets.get_rolling_average(force_name, count)
|
||||||
local force = game.forces[force_name]
|
local force = game.forces[force_name]
|
||||||
local rocket_count = force.rockets_launched
|
local rocket_count = force.rockets_launched
|
||||||
@@ -147,14 +147,20 @@ function Rockets.get_rolling_average(force_name, count)
|
|||||||
return math.floor((last_launch_time - start_rocket_time) / rocket_count)
|
return math.floor((last_launch_time - start_rocket_time) / rocket_count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- When a launch is trigger it will wait for the silo to reset
|
||||||
|
--- @param event EventData.on_rocket_launch_ordered
|
||||||
|
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
||||||
|
local silo_data = Rockets.get_silo_data(event.rocket_silo)
|
||||||
|
silo_data.launched = silo_data.launched + 1
|
||||||
|
silo_data.awaiting_reset = true
|
||||||
|
end)
|
||||||
|
|
||||||
--- Event used to update the stats and the hui when a rocket is launched
|
--- Event used to update the stats and the hui when a rocket is launched
|
||||||
--- @param event EventData.on_rocket_launched
|
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||||
Event.add(defines.events.on_rocket_launched, function(event)
|
Event.add(defines.events.on_cargo_pod_finished_ascending, function(event)
|
||||||
local entity = event.rocket_silo
|
local force = event.cargo_pod.force
|
||||||
local silo_data = Rockets.get_silo_data(entity)
|
|
||||||
local force = event.rocket_silo.force
|
|
||||||
local force_name = force.name
|
local force_name = force.name
|
||||||
local rockets_launched = force.rockets_launched + 1 -- Hasn't updated when this event fires
|
local rockets_launched = force.rockets_launched
|
||||||
|
|
||||||
--- Handles updates to the rocket stats
|
--- Handles updates to the rocket stats
|
||||||
local stats = rocket_stats[force_name]
|
local stats = rocket_stats[force_name]
|
||||||
@@ -183,16 +189,6 @@ Event.add(defines.events.on_rocket_launched, function(event)
|
|||||||
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
|
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
|
||||||
rocket_times[force_name][remove_rocket] = nil
|
rocket_times[force_name][remove_rocket] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Adds this 1 to the launch count for this silo
|
|
||||||
silo_data.launched = silo_data.launched + 1
|
|
||||||
end)
|
|
||||||
|
|
||||||
--- When a launch is reiggered it will await reset
|
|
||||||
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
|
||||||
local entity = event.rocket_silo
|
|
||||||
local silo_data = Rockets.get_silo_data(entity)
|
|
||||||
silo_data.awaiting_reset = true
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Adds a silo to the list when it is built
|
--- Adds a silo to the list when it is built
|
||||||
|
|||||||
@@ -140,12 +140,13 @@ local rocket_entry =
|
|||||||
-- Add the toggle auto launch if the player is allowed it
|
-- Add the toggle auto launch if the player is allowed it
|
||||||
-- Auto launch was removed from the api and no 2.0 equivalent was added
|
-- Auto launch was removed from the api and no 2.0 equivalent was added
|
||||||
-- https://forums.factorio.com/viewtopic.php?f=28&t=118065&p=656502
|
-- https://forums.factorio.com/viewtopic.php?f=28&t=118065&p=656502
|
||||||
--[[if check_player_permissions(player, "toggle_active") then
|
if check_player_permissions(player, "toggle_active") then
|
||||||
local flow = parent.add{ type = "flow", name = "toggle-" .. silo_name }
|
parent.add{ type = "flow" }
|
||||||
|
--[[local flow = parent.add{ type = "flow", name = "toggle-" .. silo_name }
|
||||||
local button = toggle_launch(flow)
|
local button = toggle_launch(flow)
|
||||||
button.tooltip = silo_data.toggle_tooltip
|
button.tooltip = silo_data.toggle_tooltip
|
||||||
button.sprite = silo_data.toggle_sprite
|
button.sprite = silo_data.toggle_sprite]]
|
||||||
end]]
|
end
|
||||||
|
|
||||||
-- Add the remote launch if the player is allowed it
|
-- Add the remote launch if the player is allowed it
|
||||||
if check_player_permissions(player, "remote_launch") then
|
if check_player_permissions(player, "remote_launch") then
|
||||||
@@ -544,9 +545,9 @@ local function update_rocket_gui_all(force_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Event used to update the stats when a rocket is launched
|
--- Event used to update the stats when a rocket is launched
|
||||||
Event.add(defines.events.on_rocket_launched, function(event)
|
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||||
local force = event.rocket_silo.force
|
Event.add(defines.events.on_cargo_pod_finished_ascending, function(event)
|
||||||
update_rocket_gui_all(force.name)
|
update_rocket_gui_all(event.cargo_pod.force.name)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Update only the progress gui for a force
|
--- Update only the progress gui for a force
|
||||||
@@ -560,11 +561,9 @@ local function update_rocket_gui_progress(force_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Event used to set a rocket silo to be awaiting reset
|
--- Event used to set a rocket silo to be awaiting reset
|
||||||
|
--- @param event EventData.on_rocket_launch_ordered
|
||||||
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
||||||
local silo = event.rocket_silo
|
update_rocket_gui_progress(event.rocket_silo.force.name)
|
||||||
local silo_data = Rockets.get_silo_data(silo)
|
|
||||||
silo_data.awaiting_reset = true
|
|
||||||
update_rocket_gui_progress(silo.force.name)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.on_nth_tick(150, function()
|
Event.on_nth_tick(150, function()
|
||||||
|
|||||||
Reference in New Issue
Block a user