From be56a7d5dc67183683929b016dd38b128fb52808 Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Wed, 1 Nov 2023 00:02:06 +0100 Subject: [PATCH] small random stuff --- docs/game_data/spel2.lua | 16 +++++++++------- docs/src/includes/_globals.md | 5 ++--- docs/src/includes/_types.md | 16 +++++++++------- src/game_api/color.hpp | 6 ++++++ src/game_api/entities_chars.hpp | 2 +- src/game_api/entity_lookup.cpp | 2 +- src/game_api/game_api.hpp | 6 +++--- src/game_api/illumination.hpp | 6 ++++++ src/game_api/script/usertypes/entity_lua.cpp | 1 + src/game_api/script/usertypes/state_lua.cpp | 4 +++- src/game_api/state.hpp | 18 ++++++++++-------- 11 files changed, 51 insertions(+), 31 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index b9ad798de..fae909481 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -1992,12 +1992,12 @@ do ---@field pools LiquidPool[] @size: 5 ---@class StateMemory - ---@field screen_last integer @Previous SCREEN, used to check where we're coming from when loading another SCREEN - ---@field screen integer @Current SCREEN, generally read-only or weird things will happen - ---@field screen_next integer @Next SCREEN, used to load the right screen when loading. Can be changed in PRE_LOAD_SCREEN to go somewhere else instead. Also see `state.loading`. + ---@field screen_last SCREEN @Previous SCREEN, used to check where we're coming from when loading another SCREEN + ---@field screen SCREEN @Current SCREEN, generally read-only or weird things will happen + ---@field screen_next SCREEN @Next SCREEN, used to load the right screen when loading. Can be changed in PRE_LOAD_SCREEN to go somewhere else instead. Also see `state.loading`. ---@field ingame integer @Is 1 when you in a game, is set to 0 or 1 in main menu, can't be trusted there, normally in a level is 1 unless you go to the options ---@field playing integer @Is 1 when you are in a level, but going to options sets it to 0 and does not set it back to 1 after the way back, don't trust it - ---@field pause PAUSE @8bit flags, multiple might be active at the same time
1: Menu: Pauses the level timer and engine. Can't set, controller by the menu.
2: Fade/Loading: Pauses all timers and engine.
4: Cutscene: Pauses total/level time but not engine. Used by boss cutscenes.
8: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
16: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
32: Ankh: Pauses all timers, engine, but not camera. Used by the ankh cutscene. + ---@field pause PAUSE @8bit flags, multiple might be active at the same time
1: Menu: Pauses the level timer and engine. Can't set, controlled by the menu.
2: Fade/Loading: Pauses all timers and engine.
4: Cutscene: Pauses total/level time but not engine. Used by boss cutscenes.
8: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
16: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
32: Ankh: Pauses all timers, engine, but not camera. Used by the ankh cutscene. ---@field width integer @level width in rooms (number of rooms horizontally) ---@field height integer @level height in rooms (number of rooms vertically) ---@field kali_favor integer @@ -2014,7 +2014,7 @@ do ---@field level_start integer @Level number to start new runs in ---@field theme THEME @Current THEME number, used to pick the music and by some game logic like choosing the next level on transition ---@field theme_next THEME @Next THEME number, used when loading a new level or transition - ---@field theme_start integer @THEME to start new runs in + ---@field theme_start THEME @THEME to start new runs in ---@field current_theme ThemeInfo @Points to the current ThemeInfo ---@field force_current_theme fun(self, t: integer): nil @This function should only be used in a very specific circumstance (forcing the exiting theme when manually transitioning). Will crash the game if used inappropriately! ---@field shoppie_aggro integer @Current shoppie aggro @@ -2041,7 +2041,7 @@ do ---@field win_state integer @0 = no win 1 = tiamat win 2 = hundun win 3 = CO win; set this and next doorway leads to victory scene ---@field illumination Illumination @The global level illumination, very big and bright. ---@field money_last_levels integer - ---@field money_shop_total integer @Total negative amount spent in shops during the run

The total money currently available (in single player) is `players[1].inventory.money + players[1].inventory.collected_money_total + state.money_shop_total` + ---@field money_shop_total integer @Total amount spent in shops and sold idols during the run

