Alchemy
Loading...
Searching...
No Matches

math.c File Reference

Random numbers, angles and square roots. More...

Go to the source code of this file.

Functions

u32 Random16 (void)
 Advances the game's random number generator (the C library's classic linear congruential one), stores the new seed and returns 16 bits of it.
void Vector_AddPolarOffset (s32 radius, s32 angle, void *position)
 Moves the point position by radius in direction angle on the ground plane: x by the cosine, z by the sine.
s32 ArcTan2 (s32 x, s32 y)
 Returns the angle of the vector (x, y), in 1/65536 turns, measured from the y axis: 0 along +y, 0x4000 along +x.
s32 Math_IntegerSqrt (s32 value)
 Returns the integer square root of value, a bit at a time.
s32 FixedSqrt (s32 value)
 Square root of a 16.16 fixed-point value, in 16.16.
s32 Palette_GetBasicObjColors (void)

Detailed Description

Random numbers, angles and square roots.

Part of runtime.c, the runtime object, compiled only through it.

Definition in file math.c.

Function Documentation

◆ Random16()

u32 Random16 ( void )

Advances the game's random number generator (the C library's classic linear congruential one), stores the new seed and returns 16 bits of it.

Called throughout the game.

Definition at line 10 of file math.c.

Referenced by Battle_CollectPartyCommands(), BattleEffect_ApplyToTargets(), BattleEffect_RunFallbackObjectTransition(), BattleEffect_SetRandomTableValueOnObject(), BattleEffect_SpawnBurstParticleField(), BattleEffect_UpdatePhasedRadialParticle(), BattleEnemy_CalculateCoinReward(), BattleEnemy_CalculateExperienceReward(), BattleEscape_CheckSuccess(), BattleEscape_PlayRun(), BattleFormation_BuildEnemyList(), BattleFormation_SelectLevelMatchedCandidate(), BattleFx_CircleAnchor(), BattleFx_DrawStreaks(), BattleFx_InitializeStarField(), BattleFx_RunAnnihilation(), BattleFx_RunAtalanta(), BattleFx_RunBeamSequence(), BattleFx_RunBladeRain(), BattleFx_RunBolt(), BattleFx_RunBoreas(), BattleFx_RunBreak(), BattleFx_RunBurstScene(), BattleFx_RunBurstShower(), BattleFx_RunCastingImpact(), BattleFx_RunCurse(), BattleFx_RunCybele(), BattleFx_RunDjinnBeams(), BattleFx_RunDjinnHeal(), BattleFx_RunDjinniEntrance(), BattleFx_RunDouse(), BattleFx_RunDragonCloud(), BattleFx_RunDrain(), BattleFx_RunElementBurst(), BattleFx_RunElementPillar(), BattleFx_RunEruption(), BattleFx_RunFire(), BattleFx_RunFrost(), BattleFx_RunFroth(), BattleFx_RunGaia(), BattleFx_RunGatheringLights(), BattleFx_RunGround(), BattleFx_RunGrowingColumns(), BattleFx_RunHail(), BattleFx_RunHaunt(), BattleFx_RunHealingMotes(), BattleFx_RunHelmSplitter(), BattleFx_RunIce(), BattleFx_RunImpactBurst(), BattleFx_RunJudgment(), BattleFx_RunJupiter(), BattleFx_RunKirin(), BattleFx_RunLobbedShells(), BattleFx_RunMars(), BattleFx_RunMercury(), BattleFx_RunMoteFountain(), BattleFx_RunNeptune(), BattleFx_RunNereid(), BattleFx_RunPaletteParticles(), BattleFx_RunParticleStreams(), BattleFx_RunPlanetDiver(), BattleFx_RunPlasma(), BattleFx_RunPrism(), BattleFx_RunProcne(), BattleFx_RunProjectileVolley(), BattleFx_RunRagnarok(), BattleFx_RunRamses(), BattleFx_RunRay(), BattleFx_RunRingAndSparkScene(), BattleFx_RunRushingStrike(), BattleFx_RunShatteringOpening(), BattleFx_RunShiningStar(), BattleFx_RunSleep(), BattleFx_RunSparkEmitter(), BattleFx_RunSparkGroups(), BattleFx_RunSpire(), BattleFx_RunStatBoost(), BattleFx_RunStatReduction(), BattleFx_RunSwirlingStars(), BattleFx_RunTargetBursts(), BattleFx_RunTargetMotes(), BattleFx_RunTargetStrike(), BattleFx_RunThor(), BattleFx_RunThorn(), BattleFx_RunTitanBlade(), BattleFx_RunUndeadSword(), BattleFx_RunVenus(), BattleFx_RunVenusDjinnCapture(), BattleFx_RunVolcano(), BattleFx_RunWhirlwind(), BattleFx_SpawnFallingParticles(), BattleFx_StartItemBreak(), BattleFx_SteerLiftedTarget(), BattleFx_UpdateDriftingFallObject(), BattleFx_UpdateItemBreakFragment(), BattleFx_UpdateOrbitAndReturn(), BattleFx_UpdateRadialBurst(), BattleFx_UpdateRadialCamera(), BattleFx_UpdateRadialLaunch(), BattleFx_UpdateRadialMotion(), BattleFx_UpdateRadialSpread(), BattleFx_UpdateRandomTargetParticle(), BattleFx_UpdateStarField(), BattleFx_WanderAroundAnchor(), BattleFx_WipeCanvas(), BattleGroupRandom(), BattlePres_BuildOpponentEntries(), BattlePres_RunApproachAction(), BattlePres_RunEscape(), BattlePres_RunMosaicFadeOut(), BattlePresentation_BuildSortedUnitEntries(), BattlePresentation_RunPairedUnitTransition(), BattleTarget_ReplaceDefeated(), BattleTarget_SelectForAction(), BattleTarget_SelectRandomPosition(), Camera_ApplyShake(), DisplayTransition_UpdateScanlineTable(), Djinn_RunJupiterJoinEffect(), Djinn_RunMarsJoinEffect(), EffectSlot_Initialize(), Encounter_SelectEnemyGroup(), Event_SpawnObjectTable(), FieldEffect_UpdateSparkles(), FieldFx_RunDouse(), FieldFx_RunFrost(), FieldFx_RunGrowth(), FieldFx_RunRetreat(), FieldFx_RunWhirlwind(), FieldFx_SpawnBurstParticle(), FieldFx_SpawnRandomAngleTriplet(), FieldFx_UpdateGroundParticles(), FieldFx_UpdateLightning(), FieldMotes_Update(), Graphics_ConvertBackgroundToBlueRamp(), ItemDisplay_EmitSparkles(), ItemMenu_TryBreak(), LuckyDice_Run(), Map_UpdateLayerScroll(), Object_Wander(), Owner_LevelUp(), Random16(), ReelGame_Run(), ReelGame_RunFrame(), RevealMarker_EmitSparkles(), SaveState_SelectWriteSlot(), Scene_TalkToActor(), ScriptObject_WanderNearHome(), Shop_ResetEffects(), Shop_RunPartyMemberIconBurst(), SpawnHeavyImpactEffect(), System_GetLanguage(), UiWork_AnimateSpriteSlots(), UpdateRisingParticleBurst(), and WorldMap_UpdateView().

