Skip to content

Commit

Permalink
Minimal set of fixes to build a burner mining drill, sadly still all …
Browse files Browse the repository at this point in the history
…over
  • Loading branch information
ahicks92 committed Oct 25, 2024
1 parent 71dcafe commit ecd77ba
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 108 deletions.
67 changes: 23 additions & 44 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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, ")
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -6659,31 +6638,31 @@ 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)

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)

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)

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)

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions scripts/building-tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions scripts/consts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/crafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit ecd77ba

Please sign in to comment.