1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-09-16 09:06:21 +02:00

biters can shred simple-entities

This commit is contained in:
MewMew
2019-10-08 23:50:57 +02:00
parent 26794f80e0
commit 30faca867a
5 changed files with 110 additions and 51 deletions

View File

@@ -45,6 +45,7 @@ local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16
local function get_gen_settings()
local map = {
["seed"] = math.random(1, 1000000),
["width"] = 768,
["water"] = 0.001,
["starting_area"] = 1,
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
@@ -115,14 +116,14 @@ local function biters_chew_rocks_faster(event)
end
local function hidden_biter(entity)
wave_defense_set_biter_raffle(math.floor(math.abs(entity.position.y) * 0.5) + 1)
wave_defense_set_biter_raffle(math.sqrt(entity.position.x ^ 2, entity.position.y ^ 2) * 0.65)
entity.surface.create_entity({name = wave_defense_roll_biter_name(), position = entity.position})
end
local function on_player_mined_entity(event)
if not event.entity.valid then return end
if not event.entity.valid then return end
if event.entity.force.index == 3 then
if math.random(1,48) == 1 then
if math.random(1,32) == 1 then
hidden_biter(event.entity)
end
end
@@ -142,7 +143,7 @@ local function on_entity_died(event)
if event.cause then
if event.cause.valid then
if event.cause.force.index == 2 then return end
if event.cause.force.index == 2 or event.cause.force.index == 3 then return end
end
end
if event.entity.force.index == 3 then

View File

@@ -213,10 +213,12 @@ local function biter_chunk(surface, left_top)
tile_positions[#tile_positions + 1] = p
end
end
for i = 1, 4, 1 do
for i = 1, 2, 1 do
local position = surface.find_non_colliding_position("biter-spawner", tile_positions[math_random(1, #tile_positions)], 16, 2)
if position then
surface.create_entity({name = spawner_raffle[math_random(1, #spawner_raffle)], position = position})
local e = surface.create_entity({name = spawner_raffle[math_random(1, #spawner_raffle)], position = position})
e.destructible = false
e.active = false
end
end
for _, e in pairs(surface.find_entities_filtered({area = {{left_top.x, left_top.y},{left_top.x + 32, left_top.y + 32}}, type = "cliff"})) do e.destroy() end
@@ -238,7 +240,8 @@ local function process_chunk(surface, left_top)
end
if left_top.y < 0 then rock_chunk(surface, left_top) return end
if left_top.y > 128 then out_of_map(surface, left_top) return end
if left_top.y > 64 or left_top.x > 480 or left_top.x < -512 then biter_chunk(surface, left_top) return end
--if left_top.y > 64 or left_top.x > 480 or left_top.x < -512 then biter_chunk(surface, left_top) return end
if left_top.y > 64 then biter_chunk(surface, left_top) return end
if left_top.y >= 0 then border_chunk(surface, left_top) return end
end

View File

@@ -7,7 +7,7 @@ function treasure_chest(surface, position)
--{{name = "steel-axe", count = math_random(1,3)}, weight = 2, evolution_min = 0.0, evolution_max = 0.5},
{{name = "submachine-gun", count = math_random(1,3)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1},
{{name = "slowdown-capsule", count = math_random(16,32)}, weight = 1, evolution_min = 0.3, evolution_max = 0.7},
{{name = "poison-capsule", count = math_random(16,32)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "poison-capsule", count = math_random(8,16)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "uranium-cannon-shell", count = math_random(16,32)}, weight = 5, evolution_min = 0.6, evolution_max = 1},
{{name = "cannon-shell", count = math_random(16,32)}, weight = 5, evolution_min = 0.4, evolution_max = 0.7},
{{name = "explosive-uranium-cannon-shell", count = math_random(16,32)}, weight = 5, evolution_min = 0.6, evolution_max = 1},
@@ -23,7 +23,7 @@ function treasure_chest(surface, position)
{{name = "explosive-rocket", count = math_random(16,32)}, weight = 5, evolution_min = 0.3, evolution_max = 1},
{{name = "land-mine", count = math_random(16,32)}, weight = 5, evolution_min = 0.2, evolution_max = 0.7},
{{name = "grenade", count = math_random(16,32)}, weight = 5, evolution_min = 0.0, evolution_max = 0.5},
{{name = "cluster-grenade", count = math_random(16,32)}, weight = 5, evolution_min = 0.4, evolution_max = 1},
{{name = "cluster-grenade", count = math_random(8,16)}, weight = 5, evolution_min = 0.4, evolution_max = 1},
{{name = "firearm-magazine", count = math_random(32,128)}, weight = 5, evolution_min = 0, evolution_max = 0.3},
{{name = "piercing-rounds-magazine", count = math_random(32,128)}, weight = 5, evolution_min = 0.1, evolution_max = 0.8},
{{name = "uranium-rounds-magazine", count = math_random(32,128)}, weight = 5, evolution_min = 0.5, evolution_max = 1},
@@ -39,18 +39,16 @@ function treasure_chest(surface, position)
{{name = "power-armor", count = 1}, weight = 2, evolution_min = 0.4, evolution_max = 1},
--{{name = "power-armor-mk2", count = 1}, weight = 1, evolution_min = 0.9, evolution_max = 1},
{{name = "battery-equipment", count = 1}, weight = 2, evolution_min = 0.3, evolution_max = 0.7},
{{name = "battery-mk2-equipment", count = 1}, weight = 2, evolution_min = 0.6, evolution_max = 1},
{{name = "belt-immunity-equipment", count = 1}, weight = 1, evolution_min = 0.3, evolution_max = 1},
{{name = "battery-mk2-equipment", count = 1}, weight = 2, evolution_min = 0.7, evolution_max = 1},
{{name = "belt-immunity-equipment", count = 1}, weight = 1, evolution_min = 0.5, evolution_max = 1},
--{{name = "solar-panel-equipment", count = math_random(1,4)}, weight = 5, evolution_min = 0.3, evolution_max = 0.8},
{{name = "discharge-defense-equipment", count = 1}, weight = 1, evolution_min = 0.5, evolution_max = 0.8},
{{name = "discharge-defense-equipment", count = 1}, weight = 1, evolution_min = 0.5, evolution_max = 1},
{{name = "energy-shield-equipment", count = math_random(1,2)}, weight = 2, evolution_min = 0.3, evolution_max = 0.8},
{{name = "energy-shield-mk2-equipment", count = 1}, weight = 2, evolution_min = 0.7, evolution_max = 1},
{{name = "energy-shield-mk2-equipment", count = 1}, weight = 2, evolution_min = 0.8, evolution_max = 1},
{{name = "exoskeleton-equipment", count = 1}, weight = 1, evolution_min = 0.3, evolution_max = 1},
{{name = "fusion-reactor-equipment", count = 1}, weight = 1, evolution_min = 0.5, evolution_max = 1},
{{name = "fusion-reactor-equipment", count = 1}, weight = 1, evolution_min = 0.8, evolution_max = 1},
--{{name = "night-vision-equipment", count = 1}, weight = 1, evolution_min = 0.3, evolution_max = 0.8},
{{name = "personal-laser-defense-equipment", count = 1}, weight = 2, evolution_min = 0.5, evolution_max = 1},
{{name = "exoskeleton-equipment", count = 1}, weight = 1, evolution_min = 0.3, evolution_max = 1},
{{name = "personal-laser-defense-equipment", count = 1}, weight = 1, evolution_min = 0.8, evolution_max = 1},
{{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
{{name = "copper-cable", count = math_random(100,200)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
@@ -78,43 +76,43 @@ function treasure_chest(surface, position)
{{name = "medium-electric-pole", count = math_random(8,16)}, weight = 3, evolution_min = 0.2, evolution_max = 1},
{{name = "big-electric-pole", count = math_random(4,8)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "substation", count = math_random(2,4)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "wooden-chest", count = math_random(16,24)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
{{name = "iron-chest", count = math_random(4,8)}, weight = 3, evolution_min = 0.1, evolution_max = 0.4},
{{name = "steel-chest", count = math_random(4,8)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "wooden-chest", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
{{name = "iron-chest", count = math_random(8,16)}, weight = 3, evolution_min = 0.1, evolution_max = 0.4},
{{name = "steel-chest", count = math_random(8,16)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "small-lamp", count = math_random(16,32)}, weight = 3, evolution_min = 0.1, evolution_max = 0.3},
{{name = "rail", count = math_random(25,75)}, weight = 3, evolution_min = 0.1, evolution_max = 0.6},
{{name = "assembling-machine-1", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
{{name = "assembling-machine-2", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.8},
{{name = "assembling-machine-3", count = math_random(1,2)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "accumulator", count = math_random(4,8)}, weight = 3, evolution_min = 0.4, evolution_max = 1},
{{name = "offshore-pump", count = math_random(1,3)}, weight = 2, evolution_min = 0.0, evolution_max = 0.1},
{{name = "beacon", count = math_random(1,2)}, weight = 3, evolution_min = 0.7, evolution_max = 1},
{{name = "boiler", count = math_random(4,8)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
{{name = "offshore-pump", count = math_random(1,3)}, weight = 2, evolution_min = 0.0, evolution_max = 0.2},
{{name = "beacon", count = 1}, weight = 3, evolution_min = 0.7, evolution_max = 1},
{{name = "boiler", count = math_random(3,6)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
{{name = "steam-engine", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.5},
{{name = "steam-turbine", count = math_random(1,2)}, weight = 2, evolution_min = 0.6, evolution_max = 1},
--{{name = "nuclear-reactor", count = 1}, weight = 1, evolution_min = 0.6, evolution_max = 1},
{{name = "centrifuge", count = math_random(1,2)}, weight = 1, evolution_min = 0.6, evolution_max = 1},
{{name = "centrifuge", count = 1}, weight = 1, evolution_min = 0.6, evolution_max = 1},
{{name = "heat-pipe", count = math_random(4,8)}, weight = 2, evolution_min = 0.5, evolution_max = 1},
{{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, evolution_min = 0.5, evolution_max = 1},
{{name = "arithmetic-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "constant-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "decider-combinator", count = math_random(8,16)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "power-switch", count = math_random(1,2)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "programmable-speaker", count = math_random(4,8)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "green-wire", count = math_random(50,99)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "red-wire", count = math_random(50,99)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "arithmetic-combinator", count = math_random(4,8)}, weight = 2, evolution_min = 0.1, evolution_max = 1},
{{name = "constant-combinator", count = math_random(4,8)}, weight = 2, evolution_min = 0.1, evolution_max = 1},
{{name = "decider-combinator", count = math_random(4,8)}, weight = 2, evolution_min = 0.1, evolution_max = 1},
{{name = "power-switch", count = 1}, weight = 2, evolution_min = 0.1, evolution_max = 1},
{{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, evolution_min = 0.1, evolution_max = 1},
{{name = "green-wire", count = math_random(50,99)}, weight = 4, evolution_min = 0.1, evolution_max = 1},
{{name = "red-wire", count = math_random(50,99)}, weight = 4, evolution_min = 0.1, evolution_max = 1},
{{name = "chemical-plant", count = math_random(1,3)}, weight = 3, evolution_min = 0.3, evolution_max = 1},
{{name = "burner-mining-drill", count = math_random(2,4)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
{{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.6},
{{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 1},
{{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "express-splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "express-splitter", count = math_random(1,4)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
{{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
{{name = "fast-splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.3},
{{name = "fast-splitter", count = math_random(1,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.3},
{{name = "transport-belt", count = math_random(25,75)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
{{name = "underground-belt", count = math_random(4,8)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
{{name = "splitter", count = math_random(2,4)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
{{name = "splitter", count = math_random(1,4)}, weight = 3, evolution_min = 0, evolution_max = 0.3},
--{{name = "oil-refinery", count = math_random(2,4)}, weight = 2, evolution_min = 0.3, evolution_max = 1},
{{name = "pipe", count = math_random(30,50)}, weight = 3, evolution_min = 0.0, evolution_max = 0.3},
{{name = "pipe-to-ground", count = math_random(4,8)}, weight = 1, evolution_min = 0.2, evolution_max = 0.5},
@@ -123,8 +121,8 @@ function treasure_chest(surface, position)
--{{name = "solar-panel", count = math_random(8,16)}, weight = 3, evolution_min = 0.4, evolution_max = 0.9},
{{name = "electric-furnace", count = math_random(2,4)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "steel-furnace", count = math_random(4,8)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.1},
{{name = "radar", count = math_random(1,2)}, weight = 1, evolution_min = 0.1, evolution_max = 0.3},
{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, evolution_min = 0.0, evolution_max = 0.2},
{{name = "radar", count = math_random(1,2)}, weight = 1, evolution_min = 0.1, evolution_max = 0.4},
{{name = "rail-signal", count = math_random(8,16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8},
{{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, evolution_min = 0.2, evolution_max = 0.8},
{{name = "stone-wall", count = math_random(25,75)}, weight = 1, evolution_min = 0.1, evolution_max = 0.5},
@@ -134,11 +132,11 @@ function treasure_chest(surface, position)
{{name = "express-loader", count = 1}, weight = 1, evolution_min = 0.5, evolution_max = 1},
{{name = "fast-loader", count = 1}, weight = 1, evolution_min = 0.2, evolution_max = 0.7},
{{name = "loader", count = 1}, weight = 1, evolution_min = 0.0, evolution_max = 0.5},
{{name = "lab", count = math_random(1,2)}, weight = 2, evolution_min = 0.0, evolution_max = 0.1},
{{name = "lab", count = math_random(1,2)}, weight = 2, evolution_min = 0.0, evolution_max = 0.3},
--{{name = "roboport", count = math_random(2,4)}, weight = 2, evolution_min = 0.6, evolution_max = 1},
--{{name = "flamethrower-turret", count = math_random(1,3)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
--{{name = "laser-turret", count = math_random(4,8)}, weight = 3, evolution_min = 0.5, evolution_max = 1},
{{name = "gun-turret", count = math_random(2,6)}, weight = 3, evolution_min = 0.2, evolution_max = 0.9}
{{name = "gun-turret", count = math_random(1,4)}, weight = 3, evolution_min = 0.2, evolution_max = 0.9}
}
distance_to_center = (math.abs(position.y) + 1) * 0.0002
@@ -155,7 +153,7 @@ function treasure_chest(surface, position)
local n = "wooden-chest"
if distance_to_center > 750 then n = "iron-chest" end
if distance_to_center > 1250 then n = "steel-chest" end
local e = surface.create_entity({name=n, position=position, force="player"})
local e = surface.create_entity({name=n, position=position, force="neutral"})
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(3,5), 1 do

View File

@@ -220,7 +220,7 @@ local function give_commands_to_unit_groups()
end
local function create_gui(player)
local frame = player.gui.top.add({ type = "frame", name = "wave_defense", tooltip = "Click to show map info"})
local frame = player.gui.top.add({ type = "frame", name = "wave_defense"})
frame.style.maximal_height = 38
local label = frame.add({ type = "label", caption = " ", name = "label"})
@@ -240,7 +240,7 @@ local function create_gui(player)
line.style.left_padding = 4
line.style.right_padding = 4
local label = frame.add({ type = "label", caption = " ", name = "threat"})
local label = frame.add({ type = "label", caption = " ", name = "threat", tooltip = "high threat may empower biters"})
label.style.font_color = {r=0.88, g=0.88, b=0.88}
label.style.font = "default-bold"
label.style.left_padding = 4

View File

@@ -22,10 +22,10 @@ local acid_nova_entities = {
local function acid_nova(entity)
if not acid_nova_entities[entity.name] then return end
if global.wave_defense.threat < 10000 then return end
if math_random(1, 32) ~= 1 then return end
if global.wave_defense.threat < 100000 then return end
if math_random(1, 16) ~= 1 then return end
for _ = 1, acid_nova_entities[entity.name].amount, 1 do
local i = math.random(1, #acid_nova_entities[entity.name].vectors)
local i = math_random(1, #acid_nova_entities[entity.name].vectors)
entity.surface.create_entity({
name = acid_nova_entities[entity.name].projectile,
position = entity.position,
@@ -40,14 +40,71 @@ local function acid_nova(entity)
return true
end
local function remove_unit(entity)
if not global.wave_defense.active_biters[entity.unit_number] then return end
global.wave_defense.active_biters[entity.unit_number] = nil
global.wave_defense.active_biter_count = global.wave_defense.active_biter_count - 1
end
local function create_particles(entity)
local particle = "stone-particle"
if entity.type == "tree" then particle = "branch-particle" end
local m = math_random(16, 24)
local m2 = m * 0.005
for i = 1, 64, 1 do
entity.surface.create_entity({
name = particle,
position = entity.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 shred_simple_entities(entity)
if math_random(1, 2) ~= 1 then return end
if global.wave_defense.threat < 10000 then return end
local simple_entities = entity.surface.find_entities_filtered({type = "simple-entity", area = {{entity.position.x - 3, entity.position.y - 3},{entity.position.x + 3, entity.position.y + 3}}})
if #simple_entities == 0 then return end
if #simple_entities > 1 then table.shuffle_table(simple_entities) end
local count = math.random(1, math.floor(global.wave_defense.threat * 0.0003))
local damage_dealt = 0
for i = 1, count, 1 do
if not simple_entities[i] then break end
if simple_entities[i].valid then
if simple_entities[i].health then
--create_particles(entity)
damage_dealt = damage_dealt + simple_entities[i].health
simple_entities[i].die("neutral", simple_entities[i])
end
end
end
if damage_dealt == 0 then return end
local threat_cost = math.floor(damage_dealt * 0.01)
if threat_cost < 1 then threat_cost = 1 end
global.wave_defense.threat = global.wave_defense.threat - threat_cost
end
local function on_entity_died(event)
if not event.entity.valid then return end
if event.entity.type ~= "unit" then return end
if not global.wave_defense.active_biters[event.entity.unit_number] then return end
global.wave_defense.active_biters[event.entity.unit_number] = nil
global.wave_defense.active_biter_count = global.wave_defense.active_biter_count - 1
if acid_nova(event.entity) then return end
if event.entity.type == "unit" then
remove_unit(event.entity)
acid_nova(event.entity)
end
if event.entity.force.index == 3 then
if event.cause then
if event.cause.valid then
if event.cause.force.index == 2 then
shred_simple_entities(event.entity)
end
end
end
end
end
local event = require 'utils.event'