From 1d980c6d64b004d08bb1bcbb97b7c22314fc97ba Mon Sep 17 00:00:00 2001 From: bbassie Date: Sun, 8 Nov 2020 19:02:55 +0100 Subject: [PATCH] Warp water check --- locale/en/gui.cfg | 1 + modules/gui/warp-list.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index ca7750c4..18ffc672 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -97,6 +97,7 @@ main-caption=Warp List 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__ +too-close-to-water=Cannot create warp this close to water, please move __1__ tiles away from the water body last-edit=Last edited by __1__ at __2__\nClick to view on map add-tooltip=Add new warp confirm-tooltip=Save changes diff --git a/modules/gui/warp-list.lua b/modules/gui/warp-list.lua index f28308a0..a0ff2187 100644 --- a/modules/gui/warp-list.lua +++ b/modules/gui/warp-list.lua @@ -12,7 +12,7 @@ local Roles = require 'expcore.roles' --- @dep expcore.roles local Colors = require 'utils.color_presets' --- @dep utils.color_presets local config = require 'config.gui.warps' --- @dep config.gui.warps local Warps = require 'modules.control.warps' --- @dep modules.control.warps -local format_time = _C.format_time --- @dep expcore.common +local format_time, player_return = _C.format_time, _C.player_return --- @dep expcore.common --- Stores all data for the warp gui local WrapGuiData = Datastore.connect('WrapGuiData') @@ -80,6 +80,17 @@ Gui.element{ local force_name = player.force.name local surface = player.surface local position = player.position + + -- Check if the warp is too close to water + local water_tiles = surface.find_tiles_filtered{collision_mask = "water-tile", radius = config.standard_proximity_radius + 1, position = position, limit = 1} + if #water_tiles > 0 then + player_return({'expcore-commands.command-fail', {'warp-list.too-close-to-water', config.standard_proximity_radius + 1}}, 'orange_red', player) + local play_sound = 'utility/wire_pickup' + if game.player then game.player.play_sound{path=play_sound} end + return + end + + -- Create the warp local warp_id = Warps.add_warp(force_name, surface, position, player.name) Warps.make_warp_tag(warp_id) Warps.make_warp_area(warp_id)