1
0
mirror of https://github.com/jvmguy/JvmguyScenario.git synced 2024-11-21 17:16:46 +02:00

Fix line endings. Make a special start surface.

This commit is contained in:
Kevin Morgan 2017-04-02 22:21:57 -07:00
parent 1216d4346d
commit d20a1e9104
7 changed files with 741 additions and 717 deletions

0
LICENSE Executable file → Normal file
View File

View File

@ -1,264 +1,267 @@
-- config.lua
-- Configuration Options
if not scenario then scenario = {} end
if not scenario.config then scenario.config = {} end
scenario.config.mapsettings = scenario.config.mapsettings or {}
--------------------------------------------------------------------------------
-- Messages
--------------------------------------------------------------------------------
WELCOME_MSG = "Welcome to jvmguy's server."
GAME_MODE_MSG = "In the current game mode, a satellite must be launched from the rocket silo in the center to win!"
-- GAME_MODE_MSG = "The current game mode is just basic vanilla!"
MODULES_ENABLED = "Mods Enabled: Separate Spawns, RSO, Gravestone Chests, Long-Reach, Autofill"
-- MODULES_ENABLED = "Mods Enabled: Gravestone-Chests"
-- WELCOME_MSG_TITLE = "[INSERT SERVER OWNER MSG HERE!]"
-- WELCOME_MSG_TITLE = "Welcome to Oarc's Server"
WELCOME_MSG_TITLE = "Welcome to Jvmguy's Server"
WELCOME_MSG0 = "This scenario is a variant of a scenario created by Oarc"
WELCOME_MSG1 = "Rules: Be polite. Ask before changing other players's stuff. Have fun!"
WELCOME_MSG2 = "This server is running a custom scenario that changes spawn locations."
WELCOME_MSG3 = "Due to the way this scenario works, it may take some time for the land"
WELCOME_MSG4 = "around your new spawn area to generate..."
WELCOME_MSG5 = "Please wait for 10-20 seconds when you select your first spawn."
WELCOME_MSG6 = "Oarc contact: SteamID:Oarc | Twitter:@_Oarc_ | oarcinae@gmail.com"
WELCOME_MSG7 = "jvmguy contact: SteamID:jvmguy | Discorc:@jvmguy | jvmgiu@gmail.com"
SPAWN_MSG1 = "Current Spawn Mode: HARDCORE WILDERNESS"
SPAWN_MSG2 = "In this mode, there is no default spawn. Everyone starts in the wild!"
SPAWN_MSG3 = "Resources are spread out far apart but are quite rich."
--------------------------------------------------------------------------------
-- Module Enables
-- These enables are not fully tested! For example, disable separate spawns
-- will probably break the frontier rocket silo mode
--------------------------------------------------------------------------------
-- Frontier style rocket silo mode
FRONTIER_ROCKET_SILO_MODE = true
-- Separate spawns
ENABLE_SEPARATE_SPAWNS = true
ENABLE_GOOD_STARTER_ITEMS = false
ENABLE_BETTER_STARTER_ITEMS = true
ENABLE_BEST_STARTER_ITEMS = false
ENABLE_LOGISTIC_STARTER_ITEMS = false
ENABLE_BLUEPRINT_FROM_START = false
ENABLE_ALL_RESEARCH_DONE = true
-- Enable Scenario version of RSO
ENABLE_RSO = true
-- Enable Gravestone Chests
ENABLE_GRAVESTONE_CHESTS = true
-- Enable Undecorator
ENABLE_UNDECORATOR = true
-- Enable Tags
ENABLE_TAGS = true
-- Enable Long Reach
ENABLE_LONGREACH = true
-- Enable Autofill
ENABLE_AUTOFILL = true
-- Enable BPS
ENABLE_BLUEPRINT_STRING = true
--------------------------------------------------------------------------------
-- Spawn Options
--------------------------------------------------------------------------------
ENABLE_CROP_OCTAGON=true
---------------------------------------
-- Distance Options
---------------------------------------
-- Near Distance in chunks
NEAR_MIN_DIST = 25 --50
NEAR_MAX_DIST = 100 --125
--
-- Far Distance in chunks
FAR_MIN_DIST = 100 --50
FAR_MAX_DIST = 200 --125
--
---------------------------------------
-- Resource Options
---------------------------------------
-- Start resource amounts
START_IRON_AMOUNT = 1500
START_COPPER_AMOUNT = 1500
START_STONE_AMOUNT = 1500
START_COAL_AMOUNT = 1500
START_OIL_AMOUNT = 30000
SPAWN_TREE_DENSITY = 0.2
-- Stat resource shape
-- If this is true, it will be a circle or an ellipse
-- If false, it will be a square
ENABLE_RESOURCE_SHAPE_CIRCLE = true
ELLIPSE_X_STRETCH=2.0 -- stretch the size horizontally (make it an ellipse)
-- Start resource position and size
-- Position is relative to player starting location
START_RESOURCE_STONE_POS_X = -25
START_RESOURCE_STONE_POS_Y = -31
START_RESOURCE_STONE_SIZE = 8
START_RESOURCE_COAL_POS_X = -25
START_RESOURCE_COAL_POS_Y = -16
START_RESOURCE_COAL_SIZE = 10
START_RESOURCE_COPPER_POS_X = -25
START_RESOURCE_COPPER_POS_Y = 0
START_RESOURCE_COPPER_SIZE = 12
START_RESOURCE_IRON_POS_X = -25
START_RESOURCE_IRON_POS_Y = 15
START_RESOURCE_IRON_SIZE = 14
START_RESOURCE_OIL_POS_X = 20
START_RESOURCE_OIL_POS_Y = -36
START_RESOURCE_OIL_POS2_X = 24
START_RESOURCE_OIL_POS2_Y = -36
---------------------------------------
-- We override the vertical position to give uniform spacing here. comment out to
---------------------------------------
RESOURCE_SEPARATION = 3
if RESOURCE_SEPARATION ~= nil then
START_RESOURCE_COAL_POS_Y = START_RESOURCE_STONE_POS_Y + START_RESOURCE_STONE_SIZE + RESOURCE_SEPARATION
START_RESOURCE_COPPER_POS_Y = START_RESOURCE_COAL_POS_Y + START_RESOURCE_COAL_SIZE + RESOURCE_SEPARATION
START_RESOURCE_IRON_POS_Y = START_RESOURCE_COPPER_POS_Y + START_RESOURCE_COPPER_SIZE + RESOURCE_SEPARATION
end
-- Force the land area circle at the spawn to be fully grass
ENABLE_SPAWN_FORCE_GRASS = true
---------------------------------------
-- Safe Spawn Area Options
---------------------------------------
-- Safe area has no aliens
-- +/- this in x and y direction
SAFE_AREA_TILE_DIST = CHUNK_SIZE*12
-- Warning area has reduced aliens
-- +/- this in x and y direction
WARNING_AREA_TILE_DIST = CHUNK_SIZE*14
-- 1 : X (spawners alive : spawners destroyed) in this area
WARN_AREA_REDUCTION_RATIO = 15
-- Create a circle of land area for the spawn
ENFORCE_LAND_AREA_TILE_DIST = 48
HEXSPACING = 1800 -- distance between spawns (tiles)
HEXFIRSTRING = 3 -- number of rings of start spawns
HEXRINGS = 4 -- number of rings of start spawns
HEX_FAR_SPACING = HEXSPACING * HEXFIRSTRING -- the outermost 2 rings
---------------------------------------
-- Other Forces/Teams Options
---------------------------------------
-- I am not currently implementing other teams. It gets too complicated.
-- Enable if people can join their own teams
-- ENABLE_OTHER_TEAMS = false
-- Main force is what default players join
MAIN_FORCE = "main_force"
-- Enable if people can spawn at the main base
ENABLE_DEFAULT_SPAWN = false
-- Enable if people can allow others to join their base
ENABLE_SHARED_SPAWNS = true
MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN = 2
---------------------------------------
-- Special Action Cooldowns
---------------------------------------
RESPAWN_COOLDOWN_IN_MINUTES = 15
RESPAWN_COOLDOWN_TICKS = TICKS_PER_MINUTE * RESPAWN_COOLDOWN_IN_MINUTES
-- Require playes to be online for at least 5 minutes
-- Else their character is removed and their spawn point is freed up for use
MIN_ONLIME_TIME_IN_MINUTES = 5
MIN_ONLINE_TIME = TICKS_PER_MINUTE * MIN_ONLIME_TIME_IN_MINUTES
-- Allow players to choose another spawn in the first 10 minutes
-- This does not allow creating a new spawn point. Only joining other players.
-- SPAWN_CHANGE_GRACE_PERIOD_IN_MINUTES = 10
-- SPAWN_GRACE_TIME = TICKS_PER_MINUTE * SPAWN_CHANGE_GRACE_PERIOD_IN_MINUTES
--------------------------------------------------------------------------------
-- Alien Options
--------------------------------------------------------------------------------
-- Enable/Disable enemy expansion
ENEMY_EXPANSION = false
-- Divide the alien factors by this number to reduce it (or multiply if < 1)
ENEMY_POLLUTION_FACTOR_DIVISOR = 10
ENEMY_DESTROY_FACTOR_DIVISOR = 5
--------------------------------------------------------------------------------
-- Frontier Rocket Silo Options
--------------------------------------------------------------------------------
-- SILO_DISTANCE = 4 * HEXSPACING
SILO_DISTANCE = CHUNK_SIZE -- put the silo 1 chunk east of the origin (prevents problems)
SILO_CHUNK_DISTANCE_X = math.floor(SILO_DISTANCE/CHUNK_SIZE);
SILO_DISTANCE_X = math.floor(SILO_DISTANCE/CHUNK_SIZE)* CHUNK_SIZE + CHUNK_SIZE/2
SILO_DISTANCE_Y = CHUNK_SIZE/2
-- Should be in the middle of a chunk
SILO_POSITION = {x = SILO_DISTANCE_X, y = SILO_DISTANCE_Y}
-- If this is enabled, the static position is ignored.
ENABLE_RANDOM_SILO_POSITION = false
--------------------------------------------------------------------------------
-- Long Reach Options
--------------------------------------------------------------------------------
BUILD_DIST_BONUS = 15
REACH_DIST_BONUS = BUILD_DIST_BONUS
RESOURCE_DIST_BONUS = 2
--------------------------------------------------------------------------------
-- Autofill Options
--------------------------------------------------------------------------------
AUTOFILL_TURRET_AMMO_QUANTITY = 10
--------------------------------------------------------------------------------
-- Use rso_config and rso_resourece_config for RSO config settings
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- DEBUG
--------------------------------------------------------------------------------
-- DEBUG prints for me
global.oarcDebugEnabled = false
global.jvmguyDebugEnabled = false
-- config.lua
-- Configuration Options
if not scenario then scenario = {} end
if not scenario.config then scenario.config = {} end
scenario.config.mapsettings = scenario.config.mapsettings or {}
--------------------------------------------------------------------------------
-- Messages
--------------------------------------------------------------------------------
WELCOME_MSG = "Welcome to jvmguy's server."
GAME_MODE_MSG = "In the current game mode, a satellite must be launched from the rocket silo in the center to win!"
-- GAME_MODE_MSG = "The current game mode is just basic vanilla!"
MODULES_ENABLED = "Mods Enabled: Separate Spawns, RSO, Gravestone Chests, Long-Reach, Autofill"
-- MODULES_ENABLED = "Mods Enabled: Gravestone-Chests"
-- WELCOME_MSG_TITLE = "[INSERT SERVER OWNER MSG HERE!]"
-- WELCOME_MSG_TITLE = "Welcome to Oarc's Server"
WELCOME_MSG_TITLE = "Welcome to Jvmguy's Server"
WELCOME_MSG0 = "This scenario is a variant of a scenario created by Oarc"
WELCOME_MSG1 = "Rules: Be polite. Ask before changing other players's stuff. Have fun!"
WELCOME_MSG2 = "This server is running a custom scenario that changes spawn locations."
WELCOME_MSG3 = "Due to the way this scenario works, it may take some time for the land"
WELCOME_MSG4 = "around your new spawn area to generate..."
WELCOME_MSG5 = "Please wait for 10-20 seconds when you select your first spawn."
WELCOME_MSG6 = "Oarc contact: SteamID:Oarc | Twitter:@_Oarc_ | oarcinae@gmail.com"
WELCOME_MSG7 = "jvmguy contact: SteamID:jvmguy | Discorc:@jvmguy | jvmgiu@gmail.com"
SPAWN_MSG1 = "Current Spawn Mode: HARDCORE WILDERNESS"
SPAWN_MSG2 = "In this mode, there is no default spawn. Everyone starts in the wild!"
SPAWN_MSG3 = "Resources are spread out far apart but are quite rich."
--------------------------------------------------------------------------------
-- Module Enables
-- These enables are not fully tested! For example, disable separate spawns
-- will probably break the frontier rocket silo mode
--------------------------------------------------------------------------------
-- Frontier style rocket silo mode
FRONTIER_ROCKET_SILO_MODE = true
-- put players on a special surface until they've chosen
ENABLE_SPAWN_SURFACE = true
-- Separate spawns
ENABLE_SEPARATE_SPAWNS = true
ENABLE_GOOD_STARTER_ITEMS = false
ENABLE_BETTER_STARTER_ITEMS = true
ENABLE_BEST_STARTER_ITEMS = false
ENABLE_LOGISTIC_STARTER_ITEMS = false
ENABLE_BLUEPRINT_FROM_START = false
ENABLE_ALL_RESEARCH_DONE = false
-- Enable Scenario version of RSO
ENABLE_RSO = true
-- Enable Gravestone Chests
ENABLE_GRAVESTONE_CHESTS = true
-- Enable Undecorator
ENABLE_UNDECORATOR = true
-- Enable Tags
ENABLE_TAGS = true
-- Enable Long Reach
ENABLE_LONGREACH = true
-- Enable Autofill
ENABLE_AUTOFILL = true
-- Enable BPS
ENABLE_BLUEPRINT_STRING = true
--------------------------------------------------------------------------------
-- Spawn Options
--------------------------------------------------------------------------------
ENABLE_CROP_OCTAGON=true
---------------------------------------
-- Distance Options
---------------------------------------
-- Near Distance in chunks
NEAR_MIN_DIST = 25 --50
NEAR_MAX_DIST = 100 --125
--
-- Far Distance in chunks
FAR_MIN_DIST = 100 --50
FAR_MAX_DIST = 200 --125
--
---------------------------------------
-- Resource Options
---------------------------------------
-- Start resource amounts
START_IRON_AMOUNT = 1500
START_COPPER_AMOUNT = 1500
START_STONE_AMOUNT = 1500
START_COAL_AMOUNT = 1500
START_OIL_AMOUNT = 30000
SPAWN_TREE_DENSITY = 0.2
-- Stat resource shape
-- If this is true, it will be a circle or an ellipse
-- If false, it will be a square
ENABLE_RESOURCE_SHAPE_CIRCLE = true
ELLIPSE_X_STRETCH=2.0 -- stretch the size horizontally (make it an ellipse)
-- Start resource position and size
-- Position is relative to player starting location
START_RESOURCE_STONE_POS_X = -25
START_RESOURCE_STONE_POS_Y = -31
START_RESOURCE_STONE_SIZE = 8
START_RESOURCE_COAL_POS_X = -25
START_RESOURCE_COAL_POS_Y = -16
START_RESOURCE_COAL_SIZE = 10
START_RESOURCE_COPPER_POS_X = -25
START_RESOURCE_COPPER_POS_Y = 0
START_RESOURCE_COPPER_SIZE = 12
START_RESOURCE_IRON_POS_X = -25
START_RESOURCE_IRON_POS_Y = 15
START_RESOURCE_IRON_SIZE = 14
START_RESOURCE_OIL_POS_X = 20
START_RESOURCE_OIL_POS_Y = -36
START_RESOURCE_OIL_POS2_X = 24
START_RESOURCE_OIL_POS2_Y = -36
---------------------------------------
-- We override the vertical position to give uniform spacing here. comment out to
---------------------------------------
RESOURCE_SEPARATION = 3
if RESOURCE_SEPARATION ~= nil then
START_RESOURCE_COAL_POS_Y = START_RESOURCE_STONE_POS_Y + START_RESOURCE_STONE_SIZE + RESOURCE_SEPARATION
START_RESOURCE_COPPER_POS_Y = START_RESOURCE_COAL_POS_Y + START_RESOURCE_COAL_SIZE + RESOURCE_SEPARATION
START_RESOURCE_IRON_POS_Y = START_RESOURCE_COPPER_POS_Y + START_RESOURCE_COPPER_SIZE + RESOURCE_SEPARATION
end
-- Force the land area circle at the spawn to be fully grass
ENABLE_SPAWN_FORCE_GRASS = true
---------------------------------------
-- Safe Spawn Area Options
---------------------------------------
-- Safe area has no aliens
-- +/- this in x and y direction
SAFE_AREA_TILE_DIST = CHUNK_SIZE*12
-- Warning area has reduced aliens
-- +/- this in x and y direction
WARNING_AREA_TILE_DIST = CHUNK_SIZE*14
-- 1 : X (spawners alive : spawners destroyed) in this area
WARN_AREA_REDUCTION_RATIO = 15
-- Create a circle of land area for the spawn
ENFORCE_LAND_AREA_TILE_DIST = 48
HEXSPACING = 1800 -- distance between spawns (tiles)
HEXFIRSTRING = 3 -- number of rings of start spawns
HEXRINGS = 4 -- number of rings of start spawns
HEX_FAR_SPACING = HEXSPACING * HEXFIRSTRING -- the outermost 2 rings
---------------------------------------
-- Other Forces/Teams Options
---------------------------------------
-- I am not currently implementing other teams. It gets too complicated.
-- Enable if people can join their own teams
-- ENABLE_OTHER_TEAMS = false
-- Main force is what default players join
MAIN_FORCE = "main_force"
-- Enable if people can spawn at the main base
ENABLE_DEFAULT_SPAWN = false
-- Enable if people can allow others to join their base
ENABLE_SHARED_SPAWNS = true
MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN = 2
---------------------------------------
-- Special Action Cooldowns
---------------------------------------
RESPAWN_COOLDOWN_IN_MINUTES = 15
RESPAWN_COOLDOWN_TICKS = TICKS_PER_MINUTE * RESPAWN_COOLDOWN_IN_MINUTES
-- Require playes to be online for at least 5 minutes
-- Else their character is removed and their spawn point is freed up for use
MIN_ONLIME_TIME_IN_MINUTES = 5
MIN_ONLINE_TIME = TICKS_PER_MINUTE * MIN_ONLIME_TIME_IN_MINUTES
-- Allow players to choose another spawn in the first 10 minutes
-- This does not allow creating a new spawn point. Only joining other players.
-- SPAWN_CHANGE_GRACE_PERIOD_IN_MINUTES = 10
-- SPAWN_GRACE_TIME = TICKS_PER_MINUTE * SPAWN_CHANGE_GRACE_PERIOD_IN_MINUTES
--------------------------------------------------------------------------------
-- Alien Options
--------------------------------------------------------------------------------
-- Enable/Disable enemy expansion
ENEMY_EXPANSION = false
-- Divide the alien factors by this number to reduce it (or multiply if < 1)
ENEMY_POLLUTION_FACTOR_DIVISOR = 10
ENEMY_DESTROY_FACTOR_DIVISOR = 5
--------------------------------------------------------------------------------
-- Frontier Rocket Silo Options
--------------------------------------------------------------------------------
-- SILO_DISTANCE = 4 * HEXSPACING
SILO_DISTANCE = CHUNK_SIZE -- put the silo 1 chunk east of the origin (prevents problems)
SILO_CHUNK_DISTANCE_X = math.floor(SILO_DISTANCE/CHUNK_SIZE);
SILO_DISTANCE_X = math.floor(SILO_DISTANCE/CHUNK_SIZE)* CHUNK_SIZE + CHUNK_SIZE/2
SILO_DISTANCE_Y = CHUNK_SIZE/2
-- Should be in the middle of a chunk
SILO_POSITION = {x = SILO_DISTANCE_X, y = SILO_DISTANCE_Y}
-- If this is enabled, the static position is ignored.
ENABLE_RANDOM_SILO_POSITION = false
--------------------------------------------------------------------------------
-- Long Reach Options
--------------------------------------------------------------------------------
BUILD_DIST_BONUS = 15
REACH_DIST_BONUS = BUILD_DIST_BONUS
RESOURCE_DIST_BONUS = 2
--------------------------------------------------------------------------------
-- Autofill Options
--------------------------------------------------------------------------------
AUTOFILL_TURRET_AMMO_QUANTITY = 10
--------------------------------------------------------------------------------
-- Use rso_config and rso_resourece_config for RSO config settings
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- DEBUG
--------------------------------------------------------------------------------
-- DEBUG prints for me
global.oarcDebugEnabled = false
global.jvmguyDebugEnabled = false

