From 26e1c28dc07968d8882b0d9102730d58f02d534a Mon Sep 17 00:00:00 2001 From: RedRafe <93430988+RedRafe@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:22:35 +0200 Subject: [PATCH] Factorio 2.0 update (#1436) * Init Factorio 2.0 update * add credits * fix test module * I know luackeck, I know * Fixes * Fix bad event.player_index handling * Hotfixes * Remove all filter inserters * Migrate removed items * Deprecating spidertron control and landfill features --- .gitignore | 1 + .luacheckrc | 216 +++++++++++++----- .travis/release_builder.sh | 2 +- config.lua | 22 +- features/admin_commands.lua | 48 ++-- features/antigrief.lua | 40 ++-- features/apocalypse.lua | 4 +- features/auto_stash.lua | 104 +++++---- features/autodeconstruct.lua | 2 +- features/autofill.lua | 7 +- features/battery_charge.lua | 22 +- features/biter_corpse_remover.lua | 6 +- features/chat_triggers.lua | 18 +- features/cutscene/cutscene_controller.lua | 48 ++-- features/cutscene/rendering.lua | 22 +- features/death_corpse_tags.lua | 4 +- features/death_corpse_tags_tests.lua | 10 +- features/donator.lua | 10 +- features/donator_commands.lua | 4 +- features/dump_offline_inventories.lua | 4 +- features/enemy_turret.lua | 14 +- features/fish_burps.lua | 7 +- features/force_control.lua | 2 +- features/gui/admin_panel/core.lua | 4 +- features/gui/admin_panel/functions.lua | 4 +- features/gui/admin_panel/lua_console.lua | 2 +- features/gui/admin_panel/map_manager.lua | 5 +- features/gui/admin_panel/player_manager.lua | 1 - features/gui/camera.lua | 14 +- features/gui/debug/_g_view.lua | 6 +- features/gui/debug/command.lua | 2 +- features/gui/debug/event_view.lua | 12 +- features/gui/debug/global_view.lua | 6 +- features/gui/debug/gui_data_view.lua | 2 +- features/gui/debug/redmew_global_view.lua | 2 +- features/gui/description_generator.lua | 2 +- features/gui/evolution_progress.lua | 3 +- features/gui/info.lua | 8 +- features/gui/paint.lua | 4 +- features/gui/player_list.lua | 6 +- features/gui/poll.lua | 2 +- features/gui/popup.lua | 4 +- features/gui/radio.lua | 2 +- features/gui/redmew_settings.lua | 7 +- features/gui/score.lua | 6 +- features/gui/tag_group.lua | 4 +- features/gui/tasklist.lua | 4 +- features/gui/toast.lua | 2 +- features/harmful_mining.lua | 9 +- features/infinite_storage_chest.lua | 24 +- features/landfill_remover.lua | 3 +- features/landfill_remover_tests.lua | 2 +- features/lazy_bastard.lua | 12 +- features/market.lua | 11 +- features/nuke_control.lua | 7 +- features/permissions.lua | 2 +- features/player_colors.lua | 2 +- features/player_create.lua | 20 +- features/player_logistic_requests.lua | 9 +- features/player_quick_bars.lua | 4 +- features/player_stats.lua | 20 +- features/popup_chat.lua | 15 +- features/price_raffle.lua | 19 +- features/rank_system.lua | 2 +- features/reactor_meltdown.lua | 10 +- features/redmew_commands.lua | 8 +- features/redmew_qol.lua | 32 +-- features/report.lua | 4 +- features/research_printer.lua | 2 +- features/retailer.lua | 2 +- features/scenario_data_manipulation.lua | 16 +- features/server.lua | 10 +- features/server_commands.lua | 2 +- features/spidertron_group_control.lua | 21 +- features/train_saviour.lua | 21 +- features/turret_active_delay.lua | 2 +- locale/cs/redmew_command_text.cfg | 2 +- locale/en/redmew_command_text.cfg | 2 +- locale/en/redmew_features.cfg | 1 + locale/es-ES/redmew_command_text.cfg | 2 +- locale/fi/redmew_command_text.cfg | 2 +- locale/fr/redmew_command_text.cfg | 2 +- locale/nl/redmew_command_text.cfg | 2 +- locale/no/redmew_command_text.cfg | 2 +- locale/pt-BR/redmew_command_text.cfg | 2 +- locale/ru/redmew_command_text.cfg | 2 +- locale/uk/redmew_command_text.cfg | 2 +- locale/zh-CN/redmew_command_text.cfg | 2 +- map_gen/entities/fluffy_rainbows.lua | 4 +- map_gen/entities/neko_crazy_ores.lua | 14 +- map_gen/entities/rail_grid.lua | 8 +- map_gen/entities/resource_clustertruck.lua | 6 +- map_gen/maps/1000x.lua | 5 +- map_gen/maps/HilbertSandTrap.lua | 8 +- map_gen/maps/april_fools/2019.lua | 10 +- map_gen/maps/april_fools/2024.lua | 14 +- .../modules/alternative_biters.lua | 4 +- .../april_fools/modules/crazy_toolbar.lua | 2 +- .../april_fools/modules/enemy_turrets.lua | 2 +- .../april_fools/modules/floor_is_lava.lua | 2 +- .../maps/april_fools/modules/golden_goose.lua | 4 +- map_gen/maps/april_fools/modules/meteOres.lua | 2 +- .../april_fools/modules/permanent_factory.lua | 2 +- .../maps/april_fools/modules/random_ores.lua | 2 +- .../april_fools/modules/rotate_inserters.lua | 2 +- .../maps/april_fools/modules/rotten_egg.lua | 4 +- map_gen/maps/april_fools/scenario/camera.lua | 12 +- .../april_fools/scenario/cave_collapse.lua | 9 +- .../scenario/entity-restrictions.lua | 7 +- .../scenario/evolution_control.lua | 7 +- map_gen/maps/april_fools/scenario/market.lua | 14 +- .../april_fools/scenario/market_items.lua | 3 +- map_gen/maps/april_fools/scenario/mines.lua | 15 +- .../april_fools/scenario/restart_command.lua | 4 +- .../april_fools/scenario/rocket_launched.lua | 2 +- .../april_fools/scenario/rocket_waves.lua | 18 +- map_gen/maps/christmas_tree_of_terror.lua | 7 +- map_gen/maps/concrete_jungle.lua | 25 +- .../maps/crash_site/blueprint_extractor.lua | 2 +- map_gen/maps/crash_site/commands.lua | 33 +-- map_gen/maps/crash_site/crash_site_toast.lua | 10 +- map_gen/maps/crash_site/cutscene.lua | 14 +- map_gen/maps/crash_site/events.lua | 16 +- .../features/deconstruction_targetting.lua | 4 +- .../maps/crash_site/features/rocket_tanks.lua | 8 +- .../maps/crash_site/features/sandworms.lua | 21 +- .../features/vehicle_repair_beams.lua | 6 +- map_gen/maps/crash_site/outpost_builder.lua | 10 +- .../outpost_data/big_circuit_factory.lua | 11 +- .../outpost_data/big_weapon_factory.lua | 4 +- .../outpost_data/medium_weapon_factory.lua | 2 +- map_gen/maps/crash_site/scenario.lua | 4 +- map_gen/maps/crash_site/weapon_balance.lua | 5 +- .../config/pyanodon_allowed_entities.lua | 2 - .../danger_ores/modules/banned_entities.lua | 2 +- .../maps/danger_ores/modules/biter_drops.lua | 2 +- .../modules/biter_drops_exotic_industries.lua | 2 +- .../modules/concrete_on_landfill.lua | 2 +- .../danger_ores/modules/container_dump.lua | 8 +- map_gen/maps/danger_ores/modules/expanse.lua | 40 ++-- .../remove_non_ore_stacked_recipes.lua | 2 +- .../danger_ores/modules/restart_command.lua | 4 +- .../danger_ores/modules/rocket_launched.lua | 17 +- .../rocket_launched_exotic_industries.lua | 2 +- .../modules/rocket_launched_krastorio2.lua | 2 +- .../modules/rocket_launched_pyanodon.lua | 2 +- .../modules/rocket_launched_simple.lua | 2 +- .../maps/danger_ores/modules/terraforming.lua | 16 +- .../danger_ores/presets/danger_bobs_ores.lua | 4 +- .../danger_ore_3way_beltboxes_ore_only.lua | 2 +- .../danger_ores/presets/danger_ore_bz.lua | 2 +- ...nger_ore_chessboard_beltboxes_ore_only.lua | 2 +- ..._chessboard_uniform_beltboxes_ore_only.lua | 2 +- .../danger_ore_circles_beltboxes_ore_only.lua | 2 +- .../presets/danger_ore_deadlock_beltboxes.lua | 2 +- ...danger_ore_deadlock_beltboxes_ore_only.lua | 2 +- .../presets/danger_ore_exotic_industries.lua | 2 +- .../danger_ore_exotic_industries_spiral.lua | 4 +- .../presets/danger_ore_expanse.lua | 2 +- ...ensive_grid_factory_beltboxes_ore_only.lua | 2 +- ...danger_ore_gradient_beltboxes_ore_only.lua | 2 +- ...nger_ore_hub_spiral_beltboxes_ore_only.lua | 2 +- .../danger_ore_industrial_revolution_3.lua | 2 +- ...e_industrial_revolution_3_grid_factory.lua | 2 +- .../presets/danger_ore_krastorio2.lua | 4 +- .../presets/danger_ore_landfill.lua | 1 + ...danger_ore_landfill_beltboxes_ore_only.lua | 4 +- ...danger_ore_lazy_one_beltboxes_ore_only.lua | 4 +- .../presets/danger_ore_omnimatter.lua | 4 +- .../presets/danger_ore_omnimatter_cages.lua | 4 +- .../danger_ore_one_direction_beltboxes.lua | 2 +- ...r_ore_one_direction_beltboxes_ore_only.lua | 2 +- ..._one_direction_wide_beltboxes_ore_only.lua | 2 +- .../danger_ore_patches_beltboxes_ore_only.lua | 2 +- ..._patches_beltboxes_ore_only_restricted.lua | 2 +- .../danger_ore_poor_mans_coal_fields.lua | 2 +- .../danger_ores/presets/danger_ore_pyfe.lua | 5 +- .../danger_ores/presets/danger_ore_scrap.lua | 4 +- .../danger_ores/presets/danger_ore_spiral.lua | 1 + .../danger_ore_spiral_beltboxes_ore_only.lua | 4 +- .../danger_ore_split_beltboxes_ore_only.lua | 2 +- .../danger_ore_square_beltboxes_ore_only.lua | 2 +- ...anger_ore_xmas_tree_beltboxes_ore_only.lua | 2 +- map_gen/maps/deprecated_borg_planet_v2.lua | 4 +- map_gen/maps/diggy/debug.lua | 44 +++- map_gen/maps/diggy/feature/alien_spawner.lua | 15 +- map_gen/maps/diggy/feature/coin_gathering.lua | 2 +- map_gen/maps/diggy/feature/cutscene.lua | 18 +- .../diggy/feature/diggy_cave_collapse.lua | 11 +- map_gen/maps/diggy/feature/diggy_hole.lua | 6 +- map_gen/maps/diggy/feature/experience.lua | 32 +-- map_gen/maps/diggy/feature/night_time.lua | 2 +- .../maps/diggy/feature/restart_command.lua | 6 +- map_gen/maps/diggy/feature/setup_player.lua | 2 +- map_gen/maps/diggy/feature/weapon_balance.lua | 2 +- map_gen/maps/diggy/presets/danger_ores.lua | 6 +- .../maps/diggy/presets/danger_ores_BnB.lua | 6 +- map_gen/maps/diggy/presets/normal.lua | 6 +- map_gen/maps/diggy/scenario.lua | 8 +- map_gen/maps/diggy/template.lua | 4 +- map_gen/maps/dimensions.lua | 62 ++--- map_gen/maps/dino_island.lua | 6 +- map_gen/maps/frontier/modules/enemy.lua | 30 +-- map_gen/maps/frontier/modules/lobby.lua | 4 +- map_gen/maps/frontier/modules/market.lua | 4 +- map_gen/maps/frontier/modules/restart.lua | 12 +- map_gen/maps/frontier/modules/rocket_silo.lua | 6 +- map_gen/maps/frontier/modules/spawn_shop.lua | 20 +- map_gen/maps/frontier/modules/terrain.lua | 4 +- map_gen/maps/frontier/scenario.lua | 10 +- map_gen/maps/frontier/shared/debug.lua | 4 +- map_gen/maps/fruit_loops.lua | 2 +- map_gen/maps/grid_bot_islands.lua | 10 +- map_gen/maps/hilbert_water_trap.lua | 2 +- map_gen/maps/maze_krastorio2.lua | 3 +- map_gen/maps/meteor_strike.lua | 34 +-- map_gen/maps/quadrants/enabled_recipes.lua | 11 +- map_gen/maps/quadrants/force_sync.lua | 4 +- map_gen/maps/quadrants/item_to_chest.lua | 13 +- map_gen/maps/quadrants/restrict_placement.lua | 6 +- map_gen/maps/quadrants/scenario.lua | 2 +- map_gen/maps/quadrants/switch_team.lua | 14 +- map_gen/maps/quadrants/train_crossing.lua | 6 +- .../maps/rail_grid/rail_grid_restrictions.lua | 2 +- map_gen/maps/safety_ores.lua | 7 +- map_gen/maps/sierpinski_carpet.lua | 2 +- map_gen/maps/snake_demo.lua | 2 +- map_gen/maps/solid_rock.lua | 2 +- map_gen/maps/space_race/gui/join_gui.lua | 2 +- map_gen/maps/space_race/gui/load_gui.lua | 2 +- map_gen/maps/space_race/gui/wait_gui.lua | 2 +- map_gen/maps/space_race/gui/won_gui.lua | 2 +- map_gen/maps/space_race/lobby.lua | 3 +- .../space_race/map_gen/uranium_island.lua | 2 +- map_gen/maps/space_race/market_handler.lua | 6 +- map_gen/maps/space_race/scenario.lua | 13 +- map_gen/maps/terra.lua | 4 +- map_gen/maps/tetris/scenario.lua | 10 +- map_gen/maps/tetris/tetrimino.lua | 2 +- map_gen/maps/toxic_science_jungle.lua | 9 +- map_gen/maps/triangle_of_death.lua | 7 +- map_gen/shared/biter_attacks.lua | 16 +- map_gen/shared/day_night.lua | 2 +- .../shared/entity_placement_restriction.lua | 38 +-- map_gen/shared/hail_hydra.lua | 18 +- map_gen/shared/loot_items.lua | 3 +- map_gen/shared/map_loader.lua | 2 +- map_gen/shared/naughty_words.lua | 4 +- map_gen/shared/redmew_surface.lua | 2 +- map_gen/shared/restrict_landfill_tile.lua | 6 +- map_gen/shared/spawn_control.lua | 46 ++-- map_gen/shared/wreck_items.lua | 4 +- resources/item_list.lua | 12 +- resources/map_gen_settings.lua | 2 +- resources/market_items.lua | 5 +- resources/player_sprites.lua | 4 +- resources/styles.lua | 6 +- resources/tag_groups.lua | 2 +- resources/version.lua | 2 +- scenario_templates/test/map_selection.lua | 2 +- utils/alien_evolution_progress.lua | 2 +- utils/command.lua | 5 +- utils/core.lua | 10 +- utils/debug.lua | 6 +- utils/dump_env.lua | 2 +- utils/error_logging.lua | 6 +- utils/event.lua | 6 +- utils/event_core.lua | 2 +- utils/game.lua | 61 ++--- utils/global.lua | 6 +- utils/gui.lua | 4 +- utils/locale_builder.lua | 2 +- utils/logistic_point.lua | 72 ++++++ utils/player_rewards.lua | 8 +- utils/recipe_locker.lua | 2 +- utils/rendering.lua | 28 +-- utils/sounds.lua | 2 +- utils/space_age.lua | 7 + utils/table.lua | 13 ++ utils/test/discovery.lua | 7 +- utils/test/include.lua | 2 +- utils/test/runner.lua | 8 +- utils/token.lua | 10 +- 283 files changed, 1374 insertions(+), 1202 deletions(-) create mode 100644 utils/logistic_point.lua create mode 100644 utils/space_age.lua diff --git a/.gitignore b/.gitignore index 98635664..1d43bc17 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /map_selection.lua +.vscode \ No newline at end of file diff --git a/.luacheckrc b/.luacheckrc index babe20f8..5e91f771 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -202,7 +202,7 @@ stds.factorio_control = { "get_player_settings", startup = {read_only = false, other_fields = true}, global = {read_only = false, other_fields = true}, - player = {read_only = false, other_fields = true}, + player_default = {read_only = false, other_fields = true}, }, }, @@ -211,21 +211,25 @@ stds.factorio_control = { script = { fields = { 'active_mods', + 'feature_flags', + 'get_event_handler', + 'get_event_order', + 'level', + 'mod_name', 'on_configuration_changed', - 'raise_event', + 'raise_biter_base_built', 'raise_console_chat', + 'raise_event', + 'raise_market_item_purchased', 'raise_player_crafted_item', 'raise_player_fast_transferred', - 'raise_biter_base_built', - 'raise_market_item_purchased', 'raise_script_built', 'raise_script_destroy', 'raise_script_revive', 'raise_script_set_tiles', - 'get_event_handler', - 'mod_name', - 'get_event_order', - 'register_on_entity_destroyed' + 'raise_script_teleported', + 'register_metatable', + 'register_on_object_destroyed', }, other_fields = false, }, @@ -339,6 +343,25 @@ stds.factorio_control = { } }, + helpers = { + other_fields = false, + read_only = true, + fields = { + "check_prototype_translations", + "decode_string", + "direction_to_string", + "encode_string", + "evaluate_expression", + "is_valid_sound_path", + "is_valid_sprite_path", + "json_to_table", + "parse_map_exchange_string", + "remove_path", + "table_to_json", + "write_file", + } + }, + -- @game@: Main object through which most of the API is accessed. -- It is, however, not available inside handlers registered with @script.on_load@. -- (http://lua-api.factorio.com/latest/LuaGameScript.html) @@ -348,102 +371,156 @@ stds.factorio_control = { fields = { "auto_save", "ban_player", - "check_consistency", - "check_prototype_translations", - "count_pipe_groups", + "check_consistency", "create_force", "create_profiler", "create_random_generator", "create_surface", "delete_surface", "desync_players", - "direction_to_string", "disable_replay", "disable_tips_and_tricks", "draw_resource_selection", + "enable_tip_triggers_in_custom_scenarios", "force_crc", - "get_active_entities_count", "get_entity_by_tag", + "get_entity_by_unit_number", "get_filtered_entity_prototypes", "get_map_exchange_string", "get_player", "get_surface", + "get_vehicles", "help", "is_demo", "is_multiplayer", - "is_valid_sound_path", - "json_to_table", "kick_player", "merge_forces", "mute_player", + "planet", + "planets", "play_sound", - "print", "print_stack_size", + "print", "purge_player", "regenerate_entity", "reload_mods", "reload_script", "remove_offline_players", - "remove_path", "reset_game_state", "reset_time_played", "save_atlas", "server_save", "set_game_state", + "set_lose_ending_info", + "set_win_ending_info", "show_message_dialog", - "table_to_json", "take_screenshot", "take_technology_screenshot", + "technology_notifications_enabled", + "train_manager", "unban_player", "unmute_player", - "write_file", - - active_mods = {read_only = true, other_fields = true}, - ammo_category_prototypes = {read_only = true, other_fields = true}, - autoplace_control_prototypes = {read_only = true, other_fields = true}, + backer_names = {read_only = true, other_fields = true}, + blueprints = {read_only = true, other_fields = true}, connected_players = {read_only = true, other_fields = true}, - custom_input_prototypes = {read_only = true, other_fields = true}, - damage_prototypes = {read_only = true, other_fields = true}, - decorative_prototypes = {read_only = true, other_fields = true}, default_map_gen_settings = {read_only = true, other_fields = true}, difficulty = {read_only = true, other_fields = true}, difficulty_settings = {read_only = true, other_fields = true}, enemy_has_vision_on_land_mines = {read_only = false, other_fields = false}, - entity_prototypes = {read_only = true, other_fields = true}, - equipment_grid_prototypes = {read_only = true, other_fields = true}, - equipment_prototypes = {read_only = true, other_fields = true}, finished = {read_only = true, other_fields = true}, - fluid_prototypes = {read_only = true, other_fields = true}, + finished_but_continuing = {read_only = true, other_fields = false}, forces = {read_only = true, other_fields = true}, - item_prototypes = {read_only = true, other_fields = true}, map_settings = {read_only = true, other_fields = true}, - mod_setting_prototypes = {read_only = true, other_fields = true}, - noise_layer_prototypes = {read_only = true, other_fields = true}, permissions = {read_only = true, other_fields = true}, player = {read_only = true, other_fields = true}, players = {read_only = true, other_fields = true}, - recipe_prototypes = {read_only = true, other_fields = true}, speed = {read_only = false, other_fields = false}, styles = {read_only = true, other_fields = true}, surfaces = {read_only = true, other_fields = true}, - technology_prototypes = {read_only = true, other_fields = true}, tick = {read_only = true, other_fields = true}, tick_paused = {read_only = false, other_fields = false}, ticks_played = {read_only = true, other_fields = true}, ticks_to_run = {read_only = false, other_fields = false}, - tile_prototypes = {read_only = true, other_fields = true}, - virtual_signal_prototypes = {read_only = true, other_fields = true}, - finished_but_continuing = {read_only = true, other_fields = false} }, }, + + prototypes = { + other_fields = false, + read_only = true, + fields = { + "get_achievement_filtered", + "get_decorative_filtered", + "get_entity_filtered", + "get_equipment_filtered", + "get_fluid_filtered", + "get_history", + "get_item_filtered", + "get_mod_setting_filtered", + "get_recipe_filtered", + "get_technology_filtered", + "get_tile_filtered", + achievement = {read_only = true, other_fields = true}, + active_trigger = {read_only = true, other_fields = true}, + airborne_pollutant = {read_only = true, other_fields = true}, + ammo_category = {read_only = true, other_fields = true}, + asteroid_chunk = {read_only = true, other_fields = true}, + autoplace_control = {read_only = true, other_fields = true}, + burner_usage = {read_only = true, other_fields = true}, + collision_layer = {read_only = true, other_fields = true}, + custom_event = {read_only = true, other_fields = true}, + custom_input = {read_only = true, other_fields = true}, + damage = {read_only = true, other_fields = true}, + decorative = {read_only = true, other_fields = true}, + entity = {read_only = true, other_fields = true}, + equipment = {read_only = true, other_fields = true}, + equipment_category = {read_only = true, other_fields = true}, + equipment_grid = {read_only = true, other_fields = true}, + fluid = {read_only = true, other_fields = true}, + font = {read_only = true, other_fields = true}, + fuel_category = {read_only = true, other_fields = true}, + item = {read_only = true, other_fields = true}, + item_group = {read_only = true, other_fields = true}, + item_subgroup = {read_only = true, other_fields = true}, + map_gen_preset = {read_only = true, other_fields = true}, + mod_setting = {read_only = true, other_fields = true}, + module_category = {read_only = true, other_fields = true}, + named_noise_expression = {read_only = true, other_fields = true}, + named_noise_function = {read_only = true, other_fields = true}, + particle = {read_only = true, other_fields = true}, + procession = {read_only = true, other_fields = true}, + procession_layer_inheritance_group = {read_only = true, other_fields = true}, + quality = {read_only = true, other_fields = true}, + recipe_category = {read_only = true, other_fields = true}, + resource_category = {read_only = true, other_fields = true}, + shortcut = {read_only = true, other_fields = true}, + space_connection = {read_only = true, other_fields = true}, + space_location = {read_only = true, other_fields = true}, + style = {read_only = true, other_fields = true}, + surface = {read_only = true, other_fields = true}, + surface_property = {read_only = true, other_fields = true}, + technology = {read_only = true, other_fields = true}, + tile = {read_only = true, other_fields = true}, + trivial_smoke = {read_only = true, other_fields = true}, + virtual_signal = {read_only = true, other_fields = true}, + "max_beacon_supply_area_distance", + "max_electric_pole_connection_distance", + "max_electric_pole_supply_area_distance", + "max_force_distraction_chunk_distance", + "max_force_distraction_distance", + "max_gate_activation_distance", + "max_inserter_reach_distance", + "max_pipe_to_ground_distance", + "max_underground_belt_distance", + } + }, }, globals = { -- @global@: The global dictionary, useful for storing data persistent across a save-load cycle. -- Writing access is given to the mod-id field (for mod-wise saved data). -- (http://lua-api.factorio.com/latest/Global.html) - "global", + "storage", -- @MOD@: Keep it organized, use this variable for anything that "NEEDS" to be global for some reason. "MOD" @@ -896,7 +973,8 @@ stds.factorio_defines = { 'editor', 'ghost', 'god', - 'spectator' + 'spectator', + 'remote', } }, deconstruction_item = { @@ -963,14 +1041,22 @@ stds.factorio_defines = { }, direction = { fields = { - 'east', - 'north', - 'northeast', - 'northwest', - 'south', - 'southeast', - 'southwest', - 'west' + 'north', + 'northnortheast', + 'northeast', + 'eastnortheast', + 'east', + 'eastsoutheast', + 'southeast', + 'southsoutheast', + 'south', + 'southsouthwest', + 'southwest', + 'westsouthwest', + 'west', + 'westnorthwest', + 'northwest', + 'northnorthwest', } }, distraction = { @@ -1017,6 +1103,7 @@ stds.factorio_defines = { }, events = { fields = { + 'on_achievement_gained', 'on_ai_command_completed', 'on_area_cloned', 'on_biter_base_built', @@ -1038,7 +1125,6 @@ stds.factorio_defines = { 'on_entity_cloned', 'on_entity_damaged', 'on_entity_died', - 'on_entity_destroyed', 'on_entity_renamed', 'on_entity_settings_pasted', 'on_entity_spawned', @@ -1061,6 +1147,7 @@ stds.factorio_defines = { 'on_marked_for_upgrade', 'on_market_item_purchased', 'on_mod_item_opened', + 'on_object_destroyed', 'on_picked_up_item', 'on_player_alt_selected_area', 'on_player_ammo_inventory_changed', @@ -1074,6 +1161,7 @@ stds.factorio_defines = { 'on_player_cheat_mode_disabled', 'on_player_cheat_mode_enabled', 'on_player_configured_blueprint', + 'on_player_controller_changed', 'on_player_crafted_item', 'on_player_created', 'on_player_cursor_stack_changed', @@ -1089,6 +1177,7 @@ stds.factorio_defines = { 'on_player_joined_game', 'on_player_kicked', 'on_player_left_game', + 'on_player_locale_changed', 'on_player_main_inventory_changed', 'on_player_mined_entity', 'on_player_mined_item', @@ -1097,8 +1186,8 @@ stds.factorio_defines = { 'on_player_pipette', 'on_player_placed_equipment', 'on_player_promoted', - 'on_player_removed', 'on_player_removed_equipment', + 'on_player_removed', 'on_player_repaired_entity', 'on_player_respawned', 'on_player_rotated_entity', @@ -1111,6 +1200,7 @@ stds.factorio_defines = { 'on_player_unbanned', 'on_player_unmuted', 'on_player_used_capsule', + 'on_player_used_spidertron_remote', 'on_post_entity_died', 'on_pre_chunk_deleted', 'on_pre_entity_settings_pasted', @@ -1121,6 +1211,7 @@ stds.factorio_defines = { 'on_pre_player_mined_item', 'on_pre_player_removed', 'on_pre_robot_exploded_cliff', + 'on_pre_scenario_finished', 'on_pre_surface_cleared', 'on_pre_surface_deleted', 'on_put_item', @@ -1130,9 +1221,9 @@ stds.factorio_defines = { 'on_robot_built_entity', 'on_robot_built_tile', 'on_robot_exploded_cliff', - 'on_robot_mined', 'on_robot_mined_entity', 'on_robot_mined_tile', + 'on_robot_mined', 'on_robot_pre_mined', 'on_rocket_launch_ordered', 'on_rocket_launched', @@ -1141,6 +1232,12 @@ stds.factorio_defines = { 'on_script_trigger_effect', 'on_sector_scanned', 'on_selected_entity_changed', + 'on_space_platform_built_entity', + 'on_space_platform_built_tile', + 'on_space_platform_mined_entity', + 'on_space_platform_mined_item', + 'on_space_platform_mined_tile', + 'on_space_platform_pre_mined', 'on_surface_cleared', 'on_surface_created', 'on_surface_deleted', @@ -1153,12 +1250,13 @@ stds.factorio_defines = { 'on_train_schedule_changed', 'on_trigger_created_entity', 'on_trigger_fired_artillery', + 'on_undo_applied', 'on_unit_added_to_group', 'on_unit_group_created', 'on_unit_removed_from_group', 'script_raised_built', 'script_raised_destroy', - 'script_raised_revive' + 'script_raised_revive', } }, flow_precision_index = { @@ -1605,11 +1703,17 @@ stds.factorio_defines = { 'secondary_right_split_line' } }, - wire_connection_id = { + wire_connector_id = { fields = { - 'electric_pole', - 'power_switch_left', - 'power_switch_right' + 'circuit_red', + 'circuit_green', + 'combinator_input_red', + 'combinator_input_green', + 'combinator_output_red', + 'combinator_output_green', + 'pole_copper', + 'power_switch_left_copper', + 'power_switch_right_copper', } }, wire_type = { diff --git a/.travis/release_builder.sh b/.travis/release_builder.sh index d49e1d80..dd9f0760 100755 --- a/.travis/release_builder.sh +++ b/.travis/release_builder.sh @@ -9,7 +9,7 @@ cp -rf Refactorio/RedMew working_copy echo "Removing git files" rm -rf working_copy/.??* echo "Writing the version file" -echo "global.redmew_version='$DATE_FORMATTED-$COMMIT_SHA'" > working_copy/resources/version.lua +echo "storage.redmew_version='$DATE_FORMATTED-$COMMIT_SHA'" > working_copy/resources/version.lua echo "Contents of the version file:" cat working_copy/resources/version.lua echo "Copying map_selection.lua.sample to map_selection.lua" diff --git a/config.lua b/config.lua index be42d482..0ef80aec 100644 --- a/config.lua +++ b/config.lua @@ -3,7 +3,7 @@ _CHEATS = false _DUMP_ENV = false local currency = 'coin' -global.config = { +storage.config = { -- adds a GUI listing the scenario features, the rules, and the details of the current map map_info = { enabled = true, @@ -49,7 +49,7 @@ global.config = { player_colors = { enabled = true }, - -- saves players' lives if they have a player-port in their inventory, also adds the player-port to the market and must therefor be loaded first + -- saves players' lives if they have a 'simple-entity-with-owner' in their inventory, also adds the 'simple-entity-with-owner' to the market and must therefor be loaded first train_saviour = { enabled = true }, @@ -58,9 +58,9 @@ global.config = { enabled = false, cost = 100 }, - -- Allows removing landfill using the deconstruction planner. + -- Allows removing landfill using the deconstruction planner. Built-in for 2.0 landfill_remover = { - enabled = true, + enabled = false, -- The tile that is used to replace landfill when it is removed. revert_tile = 'water-mud' }, @@ -97,6 +97,7 @@ global.config = { -- the global score trackers to show global_to_show = { 'satellites-launched', + 'rockets-launched', 'aliens-killed', 'built-by-players', 'built-by-robots', @@ -211,7 +212,7 @@ global.config = { {name = 'substation', count = 50}, {name = 'roboport', count = 10}, {name = 'infinity-chest', count = 10}, - {name = 'player-port', count = 2}, + {name = 'simple-entity-with-owner', count = 2}, {name = 'coin', count = 20000}, {name = 'infinity-pipe', count = 10}, {name = 'heat-interface', count = 10}, @@ -337,16 +338,12 @@ global.config = { backer_name = true, -- gives locos placed a random color random_train_color = true, - -- gives players entity ghosts (from destruction like biter attacks) before the required research is complete - ghosts_before_research = true, -- adds craftable loaders. loaders = true, -- turns on entity info aka alt-mode on first joining set_alt_on_create = true, -- prevents personal construction robots from being mined by other players save_bots = true, - -- enable research_queue - research_queue = true, -- pick up item an inserter put on the ground, when the inserter is mined inserter_drops_pickup = true }, @@ -435,12 +432,13 @@ global.config = { }, research_printer = { enabled = true, - print_to_force = true, -- print a message to force chat when that force finishes a new research. + print_to_force = false, -- print a message to force chat when that force finishes a new research. print_to_discord = true, -- print a message to the discord channel when the player force finishes a new research. ignore_script = false -- ignore researches unlocked by commands or by code. }, + -- Control groups of spiders with a decon planner. Built-in for 2.0 spidertron_group_control = { - enabled = true + enabled = false }, donator = { donator_perks = { @@ -476,4 +474,4 @@ global.config = { } } -return global.config +return storage.config diff --git a/features/admin_commands.lua b/features/admin_commands.lua index 7f6b16b7..7e2b9b3c 100644 --- a/features/admin_commands.lua +++ b/features/admin_commands.lua @@ -77,9 +77,9 @@ local function add_regular(args, player) local success = Rank.increase_player_rank_to(target_name, Ranks.regular) if success then - game.print({'admin_commands.regular_add_success', actor, target_name}, Color.info) + game.print({'admin_commands.regular_add_success', actor, target_name}, {color = Color.info}) if maybe_target_player then - maybe_target_player.print({'admin_commands.regular_add_notify_target'}, Color.warning) + maybe_target_player.print({'admin_commands.regular_add_notify_target'}, {color = Color.warning}) end else Game.player_print({'admin_commands.regular_add_fail', target_name, Rank.get_player_rank_name(target_name)}, Color.fail, player) @@ -98,9 +98,9 @@ local function remove_regular(args, player) if Rank.equal(target_name, Ranks.regular) then local _, new_rank = Rank.reset_player_rank(target_name) - game.print({'admin_commands.regular_remove_success', actor, target_name, new_rank}, Color.info) + game.print({'admin_commands.regular_remove_success', actor, target_name, new_rank}, {color = Color.info}) if maybe_target_player then - maybe_target_player.print({'admin_commands.regular_remove_notify_target'}, Color.warning) + maybe_target_player.print({'admin_commands.regular_remove_notify_target'}, {color = Color.warning}) end else local rank_name = Rank.get_player_rank_name(target_name) @@ -121,16 +121,16 @@ local function probation_add(args, player) if Rank.equal(target_name, Ranks.admin) then Game.player_print({'admin_commands.probation_add_fail_admin'}, Color.fail, player) if maybe_target_player then - maybe_target_player.print({'admin_commands.probation_warn_admin', actor}, Color.warning) + maybe_target_player.print({'admin_commands.probation_warn_admin', actor}, {color = Color.warning}) end return end local success = Rank.decrease_player_rank_to(target_name, Ranks.probation) if success then - game.print({'admin_commands.probation_add_success', actor, target_name}, Color.info) + game.print({'admin_commands.probation_add_success', actor, target_name}, {color = Color.info}) if maybe_target_player then - maybe_target_player.print({'admin_commands.probation_add_notify_target'}, Color.warning) + maybe_target_player.print({'admin_commands.probation_add_notify_target'}, {color = Color.warning}) end else Game.player_print({'admin_commands.probation_add_fail', target_name}, Color.fail, player) @@ -149,9 +149,9 @@ local function probation_remove(args, player) if Rank.equal(target_name, Ranks.probation) then Rank.reset_player_rank(target_name) - game.print({'admin_commands.probation_remove_success', actor, target_name}, Color.info) + game.print({'admin_commands.probation_remove_success', actor, target_name}, {color = Color.info}) if maybe_target_player then - maybe_target_player.print({'admin_commands.probation_remove_notify_target'}, Color.warning) + maybe_target_player.print({'admin_commands.probation_remove_notify_target'}, {color = Color.warning}) end else Game.player_print({'admin_commands.probation_remove_fail', target_name}, Color.fail, player) @@ -191,14 +191,14 @@ end --- Creates a rectangle of water below an admin local function pool(_, player) local t = {} - local p = player.position + local p = player.physical_position for x = p.x - 3, p.x + 3 do for y = p.y + 2, p.y + 7 do table.insert(t, {name = 'water', position = {x, y}}) end end - player.surface.set_tiles(t) - player.surface.create_entity {name = 'fish', position = {p.x + 0.5, p.y + 5}} + player.physical_surface.set_tiles(t) + player.physical_surface.create_entity {name = 'fish', position = {p.x + 0.5, p.y + 5}} Game.player_print({'admin_commands.create_pool'}, Color.success, player) end @@ -212,12 +212,12 @@ local function invoke(args, player) return end - local pos = player.surface.find_non_colliding_position('character', player.position, 50, 1) + local pos = player.physical_surface.find_non_colliding_position('character', player.physical_position, 50, 1) if not pos then Game.player_print({'admin_commands.invoke_fail_no_location'}, player) return end - target.teleport({pos.x, pos.y}, player.surface) + target.teleport({pos.x, pos.y}, player.physical_surface) game.print({'admin_commands.invoke_announce', target.name}) end @@ -233,7 +233,12 @@ local function teleport_player(args, player) local target_name = target.name local surface = target.surface - local pos = surface.find_non_colliding_position('character', target.position, 50, 1) + local position = target.position + if target.is_player() then + position = target.physical_position + surface = target.physical_surface + end + local pos = surface.find_non_colliding_position('character', position, 50, 1) if not pos then Game.player_print({'admin_commands.tp_fail_no_location'}, Color.fail, player) return @@ -249,12 +254,13 @@ local function teleport_location(_, player) Game.player_print({'admin_commands.tp_ent_fail_no_ent'}, Color.fail, player) return end - local pos = player.surface.find_non_colliding_position('character', player.selected.position, 50, 1) + local surface = player.selected.surface + local pos = surface.find_non_colliding_position('character', player.selected.position, 50, 1) if not pos then Game.player_print({'admin_commands.tp_fail_no_location'}, Color.fail, player) return end - player.teleport(pos) + player.teleport(pos, surface) Game.player_print({'admin_commands.tp_end_success'}, Color.success, player) end @@ -263,13 +269,13 @@ local function built_entity(event) local index = event.player_index if tp_players[index] then - local entity = event.created_entity + local entity = event.entity if not entity or not entity.valid or entity.type ~= 'entity-ghost' then return end - game.get_player(index).teleport(entity.position) + game.get_player(index).teleport(entity.position, entity.surface) entity.destroy() end end @@ -303,9 +309,9 @@ end --- Revives ghosts around the player local function revive_ghosts(args, player) local radius = args.radius - local pos = player.position + local pos = player.physical_position local count = 0 - for _, e in pairs(player.surface.find_entities_filtered {area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}, type = 'entity-ghost'}) do + for _, e in pairs(player.physical_surface.find_entities_filtered {area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}, type = 'entity-ghost'}) do e.revive() count = count + 1 end diff --git a/features/antigrief.lua b/features/antigrief.lua index bc4e2665..55ca585a 100644 --- a/features/antigrief.lua +++ b/features/antigrief.lua @@ -2,12 +2,12 @@ local Event = require 'utils.event' local Utils = require 'utils.core' local RS = require 'map_gen.shared.redmew_surface' -global.original_last_users_by_ent_pos = {} +storage.original_last_users_by_ent_pos = {} Event.on_init( function() - global.ag_surface = game.create_surface('antigrief', {autoplace_controls = {coal = {frequency = 'normal', richness = 'normal', size = 'none'}, ['copper-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}, ['crude-oil'] = {frequency = 'normal', richness = 'normal', size = 'none'}, desert = {frequency = 'normal', richness = 'normal', size = 'none'}, dirt = {frequency = 'normal', richness = 'normal', size = 'none'}, ['enemy-base'] = {frequency = 'normal', richness = 'normal', size = 'none'}, grass = {frequency = 'normal', richness = 'normal', size = 'none'}, ['iron-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}, sand = {frequency = 'normal', richness = 'normal', size = 'none'}, stone = {frequency = 'normal', richness = 'normal', size = 'none'}, trees = {frequency = 'normal', richness = 'normal', size = 'none'}, ['uranium-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}}, cliff_settings = {cliff_elevation_0 = 1024, cliff_elevation_interval = 10, name = 'cliff'}, height = 2000000, peaceful_mode = false, seed = 3461559752, starting_area = 'very-low', starting_points = {{x = 0, y = 0}}, terrain_segmentation = 'normal', water = 'normal', width = 2000000}) - global.ag_surface.always_day = true + storage.ag_surface = game.create_surface('antigrief', {autoplace_controls = {coal = {frequency = 'normal', richness = 'normal', size = 'none'}, ['copper-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}, ['crude-oil'] = {frequency = 'normal', richness = 'normal', size = 'none'}, desert = {frequency = 'normal', richness = 'normal', size = 'none'}, dirt = {frequency = 'normal', richness = 'normal', size = 'none'}, ['enemy-base'] = {frequency = 'normal', richness = 'normal', size = 'none'}, grass = {frequency = 'normal', richness = 'normal', size = 'none'}, ['iron-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}, sand = {frequency = 'normal', richness = 'normal', size = 'none'}, stone = {frequency = 'normal', richness = 'normal', size = 'none'}, trees = {frequency = 'normal', richness = 'normal', size = 'none'}, ['uranium-ore'] = {frequency = 'normal', richness = 'normal', size = 'none'}}, cliff_settings = {cliff_elevation_0 = 1024, cliff_elevation_interval = 10, name = 'cliff'}, height = 2000000, peaceful_mode = false, seed = 3461559752, starting_area = 'very-low', starting_points = {{x = 0, y = 0}}, terrain_segmentation = 'normal', water = 'normal', width = 2000000}) + storage.ag_surface.always_day = true end ) @@ -63,10 +63,10 @@ local function on_entity_changed(event) return end --Freebees for admins if entity.last_user ~= player and entity.force == player.force then --commented out to be able to debug - place_entity_on_surface(entity, global.ag_surface, true, event.player_index) + place_entity_on_surface(entity, storage.ag_surface, true, event.player_index) end if entity.last_user then - global.original_last_users_by_ent_pos[get_position_str(entity.position)] = entity.last_user.index + storage.original_last_users_by_ent_pos[get_position_str(entity.position)] = entity.last_user.index end end @@ -98,7 +98,7 @@ Event.add( return end - local ag_entities = global.ag_surface.find_entities_filtered {position = entity.position} + local ag_entities = storage.ag_surface.find_entities_filtered {position = entity.position} --If a player has rotated twice we want to preserve the original state. if #ag_entities == 0 or not ag_entities[1].last_user or ag_entities[1].last_user ~= entity.last_user then --Mock entity us used because the api doesnt support pre_player_rotated entity. @@ -124,12 +124,12 @@ Event.add( function(event) --is a player on the same force as the destroyed object if event.entity and event.entity.valid and event.entity.force.name == 'player' and event.cause and event.cause.force == event.entity.force and event.cause.type == 'character' then - local new_entity = place_entity_on_surface(event.entity, global.ag_surface, true, event.cause.player) + local new_entity = place_entity_on_surface(event.entity, storage.ag_surface, true, event.cause.player) if new_entity and event.entity.type == 'container' then local items = event.entity.get_inventory(defines.inventory.chest).get_contents() if items then - for item, n in pairs(items) do - new_entity.insert {name = item, count = n} + for _, item_stack in pairs(items) do + new_entity.insert(item_stack) end end end @@ -143,7 +143,7 @@ Event.add( defines.events.on_marked_for_deconstruction, function(event) if event.entity.last_user then - global.original_last_users_by_ent_pos[get_position_str(event.entity.position)] = event.entity.last_user.index + storage.original_last_users_by_ent_pos[get_position_str(event.entity.position)] = event.entity.last_user.index end end ) @@ -160,7 +160,7 @@ Module.undo = --Remove all items from all surfaces that player placed an entity on for _, surface in pairs(game.surfaces) do - if surface ~= global.ag_surface then + if surface ~= storage.ag_surface then for _, e in ipairs(surface.find_entities_filtered {force = player.force.name}) do if e.last_user == player then e.destroy() @@ -169,26 +169,26 @@ Module.undo = end end - for _, e in ipairs(global.ag_surface.find_entities_filtered {}) do + for _, e in ipairs(storage.ag_surface.find_entities_filtered {}) do if e.last_user == player then --Place removed entity IF no collision is detected - local last_user = global.original_last_users_by_ent_pos[get_position_str(e.position)] + local last_user = storage.original_last_users_by_ent_pos[get_position_str(e.position)] local new_entity = place_entity_on_surface(e, RS.get_surface(), false, last_user) --Transfer items if new_entity then local event_player = Utils.ternary(new_entity.last_user, new_entity.last_user, game.player) - local event = {created_entity = new_entity, player_index = event_player.index, stack = {}} + local event = {entity = new_entity, player_index = event_player.index, consumed_items = {}} script.raise_event(defines.events.on_built_entity, event) if e.type == 'container' then local items = e.get_inventory(defines.inventory.chest).get_contents() if items then - for item, n in pairs(items) do - new_entity.insert {name = item, count = n} + for _, item_stack in pairs(items) do + new_entity.insert(item_stack) end end end - e.destroy() --destory entity only if a new entity was created + e.destroy() --destroy entity only if a new entity was created end end end @@ -196,16 +196,16 @@ end Module.antigrief_surface_tp = function() if game.player then - if game.player.surface == global.ag_surface then + if game.player.surface == storage.ag_surface then game.player.teleport(game.player.position, RS.get_surface()) else - game.player.teleport(game.player.position, global.ag_surface) + game.player.teleport(game.player.position, storage.ag_surface) end end end Module.count_removed_entities = function(player) - return #Utils.find_entities_by_last_user(player, global.ag_surface) + return #Utils.find_entities_by_last_user(player, storage.ag_surface) end return Module diff --git a/features/apocalypse.lua b/features/apocalypse.lua index f7d8dd48..6007ee96 100644 --- a/features/apocalypse.lua +++ b/features/apocalypse.lua @@ -91,7 +91,7 @@ local biter_spawn_token = surface = RS.get_surface() player_force = game.forces.player - enemy_force.evolution_factor = 1 + enemy_force.set_evolution_factor(1, surface) local p_spawn = player_force.get_spawn_position(surface) local group = surface.create_unit_group {position = p_spawn} @@ -134,7 +134,7 @@ function Public.begin_apocalypse(_, player) end primitives.apocalypse_now = true - game.print({'apocalypse.apocalypse_begins'}, Color.pink) + game.print({'apocalypse.apocalypse_begins'}, {color = Color.pink}) Task.set_timeout(1, biter_spawn_token, {}) end diff --git a/features/auto_stash.lua b/features/auto_stash.lua index 38173771..45f4bfcb 100644 --- a/features/auto_stash.lua +++ b/features/auto_stash.lua @@ -1,6 +1,14 @@ +-- This adds a button that stashes/sorts your inventory into nearby chests in some kind of intelligent way +-- made by mewmew +-- modified by gerkiz & RedRafe +-- source: https://github.com/ComfyFactory/ComfyFactorio/blob/develop/modules/autostash.lua +-- ======================================================= -- + local Color = require 'resources.color_presets' -local Global = require 'utils.global' local Event = require 'utils.event' +local Game = require 'utils.game' +local Global = require 'utils.global' +local LP = require 'utils.logistic_point' local floor = math.floor @@ -22,6 +30,16 @@ Global.register(this, function(tbl) this = tbl end) local bps_blacklist = { ['blueprint-book'] = true, ['blueprint'] = true } +local function container_has_requests(chest) + local requests = 0 + if chest.type == 'logistic-container' then + local lp = chest.get_logistic_point(defines.logistic_member_index.logistic_container) + local filters = LP.get_filters(lp) + requests = #filters + end + return requests > 0 +end + local function create_floaty_text(surface, position, name, count) if this.floating_text_y_offsets[position.x .. '_' .. position.y] then this.floating_text_y_offsets[position.x .. '_' .. position.y] = @@ -29,10 +47,10 @@ local function create_floaty_text(surface, position, name, count) else this.floating_text_y_offsets[position.x .. '_' .. position.y] = 0 end - surface.create_entity({ - name = 'flying-text', + Game.create_local_flying_text({ + surface = surface, position = { position.x, position.y + this.floating_text_y_offsets[position.x .. '_' .. position.y] }, - text = { '', '-', count, ' ', game.item_prototypes[name].localised_name }, + text = { '', '-', count, ' ', prototypes.item[name].localised_name }, color = { r = 255, g = 255, b = 255 }, }) end @@ -134,7 +152,7 @@ local function get_nearby_chests(player, a, furnace, wagon) local r_square = r * r local chests, inventories = {}, {} local size_of_chests = 0 - local area = { { player.position.x - r, player.position.y - r }, { player.position.x + r, player.position.y + r } } + local area = { { player.physical_position.x - r, player.physical_position.y - r }, { player.physical_position.x + r, player.physical_position.y + r } } area = a or area @@ -157,14 +175,14 @@ local function get_nearby_chests(player, a, furnace, wagon) forces = { player.force, 'neutral' } end - for _, e in pairs(player.surface.find_entities_filtered({ type = container_type, area = area, force = forces })) do - if ((player.position.x - e.position.x) ^ 2 + (player.position.y - e.position.y) ^ 2) <= r_square then + for _, e in pairs(player.physical_surface.find_entities_filtered({ type = container_type, area = area, force = forces })) do + if ((player.physical_position.x - e.position.x) ^ 2 + (player.physical_position.y - e.position.y) ^ 2) <= r_square then i = i + 1 containers[i] = e end end - containers = sort_entities_by_distance(player.position, containers) + containers = sort_entities_by_distance(player.physical_position, containers) for _, entity in pairs(containers) do size_of_chests = size_of_chests + 1 chests[size_of_chests] = entity @@ -321,18 +339,15 @@ local function insert_into_wagon_filtered(stack, chests, name, floaty_text_list) for chestnr, chest in pairs(chests.chest) do if chest.type == 'logistic-container' then local chest_inventory = chests.inventory[chestnr] - for index = 1, chest.request_slot_count do - if chest_inventory.can_insert(stack) then - if chest.get_request_slot(index) ~= nil then - local n = chest.get_request_slot(index) - if n and n.name == name then - local inserted_count = chest_inventory.insert(stack) - stack.count = stack.count - inserted_count - prepare_floaty_text(floaty_text_list, chest.surface, chest.position, name, inserted_count) - if stack.count <= 0 then - return chestnr - end - end + local lp = chest.get_logistic_point(defines.logistic_member_index.logistic_container) + local filters = LP.get_filters(lp) + for _, filter in pairs(filters) do + if filter.value.name == name then + local inserted_count = chest_inventory.insert(stack) + stack.count = stack.count - inserted_count + prepare_floaty_text(floaty_text_list, chest.surface, chest.position, name, inserted_count) + if stack.count <= 0 then + return chestnr end end end @@ -360,18 +375,15 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa for chestnr, chest in pairs(chests.chest) do if chest.type == 'logistic-container' then local chest_inventory = chests.inventory[chestnr] - for index = 1, chest.request_slot_count do - if chest_inventory.can_insert(stack) then - if chest.get_request_slot(index) ~= nil then - local n = chest.get_request_slot(index) - if n and n.name == name then - local inserted_count = chest_inventory.insert(stack) - stack.count = stack.count - inserted_count - prepare_floaty_text(floaty_text_list, chest.surface, chest.position, name, inserted_count) - if stack.count <= 0 then - return chestnr - end - end + local lp = chest.get_logistic_point(defines.logistic_member_index.logistic_container) + local filters = LP.get_filters(lp) + for _, filter in pairs(filters) do + if filter.value.name == name then + local inserted_count = chest_inventory.insert(stack) + stack.count = stack.count - inserted_count + prepare_floaty_text(floaty_text_list, chest.surface, chest.position, name, inserted_count) + if stack.count <= 0 then + return chestnr end end end @@ -381,7 +393,7 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa -- Attempt to store in chests that already have the same item. for chestnr, chest in pairs(chests.chest) do if container[chest.type] then - if chest.request_slot_count and chest.request_slot_count > 0 then + if container_has_requests(chest) then goto continue end local chest_inventory = chests.inventory[chestnr] @@ -402,7 +414,7 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa -- Attempt to store in empty chests. for chestnr, chest in pairs(filtered_chests.chest) do if container[chest.type] then - if chest.request_slot_count and chest.request_slot_count > 0 then + if container_has_requests(chest) then goto continue end local chest_inventory = filtered_chests.inventory[chestnr] @@ -422,13 +434,13 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa end end - local item_prototypes = game.item_prototypes + local item_prototypes = prototypes.item -- Attempt to store in chests with same item subgroup. - local item_subgroup = game.item_prototypes[name].subgroup.name + local item_subgroup = prototypes.item[name].subgroup.name if item_subgroup then for chestnr, chest in pairs(filtered_chests.chest) do - if chest.request_slot_count and chest.request_slot_count > 0 then + if container_has_requests(chest) then goto continue end if container[chest.type] then @@ -438,8 +450,8 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa end local content = chest_inventory.get_contents() if chest_inventory.can_insert(stack) then - for equal_name, _ in pairs(content) do - local t = item_prototypes[equal_name] + for item_stack, _ in pairs(content) do + local t = item_prototypes[item_stack.name] if t and t.subgroup.name == item_subgroup then local inserted_count = chest_inventory.insert(stack) stack.count = stack.count - inserted_count @@ -458,7 +470,7 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa -- Attempt to store in mixed chests. for chestnr, chest in pairs(filtered_chests.chest) do if container[chest.type] then - if chest.request_slot_count and chest.request_slot_count > 0 then + if container_has_requests(chest) then goto continue end local chest_inventory = filtered_chests.inventory[chestnr] @@ -479,8 +491,8 @@ local function insert_item_into_chest(stack, chests, filtered_chests, name, floa end local function whitelist() - local resources = game.entity_prototypes - local items = game.item_prototypes + local resources = prototypes.entity + local items = prototypes.item this.whitelist = {} for k, _ in pairs(resources) do if resources[k] and resources[k].type == 'resource' and resources[k].mineable_properties then @@ -516,19 +528,19 @@ function Public.auto_stash(player, event) return end if not (player.character and player.character.valid) then - player.print({'auto_stash.err_no_character'}, Color.warning) + player.print({'auto_stash.err_no_character'}, {color = Color.warning}) return end local inventory = player.get_main_inventory() if inventory.is_empty() then - player.print({'auto_stash.err_no_inventory'}, Color.warning) + player.print({'auto_stash.err_no_inventory'}, {color = Color.warning}) return end local floaty_text_list = {} local chests = { chest = {}, inventory = {} } local r = this.small_radius - local area = { { player.position.x - r, player.position.y - r }, { player.position.x + r, player.position.y + r } } + local area = { { player.physical_position.x - r, player.physical_position.y - r }, { player.physical_position.x + r, player.physical_position.y + r } } if ctrl then if button == defines.mouse_button_type.right and this.insert_into_furnace then chests = get_nearby_chests(player, nil, true, false) @@ -543,7 +555,7 @@ function Public.auto_stash(player, event) end if not chests.chest or not chests.chest[1] then - player.print({'auto_stash.err_no_container'}, Color.warning) + player.print({'auto_stash.err_no_container'}, {color = Color.warning}) return end diff --git a/features/autodeconstruct.lua b/features/autodeconstruct.lua index 651b3651..34744016 100644 --- a/features/autodeconstruct.lua +++ b/features/autodeconstruct.lua @@ -24,7 +24,7 @@ Global.register_init( local fluid_ores = tbl.require_fluid_ores local pumpjack_map = tbl.pumpjack_resources_map - for name, entity in pairs(game.entity_prototypes) do + for name, entity in pairs(prototypes.entity) do if entity.type == 'mining-drill' and entity.resource_categories['basic-solid'] then local radius = entity.mining_drill_radius diff --git a/features/autofill.lua b/features/autofill.lua index 5ac67f23..8fbf5058 100644 --- a/features/autofill.lua +++ b/features/autofill.lua @@ -1,4 +1,5 @@ local Event = require 'utils.event' +local Game = require 'utils.game' local Global = require 'utils.global' local Settings = require 'utils.redmew_settings' local pairs = pairs @@ -50,7 +51,7 @@ function Public.set_player_ammo(player_index, name, value) end local function entity_built(event) - local entity = event.created_entity + local entity = event.entity if not entity.valid then return @@ -98,9 +99,9 @@ local function entity_built(event) local remaining_count = inventory.get_item_count(name) - player.surface.create_entity( + Game.create_local_flying_text( { - name = 'flying-text', + surface = player.surface, position = entity.position, text = {'autofill.insert_item', inserted, Ammos.locale[name], remaining_count} } diff --git a/features/battery_charge.lua b/features/battery_charge.lua index 9925dcb0..8b708da1 100644 --- a/features/battery_charge.lua +++ b/features/battery_charge.lua @@ -1,3 +1,9 @@ +-- Charge your armor equipment from nearby accumulators! +-- made by Hanakocz +-- modified by RedRafe +-- source: https://github.com/ComfyFactory/ComfyFactorio/blob/develop/modules/charging_station.lua +-- ======================================================= -- + local Color = require 'resources.color_presets' local Global = require 'utils.global' @@ -38,33 +44,33 @@ end function Public.recharge(player) if not player.character then - player.print({'battery_charge.err_no_character'}, Color.warning) + player.print({'battery_charge.err_no_character'}, {color = Color.warning}) return end local armor_inventory = player.get_inventory(defines.inventory.character_armor) if not armor_inventory.valid then - player.print({'battery_charge.err_no_armor'}, Color.warning) + player.print({'battery_charge.err_no_armor'}, {color = Color.warning}) return end local armor = armor_inventory[1] if not armor.valid_for_read then - player.print({'battery_charge.err_no_armor'}, Color.warning) + player.print({'battery_charge.err_no_armor'}, {color = Color.warning}) return end local grid = armor.grid if not grid or not grid.valid then - player.print({'battery_charge.err_no_armor'}, Color.warning) + player.print({'battery_charge.err_no_armor'}, {color = Color.warning}) return end - local entities = player.surface.find_entities_filtered { + local entities = player.physical_surface.find_entities_filtered { type = 'accumulator', force = player.force, - position = player.position, + position = player.physical_position, radius = this.radius, } if not entities or not next(entities) then - player.print({'battery_charge.err_no_accumulators'}, Color.warning) + player.print({'battery_charge.err_no_accumulators'}, {color = Color.warning}) return end @@ -73,7 +79,7 @@ function Public.recharge(player) if piece.valid and piece.generator_power == 0 then local energy_needs = piece.max_energy - piece.energy if energy_needs > 0 then - local energy = discharge_accumulators(player.surface, player.position, player.force, energy_needs) + local energy = discharge_accumulators(player.physical_surface, player.physical_position, player.force, energy_needs) if energy > 0 then if piece.energy + energy >= piece.max_energy then piece.energy = piece.max_energy diff --git a/features/biter_corpse_remover.lua b/features/biter_corpse_remover.lua index b23e3b1a..a8ade98e 100644 --- a/features/biter_corpse_remover.lua +++ b/features/biter_corpse_remover.lua @@ -10,14 +10,14 @@ local queue_pop = Queue.pop local queue_size = Queue.size -- config table for the max queue size --- Change at runtime with /sc global.config.biter_corpse_remover.max_queue_size = 100 -local biter_corpse_remover = global.config.biter_corpse_remover +-- Change at runtime with /sc storage.config.biter_corpse_remover.max_queue_size = 100 +local biter_corpse_remover = storage.config.biter_corpse_remover local corpse_queue = Queue.new() Global.register(corpse_queue, function(tbl) corpse_queue = tbl - biter_corpse_remover = global.config.biter_corpse_remover + biter_corpse_remover = storage.config.biter_corpse_remover end) local function process_corpses(corpses) diff --git a/features/chat_triggers.lua b/features/chat_triggers.lua index f8420447..e1a4d317 100644 --- a/features/chat_triggers.lua +++ b/features/chat_triggers.lua @@ -89,20 +89,20 @@ local function mentions(event) end if admin_call and p.admin then local message = {'chat_triggers.mention_success', prefix, game.get_player(event.player_index).name, word} - p.print(message, Color.yellow) + p.print(message, {color = Color.yellow}) p.play_sound {path = 'utility/new_objective', volume_modifier = 1} success = true end if not admin_call and (p.name:lower() == word_front_trim or p.name:lower() == word_back_trim or p.name:lower() == word_back_double_trim or p.name:lower() == word_front_back_trim) then if p.name == player.name then if _DEBUG then - player.print({'chat_triggers.mention_fail_mention_self', prefix}, Color.red) + player.print({'chat_triggers.mention_fail_mention_self', prefix}, {color = Color.red}) end success = true break end - p.print({'chat_triggers.mention_success_target', prefix, player.name}, Color.yellow) + p.print({'chat_triggers.mention_success_target', prefix, player.name}, {color = Color.yellow}) p.play_sound {path = 'utility/new_objective', volume_modifier = 1} if p.character and p.character.valid then -- If player is dead and they don't have a character then they won't get the hovering notification. local message = {'chat_triggers.mention_success_target_floating', player.name} @@ -110,7 +110,7 @@ local function mentions(event) end success = true if _DEBUG then - player.print(prefix .. 'Successful mentioned ' .. p.name, Color.red) + player.print(prefix .. 'Successful mentioned ' .. p.name, {color = Color.red}) end break end @@ -130,21 +130,21 @@ local function mentions(event) if missing_player_string ~= nil then missing_player_string = string.sub(missing_player_string, 1, (string.len(missing_player_string) - 2)) if not_found > 1 then - player.print({'chat_triggers.mention_not_found_plural', prefix, missing_player_string}, Color.yellow) + player.print({'chat_triggers.mention_not_found_plural', prefix, missing_player_string}, {color = Color.yellow}) else - player.print({'chat_triggers.mention_not_found_singular', prefix, missing_player_string}, Color.yellow) + player.print({'chat_triggers.mention_not_found_singular', prefix, missing_player_string}, {color = Color.yellow}) end end end -if global.config.hodor.enabled then +if storage.config.hodor.enabled then Event.add(defines.events.on_console_chat, hodor) end -if global.config.auto_respond.enabled then +if storage.config.auto_respond.enabled then Event.add(defines.events.on_console_chat, auto_respond) end -if global.config.mentions.enabled then +if storage.config.mentions.enabled then Event.add(defines.events.on_console_chat, mentions) end diff --git a/features/cutscene/cutscene_controller.lua b/features/cutscene/cutscene_controller.lua index 8c45db54..b609f8ec 100644 --- a/features/cutscene/cutscene_controller.lua +++ b/features/cutscene/cutscene_controller.lua @@ -127,7 +127,7 @@ function Public.play_sound(tick, player, path, times, delay, initial_delay) if (not valid(player)) then return end - if not game.is_valid_sound_path(path) then + if not helpers.is_valid_sound_path(path) then debug_print('Provided SoundPath is invalid. Try opening /radio and browse for a valid path') return end @@ -156,9 +156,9 @@ local remove_renderings = Token.register( function(renderings) for _, v in pairs(renderings) do - if rendering.is_valid(v) then - rendering.destroy(v) - debug_print('Deleted rendering with id: ' .. v) + if v.valid then + debug_print('Deleted rendering with id: ' .. v.id) + v.destroy() end end end @@ -225,7 +225,7 @@ function Public.register_running_cutscene(player_index, identifier, final_transi character = player.character, terminate_func = cutscene_function.terminate_func, rendering = {}, - current_index = -1, + current_index = 0, start_tick = 0 } local running_cutscene = running_cutscenes[player_index] @@ -284,7 +284,7 @@ function Public.register_running_cutscene(player_index, identifier, final_transi running_cutscene.auto_play_cutscene_checkbox = auto_play_cutscene_checkbox end - handler({player_index = player_index, waypoint_index = -1, tick = game.tick}) + handler({player_index = player_index, waypoint_index = 0, tick = game.tick}) end local function restart_cutscene(player_index, waypoints, start_index) @@ -343,7 +343,7 @@ local function restart_cutscene(player_index, waypoints, start_index) if start_index then player.jump_to_cutscene_waypoint(start_index + 1) else - start_index = -1 + start_index = 0 end handler({player_index = player_index, waypoint_index = start_index, tick = game.tick}) @@ -410,7 +410,7 @@ local reconnect_character = end ) -function Public.terminate_cutscene(player_index, ticks,skip_btn_flag) +function Public.terminate_cutscene(player_index, ticks, skip_btn_flag) local running_cutscene = running_cutscenes[player_index] if not running_cutscene then return @@ -433,18 +433,18 @@ function Public.terminate_cutscene(player_index, ticks,skip_btn_flag) ) end -function Public.register_rendering_id(player_index, tick, render_id) - if type(render_id) ~= 'table' then - render_id = {render_id} +function Public.register_rendering(player_index, tick, render) + if type(render) ~= 'table' then + render = {render} end local running_cutscene = running_cutscenes[player_index] - for _, id in pairs(render_id) do - if rendering.is_valid(id) then + for _, obj in pairs(render) do + if obj.valid then if not waypoint_still_active(tick, player_index) then - debug_print('The rendering with id ' .. id .. ' was not added. Destroying it instead') - rendering.destroy(id) + debug_print('The rendering with id ' .. obj.id .. ' was not added. Destroying it instead') + obj.destroy() else - table.insert(running_cutscene.rendering, id) + table.insert(running_cutscene.rendering, obj) end end end @@ -467,15 +467,15 @@ handler = function(event) if not running_cutscene then return end - running_cutscene.current_index = waypoint_index + 1 + running_cutscene.current_index = waypoint_index running_cutscene.start_tick = tick local update = running_cutscene.update if update then - restart_cutscene(player_index, update, waypoint_index) + restart_cutscene(player_index, update, waypoint_index - 1) return end - local ticks = running_cutscene.waypoints[waypoint_index + 2] + local ticks = running_cutscene.waypoints[waypoint_index + 1] if ticks then ticks = ticks.transition_time else @@ -486,7 +486,7 @@ handler = function(event) if not func then return end - local current_waypoint = running_cutscene.waypoints[waypoint_index + 2] + local current_waypoint = running_cutscene.waypoints[waypoint_index + 1] if not current_waypoint or current_waypoint.terminate then Public.terminate_cutscene(player_index, ticks) return @@ -500,19 +500,19 @@ handler = function(event) tick = tick } - debug_print('Waypoint_index ' .. waypoint_index + 1 .. ' (waypoint #' .. waypoint_index + 2 .. ') callback in ' .. ticks .. ' ticks') + debug_print('Waypoint_index ' .. waypoint_index .. ' (waypoint #' .. waypoint_index + 1 .. ') callback in ' .. ticks .. ' ticks') - set_timeout_in_ticks(ticks, callback_function, {func = running_cutscene.func, player_index = player_index, waypoint_index = waypoint_index, params = params}) + set_timeout_in_ticks(ticks, callback_function, {func = running_cutscene.func, player_index = player_index, waypoint_index = waypoint_index - 1, params = params}) end function Public.goTo(player_index, waypoint_index) local running_cutscene = running_cutscenes[player_index] - if waypoint_index < 0 or waypoint_index > #running_cutscene.waypoints - 2 then + if waypoint_index < 1 or waypoint_index > #running_cutscene.waypoints - 1 then return false end Token.get(remove_renderings)(running_cutscene.rendering) game.get_player(player_index).jump_to_cutscene_waypoint(waypoint_index) - handler({player_index = player_index, waypoint_index = waypoint_index - 1, tick = game.tick}) + handler({player_index = player_index, waypoint_index = waypoint_index, tick = game.tick}) running_cutscene.current_index = waypoint_index return true end diff --git a/features/cutscene/rendering.lua b/features/cutscene/rendering.lua index 539ce6dc..fcc43409 100644 --- a/features/cutscene/rendering.lua +++ b/features/cutscene/rendering.lua @@ -120,7 +120,7 @@ local function text_background(settings, offset, player, percentages, size, numb end function Public.draw_text(settings, offset, text, player, params, draw_background, fit_to_edge) - local ids = {} + local list = {} local player_resolution = player.display_resolution player_resolution.scale = player.display_scale local percentages = calculate_percentages(settings, player_resolution) @@ -139,10 +139,10 @@ function Public.draw_text(settings, offset, text, player, params, draw_backgroun local size = text_height_in_tiles(scale, settings.player_zoom) if draw_background == true then - insert(ids, text_background(settings, offset, player, percentages, size, 1, params, fit_to_edge)) + insert(list, text_background(settings, offset, player, percentages, size, 1, params, fit_to_edge)) end - local target = {x = player.position.x + offset.x, y = player.position.y + offset.y} + local target = {x = player.physical_position.x + offset.x, y = player.physical_position.y + offset.y} local color = params.color color = color and color or {r = 255, g = 255, b = 255} @@ -200,12 +200,12 @@ function Public.draw_text(settings, offset, text, player, params, draw_backgroun debug_print(rendering_params) - insert(ids, rendering.draw_text(rendering_params)) - return ids + insert(list, rendering.draw_text(rendering_params)) + return list end function Public.draw_multi_line_text(settings, offset, texts, player, params, draw_background, fit_to_edge) - local ids = {} + local list = {} local player_resolution = player.display_resolution player_resolution.scale = player.display_scale local percentages = calculate_percentages(settings, player_resolution) @@ -223,15 +223,15 @@ function Public.draw_multi_line_text(settings, offset, texts, player, params, dr offset.y = offset.y - size * 0.5 if draw_background then - insert(ids, text_background(settings, offset, player, percentages, size, #texts, params, fit_to_edge)) + insert(list, text_background(settings, offset, player, percentages, size, #texts, params, fit_to_edge)) draw_background = -1 end for i = 1, #texts do - insert(ids, Public.draw_text(settings, offset, texts[i], player, params, draw_background, fit_to_edge)[1]) + insert(list, Public.draw_text(settings, offset, texts[i], player, params, draw_background, fit_to_edge)[1]) offset.y = offset.y + (size * 1.5) end - return ids + return list end function Public.draw_rectangle(settings, offset, left_top, right_bottom, player, params, fit_to_edge) @@ -248,8 +248,8 @@ function Public.draw_rectangle(settings, offset, left_top, right_bottom, player, right_bottom = fit_to_screen(percentages, right_bottom) end - local target_left = {x = player.position.x + left_top.x + offset.x, y = player.position.y + left_top.y + offset.y} - local target_right = {x = player.position.x + right_bottom.x + offset.x, y = player.position.y + right_bottom.y + offset.y} + local target_left = {x = player.physical_position.x + left_top.x + offset.x, y = player.physical_position.y + left_top.y + offset.y} + local target_right = {x = player.physical_position.x + right_bottom.x + offset.x, y = player.physical_position.y + right_bottom.y + offset.y} local color = params.color color = color and color or {} diff --git a/features/death_corpse_tags.lua b/features/death_corpse_tags.lua index 81b31afb..7693e28c 100644 --- a/features/death_corpse_tags.lua +++ b/features/death_corpse_tags.lua @@ -11,8 +11,8 @@ local function player_died(event) return end - local pos = player.position - local entities = player.surface.find_entities_filtered { + local pos = player.physical_position + local entities = player.physical_surface.find_entities_filtered { area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.5, pos.y + 0.5}}, name = 'character-corpse' } diff --git a/features/death_corpse_tags_tests.lua b/features/death_corpse_tags_tests.lua index 57fe6f18..0ce7f81f 100644 --- a/features/death_corpse_tags_tests.lua +++ b/features/death_corpse_tags_tests.lua @@ -36,8 +36,8 @@ Declare.module({'features', 'death_corpse_tags'}, function() end) local function fake_death(player, has_items) - local surface = player.surface - local position = player.position + local surface = player.physical_surface + local position = player.physical_position local entity = surface.create_entity { name = 'character-corpse', @@ -61,10 +61,10 @@ Declare.module({'features', 'death_corpse_tags'}, function() declare_test('corpse removed and empty message when corpse is empty', function(context) -- Arrange. local player = context.player - player.teleport({5, 5}) + player.teleport({5, 5}, player.physical_surface) context:add_teardown(function() - player.teleport({0, 0}) + player.teleport({0, 0}, player.physical_surface) end) local actual_text @@ -83,7 +83,7 @@ Declare.module({'features', 'death_corpse_tags'}, function() DeathCorpseTags._player_died(event) -- Assert. - local corpses = player.surface.find_entities_filtered({name = 'character-corpse', position = player.position, radius = 1}) + local corpses = player.physical_surface.find_entities_filtered({name = 'character-corpse', position = player.physical_position, radius = 1}) Assert.equal(0, #corpses) local expected = {'death_corpse_tags.empty_corpse'} diff --git a/features/donator.lua b/features/donator.lua index 6f7455e0..4c784d93 100644 --- a/features/donator.lua +++ b/features/donator.lua @@ -12,7 +12,7 @@ local concat = table.concat local remove = table.remove local set_data = Server.set_data local random = math.random -local config = global.config.donator +local config = storage.config.donator local donator_data_set = 'donators' local donators = {} -- global register @@ -38,7 +38,7 @@ Global.register( donator_perks_perm = tbl.donator_perks_perm donator_perks_temp = tbl.donator_perks_temp donator_tiers = tbl.donator_tiers - config = global.config.donator + config = storage.config.donator end ) @@ -71,7 +71,7 @@ local print_after_timeout = return end - game.print(data.message, player.chat_color) + game.print(data.message, {color = player.chat_color}) end ) @@ -238,12 +238,12 @@ local function player_died(event) end -- Generic: this person has died message - game.print({'donator.death_message', player.name}, player.chat_color) + game.print({'donator.death_message', player.name}, {color = player.chat_color}) -- Player's selected message local message = messages[random(count)] message = concat({'*** ', message, ' ***'}) - game.print(message, player.chat_color) + game.print(message, {color = player.chat_color}) end local reset_run_speed = diff --git a/features/donator_commands.lua b/features/donator_commands.lua index 91dfe630..746c282e 100644 --- a/features/donator_commands.lua +++ b/features/donator_commands.lua @@ -6,7 +6,7 @@ local Color = require 'resources.color_presets' local Global = require 'utils.global' local format = string.format -local config = global.config.donator.donator_perks +local config = storage.config.donator.donator_perks Global.register( @@ -14,7 +14,7 @@ Global.register( config = config }, function() - config = global.config.donator.donator_perks + config = storage.config.donator.donator_perks end ) diff --git a/features/dump_offline_inventories.lua b/features/dump_offline_inventories.lua index f26b8fc1..935d0ad4 100644 --- a/features/dump_offline_inventories.lua +++ b/features/dump_offline_inventories.lua @@ -64,8 +64,8 @@ local function spawn_player_corpse(player, banned, timeout_minutes) return end - local position = player.position - local corpse = player.surface.create_entity { + local position = player.physical_position + local corpse = player.physical_surface.create_entity { name = 'character-corpse', position = position, inventory_size = #inv_contents, diff --git a/features/enemy_turret.lua b/features/enemy_turret.lua index 17a37582..5c87deb1 100644 --- a/features/enemy_turret.lua +++ b/features/enemy_turret.lua @@ -2,7 +2,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' local Task = require 'utils.task' local Token = require 'utils.token' -local register_on_entity_destroyed = script.register_on_entity_destroyed +local register_on_object_destroyed = script.register_on_object_destroyed local Public = {} local turrets_map = {} @@ -79,15 +79,15 @@ function Public.register(entity, refill_name) return end - local is_item = game.item_prototypes[refill_name] and true or false - local is_fluid = game.fluid_prototypes[refill_name] and true or false + local is_item = prototypes.item[refill_name] and true or false + local is_fluid = prototypes.fluid[refill_name] and true or false local is_artillery = entity.prototype.type == Artillery.turret_name if not (is_item or is_fluid or is_artillery) then return end - local destroy_id = register_on_entity_destroyed(entity) + local destroy_id = register_on_object_destroyed(entity) local unit_id = entity.unit_number local data = { @@ -109,7 +109,7 @@ function Public.register(entity, refill_name) else data.item_stack = { name = data.refill, - count = game.item_prototypes[data.refill].stack_size + count = prototypes.item[data.refill].stack_size } end @@ -193,14 +193,14 @@ local function simulate_automatic_artillery(data) end end -local function on_entity_destroyed(event) +local function on_object_destroyed(event) local destroy_id = event.registration_number local unit_id = event.unit_number register_map[destroy_id] = nil turrets_map[unit_id] = nil end -Event.add(defines.events.on_entity_destroyed, on_entity_destroyed) +Event.add(defines.events.on_object_destroyed, on_object_destroyed) local function on_tick() if primitives.index ~= nil and turrets_map[primitives.index] == nil then diff --git a/features/fish_burps.lua b/features/fish_burps.lua index 8d6c93fb..14440da9 100644 --- a/features/fish_burps.lua +++ b/features/fish_burps.lua @@ -1,5 +1,6 @@ -- A feature to add cute flying text of a fish when a player uses a fish to heal themselves. Useful for teamwork. local Event = require 'utils.event' +local Game = require 'utils.game' local function capsule_used(event) if event.item.name ~= "raw-fish" then @@ -16,10 +17,10 @@ local function capsule_used(event) return end - player.surface.create_entity { - name = 'tutorial-flying-text', + Game.create_local_flying_text { + surface = player.physical_surface, text = '[img=item.raw-fish]', - position = {player.position.x,player.position.y-3} -- creates the fish just above players head + position = {player.physical_position.x,player.physical_position.y-3} -- creates the fish just above players head } end diff --git a/features/force_control.lua b/features/force_control.lua index 531adca6..1f0835c1 100644 --- a/features/force_control.lua +++ b/features/force_control.lua @@ -61,7 +61,7 @@ local function get_valid_force(lua_force_or_name) return force end - if type(lua_force_or_name) ~= 'table' or not lua_force_or_name.valid or nil == lua_force_or_name.evolution_factor then + if type(lua_force_or_name) ~= 'table' or not lua_force_or_name.valid then return end diff --git a/features/gui/admin_panel/core.lua b/features/gui/admin_panel/core.lua index 7eab901a..39854c4c 100644 --- a/features/gui/admin_panel/core.lua +++ b/features/gui/admin_panel/core.lua @@ -73,7 +73,7 @@ function Public.get_main_frame(player) local flow = frame.add { type = 'flow', direction = 'horizontal' } Gui.set_style(flow, { horizontal_spacing = 8, vertical_align = 'center', bottom_padding = 4 }) - local label = flow.add { type = 'label', caption = 'Admin panel', style = 'heading_1_label' } + local label = flow.add { type = 'label', caption = 'Admin panel', style = 'frame_title' } label.drag_target = frame local dragger = flow.add { type = 'empty-widget', style = 'draggable_space_header' } @@ -83,7 +83,7 @@ function Public.get_main_frame(player) flow.add { type = 'sprite-button', name = close_button_name, - sprite = 'utility/close_white', + sprite = 'utility/close', clicked_sprite = 'utility/close_black', style = 'close_button', tooltip = {'gui.close-instruction'} diff --git a/features/gui/admin_panel/functions.lua b/features/gui/admin_panel/functions.lua index 86dd0766..ccbf96a0 100644 --- a/features/gui/admin_panel/functions.lua +++ b/features/gui/admin_panel/functions.lua @@ -83,8 +83,8 @@ function Actions.spank(target_name, source_player) if character.health > 5 then character.damage(5, 'player') end - target_player.surface.create_entity { name = 'water-splash', position = target_player.position } - game.print(source_player.name .. ' spanked ' .. target_player.name, Color.warning) + target_player.physical_surface.create_entity { name = 'water-splash', position = target_player.physical_position } + game.print(source_player.name .. ' spanked ' .. target_player.name, {color = Color.warning}) end -- == SURFACE ================================================================= diff --git a/features/gui/admin_panel/lua_console.lua b/features/gui/admin_panel/lua_console.lua index 6cee9204..e5058c61 100644 --- a/features/gui/admin_panel/lua_console.lua +++ b/features/gui/admin_panel/lua_console.lua @@ -30,7 +30,7 @@ local function draw_gui(player) this.last_lua_input[player.index] = this.last_lua_input[player.index] or '' this.last_lua_output[player.index] = this.last_lua_output[player.index] or '' - local info = canvas.add { type = 'frame', style = 'deep_frame_in_shallow_frame_for_tabs', direction = 'vertical' } + local info = canvas.add { type = 'frame', style = 'deep_frame_in_shallow_frame', direction = 'vertical' } Gui.set_style(info, { padding = 12, horizontally_stretchable = true }) info.add { type = 'label', caption = '[font=default-bold][color=green]Input:[/color][/font]' } info.add { type = 'label', caption = ' - no need to append `/c` at the beginning of the code' } diff --git a/features/gui/admin_panel/map_manager.lua b/features/gui/admin_panel/map_manager.lua index e57da75b..0ac7a44b 100644 --- a/features/gui/admin_panel/map_manager.lua +++ b/features/gui/admin_panel/map_manager.lua @@ -3,6 +3,7 @@ local Event = require 'utils.event' local Gui = require 'utils.gui' local math = require 'utils.math' local Surface = require 'features.gui.admin_panel.functions'.surface +local RS = require 'map_gen.shared.redmew_surface' local main_button_name = Gui.uid_name() local slider_tag_name = Gui.uid_name() @@ -187,7 +188,7 @@ local function draw_gui(player) value_step = 0.01, }, format = '%.2f', - value = game.forces.enemy.evolution_factor * 100, + value = game.forces.enemy.get_evolution_factor(RS.get_surface_name()) * 100, tooltip = 'Current value, %', }) make_slider(row_3, { @@ -316,7 +317,7 @@ end) Gui.on_click(on_evolution_value, function(event) local element = event.element local value = update_slider(element) - game.forces.enemy.evolution_factor = value / 100 + game.forces.enemy.set_evolution_factor(value / 100, RS.get_surface_name()) end) Gui.on_click(on_evolution_destroy_factor, function(event) diff --git a/features/gui/admin_panel/player_manager.lua b/features/gui/admin_panel/player_manager.lua index 42905344..f85c7321 100644 --- a/features/gui/admin_panel/player_manager.lua +++ b/features/gui/admin_panel/player_manager.lua @@ -193,7 +193,6 @@ local function draw_gui(player) local textbox = row_3.add { type = 'text-box', text = generate_ban_text(player) } Gui.set_style(textbox, { minimal_width = 460, maximal_width = 460, minimal_height = 72, horizontally_stretchable = true, vertically_stretchable = true }) textbox.word_wrap = true - textbox.clear_and_focus_on_right_click = true local flow_3 = row_3.add { type = 'flow', direction = 'horizontal' } Gui.add_pusher(flow_3) diff --git a/features/gui/camera.lua b/features/gui/camera.lua index 044ca007..eee4da9d 100644 --- a/features/gui/camera.lua +++ b/features/gui/camera.lua @@ -46,18 +46,18 @@ local function create_camera(args, player) end if not mainframe then - mainframe = mainframeflow.add {type = 'frame', name = mainframeid, direction = 'vertical', style = 'captionless_frame'} + mainframe = mainframeflow.add {type = 'frame', name = mainframeid, direction = 'vertical'} mainframe.visible = true end local headerframe = mainframe.headerframe if not headerframe then - mainframe.add {type = 'frame', name = 'headerframe', direction = 'horizontal', style = 'captionless_frame'} + mainframe.add {type = 'frame', name = 'headerframe', direction = 'horizontal'} end local cameraframe = mainframe.cameraframe if not cameraframe then - mainframe.add {type = 'frame', name = 'cameraframe', style = 'captionless_frame'} + mainframe.add {type = 'frame', name = 'cameraframe'} end mainframe.add {type = 'label', caption = 'Following: ' .. target.name} @@ -88,7 +88,7 @@ end local function camera_command(args, player) destroy_camera({player = player}) -- Once the old camera is destroyed, check to see if we need to make a new one - if global.config.camera_disabled then + if storage.config.camera_disabled then player.print('The watch/camera function has been disabled for performance reasons.') return end @@ -98,8 +98,8 @@ local function camera_command(args, player) end local function update_camera_render(target, targetframe, zoom, size, visible) - local position = {x = target.position.x, y = target.position.y - 0.5} - local surface_index = target.surface.index + local position = {x = target.physical_position.x, y = target.physical_position.y - 0.5} + local surface_index = target.physical_surface.index local preview_size = size local camera = targetframe.camera @@ -153,7 +153,7 @@ local function update_camera_size(targetframe) end local function on_tick() - if global.config.camera_disabled then + if storage.config.camera_disabled then return end for table_key, camera_table in pairs(camera_users) do diff --git a/features/gui/debug/_g_view.lua b/features/gui/debug/_g_view.lua index 43e74a63..f8783b2a 100644 --- a/features/gui/debug/_g_view.lua +++ b/features/gui/debug/_g_view.lua @@ -42,7 +42,7 @@ local ignore = { serpent = true, log = true, table_size = true, - global = true, + storage = true, remote = true, commands = true, settings = true, @@ -51,7 +51,9 @@ local ignore = { util = true, mod_gui = true, game = true, - rendering = true + rendering = true, + helpers = true, + prototypes = true, } local header_name = Gui.uid_name() diff --git a/features/gui/debug/command.lua b/features/gui/debug/command.lua index 3155da5a..3fafd2fe 100644 --- a/features/gui/debug/command.lua +++ b/features/gui/debug/command.lua @@ -135,6 +135,6 @@ Command.add( end value = dump(value) - game.write_file('dump.lua', value, false, player_index) + helpers.write_file('dump.lua', value, false, player_index) end ) diff --git a/features/gui/debug/event_view.lua b/features/gui/debug/event_view.lua index f80e258c..b0e6aff3 100644 --- a/features/gui/debug/event_view.lua +++ b/features/gui/debug/event_view.lua @@ -25,14 +25,14 @@ local clear_filter_name = Gui.uid_name() -- global tables local enabled = {} local last_events = {} -global.debug_event_view = { +storage.debug_event_view = { enabled = enabled, last_events = last_events, filter = '' } function Public.on_open_debug() - local tbl = global.debug_event_view + local tbl = storage.debug_event_view if tbl then enabled = tbl.enabled last_events = tbl.last_events @@ -40,7 +40,7 @@ function Public.on_open_debug() enabled = {} last_events = {} - global.debug_event_view = { + storage.debug_event_view = { enabled = enabled, last_events = last_events } @@ -108,7 +108,7 @@ local function redraw_event_table(gui_table, filter) end function Public.show(container) - local filter = global.debug_event_view.filter + local filter = storage.debug_event_view.filter local main_frame_flow = container.add({type = 'flow', direction = 'vertical'}) @@ -136,7 +136,7 @@ Gui.on_text_changed( local filter = element.text:gsub(' ', '_') - global.debug_event_view.filter = filter + storage.debug_event_view.filter = filter element.text = filter gui_table.clear() @@ -153,7 +153,7 @@ Gui.on_click( local gui_table = data.gui_table filter_textfield.text = '' - global.debug_event_view.filter = '' + storage.debug_event_view.filter = '' gui_table.clear() redraw_event_table(gui_table, '') diff --git a/features/gui/debug/global_view.lua b/features/gui/debug/global_view.lua index f41e066d..cfad63d3 100644 --- a/features/gui/debug/global_view.lua +++ b/features/gui/debug/global_view.lua @@ -16,7 +16,7 @@ local right_panel_name = Gui.uid_name() local input_text_box_name = Gui.uid_name() local refresh_name = Gui.uid_name() -Public.name = 'global' +Public.name = 'storage' function Public.show(container) local main_flow = container.add {type = 'flow', direction = 'horizontal'} @@ -25,7 +25,7 @@ function Public.show(container) local left_panel_style = left_panel.style left_panel_style.width = 300 - for key, _ in pairs(global) do + for key, _ in pairs(storage) do if not ignore[key] then local header = left_panel.add({type = 'flow'}).add {type = 'label', name = header_name, caption = tostring(key)} @@ -93,7 +93,7 @@ Gui.on_click( input_text_box.text = concat {"global['", key, "']"} input_text_box.style.font_color = Color.black - local content = dump(global[key]) or 'nil' + local content = dump(storage[key]) or 'nil' right_panel.text = content end ) diff --git a/features/gui/debug/gui_data_view.lua b/features/gui/debug/gui_data_view.lua index b2fb9cb2..8ceebdb7 100644 --- a/features/gui/debug/gui_data_view.lua +++ b/features/gui/debug/gui_data_view.lua @@ -212,7 +212,7 @@ Gui.on_click( if selected_player_index then input_text_box.text = - concat {'global.tokens[', Gui.token, '].data[', selected_player_index, '][', element_index, ']'} + concat {'storage.tokens[', Gui.token, '].data[', selected_player_index, '][', element_index, ']'} else input_text_box.text = 'missing player' end diff --git a/features/gui/debug/redmew_global_view.lua b/features/gui/debug/redmew_global_view.lua index b7885b93..6aa6dc12 100644 --- a/features/gui/debug/redmew_global_view.lua +++ b/features/gui/debug/redmew_global_view.lua @@ -86,7 +86,7 @@ Gui.on_click( element.style.font_color = Color.orange data.selected_header = element - input_text_box.text = concat {'global.tokens[', token_id, ']'} + input_text_box.text = concat {'storage.tokens[', token_id, ']'} input_text_box.style.font_color = Color.black local content = dump(Token.get_global(token_id)) or 'nil' diff --git a/features/gui/description_generator.lua b/features/gui/description_generator.lua index f1d73838..9cd67bc8 100644 --- a/features/gui/description_generator.lua +++ b/features/gui/description_generator.lua @@ -3,7 +3,7 @@ local Command = require 'utils.command' local Ranks = require 'resources.ranks' local Scenario_Info = require 'features.gui.info' -local creators = global.config.map_info +local creators = storage.config.map_info local gui_frame = Gui.uid_name() local generate_tags = Gui.uid_name() diff --git a/features/gui/evolution_progress.lua b/features/gui/evolution_progress.lua index cdc07870..fb693151 100644 --- a/features/gui/evolution_progress.lua +++ b/features/gui/evolution_progress.lua @@ -2,6 +2,7 @@ local Event = require 'utils.event' local Gui = require 'utils.gui' local Global = require 'utils.global' local Toast = require 'features.gui.toast' +local RS = require 'map_gen.shared.redmew_surface' local round = math.round local pairs = pairs local main_button_name = Gui.uid_name() @@ -34,7 +35,7 @@ local function get_evolution_percentage() return 0 end - local value = round(game.forces.enemy.evolution_factor * 1000) * 0.001 + local value = round(game.forces.enemy.get_evolution_factor(RS.get_surface_name()) * 1000) * 0.001 if value < 0.001 then -- 0.00 won't be shown on the button as value return 0.001 diff --git a/features/gui/info.lua b/features/gui/info.lua index b5f03814..3da592bf 100644 --- a/features/gui/info.lua +++ b/features/gui/info.lua @@ -10,7 +10,7 @@ local Color = require 'resources.color_presets' local format = string.format -local config = global.config +local config = storage.config local config_mapinfo = config.map_info local config_prewards = config.player_rewards @@ -416,7 +416,7 @@ local pages = { local market_label = grid.add {type = 'label', caption = {'info.softmods_market_text'}} market_label.style.single_line = false - grid.add {type = 'sprite', sprite = 'item/player-port'} + grid.add {type = 'sprite', sprite = 'item/simple-entity-with-owner'} local train_savior = grid.add {type = 'label', caption = {'info.softmods_saviour_label'}} local train_savior_style = train_savior.style train_savior_style.font = 'default-listbox' @@ -716,9 +716,7 @@ Gui.on_text_changed(editable_textbox_name, function(event) primitives.info_edited = true end) -Gui.on_custom_close(main_frame_name, function(event) - close_main_frame(event.element, event.player) -end) +Gui.on_custom_close(main_frame_name, toggle) Gui.allow_player_to_toggle_top_element_visibility(main_button_name) diff --git a/features/gui/paint.lua b/features/gui/paint.lua index 5a23d469..012401c4 100644 --- a/features/gui/paint.lua +++ b/features/gui/paint.lua @@ -2,7 +2,7 @@ local Event = require 'utils.event' local Gui = require 'utils.gui' local Global = require 'utils.global' -local config = global.config.paint +local config = storage.config.paint local default_fallback_hidden_tile = 'dirt-6' local brush_tools = { @@ -181,7 +181,7 @@ local function get_tile_localised_name(tile_name) return end - local proto = game.tile_prototypes[tile_name] + local proto = prototypes.tile[tile_name] if proto then return proto.localised_name or proto.name end diff --git a/features/gui/player_list.lua b/features/gui/player_list.lua index 479cb3a1..0efde348 100644 --- a/features/gui/player_list.lua +++ b/features/gui/player_list.lua @@ -403,9 +403,9 @@ local column_builders = { lines = lines + 1 if not prototype_locale_string_cache[name] then - local prototype = game.entity_prototypes[name] + local prototype = prototypes.entity[name] if not prototype then - prototype = game.item_prototypes[name] + prototype = prototypes.item[name] end prototype_locale_string_cache[name] = prototype and prototype.localised_name or {'', name} end @@ -534,7 +534,7 @@ local function get_default_player_settings() report_heading_name, } - if global.config.player_list.show_coin_column then + if storage.config.player_list.show_coin_column then table.insert(columns, 6, coin_heading_name) end diff --git a/features/gui/poll.lua b/features/gui/poll.lua index e84b419e..2b288817 100644 --- a/features/gui/poll.lua +++ b/features/gui/poll.lua @@ -257,7 +257,7 @@ local function redraw_poll_viewer_content(data) question_flow.add { type = 'sprite-button', name = poll_view_edit_name, - sprite = 'utility/rename_icon_normal', + sprite = 'utility/rename_icon', tooltip = 'Edit Poll.' } diff --git a/features/gui/popup.lua b/features/gui/popup.lua index a073bb44..e3e15364 100644 --- a/features/gui/popup.lua +++ b/features/gui/popup.lua @@ -39,9 +39,9 @@ local function show_popup(player, message, title_text, sprite_path, popup_name) if (popup) then Gui.destroy(popup) end - frame = player.gui.center.add {name = 'Popup.' .. popup_name, type = 'frame', direction = 'vertical', style = 'captionless_frame'} + frame = player.gui.center.add {name = 'Popup.' .. popup_name, type = 'frame', direction = 'vertical' } else - frame = player.gui.center.add {type = 'frame', direction = 'vertical', style = 'captionless_frame'} + frame = player.gui.center.add {type = 'frame', direction = 'vertical' } end frame.style.minimal_width = 300 diff --git a/features/gui/radio.lua b/features/gui/radio.lua index 383d0e0b..5015f04d 100644 --- a/features/gui/radio.lua +++ b/features/gui/radio.lua @@ -201,7 +201,7 @@ local function handler(event) if subname == 'radio_play:' then local path = string.sub(name, 12) local player = game.get_player(event.player_index) - if (game.is_valid_sound_path(path)) then + if (helpers.is_valid_sound_path(path)) then player.play_sound {path = path} return else diff --git a/features/gui/redmew_settings.lua b/features/gui/redmew_settings.lua index 6b42fc06..b3671aa7 100644 --- a/features/gui/redmew_settings.lua +++ b/features/gui/redmew_settings.lua @@ -274,12 +274,7 @@ local function setting_set(event) element_data.previous_value = Settings.toScalar(setting_name, event.old_value) end -Gui.on_custom_close( - main_frame_name, - function(event) - Gui.destroy(event.element) - end -) +Gui.on_custom_close(main_frame_name, toggle) Gui.allow_player_to_toggle_top_element_visibility(main_button_name) diff --git a/features/gui/score.lua b/features/gui/score.lua index c691da9f..f664fdaf 100644 --- a/features/gui/score.lua +++ b/features/gui/score.lua @@ -10,7 +10,7 @@ local ScoreTracker = require 'utils.score_tracker' local format_number = require 'util'.format_number local pairs = pairs local concat = table.concat -local scores_to_show = global.config.score.global_to_show +local scores_to_show = storage.config.score.global_to_show local set_timeout_in_ticks = Schedule.set_timeout_in_ticks local main_frame_name = Gui.uid_name() local main_button_name = Gui.uid_name() @@ -111,11 +111,11 @@ local function score_show(top) local frame = top.add { type = 'frame', name = main_frame_name, - style = 'finished_game_subheader_frame', + style = 'subheader_frame', index = top[main_button_name].get_index_in_parent() + 1 } frame.location = { x = 1, y = 38 } - Gui.set_style(frame, { natural_height = Styles.default_top_element.style.minimal_height, height = Styles.default_top_element.style.minimal_height }) + Gui.set_style(frame, { natural_height = Styles.default_top_element.style.minimal_height, height = Styles.default_top_element.style.minimal_height, padding = 6 }) local score_table = frame.add {type = 'table', name = 'score_table', column_count = table_size(scores)} local style = score_table.style diff --git a/features/gui/tag_group.lua b/features/gui/tag_group.lua index 6f983585..df38a2d7 100644 --- a/features/gui/tag_group.lua +++ b/features/gui/tag_group.lua @@ -175,7 +175,7 @@ local function draw_main_frame_content(parent) row.add { type = 'sprite-button', name = edit_tag_button_name, - sprite = 'utility/rename_icon_normal', + sprite = 'utility/rename_icon', tooltip = {'tag_group.edit_group'} } edit_button.style.top_padding = 0 @@ -636,7 +636,7 @@ Gui.on_click( path = type .. '/' .. data.choose.elem_value end - if path and not frame.gui.is_valid_sprite_path(path) then + if path and not helpers.is_valid_sprite_path(path) then player.print({'tag_group.sprite_not_valid', path}) return end diff --git a/features/gui/tasklist.lua b/features/gui/tasklist.lua index 3a768bd5..61117341 100644 --- a/features/gui/tasklist.lua +++ b/features/gui/tasklist.lua @@ -267,7 +267,7 @@ local function redraw_tasks(data, enabled) parent.add({type = 'flow'}).add { type = 'sprite-button', name = edit_task_button_name, - sprite = 'utility/rename_icon_normal', + sprite = 'utility/rename_icon', tooltip = edit_button_tooltip } edit_button.enabled = enabled @@ -346,7 +346,7 @@ local function draw_main_frame(left, player) announcements_header_flow.add { type = 'sprite-button', name = announcements_edit_button_name, - sprite = 'utility/rename_icon_normal', + sprite = 'utility/rename_icon', tooltip = edit_announcements_button_tooltip } edit_announcements_button.enabled = enabled diff --git a/features/gui/toast.lua b/features/gui/toast.lua index 775b841b..509ba546 100644 --- a/features/gui/toast.lua +++ b/features/gui/toast.lua @@ -86,7 +86,7 @@ local function toast_to(player, duration, sound) local flow_frame = frame_holder.add { type = 'flow', direction = 'vertical' } local frame = - flow_frame.add({type = 'frame', name = toast_frame_name, direction = 'vertical', style = 'captionless_frame'}) + flow_frame.add({type = 'frame', name = toast_frame_name, direction = 'vertical' }) frame.style.width = 300 local container = frame.add({type = 'flow', name = toast_container_name, direction = 'horizontal'}) diff --git a/features/harmful_mining.lua b/features/harmful_mining.lua index cf51d6e0..8f1fd882 100644 --- a/features/harmful_mining.lua +++ b/features/harmful_mining.lua @@ -1,3 +1,4 @@ +local Game = require 'utils.game' local Global = require 'utils.global' local Event = require 'utils.event' local random = math.random @@ -40,12 +41,12 @@ local function compute_fullness(player, position) local damage = ceil((warn_player.count / 2) * warn_player.count) if player.character.health >= damage then player.character.damage(damage, 'player', 'explosion') - player.character.surface.create_entity({ name = 'water-splash', position = player.position }) - player.surface.create_entity({ name = 'flying-text', position = { position.x, position.y + 0.6 }, text = messages[random(#messages)], color = { r = 0.75, g = 0.0, b = 0.0 } }) + player.character.surface.create_entity({ name = 'water-splash', position = player.physical_position }) + Game.create_local_flying_text({ surface = player.surface, position = { position.x, position.y + 0.6 }, text = messages[random(#messages)], color = { r = 0.75, g = 0.0, b = 0.0 } }) else player.character.die('enemy') is_player_warned(player, true) - game.print(player.name .. ' should have emptied their pockets.', { r = 0.75, g = 0.0, b = 0.0 }) + game.print(player.name .. ' should have emptied their pockets.', {color = { r = 0.75, g = 0.0, b = 0.0 }}) return free_slots end end @@ -54,7 +55,7 @@ local function compute_fullness(player, position) end if free_slots > 1 then if floor(inventory_size / free_slots) == 10 then -- When player has 10% free slots - player.surface.create_entity({ name = 'flying-text', position = { position.x, position.y + 0.6 }, text = 'You are feeling heavy', color = { r = 1.0, g = 0.5, b = 0.0 } }) + Game.create_local_flying_text({ surface = player.surface, position = { position.x, position.y + 0.6 }, text = 'You are feeling heavy', color = { r = 1.0, g = 0.5, b = 0.0 } }) end end return free_slots diff --git a/features/infinite_storage_chest.lua b/features/infinite_storage_chest.lua index bc4cf141..1ce05189 100644 --- a/features/infinite_storage_chest.lua +++ b/features/infinite_storage_chest.lua @@ -5,12 +5,13 @@ local Token = require 'utils.token' local Gui = require 'utils.gui' local Task = require 'utils.task' local Global = require 'utils.global' +local Table = require 'utils.table' local format = string.format local chests = {} local chests_next = {} -local config = global.config.infinite_storage_chest +local config = storage.config.infinite_storage_chest Global.register( @@ -31,7 +32,7 @@ function Module.create_chest(surface, position, storage) end local function built_entity(event) - local entity = event.created_entity + local entity = event.entity if not entity or not entity.valid or entity.name ~= 'infinity-chest' then return end @@ -42,7 +43,7 @@ local function built_entity(event) end local function get_stack_size(name) - local proto = game.item_prototypes[name] + local proto = prototypes.item[name] if not proto then log('item prototype ' .. name .. ' not found') return 1 @@ -97,15 +98,16 @@ local function tick() chests[chest_id] = nil else local storage = chest_data.storage - local inv = entity.get_inventory(1) --defines.inventory.chest + local inv = entity.get_inventory(defines.inventory.chest) local contents = inv.get_contents() - for name, count in pairs(contents) do - do_item(name, count, inv, storage) + for _, item_stack in pairs(contents) do + do_item(item_stack.name, item_stack.count, inv, storage) end + local dict = Table.array_to_dict(contents, 'name') for name, _ in pairs(storage) do - if not contents[name] then + if not dict[name] then do_item(name, 0, inv, storage) end end @@ -114,7 +116,7 @@ end local function create_chest_gui_content(frame, player, chest) local storage = chest.storage - local inv = chest.entity.get_inventory(1).get_contents() + local inv = Table.array_to_dict(chest.entity.get_inventory(defines.inventory.chest).get_contents(), 'name') local grid = frame[chest_content_table_name] @@ -125,7 +127,7 @@ local function create_chest_gui_content(frame, player, chest) end for name, count in pairs(storage) do - local number = count + (inv[name] or 0) + local number = count + (inv[name] and inv[name].count or 0) grid.add { type = 'sprite-button', sprite = 'item/' .. name, @@ -136,12 +138,12 @@ local function create_chest_gui_content(frame, player, chest) } end - for name, count in pairs(inv) do + for name, item_stack in pairs(inv) do if not storage[name] then grid.add { type = 'sprite-button', sprite = 'item/' .. name, - number = count, + number = item_stack.count, tooltip = name, --style = 'slot_button' enabled = false diff --git a/features/landfill_remover.lua b/features/landfill_remover.lua index 28a30b9b..71f07ec3 100644 --- a/features/landfill_remover.lua +++ b/features/landfill_remover.lua @@ -1,3 +1,4 @@ +-- Module deprecated in 2.0, became a built-in feature -- This feature allows players to remove landfill. -- To use, create a deconstruction planner with the landfill tile filter and select tiles only mode. -- Use the decon planner within range of the landfill to remove it @@ -7,7 +8,7 @@ local Rank = require 'features.rank_system' local Ranks = require 'resources.ranks' local table = require 'utils.table' local math = require 'utils.math' -local config = global.config.landfill_remover +local config = storage.config.landfill_remover local Public = {} diff --git a/features/landfill_remover_tests.lua b/features/landfill_remover_tests.lua index 51f8cf81..45716c23 100644 --- a/features/landfill_remover_tests.lua +++ b/features/landfill_remover_tests.lua @@ -7,7 +7,7 @@ local Ranks = require 'resources.ranks' local LandfillRemover = require 'features.landfill_remover' local main_inventory = defines.inventory.character_main -local config = global.config.landfill_remover +local config = storage.config.landfill_remover local tile_items = { 'stone-brick', diff --git a/features/lazy_bastard.lua b/features/lazy_bastard.lua index 6bc5aba4..705040b3 100644 --- a/features/lazy_bastard.lua +++ b/features/lazy_bastard.lua @@ -19,7 +19,7 @@ local clean_energy_interface = Token.register(function (params) entity.destroy() end) -if global.config.market.enabled then +if storage.config.market.enabled then local new_items = { { name = 'welcome-package', @@ -65,7 +65,7 @@ end -- players cannot build anything, just place ghosts Event.add(defines.events.on_built_entity, function(event) - local entity = event.created_entity + local entity = event.entity if not entity or not entity.valid then return end @@ -99,7 +99,9 @@ Event.add(defines.events.on_built_entity, function(event) return end - player.insert(event.stack) + for _, stack in pairs(event.consumed_items.get_contents()) do + player.insert(stack) + end end) end) @@ -107,10 +109,10 @@ Command.add('lazy-bastard-bootstrap', { description = {'command_description.lazy_bastard_bootstrap'}, required_rank = Ranks.admin, }, function(_, player) - local surface = player.surface + local surface = player.physical_surface local force = player.force - local pos = player.position + local pos = player.physical_position pos.y = round(pos.y - 4) pos.x = round(pos.x) diff --git a/features/market.lua b/features/market.lua index 139944bc..1d371c58 100644 --- a/features/market.lua +++ b/features/market.lua @@ -3,6 +3,7 @@ local Event = require 'utils.event' local Token = require 'utils.token' local Task = require 'utils.task' local Command = require 'utils.command' +local Game = require 'utils.game' local Global = require 'utils.global' local Retailer = require 'features.retailer' local Ranks = require 'resources.ranks' @@ -20,7 +21,7 @@ local pairs = pairs local round = math.round local random = math.random local format = string.format -local market_config = global.config.market +local market_config = storage.config.market local currency = market_config.currency local entity_drop_amount = market_config.entity_drop_amount @@ -124,12 +125,12 @@ local function fish_earned(event, amount) local stack = {name = currency, count = amount} local inserted = player.insert(stack) - player.surface.create_entity{name="flying-text", position = {player.position.x - 1, player.position.y}, text = "+" .. amount .. " [img=item.coin]", color = Color.gold, render_player_index = player.index} + Game.create_local_flying_text{ surface = player.surface, position = {player.position.x - 1, player.position.y}, text = "+" .. amount .. " [img=item.coin]", color = Color.gold, render_player_index = player.index} local diff = amount - inserted if diff > 0 then stack.count = diff - player.surface.spill_item_stack(player.position, stack, true) + player.surface.spill_item_stack{ position = player.position, stack = stack, enable_looted = true } end change_for_player(player_index, coins_earned_name, amount) @@ -154,7 +155,7 @@ end local spill_items = Token.register( function(data) - data.surface.spill_item_stack(data.position, {name = currency, count = data.count}, true) + data.surface.spill_item_stack{ position = data.position, stack = {name = currency, count = data.count}, enable_looted = true } end ) @@ -308,7 +309,7 @@ local function player_created(event) return end - local count = global.config.player_rewards.info_player_reward and 1 or 10 + local count = storage.config.player_rewards.info_player_reward and 1 or 10 player.insert {name = currency, count = count} end diff --git a/features/nuke_control.lua b/features/nuke_control.lua index d3c08a4f..c2cac9be 100644 --- a/features/nuke_control.lua +++ b/features/nuke_control.lua @@ -3,6 +3,7 @@ local Rank = require 'features.rank_system' local Utils = require 'utils.core' local Task = require 'utils.task' local Token = require 'utils.token' +local Game = require 'utils.game' local Global = require 'utils.global' local Report = require 'features.report' local Popup = require 'features.gui.popup' @@ -210,15 +211,15 @@ local function on_capsule_used(event) end if item.name == 'artillery-targeting-remote' then - player.surface.create_entity { - name = 'flying-text', + Game.create_local_flying_text { + surface = player.surface, text = player.name, color = player.color, position = event.position } end - local nuke_control = global.config.nuke_control + local nuke_control = storage.config.nuke_control if not nuke_control.enable_autokick and not nuke_control.enable_autoban then return end diff --git a/features/permissions.lua b/features/permissions.lua index df91902c..0d87bb84 100644 --- a/features/permissions.lua +++ b/features/permissions.lua @@ -11,7 +11,7 @@ Global.register(data, function(tbl) data = tbl end) -local config = global.config.permissions +local config = storage.config.permissions local Public = {} -- defines.input_action listed at https://lua-api.factorio.com/latest/defines.html#defines.input_action diff --git a/features/player_colors.lua b/features/player_colors.lua index d0be1460..e9a30ef5 100644 --- a/features/player_colors.lua +++ b/features/player_colors.lua @@ -81,7 +81,7 @@ local function on_command(event) return end - player.print({'player_colors.gui_setting_reference_message'}, Color.success) + player.print({'player_colors.gui_setting_reference_message'}, {color = Color.success}) Settings.set(player_index, player_color_name, player.color) local error = Settings.validate(player_chat_color_name, player.chat_color) diff --git a/features/player_create.lua b/features/player_create.lua index 5bc0d8a3..21c11f90 100644 --- a/features/player_create.lua +++ b/features/player_create.lua @@ -10,7 +10,7 @@ local get_random_weighted = table.get_random_weighted local Public = {} function Public.show_start_up(player) - local config = global.config.player_create + local config = storage.config.player_create local p = player.print for _, message in pairs(config.join_messages) do p(message) @@ -28,16 +28,16 @@ function Public.show_start_up(player) end if _DEBUG and game.is_multiplayer() then - game.print('THIS MULTIPLAYER MAP IS IN DEBUG!!!', Color.warning) + game.print('THIS MULTIPLAYER MAP IS IN DEBUG!!!', {color = Color.warning}) elseif _DEBUG then - game.print("DON'T LAUNCH THIS MAP! DEBUG MODE IS ENABLED!!!", Color.warning) + game.print("DON'T LAUNCH THIS MAP! DEBUG MODE IS ENABLED!!!", {color = Color.warning}) elseif not _DEBUG and not game.is_multiplayer() then - player.print('To change your name in single-player, open chat and type the following /c game.player.name = "your_name"', Color.info) + player.print('To change your name in single-player, open chat and type the following /c game.player.name = "your_name"', {color = Color.info}) end end local function player_created(event) - local config = global.config.player_create + local config = storage.config.player_create local player = game.get_player(event.player_index) if not player or not player.valid then @@ -79,7 +79,7 @@ if _CHEATS then ) local function player_created_cheat_mode(event) - local config = global.config.player_create + local config = storage.config.player_create local player = game.get_player(event.player_index) if not player or not player.valid then @@ -110,10 +110,10 @@ if _CHEATS then if cheats.start_with_power_armor then player_insert({name = 'power-armor-mk2', count = 1}) local armor_put = player.get_inventory(5)[1].grid.put - armor_put({name = 'fusion-reactor-equipment'}) - armor_put({name = 'fusion-reactor-equipment'}) - armor_put({name = 'fusion-reactor-equipment'}) - armor_put({name = 'fusion-reactor-equipment'}) + armor_put({name = 'fission-reactor-equipment'}) + armor_put({name = 'fission-reactor-equipment'}) + armor_put({name = 'fission-reactor-equipment'}) + armor_put({name = 'fission-reactor-equipment'}) armor_put({name = 'personal-roboport-mk2-equipment'}) armor_put({name = 'personal-roboport-mk2-equipment'}) armor_put({name = 'personal-laser-defense-equipment'}) diff --git a/features/player_logistic_requests.lua b/features/player_logistic_requests.lua index 7c934c2d..293f2a14 100644 --- a/features/player_logistic_requests.lua +++ b/features/player_logistic_requests.lua @@ -1,5 +1,8 @@ -- This module saves players' logistic requests slots between maps -- Dependencies + +--TODO: Rewrite, feature deprecated for 2.0 +--[[ local Command = require 'utils.command' local Event = require 'utils.event' local Game = require 'utils.game' @@ -71,7 +74,7 @@ local function validate_entry(item, proto_table, player) return item end - player.print({'player_logistic_requests.incompatible_item', item.name}, Color.warning) + player.print({'player_logistic_requests.incompatible_item', item.name}, {color = Color.warning}) end --- Sets the logistic request slots of a player. @@ -90,7 +93,7 @@ local set_bars_callback = return end - local item_prototypes = game.item_prototypes + local item_prototypes = prototypes.item local item for i = 1, logistic_slots do item = validate_entry(bars[i], item_prototypes, player) @@ -195,7 +198,6 @@ local function delete_bars(_, player) end -- Events - Event.add(Server.events.on_server_started, register_server_start_events) -- Commands @@ -226,3 +228,4 @@ Command.add( }, delete_bars ) +]] \ No newline at end of file diff --git a/features/player_quick_bars.lua b/features/player_quick_bars.lua index 852ccb52..609886a8 100644 --- a/features/player_quick_bars.lua +++ b/features/player_quick_bars.lua @@ -58,7 +58,7 @@ local function validate_entry(item, proto_table, player) return item end - player.print({'player_quick_bars.incompatible_item', item}, Color.warning) + player.print({'player_quick_bars.incompatible_item', item}, {color = Color.warning}) end --- Sets the quick bars of a player. @@ -76,7 +76,7 @@ local set_bars_callback = return end - local item_prototypes = game.item_prototypes + local item_prototypes = prototypes.item local item for i = 1, quickbar_slots do item = validate_entry(bars[i], item_prototypes, player) diff --git a/features/player_stats.lua b/features/player_stats.lua index e7e96e09..7b40b441 100644 --- a/features/player_stats.lua +++ b/features/player_stats.lua @@ -1,5 +1,6 @@ local Global = require 'utils.global' local Event = require 'utils.event' +local SA = require 'utils.space_age' local ScoreTracker = require 'utils.score_tracker' require 'utils.table' @@ -22,6 +23,7 @@ local player_console_chats_name = 'player-console-chats' local player_items_crafted_name = 'player-items-crafted' local player_distance_walked_name = 'player-distance-walked' local satellites_launched_name = 'satellites-launched' +local rockets_launched_name = 'rockets-launched' local player_units_killed_name = 'player-units-killed' -- biters and spitters local player_worms_killed_name = 'player-worms-killed' local player_spawners_killed_name = 'player-spawners-killed' @@ -33,7 +35,7 @@ local player_resources_hand_mined_name = 'player_resources_hand_mined' local resources_hand_mined_name = 'resources_hand_mined' local resources_exhausted_name = 'resources_exhausted' -ScoreTracker.register(rocks_smashed_name, {'player_stats.rocks_smashed'}, '[img=entity.rock-huge]') +ScoreTracker.register(rocks_smashed_name, {'player_stats.rocks_smashed'}, '[img=entity.huge-rock]') ScoreTracker.register(trees_cut_down_name, {'player_stats.trees_cut_down'}, '[img=entity.tree-02]') ScoreTracker.register(player_count_name, {'player_stats.player_count'}) ScoreTracker.register(kills_by_trains_name, {'player_stats.kills_by_trains'}, '[img=item.locomotive]') @@ -46,7 +48,10 @@ ScoreTracker.register(player_deaths_name, {'player_stats.player_deaths'}) ScoreTracker.register(player_console_chats_name, {'player_stats.player_console_chats'}) ScoreTracker.register(player_items_crafted_name, {'player_stats.player_items_crafted'}) ScoreTracker.register(player_distance_walked_name, {'player_stats.player_distance_walked'}) -ScoreTracker.register(satellites_launched_name, {'player_stats.satellites_launched'}, '[img=item.satellite]') +if not SA.enabled() then + ScoreTracker.register(satellites_launched_name, {'player_stats.satellites_launched'}, '[img=item.satellite]') +end +ScoreTracker.register(rockets_launched_name, {'player_stats.rockets_launched'}, '[img=item.rocket-silo]') ScoreTracker.register(player_units_killed_name, {'player_stats.player_units_killed'}) ScoreTracker.register(player_worms_killed_name, {'player_stats.player_worms_killed'}) ScoreTracker.register(player_spawners_killed_name, {'player_stats.player_spawners_killed'}) @@ -110,7 +115,7 @@ end) local function player_created(event) local index = event.player_index - player_last_position[index] = game.get_player(index).position + player_last_position[index] = game.get_player(index).physical_position player_death_causes[index] = {} change_for_global(player_count_name, 1) end @@ -198,7 +203,7 @@ local function player_console_chat(event) end local function player_built_entity(event) - local entity = event.created_entity + local entity = event.entity if not entity or not entity.valid then return end @@ -301,7 +306,9 @@ local function rocket_launched(event) return end - local inventory = entity.get_inventory(defines.inventory.rocket) + change_for_global(rockets_launched_name, 1) + + local inventory = entity.get_inventory(defines.inventory.rocket_silo_rocket) if not inventory or not inventory.valid then return end @@ -328,7 +335,7 @@ local function tick() if (p.afk_time < 30 or p.walking_state.walking) and p.vehicle == nil then local index = p.index local last_pos = player_last_position[index] - local pos = p.position + local pos = p.physical_position local d_x = last_pos.x - pos.x local d_y = last_pos.y - pos.y @@ -368,6 +375,7 @@ local Public = { player_console_chats_name = player_console_chats_name, player_items_crafted_name = player_items_crafted_name, player_distance_walked_name = player_distance_walked_name, + rockets_launched_name = rockets_launched_name, satellites_launched_name = satellites_launched_name, player_units_killed_name = player_units_killed_name, player_worms_killed_name = player_worms_killed_name, diff --git a/features/popup_chat.lua b/features/popup_chat.lua index eb2f6eec..0ad99c60 100644 --- a/features/popup_chat.lua +++ b/features/popup_chat.lua @@ -1,7 +1,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' -local config = global.config.popup_chat +local config = storage.config.popup_chat local MIN_LIFETIME = config.min_lifetime or 06 * 60 -- 06s local MAX_LIFETIME = config.max_lifetime or 20 * 60 -- 20s local MIN_MESSAGE_LENGTH = config.min_length or 40 @@ -48,30 +48,29 @@ local function on_console_chat(event) return end - local popup_ID = data.popup_chat[index] - if popup_ID then - rendering.destroy(popup_ID) - data.popup_chat[popup_ID] = nil + local popup = data.popup_chat[index] + if popup and popup.valid then + popup.destroy() + data.popup_chat[index] = nil end local safe_message = get_safe_message(message) local color = player.color color.a = 0.9 - popup_ID = rendering.draw_text({ + data.popup_chat[index] = rendering.draw_text({ text = safe_message, surface = player.surface, target = player.character, target_offset = {0, -4}, color = color, - font = 'compilatron-message-font', + font = 'compi', scale = 1.75, time_to_live = get_message_lifetime(safe_message), forces = { player.force }, alignment = 'center', use_rich_text = true, }) - data.popup_chat[index] = popup_ID end Event.add(defines.events.on_console_chat, on_console_chat) diff --git a/features/price_raffle.lua b/features/price_raffle.lua index 20ddd6b5..bcd91753 100644 --- a/features/price_raffle.lua +++ b/features/price_raffle.lua @@ -1,4 +1,7 @@ +-- Get random item stacks based off a budget +-- modified by RedRafe -- source: https://github.com/ComfyFactory/ComfyFactorio/blob/develop/maps/expanse/price_raffle.lua +-- ======================================================= -- -- @usage PriceRaffle --[[ @@ -53,6 +56,7 @@ local item_worths = { ['burner-mining-drill'] = 8, ['cannon-shell'] = 8, ['car'] = 128, + ['cargo-landing-pad'] = 2048, ['cargo-wagon'] = 256, ['centrifuge'] = 2048, ['chemical-plant'] = 128, @@ -72,7 +76,6 @@ local item_worths = { ['defender-capsule'] = 16, ['destroyer-capsule'] = 256, ['discharge-defense-equipment'] = 2048, - ['discharge-defense-remote'] = 32, ['distractor-capsule'] = 128, ['effectivity-module-2'] = 512, ['effectivity-module-3'] = 2048, @@ -97,16 +100,14 @@ local item_worths = { ['fast-splitter'] = 64, ['fast-transport-belt'] = 16, ['fast-underground-belt'] = 64, - ['filter-inserter'] = 40, ['firearm-magazine'] = 4, ['flamethrower-ammo'] = 32, ['flamethrower-turret'] = 2048, ['flamethrower'] = 512, ['fluid-wagon'] = 256, ['flying-robot-frame'] = 128, - ['fusion-reactor-equipment'] = 8192, + ['fission-reactor-equipment'] = 8192, ['gate'] = 16, - ['green-wire'] = 4, ['grenade'] = 16, ['gun-turret'] = 64, ['hazard-concrete'] = 4, @@ -171,17 +172,16 @@ local item_worths = { ['rail-chain-signal'] = 16, ['rail-signal'] = 16, ['rail'] = 8, - ['red-wire'] = 4, ['refined-concrete'] = 16, ['refined-hazard-concrete'] = 16, ['repair-pack'] = 8, ['roboport'] = 2048, - ['rocket-control-unit'] = 256, ['rocket-fuel'] = 256, ['rocket-launcher'] = 128, ['rocket-silo'] = 65536, ['rocket'] = 8, ['satellite'] = 32768, + ['selector-combinator'] = 16, ['shotgun-shell'] = 4, ['shotgun'] = 16, ['slowdown-capsule'] = 16, @@ -195,7 +195,6 @@ local item_worths = { ['speed-module-3'] = 2048, ['speed-module'] = 128, ['splitter'] = 16, - ['stack-filter-inserter'] = 160, ['stack-inserter'] = 128, ['steam-engine'] = 32, ['steam-turbine'] = 256, @@ -272,7 +271,7 @@ function Public.roll_item_stack(remaining_budget, blacklist, value_blacklist) end end - local stack_size = game.item_prototypes[item_name].stack_size * 32 + local stack_size = prototypes.item[item_name].stack_size * 32 local item_count = 1 @@ -354,7 +353,7 @@ local function add_recipe_products(recipe) name = name .. '-barrel' end - if game.item_prototypes[name] ~= nil then + if prototypes.item[name] ~= nil then item_unlocked[name] = item_worths[name] if item_unlocked[name] ~= nil then table_insert(item_names, name) @@ -402,7 +401,7 @@ Event.add(defines.events.on_research_finished, function(event) return end - for _, effect in pairs(technology.effects or {}) do + for _, effect in pairs(technology.prototype.effects or {}) do if effect.recipe then add_recipe_products(game.forces.player.recipes[effect.recipe]) end diff --git a/features/rank_system.lua b/features/rank_system.lua index dba30d76..94669327 100644 --- a/features/rank_system.lua +++ b/features/rank_system.lua @@ -16,7 +16,7 @@ local Server = require 'features.server' local Ranks = require 'resources.ranks' local Colors = require 'resources.color_presets' -local config = global.config.rank_system +local config = storage.config.rank_system local trust_time = config.time_for_trust local everyone_is_regular = config.everyone_is_regular diff --git a/features/reactor_meltdown.lua b/features/reactor_meltdown.lua index c45c18a9..239a14f8 100644 --- a/features/reactor_meltdown.lua +++ b/features/reactor_meltdown.lua @@ -10,7 +10,7 @@ local Global = require 'utils.global' local Ranks = require 'resources.ranks' local Color = require 'resources.color_presets' -local primitives = {reactors_enabled = global.config.reactor_meltdown.on_by_default} +local primitives = {reactors_enabled = storage.config.reactor_meltdown.on_by_default} local wastelands = {} local reactors = {} @@ -122,7 +122,7 @@ local function check_reactors() table.remove(reactors, i) end end - --global.last_reactor_warning = last_reactor_warning + --storage.last_reactor_warning = last_reactor_warning end end @@ -156,11 +156,11 @@ local function on_tick() end local function entity_build(event) - if not event.created_entity.valid then + if not event.entity.valid then return end - if event.created_entity.name == 'nuclear-reactor' and event.created_entity.surface.name ~= 'antigrief' then - table.insert(reactors, event.created_entity) + if event.entity.name == 'nuclear-reactor' and event.entity.surface.name ~= 'antigrief' then + table.insert(reactors, event.entity) end end diff --git a/features/redmew_commands.lua b/features/redmew_commands.lua index 91e35916..f3a65f05 100644 --- a/features/redmew_commands.lua +++ b/features/redmew_commands.lua @@ -8,7 +8,7 @@ local Donator = require 'features.donator' local Color = require 'resources.color_presets' local ScoreTracker = require 'utils.score_tracker' local format_number = require 'util'.format_number -local player_data_to_show = global.config.redmew_commands.whois.player_data_to_show +local player_data_to_show = storage.config.redmew_commands.whois.player_data_to_show local print_to_player = Game.player_print local concat = table.concat local tostring = tostring @@ -30,7 +30,7 @@ local function do_fish_kill(player, suicide) return false end - local e = player.surface.create_entity { name = 'fish', position = player.position } + local e = player.physical_surface.create_entity { name = 'fish', position = player.physical_position } c.die(player.force, e) -- Don't want people killing themselves for free fish. @@ -169,8 +169,8 @@ end local function print_version() local version_str - if global.redmew_version then - version_str = global.redmew_version + if storage.redmew_version then + version_str = storage.redmew_version else version_str = { 'redmew_commands.print_version_from_source' } end diff --git a/features/redmew_qol.lua b/features/redmew_qol.lua index 24d87a7f..36c5bfce 100644 --- a/features/redmew_qol.lua +++ b/features/redmew_qol.lua @@ -9,7 +9,7 @@ local Task = require 'utils.task' local Rank = require 'features.rank_system' local Gui = require 'utils.gui' -local config = global.config.redmew_qol +local config = storage.config.redmew_qol -- Localized functions local random = math.random @@ -28,7 +28,7 @@ end) --- When placed, locomotives will get a random color local random_train_color = Token.register(function(event) - local entity = event.created_entity + local entity = event.entity if entity and entity.valid and entity.type == 'locomotive' then entity.color = Utils.random_RGB() end @@ -37,7 +37,7 @@ end) --- If a newly placed entity is a provider or non-logi chest, set it to only have 1 slot available. -- If placed from a bp and the bp has restrictions on the chest, it takes priority. local restrict_chest = Token.register(function(event) - local entity = event.created_entity + local entity = event.entity if entity and entity.valid and (entity.name == 'logistic-chest-passive-provider' or entity.type == 'container') then local chest_inventory = entity.get_inventory(defines.inventory.chest) if #chest_inventory + 1 == chest_inventory.getbar() then @@ -67,7 +67,7 @@ end --- Changes the backer name on an entity that supports having a backer name. local change_backer_name = Token.register(function(event) - local entity = event.created_entity + local entity = event.entity if entity and entity.valid and entity.backer_name then entity.backer_name = pick_name() or entity.backer_name end @@ -210,10 +210,6 @@ local function register_inserter_drops_pickup() end local function on_init() - -- Set player force's ghost_time_to_live to an hour. Giving the players ghosts before the research of robots is a nice QOL improvement. - if config.ghosts_before_research then - Public.set_ghost_ttl() - end if config.loaders then Task.set_timeout_in_ticks(1, loader_check_token, nil) end @@ -223,16 +219,6 @@ Event.on_init(on_init) -- Public functions ---- Sets a ghost_time_to_live as a quality of life feature: now ghosts --- are created on death of entities before robot research --- @param force_name string with name of force --- @param time number of ticks for ghosts to live -function Public.set_ghost_ttl(force_name, time) - force_name = force_name or 'player' - time = time or (30 * 60 * 60) - game.forces[force_name].ghost_time_to_live = time -end - --- Sets random_train_color on or off. -- @param enable true to toggle on, false for off -- @return Success/failure of command @@ -347,12 +333,6 @@ if config.save_bots then Event.add(defines.events.on_selected_entity_changed, preserve_bot) end -if config.research_queue then - Event.on_init(function() - game.forces.player.research_queue_enabled = true - end) -end - local loader_crafter_frame_for_player_name = Gui.uid_name() local loader_crafter_frame_for_assembly_machine_name = Gui.uid_name() local player_craft_loader_1 = Gui.uid_name() @@ -728,11 +708,11 @@ if config.loaders then end) Event.add(defines.events.on_built_entity, function(event) - loader_built(event.created_entity) + loader_built(event.entity) end) Event.add(defines.events.on_robot_built_entity, function(event) - loader_built(event.created_entity) + loader_built(event.entity) end) end diff --git a/features/report.lua b/features/report.lua index 724fc687..914861c5 100644 --- a/features/report.lua +++ b/features/report.lua @@ -253,7 +253,7 @@ end -- @param player '|nil> the admin as LuaPlayer or '