summaryrefslogtreecommitdiff
path: root/src/manager/goronMerchantShopManager.c
blob: c2493c9982e9d527642a8ebe297e6faea2aa8101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 * @file goronMerchantShopManager.c
 * @ingroup Managers
 *
 * @brief Spawns the shop items for the kinstones for the goron merchant.
 */
#include "manager/goronMerchantShopManager.h"

#include "asm.h"
#include "flags.h"
#include "item.h"
#include "object.h"
#include "object/itemForSale.h"

typedef struct {
    u16 minType;
    u16 numTypes;
    u16 x;
    u16 y;
} GoronShopSpawnData;

void GoronMerchantShopManager_Main(GoronMerchantShopManager* this) {
    static const GoronShopSpawnData shopSpawnData[3] = { { 0x6e, 0x3, 0x210, 0x210 },
                                                         { 0x71, 0x2, 0x220, 0x210 },
                                                         { 0x73, 0x3, 0x230, 0x210 } };
    s32 uVar2;
    const GoronShopSpawnData* spawnData;
    s32 count;

    if (super->action == 0) {
        super->action++;
        if (CheckGlobalFlag(GORON_KAKERA_L) != 0 && CheckGlobalFlag(GORON_KAKERA_M) != 0 &&
            CheckGlobalFlag(GORON_KAKERA_R) != 0) {
            if (CheckGlobalFlag(GORON_KAKERA_LV2) == 0) {
                if (CheckGlobalFlag(LV1_CLEAR) != 0) {
                    SetGlobalFlag(GORON_KAKERA_LV2);
                    goto clearGlobalFlags;
                }
            } else if (CheckGlobalFlag(GORON_KAKERA_LV3) == 0) {
                if (CheckGlobalFlag(LV2_CLEAR) != 0) {
                    SetGlobalFlag(GORON_KAKERA_LV3);
                    goto clearGlobalFlags;
                }
            } else if (CheckGlobalFlag(GORON_KAKERA_LV4) == 0) {
                if (CheckGlobalFlag(LV3_CLEAR) != 0) {
                    SetGlobalFlag(GORON_KAKERA_LV4);
                    goto clearGlobalFlags;
                }
            } else if (CheckGlobalFlag(GORON_KAKERA_LV5) == 0 && CheckGlobalFlag(LV4_CLEAR) != 0) {
                SetGlobalFlag(GORON_KAKERA_LV5);
            clearGlobalFlags:
                ClearGlobalFlag(GORON_KAKERA_L);
                ClearGlobalFlag(GORON_KAKERA_M);
                ClearGlobalFlag(GORON_KAKERA_R);
            }
        }
        this->itemActive[2] = 0;
        this->itemActive[1] = 0;
        this->itemActive[0] = 0;
        spawnData = shopSpawnData;
        count = 0;
        for (count = 0; count < 3;) {
            if (CheckGlobalFlag(GORON_KAKERA_L + count) == 0) {
                ItemForSaleEntity* object = (ItemForSaleEntity*)CreateObject(
                    SHOP_ITEM, ITEM_KINSTONE, ((s32)Random() % spawnData->numTypes) + spawnData->minType);
                if (object != NULL) {
                    object->base.timer = 1;
                    object->base.subtimer = count;
                    object->base.x.HALF.HI = spawnData->x + gRoomControls.origin_x;
                    object->base.y.HALF.HI = spawnData->y + gRoomControls.origin_y;
                    object->unk_80 = spawnData->x;
                    object->unk_82 = spawnData->y;
                    object->base.collisionLayer = 1;
                    object->base.parent = (Entity*)this;
                    this->itemActive[count] = 1;
                }
            }
            count++;
            spawnData++;
        }
    }
    for (count = 0; count < 3; ++count) {
        if (CheckGlobalFlag(GORON_KAKERA_L + count) == 0) {
            if ((s8)this->itemActive[count] >= FALSE) {
            } else {
                SetGlobalFlag(GORON_KAKERA_L + count);
            }
        }
    }
}