Skip to content

Commit

Permalink
Merge pull request #383 from Mr-Auto/damage-fix
Browse files Browse the repository at this point in the history
Fix damage virtual in the api doc
  • Loading branch information
Dregu authored Jul 11, 2024
2 parents 04388ab + 477e6b9 commit 2cebb57
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 40 deletions.
6 changes: 3 additions & 3 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/src/includes/_enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---- | ---- | -----------
Expand Down
6 changes: 3 additions & 3 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6872,7 +6872,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<br/>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. `damage_dealer` can be set to nil.<br/>Returns: true if entity was affected, damage_dealer should break etc. false if the event should be ignored by damage_dealer?
vector&lt;int&gt; | [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<br/>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
Expand All @@ -6898,8 +6898,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.<br/>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.<br/>The callback signature is `optional<bool> 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.<br/>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.<br/>The callback signature is `optional<bool> damage(Movable self, int damage_dealer_uid, int damage_amount, int stun_time, float velocity_x, float velocity_y, int iframes)`<br/>Virtual function docs:<br/>Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities<br/>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.<br/>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)`<br/>Virtual function docs:<br/>Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities<br/>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.<br/>The callback signature is `optional<bool> 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)`<br/>Virtual function docs:<br/>Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities. `damage_dealer` can be set to nil.<br/>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.<br/>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)`<br/>Virtual function docs:<br/>Damage the movable by the specified amount, stuns and gives it invincibility for the specified amount of frames and applies the velocities. `damage_dealer` can be set to nil.<br/>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.<br/>The callback signature is `bool on_hit(Movable self, Entity damage_dealer)`<br/>Virtual function docs:<br/>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.<br/>The callback signature is `nil on_hit(Movable self, Entity damage_dealer)`<br/>Virtual function docs:<br/>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.<br/>The callback signature is `bool stun(Movable self, int framecount)`
Expand Down
21 changes: 0 additions & 21 deletions src/game_api/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,6 @@ void Movable::poison(int16_t frames)
write_mem_prot(offset_subsequent, frames, true);
}

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);
}

std::tuple<float, float, uint8_t> get_position(uint32_t uid)
{
Entity* ent = get_entity_ptr(uid);
Expand Down
1 change: 1 addition & 0 deletions src/game_api/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Entity;
inline constexpr uint32_t g_level_max_x = 0x56;
inline constexpr uint32_t g_level_max_y = 0x7e;

// Is always ordered by the uid
struct EntityList
{
Entity** ent_list;
Expand Down
19 changes: 11 additions & 8 deletions src/game_api/movable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ class Movable : public Entity
return (poison_tick_timer != -1);
}

/// 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<uint8_t> iframes)
{
return damage(damage_dealer_uid, damage_amount, stun_time, velocity_x, velocity_y, 80);
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) const
Expand All @@ -116,7 +118,6 @@ class Movable : public Entity
{
return (buttons & button) == 0 && (buttons_previous & button) == button;
}

void set_pre_statemachine(std::uint32_t reserved_callback_id, std::function<bool(Movable*)> pre_state_machine);
void set_post_statemachine(std::uint32_t reserved_callback_id, std::function<void(Movable*)> post_state_machine);

Expand Down Expand Up @@ -170,7 +171,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. `damage_dealer` can be set to nil.
/// 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
Expand Down
7 changes: 3 additions & 4 deletions src/game_api/script/usertypes/entity_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ void register_usertypes(sol::state& lua)
*/

auto damage = sol::overload(
static_cast<bool (Movable::*)(uint32_t, int8_t, uint16_t, float, float)>(&Movable::broken_damage),
static_cast<bool (Movable::*)(uint32_t, int8_t, uint16_t, float, float, uint8_t)>(&Movable::damage),
&Movable::on_damage);
&Movable::broken_damage,
&Movable::damage);
auto light_on_fire = sol::overload(
static_cast<void (Movable::*)()>(&Movable::light_on_fire_broken),
static_cast<void (Movable::*)(uint8_t)>(&Movable::light_on_fire));
Expand Down Expand Up @@ -495,7 +494,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",
Expand Down

0 comments on commit 2cebb57

Please sign in to comment.