Skip to content

Commit

Permalink
add support for wooden rails from BioIndustries
Browse files Browse the repository at this point in the history
fix parallel tracks always having the force of first player
  • Loading branch information
Choumiko committed Jul 31, 2016
1 parent 8eae576 commit c52145f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 29 deletions.
22 changes: 11 additions & 11 deletions Blueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,33 @@ Blueprint.group_entities = function(e)
if box.br.y < position.y then box.br.y = position.y end

local dir = e[i].direction or 0
if e[i].name == "rail-chain-signal" and not offsets.chain then
local name = e[i].name

if name == "rail-chain-signal" and not offsets.chain then
offsets.chain = {direction = dir, name = e[i].name, position = e[i].position}
-- collect all poles in bp
elseif global.electric_poles[e[i].name] then
table.insert(poles, {name = e[i].name, direction = dir, position = e[i].position})
elseif e[i].name == "straight-rail" then
table.insert(poles, {name = name, direction = dir, position = e[i].position})
elseif name == "straight-rail" or name == "bi-straight-rail-wood" then
rails = rails + 1
if not bpType then
if e[i].name == "straight-rail" then
bpType = (dir == 0 or dir == 4) and "straight" or "diagonal"
end
end
if (bpType == "diagonal" and (dir == 3 or dir == 7)) or
(bpType == "straight" and (dir == 0 or dir == 4)) then
table.insert(offsets.rails, {name = e[i].name, direction = dir, position = e[i].position, type=e[i].name})
table.insert(offsets.rails, {name = name, direction = dir, position = e[i].position, type = game.entity_prototypes[name].type})
else
return false, {"msg-bp-rail-direction"}
end
elseif e[i].name == "rail-signal" then
table.insert(offsets.signals, {name = e[i].name, direction = dir, position = e[i].position})
elseif name == "rail-signal" then
table.insert(offsets.signals, {name = name, direction = dir, position = e[i].position})
else
local e_type = game.entity_prototypes[e[i].name].type
local e_type = game.entity_prototypes[name].type
local rail_entities = {["wall"]=true}
if not rail_entities[e_type] then
table.insert(offsets.poleEntities, {name = e[i].name, direction = dir, position = e[i].position})
table.insert(offsets.poleEntities, {name = name, direction = dir, position = e[i].position})
else
table.insert(offsets.railEntities, {name = e[i].name, direction = dir, position = e[i].position})
table.insert(offsets.railEntities, {name = name, direction = dir, position = e[i].position})
end
end
end
Expand Down
37 changes: 21 additions & 16 deletions FARL.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function moveRail(rail, direction, distance)
local off = data[rail.direction] and data[rail.direction] or { x = 0, y = 0 }
local pos = addPos(off, rail.position)
pos = pos12toXY(moveposition(fixPos(pos), direction, distance))
local newRail = { name = rail.name, type = rail.type, direction = rail.direction, position = pos, force = game.players[1].force }
local newRail = { name = rail.name, type = rail.type, direction = rail.direction, position = pos, force = rail.force }
if rail.type == "straight-rail" and rail.direction % 2 == 1 and distance % 2 == 1 then
newRail.direction = (rail.direction + 4) % 8
end
Expand Down Expand Up @@ -786,13 +786,16 @@ FARL.removeEntitiesFiltered = function(self, args)
local force = self.locomotive.force
local neutral_force = game.forces.neutral
for _, entity in pairs(self.surface.find_entities_filtered(args)) do
--for _, entity in pairs(self.surface.find_entities(args.area)) do
if not self:isProtected(entity) and (entity.force == force or entity.force == neutral_force) then
local item = false
local name = entity.name
if entity.prototype.items_to_place_this then
local k, _ = next(entity.prototype.items_to_place_this)
item = k
if entity.type == "straight-rail" or entity.type == "curved-rail" then
item = entity.name
else
if entity.prototype.items_to_place_this then
local k, _ = next(entity.prototype.items_to_place_this)
item = k
end
end
if trigger_event[name] then
game.raise_event(defines.events.on_robot_pre_mined, { entity = entity })
Expand Down Expand Up @@ -950,7 +953,8 @@ FARL.removeConcrete = function(self, area)
local tileName = self.surface.get_tile(x, y).name
-- check that tile is placeable by the player
local itemsToPlace = game.tile_prototypes[tileName].items_to_place_this
if (itemsToPlace and next(itemsToPlace) ~= "landfill") and not self:is_protected_tile({ x = x, y = y }) then
local toPlace = itemsToPlace and next(itemsToPlace)
if (toPlace and toPlace ~= "landfill" and toPlace ~= "bi-adv-fertiliser") and not self:is_protected_tile({ x = x, y = y }) then
counts[tileName] = counts[tileName] or 0
table.insert(tiles, { name = self.replace_tile, position = { x, y } })
counts[tileName] = counts[tileName] + 1
Expand Down Expand Up @@ -1559,17 +1563,18 @@ end

