diff --git a/doc/control/Jail.html b/doc/control/Jail.html index ad4f9c45..c417034d 100644 --- a/doc/control/Jail.html +++ b/doc/control/Jail.html @@ -55,6 +55,7 @@ + @@ -1162,7 +1163,7 @@ generated by LDoc diff --git a/doc/control/Production.html b/doc/control/Production.html index 9ed008fd..ff355904 100644 --- a/doc/control/Production.html +++ b/doc/control/Production.html @@ -55,6 +55,7 @@ + @@ -1277,7 +1278,7 @@ generated by LDoc diff --git a/doc/control/Reports.html b/doc/control/Reports.html index 19b67119..a0194414 100644 --- a/doc/control/Reports.html +++ b/doc/control/Reports.html @@ -55,6 +55,7 @@ + @@ -1026,7 +1027,7 @@ generated by LDoc diff --git a/doc/control/Rockets.html b/doc/control/Rockets.html new file mode 100644 index 00000000..1224cd4f --- /dev/null +++ b/doc/control/Rockets.html @@ -0,0 +1,944 @@ + + + + + + + + Rockets control + + + + + + + +
+
+ + + + + + + +
+ + + + + + + + +

Rockets control

+

Control Module - Rockets + - Stores rocket stats for each force.

+

+ + + + + + +

Usage

+

+    -- import the module from the control modules
+    local Rockets = require 'modules.control.rockets'
+
+    -- Some basic information is stored for each silo that has been built
+    -- the data includes: the tick it was built, the rockets launched from it and more
+    Rockets.get_silo_data(rocket_silo_entity)
+
+    -- Some information is also stored for each force
+    Rockets.get_stats('player')
+
+    -- You can get the rocket data for all silos for a force by using get_silos
+    Rockets.get_silos('player')
+
+    -- You can get the launch time for a rocket, meaning what game tick the 50th rocket was launched
+    Rockets.get_rocket_time('player',50)
+
+    -- The rolling average will work out the time to launch one rocket based on the last X rockets
+    Rockets.get_rolling_average('player',10)
+ + + + + + + +

Dependencies

+ + + + + + + + + + + + + + + + +
utils.eventAllows registering event handlers
utils.globalAllows storing in the global table
config.rocketsContains the config for this module
+ + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
get_silo_data(silo)Gets the silo data for a given silo entity
get_silo_data_by_name(silo_name)Gets the silo data for a given silo entity
get_silo_entity(silo_name)Gets the silo entity from its silo name, reverse to get_silo_data
get_stats(force_name)Gets the rocket stats for a force
get_silos(force_name)Gets all the rocket silos that belong to a force
get_rocket_time(force_name, rocket_number)Gets the launch time of a given rocket, due to cleaning not all counts are valid
get_rocket_count(force_name)Gets the number of rockets that a force has launched
get_game_rocket_count()Gets the total number of rockets launched by all forces
get_rolling_average(force_name, count)Gets the rolling average time to launch a rocket
+ + +

Fields

+ + + + + + + + +
silo_data.launchedAdds this 1 to the launch count for this silo
+ + +
+ + +

Dependencies

+
+
+
+
+ # + utils.event +
+
+
+
+ +

Allows registering event handlers

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + utils.global +
+
+
+
+ +

Allows storing in the global table

+

+ + + + + + + + + + + + + + +
+
+
+
+ # + config.rockets +
+
+
+
+ +

Contains the config for this module

+

+ + + + + + + + + + + + + + +
+
+

Functions

+
+
+
+
+ # + get_silo_data(silo) +
+
+
+
+ +

Gets the silo data for a given silo entity

+

+ + + Parameters: + +
    + + + + + +
  • + + silo + + : + + (LuaEntity) + + the rocket silo entity + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + the data table for this silo, contains rockets launch, silo status, and its force +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_silo_data_by_name(silo_name) +
+
+
+
+ +

Gets the silo data for a given silo entity

+

+ + + Parameters: + +
    + + + + + +
  • + + silo_name + + : + + (string) + + the silo name that is stored in its data + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + the data table for this silo, contains rockets launch, silo status, and its force +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_silo_entity(silo_name) +
+
+
+
+ +

Gets the silo entity from its silo name, reverse to get_silo_data

+

+ + + Parameters: + +
    + + + + + +
  • + + silo_name + + : + + (string) + + the silo name that is stored in its data + +
  • + + +
+ + + + + Returns: +
    +
  • + (LuaEntity) + the rocket silo entity +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_stats(force_name) +
+
+
+
+ +

Gets the rocket stats for a force

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to get the stats for + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + the table of stats for the force +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_silos(force_name) +
+
+
+
+ +

Gets all the rocket silos that belong to a force

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to get the silos for + +
  • + + +
+ + + + + Returns: +
    +
  • + (table) + an array of silo data that all belong to this force +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_rocket_time(force_name, rocket_number) +
+
+
+
+ +

Gets the launch time of a given rocket, due to cleaning not all counts are valid

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to get the count for + +
  • + + + + + +
  • + + rocket_number + + : + + (number) + + the number of the rocket to get the launch time for + +
  • + + +
+ + + + + Returns: +
    +
  • + (number) + the game tick that the rocket was lanuched on +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_rocket_count(force_name) +
+
+
+
+ +

