Stabilize TradeItem System with Copy Fixes, Logic Updates and Tests #152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes:
TradeItemsubclasses, thecopyInmethods in classes likeGoldTradeItemandGoodsTradeItemwere incorrectly casting incoming objects toColonyTradeItem, causing silent failures and preventing trade items from being cloned correctly during diplomatic negotiationsequals,hashCode, andtoStringimplementations,equalsnow uses strictgetClass()checks and includessuper.equalsto ensure parent fields are compared,hashCodenow usesObjects.hash(super.hashCode(), ...)to guarantee consistency withequalsandtoStringwas rewritten to a consistent, readable format with null‑safe field handlingInciteTradeItemvaluation logic: replaced hardcoded values with a named constant (BASE_INCITE_COST), added safe fallbacks for invalid strength ratios (unknown ratio (-1orNaN) now treated as equal strength (0.5) and zero strength now treated as extreme weakness (0.1)), these changes prevent division‑by‑zero and produce stable, predictable valuationsDiplomaticTradefactory behavior, ensured unique trade items (e.g.,InciteTradeItem,StanceTradeItem) are correctly enforced and aligned factory constructors with serialization tags so saved games correctly reconstruct trade itemsGoodsTradeItemevaluateFor: replaced the nested ternary expression with clear guard clauses and straightforward condition branches, separated the logic for when the player is giving goods versus receiving them, making the flow easier to follow, moved tax‑related math into dedicated variables to make the calculation clearer and easier to adjust, improved handling of cases where no Market exists by using a simple, consistent fallback value and increased numerical accuracy by computing tax as a double and rounding only at the end