Skip to content

Commit

Permalink
Merge pull request #190 from bbassie/feature/warp-net-id
Browse files Browse the repository at this point in the history
Feature: Warps need to be connected to the same electricity network
  • Loading branch information
Cooldude2606 committed Mar 30, 2021
2 parents bbc00ac + 60bb28d commit 8431b2e
Show file tree
Hide file tree
Showing 4 changed files with 544 additions and 307 deletions.
25 changes: 18 additions & 7 deletions config/gui/warps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ return {

-- Warp area generation
entities = { --- @setting entities The entities which are created for warp areas
{'small-lamp',-3,-2},{'small-lamp',-3,2},{'small-lamp',3,-2},{'small-lamp',3,2},
{'small-lamp',-2,-3},{'small-lamp',2,-3},{'small-lamp',-2,3},{'small-lamp',2,3},
{'small-electric-pole',-3,-3},{'small-electric-pole',3,3},{'small-electric-pole',-3,3},{'small-electric-pole',3,-3}
{'small-lamp', -4, -2}, {'small-lamp', -2, -4}, {'small-electric-pole',-3,-3}, -- Top left corner
{'small-lamp', 3, -2}, {'small-lamp', 1, -4}, {'small-electric-pole',2,-3}, -- Top right corner
{'small-lamp', 3, 1}, {'small-lamp', 1, 3}, {'small-electric-pole',2,2}, -- Bottom right corner
{'small-lamp', -4, 1}, {'small-lamp', -2, 3}, {'small-electric-pole',-3,2}, -- Bottom left corner
},
base_tile = 'tutorial-grid', --- @setting base_tile The tile which is used for the warp areas
tiles = { --- @setting tiles The tiles which are created for warp areas
{-3,-2},{-3,-1},{-3,0},{-3,1},{-3,2},{3,-2},{3,-1},{3,0},{3,1},{3,2},
{-2,-3},{-1,-3},{0,-3},{1,-3},{2,-3},{-2,3},{-1,3},{0,3},{1,3},{2,3}
{"black-refined-concrete",-4,-2},{"black-refined-concrete",-4,-1},{"black-refined-concrete",-4,0},{"black-refined-concrete",-4,1},
{"black-refined-concrete",-3,-3},{"purple-refined-concrete",-3,-2},{"purple-refined-concrete",-3,-1},{"purple-refined-concrete",-3,0},
{"purple-refined-concrete",-3,1},{"black-refined-concrete",-3,2},{"black-refined-concrete",-2,-4},{"purple-refined-concrete",-2,-3},
{"purple-refined-concrete",-2,-2},{"purple-refined-concrete",-2,-1},{"purple-refined-concrete",-2,0},{"purple-refined-concrete",-2,1},
{"purple-refined-concrete",-2,2},{"black-refined-concrete",-2,3},{"black-refined-concrete",-1,-4},{"purple-refined-concrete",-1,-3},
{"purple-refined-concrete",-1,-2},{"purple-refined-concrete",-1,-1},{"purple-refined-concrete",-1,0},{"purple-refined-concrete",-1,1},
{"purple-refined-concrete",-1,2},{"black-refined-concrete",-1,3},{"black-refined-concrete",0,-4},{"purple-refined-concrete",0,-3},
{"purple-refined-concrete",0,-2},{"purple-refined-concrete",0,-1},{"purple-refined-concrete",0,0},{"purple-refined-concrete",0,1},
{"purple-refined-concrete",0,2},{"black-refined-concrete",0,3},{"black-refined-concrete",1,-4},{"purple-refined-concrete",1,-3},
{"purple-refined-concrete",1,-2},{"purple-refined-concrete",1,-1},{"purple-refined-concrete",1,0},{"purple-refined-concrete",1,1},
{"purple-refined-concrete",1,2},{"black-refined-concrete",1,3},{"black-refined-concrete",2,-3},{"purple-refined-concrete",2,-2},
{"purple-refined-concrete",2,-1},{"purple-refined-concrete",2,0},{"purple-refined-concrete",2,1},{"black-refined-concrete",2,2},
{"black-refined-concrete",3,-2},{"black-refined-concrete",3,-1},{"black-refined-concrete",3,0},{"black-refined-concrete",3,1}
}
}
}
26 changes: 20 additions & 6 deletions locale/en/gui.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,34 @@ invalid=Autofill set to maximum amount: __1__ __2__ for __3__
inserted=Inserted __1__ __2__ into __3__