3
control.lua Executable file → Normal file
View File

@ -188,6 +188,9 @@ script.on_event(defines.events.on_player_joined_game, function(event)
end)
script.on_event(defines.events.on_player_created, function(event)
if ENABLE_SPAWN_SURFACE then
AssignPlayerToStartSurface(game.players[event.player_index])
end
if ENABLE_RSO then
RSO_PlayerCreated(event)
end

0
frontier_silo.lua Executable file → Normal file
View File

View File

@ -161,6 +161,24 @@ function EnableAutomatedConstruction(force)
force.technologies['automated-construction'].researched=true;
end
function AssignPlayerToStartSurface(player)
local startSurface = game.surfaces["start_world"]
if startSurface == nil then
local settings = {
terrain_segmentation = "very-low",
water= "very-high",
width =64,
height = 64,
starting_area = "low",
peaceful_mode = true,
seed = 1
};
game.create_surface("start_world", settings)
startSurface = game.surfaces["start_world"]
end
player.teleport( {x=0,y=0}, startSurface)
end
function ShowSpawns(player, t)
if t ~= nil then
for key,spawn in pairs(t) do

View File

@ -1,454 +1,454 @@
-- Nov 2016
--
-- Code that handles everything regarding giving each player a separate spawn
-- Includes the GUI stuff
--------------------------------------------------------------------------------
-- EVENT RELATED FUNCTIONS
--------------------------------------------------------------------------------
-- When a new player is created, present the spawn options
-- Assign them to the main force so they can communicate with the team
-- without shouting.
function SeparateSpawnsPlayerCreated(event)
local player = game.players[event.player_index]
player.force = MAIN_FORCE
DisplayWelcomeTextGui(player)
global.playerCooldowns[player.name] = {setRespawn=event.tick}
end
-- Check if the player has a different spawn point than the default one
-- Make sure to give the default starting items
function SeparateSpawnsPlayerRespawned(event)
local player = game.players[event.player_index]
SendPlayerToSpawn(player)
end
function GenerateSpawnChunk( event, spawnPos)
local surface = event.surface
local chunkArea = event.area
local landArea = {left_top=
{x=spawnPos.x-ENFORCE_LAND_AREA_TILE_DIST,
y=spawnPos.y-ENFORCE_LAND_AREA_TILE_DIST},
right_bottom=
{x=spawnPos.x+ENFORCE_LAND_AREA_TILE_DIST,
y=spawnPos.y+ENFORCE_LAND_AREA_TILE_DIST}}
local safeArea = {left_top=
{x=spawnPos.x-SAFE_AREA_TILE_DIST,
y=spawnPos.y-SAFE_AREA_TILE_DIST},
right_bottom=
{x=spawnPos.x+SAFE_AREA_TILE_DIST,
y=spawnPos.y+SAFE_AREA_TILE_DIST}}
local warningArea = {left_top=
{x=spawnPos.x-WARNING_AREA_TILE_DIST,
y=spawnPos.y-WARNING_AREA_TILE_DIST},
right_bottom=
{x=spawnPos.x+WARNING_AREA_TILE_DIST,
y=spawnPos.y+WARNING_AREA_TILE_DIST}}
local chunkAreaCenter = {x=chunkArea.left_top.x+(CHUNK_SIZE/2),
y=chunkArea.left_top.y+(CHUNK_SIZE/2)}
-- Make chunks near a spawn safe by removing enemies
if CheckIfInArea(chunkAreaCenter,safeArea) then
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, force = "enemy"}) do
entity.destroy()
end
-- Create a warning area with reduced enemies
elseif CheckIfInArea(chunkAreaCenter,warningArea) then
local counter = 0
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, force = "enemy"}) do
if ((counter % WARN_AREA_REDUCTION_RATIO) ~= 0) then
entity.destroy()
end
counter = counter + 1
end
-- Remove all big and huge worms
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, name = "medium-worm-turret"}) do
entity.destroy()
end
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, name = "big-worm-turret"}) do
entity.destroy()
end
end
-- Fill in any water to make sure we have guaranteed land mass at the spawn point.
if CheckIfInArea(chunkAreaCenter,landArea) then
-- remove trees in the immediate areas?
for key, entity in pairs(surface.find_entities_filtered({area=chunkArea, type= "tree"})) do
if ((spawnPos.x - entity.position.x)^2 + (spawnPos.y - entity.position.y)^2 < ENFORCE_LAND_AREA_TILE_DIST^2) then
entity.destroy()
end
end
if (ENABLE_CROP_OCTAGON) then
CreateCropOctagon(surface, spawnPos, chunkArea, ENFORCE_LAND_AREA_TILE_DIST)
else
CreateCropCircle(surface, spawnPos, chunkArea, ENFORCE_LAND_AREA_TILE_DIST)
end
CreateWaterStrip( surface, spawnPos, ENFORCE_LAND_AREA_TILE_DIST*3/4 )
if not spawnPos.generated then
spawnPos.generated = true;
GenerateStartingResources( surface, spawnPos);
end
end
end
-- This is the main function that creates the spawn area
-- Provides resources, land and a safe zone
function SeparateSpawnsGenerateChunk(event)
local surface = event.surface
if surface.name ~= "nauvis" then return end
local chunkArea = event.area
-- This handles chunk generation near player spawns
-- If it is near a player spawn, it does a few things like make the area
-- safe and provide a guaranteed area of land and water tiles.
for name,spawnPos in pairs(global.uniqueSpawns) do
GenerateSpawnChunk(event, spawnPos)
end
for name,spawnPos in pairs(global.unusedSpawns) do
GenerateSpawnChunk(event, spawnPos)
end
end
-- Call this if a player leaves the game
-- Seems to be susceptiable to causing desyncs...
function FindUnusedSpawns(event)
local player = game.players[event.player_index]
if (event.player_index>1 and player.online_time < MIN_ONLINE_TIME) then
-- TODO dump items into a chest.
-- Clear out global variables for that player???
if (global.playerSpawns[player.name] ~= nil) then
global.playerSpawns[player.name] = nil
end
-- If a uniqueSpawn was created for the player, mark it as unused.
if (global.uniqueSpawns[player.name] ~= nil) then
table.insert(global.unusedSpawns, global.uniqueSpawns[player.name])
global.uniqueSpawns[player.name] = nil
SendBroadcastMsg(player.name .. " base was freed up because they left within 5 minutes of joining.")
end
-- Remove from shared spawns
if (global.sharedSpawns[player.name] ~= nil) then
global.sharedSpawns[player.name] = nil
end
-- remove that player's cooldown setting
if (global.playerCooldowns[player.name] ~= nil) then
global.playerCooldowns[player.name] = nil
end
-- Remove from shared spawn player slots (need to search all)
for _,sharedSpawn in pairs(global.sharedSpawns) do
for key,playerName in pairs(sharedSpawn.players) do
if (player.name == playerName) then
sharedSpawn.players[key] = nil;
end
end
end
-- Remove the character completely
game.remove_offline_players({player})
end
end
function CreateNewSharedSpawn(player)
global.sharedSpawns[player.name] = {openAccess=true,
position=global.playerSpawns[player.name],
players={}}
end
function GetOnlinePlayersAtSharedSpawn(ownerName)
if (global.sharedSpawns[ownerName] ~= nil) then
-- Does not count base owner
local count = 0
-- For each player in the shared spawn, check if online and add to count.
for _,player in pairs(game.connected_players) do
if (ownerName == player.name) then
count = count + 1
end
for _,playerName in pairs(global.sharedSpawns[ownerName].players) do
if (playerName == player.name) then
count = count + 1
end
end
end
return count
else
return 0
end
end
-- Get the number of currently available shared spawns
-- This means the base owner has enabled access AND the number of online players
-- is below the threshold.
function GetNumberOfAvailableSharedSpawns()
local count = 0
for ownerName,sharedSpawn in pairs(global.sharedSpawns) do
if (sharedSpawn.openAccess) then
if (GetOnlinePlayersAtSharedSpawn(ownerName) < MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN) then
count = count+1
end
end
end
return count
end
--------------------------------------------------------------------------------
-- NON-EVENT RELATED FUNCTIONS
-- These should be local functions where possible!
--------------------------------------------------------------------------------
function HexPoint(kangle, rad)
local degreesToRadians = math.pi / 180;
-- the slight 10 degree tilt is to make the grid slightly less obvious
local angle = kangle * 2*math.pi / 6 + 10 * degreesToRadians;
return { x= rad * math.sin(angle), y = rad * math.cos(angle) }
end
function lerp( r, a, b)
return{ x = a.x + r * (b.x-a.x), y= a.y + r * (b.y-a.y) }
end
function HexRowPoint(kangle, rad, item, itemlen)
local first = HexPoint(kangle, rad)
local last = HexPoint(kangle+1, rad)
if itemlen==0 then
return first
end
return lerp( (1.0*item)/itemlen, first, last)
end
function CenterInChunk(a)
return { x = a.x-math.fmod(a.x, 32)+16, y=a.y-math.fmod(a.y, 32)+16 }
end
function InitSpawnPoint(k, kangle, j)
a = HexRowPoint(kangle, k*HEXSPACING, j, k)
local spawn = CenterInChunk(a);
spawn.generated = false;
spawn.used = false;
spawn.radius = k
spawn.sector = kangle
spawn.seq = j
table.insert(global.unusedSpawns, spawn );
table.insert(global.allSpawns, spawn)
end
function InitSpawnGlobalsAndForces()
-- Contains an array of all player spawns
-- A secondary array tracks whether the character will respawn there.
if (global.allSpawns == nil) then
global.allSpawns = {}
end
if (global.playerSpawns == nil) then
global.playerSpawns = {}
end
if (global.uniqueSpawns == nil) then
global.uniqueSpawns = {}
end
if (global.sharedSpawns == nil) then
global.sharedSpawns = {}
end
if (global.unusedSpawns == nil) then
global.unusedSpawns = {}
-- InitSpawnPoint( 0, 0, 0);
for rad = HEXFIRSTRING,HEXRINGS do
for kangle=0,5 do
for j=0,rad-1 do
InitSpawnPoint( rad, kangle, j)
end
end
end
-- for rad = 1,HEXRINGS do
-- for kangle=0,0 do
-- for j=0,0 do
-- InitSpawnPoint( rad, kangle, j)
-- end
-- end
-- end
end
if (global.playerCooldowns == nil) then
global.playerCooldowns = {}
end
game.create_force(MAIN_FORCE)
game.forces[MAIN_FORCE].set_spawn_position(game.forces["player"].get_spawn_position("nauvis"), "nauvis")
SetCeaseFireBetweenAllForces()
end
function GenerateStartingResources(surface, spawnPos)
--local surface = player.surface
-- Generate stone
local stonePos = {x=spawnPos.x+START_RESOURCE_STONE_POS_X,
y=spawnPos.y+START_RESOURCE_STONE_POS_Y}
-- Generate coal
local coalPos = {x=spawnPos.x+START_RESOURCE_COAL_POS_X,
y=spawnPos.y+START_RESOURCE_COAL_POS_Y}
-- Generate copper ore
local copperOrePos = {x=spawnPos.x+START_RESOURCE_COPPER_POS_X,
y=spawnPos.y+START_RESOURCE_COPPER_POS_Y}
-- Generate iron ore
local ironOrePos = {x=spawnPos.x+START_RESOURCE_IRON_POS_X,
y=spawnPos.y+START_RESOURCE_IRON_POS_Y}
-- Tree generation is taken care of in chunk generation
-- Generate oil patches
surface.create_entity({name="crude-oil", amount=START_OIL_AMOUNT,
position={spawnPos.x+START_RESOURCE_OIL_POS_X, spawnPos.y+START_RESOURCE_OIL_POS_Y}})
surface.create_entity({name="crude-oil", amount=START_OIL_AMOUNT,
position={spawnPos.x+START_RESOURCE_OIL_POS2_X, spawnPos.y+START_RESOURCE_OIL_POS2_Y}})
CreateResources( surface, stonePos, START_RESOURCE_STONE_SIZE, START_STONE_AMOUNT, "stone" );
CreateResources( surface, coalPos, START_RESOURCE_COAL_SIZE, START_COAL_AMOUNT, "coal" );
CreateResources( surface, copperOrePos, START_RESOURCE_COPPER_SIZE, START_COPPER_AMOUNT, "copper-ore" );
CreateResources( surface, ironOrePos, START_RESOURCE_IRON_SIZE, START_IRON_AMOUNT, "iron-ore" );
end
function CreateResources( surface, pos, size, startAmount, resourceName )
local xsize = size * ELLIPSE_X_STRETCH
local ysize = size
local xRadiusSq = (xsize/2)^2;
local yRadiusSq = (ysize/2)^2;
local midPointY = math.floor(size/2)
local midPointX = math.floor(xsize/2)
for y=0, size do
for x=0, xsize do
if (((x-midPointX)^2/xRadiusSq + (y-midPointY)^2/yRadiusSq < 1) or not ENABLE_RESOURCE_SHAPE_CIRCLE) then
surface.create_entity({name=resourceName, amount=startAmount,
position={pos.x+x, pos.y+y}})
end
end
end
end
function DoesPlayerHaveCustomSpawn(player)
for name,spawnPos in pairs(global.playerSpawns) do
if (player.name == name) then
return true
end
end
return false
end
function ChangePlayerSpawn(player, pos)
global.playerSpawns[player.name] = pos
end
function SendPlayerToNewSpawnAndCreateIt(player, spawn)
-- Send the player to that position
if spawn == nil then
DebugPrint("SendPlayerToNewSpawnAndCreateIt: error. spawn is nil")
spawn = { x = 0, y = 0 }
end
player.teleport(spawn)
ChartArea(player.force, player.position, 4)
-- If we get a valid spawn point, setup the area
if ((spawn.x ~= 0) and (spawn.y ~= 0)) then
global.uniqueSpawns[player.name] = spawn
ClearNearbyEnemies(player, SAFE_AREA_TILE_DIST)
else
DebugPrint("THIS SHOULD NOT EVER HAPPEN! Spawn failed!")
SendBroadcastMsg("Failed to create spawn point for: " .. player.name)
end
end
function SendPlayerToSpawn(player)
if (DoesPlayerHaveCustomSpawn(player)) then
player.teleport(global.playerSpawns[player.name])
else
player.teleport(game.forces[MAIN_FORCE].get_spawn_position("nauvis"))
end
end
function SendPlayerToRandomSpawn(player)
local numSpawns = TableLength(global.uniqueSpawns)
local rndSpawn = math.random(0,numSpawns)
local counter = 0
if (rndSpawn == 0) then
player.teleport(game.forces[MAIN_FORCE].get_spawn_position("nauvis"))
else
counter = counter + 1
for name,spawnPos in pairs(global.uniqueSpawns) do
if (counter == rndSpawn) then
player.teleport(spawnPos)
break
end
counter = counter + 1
end
end
end
--------------------------------------------------------------------------------
-- UNUSED CODE
-- Either didn't work, or not used or not tested....
--------------------------------------------------------------------------------
-- local tick_counter = 0
-- function ShareVision(event)
-- if (tick_counter > (TICKS_PER_SECOND*30)) then
-- ShareVisionForAllForces()
-- tick_counter = 0
-- end
-- tick_counter = tick_counter + 1
-- end
-- function CreatePlayerCustomForce(player)
-- local newForce = nil
-- -- Check if force already exists
-- if (game.forces[player.name] ~= nil) then
-- return game.forces[player.name]
-- -- Create a new force using the player's name
-- elseif (TableLength(game.forces) < MAX_FORCES) then
-- newForce = game.create_force(player.name)
-- player.force = newForce
-- SetCeaseFireBetweenAllForces()
-- else
-- player.force = MAIN_FORCE
-- player.print("Sorry, no new teams can be created. You were assigned to the default team instead.")
-- end
-- return newForce
-- Nov 2016
--
-- Code that handles everything regarding giving each player a separate spawn
-- Includes the GUI stuff
--------------------------------------------------------------------------------
-- EVENT RELATED FUNCTIONS
--------------------------------------------------------------------------------
-- When a new player is created, present the spawn options
-- Assign them to the main force so they can communicate with the team
-- without shouting.
function SeparateSpawnsPlayerCreated(event)
local player = game.players[event.player_index]
player.force = MAIN_FORCE
DisplayWelcomeTextGui(player)
global.playerCooldowns[player.name] = {setRespawn=event.tick}
end
-- Check if the player has a different spawn point than the default one
-- Make sure to give the default starting items
function SeparateSpawnsPlayerRespawned(event)
local player = game.players[event.player_index]
SendPlayerToSpawn(player)
end
function GenerateSpawnChunk( event, spawnPos)
local surface = event.surface
local chunkArea = event.area
local landArea = {left_top=
{x=spawnPos.x-ENFORCE_LAND_AREA_TILE_DIST,
y=spawnPos.y-ENFORCE_LAND_AREA_TILE_DIST},
right_bottom=
{x=spawnPos.x+ENFORCE_LAND_AREA_TILE_DIST,
y=spawnPos.y+ENFORCE_LAND_AREA_TILE_DIST}}
local safeArea = {left_top=
{x=spawnPos.x-SAFE_AREA_TILE_DIST,
y=spawnPos.y-SAFE_AREA_TILE_DIST},
right_bottom=
{x=spawnPos.x+SAFE_AREA_TILE_DIST,
y=spawnPos.y+SAFE_AREA_TILE_DIST}}
local warningArea = {left_top=
{x=spawnPos.x-WARNING_AREA_TILE_DIST,
y=spawnPos.y-WARNING_AREA_TILE_DIST},
right_bottom=
{x=spawnPos.x+WARNING_AREA_TILE_DIST,
y=spawnPos.y+WARNING_AREA_TILE_DIST}}
local chunkAreaCenter = {x=chunkArea.left_top.x+(CHUNK_SIZE/2),
y=chunkArea.left_top.y+(CHUNK_SIZE/2)}
-- Make chunks near a spawn safe by removing enemies
if CheckIfInArea(chunkAreaCenter,safeArea) then
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, force = "enemy"}) do
entity.destroy()
end
-- Create a warning area with reduced enemies
elseif CheckIfInArea(chunkAreaCenter,warningArea) then
local counter = 0
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, force = "enemy"}) do
if ((counter % WARN_AREA_REDUCTION_RATIO) ~= 0) then
entity.destroy()
end
counter = counter + 1
end
-- Remove all big and huge worms
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, name = "medium-worm-turret"}) do
entity.destroy()
end
for _, entity in pairs(surface.find_entities_filtered{area = chunkArea, name = "big-worm-turret"}) do
entity.destroy()
end
end
-- Fill in any water to make sure we have guaranteed land mass at the spawn point.
if CheckIfInArea(chunkAreaCenter,landArea) then
-- remove trees in the immediate areas?
for key, entity in pairs(surface.find_entities_filtered({area=chunkArea, type= "tree"})) do
if ((spawnPos.x - entity.position.x)^2 + (spawnPos.y - entity.position.y)^2 < ENFORCE_LAND_AREA_TILE_DIST^2) then
entity.destroy()
end
end
if (ENABLE_CROP_OCTAGON) then
CreateCropOctagon(surface, spawnPos, chunkArea, ENFORCE_LAND_AREA_TILE_DIST)
else
CreateCropCircle(surface, spawnPos, chunkArea, ENFORCE_LAND_AREA_TILE_DIST)
end
CreateWaterStrip( surface, spawnPos, ENFORCE_LAND_AREA_TILE_DIST*3/4 )
if not spawnPos.generated then
spawnPos.generated = true;
GenerateStartingResources( surface, spawnPos);
end
end
end
-- This is the main function that creates the spawn area
-- Provides resources, land and a safe zone
function SeparateSpawnsGenerateChunk(event)
local surface = event.surface
if surface.name ~= "nauvis" then return end
local chunkArea = event.area
-- This handles chunk generation near player spawns
-- If it is near a player spawn, it does a few things like make the area
-- safe and provide a guaranteed area of land and water tiles.
for name,spawnPos in pairs(global.uniqueSpawns) do
GenerateSpawnChunk(event, spawnPos)
end
for name,spawnPos in pairs(global.unusedSpawns) do
GenerateSpawnChunk(event, spawnPos)
end
end
-- Call this if a player leaves the game
-- Seems to be susceptiable to causing desyncs...
function FindUnusedSpawns(event)
local player = game.players[event.player_index]
if (event.player_index>1 and player.online_time < MIN_ONLINE_TIME) then
-- TODO dump items into a chest.
-- Clear out global variables for that player???
if (global.playerSpawns[player.name] ~= nil) then
global.playerSpawns[player.name] = nil
end
-- If a uniqueSpawn was created for the player, mark it as unused.
if (global.uniqueSpawns[player.name] ~= nil) then
table.insert(global.unusedSpawns, global.uniqueSpawns[player.name])
global.uniqueSpawns[player.name] = nil
SendBroadcastMsg(player.name .. " base was freed up because they left within 5 minutes of joining.")
end
-- Remove from shared spawns
if (global.sharedSpawns[player.name] ~= nil) then
global.sharedSpawns[player.name] = nil
end
-- remove that player's cooldown setting
if (global.playerCooldowns[player.name] ~= nil) then
global.playerCooldowns[player.name] = nil
end
-- Remove from shared spawn player slots (need to search all)
for _,sharedSpawn in pairs(global.sharedSpawns) do
for key,playerName in pairs(sharedSpawn.players) do
if (player.name == playerName) then
sharedSpawn.players[key] = nil;
end
end
end
-- Remove the character completely
game.remove_offline_players({player})
end
end
function CreateNewSharedSpawn(player)
global.sharedSpawns[player.name] = {openAccess=true,
position=global.playerSpawns[player.name],
players={}}
end
function GetOnlinePlayersAtSharedSpawn(ownerName)
if (global.sharedSpawns[ownerName] ~= nil) then
-- Does not count base owner
local count = 0
-- For each player in the shared spawn, check if online and add to count.
for _,player in pairs(game.connected_players) do
if (ownerName == player.name) then
count = count + 1
end
for _,playerName in pairs(global.sharedSpawns[ownerName].players) do
if (playerName == player.name) then
count = count + 1
end
end
end
return count
else
return 0
end
end
-- Get the number of currently available shared spawns
-- This means the base owner has enabled access AND the number of online players
-- is below the threshold.
function GetNumberOfAvailableSharedSpawns()
local count = 0
for ownerName,sharedSpawn in pairs(global.sharedSpawns) do
if (sharedSpawn.openAccess) then
if (GetOnlinePlayersAtSharedSpawn(ownerName) < MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN) then
count = count+1
end
end
end
return count
end
--------------------------------------------------------------------------------
-- NON-EVENT RELATED FUNCTIONS
-- These should be local functions where possible!
--------------------------------------------------------------------------------
function HexPoint(kangle, rad)
local degreesToRadians = math.pi / 180;
-- the slight 10 degree tilt is to make the grid slightly less obvious
local angle = kangle * 2*math.pi / 6 + 10 * degreesToRadians;
return { x= rad * math.sin(angle), y = rad * math.cos(angle) }
end
function lerp( r, a, b)
return{ x = a.x + r * (b.x-a.x), y= a.y + r * (b.y-a.y) }
end
function HexRowPoint(kangle, rad, item, itemlen)
local first = HexPoint(kangle, rad)
local last = HexPoint(kangle+1, rad)
if itemlen==0 then
return first
end
return lerp( (1.0*item)/itemlen, first, last)
end
function CenterInChunk(a)
return { x = a.x-math.fmod(a.x, 32)+16, y=a.y-math.fmod(a.y, 32)+16 }
end
function InitSpawnPoint(k, kangle, j)
a = HexRowPoint(kangle, k*HEXSPACING, j, k)
local spawn = CenterInChunk(a);
spawn.generated = false;
spawn.used = false;
spawn.radius = k
spawn.sector = kangle
spawn.seq = j
table.insert(global.unusedSpawns, spawn );
table.insert(global.allSpawns, spawn)
end
function InitSpawnGlobalsAndForces()
-- Contains an array of all player spawns
-- A secondary array tracks whether the character will respawn there.
if (global.allSpawns == nil) then
global.allSpawns = {}
end
if (global.playerSpawns == nil) then
global.playerSpawns = {}
end
if (global.uniqueSpawns == nil) then
global.uniqueSpawns = {}
end
if (global.sharedSpawns == nil) then
global.sharedSpawns = {}
end
if (global.unusedSpawns == nil) then
global.unusedSpawns = {}
-- InitSpawnPoint( 0, 0, 0);
for rad = HEXFIRSTRING,HEXRINGS do
for kangle=0,5 do
for j=0,rad-1 do
InitSpawnPoint( rad, kangle, j)
end
end
end
-- for rad = 1,HEXRINGS do
-- for kangle=0,0 do
-- for j=0,0 do
-- InitSpawnPoint( rad, kangle, j)
-- end
-- end
-- end
end
if (global.playerCooldowns == nil) then
global.playerCooldowns = {}
end
game.create_force(MAIN_FORCE)
game.forces[MAIN_FORCE].set_spawn_position(game.forces["player"].get_spawn_position("nauvis"), "nauvis")
SetCeaseFireBetweenAllForces()
end
function GenerateStartingResources(surface, spawnPos)
--local surface = player.surface
-- Generate stone
local stonePos = {x=spawnPos.x+START_RESOURCE_STONE_POS_X,
y=spawnPos.y+START_RESOURCE_STONE_POS_Y}
-- Generate coal
local coalPos = {x=spawnPos.x+START_RESOURCE_COAL_POS_X,
y=spawnPos.y+START_RESOURCE_COAL_POS_Y}
-- Generate copper ore
local copperOrePos = {x=spawnPos.x+START_RESOURCE_COPPER_POS_X,
y=spawnPos.y+START_RESOURCE_COPPER_POS_Y}
-- Generate iron ore
local ironOrePos = {x=spawnPos.x+START_RESOURCE_IRON_POS_X,
y=spawnPos.y+START_RESOURCE_IRON_POS_Y}
-- Tree generation is taken care of in chunk generation
-- Generate oil patches
surface.create_entity({name="crude-oil", amount=START_OIL_AMOUNT,
position={spawnPos.x+START_RESOURCE_OIL_POS_X, spawnPos.y+START_RESOURCE_OIL_POS_Y}})
surface.create_entity({name="crude-oil", amount=START_OIL_AMOUNT,
position={spawnPos.x+START_RESOURCE_OIL_POS2_X, spawnPos.y+START_RESOURCE_OIL_POS2_Y}})
CreateResources( surface, stonePos, START_RESOURCE_STONE_SIZE, START_STONE_AMOUNT, "stone" );
CreateResources( surface, coalPos, START_RESOURCE_COAL_SIZE, START_COAL_AMOUNT, "coal" );
CreateResources( surface, copperOrePos, START_RESOURCE_COPPER_SIZE, START_COPPER_AMOUNT, "copper-ore" );
CreateResources( surface, ironOrePos, START_RESOURCE_IRON_SIZE, START_IRON_AMOUNT, "iron-ore" );
end
function CreateResources( surface, pos, size, startAmount, resourceName )
local xsize = size * ELLIPSE_X_STRETCH
local ysize = size
local xRadiusSq = (xsize/2)^2;
local yRadiusSq = (ysize/2)^2;
local midPointY = math.floor(size/2)
local midPointX = math.floor(xsize/2)
for y=0, size do
for x=0, xsize do
if (((x-midPointX)^2/xRadiusSq + (y-midPointY)^2/yRadiusSq < 1) or not ENABLE_RESOURCE_SHAPE_CIRCLE) then
surface.create_entity({name=resourceName, amount=startAmount,
position={pos.x+x, pos.y+y}})
end
end
end
end
function DoesPlayerHaveCustomSpawn(player)
for name,spawnPos in pairs(global.playerSpawns) do
if (player.name == name) then
return true
end
end
return false
end
function ChangePlayerSpawn(player, pos)
global.playerSpawns[player.name] = pos
end
function SendPlayerToNewSpawnAndCreateIt(player, spawn)
-- Send the player to that position
if spawn == nil then
DebugPrint("SendPlayerToNewSpawnAndCreateIt: error. spawn is nil")
spawn = { x = 0, y = 0 }
end
player.teleport(spawn, game.surfaces["nauvis"])
ChartArea(player.force, player.position, 4)
-- If we get a valid spawn point, setup the area
if ((spawn.x ~= 0) and (spawn.y ~= 0)) then
global.uniqueSpawns[player.name] = spawn
ClearNearbyEnemies(player, SAFE_AREA_TILE_DIST)
else
DebugPrint("THIS SHOULD NOT EVER HAPPEN! Spawn failed!")
SendBroadcastMsg("Failed to create spawn point for: " .. player.name)
end
end
function SendPlayerToSpawn(player)
if (DoesPlayerHaveCustomSpawn(player)) then
player.teleport(global.playerSpawns[player.name], game.surfaces["nauvis"])
else
player.teleport(game.forces[MAIN_FORCE].get_spawn_position("nauvis"), game.surfaces["nauvis"])
end
end
function SendPlayerToRandomSpawn(player)
local numSpawns = TableLength(global.uniqueSpawns)
local rndSpawn = math.random(0,numSpawns)
local counter = 0
if (rndSpawn == 0) then
player.teleport(game.forces[MAIN_FORCE].get_spawn_position("nauvis"), game.surfaces["nauvis"])
else
counter = counter + 1
for name,spawnPos in pairs(global.uniqueSpawns) do
if (counter == rndSpawn) then
player.teleport(spawnPos, game.surfaces["nauvis"])
break
end
counter = counter + 1
end
end
end
--------------------------------------------------------------------------------
-- UNUSED CODE
-- Either didn't work, or not used or not tested....
--------------------------------------------------------------------------------
-- local tick_counter = 0
-- function ShareVision(event)
-- if (tick_counter > (TICKS_PER_SECOND*30)) then
-- ShareVisionForAllForces()
-- tick_counter = 0
-- end
-- tick_counter = tick_counter + 1
-- end
-- function CreatePlayerCustomForce(player)
-- local newForce = nil
-- -- Check if force already exists
-- if (game.forces[player.name] ~= nil) then
-- return game.forces[player.name]
-- -- Create a new force using the player's name
-- elseif (TableLength(game.forces) < MAX_FORCES) then
-- newForce = game.create_force(player.name)
-- player.force = newForce
-- SetCeaseFireBetweenAllForces()
-- else
-- player.force = MAIN_FORCE
-- player.print("Sorry, no new teams can be created. You were assigned to the default team instead.")
-- end
-- return newForce
-- end

0
separate_spawns_guis.lua Executable file → Normal file
View File