1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-26 22:56:43 +02:00

Refactor Scrap Towny and ix desync issues

This commit is contained in:
Gerkiz 2022-09-30 22:23:37 +02:00
parent 4aa1a1b190
commit 30f207da55
45 changed files with 1448 additions and 1291 deletions

View File

@ -75,7 +75,7 @@ local function spawn_biter(surface, position, evolution)
end
end
local function unearthing_biters(surface, position, amount)
local function unearthing_biters(surface, position, amount, relative_evolution)
if not surface then
return
end
@ -94,6 +94,10 @@ local function unearthing_biters(surface, position, amount)
local evolution = game.forces.enemy.evolution_factor
if relative_evolution then
evolution = relative_evolution
end
local ticks = amount * 40
ticks = ticks + 80
for t = 4, ticks, 4 do
@ -111,7 +115,7 @@ local function unearthing_biters(surface, position, amount)
if t % 40 == 36 then
traps[tick][#traps[tick] + 1] = {
callback = 'spawn_biter',
params = {surface, {x = position.x, y = position.y}, evolution}
params = {surface, {x = position.x, y = position.y}, evolution, relative_evolution}
}
end
end

View File

@ -126,7 +126,7 @@ local function spawn_worm(surface, position, evolution_index)
surface.create_entity({name = worm_name, position = position})
end
local function unearthing_worm(surface, position)
local function unearthing_worm(surface, position, relative_evolution)
if not surface then
return
end
@ -144,6 +144,10 @@ local function unearthing_worm(surface, position)
end
local evolution_index = math.ceil(game.forces.enemy.evolution_factor * 10)
if relative_evolution then
evolution_index = math.ceil(relative_evolution * 10)
end
if evolution_index < 1 then
evolution_index = 1
end

View File

@ -8,6 +8,7 @@ local table_insert = table.insert
local table_remove = table.remove
local table_shuffle = table.shuffle_table
local Event = require 'utils.event'
local Global = require 'utils.global'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
@ -19,8 +20,8 @@ Global.register(
end
)
local Table = require 'modules.scrap_towny_ffa.table'
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local function get_commmands(target, group)
local commands = {}
@ -67,8 +68,8 @@ local function get_commmands(target, group)
end
local function roll_market()
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
if town_centers == nil or table_size(town_centers) == 0 then
return
end
@ -116,23 +117,23 @@ local function is_swarm_valid(swarm)
end
function Public.validate_swarms()
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for k, swarm in pairs(ffatable.swarms) do
for k, swarm in pairs(this.swarms) do
if not is_swarm_valid(swarm) then
table_remove(ffatable.swarms, k)
table_remove(this.swarms, k)
end
end
end
function Public.unit_groups_start_moving()
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for _, swarm in pairs(ffatable.swarms) do
for _, swarm in pairs(this.swarms) do
if swarm.group then
if swarm.group.valid then
swarm.group.start_moving()
@ -156,8 +157,8 @@ function Public.swarm(town_center, radius)
if town_center == nil then
return
end
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
local r = radius or 32
@ -170,8 +171,8 @@ function Public.swarm(town_center, radius)
return
end
-- skip if we have to many swarms already
local count = table_size(ffatable.swarms)
local towns = table_size(ffatable.town_centers)
local count = table_size(this.swarms)
local towns = table_size(this.town_centers)
if count > 3 * towns then
return
end
@ -255,7 +256,7 @@ function Public.swarm(town_center, radius)
commands = get_commmands(market, unit_group)
}
)
table_insert(ffatable.swarms, {group = unit_group, timeout = game.tick + 36000})
table_insert(this.swarms, {group = unit_group, timeout = game.tick + 36000})
end
local function on_unit_group_finished_gathering(event)
@ -265,8 +266,8 @@ local function on_unit_group_finished_gathering(event)
local target = entities[1]
if target ~= nil then
local force = target.force
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
local town_center = town_centers[force.name]
-- cancel if relatively new town
if new_town(town_center) then
@ -297,13 +298,10 @@ local function on_tick()
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.swarms = {}
BiterHealthBooster.acid_nova(true)
BiterHealthBooster.check_on_entity_died(true)
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_unit_group_finished_gathering, on_unit_group_finished_gathering)

View File

