1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
This commit is contained in:
Gerkiz 2019-11-09 11:22:57 +01:00
parent 97983caca7
commit 7cc9e7ed5c
4 changed files with 49 additions and 149 deletions

View File

@ -1,138 +0,0 @@
-- all the kabooms -- by mewmew
local event = require 'utils.event'
local math_random = math.random
local valid_container_types = {
["container"] = true,
["logistic-container"] = true,
["car"] = true,
["cargo-wagon"] = true
}
local projectile_types = {
["land-mine"] = {name = "grenade", count = 1, max_range = 32, tick_speed = 1},
["grenade"] = {name = "grenade", count = 1, max_range = 40, tick_speed = 1},
["cluster-grenade"] = {name = "cluster-grenade", count = 1, max_range = 40, tick_speed = 3},
["artillery-shell"] = {name = "artillery-projectile", count = 1, max_range = 60, tick_speed = 3},
["cannon-shell"] = {name = "cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["explosive-cannon-shell"] = {name = "explosive-cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["explosive-uranium-cannon-shell"] = {name = "explosive-uranium-cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["uranium-cannon-shell"] = {name = "uranium-cannon-projectile", count = 1, max_range = 60, tick_speed = 1},
["atomic-bomb"] = {name = "atomic-rocket", count = 1, max_range = 80, tick_speed = 20},
["explosive-rocket"] = {name = "explosive-rocket", count = 1, max_range = 48, tick_speed = 1},
["rocket"] = {name = "rocket", count = 1, max_range = 48, tick_speed = 1},
["flamethrower-ammo"] = {name = "flamethrower-fire-stream", count = 4, max_range = 28, tick_speed = 1},
["crude-oil-barrel"] = {name = "flamethrower-fire-stream", count = 3, max_range = 24, tick_speed = 1},
["petroleum-gas-barrel"] = {name = "flamethrower-fire-stream", count = 4, max_range = 24, tick_speed = 1},
["light-oil-barrel"] = {name = "flamethrower-fire-stream", count = 4, max_range = 24, tick_speed = 1},
["heavy-oil-barrel"] = {name = "flamethrower-fire-stream", count = 4, max_range = 24, tick_speed = 1},
["sulfuric-acid-barrel"] = {name = "acid-stream-spitter-big", count = 3, max_range = 16, tick_speed = 1, force = "enemy"},
["lubricant-barrel"] = {name = "acid-stream-spitter-big", count = 3, max_range = 16, tick_speed = 1},
["railgun-dart"] = {name = "railgun-beam", count = 5, max_range = 40, tick_speed = 5},
["shotgun-shell"] = {name = "shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["piercing-shotgun-shell"] = {name = "piercing-shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["firearm-magazine"] = {name = "shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["piercing-rounds-magazine"] = {name = "piercing-shotgun-pellet", count = 16, max_range = 24, tick_speed = 1},
["uranium-rounds-magazine"] = {name = "piercing-shotgun-pellet", count = 32, max_range = 24, tick_speed = 1},
["cliff-explosives"] = {name = "cliff-explosives", count = 1, max_range = 48, tick_speed = 2},
}
local function create_projectile(surface, name, position, force, target, max_range)
surface.create_entity({
name = name,
position = position,
force = force,
source = position,
target = target,
max_range = max_range,
speed = 0.4
})
end
local function get_near_range(range)
local r = math_random(1, math.floor(range * 2))
for i = 1, 2, 1 do
local r2 = math_random(1, math.floor(range * 2))
if r2 < r then r = r2 end
end
return r
end
local function get_near_coord_modifier(range)
local coord = {x = (range * -1) + math_random(0, range * 2), y = (range * -1) + math_random(0, range * 2)}
for i = 1, 5, 1 do
local new_coord = {x = (range * -1) + math_random(0, range * 2), y = (range * -1) + math_random(0, range * 2)}
if new_coord.x^2 + new_coord.y^2 < coord.x^2 + coord.y^2 then
coord = new_coord
end
end
return coord
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)
for key, projectile in pairs(projectile_types) do
local amount = i.get_item_count(key)
local force = entity.force.name
if projectile.force then force = projectile.force end
local projectile_count = amount * projectile.count
if amount > 0 then
for t = 0, amount * projectile.tick_speed, projectile.tick_speed do
if not global.dangerous_on_tick_schedule[game.tick + t + 1] then global.dangerous_on_tick_schedule[game.tick + t + 1] = {} end
for c = 1, math.ceil(projectile.count), 1 do
local coord_modifier = get_near_coord_modifier(projectile.max_range)
global.dangerous_on_tick_schedule[game.tick + t + 1][#global.dangerous_on_tick_schedule[game.tick + t + 1] + 1] = {
func = create_projectile,
args = {
entity.surface,
projectile.name,
{x = entity.position.x, y = entity.position.y},
force,
{entity.position.x + coord_modifier.x, entity.position.y + coord_modifier.y},
get_near_range(projectile.max_range)
}
}
projectile_count = projectile_count - 1
end
if projectile_count <= 0 then break end
end
end
end
end
local function on_tick()
if not global.dangerous_on_tick_schedule[game.tick] then return end
for _, schedule in pairs(global.dangerous_on_tick_schedule[game.tick]) do
schedule.func(unpack(schedule.args))
end
global.dangerous_on_tick_schedule[game.tick] = nil
end
local function on_init(event)
if not global.dangerous_on_tick_schedule then global.dangerous_on_tick_schedule = {} end
end
event.on_init(on_init)
event.add(defines.events.on_tick, on_tick)
event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -8,7 +8,6 @@ require "modules.spawners_contain_biters"
require "modules.biters_yield_coins"
require "modules.biter_noms_you"
require "modules.explosives"
require "maps.scrapyard.dangerous_goods"
require "modules.wave_defense.main"
local WD = require "modules.wave_defense.table"
@ -335,6 +334,17 @@ local function on_player_mined_entity(event)
return
end
if entity.type == "unit" or entity.type == "unit-spawner" then
if math_random(1,160) == 1 then
tick_tack_trap(entity.surface, entity.position)
return
end
if math.random(1,32) == 1 then
hidden_biter(event.entity)
return
end
end
if entity.name == "mineable-wreckage" then
give_coin(player)
@ -396,6 +406,16 @@ local function on_entity_died(event)
return
end
if entity.type == "unit" or entity.type == "unit-spawner" then
if math_random(1,160) == 1 then
tick_tack_trap(entity.surface, entity.position)
return
end
if math.random(1,32) == 1 then
hidden_biter(event.entity)
return
end
end
if entity.name == "mineable-wreckage" then
if math.random(1,32) == 1 then
@ -433,7 +453,7 @@ local function on_built_entity(event)
local y = event.created_entity.position.y
local ent = event.created_entity
if y >= 150 then
player.print("The scrapyard grandmaster does not approve. Your " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
player.print("The scrapyard grandmaster does not approve, " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
ent.die()
return
else
@ -452,7 +472,25 @@ local function on_built_entity(event)
end
local function on_robot_built_entity(event)
on_built_entity(event)
local y = event.created_entity.position.y
local ent = event.created_entity
if y >= 150 then
game.print("The scrapyard grandmaster does not approve, " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
ent.die()
return
else
for _, e in pairs(disabled_entities) do
if e == event.created_entity.name then
if y >= 0 then
ent.active = false
if event.player_index then
game.print("The scrapyard grandmaster disabled " .. ent.name ..".", {r = 1, g = 0.5, b = 0.1})
return
end
end
end
end
end
end
local function on_research_finished(event)

View File

@ -124,7 +124,7 @@ local function wall(surface, left_top, seed)
if surface.can_place_entity({name = "stone-wall", position = p, force = "enemy"}) then
if math_random(1,512) == 1 and y > 3 and y < 28 then
if math_random(1, 2) == 1 then
Loot.add(surface, p, "bait-chest")
Loot.add(surface, p, "wooden-chest")
else
Loot.add(surface, p, "crash-site-chest-2")
end
@ -133,12 +133,12 @@ local function wall(surface, left_top, seed)
if y < 5 or y > 26 then
if y <= 15 then
if math_random(1, y + 1) == 1 then
local e = surface.create_entity({name = "stone-wall", position = p, force = "player"})
local e = surface.create_entity({name = "stone-wall", position = p, force = "enemy"})
e.minable = false
end
else
if math_random(1, 32 - y) == 1 then
local e = surface.create_entity({name = "stone-wall", position = p, force = "player"})
local e = surface.create_entity({name = "stone-wall", position = p, force = "enemy"})
e.minable = false
end
end
@ -589,7 +589,7 @@ function Public.reveal_area(x, y, surface, max_radius)
end
end
for _, p in pairs(treasure) do
local name = "bait-chest"
local name = "crash-site-chest-1"
if math_random(1, 6) == 1 then name = "crash-site-chest-2" end
Loot.add(surface, p, name)
if math_random(1,wave_defense_table.math) == 1 then
@ -651,7 +651,7 @@ function Public.reveal(player)
end
end
for _, p in pairs(treasure) do
local name = "bait-chest"
local name = "crash-site-chest-1"
if math_random(1, 6) == 1 then name = "crash-site-chest-2" end
Loot.add(surface, p, name)
end

View File

@ -23,7 +23,7 @@ local mining_chance_weights = {
{name = "water-barrel", chance = 10},
{name = "green-wire", chance = 10},
{name = "red-wire", chance = 10},
{name = "explosives", chance = 8},
{name = "explosives", chance = 5},
{name = "advanced-circuit", chance = 5},
{name = "nuclear-fuel", chance = 1},
{name = "pipe-to-ground", chance = 10},
@ -40,7 +40,7 @@ local mining_chance_weights = {
{name = "logistic-robot", chance = 1},
{name = "construction-robot", chance = 1},
{name = "land-mine", chance = 10},
{name = "land-mine", chance = 3},
{name = "grenade", chance = 10},
{name = "rocket", chance = 3},
{name = "explosive-rocket", chance = 3},
@ -74,7 +74,7 @@ local scrap_yield_amounts = {
["light-oil-barrel"] = 3,
["water-barrel"] = 3,
["battery"] = 2,
["explosives"] = 8,
["explosives"] = 4,
["advanced-circuit"] = 2,
["nuclear-fuel"] = 0.1,
["pipe-to-ground"] = 1,