1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-01 13:08:05 +02:00

new modules

This commit is contained in:
MewMew 2019-05-28 13:29:46 +02:00
parent 9aa6985926
commit cecc4ecacf
3 changed files with 198 additions and 11 deletions

View File

@ -1,8 +1,6 @@
-- mountain digger fortress -- by mewmew --
require "modules.backpack_research"
require "modules.biters_double_damage"
require "modules.biter_evasion_hp_increaser"
require "modules.biters_yield_coins"
require "modules.dynamic_landfill"
require "modules.rocks_broken_paint_tiles"
@ -11,7 +9,9 @@ require "modules.rocks_yield_ore_veins"
require "modules.rocks_yield_ore"
require "modules.satellite_score"
require "modules.spawners_contain_biters"
require "modules.splice_double"
--require "modules.splice_double"
require "modules.more_attacks"
require "modules.evolution_extended"
local event = require 'utils.event'
local math_random = math.random
@ -143,8 +143,6 @@ local function on_player_joined_game(event)
surface.ticks_per_day = surface.ticks_per_day * 2
game.forces.player.manual_mining_speed_modifier = 2
global.biter_evasion_health_increase_factor = 2
global.surface_init_done = true
end
@ -440,13 +438,10 @@ local function on_marked_for_deconstruction(event)
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
end
end
--[[
local function on_tick(event)
if game.tick % 3600 ~= 1 then return end
global.biter_evasion_health_increase_factor = global.biter_evasion_health_increase_factor + 0.0125
if global.biter_evasion_health_increase_factor > 5 then global.biter_evasion_health_increase_factor = 5 end
if math_random(1,8) ~= 1 then return end
local surface = game.surfaces["mountain_fortress"]
@ -470,7 +465,7 @@ local function on_tick(event)
})
end
event.add(defines.events.on_tick, on_tick)
event.add(defines.events.on_tick, on_tick)--]]
event.add(defines.events.on_chunk_charted, on_chunk_charted)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)

View File

@ -0,0 +1,83 @@
--extra difficulty mode with beyond 100% evolution modifiers
require "modules.biter_evasion_hp_increaser"
local event = require 'utils.event'
local simplex_noise = require 'utils.simplex_noise'.d2
local gui_refreshrate = 900
local evo_gains = {
["unit-spawner"] = 0.0025,
["unit"] = 0.00005,
["turret"] = 0.001
}
local function draw_evolution_gui()
local seed = game.surfaces[1].map_gen_settings.seed
local color_r = math.abs(simplex_noise(global.color_counter * 0.015, 0, seed)) + 0.2
if color_r > 1 then color_r = 1 end
local color_g = math.abs(simplex_noise(global.color_counter * 0.015, 10000, seed)) + 0.2
if color_g > 1 then color_g = 1 end
local color_b = math.abs(simplex_noise(global.color_counter * 0.015, 20000, seed)) + 0.2
if color_b > 1 then color_b = 1 end
for _, player in pairs(game.connected_players) do
if player.gui.top.evolution_gui then player.gui.top.evolution_gui.destroy() end
local element = player.gui.top.add({type = "sprite-button", name = "evolution_gui", caption = "Evolution: " .. math.round(global.evolution_factor, 4) * 100 .. "%", tooltip = "Can go beyond 100%, increasing biter strength even further."})
local style = element.style
style.minimal_height = 38
style.maximal_height = 38
style.minimal_width = 176
style.top_padding = 2
style.left_padding = 4
style.right_padding = 4
style.bottom_padding = 2
style.font_color = {r = color_r, g = color_g, b = color_b}
style.font = "default-large-bold"
end
end
local function set_endgame_stats()
if global.evolution_factor < 1 then return end
game.forces.enemy.set_ammo_damage_modifier("melee", (global.evolution_factor - 1) * 1.5)
game.forces.enemy.set_ammo_damage_modifier("biological", (global.evolution_factor - 1) * 1.5)
global.biter_evasion_health_increase_factor = global.evolution_factor * 3
end
local function add_evolution(amount)
global.evolution_factor = global.evolution_factor + amount
local evo = global.evolution_factor
if evo > 1 then evo = 1 end
game.forces.enemy.evolution_factor = evo
end
local function on_entity_died(event)
if not event.entity.valid then return end
if event.entity.force.name == "enemy" then
add_evolution(evo_gains[event.entity.type])
draw_evolution_gui()
global.color_counter = global.color_counter + 1
return
end
end
local function tick()
add_evolution(global.tick_gain)
set_endgame_stats()
draw_evolution_gui()
global.color_counter = global.color_counter + 1
end
local function on_init(event)
global.evolution_factor = 0
global.color_counter = 0
local hours_to_max_evo = 12
local ticks_to_max_evo = 12 * 60 * 60 * 60
global.tick_gain = math.round((1 / ticks_to_max_evo) * gui_refreshrate, 8)
end
event.add(defines.events.on_entity_died, on_entity_died)
event.on_nth_tick(gui_refreshrate, tick)
event.on_init(on_init)

