Skip to content

Commit

Permalink
Get far enough to be able to start the game and look at the spaceship…
Browse files Browse the repository at this point in the history
… pieces
  • Loading branch information
ahicks92 committed Oct 22, 2024
1 parent 80bffda commit 9ee49f0
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 110 deletions.
131 changes: 57 additions & 74 deletions control.lua

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion data-updates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ with other mods, we convert these to arrays, then tack ours on at the end.
]]

local function augment_with_trigger(proto)
do return end
do
return
end
-- our trigger.
---@type data.Trigger
local nt = {
Expand Down
1 change: 0 additions & 1 deletion data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ access_radar.energy_per_nearby_scan = "3MJ" --Default: "250kJ"
access_radar.max_distance_of_sector_revealed = 32 --Default: 14, now scans up to 1024 tiles away instead of 448
access_radar.max_distance_of_nearby_sector_revealed = 2 --Default: 3
access_radar.rotation_speed = 0.01 --Default: 0.01
access_radar.tint = ar_tint
access_radar.minable.result = "access-radar"
access_radar.pictures.layers[1].tint = ar_tint --grey
access_radar.pictures.layers[2].tint = ar_tint --grey
Expand Down
3 changes: 2 additions & 1 deletion scripts/electrical.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function mod.get_electricity_flow_info(ent)
name = i,
input = false,
precision_index = defines.flow_precision_index.five_seconds,
category = "input",
})
)
local cap_add = 0
Expand Down Expand Up @@ -161,7 +162,7 @@ end
function mod.report_nearest_supplied_electric_pole(ent)
local result = ""
local pole, dist = mod.find_nearest_electric_pole(ent, true)
local dir = -1
local dir
if pole ~= nil then
dir = fa_utils.get_direction_biased(pole.position, ent.position)
result = "The nearest powered electric pole is " .. dist .. " tiles to the " .. fa_utils.direction_lookup(dir)
Expand Down
18 changes: 11 additions & 7 deletions scripts/fa-info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function mod.ent_info(pindex, ent, description, is_scanner)
--Chests etc: Report the most common item and say "and other items" if there are other types.
local itemset = ent.get_inventory(defines.inventory.chest).get_contents()
local itemtable = {}
for name, count in pairs(itemset) do
table.insert(itemtable, { name = name, count = count })
for _, info in pairs(itemset) do
table.insert(itemtable, { name = info.name, count = info.count })
end
table.sort(itemtable, function(k1, k2)
return k1.count > k2.count
Expand Down Expand Up @@ -265,11 +265,11 @@ function mod.ent_info(pindex, ent, description, is_scanner)
local left = ent.get_transport_line(1).get_contents()
local right = ent.get_transport_line(2).get_contents()

for name, count in pairs(right) do
for name, info in pairs(right) do
if left[name] ~= nil then
left[name] = left[name] + count
left[name] = left[name] + info.count
else
left[name] = count
left[name] = info.count
end
end
local contents = {}
Expand Down Expand Up @@ -1231,8 +1231,12 @@ function mod.selected_item_production_stats_info(pindex)
local get_stats = function(is_input)
local name = prototype.name
local interval = defines.flow_precision_index
local last_minute =
stats.get_flow_count({ name = name, input = is_input, precision_index = interval.one_minute, count = true })
local last_minute = stats.get_flow_count({
name = name,
category = is_input and "input" or "output",
precision_index = interval.one_minute,
count = true,
})
local last_10_minutes =
stats.get_flow_count({ name = name, input = is_input, precision_index = interval.ten_minutes, count = true })
local last_hour =
Expand Down
2 changes: 1 addition & 1 deletion scripts/fa-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function mod.direction_lookup(dir)
local reading = "unknown"
if dir < 0 then return "unknown direction ID " .. dir end
if dir >= dirs.north and dir <= dirs.northwest then
return game.direction_to_string(dir)
return helpers.direction_to_string(dir)
else
if dir == 8 then --Returned by the game when there is no direction in particular
reading = ""
Expand Down
10 changes: 5 additions & 5 deletions scripts/localising.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ function mod.get_alt(object, pindex)
end

function mod.get_item_from_name(name, pindex)
local proto = game.item_prototypes[name]
local proto = prototypes.item[name]
if proto == nil then return "(nil)" end
local result = mod.get(proto, pindex)
return result or "(nil)"
end

function mod.get_fluid_from_name(name, pindex)
local proto = game.fluid_prototypes[name]
local proto = prototypes.fluid[name]
if proto == nil then return "nil" end
local result = mod.get(proto, pindex)
return result
end

function mod.get_recipe_from_name(name, pindex)
local proto = game.recipe_prototypes[name]
local proto = prototypes.recipe[name]
if proto == nil then return "nil" end
local result = mod.get_alt(proto, pindex)
return result
end

function mod.get_item_group_from_name(name, pindex)
local proto = game.item_group_prototypes[name]
local proto = prototypes.item_group[name]
if proto == nil then return "nil" end
local result = mod.get_alt(proto, pindex)
return result
Expand Down Expand Up @@ -101,7 +101,7 @@ function mod.request_all_the_translations(pindex)
"equipment_category",
"shortcut",
}) do
for _, proto in pairs(game[cat .. "_prototypes"]) do
for _, proto in pairs(prototypes[cat]) do
mod.request_localisation(proto, pindex)
end
end
Expand Down
26 changes: 16 additions & 10 deletions scripts/rails.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ function mod.cursor_is_at_straight_end_rail_tip(pindex)
local p = game.get_player(pindex)
local pos = players[pindex].cursor_pos
--Get the rail at the cursor
local rails_at_cursor = p.surface.find_entities_filtered({ name = "straight-rail", position = pos })
--local rails_at_cursor = p.surface.find_entities_filtered({ name = "straight-rail", position = pos })
-- TODO: #271, need old rails back
local rails_at_cursor = nil
if rails_at_cursor == nil or #rails_at_cursor == 0 then return false end
--Check if it is an end rail that faces a cardinal direction
local rail_at_cursor = rails_at_cursor[1]
Expand All @@ -518,7 +520,9 @@ function mod.cursor_is_at_straight_end_rail_tip(pindex)
perimeter[8] = fa_utils.add_position(pos, { x = 1, y = 1 })
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 })
-- TODO: #271, we need old rails back or the query crashes.
--local ents = p.surface.find_entities_filtered({ name = { "straight-rail", "curved-rail" }, position = pos_p })
local ents = {}
if ents ~= nil and #ents > 0 then
for j, rail in ipairs(ents) do
--For rails found, check whether the unit number is different
Expand Down Expand Up @@ -1036,7 +1040,8 @@ function mod.count_rails_within_range(rail, range, pindex)
--2. Increase counter for each straight rail
counter = counter + 1
end
ents = game.get_player(pindex).surface.find_entities_filtered({ area = scan_area, name = "curved-rail" })
--ents = game.get_player(pindex).surface.find_entities_filtered({ area = scan_area, name = "curved-rail" })
ents = {}
for i, other_rail in ipairs(ents) do
--3. Increase counter for each curved rail
counter = counter + 1
Expand Down Expand Up @@ -1117,9 +1122,10 @@ function mod.find_nearest_intersection(rail, pindex, radius_in)
local radius = radius_in or 1000
local pos = rail.position
local scan_area = { { pos.x - radius, pos.y - radius }, { pos.x + radius, pos.y + radius } }
local ents = game
.get_player(pindex).surface
.find_entities_filtered({ area = scan_area, name = { "straight-rail", "curved-rail" } })

