scroll.server/crates/logic/src/lib.rs
WiseDev 9f3ac3f0b9 use the client's square root, wrong answers and all
LogicMath::sqrt is a 256-entry table of floor(16*sqrt(i)) with a seed
picked by magnitude and one or two newton steps on top, and it is not
exact: above 2147441940 the seed overshoots and the single correction
cannot pull it back, so it answers 46341 where the true root is 46340,
and 65535 for INT_MAX.

that matters because the checksum is computed over whatever it returns.
an honest square root would be a permanent, invisible disagreement, so
this one is transcribed branch for branch - including the early -1 for
negatives and the INT_MAX special case - and our own converging root is
gone. checked against the exact root across the low range and the
boundaries, where the two agree, and at the top, where they must not.

distances now go through the saturating helper before the root, the way
the client does it, rather than being squared in i64 on the way in.
2026-08-23 14:21:57 +03:00

34 lines
1.5 KiB
Rust

extern crate self as logic;
pub mod battle;
pub mod commands;
pub mod data;
pub mod factory;
pub mod home;
pub mod logic_random;
pub mod messages;
pub mod logic_math;
pub mod model;
pub use logic_math::{logic_sqrt, SQRT_TABLE};
pub use commands::{
chest_source, command_type, CommandMeta, CommandOutcome, Execute, LogicBuyCardCommand,
LogicBuyChestCommand, LogicBuyResourcePackCommand, LogicClaimAchievementRewardCommand,
LogicClaimRewardCommand, LogicCollectFreeChestCommand, LogicCollectMultiWinChestCommand,
LogicCommand, LogicCommandHeader, LogicCommandManager, LogicCompleteTutorialBattleCommand,
LogicDoSpellCommand, LogicFuseSpellsCommand,
LogicHelpOpenedCommand, LogicMoveSpellCommand, LogicPageOpenedCommand,
LogicRefreshAchievementsCommand, LogicReward, LogicShopOpenedCommand,
LogicShopSeedChangedCommand, LogicSortCollectionCommand, LogicStartMatchmakeCommand,
LogicStartRewardClaimCommand, LogicSwapSpellsCommand, LogicUpdateLastShownLevelUpCommand,
};
pub use data::{
table, DataError, LogicArenaData, LogicData, LogicDataRef, LogicDataTable,
LogicDataTableResource, LogicDataTables, LogicGlobals, LogicRarityData, LogicResourceData,
LogicResourcePackData, LogicSpellData, LogicTreasureChestData, DATA_TABLE_RESOURCES,
TABLE_COUNT,
};
pub use factory::{scroll_message_registry, LogicScrollMessageFactory};
pub use home::{randomize_shop_items, LogicHomeMode};
pub use logic_random::LogicRandom;
pub use messages::*;
pub use model::*;
pub use titan::{GlobalId, LogicLong};