Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added player research scaling #862

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ global.config = {
player_onboarding = {
enabled = true
},
-- increases technology price multiplier with number of connected players
research_scaling = {
enabled = false,
-- the increase in the multiplier with every player
scale_value = 0.05,
-- max increase in research price multiplier (-1 for disabled)
limit = -1
},
-- allows for large-scale biter attacks
biter_attacks = {
enabled = true,
Expand Down
3 changes: 3 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ end
if config.rich_text_gui.enabled then
require 'features.gui.rich_text'
end
if config.research_scaling.enabled then
require 'features.research_scaling'
end

-- Debug-only modules
if _DEBUG then
Expand Down
48 changes: 48 additions & 0 deletions features/research_scaling.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---Scales technology price multiplier based on number of online players.
---It does so only when finished research
local Event = require 'utils.event'
local Global = require 'utils.global'

local config = global.config.research_scaling
local limit = config.limit
local scale_value = config.scale_value

local multipliers = {
current_multiplier = 0,
old_multiplier = 0,
old_setting = 0
}

Global.register(
{
multipliers = multipliers
},
function(tbl)
multipliers = tbl.multipliers
end
)

local function update_research_cost()
local player_count = #game.connected_players
local setting = game.difficulty_settings.technology_price_multiplier
local modifier = player_count * scale_value - scale_value
-- if config.limit is enabled, make sure the modifier doesn't exceed the limit
if limit ~= -1 then
modifier = (modifier <= limit) and modifier or limit
end

-- keeping track of old and new multiplier
multipliers.old_multiplier = multipliers.current_multiplier
multipliers.current_multiplier = modifier

-- setting new modifier by subtracting old multiplier from setting and adding the new
if setting == multipliers.old_setting then
modifier = setting - multipliers.old_multiplier + modifier
else -- if the setting was changed in between add the modifier a new.
modifier = setting + modifier
end
game.difficulty_settings.technology_price_multiplier = modifier
multipliers.old_setting = modifier
end

Event.add(defines.events.on_research_finished, update_research_cost)