Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
equip.c
Go to the documentation of this file.
1/* The shop's helpers: a shop's stock, and who can equip an item, in which slot */
2
3#include "menus/item_shop.h"
4
5/* The items a shop sells (up to 0), noting how many in STITSHOP_funcs.count;
6 NULL for none */
8 if (shop < 0 || STITSHOP_shops[shop].items == NULL) {
9 return NULL;
10 }
12 return STITSHOP_shops[shop].items;
13}
14
15/* 1 when a partner can equip an item: the partner's bit in its partners */
16s32 STITSHOP_canEquip(s32 partner, s32 item) {
17 return (ITEM_FUNCS.get(item)->data.record->weapon.partners >> partner) & 1;
18}
19
20/* Which equipment slot a bought item would go in: 2 or 3 for the weapons (the
21 one with the weaker item when both are taken), 4 or 5 for the accessories
22 (the one with the same group, else the weaker one); -1 when it can't */
24 ItemData *data = ITEM_FUNCS.get(item)->data.record;
25 PartnerStats *stats;
26 ItemInfo *info;
27 ItemData *first;
28 ItemData *second;
29 s32 equipped[2];
30 ItemData *datas[2];
31 s32 i;
32
33 switch (data->weapon.kind) {
35 stats = GAME.funcs.getPartnerStats(partner);
36 if (stats->equip[2] > 0) {
37 equipped[0] = stats->equip[2];
38 if (stats->equip[3] > 0) {
39 equipped[1] = stats->equip[3];
40 first = ITEM_FUNCS.get(equipped[0])->data.record;
41 info = ITEM_FUNCS.get(equipped[1]);
42 second = info->data.record;
43 if (first->weapon.kind == EQUIP_KIND_BOTH_HANDS || info->type == 0x14) {
44 return 2;
45 }
46 for (i = 0; i < 2; i++) {
47 info = ITEM_FUNCS.get(equipped[i]);
48 if (info->type < 2 || info->type > 14) {
49 return -1;
50 }
51 }
52 if (first->weapon.atk < second->weapon.atk) {
53 return 2;
54 }
55 }
56 return 3;
57 }
58 return 2;
60 return 3;
61 case EQUIP_KIND_HEAD:
62 return 0;
63 case EQUIP_KIND_BODY:
64 return 1;
66 stats = GAME.funcs.getPartnerStats(partner);
67 if (stats->equip[4] > 0) {
68 equipped[0] = stats->equip[4];
69 if (stats->equip[5] > 0) {
70 equipped[1] = stats->equip[5];
71 datas[0] = ITEM_FUNCS.get(equipped[0])->data.record;
72 datas[1] = ITEM_FUNCS.get(equipped[1])->data.record;
73 /* and the accessories' bonuses signed */
74 if ((s16)datas[0]->acc.amount < (s16)datas[1]->acc.amount) {
75 return 4;
76 }
77 }
78 return 5;
79 }
80 return 4;
83 return 2;
85 stats = GAME.funcs.getPartnerStats(partner);
86 if (stats->equip[4] > 0) {
87 equipped[0] = stats->equip[4];
88 if (stats->equip[5] <= 0) {
89 return 5;
90 }
91 equipped[1] = stats->equip[5];
92 datas[0] = ITEM_FUNCS.get(equipped[0])->data.record;
93 if (datas[0]->acc.kind == EQUIP_KIND_GROUP_ACCESSORY && datas[0]->acc.group == data->acc.group) {
94 return 4;
95 }
96 datas[1] = ITEM_FUNCS.get(equipped[1])->data.record;
97 if (datas[1]->acc.kind == EQUIP_KIND_GROUP_ACCESSORY && datas[1]->acc.group == data->acc.group) {
98 return 5;
99 }
100 break;
101 }
102 return 4;
103 case 0:
104 default:
105 return -1;
106 }
107 if ((s16)datas[0]->acc.amount < (s16)datas[1]->acc.amount) {
108 return 4;
109 }
110 return 5;
111}
112
113/* Puts an item in a partner's equipment slot like STSTATUS_equip, moving the
114 counts between GAME.items and GAME.equippedItems only when fromBag is set */
115void STITSHOP_equip(s32 partner, s32 slot, s32 item, s32 fromBag) {
116 PartnerStats *stats = GAME.funcs.getPartnerStats(partner);
117 s16 *equip;
118 s16 *pair;
119 ItemData *data;
120 s32 group;
121 s32 old;
122 s32 i;
123 s32 id = item; /* the match depends on this copy, as in STSTATUS_equip */
124
125 old = *(stats->equip + slot);
126 if (old != 0) {
127 if (fromBag) {
128 GAME.equippedItems[old]--;
129 GAME.items[old]++;
130 }
131 data = ITEM_FUNCS.get(old)->data.record;
132 if (data->weapon.kind == EQUIP_KIND_BOTH_HANDS) {
133 stats->equip[2] = 0;
134 stats->equip[3] = 0;
135 } else {
136 *(stats->equip + slot) = 0;
137 }
138 }
139 if (id > 0) {
140 data = ITEM_FUNCS.get(id)->data.record;
141 if (data->weapon.kind == EQUIP_KIND_BOTH_HANDS) {
142 pair = &stats->equip[2];
143 if (stats->equip[2] == 0) {
144 pair = NULL;
145 if (stats->equip[3] != 0) {
146 pair = &stats->equip[3];
147 }
148 }
149 if (pair != NULL) {
150 if (fromBag) {
151 GAME.equippedItems[*pair]--;
152 GAME.items[*pair]++;
153 }
154 *pair = 0;
155 }
156 } else if (data->acc.kind == EQUIP_KIND_GROUP_ACCESSORY) {
157 group = data->acc.group;
158 for (i = 0; i < 2; i++) {
159 equip = &stats->equip[i + 4];
160 if (*equip != 0) {
161 data = ITEM_FUNCS.get(*equip)->data.record;
162 if (data->acc.group == group) {
163 if (fromBag) {
164 GAME.equippedItems[*equip]--;
165 GAME.items[*equip]++;
166 }
167 *equip = 0;
168 }
169 }
170 }
171 }
172 if (fromBag) {
173 GAME.equippedItems[id]++;
174 GAME.items[id]--;
175 }
176 data = ITEM_FUNCS.get(id)->data.record;
177 if (data->weapon.kind == EQUIP_KIND_BOTH_HANDS) {
178 stats->equip[2] = id;
179 stats->equip[3] = id;
180 } else {
181 *(stats->equip + slot) = id;
182 }
183 }
184}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
s16 * STITSHOP_getShopItems(s32 shop)
The items a shop sells (up to 0), noting how many in STITSHOP_funcs.count; NULL for none.
Definition equip.c:7
void STITSHOP_equip(s32 partner, s32 slot, s32 item, s32 fromBag)
Puts an item in a partner's equipment slot like STSTATUS_equip, moving the counts between GAME....
Definition equip.c:115
s32 STITSHOP_canEquip(s32 partner, s32 item)
1 when a partner can equip an item: the partner's bit in its partners
Definition equip.c:16
s32 STITSHOP_compareEquip(s32 partner, s32 item)
Which equipment slot a bought item would go in: 2 or 3 for the weapons (the one with the weaker item ...
Definition equip.c:23
#define EQUIP_KIND_RIGHT_HAND
Where an equipment item goes (its record's kind), as the shop's and STSTATUS's strings name the kinds...
Definition game_state.h:134
#define EQUIP_KIND_LEFT_HAND
Definition game_state.h:135
#define EQUIP_KIND_BODY
Definition game_state.h:138
#define EQUIP_KIND_GROUP_ACCESSORY
one of its group at a time
Definition game_state.h:141
#define EQUIP_KIND_EITHER_HAND
Definition game_state.h:136
#define EQUIP_KIND_HEAD
Definition game_state.h:137
#define EQUIP_KIND_ACCESSORY
Definition game_state.h:139
#define EQUIP_KIND_BOTH_HANDS
takes slots 2 and 3
Definition game_state.h:140
STITSHOP.PRO: the item shop.
ItemFuncs ITEM_FUNCS
Definition items.c:890
ItemShopFuncs STITSHOP_funcs
The shop's helpers.
Definition stitshop.c:228
ShopList STITSHOP_shops[31]
The shops, by ItemShop.shop.
Definition stitshop.c:194
u8 kind
EQUIP_KIND_ACCESSORY or EQUIP_KIND_GROUP_ACCESSORY.
Definition game_state.h:179
struct PartnerStats *(* getPartnerStats)(s32 partner)
Definition game_state.h:38
s8 items[0x193]
counts, up to 99
Definition game_state.h:512
s8 equippedItems[0x193]
Definition game_state.h:513
GameFuncs funcs
Definition game_state.h:582
struct ItemInfo *(* get)(s32 item)
getItem
Definition game_state.h:670
An item (ITEMS, ITEM_FUNCS)
Definition game_state.h:225
u8 type
2-14 weapons, 15-20 armour, 21-24 accessories
Definition game_state.h:230
ItemRecord data
the type's record, or the usable items' effect
Definition game_state.h:226
s32 count
the items of the shop getShopItems returned
Definition item_shop.h:225
A partner Digimon from its name on (Partner.info), as getPartnerStats gives it.
Definition game_state.h:303
s32 count
Definition item_shop.h:219
s16 * items
Definition item_shop.h:220
u8 kind
EQUIP_KIND_*.
Definition game_state.h:146
u8 partners
1 << partner for each partner who can equip it (STSTATUS_canEquip)
Definition game_state.h:148
ItemInfo.data's record, by ItemInfo.type.
Definition game_state.h:188
AccessoryData acc
Definition game_state.h:191
WeaponData weapon
Definition game_state.h:189
ItemData * record
Definition game_state.h:210