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
Matthew 074ea00c54 Add regulars to potential train station names (#561)
* Add regulars to potential train station names

* Decrease odds of in-game player and regular, increase odds of backer

* Clarify that _player_ is not the player that placed the entity

* Specify random's use, cover case of nil random_player
2018-12-19 14:43:30 +01:00

30 lines
938 B
Lua

local Event = require 'utils.event'
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
local function player_built_entity(event)
local entity = event.created_entity
if not entity or not entity.valid then
return
end
if entity.name == 'train-stop' then
event.created_entity.backer_name = pick_name(event) or event.created_entity.backer_name
end
end
Event.add(defines.events.on_built_entity, player_built_entity)
Event.add(defines.events.on_robot_built_entity, player_built_entity)