Skip to content

Commit

Permalink
add 15 stone to cargo when a rock is removed
Browse files Browse the repository at this point in the history
require landfill item to bridge water
remove 4 rail pieces per curve placed
  • Loading branch information
Choumiko committed Jun 27, 2016
1 parent b1951f9 commit 3ec619d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 38 deletions.
53 changes: 33 additions & 20 deletions FARL.lua
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ FARL.removeStone = function(self, area)
if removeStone then
for _, entity in pairs(self.surface.find_entities_filtered { area = area, name = "stone-rock" }) do
entity.die()
self:addItemToCargo("stone", 15)
local stat = global.statistics[self.locomotive.force.name].removed["stone-rock"] or 0
global.statistics[self.locomotive.force.name].removed["stone-rock"] = stat + 1
end
Expand Down Expand Up @@ -865,11 +866,11 @@ FARL.replaceWater = function(self, tiles, w, dw)
local lfills = math.ceil(w / 2 + dw * 1.5)
lfills = lfills > 20 and 20 or lfills
-- check to make sure there is enough landfill in the FARL and if there is apply the changes, remove landfill. if not then show error message
if self:getCargoCount("concrete") >= lfills then
if self:getCargoCount("landfill") >= lfills then
self.surface.set_tiles(tiles)
self:removeItemFromCargo("concrete", lfills)
self:removeItemFromCargo("landfill", lfills)
else
self:print({ "msg-not-enough-concrete", { "item-name.concrete" } })
self:print({ "msg-not-enough-concrete", { "item-name.landfill" } })
end
end
end
Expand Down Expand Up @@ -1598,11 +1599,30 @@ FARL.genericCanPlace = function(self, arg)
end
local name = arg.type == "entity-ghost" and arg.ghost_name or arg.name
--apiCalls.canplace = apiCalls.canplace + 1
local can_place = false;
if not arg.direction then
return self.surface.can_place_entity { name = name, position = arg.position }
can_place = self.surface.can_place_entity { name = name, position = arg.position }
else
return self.surface.can_place_entity { name = name, position = arg.position, direction = arg.direction }
end
can_place = self.surface.can_place_entity { name = name, position = arg.position, direction = arg.direction }
end
--TODO remove once can_place_entity is fixed
if can_place then
local area = game.entity_prototypes[name].collision_box
local st, ft = area.left_top, area.right_bottom
st = addPos(st, arg.position)
ft = addPos(ft, arg.position)
for x = st.x, ft.x, 1 do
for y = st.y, ft.y, 1 do
local tileName = self.surface.get_tile(x, y).name
-- check that tile is water, if it is add it to a list of tiles to be changed to grass
if tileName == "water" or tileName == "deepwater" then
return false
end
end
end
end

return can_place
end

FARL.genericPlace = function(self, arg, ignore)
Expand All @@ -1628,7 +1648,7 @@ FARL.genericPlace = function(self, arg, ignore)
self:protect(entity)
--local diff = subPos(arg.position, entity.position)
--if diff.x ~= 0 or diff.y~= 0 then
--self:flyingText2("x", RED,true,entity.position)
--self:flyingText2(serpent.line(canPlace, {comment=false}), RED,true,entity.position)
--self:print("Misplaced entity: "..entity.name)
--self:print("arg:"..pos2Str(arg.position).." ent:"..pos2Str(entity.position))
--end
Expand Down Expand Up @@ -1861,12 +1881,9 @@ FARL.placeRails = function(self, nextRail, newTravelDir)
end
end

local hasRail = self:getCargoCount(newRail.name) > 0
if not hasRail and newRail.name == self.settings.rail.curved then
hasRail = self:getCargoCount(self.settings.rail.straight) >= 4
removeItem = self.settings.rail.straight
removeAmount = 4
end
removeAmount = newRail.name == self.settings.rail.curved and 4 or 1
removeItem = self.settings.rail.straight
local hasRail = self:getCargoCount(newRail.name) > removeAmount

if canplace and hasRail then
newRail.force = self.locomotive.force
Expand Down Expand Up @@ -2045,13 +2062,9 @@ FARL.placeParallelCurve = function(self, traveldir, rail, lane_index)
new_curve.position = move_right_forward(rail.position, direction, right, forward)
self.lastCurve.blocked[lane_index] = self.lanes["d" .. traveldir % 2]["i" .. bi]["l" .. lane_index].lag

