Jump to content

[SOLVED] World Reset in World Creation Screen


Recommended Posts

So, I have a question for you guys. I'm trying to Reset the world creation (basically the world will start the creation from beginning) in the World Creation Screen by a specific criterea, but I don't know how to do it. ://
I already spend my entire week trying to search a way to do that, and yet the only thing that came in my mind was to Hook 'GenerateNew' from module 'worldgen_main' and to force the use of WorldSim:ResetAll(), but none of them seems to work.

@edit:

I want to force the world reset after 'DoGenerateWorld' was called and 'worldgen_main.lua' was already executed. The only circumstances that this occurs naturally that I have knowledge are: when 'GEN_PARAMETERS' is corrupted or 'forest_map.Generate' returned nil inside 'GeneratedNew' function from 'worldgen_main'. The only option that I can abuse is by forcing 'forest_map.Generate' to return nil. All I need to do is hook 'WorldSim:WorldGen_Commit' and then force it to return nil, then this code inside 'forest_map.Generate' runs:

if not WorldSim:WorldGen_Commit() then
    return nil
end

forcing this code to run:

local try = 1
local maxtries = 5

while savedata == nil do
    savedata = forest_map.Generate(prefab, max_map_width, max_map_height, choose_tasks, level, world_gen_data.level_type)

    if savedata == nil then
        if try >= maxtries then
            print("An error occured during world and we give up! [was ",try," of ",maxtries,"]")
            return nil
        else
            print("An error occured during world gen we will retry! [was ",try," of ",maxtries,"]")
        end
        try = try + 1

        --assert(try <= maxtries, "Maximum world gen retries reached!")
        collectgarbage("collect")
        WorldSim:ResetAll()
    elseif GEN_PARAMETERS == "" or world_gen_data.show_debug == true then
        ShowDebug(savedata)
    end
end

and then after all 5 retries the 'GenerateNew' returns nil and the game reload 'GEN_PARAMETERS', reload 'worldgen_main.lua' (which may change 'SEED' that is a desired effect) and retry to generate a new world.

The problem with this method is that takes WAY too many time to finish, which is a huge pain in the ass.

By the way, my code hooks 'Level:ChooseTasks' and 'Level:ChooseSetPieces', which means that the function 'GenerateNew' needs to run them before so I can check if I want to reset the world or not, and by "reset the world" I mean do it in the WorldGenScreen behind the curtains (WorldGenScreen is hidden if your world has Caves enabled)

Other thing that I'm trying to do is making my own 'GenerateNew' function and running it inside the mod environment, but I don't know if this will predict 'GenerateNew' from 'worldgen_main.lua' perfectly, and yet I too don't know how to reload 'GEN_PARAMETERS' which will be needed if I want to execute the function 'GenerateNew' alot.

Edited by Provoked
Cleanse
Link to comment
Share on other sites

-- Permanently delete all game worlds in a server cluster, regenerates new worlds afterwards
-- NOTE: This will not work properly for any shard that is offline or in a loading state
function c_regenerateworld()
    if TheWorld ~= nil and TheWorld.ismastersim then
        TheNet:SendWorldResetRequestToServer()
    end
end

Is this something you were looking for?

I think by just using TheNet:SendWorldResetRequestToServer() you should be able to reset the world.

  • Like 2
Link to comment
Share on other sites

2 hours ago, Monti18 said:

-- Permanently delete all game worlds in a server cluster, regenerates new worlds afterwards
-- NOTE: This will not work properly for any shard that is offline or in a loading state
function c_regenerateworld()
    if TheWorld ~= nil and TheWorld.ismastersim then
        TheNet:SendWorldResetRequestToServer()
    end
end

Is this something you were looking for?

I think by just using TheNet:SendWorldResetRequestToServer() you should be able to reset the world.

Yep, something like Regenerate, but it will do in the WorldGenerationScreen, behind the curtains.
TheNet:SendWorldRequestToServer didn't work btw.

Link to comment
Share on other sites

I don't know what exactly you want to check, but you can do it like this:

AddSimPostInit(function()
    if "your_check" == true then
		print("now resetting all")
		GLOBAL.TheNet:SendWorldResetRequestToServer()
    end
end)

This will regenerate the server each time your check is true.

  • Like 2
Link to comment
Share on other sites

22 hours ago, Monti18 said:

I don't know what exactly you want to check, but you can do it like this:


AddSimPostInit(function()
    if "your_check" == true then
		print("now resetting all")
		GLOBAL.TheNet:SendWorldResetRequestToServer()
    end
end)

This will regenerate the server each time your check is true.

That doesn't work, as you can see in the log file:

Spoiler

[00:01:44]: Ignored world reset request during loading state

I guess I described way too bad, I'm sorry, I'll try to rewrite everything I wanted to say in here and edit the topic after

Edited by Provoked
Link to comment
Share on other sites

Okay , so if I understand it correctly, if certain conditions are met, you want the server to regenerate the world with a differen seed?

Try using AddGamePostInit instead of AddSimPostInit, when I just tried it, my freshly created world resetted without ending when having no condition set.

AddGamePostInit(function()
	print("now resetting")
	GLOBAL.TheNet:SendWorldResetRequestToServer()
end)

Like this.

If this is not working, to solve this will probably be quite complicated. Are you running this in the modmain or modworldgenmain?

You could have a look at Gem Core from Zarklord and try to see if you find something that can help you as he is also using it to reset the worl with the same seed, perhaps there is something interesting in there.

  • Like 2
Link to comment
Share on other sites

14 minutes ago, Monti18 said:

Okay , so if I understand it correctly, if certain conditions are met, you want the server to regenerate the world with a differen seed?

Try using AddGamePostInit instead of AddSimPostInit, when I just tried it, my freshly created world resetted without ending when having no condition set.


AddGamePostInit(function()
	print("now resetting")
	GLOBAL.TheNet:SendWorldResetRequestToServer()
end)

Like this.

If this is not working, to solve this will probably be quite complicated. Are you running this in the modmain or modworldgenmain?

You could have a look at Gem Core from Zarklord and try to see if you find something that can help you as he is also using it to reset the worl with the same seed, perhaps there is something interesting in there.

Yes, I want to reset (regenerate) the server with a different seed. Yes, I can change SEED after it, but I want to see what this seed actually generates...

Again, the same error happened:

Spoiler

[00:01:13]: Ignored world reset request during loading state

Maybe that error doesn't show if I enable caves, I'll try it.

I don't want to mess up with someone else's code, and yet, Gem Core doesn't have server regeneration, it probably sends information to both server shards requesting a reset, that doesn't work since you need to have a world generated.

I will try to do my own 'worldgen_main.lua' inside my mod and hook 'TheSim:GenerateNewWorld' to predict the world generation, but I don't know if my version of the 'worldgen_main.lua' running in the mod environment will produce the same results.
 

Edited by Provoked
  • Like 1
Link to comment
Share on other sites

I just had a look, I get the error too,but it's still resetting.

Ah ok I understand it correctly now I think!

I was thinking about Gem Core as it can regenerate the server with a specific seed, that's why I thought that perhaps something interesting is in there :D

But yeah, I don't think I can help you further, this is also something I'm not sure how to fix. Your idea sounds good, I hope it works!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...