1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00
This commit is contained in:
grilledham 2018-10-03 21:06:01 +01:00
commit b90a4d68ae
49 changed files with 3141 additions and 719 deletions

View File

@ -1,5 +1,6 @@
local Event = require "utils.event"
local Utils = require "utils.utils"
local Game = require 'utils.game'
global.original_last_users_by_ent_pos = {}
@ -53,7 +54,7 @@ end
local function on_entity_changed(event)
local entity = event.entity or event.destination
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if player.admin or not entity.valid then return end --Freebees for admins
if entity.last_user ~= player and entity.force == player.force then --commented out to be able to debug
place_entity_on_surface(entity, global.ag_surface, true, event.player_index)
@ -92,7 +93,7 @@ Event.add(defines.events.on_player_rotated_entity, function(event)
--The mocked entity has the entity state before rotation
--We also dont know who rotated it and dont want the griefers name there so we set it to 1
local mock_entity = {name = entity.name, position = entity.position, mock = true,
last_user = game.players[1], force = entity.force, direction = get_pre_rotate_direction(entity)}
last_user = Game.get_player_by_index(1), force = entity.force, direction = get_pre_rotate_direction(entity)}
event.entity = mock_entity
on_entity_changed(event)
end
@ -128,7 +129,7 @@ local Module = {}
Module.undo = function(player)
if type(player) == "nil" or type(player) == "string" then return --No support for strings!
elseif type(player) == "number" then player = game.players[player] end
elseif type(player) == "number" then player = Game.get_player_by_index(player) end
--Remove all items from all surfaces that player placed an entity on
for _,surface in pairs(game.surfaces) do

View File