local hasRail = self:getCargoCount(new_curve.name) > 0
local remove_item, remove_amount = new_curve.name, 1
if not hasRail and new_curve.name == self.settings.rail.curved then
hasRail = self:getCargoCount(self.settings.rail.straight) >= 4
remove_item = self.settings.rail.straight
remove_amount = 4
end
local remove_item, remove_amount = self.settings.rail.straight, 4
local hasRail = self:getCargoCount(self.settings.rail.straight) > remove_amount

if not hasRail then
self:deactivate({ "msg-out-of-rails" })
return false
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME := FARL
VERSION_STRING := 0.5.28
VERSION_STRING := 0.5.3

OUTPUT_NAME := $(PACKAGE_NAME)_$(VERSION_STRING)
OUTPUT_DIR := build/$(OUTPUT_NAME)
Expand Down
6 changes: 3 additions & 3 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ remote.add_interface("farl",
end,

quickstart = function(player)
local items = {"farl", "curved-rail", "straight-rail", "medium-electric-pole", "big-electric-pole",
local items = {"farl", "straight-rail", "medium-electric-pole", "big-electric-pole",
"small-lamp", "solid-fuel", "rail-signal", "blueprint", "cargo-wagon"}
local count = {5,50,50,50,50,50,50,50,10,5}
local count = {5,100,50,50,50,50,50,10,5}
player = player or game.players[1]
for i=1,#items do
player.insert{name=items[i], count=count[i]}
end
end,
quickstart2 = function(player)
local items = {"power-armor-mk2", "personal-roboport-equipment", "fusion-reactor-equipment",
"blueprint", "deconstruction-planner", "construction-robot", "basic-exoskeleton-equipment"}
"blueprint", "deconstruction-planner", "construction-robot", "exoskeleton-equipment"}
local count = {1,5,3,1,1,50,2}
player = player or game.players[1]
for i=1,#items do
Expand Down
2 changes: 1 addition & 1 deletion data-final-fixes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ meta_concrete.hidden = true
--table.insert(metaitem_concrete.flags, "hidden")

for _, ent in pairs(data.raw["item"]) do
if ent.place_as_tile and ent.place_as_tile.result and type(ent.place_as_tile.result) == "string" then
if ent.name ~= "landfill" and ent.place_as_tile and ent.place_as_tile.result and type(ent.place_as_tile.result) == "string" then
local item_name = false
local amount = 1
local tile = data.raw["tile"][ent.place_as_tile.result]
Expand Down
3 changes: 2 additions & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "FARL",
"version": "{{VERSION}}",
"factorio_version": "0.13",
"title": "Fully Automated Rail Layer",
"author": "Choumiko",
"contact": "www.factorioforums.com",
"description": "Fully automated rail-layer",
"dependencies": ["base >= 0.12.32", "? 5dim_trains", "? TheFatController"]
"dependencies": ["base >= 0.13.0", "? 5dim_trains", "? TheFatController"]
}
13 changes: 2 additions & 11 deletions prototypes/entity/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@ local farl = copyPrototype("locomotive", "diesel-locomotive", "farl")
farl.icon = "__FARL__/graphics/icons/farl.png"
farl.max_speed = 0.8
farl.energy_source.fuel_inventory_size = 4
farl.pictures.filenames =
{
"__FARL__/graphics/entity/farl/farl-01.png",
"__FARL__/graphics/entity/farl/farl-02.png",
"__FARL__/graphics/entity/farl/farl-03.png",
"__FARL__/graphics/entity/farl/farl-04.png",
"__FARL__/graphics/entity/farl/farl-05.png",
"__FARL__/graphics/entity/farl/farl-06.png",
"__FARL__/graphics/entity/farl/farl-07.png",
"__FARL__/graphics/entity/farl/farl-08.png"
}

farl.color = {r = 1, g = 0.80, b = 0, a = 0.5},
data:extend({farl})

--local c_i = copyPrototype("item", "curved-rail", "farl-curved-rail", true)
Expand Down
2 changes: 1 addition & 1 deletion prototypes/styles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data.raw["gui-style"].default["farl_textfield_small"] =
data.raw["gui-style"].default["farl_button"] =
{
type = "button_style",
parent = "default",
parent = "button_style",
font = "farl-small-bold"
}
data.raw["gui-style"].default["farl_checkbox"] =
Expand Down

0 comments on commit 3ec619d

Please sign in to comment.