Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions exp_legacy/module/config/vlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return {
always_day = false,
solar_power_multiplier = 1,
min_brightness = 0.15,
ticks_per_day = 25000,
ticks_per_day = 25200,
daytime = 0,
dusk = 0.25,
evening = 0.45,
Expand All @@ -25,20 +25,20 @@ return {

interface_limit = { --- @setting interface_limit Sets the limit for the number of vlayer interfaces that can be created
energy = 1, -- >1 allows for disconnected power networks to receive power
circuit = 10, -- No caveats
storage_input = 10, -- No caveats
circuit = 20, -- No caveats
storage_input = 20, -- No caveats
storage_output = 1, -- >0 allows for item teleportation (allowed_items only)
},

allowed_items = { --- @setting allowed_items List of all items allowed in vlayer storage and their properties
--[[
Allowed properties:
starting_value = 0: The amount of the item placed into the vlayer on game start, ignores area requirements
required_area = 0: When greater than 0 the items properties are not applied unless their is sufficient surplus surface area
production = 0: The energy production of the item in MW, used for solar panels
discharge = 0: The energy discharge of the item in MW, used for accumulators
capacity = 0: The energy capacity of the item in MJ, used for accumulators
surface_area = 0: The surface area provided by the item, used for landfill
starting_value : The amount of the item placed into the vlayer on game start, ignores area requirements
required_area : When greater than 0 the items properties are not applied unless their is sufficient surplus surface area
production : The energy production of the item in MW, used for solar panels
discharge : The energy discharge of the item in MW, used for accumulators
capacity : The energy capacity of the item in MJ, used for accumulators
surface_area : The surface area provided by the item, used for landfill
]]
["solar-panel"] = {
starting_value = 0,
Expand All @@ -54,7 +54,7 @@ return {
["landfill"] = {
starting_value = 0,
required_area = 0,
surface_area = 6, -- Tiles
surface_area = 8, -- Tiles
},
["wood"] = {
starting_value = 0,
Expand All @@ -70,31 +70,40 @@ return {
fuel_value = 4, -- MJ
power = false, -- turn all coal to power to reduce trash
},
--[[
['iron-ore'] = {
["solid-fuel"] = {
starting_value = 0,
required_area = 0,
surface_area = 0
surface_area = 0,
fuel_value = 12, -- MJ
power = false, -- turn all solid fuel to power to reduce trash
},
['copper-ore'] = {
["rocket-fuel"] = {
starting_value = 0,
required_area = 0,
surface_area = 0,
fuel_value = 100, -- MJ
power = false, -- turn all rocket fuel to power to reduce trash
}
--[[
["iron-ore"] = {
starting_value = 0,
required_area = 0,
surface_area = 0
surface_area = 0,
},
['coal'] = {
["copper-ore"] = {
starting_value = 0,
required_area = 0,
surface_area = 0
surface_area = 0,
},
['stone'] = {
["stone"] = {
starting_value = 0,
required_area = 0,
surface_area = 0
surface_area = 0,
},
['uranium-ore'] = {
["uranium-ore"] = {
starting_value = 0,
required_area = 0,
surface_area = 0
surface_area = 0,
},
]]
},
Expand Down Expand Up @@ -170,5 +179,5 @@ return {
base_game_equivalent = "accumulator",
multiplier = 16384,
},
},
}
}
28 changes: 23 additions & 5 deletions exp_legacy/module/modules/control/vlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local vlayer_data = {
properties = {
total_surface_area = 0,
used_surface_area = 0,
total_production = 0,
production = 0,
discharge = 0,
capacity = 0,
Expand Down Expand Up @@ -155,7 +156,7 @@ local function get_production_multiplier()
end

if surface.darkness then
-- We are using a real surface, our config does not contain 'darkness'
-- We are using a real surface, our config does not contain "darkness"
local brightness = 1 - surface.darkness

if brightness >= surface.min_brightness then
Expand Down Expand Up @@ -212,7 +213,9 @@ function vlayer.allocate_item(item_name, count)
assert(item_properties, "Item not allowed in vlayer: " .. tostring(item_name))

if item_properties.production then
vlayer_data.properties.production = vlayer_data.properties.production + item_properties.production * count
local nc = item_properties.production * count
vlayer_data.properties.production = vlayer_data.properties.production + nc
vlayer_data.properties.total_production = vlayer_data.properties.total_production + nc
end

if item_properties.capacity then
Expand All @@ -232,6 +235,14 @@ function vlayer.allocate_item(item_name, count)
end
end

function vlayer.unable_alloc_item_pwr_calc(item_name, count)
local item_properties = config.allowed_items[item_name]

if item_properties.production then
vlayer_data.properties.total_production = vlayer_data.properties.total_production + item_properties.production * count
end
end

-- For all allowed items, setup their starting values, default 0
for item_name, properties in pairs(config.allowed_items) do
vlayer_data.storage.items[item_name] = properties.starting_value or 0
Expand Down Expand Up @@ -260,7 +271,9 @@ function vlayer.insert_item(item_name, count)
vlayer.allocate_item(item_name, allocate_count)
end

vlayer_data.storage.unallocated[item_name] = vlayer_data.storage.unallocated[item_name] + count - allocate_count
local unallocated = count - allocate_count
vlayer_data.storage.unallocated[item_name] = vlayer_data.storage.unallocated[item_name] + unallocated
vlayer.unable_alloc_item_pwr_calc(item_name, unallocated)
else
vlayer.allocate_item(item_name, count)
end
Expand Down Expand Up @@ -456,6 +469,7 @@ local function handle_unallocated()
if allocation_count > 0 then
vlayer_data.storage.unallocated[item_name] = vlayer_data.storage.unallocated[item_name] - allocation_count
vlayer.allocate_item(item_name, allocation_count)
vlayer.unable_alloc_item_pwr_calc(item_name, -allocation_count)
end
end
end
Expand All @@ -464,15 +478,19 @@ end
function vlayer.get_statistics()
local vdp = vlayer_data.properties.production * mega
local gdm = get_production_multiplier()
local gsm = get_sustained_multiplier()
local gald = get_actual_land_defecit()

return {
total_surface_area = vlayer_data.properties.total_surface_area,
used_surface_area = vlayer_data.properties.used_surface_area,
remaining_surface_area = get_actual_land_defecit(),
remaining_surface_area = gald,
surface_area = vlayer_data.properties.total_surface_area - gald,
production_multiplier = gdm,
energy_max = vdp,
energy_production = vdp * gdm,
energy_sustained = vdp * get_sustained_multiplier(),
energy_total_production = vlayer_data.properties.total_production * gsm * mega,
energy_sustained = vdp * gsm,
energy_capacity = vlayer_data.properties.capacity * mega,
energy_storage = vlayer_data.storage.energy,
day_time = math.floor(vlayer_data.surface.daytime * vlayer_data.surface.ticks_per_day),
Expand Down
42 changes: 22 additions & 20 deletions exp_legacy/module/modules/gui/vlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ local vlayer_gui_display_item_accumulator_count =
font = "heading-2",
}

--- Display label for the remaining surface area
-- @element vlayer_gui_display_signal_remaining_surface_area_name
local vlayer_gui_display_signal_remaining_surface_area_name =
--- Display label for the surface area
-- @element vlayer_gui_display_signal_surface_area_name
local vlayer_gui_display_signal_surface_area_name =
Gui.element{
type = "label",
name = "vlayer_display_signal_remaining_surface_area_name",
Expand All @@ -190,16 +190,16 @@ local vlayer_gui_display_signal_remaining_surface_area_name =
width = 200,
}

local vlayer_gui_display_signal_remaining_surface_area_count =
local vlayer_gui_display_signal_surface_area_count =
Gui.element{
type = "label",
name = "vlayer_display_signal_remaining_surface_area_count",
caption = "0",
style = "heading_2_label",
type = "progressbar",
name = "vlayer_display_signal_surface_area_count",
caption = "",
value = 0,
style = "electric_satisfaction_statistics_progressbar",
}:style{
width = 200,
height = 28,
horizontal_align = "right",
font = "heading-2",
}

--- Display label for the sustained energy production
Expand All @@ -217,14 +217,14 @@ local vlayer_gui_display_signal_sustained_name =

local vlayer_gui_display_signal_sustained_count =
Gui.element{
type = "label",
type = "progressbar",
name = "vlayer_display_signal_sustained_count",
caption = "0",
style = "heading_2_label",
caption = "",
value = 0,
style = "electric_satisfaction_statistics_progressbar",
}:style{
width = 200,
height = 28,
horizontal_align = "right",
font = "heading-2",
}

--- Display label for the current energy production
Expand Down Expand Up @@ -288,8 +288,8 @@ local vlayer_display_set =
vlayer_gui_display_item_solar_count(disp)
vlayer_gui_display_item_accumulator_name(disp)
vlayer_gui_display_item_accumulator_count(disp)
vlayer_gui_display_signal_remaining_surface_area_name(disp)
vlayer_gui_display_signal_remaining_surface_area_count(disp)
vlayer_gui_display_signal_surface_area_name(disp)
vlayer_gui_display_signal_surface_area_count(disp)
vlayer_gui_display_signal_sustained_name(disp)
vlayer_gui_display_signal_sustained_count(disp)
vlayer_gui_display_signal_production_name(disp)
Expand Down Expand Up @@ -489,11 +489,13 @@ Event.on_nth_tick(config.update_tick_gui, function(_)
val = (items_alloc["accumulator"] / math.max(items["accumulator"], 1)),
cap = format_number(items_alloc["accumulator"], false) .. " / " .. format_number(items["accumulator"], false),
},
[vlayer_gui_display_signal_remaining_surface_area_count.name] = {
cap = format_number(stats.remaining_surface_area, false),
[vlayer_gui_display_signal_surface_area_count.name] = {
val = (stats.total_surface_area / math.max(stats.surface_area, 1)),
cap = format_number(stats.remaining_surface_area)
},
[vlayer_gui_display_signal_sustained_count.name] = {
cap = format_energy(stats.energy_sustained, "W"),
val = (stats.energy_sustained / math.max(stats.energy_total_production, 1)),
cap = format_energy(stats.energy_sustained, "W") .. " / " .. format_energy(stats.energy_total_production, "W")
},
[vlayer_gui_display_signal_production_count.name] = {
val = (stats.energy_production / math.max(stats.energy_max, 1)),
Expand Down
Loading