Skip to content

Commit

Permalink
rename pickup to give_powerup and expose it, fix comments for vta…
Browse files Browse the repository at this point in the history
…ble function that have different name for hook vs function itself, some comments here and there
  • Loading branch information
Mr-Auto committed Dec 8, 2024
1 parent 79dcb16 commit 380de08
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 56 deletions.
50 changes: 28 additions & 22 deletions docs/game_data/spel2.lua

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ def run_parse():
for item in classes:
if item["name"] != func_ref.group(1):
continue
# TODO: pretty sure if the actual virtual function name is different then the one in VTableEntry there won't be comment in callback signature
func_name = func_ref.group(2)
# if it throws error at `item["member_funs"][func_name]` then the virtual defined using MemFun was not found in the parsed class/struct code
if (
Expand All @@ -645,8 +644,8 @@ def run_parse():
"index": index,
"ret": func["return"],
"args": [t for t in func["param"].split(",")],
# "ref": func_name.group(2),
"binds": binds,
"ref": func_name,
}
else:
signature = re.search(r"([_a-zA-Z][\w]*.*)\((.*)\)", signature)
Expand Down Expand Up @@ -920,11 +919,12 @@ def run_parse():
for entry in vtable["entries"].values():
entry_name = entry["name"]

func_name = entry["ref"] if "ref" in entry else entry["name"]
pre_signature = None
post_signature = None
cpp_comment = []
if entry_name in underlying_cpp_type["member_funs"]:
for fun in underlying_cpp_type["member_funs"][entry_name]:
if func_name in underlying_cpp_type["member_funs"]:
for fun in underlying_cpp_type["member_funs"][func_name]:
ret = replace_fun(fun["return"])
ret = f"optional<{ret}>" if ret else "bool"
ret = ret if entry_name != "dtor" else "nil"
Expand Down
1 change: 1 addition & 0 deletions docs/src/includes/_enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ Name | Data | Description
[ACQUIRE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.ACQUIRE) | 93 |
[TRIGGER_EXPLOSION](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.TRIGGER_EXPLOSION) | 94 |
[SPAWN_PROJECTILE](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.SPAWN_PROJECTILE) | 93 |
[GIVE_POWERUP](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ENTITY_OVERRIDE.GIVE_POWERUP) | 93 |

## ENT_FLAG

Expand Down
52 changes: 29 additions & 23 deletions docs/src/includes/_types.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/game_api/entities_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PowerupCapable : public Movable
/// Returns the uid of the currently worn backitem, or -1 if wearing nothing
int32_t worn_backitem();

/// only triggers when it has kapala
/// only triggers when entity has kapala
virtual bool on_blood_collision() = 0;
// called for stunned entities, check bunch of stuff like state, hold entity, standing on entity etc. runs until returned 1
// this is used to clear the last_owner of stunned entity when it is no longed stunned
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/entities_items.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ class RollingItem : public Purchasable
float roll_speed; // only positive numbers

/// Skip this function for item to be unpickable
virtual void pickup(Entity* who, bool) = 0;
virtual void give_powerup(Entity* who, bool) = 0;
};

class PlayerBag : public Movable
Expand Down
10 changes: 6 additions & 4 deletions src/game_api/movable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Movable : public Entity
virtual bool thrown_into(Entity* victim) = 0; // 47

/// 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 (for stuff like pot that should break after hit etc.), false if the event should be ignored by damage_dealer
/// Returns: true if entity was affected (for stuff like: if pot was thrown into entity, should that pot break after hit), 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 damage with 0 damage.
Expand Down Expand Up @@ -200,9 +200,11 @@ class Movable : public Entity
virtual void v77() = 0; // 77
virtual void process_input() = 0; // 78, more like: handle_movement
virtual void post_collision_damage_related() = 0; // 79, used for enemies attacks as well? 3 versions for: eggplant minister, players and the rest
virtual void on_picked_up() = 0; // 80, plays pickup sound depending on the entity mask/type etc. set stun for pets and mounts etc.
virtual void on_release() = 0; // 81, only for hired hands and lava pots
virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing
/// Called for entity that just has been picked up
virtual void on_picked_up() = 0; // 80, plays pickup sound depending on the entity mask/type etc. set stun for pets and mounts etc.
/// Called for entity that just has been thrown/dropped
virtual void on_release() = 0; // 81, only for hired hands and lava pots, the rest just returns
virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing
/// Applies gravity to entity. Disable to float like on hoverpack.
virtual void handle_fall_logic(float) = 0; // 83, adjusts entity.velocityy when falling
virtual void apply_friction(float, bool vertical, float) = 0; // 84, applies entity.type.friction to entity.velocityx, the two floats for characters just multiply the friction, could also be returning the value
Expand Down
2 changes: 2 additions & 0 deletions src/game_api/script/usertypes/entities_items_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ void register_usertypes(sol::state& lua)
"RollingItem",
"roll_speed",
&RollingItem::roll_speed,
"give_powerup",
&RollingItem::give_powerup,
sol::base_classes,
sol::bases<Entity, Movable, Purchasable>());

Expand Down
8 changes: 7 additions & 1 deletion src/game_api/script/usertypes/vtables_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,17 @@ void register_usertypes(sol::state& lua)
VTableEntry<"spawn_projectile", 93, MemFun<&OlmecCannon::spawn_projectile>>>;
static OlmecCannonVTable olmec_cannon_vtable(lua, lua["OlmecCannon"], "ENTITY_OVERRIDE");

using RollingItemVTable = HookableVTable<
Entity,
CallbackType::Entity,
EntityVTable,
VTableEntry<"give_powerup", 93, MemFun<&RollingItem::give_powerup>>>;
static RollingItemVTable rolling_item_vtable(lua, lua["RollingItem"], "ENTITY_OVERRIDE");

// Arrow // poison_arrow // light_up ?
// Torch // light_up // get_flame_offset // get_flame_type
// Bow // get_arrow_special_offset
// Generator // randomize_timer ?
// RollingItem // pickup
// SoundMeta // start // kill //update maybe?
// CritterSlime + CritterSnail // get_speed
// Ghist // on_body_destroyed
Expand Down

0 comments on commit 380de08

Please sign in to comment.