1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-28 23:06:38 +02:00

landmine module changes, towny optimization for mining, small fixes

This commit is contained in:
hanakocz 2022-10-24 19:00:48 +02:00
parent 247d11d393
commit 56befa681d
5 changed files with 123 additions and 56 deletions

View File

@ -78,7 +78,7 @@ require 'utils.freeplay'
--require 'modules.wave_defense.main'
--require 'modules.fjei.main'
--require 'modules.charging_station'
--require 'modules.nuclear_landmines'
--require 'modules.landmine_effects'
--require 'modules.crawl_into_pipes'
--require 'modules.no_acid_puddles'
--require 'modules.simple_tags'

View File

@ -255,8 +255,6 @@ local function treasure_chest(position, distance_to_center)
{{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},
{{name = 'railgun', count = 1}, weight = 1, evolution_min = 0.2, evolution_max = 1},
{{name = 'railgun-dart', count = math_random(16, 32)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
{{name = 'defender-capsule', count = math_random(8, 16)}, weight = 2, evolution_min = 0.0, evolution_max = 0.7},
{{name = 'distractor-capsule', count = math_random(8, 16)}, weight = 2, evolution_min = 0.2, evolution_max = 1},
{{name = 'destroyer-capsule', count = math_random(8, 16)}, weight = 2, evolution_min = 0.3, evolution_max = 1},

View File

@ -2,39 +2,33 @@ local Public = {}
local scrapable = {
-- simple entity
'small-ship-wreck',
'medium-ship-wreck',
['small-ship-wreck'] = true,
['medium-ship-wreck'] = true,
-- simple entity with owner
'crash-site-spaceship-wreck-small-1',
'crash-site-spaceship-wreck-small-2',
'crash-site-spaceship-wreck-small-3',
'crash-site-spaceship-wreck-small-4',
'crash-site-spaceship-wreck-small-5',
'crash-site-spaceship-wreck-small-6',
'big-ship-wreck-1',
'big-ship-wreck-2',
'big-ship-wreck-3',
'crash-site-chest-1',
'crash-site-chest-2',
'crash-site-spaceship-wreck-medium-1',
'crash-site-spaceship-wreck-medium-2',
'crash-site-spaceship-wreck-medium-3',
'crash-site-spaceship-wreck-big-1',
'crash-site-spaceship-wreck-big-2',
'crash-site-spaceship'
['crash-site-spaceship-wreck-small-1'] = true,
['crash-site-spaceship-wreck-small-2'] = true,
['crash-site-spaceship-wreck-small-3'] = true,
['crash-site-spaceship-wreck-small-4'] = true,
['crash-site-spaceship-wreck-small-5'] = true,
['crash-site-spaceship-wreck-small-6'] = true,
['big-ship-wreck-1'] = true,
['big-ship-wreck-2'] = true,
['big-ship-wreck-3'] = true,
['crash-site-chest-1'] = true,
['crash-site-chest-2'] = true,
['crash-site-spaceship-wreck-medium-1'] = true,
['crash-site-spaceship-wreck-medium-2'] = true,
['crash-site-spaceship-wreck-medium-3'] = true,
['crash-site-spaceship-wreck-big-1'] = true,
['crash-site-spaceship-wreck-big-2'] = true,
['crash-site-spaceship'] = true
}
function Public.is_scrap(entity)
if not entity.valid then
return false
end
local f = false
for i = 1, #scrapable, 1 do
if entity.name == scrapable[i] then
f = true
end
end
return f
return scrapable[entity.name] or false
end
return Public

View File

@ -0,0 +1,102 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Public = {}
--by hanakocz
--module to alternate what happens when landmine gets detonated
--nuke module: there is 1 in nuke_chance chance that the landmine was hidden nuclear device
--vehicle module: landmine causes affected vehicles to lose part of speed
--vehicle_slowdown should be <0, 1>, where 1 is no effect and 0 is full loss of speed
--can also add bonus damage to hit vehicles, as landmines should be counterplay to tanks,
-- while just buffing their damage causes players being oneshot and that's not fun.
local this = {
nuke_landmines = false,
nuke_chance = 512,
vehicle_effects = true,
bonus_damage_to_vehicles = 100,
vehicle_slowdown = 0.4
}
Global.register(
this,
function(tbl)
this = tbl
end
)
local function detonate_nuke(entity)
local surface = entity.surface
surface.create_entity({name = 'atomic-rocket', position = entity.position, force = entity.force, speed = 1, max_range = 800, target = entity, source = entity})
end
local function hit_car(car, hitting_force)
if not car or not car.valid then return end
car.speed = car.speed * this.vehicle_slowdown
if this.bonus_damage_to_vehicles > 0 then
--cars do have no resistance to explosions and 450 hp
--tanks do have 15/70% resistance to explosions and 2000 hp, so get (damage - 15) * (1 - 0.70) actual damage
car.damage(this.bonus_damage_to_vehicles, hitting_force or 'enemy', 'explosion')
end
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then
return
end
if entity.type == 'land-mine' and entity.armed then
if this.vehicle_effects then
local surface = entity.surface
local cars = surface.find_entities_filtered{type = 'car', position = entity.position, radius = 6}
for _, car in pairs(cars) do
if car.force.is_enemy(entity.force) then
hit_car(car, entity.force)
end
end
end
if this.nuke_landmines then
if math.random(1, this.nuke_chance) == 1 then
detonate_nuke(entity)
end
end
end
end
--- Forces a value of nuke_landmines
---@param boolean
function Public.enable_nuke_landmines(boolean)
this.nuke_landmines = boolean or false
return this.nuke_landmines
end
--- Forces a value of vehicle_effects
---@param boolean
function Public.enable_vehicle_effects(boolean)
this.vehicle_effects = boolean or false
return this.vehicle_effects
end
--- Forces a number for bonus_damage_to_vehicles
---@param number
function Public.set_bonus_damage_to_vehicles(number)
if number and type(number) == 'number' then
this.bonus_damage_to_vehicles = number or 0
end
return this.bonus_damage_to_vehicles
end
--- Forces a number for vehicle_slowdown
---@param number
function Public.set_vehicle_slowdown(number)
if number and type(number) == 'number' then
this.vehicle_slowdown = number or 1
end
return this.vehicle_slowdown
end
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

View File

@ -1,27 +0,0 @@
local math_random = math.random
local function detonate_nuke(entity)
local surface = entity.surface
surface.create_entity({name = 'atomic-rocket', position = entity.position, force = entity.force, speed = 1, max_range = 800, target = entity, source = entity})
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then
return
end
if entity.name == 'land-mine' then
if math_random(1, global.nuclear_landmines.chance) == 1 then
detonate_nuke(entity)
end
end
end
local function on_init()
global.nuclear_landmines = {}
global.nuclear_landmines.chance = 512
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_died, on_entity_died)