Test for warp distances

This commit is contained in:
Cooldude2606
2018-10-20 19:21:34 +01:00
parent b883fb6c41
commit a21903edf2
2 changed files with 8 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ local warp_tile = 'tutorial-grid'
local warp_limit = 60
local warp_item = 'discharge-defense-equipment'
local global_offset = {x=0,y=0}
local warp_min_distance = 25
-- Module Define
local _global = global
@@ -27,7 +28,7 @@ local module_verbose = false
local ThisModule = {
on_init=function(self)
if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^4.0.0') end
if loaded_modules['ExpGamingCore.Command@^4.0.0'] then require(module_path..'/src/commands',{self=self,warps=global}) end
if loaded_modules['ExpGamingCore.Command@^4.0.0'] then require(module_path..'/src/commands',{self=self,warps=global,warp_min_distance=warp_min_distance}) end
end
}

View File

@@ -1,3 +1,4 @@
local warp_min_distance = warp_min_distance^2
local warps = warps
local self = self
@@ -9,7 +10,11 @@ commands.add_command('make-warp', 'Make a warp point at your location', {
local name = args.name
if game.player.gui.top[name] then player_return({'WarpPoints.name-used'},defines.textcolor.med) return commands.error end
if warps.warps[name] then player_return({'WarpPoints.name-used'},defines.textcolor.med) return commands.error end
if position.x^2 + position.y^2 < 100 then player_return({'WarpPoints.too-close'},defines.textcolor.med) return commands.error end
for name,warp in pairs(warps.warps) do
local dx = position.x-warp.position.x
local dy = position.y-warp.position.y
if dx^2 + dy^2 < warp_min_distance then player_return({'WarpPoints.too-close'},defines.textcolor.med) return commands.error end
end
-- to do add a test for all warps
self.make_warp_point(position,game.player.surface,game.player.force,name)
end)