2012-08-27 15:06:11 -04:00
|
|
|
-- Global variables
|
|
|
|
PLUGIN = {} -- Reference to own plugin object
|
|
|
|
GENERATION_STATE = 0
|
|
|
|
OPERATION_CODE = 0 -- 0 = generation
|
|
|
|
CX = 0
|
|
|
|
CZ = 0
|
|
|
|
CURRENT = 0
|
2012-08-30 11:54:51 -04:00
|
|
|
TOTAL = 0
|
2013-10-25 06:36:39 -04:00
|
|
|
|
2012-08-27 15:06:11 -04:00
|
|
|
-- AREA Variables
|
|
|
|
AreaStartX = -10
|
|
|
|
AreaStartZ = -10
|
|
|
|
AreaEndX = 10
|
|
|
|
AreaEndZ = 10
|
2013-10-25 06:36:39 -04:00
|
|
|
|
2012-08-27 15:06:11 -04:00
|
|
|
-- RADIAL Variables
|
|
|
|
RadialX = 0
|
|
|
|
RadialZ = 0
|
2013-10-25 06:36:39 -04:00
|
|
|
Radius = 10
|
|
|
|
|
2012-08-27 15:06:11 -04:00
|
|
|
-- WORLD
|
|
|
|
WORK_WORLD = cRoot:Get():GetDefaultWorld():GetName()
|
|
|
|
WW_instance = cRoot:Get():GetDefaultWorld()
|
|
|
|
WORLDS = {}
|
|
|
|
|
2013-10-25 06:36:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-27 15:06:11 -04:00
|
|
|
function Initialize(Plugin)
|
|
|
|
PLUGIN = Plugin
|
|
|
|
|
|
|
|
PLUGIN:SetName("ChunkWorx")
|
2012-08-30 11:54:51 -04:00
|
|
|
PLUGIN:SetVersion(6)
|
2012-08-27 15:06:11 -04:00
|
|
|
|
2013-08-21 16:03:50 -04:00
|
|
|
cPluginManager.AddHook(cPluginManager.HOOK_TICK, OnTick)
|
2012-08-27 15:06:11 -04:00
|
|
|
|
|
|
|
Plugin:AddWebTab("(Re)Generation", HandleRequest_Generation)
|
|
|
|
|
|
|
|
GENERATION_STATE = 0
|
|
|
|
WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
|
|
|
|
if (WW_instance == nil) then
|
|
|
|
LOG("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": NO WORLD found :(")
|
|
|
|
end
|
|
|
|
|
2013-10-25 06:36:39 -04:00
|
|
|
-- Read the stored values:
|
|
|
|
local SettingsIni = cIniFile();
|
|
|
|
SettingsIni:ReadFile("ChunkWorx.ini"); -- ignore any read errors
|
|
|
|
AreaStartX = SettingsIni:GetValueSetI("Area data", "StartX", AreaStartX)
|
|
|
|
AreaStartZ = SettingsIni:GetValueSetI("Area data", "StartZ", AreaStartZ)
|
|
|
|
AreaEndX = SettingsIni:GetValueSetI("Area data", "EndX", AreaEndX)
|
|
|
|
AreaEndZ = SettingsIni:GetValueSetI("Area data", "EndZ", AreaEndZ)
|
|
|
|
RadialX = SettingsIni:GetValueSetI("Radial data", "RadialX", RadialX)
|
|
|
|
RadialZ = SettingsIni:GetValueSetI("Radial data", "RadialZ", RadialZ)
|
|
|
|
Radius = SettingsIni:GetValueSetI("Radial data", "Radius", Radius)
|
|
|
|
SettingsIni:WriteFile("ChunkWorx.ini");
|
2012-08-27 15:06:11 -04:00
|
|
|
|
|
|
|
LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-25 06:36:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-27 15:06:11 -04:00
|
|
|
|
2013-01-13 06:10:26 -05:00
|
|
|
function OnTick( DeltaTime )
|
2012-08-27 15:06:11 -04:00
|
|
|
if (GENERATION_STATE == 1 or GENERATION_STATE == 3) then
|
|
|
|
LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works STARTED!")
|
|
|
|
LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": At world: " .. WORK_WORLD)
|
|
|
|
WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
|
|
|
|
if (GENERATION_STATE == 1) then GENERATION_STATE = 2 end
|
|
|
|
if (GENERATION_STATE == 3) then GENERATION_STATE = 4 end
|
|
|
|
|
|
|
|
-- Changing in case coordinates are flipped
|
|
|
|
local shifter = AreaEndX
|
|
|
|
if (AreaStartX > AreaEndX) then
|
|
|
|
AreaEndX = AreaStartX
|
|
|
|
AreaStartX = shifter
|
|
|
|
end
|
|
|
|
shifter = AreaEndZ
|
|
|
|
if (AreaStartZ > AreaEndZ) then
|
|
|
|
AreaEndZ = AreaStartZ
|
|
|
|
AreaStartZ = shifter
|
|
|
|
end
|
|
|
|
|
|
|
|
CX = AreaStartX
|
|
|
|
CZ = AreaStartZ
|
|
|
|
CURRENT = 0
|
|
|
|
|
|
|
|
if (WW_instance == nil) then
|
2012-08-30 11:54:51 -04:00
|
|
|
LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works ABORTED")
|
|
|
|
LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": NO WORLD found :(")
|
2012-08-27 15:06:11 -04:00
|
|
|
GENERATION_STATE = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GENERATION_STATE == 2 or GENERATION_STATE == 4) then
|
|
|
|
if (WW_instance:GetGeneratorQueueLength() < 200
|
|
|
|
and WW_instance:GetLightingQueueLength() < 200
|
|
|
|
and (WW_instance:GetStorageSaveQueueLength() + WW_instance:GetStorageLoadQueueLength()) < 80) then
|
|
|
|
local chunk_sum = (1+ AreaEndX - AreaStartX) * (1+ AreaEndZ - AreaStartZ)
|
2012-08-30 11:54:51 -04:00
|
|
|
TOTAL = chunk_sum
|
2012-08-27 15:06:11 -04:00
|
|
|
LOG("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": PROCESSING 100 chunks, (" .. CURRENT .. "/" .. chunk_sum .. ")")
|
|
|
|
for C = 1, 100 do
|
|
|
|
if (GENERATION_STATE == 2) then WW_instance:GenerateChunk(CX, CZ) end
|
|
|
|
if (GENERATION_STATE == 4) then WW_instance:RegenerateChunk(CX, CZ) end
|
|
|
|
|
|
|
|
CX = CX + 1
|
|
|
|
CURRENT = CURRENT + 1
|
|
|
|
if (CX > AreaEndX) then
|
|
|
|
CX = AreaStartX
|
|
|
|
CZ = CZ + 1
|
|
|
|
if (CZ > AreaEndZ) then
|
|
|
|
if (GENERATION_STATE == 2) then LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " - generation ENDED!") end
|
|
|
|
if (GENERATION_STATE == 4) then LOGINFO("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " - REgeneration ENDED!") end
|
|
|
|
|
|
|
|
GENERATION_STATE = 0
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-10-25 06:36:39 -04:00
|
|
|
WW_instance:QueueSaveAllChunks()
|
2012-08-27 15:06:11 -04:00
|
|
|
WW_instance:UnloadUnusedChunks()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|