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

updated explosives

This commit is contained in:
MewMew 2019-10-11 07:13:08 +02:00
parent 4eaff2f31d
commit ebd11a96f2
3 changed files with 89 additions and 34 deletions

View File

@ -8,6 +8,7 @@ require "functions.soft_reset"
require "functions.basic_markets"
require "modules.biters_yield_coins"
require "modules.no_deconstruction_of_neutral_entities"
require "modules.explosives"
require "modules.rocks_broken_paint_tiles"
require "modules.rocks_heal_over_time"
require "modules.rocks_yield_ore_veins"
@ -37,7 +38,7 @@ require "maps.mountain_fortress_v2.market"
require "maps.mountain_fortress_v2.treasure"
require "maps.mountain_fortress_v2.terrain"
require "maps.mountain_fortress_v2.locomotive"
require "maps.mountain_fortress_v2.explosives"
--require "maps.mountain_fortress_v2.explosives"
require "maps.mountain_fortress_v2.flamethrower_nerf"
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16}
@ -225,6 +226,11 @@ local function on_init(surface)
global.rocks_yield_ore_maximum_amount = 250
global.rocks_yield_ore_base_amount = 50
global.rocks_yield_ore_distance_modifier = 0.04
global.explosion_cells_destructible_tiles = {
["out-of-map"] = 2500,
}
reset_map()
end

View File