109
modules/more_attacks.lua Normal file
View File

@ -0,0 +1,109 @@
--adds constant biter attacks onto players
local event = require 'utils.event'
local function get_random_close_spawner(surface)
local surface = game.connected_players[1].surface
local spawners = surface.find_entities_filtered({type = "unit-spawner", force = "enemy"})
if not spawners[1] then return false end
local spawner = spawners[math.random(1,#spawners)]
for i = 1, 4, 1 do
local spawner_2 = spawners[math.random(1,#spawners)]
if spawner_2.position.x ^ 2 + spawner_2.position.y ^ 2 < spawner.position.x ^ 2 + spawner.position.y ^ 2 then spawner = spawner_2 end
end
return spawner
end
local function recruit_biters()
local spawner = get_random_close_spawner(surface)
if not spawner then return end
local biters = spawner.surface.find_enemy_units(spawner.position, 128, "player")
if not biters[1] then return false end
local amount = math.floor(game.tick * 0.001) + 1
if amount > 256 then amount = 256 end
for _, biter in pairs(biters) do
global.more_attacks.biters[biter.unit_number] = {entity = biter, recruitment_tick = game.tick}
amount = amount - 1
if amount <= 0 then break end
end
end
local function kill_idle_biters()
for index, biter in pairs(global.more_attacks.biters) do
if game.tick - biter.recruitment_tick > 36000 then
if global.more_attacks.biters[index].entity.valid then
global.more_attacks.biters[index].entity.destroy()
end
global.more_attacks.biters[index] = nil
end
end
end
local function send_biters()
local k, v = next(global.more_attacks.biters)
if not k then return end
local surface = global.more_attacks.biters[k].entity.surface
local pos = surface.find_non_colliding_position("rocket-silo", global.more_attacks.biters[k].entity.position, 128, 1)
if not pos then return end
local unit_group = surface.create_unit_group({position = pos, force = "enemy"})
for _, biter in pairs(global.more_attacks.biters) do
unit_group.add_member(biter.entity)
end
local target = game.connected_players[math.random(1, #game.connected_players)].position
unit_group.set_command({
type = defines.command.compound,
structure_type = defines.compound_command.return_last,
commands = {
{
type = defines.command.attack_area,
destination = target,
radius = 32,
distraction=defines.distraction.by_enemy
}
}
})
global.more_attacks.last_sending = game.tick
end
local function on_entity_died(event)
if not event.entity.valid then return end
if not event.entity.unit_number then return end
if global.more_attacks.biters[event.entity.unit_number] then
global.more_attacks.biters[event.entity.unit_number] = nil
global.more_attacks.last_death = game.tick
end
end
local function tick()
if game.tick < 100 then return end
local k, v = next(global.more_attacks.biters)
if not k then
recruit_biters()
send_biters()
return
end
if game.tick - global.more_attacks.last_death < 1800 then return end
kill_idle_biters()
if game.tick - global.more_attacks.last_sending < 3600 then return end
send_biters()
end
local function on_init(event)
global.more_attacks = {}
global.more_attacks.biters = {}
global.more_attacks.last_death = 0
global.more_attacks.last_sending = 0
end
event.add(defines.events.on_entity_died, on_entity_died)
event.on_nth_tick(300, tick)
event.on_init(on_init)