FARL.addItemToCargo = function(self, item, count, place_result)
count = count or 1
if item == "straight-rail" or item == "curved-rail" then
item = "rail"
if item == "curved-rail" then
count = 4
end
end
local remaining = count - self.train.insert({ name = item, count = count })
local rails = {
["straight-rail"] = {name = "rail", count = 1},
["curved-rail"] = {name = "rail", count = 4},
["bi-straight-rail-wood"] = {name="bi-rail-wood", count = 1},
["bi-curved-rail-wood"] = {name = "bi-rail-wood", count = 4}
}
local itemStack = rails[item] or {name = item, count = count}
local remaining = count - self.train.insert(itemStack)

if remaining > 0 and (self.settings.dropWood or place_result) then
local position = self.surface.find_non_colliding_position("item-on-ground", self.driver.position, 100, 0.5)
self.surface.create_entity { name = "item-on-ground", position = position, stack = { name = item, count = remaining } }
self.surface.create_entity { name = "item-on-ground", position = position, stack = { name = itemStack.name, count = remaining } }
end
end

Expand Down Expand Up @@ -1661,7 +1666,7 @@ FARL.parseBlueprints = function(self, bp)
local traveldir = bpType == "straight" and 0 or 1
local signalPositions = {get_signal_for_rail(rail, traveldir, false), get_signal_for_rail(rail, traveldir, true)}
for _, signal in pairs(signalPositions) do
if not mainRail and signal.position.x == offsets.chain.position.x and signal.position.y == offsets.chain.position.y and
if not mainRail and signal.position.x == offsets.chain.position.x and signal.position.y == offsets.chain.position.y and
signal.direction == offsets.chain.direction then
rail.main = true
mainRail = rail
Expand Down Expand Up @@ -1713,7 +1718,7 @@ FARL.parseBlueprints = function(self, bp)
name = l.name,
position = subPos(l.position, mainRail.position),
direction = l.direction,
type = l.name
type = game.entity_prototypes[l.name].type
}
local move_dir = tmp.position.y < 0 and 1 or 5
if bpType == "diagonal" then
Expand Down
17 changes: 17 additions & 0 deletions GUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ GUI = {
psettings.rail = rails.basic
end
farl.lastrail = false
elseif name == "woodenRails" then
if not game.entity_prototypes["bi-straight-rail-wood"] then
psettings.rail = rails.basic
return
end
psettings.wooden = not psettings.wooden
if psettings.wooden then
psettings.rail = rails.wooden
else
psettings.rail = rails.basic
end
farl.lastrail = false
end
end,

Expand Down Expand Up @@ -270,6 +282,11 @@ GUI = {
GUI.add(settings, {type="label", caption=""})
end

if game.entity_prototypes["bi-straight-rail-wood"] then
GUI.add(settings,{type="checkbox", name="woodenRails", caption="use wooden rails", state=psettings.wooden})
GUI.add(settings, {type="label", caption=""})
end

GUI.add(settings, {type="label", caption={"stg-poleSide"}})
GUI.add(settings, {type="checkbox", name="flipPoles", caption={"stg-flipPoles"}, state=psettings.flipPoles})

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
[Look at the forums](https://forums.factorio.com/viewforum.php?f=61)

#Changelog
0.5.36
- added support for [BioIndustries](https://mods.factorio.com/mods/TheSAguy/Bio_Industries) wooden rails
- fixed parallel tracks always having the force of the first player

0.5.35

- fixed signals not being found in blueprints if placed in the wrong tile
Expand Down
7 changes: 6 additions & 1 deletion Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ require "util"

rails = {
basic = {curved = "curved-rail", straight = "straight-rail"},
electric = {curved = "curved-power-rail", straight = "straight-power-rail"}}
electric = {curved = "curved-power-rail", straight = "straight-power-rail"},
wooden = {curved = "bi-curved-rail-wood", straight = "bi-straight-rail-wood"}}

--poleDistance = 1, side = right
defaultsDiagonal = {
Expand Down Expand Up @@ -175,6 +176,7 @@ defaultSettings =
cruiseSpeed = 0.4,
dropWood = true,
electric = false,
wooden = false,
flipPoles = false,
signalDistance = 15,
minPoles = true,
Expand Down Expand Up @@ -219,6 +221,9 @@ Settings = {
if not global.electricInstalled then
self.electric = false
end
if not game.entity_prototypes['bi-straight-rail-wood'] then
self.wooden = false
end
end,

dump = function(self)
Expand Down
8 changes: 8 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ local function on_configuration_changed(data)
global.concrete = nil
global.tiles = nil
end

if oldVersion < "0.5.36" then
for _, psettings in pairs(global.players) do
if psettings.wooden == nil then
psettings.wooden = false
end
end
end
end
end
else
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FARL",
"version": "0.5.35",
"version": "0.5.36",
"factorio_version": "0.13",
"title": "Fully Automated Rail Layer",
"author": "Choumiko",
Expand Down

0 comments on commit c52145f

Please sign in to comment.