From ecd77ba0d3036337a5c2b9db8893943fc8367985 Mon Sep 17 00:00:00 2001 From: Austin Hicks Date: Thu, 24 Oct 2024 17:37:17 -0700 Subject: [PATCH] Minimal set of fixes to build a burner mining drill, sadly still all over --- control.lua | 67 +++++++++++++------------------------- scripts/building-tools.lua | 15 +++++---- scripts/consts.lua | 23 +++++++++++++ scripts/crafting.lua | 2 +- scripts/graphics.lua | 46 +++++++++++++------------- scripts/mining-tools.lua | 14 +++++--- scripts/teleport.lua | 54 +++++++++++++++--------------- 7 files changed, 113 insertions(+), 108 deletions(-) diff --git a/control.lua b/control.lua index 9a702299..d7a2da13 100644 --- a/control.lua +++ b/control.lua @@ -43,28 +43,6 @@ production_types = {} building_types = {} local dirs = defines.direction -ENT_NAMES_CLEARED_AS_OBSTACLES = { - "tree-01-stump", - "tree-02-stump", - "tree-03-stump", - "tree-04-stump", - "tree-05-stump", - "tree-06-stump", - "tree-07-stump", - "tree-08-stump", - "tree-09-stump", - "small-scorchmark", - "small-scorchmark-tintable", - "medium-scorchmark", - "medium-scorchmark-tintable", - "big-scorchmark", - "big-scorchmark-tintable", - "huge-scorchmark", - "huge-scorchmark-tintable", - "rock-big", - "rock-huge", - "sand-rock-big", -} ENT_TYPES_YOU_CAN_WALK_OVER = { "resource", "transport-belt", @@ -1473,7 +1451,7 @@ script.on_event(defines.events.on_player_changed_position, function(event) --Update cursor graphics local stack = p.cursor_stack - --if stack and stack.valid_for_read and stack.valid then fa_graphics.sync_build_cursor_graphics(pindex) end + if stack and stack.valid_for_read and stack.valid then fa_graphics.sync_build_cursor_graphics(pindex) end --Name a detected entity that you can or cannot walk on, or a tile you cannot walk on, and play a sound to indicate multiple consecutive detections refresh_player_tile(pindex) @@ -2544,7 +2522,7 @@ function move_characters(event) or stack.prototype.type == "copy-paste-tool" then --Force the pointer to the build preview location (and draw selection tool boxes) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) else --Force the pointer to the cursor location (if on screen) if fa_mouse.cursor_position_is_on_screen_with_player_centered(pindex) then @@ -2640,7 +2618,7 @@ function move(direction, pindex, nudged) local stack = first_player.cursor_stack if stack and stack.valid_for_read and stack.valid and stack.prototype.place_result ~= nil then - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) end if players[pindex].build_lock then fa_building_tools.build_item_in_hand(pindex) end @@ -2666,7 +2644,7 @@ function move(direction, pindex, nudged) local stack = first_player.cursor_stack if stack and stack.valid_for_read and stack.valid and stack.prototype.place_result ~= nil then - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) end if players[pindex].walk ~= WALKING.SMOOTH then @@ -2807,7 +2785,7 @@ function cursor_mode_move(direction, pindex, single_only) and stack.valid and (stack.prototype.place_result ~= nil or stack.is_blueprint) then - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) end --Apply build lock if active @@ -2850,7 +2828,7 @@ end function sync_remote_view(pindex) local p = game.get_player(pindex) p.zoom_to_world(players[pindex].cursor_pos) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) end --Makes the character face the cursor, choosing the nearest of 4 cardinal directions. Can be overwriten by vanilla move keys. @@ -3077,7 +3055,7 @@ script.on_event("cursor-bookmark-load", function(event) if pos == nil or pos.x == nil or pos.y == nil then return end players[pindex].cursor_pos = pos --fa_graphics.draw_cursor_highlight(pindex, nil, nil) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) printout("Loaded cursor bookmark at " .. math.floor(pos.x) .. ", " .. math.floor(pos.y), pindex) game.get_player(pindex).play_sound({ path = "Close-Inventory-Sound" }) end) @@ -3136,7 +3114,7 @@ script.on_event("teleport-to-alert-forced", function(event) players[pindex].position = game.get_player(pindex).position players[pindex].last_damage_alert_pos = game.get_player(pindex).position --fa_graphics.draw_cursor_highlight(pindex, nil, nil) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) refresh_player_tile(pindex) end) @@ -3597,13 +3575,13 @@ end) --Sets up mod character menus. Cannot actually open the character GUI. function open_player_inventory(tick, pindex) local p = game.get_player(pindex) - if p.ticks_to_respawn ~= nil then return end + if p.ticks_to_respawn ~= nil or p.character == nil then return end p.play_sound({ path = "Open-Inventory-Sound" }) p.selected = nil players[pindex].last_menu_toggle_tick = tick players[pindex].in_menu = true players[pindex].menu = "inventory" - players[pindex].inventory.lua_inventory = p.get_main_inventory() + players[pindex].inventory.lua_inventory = p.character.get_main_inventory() players[pindex].inventory.max = #players[pindex].inventory.lua_inventory players[pindex].inventory.index = 1 read_inventory_slot(pindex, "Inventory, ") @@ -4091,13 +4069,14 @@ function swap_weapon_forward(pindex, write_to_character) if gun_index == nil then return 0 --This is an intentionally selected error code end - local guns_inv = p.get_inventory(defines.inventory.character_guns) - local ammo_inv = game.get_player(pindex).get_inventory(defines.inventory.character_ammo) + local guns_inv = p.character.get_inventory(defines.inventory.character_guns) + local ammo_inv = game.get_player(pindex).character.get_inventory(defines.inventory.character_ammo) --Simple index increment (not needed) gun_index = gun_index + 1 if gun_index > 3 then gun_index = 1 end --game.print("start " .. gun_index)-- + assert(ammo_inv) --Increment again if the new index has no guns or no ammo local ammo_stack = ammo_inv[gun_index] @@ -4364,7 +4343,7 @@ script.on_event("mine-area", function(event) else --Check if it is a remnant ent, clear obstacles local ent_is_remnant = false - local remnant_names = ENT_NAMES_CLEARED_AS_OBSTACLES + local remnant_names = Consts.ENT_NAMES_CLEARED_AS_OBSTACLES for i, name in ipairs(remnant_names) do if ent.name == name then ent_is_remnant = true end end @@ -4889,7 +4868,7 @@ script.on_event("click-menu", function(event) players[pindex].cursor = true players[pindex].cursor_pos = fa_utils.center_of_tile(ent.position) --fa_graphics.draw_cursor_highlight(pindex, ent, nil) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) printout({ "fa.teleported-cursor-to", "" .. math.floor(players[pindex].cursor_pos.x) .. " " .. math.floor(players[pindex].cursor_pos.y), @@ -6373,7 +6352,7 @@ script.on_event(defines.events.on_player_cursor_stack_changed, function(event) players[pindex].bp_selecting = false players[pindex].blueprint_reselecting = false players[pindex].ghost_rail_planning = false - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) end) script.on_event(defines.events.on_player_mined_item, function(event) @@ -6659,7 +6638,7 @@ script.on_event("recalibrate-zoom", function(event) local pindex = event.player_index if not check_for_player(pindex) then return end fa_zoom.fix_zoom(pindex) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) printout("Recalibrated", pindex) end) @@ -6667,7 +6646,7 @@ script.on_event("set-standard-zoom", function(event) local pindex = event.player_index if not check_for_player(pindex) then return end fa_zoom.set_zoom(1, pindex) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) printout("Set standard zoom.", pindex) end) @@ -6675,7 +6654,7 @@ script.on_event("set-closest-zoom", function(event) local pindex = event.player_index if not check_for_player(pindex) then return end fa_zoom.set_zoom(fa_zoom.MAX_ZOOM, pindex) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) printout("Set closest zoom.", pindex) end) @@ -6683,7 +6662,7 @@ script.on_event("set-furthest-zoom", function(event) local pindex = event.player_index if not check_for_player(pindex) then return end fa_zoom.set_zoom(fa_zoom.MIN_ZOOM, pindex) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) printout("Set furthest zoom.", pindex) end) @@ -6704,7 +6683,7 @@ script.on_event("pipette-tool-info", function(event) players[pindex].cursor_rotation_offset = 0 end if players[pindex].cursor then players[pindex].cursor_pos = fa_utils.get_ent_northwest_corner_position(ent) end - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) --fa_graphics.draw_cursor_highlight(pindex, ent, nil, nil) end end) @@ -7178,7 +7157,7 @@ function cursor_skip(pindex, direction, iteration_limit, use_preview_size) --Read the tile reached read_tile(pindex, result) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) --Draw large cursor boxes if present if players[pindex].cursor_size > 0 then @@ -8226,7 +8205,7 @@ function jump_cursor_to_typed_coordinates(result, pindex) players[pindex].cursor_pos = fa_utils.center_of_tile({ x = new_x + 0.01, y = new_y + 0.01 }) printout("Cursor jumped to " .. new_x .. ", " .. new_y, pindex) --fa_graphics.draw_cursor_highlight(pindex) - --fa_graphics.sync_build_cursor_graphics(pindex) + fa_graphics.sync_build_cursor_graphics(pindex) else printout("Invalid input", pindex) end diff --git a/scripts/building-tools.lua b/scripts/building-tools.lua index a8670c45..a361ea82 100644 --- a/scripts/building-tools.lua +++ b/scripts/building-tools.lua @@ -307,9 +307,9 @@ function mod.build_item_in_hand(pindex, free_place_straight_rail) --Update cursor highlight (end) local ent = game.get_player(pindex).selected if ent and ent.valid then - fa_graphics.draw_cursor_highlight(pindex, ent, nil) + --fa_graphics.draw_cursor_highlight(pindex, ent, nil) else - fa_graphics.draw_cursor_highlight(pindex, nil, nil) + --fa_graphics.draw_cursor_highlight(pindex, nil, nil) end end @@ -431,7 +431,7 @@ function mod.rotate_building_info_read(event, forward) --Display and read the new direction info players[pindex].building_direction = build_dir - fa_graphics.sync_build_cursor_graphics(pindex) + --fa_graphics.sync_build_cursor_graphics(pindex) printout(fa_utils.direction_lookup(build_dir) .. " in hand", pindex) players[pindex].lag_building_direction = false else @@ -450,7 +450,7 @@ function mod.rotate_building_info_read(event, forward) players[pindex].blueprint_width_in_hand = temp --Call graphics update - fa_graphics.sync_build_cursor_graphics(pindex) + --fa_graphics.sync_build_cursor_graphics(pindex) elseif ent and ent.valid then if ent.supports_direction then --Assuming that the vanilla rotate event will now rotate the ent @@ -550,8 +550,8 @@ function mod.nudge_key(direction, event) printout({ "fa.nudged-one-direction", { "fa.direction", direction } }, pindex) if players[pindex].cursor then players[pindex].cursor_pos = fa_utils.offset_position(players[pindex].cursor_pos, direction, 1) - fa_graphics.draw_cursor_highlight(pindex, ent, "train-visualization") - fa_graphics.sync_build_cursor_graphics(pindex) + --fa_graphics.draw_cursor_highlight(pindex, ent, "train-visualization") + --fa_graphics.sync_build_cursor_graphics(pindex) end if ent.type == "electric-pole" then -- laterdo **bugfix when nudged electric poles have extra wire reach, cut wires @@ -1457,7 +1457,8 @@ end --If the player is standing within the build area, they are teleported out. function mod.teleport_player_out_of_build_area(left_top, right_bottom, pindex) local p = game.get_player(pindex) - local pos = p.position + if not p.character then return end + local pos = p.character.position if pos.x < left_top.x or pos.x > right_bottom.x or pos.y < left_top.y or pos.y > right_bottom.y then return end if p.walking_state.walking == true then return end if players[pindex].build_lock == true then diff --git a/scripts/consts.lua b/scripts/consts.lua index 21b2400d..7410d49a 100644 --- a/scripts/consts.lua +++ b/scripts/consts.lua @@ -13,4 +13,27 @@ mod.NEW_ENTITY_SUBSCRIBER_TRIGGER_ID = "fa.subscribe-to-new-entities" mod.RESOURCE_SEARCH_RADIUSES_ITEM = "fa-resource-radiuses-proto" +mod.ENT_NAMES_CLEARED_AS_OBSTACLES = { + "tree-01-stump", + "tree-02-stump", + "tree-03-stump", + "tree-04-stump", + "tree-05-stump", + "tree-06-stump", + "tree-07-stump", + "tree-08-stump", + "tree-09-stump", + "small-scorchmark", + "small-scorchmark-tintable", + "medium-scorchmark", + "medium-scorchmark-tintable", + "big-scorchmark", + "big-scorchmark-tintable", + "huge-scorchmark", + "huge-scorchmark-tintable", + "big-rock", + "huge-rock", + "big-sand-rock", +} + return mod diff --git a/scripts/crafting.lua b/scripts/crafting.lua index cc6c6575..db593eec 100644 --- a/scripts/crafting.lua +++ b/scripts/crafting.lua @@ -14,7 +14,7 @@ function mod.get_recipes(pindex, ent, load_all_categories) for category_name, _ in pairs(ent.prototype.crafting_categories) do table.insert(category_filters, { filter = "category", category = category_name }) end - local all_machine_recipes = game.get_filtered_recipe_prototypes(category_filters) + local all_machine_recipes = prototypes.get_recipe_filtered(category_filters) local unlocked_machine_recipes = {} local force_recipes = game.get_player(pindex).force.recipes diff --git a/scripts/graphics.lua b/scripts/graphics.lua index c1ffd822..4b598ce1 100644 --- a/scripts/graphics.lua +++ b/scripts/graphics.lua @@ -178,7 +178,7 @@ function mod.sync_build_cursor_graphics(pindex) local right_bottom = nil if stack and stack.valid_for_read and stack.valid and stack.prototype.place_result then --Redraw direction indicator arrow - if dir_indicator ~= nil then rendering.destroy(player.building_dir_arrow) end + if dir_indicator ~= nil then player.building_dir_arrow.destroy() end local arrow_pos = player.cursor_pos if players[pindex].build_lock and not players[pindex].cursor and stack.name ~= "rail" then arrow_pos = fa_utils.center_of_tile(fa_utils.offset_position(arrow_pos, players[pindex].player_direction, -2)) @@ -193,7 +193,7 @@ function mod.sync_build_cursor_graphics(pindex) orientation = dir / (2 * dirs.south), }) dir_indicator = player.building_dir_arrow - rendering.set_visible(dir_indicator, true) + --rendering.set_visible(dir_indicator, true) if players[pindex].hide_cursor or stack.name == "locomotive" @@ -201,11 +201,11 @@ function mod.sync_build_cursor_graphics(pindex) or stack.name == "fluid-wagon" or stack.name == "artillery-wagon" then - rendering.set_visible(dir_indicator, false) + --rendering.set_visible(dir_indicator, false) end --Redraw footprint (ent) - if player.building_footprint ~= nil then rendering.destroy(player.building_footprint) end + if player.building_footprint ~= nil then player.building_footprint.destroy() end --Get correct width and height width = stack.prototype.place_result.tile_width @@ -255,7 +255,7 @@ function mod.sync_build_cursor_graphics(pindex) surface = game.get_player(pindex).surface, players = nil, }) - rendering.set_visible(player.building_footprint, true) + --rendering.set_visible(player.building_footprint, true) --Hide the drawing in the desired cases if @@ -265,7 +265,7 @@ function mod.sync_build_cursor_graphics(pindex) or stack.name == "fluid-wagon" or stack.name == "artillery-wagon" then - rendering.set_visible(player.building_footprint, false) + --rendering.set_visible(player.building_footprint, false) end --Move mouse pointer according to building box @@ -305,8 +305,8 @@ function mod.sync_build_cursor_graphics(pindex) end elseif stack == nil or not stack.valid_for_read then --Invalid stack: Hide the objects - if dir_indicator ~= nil then rendering.set_visible(dir_indicator, false) end - if player.building_footprint ~= nil then rendering.set_visible(player.building_footprint, false) end + --if dir_indicator ~= nil then rendering.set_visible(dir_indicator, false) end + --if player.building_footprint ~= nil then rendering.set_visible(player.building_footprint, false) end elseif stack and stack.valid_for_read @@ -316,7 +316,7 @@ function mod.sync_build_cursor_graphics(pindex) then --Blueprints have their own data: --Redraw the direction indicator arrow - if dir_indicator ~= nil then rendering.destroy(player.building_dir_arrow) end + if dir_indicator ~= nil then player.building_dir_arrow.destroy() end local arrow_pos = player.cursor_pos local dir = players[pindex].blueprint_hand_direction if dir == nil then @@ -333,10 +333,10 @@ function mod.sync_build_cursor_graphics(pindex) orientation = dir / (2 * dirs.south), }) dir_indicator = player.building_dir_arrow - rendering.set_visible(dir_indicator, true) + --rendering.set_visible(dir_indicator, true) --Redraw the bp footprint - if player.building_footprint ~= nil then rendering.destroy(player.building_footprint) end + if player.building_footprint ~= nil then player.building_footprint.destroy() end local bp_width = players[pindex].blueprint_width_in_hand local bp_height = players[pindex].blueprint_height_in_hand if bp_width ~= nil then @@ -352,7 +352,7 @@ function mod.sync_build_cursor_graphics(pindex) surface = p.surface, players = nil, }) - rendering.set_visible(player.building_footprint, true) + --rendering.set_visible(player.building_footprint, true) --Move the mouse pointer if players[pindex].remote_view == true then @@ -365,8 +365,8 @@ function mod.sync_build_cursor_graphics(pindex) end else --Hide the objects - if dir_indicator ~= nil then rendering.set_visible(dir_indicator, false) end - if player.building_footprint ~= nil then rendering.set_visible(player.building_footprint, false) end + --if dir_indicator ~= nil then rendering.set_visible(dir_indicator, false) end + --if player.building_footprint ~= nil then rendering.set_visible(player.building_footprint, false) end --Tile placement preview if stack.valid and stack.prototype.place_as_tile_result and players[pindex].blueprint_reselecting ~= true then @@ -408,7 +408,7 @@ function mod.sync_build_cursor_graphics(pindex) draw_on_ground = false, players = nil, }) - rendering.set_visible(player.building_footprint, true) + --rendering.set_visible(player.building_footprint, true) end end @@ -424,7 +424,7 @@ function mod.draw_cursor_highlight(pindex, ent, box_type, skip_mouse_movement) local h_tile = players[pindex].cursor_tile_highlight_box if c_pos == nil then return end if h_box ~= nil and h_box.valid then h_box.destroy() end - if h_tile ~= nil and rendering.is_valid(h_tile) then rendering.destroy(h_tile) end + if h_tile ~= nil and h_tile.is_valid() then h_tile.destroy() end --Skip drawing if hide cursor is enabled if players[pindex].hide_cursor then @@ -500,7 +500,7 @@ end --Redraws the player's cursor highlight box as a rectangle around the defined area. function mod.draw_large_cursor(input_left_top, input_right_bottom, pindex, colour_in) local h_tile = players[pindex].cursor_tile_highlight_box - if h_tile ~= nil then rendering.destroy(h_tile) end + if h_tile ~= nil then h_tile.destroy() end local colour = { 0.75, 1, 1 } if colour_in ~= nil then colour = colour_in end h_tile = rendering.draw_rectangle({ @@ -511,7 +511,7 @@ function mod.draw_large_cursor(input_left_top, input_right_bottom, pindex, colou draw_on_ground = true, players = nil, }) - rendering.set_visible(h_tile, true) + --rendering.set_visible(h_tile, true) players[pindex].cursor_tile_highlight_box = h_tile --Recolor cursor boxes if multiplayer @@ -584,7 +584,7 @@ function mod.update_custom_GUI_sprite(sprite, scale_in, pindex, sprite_2) and p.cursor_stack.is_blueprint then local bp = p.cursor_stack - local bp_icons = bp.blueprint_icons or {} + local bp_icons = bp.preview_icons or {} for i = 1, 4 do local player_sprite_handle = "custom_GUI_sprite_" .. (i + 1) local icon_sprite = player[player_sprite_handle] @@ -622,8 +622,8 @@ function mod.update_overhead_sprite(sprite, scale_in, radius_in, pindex) local scale = scale_in local radius = radius_in - if player.overhead_circle ~= nil then rendering.destroy(player.overhead_circle) end - if player.overhead_sprite ~= nil then rendering.destroy(player.overhead_sprite) end + if player.overhead_circle ~= nil then player.overhead_circle.destroy() end + if player.overhead_sprite ~= nil then player.overhead_sprite.destroy() end if sprite ~= nil then player.overhead_circle = rendering.draw_circle({ color = { r = 0.2, b = 0.2, g = 0.2, a = 0.9 }, @@ -634,7 +634,7 @@ function mod.update_overhead_sprite(sprite, scale_in, radius_in, pindex) filled = true, time_to_live = 60, }) - rendering.set_visible(player.overhead_circle, true) + --rendering.set_visible(player.overhead_circle, true) player.overhead_sprite = rendering.draw_sprite({ sprite = sprite, x_scale = scale, @@ -644,7 +644,7 @@ function mod.update_overhead_sprite(sprite, scale_in, radius_in, pindex) orientation = 0, time_to_live = 60, }) - rendering.set_visible(player.overhead_sprite, true) + --rendering.set_visible(player.overhead_sprite, true) end end diff --git a/scripts/mining-tools.lua b/scripts/mining-tools.lua index 39735a70..a530586a 100644 --- a/scripts/mining-tools.lua +++ b/scripts/mining-tools.lua @@ -1,4 +1,5 @@ --Here: mining functions, such as obstacle clearing +local Consts = require("scripts.consts") local mod = {} @@ -59,7 +60,7 @@ function mod.clear_obstacles_in_circle(position, radius, pindex) local resources = surf.find_entities_filtered({ position = position, radius = radius, - name = { "rock-big", "rock-huge", "sand-rock-big" }, + name = { "big-rock", "huge-rock", "big-snad-rock" }, }) for i, resource_ent in ipairs(resources) do if resource_ent ~= nil and resource_ent.valid then @@ -77,8 +78,11 @@ function mod.clear_obstacles_in_circle(position, radius, pindex) end --Find and mine corpse entities such as building remnants - local remnant_ents = - surf.find_entities_filtered({ position = position, radius = radius, name = ENT_NAMES_CLEARED_AS_OBSTACLES }) + local remnant_ents = surf.find_entities_filtered({ + position = position, + radius = radius, + name = Consts.ENT_NAMES_CLEARED_AS_OBSTACLES, + }) for i, remnant_ent in ipairs(remnant_ents) do if remnant_ent ~= nil and remnant_ent.valid then rendering.draw_circle({ @@ -175,7 +179,7 @@ function mod.clear_obstacles_in_rectangle(left_top, right_bottom, pindex, mining --Find and mine rocks. Note that they are resource entities with specific names local resources = surf.find_entities_filtered({ area = { left_top, right_bottom }, - name = { "rock-big", "rock-huge", "sand-rock-big" }, + name = { "big-rock", "huge-rock", "big-sand-rock" }, }) for i, resource_ent in ipairs(resources) do if resource_ent ~= nil and resource_ent.valid then @@ -199,7 +203,7 @@ function mod.clear_obstacles_in_rectangle(left_top, right_bottom, pindex, mining --Find and destroy corpse entities such as building remnants local remnant_ents = - surf.find_entities_filtered({ area = { left_top, right_bottom }, name = ENT_NAMES_CLEARED_AS_OBSTACLES }) + surf.find_entities_filtered({ area = { left_top, right_bottom }, name = Consts.ENT_NAMES_CLEARED_AS_OBSTACLES }) for i, remnant_ent in ipairs(remnant_ents) do if remnant_ent ~= nil and remnant_ent.valid then rendering.draw_circle({ diff --git a/scripts/teleport.lua b/scripts/teleport.lua index f89f4964..f1b67df6 100644 --- a/scripts/teleport.lua +++ b/scripts/teleport.lua @@ -16,8 +16,10 @@ end function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) local pos = table.deepcopy(pos) local muted = muted or false - local first_player = game.get_player(pindex) - local surf = first_player.surface + local char = game.get_player(pindex).character + if not char then return false end + + local surf = char.surface local radius = 0.5 --Find a non-colliding position local new_pos = surf.find_non_colliding_position("character", pos, radius, 0.1, true) @@ -26,7 +28,7 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) new_pos = surf.find_non_colliding_position("character", pos, radius, 0.1, true) end --Do not teleport if in a vehicle, in a menu, or already at the desitination - if first_player.vehicle ~= nil and first_player.vehicle.valid then + if char.vehicle ~= nil and char.vehicle.valid then printout("Cannot teleport while in a vehicle.", pindex) return false elseif util.distance(game.get_player(pindex).position, pos) < 0.6 then @@ -42,8 +44,7 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) end --Do not teleport near enemies unless instructed to ignore them if not ignore_enemies then - local enemy = - first_player.surface.find_nearest_enemy({ position = new_pos, max_distance = 30, force = first_player.force }) + local enemy = char.surface.find_nearest_enemy({ position = new_pos, max_distance = 30, force = char.force }) if enemy and enemy.valid then printout( "Warning: There are enemies at this location, but you can force teleporting if you press CONTROL + SHIFT + T", @@ -53,9 +54,9 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) end end --Attempt teleport - local can_port = first_player.surface.can_place_entity({ name = "character", position = new_pos }) + local can_port = char.surface.can_place_entity({ name = "character", position = new_pos }) if can_port then - local old_pos = table.deepcopy(first_player.position) + local old_pos = table.deepcopy(char.position) if not muted then --Draw teleporting visuals at origin rendering.draw_circle({ @@ -63,7 +64,7 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) radius = 0.5, width = 15, target = old_pos, - surface = first_player.surface, + surface = char.surface, draw_on_ground = true, time_to_live = 60, }) @@ -72,18 +73,18 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) radius = 0.3, width = 20, target = old_pos, - surface = first_player.surface, + surface = char.surface, draw_on_ground = true, time_to_live = 60, }) local smoke_spot_ghosts = - first_player.surface.find_entities_filtered({ position = first_player.position, type = "entity-ghost" }) + char.surface.find_entities_filtered({ position = char.position, type = "entity-ghost" }) if smoke_spot_ghosts == nil or #smoke_spot_ghosts == 0 then - local smoke_effect = first_player.surface.create_entity({ + local smoke_effect = char.surface.create_entity({ name = "iron-chest", - position = first_player.position, + position = char.position, raise_built = false, - force = first_player.force, + force = char.force, }) smoke_effect.destroy({}) end @@ -95,15 +96,12 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) end local teleported = false if muted then - teleported = first_player.teleport(new_pos) + teleported = char.teleport(new_pos) else - teleported = first_player.teleport(new_pos) + teleported = char.teleport(new_pos) end if teleported then - first_player.force.chart( - first_player.surface, - { { new_pos.x - 15, new_pos.y - 15 }, { new_pos.x + 15, new_pos.y + 15 } } - ) + char.force.chart(char.surface, { { new_pos.x - 15, new_pos.y - 15 }, { new_pos.x + 15, new_pos.y + 15 } }) players[pindex].position = table.deepcopy(new_pos) reset_bump_stats(pindex) if not muted then @@ -113,7 +111,7 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) radius = 0.5, width = 15, target = new_pos, - surface = first_player.surface, + surface = char.surface, draw_on_ground = true, time_to_live = 60, }) @@ -122,18 +120,18 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) radius = 0.3, width = 20, target = new_pos, - surface = first_player.surface, + surface = char.surface, draw_on_ground = true, time_to_live = 60, }) local smoke_spot_ghosts = - first_player.surface.find_entities_filtered({ position = first_player.position, type = "entity-ghost" }) + char.surface.find_entities_filtered({ position = char.position, type = "entity-ghost" }) if smoke_spot_ghosts == nil or #smoke_spot_ghosts == 0 then - local smoke_effect = first_player.surface.create_entity({ + local smoke_effect = char.surface.create_entity({ name = "iron-chest", - position = first_player.position, + position = char.position, raise_built = false, - force = first_player.force, + force = char.force, }) smoke_effect.destroy({}) end @@ -149,9 +147,9 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) if not muted then printout( "Teleported " - .. math.ceil(fa_utils.distance(pos, first_player.position)) + .. math.ceil(fa_utils.distance(pos, char.position)) .. " " - .. fa_utils.direction(pos, first_player.position) + .. fa_utils.direction(pos, char.position) .. " of target", pindex ) @@ -160,7 +158,7 @@ function mod.teleport_to_closest(pindex, pos, muted, ignore_enemies) --Update cursor after teleport players[pindex].cursor_pos = table.deepcopy(new_pos) fa_mouse.move_mouse_pointer(fa_utils.center_of_tile(players[pindex].cursor_pos), pindex) - fa_graphics.draw_cursor_highlight(pindex, nil, nil) + --fa_graphics.draw_cursor_highlight(pindex, nil, nil) else printout("Teleport Failed", pindex) return false