Skip to content

Commit

Permalink
intermediate rail builder work
Browse files Browse the repository at this point in the history
* forks: added northeast forward extensions for diagonal rail forks. This pattern will be re-usable for the 3 other directions.
* forks: also extended cardinal direction forward exits to make the forks more pronounced.
* ghost planner: fixed crashes and then disabled this feature because it needs further fixes.
  • Loading branch information
LevFendi committed May 15, 2024
1 parent 11f5256 commit cd0ebc4
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 4 deletions.
3 changes: 3 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6650,6 +6650,7 @@ script.on_event("open-rail-builder", function(event)
if stack and stack.valid_for_read and stack.name == "rail" then
ghost_rail_case = fa_rails.cursor_is_at_straight_end_rail_tip(pindex)
end
ghost_rail_case = false --keep this feature off for now
if ghost_rail_case then
fa_rails.start_ghost_rail_planning(pindex)
else
Expand Down Expand Up @@ -7449,6 +7450,7 @@ script.on_event("read-time-and-research-progress", function(event)
game.get_player(pindex).force.research_queue_enabled = false
end)

--When the item in hand changes
script.on_event(defines.events.on_player_cursor_stack_changed, function(event)
pindex = event.player_index
if not check_for_player(pindex) then return end
Expand All @@ -7473,6 +7475,7 @@ script.on_event(defines.events.on_player_cursor_stack_changed, function(event)
fa_building_tools.delete_empty_planners_in_inventory(pindex)
players[pindex].bp_selecting = false
players[pindex].blueprint_reselecting = false
players[pindex].ghost_rail_planning = false
fa_graphics.sync_build_cursor_graphics(pindex)
end)

Expand Down
270 changes: 268 additions & 2 deletions scripts/rail-builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
-- elseif dir == dirs.west or dir == dirs.northwest then
-- build_area = {{pos.x+9, pos.y-9},{pos.x-16,pos.y+16}}
-- end
temp1, build_comment = fa_mining_tools.clear_obstacles_in_circle(pos, 12, pindex)
temp1, build_comment = fa_mining_tools.clear_obstacles_in_circle(pos, 14, pindex)

--4A. Check if every object can be placed (LEFT)
if include_left then
Expand Down Expand Up @@ -2489,6 +2489,20 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y - 10 },
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y - 12 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.east then
can_place_all = can_place_all
and surf.can_place_entity({
Expand Down Expand Up @@ -2518,6 +2532,20 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 10, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 12, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.south then
can_place_all = can_place_all
and surf.can_place_entity({
Expand Down Expand Up @@ -2547,6 +2575,20 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y + 10 },
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y + 12 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.west then
can_place_all = can_place_all
and surf.can_place_entity({
Expand Down Expand Up @@ -2576,8 +2618,109 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x - 10, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x - 12, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.northeast then
game.print("missing checks here ****")
if anchor_dir == dirs.southeast then --2
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 0 },
direction = dirs.northwest,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 2 },
direction = dirs.southeast,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 2 },
direction = dirs.northwest,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 4 },
direction = dirs.southeast,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 6, pos.y - 4 },
direction = dirs.northwest,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 6, pos.y - 6 },
direction = dirs.southeast,
force = game.forces.player,
})
elseif anchor_dir == dirs.northwest then --3
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 0, pos.y - 2 },
direction = dirs.southeast,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 2 },
direction = dirs.northwest,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 4 },
direction = dirs.southeast,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 4 },
direction = dirs.northwest,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 6 },
direction = dirs.southeast,
force = game.forces.player,
})
can_place_all = can_place_all
and surf.can_place_entity({
name = "straight-rail",
position = { pos.x + 6, pos.y - 6 },
direction = dirs.northwest,
force = game.forces.player,
})
end
elseif dir == dirs.southeast then
game.print("missing checks here ****")
elseif dir == dirs.southwest then
Expand Down Expand Up @@ -3013,6 +3156,18 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y - 10 },
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y - 12 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.east then
surf.create_entity({
name = "straight-rail",
Expand All @@ -3038,6 +3193,18 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 10, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 12, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.south then
surf.create_entity({
name = "straight-rail",
Expand All @@ -3063,6 +3230,18 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y + 10 },
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x - 0, pos.y + 12 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.west then
surf.create_entity({
name = "straight-rail",
Expand All @@ -3088,8 +3267,95 @@ function mod.build_fork_at_end_rail(anchor_rail, pindex, include_forward, includ
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x - 10, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x - 12, pos.y - 0 },
direction = dir,
force = game.forces.player,
})
elseif dir == dirs.northeast then
game.print("missing creates here ****")
game.print("verified creates here ****")
if anchor_dir == dirs.southeast then --2
surf.create_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 0 },
direction = dirs.northwest,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 2 },
direction = dirs.southeast,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 2 },
direction = dirs.northwest,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 4 },
direction = dirs.southeast,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 6, pos.y - 4 },
direction = dirs.northwest,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 6, pos.y - 6 },
direction = dirs.southeast,
force = game.forces.player,
})
elseif anchor_dir == dirs.northwest then --3
surf.create_entity({
name = "straight-rail",
position = { pos.x + 0, pos.y - 2 },
direction = dirs.southeast,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 2 },
direction = dirs.northwest,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 2, pos.y - 4 },
direction = dirs.southeast,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 4 },
direction = dirs.northwest,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 4, pos.y - 6 },
direction = dirs.southeast,
force = game.forces.player,
})
surf.create_entity({
name = "straight-rail",
position = { pos.x + 6, pos.y - 6 },
direction = dirs.northwest,
force = game.forces.player,
})
end
elseif dir == dirs.southeast then
game.print("missing creates here ****")
elseif dir == dirs.southwest then
Expand Down
5 changes: 3 additions & 2 deletions scripts/rails.lua
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,11 @@ function mod.cursor_is_at_straight_end_rail_tip(pindex)
perimeter[6] = fa_utils.add_position(pos, { x = 1, y = -1 })
perimeter[7] = fa_utils.add_position(pos, { x = 1, y = 0 })
perimeter[8] = fa_utils.add_position(pos, { x = 1, y = 1 })
for pos_p in perimeter do
for i, pos_p in ipairs(perimeter) do
--Find rails, if any
local ents = p.surface.find_entities_filtered({ name = { "straight-rail", "curved-rail" }, position = pos_p })
if ents ~= nil and #ents > 0 then
for rail in ents do
for j, rail in ipairs(ents) do
--For rails found, check whether the unit number is different
if rail.unit_number ~= rail_at_cursor.unit_number then return false end
end
Expand All @@ -541,6 +541,7 @@ end
--Note: The rail planner itself does nothing if an invalid location is chosen
function mod.end_ghost_rail_planning(pindex)
local p = game.get_player(pindex)
players[pindex].ghost_rail_planning = false
--Check if cursor is on screen OR if remote view is running
local on_screen = fa_mouse.cursor_position_is_on_screen_with_player_centered(pindex) == true
or players[pindex].remote_view == true
Expand Down

0 comments on commit cd0ebc4

Please sign in to comment.