1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00
RedMew/features/train_station_names.lua

30 lines
938 B
Lua
Raw Normal View History

2018-05-19 14:53:38 +02:00
local Event = require 'utils.event'
2018-04-06 21:58:50 +02:00
local function pick_name(event)
-- 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
local name_table = {
{event.created_entity.backer_name, 8},
{random_player.name, 1},
{table.get_random(global.regulars, false, true), 1},
}
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 14:53:38 +02:00
local entity = event.created_entity
if not entity or not entity.valid then
return
end
2017-06-13 13:16:07 +02:00
2018-05-19 14:53:38 +02:00
if entity.name == 'train-stop' then
event.created_entity.backer_name = pick_name(event) or event.created_entity.backer_name
2018-05-19 14:53:38 +02:00
end
2017-06-13 13:16:07 +02:00
end
2018-04-06 21:58:50 +02:00
Event.add(defines.events.on_built_entity, player_built_entity)
Event.add(defines.events.on_robot_built_entity, player_built_entity)