2019-10-28 18:38:36 +02:00
|
|
|
local Global = require 'utils.global'
|
|
|
|
local Event = require 'utils.event'
|
|
|
|
|
2020-08-09 20:23:45 +02:00
|
|
|
local this = {}
|
2019-10-28 18:38:36 +02:00
|
|
|
local Public = {}
|
|
|
|
|
|
|
|
Global.register(
|
2020-08-09 20:23:45 +02:00
|
|
|
this,
|
2019-10-28 18:38:36 +02:00
|
|
|
function(tbl)
|
2020-08-09 20:23:45 +02:00
|
|
|
this = tbl
|
2019-10-28 18:38:36 +02:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
function Public.reset_wave_defense()
|
2020-08-09 20:23:45 +02:00
|
|
|
this.boss_wave = false
|
|
|
|
this.boss_wave_warning = false
|
|
|
|
this.side_target_count = 0
|
|
|
|
this.active_biters = {}
|
|
|
|
this.active_biter_count = 0
|
|
|
|
this.active_biter_threat = 0
|
2021-03-01 22:47:58 +02:00
|
|
|
this.average_unit_group_size = 35
|
2020-08-09 20:23:45 +02:00
|
|
|
this.biter_raffle = {}
|
2021-02-10 22:31:43 +02:00
|
|
|
this.debug = false
|
2021-11-14 14:02:00 +02:00
|
|
|
this.debug_health = false
|
2021-10-29 00:06:35 +02:00
|
|
|
this.paused = false
|
2020-08-09 20:23:45 +02:00
|
|
|
this.game_lost = false
|
|
|
|
this.get_random_close_spawner_attempts = 5
|
|
|
|
this.group_size = 2
|
|
|
|
this.last_wave = game.tick
|
|
|
|
this.max_active_biters = 1280
|
2020-11-23 23:10:32 +02:00
|
|
|
this.max_active_unit_groups = 32
|
2020-08-09 20:23:45 +02:00
|
|
|
this.max_biter_age = 3600 * 60
|
2020-10-22 12:44:14 +02:00
|
|
|
this.nests = {}
|
2020-08-09 20:23:45 +02:00
|
|
|
this.nest_building_density = 48
|
|
|
|
this.next_wave = game.tick + 3600 * 15
|
|
|
|
this.side_targets = {}
|
2020-10-22 12:44:14 +02:00
|
|
|
this.simple_entity_shredding_cost_modifier = 0.009
|
2020-08-09 20:23:45 +02:00
|
|
|
this.spawn_position = {x = 0, y = 64}
|
|
|
|
this.spitter_raffle = {}
|
|
|
|
this.surface_index = 1
|
|
|
|
this.target = nil
|
|
|
|
this.threat = 0
|
|
|
|
this.threat_gain_multiplier = 2
|
|
|
|
this.threat_log = {}
|
|
|
|
this.threat_log_index = 0
|
|
|
|
this.unit_groups = {}
|
2021-11-11 02:56:03 +02:00
|
|
|
this.unit_groups_size = 0
|
2020-11-23 23:10:32 +02:00
|
|
|
this.unit_group_pos = {
|
2021-11-19 23:22:17 +02:00
|
|
|
index = 0,
|
2020-11-23 23:10:32 +02:00
|
|
|
positions = {}
|
|
|
|
}
|
2020-10-22 12:44:14 +02:00
|
|
|
this.index = 0
|
|
|
|
this.random_group = nil
|
2020-11-23 23:10:32 +02:00
|
|
|
this.unit_group_command_delay = 3600 * 20
|
2020-10-22 12:44:14 +02:00
|
|
|
this.unit_group_command_step_length = 15
|
2020-08-09 20:23:45 +02:00
|
|
|
this.unit_group_last_command = {}
|
|
|
|
this.wave_interval = 3600
|
2020-10-24 14:46:14 +02:00
|
|
|
this.wave_enforced = false
|
2020-08-09 20:23:45 +02:00
|
|
|
this.wave_number = 0
|
|
|
|
this.worm_building_chance = 3
|
|
|
|
this.worm_building_density = 16
|
|
|
|
this.worm_raffle = {}
|
|
|
|
this.clear_corpses = false
|
|
|
|
this.alert_boss_wave = false
|
2020-10-22 13:32:18 +02:00
|
|
|
this.remove_entities = false
|
2020-11-17 13:45:47 +02:00
|
|
|
this.enable_side_target = false
|
2020-08-09 20:23:45 +02:00
|
|
|
this.enable_threat_log = true
|
2020-11-01 17:43:58 +02:00
|
|
|
this.disable_threat_below_zero = false
|
2020-08-09 20:23:45 +02:00
|
|
|
this.check_collapse_position = true
|
2020-11-18 16:24:22 +02:00
|
|
|
this.resolve_pathing = true
|
2021-02-04 21:21:48 +02:00
|
|
|
this.increase_damage_per_wave = false
|
2021-02-10 22:21:29 +02:00
|
|
|
this.increase_boss_health_per_wave = true
|
|
|
|
this.increase_health_per_wave = false
|
2020-11-23 23:10:32 +02:00
|
|
|
this.fill_tiles_so_biter_can_path = true
|
2021-02-15 23:37:15 +02:00
|
|
|
this.modified_unit_health = {
|
2021-11-20 21:04:13 +02:00
|
|
|
current_value = 1.2,
|
|
|
|
limit_value = 90,
|
2021-11-19 23:22:17 +02:00
|
|
|
health_increase_per_boss_wave = 0.08
|
|
|
|
}
|
|
|
|
this.modified_boss_unit_health = {
|
|
|
|
current_value = 2.00,
|
|
|
|
limit_value = 500,
|
|
|
|
health_increase_per_boss_wave = 0.15
|
2021-02-15 23:37:15 +02:00
|
|
|
}
|
2019-10-28 18:38:36 +02:00
|
|
|
end
|
|
|
|
|
2020-07-24 17:33:28 +02:00
|
|
|
function Public.get(key)
|
|
|
|
if key then
|
2020-08-09 20:23:45 +02:00
|
|
|
return this[key]
|
2020-07-24 17:33:28 +02:00
|
|
|
else
|
2020-08-09 20:23:45 +02:00
|
|
|
return this
|
2020-07-24 17:33:28 +02:00
|
|
|
end
|
2019-10-28 18:38:36 +02:00
|
|
|
end
|
|
|
|
|
2020-11-15 20:23:54 +02:00
|
|
|
function Public.set(key, value)
|
2020-11-23 23:10:32 +02:00
|
|
|
if key and (value or value == false or value == 'nil') then
|
|
|
|
if value == 'nil' then
|
|
|
|
this[key] = nil
|
|
|
|
else
|
|
|
|
this[key] = value
|
|
|
|
end
|
2020-11-15 20:23:54 +02:00
|
|
|
return this[key]
|
2020-11-17 13:45:47 +02:00
|
|
|
elseif key then
|
|
|
|
return this[key]
|
2020-07-24 17:33:28 +02:00
|
|
|
else
|
2020-08-09 20:23:45 +02:00
|
|
|
return this
|
2020-07-24 17:33:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Public.get_table = Public.get
|
|
|
|
|
2020-06-07 13:33:24 +02:00
|
|
|
function Public.clear_corpses(value)
|
2020-11-17 13:45:47 +02:00
|
|
|
if (value or value == false) then
|
2020-08-09 20:23:45 +02:00
|
|
|
this.clear_corpses = value
|
2020-06-07 13:33:24 +02:00
|
|
|
end
|
2020-08-09 20:23:45 +02:00
|
|
|
return this.clear_corpses
|
2020-06-24 15:41:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Public.get_wave()
|
2020-08-09 20:23:45 +02:00
|
|
|
return this.wave_number
|
2020-06-07 13:33:24 +02:00
|
|
|
end
|
|
|
|
|
2020-11-01 17:43:58 +02:00
|
|
|
function Public.get_disable_threat_below_zero()
|
|
|
|
return this.disable_threat_below_zero
|
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.set_disable_threat_below_zero(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.disable_threat_below_zero = boolean
|
2020-11-01 17:43:58 +02:00
|
|
|
end
|
|
|
|
return this.disable_threat_below_zero
|
|
|
|
end
|
|
|
|
|
2020-10-30 23:05:05 +02:00
|
|
|
function Public.get_alert_boss_wave()
|
|
|
|
return this.get_alert_boss_wave
|
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.alert_boss_wave(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.alert_boss_wave = boolean
|
2020-06-07 13:33:24 +02:00
|
|
|
end
|
2020-08-09 20:23:45 +02:00
|
|
|
return this.alert_boss_wave
|
2020-06-07 13:33:24 +02:00
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.set_spawn_position(tbl)
|
|
|
|
if type(tbl) == 'table' then
|
|
|
|
this.spawn_position = tbl
|
2020-08-21 13:56:01 +02:00
|
|
|
else
|
2020-11-17 13:45:47 +02:00
|
|
|
error('Tbl must be of type table.')
|
2020-08-21 13:56:01 +02:00
|
|
|
end
|
|
|
|
return this.spawn_position
|
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.remove_entities(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.remove_entities = boolean
|
2020-08-04 12:10:15 +02:00
|
|
|
end
|
2020-08-09 20:23:45 +02:00
|
|
|
return this.remove_entities
|
|
|
|
end
|
|
|
|
|
2021-02-10 22:21:29 +02:00
|
|
|
function Public.increase_health_per_wave(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.increase_health_per_wave = boolean
|
|
|
|
end
|
|
|
|
return this.increase_health_per_wave
|
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.enable_threat_log(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.enable_threat_log = boolean
|
2020-08-09 20:23:45 +02:00
|
|
|
end
|
|
|
|
return this.enable_threat_log
|
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.check_collapse_position(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.check_collapse_position = boolean
|
2020-08-09 20:23:45 +02:00
|
|
|
end
|
|
|
|
return this.check_collapse_position
|
2020-08-04 12:10:15 +02:00
|
|
|
end
|
|
|
|
|
2020-11-17 13:45:47 +02:00
|
|
|
function Public.enable_side_target(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.enable_side_target = boolean
|
|
|
|
end
|
|
|
|
return this.enable_side_target
|
|
|
|
end
|
|
|
|
|
2021-02-10 22:21:29 +02:00
|
|
|
function Public.increase_boss_health_per_wave(boolean)
|
2020-11-17 13:45:47 +02:00
|
|
|
if (boolean or boolean == false) then
|
2021-02-10 22:21:29 +02:00
|
|
|
this.increase_boss_health_per_wave = boolean
|
2020-11-17 13:45:47 +02:00
|
|
|
end
|
2021-02-10 22:21:29 +02:00
|
|
|
return this.increase_boss_health_per_wave
|
2020-11-17 13:45:47 +02:00
|
|
|
end
|
|
|
|
|
2020-11-18 16:24:22 +02:00
|
|
|
function Public.resolve_pathing(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.resolve_pathing = boolean
|
|
|
|
end
|
|
|
|
return this.resolve_pathing
|
|
|
|
end
|
|
|
|
|
2020-11-23 23:10:32 +02:00
|
|
|
function Public.fill_tiles_so_biter_can_path(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.fill_tiles_so_biter_can_path = boolean
|
|
|
|
end
|
|
|
|
return this.fill_tiles_so_biter_can_path
|
|
|
|
end
|
|
|
|
|
2021-02-04 21:21:48 +02:00
|
|
|
function Public.increase_damage_per_wave(boolean)
|
|
|
|
if (boolean or boolean == false) then
|
|
|
|
this.increase_damage_per_wave = boolean
|
|
|
|
end
|
|
|
|
return this.increase_damage_per_wave
|
|
|
|
end
|
|
|
|
|
2021-11-20 21:04:13 +02:00
|
|
|
function Public.set_normal_unit_current_health(int)
|
|
|
|
this.modified_unit_health.current_value = int or 1.2
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.set_boss_unit_current_health(int)
|
|
|
|
this.modified_boss_unit_health.current_value = int or 2
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.set_normal_unit_current_per_wave(int)
|
|
|
|
this.modified_unit_health.health_increase_per_boss_wave = int or 0.08
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.set_boss_unit_current_per_wave(int)
|
|
|
|
this.modified_boss_unit_health.health_increase_per_boss_wave = int or 0.15
|
|
|
|
end
|
|
|
|
|
2021-10-29 00:06:35 +02:00
|
|
|
function Public.pause(boolean)
|
|
|
|
this.paused = boolean or false
|
|
|
|
end
|
|
|
|
|
2021-11-14 14:02:00 +02:00
|
|
|
--- Toggle debug - when you need to troubleshoot.
|
|
|
|
function Public.toggle_debug()
|
|
|
|
if this.debug then
|
|
|
|
this.debug = false
|
|
|
|
else
|
|
|
|
this.debug = true
|
|
|
|
end
|
|
|
|
|
|
|
|
return this.debug
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Toggle debug - when you need to troubleshoot.
|
|
|
|
function Public.toggle_debug_health()
|
|
|
|
if this.debug_health then
|
|
|
|
this.debug_health = false
|
|
|
|
else
|
|
|
|
this.debug_health = true
|
|
|
|
end
|
|
|
|
|
|
|
|
return this.debug_health
|
|
|
|
end
|
|
|
|
|
2020-06-07 13:33:24 +02:00
|
|
|
local on_init = function()
|
2019-10-28 18:38:36 +02:00
|
|
|
Public.reset_wave_defense()
|
|
|
|
end
|
|
|
|
|
2020-10-30 23:05:05 +02:00
|
|
|
-- Event.on_nth_tick(30, Public.debug_module)
|
|
|
|
|
2019-10-28 18:38:36 +02:00
|
|
|
Event.on_init(on_init)
|
|
|
|
|
|
|
|
return Public
|