docs: inventory removable Ref compatibility shims
This commit is contained in:
@@ -150,11 +150,13 @@ const processIncomeForNation = (
|
||||
: getRiceIncome(incomeContext, nationCities, officerCounts, nation.capitalCityId ?? 0, nation.level) +
|
||||
getWallIncome(incomeContext, nationCities, officerCounts, nation.capitalCityId ?? 0, nation.level);
|
||||
|
||||
// REF-COMPAT:BEGIN ref-income-preflush-fraction
|
||||
// Ref calculates the payout ratio from the pre-persistence income value.
|
||||
// Half-unit income (for example 943.5) is therefore not rounded before
|
||||
// salaries are distributed, even though the integer nation column is
|
||||
// rounded when the final state is flushed to MariaDB.
|
||||
const incomeValue = income;
|
||||
// REF-COMPAT:END ref-income-preflush-fraction
|
||||
const originOutcome = getOutcome(100, nationGenerals);
|
||||
const bill = resolveNationBill(nation);
|
||||
const outcome = Math.round((bill / 100) * originOutcome);
|
||||
|
||||
@@ -4,7 +4,9 @@ import { LogCategory, LogFormat, LogScope, type MapDefinition } from '@sammo-ts/
|
||||
import type { InMemoryTurnWorld } from './inMemoryWorld.js';
|
||||
import type { MonthlyEventActionHandler } from './monthlyEventHandler.js';
|
||||
|
||||
// REF-COMPAT:BEGIN ref-int-column-write-rounding
|
||||
const roundLegacyIntegerColumn = (value: number): number => Math.round(value);
|
||||
// REF-COMPAT:END ref-int-column-write-rounding
|
||||
|
||||
const resolveOfficerCity = (meta: Record<string, unknown>): number => {
|
||||
const camel = meta.officerCity;
|
||||
@@ -82,9 +84,11 @@ export const createUpdateCitySupplyHandler = (options: {
|
||||
wall: roundLegacyIntegerColumn(city.wall * 0.9),
|
||||
meta: {
|
||||
...city.meta,
|
||||
// REF-COMPAT:BEGIN ref-mariadb-float-boundary
|
||||
// 레거시 FLOAT column에 SQL 곱셈 결과가 먼저 저장된 뒤
|
||||
// 민심 30 threshold를 판정하므로 float32 양자화를 보존한다.
|
||||
trust: Math.fround(trust * 0.9),
|
||||
// REF-COMPAT:END ref-mariadb-float-boundary
|
||||
},
|
||||
});
|
||||
if (damaged) {
|
||||
|
||||
@@ -67,7 +67,9 @@ const resolveHiddenSeed = (world: InMemoryTurnWorld): string | number => {
|
||||
return typeof rawSeed === 'string' || typeof rawSeed === 'number' ? rawSeed : String(rawSeed);
|
||||
};
|
||||
|
||||
// REF-COMPAT:BEGIN ref-int-column-write-rounding
|
||||
const roundLegacyIntegerColumn = (value: number): number => Math.round(value);
|
||||
// REF-COMPAT:END ref-int-column-write-rounding
|
||||
|
||||
export const createRaiseDisasterHandler = (options: {
|
||||
getWorld: () => InMemoryTurnWorld | null;
|
||||
@@ -134,7 +136,9 @@ export const createRaiseDisasterHandler = (options: {
|
||||
const securityRatio = clamp(city.security / city.securityMax / 0.8, 0, 1);
|
||||
const affectRatio = isGood ? 1.01 + securityRatio * 0.04 : 0.8 + securityRatio * 0.15;
|
||||
const trust = typeof city.meta.trust === 'number' ? city.meta.trust : 0;
|
||||
// REF-COMPAT:BEGIN ref-mariadb-float-boundary
|
||||
const storedTrust = Math.fround(isGood ? Math.min(trust * affectRatio, 100) : trust * affectRatio);
|
||||
// REF-COMPAT:END ref-mariadb-float-boundary
|
||||
world.updateCity(city.id, {
|
||||
state: picked.stateCode,
|
||||
population: roundLegacyIntegerColumn(
|
||||
|
||||
@@ -7,10 +7,12 @@ import type { InMemoryTurnWorld, TurnCalendarHandler } from './inMemoryWorld.js'
|
||||
const MAX_AVAILABLE_WAR_SETTING_COUNT = 10;
|
||||
const MONTHLY_AVAILABLE_WAR_SETTING_INCREMENT = 2;
|
||||
|
||||
// REF-COMPAT:BEGIN ref-decimal-half-stabilization
|
||||
export const roundLegacyNationPowerValue = (value: number): number => {
|
||||
const stabilized = Number(value.toPrecision(15));
|
||||
return stabilized >= 0 ? Math.floor(stabilized + 0.5) : Math.ceil(stabilized - 0.5);
|
||||
};
|
||||
// REF-COMPAT:END ref-decimal-half-stabilization
|
||||
|
||||
const readNumber = (value: unknown, fallback = 0): number => {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
|
||||
@@ -7,12 +7,14 @@ import { resolveAppliedNationRate } from './nationTaxRate.js';
|
||||
|
||||
type SemiAnnualResource = 'gold' | 'rice';
|
||||
|
||||
// REF-COMPAT:BEGIN ref-decimal-half-stabilization
|
||||
const roundLegacyIntegerColumn = (value: number): number => {
|
||||
// MariaDB evaluates the decimal rate expression before ROUND(). Binary
|
||||
// arithmetic can instead produce values such as 2029.4999999999998.
|
||||
const stabilized = Number(value.toPrecision(15));
|
||||
return stabilized >= 0 ? Math.floor(stabilized + 0.5) : Math.ceil(stabilized - 0.5);
|
||||
};
|
||||
// REF-COMPAT:END ref-decimal-half-stabilization
|
||||
|
||||
const parseResource = (args: readonly unknown[]): SemiAnnualResource => {
|
||||
const resource = args[0];
|
||||
@@ -29,7 +31,9 @@ const resolveBasePopulationIncrease = (world: InMemoryTurnWorld): number => {
|
||||
|
||||
const decayDomesticValue = (value: number): number => roundLegacyIntegerColumn(value * 0.99);
|
||||
|
||||
// REF-COMPAT:BEGIN ref-mariadb-float-boundary
|
||||
export const storeLegacySemiAnnualTrust = (value: number): number => Math.fround(Math.max(0, Math.min(100, value)));
|
||||
// REF-COMPAT:END ref-mariadb-float-boundary
|
||||
|
||||
const applyResourceMaintenance = (value: number, ratios: readonly [number, number][]): number => {
|
||||
if (value <= 1_000) {
|
||||
|
||||
Reference in New Issue
Block a user