1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-04 09:43:00 +02:00

Adding long-reach soft mod, random silo position, player limit for joining spawns, text changes messages.

This commit is contained in:
Oarcinae 2016-12-13 18:46:48 -05:00
parent db1532575f
commit cdfc09c929
6 changed files with 221 additions and 61 deletions

View File

@ -31,4 +31,6 @@ RSO is not my own creation. It was done by Orzelek. I requested permission to in
https://mods.factorio.com/mods/orzelek/rso-mod
Several other portions of the code (tags, frontier style rocket silo) have also been adapted from other scenario code.
Several other portions of the code (tags, frontier style rocket silo) have also been adapted from other scenario code.
Credit to 3Ra as well: https://github.com/3RaGaming/3Ra-Enhanced-Vanilla

View File

@ -5,15 +5,20 @@
-- Messages
--------------------------------------------------------------------------------
WELCOME_MSG = "Welcome to Oarc's server! Follow @_Oarc_ for server updates."
GAME_MODE_MSG = "In the current game mode, a satellite must be launched from the rocket silo to the far east to win!"
WELCOME_MSG = "Welcome to Oarc's official server! Follow @_Oarc_ for server updates."
GAME_MODE_MSG = "In the current game mode, a satellite must be launched from an existing far away rocket silo to win!"
-- GAME_MODE_MSG = "The current game mode is just basic vanilla!"
MODULES_ENABLED = "Mods Enabled: Separate Spawns, RSO, Gravestone Chests"
MODULES_ENABLED = "Mods Enabled: Separate Spawns, RSO, Gravestone Chests, Long-Reach"
-- MODULES_ENABLED = "Mods Enabled: Gravestone-Chests"
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."
OTHER_MSG1 = "Latest updates in this scenario version (0.2.2):"
OTHER_MSG2 = "Long-reach soft mod, random silo position, limited # players joining a spawn."
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."
@ -48,6 +53,9 @@ ENABLE_UNDECORATOR = true
-- Enable Tags
ENABLE_TAGS = true
-- Enable Long Reach
ENABLE_LONGREACH = true
--------------------------------------------------------------------------------
-- Spawn Options
--------------------------------------------------------------------------------
@ -81,11 +89,11 @@ 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*12
-- Warning area has reduced aliens
-- +/- this in x and y direction
WARNING_AREA_TILE_DIST = CHUNK_SIZE*16
WARNING_AREA_TILE_DIST = CHUNK_SIZE*20
-- 1 : X (spawners alive : spawners destroyed) in this area
WARN_AREA_REDUCTION_RATIO = 15
@ -108,15 +116,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
--------------------------------------------------------------------------------
@ -130,7 +150,6 @@ ENEMY_EXPANSION = false
ENEMY_POLLUTION_FACTOR_DIVISOR = 15
ENEMY_DESTROY_FACTOR_DIVISOR = 5
--------------------------------------------------------------------------------
-- Frontier Rocket Silo Options
--------------------------------------------------------------------------------
@ -142,6 +161,17 @@ SILO_DISTANCE_Y = 16
-- 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
--------------------------------------------------------------------------------
-- Use rso_config and rso_resourece_config for RSO config settings

View File

