Skip to content

Commit

Permalink
removed unused functions and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Choumiko committed Jul 23, 2016
1 parent d78956c commit e2e3df9
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 131 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ Global Settings UI
---
![Global Settings](https://raw.githubusercontent.com/Choumiko/SmartTrains/master/readme_content/global_settings.png "Global Settings")
- **Refueling:** Sets the lower and upper limits for available fuel. If any locomotive of a train is below the lower limit, it will add the refueling station, if all are above the upper limit again it will get removed.
- **Min flow rate:** Used for the railtanker mod with the "No change" rule. If the amount of liquid in a tanker has changed by less than that rate, it is considered to be equal. With default settings: If it doesn't change by more than 2 units in 2 seconds the "No change" rule is considered true.
- **Update intervals:** Number of ticks between updating the constant combinators at smart train stops.
121 changes: 0 additions & 121 deletions Train.lua
Original file line number Diff line number Diff line change
Expand Up @@ -471,127 +471,6 @@ Train = {
return self.cargo
end,

cargoEquals = function(self, c1, c2, minFlow, interval)
local liquids1 = {}
local liquids2 = {}
local goodflow = false
local fluids = game.fluid_prototypes
c1 = c1 or {}
c2 = c2 or {}
--log("c1 "..serpent.line(c1))
--log("c2 "..serpent.line(c2))
local abs = math.abs
for l,_ in pairs(fluids) do
liquids1[l], liquids2[l] = false, false
if c1[l] ~= nil or c2[l] ~= nil then
liquids1[l] = c1[l] or 0
liquids2[l] = c2[l] or 0
local flow = (liquids1[l] - liquids2[l])/(interval/60)
if abs(flow) >= minFlow then
goodflow = true
end
--self:flyingText("flow: "..flow, colors.YELLOW, {offset=1})
c1[l] = nil
c2[l] = nil
end
end
local eq = table.compare(c1, c2)
for l,_ in pairs(fluids) do
if liquids1[l] ~= false and liquids1[l] > 0 then c1[l] = liquids1[l] end
if liquids2[l] ~= false and liquids2[l] > 0 then c2[l] = liquids2[l] end
end
return (eq and not goodflow)
end,

isCargoEmpty = function(self)
local train = self.train
if not self.railtanker and not self.proxy_chests then
return train.get_item_count() == 0
end
local floor = math.floor
for i, wagon in pairs(train.cargo_wagons) do
if self.proxy_chests and self.proxy_chests[i] then
--wagon is used by logistics railway
local chest = self.proxy_chests[i]
local inventory = chest.get_inventory(defines.inventory.chest)
--debugDump({i=i, empty=inventory.is_empty()},true)
if not inventory.is_empty() then
return false
end
else
if wagon.name ~= "rail-tanker" then
if not wagon.get_inventory(1).is_empty() then
return false
end
else
if remote.interfaces.railtanker and remote.interfaces.railtanker.getLiquidByWagon then
local d = remote.call("railtanker", "getLiquidByWagon", wagon)
if d.type ~= nil then
if floor(d.amount) > 0 then
return false
end
end
end
end
end
end
return true
end,

isCargoFull = function(self)
local train = self.train
local inv_full = function(inv, wagon)
--check if all slots are blocked
if inv.can_insert{name="railgun", count=1} then
--inserted railgun -> at least 1 slot is free
return false
end
if inv.hasbar() and inv.getbar() == 0 then
return false
end
-- check if all stacks are full
local contents = inv.get_contents()
for item, _ in pairs(contents) do
if inv.can_insert{name=item, count=1} then
return false
end
end
if inv.has_filters() then
local filtered_item
for i=1, #inv do
filtered_item = inv.get_filter(i)
if filtered_item then
if inv.can_insert{name=filtered_item, count=1} then return false end
end
end
end
-- all stacks are full, filtered slots are full
return true
end
local ceil = math.ceil
for i, wagon in pairs(train.cargo_wagons) do
if self.proxy_chests and self.proxy_chests[i] then
--wagon is used by logistics railway
local chest = self.proxy_chests[i]
local inventory = chest.get_inventory(defines.inventory.chest)
if not inv_full(inventory) then return false end
else
if wagon.name ~= "rail-tanker" then
local inv = wagon.get_inventory(1)
if not inv_full(inv, wagon) then return false end
else
if remote.interfaces.railtanker and remote.interfaces.railtanker.getLiquidByWagon then
local d = remote.call("railtanker", "getLiquidByWagon", wagon)
if ceil(d.amount) < 2500 then
return false
end
end
end
end
end
return true
end,

updateState = function(self)
--debugDump(util.formattime(game.tick,true).."@ "..getKeyByValue(defines.train_state, self.train.state),true)
self.previousState = self.state
Expand Down
4 changes: 1 addition & 3 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require("Train")
defaultTrainSettings = {autoRefuel = false}
defaultSettings =
{ refuel = { station = "Refuel", rangeMin = 25*8, rangeMax = 50*8, time = 600 },
minFlow = 1, -- minimal liquid change to count as changed
intervals = {
write = 60, -- ticks between constant combinator updates
inactivity = 120, --ticks between cargo comparison
Expand Down Expand Up @@ -504,7 +503,6 @@ local update_from_version = {
global.settings.intervals.read = global.settings.circuit.interval or defaultSettings.intervals.read
global.settings.intervals.noChange = defaultSettings.intervals.inactivity
global.settings.intervals.cargoRule = global.settings.intervals.read --defaultSettings.intervals.cargoRule
global.settings.minFlow = global.settings.depart.minFlow or defaultSettings.minFlow

global.settings.circuit = nil
global.settings.depart = nil
Expand Down Expand Up @@ -579,7 +577,6 @@ local update_from_version = {


for name, trainline in pairs(global.trainLines) do
log(name)
local tmp = {}
local records = trainline.records
trainline.rules.inactivity = trainline.rules.noChange
Expand Down Expand Up @@ -674,6 +671,7 @@ local update_from_version = {
global.settings.intervals.read = nil
global.settings.intervals.cargoRule = nil
global.settings.intervals.noChange = nil
global.settings.minFlow = nil
return "0.4.3"
end,
}
Expand Down
6 changes: 0 additions & 6 deletions gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ GUI = {
GUI.addLabel(tbl, {"stg-refuel-station"})
GUI.addTextfield(tbl, {name="refuelStation", style="st_textfield_big", text = global.settings.refuel.station})

GUI.addLabel(tbl, {"stg-min-flow-rate"})
GUI.addTextfield(tbl, {name="minFlow", style="st_textfield_small", text = global.settings.minFlow})

local intervals = gui.globalSettings.add({type = "frame", name="frm_intervals", direction="horizontal", style = "st_inner_frame", caption = {"stg-intervals"}})
tbl = intervals.add{type="table", name="tbl", colspan=2, style="st_table"}

Expand Down Expand Up @@ -713,15 +710,12 @@ on_gui_click = {
local station = refueling.refuelStation.text
global.settings.refuel = {time=time, rangeMin = min, rangeMax = max, station = station}

local minFlow = sanitizeNumber(refueling.minFlow.text, global.settings.minFlow)

local intervals = settings.frm_intervals.tbl
local i_inactivity = 120 --sanitizeNumber(intervals.intervals_inactivity.text, global.settings.intervals.inactivity)
local i_write = sanitizeNumber(intervals.intervals_write.text, global.settings.intervals.write)

if i_write < 1 then i_write = 1 end

global.settings.minFlow = minFlow
global.settings.intervals = {write = i_write, inactivity = i_inactivity}

return true
Expand Down
Binary file modified readme_content/global_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e2e3df9

Please sign in to comment.