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

Merge latest Oarc code with minor revisions.

This commit is contained in:
Kevin Morgan 2016-12-19 00:11:25 -08:00
parent 4e55a4603a
commit a8b02fee6d
8 changed files with 400 additions and 82 deletions

View File

@ -23,4 +23,6 @@ Much needed.
## Credit
Very little of this is my own creation. It's my spin on a scenario created by Oarc.
See https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn

View File

@ -37,10 +37,10 @@ SPAWN_MSG3 = "Resources are spread out far apart but are quite rich."
-- will probably break the frontier rocket silo mode
--------------------------------------------------------------------------------
-- Separate spawns
-- Frontier style rocket silo mode
FRONTIER_ROCKET_SILO_MODE = true
-- Frontier style rocket silo mode
-- Separate spawns
ENABLE_SEPARATE_SPAWNS = true
-- Enable Scenario version of RSO
@ -55,10 +55,16 @@ ENABLE_UNDECORATOR = true
-- Enable Tags
ENABLE_TAGS = true
-- Enable Long Reach
ENABLE_LONGREACH = true
-- Enable Autofill
ENABLE_AUTOFILL = true
--------------------------------------------------------------------------------
-- Spawn Options
--------------------------------------------------------------------------------
ENABLE_CROP_HEXAGON=true
---------------------------------------
-- Distance Options
---------------------------------------
@ -75,12 +81,38 @@ FAR_MAX_DIST = 200 --125
---------------------------------------
-- Start resource amounts
START_IRON_AMOUNT = 1500
START_IRON_AMOUNT = 1800
START_COPPER_AMOUNT = 1500
START_STONE_AMOUNT = 1500
START_COAL_AMOUNT = 1500
START_OIL_AMOUNT = 30000
-- 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 = 14
START_RESOURCE_COAL_POS_X = -25
START_RESOURCE_COAL_POS_Y = -16
START_RESOURCE_COAL_SIZE = 14
START_RESOURCE_COPPER_POS_X = -25
START_RESOURCE_COPPER_POS_Y = 0
START_RESOURCE_COPPER_SIZE = 14
START_RESOURCE_IRON_POS_X = -25
START_RESOURCE_IRON_POS_Y = 15
START_RESOURCE_IRON_SIZE = 14
START_RESOURCE_OIL_POS_X = -32
START_RESOURCE_OIL_POS_Y = 0
---------------------------------------
-- Safe Spawn Area Options
@ -88,7 +120,7 @@ START_OIL_AMOUNT = 30000
-- Safe area has no aliens
-- +/- this in x and y direction
SAFE_AREA_TILE_DIST = CHUNK_SIZE*8
SAFE_AREA_TILE_DIST = CHUNK_SIZE*10
-- Warning area has reduced aliens
-- +/- this in x and y direction
@ -120,15 +152,27 @@ 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 = 3
---------------------------------------
-- Special Action Cooldowns
---------------------------------------
RESPAWN_COOLDOWN_TICKS = TICKS_PER_SECOND * 60 * 60
RESPAWN_COOLDOWN_IN_MINUTES = 60
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_ONLINE_TIME = TICKS_PER_SECOND * 60 * 5
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
--------------------------------------------------------------------------------
@ -139,8 +183,8 @@ MIN_ONLINE_TIME = TICKS_PER_SECOND * 60 * 5
ENEMY_EXPANSION = false
-- Divide the alien factors by this number to reduce it (or multiply if < 1)
ENEMY_POLLUTION_FACTOR_DIVISOR = 5
ENEMY_DESTROY_FACTOR_DIVISOR = 5
ENEMY_POLLUTION_FACTOR_DIVISOR = 20
ENEMY_DESTROY_FACTOR_DIVISOR = 8
--------------------------------------------------------------------------------
@ -148,12 +192,29 @@ ENEMY_DESTROY_FACTOR_DIVISOR = 5
--------------------------------------------------------------------------------
SILO_DISTANCE = 4 * HEXSPACING
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 = true
--------------------------------------------------------------------------------
-- 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

View File

