File WfItem.h

File List > game > include > WfItem.h

Go to the documentation of this file

#ifndef WFITEM_H
#define WFITEM_H
#include "HandleDefs.h"
#include <stdbool.h>
#include "WfEnums.h"
#include "ZzFX.h"
#include "DrawContext.h"
#include "InputContext.h"
#define UI_SPRITE_DIMS_PXLS 32
struct Entity2D;
struct GameFrameworkLayer;
struct WfItemDef;

enum WfItemIndices
{
    WfBasicAxe,
    WfBasicSword,
    WfBasicPickAxe,
    WfBasicScythe,
    WfBasicFishingRod,
    WfBasicHoe,
    WfBasicBow,
    WfWoodItem,
    WfNumBuiltinItems
};

enum WfEquipSlot
{
    Ring1,
    Ring2,
    Head,
    Torso,
    Legs,
    Arms
};

/* when it is switched to in the menu */
typedef void(*OnMakeItemCurrentFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer);
typedef void(*OnStopBeingCurrentItemFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer);
typedef bool(*OnUseItemFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer); // return false if item is used up
typedef bool(*TryEquipFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer, enum WfEquipSlot slot);

// An item definition might use this to initialize data from the atlas such as sprites or named tiles
typedef void(*OnPushGameLayerItemFnItemFn)(struct WfItemDef* pDef, struct GameFrameworkLayer* pLayer, DrawContext* drawContext, InputContext* inputContext);

typedef void(*OnPopGameLayerItemFnItemFn)(struct WfItemDef* pDef, struct GameFrameworkLayer* pLayer, DrawContext* drawContext, InputContext* inputContext);

struct WfItemDef
{
    const char* UISpriteName;

    void* pUserData;

    OnMakeItemCurrentFn onMakeCurrent;

    OnStopBeingCurrentItemFn onStopBeingCurrent;

    OnUseItemFn onUseItem;

    TryEquipFn onTryEquip;

    OnPushGameLayerItemFnItemFn onGameLayerPush;

    OnPushGameLayerItemFnItemFn onGameLayerPop;

    enum WfActionAnimation onUseAnimation;

    bool bCanUseItem;

    const char* pickupSpriteName;

    bool bSoundEffectOnPickup;

    struct ZZFXSound zzfxPickup;
};

void WfAddItemDef(struct WfItemDef* pDef);

void WfAddBuiltinItems();

void WfInitItems();

void WfRegisterItemScriptFunctions();

const struct WfItemDef* WfGetItemDef(int itemIndex);

struct WfItemDef* WfGetItemDefs(int* numDefs);
#endif