Gets the number of rockets that a force has launched

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to get the count for + +
  • + + +
+ + + + + Returns: +
    +
  • + (number) + the number of rockets that the force has launched +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_game_rocket_count() +
+
+
+
+ +

Gets the total number of rockets launched by all forces

+

+ + + + + + Returns: +
    +
  • + (number) + the total number of rockets launched this game +
  • +
+ + + + + + + + + +
+
+
+
+ # + get_rolling_average(force_name, count) +
+
+
+
+ +

Gets the rolling average time to launch a rocket

+

+ + + Parameters: + +
    + + + + + +
  • + + force_name + + : + + (string) + + the name of the force to get the average for + +
  • + + + + + +
  • + + count + + : + + (number) + + the distance to get the rolling average over + +
  • + + +
+ + + + + Returns: +
    +
  • + (number) + the number of ticks required to launch one rocket +
  • +
+ + + + + + + + + +
+
+

Fields

+
+
+
+
+ # + silo_data.launched +
+
+
+
+ +

Adds this 1 to the launch count for this silo

+

+ + + + + + + + + + + + + + +
+
+ + + +
+
+
+ + + + diff --git a/doc/control/Tasks.html b/doc/control/Tasks.html index 99b1a5b8..c47d82cd 100644 --- a/doc/control/Tasks.html +++ b/doc/control/Tasks.html @@ -54,6 +54,7 @@ + @@ -990,7 +991,7 @@ generated by LDoc diff --git a/doc/control/Warnings.html b/doc/control/Warnings.html index 591baa1b..815de7b7 100644 --- a/doc/control/Warnings.html +++ b/doc/control/Warnings.html @@ -54,6 +54,7 @@ + @@ -1419,7 +1420,7 @@ generated by LDoc diff --git a/doc/index.html b/doc/index.html index e9655050..f872e710 100644 --- a/doc/index.html +++ b/doc/index.html @@ -60,6 +60,11 @@ - Adds a way to report players and store report messages. + Rockets + Control Module - Rockets + - Stores rocket stats for each force. + + Tasks Control Module - Tasks - Stores tasks for each force. @@ -391,7 +396,7 @@ generated by LDoc diff --git a/doc/modules/config._file_loader.html b/doc/modules/config._file_loader.html index 65a02b9a..b03f853a 100644 --- a/doc/modules/config._file_loader.html +++ b/doc/modules/config._file_loader.html @@ -112,6 +112,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/config.action_buttons.html b/doc/modules/config.action_buttons.html index 925b8ee8..d6e27bf9 100644 --- a/doc/modules/config.action_buttons.html +++ b/doc/modules/config.action_buttons.html @@ -112,6 +112,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/config.advanced_start.html b/doc/modules/config.advanced_start.html index 101947cb..46f86d5d 100644 --- a/doc/modules/config.advanced_start.html +++ b/doc/modules/config.advanced_start.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.bonuses.html b/doc/modules/config.bonuses.html index d563a677..48090971 100644 --- a/doc/modules/config.bonuses.html +++ b/doc/modules/config.bonuses.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.chat_reply.html b/doc/modules/config.chat_reply.html index 3a386346..2229425f 100644 --- a/doc/modules/config.chat_reply.html +++ b/doc/modules/config.chat_reply.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.death_logger.html b/doc/modules/config.death_logger.html index 86e4c6ac..3b58eef0 100644 --- a/doc/modules/config.death_logger.html +++ b/doc/modules/config.death_logger.html @@ -112,6 +112,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/config.discord_alerts.html b/doc/modules/config.discord_alerts.html index 703540ea..1ec329a3 100644 --- a/doc/modules/config.discord_alerts.html +++ b/doc/modules/config.discord_alerts.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.auth_admin.html b/doc/modules/config.expcore-commands.auth_admin.html index 8836a4c3..e6579a3e 100644 --- a/doc/modules/config.expcore-commands.auth_admin.html +++ b/doc/modules/config.expcore-commands.auth_admin.html @@ -112,6 +112,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.auth_roles.html b/doc/modules/config.expcore-commands.auth_roles.html index 3f91f6cc..d5ec3dc7 100644 --- a/doc/modules/config.expcore-commands.auth_roles.html +++ b/doc/modules/config.expcore-commands.auth_roles.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.auth_runtime_disable.html b/doc/modules/config.expcore-commands.auth_runtime_disable.html index 7b6d4728..4550ddc2 100644 --- a/doc/modules/config.expcore-commands.auth_runtime_disable.html +++ b/doc/modules/config.expcore-commands.auth_runtime_disable.html @@ -112,6 +112,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.parse_general.html b/doc/modules/config.expcore-commands.parse_general.html index 78105732..d6145e86 100644 --- a/doc/modules/config.expcore-commands.parse_general.html +++ b/doc/modules/config.expcore-commands.parse_general.html @@ -112,6 +112,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/config.expcore-commands.parse_roles.html b/doc/modules/config.expcore-commands.parse_roles.html index 0468d949..02a0dec6 100644 --- a/doc/modules/config.expcore-commands.parse_roles.html +++ b/doc/modules/config.expcore-commands.parse_roles.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.permission_groups.html b/doc/modules/config.permission_groups.html index 9cffe3c0..dfdff98c 100644 --- a/doc/modules/config.permission_groups.html +++ b/doc/modules/config.permission_groups.html @@ -112,6 +112,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/config.popup_messages.html b/doc/modules/config.popup_messages.html index 10125ac4..780eb96a 100644 --- a/doc/modules/config.popup_messages.html +++ b/doc/modules/config.popup_messages.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.rockets.html b/doc/modules/config.rockets.html index 376adb6d..c100d0ef 100644 --- a/doc/modules/config.rockets.html +++ b/doc/modules/config.rockets.html @@ -120,6 +120,7 @@ + @@ -268,7 +269,7 @@ generated by LDoc diff --git a/doc/modules/config.roles.html b/doc/modules/config.roles.html index 9deddbdd..ebc9f4e6 100644 --- a/doc/modules/config.roles.html +++ b/doc/modules/config.roles.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.scorched_earth.html b/doc/modules/config.scorched_earth.html index 05be80a1..77beab86 100644 --- a/doc/modules/config.scorched_earth.html +++ b/doc/modules/config.scorched_earth.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.spawn_area.html b/doc/modules/config.spawn_area.html index 481105d9..6064aa21 100644 --- a/doc/modules/config.spawn_area.html +++ b/doc/modules/config.spawn_area.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.warnings.html b/doc/modules/config.warnings.html index 8b6301c6..18afe26e 100644 --- a/doc/modules/config.warnings.html +++ b/doc/modules/config.warnings.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/config.warps.html b/doc/modules/config.warps.html index e1daa0f9..ccd58f86 100644 --- a/doc/modules/config.warps.html +++ b/doc/modules/config.warps.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/control.html b/doc/modules/control.html index 33844193..53371685 100644 --- a/doc/modules/control.html +++ b/doc/modules/control.html @@ -112,6 +112,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/expcore.commands.html b/doc/modules/expcore.commands.html index 4c31a2f2..12371423 100644 --- a/doc/modules/expcore.commands.html +++ b/doc/modules/expcore.commands.html @@ -112,6 +112,7 @@ + @@ -183,7 +184,7 @@ generated by LDoc diff --git a/doc/modules/expcore.common.html b/doc/modules/expcore.common.html index e31c5f07..a1ab355a 100644 --- a/doc/modules/expcore.common.html +++ b/doc/modules/expcore.common.html @@ -120,6 +120,7 @@ + @@ -2266,7 +2267,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.center.html b/doc/modules/expcore.gui.concepts.center.html index 70f42555..789e5d41 100644 --- a/doc/modules/expcore.gui.concepts.center.html +++ b/doc/modules/expcore.gui.concepts.center.html @@ -120,6 +120,7 @@ + @@ -924,7 +925,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.left.html b/doc/modules/expcore.gui.concepts.left.html index 379a1f23..9d7e8f50 100644 --- a/doc/modules/expcore.gui.concepts.left.html +++ b/doc/modules/expcore.gui.concepts.left.html @@ -120,6 +120,7 @@ + @@ -1190,7 +1191,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.popups.html b/doc/modules/expcore.gui.concepts.popups.html index d2ce677d..75c67218 100644 --- a/doc/modules/expcore.gui.concepts.popups.html +++ b/doc/modules/expcore.gui.concepts.popups.html @@ -121,6 +121,7 @@ + @@ -670,7 +671,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.concepts.toolbar.html b/doc/modules/expcore.gui.concepts.toolbar.html index 5bf59e25..2b00f1de 100644 --- a/doc/modules/expcore.gui.concepts.toolbar.html +++ b/doc/modules/expcore.gui.concepts.toolbar.html @@ -120,6 +120,7 @@ + @@ -377,7 +378,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.core.html b/doc/modules/expcore.gui.core.html index b44c870c..354bf65d 100644 --- a/doc/modules/expcore.gui.core.html +++ b/doc/modules/expcore.gui.core.html @@ -112,6 +112,7 @@ + @@ -182,7 +183,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.buttons.html b/doc/modules/expcore.gui.elements.buttons.html index 9b91013f..72738285 100644 --- a/doc/modules/expcore.gui.elements.buttons.html +++ b/doc/modules/expcore.gui.elements.buttons.html @@ -120,6 +120,7 @@ + @@ -520,7 +521,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.checkboxs.html b/doc/modules/expcore.gui.elements.checkboxs.html index c999b155..10dd9f2a 100644 --- a/doc/modules/expcore.gui.elements.checkboxs.html +++ b/doc/modules/expcore.gui.elements.checkboxs.html @@ -120,6 +120,7 @@ + @@ -838,7 +839,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.dropdown.html b/doc/modules/expcore.gui.elements.dropdown.html index 30597af7..982d665a 100644 --- a/doc/modules/expcore.gui.elements.dropdown.html +++ b/doc/modules/expcore.gui.elements.dropdown.html @@ -120,6 +120,7 @@ + @@ -700,7 +701,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.elem-button.html b/doc/modules/expcore.gui.elements.elem-button.html index f1c6593f..5dbe195c 100644 --- a/doc/modules/expcore.gui.elements.elem-button.html +++ b/doc/modules/expcore.gui.elements.elem-button.html @@ -121,6 +121,7 @@ + @@ -396,7 +397,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.progress-bar.html b/doc/modules/expcore.gui.elements.progress-bar.html index c769c914..84edc077 100644 --- a/doc/modules/expcore.gui.elements.progress-bar.html +++ b/doc/modules/expcore.gui.elements.progress-bar.html @@ -120,6 +120,7 @@ + @@ -1141,7 +1142,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.slider.html b/doc/modules/expcore.gui.elements.slider.html index 9e1c7fe9..879a55ae 100644 --- a/doc/modules/expcore.gui.elements.slider.html +++ b/doc/modules/expcore.gui.elements.slider.html @@ -120,6 +120,7 @@ + @@ -471,7 +472,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.elements.text.html b/doc/modules/expcore.gui.elements.text.html index 7cc63511..64a31026 100644 --- a/doc/modules/expcore.gui.elements.text.html +++ b/doc/modules/expcore.gui.elements.text.html @@ -120,6 +120,7 @@ + @@ -517,7 +518,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.html b/doc/modules/expcore.gui.html index f40c4ecf..0c2fdc11 100644 --- a/doc/modules/expcore.gui.html +++ b/doc/modules/expcore.gui.html @@ -112,6 +112,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.instances.html b/doc/modules/expcore.gui.instances.html index 52be8241..117eae7f 100644 --- a/doc/modules/expcore.gui.instances.html +++ b/doc/modules/expcore.gui.instances.html @@ -112,6 +112,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.prototype.html b/doc/modules/expcore.gui.prototype.html index c2a17297..aeaba45b 100644 --- a/doc/modules/expcore.gui.prototype.html +++ b/doc/modules/expcore.gui.prototype.html @@ -121,6 +121,7 @@ + @@ -1411,7 +1412,7 @@ generated by LDoc diff --git a/doc/modules/expcore.gui.test.html b/doc/modules/expcore.gui.test.html index 08d6dc0e..dc444eb2 100644 --- a/doc/modules/expcore.gui.test.html +++ b/doc/modules/expcore.gui.test.html @@ -112,6 +112,7 @@ + @@ -181,7 +182,7 @@ generated by LDoc diff --git a/doc/modules/expcore.permission_groups.html b/doc/modules/expcore.permission_groups.html index b6c5b3a4..2ea7cf39 100644 --- a/doc/modules/expcore.permission_groups.html +++ b/doc/modules/expcore.permission_groups.html @@ -120,6 +120,7 @@ + @@ -1219,7 +1220,7 @@ generated by LDoc diff --git a/doc/modules/expcore.roles.html b/doc/modules/expcore.roles.html index a615db33..cbc0db93 100644 --- a/doc/modules/expcore.roles.html +++ b/doc/modules/expcore.roles.html @@ -120,6 +120,7 @@ + @@ -2691,7 +2692,7 @@ generated by LDoc diff --git a/doc/modules/expcore.store.html b/doc/modules/expcore.store.html index 81ffe376..9a35724b 100644 --- a/doc/modules/expcore.store.html +++ b/doc/modules/expcore.store.html @@ -120,6 +120,7 @@ + @@ -766,7 +767,7 @@ generated by LDoc diff --git a/doc/modules/expcore.sudo.html b/doc/modules/expcore.sudo.html index 98ac29e0..46843afb 100644 --- a/doc/modules/expcore.sudo.html +++ b/doc/modules/expcore.sudo.html @@ -112,6 +112,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/modules.addons.advanced-start.html b/doc/modules/modules.addons.advanced-start.html index 978deeac..82a178fc 100644 --- a/doc/modules/modules.addons.advanced-start.html +++ b/doc/modules/modules.addons.advanced-start.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/modules.addons.chat-popups.html b/doc/modules/modules.addons.chat-popups.html index 28a8c0db..96b0ab72 100644 --- a/doc/modules/modules.addons.chat-popups.html +++ b/doc/modules/modules.addons.chat-popups.html @@ -112,6 +112,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/modules.addons.damage-popups.html b/doc/modules/modules.addons.damage-popups.html index 3d72477d..6037c15f 100644 --- a/doc/modules/modules.addons.damage-popups.html +++ b/doc/modules/modules.addons.damage-popups.html @@ -112,6 +112,7 @@ + @@ -180,7 +181,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.player-list.html b/doc/modules/modules.gui.player-list.html index 6c29676f..e0c91910 100644 --- a/doc/modules/modules.gui.player-list.html +++ b/doc/modules/modules.gui.player-list.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.rocket-info.html b/doc/modules/modules.gui.rocket-info.html index fa840f3a..67dedf45 100644 --- a/doc/modules/modules.gui.rocket-info.html +++ b/doc/modules/modules.gui.rocket-info.html @@ -120,6 +120,7 @@ + @@ -237,7 +238,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.science-info.html b/doc/modules/modules.gui.science-info.html index 768b8fbc..dc452e17 100644 --- a/doc/modules/modules.gui.science-info.html +++ b/doc/modules/modules.gui.science-info.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/modules.gui.task-list.html b/doc/modules/modules.gui.task-list.html index 441ada3f..e92f1e01 100644 --- a/doc/modules/modules.gui.task-list.html +++ b/doc/modules/modules.gui.task-list.html @@ -112,6 +112,7 @@ + @@ -179,7 +180,7 @@ generated by LDoc diff --git a/doc/modules/utils.alien_evolution_progress.html b/doc/modules/utils.alien_evolution_progress.html index 5a755f92..6577ef87 100644 --- a/doc/modules/utils.alien_evolution_progress.html +++ b/doc/modules/utils.alien_evolution_progress.html @@ -120,6 +120,7 @@ + @@ -264,7 +265,7 @@ fraction will decide a chance to spawn. 1 alien for 2 spawners will have 50% on generated by LDoc diff --git a/doc/modules/utils.core.html b/doc/modules/utils.core.html index ed4b920e..74599b61 100644 --- a/doc/modules/utils.core.html +++ b/doc/modules/utils.core.html @@ -121,6 +121,7 @@ + @@ -971,7 +972,7 @@ generated by LDoc diff --git a/doc/modules/utils.debug.html b/doc/modules/utils.debug.html index 21cbca24..f0b0fb4f 100644 --- a/doc/modules/utils.debug.html +++ b/doc/modules/utils.debug.html @@ -120,6 +120,7 @@ + @@ -596,7 +597,7 @@ generated by LDoc diff --git a/doc/modules/utils.event.html b/doc/modules/utils.event.html index 91796216..2d9be1ae 100644 --- a/doc/modules/utils.event.html +++ b/doc/modules/utils.event.html @@ -120,6 +120,7 @@ + @@ -1109,7 +1110,7 @@ generated by LDoc diff --git a/doc/modules/utils.event_core.html b/doc/modules/utils.event_core.html index 19c1bce3..c905d4c0 100644 --- a/doc/modules/utils.event_core.html +++ b/doc/modules/utils.event_core.html @@ -120,6 +120,7 @@ + @@ -376,7 +377,7 @@ generated by LDoc diff --git a/doc/modules/utils.math.html b/doc/modules/utils.math.html index 312b3480..1a2d3b35 100644 --- a/doc/modules/utils.math.html +++ b/doc/modules/utils.math.html @@ -120,6 +120,7 @@ + @@ -280,7 +281,7 @@ generated by LDoc diff --git a/doc/modules/utils.recipe_locker.html b/doc/modules/utils.recipe_locker.html index e053bcb9..2b43095d 100644 --- a/doc/modules/utils.recipe_locker.html +++ b/doc/modules/utils.recipe_locker.html @@ -120,6 +120,7 @@ + @@ -261,7 +262,7 @@ generated by LDoc diff --git a/doc/modules/utils.state_machine.html b/doc/modules/utils.state_machine.html index c8a69a34..dc6fbc2d 100644 --- a/doc/modules/utils.state_machine.html +++ b/doc/modules/utils.state_machine.html @@ -120,6 +120,7 @@ + @@ -653,7 +654,7 @@ generated by LDoc diff --git a/doc/modules/utils.table.html b/doc/modules/utils.table.html index 0755a4f3..2cff6900 100644 --- a/doc/modules/utils.table.html +++ b/doc/modules/utils.table.html @@ -121,6 +121,7 @@ + @@ -1283,7 +1284,7 @@ generated by LDoc diff --git a/doc/modules/utils.task.html b/doc/modules/utils.task.html index 2b8fcbb0..b1c53dca 100644 --- a/doc/modules/utils.task.html +++ b/doc/modules/utils.task.html @@ -120,6 +120,7 @@ + @@ -378,7 +379,7 @@ generated by LDoc diff --git a/doc/modules/utils.timestamp.html b/doc/modules/utils.timestamp.html index 3ab4ce29..c934ba53 100644 --- a/doc/modules/utils.timestamp.html +++ b/doc/modules/utils.timestamp.html @@ -120,6 +120,7 @@ + @@ -384,7 +385,7 @@ generated by LDoc diff --git a/doc/topics/license.html b/doc/topics/license.html index b3ae6425..d0c8b83a 100644 --- a/doc/topics/license.html +++ b/doc/topics/license.html @@ -53,6 +53,7 @@ + @@ -731,7 +732,7 @@ Public License instead of this License. But first, please read generated by LDoc diff --git a/doc/topics/readme.md.html b/doc/topics/readme.md.html index cc8ddc79..49c37f5a 100644 --- a/doc/topics/readme.md.html +++ b/doc/topics/readme.md.html @@ -53,6 +53,7 @@ + @@ -271,7 +272,7 @@ generated by LDoc diff --git a/modules/control/rockets.lua b/modules/control/rockets.lua new file mode 100644 index 00000000..d212cea9 --- /dev/null +++ b/modules/control/rockets.lua @@ -0,0 +1,219 @@ +--[[-- Control Module - Rockets + - Stores rocket stats for each force. + @control Rockets + @alias Rockets + + @usage + -- import the module from the control modules + local Rockets = require 'modules.control.rockets' + + -- Some basic information is stored for each silo that has been built + -- the data includes: the tick it was built, the rockets launched from it and more + Rockets.get_silo_data(rocket_silo_entity) + + -- Some information is also stored for each force + Rockets.get_stats('player') + + -- You can get the rocket data for all silos for a force by using get_silos + Rockets.get_silos('player') + + -- You can get the launch time for a rocket, meaning what game tick the 50th rocket was launched + Rockets.get_rocket_time('player',50) + + -- The rolling average will work out the time to launch one rocket based on the last X rockets + Rockets.get_rolling_average('player',10) + +]] + +--- Allows registering event handlers +-- @dep utils.event +local Event = require 'utils.event' +--- Allows storing in the global table +-- @dep utils.global +local Global = require 'utils.global' +--- Contains the config for this module +-- @dep config.rockets +local config = require 'config.rockets' + +local largest_rolling_avg = 0 +for _,avg_over in pairs(config.stats.rolling_avg) do + if avg_over > largest_rolling_avg then + largest_rolling_avg = avg_over + end +end + +local Rockets = { + times = {}, + stats = {}, + silos = {} +} + +local rocket_times = Rockets.times +local rocket_stats = Rockets.stats +local rocket_silos = Rockets.silos +Global.register({ + rocket_times = rocket_times, + rocket_stats = rocket_stats, + rocket_silos = rocket_silos +},function(tbl) + rocket_times = tbl.rocket_times + rocket_stats = tbl.rocket_stats + rocket_silos = tbl.rocket_silos +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 +function Rockets.get_silo_data(silo) + local position = silo.position + local silo_name = math.floor(position.x)..':'..math.floor(position.y) + return rocket_silos[silo_name] +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 +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 +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 +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 +function Rockets.get_silos(force_name) + local rtn = {} + for _,silo_data in pairs(rocket_silos) do + if silo_data.force == force_name then + table.insert(rtn,silo_data) + end + end + return rtn +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 +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 +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 +function Rockets.get_game_rocket_count() + local rtn = 0 + for _,force in pairs(game.forces) do + rtn = rtn + force.rockets_launched + end + return rtn +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 +function Rockets.get_rolling_average(force_name,count) + local force = game.forces[force_name] + local rocket_count = force.rockets_launched + local start_rocket_time = 0 + if count < rocket_count then + start_rocket_time = rocket_times[force_name][rocket_count-count+1] + rocket_count = count + end + return rocket_count > 0 and math.floor((game.tick-start_rocket_time)/rocket_count) or 0 +end + +--- Event used to update the stats and the hui when a rocket is 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 + local force_name = force.name + local rockets_launched = force.rockets_launched + + --- Handles updates to the rocket stats + local stats = rocket_stats[force_name] + if not stats then + rocket_stats[force_name] = {} + stats = rocket_stats[force_name] + end + + if rockets_launched == 1 then + stats.first_launch = event.tick + stats.fastest_launch = event.tick + elseif event.tick-stats.last_launch < stats.fastest_launch then + stats.fastest_launch = event.tick-stats.last_launch + end + + stats.last_launch = event.tick + + --- Appends the new rocket into the array + if not rocket_times[force_name] then + rocket_times[force_name] = {} + end + + rocket_times[force_name][rockets_launched] = event.tick + + local remove_rocket = rockets_launched-largest_rolling_avg + 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 +local function on_built(event) + local entity = event.created_entity + if entity.valid and entity.name == 'rocket-silo' then + local force = entity.force + local force_name = force.name + local position = entity.position + local silo_name = math.floor(position.x)..':'..math.floor(position.y) + + rocket_silos[silo_name] = { + name=silo_name, + force=force_name, + entity=entity, + launched=0, + awaiting_reset=false, + built=game.tick + } + end +end + +Event.add(defines.events.on_built_entity,on_built) +Event.add(defines.events.on_robot_built_entity,on_built) + +return Rockets \ No newline at end of file diff --git a/modules/gui/rocket-info.lua b/modules/gui/rocket-info.lua index fc286ed3..131513c4 100644 --- a/modules/gui/rocket-info.lua +++ b/modules/gui/rocket-info.lua @@ -3,36 +3,9 @@ local Gui = require 'expcore.gui' local Roles = require 'expcore.roles' local Event = require 'utils.event' local config = require 'config.rockets' -local Global = require 'utils.global' local format_time = ext_require('expcore.common','format_time') local Colors = require 'resources.color_presets' - -local largest_rolling_avg = 0 -for _,avg_over in pairs(config.stats.rolling_avg) do - if avg_over > largest_rolling_avg then - largest_rolling_avg = avg_over - end -end - -local rocket_times = {} -local rocket_stats = {} -local rocket_silos = {} - -Global.register({ - rocket_times = rocket_times, - rocket_stats = rocket_stats, - rocket_silos = rocket_silos -},function(tbl) - rocket_times = tbl.rocket_times - rocket_stats = tbl.rocket_stats - rocket_silos = tbl.rocket_silos -end) - ---- Gets the name used to refrence the the rocket silo -local function get_silo_name(entity) - local position = entity.position - return math.floor(position.x)..':'..math.floor(position.y) -end +local Rockets = require 'modules.control.rockets' --- Gets if a player is allowed to use the action buttons local function player_allowed(player,action) @@ -54,11 +27,9 @@ end --- Used on the name label to allow zoom to map local zoom_to_map_name = Gui.uid_name() Gui.on_click(zoom_to_map_name,function(event) - local force = event.player.force local rocket_silo_name = event.element.parent.caption - local rocket_silo_data = rocket_silos[force.name][rocket_silo_name] - local position = rocket_silo_data.entity.position - event.player.zoom_to_world(position,2) + local rocket_silo = Rockets.get_silo_entity(rocket_silo_name) + event.player.zoom_to_world(rocket_silo.position,2) end) --- Used to launch the rocket, when it is ready @@ -75,11 +46,10 @@ end) style.height = 16 end) :on_click(function(player,element) - local force = player.force local rocket_silo_name = element.parent.name:sub(8) - local rocket_silo_data = rocket_silos[force.name][rocket_silo_name] - if rocket_silo_data.entity.launch_rocket() then - rocket_silo_data.awaiting_reset = true + local silo_data = Rockets.get_silo_data_by_name(rocket_silo_name) + if silo_data.entity.launch_rocket() then + silo_data.awaiting_reset = true element.enabled = false local progress_label = element.parent.parent[rocket_silo_name].label progress_label.caption = {'rocket-info.progress-launched'} @@ -103,18 +73,16 @@ end) style.height = 16 end) :on_click(function(player,element) - local force = player.force local rocket_silo_name = element.parent.name:sub(8) - local rocket_silo_data = rocket_silos[force.name][rocket_silo_name] - local active = rocket_silo_data.entity.auto_launch -- need to test for auto launch - if active then + local rocket_silo = Rockets.get_silo_entity(rocket_silo_name) + if rocket_silo.auto_launch then element.sprite = 'utility/play' element.tooltip = {'rocket-info.toggle-rocket-tooltip'} - rocket_silo_data.entity.auto_launch = false + rocket_silo.auto_launch = false else element.sprite = 'utility/stop' element.tooltip = {'rocket-info.toggle-rocket-tooltip-disabled'} - rocket_silo_data.entity.auto_launch = true + rocket_silo.auto_launch = true end end) @@ -263,28 +231,25 @@ end local function generate_stats(player,frame) if not config.stats.show_stats then return end local element = frame.container.stats.table - local force_rockets = player.force.rockets_launched + local force_name = player.force.name + local force_rockets = Rockets.get_rocket_count(force_name) + local stats = Rockets.get_stats(force_name) if config.stats.show_first_rocket then - create_label_value_pair_time(element,'first-launch',rocket_stats.first_launch or 0) + create_label_value_pair_time(element,'first-launch',stats.first_launch or 0) end if config.stats.show_last_rocket then - create_label_value_pair_time(element,'last-launch',rocket_stats.last_launch or 0) + create_label_value_pair_time(element,'last-launch',stats.last_launch or 0) end if config.stats.show_fastest_rocket then - create_label_value_pair_time(element,'fastest-launch',rocket_stats.fastest_launch or 0,true) + create_label_value_pair_time(element,'fastest-launch',stats.fastest_launch or 0,true) end if config.stats.show_total_rockets then - local total_rockets = 1 - if force_rockets > 0 then - total_rockets = 0 - for _,force in pairs(game.forces) do - total_rockets = total_rockets + force.rockets_launched - end - end + local total_rockets = Rockets.get_game_rocket_count() + total_rockets = total_rockets == 0 and 1 or total_rockets local percentage = math.round(force_rockets/total_rockets,3)*100 create_label_value_pair(element,'total-rockets',force_rockets,{'rocket-info.value-tooltip-total-rockets',percentage}) end @@ -295,14 +260,7 @@ local function generate_stats(player,frame) end for _,avg_over in pairs(config.stats.rolling_avg) do - local rocket_count = avg_over - local first_rocket = 0 - if avg_over < force_rockets then - first_rocket = rocket_times[player.force.name][force_rockets-avg_over+1] - else - rocket_count = force_rockets - end - local avg = rocket_count > 0 and math.floor((game.tick-first_rocket)/rocket_count) or 0 + local avg = Rockets.get_rolling_average(force_name,avg_over) create_label_value_pair_time(element,'avg-launch-n',avg,true,avg_over) end @@ -312,11 +270,12 @@ end local function generate_milestones(player,frame) if not config.milestones.show_milestones then return end local element = frame.container.milestones.table - local force_rockets = player.force.rockets_launched + local force_name = player.force.name + local force_rockets = Rockets.get_rocket_count(force_name) for _,milestone in ipairs(config.milestones) do if milestone <= force_rockets then - local time = rocket_times[player.force.name][milestone] + local time = Rockets.get_rocket_time(force_name,milestone) create_label_value_pair_time(element,'milestone-n',time,false,milestone) else create_label_value_pair_time(element,'milestone-n',0,false,milestone) @@ -326,10 +285,11 @@ local function generate_milestones(player,frame) end --- Creats the different buttons used with the rocket silos -local function generate_progress_buttons(player,element,rocket_silo_data) - local silo_name = rocket_silo_data.name - local status = rocket_silo_data.entity.status == defines.entity_status.waiting_to_launch_rocket - local active = rocket_silo_data.entity.auto_launch +local function generate_progress_buttons(player,element,silo_data) + local silo_name = silo_data.name + local rocket_silo = silo_data.entity + local status = rocket_silo.status == defines.entity_status.waiting_to_launch_rocket + local active = rocket_silo.auto_launch if player_allowed(player,'toggle_active') then local button_element = element['toggle-'..silo_name] @@ -358,7 +318,7 @@ local function generate_progress_buttons(player,element,rocket_silo_data) button_element = launch_rocket(element,silo_name) end - if rocket_silo_data.awaiting_reset then + if silo_data.awaiting_reset then button_element.enabled = false else button_element.enabled = status @@ -383,17 +343,18 @@ local function generate_progress(player,frame) local element = frame.container.progress.table local force = player.force local force_name = force.name - local force_silo_data = rocket_silos[force_name] + local force_silos = Rockets.get_silos(force_name) - if not force_silo_data or table.size(force_silo_data) == 0 then + if not force_silos or table.size(force_silos) == 0 then element.parent.no_silos.visible = true else element.parent.no_silos.visible = false - for silo_name,rocket_silo_data in pairs(force_silo_data) do - if not rocket_silo_data.entity or not rocket_silo_data.entity.valid then - force_silo_data[silo_name] = nil + for _,silo_data in pairs(force_silos) do + local silo_name = silo_data.name + if not silo_data.entity or not silo_data.entity.valid then + force_silos[silo_name] = nil Gui.destory_if_valid(element['toggle-'..silo_name]) Gui.destory_if_valid(element['launch-'..silo_name]) Gui.destory_if_valid(element['label-x-'..silo_name]) @@ -401,14 +362,14 @@ local function generate_progress(player,frame) Gui.destory_if_valid(element[silo_name]) elseif not element[silo_name] then - local entity = rocket_silo_data.entity + local entity = silo_data.entity local progress = entity.rocket_parts local pos = { x=entity.position.x, y=entity.position.y } - generate_progress_buttons(player,element,rocket_silo_data) + generate_progress_buttons(player,element,silo_data) --- Creats two flows and two labels for the X and Y position local name = config.progress.allow_zoom_to_map and zoom_to_map_name or nil @@ -445,30 +406,30 @@ local function generate_progress(player,frame) type='label', name='label', caption={'rocket-info.progress-caption',progress}, - tooltip={'rocket-info.progress-tooltip',rocket_silo_data.launched or 0} + tooltip={'rocket-info.progress-tooltip',silo_data.launched or 0} } else - local entity = rocket_silo_data.entity + local entity = silo_data.entity local progress = entity.rocket_parts local status = entity.status == 21 local label = element[silo_name].label label.caption = {'rocket-info.progress-caption',progress} - label.tooltip = {'rocket-info.progress-tooltip',rocket_silo_data.launched or 0} + label.tooltip = {'rocket-info.progress-tooltip',silo_data.launched or 0} - if status and rocket_silo_data.awaiting_reset then + if status and silo_data.awaiting_reset then label.caption = {'rocket-info.progress-launched'} label.style.font_color = Colors.green elseif status then label.caption = {'rocket-info.progress-caption',100} label.style.font_color = Colors.cyan else - rocket_silo_data.awaiting_reset = false + silo_data.awaiting_reset = false label.style.font_color = Colors.white end - generate_progress_buttons(player,element,rocket_silo_data) + generate_progress_buttons(player,element,silo_data) end end @@ -501,43 +462,10 @@ end) --- Event used to update the stats and the hui when a rocket is launched Event.add(defines.events.on_rocket_launched,function(event) - local entity = event.rocket_silo - local silo_name = get_silo_name(entity) local force = event.rocket_silo.force - local force_name = force.name - local force_silo_data = rocket_silos[force_name] local rockets_launched = force.rockets_launched local first_rocket = rockets_launched == 1 - --- Handles updates to the rocket stats - if not rocket_stats[force_name] then - rocket_stats[force_name] = {} - end - - if first_rocket then - rocket_stats.first_launch = event.tick - rocket_stats.fastest_launch = event.tick - elseif event.tick-rocket_stats.last_launch < rocket_stats.fastest_launch then - rocket_stats.fastest_launch = event.tick-rocket_stats.last_launch - end - - rocket_stats.last_launch = event.tick - - --- Appends the new rocket into the array - if not rocket_times[force_name] then - rocket_times[force_name] = {} - end - - rocket_times[force_name][rockets_launched] = event.tick - - local remove_rocket = rockets_launched-largest_rolling_avg - 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 - force_silo_data[silo_name].launched = force_silo_data[silo_name].launched+1 - --- Updates all the guis (and toolbar since the button may now be visible) for _,player in pairs(force.players) do rocket_info:update(player) @@ -548,34 +476,11 @@ Event.add(defines.events.on_rocket_launched,function(event) end 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_name = get_silo_name(entity) - local force = event.rocket_silo.force - local force_name = force.name - local force_silo_data = rocket_silos[force_name] - force_silo_data[silo_name].awaiting_reset = true -end) - --- Adds a silo to the list when it is built local function on_built(event) local entity = event.created_entity if entity.valid and entity.name == 'rocket-silo' then local force = entity.force - local force_name = force.name - local silo_name = get_silo_name(entity) - - if not rocket_silos[force_name] then - rocket_silos[force_name] = {} - end - - rocket_silos[force_name][silo_name] = { - name=silo_name, - entity=entity, - launched=0, - awaiting_reset=false - } for _,player in pairs(force.players) do local frame = rocket_info:get_frame(player) @@ -590,8 +495,8 @@ Event.add(defines.events.on_robot_built_entity,on_built) --- Optimised update for only the build progress Event.on_nth_tick(150,function() for _,force in pairs(game.forces) do - local silos = rocket_silos[force.name] - if silos then + local silos = Rockets.get_silos(force.name) + if #silos > 0 then for _,player in pairs(force.connected_players) do local frame = rocket_info:get_frame(player) generate_progress(player,frame)