1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-12 10:13:58 +02:00

Increased radar protected range. Fixed pollution check. Added reset of chunk if all buildings removed. Added randomized RSO resources back in.

This commit is contained in:
oarcinae 2017-08-07 19:27:15 -04:00
parent 379c93b2bd
commit 32e0e5147f
7 changed files with 105 additions and 36 deletions

View File

@ -83,7 +83,7 @@ ENABLE_GRAVESTONE_ON_LEAVING = false
ENABLE_GRAVESTONE_ON_LEAVING_TIME_MINS = 30
-- Enable quick start items
ENABLE_POWER_ARMOR_QUICK_START = false
ENABLE_POWER_ARMOR_QUICK_START = true
-- Enable shared vision between teams (all teams are still COOP)
ENABLE_SHARED_TEAM_VISION = true

View File

@ -268,8 +268,11 @@ script.on_event(defines.events.on_built_entity, function(event)
if ENABLE_AUTOFILL then
Autofill(event)
end
end)
if ENABLE_REGROWTH then
OarcRegrowthOffLimitsChunk(event.created_entity.position)
end
end)
----------------------------------------
@ -297,13 +300,18 @@ if ENABLE_REGROWTH then
OarcRegrowthSectorScan(event)
end)
script.on_event(defines.events.on_built_entity, function (event)
OarcRegrowthOffLimits(event.created_entity.position, 1)
script.on_event(defines.events.on_robot_built_entity, function (event)
OarcRegrowthOffLimitsChunk(event.created_entity.position)
end)
script.on_event(defines.events.on_robot_built_entity, function (event)
OarcRegrowthOffLimits(event.created_entity.position, 1)
script.on_event(defines.events.on_player_mined_entity, function(event)
OarcRegrowthCheckChunkEmpty(event)
end)
script.on_event(defines.events.on_robot_mined_entity, function(event)
OarcRegrowthCheckChunkEmpty(event)
end)
end
@ -313,7 +321,9 @@ end
----------------------------------------
script.on_event(defines.events.on_console_chat, function(event)
if (ENABLE_SHARED_TEAM_CHAT) then
ShareChatBetweenForces(game.players[event.player_index], event.message)
if (game.players[event.player_index] ~= nil) then
ShareChatBetweenForces(game.players[event.player_index], event.message)
end
end
end)
@ -327,11 +337,3 @@ script.on_event(defines.events.on_research_finished, function(event)
end
end)
----------------------------------------
-- Other?
----------------------------------------
-- script.on_event(defines.events.on_robot_built_entity, function(event)
-- end)

View File

@ -12,6 +12,7 @@ CHUNK_SIZE = 32
MAX_FORCES = 64
TICKS_PER_SECOND = 60
TICKS_PER_MINUTE = TICKS_PER_SECOND * 60
TICKS_PER_HOUR = TICKS_PER_MINUTE * 60
--------------------------------------------------------------------------------
GAME_SURFACE_NAME="Game"
@ -712,7 +713,7 @@ function AutoFillVehicle(player, vehicle)
-- Attempt to transfer some fuel
if ((vehicle.name == "car") or (vehicle.name == "tank") or (vehicle.name == "locomotive")) then
TransferItemMultipleTypes(mainInv, vehicle, {"raw-wood", "coal", "solid-fuel", "rocket-fuel"}, 50)
TransferItemMultipleTypes(mainInv, vehicle, {"rocket-fuel", "solid-fuel", "coal", "raw-wood"}, 50)
end
-- Attempt to transfer some ammo
@ -722,7 +723,7 @@ function AutoFillVehicle(player, vehicle)
-- Attempt to transfer some tank shells
if (vehicle.name == "tank") then
TransferItemMultipleTypes(mainInv, vehicle, {"explosive-cannon-shell", "cannon-shell"}, 100)
TransferItemMultipleTypes(mainInv, vehicle, {"explosive-uranium-cannon-shell", "uranium-cannon-shell", "explosive-cannon-shell", "cannon-shell"}, 100)
end
end

View File

@ -27,7 +27,7 @@ richness_distance_factor= 1 -- exponent for richness distance factor calculatio
fluid_richness_distance_factor = 0.8 -- exponent for richness distance factor calculation for fluids
size_distance_factor=0.15 -- exponent for size distance factor calculation
deterministic = true -- set to false to use system for all decisions math.random
deterministic = false -- set to false to use system for all decisions math.random
-- mode is no longer used by generation process - it autodetects endless resources
-- endless_resource_mode = false -- if true, the size of each resource is modified by the following modifier. Use with the endless resources mod.

View File

@ -1109,6 +1109,7 @@ local function roll_region(c_x, c_y)
return false
end
-- Reroll regions every region_size^2 chunk generation calls.
local regrow_rso = false
if (ENABLE_REGROWTH) then
if (global.chunk_regrow.rso_region_roll_counter > (region_size*region_size/2)) then

View File

@ -16,14 +16,23 @@
-- 6. Chunks timeout after 1 hour-ish, configurable
-- 7. For now, oarc spawns are deletion safe as well, but only immediate area.
-- Generic Utility Includes
require("locale/oarc_utils")
-- Time after which chunks should be cleared.
REGROWTH_TIMEOUT_TICKS = 60*60*60 -- 1 hour
-- Default timeout of generated chunks
REGROWTH_TIMEOUT_TICKS = TICKS_PER_HOUR
-- We can't delete chunks regularly without causing lag.
-- So we should save them up to delete them.
REGROWTH_CLEANING_INTERVAL_TICKS = REGROWTH_TIMEOUT_TICKS
-- Not used right now.
-- It takes a radar 7 hours and 20 minutes to scan it's whole area completely
-- So I will bump the refresh time of blocks up by 8 hours
-- RADAR_COMPLETE_SCAN_TICKS = TICKS_PER_HOUR*8
-- Additional bonus time for certain things:
-- REFRESH_BONUS_RADAR = RADAR_COMPLETE_SCAN_TICKS
-- Init globals and set player join area to be off limits.
@ -52,6 +61,46 @@ function GetChunkCoordsFromPos(pos)
return {x=math.floor(pos.x/32), y=math.floor(pos.y/32)}
end
-- This complicated function checks that if a chunk
function CheckChunkEmpty(pos)
chunkPos = GetChunkCoordsFromPos(pos)
search_top_left = {x=chunkPos.x*32, y=chunkPos.y*32}
search_area = {search_top_left, {x=search_top_left.x+32,y=search_top_left.y+32}}
total = 0
for f,_ in pairs(game.forces) do
if f ~= "neutral" and f ~= "enemy" then
entities = game.surfaces[GAME_SURFACE_NAME].find_entities_filtered{area = search_area, force=f}
total = total + #entities
if (#entities > 0) then
for _,e in pairs(entities) do
if ((e.type == "player") or
(e.type == "car") or
(e.type == "logistic-robot") or
(e.type == "construction-robot")) then
total = total - 1
end
end
end
end
end
-- A destroyed entity is still found during the event check.
return (total == 1)
end
-- game.surfaces[GAME_SURFACE_NAME].find_entities_filtered{area = {game.player.position, {game.player.position.x+32, game.player.position-`32}}, type= "resource"}
-- If an entity is mined or destroyed, then check if the chunk
-- is empty. If it's empty, reset the refresh timer.
function OarcRegrowthCheckChunkEmpty(event)
if ((event.entity.force ~= nil) and (event.entity.force ~= "neutral") and (event.entity.force ~= "enemy")) then
if CheckChunkEmpty(event.entity.position) then
DebugPrint("Resetting chunk timer."..event.entity.position.x.." "..event.entity.position.y)
OarcRegrowthForceRefreshChunk(event.entity.position, 0)
end
end
end
-- Adds new chunks to the global table to track them.
-- This should always be called first in the chunk generate sequence
@ -141,7 +190,18 @@ function OarcRegrowthRefreshChunk(pos, bonus_time)
end
end
-- Refreshes timers on all chunks around a certain area
-- Forcefully refreshes timers on a chunk containing position
-- Will overwrite -1 flag.
function OarcRegrowthForceRefreshChunk(pos, bonus_time)
local c_pos = GetChunkCoordsFromPos(pos)
if (global.chunk_regrow.map[c_pos.x] == nil) then
global.chunk_regrow.map[c_pos.y] = {}
end
global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick + bonus_time
end
-- Refreshes timers on all chunks around a certain area
function OarcRegrowthRefreshArea(pos, chunk_radius, bonus_time)
local c_pos = GetChunkCoordsFromPos(pos)
@ -162,7 +222,7 @@ end
-- Refreshes timers on all chunks near an ACTIVE radar
function OarcRegrowthSectorScan(event)
OarcRegrowthRefreshArea(event.radar.position, 4, 0)
OarcRegrowthRefreshArea(event.radar.position, 14, 0)
OarcRegrowthRefreshChunk(event.chunk_position)
end
@ -183,9 +243,11 @@ function OarcRegrowthCheckArray()
-- Increment X
if (global.chunk_regrow.x_index > global.chunk_regrow.max_x) then
global.chunk_regrow.x_index = global.chunk_regrow.min_x
-- Increment Y
if (global.chunk_regrow.y_index > global.chunk_regrow.max_y) then
global.chunk_regrow.y_index = global.chunk_regrow.min_y
DebugPrint("Finished checking regrowth array."..global.chunk_regrow.min_x.." "..global.chunk_regrow.max_x.." "..global.chunk_regrow.min_y.." "..global.chunk_regrow.max_y)
else
global.chunk_regrow.y_index = global.chunk_regrow.y_index + 1
end
@ -256,14 +318,14 @@ function OarcRegrowthOnTick(event)
end
-- Send a broadcast warning before it happens.
if ((game.tick % REGROWTH_TIMEOUT_TICKS) == REGROWTH_TIMEOUT_TICKS-601) then
if ((game.tick % REGROWTH_CLEANING_INTERVAL_TICKS) == REGROWTH_CLEANING_INTERVAL_TICKS-601) then
if (#global.chunk_regrow.removal_list > 100) then
SendBroadcastMsg("Map cleanup in 10 seconds...")
end
end
-- Delete all listed chunks
if ((game.tick % REGROWTH_TIMEOUT_TICKS) == REGROWTH_TIMEOUT_TICKS-1) then
if ((game.tick % REGROWTH_CLEANING_INTERVAL_TICKS) == REGROWTH_CLEANING_INTERVAL_TICKS-1) then
if (#global.chunk_regrow.removal_list > 100) then
OarcRegrowthRemoveAllChunks()
SendBroadcastMsg("Map cleanup done...")
@ -272,7 +334,10 @@ function OarcRegrowthOnTick(event)
-- Catch force remove flag
if (game.tick == global.chunk_regrow.force_removal_flag+60) then
SendBroadcastMsg("Map cleanup in 10 seconds...")
end
if (game.tick == global.chunk_regrow.force_removal_flag+660) then
OarcRegrowthRemoveAllChunks()
-- SendBroadcastMsg("Immediate map cleanup done...")
SendBroadcastMsg("Map cleanup done...")
end
end

View File

@ -349,15 +349,15 @@ function SpawnOptsGuiClick(event)
end
-- Re-used abandoned spawns...
if (#global.unusedSpawns >= 1) then
oldSpawn = table.remove(global.unusedSpawns)
global.uniqueSpawns[player.name] = oldSpawn
player.print("Sorry! You have been assigned to an abandoned base! This is done to keep map size small.")
ChangePlayerSpawn(player, oldSpawn.pos)
SendPlayerToSpawn(player)
GivePlayerStarterItems(player)
SendBroadcastMsg(player.name .. " joined an abandoned base!")
else
-- if (#global.unusedSpawns >= 1) then
-- oldSpawn = table.remove(global.unusedSpawns)
-- global.uniqueSpawns[player.name] = oldSpawn
-- player.print("Sorry! You have been assigned to an abandoned base! This is done to keep map size small.")
-- ChangePlayerSpawn(player, oldSpawn.pos)
-- SendPlayerToSpawn(player)
-- GivePlayerStarterItems(player)
-- SendBroadcastMsg(player.name .. " joined an abandoned base!")
-- else
-- Find coordinates of a good place to spawn
if (elemName == "isolated_spawn_far") then
@ -386,7 +386,7 @@ function SpawnOptsGuiClick(event)
player.print("PLEASE WAIT WHILE YOUR SPAWN POINT IS GENERATED!")
player.print("PLEASE WAIT WHILE YOUR SPAWN POINT IS GENERATED!!")
player.print("PLEASE WAIT WHILE YOUR SPAWN POINT IS GENERATED!!!")
end
-- end
elseif (elemName == "join_other_spawn") then
DisplaySharedSpawnOptions(player)
@ -455,7 +455,7 @@ function SharedSpwnOptsGuiClick(event)
-- If a spawn is removed during this time, the button will not do anything
else
for spawnName,sharedSpawn in pairs(global.sharedSpawns) do
if (buttonClicked == spawnName) then
if ((buttonClicked == spawnName) and (game.players[spawnName] ~= nil)) then
CreateSpawnCtrlGui(player)
ChangePlayerSpawn(player,sharedSpawn.position)
SendPlayerToSpawn(player)