Skip to Content
The Alchemy Project

src/system/system_math.c

Random numbers, angles and square roots. More…

Included by system.c.

Macros

NameDescription
#defineATAN_ENTRIES 256The entries of MathTanTable in a quarter turn, which syAtan searches, the angle between neighbouring entries, and the tangent of the last one searched, in 8.8, beyond which syAtan gives a quarter turn.
#defineATAN_ENTRY_ANGLE (DEGtoANG(90) / ATAN_ENTRIES)
#defineATAN_RATIO_MAX 64362
#defineROOT_BITS 16The bits of a 32-bit value's square root.

Functions

NameDescription
Uint32syRandom (void)Advances the game's random number generator (the C library's classic linear congruential one), stores the new seed and returns its bits 8 to 23, 0 to 65535.
voidsyVectorAddPolarOffset (FIXED radius, ANGLE angle, POINT pos)Moves the point pos by radius in direction angle on the ground plane: x by the cosine, z by the sine.
ANGLEsyAtan (FIXED x, FIXED y)Returns the angle of the vector (x, y), from 0 to TRIG_TURN - 1, measured from the y axis: 0 along +y, a quarter turn along +x; (0, 0) gives 0.
Sint32sySquart (Sint32 value)Returns the integer square root of value, rounded down, a bit at a time; a negative value gives 0.
FIXEDsySquartFX (FIXED value)Square root of a 16.16 fixed-point value, in 16.16.
const Uint8 *syPaletteGetBasicSpriteColors (void)Returns the basic sprite palettes (BasicSpritePalettes).

Description

Random numbers, angles and square roots. Part of system.c.

Macros in detail

ATAN_ENTRIES

#define ATAN_ENTRIES 256

The entries of MathTanTable in a quarter turn, which syAtan searches, the angle between neighbouring entries, and the tangent of the last one searched, in 8.8, beyond which syAtan gives a quarter turn.

Referenced by syAtan().

Definition at line 34 of file system_math.c.

ATAN_ENTRY_ANGLE

#define ATAN_ENTRY_ANGLE (DEGtoANG(90) / ATAN_ENTRIES)

Referenced by syAtan().

Definition at line 35 of file system_math.c.

ATAN_RATIO_MAX

#define ATAN_RATIO_MAX 64362

Referenced by syAtan().

Definition at line 36 of file system_math.c.

ROOT_BITS

#define ROOT_BITS 16

The bits of a 32-bit value's square root.

Referenced by sySquart().

Definition at line 146 of file system_math.c.

Functions in detail

syRandom

Uint32 syRandom(void)

Advances the game's random number generator (the C library's classic linear congruential one), stores the new seed and returns its bits 8 to 23, 0 to 65535.

References RandWork.

