#include "entity.h"
#include "object.h"

void (*const gObjectFunctions[])(Entity*) = {
    [GROUND_ITEM] = ItemOnGround,
    [DEATH_FX] = DeathFx,
    [SHOP_ITEM] = ItemForSale,
    [BUTTON] = Button,
    [MINISH_EMOTICON] = MinishEmoticon,
    [POT] = Pot,
    [EZLO_CAP] = EzloCap,
    [PUSHED_BLOCK] = BlockPushed,
    [LOCKED_DOOR] = LockedDoor,
    [OBJECT_9] = Object9,
    [OBJECT_A] = ObjectA,
    [OBJECT_B] = ObjectB,
    [CHEST_SPAWNER] = ChestSpawner,
    [OBJECT_D] = ObjectD,
    [OBJECT_E] = ObjectE,
    [SPECIAL_FX] = SpecialFx,
    [PLAYER_CLONE] = PlayerClone,
    [OBJECT_11] = Object11,
    [OBJECT_12] = Object12,
    [RAILTRACK] = Railtrack,
    [LILYPAD_LARGE] = LilypadLarge,
    [OBJECT_15] = Object15,
    [FLOATING_PLATFORM] = FloatingPlatform,
    [OBJECT_17] = Object17,
    [EVIL_SPIRIT] = EvilSpirit,
    [HOUSE_DOOR_EXT] = HouseDoorExterior,
    [RUPEE_OBJECT] = Rupee,
    [GREAT_FAIRY] = GreatFairy,
    [OBJECT_1C] = Object1C,
    [OBJECT_1D] = Object1D,
    [OBJECT_1E] = Object1E,
    [OBJECT_1F] = Object1F,
    [OBJECT_20] = Object20,
    [OBJECT_21] = Object21,
    [FIGURINE_DEVICE] = FigurineDevice,
    [EYE_SWITCH] = EyeSwitch,
    [PRESSURE_PLATE] = PressurePlate,
    [BIG_BARREL] = BigBarrel,
    [BARREL_INSIDE] = BarrelInside,
    [PUSHABLE_STATUE] = PushableStatue,
    [OBJECT_28] = Object28,
    [AMBIENT_CLOUDS] = AmbientClouds,
    [OBJECT_2A] = Object2A,
    [OBJECT_2B] = Object2B,
    [BEANSTALK] = Beanstalk,
    [SMOKE] = Smoke,
    [PUSHABLE_ROCK] = PushableRock,
    [HITTABLE_LEVER] = HittableLever,
    [OBJECT_30] = Object30,
    [FROZEN_FLOWER] = FrozenFlower,
    [PULLABLE_MUSHROOM] = PullableMushroom,
    [BOLLARD] = Bollard,
    [WARP_POINT] = WarpPoint,
    [OBJECT_35] = Object35,
    [OBJECT_36] = Object36,
    [OBJECT_37] = Object37,
    [JAR_PORTAL] = JarPortal,
    [BOSS_DOOR] = BossDoor,
    [OBJECT_3A] = Object3A,
    [PORTAL_MUSHROOM_STALKS] = MacroMushromStalks,
    [PORTAL_FALLING_PLAYER] = MacroPlayer,
    [OBJECT_3D] = Object3D,
    [OBJECT_3E] = Object3E,
    [GIANT_LEAF] = GiantLeaf,
    [FAIRY] = Fairy,
    [LADDER_UP] = LadderUp,
    [OBJECT_42] = Object42,
    [OBJECT_43] = Object43,
    [OBJECT_44] = Object44,
    [OBJECT_45] = Object45,
    [GIANT_BOOK_LADDER] = GiantBookLadder,
    [HEART_CONTAINER] = HeartContainer,
    [FILE_SCREEN_OBJECTS] = FileScreenObjects,
    [OBJECT_49] = Object49,
    [BACKGROUND_CLOUD] = BackgroundCloud,
    [OBJECT_4B] = Object4B,
    [PUSHABLE_FURNITURE] = PushableFurniture,
    [FURNITURE] = Furniture,
    [MINISH_SIZED_ENTRANCE] = MinishSizedEntrance,
    [ARCHWAY] = Archway,
    [GIANT_ROCK] = GiantRock,
    [GIANT_ROCK2] = GiantRock2,
    [OBJECT_52] = Object52,
    [OBJECT_53] = Object53,
    [PULLABLE_LEVER] = PullableLever,
    [MINECART] = Minecart,
    [THOUGHT_BUBBLE] = ThoughtBubble,
    [HIDDEN_LADDER_DOWN] = HiddenLadderDown,
    [GENTARI_CURTAIN] = GentariCurtain,
    [LAVA_PLATFORM] = LavaPlatform,
    [PAPER] = Paper,
    [OBJECT_5B] = Object5B,
    [MASK] = Mask,
    [HOUSE_DOOR_INT] = HouseDoorInterior,
    [WHIRLWIND] = Whirlwind,
    [OBJECT_BLOCKING_STAIRS] = ObjectBlockingStairs,
    [SWORDSMAN_NEWSLETTER] = SwordsmanNewsletter,
    [OBJECT_61] = Object61,
    [GIANT_TWIG] = GiantTwig,
    [OBJECT_63] = Object63,
    [OBJECT_64] = Object64,
    [LADDER_HOLE] = LadderHoleInBookshelf,
    [OBJECT_66] = Object66,
    [OBJECT_67] = Object67,
    [OBJECT_68] = Object68,
    [OBJECT_69] = Object69,
    [OBJECT_6A] = Object6A,
    [CRENEL_BEAN_SPROUT] = CrenelBeanSprout,
    [MINECART_DOOR] = MinecartDoor,
    [OBJECT_ON_PILLAR] = ObjectOnPillar,
    [MINERAL_WATER_SOURCE] = MineralWaterSource,
    [MINISH_SIZED_ARCHWAY] = MinishSizedArchway,
    [OBJECT_70] = Object70,
    [PUSHABLE_GRAVE] = PushableGrave,
    [STONE_TABLET] = StoneTablet,
    [LILYPAD_SMALL] = LilypadSmall,
    [OBJECT_74] = Object74,
    [OBJECT_75] = Object75,
    [OBJECT_76] = Object76,
    [BELL] = Bell,
    [HUGE_DECORATION] = MacroDecoration,
    [OBJECT_79] = Object79,
    [STEAM] = Steam,
    [PUSHABLE_LEVER] = PushableLever,
    [HUGE_SHOES] = MacroShoes,
    [OBJECT_ON_BEETLE] = ObjectOnSpinyBeetle,
    [OBJECT_7E] = Object7E,
    [PICO_BLOOM] = PicoBloom,
    [BOARD] = Board,
    [OBJECT_81] = Object81,
    [BIG_VORTEX] = BigVortex,
    [BIG_PUSHABLE_LEVER] = BigPushableLever,
    [SMALL_ICE_BLOCK] = SmallIceBlock,
    [BIG_ICE_BLOCK] = BigIceBlock,
    [OBJECT_86] = Object86,
    [OCTOROK_BOSS_OBJECT] = OctorokBossObject,
    [HUGE_BOOK] = MacroBook,
    [MAZAAL_BOSS_OBJECT] = MazaalBossObject,
    [CABIN_FURNITURE] = CabinFurniture,
    [DOUBLE_BOOKSHELF] = DoubleBookshelf,
    [BOOK] = Book,
    [FIREPLACE] = Fireplace,
    [OBJECT_8E] = Object8E,
    [FROZEN_WATER_ELEMENT] = FrozenWaterElement,
    [OBJECT_90] = Object90,
    [FROZEN_OCTOROK] = FrozenOctorok,
    [BAKER_OVEN] = BakerOven,
    [LAMP] = Lamp,
    [WIND_TRIBE_FLAG] = WindTribeFlag,
    [BIRD] = Bird,
    [OBJECT_96] = Object96,
    [KEY_STEALING_TAKKURI] = KeyStealingTakkuri,
    [OBJECT_98] = Object98,
    [OBJECT_99] = Object99,
    [HUGE_ACORN] = MacroAcorn,
    [OBJECT_9B] = Object9B,
    [TREE_HIDING_PORTAL] = TreeHidingPortal,
    [LIGHTABLE_SWITCH] = LightableSwitch,
    [TREE_THORNS] = TreeThorns,
    [FAN] = Fan,
    [ANGRY_STATUE] = AngryStatue,
    [PALACE_ARCHWAY] = PalaceArchway,
    [OBJECT_A2] = ObjectA2,
    [CLOUD] = Cloud,
    [MINISH_LIGHT] = MinishLight,
    [FIREBALL_CHAIN] = FireballChain,
    [OBJECT_A6] = ObjectA6,
    [OBJECT_A7] = ObjectA7,
    [OBJECT_A8] = ObjectA8,
    [OBJECT_A9] = ObjectA9,
    [WATERFALL_OPENING] = WaterfallOpening,
    [OBJECT_AB] = ObjectAB,
    [FOUR_ELEMENTS] = FourElements,
    [OBJECT_AD] = ObjectAD,
    [FLOATING_BLOCK] = FloatingBlock,
    [OBJECT_AF] = ObjectAF,
    [METAL_DOOR] = MetalDoor,
    [JAIL_BARS] = JailBars,
    [OBJECT_B2] = ObjectB2,
    [OBJECT_B3] = ObjectB3,
    [OBJECT_B4] = ObjectB4,
    [OBJECT_B5] = ObjectB5,
    [OBJECT_B6] = ObjectB6,
    [WELL] = Well,
    [WIND_TRIBE_TELEPORTER] = WindTribeTeleporter,
    [OBJECT_B9] = ObjectB9,
    [GYORG_BOSS_OBJECT] = GyorgBossObject,
    [WINDCREST] = Windcrest,
    [LIT_AREA] = LitArea,
    [OBJECT_BD] = ObjectBD,
    [PINWHEEL] = Pinwheel,
    [OBJECT_BF] = ObjectBF,
    [ENEMY_ITEM] = EnemyItem,
    [OBJECT_C1] = ObjectC1,
};

void ObjectInit(Entity*);

void ObjectUpdate(Entity* this) {
    if ((this->flags & ENT_DID_INIT) == 0 && this->action == 0)
        ObjectInit(this);
    if (this->iframes != 0)
        this->iframes++;
    if (!EntityIsDeleted(this)) {
        gObjectFunctions[this->id](this);
        this->bitfield &= ~0x80;
    }
    DrawEntity(this);
}
