diff --git a/maps/scrap_towny_ffa/building.lua b/maps/scrap_towny_ffa/building.lua index 52ffc7c0..dc87bc31 100644 --- a/maps/scrap_towny_ffa/building.lua +++ b/maps/scrap_towny_ffa/building.lua @@ -4,6 +4,7 @@ local math_floor = math.floor local table_insert = table.insert local table_size = table.size local ScenarioTable = require 'maps.scrap_towny_ffa.table' +local PvPShield = require 'maps.scrap_towny_ffa.pvp_shield' local town_zoning_entity_types = { "wall", "gate", "electric-pole", "ammo-turret", "electric-turret", "fluid-turret"} @@ -223,26 +224,19 @@ local function process_built_entities(event) local name = entity.name local surface = entity.surface local position = entity.position + local force local force_name if player_index ~= nil then local player = game.players[player_index] - if player ~= nil then - local force = player.force - if force ~= nil then - force_name = force.name - end - end + force = player.force + force_name = force.name else local robot = event.robot - if robot ~= nil then - local force = robot.force - if force ~= nil then - force_name = force.name - end - end + force = robot.force + force_name = force.name end - if Public.near_another_town(force_name, position, surface, 32) == true then + if PvPShield.in_other_zones(surface, position, force) or Public.near_another_town(force_name, position, surface, 32) == true then if neutral_whitelist[name] then entity.force = game.forces['neutral'] else @@ -335,6 +329,9 @@ local function on_player_built_tile(event) if prevent_landfill_in_restricted_zone(event) then return end + if process_built_entities(event) then + return + end if prevent_tiles_near_towns(event) then return end diff --git a/maps/scrap_towny_ffa/info.lua b/maps/scrap_towny_ffa/info.lua index 17576c64..7ae406e0 100644 --- a/maps/scrap_towny_ffa/info.lua +++ b/maps/scrap_towny_ffa/info.lua @@ -37,6 +37,9 @@ Survive as long as you can. Raid other towns. Defend your town. Tip: use filter inserters with to get coins/iron/.. out of the market - Fishes procreate near towns. The more fishes, the quicker they multiply. Automated fish farm, anyone? - Use /rename-town (chat command) to rename your town +- PvP shields prevent players from entering and building inside, but they can still shoot inside! +- Your town has a AFK PvP shield that you can use to safely take a quick break + without other players killing your town. Deploy it from the market. # Town members and alliances - Once a town is formed, members may invite other players and teams using a coin. To invite another player, drop a coin diff --git a/maps/scrap_towny_ffa/pvp_shield.lua b/maps/scrap_towny_ffa/pvp_shield.lua index 6232d333..24bc942a 100644 --- a/maps/scrap_towny_ffa/pvp_shield.lua +++ b/maps/scrap_towny_ffa/pvp_shield.lua @@ -33,7 +33,7 @@ local function remove_drawn_borders(shield) end end -local function scale_size_and_box(shield) +local function scale_size_by_lifetime(shield) local time_scale = math.min(1, (game.tick - shield.lifetime_start) / shield.time_to_full_size_ticks) local scaled_size = time_scale * shield.max_size @@ -63,7 +63,7 @@ function Public.add_shield(surface, force, center, max_size, lifetime_ticks, tim string.format("%.0f", (Public.remaining_lifetime(shield)) / 60 / 60) .. ' minutes') end - scale_size_and_box(shield) + scale_size_by_lifetime(shield) this.pvp_shields[force.name] = shield end @@ -89,7 +89,7 @@ local function update_shield_lifetime() if Public.remaining_lifetime(shield) > 0 then if shield.size < shield.max_size then remove_drawn_borders(shield) - scale_size_and_box(shield) + scale_size_by_lifetime(shield) draw_borders(shield) -- Push everyone out as we grow (even if they're just standing) @@ -107,6 +107,18 @@ local function vector_norm(vector) return math_sqrt(vector.x ^ 2 + vector.y ^ 2) end +function Public.in_other_zones(surface, position, force) + local this = ScenarioTable.get_table() + for _, shield in pairs(this.pvp_shields) do + if not (shield.force == force or surface ~= shield.surface) then + if CommonFunctions.point_in_bounding_box(position, shield.box) then + return true + end + end + end + return false +end + function Public.push_enemies_out(player) local this = ScenarioTable.get_table() for _, shield in pairs(this.pvp_shields) do diff --git a/maps/scrap_towny_ffa/town_center.lua b/maps/scrap_towny_ffa/town_center.lua index 98fbeb16..2a9ed419 100644 --- a/maps/scrap_towny_ffa/town_center.lua +++ b/maps/scrap_towny_ffa/town_center.lua @@ -419,7 +419,7 @@ local function add_pvp_shield_scaled(position, force, surface) force.print("Based on the highest tech on map, your town deploys a PvP shield of " .. string.format("%.0f", size) .. " tiles" .. " for " .. string.format("%.0f", lifetime_ticks/60/60) .. " minutes." - .. " Enemy players will not be able to enter the shielded area.") + .. " Enemy players will not be able to enter and build in the shielded area.") end local function found_town(event)