Skip to content

Commit

Permalink
fix signals not being set when toggling auto/manual on a train at
Browse files Browse the repository at this point in the history
station

update station # at trainstops when line schedule is changed
changed lamp back to white, can now be colored by signals
switch lamp/combinator positions
  • Loading branch information
Choumiko committed Jul 5, 2016
1 parent c1afe4e commit b7ab377
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME := SmartTrains
VERSION_STRING := 0.4.0
VERSION_STRING := 0.4.1

OUTPUT_NAME := $(PACKAGE_NAME)_$(VERSION_STRING)
OUTPUT_DIR := build/$(OUTPUT_NAME)
Expand Down
45 changes: 40 additions & 5 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,37 @@ function get_station_number(force_name, station_name)
return station_number
end

function add_or_update_parameter(behavior, signal, index)
if behavior then
local parameters = behavior.parameters.parameters
if not parameters[index] or (not parameters[index].signal.name or parameters[index].signal.name == signal.signal.name)then
parameters[index] = signal
behavior.parameters = {parameters = parameters}
else
for i, param in pairs(parameters) do
if not param.signal or not param.signal.name then
parameters[i] = signal
parameters[i].index = i
behavior.parameters = {parameters = parameters}
return
end
end
end
end
end

function update_station_numbers()
for force, smartTrainstops in pairs(global.smartTrainstops) do
global.stationNumbers[force] = {}
for key, station in pairs(smartTrainstops) do
if station.station and station.station.valid then
global.stationNumbers[force][station.station.backer_name] = get_station_number(force,station.station.backer_name)
local number = get_station_number(force,station.station.backer_name)
global.stationNumbers[force][station.station.backer_name] = number
local signal = {signal={type = "virtual", name = "signal-station-number"}, count = number, index = 1}
if number == 0 then
signal = {signal={type = "item"}, count = 1, index = 1}
end
add_or_update_parameter(station.cargo.get_or_create_control_behavior(), signal, 1)
end
end
end
Expand Down Expand Up @@ -540,6 +565,10 @@ local update_from_version = {
update_station_numbers()
return "0.4.0"
end,
["0.4.0"] = function()
update_station_numbers()
return "0.4.1"
end,
}

function on_configuration_changed(data)
Expand Down Expand Up @@ -600,7 +629,7 @@ local function getProxyPositions(trainstop)
[6]={x=-0.5,y=-0.5}}
local pos = Position.add(trainstop.position, offset[trainstop.direction])
local poscargo = Position.add(trainstop.position, offsetcargo[trainstop.direction])
return {signalProxy = pos, cargo = poscargo}
return {signalProxy = poscargo, cargo = pos}
end

function createProxy(trainstop)
Expand All @@ -611,7 +640,7 @@ function createProxy(trainstop)
local signalProxy, cargoProxy
local force = trainstop.force.name
local proxy = {name="smart-train-stop-proxy", direction = 0, force=trainstop.force, position=positions.signalProxy}
local proxycargo = {name="smart-train-stop-proxy-cargo", direction = (trainstop.direction+2)%8, force=trainstop.force, position=positions.cargo}
local proxycargo = {name="smart-train-stop-proxy-cargo", direction = trainstop.direction, force=trainstop.force, position=positions.cargo}
if global.blueprinted_proxies[keySignal] then
local signal = global.blueprinted_proxies[keySignal]
if signal and signal.valid then
Expand Down Expand Up @@ -722,7 +751,12 @@ function findTrainStopByTrain(vehicle, rail)
}
local off = offsets
local pos = Position.add(rail.position, off[rail.direction][trainDir].position)
return surface.find_entity("smart-train-stop", pos) or surface.find_entity("train-stop", pos)
local stops = surface.find_entities_filtered{type="train-stop", area = Position.expand_to_area(pos, 0.25)}
if #stops == 0 then
pos = Position.translate(pos, trainDir, -2)
stops = surface.find_entities_filtered{type="train-stop", area = Position.expand_to_area(pos, 0.25)}
end
return stops[1]
end

function findSmartTrainStopByTrain(vehicle, rail, stationName)
Expand Down Expand Up @@ -973,7 +1007,7 @@ function on_train_changed_state(event)
t:removeRefuelStation()
end
end
log(t.name .. "updating")
log(t.name .. " updating")
t:updateLine()
if t.train.speed ~= 0 then --only update direction when train is moving: prevents direction being lost when train is stopped/started at a station
t.direction = t.train.speed < 0 and 1 or 0
Expand Down Expand Up @@ -1273,6 +1307,7 @@ function on_station_rename(force, newName, oldName)
global.stationCount[force][oldName] = nil
end
increaseStationCount(force, newName)
update_station_numbers()
end


Expand Down
6 changes: 1 addition & 5 deletions prototypes/smart_train_stop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ smart_train_stop.selection_box = {{-0.6, -0.6}, {0.6, 0.6}}

local st_proxy = copyPrototype("lamp", "small-lamp","smart-train-stop-proxy")
st_proxy.icon = "__SmartTrains__/graphics/lamp/icon.png"
st_proxy.picture_off.filename = "__SmartTrains__/graphics/lamp/light-off.png"
st_proxy.picture_off.shift = { 0, 0 }
st_proxy.picture_on.filename = "__SmartTrains__/graphics/lamp/light-on-patch.png"
st_proxy.picture_on.shift = { -0.015625, -0.1875 }
st_proxy.energy_usage_per_tick = "250W"
st_proxy.collision_mask = { "resource-layer" }
st_proxy.light = { intensity = 0.5, size = 5, color = { r = 0.02, g = 0.2, b = 0.02, a = 0 } }
st_proxy.light = { intensity = 1, size = 6 }
st_proxy.minable = nil

local st_proxy_i = copyPrototype("item", "small-lamp", "smart-train-stop-proxy")
Expand Down

0 comments on commit b7ab377

Please sign in to comment.