1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-07 15:11:02 +02:00

fish defender v2 - refactor

This commit is contained in:
Gerkiz 2021-11-26 13:48:49 +01:00
parent 04cabd81ad
commit 9a032f8115
19 changed files with 780 additions and 566 deletions

@ -1,14 +1,13 @@
local simplex_noise = require 'utils.simplex_noise'.d2
-- local map_data = require 'maps.fish_defender_v2.fish_defender_layout'
local map_data = require 'maps.fish_defender_v2.map'
local Public = require 'maps.fish_defender_v2.table'
local random = math.random
local abs = math.abs
local floor = math.floor
local scale = 1
local Public = {}
local tile_map = {
[1] = false,
[2] = true,
@ -171,11 +170,12 @@ function Public.make_chunk(event)
end
local surface = event.surface
local area = event.area
local x1 = event.area.left_top.x
local y1 = event.area.left_top.y
local x2 = event.area.right_bottom.x
local y2 = event.area.right_bottom.y
local x1 = area.left_top.x
local y1 = area.left_top.y
local x2 = area.right_bottom.x
local y2 = area.right_bottom.y
local seed = game.surfaces[1].map_gen_settings.seed

@ -1,7 +1,8 @@
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local random = math.random
local sqrt = math.sqrt
local boss_biter = {}
local math_random = math.random
local radius = 6
local targets = {}
local acid_splashes = {
@ -16,15 +17,15 @@ local acid_lines = {
}
for x = radius * -1, radius, 1 do
for y = radius * -1, radius, 1 do
if math.sqrt(x ^ 2 + y ^ 2) <= radius then
if sqrt(x ^ 2 + y ^ 2) <= radius then
targets[#targets + 1] = {x = x, y = y}
end
end
end
local function acid_nova(event)
for _ = 1, math.random(16, 32) do
local i = math.random(1, #targets)
for _ = 1, random(16, 32) do
local i = random(1, #targets)
event.entity.surface.create_entity(
{
name = acid_splashes[event.entity.name],
@ -39,19 +40,19 @@ local function acid_nova(event)
end
end
boss_biter.died = function(event)
local acid_lines_delay = FDT.get('acid_lines_delay')
function Public.died(event)
local acid_lines_delay = Public.get('acid_lines_delay')
if acid_splashes[event.entity.name] then
acid_nova(event)
end
if acid_lines_delay[event.entity.unit_number] then
FDT.get('acid_lines_delay')[event.entity.unit_number] = nil
Public.get('acid_lines_delay')[event.entity.unit_number] = nil
end
FDT.get('boss_biters')[event.entity.unit_number] = nil
Public.get('boss_biters')[event.entity.unit_number] = nil
end
local function acid_line(surface, name, source, target)
local distance = math.sqrt((source.x - target.x) ^ 2 + (source.y - target.y) ^ 2)
local distance = sqrt((source.x - target.x) ^ 2 + (source.y - target.y) ^ 2)
if distance > 16 then
return false
@ -62,7 +63,7 @@ local function acid_line(surface, name, source, target)
local position = {source.x, source.y}
for i = 1, distance + 4, 1 do
if math_random(1, 3) == 1 then
if random(1, 3) == 1 then
surface.create_entity(
{
name = name,
@ -81,19 +82,22 @@ local function acid_line(surface, name, source, target)
return true
end
boss_biter.damaged_entity = function(event)
if acid_lines[event.cause.name] then
local acid_lines_delay = FDT.get('acid_lines_delay')
if not acid_lines_delay[event.cause.unit_number] then
FDT.set('acid_lines_delay')[event.cause.unit_number] = 0
function Public.damaged_entity(event)
local entity = event.entity
local cause = event.cause
if acid_lines[cause.name] then
local acid_lines_delay = Public.get('acid_lines_delay')
if not acid_lines_delay[cause.unit_number] then
Public.set('acid_lines_delay')[cause.unit_number] = 0
end
if acid_lines_delay[event.cause.unit_number] < game.tick then
if acid_line(event.cause.surface, acid_lines[event.cause.name], event.cause.position, event.entity.position) then
FDT.set('acid_lines_delay')[event.cause.unit_number] = game.tick + 180
if acid_lines_delay[cause.unit_number] < game.tick then
if acid_line(cause.surface, acid_lines[cause.name], cause.position, entity.position) then
Public.set('acid_lines_delay')[cause.unit_number] = game.tick + 180
end
end
end
end
return boss_biter
return Public

@ -1,5 +1,7 @@
local Public = require 'maps.fish_defender_v2.table'
local radius = 9
local math_random = math.random
local random = math.random
local ammo_to_projectile_translation = {
['shotgun-shell'] = 'shotgun-pellet',
@ -21,7 +23,7 @@ local function create_projectile(surface, position, target, name)
end
local function bounce(surface, position, ammo)
if math_random(1, 3) ~= 1 then
if random(1, 3) ~= 1 then
return
end
local valid_entities = {}
@ -40,25 +42,26 @@ local function bounce(surface, position, ammo)
return
end
for _ = 1, math_random(3, 6), 1 do
create_projectile(surface, position, valid_entities[math_random(1, #valid_entities)].position, ammo)
for _ = 1, random(3, 6), 1 do
create_projectile(surface, position, valid_entities[random(1, #valid_entities)].position, ammo)
end
end
local function bouncy_shells(event)
if event.damage_type.name ~= 'physical' then
function Public.bouncy_shells(event)
local damage_type = event.damage_type
if damage_type.name ~= 'physical' then
return false
end
local player = event.cause
if player.shooting_state.state == defines.shooting.not_shooting then
local cause = event.cause
if cause.shooting_state.state == defines.shooting.not_shooting then
return false
end
local selected_weapon = player.get_inventory(defines.inventory.character_guns)[player.selected_gun_index]
local selected_weapon = cause.get_inventory(defines.inventory.character_guns)[cause.selected_gun_index]
if selected_weapon.name ~= 'combat-shotgun' and selected_weapon.name ~= 'shotgun' then
return false
end
local selected_ammo = player.get_inventory(defines.inventory.character_ammo)[player.selected_gun_index]
local selected_ammo = cause.get_inventory(defines.inventory.character_ammo)[cause.selected_gun_index]
if not selected_ammo then
return
end
@ -66,7 +69,7 @@ local function bouncy_shells(event)
return
end
bounce(player.surface, event.entity.position, ammo_to_projectile_translation[selected_ammo.name])
bounce(cause.surface, event.entity.position, ammo_to_projectile_translation[selected_ammo.name])
end
return bouncy_shells
return Public

@ -0,0 +1,58 @@
local Event = require 'utils.event'
local Public = require 'maps.fish_defender_v2.table'
local function protect_market(entity, cause, final_damage_amount)
if entity.name ~= 'market' then
return
end
if cause then
if cause.force.name == 'enemy' then
return
end
end
entity.health = entity.health + final_damage_amount
return true
end
Event.add(
defines.events.on_entity_damaged,
function(event)
local entity = event.entity
local cause = event.cause
local final_damage_amount = event.final_damage_amount
if not entity then
return
end
if not entity.valid then
return
end
if protect_market(entity, cause, final_damage_amount) then
return
end
if not cause then
return
end
local explosive_bullets_unlocked = Public.get('explosive_bullets_unlocked')
local bouncy_shells_unlocked = Public.get('bouncy_shells_unlocked')
if cause.name ~= 'character' then
return
end
if explosive_bullets_unlocked then
if Public.explosive_bullets(event) then
return
end
end
if bouncy_shells_unlocked then
if Public.bouncy_shells(event) then
return
end
end
end
)
return Public

@ -1,5 +1,5 @@
local Server = require 'utils.server'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
@ -30,7 +30,7 @@ commands.add_command(
::continue::
local this = FDT.get()
local this = Public.get()
local reset_map = require 'maps.fish_defender_v2.main'.reset_game
if not this.reset_are_you_sure then
@ -103,13 +103,15 @@ commands.add_command(
end
end
local stop_generating_map = FDT.get('stop_generating_map')
local stop_generating_map = Public.get('stop_generating_map')
if not stop_generating_map then
FDT.set('stop_generating_map', true)
Public.set('stop_generating_map', true)
player.print('Stopped generating the map!')
else
FDT.set('stop_generating_map', false)
Public.set('stop_generating_map', false)
player.print('Resumed the generation of map!')
end
end
)
return Public

@ -0,0 +1,19 @@
local Public = require 'maps.fish_defender_v2.table'
Public[#Public + 1] = require 'maps.fish_defender_v2.b'
Public[#Public + 1] = require 'maps.fish_defender_v2.boss_biters'
Public[#Public + 1] = require 'maps.fish_defender_v2.bouncy_shells'
Public[#Public + 1] = require 'maps.fish_defender_v2.commands'
Public[#Public + 1] = require 'maps.fish_defender_v2.check_damaged'
Public[#Public + 1] = require 'maps.fish_defender_v2.crumbly_walls'
Public[#Public + 1] = require 'maps.fish_defender_v2.explosive_gun_bullets'
Public[#Public + 1] = require 'maps.fish_defender_v2.flame_boots'
Public[#Public + 1] = require 'maps.fish_defender_v2.laser_pointer'
Public[#Public + 1] = require 'maps.fish_defender_v2.market'
Public[#Public + 1] = require 'maps.fish_defender_v2.shotgun_buff'
Public[#Public + 1] = require 'maps.fish_defender_v2.terrain'
Public[#Public + 1] = require 'maps.fish_defender_v2.trapped_capsules'
Public[#Public + 1] = require 'maps.fish_defender_v2.ultra_mines'
Public[#Public + 1] = require 'maps.fish_defender_v2.vehicle_nanobots'
return Public

@ -1,11 +1,11 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local math_random = math.random
local Public = require 'maps.fish_defender_v2.table'
local random = math.random
local rock_raffle = {'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'}
local function on_entity_died(event)
local crumbly_walls_unlocked = FDT.get('crumbly_walls_unlocked')
local crumbly_walls_unlocked = Public.get('crumbly_walls_unlocked')
if not crumbly_walls_unlocked then
return
end
@ -16,10 +16,12 @@ local function on_entity_died(event)
if entity.name ~= 'stone-wall' then
return
end
if math_random(1, 4) == 1 then
if random(1, 4) == 1 then
return
end
entity.surface.create_entity({name = rock_raffle[math_random(1, #rock_raffle)], position = entity.position, force = 'player'})
entity.surface.create_entity({name = rock_raffle[random(1, #rock_raffle)], position = entity.position, force = 'player'})
end
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

@ -1,14 +1,18 @@
local Public = require 'maps.fish_defender_v2.table'
local radius = 3
local random = math.random
local floor = math.floor
local sqrt = math.sqrt
local function splash_damage(surface, position, final_damage_amount)
local damage = math.random(math.floor(final_damage_amount * 3), math.floor(final_damage_amount * 4))
local damage = random(floor(final_damage_amount * 3), floor(final_damage_amount * 4))
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - radius, position.y - radius}, {position.x + radius, position.y + radius}}})) do
if e.valid and e.health then
local distance_from_center = math.sqrt((e.position.x - position.x) ^ 2 + (e.position.y - position.y) ^ 2)
local distance_from_center = sqrt((e.position.x - position.x) ^ 2 + (e.position.y - position.y) ^ 2)
if distance_from_center <= radius then
local damage_distance_modifier = 1 - distance_from_center / radius
if damage > 0 then
if math.random(1, 3) == 1 then
if random(1, 3) == 1 then
surface.create_entity({name = 'explosion', position = e.position})
end
e.damage(damage * damage_distance_modifier, 'player', 'explosion')
@ -18,25 +22,28 @@ local function splash_damage(surface, position, final_damage_amount)
end
end
local function explosive_bullets(event)
if math.random(1, 3) ~= 1 then
function Public.explosive_bullets(event)
if random(1, 3) ~= 1 then
return false
end
if event.damage_type.name ~= 'physical' then
local damage_type = event.damage_type
if damage_type.name ~= 'physical' then
return false
end
local player = event.cause
if player.shooting_state.state == defines.shooting.not_shooting then
local cause = event.cause
local entity = event.entity
if cause.shooting_state.state == defines.shooting.not_shooting then
return false
end
local selected_weapon = player.get_inventory(defines.inventory.character_guns)[player.selected_gun_index]
local selected_weapon = cause.get_inventory(defines.inventory.character_guns)[cause.selected_gun_index]
if selected_weapon.name ~= 'submachine-gun' and selected_weapon.name ~= 'pistol' then
return false
end
player.surface.create_entity({name = 'explosion', position = event.entity.position})
cause.surface.create_entity({name = 'explosion', position = entity.position})
splash_damage(player.surface, event.entity.position, event.final_damage_amount)
splash_damage(cause.surface, entity.position, event.final_damage_amount)
end
return explosive_bullets
return Public

@ -1,15 +1,20 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local function on_player_changed_position(event)
local flame_boots = FDT.get('flame_boots')
local flame_boots = Public.get('flame_boots')
if not flame_boots then
return
end
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if not (player and player.valid) then
return
end
if not player.character then
return
end
if player.character.driving then
return
end
@ -50,3 +55,5 @@ local function on_player_changed_position(event)
end
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
return Public

@ -1,14 +1,14 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local radius = 32
local function on_player_used_capsule(event)
local laser_pointer_unlocked = FDT.get('laser_pointer_unlocked')
local laser_pointer_unlocked = Public.get('laser_pointer_unlocked')
if not laser_pointer_unlocked then
return
end
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local position = event.position
local used_item = event.item
if used_item.name ~= 'artillery-targeting-remote' then
@ -35,3 +35,5 @@ local function on_player_used_capsule(event)
end
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
return Public

@ -2,16 +2,11 @@
--require "modules.rpg"
require 'maps.fish_defender_v2.terrain'
require 'maps.fish_defender_v2.market'
require 'maps.fish_defender_v2.commands'
require 'maps.fish_defender_v2.shotgun_buff'
require 'maps.fish_defender_v2.on_entity_damaged'
local Public = require 'maps.fish_defender_v2.core'
require 'modules.rocket_launch_always_yields_science'
require 'modules.launch_fish_to_win'
require 'modules.biters_yield_coins'
require 'modules.custom_death_messages'
local Unit_health_booster = require 'modules.biter_health_booster_v2'
local Difficulty = require 'modules.difficulty_vote'
local Map = require 'modules.map_info'
@ -20,18 +15,14 @@ local Reset = require 'functions.soft_reset'
local Server = require 'utils.server'
local Session = require 'utils.datastore.session_data'
local Poll = require 'comfy_panel.poll'
local boss_biter = require 'maps.fish_defender_v2.boss_biters'
local FDT = require 'maps.fish_defender_v2.table'
local Score = require 'comfy_panel.score'
local AntiGrief = require 'antigrief'
local Core = require 'utils.core'
local format_number = require 'util'.format_number
local math_random = math.random
local random = math.random
local insert = table.insert
local enable_start_grace_period = true
local Public = {}
local starting_items = {
['pistol'] = 1,
['firearm-magazine'] = 20,
@ -40,6 +31,52 @@ local starting_items = {
['stone'] = 20
}
local threat_values = {
['small_biter'] = 1,
['medium_biter'] = 3,
['big_biter'] = 5,
['behemoth_biter'] = 10,
['small_spitter'] = 1,
['medium_spitter'] = 3,
['big_spitter'] = 5,
['behemoth_spitter'] = 10
}
local attack_group_count_thresholds = {
{0, 1},
{50, 2},
{100, 3},
{150, 4},
{200, 5},
{1000, 6},
{2000, 7},
{3000, 8}
}
local biter_splash_damage = {
['medium-biter'] = {
visuals = {'blood-explosion-big', 'big-explosion'},
radius = 1.5,
damage_min = 50,
damage_max = 100,
chance = 32
},
['big-biter'] = {
visuals = {'blood-explosion-huge', 'ground-explosion'},
radius = 2,
damage_min = 75,
damage_max = 150,
chance = 48
},
['behemoth-biter'] = {
visuals = {'blood-explosion-huge', 'big-artillery-explosion'},
radius = 2.5,
damage_min = 100,
damage_max = 200,
chance = 64
}
}
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
@ -52,13 +89,13 @@ end
local biter_count_limit = 1024 --maximum biters on the east side of the map, next wave will be delayed if the maximum has been reached
local function check_timer()
local wave_grace_period = FDT.get('wave_grace_period')
local wave_grace_period = Public.get('wave_grace_period')
if not wave_grace_period then
return
end
if wave_grace_period < game.tick then
FDT.set('wave_grace_period', 72000)
Public.set('wave_grace_period', 72000)
end
end
@ -70,12 +107,12 @@ local function create_wave_gui(player)
frame.style.maximal_height = 38
local wave_count = 0
local wave_count_fdt = FDT.get('wave_count')
local wave_grace_period = FDT.get('wave_grace_period')
local wave_interval = FDT.get('wave_interval')
local wave_count_public = Public.get('wave_count')
local wave_grace_period = Public.get('wave_grace_period')
local wave_interval = Public.get('wave_interval')
if wave_count_fdt then
wave_count = wave_count_fdt
if wave_count_public then
wave_count = wave_count_public
end
if not wave_grace_period then
@ -98,7 +135,7 @@ local function create_wave_gui(player)
else
local time_remaining = math.floor(((wave_grace_period - (game.tick % wave_grace_period)) / 60) / 60)
if time_remaining <= 0 then
FDT.set('wave_grace_period', nil)
Public.set('wave_grace_period', nil)
return
else
check_timer()
@ -112,7 +149,7 @@ local function create_wave_gui(player)
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
if not enable_start_grace_period then
FDT.set('wave_grace_period', nil)
Public.set('wave_grace_period', nil)
return
end
end
@ -138,7 +175,7 @@ local function show_fd_stats(player)
column_count = 2
}
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
local table_header = {'Building', 'Placed' .. '/' .. 'Limit'}
for k, v in pairs(table_header) do
@ -182,13 +219,14 @@ local function add_fd_stats_button(player)
end
local function on_gui_click(event)
if not event.element.valid then
local element = event.element
if not element.valid then
return
end
if event.element.name ~= 'fd-stats-button' then
if element.name ~= 'fd-stats-button' then
return
end
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local frame = player.gui.left['fd-stats']
if frame == nil then
show_fd_stats(player)
@ -201,19 +239,8 @@ local function on_market_item_purchased()
update_fd_stats()
end
local threat_values = {
['small_biter'] = 1,
['medium_biter'] = 3,
['big_biter'] = 5,
['behemoth_biter'] = 10,
['small_spitter'] = 1,
['medium_spitter'] = 3,
['big_spitter'] = 5,
['behemoth_spitter'] = 10
}
local function get_biter_initial_pool()
local wave_count = FDT.get('wave_count')
local wave_count = Public.get('wave_count')
local biter_pool
if wave_count > 1750 then
biter_pool = {
@ -360,7 +387,7 @@ local function fish_eye(surface, position)
end
end
print('Fish Eye created.')
FDT.set('fish_eye', true)
Public.set('fish_eye', true)
end
local function get_biter_pool()
@ -375,11 +402,11 @@ local function get_biter_pool()
end
local function spawn_biter(pos, biter_pool)
local attack_wave_threat = FDT.get('attack_wave_threat')
local attack_wave_threat = Public.get('attack_wave_threat')
if attack_wave_threat < 1 then
return false
end
local active_surface_index = FDT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not surface or not surface.valid then
@ -387,7 +414,7 @@ local function spawn_biter(pos, biter_pool)
end
biter_pool = shuffle(biter_pool)
FDT.set('attack_wave_threat', attack_wave_threat - biter_pool[1].threat)
Public.set('attack_wave_threat', attack_wave_threat - biter_pool[1].threat)
local valid_pos = surface.find_non_colliding_position(biter_pool[1].name, pos, 100, 2)
local biter = surface.create_entity({name = biter_pool[1].name, position = valid_pos})
biter.ai_settings.allow_destroy_when_commands_fail = false
@ -404,20 +431,9 @@ local function get_y_coord_raffle_table()
return t
end
local attack_group_count_thresholds = {
{0, 1},
{50, 2},
{100, 3},
{150, 4},
{200, 5},
{1000, 6},
{2000, 7},
{3000, 8}
}
local function get_number_of_attack_groups()
local n = 1
local wave_count = FDT.get('wave_count')
local wave_count = Public.get('wave_count')
for _, entry in pairs(attack_group_count_thresholds) do
if wave_count >= entry[1] then
n = entry[2]
@ -427,7 +443,7 @@ local function get_number_of_attack_groups()
end
local function clear_corpses(surface)
local wave_count = FDT.get('wave_count')
local wave_count = Public.get('wave_count')
if not wave_count then
return
@ -442,7 +458,7 @@ local function clear_corpses(surface)
local area = {{-137, -256}, {160, 256}}
for _, entity in pairs(surface.find_entities_filtered {area = area, type = 'corpse'}) do
if math_random(1, chance) == 1 then
if random(1, chance) == 1 then
entity.destroy()
end
end
@ -450,7 +466,7 @@ end
local function send_unit_group(unit_group)
local commands = {}
local market = FDT.get('market')
local market = Public.get('market')
if not (market and market.valid) then
return
end
@ -487,14 +503,14 @@ local function send_unit_group(unit_group)
end
local function spawn_boss_units(surface)
local wave_count = FDT.get('wave_count')
local wave_count = Public.get('wave_count')
if wave_count <= 2000 then
game.print({'fish_defender_v2.boss_message', wave_count, {'fish_defender_v2.' .. wave_count}}, {r = 0.8, g = 0.1, b = 0.1})
else
game.print({'fish_defender_v2.boss_message', wave_count}, {r = 0.8, g = 0.1, b = 0.1})
end
local boss_waves = FDT.get('boss_waves')
local boss_waves = Public.get('boss_waves')
if not boss_waves[wave_count] then
local amount = wave_count
@ -507,13 +523,13 @@ local function spawn_boss_units(surface)
}
end
local health_factor = FDT.get_current_difficulty_boss_modifier()
local health_factor = Public.get_current_difficulty_boss_modifier()
if wave_count == 100 then
health_factor = health_factor * 2
end
local biter_health_boost = Unit_health_booster.get('biter_health_boost')
local boss_biters = FDT.get('boss_biters')
local boss_biters = Public.get('boss_biters')
local position = {x = 216, y = 0}
local biter_group = surface.create_unit_group({position = position})
@ -535,7 +551,7 @@ local function spawn_boss_units(surface)
end
local function wake_up_the_biters(surface)
local market = FDT.get('market')
local market = Public.get('market')
if not (market and market.valid) then
return
end
@ -593,16 +609,16 @@ end
local function biter_attack_wave()
local Diff = Difficulty.get()
local market = FDT.get('market')
local market = Public.get('market')
if not market or not market.valid then
return
end
local wave_grace_period = FDT.get('wave_grace_period')
local wave_grace_period = Public.get('wave_grace_period')
if wave_grace_period then
return
end
local active_surface_index = FDT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not surface or not surface.valid then
return
@ -615,18 +631,18 @@ local function biter_attack_wave()
--game.print("Biter limit reached, wave delayed.", {r = 0.7, g = 0.1, b = 0.1})
return
end
local wave_count = FDT.get('wave_count')
local wave_count = Public.get('wave_count')
if not wave_count then
FDT.set('wave_count', 1)
Public.set('wave_count', 1)
else
FDT.set('wave_count', wave_count + 1)
Public.set('wave_count', wave_count + 1)
end
wave_count = FDT.get('wave_count')
wave_count = Public.get('wave_count')
local m = 0.0015
if Diff.difficulty_vote_index then
m = m * FDT.get_current_difficulty_strength_modifier()
m = m * Public.get_current_difficulty_strength_modifier()
end
game.forces.enemy.set_ammo_damage_modifier('melee', wave_count * m)
@ -644,20 +660,20 @@ local function biter_attack_wave()
m = 4
if Diff.difficulty_vote_index then
m = m * FDT.get_current_difficulty_amount_modifier()
m = m * Public.get_current_difficulty_amount_modifier()
end
if wave_count % 50 == 0 then
local attack_wave_threat = FDT.set('attack_wave_threat', math.floor(wave_count * (m * 1.5)))
local attack_wave_threat = Public.set('attack_wave_threat', math.floor(wave_count * (m * 1.5)))
spawn_boss_units(surface)
if attack_wave_threat > 10000 then
FDT.set('attack_wave_threat', 10000)
Public.set('attack_wave_threat', 10000)
end
else
local attack_wave_threat = FDT.set('attack_wave_threat', math.floor(wave_count * m))
FDT.set('attack_wave_threat', math.floor(wave_count * m))
local attack_wave_threat = Public.set('attack_wave_threat', math.floor(wave_count * m))
Public.set('attack_wave_threat', math.floor(wave_count * m))
if attack_wave_threat > 10000 then
FDT.set('attack_wave_threat', 10000)
Public.set('attack_wave_threat', 10000)
end
end
@ -670,7 +686,7 @@ local function biter_attack_wave()
local y_raffle = get_y_coord_raffle_table()
local unit_groups = {}
if wave_count > 50 and math_random(1, 8) == 1 then
if wave_count > 50 and random(1, 8) == 1 then
for i = 1, 10, 1 do
unit_groups[i] = surface.create_unit_group({position = {x = 300, y = y_raffle[i]}})
end
@ -682,7 +698,7 @@ local function biter_attack_wave()
local biter_pool = get_biter_pool()
while FDT.get('attack_wave_threat') > 0 do
while Public.get('attack_wave_threat') > 0 do
for i = 1, #unit_groups, 1 do
local biter = spawn_biter(unit_groups[i].position, biter_pool)
if biter then
@ -760,12 +776,15 @@ local function get_mvps()
end
local function is_game_lost()
local game_has_ended = FDT.get('game_has_ended')
local game_has_ended = Public.get('game_has_ended')
if not game_has_ended then
return
end
for _, player in pairs(game.connected_players) do
local players = game.connected_players
for i = 1, #players do
local player = players[i]
if player.gui.left['fish_defense_game_lost'] then
return
end
@ -788,7 +807,7 @@ local function is_game_lost()
local market_age_label
local market_age = FDT.get('market_age')
local market_age = Public.get('market_age')
if not market_age then
return
end
@ -814,7 +833,7 @@ local function is_game_lost()
local mvp = get_mvps()
if mvp then
local time_played = Core.format_time(game.ticks_played)
local wave = FDT.get('wave_count')
local wave = Public.get('wave_count')
local mvp_defender_label = t.add({type = 'label', caption = 'MVP Defender >> '})
mvp_defender_label.style.font = 'default-listbox'
@ -854,7 +873,7 @@ local function is_game_lost()
wave_lasted_name_label.style.font = 'default-bold'
wave_lasted_name_label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local results_sent = FDT.get('results_sent')
local results_sent = Public.get('results_sent')
if not results_sent then
local result = {}
insert(result, 'MVP Defender: \\n')
@ -873,19 +892,20 @@ local function is_game_lost()
insert(result, tonumber(format_number(wave, true)))
local message = table.concat(result)
Server.to_discord_embed(message)
FDT.set('results_sent', true)
Public.set('results_sent', true)
end
end
player.play_sound {path = 'utility/game_lost', volume_modifier = 0.75}
end
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_distance = 15
game.map_settings.enemy_expansion.settler_group_min_size = 15
game.map_settings.enemy_expansion.settler_group_max_size = 30
game.map_settings.enemy_expansion.min_expansion_cooldown = 600
game.map_settings.enemy_expansion.max_expansion_cooldown = 600
local map_settings = game.map_settings
map_settings.enemy_expansion.enabled = true
map_settings.enemy_expansion.max_expansion_distance = 15
map_settings.enemy_expansion.settler_group_min_size = 15
map_settings.enemy_expansion.settler_group_max_size = 30
map_settings.enemy_expansion.min_expansion_cooldown = 600
map_settings.enemy_expansion.max_expansion_cooldown = 600
end
local function damage_entities_in_radius(surface, position, radius, damage)
@ -909,13 +929,13 @@ local function damage_entities_in_radius(surface, position, radius, damage)
end
local function market_kill_visuals()
local active_surface_index = FDT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not (surface and surface.valid) then
return
end
local market = FDT.get('market')
local market = Public.get('market')
if not (market and market.valid) then
return
end
@ -937,7 +957,7 @@ local function market_kill_visuals()
for x = -5, 5, 0.5 do
for y = -5, 5, 0.5 do
if math_random(1, 2) == 1 then
if random(1, 2) == 1 then
surface.create_trivial_smoke(
{
name = 'smoke-fast',
@ -945,7 +965,7 @@ local function market_kill_visuals()
}
)
end
if math_random(1, 3) == 1 then
if random(1, 3) == 1 then
surface.create_trivial_smoke(
{
name = 'train-smoke',
@ -958,63 +978,39 @@ local function market_kill_visuals()
surface.spill_item_stack(market.position, {name = 'raw-fish', count = 1024}, true)
end
local biter_splash_damage = {
['medium-biter'] = {
visuals = {'blood-explosion-big', 'big-explosion'},
radius = 1.5,
damage_min = 50,
damage_max = 100,
chance = 32
},
['big-biter'] = {
visuals = {'blood-explosion-huge', 'ground-explosion'},
radius = 2,
damage_min = 75,
damage_max = 150,
chance = 48
},
['behemoth-biter'] = {
visuals = {'blood-explosion-huge', 'big-artillery-explosion'},
radius = 2.5,
damage_min = 100,
damage_max = 200,
chance = 64
}
}
local function on_entity_died(event)
if not event.entity.valid then
return
end
local boss_biters = FDT.get('boss_biters')
local boss_biters = Public.get('boss_biters')
if event.entity.force.name == 'enemy' then
local surface = event.entity.surface
if boss_biters[event.entity.unit_number] then
boss_biter.died(event)
Public.died(event)
end
local splash = biter_splash_damage[event.entity.name]
if splash then
if math_random(1, splash.chance) == 1 then
if random(1, splash.chance) == 1 then
for _, visual in pairs(splash.visuals) do
surface.create_entity({name = visual, position = event.entity.position})
end
damage_entities_in_radius(surface, event.entity.position, splash.radius, math_random(splash.damage_min, splash.damage_max))
damage_entities_in_radius(surface, event.entity.position, splash.radius, random(splash.damage_min, splash.damage_max))
return
end
end
if event.entity.name == 'behemoth-biter' then
if math_random(1, 16) == 1 then
if random(1, 16) == 1 then
local p = surface.find_non_colliding_position('big-biter', event.entity.position, 3, 0.5)
if p then
surface.create_entity {name = 'big-biter', position = p}
end
end
for i = 1, math_random(1, 2), 1 do
for i = 1, random(1, 2), 1 do
local p = surface.find_non_colliding_position('medium-biter', event.entity.position, 3, 0.5)
if p then
surface.create_entity {name = 'medium-biter', position = p}
@ -1024,15 +1020,15 @@ local function on_entity_died(event)
return
end
local market = FDT.get('market')
local last_reset = FDT.get('last_reset')
local market = Public.get('market')
local last_reset = Public.get('last_reset')
if event.entity == market then
market_kill_visuals()
market.die()
FDT.set('market', nil)
FDT.set('market_age', game.tick - last_reset)
FDT.set('game_has_ended', true)
Public.set('market', nil)
Public.set('market_age', game.tick - last_reset)
Public.set('game_has_ended', true)
is_game_lost()
local name = Server.get_server_name()
local date = Server.get_start_time()
@ -1040,7 +1036,7 @@ local function on_entity_died(event)
return
end
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
if entity_limits[event.entity.name] then
entity_limits[event.entity.name].placed = entity_limits[event.entity.name].placed - 1
@ -1050,7 +1046,7 @@ end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
local active_surface_index = FDT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not surface or not surface.valid then
return
@ -1120,7 +1116,7 @@ local function on_built_entity(event)
if not entity.valid then
return
end
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
if entity_limits[entity.name] then
local surface = entity.surface
@ -1144,7 +1140,7 @@ local function on_built_entity(event)
color = {r = 0.82, g = 0.11, b = 0.11}
}
)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
player.insert({name = entity.name, count = 1})
if get_score then
if get_score[player.force.name] then
@ -1164,7 +1160,7 @@ local function on_robot_built_entity(event)
return
end
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
if entity_limits[entity.name] then
local surface = entity.surface
@ -1196,8 +1192,8 @@ local function on_robot_built_entity(event)
end
local function on_player_changed_position(event)
local player = game.players[event.player_index]
local active_surface_index = FDT.get('active_surface_index')
local player = game.get_player(event.player_index)
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not surface or not surface.valid then
return
@ -1217,7 +1213,7 @@ local function on_player_changed_position(event)
end
local function on_player_mined_entity(event)
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
if entity_limits[event.entity.name] then
entity_limits[event.entity.name].placed = entity_limits[event.entity.name].placed - 1
@ -1226,7 +1222,7 @@ local function on_player_mined_entity(event)
end
local function on_robot_mined_entity(event)
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
if entity_limits[event.entity.name] then
entity_limits[event.entity.name].placed = entity_limits[event.entity.name].placed - 1
@ -1239,12 +1235,12 @@ local function on_research_finished(event)
if research ~= 'tank' then
return
end
game.forces['player'].technologies['artillery'].researched = true
game.forces.player.technologies['artillery'].researched = true
game.forces.player.recipes['artillery-wagon'].enabled = false
end
local function on_player_respawned(event)
local market_age = FDT.get('market_age')
local market_age = Public.get('market_age')
if not market_age then
return
end
@ -1253,22 +1249,22 @@ local function on_player_respawned(event)
end
local function has_the_game_ended()
local market_age = FDT.get('market_age')
local market_age = Public.get('market_age')
if market_age then
local game_restart_timer = FDT.get('game_restart_timer')
local game_restart_timer = Public.get('game_restart_timer')
if not game_restart_timer then
FDT.set('game_restart_timer', 5400)
Public.set('game_restart_timer', 5400)
else
if game_restart_timer < 0 then
return
end
FDT.set('game_restart_timer', game_restart_timer - 30)
Public.set('game_restart_timer', game_restart_timer - 30)
end
game_restart_timer = FDT.get('game_restart_timer')
game_restart_timer = Public.get('game_restart_timer')
local cause_msg
local restart = FDT.get('restart')
local shutdown = FDT.get('shutdown')
local soft_reset = FDT.get('soft_reset')
local restart = Public.get('restart')
local shutdown = Public.get('shutdown')
local soft_reset = Public.get('soft_reset')
if restart then
cause_msg = 'restart'
elseif shutdown then
@ -1279,23 +1275,23 @@ local function has_the_game_ended()
if game_restart_timer % 1800 == 0 then
if game_restart_timer > 0 then
FDT.set('game_reset', true)
Public.set('game_reset', true)
game.print('Game will ' .. cause_msg .. ' in ' .. game_restart_timer / 60 .. ' seconds!', {r = 0.22, g = 0.88, b = 0.22})
end
if soft_reset and game_restart_timer == 0 then
FDT.set('game_reset_tick', nil)
Public.set('game_reset_tick', nil)
-- Server.start_scenario('Fish_Defender')
Public.reset_game()
return
end
local announced_message = FDT.get('announced_message')
local announced_message = Public.get('announced_message')
if restart and game_restart_timer == 0 then
if not announced_message then
game.print('Soft-reset is disabled. Server will restart!', {r = 0.22, g = 0.88, b = 0.22})
local message = 'Soft-reset is disabled. Server will restart!'
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
Server.start_scenario('Fish_Defender')
FDT.set('announced_message', true)
Public.set('announced_message', true)
return
end
end
@ -1305,7 +1301,7 @@ local function has_the_game_ended()
local message = 'Soft-reset is disabled. Server is shutting down!'
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
Server.stop_scenario()
FDT.set('announced_message', true)
Public.set('announced_message', true)
return
end
end
@ -1314,7 +1310,7 @@ local function has_the_game_ended()
end
function Public.reset_game()
FDT.reset_table()
Public.reset_table()
local get_score = Score.get_table()
Poll.reset()
@ -1322,14 +1318,14 @@ function Public.reset_game()
AntiGrief.reset_tables()
FDT.set('fish_eye_location', {x = -1667, y = -50})
Public.set('fish_eye_location', {x = -1667, y = -50})
game.speed = 1
global.fish_in_space = 0
get_score.score_table = {}
local wave_grace_period = FDT.get('wave_grace_period')
local wave_grace_period = Public.get('wave_grace_period')
if not wave_grace_period then
wave_grace_period = game.tick + 72000
end
@ -1397,8 +1393,8 @@ function Public.reset_game()
--}
local map_gen_settings = {}
map_gen_settings.seed = math_random(10000, 99999)
map_gen_settings.starting_area = 1
map_gen_settings.seed = random(10000, 99999)
map_gen_settings.starting_area = 0.1
--map_gen_settings.starting_points = spawn_poses
map_gen_settings.width = 4000
@ -1417,16 +1413,14 @@ function Public.reset_game()
['enemy-base'] = {frequency = 'none', size = 'none', richness = 'none'}
}
map_gen_settings.property_expression_names = {moisture = math_random(4, 7) * 0.1}
local active_surface_index = FDT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
if not active_surface_index then
FDT.set('active_surface_index', game.create_surface('fish_defender', map_gen_settings).index)
active_surface_index = FDT.get('active_surface_index')
Public.set('active_surface_index', game.create_surface('fish_defender', map_gen_settings).index)
active_surface_index = Public.get('active_surface_index')
else
FDT.set('active_surface_index', Reset.soft_reset_map(game.surfaces[active_surface_index], map_gen_settings, starting_items).index)
active_surface_index = FDT.get('active_surface_index')
Public.set('active_surface_index', Reset.soft_reset_map(game.surfaces[active_surface_index], map_gen_settings, starting_items).index)
active_surface_index = Public.get('active_surface_index')
end
local surface = game.surfaces[active_surface_index]
@ -1434,11 +1428,15 @@ function Public.reset_game()
return
end
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = {{-300, -256}, {300, 300}}})) do
surface.set_tiles({{name = Public.get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true)
end
Unit_health_booster.set_active_surface(surface.name)
Unit_health_booster.check_on_entity_died(true)
Unit_health_booster.acid_nova(true)
Unit_health_booster.boss_spawns_projectiles(true)
Unit_health_booster.set('biter_health_boost', 4)
Unit_health_booster.set('biter_health_boost', 2)
surface.peaceful_mode = false
@ -1556,7 +1554,7 @@ function Public.on_init()
end
local function on_tick()
local active_surface_index = FDT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not surface or not surface.valid then
return
@ -1564,7 +1562,7 @@ local function on_tick()
local tick = game.tick
if tick % 30 == 0 then
has_the_game_ended()
local market = FDT.get('market')
local market = Public.get('market')
if market and market.valid then
for _, player in pairs(game.connected_players) do
if surface.peaceful_mode == false then
@ -1575,12 +1573,12 @@ local function on_tick()
if tick % 180 == 0 then
if surface then
game.forces.player.chart(surface, {{-160, -130}, {160, 179}})
FDT.set('wave_interval', FDT.get_current_difficulty_wave_interval())
Public.set('wave_interval', Public.get_current_difficulty_wave_interval())
end
end
local wave_count = FDT.get('wave_count')
local wave_limit = FDT.get('wave_limit')
local wave_count = Public.get('wave_count')
local wave_limit = Public.get('wave_limit')
if wave_count >= wave_limit then
if market and market.valid then
@ -1589,14 +1587,14 @@ local function on_tick()
end
end
local spawn_area_generated = FDT.get('spawn_area_generated')
local fish = FDT.get('fish_eye')
local spawn_area_generated = Public.get('spawn_area_generated')
local fish = Public.get('fish_eye')
if spawn_area_generated and not fish then
fish_eye(surface, {x = -1667, y = -50})
end
end
local wave_interval = FDT.get('wave_interval')
local wave_interval = Public.get('wave_interval')
if tick % wave_interval == wave_interval - 1 then
if surface.peaceful_mode == true then

@ -1,12 +1,5 @@
require 'maps.fish_defender_v2.flame_boots'
require 'maps.fish_defender_v2.trapped_capsules'
require 'maps.fish_defender_v2.ultra_mines'
require 'maps.fish_defender_v2.crumbly_walls'
require 'maps.fish_defender_v2.vehicle_nanobots'
require 'maps.fish_defender_v2.laser_pointer'
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local slot_upgrade_offers = {
[1] = {'gun-turret', 'gun turret'},
@ -27,7 +20,7 @@ local special_descriptions = {
}
local function refresh_market_offers()
local market = FDT.get('market')
local market = Public.get('market')
if not market or not market.valid then
return
end
@ -38,7 +31,7 @@ local function refresh_market_offers()
end
end
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
local str1 = 'Gun Turret Slot for ' .. tostring(entity_limits['gun-turret'].limit * entity_limits['gun-turret'].slot_price)
str1 = str1 .. ' Coins.'
@ -115,7 +108,7 @@ local function refresh_market_offers()
market.add_market_item(item)
end
if not FDT.get('trapped_capsules_unlocked') then
if not Public.get('trapped_capsules_unlocked') then
market.add_market_item(
{
price = {{'coin', 3500}},
@ -123,7 +116,7 @@ local function refresh_market_offers()
}
)
end
if not FDT.get('explosive_bullets_unlocked') then
if not Public.get('explosive_bullets_unlocked') then
market.add_market_item(
{
price = {{'coin', 4500}},
@ -131,7 +124,7 @@ local function refresh_market_offers()
}
)
end
if not FDT.get('bouncy_shells_unlocked') then
if not Public.get('bouncy_shells_unlocked') then
market.add_market_item(
{
price = {{'coin', 10000}},
@ -139,7 +132,7 @@ local function refresh_market_offers()
}
)
end
if not FDT.get('vehicle_nanobots_unlocked') then
if not Public.get('vehicle_nanobots_unlocked') then
market.add_market_item(
{
price = {{'coin', 15000}},
@ -155,7 +148,7 @@ local function refresh_market_offers()
market.add_market_item({price = {{"coin", 45000}}, offer = {type = 'nothing', effect_description = special_descriptions["ultra-mines"]}})
end
]]
if not FDT.get('laser_pointer_unlocked') then
if not Public.get('laser_pointer_unlocked') then
market.add_market_item(
{
price = {{'coin', 65000}},
@ -166,7 +159,7 @@ local function refresh_market_offers()
end
local function slot_upgrade(player, offer_index)
local entity_limits = FDT.get('entity_limits')
local entity_limits = Public.get('entity_limits')
local price = entity_limits[slot_upgrade_offers[offer_index][1]].limit * entity_limits[slot_upgrade_offers[offer_index][1]].slot_price
local gain = 1
@ -195,7 +188,7 @@ local function slot_upgrade(player, offer_index)
end
local function on_market_item_purchased(event)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local market = event.market
local offer_index = event.offer_index
local offers = market.get_market_items()
@ -216,62 +209,62 @@ local function on_market_item_purchased(event)
if bought_offer.effect_description == special_descriptions['explosive-bullets'] then
game.print(player.name .. ' has unlocked explosive bullets.', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('explosive_bullets_unlocked', true)
Public.set('explosive_bullets_unlocked', true)
refresh_market_offers()
return
end
if bought_offer.effect_description == special_descriptions['bouncy-shells'] then
game.print(player.name .. ' has unlocked bouncy shells.', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('bouncy_shells_unlocked', true)
Public.set('bouncy_shells_unlocked', true)
refresh_market_offers()
return
end
if bought_offer.effect_description == special_descriptions['trapped-capsules'] then
game.print(player.name .. ' has unlocked trapped capsules!', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('trapped_capsules_unlocked', true)
Public.set('trapped_capsules_unlocked', true)
refresh_market_offers()
return
end
if bought_offer.effect_description == special_descriptions['ultra-mines'] then
game.print(player.name .. ' has unlocked ultra mines!', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('ultra_mines_unlocked', true)
Public.set('ultra_mines_unlocked', true)
refresh_market_offers()
return
end
if bought_offer.effect_description == special_descriptions['laser-pointer'] then
game.print(player.name .. ' has unleashed the quest to slay the red dot!', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('laser_pointer_unlocked', true)
Public.set('laser_pointer_unlocked', true)
refresh_market_offers()
return
end
if bought_offer.effect_description == special_descriptions['crumbly-walls'] then
game.print(player.name .. ' has unlocked crumbly walls!', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('crumbly_walls_unlocked', true)
Public.set('crumbly_walls_unlocked', true)
refresh_market_offers()
return
end
if bought_offer.effect_description == special_descriptions['vehicle-nanobots'] then
game.print(player.name .. ' has unlocked vehicle nanobots!', {r = 0.22, g = 0.77, b = 0.44})
FDT.set('vehicle_nanobots_unlocked', true)
Public.set('vehicle_nanobots_unlocked', true)
refresh_market_offers()
return
end
end
local function on_gui_opened(event)
if not event.entity then
local entity = event.entity
if not (entity and entity.valid) then
return
end
if not event.entity.valid then
return
end
if event.entity.name == 'market' then
if entity.name == 'market' then
refresh_market_offers()
return
end

@ -1,55 +0,0 @@
require 'maps.fish_defender_v2.boss_biters'
local Event = require 'utils.event'
local explosive_bullets = require 'maps.fish_defender_v2.explosive_gun_bullets'
local bouncy_shells = require 'maps.fish_defender_v2.bouncy_shells'
local FDT = require 'maps.fish_defender_v2.table'
local function protect_market(event)
if event.entity.name ~= 'market' then
return
end
if event.cause then
if event.cause.force.name == 'enemy' then
return
end
end
event.entity.health = event.entity.health + event.final_damage_amount
return true
end
local function on_entity_damaged(event)
if not event.entity then
return
end
if not event.entity.valid then
return
end
if protect_market(event) then
return
end
if not event.cause then
return
end
local explosive_bullets_unlocked = FDT.get('explosive_bullets_unlocked')
local bouncy_shells_unlocked = FDT.get('bouncy_shells_unlocked')
if event.cause.name ~= 'character' then
return
end
if explosive_bullets_unlocked then
if explosive_bullets(event) then
return
end
end
if bouncy_shells_unlocked then
if bouncy_shells(event) then
return
end
end
end
Event.add(defines.events.on_entity_damaged, on_entity_damaged)

@ -1,11 +1,11 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local gain_multiplier = 4
local function on_research_finished(event)
local research = event.research
local force_name = research.force.name
local shotgun_shell_damage_modifier_old = FDT.get('shotgun_shell_damage_modifier_old')
local shotgun_shell_damage_modifier_old = Public.get('shotgun_shell_damage_modifier_old')
if not shotgun_shell_damage_modifier_old[force_name] then
shotgun_shell_damage_modifier_old[force_name] = game.forces[force_name].get_ammo_damage_modifier('shotgun-shell') - 0.1
@ -27,3 +27,5 @@ end
Event.on_init(on_init)
Event.add(defines.events.on_research_finished, on_research_finished)
return Public

@ -22,7 +22,7 @@ function Public.reset_table()
this.announced_message = false
this.force_chunk = false
this.fish_eye = false
this.chunk_load_tick = game.tick + 600
this.chunk_load_tick = game.tick + 500
-- @end
this.game_has_ended = false
this.game_reset = false

@ -1,31 +1,101 @@
local Event = require 'utils.event'
local Builder = require 'maps.fish_defender_v2.b'
local map_functions = require 'tools.map_functions'
local simplex_noise = require 'utils.simplex_noise'.d2
local FDT = require 'maps.fish_defender_v2.table'
local math_random = math.random
local math_abs = math.abs
local math_sqrt = math.sqrt
local Public = require 'maps.fish_defender_v2.table'
local Task = require 'utils.task'
local Token = require 'utils.token'
local random = math.random
local abs = math.abs
local sqrt = math.sqrt
--rock spawning code for stone pile
local rock_raffle = {'sand-rock-big', 'sand-rock-big', 'rock-big', 'rock-big', 'rock-big', 'rock-huge'}
local rock_raffle = {
'sand-rock-big',
'sand-rock-big',
'rock-big',
'rock-big',
'rock-big',
'rock-huge'
}
local size_of_rock_raffle = #rock_raffle
local function place_rock(surface, position)
local a = (math_random(-250, 250)) * 0.05
local b = (math_random(-250, 250)) * 0.05
surface.create_entity({name = rock_raffle[math_random(1, size_of_rock_raffle)], position = {position.x + a, position.y + b}})
local a = (random(-250, 250)) * 0.05
local b = (random(-250, 250)) * 0.05
surface.create_entity({name = rock_raffle[random(1, size_of_rock_raffle)], position = {position.x + a, position.y + b}})
end
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math.random(size)
local rand = random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local function get_replacement_tile(surface, position)
local function resource_placement(surface, position, name, amount, tiles)
local w_max = 256
local h_max = 256
local biases = {[0] = {[0] = 1}}
local ti = 1
local function grow(grid, t)
local old = {}
local new_count = 0
for x, _ in pairs(grid) do
for y, _ in pairs(_) do
table.insert(old, {x, y})
end
end
for _, pos in pairs(old) do
local x, y = pos[1], pos[2]
for dx = -1, 1, 1 do
for dy = -1, 1, 1 do
local a, b = x + dx, y + dy
if (math.random() > 0.9) and (abs(a) < w_max) and (abs(b) < h_max) then
grid[a] = grid[a] or {}
if not grid[a][b] then
grid[a][b] = 1 - (t / tiles)
new_count = new_count + 1
if (new_count + t) == tiles then
return new_count
end
end
end
end
end
end
return new_count
end
repeat
ti = ti + grow(biases, ti)
until ti >= tiles
local total_bias = 0
for _, _ in pairs(biases) do
for _, bias in pairs(_) do
total_bias = total_bias + bias
end
end
for x, _ in pairs(biases) do
for y, bias in pairs(_) do
surface.create_entity {
name = name,
amount = amount * (bias / total_bias),
force = 'neutral',
position = {position.x + x, position.y + y}
}
end
end
end
function Public.get_replacement_tile(surface, position)
for i = 1, 128, 1 do
local vectors = {{0, i}, {0, i * -1}, {i, 0}, {i * -1, 0}}
shuffle(vectors)
@ -40,7 +110,7 @@ local function get_replacement_tile(surface, position)
end
local function is_enemy_territory(p)
if p.x - 64 < math_abs(p.y) then
if p.x - 64 < abs(p.y) then
return false
end
--if p.x - 64 < p.y then return false end
@ -66,256 +136,345 @@ local function place_fish_market(surface, position)
return market
end
local function enemy_territory(surface, left_top)
if left_top.x < 256 then
return
end
if left_top.x > 750 then
return
end
if left_top.y > 766 then
return
end
if left_top.y < -256 then
return
end
local enemy_territory_token =
Token.register(
function(data)
local surface_index = data.surface_index
local left_top = data.left_top
local surface = game.get_surface(surface_index)
if left_top.x < 256 then
return
end
if left_top.x > 750 then
return
end
if left_top.y > 766 then
return
end
if left_top.y < -256 then
return
end
local area = {{left_top.x, left_top.y}, {left_top.x + 32, left_top.y + 32}}
local area = {{left_top.x, left_top.y}, {left_top.x + 32, left_top.y + 32}}
if left_top.x > 300 then
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
if is_enemy_territory(pos) then
if math_random(1, 512) == 1 then
if surface.can_place_entity({name = 'biter-spawner', force = 'decoratives', position = pos}) then
local entity
if math_random(1, 4) == 1 then
entity = surface.create_entity({name = 'spitter-spawner', force = 'decoratives', position = pos})
else
entity = surface.create_entity({name = 'biter-spawner', force = 'decoratives', position = pos})
if left_top.x > 300 then
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
if is_enemy_territory(pos) then
if random(1, 512) == 1 then
if surface.can_place_entity({name = 'biter-spawner', force = 'decoratives', position = pos}) then
local entity
if random(1, 4) == 1 then
entity = surface.create_entity({name = 'spitter-spawner', force = 'decoratives', position = pos})
else
entity = surface.create_entity({name = 'biter-spawner', force = 'decoratives', position = pos})
end
entity.active = false
entity.destructible = false
end
entity.active = false
entity.destructible = false
end
end
end
end
end
end
for _, entity in pairs(surface.find_entities_filtered({area = area, type = {'tree', 'cliff'}})) do
if is_enemy_territory(entity.position) then
entity.destroy()
end
end
for _, entity in pairs(surface.find_entities_filtered({area = area, type = 'resource'})) do
if is_enemy_territory(entity.position) then
surface.create_entity({name = 'uranium-ore', position = entity.position, amount = math_random(200, 8000)})
entity.destroy()
end
end
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = area})) do
if is_enemy_territory(tile.position) then
surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true)
end
end
end
local function fish_mouth(surface, left_top)
if left_top.x > -1800 then
return
end
if left_top.y > 64 then
return
end
if left_top.y < -64 then
return
end
if left_top.x < -2200 then
return
end
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
local noise = simplex_noise(pos.x * 0.006, 0, game.surfaces[1].map_gen_settings.seed) * 20
if pos.y <= 12 + noise and pos.y >= -12 + noise then
surface.set_tiles({{name = 'water', position = pos}})
end
end
end
end
local function generate_spawn_area(surface)
local spawn_area_generated = FDT.get('spawn_area_generated')
if spawn_area_generated then
return
end
surface.request_to_generate_chunks({0, 0}, 8)
local chunk_load_tick = FDT.get('chunk_load_tick')
if chunk_load_tick > game.tick then
return
end
local spawn_position_x = -128
surface.create_entity({name = 'electric-beam', position = {254, -143}, source = {254, -143}, target = {254, 193}}) -- fish
--surface.create_entity({name = 'electric-beam', position = {160, -101}, source = {160, -101}, target = {160, 248}}) -- fish
--surface.create_entity({name = 'electric-beam', position = {160, -88}, source = {160, -88}, target = {160, 185}})
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = {{-300, -256}, {300, 300}}})) do
local noise = math_abs(simplex_noise(tile.position.x * 0.02, tile.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 16)
if tile.position.x > -160 + noise then
surface.set_tiles({{name = get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true)
end
end
for _, entity in pairs(surface.find_entities_filtered({type = {'resource', 'cliff'}, area = {{-300, -256}, {300, 300}}})) do
if entity.position.x > -300 + math_abs(simplex_noise(entity.position.x * 0.02, entity.position.y * 0.02, game.surfaces[1].map_gen_settings.seed) * 32) then
entity.destroy()
end
end
local decorative_names = {}
for k, v in pairs(game.decorative_prototypes) do
if v.autoplace_specification then
decorative_names[#decorative_names + 1] = k
end
end
for x = -4, 4, 1 do
for y = -3, 3, 1 do
surface.regenerate_decorative(decorative_names, {{x, y}})
end
end
local _y = 80
local ore_positions = {
{x = spawn_position_x - 52, y = _y},
{x = spawn_position_x - 52, y = _y * 0.5},
{x = spawn_position_x - 52, y = 0},
{x = spawn_position_x - 52, y = _y * -0.5},
{x = spawn_position_x - 52, y = _y * -1}
}
shuffle(ore_positions)
map_functions.draw_smoothed_out_ore_circle(ore_positions[1], 'copper-ore', surface, 16, 3500)
map_functions.draw_smoothed_out_ore_circle(ore_positions[2], 'iron-ore', surface, 16, 3500)
map_functions.draw_smoothed_out_ore_circle(ore_positions[3], 'coal', surface, 16, 2500)
map_functions.draw_smoothed_out_ore_circle(ore_positions[4], 'stone', surface, 16, 2500)
for _ = 0,10,1 do
place_rock(surface, ore_positions[4]) --add rocks to stone area
end
map_functions.draw_noise_tile_circle({x = spawn_position_x - 20, y = 0}, 'water', surface, 16)
map_functions.draw_oil_circle(ore_positions[5], 'crude-oil', surface, 8, 200000)
local pos = surface.find_non_colliding_position('market', {spawn_position_x, 0}, 50, 1)
local market = FDT.set('market', place_fish_market(surface, pos))
local r = 16
for _, entity in pairs(
surface.find_entities_filtered(
{
area = {
{market.position.x - r, market.position.y - r},
{market.position.x + r, market.position.y + r}
},
type = 'tree'
}
)
) do
local distance_to_center = math_sqrt((entity.position.x - market.position.x) ^ 2 + (entity.position.y - market.position.y) ^ 2)
if distance_to_center < r then
if math_random(1, r) > distance_to_center then
for _, entity in pairs(surface.find_entities_filtered({area = area, type = {'tree', 'cliff'}})) do
if is_enemy_territory(entity.position) then
entity.destroy()
end
end
for _, entity in pairs(surface.find_entities_filtered({area = area, type = 'resource'})) do
if is_enemy_territory(entity.position) then
surface.create_entity({name = 'uranium-ore', position = entity.position, amount = random(200, 8000)})
entity.destroy()
end
end
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = area})) do
if is_enemy_territory(tile.position) then
surface.set_tiles({{name = Public.get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true)
end
end
end
)
local turret_pos = surface.find_non_colliding_position('gun-turret', {spawn_position_x + 5, 1}, 50, 1)
local turret = surface.create_entity({name = 'gun-turret', position = turret_pos, force = 'player'})
turret.insert({name = 'firearm-magazine', count = 32})
local fish_mouth_token =
Token.register(
function(data)
local surface_index = data.surface_index
local left_top = data.left_top
local surface = game.get_surface(surface_index)
if left_top.x > -1800 then
return
end
if left_top.y > 64 then
return
end
if left_top.y < -64 then
return
end
if left_top.x < -2200 then
return
end
for x = -20, 20, 1 do
for y = -20, 20, 1 do
local market_pos = {x = market.position.x + x, y = market.position.y + y}
local distance_to_center = x ^ 2 + y ^ 2
if distance_to_center > 64 and distance_to_center < 225 then
if math_random(1, 3) == 1 and surface.can_place_entity({name = 'wooden-chest', position = market_pos, force = 'player'}) then
surface.create_entity({name = 'wooden-chest', position = market_pos, force = 'player'})
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
local noise = simplex_noise(pos.x * 0.006, 0, game.surfaces[1].map_gen_settings.seed) * 20
if pos.y <= 12 + noise and pos.y >= -12 + noise then
surface.set_tiles({{name = 'water', position = pos}})
end
end
end
end
)
local area = {{x = -160, y = -96}, {x = 160, y = 96}}
for _, tile in pairs(surface.find_tiles_filtered({name = 'water', area = area})) do
if math_random(1, 32) == 1 then
surface.create_entity({name = 'fish', position = tile.position})
local request_to_generate_chunks_token =
Token.register(
function(data)
local surface_index = data.surface_index
local surface = game.get_surface(surface_index)
local spawn_area_generated = Public.get('spawn_area_generated')
if spawn_area_generated then
return
end
surface.request_to_generate_chunks({0, 0}, 8)
local fish_eye_location = Public.get('fish_eye_location')
surface.request_to_generate_chunks(fish_eye_location, 2)
end
)
local character_pos = surface.find_non_colliding_position('character', {spawn_position_x + 1, 4}, 50, 1)
game.forces['player'].set_spawn_position(character_pos, surface)
for _, player in pairs(game.connected_players) do
local spawn_pos = surface.find_non_colliding_position('character', {spawn_position_x + 1, 4}, 50, 1)
player.teleport(spawn_pos, surface)
end
local rr = 200
local p = {x = -131, y = 5}
game.forces.player.chart(
surface,
{
{p.x - rr - 100, p.y - rr},
{p.x + rr + 400, p.y + rr}
}
)
local fish_eye_location = FDT.get('fish_eye_location')
surface.request_to_generate_chunks(fish_eye_location, 2)
FDT.set('spawn_area_generated', true)
local function initial_cargo_boxes()
return {
{name = 'coal', count = random(32, 64)},
{name = 'coal', count = random(32, 64)},
{name = 'coal', count = random(32, 64)},
{name = 'iron-ore', count = random(32, 128)},
{name = 'iron-ore', count = random(32, 128)},
{name = 'iron-ore', count = random(32, 128)},
{name = 'copper-ore', count = random(32, 128)},
{name = 'copper-ore', count = random(32, 128)},
{name = 'copper-ore', count = random(32, 128)},
{name = 'submachine-gun', count = 1},
{name = 'submachine-gun', count = 1},
{name = 'submachine-gun', count = 1},
{name = 'shotgun', count = 1},
{name = 'shotgun', count = 1},
{name = 'shotgun', count = 1},
{name = 'burner-mining-drill', count = 1},
{name = 'burner-mining-drill', count = 2},
{name = 'burner-mining-drill', count = 1},
{name = 'burner-mining-drill', count = 4},
{name = 'gun-turret', count = 1},
{name = 'gun-turret', count = 1},
{name = 'gun-turret', count = 1},
{name = 'shotgun-shell', count = random(4, 5)},
{name = 'shotgun-shell', count = random(4, 5)},
{name = 'shotgun-shell', count = random(4, 5)},
{name = 'grenade', count = random(2, 7)},
{name = 'grenade', count = random(2, 8)},
{name = 'grenade', count = random(2, 7)},
{name = 'light-armor', count = random(2, 4)},
{name = 'iron-gear-wheel', count = random(7, 15)},
{name = 'iron-gear-wheel', count = random(7, 15)},
{name = 'iron-gear-wheel', count = random(7, 15)},
{name = 'iron-gear-wheel', count = random(7, 15)},
{name = 'iron-plate', count = random(15, 23)},
{name = 'iron-plate', count = random(15, 23)},
{name = 'iron-plate', count = random(15, 23)},
{name = 'iron-plate', count = random(15, 23)},
{name = 'copper-plate', count = random(15, 23)},
{name = 'copper-plate', count = random(15, 23)},
{name = 'copper-plate', count = random(15, 23)},
{name = 'copper-plate', count = random(15, 23)},
{name = 'firearm-magazine', count = random(10, 15)},
{name = 'firearm-magazine', count = random(10, 15)},
{name = 'firearm-magazine', count = random(10, 15)},
{name = 'firearm-magazine', count = random(10, 15)}
}
end
local generate_spawn_area_token =
Token.register(
function(data)
local surface_index = data.surface_index
local surface = game.get_surface(surface_index)
local spawn_area_generated = Public.get('spawn_area_generated')
if spawn_area_generated then
return
end
local chunk_load_tick = Public.get('chunk_load_tick')
if chunk_load_tick > game.tick then
if game.tick % 100 == 1 then
game.print('[color=blue][Map Generator][/color] Generating map in progress...')
end
return
end
local spawn_position_x = -128
surface.create_entity({name = 'electric-beam', position = {254, -143}, source = {254, -143}, target = {254, 193}}) -- fish
--surface.create_entity({name = 'electric-beam', position = {160, -101}, source = {160, -101}, target = {160, 248}}) -- fish
--surface.create_entity({name = 'electric-beam', position = {160, -88}, source = {160, -88}, target = {160, 185}})
for _, tile in pairs(surface.find_tiles_filtered({name = {'water', 'deepwater'}, area = {{-300, -256}, {300, 300}}})) do
surface.set_tiles({{name = Public.get_replacement_tile(surface, tile.position), position = {tile.position.x, tile.position.y}}}, true)
end
for _, entity in pairs(surface.find_entities_filtered({type = {'resource', 'cliff'}, area = {{-300, -256}, {300, 300}}})) do
entity.destroy()
end
local decorative_names = {}
for k, v in pairs(game.decorative_prototypes) do
if v.autoplace_specification then
decorative_names[#decorative_names + 1] = k
end
end
for x = -4, 4, 1 do
for y = -3, 3, 1 do
surface.regenerate_decorative(decorative_names, {{x, y}})
end
end
local _y = 80
local ore_positions = {
{x = spawn_position_x - 52, y = _y},
{x = spawn_position_x - 52, y = _y * 0.5},
{x = spawn_position_x - 52, y = 0},
{x = spawn_position_x - 52, y = _y * -0.5},
{x = spawn_position_x - 52, y = _y * -1}
}
shuffle(ore_positions)
resource_placement(surface, ore_positions[1], 'copper-ore', 1500000, 650)
resource_placement(surface, ore_positions[2], 'iron-ore', 1500000, 650)
resource_placement(surface, ore_positions[3], 'coal', 1300000, 650)
resource_placement(surface, ore_positions[4], 'stone', 1300000, 650)
for _ = 0, 10, 1 do
place_rock(surface, ore_positions[4]) --add rocks to stone area
end
map_functions.draw_noise_tile_circle({x = spawn_position_x - 20, y = 0}, 'water', surface, 16)
map_functions.draw_oil_circle(ore_positions[5], 'crude-oil', surface, 8, 200000)
local pos = surface.find_non_colliding_position('market', {spawn_position_x, 0}, 50, 1)
local market = Public.set('market', place_fish_market(surface, pos))
local r = 16
for _, entity in pairs(
surface.find_entities_filtered(
{
area = {
{market.position.x - r, market.position.y - r},
{market.position.x + r, market.position.y + r}
},
type = 'tree'
}
)
) do
local distance_to_center = sqrt((entity.position.x - market.position.x) ^ 2 + (entity.position.y - market.position.y) ^ 2)
if distance_to_center < r then
if random(1, r) > distance_to_center then
entity.destroy()
end
end
end
local turret_pos = surface.find_non_colliding_position('gun-turret', {spawn_position_x + 5, 1}, 50, 1)
local turret = surface.create_entity({name = 'gun-turret', position = turret_pos, force = 'player'})
turret.insert({name = 'firearm-magazine', count = 32})
local cargo_boxes = initial_cargo_boxes()
for x = -20, 20, 1 do
for y = -20, 20, 1 do
local market_pos = {x = market.position.x + x, y = market.position.y + y}
local distance_to_center = x ^ 2 + y ^ 2
if distance_to_center > 64 and distance_to_center < 225 then
if random(1, 3) == 1 and surface.can_place_entity({name = 'wooden-chest', position = market_pos, force = 'player'}) then
local e = surface.create_entity({name = 'wooden-chest', position = market_pos, force = 'player', create_build_effect_smoke = false})
if random(1, 8) == 1 then
local inventory = e.get_inventory(defines.inventory.chest)
inventory.insert(cargo_boxes[random(1, #cargo_boxes)])
end
end
end
end
end
local area = {{x = -160, y = -96}, {x = 160, y = 96}}
for _, tile in pairs(surface.find_tiles_filtered({name = 'water', area = area})) do
if random(1, 32) == 1 then
surface.create_entity({name = 'fish', position = tile.position})
end
end
local character_pos = surface.find_non_colliding_position('character', {spawn_position_x + 1, 4}, 50, 1)
game.forces['player'].set_spawn_position(character_pos, surface)
for _, player in pairs(game.connected_players) do
local spawn_pos = surface.find_non_colliding_position('character', {spawn_position_x + 1, 4}, 50, 1)
player.teleport(spawn_pos, surface)
end
local rr = 200
local p = {x = -131, y = 5}
game.forces.player.chart(
surface,
{
{p.x - rr - 100, p.y - rr},
{p.x + rr + 400, p.y + rr}
}
)
Public.set('spawn_area_generated', true)
end
)
local function process_chunk(left_top)
local active_surface_index = FDT.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
local active_surface_index = Public.get('active_surface_index')
local surface = game.get_surface(active_surface_index)
if not surface or not surface.valid then
return
end
generate_spawn_area(surface, left_top)
enemy_territory(surface, left_top)
fish_mouth(surface, left_top)
Task.set_timeout_in_ticks(1, request_to_generate_chunks_token, {surface_index = surface.index})
Task.set_timeout_in_ticks(15, generate_spawn_area_token, {surface_index = surface.index})
Task.set_timeout_in_ticks(60, enemy_territory_token, {surface_index = surface.index, left_top = left_top})
Task.set_timeout_in_ticks(90, fish_mouth_token, {surface_index = surface.index, left_top = left_top})
local market = FDT.get('market')
local market = Public.get('market')
game.forces.player.chart(surface, {{left_top.x, left_top.y}, {left_top.x + 31, left_top.y + 31}})
if market and market.valid then
FDT.set('game_reset', false)
Public.set('game_reset', false)
end
end
local function on_chunk_generated(event)
local map_name = 'fish_defender'
local surface = event.surface
local area = event.area
local left_top = area.left_top
if string.sub(event.surface.name, 0, #map_name) ~= map_name then
if string.sub(surface.name, 0, #map_name) ~= map_name then
return
end
if FDT.get('stop_generating_map') then
if Public.get('stop_generating_map') then
return
end
local left_top = event.area.left_top
Builder.make_chunk(event)
Public.make_chunk(event)
process_chunk(left_top)
end
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
return Public

@ -1,5 +1,5 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local radius = 20
@ -10,23 +10,25 @@ local whitelist = {
}
local function on_entity_died(event)
local trapped_capsules_unlocked = FDT.get('trapped_capsules_unlocked')
local trapped_capsules_unlocked = Public.get('trapped_capsules_unlocked')
if not trapped_capsules_unlocked then
return
end
if not event.entity.valid then
local entity = event.entity
if not entity.valid then
return
end
if not whitelist[event.entity.name] then
if not whitelist[entity.name] then
return
end
local valid_targets = {}
local position = event.entity.position
local position = entity.position
for _, e in pairs(
event.entity.surface.find_entities_filtered(
entity.surface.find_entities_filtered(
{
area = {{position.x - radius, position.y - radius}, {position.x + radius, position.y + radius}},
force = 'enemy'
@ -45,9 +47,9 @@ local function on_entity_died(event)
return
end
event.entity.surface.create_entity(
entity.surface.create_entity(
{
name = whitelist[event.entity.name],
name = whitelist[entity.name],
position = position,
force = 'player',
source = position,
@ -59,3 +61,5 @@ local function on_entity_died(event)
end
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

@ -1,5 +1,5 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local radius = 8
local function damage_entities_around_target(entity, damage)
@ -25,27 +25,31 @@ local function damage_entities_around_target(entity, damage)
end
local function on_entity_died(event)
local ultra_mines_unlocked = FDT.get('ultra_mines_unlocked')
local ultra_mines_unlocked = Public.get('ultra_mines_unlocked')
if not ultra_mines_unlocked then
return
end
if not event.entity.valid then
return
end
if event.entity.name ~= 'land-mine' then
local entity = event.entity
if not entity.valid then
return
end
event.entity.surface.create_entity(
if entity.name ~= 'land-mine' then
return
end
entity.surface.create_entity(
{
name = 'big-artillery-explosion',
position = event.entity.position
position = entity.position
}
)
local damage = (1 + event.entity.force.get_ammo_damage_modifier('grenade')) * 250
local damage = (1 + entity.force.get_ammo_damage_modifier('grenade')) * 250
damage_entities_around_target(event.entity, damage)
damage_entities_around_target(entity, damage)
end
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

@ -1,25 +1,28 @@
local Event = require 'utils.event'
local FDT = require 'maps.fish_defender_v2.table'
local Public = require 'maps.fish_defender_v2.table'
local function on_player_changed_position(event)
local vehicle_nanobots_unlocked = FDT.get('vehicle_nanobots_unlocked')
local vehicle_nanobots_unlocked = Public.get('vehicle_nanobots_unlocked')
if not vehicle_nanobots_unlocked then
return
end
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if not (player and player.valid) then
return
end
if not player.character then
return
end
if not player.character.driving then
return
end
if not player.vehicle then
return
end
if not player.vehicle.valid then
if not (player.vehicle and player.vehicle.valid) then
return
end
if player.vehicle.health == player.vehicle.prototype.max_health then
return
end
@ -27,3 +30,5 @@ local function on_player_changed_position(event)
end
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
return Public