@ -87,6 +87,10 @@ script.on_init(function(event)
InitSpawnGlobalsAndForces()
end
if ENABLE_RANDOM_SILO_POSITION then
SetRandomSiloPosition()
end
if FRONTIER_ROCKET_SILO_MODE then
ChartRocketSiloArea(game.forces[MAIN_FORCE])
end
@ -161,6 +165,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

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,9 @@ my_spacer_style = {
maximal_height = 20,
font_color = {r=0,g=0,b=0}
}
my_small_button_style = {
font = "default-small-semibold"
}
--------------------------------------------------------------------------------
@ -378,6 +381,27 @@ function ConfigureAlienStartingParams()
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
-- This technically creates a position in a diamon shape I think?
function SetRandomSiloPosition()
-- Get an X,Y on a circle far away.
distX = math.random(0,SILO_CHUNK_DISTANCE_X)
distY = math.floor(math.sqrt(distX^2 + SILO_CHUNK_DISTANCE_X^2))
-- Set those values.
SILO_DISTANCE_X = distX*CHUNK_SIZE + CHUNK_SIZE/2
SILO_DISTANCE_Y = distY*CHUNK_SIZE + CHUNK_SIZE/2
SILO_POSITION = {x = SILO_DISTANCE_X, y = SILO_DISTANCE_Y}
end
--------------------------------------------------------------------------------
-- EVENT SPECIFIC FUNCTIONS

View File

@ -145,19 +145,72 @@ 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 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

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.
@ -38,6 +48,16 @@ function DisplayWelcomeTextGui(player)
ApplyStyle(wGui.welcome_msg_lbl2, my_label_style)
ApplyStyle(wGui.welcome_msg_spacer1, my_spacer_style)
wGui.add{name = "other_msg_lbl1", type = "label",
caption=OTHER_MSG1}
wGui.add{name = "other_msg_lbl2", type = "label",
caption=OTHER_MSG2}
wGui.add{name = "other_msg_spacer1", type = "label",
caption=" "}
ApplyStyle(wGui.other_msg_lbl1, my_label_style)
ApplyStyle(wGui.other_msg_lbl2, my_label_style)
ApplyStyle(wGui.other_msg_spacer1, my_spacer_style)
wGui.add{name = "welcome_msg_lbl3", type = "label",
caption=WELCOME_MSG3}
@ -154,40 +174,52 @@ function DisplaySpawnOptions(player)
-- Spawn options to join another player's base.
if (TableLength(global.sharedSpawns) > 0) then
sGui.add{name = "join_other_spawn",
type = "button",
caption="Join Someone (" .. TableLength(global.sharedSpawns) .. " available)"}
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="You are spawned in someone else's base."}
sGui.add{name = "join_other_spawn_lbl2", type = "label",
caption="This requires at least 1 person to have allowed access to their base."}
sGui.add{name = "join_other_spawn_lbl3", type = "label",
caption="This choice is final and you will not be able to create your own spawn later."}
sGui.add{name = "join_other_spawn_spacer", type = "label",
caption=" "}
ApplyStyle(sGui.join_other_spawn_lbl1, my_label_style)
ApplyStyle(sGui.join_other_spawn_lbl2, my_label_style)
ApplyStyle(sGui.join_other_spawn_lbl3, my_label_style)
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
if ENABLE_SHARED_SPAWNS then
local numAvailSpawns = GetNumberOfAvailableSharedSpawns()
if (numAvailSpawns > 0) then
sGui.add{name = "join_other_spawn",
type = "button",
caption="Join Someone (" .. numAvailSpawns .. " available)"}
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="You are spawned in someone else's base."}
sGui.add{name = "join_other_spawn_lbl2", type = "label",
caption="This requires at least 1 person to have allowed access to their base."}
sGui.add{name = "join_other_spawn_lbl3", type = "label",
caption="This choice is final and you will not be able to create your own spawn later."}
sGui.add{name = "join_other_spawn_spacer", type = "label",
caption=" "}
ApplyStyle(sGui.join_other_spawn_lbl1, my_label_style)
ApplyStyle(sGui.join_other_spawn_lbl2, my_label_style)
ApplyStyle(sGui.join_other_spawn_lbl3, my_label_style)
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
else
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="There are currently no shared bases availble to spawn at."}
sGui.add{name = "join_other_spawn_spacer", type = "label",
caption=" "}
ApplyStyle(sGui.join_other_spawn_lbl1, my_warning_style)
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
sGui.add{name = "join_other_spawn_check",
type = "button",
caption="Check Again"}
end
else
sGui.add{name = "join_other_spawn_lbl1", type = "label",
caption="There are currently no shared bases availble to spawn at."}
sGui.add{name = "join_other_spawn_spacer", type = "label",
caption=" "}
caption="Shared spawns are disabled in this mode."}
ApplyStyle(sGui.join_other_spawn_lbl1, my_warning_style)
ApplyStyle(sGui.join_other_spawn_spacer, my_spacer_style)
sGui.add{name = "join_other_spawn_check",
type = "button",
caption="Check Again"}
end
-- Some final notes
sGui.add{name = "note_spacer1", type = "label",
caption="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"}
sGui.add{name = "note_spacer2", type = "label",
caption=" "}
if MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN then
sGui.add{name = "shared_spawn_note1", type = "label",
caption="If you create your own spawn point you can allow up to " .. MAX_ONLINE_PLAYERS_AT_SHARED_SPAWN-1 .. " other online players to join." }
ApplyStyle(sGui.shared_spawn_note1, my_note_style)
end
sGui.add{name = "note_lbl1", type = "label",
caption="Near spawn is between " .. NEAR_MIN_DIST*CHUNK_SIZE .. "-" .. NEAR_MAX_DIST*CHUNK_SIZE .. " tiles away from the center of the map."}
sGui.add{name = "note_lbl2", type = "label",
@ -305,10 +337,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
@ -333,12 +371,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()
@ -358,7 +397,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
@ -372,9 +412,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
@ -398,17 +438,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
@ -450,12 +490,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
@ -471,5 +516,3 @@ function SpawnCtrlGuiClick(event)
end
end
end