Skip to content

Conversation

evanpelle
Copy link
Collaborator

@evanpelle evanpelle commented Aug 8, 2025

Description:

The previous behavior had trade ship spawn rate decrease as the number of trade ships on the map increased. This was problematic because large players with many ports could starve out smaller players.

This change has the trade ship spawn rate decrease as number of ports increases, but increases the value of trade ships to compensate. It also decreases as a function of number of tradeships, but it is less of a factor as before.

Gold per trade ship scales with goldMultiplier(), but tradeship spawn rate decreases with sqrt(goldMultiplier()), this ensures that more ports => more gold.

After roughly 10-15 ports the increase trails off, preventing large players from gaining too much gold.

Screenshot 2025-08-08 at 12 20 34 PM

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced
  • I have read and accepted the CLA agreement (only required once).

Please put your Discord username so you can be contacted if a bug or regression is found:

evan

Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

Walkthrough

The changes update the calculation of trade ship spawn rates and gold rewards by modifying method signatures and logic to consider both the number of trade ships and player-owned ports. A new method for expected spawn rate is added, and internal usage is updated to match the new parameters.

Changes

Cohort / File(s) Change Summary
Config Interface Update
src/core/configuration/Config.ts
Changed tradeShipSpawnRate method to accept two parameters: numTradeShips and numPlayerPorts instead of one.
DefaultConfig Logic Overhaul
src/core/configuration/DefaultConfig.ts
Updated tradeShipSpawnRate to use both trade ship and player port counts, simplified tradeShipGold calculation, and added expectedTradeShipSpawnRate method.
PortExecution Spawn Logic
src/core/execution/PortExecution.ts
Modified shouldSpawnTradeShip to use the new tradeShipSpawnRate signature, passing both trade ship and player port counts.

Sequence Diagram(s)

sequenceDiagram
    participant Player
    participant PortExecution
    participant Config (DefaultConfig)
    Player->>PortExecution: Attempt to spawn trade ship
    PortExecution->>Config (DefaultConfig): tradeShipSpawnRate(numTradeShips, numPlayerPorts)
    Config (DefaultConfig)-->>PortExecution: Return calculated spawn rate
    PortExecution->>PortExecution: Determine if spawn occurs (random check)
    PortExecution-->>Player: Result (spawn or not)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

Balance Tweak

Poem

Trade ships sail with rates anew,
Ports and ships now both in view.
Gold rewards, a simpler sum,
Ports count up, the traders come!
With logic changed and methods neat,
The balance tweak is quite a feat.
🚢⚓

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92cf015 and 24fc638.

📒 Files selected for processing (3)
  • src/core/configuration/Config.ts (1 hunks)
  • src/core/configuration/DefaultConfig.ts (1 hunks)
  • src/core/execution/PortExecution.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/core/configuration/Config.ts
  • src/core/execution/PortExecution.ts
  • src/core/configuration/DefaultConfig.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Deploy to openfront.dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@evanpelle evanpelle force-pushed the fix-tradeship-freq branch from f0b50b2 to af523bc Compare August 8, 2025 02:16
@evanpelle evanpelle force-pushed the fix-tradeship-freq branch from af523bc to 92cf015 Compare August 8, 2025 02:17
@evanpelle evanpelle changed the base branch from main to v25 August 8, 2025 02:18
@evanpelle evanpelle added this to the v25 milestone Aug 8, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1b5c80 and 92cf015.

📒 Files selected for processing (4)
  • Dockerfile (1 hunks)
  • src/core/configuration/Config.ts (1 hunks)
  • src/core/configuration/DefaultConfig.ts (2 hunks)
  • src/core/execution/PortExecution.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-05-19T06:00:38.007Z
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:125-134
Timestamp: 2025-05-19T06:00:38.007Z
Learning: In StatsImpl.ts, unused parameters in boat/stats-related methods are intentionally kept for future use and shouldn't be removed.

Applied to files:

  • src/core/configuration/Config.ts
  • src/core/execution/PortExecution.ts
  • src/core/configuration/DefaultConfig.ts
📚 Learning: 2025-05-31T18:15:03.445Z
Learnt from: 1brucben
PR: openfrontio/OpenFrontIO#977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.

Applied to files:

  • src/core/configuration/Config.ts
  • src/core/configuration/DefaultConfig.ts
📚 Learning: 2025-05-22T23:48:51.113Z
Learnt from: jrouillard
PR: openfrontio/OpenFrontIO#848
File: src/core/execution/TradeShipExecution.ts:125-127
Timestamp: 2025-05-22T23:48:51.113Z
Learning: In TradeShipExecution, the path length is already checked in the computeNewPath() function. If the path is empty, it returns PathFindResultType.PathNotFound instead of PathFindResultType.Completed, making additional empty path checks unnecessary when handling the Completed case.

Applied to files:

  • src/core/execution/PortExecution.ts
📚 Learning: 2025-06-22T05:48:19.241Z
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#786
File: src/client/TerritoryPatternsModal.ts:337-338
Timestamp: 2025-06-22T05:48:19.241Z
Learning: In src/client/TerritoryPatternsModal.ts, the bit shifting operators (<<) used in coordinate calculations with decoder.getScale() are intentional and should not be changed to multiplication. The user scottanderson confirmed this is functioning as intended.

Applied to files:

  • src/core/execution/PortExecution.ts
🧬 Code Graph Analysis (1)
src/core/configuration/DefaultConfig.ts (1)
src/core/game/Game.ts (1)
  • Gold (16-16)
🔇 Additional comments (5)
Dockerfile (1)

53-54: Good addition for version traceability.

Adding the GIT_COMMIT environment variable to the final stage ensures version information is available at runtime, which helps with debugging and deployment tracking.

src/core/execution/PortExecution.ts (1)

81-84: Implementation correctly updated to match interface.

The code properly calculates the player's port count and passes both numTradeShips and numPlayerPorts to the spawn rate method, aligning with the new signature and game mechanics requirements.

src/core/configuration/DefaultConfig.ts (3)

344-351: Well-designed diminishing returns helper.

The goldMultiplier method implements sensible economics with a 0.95 diminishing factor and 0.1 minimum value per additional port. This prevents excessive scaling while still rewarding port expansion.


354-357: Balanced trade ship gold adjustment.

Halving the base gold from 50000 to 25000 while applying the port multiplier maintains economic balance, ensuring the spawn rate changes don't dramatically alter gold income.


329-329: Please verify the doubled train spawn rate is intentional

It looks like the multiplier in trainSpawnRate(numberOfStations) was increased from 20 to 40, so:

  • In src/core/configuration/DefaultConfig.ts (line 329), you now return Math.round(40 * √numberOfStations) (capped at 1400) instead of 20 * √numberOfStations.
  • In src/core/execution/TrainStationExecution.ts, that higher value flows into shouldSpawnTrain, boosting the per‐tick chance (for each unit level) of spawning a train.

I didn’t find any tests or documentation covering this change. Please confirm:

  • That doubling the multiplier is deliberate.
  • There’s no risk of overwhelming the system with too many trains.
  • Any additional test coverage or documentation updates are handled.

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Aug 8, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 8, 2025
@evanpelle evanpelle marked this pull request as ready for review August 8, 2025 19:24
@evanpelle evanpelle requested a review from a team as a code owner August 8, 2025 19:24
@evanpelle evanpelle closed this Aug 8, 2025
@github-project-automation github-project-automation bot moved this from Development to Complete in OpenFront Release Management Aug 8, 2025
@TheGiraffe3 TheGiraffe3 removed this from the v25 milestone Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

2 participants