From 8a91c249f1801c5999c2a9ec87bff2d336914bdd Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sat, 18 Dec 2021 14:04:02 +0100 Subject: [PATCH] Explosives Added cliff-explosives to explosives. --- modules/explosives.lua | 54 +++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/modules/explosives.lua b/modules/explosives.lua index c47820cf..9785c0f8 100644 --- a/modules/explosives.lua +++ b/modules/explosives.lua @@ -4,7 +4,11 @@ local Collapse = require 'modules.collapse' local this = { explosives = {}, settings = { - check_growth_below_void = false + check_growth_below_void = false, + valid_items = { + ['explosives'] = 500, + ['cliff-explosives'] = 750 + } } } Global.register( @@ -113,13 +117,6 @@ local function grow_cell(cell) local new_cell_health = math_round(cell.health / #positions, 3) - this.explosives.damage_decay - --[[ - if new_cell_health > 0 then - this.explosives.cells_damage_dealt = this.explosives.cells_damage_dealt + damage_decay * #positions - else - this.explosives.cells_damage_dealt = this.explosives.cells_damage_dealt + (new_cell_health + damage_decay) * #positions - end - ]] if new_cell_health <= 0 then return end @@ -237,6 +234,17 @@ local function tick() end end +local function check_entity_for_items(item) + local items = this.settings.valid_items + for name, damage in pairs(items) do + local amount = item.get_item_count(name) + if amount and amount > 1 then + return amount, damage + end + end + return false +end + local function on_entity_died(event) local entity = event.entity if not entity.valid then @@ -256,22 +264,13 @@ local function on_entity_died(event) inventory = defines.inventory.car_trunk end - local i = entity.get_inventory(inventory) - local amount = i.get_item_count('explosives') + local item = entity.get_inventory(inventory) + local amount, damage = check_entity_for_items(item) 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 * this.explosives.damage_per_explosive - ) + 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) end function Public.detonate_chest(entity) @@ -292,8 +291,8 @@ function Public.detonate_chest(entity) inventory = defines.inventory.car_trunk end - local i = entity.get_inventory(inventory) - local amount = i.get_item_count('explosives') + local item = entity.get_inventory(inventory) + local amount, damage = check_entity_for_items(item) if not amount then return false end @@ -301,13 +300,7 @@ function Public.detonate_chest(entity) return false 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 * this.explosives.damage_per_explosive - ) + 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) return true end @@ -317,9 +310,6 @@ function Public.reset() if not this.explosives.vectors then this.explosives.vectors = {{density, 0}, {density * -1, 0}, {0, density}, {0, density * -1}} end - if not this.explosives.damage_per_explosive then - this.explosives.damage_per_explosive = 500 - end if not this.explosives.damage_decay then this.explosives.damage_decay = 10 end