1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Bug fixes (#620)

* fixed error on empty regular list

* fixed train kill count
This commit is contained in:
grilledham 2019-01-01 21:26:57 +00:00 committed by Valansch
parent 7bda4622a1
commit 14a81aedb4
2 changed files with 20 additions and 10 deletions

View File

@ -23,10 +23,10 @@ local total_player_built_entities = {0}
local total_biter_kills = {0}
local train_kill_causes = {
'locomotive',
'cargo-wagon',
'fluid-wagon',
'artillery-wagon'
['locomotive'] = true,
['cargo-wagon'] = true,
['fluid-wagon'] = true,
['artillery-wagon'] = true
}
Global.register(
@ -110,8 +110,8 @@ local function player_died(event)
local cause_count = causes[cause] or 0
causes[cause] = cause_count + 1
if table.contains(train_kill_causes, cause) then
total_train_kills = total_train_kills + 1
if train_kill_causes[cause] then
total_train_kills[1] = total_train_kills[1] + 1
end
end

View File

@ -1,15 +1,25 @@
local Event = require 'utils.event'
local function pick_name(event)
local function pick_name()
-- 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 regulars = global.regulars
local reg
if table.size(regulars) == 0 then
reg = nil
else
reg = {table.get_random(regulars, false, true), 1}
end
local name_table = {
{event.created_entity.backer_name, 8},
{false, 8},
{random_player.name, 1},
{table.get_random(global.regulars, false, true), 1},
reg
}
return table.get_random_weighted(name_table)
end
@ -21,7 +31,7 @@ local function player_built_entity(event)
end
if entity.name == 'train-stop' then
event.created_entity.backer_name = pick_name(event) or event.created_entity.backer_name
entity.backer_name = pick_name() or entity.backer_name
end
end