@ -3,7 +3,7 @@ local Public = {}
local math_floor = math.floor
local table_insert = table.insert
local table_size = table.size
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
--[[
local town_radius = 27
local connection_radius = 15
@ -231,12 +231,12 @@ function Public.near_another_town(force_name, position, surface, radius)
if force_name == nil then
return false
end
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local forces = {}
-- check for nearby town centers
local fail = false
if table_size(ffatable.town_centers) > 0 then
for _, town_center in pairs(ffatable.town_centers) do
if table_size(this.town_centers) > 0 then
for _, town_center in pairs(this.town_centers) do
if town_center ~= nil then
local market = town_center.market
if market ~= nil and market.valid then
@ -285,8 +285,8 @@ function Public.near_another_town(force_name, position, surface, radius)
end
--[[
local function in_own_town(force, position)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
if town_center ~= nil then
local market = town_center.market
if market ~= nil then

View File

@ -2,7 +2,7 @@ local Public = {}
local table_shuffle = table.shuffle_table
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Color = require 'utils.color_presets'
local colors = {}
@ -151,8 +151,8 @@ local function is_color_used(color, town_centers)
end
function Public.get_random_color()
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
local rgb
local color = {}
local name
@ -187,8 +187,8 @@ local function random_color(cmd)
player.print('You are not member of a town!', Color.fail)
return
end
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
local crayon = Public.get_random_color()

View File

@ -2,7 +2,7 @@ local Public = {}
local math_floor = math.floor
local math_log10 = math.log10
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local biters = {
[1] = 'small-biter',
@ -358,7 +358,7 @@ local function get_unit_size(evolution)
if (evolution >= 0.90 and evolution < 1) then
local r = math.random()
if r < 0.5 then
return 3
return 3
end
return 4
end
@ -381,20 +381,26 @@ local function calculate_relative_evolution(evolution_factor, distance_factor)
-- distance factor will be from 0.0 to 1.0 but drop off dramatically towards zero
local log_distance_factor = math_log10(distance_factor * 10 + 1)
local evo = log_distance_factor * evolution_factor
if evo < 0.0 then evo = 0.0 end
if evo > 1.0 then evo = 1.0 end
if evo < 0.0 then
evo = 0.0
end
if evo > 1.0 then
evo = 1.0
end
return evo
end
local function get_relative_biter_evolution(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local relative_evolution = 0.0
local max_d2 = max_evolution_distance * max_evolution_distance
-- for all of the teams
local teams = ffatable.town_centers
local teams = this.town_centers
for _, town_center in pairs(teams) do
local market = town_center.market
if market == nil or not market.valid then return relative_evolution end
if market == nil or not market.valid then
return relative_evolution
end
-- calculate the distance squared
local d2 = distance_squared(position, market.position)
if d2 < max_d2 then
@ -416,14 +422,16 @@ local function get_relative_biter_evolution(position)
end
local function get_relative_spitter_evolution(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local relative_evolution = 0.0
local max_d2 = max_evolution_distance * max_evolution_distance
-- for all of the teams
local teams = ffatable.town_centers
local teams = this.town_centers
for _, town_center in pairs(teams) do
local market = town_center.market
if market == nil or not market.valid then return relative_evolution end
if market == nil or not market.valid then
return relative_evolution
end
-- calculate the distance squared
local d2 = distance_squared(position, market.position)
if d2 < max_d2 then
@ -445,14 +453,16 @@ local function get_relative_spitter_evolution(position)
end
local function get_relative_worm_evolution(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local relative_evolution = 0.0
local max_d2 = max_evolution_distance * max_evolution_distance
-- for all of the teams
local teams = ffatable.town_centers
local teams = this.town_centers
for _, town_center in pairs(teams) do
local market = town_center.market
if market == nil or not market.valid then return relative_evolution end
if market == nil or not market.valid then
return relative_evolution
end
-- calculate the distance squared
local d2 = distance_squared(position, market.position)
if d2 < max_d2 then
@ -636,8 +646,8 @@ local function update_evolution(force_name, technology)
if technology == nil then
return
end
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force_name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force_name]
-- town_center is a reference to a global table
if not town_center then
return

View File

@ -3,8 +3,9 @@
local math_min = math.min
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local Pollution = require 'modules.scrap_towny_ffa.pollution'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Pollution = require 'maps.scrap_towny_ffa.pollution'
local Event = require 'utils.event'
--local damage_per_explosive = 100
local damage_per_explosive = 50
@ -1676,18 +1677,18 @@ local circle_coordinates = {
}
local function process_explosion_tile(pos, explosion_index, current_radius)
local ffatable = Table.get_table()
local surface = game.surfaces[ffatable.explosion_schedule[explosion_index].surface]
local this = ScenarioTable.get_table()
local surface = game.surfaces[this.explosion_schedule[explosion_index].surface]
local target_entities = surface.find_entities_filtered({area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.499, pos.y + 0.499}}})
local explosion_animation = 'explosion'
local tile = surface.get_tile(pos)
if tile.name == 'out-of-map' then
if ffatable.explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
if this.explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
explosion_animation = 'big-explosion'
surface.set_tiles({{name = 'dirt-5', position = pos}}, true)
end
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
else
local decay_explosion = true
for _, entity in pairs(target_entities) do
@ -1696,35 +1697,35 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
end
end
if decay_explosion then
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
end
end
for _, entity in pairs(target_entities) do
if entity.valid then
if entity.health then
if entity.health < ffatable.explosion_schedule[explosion_index].damage_remaining then
if entity.health < this.explosion_schedule[explosion_index].damage_remaining then
explosion_animation = 'big-explosion'
if entity.health > 500 then
explosion_animation = 'big-artillery-explosion'
end
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - entity.health
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - entity.health
if entity.name ~= 'character' then
entity.damage(2097152, 'player', 'explosion')
else
entity.die('player')
end
else
entity.damage(ffatable.explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
entity.damage(this.explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
if entity.valid then
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - entity.health
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - entity.health
end
end
end
end
end
if ffatable.explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if this.explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if math_random(1, 2) == 1 then
explosion_animation = 'big-explosion'
else
@ -1735,7 +1736,7 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
surface.create_entity({name = explosion_animation, position = pos})
Pollution.explosion(pos, surface, explosion_animation)
if ffatable.explosion_schedule[explosion_index].damage_remaining <= 0 then
if this.explosion_schedule[explosion_index].damage_remaining <= 0 then
return false
end
@ -1752,7 +1753,7 @@ local function volatility(inventory)
end
local function create_explosion_schedule(entity)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local inventory = defines.inventory.chest
if entity.type == 'car' then
inventory = defines.inventory.car_trunk
@ -1764,22 +1765,22 @@ local function create_explosion_schedule(entity)
end
local center_position = entity.position
if not ffatable.explosion_schedule then
ffatable.explosion_schedule = {}
if not this.explosion_schedule then
this.explosion_schedule = {}
end
ffatable.explosion_schedule[#ffatable.explosion_schedule + 1] = {}
ffatable.explosion_schedule[#ffatable.explosion_schedule].surface = entity.surface.name
ffatable.explosion_schedule[#ffatable.explosion_schedule].damage_remaining = damage_per_explosive * explosives_amount
this.explosion_schedule[#this.explosion_schedule + 1] = {}
this.explosion_schedule[#this.explosion_schedule].surface = entity.surface.name
this.explosion_schedule[#this.explosion_schedule].damage_remaining = damage_per_explosive * explosives_amount
for current_radius = 1, 23, 1 do
ffatable.explosion_schedule[#ffatable.explosion_schedule][current_radius] = {}
ffatable.explosion_schedule[#ffatable.explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
this.explosion_schedule[#this.explosion_schedule][current_radius] = {}
this.explosion_schedule[#this.explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
local circle_coords = circle_coordinates[current_radius]
for index, tile_position in pairs(circle_coords) do
local pos = {x = center_position.x + tile_position.x, y = center_position.y + tile_position.y}
ffatable.explosion_schedule[#ffatable.explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
this.explosion_schedule[#this.explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
end
end
entity.die('player')
@ -1816,24 +1817,24 @@ local function on_entity_damaged(event)
end
local function on_tick(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local tick = event.tick
if ffatable.explosion_schedule then
if this.explosion_schedule then
local explosion_schedule_is_alive = false
for explosion_index = 1, #ffatable.explosion_schedule, 1 do
if #ffatable.explosion_schedule[explosion_index] > 0 then
for explosion_index = 1, #this.explosion_schedule, 1 do
if #this.explosion_schedule[explosion_index] > 0 then
explosion_schedule_is_alive = true
for radius = 1, #ffatable.explosion_schedule[explosion_index], 1 do
if ffatable.explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #ffatable.explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(ffatable.explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
for radius = 1, #this.explosion_schedule[explosion_index], 1 do
if this.explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #this.explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(this.explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
if not continue_explosion then
ffatable.explosion_schedule[explosion_index] = {}
this.explosion_schedule[explosion_index] = {}
break
end
end
if radius == #ffatable.explosion_schedule[explosion_index] then
ffatable.explosion_schedule[explosion_index] = {}
if radius == #this.explosion_schedule[explosion_index] then
this.explosion_schedule[explosion_index] = {}
end
break
end
@ -1841,17 +1842,10 @@ local function on_tick(event)
end
end
if not explosion_schedule_is_alive then
ffatable.explosion_schedule = nil
this.explosion_schedule = nil
end
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.explosion_schedule = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_tick, on_tick)

View File

@ -2,11 +2,19 @@ local Public = {}
local math_random = math.random
local math_floor = math.floor
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
function Public.reproduce()
local ffatable = Table.get_table()
for _, town_center in pairs(ffatable.town_centers) do
local this = ScenarioTable.get_table()
for _, town_center in pairs(this.town_centers) do
if not town_center then
return
end
if not town_center.market or not town_center.market.valid then
return
end
local surface = town_center.market.surface
local position = town_center.market.position
local fishes = surface.find_entities_filtered({name = 'fish', position = position, radius = 27})
@ -29,10 +37,10 @@ function Public.reproduce()
end
end
if guppy == true then
for i=1, math_random(1, 5) do
surface.create_entity({name = 'water-splash', position = fish.position})
surface.create_entity({name = 'fish', position = fish.position})
end
for i = 1, math_random(1, 5) do
surface.create_entity({name = 'water-splash', position = fish.position})
surface.create_entity({name = 'fish', position = fish.position})
end
end
end
end

View File

@ -3,8 +3,9 @@
local math_random = math.random
local math_floor = math.floor
local Table = require 'modules.scrap_towny_ffa.table'
local Pollution = require 'modules.scrap_towny_ffa.pollution'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Pollution = require 'maps.scrap_towny_ffa.pollution'
local Event = require 'utils.event'
local empty_tile_damage_decay = 50
local out_of_map_tile_health = 1500
@ -35,18 +36,18 @@ local function shuffle(tbl)
end
local function process_explosion_tile(pos, explosion_index, current_radius)
local ffatable = Table.get_table()
local surface = game.surfaces[ffatable.fluid_explosion_schedule[explosion_index].surface]
local this = ScenarioTable.get_table()
local surface = game.surfaces[this.fluid_explosion_schedule[explosion_index].surface]
local target_entities = surface.find_entities_filtered({area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.499, pos.y + 0.499}}})
local explosion_animation = 'explosion'
local tile = surface.get_tile(pos)
if tile.name == 'out-of-map' then
if ffatable.fluid_explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
if this.fluid_explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
explosion_animation = 'big-explosion'
surface.set_tiles({{name = 'dirt-5', position = pos}}, true)
end
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = ffatable.fluid_explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
this.fluid_explosion_schedule[explosion_index].damage_remaining = this.fluid_explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
else
local decay_explosion = true
for _, entity in pairs(target_entities) do
@ -55,33 +56,33 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
end
end
if decay_explosion then
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = ffatable.fluid_explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
this.fluid_explosion_schedule[explosion_index].damage_remaining = this.fluid_explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
end
end
for _, entity in pairs(target_entities) do
if entity.valid then
if entity.health then
if entity.health <= ffatable.fluid_explosion_schedule[explosion_index].damage_remaining then
if entity.health <= this.fluid_explosion_schedule[explosion_index].damage_remaining then
explosion_animation = 'big-explosion'
if entity.health > 500 then
explosion_animation = 'big-artillery-explosion'
end
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = ffatable.fluid_explosion_schedule[explosion_index].damage_remaining - entity.health
this.fluid_explosion_schedule[explosion_index].damage_remaining = this.fluid_explosion_schedule[explosion_index].damage_remaining - entity.health
if entity.name ~= 'character' then
entity.damage(2097152, 'player', 'explosion')
else
entity.die('player')
end
else
entity.damage(ffatable.fluid_explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = 0
entity.damage(this.fluid_explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
this.fluid_explosion_schedule[explosion_index].damage_remaining = 0
end
end
end
end
if ffatable.fluid_explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if this.fluid_explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if math_random(1, 2) == 1 then
explosion_animation = 'big-explosion'
else
@ -92,7 +93,7 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
surface.create_entity({name = explosion_animation, position = pos})
Pollution.explosion(pos, surface, explosion_animation)
if ffatable.fluid_explosion_schedule[explosion_index].damage_remaining <= 0 then
if this.fluid_explosion_schedule[explosion_index].damage_remaining <= 0 then
return false
end
@ -100,7 +101,7 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
end
local function create_explosion_schedule(entity)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local explosives_amount = math_floor(entity.fluidbox[1].amount)
if explosives_amount < 1 then
@ -108,13 +109,13 @@ local function create_explosion_schedule(entity)
end
local center_position = entity.position
if not ffatable.fluid_explosion_schedule then
ffatable.fluid_explosion_schedule = {}
if not this.fluid_explosion_schedule then
this.fluid_explosion_schedule = {}
end
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule + 1] = {}
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule].surface = entity.surface.name
this.fluid_explosion_schedule[#this.fluid_explosion_schedule + 1] = {}
this.fluid_explosion_schedule[#this.fluid_explosion_schedule].surface = entity.surface.name
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule].damage_remaining = fluid_damages[entity.fluidbox[1].name] * explosives_amount
this.fluid_explosion_schedule[#this.fluid_explosion_schedule].damage_remaining = fluid_damages[entity.fluidbox[1].name] * explosives_amount
local circle_coordinates = {
[1] = {{x = 0, y = 0}},
@ -890,15 +891,15 @@ local function create_explosion_schedule(entity)
}
for current_radius = 1, 16, 1 do
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule][current_radius] = {}
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
this.fluid_explosion_schedule[#this.fluid_explosion_schedule][current_radius] = {}
this.fluid_explosion_schedule[#this.fluid_explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
local circle_coords = circle_coordinates[current_radius]
circle_coords = shuffle(circle_coords)
for index, tile_position in pairs(circle_coords) do
local pos = {x = center_position.x + tile_position.x, y = center_position.y + tile_position.y}
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
this.fluid_explosion_schedule[#this.fluid_explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
end
end
entity.die('player')
@ -932,24 +933,24 @@ local function on_entity_damaged(event)
end
local function on_tick(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local tick = event.tick
if ffatable.fluid_explosion_schedule then
if this.fluid_explosion_schedule then
local explosion_schedule_is_alive = false
for explosion_index = 1, #ffatable.fluid_explosion_schedule, 1 do
if #ffatable.fluid_explosion_schedule[explosion_index] > 0 then
for explosion_index = 1, #this.fluid_explosion_schedule, 1 do
if #this.fluid_explosion_schedule[explosion_index] > 0 then
explosion_schedule_is_alive = true
for radius = 1, #ffatable.fluid_explosion_schedule[explosion_index], 1 do
if ffatable.fluid_explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #ffatable.fluid_explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(ffatable.fluid_explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
for radius = 1, #this.fluid_explosion_schedule[explosion_index], 1 do
if this.fluid_explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #this.fluid_explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(this.fluid_explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
if not continue_explosion then
ffatable.fluid_explosion_schedule[explosion_index] = {}
this.fluid_explosion_schedule[explosion_index] = {}
break
end
end
if radius == #ffatable.fluid_explosion_schedule[explosion_index] then
ffatable.fluid_explosion_schedule[explosion_index] = {}
if radius == #this.fluid_explosion_schedule[explosion_index] then
this.fluid_explosion_schedule[explosion_index] = {}
end
break
end
@ -957,17 +958,10 @@ local function on_tick(event)
end
end
if not explosion_schedule_is_alive then
ffatable.fluid_explosion_schedule = nil
this.fluid_explosion_schedule = nil
end
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.fluid_explosion_schedule = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_tick, on_tick)

View File

@ -1,6 +1,7 @@
local Public = {}
local info = [[You wake up on this god-forsaken planet with a bunch of other desolate fools. Who will survive?
local info =
[[You wake up on this god-forsaken planet with a bunch of other desolate fools. Who will survive?
You can either
- Found a new town or join an existing one
@ -20,19 +21,21 @@ Survive as long as you can. Raid other towns. Defend your town.
# Advanced tips and tricks
It's best to found new towns far from existing towns, as enemies will become aggressive with town's research.
- It's best to found new towns far from existing towns, as enemies will become aggressive with town's research.
Biters and spitters become more aggressive towards towns that are advanced in research.
Their evolution will scale around technology progress in any nearby towns and pollution levels.
Are you out of ore patches? Make sure you researched steel processing,
then hand mine a few big rocks to find ore patches under them!
- Are you out of ore patches? Make sure you researched steel processing,
then hand mine a few big rocks to find ore patches under them!
The town market is the heart of your town. If it is destroyed, you lose everything.
So protect it well, repair it whenever possible, and if you can afford, increase its health by purchasing upgrades.
- The town market is the heart of your town. If it is destroyed, you lose everything.
So protect it well, repair it whenever possible, and if you can afford, increase its health by purchasing upgrades.
It's possible to automate trading with the town center! How cool is that?!! Try it out.
- It's possible to automate trading with the town center! How cool is that?!! Try it out.
When building your town, note that you may only build nearby existing structures such as your town market and walls and
any other structure you have placed. Beware that biters and spitters become more aggressive towards towns that are
advanced in research. Their evolution will scale around technology progress in any nearby towns and pollution levels.
- Fishes procreate near towns (the more fishes, the quicker they multiply)
- Use /rename-town (chat command) to rename your town
# Alliances
@ -74,7 +77,6 @@ function Public.show(player, info_type)
label.style.font_color = {r = 0.85, g = 0.85, b = 0.85}
label.style.right_padding = 8
frame.add {type = 'line'}
local cap = info
if info_type == 'adv' then

View File

@ -0,0 +1,22 @@
local Public = {}
local function initialize_limbo()
if game.surfaces['limbo'] then
-- clear the surface
game.surfaces['limbo'].clear(false)
else
game.create_surface('limbo')
end
local surface = game.surfaces['limbo']
surface.generate_with_lab_tiles = true
surface.peaceful_mode = true
surface.always_day = true
surface.freeze_daytime = true
surface.clear(true)
end
function Public.initialize()
initialize_limbo()
end
return Public

View File

@ -1,10 +1,12 @@
local Public = {}
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
function Public.reset()
local ffatable = Table.get_table()
if ffatable.testing_mode then return end
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for index = 1, table.size(game.forces), 1 do
local force = game.forces[index]
if force ~= nil then
@ -16,7 +18,9 @@ end
local function add_force(id, force_name)
local forces = rendering.get_forces(id)
for _, force in ipairs(forces) do
if force.name == force_name or force == force_name then return end
if force.name == force_name or force == force_name then
return
end
end
forces[#forces + 1] = force_name
rendering.set_forces(id, forces)
@ -40,8 +44,12 @@ local function on_chunk_charted(event)
local markets = surface.find_entities_filtered({area = area, name = 'market'})
for _, market in pairs(markets) do
local force_name = market.force.name
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force_name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force_name]
if not town_center then
return
end
-- town caption
local town_caption = town_center.town_caption
update_forces(town_caption)

View File

@ -3,71 +3,42 @@ require 'modules.flashlight_toggle_button'
require 'modules.global_chat_toggle'
require 'modules.scrap_towny_ffa.worms_create_oil_patches'
require 'modules.biters_yield_coins'
require 'modules.scrap_towny_ffa.mining'
require 'modules.scrap_towny_ffa.on_tick_schedule'
require 'modules.scrap_towny_ffa.building'
require 'modules.scrap_towny_ffa.spaceship'
require 'modules.scrap_towny_ffa.town_center'
require 'modules.scrap_towny_ffa.market'
require 'modules.scrap_towny_ffa.slots'
require 'modules.scrap_towny_ffa.wreckage_yields_scrap'
require 'modules.scrap_towny_ffa.rocks_yield_ore_veins'
require 'modules.scrap_towny_ffa.spawners_contain_biters'
require 'modules.scrap_towny_ffa.explosives_are_explosive'
require 'modules.scrap_towny_ffa.fluids_are_explosive'
require 'modules.scrap_towny_ffa.trap'
require 'modules.scrap_towny_ffa.turrets_drop_ammo'
require 'modules.scrap_towny_ffa.combat_balance'
require 'maps.scrap_towny_ffa.reset'
require 'maps.scrap_towny_ffa.mining'
require 'maps.scrap_towny_ffa.building'
require 'maps.scrap_towny_ffa.spaceship'
require 'maps.scrap_towny_ffa.town_center'
require 'maps.scrap_towny_ffa.market'
require 'maps.scrap_towny_ffa.slots'
require 'maps.scrap_towny_ffa.wreckage_yields_scrap'
require 'maps.scrap_towny_ffa.rocks_yield_ore_veins'
require 'maps.scrap_towny_ffa.spawners_contain_biters'
require 'maps.scrap_towny_ffa.explosives_are_explosive'
require 'maps.scrap_towny_ffa.fluids_are_explosive'
require 'maps.scrap_towny_ffa.trap'
require 'maps.scrap_towny_ffa.turrets_drop_ammo'
require 'maps.scrap_towny_ffa.combat_balance'
require 'maps.scrap_towny_ffa.vehicles'
local Event = require 'utils.event'
local Autostash = require 'modules.autostash'
local MapDefaults = require 'maps.scrap_towny_ffa.map_defaults'
local BottomFrame = require 'utils.gui.bottom_frame'
local Table = require 'modules.scrap_towny_ffa.table'
local Nauvis = require 'modules.scrap_towny_ffa.nauvis'
local Biters = require 'modules.scrap_towny_ffa.biters'
local Pollution = require 'modules.scrap_towny_ffa.pollution'
local Fish = require 'modules.scrap_towny_ffa.fish_reproduction'
local Info = require 'modules.scrap_towny_ffa.info'
local Team = require 'modules.scrap_towny_ffa.team'
local Spawn = require 'modules.scrap_towny_ffa.spawn'
local Radar = require 'modules.scrap_towny_ffa.limited_radar'
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Nauvis = require 'maps.scrap_towny_ffa.nauvis'
local Biters = require 'maps.scrap_towny_ffa.biters'
local Pollution = require 'maps.scrap_towny_ffa.pollution'
local Fish = require 'maps.scrap_towny_ffa.fish_reproduction'
local Team = require 'maps.scrap_towny_ffa.team'
local Radar = require 'maps.scrap_towny_ffa.limited_radar'
local Limbo = require 'maps.scrap_towny_ffa.limbo'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local mod_gui = require('mod-gui')
local Gui = require 'utils.gui'
local Color = require 'utils.color_presets'
local Where = require 'utils.commands.where'
local Inventory = require 'modules.show_inventory'
-- for testing purposes only!!!
local testing_mode = false
-- how long in ticks between spawn and death will be considered spawn kill (10 seconds)
local max_ticks_between_spawns = 60 * 10
-- how many players must login before teams are teams_enabled
local min_players_for_enabling_towns = 0
local function load_buffs(player)
if player.force.name ~= 'player' and player.force.name ~= 'rogue' then
return
end
local ffatable = Table.get_table()
local player_index = player.index
if player.character == nil then
return
end
if ffatable.buffs[player_index] == nil then
ffatable.buffs[player_index] = {}
end
if ffatable.buffs[player_index].character_inventory_slots_bonus ~= nil then
player.character.character_inventory_slots_bonus = ffatable.buffs[player_index].character_inventory_slots_bonus
end
if ffatable.buffs[player_index].character_mining_speed_modifier ~= nil then
player.character.character_mining_speed_modifier = ffatable.buffs[player_index].character_mining_speed_modifier
end
if ffatable.buffs[player_index].character_crafting_speed_modifier ~= nil then
player.character.character_crafting_speed_modifier = ffatable.buffs[player_index].character_crafting_speed_modifier
end
end
local function spairs(t, order)
local keys = {}
for k in pairs(t) do
@ -93,8 +64,8 @@ local function spairs(t, order)
end
local function init_score_board(player)
local ffatable = Table.get_table()
local saved_frame = ffatable.score_gui_frame[player.index]
local this = ScenarioTable.get_table()
local saved_frame = this.score_gui_frame[player.index]
if saved_frame and saved_frame.valid then
return
end
@ -102,14 +73,14 @@ local function init_score_board(player)
local flow = mod_gui.get_frame_flow(player)
local frame = flow.add {type = 'frame', style = mod_gui.frame_style, caption = 'Town survival', direction = 'vertical'}
frame.style.vertically_stretchable = false
ffatable.score_gui_frame[player.index] = frame
this.score_gui_frame[player.index] = frame
end
local function update_score()
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
for _, player in pairs(game.connected_players) do
local frame = ffatable.score_gui_frame[player.index]
local frame = this.score_gui_frame[player.index]
if not (frame and frame.valid) then
init_score_board(player)
end
@ -138,7 +109,7 @@ local function update_score()
end
local town_ages = {}
for _, town_center in pairs(ffatable.town_centers) do
for _, town_center in pairs(this.town_centers) do
if town_center ~= nil then
local age = game.tick - town_center.creation_tick
town_ages[town_center] = age
@ -154,13 +125,15 @@ local function update_score()
end
) do
local position = information_table.add {type = 'label', caption = '#' .. rank}
if town_center == ffatable.town_centers[player.force.name] then
if town_center == this.town_centers[player.force.name] then
position.style.font = 'default-semibold'
position.style.font_color = {r = 1, g = 1}
end
local label = information_table.add {type = 'label', caption = town_center.town_name ..
" (" .. #town_center.market.force.connected_players ..
"/" .. #town_center.market.force.players..")"}
local label =
information_table.add {
type = 'label',
caption = town_center.town_name .. ' (' .. #town_center.market.force.connected_players .. '/' .. #town_center.market.force.players .. ')'
}
label.style.font = 'default-semibold'
label.style.font_color = town_center.color
local age_hours = age / 60 / 3600
@ -171,137 +144,20 @@ local function update_score()
-- Outlander section
information_table.add {type = 'label', caption = '-'}
local outlander_on = #game.forces["player"].connected_players + #game.forces["rogue"].connected_players
local outlander_total = #game.forces["player"].players + #game.forces["rogue"].players
local outlander_on = #game.forces['player'].connected_players + #game.forces['rogue'].connected_players
local outlander_total = #game.forces['player'].players + #game.forces['rogue'].players
local label = information_table.add {type = 'label', caption = 'Outlanders' .. " (" .. outlander_on ..
"/" .. outlander_total ..")"}
local label =
information_table.add {
type = 'label',
caption = 'Outlanders' .. ' (' .. outlander_on .. '/' .. outlander_total .. ')'
}
label.style.font_color = {170, 170, 170}
information_table.add {type = 'label', caption = '-'}
end
end
end
local function on_player_joined_game(event)
local ffatable = Table.get_table()
local player = game.players[event.player_index]
local surface = game.surfaces['nauvis']
player.game_view_settings.show_entity_info = true
player.map_view_settings = {
['show-logistic-network'] = false,
['show-electric-network'] = false,
['show-turret-range'] = false,
['show-pollution'] = false,
['show-train-station-names'] = false,
['show-player-names'] = false,
['show-networkless-logistic-members'] = false,
['show-non-standard-map-info'] = false
}
--player.game_view_settings.show_side_menu = false
init_score_board(player)
Info.toggle_button(player)
Team.set_player_color(player)
if player.force ~= game.forces.player then
return
end
if player.online_time == 0 then
Info.show(player)
if testing_mode then
ffatable.towns_enabled = true
else
ffatable.players = ffatable.players + 1
if ffatable.players >= min_players_for_enabling_towns then
ffatable.towns_enabled = true
end
end
player.teleport({0, 0}, game.surfaces['limbo'])
Team.set_player_to_outlander(player)
Team.give_player_items(player)
Team.give_key(player.index)
if (testing_mode == true) then
player.cheat_mode = true
player.force.research_all_technologies()
player.insert {name = 'coin', count = 9900}
end
-- first time spawn point
local spawn_point = Spawn.get_new_spawn_point(player, surface)
ffatable.strikes[player.name] = 0
Spawn.clear_spawn_point(spawn_point, surface)
-- reset cooldown
ffatable.cooldowns_town_placement[player.index] = 0
ffatable.last_respawn[player.name] = 0
player.teleport(spawn_point, surface)
return
end
load_buffs(player)
if not ffatable.requests[player.index] or ffatable.requests[player.index] ~= 'kill-character' then
return
end
if player.character then
if player.character.valid then
local inventories = {
player.get_inventory(defines.inventory.character_main),
player.get_inventory(defines.inventory.character_guns),
player.get_inventory(defines.inventory.character_ammo),
player.get_inventory(defines.inventory.character_armor),
player.get_inventory(defines.inventory.character_vehicle),
player.get_inventory(defines.inventory.character_trash)
}
for _, i in pairs(inventories) do
i.clear()
end
player.character.die()
end
end
ffatable.requests[player.index] = nil
end
local function on_player_respawned(event)
local ffatable = Table.get_table()
local player = game.players[event.player_index]
local surface = player.surface
Team.give_player_items(player)
if player.force == game.forces['rogue'] then
Team.set_player_to_outlander(player)
end
if player.force == game.forces['player'] then
Team.give_key(player.index)
end
-- get_spawn_point will always return a valid spawn
local spawn_point = Spawn.get_spawn_point(player, surface)
-- reset cooldown
ffatable.last_respawn[player.name] = game.tick
player.teleport(spawn_point, surface)
load_buffs(player)
end
local function on_player_died(event)
local ffatable = Table.get_table()
local player = game.players[event.player_index]
if ffatable.strikes[player.name] == nil then
ffatable.strikes[player.name] = 0
end
local ticks_elapsed = game.tick - ffatable.last_respawn[player.name]
if ticks_elapsed < max_ticks_between_spawns then
ffatable.strikes[player.name] = ffatable.strikes[player.name] + 1
else
ffatable.strikes[player.name] = 0
end
end
local function on_init()
Autostash.insert_into_furnace(true)
Autostash.insert_into_wagon(true)
@ -316,17 +172,8 @@ local function on_init()
game.draw_resource_selection = true
game.disable_tutorial_triggers()
local ffatable = Table.get_table()
ffatable.last_respawn = {}
ffatable.last_death = {}
ffatable.strikes = {}
ffatable.score_gui_frame = {}
ffatable.testing_mode = testing_mode
ffatable.spawn_point = {}
ffatable.buffs = {}
ffatable.players = 0
ffatable.towns_enabled = true
MapDefaults.initialize()
Limbo.initialize()
Nauvis.initialize()
Team.initialize()
end
@ -377,13 +224,8 @@ local function ui_smell_evolution()
end
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.on_nth_tick(60, on_nth_tick) -- once every second
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_respawned, on_player_respawned)
Event.add(defines.events.on_player_died, on_player_died)
Event.on_nth_tick(60 * 30, ui_smell_evolution)
Event.on_nth_tick(60, update_score)
@ -411,3 +253,5 @@ Event.add(
end
end
)
require 'maps.scrap_towny_ffa.scrap_towny_ffa_layout'

View File

@ -0,0 +1,71 @@
local Public = {}
function Public.initialize()
-- difficulty settings
game.difficulty_settings.recipe_difficulty = defines.difficulty_settings.recipe_difficulty.normal
game.difficulty_settings.technology_difficulty = defines.difficulty_settings.technology_difficulty.normal
game.difficulty_settings.technology_price_multiplier = 0.50
game.difficulty_settings.research_queue_from_the_start = 'always'
-- pollution settings
game.map_settings.pollution.enabled = true
game.map_settings.pollution.diffusion_ratio = 0.02 -- amount that is diffused to neighboring chunk each second
game.map_settings.pollution.min_to_diffuse = 15 -- minimum number of pollution units on the chunk to start diffusing
game.map_settings.pollution.ageing = 1 -- percent of pollution eaten by a chunk's tiles per second
game.map_settings.pollution.expected_max_per_chunk = 150 -- anything greater than this number of pollution units is visualized similarly
game.map_settings.pollution.min_to_show_per_chunk = 50
game.map_settings.pollution.min_pollution_to_damage_trees = 60
game.map_settings.pollution.pollution_with_max_forest_damage = 150
game.map_settings.pollution.pollution_per_tree_damage = 50
game.map_settings.pollution.pollution_restored_per_tree_damage = 10
game.map_settings.pollution.max_pollution_to_restore_trees = 20
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 1
-- enemy evolution settings
game.map_settings.enemy_evolution.enabled = true
game.map_settings.enemy_evolution.time_factor = 0.0 -- percent increase in the evolution factor per second
game.map_settings.enemy_evolution.destroy_factor = 0.0 -- percent increase in the evolution factor for each spawner destroyed
game.map_settings.enemy_evolution.pollution_factor = 0.0 -- percent increase in the evolution factor for each pollution unit
-- enemy expansion settings
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_distance = 7 -- maximum distance in chunks from the nearest base (4 = 128 tiles)
game.map_settings.enemy_expansion.friendly_base_influence_radius = 4 -- consider other nests within radius number of chunks (2 = 64 tiles)
game.map_settings.enemy_expansion.other_base_coefficient = 2.0 -- multiply by coefficient for friendly bases
game.map_settings.enemy_expansion.neighbouring_base_chunk_coefficient = 0.4 -- multiply by coefficient for friendly bases (^distance)
game.map_settings.enemy_expansion.enemy_building_influence_radius = 4 -- consider player buildings within radius number of chunks
game.map_settings.enemy_expansion.building_coefficient = 1.0 -- multiply by coefficient for player buildings
game.map_settings.enemy_expansion.neighbouring_chunk_coefficient = 0.5 -- multiply by coefficient for player buildings (^distance)
game.map_settings.enemy_expansion.max_colliding_tiles_coefficient = 0.9 -- percent of unbuildable tiles to not be considered a candidate
game.map_settings.enemy_expansion.settler_group_min_size = 4 -- min size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.settler_group_max_size = 12 -- max size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.min_expansion_cooldown = 1200 -- minimum time before next expansion
game.map_settings.enemy_expansion.max_expansion_cooldown = 3600 -- maximum time before next expansion
-- unit group settings
game.map_settings.unit_group.min_group_gathering_time = 400
game.map_settings.unit_group.max_group_gathering_time = 2400
game.map_settings.unit_group.max_wait_time_for_late_members = 3600
game.map_settings.unit_group.max_group_radius = 30.0
game.map_settings.unit_group.min_group_radius = 5.0
game.map_settings.unit_group.max_member_speedup_when_behind = 1.4
game.map_settings.unit_group.max_member_slowdown_when_ahead = 0.6
game.map_settings.unit_group.max_group_slowdown_factor = 0.3
game.map_settings.unit_group.max_group_member_fallback_factor = 3
game.map_settings.unit_group.member_disown_distance = 10
game.map_settings.unit_group.tick_tolerance_when_member_arrives = 60
game.map_settings.unit_group.max_gathering_unit_groups = 30
game.map_settings.unit_group.max_unit_group_size = 200
---- steering settings
--game.map_settings.steering.default.radius = 1.2
--game.map_settings.steering.default.separation_force = 0.005
--game.map_settings.steering.default.separation_factor = 1.2
--game.map_settings.steering.default.force_unit_fuzzy_goto_behavior = false
--game.map_settings.steering.moving.radius = 3
--game.map_settings.steering.moving.separation_force = 0.01
--game.map_settings.steering.moving.separation_factor = 3
--game.map_settings.steering.moving.force_unit_fuzzy_goto_behavior = false
end
return Public

View File

@ -1,7 +1,7 @@
local table_insert = table.insert
local Table = require 'modules.scrap_towny_ffa.table'
local Town_center = require 'modules.scrap_towny_ffa.town_center'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Town_center = require 'maps.scrap_towny_ffa.town_center'
local upgrade_functions = {
-- Upgrade Town Center Health
@ -78,12 +78,12 @@ local upgrade_functions = {
end,
-- Set Spawn Point
[7] = function(town_center, player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local market = town_center.market
local force = market.force
local surface = market.surface
local spawn_point = force.get_spawn_position(surface)
ffatable.spawn_point[player.name] = spawn_point
this.spawn_point[player.name] = spawn_point
surface.play_sound({path = 'utility/scenario_message', position = player.position, volume_modifier = 1})
return false
end
@ -169,7 +169,7 @@ local function set_offers(town_center)
end
local function refresh_offers(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
local market = event.entity or event.market
if not market then
@ -181,7 +181,7 @@ local function refresh_offers(event)
if market.name ~= 'market' then
return
end
local town_center = ffatable.town_centers[market.force.name]
local town_center = this.town_centers[market.force.name]
if not town_center then
return
end
@ -192,19 +192,19 @@ local function refresh_offers(event)
if player.opened ~= nil then
player.opened = nil
player.surface.create_entity(
{
name = 'flying-text',
position = {market.position.x - 1.75, market.position.y},
text = 'Sorry, we are closed.',
color = {r = 1, g = 0.68, b = 0.26}
}
{
name = 'flying-text',
position = {market.position.x - 1.75, market.position.y},
text = 'Sorry, we are closed.',
color = {r = 1, g = 0.68, b = 0.26}
}
)
end
end
end
local function offer_purchased(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
local market = event.market
local offer_index = event.offer_index
@ -212,7 +212,7 @@ local function offer_purchased(event)
if not upgrade_functions[offer_index] then
return
end
local town_center = ffatable.town_centers[market.force.name]
local town_center = this.town_centers[market.force.name]
if not town_center then
return
end
@ -272,26 +272,34 @@ local function is_loader(entity)
end
local function is_filtered_inserter(entity)
return entity.name == 'filter-inserter' or entity.name == "stack-filter-inserter"
return entity.name == 'filter-inserter' or entity.name == 'stack-filter-inserter'
end
local function max_stack_size(entity)
if is_loader(entity) then return 1 end
if (entity.name == "stack-inserter" or entity.name == "stack-filter-inserter") then
if is_loader(entity) then
return 1
end
if (entity.name == 'stack-inserter' or entity.name == 'stack-filter-inserter') then
local override = entity.inserter_stack_size_override
if override > 0 then return override end
if override > 0 then
return override
end
local capacity = entity.force.stack_inserter_capacity_bonus
return 1 + capacity
else
local override = entity.inserter_stack_size_override
if override > 0 then return override end
if override > 0 then
return override
end
local bonus = entity.force.inserter_stack_size_bonus
return 1 + bonus
end
end
local function get_connected_entities(market)
if not market.valid then return {} end
if not market.valid then
return {}
end
local items = {
'burner-inserter',
'inserter',
@ -305,7 +313,7 @@ local function get_connected_entities(market)
'express-loader'
}
local items2 = {
'long-handed-inserter',
'long-handed-inserter'
}
local bb = market.bounding_box
local s = market.surface
@ -313,7 +321,7 @@ local function get_connected_entities(market)
local entities = s.find_entities_filtered({area = area, name = items})
local area2 = {left_top = {bb.left_top.x - 2, bb.left_top.y - 2}, right_bottom = {bb.right_bottom.x + 2, bb.right_bottom.y + 2}}
local entities2 = s.find_entities_filtered({area = area2, name = items2})
for k,v in pairs(entities2) do
for k, v in pairs(entities2) do
entities[k] = v
end
return entities
@ -335,19 +343,19 @@ end
local function get_loader_market_position(entity)
-- gets the position of the market relative to the loader
local position = {x=entity.position.x, y=entity.position.y}
local position = {x = entity.position.x, y = entity.position.y}
local orientation = entity.orientation
local type = entity.loader_type
if (orientation == 0.0 and type == "input") or (orientation == 0.5 and type == "output") then
if (orientation == 0.0 and type == 'input') or (orientation == 0.5 and type == 'output') then
position.y = position.y - 1.5
end
if (orientation == 0.25 and type == "input") or (orientation == 0.75 and type == "output") then
if (orientation == 0.25 and type == 'input') or (orientation == 0.75 and type == 'output') then
position.x = position.x + 1.5
end
if (orientation == 0.5 and type == "input") or (orientation == 0.0 and type == "output") then
if (orientation == 0.5 and type == 'input') or (orientation == 0.0 and type == 'output') then
position.y = position.y + 1.5
end
if (orientation == 0.75 and type == "input") or (orientation == 0.25 and type == "output") then
if (orientation == 0.75 and type == 'input') or (orientation == 0.25 and type == 'output') then
position.x = position.x - 1.5
end
return position
@ -405,7 +413,7 @@ local function trade_coin_for_items(town_center, market, trade)
town_center.output_buffer[item] = 0
end
while town_center.coin_balance - price >= 0 do
if town_center.output_buffer[item] == 0 then
if town_center.output_buffer[item] == 0 then
town_center.coin_balance = town_center.coin_balance - price
town_center.output_buffer[item] = town_center.output_buffer[item] + count
else
@ -419,7 +427,9 @@ local function handle_loader_output(town_center, market, entity, index)
local line = entity.get_transport_line(index)
-- get loader filters
local filter = get_loader_filter(entity, index)
if filter == nil then return end
if filter == nil then
return
end
if filter == 'coin' then
-- output for coins
while town_center.coin_balance > 0 and line.can_insert_at_back() do
@ -451,12 +461,16 @@ end
local function handle_inserter_output(town_center, market, entity)
-- get inserter filter
local filter = get_inserter_filter(entity)
if filter == nil then return end
if filter == nil then
return
end
local amount = max_stack_size(entity)
local stack = {name = 'coin', count = amount}
if filter == 'coin' then
-- output coins
if amount > town_center.coin_balance then amount = town_center.coin_balance end
if amount > town_center.coin_balance then
amount = town_center.coin_balance
end
stack.count = amount
if town_center.coin_balance > 0 then
town_center.coin_balance = town_center.coin_balance - amount
@ -622,26 +636,26 @@ local function get_entity_mode(market, entity)
if inside(ppos, bb) then
return 'output'
end
return "none"
return 'none'
end
end
local function handle_connected_entity(town_center, market, entity)
local mode = get_entity_mode(market, entity)
if mode == "input" then
if mode == 'input' then
handle_market_input(town_center, market, entity)
end
if mode == "output" then
if mode == 'output' then
handle_market_output(town_center, market, entity)
end
end
local function on_tick(_)
local ffatable = Table.get_table()
if not ffatable.town_centers then
local this = ScenarioTable.get_table()
if not this.town_centers then
return
end
for _, town_center in pairs(ffatable.town_centers) do
for _, town_center in pairs(this.town_centers) do
-- get connected entities on markets
local market = town_center.market
local entities = get_connected_entities(market)

View File

@ -1,4 +1,5 @@
local Table = require 'modules.scrap_towny_ffa.table'
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local crash_site = {
-- simple entity with owner
@ -51,12 +52,12 @@ local function mining_sound(player)
end
local function on_tick()
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
for index, player in pairs(game.players) do
if player.character ~= nil then
local mining = player.mining_state.mining
if ffatable.mining[index] ~= mining then
ffatable.mining[index] = mining
if this.mining[index] ~= mining then
this.mining[index] = mining
-- state change
if mining == true then
--log(player.name .. " started mining")
@ -68,14 +69,14 @@ local function on_tick()
if is_crash_site(target) then
-- mining crash site
mining_sound(player)
ffatable.mining_target[index] = target
this.mining_target[index] = target
end
end
else
--log(player.name .. " stopped mining")
local target = ffatable.mining_target[index]
local target = this.mining_target[index]
if target ~= nil then
ffatable.mining_target[index] = nil
this.mining_target[index] = nil
end
end
else
@ -95,13 +96,4 @@ local function on_tick()
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.mining = {}
ffatable.mining_entity = {}
ffatable.mining_target = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)

View File

@ -0,0 +1,224 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local math_random = math.random
local math_abs = math.abs
local table_shuffle = table.shuffle_table
local Public = {}
--local Server = require 'utils.server'
local map_width = 2560
local map_height = 2560
function Public.nuke(position)
local surface = game.surfaces['nauvis']
surface.create_entity({name = 'atomic-rocket', position = position, target = position, speed = 0.5})
end
function Public.armageddon()
local targets = {}
local offset = 1
local this = ScenarioTable.get_table()
for _, town_center in pairs(this.town_centers) do
local market = town_center.market
if market and market.valid then
for _ = 1, 5 do
local px = market.position.x + math_random(1, 256) - 128
local py = market.position.y + math_random(1, 256) - 128
targets[offset] = {x = px, y = py}
offset = offset + 1
end
targets[offset] = {x = market.position.x, y = market.position.y}
offset = offset + 1
end
end
for _, spaceship in pairs(this.spaceships) do
local market = spaceship.market
if market and market.valid then
for _ = 1, 5 do
local px = market.position.x + math_random(1, 256) - 128
local py = market.position.y + math_random(1, 256) - 128
targets[offset] = {x = px, y = py}
offset = offset + 1
end
targets[offset] = {x = market.position.x, y = market.position.y}
offset = offset + 1
end
end
table_shuffle(targets)
for i, pos in pairs(targets) do
local position = pos
local future = game.tick + i * 60
-- schedule to run this method again with a higher radius on next tick
if not this.nuke_tick_schedule[future] then
this.nuke_tick_schedule[future] = {}
end
this.nuke_tick_schedule[future][#this.nuke_tick_schedule[future] + 1] = {
callback = 'nuke',
params = {position}
}
end
end
local function get_seed()
local max = 4294967296
local salt = game.surfaces[1].map_gen_settings.seed
local seed = math_abs(salt + math_random(1, max)) % max + 1
return seed
end
function Public.initialize()
if game.surfaces['nauvis'] then
-- clear the surface
game.surfaces['nauvis'].clear(false)
end
local surface = game.surfaces['nauvis']
-- this overrides what is in the map_gen_settings.json file
local mgs = surface.map_gen_settings
mgs.default_enable_all_autoplace_controls = true -- don't mess with this!
mgs.autoplace_controls = {
coal = {frequency = 'none', size = 1, richness = 'normal'},
stone = {frequency = 'none', size = 1, richness = 'normal'},
['copper-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['iron-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['uranium-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['crude-oil'] = {frequency = 'very-low', size = 'very-small', richness = 'normal'},
trees = {frequency = 2, size = 'normal', richness = 'normal'},
['enemy-base'] = {frequency = 'very-high', size = 2, richness = 'normal'}
}
mgs.autoplace_settings = {
entity = {
settings = {
['rock-huge'] = {frequency = 2, size = 12, richness = 'very-high'},
['rock-big'] = {frequency = 3, size = 12, richness = 'very-high'},
['sand-rock-big'] = {frequency = 3, size = 12, richness = 1, 'very-high'}
}
},
decorative = {
settings = {
['rock-tiny'] = {frequency = 10, size = 'normal', richness = 'normal'},
['rock-small'] = {frequency = 5, size = 'normal', richness = 'normal'},
['rock-medium'] = {frequency = 2, size = 'normal', richness = 'normal'},
['sand-rock-small'] = {frequency = 10, size = 'normal', richness = 'normal'},
['sand-rock-medium'] = {frequency = 5, size = 'normal', richness = 'normal'}
}
}
}
mgs.cliff_settings = {
name = 'cliff',
cliff_elevation_0 = 5,
cliff_elevation_interval = 10,
richness = 0.4
}
-- water = 0 means no water allowed
-- water = 1 means elevation is not reduced when calculating water tiles (elevation < 0)
-- water = 2 means elevation is reduced by 10 when calculating water tiles (elevation < 0)
-- or rather, the water table is 10 above the normal elevation
mgs.water = 0.5
mgs.peaceful_mode = false
mgs.starting_area = 'none'
mgs.terrain_segmentation = 8
-- terrain size is 64 x 64 chunks, water size is 80 x 80
mgs.width = map_width
mgs.height = map_height
--mgs.starting_points = {
-- {x = 0, y = 0}
--}
-- here we put the named noise expressions for the specific noise-layer if we want to override them
mgs.property_expression_names = {
-- here we are overriding the moisture noise-layer with a fixed value of 0 to keep moisture consistently dry across the map
-- it allows to free up the moisture noise expression
-- low moisture
--moisture = 0,
-- here we are overriding the aux noise-layer with a fixed value to keep aux consistent across the map
-- it allows to free up the aux noise expression
-- aux should be not sand, nor red sand
--aux = 0.5,
-- here we are overriding the temperature noise-layer with a fixed value to keep temperature consistent across the map
-- it allows to free up the temperature noise expression
-- temperature should be 20C or 68F
--temperature = 20,
-- here we are overriding the cliffiness noise-layer with a fixed value of 0 to disable cliffs
-- it allows to free up the cliffiness noise expression (which may or may not be useful)
-- disable cliffs
--cliffiness = 0,
-- we can disable starting lakes two ways, one by setting starting-lake-noise-amplitude = 0
-- or by making the elevation a very large number
-- make sure starting lake amplitude is 0 to disable starting lakes
['starting-lake-noise-amplitude'] = 0,
-- allow enemies to get up close on spawn
['starting-area'] = 0,
-- this accepts a string representing a named noise expression
-- or number to determine the elevation based on x, y and distance from starting points
-- we can not add a named noise expression at this point, we can only reference existing ones
-- if we have any custom noise expressions defined from a mod, we will be able to use them here
-- setting it to a fixed number would mean a flat map
-- elevation < 0 means there is water unless the water table has been changed
--elevation = -1,
--elevation = 0,
--elevation-persistence = 0,
-- testing
--["control-setting:moisture:bias"] = 0.5,
--["control-setting:moisture:frequency:multiplier"] = 0,
--["control-setting:aux:bias"] = 0.5,
--["control-setting:aux:frequency:multiplier"] = 1,
--["control-setting:temperature:bias"] = 0.01,
--["control-setting:temperature:frequency:multiplier"] = 100,
--["tile:water:probability"] = -1000,
--["tile:deep-water:probability"] = -1000,
-- a constant intensity means base distribution will be consistent with regard to distance
['enemy-base-intensity'] = 1,
-- adjust this value to set how many nests spawn per tile
['enemy-base-frequency'] = 0.4,
-- this will make and average base radius around 12 tiles
['enemy-base-radius'] = 12
}
mgs.seed = get_seed(game.surfaces[1].map_gen_settings.seed)
surface.map_gen_settings = mgs
surface.peaceful_mode = false
surface.always_day = false
surface.freeze_daytime = false
surface.clear(true)
surface.regenerate_entity({'rock-huge', 'rock-big', 'sand-rock-big'})
surface.regenerate_decorative()
-- this will force generate the entire map
--Server.to_discord_embed('ScrapTownyFFA Map Regeneration in Progress')
--surface.request_to_generate_chunks({x=0,y=0},64)
--surface.force_generate_chunk_requests()
--Server.to_discord_embed('Regeneration Complete')
end
local function on_tick()
local this = ScenarioTable.get_table()
if not this.nuke_tick_schedule[game.tick] then
return
end
for _, token in pairs(this.nuke_tick_schedule[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'nuke' then
Public.nuke(params[1])
end
end
this.nuke_tick_schedule[game.tick] = nil
end
function Public.clear_nuke_schedule()
local this = ScenarioTable.get_table()
this.nuke_tick_schedule = {}
end
Event.add(defines.events.on_tick, on_tick)
return Public

View File

@ -0,0 +1,164 @@
local Public = {}
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Team = require 'maps.scrap_towny_ffa.team'
local Event = require 'utils.event'
local Spawn = require 'maps.scrap_towny_ffa.spawn'
local Info = require 'maps.scrap_towny_ffa.info'
-- how long in ticks between spawn and death will be considered spawn kill (10 seconds)
local max_ticks_between_spawns = 60 * 10
-- how many players must login before teams are teams_enabled
local min_players_for_enabling_towns = 0
function Public.settings(player)
player.game_view_settings.show_minimap = false
player.game_view_settings.show_map_view_options = false
player.game_view_settings.show_entity_info = true
player.map_view_settings = {
['show-logistic-network'] = false,
['show-electric-network'] = false,
['show-turret-range'] = false,
['show-pollution'] = false,
['show-train-station-names'] = false,
['show-player-names'] = false,
['show-networkless-logistic-members'] = false,
['show-non-standard-map-info'] = false
}
player.show_on_map = false
--player.game_view_settings.show_side_menu = false
end
function Public.initialize(player)
player.teleport({0, 0}, game.surfaces['limbo'])
Team.set_player_to_outlander(player)
Team.give_player_items(player)
player.insert {name = 'coin', count = '100'}
player.insert {name = 'stone-furnace', count = '1'}
Team.give_key(player.index)
local this = ScenarioTable.get()
if (this.testing_mode == true) then
player.cheat_mode = true
player.force.research_all_technologies()
player.insert {name = 'coin', count = '9900'}
end
end
function Public.spawn(player)
-- first time spawn point
local surface = game.surfaces['nauvis']
local spawn_point = Spawn.get_new_spawn_point(player, surface)
local this = ScenarioTable.get()
this.strikes[player.name] = 0
Spawn.clear_spawn_point(spawn_point, surface)
-- reset cooldown
this.cooldowns_town_placement[player.index] = 0
this.last_respawn[player.name] = 0
player.teleport(spawn_point, surface)
end
function Public.load_buffs(player)
if player.force.name ~= 'player' and player.force.name ~= 'rogue' then
return
end
local this = ScenarioTable.get()
local player_index = player.index
if player.character == nil then
return
end
if this.buffs[player_index] == nil then
this.buffs[player_index] = {}
end
if this.buffs[player_index].character_inventory_slots_bonus ~= nil then
player.character.character_inventory_slots_bonus = this.buffs[player_index].character_inventory_slots_bonus
end
if this.buffs[player_index].character_mining_speed_modifier ~= nil then
player.character.character_mining_speed_modifier = this.buffs[player_index].character_mining_speed_modifier
end
if this.buffs[player_index].character_crafting_speed_modifier ~= nil then
player.character.character_crafting_speed_modifier = this.buffs[player_index].character_crafting_speed_modifier
end
end
function Public.requests(player)
local this = ScenarioTable.get()
if this.requests[player.index] and this.requests[player.index] == 'kill-character' then
if player.character then
if player.character.valid then
player.character.die()
end
end
this.requests[player.index] = nil
end
end
function Public.increment()
local this = ScenarioTable.get()
local count = this.players + 1
this.players = count
if this.testing_mode then
this.towns_enabled = true
else
if this.players >= min_players_for_enabling_towns then
this.towns_enabled = true
end
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
Public.settings(player)
Info.toggle_button(player)
Team.set_player_color(player)
if player.online_time == 0 then
Public.increment()
Public.initialize(player)
Public.spawn(player)
Info.show(player)
end
Public.load_buffs(player)
Public.requests(player)
end
local function on_player_respawned(event)
local this = ScenarioTable.get()
local player = game.players[event.player_index]
local surface = player.surface
Team.give_player_items(player)
if player.force == game.forces['rogue'] then
Team.set_player_to_outlander(player)
end
if player.force == game.forces['player'] then
Team.give_key(player.index)
end
-- get_spawn_point will always return a valid spawn
local spawn_point = Spawn.get_spawn_point(player, surface)
-- reset cooldown
this.last_respawn[player.name] = game.tick
player.teleport(spawn_point, surface)
Public.load_buffs(player)
end
local function on_player_died(event)
local this = ScenarioTable.get()
local player = game.players[event.player_index]
if this.strikes[player.name] == nil then
this.strikes[player.name] = 0
end
local ticks_elapsed = game.tick - this.last_respawn[player.name]
if ticks_elapsed < max_ticks_between_spawns then
this.strikes[player.name] = this.strikes[player.name] + 1
else
this.strikes[player.name] = 0
end
end
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_respawned, on_player_respawned)
Event.add(defines.events.on_player_died, on_player_died)
return Public

View File

@ -1,8 +1,8 @@
local Public = {}
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local Scrap = require 'modules.scrap_towny_ffa.scrap'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local pollution_index = {
['small-biter'] = {min = 0.1, max = 0.1},
@ -46,11 +46,11 @@ local pollution_index = {
}
function Public.market_scent()
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
local town_centers = ffatable.town_centers
local town_centers = this.town_centers
if town_centers == nil then
return
end

View File

@ -0,0 +1,204 @@
local Event = require 'utils.event'
local Server = require 'utils.server'
local Alert = require 'utils.alert'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Nauvis = require 'maps.scrap_towny_ffa.nauvis'
local Team = require 'maps.scrap_towny_ffa.team'
local Player = require 'maps.scrap_towny_ffa.player'
local Color = require 'utils.color_presets'
local table_insert = table.insert
-- game duration in ticks
-- 7d * 24h * 60m * 60s * 60t
-- local game_duration = 36288000
local game_duration = 36288000
local armageddon_duration = 3600
local warning_duration = 600
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
local function on_rocket_launched(event)
local this = ScenarioTable.get()
local rocket = event.rocket
local tick = event.tick
local force_index = rocket.force.index
table_insert(this.rocket_launches, {force_index = force_index, tick = tick})
end
local function get_victorious_force()
local this = ScenarioTable.get_table()
if this.rocket_launches then
for _, launch in pairs(this.rocket_launches) do
local force = game.forces[launch.force_index]
if force.valid then
return force.name
end
end
end
return nil
end
local function warning()
Alert.alert_all_players(5, 'The world is ending!', Color.white, 'warning-white', 1.0)
end
local function armageddon()
if not get_victorious_force() then
Nauvis.armageddon()
end
end
local function reset_map()
local this = ScenarioTable.get_table()
if this.shutdown then
Server.to_discord_bold('*** Soft-reset is disabled! Server will shutdown. Most likely because of updates. ***', true)
return Server.stop_scenario()
end
if this.restart then
Server.to_discord_bold('*** Soft-reset is disabled! Server will restart to load new changes. ***', true)
return Server.start_scenario('Towny')
end
for _, player in pairs(game.players) do
local frame = this.score_gui_frame[player.index]
if frame and frame.valid then
frame.destroy()
end
end
ScenarioTable.reset_table()
local surface = game.surfaces['nauvis']
if get_victorious_force() then
surface.play_sound({path = 'utility/game_won', volume_modifier = 1})
else
surface.play_sound({path = 'utility/game_lost', volume_modifier = 1})
end
game.reset_time_played()
game.reset_game_state()
for _, player in pairs(game.players) do
player.teleport({0, 0}, game.surfaces['limbo'])
end
Nauvis.initialize()
Team.initialize()
if game.forces['rogue'] == nil then
log('rogue force is missing!')
end
for _, player in pairs(game.players) do
Player.increment()
Player.initialize(player)
Team.set_player_color(player)
Player.spawn(player)
Player.load_buffs(player)
Player.requests(player)
end
Alert.alert_all_players(5, 'The world has been reset!', Color.white, 'restart_required', 1.0)
Server.to_discord_embed('*** The world has been reset! ***')
end
local function on_tick()
local tick = game.tick
if tick > 0 then
if (tick + armageddon_duration + warning_duration) % game_duration == 0 then
warning()
end
if (tick + armageddon_duration) % game_duration == 0 then
armageddon()
end
if (tick + 1) % game_duration == 0 then
Nauvis.clear_nuke_schedule()
Team.reset_all_forces()
end
if tick % game_duration == 0 then
reset_map()
end
end
end
commands.add_command(
'scenario',
'Usable only for admins - controls the scenario!',
function(cmd)
local p
local player = game.player
if not player or not player.valid then
p = log
else
p = player.print
if not player.admin then
return
end
end
local this = ScenarioTable.get_table()
local param = cmd.parameter
if param == 'restart' or param == 'shutdown' or param == 'reset' or param == 'restartscenario' then
goto continue
else
p('[ERROR] Arguments are:\nrestart\nshutdown\nreset\nrestartscenario')
return
end
::continue::
if not this.reset_are_you_sure then
this.reset_are_you_sure = true
p('[WARNING] This command will disable the soft-reset feature, run this command again if you really want to do this!')
return
end
if param == 'restart' then
if this.restart then
this.reset_are_you_sure = nil
this.restart = false
this.soft_reset = true
p('[SUCCESS] Soft-reset is enabled.')
return
else
this.reset_are_you_sure = nil
this.restart = true
this.soft_reset = false
if this.shutdown then
this.shutdown = false
end
p('[WARNING] Soft-reset is disabled! Server will restart from scenario to load new changes.')
return
end
elseif param == 'restartscenario' then
this.reset_are_you_sure = nil
Server.start_scenario('Towny')
return
elseif param == 'shutdown' then
if this.shutdown then
this.reset_are_you_sure = nil
this.shutdown = false
this.soft_reset = true
p('[SUCCESS] Soft-reset is enabled.')
return
else
this.reset_are_you_sure = nil
this.shutdown = true
this.soft_reset = false
if this.restart then
this.restart = false
end
p('[WARNING] Soft-reset is disabled! Server will shutdown. Most likely because of updates.')
return
end
elseif param == 'reset' then
this.reset_are_you_sure = nil
if player and player.valid then
game.print(mapkeeper .. ' ' .. player.name .. ', has reset the game!', {r = 0.98, g = 0.66, b = 0.22})
else
game.print(mapkeeper .. ' server, has reset the game!', {r = 0.98, g = 0.66, b = 0.22})
end
reset_map()
p('[WARNING] Game has been reset!')
return
end
end
)
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_rocket_launched, on_rocket_launched)

View File

@ -3,7 +3,7 @@ local math_floor = math.floor
local table_insert = table.insert
local table_shuffle = table.shuffle_table
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local valid_entities = {
['rock-big'] = true,
@ -31,14 +31,14 @@ local function get_chances()
end
local function set_raffle()
local ffatable = Table.get_table()
ffatable.rocks_yield_ore_veins.raffle = {}
local this = ScenarioTable.get_table()
this.rocks_yield_ore_veins.raffle = {}
for _, t in pairs(get_chances()) do
for _ = 1, t[2], 1 do
table_insert(ffatable.rocks_yield_ore_veins.raffle, t[1])
table_insert(this.rocks_yield_ore_veins.raffle, t[1])
end
end
ffatable.rocks_yield_ore_veins.mixed_ores = {'iron-ore', 'copper-ore', 'stone', 'coal'}
this.rocks_yield_ore_veins.mixed_ores = {'iron-ore', 'copper-ore', 'stone', 'coal'}
end
local function get_amount()
@ -46,7 +46,7 @@ local function get_amount()
end
local function draw_chain(surface, count, ore, ore_entities, ore_positions)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local vectors = {{0, -0.75}, {-0.75, 0}, {0.75, 0}, {0, 0.75}}
local r = math_random(1, #ore_entities)
local position = {x = ore_entities[r].ore.position.x, y = ore_entities[r].ore.position.y}
@ -61,7 +61,7 @@ local function draw_chain(surface, count, ore, ore_entities, ore_positions)
local name = ore
if ore == 'mixed' then
name = ffatable.rocks_yield_ore_veins.mixed_ores[math_random(1, #ffatable.rocks_yield_ore_veins.mixed_ores)]
name = this.rocks_yield_ore_veins.mixed_ores[math_random(1, #this.rocks_yield_ore_veins.mixed_ores)]
end
if surface.can_place_entity({name = name, position = p, force = 'neutral'}) then
if math_random(1, 2) == 1 then
@ -95,10 +95,10 @@ local function draw_chain(surface, count, ore, ore_entities, ore_positions)
end
local function ore_vein(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = event.entity.surface
local size = size_raffle[math_random(1, #size_raffle)]
local ore = ffatable.rocks_yield_ore_veins.raffle[math_random(1, #ffatable.rocks_yield_ore_veins.raffle)]
local ore = this.rocks_yield_ore_veins.raffle[math_random(1, #this.rocks_yield_ore_veins.raffle)]
local icon
if game.entity_prototypes[ore] then
icon = '[img=entity/' .. ore .. ']'
@ -141,7 +141,7 @@ local function ore_vein(event)
ore_entities = {
{
ore = {
name = ffatable.rocks_yield_ore_veins.mixed_ores[math_random(1, #ffatable.rocks_yield_ore_veins.mixed_ores)],
name = this.rocks_yield_ore_veins.mixed_ores[math_random(1, #this.rocks_yield_ore_veins.mixed_ores)],
position = {x = position.x, y = position.y}
},
amount = get_amount()
@ -178,7 +178,7 @@ local function ore_vein(event)
end
local function on_player_mined_entity(event)
local rocks_yield_ore_veins = Table.get('rocks_yield_ore_veins')
local rocks_yield_ore_veins = ScenarioTable.get('rocks_yield_ore_veins')
if not rocks_yield_ore_veins then
return
end
@ -200,11 +200,11 @@ local function on_player_mined_entity(event)
end
local function on_init()
local ffatable = Table.get_table()
ffatable.rocks_yield_ore_veins = {}
ffatable.rocks_yield_ore_veins.raffle = {}
ffatable.rocks_yield_ore_veins.mixed_ores = {}
ffatable.rocks_yield_ore_veins.chance = 10
local this = ScenarioTable.get_table()
this.rocks_yield_ore_veins = {}
this.rocks_yield_ore_veins.raffle = {}
this.rocks_yield_ore_veins.mixed_ores = {}
this.rocks_yield_ore_veins.chance = 10
set_raffle()
end

View File

@ -4,8 +4,8 @@ local math_floor = math.floor
local math_abs = math.abs
local get_noise = require 'utils.get_noise'
local Table = require 'modules.scrap_towny_ffa.table'
local Scrap = require 'modules.scrap_towny_ffa.scrap'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local scrap_entities = {
-- simple entity with owner
@ -173,9 +173,9 @@ end
local size_of_scrap_raffle = #scrap_raffle
local function place_scrap(surface, position)
local ffatable = Table.get_table()
if ffatable.spaceships == nil then
ffatable.spaceships = {}
local this = ScenarioTable.get_table()
if this.spaceships == nil then
this.spaceships = {}
end
-- place turrets
if math_random(1, 700) == 1 then
@ -331,7 +331,7 @@ local function on_chunk_generated(event)
end
end
move_away_biteys(surface, event.area)
--ffatable.chunk_generated[key] = true
--this.chunk_generated[key] = true
end
local function on_chunk_charted(event)
@ -345,8 +345,8 @@ local function on_chunk_charted(event)
end
-- local on_init = function ()
-- local ffatable = Table.get_table()
-- ffatable.chunk_generated = {}
-- local this = ScenarioTable.get_table()
-- this.chunk_generated = {}
-- end
local Event = require 'utils.event'

View File

@ -1,8 +1,8 @@
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
-- called whenever a player places an item
local function on_built_entity(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local entity = event.created_entity
if not entity.valid then
return
@ -12,7 +12,7 @@ local function on_built_entity(event)
end
local player = game.players[event.player_index]
local force = player.force
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
local surface = entity.surface
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index or town_center == nil then
surface.create_entity(
@ -44,10 +44,10 @@ local function on_built_entity(event)
return
end
local key = script.register_on_entity_destroyed(entity)
if (ffatable.laser_turrets == nil) then
ffatable.laser_turrets = {}
if (this.laser_turrets == nil) then
this.laser_turrets = {}
end
ffatable.laser_turrets[key] = force.index
this.laser_turrets[key] = force.index
locations = locations + 1
town_center.upgrades.laser_turret.locations = locations
surface.create_entity(
@ -62,7 +62,7 @@ end
-- called whenever a robot places an item
local function on_robot_built_entity(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local entity = event.created_entity
if not entity.valid then
return
@ -72,7 +72,7 @@ local function on_robot_built_entity(event)
end
local robot = event.robot
local force = robot.force
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
local surface = entity.surface
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index or town_center == nil then
surface.create_entity(
@ -103,10 +103,10 @@ local function on_robot_built_entity(event)
return
end
local key = script.register_on_entity_destroyed(entity)
if (ffatable.laser_turrets == nil) then
ffatable.laser_turrets = {}
if (this.laser_turrets == nil) then
this.laser_turrets = {}
end
ffatable.laser_turrets[key] = force.index
this.laser_turrets[key] = force.index
locations = locations + 1
town_center.upgrades.laser_turret.locations = locations
surface.create_entity(
@ -122,15 +122,15 @@ end
-- called whenever a laser-turret is removed from the map
local function on_entity_destroyed(event)
local key = event.registration_number
local ffatable = Table.get_table()
if (ffatable.laser_turrets == nil) then
local this = ScenarioTable.get_table()
if (this.laser_turrets == nil) then
return
end
if (ffatable.laser_turrets[key] ~= nil) then
local index = ffatable.laser_turrets[key]
if (this.laser_turrets[key] ~= nil) then
local index = this.laser_turrets[key]
local force = game.forces[index]
if force ~= nil then
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
if town_center ~= nil then
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index or town_center == nil then
return

View File

@ -1,70 +1,70 @@
local table_insert = table.insert
local Table = require 'modules.scrap_towny_ffa.table'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Event = require 'utils.event'
local upgrade_functions = {
-- Upgrade Backpack
[1] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
if player.character.character_inventory_slots_bonus + 5 > 100 then
return false
end
player.character.character_inventory_slots_bonus = player.character.character_inventory_slots_bonus + 5
if not ffatable.buffs[player.index] then
ffatable.buffs[player.index] = {}
if not this.buffs[player.index] then
this.buffs[player.index] = {}
end
if not ffatable.buffs[player.index].character_inventory_slots_bonus then
ffatable.buffs[player.index].character_inventory_slots_bonus = 0
if not this.buffs[player.index].character_inventory_slots_bonus then
this.buffs[player.index].character_inventory_slots_bonus = 0
end
ffatable.buffs[player.index].character_inventory_slots_bonus = player.character.character_inventory_slots_bonus
this.buffs[player.index].character_inventory_slots_bonus = player.character.character_inventory_slots_bonus
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return true
end,
-- Upgrade Pickaxe Speed
[2] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
if player.character.character_mining_speed_modifier + 0.1 > 1 then
return false
end
player.character.character_mining_speed_modifier = player.character.character_mining_speed_modifier + 0.1
if not ffatable.buffs[player.index] then
ffatable.buffs[player.index] = {}
if not this.buffs[player.index] then
this.buffs[player.index] = {}
end
if not ffatable.buffs[player.index].character_mining_speed_modifier then
ffatable.buffs[player.index].character_mining_speed_modifier = 0
if not this.buffs[player.index].character_mining_speed_modifier then
this.buffs[player.index].character_mining_speed_modifier = 0
end
ffatable.buffs[player.index].character_mining_speed_modifier = player.character.character_mining_speed_modifier
this.buffs[player.index].character_mining_speed_modifier = player.character.character_mining_speed_modifier
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return true
end,
-- Upgrade Crafting Speed
[3] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
if player.character.character_crafting_speed_modifier + 0.1 > 1 then
return false
end
player.character.character_crafting_speed_modifier = player.character.character_crafting_speed_modifier + 0.1
if not ffatable.buffs[player.index] then
ffatable.buffs[player.index] = {}
if not this.buffs[player.index] then
this.buffs[player.index] = {}
end
if not ffatable.buffs[player.index].character_crafting_speed_modifier then
ffatable.buffs[player.index].character_crafting_speed_modifier = 0
if not this.buffs[player.index].character_crafting_speed_modifier then
this.buffs[player.index].character_crafting_speed_modifier = 0
end
ffatable.buffs[player.index].character_crafting_speed_modifier = player.character.character_crafting_speed_modifier
this.buffs[player.index].character_crafting_speed_modifier = player.character.character_crafting_speed_modifier
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return true
end,
-- Set Spawn Point
[4] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
local position = player.position
position = surface.find_non_colliding_position('character', position, 0, 0.25)
if position ~= nil and player ~= nil then
ffatable.spawn_point[player.name] = {x = position.x, y = position.y}
this.spawn_point[player.name] = {x = position.x, y = position.y}
surface.play_sound({path = 'utility/scenario_message', position = player.position, volume_modifier = 1})
else
surface.create_entity(
@ -168,7 +168,7 @@ local function refresh_offers(event)
return
end
local player = game.players[event.player_index]
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local market = event.entity or event.market
if not market then
return
@ -180,7 +180,7 @@ local function refresh_offers(event)
return
end
local position = market.position
local spaceship = ffatable.spaceships[position.x][position.y]
local spaceship = this.spaceships[position.x][position.y]
if not spaceship then
return
end
@ -189,7 +189,7 @@ local function refresh_offers(event)
end
local function offer_purchased(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
local market = event.market
local offer_index = event.offer_index
@ -197,7 +197,7 @@ local function offer_purchased(event)
if not upgrade_functions[offer_index] then
return
end
local spaceship = ffatable.spaceships[market.position.x][market.position.y]
local spaceship = this.spaceships[market.position.x][market.position.y]
if not spaceship then
return
end
@ -242,10 +242,10 @@ local function on_market_item_purchased(event)
end
local function kill_spaceship(entity)
local ffatable = Table.get_table()
local spaceship = ffatable.spaceships[entity.position.x][entity.position.y]
local this = ScenarioTable.get_table()
local spaceship = this.spaceships[entity.position.x][entity.position.y]
if spaceship ~= nil then
ffatable.spaceships[entity.position.x][entity.position.y] = nil
this.spaceships[entity.position.x][entity.position.y] = nil
end
end
@ -256,13 +256,6 @@ local function on_entity_died(event)
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.spaceships = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -8,9 +8,9 @@ local math_sin = math.sin
local math_cos = math.cos
local math_floor = math.floor
local Table = require 'modules.scrap_towny_ffa.table'
local Enemy = require 'modules.scrap_towny_ffa.enemy'
local Building = require 'modules.scrap_towny_ffa.building'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Enemy = require 'maps.scrap_towny_ffa.enemy'
local Building = require 'maps.scrap_towny_ffa.building'
-- don't spawn if town is within this range
local spawn_point_town_buffer = 256
@ -55,9 +55,9 @@ end
-- is the position already used
local function in_use(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local result = false
for _, v in pairs(ffatable.spawn_point) do
for _, v in pairs(this.spawn_point) do
if v == position then
result = true
end
@ -95,7 +95,7 @@ end
-- finds a valid spawn point that is not near a town and not in a polluted area
local function find_valid_spawn_point(force_name, surface)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
-- check center of map first if valid
local position = {x = 0, y = 0}
@ -114,13 +114,13 @@ local function find_valid_spawn_point(force_name, surface)
end
-- otherwise find a nearby town
local keyset = {}
for town_name, _ in pairs(ffatable.town_centers) do
for town_name, _ in pairs(this.town_centers) do
table_insert(keyset, town_name)
end
local count = table_size(keyset)
if count > 0 then
local town_name = keyset[math_random(1, count)]
local town_center = ffatable.town_centers[town_name]
local town_center = this.town_centers[town_name]
if town_center ~= nil then
position = town_center.market.position
end
@ -161,7 +161,7 @@ local function find_valid_spawn_point(force_name, surface)
end
function Public.get_new_spawn_point(player, surface)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
-- get a new spawn point
local position = {0, 0}
if player ~= nil then
@ -172,17 +172,17 @@ function Public.get_new_spawn_point(player, surface)
end
end
-- should never be invalid or blocked
ffatable.spawn_point[player.name] = position
this.spawn_point[player.name] = position
--log("player " .. player.name .. " assigned new spawn point at {" .. position.x .. "," .. position.y .. "}")
return position
end
-- gets a new or existing spawn point for the player
function Public.get_spawn_point(player, surface)
local ffatable = Table.get_table()
local position = ffatable.spawn_point[player.name]
local this = ScenarioTable.get_table()
local position = this.spawn_point[player.name]
-- if there is a spawn point and less than three strikes
if position ~= nil and ffatable.strikes[player.name] < 3 then
if position ~= nil and this.strikes[player.name] < 3 then
-- check that the spawn point is not blocked
if surface.can_place_entity({name = 'character', position = position}) then
--log("player " .. player.name .. "using existing spawn point at {" .. position.x .. "," .. position.y .. "}")

View File

@ -1,7 +1,7 @@
-- spawners release biters on death -- by mewmew
local math_random = math.random
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local biter_building_inhabitants = {
[1] = {{'small-biter', 8, 16}},

View File

@ -0,0 +1,71 @@
local Public = {}
-- one table to rule them all!
local Global = require 'utils.global'
local Event = require 'utils.event'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
function Public.reset_table()
this.key = {}
this.rocket_launches = {}
this.requests = {}
this.town_centers = {}
this.number_of_towns = 0
this.cooldowns_town_placement = {}
this.last_respawn = {}
this.last_death = {}
this.strikes = {}
this.score_gui_frame = {}
this.testing_mode = false
this.spawn_point = {}
this.buffs = {}
this.players = 0
this.towns_enabled = true
this.nuke_tick_schedule = {}
this.swarms = {}
this.explosion_schedule = {}
this.fluid_explosion_schedule = {}
this.mining = {}
this.mining_entity = {}
this.mining_target = {}
this.spaceships = {}
end
function Public.get_table()
return this
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
function Public.set(key, value)
if key and (value or value == false) then
this[key] = value
return this[key]
elseif key then
return this[key]
else
return this
end
end
Event.on_init(
function()
Public.reset_table()
end
)
return Public

View File

@ -6,8 +6,8 @@ local string_match = string.match
local string_lower = string.lower
local Server = require 'utils.server'
local Map = require 'modules.scrap_towny_ffa.map'
local Table = require 'modules.scrap_towny_ffa.table'
local Map = require 'maps.scrap_towny_ffa.map'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local outlander_color = {150, 150, 150}
local outlander_chat_color = {170, 170, 170}
@ -41,35 +41,6 @@ local destroy_robot_types = {
['logistic-robot'] = true
}
-- hand craftable
local player_force_disabled_recipes = {
'lab',
'automation-science-pack',
'steel-furnace',
'electric-furnace',
'stone-wall',
'stone-brick',
'radar'
}
local player_force_enabled_recipes = {
'submachine-gun',
'assembling-machine-1',
'small-lamp',
'shotgun',
'shotgun-shell',
'underground-belt',
'splitter',
'steel-plate',
'car',
'tank',
'engine-unit',
'constant-combinator',
'green-wire',
'red-wire',
'arithmetic-combinator',
'decider-combinator'
}
local function min_slots(slots)
local min = 0
for i = 1, 3, 1 do
@ -81,10 +52,14 @@ local function min_slots(slots)
end
local function can_force_accept_member(force)
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
if ffatable.member_limit == nil then
ffatable.member_limit = 1
if not force or not force.valid then
log('force nil or not valid!')
return
end
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
if this.member_limit == nil then
this.member_limit = 1
end
-- get the members of each force name into a table
@ -105,7 +80,7 @@ local function can_force_accept_member(force)
end
-- get the min of all slots
local member_limit = min_slots(slots) + 1
ffatable.member_limit = member_limit
this.member_limit = member_limit
if #force.connected_players >= member_limit then
game.print('>> Town ' .. force.name .. ' has too many settlers! Current limit (' .. member_limit .. ')', {255, 255, 0})
@ -114,53 +89,63 @@ local function can_force_accept_member(force)
return true
end
local function is_towny(force)
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index then
return false
end
return true
function Public.is_rogue(force)
return force.name == 'rogue'
end
function Public.is_outlander(force)
return force.name == 'player'
end
function Public.is_towny(force)
return force.name ~= 'rogue' and force.name ~= 'player'
end
function Public.has_key(index)
local ffatable = Table.get_table()
if ffatable.key == nil then
ffatable.key = {}
local this = ScenarioTable.get_table()
if this.key == nil then
this.key = {}
end
if ffatable.key[index] ~= nil then
return ffatable.key[index]
if this.key[index] ~= nil then
return this.key[index]
end
return false
end
function Public.give_key(index)
local ffatable = Table.get_table()
if ffatable.key == nil then
ffatable.key = {}
local this = ScenarioTable.get_table()
if this.key == nil then
this.key = {}
end
ffatable.key[index] = true
this.key[index] = true
end
function Public.remove_key(index)
local ffatable = Table.get_table()
if ffatable.key == nil then
ffatable.key = {}
local this = ScenarioTable.get_table()
if this.key == nil then
this.key = {}
end
ffatable.key[index] = false
this.key[index] = false
end
function Public.set_player_color(player)
local ffatable = Table.get_table()
if player.force.index == game.forces['player'].index then
if not player or not player.valid then
log('player nil or not valid!')
return
end
local this = ScenarioTable.get_table()
local force_name = player.force.name
if force_name == 'player' then
player.color = outlander_color
player.chat_color = outlander_chat_color
return
end
if player.force.index == game.forces['rogue'].index then
if force_name == 'rogue' then
player.color = rogue_color
player.chat_color = rogue_chat_color
return
end
local town_center = ffatable.town_centers[player.force.name]
local town_center = this.town_centers[player.force.name]
if not town_center then
return
end
@ -169,13 +154,13 @@ function Public.set_player_color(player)
end
local function set_town_color(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
if event.command ~= 'color' then
return
end
local player = game.players[event.player_index]
local force = player.force
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
if not town_center then
Public.set_player_color(player)
return
@ -194,6 +179,10 @@ function Public.set_all_player_colors()
end
local function reset_player(player)
if not player or not player.valid then
log('player nil or not valid!')
return
end
if player.character ~= nil then
local character = player.character
character.character_crafting_speed_modifier = 0.0
@ -203,14 +192,22 @@ local function reset_player(player)
end
function Public.add_player_to_town(player, town_center)
local ffatable = Table.get_table()
if not player or not player.valid then
log('player nil or not valid!')
return
end
if not town_center then
log('town_center nil!')
return
end
local this = ScenarioTable.get_table()
local market = town_center.market
local force = market.force
local surface = market.surface
reset_player(player)
player.force = market.force
Public.remove_key(player.index)
ffatable.spawn_point[player.name] = force.get_spawn_position(surface)
this.spawn_point[player.index] = force.get_spawn_position(surface)
game.permissions.get_group(force.name).add_player(player)
player.tag = ''
Map.enable_world_map(player)
@ -219,13 +216,17 @@ end
-- given to player upon respawn
function Public.give_player_items(player)
if not player or not player.valid then
log('player nil or not valid!')
return
end
player.clear_items_inside()
player.insert({name = 'raw-fish', count = 3})
player.insert({name = 'stone-furnace', count = 1})
end
function Public.set_player_to_outlander(player)
if player == nil then
if not player or not player.valid then
log('player nil or not valid!')
return
end
player.force = game.forces.player
@ -240,42 +241,52 @@ function Public.set_player_to_outlander(player)
end
local function set_player_to_rogue(player)
if player == nil then
if not player or not player.valid then
log('player nil or not valid!')
return
end
player.force = 'rogue'
if game.permissions.get_group('rogue') == nil then
game.permissions.create_group('rogue')
local group = game.permissions.get_group('rogue')
if group == nil then
group = game.permissions.create_group('rogue')
end
game.permissions.get_group('rogue').add_player(player)
group.add_player(player)
player.tag = '[Rogue]'
Map.disable_world_map(player)
Public.set_player_color(player)
end
local function ally_outlander(player, target)
local ffatable = Table.get_table()
if not player or not player.valid then
log('player nil or not valid!')
return
end
if not target or not target.valid then
log('target nil or not valid!')
return
end
local this = ScenarioTable.get_table()
local requesting_force = player.force
local target_force = target.force
-- don't handle if towns not yet enabled
if not ffatable.towns_enabled then
if not this.towns_enabled then
player.print('You must wait for more players to join!', {255, 255, 0})
return false
end
-- don't handle request if target is not a town
if not is_towny(requesting_force) and not is_towny(target_force) then
if not Public.is_towny(requesting_force) and not Public.is_towny(target_force) then
return false
end
-- don't handle request to another town if already in a town
if is_towny(requesting_force) and is_towny(target_force) then
if Public.is_towny(requesting_force) and Public.is_towny(target_force) then
return false
end
-- handle the request
if not is_towny(requesting_force) and is_towny(target_force) then
ffatable.requests[player.index] = target_force.name
if not Public.is_towny(requesting_force) and Public.is_towny(target_force) then
this.requests[player.index] = target_force.name
local target_player
if target.type == 'character' then
@ -285,14 +296,14 @@ local function ally_outlander(player, target)
end
if target_player then
if ffatable.requests[target_player.index] then
if ffatable.requests[target_player.index] == player.name then
if ffatable.town_centers[target_force.name] then
if this.requests[target_player.index] then
if this.requests[target_player.index] == player.name then
if this.town_centers[target_force.name] then
if not can_force_accept_member(target_force) then
return true
end
game.print('>> ' .. player.name .. ' has settled in ' .. target_force.name .. "'s Town!", {255, 255, 0})
Public.add_player_to_town(player, ffatable.town_centers[target_force.name])
Public.add_player_to_town(player, this.town_centers[target_force.name])
return true
end
end
@ -304,7 +315,7 @@ local function ally_outlander(player, target)
end
-- handle the approval
if is_towny(requesting_force) and not is_towny(target_force) then
if Public.is_towny(requesting_force) and not Public.is_towny(target_force) then
if target.type ~= 'character' then
return true
end
@ -312,10 +323,10 @@ local function ally_outlander(player, target)
if not target_player then
return true
end
ffatable.requests[player.index] = target_player.name
this.requests[player.index] = target_player.name
if ffatable.requests[target_player.index] then
if ffatable.requests[target_player.index] == player.force.name then
if this.requests[target_player.index] then
if this.requests[target_player.index] == player.force.name then
if not can_force_accept_member(player.force) then
return true
end
@ -324,7 +335,7 @@ local function ally_outlander(player, target)
else
game.print('>> ' .. player.name .. ' has accepted ' .. target_player.name .. ' into' .. player.force.name .. "'s Town!", {255, 255, 0})
end
Public.add_player_to_town(target_player, ffatable.town_centers[player.force.name])
Public.add_player_to_town(target_player, this.town_centers[player.force.name])
return true
end
end
@ -339,6 +350,14 @@ local function ally_outlander(player, target)
end
local function ally_neighbour_towns(player, target)
if not player or not player.valid then
log('player nil or not valid!')
return
end
if not target or not target.valid then
log('target nil or not valid!')
return
end
local requesting_force = player.force
local target_force = target.force
@ -355,6 +374,10 @@ local function ally_neighbour_towns(player, target)
end
local function ally_town(player, item)
if not player or not player.valid then
log('player nil or not valid!')
return
end
local position = item.position
local surface = player.surface
local area = {{position.x - item_drop_radius, position.y - item_drop_radius}, {position.x + item_drop_radius, position.y + item_drop_radius}}
@ -382,7 +405,11 @@ local function ally_town(player, item)
end
local function declare_war(player, item)
local ffatable = Table.get_table()
if not player or not player.valid then
log('player nil or not valid!')
return
end
local this = ScenarioTable.get_table()
local position = item.position
local surface = player.surface
local area = {{position.x - item_drop_radius, position.y - item_drop_radius}, {position.x + item_drop_radius, position.y + item_drop_radius}}
@ -394,7 +421,7 @@ local function declare_war(player, item)
return
end
local target_force = target.force
if not is_towny(target_force) then
if not Public.is_towny(target_force) then
return
end
@ -402,7 +429,7 @@ local function declare_war(player, item)
if player.name ~= target.force.name then
Public.set_player_to_outlander(player)
game.print('>> ' .. player.name .. ' has abandoned ' .. target_force.name .. "'s Town!", {255, 255, 0})
ffatable.requests[player.index] = nil
this.requests[player.index] = nil
end
if player.name == target.force.name then
if target.type ~= 'character' then
@ -417,12 +444,12 @@ local function declare_war(player, item)
end
Public.set_player_to_outlander(target_player)
game.print('>> ' .. player.name .. ' has banished ' .. target_player.name .. ' from their Town!', {255, 255, 0})
ffatable.requests[player.index] = nil
this.requests[player.index] = nil
end
return
end
if not is_towny(requesting_force) then
if not Public.is_towny(requesting_force) then
return
end
@ -433,6 +460,10 @@ local function declare_war(player, item)
end
local function delete_chart_tag_for_all_forces(market)
if not market or not market.valid then
log('market nil or not valid!')
return
end
local forces = game.forces
local position = market.position
local surface = market.surface
@ -448,6 +479,10 @@ local function delete_chart_tag_for_all_forces(market)
end
function Public.add_chart_tag(town_center)
if not town_center then
log('town_center nil or not valid!')
return
end
local market = town_center.market
local force = market.force
local position = market.position
@ -459,8 +494,8 @@ function Public.add_chart_tag(town_center)
end
function Public.update_town_chart_tags()
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
local forces = game.forces
for _, town_center in pairs(town_centers) do
local market = town_center.market
@ -574,8 +609,7 @@ local function disable_deconstruct(permission_group)
end
end
-- not in use
--[[ local function enable_artillery(force, permission_group)
local function enable_artillery(force, permission_group)
permission_group.set_allows_action(defines.input_action.use_artillery_remote, true)
force.technologies['artillery'].enabled = true
force.technologies['artillery-shell-range-1'].enabled = true
@ -584,7 +618,8 @@ end
force.recipes['artillery-wagon'].enabled = false
force.recipes['artillery-targeting-remote'].enabled = false
force.recipes['artillery-shell'].enabled = false
end ]]
end
local function disable_artillery(force, permission_group)
permission_group.set_allows_action(defines.input_action.use_artillery_remote, false)
force.technologies['artillery'].enabled = false
@ -642,14 +677,14 @@ end
-- setup a team force
function Public.add_new_force(force_name)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
-- disable permissions
local force = game.create_force(force_name)
local permission_group = game.permissions.create_group(force_name)
reset_permissions(permission_group)
enable_blueprints(permission_group)
enable_deconstruct(permission_group)
disable_artillery(force, permission_group)
enable_artillery(force, permission_group)
disable_spidertron(force, permission_group)
disable_rockets(force)
disable_nukes(force)
@ -664,12 +699,7 @@ function Public.add_new_force(force_name)
-- balance initial combat
force.set_ammo_damage_modifier('landmine', -0.75)
force.set_ammo_damage_modifier('grenade', -0.5)
--Give townys same tech as outlanders
local recipes = force.recipes
for _, recipe_name in pairs(player_force_enabled_recipes) do
recipes[recipe_name].enabled = true
end
if (ffatable.testing_mode == true) then
if (this.testing_mode == true) then
local e_force = game.forces['enemy']
e_force.set_friend(force, true) -- team force should not be attacked by turrets
e_force.set_cease_fire(force, true) -- team force should not be attacked by units
@ -679,10 +709,23 @@ function Public.add_new_force(force_name)
return force
end
function Public.reset_all_forces()
for _, force in pairs(game.forces) do
if force and force.valid then
if force.name ~= 'enemy' and force.name ~= 'player' and force.name ~= 'neutral' and force.name ~= 'rogue' then
game.merge_forces(force.name, 'player')
end
end
end
game.forces['enemy'].reset()
game.forces['neutral'].reset()
game.forces['player'].reset()
end
local function kill_force(force_name, cause)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local force = game.forces[force_name]
local town_center = ffatable.town_centers[force_name]
local town_center = this.town_centers[force_name]
local market = town_center.market
local position = market.position
local surface = market.surface
@ -690,14 +733,16 @@ local function kill_force(force_name, cause)
local town_name = town_center.town_name
surface.create_entity({name = 'big-artillery-explosion', position = position})
for _, player in pairs(force.players) do
ffatable.spawn_point[player.name] = nil
ffatable.cooldowns_town_placement[player.index] = game.tick + 3600 * 15
this.spawn_point[player.index] = nil
this.cooldowns_town_placement[player.index] = game.tick + 3600 * 5
this.buffs[player.index] = {}
if player.character then
player.character.die()
else
ffatable.requests[player.index] = 'kill-character'
this.requests[player.index] = 'kill-character'
end
player.force = game.forces.player
Map.disable_world_map(player)
Public.set_player_color(player)
Public.give_key(player.index)
end
@ -740,18 +785,18 @@ local function kill_force(force_name, cause)
end
game.merge_forces(force_name, 'neutral')
ffatable.town_centers[force_name] = nil
ffatable.number_of_towns = ffatable.number_of_towns - 1
this.town_centers[force_name] = nil
this.number_of_towns = this.number_of_towns - 1
delete_chart_tag_for_all_forces(market)
-- reward the killer
if cause == nil or not cause.valid then
Server.to_discord_embed(town_name .. ' has fallen!')
game.print('>> ' .. town_name .. ' has fallen!', {255, 255, 0})
Server.to_discord_embed(town_name .. ' has fallen to the biters!')
game.print('>> ' .. town_name .. ' has fallen to the biters!', {255, 255, 0})
return
end
if cause.force == nil then
Server.to_discord_embed(town_name .. ' has fallen!')
game.print('>> ' .. town_name .. ' has fallen!', {255, 255, 0})
Server.to_discord_embed(town_name .. ' has fallen to the biters!')
game.print('>> ' .. town_name .. ' has fallen to the biters!', {255, 255, 0})
return
end
if cause.force.name == 'player' or cause.force.name == 'rogue' then
@ -774,8 +819,8 @@ local function kill_force(force_name, cause)
end
else
if cause.force.name ~= 'enemy' then
if ffatable.town_centers[cause.force.name] ~= nil then
local killer_town_center = ffatable.town_centers[cause.force.name]
if this.town_centers[cause.force.name] ~= nil then
local killer_town_center = this.town_centers[cause.force.name]
if balance > 0 then
killer_town_center.coin_balance = killer_town_center.coin_balance + balance
end
@ -789,6 +834,35 @@ local function kill_force(force_name, cause)
end
end
-- hand craftable
local player_force_disabled_recipes = {
'lab',
'automation-science-pack',
'steel-furnace',
'electric-furnace',
'stone-wall',
'stone-brick',
'radar'
}
local player_force_enabled_recipes = {
'submachine-gun',
'assembling-machine-1',
'small-lamp',
'shotgun',
'shotgun-shell',
'underground-belt',
'splitter',
'steel-plate',
'car',
'tank',
'engine-unit',
'constant-combinator',
'green-wire',
'red-wire',
'arithmetic-combinator',
'decider-combinator'
}
local function setup_neutral_force()
local force = game.forces['neutral']
force.technologies['military'].researched = true
@ -807,7 +881,7 @@ end
-- setup the player force (this is the default for Outlanders)
local function setup_player_force()
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local force = game.forces.player
local permission_group = game.permissions.create_group('outlander')
-- disable permissions
@ -837,16 +911,18 @@ local function setup_player_force()
end
force.set_ammo_damage_modifier('landmine', -0.75)
force.set_ammo_damage_modifier('grenade', -0.5)
if (ffatable.testing_mode == true) then
if (this.testing_mode == true) then
force.enable_all_prototypes()
end
end
local function setup_rogue_force()
local ffatable = Table.get_table()
local force_name = 'rogue'
local force = game.create_force(force_name)
local permission_group = game.permissions.create_group(force_name)
local this = ScenarioTable.get_table()
local force = game.forces['rogue']
if game.forces['rogue'] == nil then
force = game.create_force('rogue')
end
local permission_group = game.permissions.create_group('rogue')
-- disable permissions
reset_permissions(permission_group)
disable_blueprints(permission_group)
@ -874,18 +950,18 @@ local function setup_rogue_force()
end
force.set_ammo_damage_modifier('landmine', -0.75)
force.set_ammo_damage_modifier('grenade', -0.5)
if (ffatable.testing_mode == true) then
if (this.testing_mode == true) then
force.enable_all_prototypes()
end
end
local function setup_enemy_force()
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local e_force = game.forces['enemy']
e_force.evolution_factor = 1 -- this should never change since we are changing biter types on spawn
e_force.set_friend(game.forces.player, true) -- outlander force (player) should not be attacked by turrets
e_force.set_cease_fire(game.forces.player, true) -- outlander force (player) should not be attacked by units
if (ffatable.testing_mode == true) then
if (this.testing_mode == true) then
e_force.set_friend(game.forces['rogue'], true) -- rogue force (rogue) should not be attacked by turrets
e_force.set_cease_fire(game.forces['rogue'], true) -- rogue force (rogue) should not be attacked by units
else
@ -895,6 +971,18 @@ local function setup_enemy_force()
end
end
local function reset_forces()
local players = game.players
local forces = game.forces
for i = 1, #players do
local player = players[i]
local force = forces[player.name]
if force then
game.merge_forces(force, 'player')
end
end
end
local function on_player_dropped_item(event)
local player = game.players[event.player_index]
local entity = event.entity
@ -918,7 +1006,7 @@ end
local function on_entity_damaged(event)
local entity = event.entity
if not entity.valid then
if not entity or not entity.valid then
return
end
local cause = event.cause
@ -929,41 +1017,67 @@ local function on_entity_damaged(event)
if cause ~= nil then
if cause.type == 'character' and force.index == game.forces['player'].index then
local player = cause.player
if player ~= nil and force.index == game.forces['player'].index then
if player and player.valid and force.index == game.forces['player'].index then
-- set the force of the player to rogue until they die or create a town
player.print('You have broken the peace with the biters. They will seek revenge!')
set_player_to_rogue(player)
end
end
-- cars and tanks
if cause.type == 'car' or cause.type == 'tank' then
local driver = cause.get_driver()
if driver ~= nil and driver.force.index == game.forces['player'].index then
-- set the force of the player to rogue until they die or create a town
set_player_to_rogue(driver)
if driver and driver.valid then
-- driver may be LuaEntity or LuaPlayer
local player = driver
if driver.object_name == 'LuaEntity' then
player = driver.player
end
if player and player.valid and player.force.index == game.forces['player'].index then
-- set the force of the player to rogue until they die or create a town
set_player_to_rogue(player)
end
end
local passenger = cause.get_passenger()
if passenger ~= nil and passenger.force.index == game.forces['player'].index then
-- set the force of the player to rogue until they die or create a town
set_player_to_rogue(passenger)
if passenger and passenger.valid then
-- passenger may be LuaEntity or LuaPlayer
local player = passenger
if passenger.object_name == 'LuaEntity' then
player = passenger.player
end
if player and player.valid and player.force.index == game.forces['player'].index then
-- set the force of the player to rogue until they die or create a town
set_player_to_rogue(player)
end
end
-- set the vehicle to rogue
cause.force = game.forces['rogue']
end
-- trains
if cause.type == 'locomotive' or cause.type == 'cargo-wagon' or cause.type == 'fluid-wagon' or cause.type == 'artillery-wagon' then
local train = cause.train
for _, passenger in pairs(train.passengers) do
if passenger ~= nil and passenger.force.index == game.forces['player'].index then
set_player_to_rogue(passenger)
if passenger and passenger.valid then
-- passenger may be LuaEntity or LuaPlayer
local player = passenger
if passenger.object_name == 'LuaEntity' then
player = passenger.player
end
if player and player.valid and player.force.index == game.forces['player'].index then
set_player_to_rogue(player)
end
end
end
cause.force = game.forces['rogue']
end
-- combat robots
if cause.type == 'combat-robot' then
local owner = cause.last_user
if owner ~= nil and owner.force == game.forces['player]'] then
local owner = cause.combat_robot_owner
if owner and owner.valid and owner.force == game.forces['player'] then
-- set the force of the player to rogue until they die or create a town
set_player_to_rogue(owner)
end
-- set the robot to rogue
cause.force = game.forces['rogue']
end
end
end
@ -972,7 +1086,7 @@ end
local function on_entity_died(event)
local entity = event.entity
local cause = event.cause
if entity ~= nil and entity.valid and entity.name == 'market' then
if entity and entity.valid and entity.name == 'market' then
kill_force(entity.force.name, cause)
end
end
@ -1006,21 +1120,14 @@ local function on_console_chat(event)
end
function Public.initialize()
reset_forces()
setup_neutral_force()
setup_player_force()
setup_rogue_force()
setup_enemy_force()
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.key = {}
ffatable.spawn_point = {}
ffatable.requests = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_player_dropped_item, on_player_dropped_item)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -5,12 +5,13 @@ local table_insert = table.insert
local math_floor = math.floor
local table_shuffle = table.shuffle_table
local Event = require 'utils.event'
local Server = require 'utils.server'
local Table = require 'modules.scrap_towny_ffa.table'
local Team = require 'modules.scrap_towny_ffa.team'
local Building = require 'modules.scrap_towny_ffa.building'
local Colors = require 'modules.scrap_towny_ffa.colors'
local Enemy = require 'modules.scrap_towny_ffa.enemy'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Team = require 'maps.scrap_towny_ffa.team'
local Building = require 'maps.scrap_towny_ffa.building'
local Colors = require 'maps.scrap_towny_ffa.colors'
local Enemy = require 'maps.scrap_towny_ffa.enemy'
local Color = require 'utils.color_presets'
local town_radius = 27
@ -135,17 +136,15 @@ local starter_supplies = {
local function count_nearby_ore(surface, position, ore_name)
local count = 0
local r = town_radius + 8
for _, e in pairs(
surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', name = ore_name})
) do
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', name = ore_name})) do
count = count + e.amount
end
return count
end
local function draw_town_spawn(player_name)
local ffatable = Table.get_table()
local market = ffatable.town_centers[player_name].market
local this = ScenarioTable.get_table()
local market = this.town_centers[player_name].market
local position = market.position
local surface = market.surface
@ -275,7 +274,7 @@ local function draw_town_spawn(player_name)
end
local function is_valid_location(force_name, surface, position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
if not surface.can_place_entity({name = 'market', position = position}) then
surface.create_entity(
{
@ -303,7 +302,7 @@ local function is_valid_location(force_name, surface, position)
end
end
if ffatable.number_of_towns > 48 then
if this.number_of_towns > 48 then
surface.create_entity(
{
name = 'flying-text',
@ -331,8 +330,8 @@ local function is_valid_location(force_name, surface, position)
end
function Public.in_any_town(position)
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
for _, town_center in pairs(town_centers) do
local market = town_center.market
if market ~= nil then
@ -345,14 +344,14 @@ function Public.in_any_town(position)
end
function Public.update_town_name(force)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
rendering.set_text(town_center.town_caption, town_center.town_name)
end
function Public.set_market_health(entity, final_damage_amount)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[entity.force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[entity.force.name]
town_center.health = math_floor(town_center.health - final_damage_amount)
if town_center.health > town_center.max_health then
town_center.health = town_center.max_health
@ -363,8 +362,8 @@ function Public.set_market_health(entity, final_damage_amount)
end
function Public.update_coin_balance(force)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
rendering.set_text(town_center.coins_text, 'Coins: ' .. town_center.coin_balance)
end
@ -402,8 +401,8 @@ local function found_town(event)
entity.destroy()
-- are towns enabled?
local ffatable = Table.get_table()
if not ffatable.towns_enabled then
local this = ScenarioTable.get_table()
if not this.towns_enabled then
player.print('You must wait for more players to join!', {255, 255, 0})
player.insert({name = 'stone-furnace', count = 1})
return
@ -423,13 +422,13 @@ local function found_town(event)
end
-- is town placement on cooldown?
if ffatable.cooldowns_town_placement[player.index] then
if game.tick < ffatable.cooldowns_town_placement[player.index] then
if this.cooldowns_town_placement[player.index] then
if game.tick < this.cooldowns_town_placement[player.index] then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = 'Town founding is on cooldown for ' .. math.ceil((ffatable.cooldowns_town_placement[player.index] - game.tick) / 3600) .. ' minutes.',
text = 'Town founding is on cooldown for ' .. math.ceil((this.cooldowns_town_placement[player.index] - game.tick) / 3600) .. ' minutes.',
color = {r = 0.77, g = 0.0, b = 0.0}
}
)
@ -446,8 +445,8 @@ local function found_town(event)
local force = Team.add_new_force(force_name)
ffatable.town_centers[force_name] = {}
local town_center = ffatable.town_centers[force_name]
this.town_centers[force_name] = {}
local town_center = this.town_centers[force_name]
town_center.town_name = player.name .. "'s Town"
town_center.market = surface.create_entity({name = 'market', position = position, force = force_name})
town_center.chunk_position = {math.floor(town_center.market.position.x / 32), math.floor(town_center.market.position.y / 32)}
@ -514,7 +513,7 @@ local function found_town(event)
scale_with_zoom = false
}
ffatable.number_of_towns = ffatable.number_of_towns + 1
this.number_of_towns = this.number_of_towns + 1
Enemy.clear_enemies(position, surface, town_radius * 5)
draw_town_spawn(force_name)
@ -561,13 +560,6 @@ local function on_entity_damaged(event)
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.town_centers = {}
ffatable.number_of_towns = 0
ffatable.cooldowns_town_placement = {}
end
local function rename_town(cmd)
local player = game.players[cmd.player_index]
if not player or not player.valid then
@ -583,8 +575,8 @@ local function rename_town(cmd)
player.print('Must specify new town name!', Color.fail)
return
end
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
local old_name = town_center.town_name
town_center.town_name = name
Public.update_town_name(force)
@ -610,8 +602,6 @@ commands.add_command(
end
)
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
--Event.add(defines.events.on_robot_repaired_entity, on_robot_repaired_entity)

View File

@ -1,10 +1,10 @@
local math_random = math.random
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local Town_center = require 'modules.scrap_towny_ffa.town_center'
local Scrap = require 'modules.scrap_towny_ffa.scrap'
local unearthing_worm = require 'modules.scrap_towny_ffa.unearthing_worm'
local unearthing_biters = require 'modules.scrap_towny_ffa.unearthing_biters'
local tick_tack_trap = require 'modules.scrap_towny_ffa.tick_tack_trap'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local Town_center = require 'maps.scrap_towny_ffa.town_center'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local unearthing_worm = require 'functions.unearthing_worm'
local unearthing_biters = require 'functions.unearthing_biters'
local tick_tack_trap = require 'functions.tick_tack_trap'
local function trap(entity)
-- check if within 32 blocks of market

View File

@ -0,0 +1,28 @@
local Event = require 'utils.event'
local Public = {}
local function on_player_driving_changed_state(event)
local player = game.players[event.player_index]
if not player or not player.valid then
return
end
local vehicle = player.vehicle
if vehicle and vehicle.valid then
-- player entered a vehicle
if vehicle.name == 'locomotive' or vehicle.name == 'cargo-wagon' or vehicle.name == 'fluid-wagon' then
vehicle.force = 'neutral'
else
-- includes cars, tanks and artillery-wagons
vehicle.force = player.force.name
end
else
-- player exited a vehicle
vehicle = event.entity
vehicle.force = 'neutral'
end
end
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
return Public

View File

@ -1,7 +1,7 @@
--wreckage yields scrap
local table_insert = table.insert
local Scrap = require 'modules.scrap_towny_ffa.scrap'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
-- loot chances and amounts for scrap entities

View File

@ -1,215 +0,0 @@
local Public = {}
--local Server = require 'utils.server'
local function create_limbo()
game.create_surface('limbo')
end
local function initialize_nauvis()
local surface = game.surfaces['nauvis']
-- this overrides what is in the map_gen_settings.json file
local mgs = surface.map_gen_settings
mgs.default_enable_all_autoplace_controls = true -- don't mess with this!
mgs.autoplace_controls = {
coal = {frequency = 2, size = 0.1, richness = 'very-low'},
stone = {frequency = 2, size = 0.1, richness = 'very-low'},
['copper-ore'] = {frequency = 7, size = 0.1, richness = 'very-low'},
['iron-ore'] = {frequency = 7, size = 0.1, richness = 'very-low'},
['uranium-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['crude-oil'] = {frequency = 2, size = 0.05, richness = 'very-low'},
trees = {frequency = 2, size = 'normal', richness = 'normal'},
['enemy-base'] = {frequency = 'very-high', size = 2, richness = 'normal'}
}
mgs.autoplace_settings = {
entity = {
settings = {
['rock-huge'] = {frequency = 2, size = 3, richness = 'very-high'},
['rock-big'] = {frequency = 2, size = 3, richness = 'very-high'},
['sand-rock-big'] = {frequency = 2, size = 3, richness = 1, 'very-high'}
}
},
decorative = {
settings = {
['rock-tiny'] = {frequency = 10, size = 'normal', richness = 'normal'},
['rock-small'] = {frequency = 5, size = 'normal', richness = 'normal'},
['rock-medium'] = {frequency = 2, size = 'normal', richness = 'normal'},
['sand-rock-small'] = {frequency = 10, size = 'normal', richness = 'normal'},
['sand-rock-medium'] = {frequency = 5, size = 'normal', richness = 'normal'}
}
}
}
mgs.cliff_settings = {
name = 'cliff',
cliff_elevation_0 = 5,
cliff_elevation_interval = 10,
richness = 0.4
}
-- water = 0 means no water allowed
-- water = 1 means elevation is not reduced when calculating water tiles (elevation < 0)
-- water = 2 means elevation is reduced by 10 when calculating water tiles (elevation < 0)
-- or rather, the water table is 10 above the normal elevation
mgs.water = 0.5
mgs.peaceful_mode = false
mgs.starting_area = 'none'
mgs.terrain_segmentation = 8
-- terrain size is 64 x 64 chunks, water size is 80 x 80
mgs.width = 2560
mgs.height = 2560
--mgs.starting_points = {
-- {x = 0, y = 0}
--}
mgs.research_queue_from_the_start = 'always'
-- here we put the named noise expressions for the specific noise-layer if we want to override them
mgs.property_expression_names = {
-- here we are overriding the moisture noise-layer with a fixed value of 0 to keep moisture consistently dry across the map
-- it allows to free up the moisture noise expression
-- low moisture
--moisture = 0,
-- here we are overriding the aux noise-layer with a fixed value to keep aux consistent across the map
-- it allows to free up the aux noise expression
-- aux should be not sand, nor red sand
--aux = 0.5,
-- here we are overriding the temperature noise-layer with a fixed value to keep temperature consistent across the map
-- it allows to free up the temperature noise expression
-- temperature should be 20C or 68F
--temperature = 20,
-- here we are overriding the cliffiness noise-layer with a fixed value of 0 to disable cliffs
-- it allows to free up the cliffiness noise expression (which may or may not be useful)
-- disable cliffs
--cliffiness = 0,
-- we can disable starting lakes two ways, one by setting starting-lake-noise-amplitude = 0
-- or by making the elevation a very large number
-- make sure starting lake amplitude is 0 to disable starting lakes
['starting-lake-noise-amplitude'] = 0,
-- allow enemies to get up close on spawn
['starting-area'] = 0,
-- this accepts a string representing a named noise expression
-- or number to determine the elevation based on x, y and distance from starting points
-- we can not add a named noise expression at this point, we can only reference existing ones
-- if we have any custom noise expressions defined from a mod, we will be able to use them here
-- setting it to a fixed number would mean a flat map
-- elevation < 0 means there is water unless the water table has been changed
--elevation = -1,
--elevation = 0,
--elevation-persistence = 0,
-- testing
--["control-setting:moisture:bias"] = 0.5,
--["control-setting:moisture:frequency:multiplier"] = 0,
--["control-setting:aux:bias"] = 0.5,
--["control-setting:aux:frequency:multiplier"] = 1,
--["control-setting:temperature:bias"] = 0.01,
--["control-setting:temperature:frequency:multiplier"] = 100,
--["tile:water:probability"] = -1000,
--["tile:deep-water:probability"] = -1000,
-- a constant intensity means base distribution will be consistent with regard to distance
['enemy-base-intensity'] = 1,
-- adjust this value to set how many nests spawn per tile
['enemy-base-frequency'] = 0.4,
-- this will make and average base radius around 12 tiles
['enemy-base-radius'] = 12
}
mgs.seed = game.surfaces[1].map_gen_settings.seed
surface.map_gen_settings = mgs
surface.peaceful_mode = false
surface.always_day = false
surface.freeze_daytime = false
surface.clear(true)
surface.regenerate_entity({'rock-huge', 'rock-big', 'sand-rock-big'})
surface.regenerate_decorative()
-- this will force generate the entire map
--Server.to_discord_embed('ScrapTownyFFA Map Regeneration in Progress')
--surface.request_to_generate_chunks({x=0,y=0},64)
--surface.force_generate_chunk_requests()
--Server.to_discord_embed('Regeneration Complete')
end
local function initialize_limbo()
local surface = game.surfaces['limbo']
surface.generate_with_lab_tiles = true
surface.peaceful_mode = true
surface.always_day = true
surface.freeze_daytime = true
surface.clear(true)
end
function Public.initialize()
-- difficulty settings
game.difficulty_settings.recipe_difficulty = defines.difficulty_settings.recipe_difficulty.normal
game.difficulty_settings.technology_difficulty = defines.difficulty_settings.technology_difficulty.normal
game.difficulty_settings.technology_price_multiplier = 0.50
-- pollution settings
game.map_settings.pollution.enabled = true
game.map_settings.pollution.diffusion_ratio = 0.02 -- amount that is diffused to neighboring chunk each second
game.map_settings.pollution.min_to_diffuse = 15 -- minimum number of pollution units on the chunk to start diffusing
game.map_settings.pollution.ageing = 1 -- percent of pollution eaten by a chunk's tiles per second
game.map_settings.pollution.expected_max_per_chunk = 150 -- anything greater than this number of pollution units is visualized similarly
game.map_settings.pollution.min_to_show_per_chunk = 50
game.map_settings.pollution.min_pollution_to_damage_trees = 60
game.map_settings.pollution.pollution_with_max_forest_damage = 150
game.map_settings.pollution.pollution_per_tree_damage = 50
game.map_settings.pollution.pollution_restored_per_tree_damage = 10
game.map_settings.pollution.max_pollution_to_restore_trees = 20
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 1
-- enemy evolution settings
game.map_settings.enemy_evolution.enabled = true
game.map_settings.enemy_evolution.time_factor = 0.0 -- percent increase in the evolution factor per second
game.map_settings.enemy_evolution.destroy_factor = 0.0 -- percent increase in the evolution factor for each spawner destroyed
game.map_settings.enemy_evolution.pollution_factor = 0.0 -- percent increase in the evolution factor for each pollution unit
-- enemy expansion settings
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_distance = 7 -- maximum distance in chunks from the nearest base (4 = 128 tiles)
game.map_settings.enemy_expansion.friendly_base_influence_radius = 4 -- consider other nests within radius number of chunks (2 = 64 tiles)
game.map_settings.enemy_expansion.other_base_coefficient = 2.0 -- multiply by coefficient for friendly bases
game.map_settings.enemy_expansion.neighbouring_base_chunk_coefficient = 0.4 -- multiply by coefficient for friendly bases (^distance)
game.map_settings.enemy_expansion.enemy_building_influence_radius = 4 -- consider player buildings within radius number of chunks
game.map_settings.enemy_expansion.building_coefficient = 1.0 -- multiply by coefficient for player buildings
game.map_settings.enemy_expansion.neighbouring_chunk_coefficient = 0.5 -- multiply by coefficient for player buildings (^distance)
game.map_settings.enemy_expansion.max_colliding_tiles_coefficient = 0.9 -- percent of unbuildable tiles to not be considered a candidate
game.map_settings.enemy_expansion.settler_group_min_size = 4 -- min size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.settler_group_max_size = 12 -- max size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.min_expansion_cooldown = 1200 -- minimum time before next expansion
game.map_settings.enemy_expansion.max_expansion_cooldown = 3600 -- maximum time before next expansion
-- unit group settings
game.map_settings.unit_group.min_group_gathering_time = 400
game.map_settings.unit_group.max_group_gathering_time = 2400
game.map_settings.unit_group.max_wait_time_for_late_members = 3600
game.map_settings.unit_group.max_group_radius = 30.0
game.map_settings.unit_group.min_group_radius = 5.0
game.map_settings.unit_group.max_member_speedup_when_behind = 1.4
game.map_settings.unit_group.max_member_slowdown_when_ahead = 0.6
game.map_settings.unit_group.max_group_slowdown_factor = 0.3
game.map_settings.unit_group.max_group_member_fallback_factor = 3
game.map_settings.unit_group.member_disown_distance = 10
game.map_settings.unit_group.tick_tolerance_when_member_arrives = 60
game.map_settings.unit_group.max_gathering_unit_groups = 30
game.map_settings.unit_group.max_unit_group_size = 200
---- steering settings
--game.map_settings.steering.default.radius = 1.2
--game.map_settings.steering.default.separation_force = 0.005
--game.map_settings.steering.default.separation_factor = 1.2
--game.map_settings.steering.default.force_unit_fuzzy_goto_behavior = false
--game.map_settings.steering.moving.radius = 3
--game.map_settings.steering.moving.separation_force = 0.01
--game.map_settings.steering.moving.separation_factor = 3
--game.map_settings.steering.moving.force_unit_fuzzy_goto_behavior = false
create_limbo()
initialize_limbo()
initialize_nauvis()
end
return Public

View File

@ -1,21 +0,0 @@
local Table = require 'modules.scrap_towny_ffa.table'
local function on_tick()
local ffatable = Table.get_table()
if not ffatable.on_tick_schedule[game.tick] then
return
end
for _, schedule in pairs(ffatable.on_tick_schedule[game.tick]) do
schedule.func(unpack(schedule.args))
end
ffatable.on_tick_schedule[game.tick] = nil
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.on_tick_schedule = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)

View File

@ -1,49 +0,0 @@
local Public = {}
-- one table to rule them all!
local Global = require 'utils.global'
local ffatable = {}
Global.register(
ffatable,
function(tbl)
ffatable = tbl
end
)
function Public.reset_table()
for k, _ in pairs(ffatable) do
ffatable[k] = nil
end
end
function Public.get_table()
return ffatable
end
function Public.get(key)
if key then
return ffatable[key]
else
return ffatable
end
end
function Public.set(key, value)
if key and (value or value == false) then
ffatable[key] = value
return ffatable[key]
elseif key then
return ffatable[key]
else
return ffatable
end
end
local on_init = function()
Public.reset_table()
end
local Event = require 'utils.event'
Event.on_init(on_init)
return Public

View File

@ -1,112 +0,0 @@
-- timer traps -- by mewmew
local table_insert = table.insert
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local tick_tacks = {'*tick*', '*tick*', '*tack*', '*tak*', '*tik*', '*tok*'}
local kaboom_weights = {
{name = 'grenade', chance = 7},
{name = 'cluster-grenade', chance = 1},
{name = 'destroyer-capsule', chance = 1},
{name = 'defender-capsule', chance = 4},
{name = 'distractor-capsule', chance = 3},
{name = 'poison-capsule', chance = 2},
{name = 'explosive-uranium-cannon-projectile', chance = 3},
{name = 'explosive-cannon-projectile', chance = 5}
}
local kabooms = {}
for _, t in pairs(kaboom_weights) do
for _ = 1, t.chance, 1 do
table_insert(kabooms, t.name)
end
end
local function create_flying_text(surface, position, text)
surface.create_entity(
{
name = 'flying-text',
position = position,
text = text,
color = {r = 0.75, g = 0.75, b = 0.75}
}
)
if text == '...' then
return
end
surface.play_sound({path = 'utility/armor_insert', position = position, volume_modifier = 0.75})
end
local function create_kaboom(surface, position, name)
local target = position
local speed = 0.5
if name == 'defender-capsule' or name == 'destroyer-capsule' or name == 'distractor-capsule' then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = '(((Sentries Engaging Target)))',
color = {r = 0.8, g = 0.0, b = 0.0}
}
)
local nearest_player_unit = surface.find_nearest_enemy({position = position, max_distance = 128, force = 'enemy'})
if nearest_player_unit then
target = nearest_player_unit.position
end
speed = 0.001
end
surface.create_entity(
{
name = name,
position = position,
force = 'enemy',
target = target,
speed = speed
}
)
end
local function tick_tack_trap(surface, position)
local ffatable = Table.get_table()
if not surface then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local tick_tack_count = math_random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not ffatable.on_tick_schedule[game.tick + t] then
ffatable.on_tick_schedule[game.tick + t] = {}
end
if t < tick_tack_count * 60 then
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_flying_text,
args = {surface, {x = position.x, y = position.y}, tick_tacks[math_random(1, #tick_tacks)]}
}
else
if math_random(1, 10) == 1 then
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_flying_text,
args = {surface, {x = position.x, y = position.y}, '...'}
}
else
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_kaboom,
args = {surface, {x = position.x, y = position.y}, kabooms[math_random(1, #kabooms)]}
}
end
end
end
end
return tick_tack_trap

View File

@ -1,104 +0,0 @@
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local function create_particles(surface, position, amount)
if not surface.valid then
return
end
for _ = 1, amount, 1 do
local m = math_random(6, 12)
local m2 = m * 0.005
surface.create_particle(
{
name = 'stone-particle',
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
}
)
end
end
local function spawn_biter(surface, position, evolution)
if not surface.valid then
return
end
local evo = math.floor(evolution * 1000)
local biter_chances = {
{name = 'small-biter', chance = math.floor(1000 - (evo * 1.6))},
{name = 'small-spitter', chance = math.floor(500 - evo * 0.8)},
{name = 'medium-biter', chance = -150 + evo},
{name = 'medium-spitter', chance = -75 + math.floor(evo * 0.5)},
{name = 'big-biter', chance = math.floor((evo - 500) * 3)},
{name = 'big-spitter', chance = math.floor((evo - 500) * 2)},
{name = 'behemoth-biter', chance = math.floor((evo - 800) * 6)},
{name = 'behemoth-spitter', chance = math.floor((evo - 800) * 4)}
}
local max_chance = 0
for i = 1, 8, 1 do
if biter_chances[i].chance < 0 then
biter_chances[i].chance = 0
end
max_chance = max_chance + biter_chances[i].chance
end
local r = math_random(1, max_chance)
local current_chance = 0
for i = 1, 8, 1 do
current_chance = current_chance + biter_chances[i].chance
if r <= current_chance then
local biter_name = biter_chances[i].name
local p = surface.find_non_colliding_position(biter_name, position, 10, 1)
if not p then
return
end
surface.create_entity({name = biter_name, position = p, force = 'enemy'})
return
end
end
end
local function unearthing_biters(surface, position, amount, relative_evolution)
local ffatable = Table.get_table()
if not surface then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local ticks = amount * 30
ticks = ticks + 90
for t = 1, ticks, 1 do
if not ffatable.on_tick_schedule[game.tick + t] then
ffatable.on_tick_schedule[game.tick + t] = {}
end
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_particles,
args = {surface, {x = position.x, y = position.y}, 4}
}
if t > 90 then
if t % 30 == 29 then
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = spawn_biter,
args = {surface, {x = position.x, y = position.y}, relative_evolution}
}
end
end
end
end
return unearthing_biters

View File

@ -1,87 +0,0 @@
local math_random = math.random
local math_ceil = math.ceil
local Table = require 'modules.scrap_towny_ffa.table'
local function create_particles(surface, position, amount)
if not surface.valid then
return
end
for _ = 1, amount, 1 do
local m = math_random(8, 24)
local m2 = m * 0.005
surface.create_particle(
{
name = 'stone-particle',
position = position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
}
)
end
end
local function spawn_worm(surface, position, evolution_index)
if not surface.valid then
return
end
local worm_raffle_table = {
[1] = {'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'small-worm-turret'},
[2] = {'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'medium-worm-turret'},
[3] = {'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'medium-worm-turret', 'medium-worm-turret'},
[4] = {'small-worm-turret', 'small-worm-turret', 'small-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret'},
[5] = {'small-worm-turret', 'small-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret'},
[6] = {'small-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret'},
[7] = {'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret', 'big-worm-turret'},
[8] = {'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret', 'big-worm-turret'},
[9] = {'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret', 'big-worm-turret', 'big-worm-turret'},
[10] = {'medium-worm-turret', 'medium-worm-turret', 'medium-worm-turret', 'big-worm-turret', 'big-worm-turret', 'big-worm-turret'}
}
local raffle = worm_raffle_table[evolution_index]
local worm_name = raffle[math_random(1, #raffle)]
surface.create_entity({name = worm_name, position = position})
end
local function unearthing_worm(surface, position, relative_evolution)
local ffatable = Table.get_table()
if not surface then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local evolution_index = math.ceil(relative_evolution * 10)
if evolution_index < 1 then
evolution_index = 1
end
for t = 1, 330, 1 do
if not ffatable.on_tick_schedule[game.tick + t] then
ffatable.on_tick_schedule[game.tick + t] = {}
end
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_particles,
args = {surface, {x = position.x, y = position.y}, math_ceil(t * 0.05)}
}
if t == 330 then
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = spawn_worm,
args = {surface, {x = position.x, y = position.y}, evolution_index}
}
end
end
end
return unearthing_worm

View File

@ -1,2 +1 @@
require 'maps.scrap_towny_ffa.main'
return require 'terrain_layouts.scrap_towny_ffa'
return require 'maps.scrap_towny_ffa.main'