Skip to content

convert: strict int/float numbers like nyan - #1835

Open
JotaJazz wants to merge 3 commits into
SFTtech:masterfrom
JotaJazz:converter-strict-numbers
Open

JotaJazz wants to merge 3 commits into
SFTtech:masterfrom
JotaJazz:converter-strict-numbers

Conversation

@JotaJazz

@JotaJazz JotaJazz commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the discussion in #1832: nyan separates int and float strictly, so the converter now does too, instead of silently truncating.

  • convert: make projectile arc and ability ranges floats: Projectile.arc and the min_range/max_range members become floats, since the data has fractional values (e.g. arc -3.44, Fire Galley range 2.49).
  • convert: make attribute settings, resource amounts and slots floats: tech and civ bonuses multiply HP, creation costs and garrison slots by fractional factors (e.g. HP *= 1.1, costs *= 0.8), so AttributeSetting.{min,max,starting}_value, ResourceAmount.amount and EntityContainer.slots become floats and these stay plain member patches. The engine rounds the starting attribute value where it reads it. Members that are only ever multiplied by integral factors in the data (projectiles, ResourceSpot, ResourceContingent) stay ints and fail on fractional factors.
  • nyan: separate int and float members strictly like nyan: non-integral values for int members and division by zero now raise.

With all three commits, a full AoC 1.0c conversion succeeds with the strict typing, i.e. no int member gets a non-integral value.

Tests: convert.processor.conversion.aoc.tests.hp_float_patches, nyan.tests.number_typing.

🤖 Generated with Claude Code

@TheJJ TheJJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! i fear modeling this through modifier is suboptimal, because modifiers are meant for things like global (temporary) adjustments - member value updates should be used instead oike before. but that's tricky now, unfortunately. see inline:

) -> ForwardRef:
"""
Creates a patch that adds a modifier with a Multiplier property to the
game entity of a line. nyan can't multiply int members with a float,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting idea, but i think a better solution here would be to change the members to be float then. nyan not able to multiply ints with floats was decided because the resulting rounding is implicit and thus unclear.
using modifiers for changing simple number values is way more complicated and harder for modding than plain member patching i'd say.

so in other words, all members being added/multiplied/etc with floats should be stored as floats in nyan. the rounding then has to be done by the consumer (e.g. for display).

i'm also open to rethinking the nyan int/float mixing prevention, if it turns out to be the better solution to actually allow multiplying/... ints with floats and then implicit rounding, that's also nice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, makes sense.

Done: dropped the modifiers, the multiplied members (attribute settings, resource amounts, container slots) are floats now and stay plain patches; the engine rounds the starting HP when reading it.

JotaJazz and others added 3 commits November 20, 2026 19:55
The original data has fractional projectile arcs (e.g. -3.44 degrees)
and ranges (the Fire Galley's 2.49), which int members can't hold
without rounding and thus changing gameplay. Make arc, min_range and
max_range floats in the API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Many tech and civ bonuses multiply HP, creation costs and garrison
slots by fractional factors (e.g. HP *= 1.1, costs *= 0.8), which nyan
can't apply to int members without implicit rounding. Make the
AttributeSetting values, ResourceAmount.amount and EntityContainer.slots
floats so these stay plain member patches, and round where the engine
consumes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nyan rejects float values and operands for int members, but the
converter silently truncated them, hiding lossy conversions. Convert
numbers only without loss and raise on non-integral values for int
members and on division by zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JotaJazz
JotaJazz force-pushed the converter-strict-numbers branch from 7ba4aab to 324901f Compare November 20, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants