From c52145f70ab5ea70bb0cdaef8cce90d8434c86c9 Mon Sep 17 00:00:00 2001 From: Choumiko Date: Sun, 31 Jul 2016 13:55:18 +0200 Subject: [PATCH] add support for wooden rails from BioIndustries fix parallel tracks always having the force of first player --- Blueprint.lua | 22 +++++++++++----------- FARL.lua | 37 +++++++++++++++++++++---------------- GUI.lua | 17 +++++++++++++++++ README.md | 4 ++++ Settings.lua | 7 ++++++- control.lua | 8 ++++++++ info.json | 2 +- 7 files changed, 68 insertions(+), 29 deletions(-) diff --git a/Blueprint.lua b/Blueprint.lua index 5688c01..e00b3fe 100644 --- a/Blueprint.lua +++ b/Blueprint.lua @@ -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 diff --git a/FARL.lua b/FARL.lua index 54c55c4..448742f 100644 --- a/FARL.lua +++ b/FARL.lua @@ -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 @@ -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 }) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/GUI.lua b/GUI.lua index c8f3475..215576c 100644 --- a/GUI.lua +++ b/GUI.lua @@ -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, @@ -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}) diff --git a/README.md b/README.md index 897c1c1..7085146 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Settings.lua b/Settings.lua index 4e419a5..aec16f6 100644 --- a/Settings.lua +++ b/Settings.lua @@ -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 = { @@ -175,6 +176,7 @@ defaultSettings = cruiseSpeed = 0.4, dropWood = true, electric = false, + wooden = false, flipPoles = false, signalDistance = 15, minPoles = true, @@ -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) diff --git a/control.lua b/control.lua index f2669d5..c1ec720 100644 --- a/control.lua +++ b/control.lua @@ -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 diff --git a/info.json b/info.json index 5b004ed..7ff438c 100644 --- a/info.json +++ b/info.json @@ -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",