Skip to Content
The Alchemy Project

src/field/lucky_dice.c

The Lucky Dice minigame: its tables, its start, its helpers and its run.

Macros

NameDescription
#defineDICE_COINS_WINDOW_X BY_LANGUAGE(18, 18, 16, 17, 16, 17)Lucky Dice's layout, fitted to each language's text: the coins window at the top and its label, the help window (Throw / Quit) and the winnings window at the bottom with their text, in tiles for windows and pixels within them, and the centre of the result lettering in sprite x, which wraps at 512.
#defineDICE_COINS_WINDOW_WIDTH BY_LANGUAGE(11, 12, 14, 13, 14, 13)
#defineDICE_COINS_LABEL_X BY_LANGUAGE(48, 48, 53, 56, 53, 56)
#defineDICE_HELP_WINDOW_X BY_LANGUAGE(23, 22, 20, 20, 21, 22)The help window (Throw / Quit): its column and width, in tiles.
#defineDICE_HELP_WINDOW_WIDTH BY_LANGUAGE(7, 8, 10, 10, 9, 8)
#defineDICE_REOPENED_HELP_WINDOW_X SPANISH_OR(21, DICE_HELP_WINDOW_X)The help window reopened after a payout; in Spanish it is a tile narrower than the one Lucky Dice opens with, for the same two lines.
#defineDICE_REOPENED_HELP_WINDOW_WIDTH SPANISH_OR(9, DICE_HELP_WINDOW_WIDTH)
#defineDICE_WINNINGS_WINDOW_X BY_LANGUAGE(10, 8, 7, 9, 9, 9)The winnings window opens at this x less half its digits and is this width plus its digits; after the winnings label the number stands at DICE_WINNINGS_NUMBER_X, and the coins label at DICE_WINNINGS_COINS_X past the number's digits.
#defineDICE_WINNINGS_WINDOW_WIDTH BY_LANGUAGE(10, 13, 14, 13, 13, 13)
#defineDICE_WINNINGS_COINS_X BY_LANGUAGE(40, 56, 53, 64, 53, 64)
#defineDICE_WINNINGS_NUMBER_X BY_LANGUAGE(40, 56, 53, 56, 53, 56)
#defineDICE_RESULT_LABEL_CENTER_X JAPANESE_OR(640, 632)The centre of the result lettering, in sprite x, which wraps at 512.
#defineDICE_COUNT 2The dice thrown, and the sprites drawn for them: the dice, then their shadows.
#defineDICE_RESULT_COUNT 4
#defineDICE_NUMBER_REVEAL_TICKS 5The result: one number every 5 ticks, then 20 ticks in the lettering, the winnings, and A to go on; the payout closes 15 ticks after it starts.
#defineDICE_RESULT_TICKS 20
#defineDICE_PAYOUT_TICKS 15
#defineDICE_TOUCH_DISTANCE 50Two dice whose centres come closer than this push each other apart.
#defineDICE_NUMBER_TILES 152Where each picture's sprite tiles start, in OAM's 32-byte steps (two to a 256-colour tile): the rolling die's views from 0, its shadow at DICE_SHADOW_TILE (field/field.h), the big numbers (the result's lettering counted on from them), the aiming hand, the Perfect Bonus sign, its 3, 5 and times sign, and the lucky numbers' small faces.
#defineDICE_AIM_MARKER_TILE 344
#defineDICE_BONUS_SIGN_TILE 856
#defineDICE_THREE_TILE 920
#defineDICE_FIVE_TILE 928
#defineDICE_TIMES_TILE 936
#defineDICE_LUCKY_NUMBER_TILES 944
#defineDICE_PERFECT_PAYOUT 5Four alike pays five times the bet; four of a lucky number pays three or five times that, the multipliers drawn beside the two lucky numbers.
#defineDICE_FIRST_LUCKY_MULTIPLIER 3
#defineDICE_SECOND_LUCKY_MULTIPLIER 5
#defineDICE_FLASH_TICKS 60A win flashes a die (both for four alike) for this many ticks.
#defineDICE_PERFECT_FLASH_TICKS 120
#defineDICE_BOARD_PALETTE_COLORS 224The board's picture begins with its 224 colours, the sprites' with all 256, each before its tiles.
#defineDICE_SPRITES_PALETTE_COLORS 256

Enumerations

