9#define SHOP_INVENTORY_OFFSET ((s32)offsetof(struct BattleUnit, inventory))
10#define SHOP_ICON_DEPTH_OFFSET ((s32)offsetof(struct RenderOutput, sentinel))
12#define SHOP_STACK_LIMIT 30
28 s32 repromptRecipient;
50 selectionIndex = selected;
61 itemId = stockIds[selectionIndex];
73 selected = selectionIndex;
84 previousIndex = selectionIndex;
86 selectionIndex = (selectionIndex + stockCount) % stockCount;
87 if (previousIndex != selectionIndex) {
93 previousIndex = selectionIndex;
95 selectionIndex = (selectionIndex + stockCount) % stockCount;
96 if (previousIndex != selectionIndex) {
113 if (selectionIndex > stockCount - 1)
114 selectionIndex = stockCount - 1;
122 if (selectionResult != 0)
130 repromptRecipient = 0;
140 if (repromptRecipient != 0) {
141 repromptRecipient = 0;
161 if (capacitySlot < 0) {
175 selectionResult = -1;
182 repromptRecipient = 1;
189 repromptRecipient = 1;
199 selectionResult = -1;
221 for (removedCount = 0; removedCount < quantity; removedCount++)
262 if (stockIndex != 0) {
279 if (stockIndex < (
u32)itemCount) {
280 stockCursor = (
s16 *)((stockIndex * 2) + (
u32)itemIds);
284 priceX += 32, pageSlot++, stockCursor++, stockIndex++) {
285 itemId = *stockCursor;
290 if (stockIndex == selected) {
312#if (LANGUAGE != LANGUAGE_JAPANESE)
316 s32 msg = MsgYourCoins;
342 labelMessage = MsgPrice;
387 for (memberIndex = 0; memberIndex < shop->
partyMemberCount; memberIndex++) {
388 if (memberIndex == selected)
411 s32 replacedItemId = -1;
428 if (previewSlot == -1) {
448 savedEntry = unit->
inventory[previewSlot];
451 previewStats[0] = unit->
atk;
452 previewStats[1] = unit->
def;
453 previewStats[2] = unit->
agi;
454 previewStats[3] = unit->
luck;
455 unit->
inventory[previewSlot] = savedEntry;
457 baseStats[0] = unit->
atk;
458 baseStats[1] = unit->
def;
459 baseStats[2] = unit->
agi;
460 baseStats[3] = unit->
luck;
461 for (index = 0; index <= 2; index++) {
462 if (baseStats[index] > previewStats[index])
466 else if (baseStats[index] < previewStats[index])
471 if (baseStats[index] != previewStats[index])
478 if (replacedItemId != -1)
517 if (*(
u16 *)(unitBytes + firstOffset) != 0) {
521 *(
u16 *)(unitBytes + itemOffset), 27, window, x, y);
524 if (itemIndex == 4) {
528 if (itemIndex == 9) {
536 if (*(
u16 *)(unitBytes + nextOffset) == 0)
555 s32 selectedQuantity;
560 selectedQuantity = 1;
571 if (item->
price != 0)
576 if (quantityLimit > artifactLimit)
579 artifactLimit = quantityLimit;
580 quantityLimit = artifactLimit;
583 quantityLimit += carriedQuantity;
592 return selectedQuantity;
595#if (LANGUAGE == LANGUAGE_GERMAN) || (LANGUAGE == LANGUAGE_FRENCH)
596#define SHOP_QUANTITY_NUMBER_X 64
597#define SHOP_QUANTITY_COIN_LABEL_X 128
598#elif (LANGUAGE == LANGUAGE_SPANISH)
599#define SHOP_QUANTITY_NUMBER_X 72
600#define SHOP_QUANTITY_COIN_LABEL_X 144
602#define SHOP_QUANTITY_NUMBER_X 72
603#define SHOP_QUANTITY_COIN_LABEL_X 136
617 s32 selectedQuantity;
619#if (LANGUAGE == LANGUAGE_JAPANESE)
626 selectedQuantity = -1;
640 selectedQuantity = quantityIndex + 1;
645 selectedQuantity = -1;
660 quantityIndex = (quantityIndex + maximum) % maximum;
670 selectedQuantity = quantityIndex + 1;
671#if (LANGUAGE != LANGUAGE_JAPANESE)
680 unitMessageBase = MsgPiece;
694 return selectedQuantity;
702 s32 remainingQuantity;
706 remainingQuantity = quantity;
713 if (lastAddedSlot < remainingQuantity) {
717 remainingQuantity -= 1;
720 }
while (remainingQuantity != 0);
747 if (replacedSlot != -1) {
811 salePrice = salePrice / 2;
813 salePrice = salePrice * 3 / 4;
818#undef SHOP_QUANTITY_NUMBER_X
819#undef SHOP_QUANTITY_COIN_LABEL_X
820#undef SHOP_INVENTORY_OFFSET
821#undef SHOP_ICON_DEPTH_OFFSET
822#undef SHOP_STACK_LIMIT
void Shop_BuySpecialItem(struct UiWindow *window, struct UiWindow *itemWindow)
Gives a Game Ticket once the party's shop credit (what it has spent in shops) reaches the next ticket...
#define SHOP_ICON_DEPTH_OFFSET
void Shop_DrawParty(struct UiWindow *window, s32 selected, s32 itemId)
Shows the chosen member walking and the others standing, and draws at four fifths of their size the m...
void Shop_DrawUnitItem(struct UiWindow *window, s32 unitId, s32 itemId)
Shows the quantity already carried and the member's inventory icons.
s32 Shop_ConfirmEquip(s32 unitId, s32 slot)
Offers to equip the item just bought, unless it is equipped already, the member cannot equip it,...
#define SHOP_QUANTITY_COIN_LABEL_X
s32 Shop_SalePrice(s32 inventoryEntry)
Returns what the shops pay for an inventory entry: nothing for an indispensable item,...
void Shop_DrawEquipComparison(struct UiWindow *window, s32 unitId, s32 itemId)
Shows how Attack, Defense and Agility would change if the member wore the item: equips it in place of...
s32 Shop_SellOld(s32 unitId, s32 slot)
Offers to sell the item the new one replaced, unless there is none or it is a Psynergy item or indisp...
void Shop_BuyDone(s32 unitId, s32 itemId, s32 quantity)
Adds each item bought to the member, charging its price and adding it to the shop credit one at a tim...
#define SHOP_QUANTITY_NUMBER_X
void Shop_DrawMoney(void)
Draws the party's coins in the coins window, in the edition's layout.
s32 Shop_SelectBuy(void)
Runs the Buy and Artifacts counters: the player browses the stock seven items a page,...
void Shop_DrawMsg(struct UiWindow *window, s32 message)
Shows message, an item's description, in the help window; a NULL window is ignored.
s32 Shop_SelectQuantity(s32 minimum, s32 maximum, s32 price)
Chooses how many items to buy or sell, returning the quantity above minimum or -1 when cancelled.
s32 Shop_SelectBuyNum(s32 unitId, s32 itemId)
Asks how many to buy when the item stacks, limited by what the coins buy, the artifact's stock and a ...
void Shop_DrawItemPrice(struct UiWindow *window, s32 itemId, s32 price, s32 priceKind)
Draws the item's name and below it its price.
void Shop_DrawStock(struct UiWindow *window, s32 selected)
Draws a page of seven stock items with their prices, the page arrows, and the chosen item lifted and ...
#define SHOP_INVENTORY_OFFSET
#define SHOP_STACK_LIMIT
maximum quantity accepted by Inventory_AddItem
void Shop_PlaceCursor(struct UiWindow *window, s32 x, s32 y)
Starts the hand cursor's glide to (x, y) pixels inside window (the screen when it is NULL),...
struct RenderOutput * Shop_CreatePriceSprite(s32 value, struct UiWindow *window, s32 x, s32 y)
Builds a price of up to five digits in scratch tiles (heap slot 14), loads them into a free VRAM cach...
void Shop_FillSelector(s32 itemCount, s32 paletteSelector, u8 *tileBuffer)
Colours the first itemCount segments of the quantity bar with palette paletteSelector,...
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
s32 AnimationObjects_SelectAnimationFar(struct AnimationObject *state, s32 flags)
struct BattleUnit * UnitGetFar(u32 owner)
struct ItemDefinition * Item_GetDirectFar(s32 item)
s32 Item_AdjustCounterFar(s32 item_id, s32 delta)
s32 Inventory_CountFar(s32 owner)
s32 Inventory_FindEquippedFar(s32 owner, s32 type)
s32 Inventory_AddItemFar(s32 owner_id, s32 item_id)
s32 Item_GetEquipmentGroupFar(s32 item_id)
s32 Item_IsCompatibleWithOwnerFar(s32 unit, s32 item)
s32 Inventory_RemoveFar(s32 owner, s32 slot)
s32 Inventory_EquipFar(s32 owner, s32 slot)
s32 Item_CanOwnerEquip(s32 unit, s32 item)
Far call to Item_CanOwnerEquipDirect.
s32 Inventory_FindFar(s32 owner, s32 item_id)
void UnitCalcFar(s32 owner)
s32 Party_AdjustShopCreditFar(s32 amount)
s32 Party_AdjustCoinsFar(s32 amount)
void AudioCommand_PlayFar(s32 id)
void RenderOutput_PrepareForRedrawFar(struct UiWindow *window)
struct UiWindow * UiWindow_CreateFar(s32 x, s32 y, s32 width, s32 height, s32 attrs)
void RenderOutput_ClearListFar(void *work)
void UiText_DrawNumberInWindowFar(s32 arg0, s32 arg1, struct UiWindow *arg2, s32 arg3, s32 arg4)
struct RenderOutput * RenderOutput_CreateLoadedFar(s32 code, s32 layers, struct UiWindow *input, s32 x, s32 y)
void UiWindow_DrawDividerLineFar(struct UiWindow *win, u32 x1, u32 y1, u32 x2, u32 y2)
void UiText_DrawCharacterAtOffsetFar(s32 character, const struct UiWindow *position, u32 offsetX, u32 offsetY)
struct RenderOutput * RenderOutput_CreateFar(s32 slot, s32 flags, struct UiWindow *input, s32 offsetX, s32 offsetY)
void UiText_DrawResourceFar(s32 arg0, struct UiWindow *arg1, s32 arg2, s32 arg3)
void UiWork_FinalizeFar(struct UiWindow *work, s32 release)
void UiWork_PushValueSlotFar(u32 value, u32 kind)
s32 UiWork_IsCompleteFar(void)
void RenderOutput_RedrawSavedRectFar(struct UiWindow *window)
struct UiWindow * UiText_OpenMessageWindowFar(s32 message, s32 x, s32 y, u32 packed)
void UiWork_FinalizePendingCoreFar(void)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
struct GameState gGameState
void * Runtime_AllocateBlock(s32 kind, s32 size)
As Runtime_AllocateHeapBlock, but tries EWRAM first, for blocks that need room more than speed: the b...
@ ITEM_TYPE_PSYNERGY
The items that teach Psynergy while held: Orb of Force to Catch Beads.
@ INVENTORY_QUANTITY_SHIFT
volatile u32 gKeysPressed
Keys that went down this frame.
volatile u32 gKeysRepeat
Pressed keys, repeating while held: after 19 frames, then every 6.
void Runtime_ReleaseHeapBlock(s32 slot)
void UiMessage_ShowAndRestoreState(s32 messageId)
Shows a shopkeeper's line as UiMessage_ShowAndWait does, hiding the hand cursor while it shows and pu...
s32 Shop_ListAvailableArtifacts(void)
Lists the current shop's artifacts: every item of the shop's type whose shared stock counter is above...
s32 UiMessage_ShowChoice(s32 choice)
Runs the Yes or No choice beside the shopkeeper's line and returns it, keeping the hand cursor's moti...
void UiMessage_ShowAndWait(s32 messageId)
Shows a shopkeeper's line and waits for its window to finish, one more frame included.
void Shop_SellItem(s32 unitId, s32 slot, s32 count)
Sells count of the item in slot: refuses an item the shop does not buy or one equipped and cursed on,...
void Shop_DrawUnitGrid(struct UiWindow *window, s32 unitId)
Draws the member's items as icons in rows of five, or a line saying it has none.
const u8 gShop_QuantityTiles[]
What every part of the shop object shares: its includes, the shop actions and sanctum services,...
#define SHOP_QUANTITY_CURSOR_X
#define SHOP_DRAW_MESSAGE
#define SHOP_PRICE_NUMBER_X
#define SHOP_PRICE_LABEL_X
#define SE_MENU_CURSOR_MOVE
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u8 luck
0 to 99 (UnitCalc)
u16 atk
Attack, 0 to 999 (UnitCalc).
u16 agi
Agility, 0 to 999: the order of the round's actions.
u16 def
Defense, 0 to 999 (UnitCalc).
u16 inventory[15]
Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*...
An item's definition: its price, type, who can equip it, its bonuses and unleash, its effects and the...
u8 type
enum ItemType; 0 for an item that is not equipment
u16 icon
indexes gUiIcon_ItemIconPointers
A render output: a sprite in a window's output list (a character, an icon or a portrait),...
u8 sentinel
depth slot it is drawn at (254 for glyphs)
s8 active
its UI_SPRITE_ motion; 0 while free
u16 animStep
step of its motion's animation
s8 kind
0 for a glyph; otherwise it owns VRAM cache slot index, freed with it, and 2 (a portrait) also its pa...
struct RenderOutput * anchor
the cursor's sprite, moved with its OAM
A shop's work: its windows, the party members' icons, the stock, the cursor and its icons,...
s32 partyMemberScale[8]
16.16 fixed point, 0x10000 full size
struct UiWindow * itemWindow
struct ShopCursor cursor
the hand cursor
s16 partyMemberIds[9]
the party in order (Party_ListActiveOwners)
struct AnimationObject * partyMemberIcons[8]
the party row's sprites
struct UiWindow * moneyWindow
the coins window
u16 selectedItem
the item being bought, sold or repaired
s16 stockItemIds[129]
the items on sale, ended by 0
s8 partyAction
the counter chosen (enum ShopAction)
u8 mode
passed on as the hand cursor's kind; set to 12 at first
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
s32 VramCache_Load(u32 no, u32 size, const void *src)
Gives cache entry no size bytes of sprite VRAM and copies src there.