2021-02-06 22:42:10 +02:00
local string_sub = string.sub
local string_len = string.len
-- ammo damage modifiers are static values that increase with research
-- modifier is multiplied by base damage and then added to damage, so a negative value will reduce base damage and a positive value will increase damage
local balance_functions = {
2021-03-24 17:46:00 +02:00
[ ' land-mine ' ] = function ( force_name )
-- landmines normally have a modifier of 0, so have them start at 25% of normal
if force_name ~= nil then
game.forces [ force_name ] . set_ammo_damage_modifier ( ' landmine ' , - 0.75 )
end
end ,
[ ' military-2 ' ] = function ( force_name )
-- grenades normally have a modifier of 0, so have them start at 50% of normal
if force_name ~= nil then
game.forces [ force_name ] . set_ammo_damage_modifier ( ' grenade ' , - 0.5 )
end
end ,
[ ' military-4 ' ] = function ( force_name )
-- cluster-grenades normally have a modifier of 0, so have them start at 50% of normal
if force_name ~= nil then
game.forces [ force_name ] . set_ammo_damage_modifier ( ' grenade ' , - 0.5 )
end
end ,
[ ' stronger-explosives ' ] = function ( force_name )
-- landmines should never increase in damage with stronger explosives
if force_name ~= nil then
game.forces [ force_name ] . set_ammo_damage_modifier ( ' landmine ' , - 0.75 )
-- allow grenades to increase by 10%
game.forces [ force_name ] . set_ammo_damage_modifier ( ' grenade ' , game.forces [ force_name ] . get_ammo_damage_modifier ( ' grenade ' ) + 0.1 )
end
end
2021-02-06 22:42:10 +02:00
}
local function on_research_finished ( event )
2021-03-24 17:46:00 +02:00
local research_name = event.research . name
local force_name = event.research . force.name
for b = 1 , string_len ( research_name ) , 1 do
2022-03-01 20:11:08 +02:00
local key = string_sub ( research_name , 0 , b )
2021-03-24 17:46:00 +02:00
if balance_functions [ key ] then
balance_functions [ key ] ( force_name )
return
end
end
2021-02-06 22:42:10 +02:00
end
local Event = require ' utils.event '
Event.add ( defines.events . on_research_finished , on_research_finished )