1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-22 03:38:48 +02:00

unit group size raffle

This commit is contained in:
MewMew 2019-11-09 13:18:30 +01:00
parent 9227fda072
commit 332849d3a2
2 changed files with 36 additions and 23 deletions

View File

@ -5,9 +5,23 @@ local ThreatEvent = require "modules.wave_defense.threat_events"
local update_gui = require "modules.wave_defense.gui"
local threat_values = require "modules.wave_defense.threat_values"
local WD = require "modules.wave_defense.table"
local math_random = math.random
local math_floor = math.floor
local table_insert = table.insert
local math_sqrt = math.sqrt
local math_round = math.round
local event = require 'utils.event'
local Public = {}
local group_size_modifier_raffle = {}
local group_size_chances = {{4, 0.4}, {5, 0.5}, {6, 0.6}, {7, 0.7}, {8, 0.8}, {9, 0.9}, {10, 1}, {9, 1.1}, {8, 1.2}, {7, 1.3}, {6, 1.4}, {5, 1.5}, {4, 1.6}, {3, 1.7}, {2, 1.8}}
for _, v in pairs(group_size_chances) do
for c = 1, v[1], 1 do
table_insert(group_size_modifier_raffle, v[2])
end
end
local group_size_modifier_raffle_size = #group_size_modifier_raffle
local function debug_print(msg)
local wave_defense_table = WD.get_table()
if not wave_defense_table.debug then return end
@ -34,7 +48,7 @@ local function refresh_active_unit_threat()
end
end
end
wave_defense_table.active_biter_threat = math.round(active_biter_threat * global.biter_health_boost, 2)
wave_defense_table.active_biter_threat = math_round(active_biter_threat * global.biter_health_boost, 2)
debug_print("refresh_active_unit_threat - new value " .. wave_defense_table.active_biter_threat)
end
@ -45,7 +59,7 @@ local function time_out_biters()
wave_defense_table.active_biter_count = wave_defense_table.active_biter_count - 1
if biter.entity then
if biter.entity.valid then
wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat - math.round(threat_values[biter.entity.name] * global.biter_health_boost, 2)
wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat - math_round(threat_values[biter.entity.name] * global.biter_health_boost, 2)
if biter.entity.force.index == 2 then
biter.entity.destroy()
end
@ -61,9 +75,9 @@ local function get_random_close_spawner(surface)
local spawners = surface.find_entities_filtered({type = "unit-spawner"})
if not spawners[1] then return false end
local center = wave_defense_table.target.position
local spawner = spawners[math.random(1,#spawners)]
local spawner = spawners[math_random(1,#spawners)]
for i = 1, wave_defense_table.get_random_close_spawner_attempts, 1 do
local spawner_2 = spawners[math.random(1,#spawners)]
local spawner_2 = spawners[math_random(1,#spawners)]
if (center.x - spawner_2.position.x) ^ 2 + (center.y - spawner_2.position.y) ^ 2 < (center.x - spawner.position.x) ^ 2 + (center.y - spawner.position.y) ^ 2 then spawner = spawner_2 end
end
debug_print("get_random_close_spawner - Found at x" .. spawner.position.x .. " y" .. spawner.position.y)
@ -77,7 +91,7 @@ local function set_main_target()
end
if not wave_defense_table.side_targets then return end
if #wave_defense_table.side_targets == 0 then return end
local target = wave_defense_table.side_targets[math.random(1, #wave_defense_table.side_targets)]
local target = wave_defense_table.side_targets[math_random(1, #wave_defense_table.side_targets)]
if not target then return end
if not target.valid then return end
wave_defense_table.target = target
@ -107,8 +121,8 @@ local function set_enemy_evolution()
end
if wave_defense_table.threat > 50000 then
biter_health_boost = math.round(biter_health_boost + (wave_defense_table.threat - 50000) * 0.000033, 3)
--damage_increase = math.round(damage_increase + wave_defense_table.threat * 0.0000025, 3)
biter_health_boost = math_round(biter_health_boost + (wave_defense_table.threat - 50000) * 0.000033, 3)
--damage_increase = math_round(damage_increase + wave_defense_table.threat * 0.0000025, 3)
end
global.biter_health_boost = biter_health_boost
@ -164,7 +178,7 @@ local function spawn_biter(surface)
if not can_units_spawn() then return end
local name
if math.random(1,100) > 73 then
if math_random(1,100) > 73 then
name = BiterRolls.wave_defense_roll_spitter_name()
else
name = BiterRolls.wave_defense_roll_biter_name()
@ -176,22 +190,20 @@ local function spawn_biter(surface)
biter.ai_settings.allow_try_return_to_spawner = false
wave_defense_table.active_biters[biter.unit_number] = {entity = biter, spawn_tick = game.tick}
wave_defense_table.active_biter_count = wave_defense_table.active_biter_count + 1
wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat + math.round(threat_values[name] * global.biter_health_boost, 2)
wave_defense_table.active_biter_threat = wave_defense_table.active_biter_threat + math_round(threat_values[name] * global.biter_health_boost, 2)
return biter
end
local function set_next_wave()
local wave_defense_table = WD.get_table()
wave_defense_table.wave_number = wave_defense_table.wave_number + 1
wave_defense_table.group_size = wave_defense_table.wave_number * 2
if wave_defense_table.group_size > wave_defense_table.max_group_size then wave_defense_table.group_size = wave_defense_table.max_group_size end
local threat_gain = wave_defense_table.wave_number * wave_defense_table.threat_gain_multiplier
if wave_defense_table.wave_number > 1000 then
threat_gain = threat_gain * (wave_defense_table.wave_number * 0.001)
end
wave_defense_table.threat = wave_defense_table.threat + math.floor(threat_gain)
wave_defense_table.threat = wave_defense_table.threat + math_floor(threat_gain)
wave_defense_table.last_wave = wave_defense_table.next_wave
wave_defense_table.next_wave = game.tick + wave_defense_table.wave_interval
end
@ -202,14 +214,14 @@ local function get_commmands(group)
local group_position = {x = group.position.x, y = group.position.y}
local step_length = wave_defense_table.unit_group_command_step_length
if math.random(1,2) == 1 then
if math_random(1,2) == 1 then
local side_target = SideTargets.get_side_target()
if side_target then
debug_print("get_side_target -- " .. side_target.name .. " at position x" .. side_target.position.x .. " y" .. side_target.position.y .. " selected.")
local target_position = side_target.position
local distance_to_target = math.floor(math.sqrt((target_position.x - group_position.x) ^ 2 + (target_position.y - group_position.y) ^ 2))
local steps = math.floor(distance_to_target / step_length) + 1
local vector = {math.round((target_position.x - group_position.x) / steps, 3), math.round((target_position.y - group_position.y) / steps, 3)}
local distance_to_target = math_floor(math_sqrt((target_position.x - group_position.x) ^ 2 + (target_position.y - group_position.y) ^ 2))
local steps = math_floor(distance_to_target / step_length) + 1
local vector = {math_round((target_position.x - group_position.x) / steps, 3), math_round((target_position.y - group_position.y) / steps, 3)}
if wave_defense_table.debug then
debug_print("get_commmands - to side_target x" .. side_target.position.x .. " y" .. side_target.position.y)
@ -240,9 +252,9 @@ local function get_commmands(group)
end
local target_position = wave_defense_table.target.position
local distance_to_target = math.floor(math.sqrt((target_position.x - group_position.x) ^ 2 + (target_position.y - group_position.y) ^ 2))
local steps = math.floor(distance_to_target / step_length) + 1
local vector = {math.round((target_position.x - group_position.x) / steps, 3), math.round((target_position.y - group_position.y) / steps, 3)}
local distance_to_target = math_floor(math_sqrt((target_position.x - group_position.x) ^ 2 + (target_position.y - group_position.y) ^ 2))
local steps = math_floor(distance_to_target / step_length) + 1
local vector = {math_round((target_position.x - group_position.x) / steps, 3), math_round((target_position.y - group_position.y) / steps, 3)}
if wave_defense_table.debug then
debug_print("get_commmands - to main target x" .. target_position.x .. " y" .. target_position.y)
@ -325,13 +337,14 @@ local function spawn_unit_group()
local surface = game.surfaces[wave_defense_table.surface_index]
set_group_spawn_position(surface)
debug_print("Spawning unit group at x" .. wave_defense_table.spawn_position.x .." y" .. wave_defense_table.spawn_position.y)
local unit_group = surface.create_unit_group({position = wave_defense_table.spawn_position, force = "enemy"})
for a = 1, wave_defense_table.group_size, 1 do
local unit_group = surface.create_unit_group({position = wave_defense_table.spawn_position, force = "enemy"})
local group_size = math_floor(wave_defense_table.average_unit_group_size * group_size_modifier_raffle[math_random(1, group_size_modifier_raffle_size)])
for a = 1, group_size, 1 do
local biter = spawn_biter(surface)
if not biter then break end
unit_group.add_member(biter)
end
table.insert(wave_defense_table.unit_groups, unit_group)
table_insert(wave_defense_table.unit_groups, unit_group)
return true
end

View File

@ -24,7 +24,7 @@ function Public.reset_wave_defense()
wave_defense.max_active_biters = 1280
wave_defense.max_active_unit_groups = 8
wave_defense.max_biter_age = 3600 * 60
wave_defense.max_group_size = 200
wave_defense.average_unit_group_size = 168
wave_defense.nest_building_density = 48
wave_defense.next_wave = game.tick + 3600 * 15
wave_defense.side_targets = {}