Alchemy
Loading...
Searching...
No Matches

snapshot.c

Go to the documentation of this file.
1/// @file
2/// Equipping a given item, and the equipment put aside for the Colosso.
3/// Part of game.c, the game object, compiled only through it.
4
5#include "../game_internal.h"
6
7/// Gives a unit `itemId` and equips every exactly matching inventory entry.
8/// Called by InventorySnapshot_Save to arm Isaac for the Colosso.
9void Inventory_AddAndEquip(s32 owner, s32 itemId) {
10 struct BattleUnit *unit = UnitGet(owner);
11 u16 *entry;
12 s32 slot;
13
14 Inventory_AddItem(owner, itemId);
15 slot = 0;
16 entry = unit->inventory;
17 do {
18 if (*entry++ == itemId)
19 Inventory_Equip(owner, slot);
20 slot++;
21 } while (slot < INVENTORY_SLOTS);
22}
23
24/// The party's equipment, put aside while the Colosso takes it away; the
25/// sentinel marks the snapshot as taken.
26#define INVENTORY_SNAPSHOT_SENTINEL 0x6774
27
28/// Saves the first four characters' inventories, shortcuts and party order,
29/// then keeps only the Psynergy-granting items, gives Isaac the Short
30/// Sword, sets FLAG_INVENTORY_SNAPSHOT and restores everyone's HP and PP.
31/// Nothing happens when a snapshot is already saved, apart from the restore.
32/// Called by the Colosseum entrance scene as Isaac enters the Colosso.
34 u16 *save;
35 struct BattleUnit *unit;
37 s32 owner;
38 s32 slot;
39 s16 firstShortcut;
40 s16 secondShortcut;
41
42 save = gInventorySnapshot;
43 if (*save != INVENTORY_SNAPSHOT_SENTINEL) {
45 firstShortcut = gGameState.firstShortcut;
46 secondShortcut = gGameState.secondShortcut;
47 // Save each inventory before retaining its Psynergy-granting items.
48 for (owner = 0; owner < 4; owner++) {
49 unit = UnitGet(owner);
50 for (slot = 0; slot < INVENTORY_SLOTS; slot++)
51 *save++ = unit->inventory[slot];
52 for (slot = 0; slot < INVENTORY_SLOTS; slot++) {
54 unit->inventory[slot] = 0;
55 }
56 inventory = unit->inventory;
57 Inventory_CompactSlots(inventory);
58 Unit_UpdateClass(owner);
59 UnitCalc(owner);
60 }
61 // Keep shortcuts and party order with the inventory snapshot.
62 *save++ = firstShortcut;
63 *save++ = secondShortcut;
64#ifdef UBFIX
65 // Party order is a byte array; pack its two saved halfwords explicitly.
66 save[0] = gGameState.activeOwners[0] | (gGameState.activeOwners[1] << 8);
67 save[1] = gGameState.activeOwners[2] | (gGameState.activeOwners[3] << 8);
68#else
70 save[0] = inventory[0];
71 save[1] = inventory[1];
72#endif
75 }
77}
78
79/// Gives back the inventories, shortcuts and party order InventorySnapshot_Save
80/// put aside, then clears the snapshot and FLAG_INVENTORY_SNAPSHOT. Called by
81/// the Babi palace scene after the Colosso, and by the file select screen.
83 s32 owner;
84 u16 *source = gInventorySnapshot;
85
86 if (*source++ == INVENTORY_SNAPSHOT_SENTINEL) {
87 owner = 0;
88 do {
89 u16 *inventory = UnitGet(owner)->inventory;
90 s32 remaining = 14;
91
92 do {
93 *inventory++ = *source++;
94 remaining--;
95 } while (remaining >= 0);
96 Unit_UpdateClass(owner);
97 UnitCalc(owner);
98 owner++;
99 } while (owner <= 3);
100
101 gGameState.firstShortcut = *source++;
102 gGameState.secondShortcut = *source++;
103#ifdef UBFIX
104 gGameState.activeOwners[0] = source[0];
105 gGameState.activeOwners[1] = source[0] >> 8;
106 gGameState.activeOwners[2] = source[1];
107 gGameState.activeOwners[3] = source[1] >> 8;
108 source++;
109#else
110 *(u16 *)gGameState.activeOwners = *source++;
111 *(u16 *)((u8 *)gGameState.activeOwners + 2) = *source;
112#endif
113 source = gInventorySnapshot;
114 *source = 0;
116 }
117}
118
119#undef INVENTORY_SNAPSHOT_SENTINEL
#define ISAAC
Robin.
s32 GameFlag_SetBit(s32 flag)
Sets flag and returns its byte number.
Definition flags.c:27
void GameFlag_ClearBit(s32 flag)
Clears flag.
Definition flags.c:40
#define FLAG_INVENTORY_SNAPSHOT
Set while the Colosso holds the party's equipment (the inventory snapshot).
Definition flags.h:92
void Unit_UpdateClass(s32 ownerId)
Works out a character's class again after its Djinn change, then its Psynergy list and its base eleme...
Definition classes.c:232
u16 gInventorySnapshot[]
What every part of the game object shares: its includes and the inventory helper two parts use.
struct GameState gGameState
s32 Inventory_AddItem(s32 owner, s32 itemId)
Gives a unit one item, joining its first matching stack (up to 30) or taking the first free slot.
Definition inventory.c:144
s32 Inventory_Equip(s32 owner, s32 slot)
Equips the item in slot, clearing the equipped bit of the item of the same type it replaces.
Definition inventory.c:257
struct ItemDefinition * Item_GetDirect(s32 item)
Returns item item's definition; an inventory entry may be passed, its equipped and quantity bits are ...
Definition inventory.c:10
@ ITEM_TYPE_PSYNERGY
The items that teach Psynergy while held: Orb of Force to Catch Beads.
Definition item.h:52
@ INVENTORY_SLOTS
Definition item.h:23
@ ITEM_SHORT_SWORD
Definition item_ids.h:14
void InventorySnapshot_Restore(void)
Gives back the inventories, shortcuts and party order InventorySnapshot_Save put aside,...
Definition snapshot.c:82
void Inventory_AddAndEquip(s32 owner, s32 itemId)
Gives a unit itemId and equips every exactly matching inventory entry.
Definition snapshot.c:9
void InventorySnapshot_Save(void)
Saves the first four characters' inventories, shortcuts and party order, then keeps only the Psynergy...
Definition snapshot.c:33
#define INVENTORY_SNAPSHOT_SENTINEL
The party's equipment, put aside while the Colosso takes it away; the sentinel marks the snapshot as ...
Definition snapshot.c:26
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
u16 inventory[15]
Items held, one entry each: bits 15..11 quantity | 10 broken | 9 equipped | 8..0 item id (INVENTORY_*...
u16 firstShortcut
The shortcuts' assignments.
Definition game_state.h:86
u16 secondShortcut
Definition game_state.h:87
u8 activeOwners[8]
the party in order
Definition game_state.h:60
u8 type
enum ItemType; 0 for an item that is not equipment
Definition item.h:106
signed int s32
Definition types.h:14
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
void UnitCalc(s32 owner)
Recomputes a unit's stats from its base stats, equipment, set Djinn, class and battle stat levels,...
Definition units.c:149
void Party_RestoreHpPp(s32 cureConditions)
Restores every party member's HP and PP; with cureConditions 1 it also cures poison and haunting.
Definition units.c:662
struct BattleUnit * UnitGet(u32 owner)
Returns the unit record of owner: 0 to 7 are the playable characters in the game state,...
Definition units.c:73