#pragma once #include "anm2.h" #include "classes.h" #include "entity.h" #include "sfx_manager.h" #include // The grid entity types (Lua's GridEntityType). The last, which Lua leaves unnamed, makes spikes. enum GridEntityType : int { GRID_NULL, GRID_DECORATION, GRID_ROCK, GRID_ROCKB, GRID_ROCKT, GRID_ROCK_BOMB, GRID_ROCK_ALT, GRID_PIT, GRID_SPIKES, GRID_SPIKES_ONOFF, GRID_SPIDERWEB, GRID_LOCK, GRID_TNT, GRID_FIREPLACE, GRID_POOP, GRID_WALL, GRID_DOOR, GRID_TRAPDOOR, GRID_STAIRS, GRID_GRAVITY, GRID_PRESSURE_PLATE, GRID_STATUE, GRID_ROCK_SS, GRID_TELEPORTER, GRID_PILLAR, GRID_ROCK_SPIKED, GRID_ROCK_ALT2, GRID_ROCK_GOLD, GRID_SPIKES_ALT }; // What a grid entity blocks (Lua's GridCollisionClass). enum GridCollision : int { COLLISION_NONE, COLLISION_PIT, COLLISION_OBJECT, COLLISION_SOLID, COLLISION_WALL, COLLISION_WALL_EXCEPT_PLAYER }; // The room's grid path a grid entity claims for its cell: freed when it breaks, solid while it stands. constexpr int GRID_PATH_FREED = 900; constexpr int GRID_PATH_SOLID = 1000; // The seeds and RNG a grid entity holds before Init seeds it. constexpr uint32_t GRID_SEED_DEFAULT = 0x16a9de81; constexpr RNG GRID_RNG_DEFAULT = {0xaa17414f, 5, 9, 7}; // How water clips around a grid entity (REPENTOGON's WaterClipInfo): which sides, and how far. struct WaterClipInfo { uint32_t flags = 0; float value = 0; }; // The water clips the grid entities use. constexpr uint32_t WATER_CLIP_SOLID = 0x39; constexpr uint32_t WATER_CLIP_FLAT = 0x26; constexpr uint32_t WATER_CLIP_RAISED = 0x19; // What hurt_func and hurt_surroundings deal to the entities near a grid entity. struct GridHurt { uint64_t damageFlags = 0; float damage = 0; float distance = 0; float playerDistance = 0; int playerDamage = 0; bool isIgnoreGridCollisionClass = false; }; // Construction, destruction and the deleting destructors (00709c40, 00709cb0, 00709d40) are the defaults. The field // accessors (004073c0, 00428930, 0043eec0, 004e4830, 0067efc0, 00709c00, 00738140, 0085dda0) are the public fields. // Lua's Hurt, Destroy, PostInit and Update (0085ddb0, 0085de20, 008c5cd9, 008c5ce8, 008c5cfc) are the virtual calls, // with a default EntityRef for the source. An obstacle on one cell of the room's grid (Lua's GridEntity): rocks, pits, // poop, spikes, doors, walls and the rest. Its type, variant, state and seeds are the GridEntityDesc a room saves for // the cell. struct GridEntity { ANM2 sprite; RNG rng = GRID_RNG_DEFAULT; GridEntityType type = GRID_NULL; GridCollision collisionClass = COLLISION_NONE; int gridIndex = 0; int spawnCount = 0; int spawnFrame = 0; int state = 0; int varData = 0; int variant = 0; uint32_t spawnSeed = GRID_SEED_DEFAULT; uint32_t variableSeed = GRID_SEED_DEFAULT; bool isInitialized = false; virtual ~GridEntity() = default; virtual void PostInit() {} virtual void Update() = 0; virtual void Render(const Vector& offset); virtual bool Hurt(int damage, const EntityRef& source); virtual bool Destroy(bool isImmediate, const EntityRef& source); virtual WaterClipInfo GetWaterClipInfo(); virtual bool CanTakeDamageFromTearEffects(); // Slot 8, which the decompile calls BeginBatches: what a type sets up before its first update. virtual void subclass_init() = 0; void Init(uint32_t seed); GridEntityDesc desc_save(); void desc_load(const GridEntityDesc& desc); Vector Position(); Vector get_render_position(); void sprite_render(const Vector& offset); void path_set(int value); bool IsBreakableRock(); bool IsEasyCrushableOrWalkable(); bool IsDangerousCrushableOrWalkable(); void hurt_func(Entity& entity, const GridHurt& hurt); void hurt_surroundings(const GridHurt& hurt); void trigger_output(); }; GridEntity* CreateGridEntity(GridEntityType type, int gridIndex); void grid_sound_play(int sound, SoundPlay play = {});