2018-05-19 13:53:38 +01:00
|
|
|
local Event = require 'utils.event'
|
2018-04-06 20:58:50 +01:00
|
|
|
|
2019-01-01 21:26:57 +00:00
|
|
|
local function pick_name()
|
2018-12-19 08:43:30 -05:00
|
|
|
-- Create a weight table comprised of the backer name, a player's name, and a regular's name
|
|
|
|
local random_player = table.get_random(game.players, true)
|
|
|
|
if not random_player then
|
|
|
|
return
|
|
|
|
end
|
2019-01-01 21:26:57 +00:00
|
|
|
|
|
|
|
local regulars = global.regulars
|
|
|
|
|
|
|
|
local reg
|
|
|
|
if table.size(regulars) == 0 then
|
|
|
|
reg = nil
|
|
|
|
else
|
|
|
|
reg = {table.get_random(regulars, false, true), 1}
|
|
|
|
end
|
|
|
|
|
2018-12-19 08:43:30 -05:00
|
|
|
local name_table = {
|
2019-01-01 21:26:57 +00:00
|
|
|
{false, 8},
|
2018-12-19 08:43:30 -05:00
|
|
|
{random_player.name, 1},
|
2019-01-01 21:26:57 +00:00
|
|
|
reg
|
2018-12-19 08:43:30 -05:00
|
|
|
}
|
|
|
|
return table.get_random_weighted(name_table)
|
|
|
|
end
|
|
|
|
|
2017-06-13 13:16:07 +02:00
|
|
|
local function player_built_entity(event)
|
2018-05-19 13:53:38 +01:00
|
|
|
local entity = event.created_entity
|
2018-11-20 05:46:19 -05:00
|
|
|
if not entity or not entity.valid then
|
|
|
|
return
|
|
|
|
end
|
2017-06-13 13:16:07 +02:00
|
|
|
|
2018-05-19 13:53:38 +01:00
|
|
|
if entity.name == 'train-stop' then
|
2019-01-01 21:26:57 +00:00
|
|
|
entity.backer_name = pick_name() or entity.backer_name
|
2018-05-19 13:53:38 +01:00
|
|
|
end
|
2017-06-13 13:16:07 +02:00
|
|
|
end
|
|
|
|
|
2018-04-06 20:58:50 +01:00
|
|
|
Event.add(defines.events.on_built_entity, player_built_entity)
|
|
|
|
Event.add(defines.events.on_robot_built_entity, player_built_entity)
|