@ -3,6 +3,7 @@
local Event = require 'utils.event'
local Token = require 'utils.global_token'
local Gui = require 'utils.gui'
local Game = require 'utils.game'
local function getBlueprintCursorStack(player)
local cursor = player.cursor_stack
@ -265,7 +266,7 @@ local filter_table_clear_name = Gui.uid_name()
local clear_all_filters_name = Gui.uid_name()
local function player_joined(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

17
bot.lua
View File

@ -1,30 +1,31 @@
local Event = require "utils.event"
local Game = require 'utils.game'
Event.add(defines.events.on_player_died, function (event)
local player = event.player_index
if game.players[player].name ~= nil then
print("PLAYER$die," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$die," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
end
end)
Event.add(defines.events.on_player_respawned, function (event)
local player = event.player_index
if game.players[player].name ~= nil then
print("PLAYER$respawn," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$respawn," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
end
end)
Event.add(defines.events.on_player_joined_game, function (event)
local player = event.player_index
if game.players[player].name ~= nil then
print("PLAYER$join," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$join," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
end
end)
Event.add(defines.events.on_player_left_game, function (event)
local player = event.player_index
if game.players[player].name ~= nil then
print("PLAYER$leave," .. player .. "," .. game.players[player].name .. "," .. game.players[player].force.name)
if Game.get_player_by_index(player).name ~= nil then
print("PLAYER$leave," .. player .. "," .. Game.get_player_by_index(player).name .. "," .. Game.get_player_by_index(player).force.name)
end
end)

View File

@ -2,6 +2,11 @@ require 'config'
require 'utils.utils'
require 'utils.list_utils'
local UserGroups = require 'user_groups'
require 'utils.math_fix'
local Game = require 'utils.game'
require 'user_groups'
require 'custom_commands'
require 'base_data'
require 'train_station_names'
@ -34,7 +39,7 @@ local Event = require 'utils.event'
local Donators = require 'resources.donators'
local function player_created(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
@ -126,13 +131,13 @@ local function hodor(event)
end
-- player_index is nil if the message came from the server,
-- and indexing game.players with nil is apparently an error.
-- and indexing Game.players with nil is apparently an error.
local player_index = event.player_index
if not player_index then
return
end
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
@ -154,7 +159,7 @@ local function hodor(event)
end
local function player_joined(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
@ -164,7 +169,7 @@ local function player_joined(event)
return
end
game.print(table.concat({'*** ', message, ' ***'}))
game.print(table.concat({'*** ', message, ' ***'}), player.chat_color)
end
Event.add(defines.events.on_player_created, player_created)
@ -179,7 +184,7 @@ Event.add(
local p_index = event.player_index
local name
if p_index then
name = game.players[event.player_index].name
name = Game.get_player_by_index(event.player_index).name
else
name = '<server>'
end
@ -244,7 +249,7 @@ Event.add(
defines.events.on_player_crafted_item,
function(event)
local pi = event.player_index
local p = game.players[pi]
local p = Game.get_player_by_index(pi)
if not p or not p.valid or not p.cheat_mode then
return
@ -275,7 +280,7 @@ Event.add(
function print_cheated_items()
local res = {}
local players = game.players
local players = Game.players
for pi, data in pairs(global.cheated_items) do
res[players[pi].name] = data
@ -291,7 +296,7 @@ Event.add(
if not player_index then
return
end
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
local command = event.parameters or ''
if player.name:lower() == 'gotze' and string.find(command, 'insert') then
string.gsub(

View File

@ -2,6 +2,7 @@ local Event = require 'utils.event'
local Global = require 'utils.global'
local Task = require 'utils.Task'
local Token = require 'utils.global_token'
local Game = require 'utils.game'
local player_corpses = {}
@ -14,7 +15,7 @@ Global.register(
local function player_died(event)
local player_index = event.player_index
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
if not player or not player.valid then
return

View File

@ -3,6 +3,7 @@ local Event = require 'utils.event'
local Token = require 'utils.global_token'
local UserGroups = require 'user_groups'
local Utils = require 'utils.utils'
local Game = require 'utils.game'
--local Antigrief = require 'antigrief'
function player_print(str)
@ -297,7 +298,7 @@ local function built_entity(event)
return
end
game.players[index].teleport(entity.position)
Game.get_player_by_index(index).teleport(entity.position)
entity.destroy()
end
end
@ -740,7 +741,7 @@ commands.add_command(
'Shows user reports (Admins only)',
function(event)
if game.player and game.player.admin then
Report.show_reports(game.players[event.player_index])
Report.show_reports(Game.get_player_by_index(event.player_index))
end
end
)

View File

@ -20,6 +20,7 @@ local Event = require 'utils.event'
local Token = require 'utils.global_token'
local Task = require 'utils.Task'
local PlayerStats = require 'player_stats'
local Game = require 'utils.game'
local Market_items = require 'resources.market_items'
local market_item = Market_items.market_item
@ -115,7 +116,7 @@ local total_fish_market_bonus_messages = #fish_market_bonus_message
local function fish_earned(event, amount)
local player_index = event.player_index
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
local stack = {name = market_item, count = amount}
local inserted = player.insert(stack)
@ -311,12 +312,12 @@ local function market_item_purchased(event)
PlayerStats.change_coin_spent(player_index, fish_cost)
if event.offer_index == 1 then -- Temporary speed bonus
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
boost_player_runningspeed(player, market)
end
if event.offer_index == 2 then -- Temporary mining bonus
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
boost_player_miningspeed(player, market)
end
@ -376,14 +377,14 @@ local function on_180_ticks()
if global.player_speed_boost_records then
for k, v in pairs(global.player_speed_boost_records) do
if game.tick - v.start_tick > 3000 then
reset_player_runningspeed(game.players[k])
reset_player_runningspeed(Game.get_player_by_index(k))
end
end
end
if global.player_mining_boost_records then
for k, v in pairs(global.player_mining_boost_records) do
if game.tick - v.start_tick > 6000 then
reset_player_miningspeed(game.players[k])
reset_player_miningspeed(Game.get_player_by_index(k))
end
end
end

View File

@ -1,6 +1,7 @@
global.follows = {}
global.follows.n_entries = 0
local Utils = require "utils.utils"
local Game = require 'utils.game'
function get_direction(follower, target)
local delta_x = target.position.x - follower.position.x
@ -41,7 +42,7 @@ end
function walk_on_tick()
if global.follows.n_entries > 0 then
for k,v in pairs(global.follows) do
local follower = game.players[k]
local follower = game.playesr[k]
local target = game.players[v]
if follower ~= nil and target ~= nil then
local d = Utils.distance(follower, target)

View File

@ -3,6 +3,7 @@ local Token = require 'utils.global_token'
local Gui = require 'utils.gui'
local Task = require 'utils.Task'
local Global = require 'utils.global'
local Game = require 'utils.game'
local chests = {}
local chests_next = {}
@ -188,7 +189,7 @@ local function gui_opened(event)
return
end
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
@ -224,7 +225,7 @@ Event.add(defines.events.on_gui_opened, gui_opened)
Event.add(
defines.events.on_player_died,
function(event)
local player = game.players[event.player_index or 0]
local player = Game.get_player_by_index(event.player_index or 0)
if not player or not player.valid then
return

View File

@ -2,6 +2,7 @@ local Gui = require 'utils.gui'
local Global = require 'utils.global'
local Event = require 'utils.event'
local UserGroups = require 'user_groups'
local Game = require 'utils.game'
local normal_color = {r = 1, g = 1, b = 1}
local focus_color = {r = 1, g = 0.55, b = 0.1}
@ -633,7 +634,7 @@ local function toggle(event)
end
local function player_created(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return

View File

@ -16,7 +16,7 @@ random game events // earthquake, biters, rock treasure, messages
local simplex_noise = require 'map_gen.shared.simplex_noise'
local Event = require 'utils.event'
local market_items = require "map_gen.combined.cave_miner.market_items"
local Game = require 'utils.game'
local Info = require 'info'
@ -473,7 +473,7 @@ end
local function on_player_joined_game(event)
local surface = game.surfaces[1]
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not global.cave_miner_init_done then
local p = surface.find_non_colliding_position("player", {0,-40}, 10, 1)
game.forces["player"].set_spawn_position(p,surface)
@ -765,7 +765,7 @@ local function on_tick(event)
if game.forces.map_pregen.is_chunk_charted(game.surfaces[1], {40,40}) then
game.print("Map generation done!", { r=0.22, g=0.99, b=0.99})
game.players[1].force = game.forces["player"]
Game.get_player_by_index(1).force = game.forces["player"]
global.map_pregeneration_is_active = nil
end
end
@ -774,7 +774,7 @@ end
local function on_marked_for_deconstruction(event)
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
event.entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force.name)
end
end
@ -790,7 +790,7 @@ local function pre_player_mined_item(event)
end
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
local rock_position = {x = event.entity.position.x, y = event.entity.position.y}
event.entity.destroy()
local tile_distance_to_center = math.sqrt(rock_position.x^2 + rock_position.y^2)
@ -873,7 +873,7 @@ local function on_player_mined_entity(event)
end
if event.entity.name == "fish" then
if math.random(1,2) == 1 then
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
local health = player.character.health
player.character.damage(math.random(50,150),"enemy")
if not player.character then
@ -920,7 +920,7 @@ local function on_entity_damaged(event)
end
local function on_player_respawned(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
player.character.disable_flashlight()
global.player_hunger[player.name] = global.player_hunger_spawn_value
hunger_update(player, 0)
@ -936,7 +936,7 @@ end
local function on_gui_click(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.element.player_index]
local player = Game.get_player_by_index(event.element.player_index)
local name = event.element.name
local frame = player.gui.top["caver_miner_stats_frame"]
@ -951,7 +951,7 @@ end
local function on_player_used_capsule(event)
if event.item.name == "raw-fish" then
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
hunger_update(player, global.player_hunger_fish_food_value)
player.play_sound{path="utility/armor_insert", volume_modifier=1}
refresh_gui()
@ -961,7 +961,7 @@ end
function map_pregen()
local radius = 1280
if not game.forces.map_pregen then game.create_force("map_pregen") end
game.players[1].force = game.forces["map_pregen"]
Game.get_player_by_index(1).force = game.forces["map_pregen"]
game.forces.map_pregen.chart(game.surfaces[1],{{x = -1 * radius, y = -1 * radius}, {x = radius, y = radius}})
global.map_pregeneration_is_active = true
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
global.allowed_entites = {
['transport-belt'] = true,
@ -53,7 +54,7 @@ Event.add(
return
end
local p = game.players[event.player_index]
local p = Game.get_player_by_index(event.player_index)
if not p or not p.valid then
return
end

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
global.allowed_landfill_tiles = {}
@ -29,7 +30,7 @@ Event.add(
local surface = game.surfaces[event.surface_index]
surface.set_tiles(new_tiles)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
player.insert {name = item_name, count = count}
end
)

View File

@ -1,4 +1,5 @@
local Event = require "utils.event"
local Game = require 'utils.game'
Event.on_init(function()
@ -12,7 +13,7 @@ Event.on_init(function()
end)
Event.add(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
--player.print("Info: PVP server mod 'Bearded Snails' (c) byte");
guiNewPlayer(player.gui.left);
printNewPlayer(player);
@ -30,7 +31,7 @@ Event.add(defines.events.on_player_created, function(event)
end)
Event.add(defines.events.on_player_respawned, function(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
player.insert{name="heavy-armor", count=1}
player.insert{name="pistol", count=1}
@ -69,7 +70,7 @@ Event.add(defines.events.on_rocket_launched, function(event)
end)
Event.add(defines.events.on_gui_click, function(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
local gui = player.gui.left;
if player.force == game.forces.player and event.element.name == "new_button" then
@ -91,7 +92,7 @@ Event.add(defines.events.on_gui_click, function(event)
elseif event.element.name == "inv_button" then
local name = gui.own_force.inv_name.text;
if name ~= nil and validPlayer(name) then
local iplayer = game.players[name];
local iplayer = Game.get_player_by_index(name);
local igui = iplayer.gui.left;
iplayer.force = player.force;
@ -142,7 +143,7 @@ function dist(position1, position2)
end
function validPlayer(name)
if name ~= nil and game.players[name] ~= nil and game.players[name].force == game.forces.player then
if name ~= nil and Game.get_player_by_index(name) ~= nil and Game.get_player_by_index(name).force == game.forces.player then
return true;
end
return false;

View File

@ -4,6 +4,7 @@ require("rso_config")
require("util")
require("rso_resource_config")
local Utils = require "utils.utils"
local Game = require 'utils.game'
local MB=require "metaball"
local drand = require 'drand'
@ -32,9 +33,9 @@ local max = math.max
local function rso_debug(str)
if rso_debug_enabled then
if (type(str) == "table") then
game.players[1].print(serpent.dump(str))
Game.get_player_by_index(1).print(serpent.dump(str))
else
game.players[1].print(str)
Game.get_player_by_index(1).print(str)
end
end
end
@ -1136,26 +1137,26 @@ function RSO_init()
initDone = true
if surface.map_gen_settings.autoplace_controls["iron-ore"].size ~= "none" then
game.players[1].print("RSO WARNING - VANILLA iron-ore GEN IS NOT DISABLED!")
Game.get_player_by_index(1).print("RSO WARNING - VANILLA iron-ore GEN IS NOT DISABLED!")
end
if surface.map_gen_settings.autoplace_controls["copper-ore"].size ~= "none" then
game.players[1].print("RSO WARNING - VANILLA copper-ore GEN IS NOT DISABLED!")
Game.get_player_by_index(1).print("RSO WARNING - VANILLA copper-ore GEN IS NOT DISABLED!")
end
if surface.map_gen_settings.autoplace_controls["uranium-ore"].size ~= "none" then
game.players[1].print("RSO WARNING - VANILLA uranium-ore GEN IS NOT DISABLED!")
Game.get_player_by_index(1).print("RSO WARNING - VANILLA uranium-ore GEN IS NOT DISABLED!")
end
if surface.map_gen_settings.autoplace_controls["crude-oil"].size ~= "none" then
game.players[1].print("RSO WARNING - VANILLA crude-oil GEN IS NOT DISABLED!")
Game.get_player_by_index(1).print("RSO WARNING - VANILLA crude-oil GEN IS NOT DISABLED!")
end
if surface.map_gen_settings.autoplace_controls["enemy-base"].size ~= "none" then
-- Not a problem, as this RSO does not gen biters
-- game.players[1].print("RSO WARNING - VANILLA enemy-base GEN IS NOT DISABLED!")
-- Game.get_player_by_index(1).print("RSO WARNING - VANILLA enemy-base GEN IS NOT DISABLED!")
end
if surface.map_gen_settings.autoplace_controls["stone"].size ~= "none" then
game.players[1].print("RSO WARNING - VANILLA stone GEN IS NOT DISABLED!")
Game.get_player_by_index(1).print("RSO WARNING - VANILLA stone GEN IS NOT DISABLED!")
end
if surface.map_gen_settings.autoplace_controls["coal"].size ~= "none" then
game.players[1].print("RSO WARNING - VANILLA coal GEN IS NOT DISABLED!")
Game.get_player_by_index(1).print("RSO WARNING - VANILLA coal GEN IS NOT DISABLED!")
end
end

View File

@ -1,8 +1,9 @@
local Global = require 'utils.global'
local seed = nil -- Set to number to force seed.
local resource_rate = 768 -- Number of tiles per resouce on average.
local seed = nil -- Set to number to force seed.
local generator
Global.register_init(
@ -24,43 +25,47 @@ local function value(base, mult, pow)
end
end
local ores = {
{'iron-ore', value(40000, 20, 1.5), 100},
{'copper-ore', value(40000, 20, 1.5), 60},
{'coal', value(40000, 20, 1.25), 25},
{'stone', value(20000, 20, 1.25), 15},
{'uranium-ore', value(5000, 5, 1.35), 5},
{'crude-oil', value(600000, 200, 1.25), 4}
}
return function(tiles_per_resource)
resource_rate = tiles_per_resource or 768
local total_weights = {}
local t = 0
for _, v in ipairs(ores) do
t = t + v[3]
local ores = {
{'iron-ore', value(40000, 20, 1.5), 100},
{'copper-ore', value(40000, 20, 1.5), 60},
{'coal', value(40000, 20, 1.25), 25},
{'stone', value(20000, 20, 1.25), 15},
{'uranium-ore', value(5000, 5, 1.35), 5},
{'crude-oil', value(600000, 200, 1.25), 4}
}
local total_weights = {}
local t = 0
for _, v in ipairs(ores) do
t = t + v[3]
table.insert(total_weights, t)
end
t = resource_rate * t
table.insert(ores, {false})
table.insert(total_weights, t)
end
t = resource_rate * t
table.insert(ores, {false})
table.insert(total_weights, t)
return function(x, y, world)
local r_seed = bit32.band(x * 374761393 + y * 668265263 + seed, 4294967295)
generator.re_seed(r_seed)
local i = generator(t)
return function(x, y)
local r_seed = bit32.band(x * 374761393 + y * 668265263 + seed, 4294967295)
generator.re_seed(r_seed)
local i = generator(t)
local index = table.binary_search(total_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
local index = table.binary_search(total_weights, i)
if (index < 0) then
index = bit32.bnot(index)
local ore_data = ores[index]
local ore = ore_data[1]
if not ore then
return
end
local amount = ore_data[2](world.x, world.y)
return {name = ore, amount = amount}
end
local ore_data = ores[index]
local ore = ore_data[1]
if not ore then
return
end
local amount = ore_data[2](x, y)
return {name = ore, amount = amount}
end

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ local Gui = require 'utils.gui'
local Event = require 'utils.event'
local Global = require 'utils.global'
local PlayerStats = require 'player_stats'
local Game = require 'utils.game'
local Public = {}
@ -118,7 +119,7 @@ local function gui_opened(event)
return
end
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
@ -156,7 +157,7 @@ Gui.on_custom_close(
Event.add(
defines.events.on_player_died,
function(event)
local player = game.players[event.player_index or 0]
local player = Game.get_player_by_index(event.player_index or 0)
if not player or not player.valid then
return

View File

@ -6,59 +6,104 @@ This map has isolated areas, it's recommend turning biters to peaceful to reduce
local b = require 'map_gen.shared.builders'
-- change these to change the pattern.
local seed1 = 1234
local seed2 = 5678
local seed1 = 12345
local seed2 = 56789
local value = b.manhattan_value
local fish_scale = 1.75
local value = b.exponential_value
local pic = require 'map_gen.data.presets.fish'
pic = b.decompress(pic)
local fish = b.picture(pic)
fish = b.change_tile(fish, 'water', false)
fish = b.scale(fish, fish_scale)
local ores = {
{resource_type = 'iron-ore', value = value(250, 2)},
{resource_type = 'copper-ore', value = value(200, 1.5)},
{resource_type = 'stone', value = value(200, 0.8)},
{resource_type = 'coal', value = value(400, 0.8)},
{resource_type = 'uranium-ore', value = value(50, 0.2)},
{resource_type = 'crude-oil', value = value(50000, 350)}
{resource_type = 'iron-ore', value = value(75, 0.25, 1.15)},
{resource_type = 'copper-ore', value = value(65, 0.2, 1.15)},
{resource_type = 'stone', value = value(50, 0.2, 1.1)},
{resource_type = 'coal', value = value(50, 0.15, 1.1)},
{resource_type = 'uranium-ore', value = value(10, 0.1, 1.075)},
{resource_type = 'crude-oil', value = value(25000, 25, 1.15)}
}
local cap = b.translate(b.rectangle(48, 48), 100, 0)
local cap = b.translate(b.rectangle(48 * fish_scale, 48 * fish_scale), 100 * fish_scale, 0)
local rich_tile = b.rectangle(3, 3)
rich_tile = b.translate(rich_tile, 100 * fish_scale, 0)
local function rich_value()
return 1111111
end
local iron = b.resource(cap, ores[1].resource_type, ores[1].value)
local copper = b.resource(cap, ores[2].resource_type, ores[2].value)
local stone = b.resource(cap, ores[3].resource_type, ores[3].value)
local coal = b.resource(cap, ores[4].resource_type, ores[4].value)
local uranium = b.resource(cap, ores[5].resource_type, ores[5].value)
local iron =
b.any {
b.resource(rich_tile, ores[1].resource_type, rich_value),
b.resource(cap, ores[1].resource_type, ores[1].value)
}
local copper =
b.any {
b.resource(rich_tile, ores[2].resource_type, rich_value),
b.resource(cap, ores[2].resource_type, ores[2].value)
}
local stone =
b.any {
b.resource(rich_tile, ores[3].resource_type, rich_value),
b.resource(cap, ores[3].resource_type, ores[3].value)
}
local coal =
b.any {
b.resource(rich_tile, ores[4].resource_type, rich_value),
b.resource(cap, ores[4].resource_type, ores[4].value)
}
local uranium =
b.any {
b.resource(rich_tile, ores[5].resource_type, rich_value),
b.resource(cap, ores[5].resource_type, ores[5].value)
}
local oil = b.resource(b.throttle_world_xy(cap, 1, 8, 1, 8), ores[6].resource_type, ores[6].value)
local worm_names = {'small-worm-turret', 'medium-worm-turret', 'big-worm-turret'}
local factor = 1 / (1024 * 16)
local max_chance = 1 / 2
local worm_names = {
'small-worm-turret',
'medium-worm-turret',
'big-worm-turret'
}
local max_worm_chance = 1 / 64
local worm_chance_factor = 1 / 256
local function worms(x, y, world)
if not cap(x, y) then
return nil
end
local wx, wy = world.x, world.y
local d = math.sqrt(wx * wx + wy * wy)
local d = math.sqrt(world.x * world.x + world.y * world.y)
local worm_chance = d - 64
local lvl
if d < 192 then
lvl = 1
elseif d < 384 then
lvl = 2
else
lvl = 3
end
if worm_chance > 0 then
worm_chance = worm_chance * worm_chance_factor
worm_chance = math.min(worm_chance, max_worm_chance)
local chance = math.min(max_chance, d * factor)
if math.random() < chance then
local worm_id = math.random(1, lvl)
return {name = worm_names[worm_id]}
if math.random() < worm_chance then
if d < 512 then
return {name = 'small-worm-turret'}
else
local max_lvl
local min_lvl
if d < 1024 then
max_lvl = 2
min_lvl = 1
else
max_lvl = 3
min_lvl = 2
end
local lvl = math.random() ^ (512 / d) * max_lvl
lvl = math.ceil(lvl)
lvl = math.clamp(lvl, min_lvl, 3)
return {name = worm_names[lvl]}
end
end
end
end
@ -120,7 +165,7 @@ for c = 1, p_cols do
end
end
local map = b.grid_pattern_full_overlap(pattern, p_cols, p_rows, 215, 215)
local map = b.grid_pattern_full_overlap(pattern, p_cols, p_rows, 215 * fish_scale, 215 * fish_scale)
local start = require 'map_gen.data.presets.soy_sauce'
start = b.decompress(start)
@ -141,13 +186,13 @@ start_copper = b.translate(start_copper, 32, 0)
start_stone = b.translate(start_stone, 0, 32)
start_coal = b.translate(start_coal, 0, -32)
start_iron = b.resource(start_iron, ores[1].resource_type, value(1000, 0.5))
start_copper = b.resource(start_copper, ores[2].resource_type, value(800, 0.5))
start_stone = b.resource(start_stone, ores[3].resource_type, value(600, 0.5))
start_coal = b.resource(start_coal, ores[4].resource_type, value(600, 0.5))
start_iron = b.resource(start_iron, ores[1].resource_type, value(1000, 0.5, 1))
start_copper = b.resource(start_copper, ores[2].resource_type, value(800, 0.5, 1))
start_stone = b.resource(start_stone, ores[3].resource_type, value(600, 0.5, 1))
start_coal = b.resource(start_coal, ores[4].resource_type, value(600, 0.5, 1))
local start_oil = b.translate(b.rectangle(1, 1), -44, 74)
start_oil = b.resource(start_oil, ores[6].resource_type, value(100000, 0))
start_oil = b.resource(start_oil, ores[6].resource_type, value(100000, 0, 1))
local worms_area = b.rectangle(150, 72)
worms_area = b.translate(worms_area, 0, -210)
@ -176,4 +221,7 @@ local sea = b.fish(sea, 0.0025)
map = b.if_else(map, sea)
--map = b.scale(map, 2, 2)
--map = b.apply_entity(b.full_shape, iron)
return map

View File

@ -1,43 +1,172 @@
local b = require "map_gen.shared.builders"
local b = require 'map_gen.shared.builders'
local Random = require 'map_gen.shared.random'
local seed1 = 17000
local seed2 = seed1 * 2
local ore_blocks = 100
local ore_block_size = 32
local random_ore = Random.new(seed1, seed2)
local small_ore_patch = b.circle(12)
local medium_ore_patch = b.circle(24)
local big_ore_patch = b.subtract(b.circle(36), b.circle(16))
local ore_patches = {
{shape = small_ore_patch, weight = 3},
{shape = medium_ore_patch, weight = 2},
{shape = big_ore_patch, weight = 1}
}
local total_ore_patch_weights = {}
local square_t = 0
for _, v in ipairs(ore_patches) do
square_t = square_t + v.weight
table.insert(total_ore_patch_weights, square_t)
end
local value = b.exponential_value
local function non_transform(shape)
return shape
end
local function uranium_transform(shape)
return b.scale(shape, 0.5)
end
local function oil_transform(shape)
shape = b.scale(shape, 0.5)
return b.throttle_world_xy(shape, 1, 4, 1, 4)
end
local function empty_transform()
return b.empty_shape
end
local ores = {
{transform = non_transform, resource = 'iron-ore', value = value(250, 0.4, 1.1), weight = 16},
{transform = non_transform, resource = 'copper-ore', value = value(200, 0.4, 1.1), weight = 10},
{transform = non_transform, resource = 'stone', value = value(125, 0.2, 1.05), weight = 3},
{transform = non_transform, resource = 'coal', value = value(200, 0.3, 1.075), weight = 5},
{transform = uranium_transform, resource = 'uranium-ore', value = value(100, 0.3, 1.025), weight = 3},
{transform = oil_transform, resource = 'crude-oil', value = value(100000, 50, 1.05), weight = 6},
{transform = empty_transform, weight = 300}
}
local total_ore_weights = {}
local ore_t = 0
for _, v in ipairs(ores) do
ore_t = ore_t + v.weight
table.insert(total_ore_weights, ore_t)
end
local function do_resources()
local pattern = {}
for r = 1, ore_blocks do
local row = {}
pattern[r] = row
for c = 1, ore_blocks do
local shape
local i = random_ore:next_int(1, square_t)
local index = table.binary_search(total_ore_patch_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
shape = ore_patches[index].shape
local ore_data
i = random_ore:next_int(1, ore_t)
index = table.binary_search(total_ore_weights, i)
if (index < 0) then
index = bit32.bnot(index)
end
ore_data = ores[index]
shape = ore_data.transform(shape)
local ore = b.resource(shape, ore_data.resource, ore_data.value)
row[c] = ore
end
end
return b.grid_pattern_full_overlap(pattern, ore_blocks, ore_blocks, ore_block_size, ore_block_size)
end
local map_ores = do_resources()
local root2 = math.sqrt(2)
local big_circle = b.circle(150)
local small_circle = b.circle(140)
local crop = b.rectangle(300,150)
crop = b.translate(crop,0,-75)
local arc = b.all{big_circle, b.invert(small_circle), b.invert(crop)}
arc = b.scale(arc,12,4)
local crop = b.rectangle(300, 150)
crop = b.translate(crop, 0, -75)
local arc = b.all {big_circle, b.invert(small_circle), b.invert(crop)}
arc = b.scale(arc, 6, 2)
local circle = b.circle(200)
local ball1 = b.translate(circle, 0,820)
local ball2 = b.translate(circle, -920,740)
local ball3 = b.translate(circle, 920,740)
local rectangle = b.rectangle(25,40)
local arm1 = b.translate(rectangle, 0, 610)
local arm2 = b.translate(rectangle, -920, 530)
local arm3 = b.translate(rectangle, 920, 530)
local rectangle = b.rectangle(25, 40)
local arc1 = b.any{arc, ball1,ball2,ball3,arm1,arm2,arm3}
arc1 = b.single_pattern(arc1, 2760,2760)
local function h_arc()
local circle = b.circle(100)
circle = b.apply_entity(circle, map_ores)
local ball1 = b.translate(circle, 0, 410)
local ball2 = b.translate(circle, -460, 370)
local ball3 = b.translate(circle, 460, 370)
local arm1 = b.translate(rectangle, 0, 310)
local arm2 = b.translate(rectangle, -460, 270)
local arm3 = b.translate(rectangle, 460, 270)
local root2 = math.sqrt(2)
circle = b.circle(200 / root2)
ball1 = b.translate(circle, -0,770)
ball2 = b.translate(circle, -920,690)
ball3 = b.translate(circle, 920,690)
rectangle = b.rectangle(25,40)
arm1 = b.translate(rectangle, 0, 610)
arm2 = b.translate(rectangle, -920, 530)
arm3 = b.translate(rectangle, 920, 530)
return b.any {arc, ball1, ball2, ball3, arm1, arm2, arm3}
end
local arc2 = b.any{arc, ball1,ball2,ball3,arm1,arm2,arm3}
arc2 = b.single_pattern(arc2, 2760,2760)
local function v_arc()
local circle = b.circle(100 / root2)
circle = b.apply_entity(circle, map_ores)
local ball1 = b.translate(circle, -0, 385)
local ball2 = b.translate(circle, -460, 345)
local ball3 = b.translate(circle, 460, 345)
local arm1 = b.translate(rectangle, 0, 305)
local arm2 = b.translate(rectangle, -460, 265)
local arm3 = b.translate(rectangle, 460, 265)
local arc2 = b.rotate(arc2,degrees(45))
arc2 = b.scale(arc2, root2,root2)
arc2 = b.translate(arc2, -330,-1375)
return b.any {arc, ball1, ball2, ball3, arm1, arm2, arm3}
end
local map = b.any{arc1,arc2}
map = b.translate(map,0,-700)
--map = b.scale(map, .2, .2)
local arc1 = h_arc()
arc1 = b.single_pattern(arc1, 1380, 1380)
return map
local arc2 = v_arc()
arc2 = b.single_pattern(arc2, 1380, 1380)
arc2 = b.rotate(arc2, degrees(45))
arc2 = b.scale(arc2, root2, root2)
arc2 = b.translate(arc2, -165, -688)
local map = b.any {arc1, arc2}
--map = b.apply_entity(map, map_ores)
map = b.translate(map, 0, -414)
local function constant(x)
return function()
return x
end
end
local small_circle = b.circle(32)
local start_iron = b.resource(small_circle, ores[1].resource, constant(900))
local start_copper = b.resource(small_circle, ores[2].resource, constant(600))
local start_stone = b.resource(small_circle, ores[3].resource, constant(400))
local start_coal = b.resource(small_circle, ores[4].resource, constant(700))
local start_segmented = b.segment_pattern({start_iron, start_copper, start_stone, start_coal})
local start_shape = b.change_map_gen_collision_tile(small_circle, 'water-tile', 'grass-1')
start_shape = b.apply_entity(start_shape, start_segmented)
start_shape = b.translate(start_shape, 0, 48)
start_shape = b.any {start_shape, b.full_shape}
map = b.choose(b.circle(100), start_shape, map)
return map

View File

@ -0,0 +1,20 @@
local b = require 'map_gen.shared.builders'
local pic = require 'map_gen.data.presets.vanilla'
local ore_mask = require 'map_gen.data.presets.vanilla-ore-mask'
local tiny_ores = require('map_gen.ores.tiny_ores')(256)
local map = b.picture(pic)
local ores = b.picture(ore_mask)
ores = b.choose(ores, tiny_ores, b.no_entity)
map = b.apply_entity(map, ores)
map = b.single_pattern(map, pic.width, pic.height)
map = b.change_tile(map, 'out-of-map', 'deepwater')
map = b.fish(map, 0.0025)
return map

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
local mines_factor = 1
@ -35,7 +36,7 @@ local death_messages = {
}
local function player_died(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

View File

@ -80,6 +80,7 @@ local tiles_per_tick = 32
--shape = require "map_gen.presets.bacon_islands"
--shape = require "map_gen.presets.spiral"
--shape = require "map_gen.presets.hub_spiral"
--shape = require "map_gen.presets.vanilla"
--shape = require "map_gen.presets.test"
--shapes--

View File

@ -1,17 +1,18 @@
local Event = require "utils.event"
local UserGroups = require "user_groups"
local Utils = require "utils.utils"
local Game = require 'utils.game'
function allowed_to_nuke(player)
if type(player) == "table" then
return player.admin or UserGroups.is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_control.nuke_min_time_hours)
elseif type(player) == "number" then
return allowed_to_nuke(game.players[player])
return allowed_to_nuke(Game.get_player_by_index(player))
end
end
local function ammo_changed(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if allowed_to_nuke(player) then return end
local nukes = player.remove_item({name="atomic-bomb", count=1000})
if nukes > 0 then
@ -30,7 +31,7 @@ local function ammo_changed(event)
end
local function on_player_deconstructed_area(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if allowed_to_nuke(player) then return end
player.remove_item({name="deconstruction-planner", count=1000})
@ -59,8 +60,8 @@ local function on_player_deconstructed_area(event)
Utils.print_admins("Warning! " .. player.name .. " just tried to deconstruct " .. tostring(#entities) .. " entities!")
end
for _,entity in pairs(entities) do
if entity.valid and entity.to_be_deconstructed(game.players[event.player_index].force) then
entity.cancel_deconstruction(game.players[event.player_index].force)
if entity.valid and entity.to_be_deconstructed(Game.get_player_by_index(event.player_index).force) then
entity.cancel_deconstruction(Game.get_player_by_index(event.player_index).force)
end
end
end
@ -107,7 +108,7 @@ end
global.players_warned = {}
local function on_capsule_used(event)
local item = event.item
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid or
(global.scenario.config.nuke_control.enable_autokick and global.scenario.config.nuke_control.enable_autoban) then

View File

@ -1,5 +1,6 @@
local Event = require 'utils.event'
local Gui = require 'utils.gui'
local Game = require 'utils.game'
local brush_tool = 'refined-hazard-concrete'
@ -52,7 +53,7 @@ local function player_build_tile(event)
return
end
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player.gui.left[main_frame_name] then
return
end
@ -77,7 +78,7 @@ local function player_joined(event)
if not global.scenario.config.paint.enable then
return
end
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
local player_colors = {
['grilledham'] = {
@ -26,7 +27,7 @@ local player_colors = {
Event.add(
defines.events.on_player_created,
function(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

View File

@ -6,6 +6,7 @@ local UserGroups = require 'user_groups'
local PlayerStats = require 'player_stats'
local Utils = require 'utils.utils'
local Report = require 'report'
local Game = require 'utils.game'
local poke_messages = require 'resources.poke_messages'
local player_sprites = require 'resources.player_sprites'
@ -611,7 +612,7 @@ local function tick()
end
local function player_joined(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

View File

@ -1,5 +1,6 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Game = require 'utils.game'
local player_last_position = {}
local player_walk_distances = {}
@ -30,7 +31,7 @@ Global.register(
local function player_created(event)
local index = event.player_index
player_last_position[index] = game.players[index].position
player_last_position[index] = Game.get_player_by_index(index).position
player_walk_distances[index] = 0
player_coin_earned[index] = 0
player_coin_spent[index] = 0

View File

@ -3,6 +3,7 @@ local Global = require 'utils.global'
local Event = require 'utils.event'
local UserGroups = require 'user_groups'
local Server = require 'server'
local Game = require 'utils.game'
local default_poll_duration = 300 * 60 -- in ticks
local duration_max = 3600 -- in seconds
@ -172,7 +173,7 @@ local function redraw_poll_viewer_content(data)
end
for player_index, answer in pairs(voters) do
local p = game.players[player_index]
local p = Game.get_player_by_index(player_index)
table.insert(tooltips[answer], p.name)
end
@ -199,7 +200,7 @@ local function redraw_poll_viewer_content(data)
if next(edited_by_players) then
local edit_names = {'Edited by '}
for pi, _ in pairs(edited_by_players) do
local p = game.players[pi]
local p = Game.get_player_by_index(pi)
if p and p.valid then
table.insert(edit_names, p.name)
table.insert(edit_names, ', ')
@ -710,7 +711,7 @@ local function update_vote(voters, answer, direction)
local tooltip = {}
for pi, a in pairs(voters) do
if a == answer then
local player = game.players[pi]
local player = Game.get_player_by_index(pi)
table.insert(tooltip, player.name)
end
end
@ -782,7 +783,7 @@ local function vote(event)
end
local function player_joined(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

View File

@ -2,6 +2,7 @@ local Module = {}
local Gui = require("utils.gui")
local Utils = require("utils.utils");
local Game = require 'utils.game'
local report_frame_name = Gui.uid_name()
local report_close_button_name = Gui.uid_name()
local report_tab_button_name = Gui.uid_name()
@ -18,8 +19,8 @@ local function draw_report(parent, report_id)
parent.add {type = "label", caption="No reports yet."}
return
end
local reported_player_name = game.players[report.reported_player_index].name
local reporting_player_name = game.players[report.reporting_player_index].name
local reported_player_name = Game.get_player_by_index(report.reported_player_index).name
local reporting_player_name = Game.get_player_by_index(report.reporting_player_index).name
local time = Utils.format_time(report.tick)
local time_ago = Utils.format_time(game.tick - report.tick)
@ -63,7 +64,7 @@ Module.show_reports = function(player)
button_cell.add {
type="button",
name=report_tab_button_name,
caption = game.players[report.reported_player_index].name
caption = Game.get_player_by_index(report.reported_player_index).name
}
end
end
@ -178,9 +179,9 @@ Gui.on_click(
local reported_player_index = data["reported_player_index"]
Gui.destroy(frame)
Module.report(event.player, game.players[reported_player_index], msg)
Module.report(event.player, Game.get_player_by_index(reported_player_index), msg)
event.player.print("Sucessfully reported " .. game.players[reported_player_index].name)
event.player.print("Sucessfully reported " .. Game.get_player_by_index(reported_player_index).name)
end
)

View File

@ -16,6 +16,7 @@ Module.donators = {
['Xertez'] = d.rank,
['Chevalier1200'] = d.rank + d.train,
['DraugTheWhopper'] = d.rank + d.train,
['der-dave.com'] = d.rank + d.train,
['Jayefuu'] = d.rank,
['Chromaddict'] = d.rank,
['Valansch'] = d.rank
@ -23,7 +24,8 @@ Module.donators = {
Module.welcome_messages = {
['Linaori'] = 'I present to you Linaori of house Refactorio, Lady of the Void, Remover of Spaghetti, Queen of the Endless Nauvis, Breaker of Biters and Mother of Code!',
['Valansch'] = 'Welcome Valansch, <insert custom welcome message here>.'
['Valansch'] = 'Welcome Valansch, <insert custom welcome message here>.',
['der-dave.com'] = "Dave doesn't want a welcome message."
}
return Module

View File

@ -945,5 +945,55 @@ return {
['Cretlin'] = true,
['niko8'] = true,
['neuro666'] = true,
['kreeg'] = true
['kreeg'] = true,
['Jimbogab'] = true,
['Medival3'] = true,
['willzcn'] = true,
['uranopa3'] = true,
['JSONROY'] = true,
['o12eMaRkAbLeo'] = true,
['VanHate'] = true,
['RichardMNixon'] = true,
['Subsup'] = true,
['Sitrom'] = true,
['odgaar'] = true,
['glxl'] = true,
['Julian1109'] = true,
['ice9000'] = true,
['plukona'] = true,
['Serule'] = true,
['IDragonfyreI'] = true,
['jan1412'] = true,
['ko5h'] = true,
['DJStrikerLP'] = true,
['maverick85'] = true,
['kacperion'] = true,
['Heinrich0815'] = true,
['Martox111'] = true,
['skudd3r'] = true,
['Ingenieur_quoi'] = true,
['SumBeam'] = true,
['ScienceLion'] = true,
['dimash'] = true,
['TNT_MAN1111'] = true,
['crayzz2'] = true,
['Gerkiz'] = true,
['piterfersin'] = true,
['SiMoZ_287'] = true,
['SSeltmann'] = true,
['AbsoluteZeroIs0K'] = true,
['jufacto'] = true,
['okan009'] = true,
['CounterfeitThe'] = true,
['TZsec'] = true,
['jamesh92'] = true,
['Flameoguy'] = true,
['Toledini'] = true,
['alnmike'] = true,
['Krzys132'] = true,
['jrz126'] = true,
['Rothguard'] = true,
['Rascher'] = true,
['XeoXius'] = true,
['InphinitePhractals'] = true
}

View File

@ -1,9 +1,10 @@
local Event = require "utils.event"
local Game = require 'utils.game'
if not global.score_rockets_launched then global.score_rockets_launched = 0 end
local function create_score_gui(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if player.gui.top.score == nil then
local button = player.gui.top.add({ type = "sprite-button", name = "score", sprite = "item/rocket-silo" })
@ -18,8 +19,8 @@ end
function refresh_score()
local x = 1
while (game.players[x] ~= nil) do
local player = game.players[x]
while (Game.get_player_by_index(x) ~= nil) do
local player = Game.get_player_by_index(x)
local frame = player.gui.top["score_panel"]
if (frame) then
@ -72,7 +73,7 @@ end
local function on_gui_click(event)
if not (event and event.element and event.element.valid) then return end
local player = game.players[event.element.player_index]
local player = Game.get_player_by_index(event.element.player_index)
local name = event.element.name
local frame = player.gui.top["score_panel"]

View File

@ -1,4 +1,5 @@
local Event = require "utils.event"
local Game = require 'utils.game'
global.player_spawns = {} -- player_index to spawn_name
global.spawns = {} -- spawn_name to x, y, player_online_count
@ -55,7 +56,7 @@ local function player_joined_game(event)
local spawn = global.spawns[spawn_name]
global.player_spawns[index] = spawn_name
game.players[index].teleport(spawn)
Game.get_player_by_index(index).teleport(spawn)
local count = spawn.count
spawn.count = count + 1
@ -79,11 +80,11 @@ local function player_respawned(event)
if not spawn then return end
game.players[index].teleport(spawn)
Game.get_player_by_index(index).teleport(spawn)
end
local function tp_spawn(player_name, spawn_name)
local player = game.players[player_name]
local player = Game.get_player_by_index(player_name)
if not player then
player_name = player_name or ""
game.player.print("player " .. player_name .. " does not exist.")
@ -109,7 +110,7 @@ local function change_spawn(player_name, spawn_name)
return
end
local player = game.players[player_name]
local player = Game.get_player_by_index(player_name)
if not player then
player_name = player_name or ""
@ -151,7 +152,7 @@ local function print_players_for_spawn(target_spawn_name)
str = ""
for index, spawn_name in pairs(global.player_spawns) do
if target_spawn_name == spawn_name then
local player = game.players[index]
local player = Game.get_player_by_index(index)
if player.connected then
str = str .. player.name .. ", "
end

View File

@ -2,6 +2,7 @@ local Event = require 'utils.event'
local Gui = require 'utils.gui'
local Global = require 'utils.global'
local UserGroups = require 'user_groups'
local Game = require 'utils.game'
local deafult_verb = 'expanded'
@ -86,7 +87,7 @@ local function get_size(players, show_offline)
size = table.size(players)
else
for pi, _ in pairs(players) do
local player = game.players[pi]
local player = Game.get_player_by_index(pi)
if player and player.valid and player.connected then
size = size + 1
end
@ -118,7 +119,7 @@ local delete_tag_name = Gui.uid_name()
local close_create_tag_name = Gui.uid_name()
local function player_joined(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
@ -179,11 +180,11 @@ local function draw_main_frame_content(parent)
if players then
for k, _ in pairs(players) do
local p = game.players[k]
local p = Game.get_player_by_index(k)
if p and p.valid and p.connected then
local color = {r = 0.4 + 0.6 * p.color.r, g = 0.4 + 0.6 * p.color.g, b = 0.4 + 0.6 * p.color.b}
local label = list.add {type = 'label', caption = game.players[k].name}
local label = list.add {type = 'label', caption = Game.get_player_by_index(k).name}
label.style.top_padding = 8
label.style.font_color = color
end

View File

@ -3,6 +3,7 @@ local Gui = require 'utils.gui'
local Global = require 'utils.global'
local UserGroups = require 'user_groups'
local Utils = require 'utils.utils'
local Game = require 'utils.game'
local normal_color = {r = 1, g = 1, b = 1}
local focus_color = {r = 1, g = 0.55, b = 0.1}
@ -111,7 +112,7 @@ local function get_editing_players_message(players)
local message = {'Editing players: '}
for pi, _ in pairs(players) do
local name = game.players[pi].name
local name = Game.get_player_by_index(pi).name
table.insert(message, name)
table.insert(message, ', ')
end
@ -405,6 +406,24 @@ local function draw_main_frame(left, player)
frame.add {type = 'button', name = main_button_name, caption = 'Close'}
end
local function close_edit_announcments_frame(frame)
local editing_players = announcements.editing_players
editing_players[frame.player_index] = nil
Gui.destroy(frame)
if not next(editing_players) then
return
end
local editing_players_message = get_editing_players_message(editing_players)
for _, data in pairs(editing_players) do
local editing_players_label = data.editing_players_label
editing_players_label.caption = editing_players_message
editing_players_label.tooltip = editing_players_message
end
end
local function toggle(event)
local player = event.player
local left = player.gui.left
@ -413,7 +432,7 @@ local function toggle(event)
Gui.destroy(frame)
frame = left[edit_announcements_frame_name]
if frame and frame.valid then
Gui.destroy(frame)
close_edit_announcments_frame(frame)
end
frame = left[create_task_frame_name]
if frame and frame.valid then
@ -448,24 +467,6 @@ local function update_edit_announcements_textbox(text, player)
end
end
local function close_edit_announcments_frame(frame)
local editing_players = announcements.editing_players
editing_players[frame.player_index] = nil
Gui.destroy(frame)
if not next(editing_players) then
return
end
local editing_players_message = get_editing_players_message(editing_players)
for _, data in pairs(editing_players) do
local editing_players_label = data.editing_players_label
editing_players_label.caption = editing_players_message
editing_players_label.tooltip = editing_players_message
end
end
local function update_announcements(player)
local text = announcements.edit_text
@ -584,7 +585,7 @@ local function draw_create_task_frame(left, previous_task)
end
local function player_created(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end
@ -630,7 +631,7 @@ local function player_created(event)
end
local function player_left(event)
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
local left = player.gui.left
local frame = left[edit_announcements_frame_name]

View File

@ -3,6 +3,7 @@ local Market_items = require 'resources.market_items'
local Global = require 'utils.global'
local Donators = require 'resources.donators'
local UserGroups = require 'user_groups'
local Game = require 'utils.game'
local train_perk_flag = Donators.donator_perk_flags.train
local saviour_token_name = 'small-plane' -- item name for what saves players
@ -52,7 +53,7 @@ local function on_pre_death(event)
end
local player_index = event.player_index
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
if not player or not player.valid then
return
end

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
local function player_built_entity(event)
local entity = event.created_entity
@ -7,8 +8,8 @@ local function player_built_entity(event)
if entity.name == 'train-stop' then
local y = math.random(1, 3)
if y ~= 1 then
local x = math.random(1, #game.players)
local player = game.players[x]
local x = math.random(1, #Game.players)
local player = Game.get_player_by_index(x)
event.created_entity.backer_name = player.name
end
end

View File

@ -6,6 +6,7 @@ local Server = require 'server'
global.regulars = {}
global.donators = {}
global.donator_welcome_messages = {}
local Game = require 'utils.game'
local Module = {}
@ -125,7 +126,7 @@ end
Event.add(
defines.events.on_player_joined_game,
function(event)
local correctCaseName = game.players[event.player_index].name
local correctCaseName = Game.get_player_by_index(event.player_index).name
if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then
global.regulars[correctCaseName:lower()] = nil
global.regulars[correctCaseName] = true

42
utils/game.lua Normal file
View File

@ -0,0 +1,42 @@
local Global = require 'utils.global'
local Game = {}
local bad_name_players = {}
Global.register(
bad_name_players,
function(tbl)
bad_name_players = tbl
end
)
--[[
Due to a bug in the Factorio api the following expression isn't guaranteed to be true.
game.players[player.index] == player
get_player_by_index(index) will always return the correct player.
When looking up players by name or iterating through all players use game.players instead.
]]
function Game.get_player_by_index(index)
local p = game.players[index]
if not p then
return nil
end
if p.index == index then
return p
end
p = bad_name_players[index]
if p then
return p
end
for k, v in pairs(game.players) do
if k == index then
bad_name_players[index] = v
return v
end
end
end
return Game

View File

@ -8,12 +8,12 @@ local init_data = {}
function Global.register(tbl, callback)
local token = Token.register_global(tbl)
table.insert(load_data, {tbl = tbl, callback = callback, token = token})
table.insert(load_data, {callback = callback, token = token})
end
function Global.register_init(tbl, init_handler, callback)
local token = Token.register_global(tbl)
table.insert(load_data, {tbl = tbl, callback = callback, token = token})
table.insert(load_data, {callback = callback, token = token})
table.insert(init_data, {token = token, init_handler = init_handler, callback = callback})
end

View File

@ -1,5 +1,6 @@
local Token = require 'utils.global_token'
local Event = require 'utils.event'
local Game = require 'utils.game'
local Gui = {}
@ -81,7 +82,7 @@ local function handler_factory(event_id)
return
end
local player = game.players[event.player_index]
local player = Game.get_player_by_index(event.player_index)
if not player or not player.valid then
return
end

11
utils/math_fix.lua Normal file
View File

@ -0,0 +1,11 @@
local _sin = math.sin
local _cos = math.cos
math.sin = function(x)
return math.floor(_sin(x) * 10000000 + 0.5) / 10000000
end
math.cos = function(x)
return math.floor(_cos(x) * 10000000 + 0.5) / 10000000
end

View File

@ -1,4 +1,5 @@
local Module = {}
local Game = require 'utils.game'
Module.distance = function(pos1, pos2)
local dx = pos2.x - pos1.x
@ -79,7 +80,7 @@ Module.find_entities_by_last_user =
surface = game.surfaces[surface]
end
if type(player) == 'number' then
player = game.players[player]
player = Game.get_player_by_index(player)
end
filters.force = player.force.name
for _, e in pairs(surface.find_entities_filtered(filters)) do

View File

@ -2,6 +2,7 @@ local Event = require 'utils.event'
local Token = require 'utils.global_token'
local Task = require 'utils.Task'
local PlayerStats = require 'player_stats'
local Game = require 'utils.game'
local market_items = require 'resources.market_items'
@ -160,12 +161,12 @@ local function market_item_purchased(event)
PlayerStats.change_fish_spent(player_index, cost)
if event.offer_index == 1 then -- Temporary speed bonus
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
boost_player_runningspeed(player, market)
end
if event.offer_index == 2 then -- Temporary mining bonus
local player = game.players[player_index]
local player = Game.get_player_by_index(player_index)
boost_player_miningspeed(player, market)
end
end
@ -179,14 +180,14 @@ local function on_180_ticks()
if global.player_speed_boost_records then
for k, v in pairs(global.player_speed_boost_records) do
if game.tick - v.start_tick > 3000 then
reset_player_runningspeed(game.players[k])
reset_player_runningspeed(Game.get_player_by_index(k))
end
end
end
if global.player_mining_boost_records then
for k, v in pairs(global.player_mining_boost_records) do
if game.tick - v.start_tick > 6000 then
reset_player_miningspeed(game.players[k])
reset_player_miningspeed(Game.get_player_by_index(k))
end
end
end