1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00

Merge pull request #226 from ComfyFactory/scrap_towny

scrap towny ffa fixes
This commit is contained in:
Gerkiz 2022-03-01 19:34:25 +01:00 committed by GitHub
commit 2a984b8b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 51 deletions

View File

@ -1,7 +1,6 @@
local Public = {}
--local Server = require 'utils.server'
local Table = require 'modules.scrap_towny_ffa.table'
local function create_limbo()
game.create_surface('limbo')
@ -9,7 +8,6 @@ end
local function initialize_nauvis()
local surface = game.surfaces['nauvis']
local map_seed = Table.get('map_seed')
-- this overrides what is in the map_gen_settings.json file
local mgs = surface.map_gen_settings
@ -119,7 +117,7 @@ local function initialize_nauvis()
-- this will make and average base radius around 12 tiles
['enemy-base-radius'] = 12
}
mgs.seed = map_seed
mgs.seed = game.surfaces[1].map_gen_settings.seed
surface.map_gen_settings = mgs
surface.peaceful_mode = false
surface.always_day = false

View File

@ -2,9 +2,7 @@ local Public = {}
-- one table to rule them all!
local Global = require 'utils.global'
local ffatable = {
map_seed = 3747269588
}
local ffatable = {}
Global.register(
ffatable,
function(tbl)

View File

@ -92,31 +92,31 @@ local function is_towny(force)
return true
end
function Public.has_key(player_index)
function Public.has_key(index)
local ffatable = Table.get_table()
if ffatable.key == nil then
ffatable.key = {}
end
if ffatable.key[player_index] ~= nil then
return ffatable.key[player_index]
if ffatable.key[index] ~= nil then
return ffatable.key[index]
end
return false
end
function Public.give_key(player_index)
function Public.give_key(index)
local ffatable = Table.get_table()
if ffatable.key == nil then
ffatable.key = {}
end
ffatable.key[player_index] = true
ffatable.key[index] = true
end
function Public.remove_key(player_index)
function Public.remove_key(index)
local ffatable = Table.get_table()
if ffatable.key == nil then
ffatable.key = {}
end
ffatable.key[player_index] = false
ffatable.key[index] = false
end
function Public.set_player_color(player)
@ -206,7 +206,7 @@ function Public.set_player_to_outlander(player)
player.tag = '[Outlander]'
Map.disable_world_map(player)
Public.set_player_color(player)
Public.give_key(player)
Public.give_key(player.index)
end
local function set_player_to_rogue(player)

View File

@ -15,7 +15,7 @@ local Color = require 'utils.color_presets'
local town_radius = 27
local radius_between_towns = 64
local ore_amount = 1000 * (200/168.5)
local ore_amount = 1000 * (200 / 168.5)
local colors = {}
local c1 = 250
@ -136,7 +136,9 @@ local starter_supplies = {
local function count_nearby_ore(surface, position, ore_name)
local count = 0
local r = town_radius + 8
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', name = ore_name})) do
for _, e in pairs(
surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', name = ore_name})
) do
count = count + e.amount
end
return count
@ -277,12 +279,12 @@ local function is_valid_location(force_name, surface, position)
local ffatable = Table.get_table()
if not surface.can_place_entity({name = 'market', position = position}) then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = 'Position is obstructed - no room for market!',
color = {r = 0.77, g = 0.0, b = 0.0}
}
{
name = 'flying-text',
position = position,
text = 'Position is obstructed - no room for market!',
color = {r = 0.77, g = 0.0, b = 0.0}
}
)
return false
end
@ -370,13 +372,17 @@ end
local function found_town(event)
local entity = event.created_entity
-- is a valid entity placed?
if entity == nil or not entity.valid then return end
if entity == nil or not entity.valid then
return
end
local player = game.players[event.player_index]
-- is player not a character?
local character = player.character
if character == nil then return end
if character == nil then
return
end
-- is it a stone-furnace?
if entity.name ~= 'stone-furnace' then
@ -421,12 +427,12 @@ local function found_town(event)
if ffatable.cooldowns_town_placement[player.index] then
if game.tick < ffatable.cooldowns_town_placement[player.index] then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = 'Town founding is on cooldown for ' .. math.ceil((ffatable.cooldowns_town_placement[player.index] - game.tick) / 3600) .. ' minutes.',
color = {r = 0.77, g = 0.0, b = 0.0}
}
{
name = 'flying-text',
position = position,
text = 'Town founding is on cooldown for ' .. math.ceil((ffatable.cooldowns_town_placement[player.index] - game.tick) / 3600) .. ' minutes.',
color = {r = 0.77, g = 0.0, b = 0.0}
}
)
player.insert({name = 'stone-furnace', count = 1})
return
@ -446,7 +452,7 @@ local function found_town(event)
player.insert({name = 'stone-furnace', count = 1})
return
else
inventory.remove({name='coin',count=100})
inventory.remove({name = 'coin', count = 100})
end
local force = Team.add_new_force(force_name)
@ -478,7 +484,7 @@ local function found_town(event)
town_center.creation_tick = game.tick
town_center.town_caption =
rendering.draw_text {
rendering.draw_text {
text = town_center.town_name,
surface = surface,
forces = {force_name},
@ -492,7 +498,7 @@ local function found_town(event)
}
town_center.health_text =
rendering.draw_text {
rendering.draw_text {
text = 'HP: ' .. town_center.health .. ' / ' .. town_center.max_health,
surface = surface,
forces = {force_name},
@ -506,7 +512,7 @@ local function found_town(event)
}
town_center.coins_text =
rendering.draw_text {
rendering.draw_text {
text = 'Coins: ' .. town_center.coin_balance,
surface = surface,
forces = {force_name},
@ -530,7 +536,7 @@ local function found_town(event)
force.set_spawn_position(pos, surface)
Team.add_player_to_town(player, town_center)
Team.remove_key(player)
Team.remove_key(player.index)
Team.add_chart_tag(town_center)
game.print('>> ' .. player.name .. ' has founded a new town!', {255, 255, 0})
@ -603,16 +609,16 @@ local function rename_town(cmd)
Team.set_player_color(p)
end
game.print('>> ' .. old_name .. " is now known as " .. '"' .. name .. '"', {255, 255, 0})
game.print('>> ' .. old_name .. ' is now known as ' .. '"' .. name .. '"', {255, 255, 0})
Server.to_discord_embed(old_name .. ' is now known as ' .. '"' .. name .. '"')
end
commands.add_command(
'rename-town',
'Renames your town..',
function(cmd)
rename_town(cmd)
end
'rename-town',
'Renames your town..',
function(cmd)
rename_town(cmd)
end
)
local Event = require 'utils.event'

View File

@ -188,7 +188,9 @@ local size_of_scrap_raffle = #scrap_raffle
local function place_scrap(surface, position)
local ffatable = Table.get_table()
if ffatable.spaceships == nil then ffatable.spaceships = {} end
if ffatable.spaceships == nil then
ffatable.spaceships = {}
end
-- place turrets
if math_random(1, 700) == 1 then
if position.x ^ 2 + position.x ^ 2 > 4096 then
@ -203,13 +205,17 @@ local function place_scrap(surface, position)
-- place market spaceship
if math_random(1, 4096) == 1 then
local spaceship = {}
spaceship.market = surface.create_entity({name = 'crash-site-spaceship-market', position = position, force = 'neutral'})
spaceship.market.minable = false
spaceship.max_health = 300
spaceship.health = spaceship.max_health
if spaceship.market ~= nil then
if ffatable.spaceships[position.x] == nil then ffatable.spaceships[position.x] = {} end
ffatable.spaceships[position.x][position.y] = spaceship
if surface.can_place_entity({name = 'crash-site-spaceship-market', position = position, force = 'neutral'}) then
spaceship.market = surface.create_entity({name = 'crash-site-spaceship-market', position = position, force = 'neutral'})
spaceship.market.minable = false
spaceship.max_health = 300
spaceship.health = spaceship.max_health
if spaceship.market and spaceship.market.valid then
if ffatable.spaceships[position.x] == nil then
ffatable.spaceships[position.x] = {}
end
ffatable.spaceships[position.x][position.y] = spaceship
end
end
return
end
@ -311,7 +317,7 @@ local function on_chunk_generated(event)
--log('chunk_position = {' .. chunk_position.x .. ',' .. chunk_position.y .. '}')
if chunk_position.x >= -33 and chunk_position.x <= 32 and chunk_position.y >= -33 and chunk_position.y <= 32 then
if chunk_position.x == -33 or chunk_position.x == 32 or chunk_position.y == -33 or chunk_position.y == 32 then
local area = {{x = left_top_x, y = left_top_y},{x = left_top_x + 31, y = left_top_y + 31}}
local area = {{x = left_top_x, y = left_top_y}, {x = left_top_x + 31, y = left_top_y + 31}}
local entities = surface.find_entities(area)
for _, e in pairs(entities) do
e.destroy()
@ -328,7 +334,7 @@ local function on_chunk_generated(event)
end
end
if chunk_position.x < -33 or chunk_position.x > 32 or chunk_position.y < -33 or chunk_position.y > 32 then
local area = {{x = left_top_x, y = left_top_y},{x = left_top_x + 31, y = left_top_y + 31}}
local area = {{x = left_top_x, y = left_top_y}, {x = left_top_x + 31, y = left_top_y + 31}}
local entities = surface.find_entities(area)
for _, e in pairs(entities) do
e.destroy()