NameDescription
enumLUCKY_DICE_HELP_MESSAGE { DICE_HELP_THROW, DICE_HELP_QUIT }The help window's two lines, as messages after MsgLuckyDiceCoins.
enumDICE_RESULT { DICE_RESULT_NONE, DICE_RESULT_PERFECT, DICE_RESULT_TRIPLE, D … }What a throw's four numbers make, in the rules' words: "If two numbers match on either the dice or the table... it's called a pair, and you don't win or lose anything.
enumLUCKY_DICE_STATE { LUCKY_DICE_AIM, LUCKY_DICE_ROLL, LUCKY_DICE_RESULT, LUCKY_DI … }What the Lucky Dice screen is doing.

Functions

NameDescription
Sint32fdLuckyDiceStart (void)Starts the Lucky Dice minigame: leaves only the sprites on screen, starts the music and plays until the player quits.
voidfdCameraResetViewDefaults (void)Puts the 3D camera back at its starting view: at the origin, unturned, pitched to 152/256 of a turn and 510 pixels away, following nothing.
Sint32fdFixedPointMultiplyQ8 (Sint32 a, Sint32 b)Unused: multiplies two 8.8 fixed-point values, rounding toward zero.
Sint16fdFixedPointDivQ8 (Sint16 numerator, Sint16 denominator)Unused: divides two 8.8 fixed-point values.
Sint16fdFixedPointReciprocal (Sint16 value)Unused: the reciprocal of an 8.8 fixed-point value.
Sint32fdLuckyDiceScaleRGB555Buffer (Uint16 *src, Uint16 *dest, FIXED scale, Sint32 count)Copies count RGB555 colours from source to destination with each channel multiplied by scale (16.16: 0 is black, toFIXED(1) unchanged), for fades.
voidfdLuckyDiceRun (void)Runs the Lucky Dice minigame until the player quits or cannot afford a throw.

Variables

NameDescription
const Sint32LuckyDiceUnusedSigns []Unused: a table of signs.
const Uint8LuckyDiceLabelCounts []How many sprites each result's lettering takes, 32 pixels each.
const Uint8LuckyDiceLabelTiles []The first tile of each result's lettering, in 16-pixel steps from DICE_NUMBER_TILES.
const Uint8LuckyDiceFaceTiles []The die face tile at each step of its roll: one for each DICE_ROLL_PER_TILE of the roll angle (variant), three to a face.
const Sint16LuckyDiceFaceHeights []The board's rows by depth: a die at rest is in the first row whose value its z (16.16 pixels) exceeds, -32767 taking the rest.

Description

The Lucky Dice minigame: its tables, its start, its helpers and its run.

Macros in detail

DICE_COINS_WINDOW_X

#define DICE_COINS_WINDOW_X BY_LANGUAGE(18, 18, 16, 17, 16, 17)

Lucky Dice's layout, fitted to each language's text: the coins window at the top and its label, the help window (Throw / Quit) and the winnings window at the bottom with their text, in tiles for windows and pixels within them, and the centre of the result lettering in sprite x, which wraps at 512.

Referenced by fdLuckyDiceRun().

Definition at line 193 of file lucky_dice.c.

DICE_COINS_WINDOW_WIDTH

#define DICE_COINS_WINDOW_WIDTH BY_LANGUAGE(11, 12, 14, 13, 14, 13)

Referenced by fdLuckyDiceRun().

Definition at line 194 of file lucky_dice.c.

DICE_COINS_LABEL_X

#define DICE_COINS_LABEL_X BY_LANGUAGE(48, 48, 53, 56, 53, 56)

Referenced by fdLuckyDiceRun().

Definition at line 195 of file lucky_dice.c.

DICE_HELP_WINDOW_X

#define DICE_HELP_WINDOW_X BY_LANGUAGE(23, 22, 20, 20, 21, 22)

The help window (Throw / Quit): its column and width, in tiles.

Referenced by fdLuckyDiceRun().

Definition at line 198 of file lucky_dice.c.

DICE_HELP_WINDOW_WIDTH

#define DICE_HELP_WINDOW_WIDTH BY_LANGUAGE(7, 8, 10, 10, 9, 8)

Referenced by fdLuckyDiceRun().

Definition at line 199 of file lucky_dice.c.

DICE_REOPENED_HELP_WINDOW_X

#define DICE_REOPENED_HELP_WINDOW_X SPANISH_OR(21, DICE_HELP_WINDOW_X)

The help window reopened after a payout; in Spanish it is a tile narrower than the one Lucky Dice opens with, for the same two lines.

