Alchemy
Loading...
Searching...
No Matches

inn.c

Go to the documentation of this file.
1/// @file
2/// The inn: room prices, checking in and the night's sleep.
3/// Part of shop.c, the shop object, compiled only through it.
4
5#include "../shop_internal.h"
6
7/// The innkeeper's lines, in message order from MsgInnWelcome.
14};
15
16/// The coins a night costs each living guest, by inn: Vale, Vault, Bilibin,
17/// Kolima, Imil, Xian, Altin, Kalay, Lunpa, 9 (no inn), Suhalla, Lalivero.
18// clang-format off
19static const s8 sInnPricesPerGuest[12] = {
20 2, 4, 7, 8, 8, 10, 12, 15, 20, 0, 18, 25,
21};
22// clang-format on
23
24/// Returns the night's price: the inn's price per guest times the party
25/// members still standing. Called by Inn_CheckIn.
27 struct ShopRuntime *shop = gMenuWork;
28 s32 guestCount = 0;
29 s32 pricePerGuest = sInnPricesPerGuest[innId];
30 s32 memberIndex;
31
32 for (memberIndex = 0; memberIndex < shop->partyMemberCount; memberIndex++) {
33 if (UnitGetFar(shop->partyMemberIds[memberIndex])->hp != 0)
34 guestCount++;
35 }
36 return pricePerGuest * guestCount;
37}
38
39/// Runs an inn's counter: the innkeeper names the price, and on Yes, with the
40/// coins, the party sleeps (Inn_PlaySleep) and the innkeeper speaks again.
41/// Holds the shop's work block while it runs. Called by the town scenes'
42/// innkeepers through SHOP.S (Engine_InnOpen).
43s32 Inn_CheckIn(s32 innId, s32 objectId) {
44 struct InnRuntimeState *state;
45 struct FieldActor *innkeeper;
46 struct UiWindow *innkeeperWindow;
47 s32 roomPrice;
48 s32 messageBase;
49
52 state->active = 1;
53 // Xian's inn has lines of its own, as far past the other inns' as the
54 // warriors' shops' are past the weapon shop's (warriorShop).
55 if (innId == 5)
56 state->specialActive = 1;
57
58 innkeeper = Object_GetByIdFar(objectId);
59 state->resourceId =
60 ((struct AnimationObject *)innkeeper->sprite)->entries[0]->animId;
61 innkeeperWindow =
63
64 roomPrice = Inn_RoomPrice(innId);
65 UiWork_PushValueSlotFar(roomPrice, 5);
66 messageBase = MsgInnWelcome;
67 UiMessage_ShowAndWait(messageBase);
70
71 if (UiMessage_ShowChoice(0) != 0) {
72 UiMessage_ShowAndWait(messageBase +
74 UiWork_FinalizeFar(state->window, 2);
75 } else if (roomPrice > (u32)gGameState.coins) {
76 UiMessage_ShowAndWait(messageBase +
78 UiWork_FinalizeFar(state->window, 2);
79 } else {
80 UiWork_FinalizeFar(state->window, 2);
81 UiMessage_ShowAndWait(messageBase +
83 UiWork_FinalizeFar(innkeeperWindow, 2);
84 Inn_PlaySleep(roomPrice);
85
86 innkeeper = Object_GetByIdFar(objectId);
87 state->resourceId =
88 ((struct AnimationObject *)innkeeper->sprite)->entries[0]->animId;
89 innkeeperWindow =
91 UiMessage_ShowAndWait(messageBase +
93 }
94
95 UiWork_FinalizeFar(innkeeperWindow, 2);
97 return 0;
98}
99
100/// Charges `roomPrice`, restores the HP and PP of each member still standing,
101/// and plays the night: a fade to black, the inn's music and a fade back.
102/// Called by Inn_CheckIn.
103void Inn_PlaySleep(s32 roomPrice) {
104 s16 partyMemberIds[8];
105 s32 memberCount;
106 s32 memberIndex;
107 struct BattleUnit *unit;
108 struct FieldWork *fieldWork;
109
110 memberCount = Party_ListActiveOwnersFar(partyMemberIds);
111 // Charge once and restore only party members who are alive.
112 Party_AdjustCoinsFar(-roomPrice);
113
114 for (memberIndex = 0; memberIndex < memberCount; memberIndex++) {
115 unit = UnitGetFar(partyMemberIds[memberIndex]);
116 if (unit->hp != 0) {
117 unit->hp = unit->maxHp;
118 unit->pp = unit->maxPp;
119 UnitRatioFar(partyMemberIds[memberIndex]);
120 }
121 }
122
123 // Sleep between the two screen-transition halves and the rest sound.
124 fieldWork = (struct FieldWork *)gEventWork;
125 fieldWork->transition = 0x209;
126 fieldWork->transitionFrames = 60;
127 WaitFrames(20);
132 WaitFrames(10);
135 WaitFrames(30);
136 ((struct FieldWork *)gEventWork)->transitionFrames = 16;
137}
void Shop_DrawMoney(void)
Draws the party's coins in the coins window, in the edition's layout.
Definition buy.c:305
struct BattleUnit * UnitGetFar(u32 owner)
s32 Party_ListActiveOwnersFar(s16 *owners)
void UnitRatioFar(s32 owner_id)
s32 Party_AdjustCoinsFar(s32 amount)
void Event_FinishScreenTransitionFar(void)
void Event_WaitTransitionFramesFar(void)
void Event_StartScreenTransitionFar(void)
struct FieldActor * Object_GetByIdFar(s32 objectId)
void AudioCommand_PlayFar(s32 id)
struct UiWindow * UiWindow_CreateFar(s32 x, s32 y, s32 width, s32 height, s32 attrs)
void UiWork_FinalizeFar(struct UiWindow *work, s32 release)
struct UiWindow * UiWindow_CreateWithSideObjectFar(s32 arg0, s32 arg1, s32 x, s32 y)
void UiWork_PushValueSlotFar(u32 value, u32 kind)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
struct GameState gGameState
void * gMenuWork
InnMessageId
The innkeeper's lines, in message order from MsgInnWelcome.
Definition inn.c:8
@ INN_MESSAGE_GOODBYE
Definition inn.c:12
@ INN_MESSAGE_NOT_ENOUGH_COINS
Definition inn.c:11
@ INN_MESSAGE_STAY_COMPLETE
Definition inn.c:10
@ INN_MESSAGE_REST_COMPLETE
Definition inn.c:13
@ INN_MESSAGE_WELCOME
Definition inn.c:9
void Inn_PlaySleep(s32 roomPrice)
Charges roomPrice, restores the HP and PP of each member still standing, and plays the night: a fade ...
Definition inn.c:103
static const s8 sInnPricesPerGuest[12]
The coins a night costs each living guest, by inn: Vale, Vault, Bilibin, Kolima, Imil,...
Definition inn.c:19
s32 Inn_CheckIn(s32 innId, s32 objectId)
Runs an inn's counter: the innkeeper names the price, and on Yes, with the coins, the party sleeps (I...
Definition inn.c:43
s32 Inn_RoomPrice(s32 innId)
Returns the night's price: the inn's price per guest times the party members still standing.
Definition inn.c:26
void Shop_ReleaseCursorWork(void)
Stops the cursor task, frees the six cursor icons and the work block.
Definition run.c:79
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...
Definition run.c:278
void AudioCommand_WaitForStateByteClear(void)
Waits one frame at a time until the sound driver has finished the last command.
Definition run.c:198
void Shop_InitializeCursorWork(void)
Allocates and clears the work block in the menu's heap slot, lists the party, loads the six cursor ic...
Definition run.c:47
void UiMessage_ShowAndWait(s32 messageId)
Shows a shopkeeper's line and waits for its window to finish, one more frame included.
Definition run.c:214
What every part of the shop object shares: its includes, the shop actions and sanctum services,...
#define SHOP_MONEY_WINDOW_WIDTH
#define MUS_086
Definition songs.h:85
struct EventWork * gEventWork
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
struct AnimationEntry * entries[4]
its layers; empty ones null
Definition animspr.h:130
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
s16 maxPp
0 to 1999 for a character, 9999 for an enemy (UnitCalc)
s16 hp
current HP, 0 when downed
s16 pp
current PP
s16 maxHp
0 to 1999 for a character, 9999 for an enemy (UnitCalc)
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
Full event work allocated by Field_RunScene (heap slot 27).
s32 transition
SCENE_TRANSITION(style, variant); 0x100 on entry.
s32 transitionFrames
frames; 16 on entry and at each event
An inn's work, in the menu work: the coins window and the innkeeper's portrait.
Definition inn_runtime.h:13
struct UiWindow * window
the coins window: ShopRuntime's moneyWindow
Definition inn_runtime.h:15
u16 resourceId
The innkeeper's animation, which picks the portrait: ShopRuntime's keeperResource.
Definition inn_runtime.h:22
A shop's work: its windows, the party members' icons, the stock, the cursor and its icons,...
Definition shop.h:18
s8 partyMemberCount
Definition shop.h:47
s16 partyMemberIds[9]
the party in order (Party_ListActiveOwners)
Definition shop.h:30
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
u16 state
0 while a message channel is typing into the window; 1 once its text has ended or closed the window,...
Definition uiwindow.h:24
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12