@ -88,9 +88,21 @@ script.on_init(function(event)
InitSpawnGlobalsAndForces()
end
if ENABLE_RANDOM_SILO_POSITION then
SetRandomSiloPosition()
else
SetFixedSiloPosition()
end
if FRONTIER_ROCKET_SILO_MODE then
ChartRocketSiloArea(game.forces[MAIN_FORCE])
end
-- local entityTest = game.surfaces["nauvis"].create_entity({name = "big-ship-wreck-1", position = {0, 0}, force = "neutral", direction = 0})
-- game.surfaces["nauvis"].create_entity({name="flying-text", position={0,0}, text="Hello world", color={r=0.5,g=1,b=1}})
-- local entityEnvTest = entityTest.get_inventory(defines.inventory.chest)
-- entityEnvTest.insert{name="iron-plate", count=3}
end)
@ -162,6 +174,10 @@ script.on_event(defines.events.on_player_created, function(event)
RSO_PlayerCreated(event)
end
if ENABLE_LONGREACH then
GivePlayerLongReach(game.players[event.player_index])
end
if not ENABLE_SEPARATE_SPAWNS then
PlayerSpawnItems(event)
else
@ -181,6 +197,10 @@ script.on_event(defines.events.on_player_respawned, function(event)
else
SeparateSpawnsPlayerRespawned(event)
end
if ENABLE_LONGREACH then
GivePlayerLongReach(game.players[event.player_index])
end
end)
script.on_event(defines.events.on_player_left_game, function(event)
@ -189,6 +209,13 @@ script.on_event(defines.events.on_player_left_game, function(event)
end
end)
script.on_event(defines.events.on_built_entity, function(event)
if ENABLE_AUTOFILL then
Autofill(event)
end
end)
----------------------------------------
-- On Research Finished

View File

@ -6,10 +6,10 @@ require("oarc_utils")
-- Create a rocket silo
local function CreateRocketSilo(surface, chunkArea)
if CheckIfInArea(SILO_POSITION, chunkArea) then
if CheckIfInArea(global.siloPosition, chunkArea) then
-- Delete any entities beneat the silo?
for _, entity in pairs(surface.find_entities_filtered{area = {{SILO_POSITION.x-5, SILO_POSITION.y-6},{SILO_POSITION.x+6, SILO_POSITION.y+6}}}) do
for _, entity in pairs(surface.find_entities_filtered{area = {{global.siloPosition.x-5, global.siloPosition.y-6},{global.siloPosition.x+6, global.siloPosition.y+6}}}) do
entity.destroy()
end
@ -18,7 +18,7 @@ local function CreateRocketSilo(surface, chunkArea)
local i = 1
for dx = -6,6 do
for dy = -7,6 do
tiles[i] = {name = "grass", position = {SILO_POSITION.x+dx, SILO_POSITION.y+dy}}
tiles[i] = {name = "grass", position = {global.siloPosition.x+dx, global.siloPosition.y+dy}}
i=i+1
end
end
@ -27,14 +27,14 @@ local function CreateRocketSilo(surface, chunkArea)
i = 1
for dx = -5,5 do
for dy = -6,5 do
tiles[i] = {name = "concrete", position = {SILO_POSITION.x+dx, SILO_POSITION.y+dy}}
tiles[i] = {name = "concrete", position = {global.siloPosition.x+dx, global.siloPosition.y+dy}}
i=i+1
end
end
surface.set_tiles(tiles, true)
-- Create silo and assign to main force
local silo = surface.create_entity{name = "rocket-silo", position = {SILO_POSITION.x+0.5, SILO_POSITION.y}, force = MAIN_FORCE}
local silo = surface.create_entity{name = "rocket-silo", position = {global.siloPosition.x+0.5, global.siloPosition.y}, force = MAIN_FORCE}
silo.destructible = false
silo.minable = false
end
@ -58,11 +58,11 @@ function GenerateRocketSiloChunk(event)
local chunkAreaCenter = {x=chunkArea.left_top.x+(CHUNK_SIZE/2),
y=chunkArea.left_top.y+(CHUNK_SIZE/2)}
local safeArea = {left_top=
{x=SILO_POSITION.x-150,
y=SILO_POSITION.y-150},
{x=global.siloPosition.x-150,
y=global.siloPosition.y-150},
right_bottom=
{x=SILO_POSITION.x+150,
y=SILO_POSITION.y+150}}
{x=global.siloPosition.x+150,
y=global.siloPosition.y+150}}
-- Clear enemies directly next to the rocket
@ -74,9 +74,9 @@ function GenerateRocketSiloChunk(event)
-- Create rocket silo
CreateRocketSilo(surface, chunkArea)
CreateCropCircle(surface, SILO_POSITION, chunkArea, 40)
CreateCropCircle(surface, global.siloPosition, chunkArea, 40)
end
function ChartRocketSiloArea(force)
force.chart(game.surfaces["nauvis"], {{SILO_POSITION.x-(CHUNK_SIZE*2), SILO_POSITION.y-(CHUNK_SIZE*2)}, {SILO_POSITION.x+(CHUNK_SIZE*2), SILO_POSITION.y+(CHUNK_SIZE*2)}})
force.chart(game.surfaces["nauvis"], {{global.siloPosition.x-(CHUNK_SIZE*2), global.siloPosition.y-(CHUNK_SIZE*2)}, {global.siloPosition.x+(CHUNK_SIZE*2), global.siloPosition.y+(CHUNK_SIZE*2)}})
end

View File

@ -11,6 +11,7 @@
CHUNK_SIZE = 32
MAX_FORCES = 64
TICKS_PER_SECOND = 60
TICKS_PER_MINUTE = TICKS_PER_SECOND * 60
--------------------------------------------------------------------------------
@ -46,7 +47,10 @@ my_spacer_style = {
maximal_height = 20,
font_color = {r=0,g=0,b=0}
}
my_small_button_style = {
font = "default-small-semibold"
}
my_color_red = {r=1,g=0.1,b=0.1}
--------------------------------------------------------------------------------
@ -61,6 +65,17 @@ function DebugPrint(msg)
end
end
-- Prints flying text.
-- Color is optional
function FlyingText(msg, pos, color)
local surface = game.surfaces["nauvis"]
if color == nil then
surface.create_entity({ name = "flying-text", position = pos, text = msg })
else
surface.create_entity({ name = "flying-text", position = pos, text = msg, color = color })
end
end
-- Broadcast messages
function SendBroadcastMsg(msg)
for name,player in pairs(game.connected_players) do
@ -370,8 +385,116 @@ function CreateCropCircle(surface, centerPos, chunkArea, tileRadius)
surface.set_tiles(dirtTiles)
end
-- Adjust alien params
function ConfigureAlienStartingParams()
game.map_settings.enemy_evolution.time_factor=0
game.map_settings.enemy_evolution.destroy_factor = game.map_settings.enemy_evolution.destroy_factor / ENEMY_DESTROY_FACTOR_DIVISOR
game.map_settings.enemy_evolution.pollution_factor = game.map_settings.enemy_evolution.pollution_factor / ENEMY_POLLUTION_FACTOR_DIVISOR
game.map_settings.enemy_expansion.enabled = ENEMY_EXPANSION
end
-- Add Long Reach to Character
function GivePlayerLongReach(player)
player.character.character_build_distance_bonus = BUILD_DIST_BONUS
player.character.character_reach_distance_bonus = REACH_DIST_BONUS
-- player.character.character_resource_reach_distance_bonus = RESOURCE_DIST_BONUS
end
function SetRandomSiloPosition()
if (global.siloPosition == nil) then
-- Get an X,Y on a circle far away.
distX = math.random(0,SILO_CHUNK_DISTANCE_X)
distY = RandomNegPos() * math.floor(math.sqrt(SILO_CHUNK_DISTANCE_X^2 - distX^2))
distX = RandomNegPos() * distX
-- Set those values.
local siloX = distX*CHUNK_SIZE + CHUNK_SIZE/2
local siloY = distY*CHUNK_SIZE + CHUNK_SIZE/2
global.siloPosition = {x = siloX, y = siloY}
end
end
-- Use preset value
function SetFixedSiloPosition()
if (global.siloPosition == nil) then
global.siloPosition = SILO_POSITION
end
end
-- Transfer Items Between Inventory
-- Returns the number of items that were successfully transferred.
-- Returns -1 if item not available.
-- Returns -2 if can't place item into destInv (ERROR)
function TransferItems(srcInv, destEntity, itemStack)
-- Check if item is in srcInv
if (srcInv.get_item_count(itemStack.name) == 0) then
return -1
end
-- Check if can insert into destInv
if (not destEntity.can_insert(itemStack)) then
return -2
end
-- Insert items
local itemsRemoved = srcInv.remove(itemStack)
itemStack.count = itemsRemoved
return destEntity.insert(itemStack)
end
-- Attempts to transfer at least some of one type of item from an array of items.
-- Use this to try transferring several items in order
-- It returns once it successfully inserts at least some of one type.
function TransferItemMultipleTypes(srcInv, destEntity, itemNameArray, itemCount)
local ret = 0
for _,itemName in pairs(itemNameArray) do
ret = TransferItems(srcInv, destEntity, {name=itemName, count=itemCount})
if (ret > 0) then
return ret -- Return the value succesfully transferred
end
end
return ret -- Return the last error code
end
function AutofillTurret(player, turret)
local mainInv = player.get_inventory(defines.inventory.player_main)
-- Attempt to transfer some ammo
local ret = TransferItemMultipleTypes(mainInv, turret, {"piercing-rounds-magazine","firearm-magazine"}, AUTOFILL_TURRET_AMMO_QUANTITY)
-- Check the result and print the right text to inform the user what happened.
if (ret > 0) then
-- Inserted ammo successfully
-- FlyingText("Inserted ammo x" .. ret, turret.position, my_color_red)
elseif (ret == -1) then
FlyingText("Out of ammo!", turret.position, my_color_red)
elseif (ret == -2) then
FlyingText("Autofill ERROR! - Report this bug!", turret.position, my_color_red)
end
end
function AutoFillVehicle(player, vehicle)
local mainInv = player.get_inventory(defines.inventory.player_main)
-- Attempt to transfer some fuel
if ((vehicle.name == "car") or (vehicle.name == "tank") or (vehicle.name == "diesel-locomotive")) then
TransferItemMultipleTypes(mainInv, vehicle, {"raw-wood", "coal", "solid-fuel"}, 50)
end
-- Attempt to transfer some ammo
if ((vehicle.name == "car") or (vehicle.name == "tank")) then
TransferItemMultipleTypes(mainInv, vehicle, {"piercing-rounds-magazine","firearm-magazine"}, 100)
end
-- Attempt to transfer some tank shells
if (vehicle.name == "tank") then
TransferItemMultipleTypes(mainInv, vehicle, {"explosive-cannon-shell", "cannon-shell"}, 100)
end
end
-- Enforce a square of land, with a tree border
function CreateCropSquare(surface, centerPos, chunkArea, tileRadius)
function CreateCropHexagon(surface, centerPos, chunkArea, tileRadius)
local dirtTiles = {}
for i=chunkArea.left_top.x,chunkArea.right_bottom.x,1 do
@ -414,14 +537,6 @@ function CreateWaterStrip(surface, spawnPos, tileRadius)
surface.set_tiles(waterTiles)
end
-- Adjust alien params
function ConfigureAlienStartingParams()
game.map_settings.enemy_evolution.time_factor=0
game.map_settings.enemy_evolution.destroy_factor = game.map_settings.enemy_evolution.destroy_factor / ENEMY_DESTROY_FACTOR_DIVISOR
game.map_settings.enemy_evolution.pollution_factor = game.map_settings.enemy_evolution.pollution_factor / ENEMY_POLLUTION_FACTOR_DIVISOR
game.map_settings.enemy_expansion.enabled = ENEMY_EXPANSION
end
--------------------------------------------------------------------------------
@ -459,6 +574,19 @@ function PlayerSpawnItems(event)
GivePlayerStarterItems(game.players[event.player_index])
end
-- Autofill softmod
function Autofill(event)
local player = game.players[event.player_index]
local eventEntity = event.created_entity
if (eventEntity.name == "gun-turret") then
AutofillTurret(player, eventEntity)
end
if ((eventEntity.name == "car") or (eventEntity.name == "tank") or (eventEntity.name == "diesel-locomotive")) then
AutoFillVehicle(player, eventEntity)
end
end
--------------------------------------------------------------------------------
-- UNUSED CODE

View File

@ -23,7 +23,7 @@ multi_resource_chance_diminish = 0.6 -- diminishing effect factor on multi_resou
min_amount=250 -- default value for minimum amount of resource in single pile
richness_distance_factor=0.6 -- exponent for richness distance factor calculation
richness_distance_factor=0.9 -- exponent for richness distance factor calculation
size_distance_factor=0.15 -- exponent for size distance factor calculation
deterministic = true -- set to false to use system for all decisions math.random

View File

@ -94,7 +94,11 @@ function GenerateSpawnChunk( event, spawnPos)
entity.destroy()
end
end
CreateCropSquare(surface, spawnPos, chunkArea, ENFORCE_LAND_AREA_TILE_DIST)
if (ENABLE_CROP_HEXAGON) then
CreateCropHexagon(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;
@ -128,6 +132,8 @@ function FindUnusedSpawns(event)
local player = game.players[event.player_index]
if (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
@ -140,19 +146,82 @@ function FindUnusedSpawns(event)
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
@ -235,40 +304,48 @@ function GenerateStartingResources(surface, spawnPos)
--local surface = player.surface
-- Generate stone
local stonePos = {x=spawnPos.x-25,
y=spawnPos.y-31}
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-25,
y=spawnPos.y-16}
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-25,
y=spawnPos.y+0}
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-25,
y=spawnPos.y+15}
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-30, spawnPos.y-2}})
position={spawnPos.x+START_RESOURCE_OIL_POS_X, spawnPos.y+START_RESOURCE_OIL_POS_Y-2}})
surface.create_entity({name="crude-oil", amount=START_OIL_AMOUNT,
position={spawnPos.x-30, spawnPos.y+2}})
position={spawnPos.x+START_RESOURCE_OIL_POS_X, spawnPos.y+START_RESOURCE_OIL_POS_Y+2}})
for y=0, 15 do
for x=0, 20 do
if ((x-10)^2/10^2 + (y - 7)^2/7^2 < 1) then
surface.create_entity({name="iron-ore", amount=START_IRON_AMOUNT,
position={ironOrePos.x+x, ironOrePos.y+y}})
surface.create_entity({name="copper-ore", amount=START_COPPER_AMOUNT,
position={copperOrePos.x+x, copperOrePos.y+y}})
surface.create_entity({name="stone", amount=START_STONE_AMOUNT,
position={stonePos.x+x, stonePos.y+y}})
surface.create_entity({name="coal", amount=START_COAL_AMOUNT,
position={coalPos.x+x, coalPos.y+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
@ -292,11 +369,11 @@ function SendPlayerToNewSpawnAndCreateIt(player, spawn)
player.teleport(spawn)
GivePlayerStarterItems(player)
ChartArea(player.force, player.position, 4)
-- ClearNearbyEnemies(player.surface, spawn, SAFE_AREA_TILE_DIST)
-- 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.surface, spawn, SAFE_AREA_TILE_DIST)
else
DebugPrint("THIS SHOULD NOT EVER HAPPEN! Spawn failed!")
SendBroadcastMsg("Failed to create spawn point for: " .. player.name)
@ -367,4 +444,4 @@ end
-- end
-- return newForce
-- end
-- end

View File

@ -9,9 +9,19 @@ local SPAWN_GUI_MAX_WIDTH = 450
local SPAWN_GUI_MAX_HEIGHT = 650
-- Use this for testing shared spawns...
-- /c global.sharedSpawns = {TESTNAME1={x=50,y=50},
-- TESTNAME2={x=-50,y=-50},
-- TESTNAME3={x=-50,y=50}}
-- local sharedSpawnExample1 = {openAccess=true,
-- position={x=50,y=50},
-- players={"ABC", "DEF"}}
-- local sharedSpawnExample2 = {openAccess=false,
-- position={x=200,y=200},
-- players={"ABC", "DEF"}}
-- local sharedSpawnExample3 = {openAccess=true,
-- owner="testName1",
-- players={"A", "B", "C", "D"}}
-- global.sharedSpawns = {testName1=sharedSpawnExample1,
-- testName2=sharedSpawnExample2,
-- testName3=sharedSpawnExample3}
-- A display gui message
-- Meant to be display the first time a player joins.
@ -229,6 +239,7 @@ function SpawnOptsGuiClick(event)
if (player.gui.center.spawn_opts ~= nil) then
player.gui.center.spawn_opts.destroy()
end
end
if (buttonClicked == "default_spawn_btn") then
@ -237,6 +248,7 @@ function SpawnOptsGuiClick(event)
ChangePlayerSpawn(player, player.force.get_spawn_position("nauvis"))
SendBroadcastMsg(player.name .. " joined the main force!")
ChartArea(player.force, player.position, 4)
elseif ((buttonClicked == "isolated_spawn_near") or (buttonClicked == "isolated_spawn_far")) then
CreateSpawnCtrlGui(player)
@ -328,10 +340,16 @@ function DisplaySharedSpawnOptions(player)
shGui.horizontal_scroll_policy = "never"
for spawnName,_ in pairs(global.sharedSpawns) do
shGui.add{type="button", caption=spawnName, name=spawnName}
shGui.add{name = spawnName .. "spacer_lbl", type = "label", caption=" "}
ApplyStyle(shGui[spawnName .. "spacer_lbl"], my_spacer_style)
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
if sharedSpawn.openAccess then
local spotsRemaining = MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN - GetOnlinePlayersAtSharedSpawn(spawnName)
if (spotsRemaining > 0) then
shGui.add{type="button", caption=spawnName .. " (" .. spotsRemaining .. " spots remaining)", name=spawnName}
shGui.add{name = spawnName .. "spacer_lbl", type = "label", caption=" "}
ApplyStyle(shGui[spawnName], my_small_button_style)
ApplyStyle(shGui[spawnName .. "spacer_lbl"], my_spacer_style)
end
end
end
@ -356,12 +374,13 @@ function SharedSpwnOptsGuiClick(event)
-- Else check for which spawn was selected
-- If a spawn is removed during this time, the button will not do anything
else
for spawnName,spawnPos in pairs(global.sharedSpawns) do
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
if (buttonClicked == spawnName) then
CreateSpawnCtrlGui(player)
ChangePlayerSpawn(player,spawnPos)
ChangePlayerSpawn(player,sharedSpawn.position)
SendPlayerToSpawn(player)
GivePlayerStarterItems(player)
table.insert(sharedSpawn.players, player.name)
SendBroadcastMsg(player.name .. " joined " .. spawnName .. "'s base!")
if (player.gui.center.shared_spawn_opts ~= nil) then
player.gui.center.shared_spawn_opts.destroy()
@ -381,7 +400,8 @@ end
local function IsSharedSpawnActive(player)
if (global.sharedSpawns[player.name] == nil) then
if ((global.sharedSpawns[player.name] == nil) or
(global.sharedSpawns[player.name].openAccess == false)) then
return false
else
return true
@ -395,9 +415,9 @@ function GetRandomSpawnPoint()
if (numSpawnPoints > 0) then
local randSpawnNum = math.random(1,numSpawnPoints)
local counter = 1
for _, spawnPos in pairs(global.sharedSpawns) do
for _,sharedSpawn in pairs(global.sharedSpawns) do
if (randSpawnNum == counter) then
return spawnPos
return sharedSpawn.position
end
counter = counter + 1
end
@ -421,17 +441,17 @@ function ExpandSpawnCtrlGui(player, tick)
spwnCtrls.style.maximal_height = SPAWN_GUI_MAX_HEIGHT
spwnCtrls.horizontal_scroll_policy = "never"
if (global.uniqueSpawns[player.name] ~= nil) then
-- This checkbox allows people to join your base when they first
-- start the game.
spwnCtrls.add{type="checkbox", name="accessToggle",
caption="Allow others to join your base.",
state=IsSharedSpawnActive(player)}
spwnCtrls["accessToggle"].style.top_padding = 10
spwnCtrls["accessToggle"].style.bottom_padding = 10
ApplyStyle(spwnCtrls["accessToggle"], my_fixed_width_style)
if ENABLE_SHARED_SPAWNS then
if (global.uniqueSpawns[player.name] ~= nil) then
-- This checkbox allows people to join your base when they first
-- start the game.
spwnCtrls.add{type="checkbox", name="accessToggle",
caption="Allow others to join your base.",
state=IsSharedSpawnActive(player)}
spwnCtrls["accessToggle"].style.top_padding = 10
spwnCtrls["accessToggle"].style.bottom_padding = 10
ApplyStyle(spwnCtrls["accessToggle"], my_fixed_width_style)
end
end
@ -473,12 +493,17 @@ function SpawnCtrlGuiClick(event)
if (name == "accessToggle") then
if event.element.state then
if DoesPlayerHaveCustomSpawn(player) then
global.sharedSpawns[player.name] = global.playerSpawns[player.name]
if (global.sharedSpawns[player.name] == nil) then
CreateNewSharedSpawn(player)
else
global.sharedSpawns[player.name].openAccess = true
end
SendBroadcastMsg("New players can now join " .. player.name .. "'s base!")
end
else
if (global.sharedSpawns[player.name] ~= nil) then
global.sharedSpawns[player.name] = nil
global.sharedSpawns[player.name].openAccess = false
SendBroadcastMsg("New players can no longer join " .. player.name .. "'s base!")
end
end
@ -494,5 +519,3 @@ function SpawnCtrlGuiClick(event)
end
end
end