Skip to content

Conversation

@JaskRendix
Copy link

Changes:

  • fixed a critical type‑mismatch in several TradeItem subclasses, the copyIn methods in classes like GoldTradeItem and GoodsTradeItem were incorrectly casting incoming objects to ColonyTradeItem, causing silent failures and preventing trade items from being cloned correctly during diplomatic negotiations
  • standardized equals, hashCode, and toString implementations, equals now uses strict getClass() checks and includes super.equals to ensure parent fields are compared, hashCode now uses Objects.hash(super.hashCode(), ...) to guarantee consistency with equals and toString was rewritten to a consistent, readable format with null‑safe field handling
  • updated InciteTradeItem valuation logic: replaced hardcoded values with a named constant (BASE_INCITE_COST), added safe fallbacks for invalid strength ratios (unknown ratio (-1 or NaN) 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 valuations
  • improved DiplomaticTrade factory 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 items
  • GoodsTradeItem evaluateFor: 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
  • added new test suite

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.

1 participant