1#ifndef DW3_GAME_STATE_H
2#define DW3_GAME_STATE_H
68#define FLAG(group, id) ((group) << 8 | (id))
69#define PROGRESS(n) (0x6000 | (n))
70#define SPECIAL(id) (0x7000 | (id))
71#define PARTY_STAT(id) (0x7200 | (id))
72#define EVENT_BATTLE(id) (0x7400 | (id))
73#define CARD_BATTLE(opponent, kind) ((0x7600 + (kind) * 0x200) | (opponent))
76#define PLACE(n) (0x7E00 | ((n) - 1))
77#define PLACE_ARG(n) (0x7E00 | ((n) + 29))
80#define ITEM(kind, id) (0x8000 | (kind) << 9 | (id))
81#define START_EVENT(index) (0x9000 | (index))
82#define CARD(id) (0x9200 | (id))
83#define CODES_END 0xFFFF
134#define EQUIP_KIND_RIGHT_HAND 1
135#define EQUIP_KIND_LEFT_HAND 2
136#define EQUIP_KIND_EITHER_HAND 3
137#define EQUIP_KIND_HEAD 4
138#define EQUIP_KIND_BODY 5
139#define EQUIP_KIND_ACCESSORY 6
140#define EQUIP_KIND_BOTH_HANDS 7
141#define EQUIP_KIND_GROUP_ACCESSORY 8
195#define ITEM_USE_MENU 1
196#define ITEM_USE_BATTLE 2
197#define ITEM_CARD_PACK 4
218#define ITEM_KIND_KEY 1
219#define ITEM_KIND_USABLE 2
220#define ITEM_KIND_WEAPON 3
221#define ITEM_KIND_ARMOR 4
222#define ITEM_KIND_ACCESSORY 5
235#define IS_WEAPON_TYPE(type) ((u8)((type) - 2) < 13)
236#define IS_ARMOR_TYPE(type) ((u8)((type) - 15) < 6)
237#define IS_ACCESSORY_TYPE(type) ((u8)((type) - 21) < 4)
240#define PARTNER_ENTRY_COUNT 44
241#define PARTNER_SLOT_COUNT 3
244#define FIRST_ENTRY_ID 3
255#define SKILL_ID 0x1FFF
256#define SKILL_KNOWN 0x2000
257#define SKILL_MARKED 0x4000
258#define SKILL_LAST 0x8000
265#define CARD_COPIES_MAX 9
286#define STAT_STRENGTH 6
287#define STAT_DEFENSE 7
291#define STAT_CHARISMA 11
292#define STAT_RESISTS 12
364#define BATTLE_BLOCK_POISON 0
365#define BATTLE_BLOCK_PARALYSIS 1
366#define BATTLE_BLOCK_CONFUSION 2
367#define BATTLE_BLOCK_SLEEP 3
368#define BATTLE_BLOCK_KNOCK_OUT 4
369#define BATTLE_BLOCK_DRAIN 5
370#define BATTLE_BLOCK_STEAL 7
371#define BATTLE_BLOCK_LOWER_ATTACK 8
372#define BATTLE_BLOCK_LOWER_DEFENSE 9
373#define BATTLE_BLOCK_LOWER_SPEED 10
374#define BATTLE_BLOCK_RUN_AWAY 11
429#define MODE_NEW_GAME 0x2D7
430#define MODE_DECK_EDITOR 0x400
431#define MODE_PLAYER_NAME 0x500
432#define MODE_BATTLE 0x600
433#define MODE_CARD_GAME 0x700
434#define MODE_TRAINING 0xA00
435#define MODE_NAMING 0xB00
436#define MODE_CONTINUE 0xC00
437#define MODE_DIGI_LAB 0xD00
438#define MODE_TITLE 0xE00
439#define MODE_OPENING 0xE01
441#define MODE_BATTLE_MOVIE 0xE09
442#define MODE_ENDING 0xE0A
443#elif VERSION_EU || VERSION_JP
444#define MODE_OPENING_2 0xE02
446#define MODE_BATTLE_MOVIE 0xE0A
447#define MODE_ENDING 0xE0B
449#define MODE_ITEM_SHOP 0xF00
450#define MODE_STATUS 0x1000
451#define MODE_CARD_ALBUM 0x1200
452#define MODE_CARD_SHOP 0x1300
453#define MODE_BATTLE_REPORT 0x1400
454#define MODE_STAGE_SELECT 0x1500
455#define MODE_COUNTRY_SELECT 0x1600
459#define MODE_OVERLAY(mode) ((mode) & 0xFF00)
482#define MONEY_MAX 9999999
554#elif VERSION_EU || VERSION_JP
589#define GAME_SAVE_SIZE 0x26BC
590#elif VERSION_EU || VERSION_JP
591#define GAME_SAVE_SIZE 0x26C4
s32 checkProgressRange(s32 unused, s32 index)
Special conditions 0x30: whether GAME.progress is within PROGRESS_RANGES[index].
s32 findDigimon(s32 id)
The index in DIGIMON_DATA of Digimon id (the first 52 entries are searched), or -1.
s32 getPartyPartner(u32 index)
The partner id of party member index (its unlocked value - 3), or -1.
s32 addPartnerEntry(s32 partner, s32 id)
Gives a partner Digimon id at level 1; 0 if it has it already or has no room.
u16 * ITEM_LISTS[]
listItems' lists, 0-terminated
s32 testBit(u8 *bits, s32 index, s32 set)
Whether bit index of a bitset is set (set != 0) or clear (set 0)
DigimonData DIGIMON_DATA[]
55 entries: the 52 Digimon, then three placeholders (0x1D4-0x1D6)
s32 getItemCategory(s32 id)
The category of an item's type (ITEM_TYPE_CATEGORIES); an s32, as the menus that call it through ITEM...
void newGame(void)
Clears the save data and sets up a new game.
s32 checkPartner(u32 op, s32 arg)
Special conditions 0x10: tests partners (unlocked, in the party, levels) or unlocks one; the European...
s32 checkItemSet(s32 op, s32 arg)
Special condition 0x00: the player has every item of a set (the European and Japanese versions have a...
s32 checkCard(s32 card, s32 have)
Conditions 0x92: whether the player has card item (have != 0) or not.
void startCardBattle(s32 opponent, s32 kind)
Actions 0x76 and 0x78: a card battle (MODE_CARD_GAME) against an opponent.
DigimonData * getDigimon(s32 id)
The DIGIMON_DATA entry of Digimon id, or NULL.
void addCards(s32 card, s32 count)
Gives count copies of a card (up to CARD_COPIES_MAX) and marks it seen.
void applyActions(u16 *list)
Runs every (code, value) action until 0xFFFF.
void giveStarterDeck(void)
Gives the starter deck's cards and puts them in every deck.
PartnerStats * getPartnerStats(s32 partner)
A partner's name, stats and Digimon.
u8 STARTER_PARTIES[][3]
setParty's partners, by starter pack
#define PARTY_SIZE
How many partners the party holds.
s32 PARTY_STAT_THRESHOLDS[]
checkPartyStat's thresholds
s32 checkConditions(u16 *list)
All the (code, value) pairs until 0xFFFF must hold.
void requestMode(s32 mode, s32 arg)
Asks for a mode change, applied when main recreates the mode task.
s32 isItemKind(s32 item, s32 kind)
ITEM_FUNCS.isKind.
void resetPlayTime(void)
Sets the play time to zero.
s32 STARTER_DECK[40]
The cards of giveStarterDeck's deck.
u8 PROGRESS_RANGES[][2]
checkProgressRange's ranges of GAME.progress: { min, max }; 0x63 is past the end of the story
s32 checkWarpArg(s32 id, s32 mode)
Conditions 0x7E: the values a warp leaves for its stage (GAME.place for ids under 30,...
s32 findPartnerEntry(s32 slot, s32 id)
The index of Digimon id among a partner's entries, or -1.
s32 checkSpecialCondition(s32 id, s32 expected)
Runs SPECIAL_CONDITIONS entry id; whether its result equals expected
ItemInfo ITEMS[]
The items, from 1: getItem(id) is ITEMS[id - 1].
void updatePlayTime(void)
Turns the vsync-counted frames into seconds, minutes and hours, stopping at 999:59:59.
void computeStats(s32 partner, PartnerTotals *out)
A partner's stats with its equipment (and its equipment set bonus) added.
s32 checkMoney(s32 op, s32 item)
Special conditions 0x20: whether the player has MONEY_REQUIRED[item], or gives or takes an amount.
s32 getPartnerSlots(s32 partner, s16 *out)
Copies the ids of the Digimon a partner takes to battle; returns how many there are.
void applyAction(s32 code, s32 value)
Actions: the same flag groups (set to value), 0x70 special actions, 0x74 an overlay hook,...
BattleResult BATTLE_RESULT
s32 unequipItem(s32 slot, s32 item)
Takes item item off a partner (one of type 7 empties slots 2 and 3 both); 1 if it had it.
TechData TECHS[]
The techniques, from 1: technique n is TECHS[n - 1].
void clearBattleGauges(void)
Empties the battle gauges (BATTLE_SETUP.gauges, up to 1000 in a battle)
void initNewGameData(void)
The new game's player name, deck names, starter deck and partners.
s32 MONEY_REQUIRED[]
checkMoney's amounts, by its argument
s32 getPartyMember(u32 index)
The partner index of party member index, or -1.
SpecialCondition SPECIAL_CONDITIONS[]
checkSpecialCondition's conditions, up to an id of 0xFF
s32 getPrevMode(void)
The game mode before the current one.
s32 listPartnerEntries(s32 partner, u16 *out)
Copies the ids of a partner's Digimon, zero-filled; returns how many there are.
void setParty(s32 set)
Gives the party STARTER_PARTIES[set], unlocking its partners.
void changeCard(s32 card, s32 add)
Actions 0x92: gives or takes a copy of a card.
s16 EQUIP_SET_BONUSES[][6]
void addStat(s32 partner, u32 stat, s32 delta)
Adds to a partner's stat, kept within the same limits as setStat.
void setPartnerSlots(s32 partner, s16 *ids)
Picks the Digimon a partner takes to battle (-1 for ids it does not have)
EquipSet EQUIP_SETS[]
Each partner's equipment set and what wearing it whole adds (computeStats)
void addStatBonus(s16 *p, s32 stat, s32 delta)
Adds an equipment bonus to a stat of computeStats' result (7 raises every battle stat)
s32 getMode(void)
The current game mode.
#define DECK_SIZE
The cards of a deck, and the decks the player has.
s32 isModeChangePending(void)
Whether a mode change was requested.
s32 checkFlagCount(s32 unused, s32 mode)
Special conditions 0x40: group 0 as in the USA version; group 1 whether four flags of group 0x10 are ...
ItemInfo * getItem(s32 id)
The ITEMS entry of item id (from 1), or NULL.
StarterPack
The registration's starter packs (GAME.partySet, STARTER_PARTIES' rows): NAMEET's strings 10-12 name ...
void changeItem(s32 item, s32 add)
Actions 0x80-0x8E: gives an item (up to 99) or takes one, from the bag or else off a partner.
s32 showActorIcon(s32 op, s32 arg)
Special condition 0x50: the field actor's icon (FIELDSTG's task 0x16, FIELD_TASK_ICON) plays its anim...
s32 checkPartyStat(s32 index, s32 mode)
Conditions 0x72: whether the party's total of battle stat 5 reaches PARTY_STAT_THRESHOLDS[index] (mod...
s32 checkCondition(u16, u16)
Event scripts test conditions and run actions given as (code, value) pairs.
s32 listItems(s32 type, s16 *out)
Copies the items of ITEM_LISTS[type] the player has (with the top bit, equipped ones too); returns ho...
void commitMode(void)
Makes the requested mode current (main calls it before recreating the mode task)
void setStat(s32 partner, u32 stat, s16 value)
Sets a partner's stat, kept within 0-99 (level, TP), 0-9999 (HP, MP) or 0-999.
u8 ITEM_TYPE_CATEGORIES[]
The categories' strings, by item type.
GameState GAME
The save data, the game mode and the methods.
void setBit(u8 *bits, s32 index, s32 set)
Sets or clears bit index of a bitset.
void updateModeFlags(void)
On a mode change: clears the temporary flags if asked, and sets flags 0x10-0x12 after a card battle.
s32 setPartnerEntry(s32 partner, s32 id, PartnerEntry *in)
Overwrites a partner's Digimon id; returns its index, or -1.
s32 getModeArg(void)
The argument the current mode was requested with.
s32 getPartnerEntry(s32 partner, s32 id, PartnerEntry *out)
Copies a partner's Digimon id; returns its index, or -1.
s32 checkProgress(s32 value, s32 mode)
Conditions 0x60: whether GAME.progress is value (mode != 0) or not.
#define PARTNER_ENTRY_COUNT
The Digimon a partner can have, and the ones it takes to battle.
s32 checkItem(s32 index, s32 mode)
Conditions 0x80-0x8E: whether the player has item index, in the bag or equipped (mode !...
PartnerId
The partner Digimon (GAME.partners' index): partner i is DIGNAM's string i + 1, as the registration's...
GameFlags FLAGS_00
The flag bitset FLAGS_00 and the event functions.
Display, drawing layers, the drawing helpers and the screen fade (gfx/)
The story: the points of GAME.progress, and the event flags by name.
An accessory's (types 21-24, ACCESSORY_DATA)
u8 pad[3]
0 on every accessory; never read: ACCESSORY_DATA's entries are 0xC bytes
u8 kind
EQUIP_KIND_ACCESSORY or EQUIP_KIND_GROUP_ACCESSORY.
An armour's (types 15-20, ARMOR_DATA)
u8 padE[2]
0 on every armour
u8 evasion
added to the battle's (FIGHTSTG_computeStats)
u8 unused11
1 on every armour; nothing reads it
u8 pad12[2]
0 on every armour; never read: ARMOR_DATA's entries are 0x14 bytes
An enemy of a battle (FIELDSTG's encounter table points to these)
s16 strength
its stats and techniques' power, in 16ths
What the battle left for the report (BATTLE_RESULT, cleared by WFIGHTMN)
s16 member
the party member whose accessory adds money
s16 battle
row of STFGTREP_rewards
struct BattleResult::@9 partners[3]
u8 used[3]
the Digimon of each slot was used
s16 item
the item won, 0 for none
The next battle: FIELDSTG_startEncounter fills it (the stage select its first words),...
s32 debugUpDown
-1 to 3, set by the stage select (pad 2's up/down); nothing reads it
s32 prize
an item (BattleResult.item)
u8 ambushChance
a chance that WFIGHTMN scales by level
s32 randomBattles
the field starts random battles; the stage select toggles it (Select)
void(* clearGauges)(void)
s32 battle
the battle (BattleResult.battle)
s16 gauges[8]
filled in battle, up to 1000
s32 debugLeftRight
-1 to 7, set by the stage select (pad 2's left/right); nothing reads it
u8 encounterKind
Encounter.kind; only the enemies' condition 13 reads it.
u8 blocks[12]
by BATTLE_BLOCK_*: what the player can't do in the battle
s32 music
the battle's music
s32 stage
the battle's fight stage
s32 hasPrize
1: the battle always gives prize
Digimon definition (DIGIMON_DATA, 52 of them; the first 8 are the partners)
u8 statusResists[5]
against poison, paralysis, confusion, sleep and knock-outs
u8 nameId
string in file 0x4F
u8 resistGrowth[7]
1-5: how fast the gyms raise them
u8 pairPartner
the Digimon (from 1) it does pairTech with, 0 for none
u16 pairTech
its pair technique, with pairPartner
u8 blastForms[5]
what a blast turns a partner into (from 1), by its level's tier
u16 skills[7]
[1]-[6] are learnt at skillLevels
u8 expLevel
the level after which its exp grows faster
u8 expRate
a partner's exp per level, in tenths
u8 hpGrowth
what a partner's max HP grows by a level
u8 statGrowth[6]
columns of the growth tables
u8 knownLevels[5]
the levels that mark an entry's skills[0]-[4] known
u8 family
the family it fights as (BattleStats.family)
A partner's equipment set: the four items computeStats compares with equip[0-3].
FLAGS_00, the first flag bitset, followed by the event functions: FIELDSTG and the stages call them t...
void(* applyActions)(u16 *list)
s32 cardBattleWon
1 when the player won the card battle; updateModeFlags copies it to FLAG_CARD_BATTLE_WON
void(* applyAction)(s32 code, s32 value)
s32(* checkCondition)(u16 code, u16 value)
s32(* checkConditions)(u16 *list)
void(* updateModeFlags)(void)
The game state's methods (GAME.funcs)
void(* setStat)(s32 partner, u32 stat, s16 value)
void(* giveStarterDeck)(void)
s32(* getPartnerEntry)()
-1 if it hasn't the Digimon
void(* computeStats)(s32 partner, union PartnerTotals *out)
s32(* addPartnerEntry)()
(partner, id): 0 if it has it or has no room
void(* requestMode)(s32 mode, s32 arg)
void(* setPartnerSlots)()
s32(* getPartyMember)(u32 index)
void(* addCards)(s32 card, s32 count)
s32(* getPartnerSlots)()
(partner, s16 *out): the count
s32(* listPartnerEntries)()
(partner, s16 *out): the count
s32(* isModeChangePending)()
The game state (GAME): the first 0x26BC bytes are what newGame clears (the save data),...
s8 cards[0x13D]
counts, up to CARD_COPIES_MAX
u8 flags02[0x12]
flags02-flags40: the event flag groups 0x02-0x40 (checkCondition, applyAction), bitsets packed one af...
s8 items[0x193]
counts, up to 99
u16 place
where the last warp or trigger put the player (FieldBattles.id)
u8 checksum
a save's, of its bytes from 0x4 (STGMCARD_runSaves)
char name[0x18]
the player's
Partner partners[PARTNER_COUNT]
s32 unusedC
newGame sets it to -1; nothing reads it
u16 placeArg
the place's argument, which the stage reads with it
s32 party[3]
partner indices
u8 pad3
never read or written
s32 partySet
setParty's: the starter pack (enum StarterPack)
u8 pad1
never read or written
s32 battleSteps
to the next random battle, which each step lowers
u8 pad10[0x18]
never read or written
s32 stageSelectTop
the debug stage select's first line
s32 fieldMode
where the menu returns to
u8 version
a save's MEMCARD_SAVE_VERSION (stgmcard.h)
s32 randomGauges
gauge games left with random rows, reset with each new mode
u8 pad5[7]
never read or written
Vec2 fieldPos
the player's, there
What a usable item does (its ItemInfo.data, an ITEM_EFFECT_*)
u16 amount
the HP it heals, the gauge it fills, a boost in 128ths
u8 kind
1 heals amount HP, 2-17 raise a stat by up to amount (STSTATUS_useItem)
The item functions (ITEM_FUNCS)
s32(* getCategory)(s32 item)
getItemCategory
s32(* isKind)(s32 item, s32 kind)
ItemInfo.kind == kind.
s32(* list)(s32 type, s16 *out)
listItems
An item (ITEMS, ITEM_FUNCS)
u8 type
2-14 weapons, 15-20 armour, 21-24 accessories
u8 kind
ITEM_KIND_* (ITEM_FUNCS.isKind)
u16 sellPrice
0: cannot be sold
ItemRecord data
the type's record, or the usable items' effect
A partner Digimon's animation in a menu: up to seven sprite ids, -1 ending it early (the sprites are ...
One of a partner's Digimon (getPartnerEntry, setPartnerEntry)
s8 level
shown in the lab; 1 when added
s16 skills[6]
SKILL_ID and the flags below, 0 for none.
s16 id
FIRST_ENTRY_ID and up.
PartnerStats.equip as a whole: STSTATUS and STITSHOP save it with a struct copy before they equip an ...
A partner Digimon from its name on (Partner.info), as getPartnerStats gives it.
s16 slots[4]
PARTNER_SLOT_COUNT entries picked from entries[].
u8 lastBonus
the training whose bonus try last worked, 0 for none: its try can't work again at once
One of the eight partner Digimon.
u8 pad[4]
nothing reads or writes it
s32 battleDigivolve
an entry id, compared with the slots': the Digimon the battle starts it as, 0 for its own
s32 unlocked
partner id + 3, 0 while locked
GameState's play time, which a memory card save copies whole.
s16 maxed
stopped at 999:59:59
s32 frames
8.8, counted by the vsync callback
A special condition (SPECIAL(id)): checkSpecialCondition runs the check function of kind check >> 4 (...
PartnerStats' stats[] and the status[] after them as one block, which computeStats and STITSHOP_compu...
s16 penalties[3]
subtracted from STAT_STRENGTH, STAT_DEFENSE and STAT_SPEED
A technique (TECHS, from 1: technique n is TECHS[n - 1])
u8 scriptSound
its script's hit sound (BattleScript.sound)
u8 scriptEffect
its script's sprite effect (BattleScript.effect)
u8 effect
TECH_EFFECT_* (fightstg/battle.h), under TECH_EFFECT_FIRST none.
u8 family
FAMILY_FIRST and up, under it none.
u8 effectPower
the effect's strength (a boost's amount, a drain's 128ths)
u16 power
its damage, times the user's attack over the target's defense
u8 kind
3: heals the target
u8 element
ELEMENT_FIRST and up, under it none.
u8 icon
a frame of the menu sprites, from 0x37
u8 elementPower
how much the element adds, against the target's resistance
u8 scriptStage
its script's stage (BattleScript.stage)
u8 script
its script in the user's archive (BattleScript.index); 5 and 12 are special
ItemInfo.data's record for a weapon (types 2-14, WEAPON_DATA)
u8 statusChance
of the status its hits inflict
u16 amounts[2]
what it adds to stats[]
u8 family
its hits': FAMILY_FIRST and up, under it none
u8 hitEffect
1 none, 2 poison, 3 paralysis, 4 confusion, 6 knock-out, 8 drain, 11 criticals; nothing reads it: FIG...
u8 partners
1 << partner for each partner who can equip it (STSTATUS_canEquip)
u8 accuracy
added to the battle's (FIGHTSTG_computeStats)
u8 statusPower
the status's, or the critical bonus
s16 charisma
what it adds to STAT_CHARISMA (computeStats); armour and accessories too
ItemInfo.data's record, by ItemInfo.type.
What ItemInfo.data points to: a weapon's, an armour's or an accessory's record, or a usable item's ef...
WeaponData * weapon
WEAPON_DATA's, for ITEMS.
computeStats' result: the stats with the equipment added, by STAT_* or by name.
StatBlock block
the first 0x2C bytes, which computeStats copies whole
s16 tp
what the training's intensities cost
s32 spare
not filled: STGTRAIN's result keeps its yes/no answer here, 0 yes
s16 lowered[3]
taken from battle[0], [1] and [4]
s16 battle[6]
strength (raised by weapons), defense (by armour), spirit, wisdom, speed and charisma (by all equipme...
struct PartnerTotals::@10 fields