Fixed Existing Lua Check Errors

This commit is contained in:
Cooldude2606
2020-05-26 18:21:10 +01:00
parent 2aaeb06be3
commit 32507492b8
76 changed files with 1622 additions and 1617 deletions

View File

@@ -9,7 +9,7 @@ local config = require 'config.scorched_earth' --- @dep config.scorched_earth
-- Loops over the config and finds the wile which has the highest value for strength
local max_strength = 0
for _,strength in pairs(config.strengths) do
for _, strength in pairs(config.strengths) do
if strength > max_strength then
max_strength = strength
end
@@ -22,12 +22,12 @@ Global.register(debug_players, function(tbl)
end)
-- Will degrade a tile down to the next tile when called
local function degrade(surface,position)
local function degrade(surface, position)
local tile = surface.get_tile(position)
local tile_name = tile.name
local degrade_tile_name = config.degrade_order[tile_name]
if not degrade_tile_name then return end
surface.set_tiles{{name=degrade_tile_name,position=position}}
surface.set_tiles{{name=degrade_tile_name, position=position}}
end
-- Same as degrade but will degrade all tiles that are under an entity
@@ -42,12 +42,12 @@ local function degrade_entity(entity)
for x = lt.x, rb.x do -- x loop
local px = position.x+x
for y = lt.y, rb.y do -- y loop
local p = {x=px,y=position.y+y}
local p = {x=px, y=position.y+y}
local tile = surface.get_tile(p)
local tile_name = tile.name
local degrade_tile_name = config.degrade_order[tile_name]
if not degrade_tile_name then return end
table.insert(tiles,{name=degrade_tile_name,position=p})
table.insert(tiles, {name=degrade_tile_name, position=p})
end
end
surface.set_tiles(tiles)
@@ -62,15 +62,15 @@ local function get_probability(strength)
end
-- Gets the mean of the strengths around a tile to give the strength at that position
local function get_tile_strength(surface,position)
local function get_tile_strength(surface, position)
local tile = surface.get_tile(position)
local tile_name = tile.name
local strength = config.strengths[tile_name]
if not strength then return end
for x = -1,1 do -- x loop
for x = -1, 1 do -- x loop
local px = position.x + x
for y = -1,1 do -- y loop
local check_tile = surface.get_tile{x=px,y=position.y+y}
for y = -1, 1 do -- y loop
local check_tile = surface.get_tile{x=px, y=position.y+y}
local check_tile_name = check_tile.name
local check_strength = config.strengths[check_tile_name] or 0
strength = strength + check_strength
@@ -80,12 +80,12 @@ local function get_tile_strength(surface,position)
end
-- Same as get_tile_strength but returns to a in game text rather than as a value
local function debug_get_tile_strength(surface,position)
for x = -3,3 do -- x loop
local function debug_get_tile_strength(surface, position)
for x = -3, 3 do -- x loop
local px = position.x+x
for y = -3,3 do -- y loop
local p = {x=px,y=position.y+y}
local strength = get_tile_strength(surface,p) or 0
for y = -3, 3 do -- y loop
local p = {x=px, y=position.y+y}
local strength = get_tile_strength(surface, p) or 0
local tile = surface.get_tile(p)
print_grid_value(get_probability(strength)*config.weakness_value, surface, tile.position)
end
@@ -97,13 +97,13 @@ Event.add(defines.events.on_player_changed_position, function(event)
local player = Game.get_player_by_index(event.player_index)
local surface = player.surface
local position = player.position
local strength = get_tile_strength(surface,position)
local strength = get_tile_strength(surface, position)
if not strength then return end
if get_probability(strength) > math.random() then
degrade(surface,position)
degrade(surface, position)
end
if debug_players[player.name] then
debug_get_tile_strength(surface,position)
debug_get_tile_strength(surface, position)
end
end)
@@ -112,7 +112,7 @@ Event.add(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local surface = entity.surface
local position = entity.position
local strength = get_tile_strength(surface,position)
local strength = get_tile_strength(surface, position)
if not strength then return end
if get_probability(strength)*config.weakness_value > math.random() then
degrade_entity(entity)
@@ -124,7 +124,7 @@ Event.add(defines.events.on_robot_built_entity, function(event)
local entity = event.created_entity
local surface = entity.surface
local position = entity.position
local strength = get_tile_strength(surface,position)
local strength = get_tile_strength(surface, position)
if not strength then return end
if get_probability(strength)*config.weakness_value > math.random() then
degrade_entity(entity)
@@ -132,7 +132,7 @@ Event.add(defines.events.on_robot_built_entity, function(event)
end)
-- Used as a way to access the global table
return function(player_name,state)
return function(player_name, state)
local player = Game.get_player_from_any(player_name)
clear_flying_text(player.surface)
debug_players[player_name] = state