Skip to content

Commit

Permalink
fluids: start announcing undergrounds again
Browse files Browse the repository at this point in the history
  • Loading branch information
ahicks92 committed Nov 7, 2024
1 parent a3483f9 commit 8ed843a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
6 changes: 3 additions & 3 deletions locale/en/entity-info.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ ent-info-inventory-presentation=Has __1__
ent-info-inventory-presentation-truncated=Has __1__ and __2__ more
ent-info-fluid-connections-in=__1__ in from the __2__
ent-info-fluid-connections-out=__1__ out to the __2__
ent-info-fluid-connections-bidirectional=__1__ in and out to the __2__
ent-info-fluid-connections-in=__1__ in from the __2__ __plural_for_parameter__3__{0=|1=|rest=via __3__ tiles underground}__
ent-info-fluid-connections-out=__1__ out to the __2__ __plural_for_parameter__3__{0=|1=|rest=via __3__ tiles underground}__
ent-info-fluid-connections-bidirectional=__1__ in and out to the __2__ __plural_for_parameter__3__{0=|1=|rest=via __3__ tiles underground}__
ent-info-fluid-connections-any=any fluid
ent-info-fluid-connections-closed=closed
44 changes: 26 additions & 18 deletions scripts/fa-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -770,30 +770,38 @@ local function ent_info_fluid_connections(ctx)
for dir, c in pairs(set) do
local f = c.fluid or none
if not c.open then f = closed end
local realdir = rotate and FaUtils.rotate_180(dir) or dir
local dist = c.distance_in_tiles
buckets[f] = buckets[f] or {}
table.insert(buckets[f], rotate and FaUtils.rotate_180(dir) or dir)
buckets[f][dist] = buckets[f][dist] or {}

print(serpent.line(c))
table.insert(buckets[f][dist], realdir)
end

for fluid, dirs in pairs(buckets) do
table.sort(dirs, function(a, b)
return a < b
end)
print(serpent.line(buckets))
for fluid, distdirs in pairs(buckets) do
for dist, dirs in pairs(distdirs) do
table.sort(dirs, function(a, b)
return a < b
end)

local dirparts = {}
for _, dir in pairs(dirs) do
table.insert(dirparts, FaUtils.direction_lookup(dir))
end
local dirparts = {}
for _, dir in pairs(dirs) do
table.insert(dirparts, FaUtils.direction_lookup(dir))
end

local dirlist = FaUtils.localise_cat_table(dirparts, ", ")
---@type LocalisedString
local loc_fluid = { "fa.ent-info-fluid-connections-any" }
if fluid == closed then
loc_fluid = { "fa.ent-info-fluid-connections-closed" }
elseif fluid ~= none then
loc_fluid = Localising.get_localised_name_with_fallback(prototypes.fluid[fluid])
end
local dirlist = FaUtils.localise_cat_table(dirparts, ", ")
---@type LocalisedString
local loc_fluid = { "fa.ent-info-fluid-connections-any" }
if fluid == closed then
loc_fluid = { "fa.ent-info-fluid-connections-closed" }
elseif fluid ~= none then
loc_fluid = Localising.get_localised_name_with_fallback(prototypes.fluid[fluid])
end

ctx.message:list_item({ key, loc_fluid, dirlist })
ctx.message:list_item({ key, loc_fluid, dirlist, dist })
end
end
end

Expand Down
13 changes: 13 additions & 0 deletions scripts/fluids.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ connections for code needing more.
---@field fluid string? Set if the fluid must be a specific one.
---@field type data.PipeConnectionType
---@field open boolean Closed if it's a crafting machine and the recipe doesn't use it.
---@field position_in_tiles number Not the same as just checking positions unless it's "normal"
---@field raw PipeConnection

--[[
Expand Down Expand Up @@ -147,6 +148,17 @@ function mod.get_connection_points(ent)
in_dir = FaUtils.rotate_180(out_dir)
end

local distance_in_tiles = 1

-- For underground and linked connections, the game does not report the
-- position of the other side directly and instead yields the position
-- of the fluidbox in this entity, e.g. c.position==c.target. We have
-- to look at the other side indirectly.
if c.connection_type ~= "normal" then
local other_pos =
c.target.get_pipe_connections(c.target_fluidbox_index)[c.target_pipe_connection_index].position
distance_in_tiles = math.ceil(FaUtils.distance(c.position, other_pos))
end
local open = true
if is_crafting_machine then open = not closed_because_no_recipe or fb.get_locked_fluid(i) ~= nil end
---@type fa.Fluids.ConnectionPoint
Expand All @@ -159,6 +171,7 @@ function mod.get_connection_points(ent)
input_direction = in_dir,
output_direction = out_dir,
open = open,
distance_in_tiles = distance_in_tiles,
}
table.insert(res, part)
end
Expand Down

0 comments on commit 8ed843a

Please sign in to comment.