Referenced by fdLuckyDiceRun().

Definition at line 203 of file lucky_dice.c.

DICE_REOPENED_HELP_WINDOW_WIDTH

#define DICE_REOPENED_HELP_WINDOW_WIDTH SPANISH_OR(9, DICE_HELP_WINDOW_WIDTH)

Referenced by fdLuckyDiceRun().

Definition at line 204 of file lucky_dice.c.

DICE_WINNINGS_WINDOW_X

#define DICE_WINNINGS_WINDOW_X BY_LANGUAGE(10, 8, 7, 9, 9, 9)

The winnings window opens at this x less half its digits and is this width plus its digits; after the winnings label the number stands at DICE_WINNINGS_NUMBER_X, and the coins label at DICE_WINNINGS_COINS_X past the number's digits.

Referenced by fdLuckyDiceRun().

Definition at line 210 of file lucky_dice.c.

DICE_WINNINGS_WINDOW_WIDTH

#define DICE_WINNINGS_WINDOW_WIDTH BY_LANGUAGE(10, 13, 14, 13, 13, 13)

Referenced by fdLuckyDiceRun().

Definition at line 211 of file lucky_dice.c.

DICE_WINNINGS_COINS_X

#define DICE_WINNINGS_COINS_X BY_LANGUAGE(40, 56, 53, 64, 53, 64)

Referenced by fdLuckyDiceRun().

Definition at line 212 of file lucky_dice.c.

DICE_WINNINGS_NUMBER_X

#define DICE_WINNINGS_NUMBER_X BY_LANGUAGE(40, 56, 53, 56, 53, 56)

Referenced by fdLuckyDiceRun().

Definition at line 213 of file lucky_dice.c.

DICE_RESULT_LABEL_CENTER_X

#define DICE_RESULT_LABEL_CENTER_X JAPANESE_OR(640, 632)

The centre of the result lettering, in sprite x, which wraps at 512.

Referenced by fdLuckyDiceRun().

Definition at line 216 of file lucky_dice.c.

DICE_COUNT

#define DICE_COUNT 2

The dice thrown, and the sprites drawn for them: the dice, then their shadows.

Referenced by fdLuckyDiceRun().

Definition at line 220 of file lucky_dice.c.

DICE_RESULT_COUNT

#define DICE_RESULT_COUNT 4

Referenced by fdLuckyDiceRun().

Definition at line 221 of file lucky_dice.c.

DICE_NUMBER_REVEAL_TICKS

#define DICE_NUMBER_REVEAL_TICKS 5

The result: one number every 5 ticks, then 20 ticks in the lettering, the winnings, and A to go on; the payout closes 15 ticks after it starts.

Referenced by fdLuckyDiceRun().

Definition at line 224 of file lucky_dice.c.

DICE_RESULT_TICKS

#define DICE_RESULT_TICKS 20

Referenced by fdLuckyDiceRun().

Definition at line 225 of file lucky_dice.c.

DICE_PAYOUT_TICKS

#define DICE_PAYOUT_TICKS 15

Referenced by fdLuckyDiceRun().

Definition at line 226 of file lucky_dice.c.

DICE_TOUCH_DISTANCE

#define DICE_TOUCH_DISTANCE 50

Two dice whose centres come closer than this push each other apart.

Referenced by fdLuckyDiceRun().

Definition at line 229 of file lucky_dice.c.

DICE_NUMBER_TILES

#define DICE_NUMBER_TILES 152

Where each picture's sprite tiles start, in OAM's 32-byte steps (two to a 256-colour tile): the rolling die's views from 0, its shadow at DICE_SHADOW_TILE (field/field.h), the big numbers (the result's lettering counted on from them), the aiming hand, the Perfect Bonus sign, its 3, 5 and times sign, and the lucky numbers' small faces.

Referenced by fdLuckyDiceRun().

Definition at line 235 of file lucky_dice.c.

DICE_AIM_MARKER_TILE

#define DICE_AIM_MARKER_TILE 344

Referenced by fdLuckyDiceRun().

Definition at line 236 of file lucky_dice.c.

DICE_BONUS_SIGN_TILE

#define DICE_BONUS_SIGN_TILE 856

Referenced by fdLuckyDiceRun().

Definition at line 237 of file lucky_dice.c.

DICE_THREE_TILE

#define DICE_THREE_TILE 920

Referenced by fdLuckyDiceRun().