local ents = {}
-- .get_player(pindex).surface
-- .find_entities_filtered({ area = scan_area, name = { "straight-rail", "curved-rail" } })
local nearest = nil
local min_dist = radius
for i, other_rail in ipairs(ents) do
Expand Down Expand Up @@ -1166,10 +1172,10 @@ function mod.check_and_play_train_track_alert_sounds(step)
for pindex, player in pairs(players) do
--Check if the player is standing on a rail
local p = game.get_player(pindex)
local floor_ents =
p.surface.find_entities_filtered({ position = p.position, name = { "straight-rail", "curved-rail" } })
local nearby_ents =
p.surface.find_entities_filtered({ position = p.position, radius = 4, name = { "curved-rail" } })
local floor_ents = {}
--p.surface.find_entities_filtered({ position = p.position, name = { "straight-rail", "curved-rail" } })
local nearby_ents = {}
--p.surface.find_entities_filtered({ position = p.position, radius = 4, name = { "curved-rail" } })
local found_rail = nil
if #floor_ents > 0 then
found_rail = floor_ents[1]
Expand Down
12 changes: 6 additions & 6 deletions scripts/scanner/backends/resource-patches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local mod = {}

---@type function(): table<string, number>
local PROTOTYPE_SEARCH_RADIUSES = Functools.cached(function()
local ln = game.item_prototypes[Consts.RESOURCE_SEARCH_RADIUSES_ITEM].localised_description
local ln = prototypes.item[Consts.RESOURCE_SEARCH_RADIUSES_ITEM].localised_description
---@cast ln string
local ret = {}

Expand Down Expand Up @@ -91,7 +91,7 @@ function ResourcePatchesBackend:get_clusterer_for(proto)
local c = self.clusterers[proto]
if c then return c end

local proto_def = game.entity_prototypes[proto]
local proto_def = prototypes.entity[proto]

-- The radius of the resource is only available on the raw prototype. While
-- it is the case that the resource search distance is optional, we're a mod
Expand Down Expand Up @@ -169,16 +169,16 @@ function ResourcePatchesBackend:readout_entry(player, ent)

local total_str

if game.entity_prototypes[pname].type == "resource" and game.entity_prototypes[pname].infinite_resource then
local t = math.floor(total / game.entity_prototypes[pname].normal_resource_amount * 100)
if prototypes.entity[pname].type == "resource" and prototypes.entity[pname].infinite_resource then
local t = math.floor(total / prototypes.entity[pname].normal_resource_amount * 100)
total_str = string.format("%i percent", t)
else
total_str = FaUtils.format_number(total)
end

local percent = math.floor(total / bd.initial_total_amount * 100)

local pname = game.entity_prototypes[pname].localised_name
local pname = prototypes.entity[pname].localised_name

local res = {
"fa.scanner-resource-patch",
Expand All @@ -200,7 +200,7 @@ function ResourcePatchesBackend:dump_entries_to_callback(player, callback)
if seen_clusterers[c] then goto continue end
seen_clusterers[c] = true

local is_infinite = game.entity_prototypes[n].infinite_resource
local is_infinite = prototypes.entity[n].infinite_resource

local zoom_dist = nil

Expand Down
2 changes: 1 addition & 1 deletion scripts/scanner/backends/simple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ end
function SimpleBackend:on_new_entity(ent)
if not ent.valid then return end

self.known_entities[script.register_on_entity_destroyed(ent)] = ent
self.known_entities[script.register_on_object_destroyed(ent)] = ent
end

---@param event EventData.on_entity_destroyed
Expand Down
6 changes: 3 additions & 3 deletions scripts/scanner/surface-scanner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ local BACKEND_NAME_OVERRIDES = Functools.cached(function()
})

-- remnants
for proto in pairs(game.entity_prototypes) do
for proto in pairs(prototypes.entity) do
if proto:match("-remnants$") then bno[proto] = SEB.Remnants end
end

Expand Down Expand Up @@ -237,7 +237,7 @@ local function scan_chunk(cmd)
-- We just got these from the surface with no gap, so do everything assuming
-- it's valid.
TH.retain_unordered(ents, function(item)
local dest_req = script.register_on_entity_destroyed(item)
local dest_req = script.register_on_object_destroyed(item)
if state.seen_entities:test(dest_req) then return false end

-- The entity may not have the center in this chunk.
Expand Down Expand Up @@ -338,7 +338,7 @@ function mod.on_new_entity(surface_index, ent)
if not ent.valid then return end

local state = surface_state[surface_index]
local dest_req = script.register_on_entity_destroyed(ent)
local dest_req = script.register_on_object_destroyed(ent)

if state.seen_entities:test(dest_req) then return end
state.seen_entities:set(dest_req)
Expand Down

0 comments on commit 9ee49f0

Please sign in to comment.