Referenced by btAutoBattleRunApproachAttack(), btAutoBattleRunPsynergy(), btCameraShake(), btEffectConvertBackgroundToBlueRamp(), btEffectDrawStreaks(), btEffectRunAnnihilation(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunBladeRain(), btEffectRunBolt(), btEffectRunBoreas(), btEffectRunBreak(), btEffectRunBurstShower(), btEffectRunCastingImpact(), btEffectRunCriticalHit(), btEffectRunCurse(), btEffectRunCybele(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniEntrance(), btEffectRunDouse(), btEffectRunDragonCloud(), btEffectRunDragonFire(), btEffectRunDrain(), btEffectRunElementBurst(), btEffectRunElementPillar(), btEffectRunEruption(), btEffectRunFire(), btEffectRunFlurry(), btEffectRunFrost(), btEffectRunFroth(), btEffectRunGaia(), btEffectRunGatheringLights(), btEffectRunGround(), btEffectRunGrowingColumns(), btEffectRunHail(), btEffectRunHaunt(), btEffectRunHealingMotes(), btEffectRunHelmSplitter(), btEffectRunIce(), btEffectRunImpactBurst(), btEffectRunJudgment(), btEffectRunJupiter(), btEffectRunKirin(), btEffectRunLobbedShells(), btEffectRunMars(), btEffectRunMercury(), btEffectRunMoteFountain(), btEffectRunNeptune(), btEffectRunNereid() and 84 more.

Definition at line 6 of file system_math.c.

syVectorAddPolarOffset

void syVectorAddPolarOffset(FIXED radius, ANGLE angle, POINT pos)

Moves the point pos by radius in direction angle on the ground plane: x by the cosine, z by the sine.

References syMulFX() and sySin().

Referenced by fdActorGetCueMetatileAheadOfCurrent(), fdActorMoveByKeys(), fdActorMoveOnWorldMap(), fdActorScriptWanderNearHome(), fdActorUpdatePlayerControl(), fdActorWander(), fdEffectRunAngledApproachPhases(), fdEffectRunSparkEmitter(), fdEffectSpawnBurstParticleField(), fdEffectSpawnFallingParticles(), fdEffectUpdateDescendingOrbitActor(), fdEffectUpdateHaltParticle(), fdEffectUpdateMarsSpark(), fdEffectUpdateMoveHand(), fdEffectUpdateOutAndBack(), fdEffectUpdateRadialBurst(), fdEffectUpdateRadialSpread(), fdEffectUpdateRandomTargetParticle(), fdEffectUpdateShrinkingOrbitActor(), fdEffectUpdateSpiralParticle(), fdGetCollisionAheadOfLeader(), fdItemDisplayEmitSparkles(), fdItemDisplayShowItemInFront(), fdMapScreenUpdateMarkers(), fdPsynergyCatch(), fdPsynergyDouse(), fdPsynergyForce(), fdPsynergyFrost(), fdPsynergyGrowth(), fdPsynergyHalt(), fdPsynergySetupActorPair(), fdPsynergySteerLiftedTarget(), fdPsynergySteerPushedTarget(), fdPsynergyWhirlwind(), fdRetreatUpdateSpark(), fdRevealEmitSparkles(), fdSpriteViewerLayOutRing(), fdTreasureSpotMoveLeaderAway(), fdTryJumpForward(), mnSanctumUpdateBurstSparkle(), scAltmillerCaveHopOverPuddle(), scAltmillerCavePlaceLight(), scAltmillerCaveUpdateWallFragment(), scColosseumNavampaMatchRollLongLog(), scColossoFindActorAhead(), scColossoSparkleAroundPrize(), scCrossboneIsleSteppingStonesTryJumpAcrossPillar(), scCrossboneIsleTryHop(), scFieldVectorAddPolarOffsetFX(), scImilSwayAndSpark() and 12 more.

Definition at line 22 of file system_math.c.

syAtan

ANGLE syAtan(FIXED x, FIXED y)

Returns the angle of the vector (x, y), from 0 to TRIG_TURN - 1, measured from the y axis: 0 along +y, a quarter turn along +x; (0, 0) gives 0. It binary-searches the tangent table to ATAN_ENTRY_ANGLE.

References MathTanTable and Sint32.

Referenced by btEffectRunProcne(), btMotionReturnToSpot(), btObjectMake(), btStagingRunAttack(), btStagingRunPlainAttack(), btStagingRunPsynergyCast(), fdActorFaceActorById(), fdActorFindNearestFacingTarget(), fdActorScriptFaceWatched(), fdActorScriptWanderNearHome(), fdActorSystemProjectSprites(), fdActorTurnPairToFaceEachOther(), fdActorTurnTowardWatchedActor(), fdActorUpdateAllMotion(), fdActorUpdateAllOnField(), fdActorUpdatePlayerControl(), fdEffectUpdateMoveHand(), fdFindNearbyPsynergyTarget(), fdFindNearbyTalkTarget(), fdMapScreenUpdateMarkers(), fdParticleUpdateMotion(), fdPsynergyUpdateMindReadWave(), fdTreasureSpotMoveLeaderAway(), scAlpineCrossingLeaderFaceFeizhi(), scColossoUpdatePathOpponent(), scCrossboneIsleKeysFaceBaneTowardLeader(), scFuchinTempleFaceLeader(), scLogRoomsAFaceSuspectsTowardLeader(), scLogRoomsAUpdateCorneringChase(), scMercuryLighthouseEntranceMiaWatchesLeader(), scSanctumKeepFacingActor(), scTolbiKidStopForTarget(), scTurnTowardTarget(), scValeCaveFaceActorTowardLeader(), scValeTestFacing(), scVaultStopIfFacingNear() and scXianStopCarrierBeforeLeader().

Definition at line 41 of file system_math.c.

sySquart

Sint32 sySquart(Sint32 value)

Returns the integer square root of value, rounded down, a bit at a time; a negative value gives 0. Reached through the stub table.

References Sint32.

Definition at line 150 of file system_math.c.

sySquartFX

FIXED sySquartFX(FIXED value)

Square root of a 16.16 fixed-point value, in 16.16. The square root of the raw value is the result in 8.8, so the low eight bits are always 0.

References sySquartIWRAM().

Referenced by btElementGlowUpdateStarField(), fdActorMoveOnWorldMap(), fdActorSetMoveTarget(), fdActorUpdateAllOnField(), fdActorUpdatePlayerControl(), fdCameraFollowLeaderInBounds(), fdParticleUpdateMotion(), scMercuryLighthouseFollowLeader() and syMatrixBuildLookAt().

Definition at line 174 of file system_math.c.

syPaletteGetBasicSpriteColors

const Uint8 *syPaletteGetBasicSpriteColors(void)

Returns the basic sprite palettes (BasicSpritePalettes).

References BasicSpritePalettes.

Referenced by mnOpenBackdropScreen() and mnPartyStatusDrawBars().

Definition at line 185 of file system_math.c.