From 1c2a4d6f4d2d061da338d0f13d8bc46fa77a1f3d Mon Sep 17 00:00:00 2001
From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com>
Date: Fri, 17 May 2024 18:45:36 +0200
Subject: [PATCH] fix damage virtual in the api doc
---
docs/game_data/spel2.lua | 6 ++---
docs/src/includes/_enums.md | 2 +-
docs/src/includes/_types.md | 6 ++---
src/game_api/entity.cpp | 26 --------------------
src/game_api/movable.hpp | 19 +++++++++-----
src/game_api/script/usertypes/entity_lua.cpp | 7 +++---
6 files changed, 23 insertions(+), 43 deletions(-)
diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua
index 740da2263..f2c6d4910 100644
--- a/docs/game_data/spel2.lua
+++ b/docs/game_data/spel2.lua
@@ -2640,7 +2640,7 @@ function Entity:destroy_recursive() end
---@field standing_on fun(self): Entity
---@field collect_treasure fun(self, value: integer, treasure: ENT_TYPE): nil @Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. Adds treasure to the inventory list shown on transition. Use the global add_money to add money without adding specific treasure.
---@field is_on_fire fun(self): boolean
- ---@field damage fun(self, damage_dealer_uid: integer, damage_amount: integer, stun_time: integer, velocity_x: number, velocity_y: number, iframes: integer): boolean @Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+ ---@field damage fun(self, damage_dealer: Entity, damage_amount: integer, damage_flags: DAMAGE_TYPE, velocity: Vec2, unknown_damage_phase: integer, stun_amount: integer, iframes: integer, unknown_is_final: boolean): boolean @Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
---@field get_all_behaviors fun(self): integer[] @Get all avaible behavior ids
---@field set_behavior fun(self, behavior_id: integer): boolean @Set behavior, this is more than just state as it's an active function, for example climbing ladder is a behavior and it doesn't actually need ladder/rope entity
Returns false if entity doesn't have this behavior id
---@field get_behavior fun(self): integer @Get the current behavior id
@@ -2663,8 +2663,8 @@ function Entity:destroy_recursive() end
---@field set_post_stomp_damage fun(self, fun: fun(self: Movable): integer?): CallbackId @Hooks after the virtual function.
The callback signature is `nil stomp_damage(Movable self)`
---@field set_pre_is_on_fire fun(self, fun: fun(self: Movable): boolean?): CallbackId @Hooks before the virtual function.
The callback signature is `optional is_on_fire(Movable self)`
---@field set_post_is_on_fire fun(self, fun: fun(self: Movable): boolean?): CallbackId @Hooks after the virtual function.
The callback signature is `nil is_on_fire(Movable self)`
- ---@field set_pre_damage fun(self, fun: fun(self: Movable, damage_dealer_uid: integer, damage_amount: integer, stun_time: integer, velocity_x: number, velocity_y: number, iframes: integer): boolean?): CallbackId @Hooks before the virtual function.
The callback signature is `optional damage(Movable self, integer damage_dealer_uid, integer damage_amount, integer stun_time, number velocity_x, number velocity_y, integer iframes)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
- ---@field set_post_damage fun(self, fun: fun(self: Movable, damage_dealer_uid: integer, damage_amount: integer, stun_time: integer, velocity_x: number, velocity_y: number, iframes: integer): boolean?): CallbackId @Hooks after the virtual function.
The callback signature is `nil damage(Movable self, integer damage_dealer_uid, integer damage_amount, integer stun_time, number velocity_x, number velocity_y, integer iframes)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+ ---@field set_pre_damage fun(self, fun: fun(self: Movable, damage_dealer: Entity, damage_amount: integer, damage_flags: DAMAGE_TYPE, velocity: Vec2, unknown_damage_phase: integer, stun_amount: integer, iframes: integer, unknown_is_final: boolean): boolean?): CallbackId @Hooks before the virtual function.
The callback signature is `optional damage(Movable self, Entity damage_dealer, integer damage_amount, DAMAGE_TYPE damage_flags, Vec2 velocity, integer unknown_damage_phase, integer stun_amount, integer iframes, boolean unknown_is_final)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+ ---@field set_post_damage fun(self, fun: fun(self: Movable, damage_dealer: Entity, damage_amount: integer, damage_flags: DAMAGE_TYPE, velocity: Vec2, unknown_damage_phase: integer, stun_amount: integer, iframes: integer, unknown_is_final: boolean): boolean?): CallbackId @Hooks after the virtual function.
The callback signature is `nil damage(Movable self, Entity damage_dealer, integer damage_amount, DAMAGE_TYPE damage_flags, Vec2 velocity, integer unknown_damage_phase, integer stun_amount, integer iframes, boolean unknown_is_final)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
---@field set_pre_on_hit fun(self, fun: fun(self: Movable, damage_dealer: Entity): boolean): CallbackId @Hooks before the virtual function.
The callback signature is `bool on_hit(Movable self, Entity damage_dealer)`
Virtual function docs:
Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage.
---@field set_post_on_hit fun(self, fun: fun(self: Movable, damage_dealer: Entity): boolean): CallbackId @Hooks after the virtual function.
The callback signature is `nil on_hit(Movable self, Entity damage_dealer)`
Virtual function docs:
Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage.
---@field set_pre_stun fun(self, fun: fun(self: Movable, framecount: integer): boolean): CallbackId @Hooks before the virtual function.
The callback signature is `bool stun(Movable self, integer framecount)`
diff --git a/docs/src/includes/_enums.md b/docs/src/includes/_enums.md
index c2b7f0caf..274846aab 100644
--- a/docs/src/includes/_enums.md
+++ b/docs/src/includes/_enums.md
@@ -143,7 +143,7 @@ Name | Data | Description
> Search script examples for [DAMAGE_TYPE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=DAMAGE_TYPE)
-16bit bitmask used in [Movable](#Movable)::regular_damage. Can be many things, like 0x2024 = hit by a burning object that was thrown by an explosion.
+16bit bitmask used in [Movable](#Movable)::damage. Can be many things, like 0x2024 = hit by a burning object that was thrown by an explosion.
Name | Data | Description
---- | ---- | -----------
diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md
index 01bf3445b..1648da099 100644
--- a/docs/src/includes/_types.md
+++ b/docs/src/includes/_types.md
@@ -6852,7 +6852,7 @@ bool | [can_jump()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=can
[Entity](#Entity) | [standing_on()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=standing_on) |
nil | [collect_treasure(int value, ENT_TYPE treasure)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=collect_treasure) | Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. Adds treasure to the inventory list shown on transition. Use the global add_money to add money without adding specific treasure.
bool | [is_on_fire()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=is_on_fire) |
-bool | [damage(int damage_dealer_uid, int damage_amount, int stun_time, float velocity_x, float velocity_y, int iframes)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=damage) | Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+bool | [damage(Entity damage_dealer, int damage_amount, DAMAGE_TYPE damage_flags, Vec2 velocity, int unknown_damage_phase, int stun_amount, int iframes, bool unknown_is_final)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=damage) | Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
vector<int> | [get_all_behaviors()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_all_behaviors) | Get all avaible behavior ids
bool | [set_behavior(int behavior_id)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_behavior) | Set behavior, this is more than just state as it's an active function, for example climbing ladder is a behavior and it doesn't actually need ladder/rope entity
Returns false if entity doesn't have this behavior id
int | [get_behavior()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_behavior) | Get the current behavior id
@@ -6878,8 +6878,8 @@ nil | [clear_virtual(CallbackId callback_id)](https://github.com/spelunky-fyi/ov
[CallbackId](#Aliases) | [set_post_stomp_damage(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_stomp_damage) | Hooks after the virtual function.
The callback signature is `nil stomp_damage(Movable self)`
[CallbackId](#Aliases) | [set_pre_is_on_fire(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_is_on_fire) | Hooks before the virtual function.
The callback signature is `optional is_on_fire(Movable self)`
[CallbackId](#Aliases) | [set_post_is_on_fire(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_is_on_fire) | Hooks after the virtual function.
The callback signature is `nil is_on_fire(Movable self)`
-[CallbackId](#Aliases) | [set_pre_damage(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_damage) | Hooks before the virtual function.
The callback signature is `optional damage(Movable self, int damage_dealer_uid, int damage_amount, int stun_time, float velocity_x, float velocity_y, int iframes)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
-[CallbackId](#Aliases) | [set_post_damage(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_damage) | Hooks after the virtual function.
The callback signature is `nil damage(Movable self, int damage_dealer_uid, int damage_amount, int stun_time, float velocity_x, float velocity_y, int iframes)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+[CallbackId](#Aliases) | [set_pre_damage(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_damage) | Hooks before the virtual function.
The callback signature is `optional damage(Movable self, Entity damage_dealer, int damage_amount, DAMAGE_TYPE damage_flags, Vec2 velocity, int unknown_damage_phase, int stun_amount, int iframes, bool unknown_is_final)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+[CallbackId](#Aliases) | [set_post_damage(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_damage) | Hooks after the virtual function.
The callback signature is `nil damage(Movable self, Entity damage_dealer, int damage_amount, DAMAGE_TYPE damage_flags, Vec2 velocity, int unknown_damage_phase, int stun_amount, int iframes, bool unknown_is_final)`
Virtual function docs:
Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
[CallbackId](#Aliases) | [set_pre_on_hit(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_on_hit) | Hooks before the virtual function.
The callback signature is `bool on_hit(Movable self, Entity damage_dealer)`
Virtual function docs:
Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage.
[CallbackId](#Aliases) | [set_post_on_hit(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_on_hit) | Hooks after the virtual function.
The callback signature is `nil on_hit(Movable self, Entity damage_dealer)`
Virtual function docs:
Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage.
[CallbackId](#Aliases) | [set_pre_stun(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_stun) | Hooks before the virtual function.
The callback signature is `bool stun(Movable self, int framecount)`
diff --git a/src/game_api/entity.cpp b/src/game_api/entity.cpp
index 4d0f09f38..f08c2a0fd 100644
--- a/src/game_api/entity.cpp
+++ b/src/game_api/entity.cpp
@@ -214,32 +214,6 @@ bool Movable::is_poisoned()
return (poison_tick_timer != -1);
}
-bool Movable::broken_damage(uint32_t damage_dealer_uid, int8_t damage_amount, uint16_t stun_time, float velocity_x, float velocity_y)
-{
- return damage(damage_dealer_uid, damage_amount, stun_time, velocity_x, velocity_y, 80);
-}
-
-bool Movable::damage(uint32_t damage_dealer_uid, int8_t damage_amount, uint16_t stun_time, float velocity_x, float velocity_y, uint8_t iframes)
-{
- /* why?
- if ((flags & (1 << 28)) > 0)
- {
- return;
- }*/
-
- auto dealer = get_entity_ptr(damage_dealer_uid);
- /* but it can be nil?
- if (dealer == nullptr)
- {
- return;
- }*/
-
- Vec2 velocity{velocity_x, velocity_y};
- uint8_t unknown1{0};
- bool unknown2{true};
- return on_damage(dealer, damage_amount, 0x1, &velocity, unknown1, stun_time, iframes, unknown2);
-}
-
bool Movable::is_button_pressed(BUTTON button)
{
return (buttons & button) == button && (buttons_previous & button) == 0;
diff --git a/src/game_api/movable.hpp b/src/game_api/movable.hpp
index 8badf0250..cfb895890 100644
--- a/src/game_api/movable.hpp
+++ b/src/game_api/movable.hpp
@@ -92,11 +92,16 @@ class Movable : public Entity
void poison(int16_t frames); // 1 - 32767 frames ; -1 = no poison // Changes default poison_tick_timer
bool is_poisoned();
- /// Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
- /// Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
- bool damage(uint32_t damage_dealer_uid, int8_t damage_amount, uint16_t stun_time, float velocity_x, float velocity_y, uint8_t iframes);
- // the original damage function was added to the API without the iframes param, but for backwards compatibility we preserve the broken one
- bool broken_damage(uint32_t damage_dealer_uid, int8_t damage_amount, uint16_t stun_time, float velocity_x, float velocity_y);
+ /// NoDoc
+ bool broken_damage(uint32_t damage_dealer_uid, int8_t damage_amount, uint16_t stun_time, float velocity_x, float velocity_y, std::optional iframes)
+ {
+ auto dealer = get_entity_ptr(damage_dealer_uid);
+
+ Vec2 velocity{velocity_x, velocity_y};
+ uint8_t unknown1{0};
+ bool unknown2{true};
+ return damage(dealer, damage_amount, 0x1, &velocity, unknown1, stun_time, iframes.value_or(80), unknown2);
+ }
bool is_button_pressed(BUTTON button);
bool is_button_held(BUTTON button);
@@ -149,7 +154,9 @@ class Movable : public Entity
virtual void v46() = 0; // 46
virtual void v47() = 0; // 47
- virtual bool on_damage(Entity* damage_dealer, int8_t damage_amount, DAMAGE_TYPE damage_flags, Vec2* velocity, uint8_t unknown_damage_phase, uint16_t stun_amount, uint8_t iframes, bool unknown_is_final) = 0; // 48
+ /// Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities
+ /// Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
+ virtual bool damage(Entity* damage_dealer, int8_t damage_amount, DAMAGE_TYPE damage_flags, Vec2* velocity, uint8_t unknown_damage_phase, uint16_t stun_amount, uint8_t iframes, bool unknown_is_final) = 0; // 48
/// Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage.
virtual void on_hit(Entity* damage_dealer) = 0; // 49
diff --git a/src/game_api/script/usertypes/entity_lua.cpp b/src/game_api/script/usertypes/entity_lua.cpp
index 7e4e0ec5e..37fc69c61 100644
--- a/src/game_api/script/usertypes/entity_lua.cpp
+++ b/src/game_api/script/usertypes/entity_lua.cpp
@@ -293,9 +293,8 @@ void register_usertypes(sol::state& lua)
*/
auto damage = sol::overload(
- static_cast(&Movable::broken_damage),
- static_cast(&Movable::damage),
- &Movable::on_damage);
+ &Movable::broken_damage,
+ &Movable::damage);
auto light_on_fire = sol::overload(
static_cast(&Movable::light_on_fire_broken),
static_cast(&Movable::light_on_fire));
@@ -494,7 +493,7 @@ void register_usertypes(sol::state& lua)
// Value of 0, treated by all the functions as ANY mask
*/
- /// 16bit bitmask used in Movable::regular_damage. Can be many things, like 0x2024 = hit by a burning object that was thrown by an explosion.
+ /// 16bit bitmask used in Movable::damage. Can be many things, like 0x2024 = hit by a burning object that was thrown by an explosion.
lua.create_named_table(
"DAMAGE_TYPE",
"GENERIC",