[warp-list]
main-caption=Warp List
main-caption=Warp List [img=info]
main-tooltip=Warp List; Must be within __1__ tiles to use
sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles
too-close=Can't make warp; too close to warp: __1__
sub-tooltip=Warps can only be used every __1__ seconds and when within __2__ tiles\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__
sub-tooltip-current= - __1__ This is your current warp point;
sub-tooltip-connected= - __1__ You can travel to this warp point;
sub-tooltip-different= - __1__ This warp is on a different network;
sub-tooltip-cooldown= - __1__ You are currently on cooldown;
sub-tooltip-not_available= - __1__ You are not in range of a warp point;
sub-tooltip-bypass= - __1__ Your role allows you to travel here;
too-close=Cannot create warp; too close to existing warp point: __1__
too-close-to-water=Cannot create warp; too close to water, please move __1__ tiles away from the water body or landfill it
too-close-to-entities=Cannot create warp; too close to other entities, please move __1__ tiles away from the entities or remove them
last-edit=Last edited by __1__ at __2__\nClick to view on map
add-tooltip=Add new warp
confirm-tooltip=Save changes
cancel-tooltip=Discard changes
edit-tooltip=Currently being edited by: __1__
edit-tooltip-none=Currently being edited by: Nobody
discard-tooltip=Remove warp
timer-tooltip=Warp cooldown takes __1__ seconds
remove-tooltip=Remove warp
timer-tooltip=Please wait __1__ seconds before you can warp
timer-tooltip-zero=After each warp you will need to wait __1__ seconds before you can warp again
goto-tooltip=Go to x __1__ y __2__
goto-disabled=You must be on a warp point and have a full charge to warp
goto-bypass=Go to x __1__ y __2__, bypass mode
goto-bypass-different-network=Go to x __1__ y __2__, bypass mode different network
goto-same-warp=You are already on this warp
goto-different-network=This warp is on a different network, use power poles to connect it
goto-cooldown=You are on cooldown, wait for your cooldown to recharge
goto-disabled=You are not on a warp point, walk to a warp point
goto-edit=Edit warp icon

[readme]
Expand Down
77 changes: 39 additions & 38 deletions modules/control/warps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ Global.register(force_warps, function(tbl)
force_warps = tbl
end)

-- When a warp is updated change its chat tag and resort the warp order
-- Create an array of entity names that will be added to the remove filter
local remove_warp_area_entity_names = {}
for _, entity in pairs(config.entities) do
table.insert(remove_warp_area_entity_names, entity[1])
end

