mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Fix Rocket Control
This commit is contained in:
@@ -59,8 +59,8 @@ Storage.register({
|
||||
end)
|
||||
|
||||
--- Gets the silo data for a given silo entity
|
||||
-- @tparam LuaEntity silo the rocket silo entity
|
||||
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
|
||||
--- @param silo LuaEntity Rocket silo entity
|
||||
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
|
||||
function Rockets.get_silo_data(silo)
|
||||
local position = silo.position
|
||||
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
|
||||
@@ -68,30 +68,30 @@ function Rockets.get_silo_data(silo)
|
||||
end
|
||||
|
||||
--- Gets the silo data for a given silo entity
|
||||
-- @tparam string silo_name the silo name that is stored in its data
|
||||
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
|
||||
--- @param silo_name string Silo name that is stored in its data
|
||||
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
|
||||
function Rockets.get_silo_data_by_name(silo_name)
|
||||
return rocket_silos[silo_name]
|
||||
end
|
||||
|
||||
--- 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
|
||||
-- @treturn LuaEntity the rocket silo entity
|
||||
--- @param silo_name string Silo name that is stored in its data
|
||||
--- @return LuaEntity # Rocket silo entity
|
||||
function Rockets.get_silo_entity(silo_name)
|
||||
local data = rocket_silos[silo_name]
|
||||
return data.entity
|
||||
end
|
||||
|
||||
--- Gets the rocket stats for a force
|
||||
-- @tparam string force_name the name of the force to get the stats for
|
||||
-- @treturn table the table of stats for the force
|
||||
--- @param force_name string Name of the force to get the stats for
|
||||
--- @return table # Stats for the force
|
||||
function Rockets.get_stats(force_name)
|
||||
return rocket_stats[force_name] or {}
|
||||
end
|
||||
|
||||
--- Gets all the rocket silos that belong to a force
|
||||
-- @tparam string force_name the name of the force to get the silos for
|
||||
-- @treturn table an array of silo data that all belong to this force
|
||||
--- @param force_name string Name of the force to get the silos for
|
||||
--- @return table # Array of silo data that all belong to this force
|
||||
function Rockets.get_silos(force_name)
|
||||
local rtn = {}
|
||||
for _, silo_data in pairs(rocket_silos) do
|
||||
@@ -104,23 +104,23 @@ function Rockets.get_silos(force_name)
|
||||
end
|
||||
|
||||
--- 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
|
||||
-- @tparam number rocket_number the number of the rocket to get the launch time for
|
||||
-- @treturn number the game tick that the rocket was lanuched on
|
||||
--- @param force_name string Name of the force to get the count for
|
||||
--- @param rocket_number number Number of the rocket to get the launch time for
|
||||
--- @return number? # Game tick that the rocket was launched on
|
||||
function Rockets.get_rocket_time(force_name, rocket_number)
|
||||
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
|
||||
end
|
||||
|
||||
--- Gets the number of rockets that a force has launched
|
||||
-- @tparam string force_name the name of the force to get the count for
|
||||
-- @treturn number the number of rockets that the force has launched
|
||||
--- @param force_name string the name of the force to get the count for
|
||||
--- @return number # Number of rockets that the force has launched
|
||||
function Rockets.get_rocket_count(force_name)
|
||||
local force = game.forces[force_name]
|
||||
return force.rockets_launched
|
||||
end
|
||||
|
||||
--- 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()
|
||||
local rtn = 0
|
||||
for _, force in pairs(game.forces) do
|
||||
@@ -131,9 +131,9 @@ function Rockets.get_game_rocket_count()
|
||||
end
|
||||
|
||||
--- Gets the rolling average time to launch a rocket
|
||||
-- @tparam string force_name the name of the force to get the average for
|
||||
-- @tparam number count the distance to get the rolling average over
|
||||
-- @treturn number the number of ticks required to launch one rocket
|
||||
--- @param force_name string Name of the force to get the average for
|
||||
--- @param count number Distance to get the rolling average over
|
||||
--- @return number # Number of ticks required to launch one rocket
|
||||
function Rockets.get_rolling_average(force_name, count)
|
||||
local force = game.forces[force_name]
|
||||
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)
|
||||
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
|
||||
--- @param event EventData.on_rocket_launched
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
local entity = event.rocket_silo
|
||||
local silo_data = Rockets.get_silo_data(entity)
|
||||
local force = event.rocket_silo.force
|
||||
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||
Event.add(defines.events.on_cargo_pod_finished_ascending, function(event)
|
||||
local force = event.cargo_pod.force
|
||||
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
|
||||
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
|
||||
rocket_times[force_name][remove_rocket] = nil
|
||||
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)
|
||||
|
||||
--- 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
|
||||
-- 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
|
||||
--[[if check_player_permissions(player, "toggle_active") then
|
||||
local flow = parent.add{ type = "flow", name = "toggle-" .. silo_name }
|
||||
if check_player_permissions(player, "toggle_active") then
|
||||
parent.add{ type = "flow" }
|
||||
--[[local flow = parent.add{ type = "flow", name = "toggle-" .. silo_name }
|
||||
local button = toggle_launch(flow)
|
||||
button.tooltip = silo_data.toggle_tooltip
|
||||
button.sprite = silo_data.toggle_sprite
|
||||
end]]
|
||||
button.sprite = silo_data.toggle_sprite]]
|
||||
end
|
||||
|
||||
-- Add the remote launch if the player is allowed it
|
||||
if check_player_permissions(player, "remote_launch") then
|
||||
@@ -544,9 +545,9 @@ local function update_rocket_gui_all(force_name)
|
||||
end
|
||||
|
||||
--- Event used to update the stats when a rocket is launched
|
||||
Event.add(defines.events.on_rocket_launched, function(event)
|
||||
local force = event.rocket_silo.force
|
||||
update_rocket_gui_all(force.name)
|
||||
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||
Event.add(defines.events.on_cargo_pod_finished_ascending, function(event)
|
||||
update_rocket_gui_all(event.cargo_pod.force.name)
|
||||
end)
|
||||
|
||||
--- Update only the progress gui for a force
|
||||
@@ -560,11 +561,9 @@ local function update_rocket_gui_progress(force_name)
|
||||
end
|
||||
|
||||
--- 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)
|
||||
local silo = event.rocket_silo
|
||||
local silo_data = Rockets.get_silo_data(silo)
|
||||
silo_data.awaiting_reset = true
|
||||
update_rocket_gui_progress(silo.force.name)
|
||||
update_rocket_gui_progress(event.rocket_silo.force.name)
|
||||
end)
|
||||
|
||||
Event.on_nth_tick(150, function()
|
||||
|
||||
Reference in New Issue
Block a user