Definition at line 238 of file lucky_dice.c.

DICE_FIVE_TILE

#define DICE_FIVE_TILE 928

Referenced by fdLuckyDiceRun().

Definition at line 239 of file lucky_dice.c.

DICE_TIMES_TILE

#define DICE_TIMES_TILE 936

Referenced by fdLuckyDiceRun().

Definition at line 240 of file lucky_dice.c.

DICE_LUCKY_NUMBER_TILES

#define DICE_LUCKY_NUMBER_TILES 944

Referenced by fdLuckyDiceRun().

Definition at line 241 of file lucky_dice.c.

DICE_PERFECT_PAYOUT

#define DICE_PERFECT_PAYOUT 5

Four alike pays five times the bet; four of a lucky number pays three or five times that, the multipliers drawn beside the two lucky numbers.

Referenced by fdLuckyDiceRun().

Definition at line 244 of file lucky_dice.c.

DICE_FIRST_LUCKY_MULTIPLIER

#define DICE_FIRST_LUCKY_MULTIPLIER 3

Referenced by fdLuckyDiceRun().

Definition at line 245 of file lucky_dice.c.

DICE_SECOND_LUCKY_MULTIPLIER

#define DICE_SECOND_LUCKY_MULTIPLIER 5

Referenced by fdLuckyDiceRun().

Definition at line 246 of file lucky_dice.c.

DICE_FLASH_TICKS

#define DICE_FLASH_TICKS 60

A win flashes a die (both for four alike) for this many ticks.

Referenced by fdLuckyDiceRun().

Definition at line 248 of file lucky_dice.c.

DICE_PERFECT_FLASH_TICKS

#define DICE_PERFECT_FLASH_TICKS 120

Referenced by fdLuckyDiceRun().

Definition at line 249 of file lucky_dice.c.

DICE_BOARD_PALETTE_COLORS

#define DICE_BOARD_PALETTE_COLORS 224

The board's picture begins with its 224 colours, the sprites' with all 256, each before its tiles.

Referenced by fdLuckyDiceRun().

Definition at line 253 of file lucky_dice.c.

DICE_SPRITES_PALETTE_COLORS

#define DICE_SPRITES_PALETTE_COLORS 256

Referenced by fdLuckyDiceRun().

Definition at line 254 of file lucky_dice.c.

Enumerations in detail

LUCKY_DICE_HELP_MESSAGE

enum LUCKY_DICE_HELP_MESSAGE

The help window's two lines, as messages after MsgLuckyDiceCoins.

EnumeratorValueDescription
DICE_HELP_THROW10":Throw" after its button
DICE_HELP_QUIT11":Quit" after its button

Definition at line 15 of file lucky_dice.c.

DICE_RESULT

enum DICE_RESULT

What a throw's four numbers make, in the rules' words: "If two numbers match on either the dice or the table... it's called a pair, and you don't win or lose anything. Two pair doubles your money. Triple matches triple your money. Four of a kind is perfect, and you win five times your bet." Every result has its lettering (hand_titles.png: "Perfect!!!", "Triple!", "Two Pair!" and "One Pair!"), numbered from 0.

EnumeratorValueDescription
DICE_RESULT_NONE-1no two numbers alike: the bet is lost
DICE_RESULT_PERFECTall four alike: DICE_PERFECT_PAYOUT times the bet
DICE_RESULT_TRIPLEthree alike: three times the bet
DICE_RESULT_TWO_PAIRtwo pairs: twice the bet
DICE_RESULT_ONE_PAIRone pair: the bet back

Definition at line 27 of file lucky_dice.c.

LUCKY_DICE_STATE

enum LUCKY_DICE_STATE

What the Lucky Dice screen is doing.

EnumeratorValueDescription
LUCKY_DICE_AIMthe dice wait to be thrown; Up and Down raise them
LUCKY_DICE_ROLLthe dice fly, bounce and settle
LUCKY_DICE_RESULTthe four numbers and the result are shown
LUCKY_DICE_PAYOUTthe winnings move into the coins

Definition at line 257 of file lucky_dice.c.

Functions in detail

fdLuckyDiceStart

Sint32 fdLuckyDiceStart(void)

Starts the Lucky Dice minigame: leaves only the sprites on screen, starts the music and plays until the player quits. Returns 0.

References fdLuckyDiceRun(), Sint32 and sySoundPlayStub().

Definition at line 74 of file lucky_dice.c.