-- When a warp is updated change its chat tag and restore the warp order
WrapData:on_update(function(warp_id, warp, old_warp)
if warp then
warp.updates = warp.updates + 1
-- Update the map chart tag if there is one
if warp.tag then
Warps.make_warp_tag(warp_id)
Expand Down Expand Up @@ -148,31 +155,15 @@ function Warps.make_warp_area(warp_id)
local position = warp.position
local posx = position.x
local posy = position.y
local radius = config.standard_proximity_radius
local radius2 = radius^2

-- Get the tile that is being replaced, store.update not needed as we dont want it to trigger
-- Get the tile that is being replaced, store.update not needed as we don't want it to trigger
local old_tile = surface.get_tile(position).name
warp.old_tile = old_tile

-- Make a circle that acts as a base for the warp structure
local base_tile = config.base_tile
local base_tiles = {}
for x = -radius, radius do
local x2 = x^2
for y = -radius, radius do
local y2 = y^2
if x2+y2 < radius2 then
table.insert(base_tiles, {name=base_tile, position={x+posx, y+posy}})
end
end
end
surface.set_tiles(base_tiles)

-- Add a tile pattern on top of the base
local tiles = {}
for _, pos in pairs(config.tiles) do
table.insert(tiles, {name=base_tile, position={pos[1]+posx, pos[2]+posy}})
for _, tile in pairs(config.tiles) do
table.insert(tiles, {name=tile[1], position={tile[2]+posx, tile[3]+posy}})
end
surface.set_tiles(tiles)

Expand All @@ -187,6 +178,11 @@ function Warps.make_warp_area(warp_id)
entity.health = 0
entity.minable = false
entity.rotatable = false

-- Save reference of the last power pole
if entity.type == 'electric-pole' then
warp.electric_pole = entity
end
end
end

Expand All @@ -202,22 +198,15 @@ function Warps.remove_warp_area(warp_id)
local position = warp.position
local surface = warp.surface
local radius = config.standard_proximity_radius
local radius2 = radius^2

-- Check that a warp area was created previously
local base_tile = warp.old_tile
if not base_tile then return end
local old_tile = warp.old_tile
if not old_tile then return end

-- Reset all the tiles that were replaced
-- Restore the original tiles before the creation of the warp
local tiles = {}
for x = -radius, radius do
local x2 = x^2
for y = -radius, radius do
local y2 = y^2
if x2+y2 < radius2 then
table.insert(tiles, {name=base_tile, position={x+position.x, y+position.y}})
end
end
for _, tile in pairs(config.tiles) do
table.insert(tiles, {name=old_tile, position={tile[2]+position.x, tile[3]+position.y}})
end
surface.set_tiles(tiles)

Expand All @@ -226,11 +215,17 @@ function Warps.remove_warp_area(warp_id)
{position.x+radius, position.y+radius}
}

-- Remove all the entities that are in the area
local entities = surface.find_entities_filtered{ force='neutral', area=area }
for _, entity in pairs(entities) do if entity and entity.valid and entity.name ~= 'player' then entity.destroy() end end
-- Remove warp structure entities
local entities = surface.find_entities_filtered{ force='neutral', area=area, name = remove_warp_area_entity_names }
for _, entity in pairs(entities) do
-- Destroy them, this will leave corpses of the entities that it destroyed.
if entity and entity.valid and entity.destructible == false then
entity.destructible = true
entity.die(entity.force)
end
end

-- Rechart map area, usefull if warp is not covered by a radar
-- Rechart map area, useful if warp is not covered by a radar
game.forces[warp.force_name].chart(surface, area)
end

Expand Down Expand Up @@ -351,7 +346,8 @@ function Warps.add_warp(force_name, surface, position, player_name, warp_name)
},
last_edit_name = player_name or '<server>',
last_edit_time = game.tick,
currently_editing = editing
currently_editing = editing,
updates = 0,
})

return warp_id
Expand Down Expand Up @@ -385,6 +381,11 @@ Warps.update_warp(warp_id, 'My Warp', 'iron-plate', game.player.name)
]]
function Warps.update_warp(warp_id, new_name, new_icon, player_name)
WrapData:update(warp_id, function(_, warp)
-- If the icon is not valid then replace with the old icon
if new_icon and not new_icon.name or not new_icon.type then
new_icon = warp.icon
end

warp.last_edit_name = player_name or '<server>'
warp.last_edit_time = game.tick
warp.name = new_name or warp.name
Expand Down Expand Up @@ -476,4 +477,4 @@ function Warps.get_editing(warp_id, player_name)
end

-- Module return
return Warps
return Warps

0 comments on commit 8431b2e

Please sign in to comment.