@ -1,13 +1,19 @@
--Explosives by MewMew
--/c cell_birth(game.player.surface.index, {x = -5, y = -5}, game.tick, {x = -5, y = -5}, 100000)
--Cellular Automata Explosives by MewMew
local damage_decay = 8
local speed = 4
--Example: cell_birth(game.player.surface.index, {x = -0, y = -64}, game.tick, {x = -0, y = -64}, 100000) --100000 = damage
--1 steel chest filled with explosives = ~1 million damage
local damage_per_explosive = 500
local damage_decay = 10
local speed = 3
local density = 1
local destructible_tiles = {
local density_r = density * 0.5
local valid_container_types = {
["container"] = true,
["logistic-container"] = true,
["car"] = true,
["cargo-wagon"] = true
}
local function pos_to_key(position)
@ -20,7 +26,7 @@ local function get_explosion_name(health)
return "big-artillery-explosion"
end
function cell_birth(surface_index, origin_position, origin_tick, position, health)
local function cell_birth(surface_index, origin_position, origin_tick, position, health)
local key = pos_to_key(position)
--Merge cells that are overlapping.
@ -42,29 +48,30 @@ end
local function grow_cell(cell)
table.shuffle_table(global.explosion_cells_vectors)
local radius = math.floor((game.tick - cell.origin_tick) / 18) + 3
local radius = math.floor((game.tick - cell.origin_tick) / 9) + 2
local positions = {}
for i = 1, 4, 1 do
local position = {x = cell.position.x + global.explosion_cells_vectors[i][1], y = cell.position.y + global.explosion_cells_vectors[i][2]}
local position = {x = cell.position.x + global.explosion_cells_vectors[i][1], y = cell.position.y + global.explosion_cells_vectors[i][2]}
if not global.explosion_cells[pos_to_key(position)] then
local distance = math.sqrt((cell.origin_position.x - position.x) ^ 2 + (cell.origin_position.y - position.y) ^ 2)
if distance < radius then
positions[#positions + 1] = position
end
end
end
end
if #positions == 0 then positions[#positions + 1] = {x = cell.position.x + global.explosion_cells_vectors[1][1], y = cell.position.y + global.explosion_cells_vectors[1][2]} end
local new_cell_health = math.round(cell.health / #positions, 2) - damage_decay
local new_cell_health = math.round(cell.health / #positions, 3) - damage_decay
--[[
if new_cell_health > 0 then
global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + damage_decay * #positions
else
global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + (new_cell_health + damage_decay) * #positions
end
]]
if new_cell_health <= 0 then return end
for _, p in pairs(positions) do
@ -76,22 +83,21 @@ local function damage_area(cell)
local surface = game.surfaces[cell.surface_index]
if not surface then return end
if not surface.valid then return end
surface.create_entity({name = get_explosion_name(cell.health), position = cell.position})
for _, e in pairs(surface.find_entities_filtered({area = {{cell.position.x - density, cell.position.y - density},{cell.position.x + density, cell.position.y + density}}})) do
if math.random(1,6) == 1 then
surface.create_entity({name = get_explosion_name(cell.health), position = cell.position})
end
for _, e in pairs(surface.find_entities({{cell.position.x - density_r, cell.position.y - density_r},{cell.position.x + density_r, cell.position.y + density_r}})) do
if e.valid then
if e.health then
if e.destructible then
if cell.health > e.health then
global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + e.health
cell.health = cell.health - e.health
if e.destructible and e.minable then
if cell.health > e.health then
--global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + e.health
cell.health = cell.health - e.health
e.die()
else
global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + cell.health
else
--global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + cell.health
e.health = e.health - cell.health
return
end
@ -100,6 +106,25 @@ local function damage_area(cell)
end
end
local tile = surface.get_tile(cell.position)
if global.explosion_cells_destructible_tiles[tile.name] then
local key = pos_to_key(tile.position)
if not global.explosion_cells_tiles[key] then global.explosion_cells_tiles[key] = global.explosion_cells_destructible_tiles[tile.name] end
if cell.health > global.explosion_cells_tiles[key] then
--global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + global.explosion_cells_tiles[key]
cell.health = cell.health - global.explosion_cells_tiles[key]
global.explosion_cells_tiles[key] = nil
surface.set_tiles({{name = "landfill", position = tile.position}}, true)
else
--global.explosion_cells_damage_dealt = global.explosion_cells_damage_dealt + cell.health
global.explosion_cells_tiles[key] = global.explosion_cells_tiles[key] - cell.health
return
end
end
return true
end
@ -117,12 +142,36 @@ local function tick(event)
end
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then return end
if not valid_container_types[entity.type] then return end
local inventory = defines.inventory.chest
if entity.type == "car" then inventory = defines.inventory.car_trunk end
local i = entity.get_inventory(inventory)
local amount = i.get_item_count("explosives")
if not amount then return end
if amount < 1 then return end
cell_birth(entity.surface.index, {x = entity.position.x, y = entity.position.y}, game.tick, {x = entity.position.x, y = entity.position.y}, amount * damage_per_explosive)
end
local function on_init(surface)
global.explosion_cells = {}
global.explosion_cells_vectors = {{density, 0}, {density * -1, 0}, {0, density}, {0, density * -1}}
global.explosion_cells_damage_dealt = 0
--global.explosion_cells_damage_dealt = 0
global.explosion_cells_tiles = {}
global.explosion_cells_destructible_tiles = {
["water"] = false,
["deepwater"] = false,
["out-of-map"] = false,
}
end
local event = require 'utils.event'
event.on_init(on_init)
event.on_nth_tick(speed, tick)
event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -243,7 +243,7 @@ local function get_commmands(group)
for i = 1, steps, 1 do
group_position.x = group_position.x + vector[1]
group_position.y = group_position.y + vector[2]
local position = group.surface.find_non_colliding_position("small-biter", group_position, 64, 2)
local position = group.surface.find_non_colliding_position("small-biter", group_position, 64, 1)
if position then
commands[#commands + 1] = {
type = defines.command.attack_area,
@ -364,15 +364,15 @@ function reset_wave_defense()
active_biters = {},
unit_groups = {},
unit_group_last_command = {},
unit_group_command_delay = 3600 * 15,
unit_group_command_step_length = 48,
unit_group_command_delay = 3600 * 8,
unit_group_command_step_length = 64,
max_group_size = 192,
max_active_unit_groups = 8,
max_active_biters = 1024,
max_biter_age = 3600 * 60,
active_unit_group_count = 0,
active_biter_count = 0,
get_random_close_spawner_attempts = 3,
get_random_close_spawner_attempts = 5,
side_target_search_radius = 768,
spawn_position = {x = 0, y = 64},
last_wave = game.tick,
@ -384,7 +384,7 @@ function reset_wave_defense()
simple_entity_shredding_count_modifier = 0.0003,
simple_entity_shredding_cost_modifier = 0.005, --threat cost for one health
nest_building_density = 64, --lower values = more dense building
nest_building_chance = 8, --high value = less chance
nest_building_chance = 4, --high value = less chance
worm_building_density = 8, --lower values = more dense building
worm_building_chance = 2, --high value = less chance
}