fdCameraResetViewDefaults

void fdCameraResetViewDefaults(void)

Puts the 3D camera back at its starting view: at the origin, unturned, pitched to 152/256 of a turn and 510 pixels away, following nothing.

References ProjectionWork, Sint32, syCalcPoint(), syDivFX(), syInitMatrix(), syMatrixTranslateVector(), syRotX(), syRotY() and sySetScreenDist().

Referenced by fdLuckyDiceRun().

Definition at line 84 of file lucky_dice.c.

fdFixedPointMultiplyQ8

Sint32 fdFixedPointMultiplyQ8(Sint32 a, Sint32 b)

Unused: multiplies two 8.8 fixed-point values, rounding toward zero.

References Sint32.

Definition at line 113 of file lucky_dice.c.

fdFixedPointDivQ8

Sint16 fdFixedPointDivQ8(Sint16 numerator, Sint16 denominator)

Unused: divides two 8.8 fixed-point values.

Definition at line 137 of file lucky_dice.c.

fdFixedPointReciprocal

Sint16 fdFixedPointReciprocal(Sint16 value)

Unused: the reciprocal of an 8.8 fixed-point value.

Definition at line 143 of file lucky_dice.c.

fdLuckyDiceScaleRGB555Buffer

Sint32 fdLuckyDiceScaleRGB555Buffer(Uint16 *src, Uint16 *dest, FIXED scale, Sint32 count)

Copies count RGB555 colours from source to destination with each channel multiplied by scale (16.16: 0 is black, toFIXED(1) unchanged), for fades.

References Sint32.

Referenced by fdLuckyDiceRun().

Definition at line 150 of file lucky_dice.c.

fdLuckyDiceRun

void fdLuckyDiceRun(void)

Runs the Lucky Dice minigame until the player quits or cannot afford a throw. Each throw costs ten coins per level of the party's average.

References BgScrollWork, fdCameraResetViewDefaults(), fdLuckyDiceScaleRGB555Buffer(), gmPartyAdjustCoinsStub(), gmPartyGetAverageLevelStub(), LuckyDiceFaceHeights, LuckyDiceFaceTiles, LuckyDiceLabelCounts, LuckyDiceLabelTiles, MainRoutineStateWork, mnTextDrawMessageAsTilesStub(), mnTextDrawNumberInWindowStub(), mnWindowCloseStub(), mnWindowCreateStub(), mnWindowSystemInitFieldStub(), MsgLuckyDiceCoins, OamCopyEnabled, PerWork, scFieldDecompressTaggedLZ(), Sint32, syConvert3Dto2D(), syCos(), syDMAXCopy(), syHeapSlotAllocate(), syHeapSlotAllocateEWRAM(), syHeapSlotRelease(), syInitEvent(), syInitMatrix(), syLookAtLoad(), syRandom(), syResourceGetTableEntry(), syResourceReservedNoOperation(), sySin(), sySoundPlayStub(), sySquartIWRAM() and sySynch().

Referenced by fdLuckyDiceStart().

Definition at line 267 of file lucky_dice.c.

Variables in detail

LuckyDiceUnusedSigns

const Sint32 LuckyDiceUnusedSigns[]

Unused: a table of signs.

References Sint32.

Definition at line 37 of file lucky_dice.c.

LuckyDiceLabelCounts

const Uint8 LuckyDiceLabelCounts[]

How many sprites each result's lettering takes, 32 pixels each.

Referenced by fdLuckyDiceRun().

Definition at line 40 of file lucky_dice.c.

LuckyDiceLabelTiles

const Uint8 LuckyDiceLabelTiles[]

The first tile of each result's lettering, in 16-pixel steps from DICE_NUMBER_TILES.

Referenced by fdLuckyDiceRun().

Definition at line 49 of file lucky_dice.c.

LuckyDiceFaceTiles

const Uint8 LuckyDiceFaceTiles[]

The die face tile at each step of its roll: one for each DICE_ROLL_PER_TILE of the roll angle (variant), three to a face.

Referenced by fdLuckyDiceRun().

Definition at line 65 of file lucky_dice.c.

LuckyDiceFaceHeights

const Sint16 LuckyDiceFaceHeights[]

The board's rows by depth: a die at rest is in the first row whose value its z (16.16 pixels) exceeds, -32767 taking the rest.

Referenced by fdLuckyDiceRun().

Definition at line 70 of file lucky_dice.c.