Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Warps need to be connected to the same electricity network #190

Merged
merged 29 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8197b17
Working implementation
bbassie Nov 7, 2020
94cfceb
Fix electric pole name
bbassie Nov 8, 2020
90e025a
Warp-list changes:
bbassie Nov 8, 2020
bb5790a
Fix function name
bbassie Nov 8, 2020
c95616d
Fix network id checks
bbassie Nov 8, 2020
e851b48
Remove spawn debug message
bbassie Nov 8, 2020
84fda87
Changed warp area to fit the radius
bbassie Nov 8, 2020
1d980c6
Warp water check
bbassie Nov 8, 2020
ebfe24c
Removed temp debug rendering
bbassie Nov 8, 2020
94fa2bc
Warp additions
bbassie Nov 15, 2020
c308aa8
* If statement restructured like suggested, seems to work fine;
bbassie Nov 17, 2020
d0afee7
Color status to icon status
bbassie Jan 23, 2021
8b717ee
Warp improvements
bbassie Jan 24, 2021
7e7660f
Add tooltip to icon for better accessibility
bbassie Jan 24, 2021
290ec4f
Bumped lua action to v8
Cooldude2606 Jan 24, 2021
a7b1d33
Bumped luarocks action to v4
Cooldude2606 Jan 24, 2021
ca8d033
Removed one use variable
bbassie Jan 24, 2021
e72f927
Fixes to warp module
bbassie Jan 24, 2021
b84dad6
Fixes to warp-list gui
bbassie Jan 24, 2021
2fc598f
Merge branch 'feature/warp-net-id' of https://github.com/bbassie/scen…
bbassie Jan 24, 2021
cd566c8
Implemented requested changes
bbassie Jan 26, 2021
90f650c
Implemented requested changes
bbassie Jan 26, 2021
8499572
Merge branch 'feature/warp-net-id' of https://github.com/bbassie/scen…
bbassie Jan 26, 2021
2fe9d56
Finishing touches:
bbassie Jan 29, 2021
d987a6c
Made requested locale changes
Cooldude2606 Mar 30, 2021
023e142
Apply suggestions from code review
Cooldude2606 Mar 30, 2021
cf612e6
Fixed warp cooldown not using seconds
Cooldude2606 Mar 30, 2021
ab590d0
Merge branch 'feature/warp-net-id' of github.com:bbassie/scenario int…
Cooldude2606 Mar 30, 2021
60bb28d
Chagned tooltips on buttons to match info tooltip
Cooldude2606 Mar 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
fetch-depth: 0

- name: Install Lua
uses: leafo/gh-actions-lua@v5
uses: leafo/gh-actions-lua@v8.0.0

- name: Install LuaRocks
uses: leafo/gh-actions-luarocks@v2
uses: leafo/gh-actions-luarocks@v4

- name: Install LDoc
run: luarocks install ldoc 1.4.4-1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
fetch-depth: 0

- name: Install Lua
uses: leafo/gh-actions-lua@v5
uses: leafo/gh-actions-lua@v8.0.0

- name: Install LuaRocks
uses: leafo/gh-actions-luarocks@v2
uses: leafo/gh-actions-luarocks@v4

- name: Install LDoc
run: luarocks install ldoc 1.4.4-1
Expand Down
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 @@ -93,20 +93,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;
Cooldude2606 marked this conversation as resolved.
Show resolved Hide resolved
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
Cooldude2606 marked this conversation as resolved.
Show resolved Hide resolved
-- 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 @@ -333,7 +328,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 @@ -367,6 +363,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 @@ -458,4 +459,4 @@ function Warps.get_editing(warp_id, player_name)
end

-- Module return
return Warps
return Warps
Loading