1#ifndef ALCHEMY_UNIT_GAME_GAME_H
2#define ALCHEMY_UNIT_GAME_GAME_H
119 s32 elementDifference);
121 s32 powerMultiplier);
130 s32 effectId,
s32 successScale);
s32 BattleTarget_IsWeakToEffect(const struct BattleUnit *target, s32 effectId)
Returns 1 when the unit is weak to effect effectId: one of three listed for its enemy kind (EnemyDefi...
s32 RollWeaponUnleash(struct BattleUnit *owner)
Rolls whether a character's weapon unleashes: its chance is the weapon's unleashChance times 5 percen...
s32 Battle_CalcRecovery(s32 power, s32 elementPower, s32 powerMultiplier)
Returns the amount healed: power and powerMultiplier (256 is 1x) times the multiplier for twice the h...
s32 Battle_GetElementMultiplier(s32 input, s32 halve)
Returns the multiplier (256 = 1x) for an element difference input, read from a five-point line (gElem...
s32 Item_GetEquippedElement(s32 owner)
Returns the element the unit attacks with (ELEMENT_NONE for none): an enemy's comes from its kind,...
s32 Battle_IsReviveEffect(s32 effectId)
Returns 1 for the revive effects (Revive, Quartz, Dew), which only work on a downed unit.
s32 Battle_CalcAttackDamage(s32 attack, s32 defense, s32 addedPower, s32 elementDifference)
Scales max(attack - defense, 0) + twice the action's added power by the elemental multiplier,...
s32 BattleFx_GetBaseSuccessRate(s32 effectId)
Returns the base chance, in percent, of effect effectId.
s32 BattleRandom(void)
The battle's random number generator, the same linear congruential one as Random16 with its own seed.
s32 BattleFx_RollSuccess(s32 caster, s32 target, s32 resistanceCategory, s32 effectId, s32 successScale)
Rolls whether effect effectId takes hold on target: it fails at once when there is nothing for it to ...
s32 Battle_CalcPsynergyPower(s32 power, s32 elementDifference, s32 powerMultiplier)
Returns the power of Psynergy: power times the multiplier for the element difference (power minus res...
s32 Equipment_GetUnleashRateBonus(struct BattleUnit *unit)
Returns the unleash chance, in percent, that a unit's equipment adds (ITEM_EFFECT_ADD_UNLEASH_CHANCE)...
u32 BattleRandomPercent(void)
Returns a battle random number from 0 to 99.
s32 GameFlag_Test(s32 flag)
Returns 1 when flag is set.
u8 GameFlag_DecrementByte(s32 flag)
Takes 1 from the byte flag is in, stopping at 0, and returns it.
u32 GameFlag_Toggle(s32 flag)
Flips flag and returns its new value.
s32 GameFlag_SetBit(s32 flag)
Sets flag and returns its byte number.
void GameFlag_SetNibble(s32 flag, s32 value)
Sets the four bits flag is in.
void GameFlag_SetByte(s32 flag, s32 value)
Sets the whole byte flag is in.
void GameFlag_ClearBit(s32 flag)
Clears flag.
s32 GameFlag_GetByte(s32 flag)
Returns the whole byte flag is in, a counter kept among the flags.
s32 GameFlag_GetNibble(u32 flag)
Returns the four bits flag is in (bit 2 of the number picks the half).
u8 GameFlag_IncrementByte(s32 flag)
Adds 1 to the byte flag is in, stopping at 255, and returns it.
void Unit_UpdateClass(s32 ownerId)
Works out a character's class again after its Djinn change, then its Psynergy list and its base eleme...
struct ClassDefinition * Class_GetDefinition(s32 classId)
Returns class classId's definition: its series, element requirements, stat multipliers and the Psyner...
s32 Class_Determine(s32 character, const u8 *djinn)
Returns the class a character has with djinn set: the series is chosen by its two strongest elements,...
s32 Enemy_GetAttackElement(struct BattleUnit *unit)
Returns the element an enemy attacks with, from its element preset.
u32 Unit_CalcBaseElements(s32 owner, s16 destination[4][2])
s32 Unit_GetElementLevel(s32 owner, s32 element)
Returns a unit's level in element (0 to 3).
s32 Unit_GetElementLevels(s32 record, const u8 *source, s32 output[4])
Writes ten times each element level to output: an enemy's from its element preset,...
s32 Class_GetSeries(s32 primaryElement, s32 secondaryElement)
Returns the class series of a character whose strongest element is primaryElement and second secondar...
s32 Djinn_AddToOwner(s32 owner, s32 element, s32 djinnIndex)
Gives Djinni djinnIndex of element to a unit: sets its bit in djinnAvailable and counts it.
s32 Djinn_GetAbilityId(u32 group, u32 index)
Returns the ability ID used when the Djinni is unleashed.
u32 Djinn_IsActive(s32 owner, s32 element, s32 djinnIndex)
Returns 1 when the Djinni is set on the unit.
const struct DjinnDefinition * Djinn_GetDefinition(u32 group, u32 index)
Returns the definition of Djinn index (0 to 19) of element group (0 to 3); anything out of range give...
s32 Djinn_AddToLeastLoadedOwner(s32 element, s32 djinn)
Gives a newly found Djinni to the party member holding the fewest Djinn who has room in that element,...
s32 Djinn_IsReady(s32 owner, s32 element, s32 djinnIndex)
Returns 1 when the unit holds the Djinni and it can be set: it is not set already,...
s32 Party_SumDjinnCounts(s32 element)
Returns how many Djinn of element the party holds, or of all elements for -1.
u32 Djinn_Deactivate(s32 owner, s32 element, s32 djinnIndex)
Takes a set Djinni off the unit and works out its class again.
s32 Djinn_Activate(s32 owner, s32 element, s32 djinnIndex)
Sets a ready Djinni on the unit, counts it and works out the unit's class again.
u32 * DjinnRecovery_AddStandby(u32 owner, u32 element, u32 djinnIndex)
Puts the owner's Djinni at the end of its side's list on standby (turns -1), moving it there if it wa...
s32 DjinnRecovery_Remove(s32 owner, s32 element, s32 djinnIndex)
Takes the Djinni off its side's standby and recovery list, closing the gap.
s32 Djinn_Transfer(s32 source, s32 element, s32 djinnIndex, s32 target)
Moves a Djinni from one unit to another, keeping it set or on standby.
s32 DjinnRecovery_CountStandby(u8 *counts)
Counts the party's Djinn on standby, by element into counts when it is given.
u8 Item_GetTargetMode(s32 itemId)
Returns how the action an item performs when used picks its targets.
s32 PartyInventory_Discard(s32 itemId)
Discards one itemId from whoever carries it first, as Inventory_Discard does; always returns 0.
s32 PartyInventory_HasSpace(void)
Returns 1 when the selected character or any party member has a free inventory slot.
struct ItemDefinition * Inventory_GetEquippedDefinition(struct BattleUnit *unit, s32 type)
Returns the definition of the unit's equipped item of type, or NULL.
s32 Inventory_FindEquipped(s32 owner, s32 type)
Returns the slot of the equipped item of type, or -1.
s32 Inventory_CheckDiscard(s32 owner, s32 slot)
Returns whether the item in slot may be dropped: 0 yes, -1 the slot is empty, -4 the item is indispen...
s32 Inventory_GetEquippedItem(struct BattleUnit *unit, s32 type)
Returns the id of the unit's equipped item of type, or 0.
s32 Inventory_GetQuantity(s32 owner, s32 slot)
Returns how many of the item in slot the unit carries (0 for an empty slot).
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.
s32 Item_IsCompatibleWithOwner(s32 unit, s32 item)
Returns 1 for an item that is not a weapon or armor, and for those whether the character can equip it...
s32 Inventory_Count(s32 owner)
Counts filled inventory slots up to the first empty slot; the inventory is kept closed up,...
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.
struct ItemDefinition * Item_GetDirect(s32 item)
Returns item item's definition; an inventory entry may be passed, its equipped and quantity bits are ...
s32 ItemCounter_Adjust(s32 index, s32 delta)
Adds delta to rare item counter index, kept between 0 and 99, and returns the new count (0 for an ind...
s32 PartyInventory_CountItem(s32 itemId)
Counts itemId across the party.
s32 Inventory_Repair(s32 owner, s32 slot)
Clears the broken mark of the item in slot; returns -1 for an empty slot.
s32 Inventory_Discard(s32 owner, s32 slot)
Removes one item as Inventory_Remove does, and puts a rare item back into circulation (its counter go...
s32 Inventory_Find(s32 owner, s32 itemId)
Returns the first slot holding itemId (any quantity, equipped or not), or -1.
s32 Inventory_CountItem(s32 owner, s32 itemId)
Counts matching nonstackable items, or the quantity in the first matching stack.
s32 PartyInventory_CountFreeSlots(void)
Returns the free inventory slots of the whole party.
s32 Inventory_Remove(s32 owner, s32 slot)
Takes one item out of slot: a stack shrinks by one (returns 1), a last item empties the slot and the ...
s32 PartyInventory_FindOwner(s32 itemId)
Returns who carries itemId, asking the selected character first, or -1.
s32 Item_GetEquipmentGroup(s32 itemId)
Returns what kind of thing an item is: 1 a weapon, 2 armor (armor, shields, helms,...
s32 PartyInventory_Add(s32 itemId)
Gives the item to the first party member with room.
s32 Item_AdjustCounter(s32 itemId, s32 delta)
Adds delta to the counter of a rare item; ordinary items have none.
s32 Inventory_Break(s32 owner, s32 slot)
Marks the item in slot broken; returns -1 for an empty slot.
s32 Item_CanOwnerEquipDirect(s32 owner, s32 item)
Returns whether the character can equip item: bit classId of the item's equipMask.
s32 PartyInventory_Remove(s32 itemId)
Removes one itemId from whoever carries it first; always returns 0.
u32 Unit_GetExperienceForLevel(s32 owner, s32 level)
Returns the experience a character needs for level (0 for level 0 and below); -1 for an enemy or a le...
s32 Unit_KnowsAction(s32 owner, s32 actionId)
Returns 1 when actionId is in the unit's action list.
UNUSED void Owner_LevelNoOp(void)
Unused reserved entry; keeps its place in the far-call table.
struct LevelUpResult * Owner_LevelUp(s32 owner, struct LevelUpResult *gains)
Raises a character one level (up to 99), adding to each base stat the growth between the two points o...
void Unit_LevelUpTo(s32 owner, s32 targetLevel)
Levels character owner up one level at a time until targetLevel, then recomputes its stats.
s32 Unit_RefreshPsynergy(s32 owner)
Rebuilds a character's Psynergy list: drops the actions its class and items gave, closes up the list,...
struct CharacterDefinition * Character_GetDefinition(s32 index)
Returns character index's definition: growth curves, starting level and equipment.
struct LevelUpResult * Unit_TryLevelUp(s32 owner, struct LevelUpResult *gains)
Levels the character up once if its experience reaches the next level.
s32 Unit_LearnPsynergy(s32 stateIndex, s32 value)
Teaches a character action value for good (or makes a class action permanent by clearing its marks),...
struct LevelUpResult * Unit_CheckLevelUp(s32 owner, struct LevelUpResult *gains)
Levels the character up once if it has the experience.
void Party_InitCharacters(void)
Sets up all eight characters for a new game: names from the message table, starting equipment equippe...
struct BattleAct * BattleAction_GetDirect(s32 actionId)
Returns the definition of action actionId (its low 14 bits); an id past the table gives the first.
s32 BattleUnitSet(s32 unitId, s32 enemyId, s32 suffix)
Fills battle unit unitId (0x80 to 0x86) with enemy enemyId: stats, name with its suffix letter,...
s32 Party_AdjustShopCredit(s32 amount)
s32 Party_CountActiveOwners(void)
Returns the number of party members, counted from game flags 0 to 7.
s32 Party_RemoveActiveOwner(s32 owner)
Takes character owner out of the party: clears its game flag and closes the gap it leaves in gGameSta...
s32 Summon_ListLearned(u8 *output)
Writes the summons whose bit is set in the first word of the party's Djinn table to output,...
const struct SummonDefinition * SummonDefinition_GetNear(u32 summonId)
Returns summon summonId's definition, or NULL past the sixteenth.
s32 Party_AdjustShopGifts(s32 amount)
s32 Party_AdjustCoins(s32 amount)
Adds amount to the party's coins, kept between 0 and 999999, and returns the new total.
s32 Party_AddActiveOwner(s32 owner)
Adds character owner to the end of the party: sets its game flag and appends it to gGameState....
s32 Party_ListActiveOwners(s16 *owners)
Writes the party members to owners, ending with 0xff, and returns how many there are.
void InventorySnapshot_Restore(void)
Gives back the inventories, shortcuts and party order InventorySnapshot_Save put aside,...
void Inventory_AddAndEquip(s32 owner, s32 itemId)
Gives a unit itemId and equips every exactly matching inventory entry.
void InventorySnapshot_Save(void)
Saves the first four characters' inventories, shortcuts and party order, then keeps only the Psynergy...
An ability's definition, a row of gBattleAction_DefinitionTable: its targeting, kind,...
A unit's elemental power and resistance in one element.
A unit in battle: a party member's or an enemy's stats, Psynergy, items, Djinn and ailments.
s16 hp
current HP, 0 when downed
A character's definition: the growth curves of its stats, its element bonus, starting level and start...
A class: its series, the element levels it needs, its stat multipliers and the abilities it teaches.
A Djinni: its ability and the stat bonuses it gives while set.
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
A level up's result: the level reached, an ability learned and the gain in each stat.
A summon: its name's message and the Djinn of each element it needs.
The integer types, TRUE, UNUSED and the fixed-address macros.
void UnitCalc(s32 owner)
Recomputes a unit's stats from its base stats, equipment, set Djinn, class and battle stat levels,...
const u8 * Enemy_GetDefinition(s32 selector)
Returns the definition of enemy selector - 8; an id past the first 250 gives the first.
void Party_RestorePpOfLitElements(void)
Restores the PP of each party member whose element group has a lit lighthouse: Venus or Mars for grou...
s16 Unit_AddPp(s32 owner, s32 delta)
Adds delta to the PP of unit owner, clamped to 0..maxPp, recomputes its gauges and returns the new PP...
void Party_RestoreHpPp(s32 cureConditions)
Restores every party member's HP and PP; with cureConditions 1 it also cures poison and haunting.
void Unit_SetPp(struct BattleUnit *unit, s32 pp)
Sets the unit's PP, clamped to 0..maxPp, and recomputes its HP and PP gauges.
void Runtime_CopyBytesDirectional(u8 *first, u8 *second, s32 count, s32 direction)
Copies count bytes from first to second when direction is set, and from second to first otherwise.
u32 Party_GetAverageLevel(void)
Returns the average level of the party members, rounded down (0 with no members).
struct BattleUnit * UnitGet(u32 owner)
Returns the unit record of owner: 0 to 7 are the playable characters in the game state,...
void * Djinn_GetRecoveryTable(s32 enemySide)
Returns the party's Djinn recovery bank (the standby Djinn and their turns to recover),...
void GameFlag_RefreshLureCap(void)
Sets FLAG_LURE_CAP when any party member has the Lure Cap (the one item with ITEM_EFFECT_LURE) equipp...
void UnitRatio(s32 owner)
Recomputes the HP and PP gauges of owner from its current HP and PP, so that UnitCalc keeps the same ...
UNUSED void Owner_RatioNoOp(void)
Unused reserved entry; keeps its place in the far-call table.
s32 Unit_AddHp(s32 owner, s32 delta)
Adds delta to the HP of unit owner, clamped to 0..maxHp, recomputes its gauges and returns the new HP...
void Party_BeginChildhood(void)
Sets FLAG_CHILDHOOD and recomputes Isaac, Garet and Jenna, whose classes then take their childhood fo...
void GameState_InitDefaults(void)
Clears the game-state header, scene state, flags and save stamp; sets a new game's defaults: Isaac al...
void Game_Restart(void)
Starts a new game: clears the game state and restarts at the opening.
void Unit_SetHp(struct BattleUnit *unit, s32 hp)
Sets the unit's HP, clamped to 0..maxHp, and recomputes its HP and PP gauges.
u32 Runtime_GetBuildStampTime(void)
Encodes the build-stamp time as ((hours * 16 + minutes) * 64 + seconds) with bit 12 set.
void Party_EndChildhood(void)
The party set-up after the prologue: flags, Jenna recomputed, Isaac and Garet healed with the Machete...