The total money currently available is `loop (players[].inventory.money + players[].inventory.collected_money_total) + state.money_shop_total` ---@field player_inputs PlayerInputs @Access the player inputs even when no player entities are available ---@field quests QuestsInfo @NPC quest states ---@field camera Camera @Camera bounds and position @@ -2096,7 +2096,7 @@ do ---@field journal_progress_stain_count integer ---@field journal_progress_stain_slots JournalProgressStainSlot[] @size: 30 @blood splats and paw prints in journal progress page ---@field journal_progress_theme_count integer - ---@field journal_progress_theme_slots integer[] @size: 9 @visited themes in journal progress page + ---@field journal_progress_theme_slots THEME[] @size: 9 @visited themes in journal progress page ---@field theme_info ThemeInfo @Points to the current ThemeInfo ---@field logic LogicList @Level logic like dice game and cutscenes ---@field liquid LiquidPhysics @@ -2108,6 +2108,7 @@ do ---@field green number ---@field blue number ---@field size number + ---@field as_color fun(self): Color @Returns LightParams as Color, note that size = alpha ---@class Illumination ---@field lights LightParams[] @size: 4 @Table of light1, light2, ... etc. @@ -2266,6 +2267,7 @@ function PRNG:random(min, max) end ---@field set_rgba fun(self, red: integer, green: integer, blue: integer, alpha: integer): Color @Changes color based on given RGBA colors in 0..255 range ---@field get_ucolor fun(self): uColor @Returns the `uColor` used in `GuiDrawContext` drawing functions ---@field set_ucolor fun(self, color: uColor): Color @Changes color based on given uColor + ---@field set fun(self, other: Color): Color @Copies the values of different Color to this one ---@class Animation ---@field id integer diff --git a/docs/src/includes/_globals.md b/docs/src/includes/_globals.md index 2dec314e2..85141bcde 100644 --- a/docs/src/includes/_globals.md +++ b/docs/src/includes/_globals.md @@ -1735,8 +1735,7 @@ function change_layer(layer_to, load_time) state.layer_transition_timer = load_time state.transition_to_layer = layer_to - -- actual layer change after time delay - set_timeout(function() state.camera_layer = layer_to end, load_time) + state.camera_layer = layer_to end ``` @@ -3676,7 +3675,7 @@ Use `get_entities_overlapping_hitbox` instead #### int get_entity_ai_state(int uid) -As the name is misleading. use entity `move_state` field instead +As the name is misleading. use [Movable](#Movable).`move_state` field instead ### set_arrowtrap_projectile diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index 59dd3306c..f33db0fe8 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -640,6 +640,7 @@ tuple<int, int, int, int> | [get_rgba()](https://github.com/spelunky-fyi/o [Color](#Color) | [set_rgba(int red, int green, int blue, int alpha)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_rgba) | Changes color based on given RGBA colors in 0..255 range [uColor](#Aliases) | [get_ucolor()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_ucolor) | Returns the `uColor` used in `GuiDrawContext` drawing functions [Color](#Color) | [set_ucolor(uColor color)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_ucolor) | Changes color based on given [uColor](#Aliases) +[Color](#Color) | [set(Color other)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set) | Copies the values of different [Color](#Color) to this one ### CutsceneBehavior @@ -1303,6 +1304,7 @@ float | [red](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=red) | float | [green](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=green) | float | [blue](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=blue) | float | [size](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=size) | +[Color](#Color) | [as_color()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=as_color) | Returns [LightParams](#LightParams) as [Color](#Color), note that size = alpha ## Liquid types @@ -2819,12 +2821,12 @@ Can be accessed via global [state](#state) Type | Name | Description ---- | ---- | ----------- -int | [screen_last](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_last) | Previous [SCREEN](#SCREEN), used to check where we're coming from when loading another [SCREEN](#SCREEN) -int | [screen](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen) | Current [SCREEN](#SCREEN), generally read-only or weird things will happen -int | [screen_next](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_next) | Next [SCREEN](#SCREEN), used to load the right screen when loading. Can be changed in PRE_LOAD_SCREEN to go somewhere else instead. Also see `state.loading`. +[SCREEN](#SCREEN) | [screen_last](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_last) | Previous [SCREEN](#SCREEN), used to check where we're coming from when loading another [SCREEN](#SCREEN) +[SCREEN](#SCREEN) | [screen](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen) | Current [SCREEN](#SCREEN), generally read-only or weird things will happen +[SCREEN](#SCREEN) | [screen_next](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_next) | Next [SCREEN](#SCREEN), used to load the right screen when loading. Can be changed in PRE_LOAD_SCREEN to go somewhere else instead. Also see `state.loading`. int | [ingame](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ingame) | Is 1 when you in a game, is set to 0 or 1 in main menu, can't be trusted there, normally in a level is 1 unless you go to the options int | [playing](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=playing) | Is 1 when you are in a level, but going to options sets it to 0 and does not set it back to 1 after the way back, don't trust it -[PAUSE](#PAUSE) | [pause](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=pause) | 8bit flags, multiple might be active at the same time
1: Menu: Pauses the level timer and engine. Can't set, controller by the menu.
2: Fade/Loading: Pauses all timers and engine.
4: Cutscene: Pauses total/level time but not engine. Used by boss cutscenes.
8: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
16: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
32: Ankh: Pauses all timers, engine, but not camera. Used by the ankh cutscene. +[PAUSE](#PAUSE) | [pause](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=pause) | 8bit flags, multiple might be active at the same time
1: Menu: Pauses the level timer and engine. Can't set, controlled by the menu.
2: Fade/Loading: Pauses all timers and engine.
4: Cutscene: Pauses total/level time but not engine. Used by boss cutscenes.
8: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
16: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs.
32: Ankh: Pauses all timers, engine, but not camera. Used by the ankh cutscene. int | [width](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=width) | level width in rooms (number of rooms horizontally) int | [height](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=height) | level height in rooms (number of rooms vertically) int | [kali_favor](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=kali_favor) | @@ -2841,7 +2843,7 @@ int | [level_next](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=leve int | [level_start](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=level_start) | Level number to start new runs in [THEME](#THEME) | [theme](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme) | Current [THEME](#THEME) number, used to pick the music and by some game logic like choosing the next level on transition [THEME](#THEME) | [theme_next](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme_next) | Next [THEME](#THEME) number, used when loading a new level or transition -int | [theme_start](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme_start) | [THEME](#THEME) to start new runs in +[THEME](#THEME) | [theme_start](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme_start) | [THEME](#THEME) to start new runs in [ThemeInfo](#ThemeInfo) | [current_theme](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=current_theme) | Points to the current [ThemeInfo](#ThemeInfo) nil | [force_current_theme(int t)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=force_current_theme) | This function should only be used in a very specific circumstance (forcing the exiting theme when manually transitioning). Will crash the game if used inappropriately! int | [shoppie_aggro](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=shoppie_aggro) | Current shoppie aggro @@ -2868,7 +2870,7 @@ int | [saved_hamsters](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q= int | [win_state](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=win_state) | 0 = no win 1 = tiamat win 2 = hundun win 3 = CO win; set this and next doorway leads to victory scene [Illumination](#Illumination) | [illumination](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=illumination) | The global level illumination, very big and bright. int | [money_last_levels](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_last_levels) | -int | [money_shop_total](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_shop_total) | Total negative amount spent in shops during the run

The total money currently available (in single player) is `players[1].inventory.money + players[1].inventory.collected_money_total + state.money_shop_total` +int | [money_shop_total](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=money_shop_total) | Total amount spent in shops and sold idols during the run

The total money currently available is `loop (players[].inventory.money + players[].inventory.collected_money_total) + state.money_shop_total` [PlayerInputs](#PlayerInputs) | [player_inputs](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_inputs) | Access the player inputs even when no player entities are available [QuestsInfo](#QuestsInfo) | [quests](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=quests) | [NPC](#NPC) quest states [Camera](#Camera) | [camera](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=camera) | [Camera](#Camera) bounds and position @@ -2923,7 +2925,7 @@ array<[JournalProgressStickerSlot](#JournalProgressStickerSlot), 40> | [jo int | [journal_progress_stain_count](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=journal_progress_stain_count) | array<[JournalProgressStainSlot](#JournalProgressStainSlot), 30> | [journal_progress_stain_slots](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=journal_progress_stain_slots) | blood splats and paw prints in journal progress page int | [journal_progress_theme_count](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=journal_progress_theme_count) | -array<int, 9> | [journal_progress_theme_slots](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=journal_progress_theme_slots) | visited themes in journal progress page +array<[THEME](#THEME), 9> | [journal_progress_theme_slots](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=journal_progress_theme_slots) | visited themes in journal progress page [ThemeInfo](#ThemeInfo) | [theme_info](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme_info) | Points to the current [ThemeInfo](#ThemeInfo) [LogicList](#LogicList) | [logic](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=logic) | Level logic like dice game and cutscenes [LiquidPhysics](#LiquidPhysics) | [liquid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=liquid) | diff --git a/src/game_api/color.hpp b/src/game_api/color.hpp index 5cb196d83..20df107c8 100644 --- a/src/game_api/color.hpp +++ b/src/game_api/color.hpp @@ -153,6 +153,12 @@ struct Color uint8_t alpha = (color >> 24U) & 0xFF; return set_rgba(red, green, blue, alpha); } + /// Copies the values of different Color to this one + Color& set(Color other) + { + *this = other; + return *this; + } float r{0.0f}; float g{0.0f}; diff --git a/src/game_api/entities_chars.hpp b/src/game_api/entities_chars.hpp index d84c752e6..863161149 100644 --- a/src/game_api/entities_chars.hpp +++ b/src/game_api/entities_chars.hpp @@ -8,7 +8,6 @@ #include // for vector #include "aliases.hpp" // for ENT_TYPE -#include "color.hpp" // for Color #include "containers/custom_map.hpp" // #include "movable.hpp" // for Movable @@ -16,6 +15,7 @@ struct Illumination; struct PlayerInputs; struct Inventory; struct PlayerSlot; +struct Color; class Entity; class Ai diff --git a/src/game_api/entity_lookup.cpp b/src/game_api/entity_lookup.cpp index e27088238..3e9b609fb 100644 --- a/src/game_api/entity_lookup.cpp +++ b/src/game_api/entity_lookup.cpp @@ -178,7 +178,7 @@ std::vector get_entities_at(std::vector entity_types, uint32 for (auto& item : entities.entities()) { auto [ix, iy] = item->position(); - float distance = std::sqrt(std::pow(x - ix, 2.0f) + std::pow(y - iy, 2.0f)); + float distance = (float)std::sqrt(std::pow(x - ix, 2) + std::pow(y - iy, 2)); if (distance < radius && entity_type_check(proper_types, item->type->id)) { found.push_back(item->uid); diff --git a/src/game_api/game_api.hpp b/src/game_api/game_api.hpp index 221c479ef..552b6bfdc 100644 --- a/src/game_api/game_api.hpp +++ b/src/game_api/game_api.hpp @@ -6,13 +6,13 @@ struct Renderer { - uint32_t render_width; // sam as window size unless resolution scale is set + uint32_t render_width; // same as window size unless resolution scale is set uint32_t render_height; uint32_t fps; // changing it doesn't seam to do anything uint32_t fps_denominator; - uint32_t render_width2; // repeat + uint32_t render_width2; // repeat? uint32_t render_height2; uint8_t flags1; @@ -36,7 +36,7 @@ struct Renderer size_t swap_chain; - // somewhere there should be shareds stored + // somewhere there should be shaders stored // added just to have the vtable virtual ~Renderer() = 0; diff --git a/src/game_api/illumination.hpp b/src/game_api/illumination.hpp index c03b0b62f..7376ce473 100644 --- a/src/game_api/illumination.hpp +++ b/src/game_api/illumination.hpp @@ -22,6 +22,12 @@ struct LightParams // it's probably just Color float green; float blue; float size; + + /// Returns LightParams as Color, note that size = alpha + Color* as_color() + { + return reinterpret_cast(this); + }; }; struct Illumination diff --git a/src/game_api/script/usertypes/entity_lua.cpp b/src/game_api/script/usertypes/entity_lua.cpp index a8aaec46e..5c492c951 100644 --- a/src/game_api/script/usertypes/entity_lua.cpp +++ b/src/game_api/script/usertypes/entity_lua.cpp @@ -53,6 +53,7 @@ void register_usertypes(sol::state& lua) color_type["set_rgba"] = &Color::set_rgba; color_type["get_ucolor"] = &Color::get_ucolor; color_type["set_ucolor"] = &Color::set_ucolor; + color_type["set"] = &Color::set; /// Used in EntityDB lua.new_usertype( diff --git a/src/game_api/script/usertypes/state_lua.cpp b/src/game_api/script/usertypes/state_lua.cpp index b95ca54ad..d0872d672 100644 --- a/src/game_api/script/usertypes/state_lua.cpp +++ b/src/game_api/script/usertypes/state_lua.cpp @@ -412,7 +412,9 @@ void register_usertypes(sol::state& lua) "blue", &LightParams::blue, "size", - &LightParams::size); + &LightParams::size, + "as_color", + &LightParams::as_color); /// Generic obcject for lights in the game, you can make your own with [create_illumination](#create_illumination)
/// Used in StateMemory, Player, PlayerGhost, BurningRopeEffect ... diff --git a/src/game_api/state.hpp b/src/game_api/state.hpp index 7cf1b152c..2f694a1de 100644 --- a/src/game_api/state.hpp +++ b/src/game_api/state.hpp @@ -51,13 +51,15 @@ void fix_liquid_out_of_bounds(); #pragma pack(push, 1) // disable struct padding struct StateMemory { + using SCREEN = uint32_t; + size_t p00; /// Previous SCREEN, used to check where we're coming from when loading another SCREEN - uint32_t screen_last; + SCREEN screen_last; /// Current SCREEN, generally read-only or weird things will happen - uint32_t screen; + SCREEN screen; /// Next SCREEN, used to load the right screen when loading. Can be changed in PRE_LOAD_SCREEN to go somewhere else instead. Also see `state.loading`. - uint32_t screen_next; + SCREEN screen_next; /// Shows the current loading state (0=Not loading, 1=Fadeout, 2=Loading, 3=Fadein). Writing 1 or 2 will trigger a screen load to `screen_next`. uint32_t loading; /// The global level illumination, very big and bright. @@ -75,7 +77,7 @@ struct StateMemory /// Is 1 when you are in a level, but going to options sets it to 0 and does not set it back to 1 after the way back, don't trust it uint8_t playing; /// 8bit flags, multiple might be active at the same time - /// 1: Menu: Pauses the level timer and engine. Can't set, controller by the menu. + /// 1: Menu: Pauses the level timer and engine. Can't set, controlled by the menu. /// 2: Fade/Loading: Pauses all timers and engine. /// 4: Cutscene: Pauses total/level time but not engine. Used by boss cutscenes. /// 8: Unknown: Pauses total/level time and engine. Does not pause the global counter so set_global_interval still runs. @@ -106,15 +108,15 @@ struct StateMemory /// 0 - none, 1 - item, 3 - kapala int8_t kali_gifts; int32_t outposts_spawned; - /// Total negative amount spent in shops during the run
- /// The total money currently available (in single player) is `players[1].inventory.money + players[1].inventory.collected_money_total + state.money_shop_total` + /// Total amount spent in shops and sold idols during the run
+ /// The total money currently available is `loop (players[].inventory.money + players[].inventory.collected_money_total) + state.money_shop_total` int32_t money_shop_total; /// World number to start new runs in uint8_t world_start; /// Level number to start new runs in uint8_t level_start; /// THEME to start new runs in - uint8_t theme_start; + THEME theme_start; uint8_t b5f; /// Current seed in seeded mode, just set to a funny value and does nothing in adventure mode uint32_t seed; @@ -172,7 +174,7 @@ struct StateMemory std::array journal_progress_stain_slots; uint8_t journal_progress_theme_count; /// visited themes in journal progress page - std::array journal_progress_theme_slots; + std::array journal_progress_theme_slots; uint8_t unknown3; uint8_t unknown4; uint8_t unknown5a;