-
Notifications
You must be signed in to change notification settings - Fork 36
Custom level generation #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 24 commits
8b17521
7c047e1
ea8320c
d2bf067
2490b78
8f8c157
f9fb019
f65b5f5
d313242
e2f77b4
32e508d
1feba7f
bfab985
845072c
c2cc975
47dbdd9
7d5ce08
57a718d
05c839a
9a7e37e
40605fd
797a52d
8ad7897
2e6f9f4
e1b7d98
bd2415e
52c50b5
c308a3e
0bbb155
d89ff98
fc5098b
6edd184
2c37191
86ff2bb
062d157
4732779
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| #include "../Patches/MainMenuBlock.h" | ||
| #include "../Patches/XMLData.h" | ||
| #include "../Patches/EntityPlus.h" | ||
| #include "LuaDungeonGenerator.h" | ||
|
|
||
| //Callback tracking for optimizations | ||
| std::bitset<500> CallbackState; // For new REPENTOGON callbacks. I dont think we will add 500 callbacks but lets set it there for now | ||
|
|
@@ -5646,4 +5647,90 @@ HOOK_STATIC(LuaEngine, PostEntityKill, (Entity* ent) -> void, __stdcall) { | |
| .push(lastSource, lua::Metatables::ENTITY_REF) | ||
| .call(1); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //MC_PRE_GENERATE_DUNGEON(1340) | ||
| bool ProcessGenerateDungeonCallback(Level* level, RNG& rng, int dungeonType) { | ||
| const int callbackId = 1340; | ||
| if (!CallbackState.test(callbackId - 1000)) { | ||
| return false; | ||
| } | ||
|
|
||
| lua_State* L = g_LuaEngine->_state; | ||
| lua::LuaStackProtector protector(L); | ||
| lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key); | ||
|
|
||
| DungeonGenerator generator(&rng); | ||
| lua::LuaResults results = lua::LuaCaller(L) | ||
| .push(callbackId) | ||
| .push(dungeonType) | ||
| .push(&generator, lua::metatables::DungeonGeneratorMT) | ||
| .push(&rng, lua::Metatables::RNG) | ||
| .push(dungeonType) | ||
| .call(1); | ||
|
|
||
| if (results || !lua_isboolean(L, -1) || !lua_toboolean(L, -1)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to change this, as right now I expect that if someone returns an invalid level layout, we don't give a chance for other callbacks to run and simply return to default generation.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic here seems like it might be fine, but yeah this callback will likely require custom handling in main_ex.lua. We could potentially detect that a mod left things in an invalid state, possibly print an error to the console, then reset it before we run the next callback. Not mandatory for an initial push, but is something we should sort out before this gets included in a release. |
||
| { | ||
| return false; | ||
| } | ||
|
|
||
| bool correctGeneration = generator.Generate(level); | ||
|
|
||
| return correctGeneration; | ||
| } | ||
|
|
||
| HOOK_METHOD(Level, generate_dungeon, (RNG* rng) -> void) | ||
| { | ||
| bool skip = ProcessGenerateDungeonCallback(this, *rng, 0); | ||
|
||
| if (skip) { | ||
| return; | ||
| } | ||
|
|
||
| super(rng); | ||
| } | ||
|
|
||
| HOOK_METHOD(Level, generate_blue_womb, () -> void) { | ||
| bool skip = ProcessGenerateDungeonCallback(this, g_Game->_generationRNG, 1); | ||
|
||
| if (skip) { | ||
| return; | ||
| } | ||
|
|
||
| super(); | ||
| } | ||
|
|
||
| HOOK_METHOD(Level, generate_backwards_dungeon, () -> void) { | ||
| bool skip = ProcessGenerateDungeonCallback(this, g_Game->_generationRNG, 2); | ||
| if (skip) { | ||
| return; | ||
| } | ||
|
|
||
| super(); | ||
| } | ||
|
|
||
| HOOK_METHOD(Level, generate_home_dungeon, () -> void) { | ||
| bool skip = ProcessGenerateDungeonCallback(this, g_Game->_generationRNG, 3); | ||
| if (skip) { | ||
| return; | ||
| } | ||
|
|
||
| super(); | ||
| } | ||
|
|
||
| HOOK_METHOD(Level, generate_redkey_dungeon, () -> void) { | ||
| bool skip = ProcessGenerateDungeonCallback(this, g_Game->_generationRNG, 4); | ||
| if (skip) { | ||
| return; | ||
| } | ||
|
|
||
| super(); | ||
| } | ||
|
|
||
| HOOK_METHOD(Level, generate_greed_dungeon, () -> void) { | ||
| bool skip = ProcessGenerateDungeonCallback(this, g_Game->_generationRNG, 5); | ||
| if (skip) { | ||
| return; | ||
| } | ||
|
|
||
| super(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nitpick, change the name of the bool parameter to 'resetLilPortalRoom'