◆ Vector_AddPolarOffset()

void Vector_AddPolarOffset ( s32 radius,
s32 angle,
void * position )

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

The point is any three s32 coordinates x, y, z in a row (struct FieldPosition, struct EffectVector and others), so it takes a plain pointer. Byte offsets reach each coordinate without treating separate struct members as an array.

Definition at line 23 of file math.c.

Referenced by AltmillerCave_HopSelectedActor(), AltmillerCave_PlaceLight(), AltmillerCave_UpdateWallFragment(), BattleEffect_RunFallbackObjectTransition(), BattleEffect_SpawnBurstParticleField(), BattleEffect_UpdatePhasedRadialParticle(), BattleFx_RunAngledApproachPhases(), BattleFx_RunSparkEmitter(), BattleFx_SetupObjectPair(), BattleFx_SpawnFallingParticles(), BattleFx_StartRandomParticleEmitter(), BattleFx_SteerLiftedTarget(), BattleFx_SteerPushedTarget(), BattleFx_UpdateDescendingOrbitObject(), BattleFx_UpdateItemBreakFragment(), BattleFx_UpdateOrbitAndReturn(), BattleFx_UpdateRadialBurst(), BattleFx_UpdateRadialCamera(), BattleFx_UpdateRadialLaunch(), BattleFx_UpdateRadialMotion(), BattleFx_UpdateRadialSpread(), BattleFx_UpdateRandomTargetParticle(), BattleFx_UpdateShrinkingOrbitObject(), Colosso_FindActorAhead(), ColossoLogRollingStage_SpawnRandomSceneEffect(), ColossoRiver_SpawnRandomEffect(), ColossoWall_SpawnRandomSceneEffect(), CrossboneIsle_TryHop(), CrossboneIslePillarRooms_TryJumpAcrossPillar(), Effect_ConfigureSpawnedParticle(), Effect_UpdateParticlePosition(), Event_JumpAcrossGap(), Event_JumpToNextPillar(), Event_RollLongLog(), Field_GetCollisionAheadOfLeader(), Field_TryJumpForward(), FieldFx_RunCatch(), FieldFx_RunDouse(), FieldFx_RunForce(), FieldFx_RunFrost(), FieldFx_RunGrowth(), FieldFx_RunWhirlwind(), FieldFx_UpdateSpiralParticle(), FieldObject_UpdatePlayerControl(), FieldVector_AddPolarOffset(), Imil_RunIceSlide(), Imil_SwayAndSpark(), Imil_UpdateCountdownArc(), ItemDisplay_EmitSparkles(), KolimaForestBend_RollLog(), KolimaForestTree_UpdateOrbitSpark(), Map_BuildProbeRing(), Map_UpdateWorldMapMarkers(), Marker_MoveLeaderAway(), MercuryLighthouse_HopAcrossPool(), MercuryLighthouseAerie_JumpToPlatform(), Motion_SetTargetPositionFromMagnitudeAngle(), Object_GetTriggerTileAheadOfCurrent(), Object_MoveByKeys(), Object_MoveOnWorldMap(), Object_Wander(), RevealMarker_EmitSparkles(), SceneEffect_SpawnRandomizedBurst(), ScriptObject_WanderNearHome(), System_GetLanguage(), TretTreeInteriors_UpdateSwirlSpark(), VaultCave_OffsetActorRadially(), Vector_AddPolarOffset(), and WorldMap_UpdateBobbingMarker().

◆ ArcTan2()

◆ Math_IntegerSqrt()

s32 Math_IntegerSqrt ( s32 value)

Returns the integer square root of value, a bit at a time.

Reached through the far-call table.

Definition at line 126 of file math.c.

Referenced by Math_IntegerSqrt(), and System_GetLanguage().

◆ FixedSqrt()

◆ Palette_GetBasicObjColors()

s32 Palette_GetBasicObjColors ( void )