Skip to content

Conversation

@DevelopingTom
Copy link
Contributor

@DevelopingTom DevelopingTom commented Jul 11, 2025

Description:

  • Change trains so it spawns from factories only
  • Increase train frequency as they will now spawn from a single structure.
  • Factory will spawn more trains depending on its level
  • Fix port to connect to nearby railroads
  • Add factory description

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 understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors

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

IngloriousTom

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

This update introduces and localizes a new "Factory" building type, adjusts the train spawn rate formula, and refines the logic for creating and managing train stations, especially those linked to factories and ports. The CSS and language resources are updated to support the new factory icon and descriptions. Train spawning now uses a cooldown and probability system based on unit level.

Changes

File(s) Change Summary
resources/lang/en.json Added "Factory" building and descriptions; updated wording and punctuation for consistency.
src/client/styles.css Added .factory-icon CSS mask for the help modal, matching other building icons.
src/core/configuration/DefaultConfig.ts Adjusted train spawn rate formula: lower multiplier and exponent for slower scaling.
src/core/execution/FactoryExecution.ts Simplified station creation logic; removed seed counter and related comments.
src/core/execution/PortExecution.ts Added createStation method to allow ports near factories to become train stations.
src/core/execution/TrainStationExecution.ts Refactored train spawning: added cooldown, probability based on level, and spawn enable flag.
src/core/game/TrainStation.ts Factory gold bonus now scales with unit level and matches city/port handlers; removed explicit bonus event.

Sequence Diagram(s)

sequenceDiagram
    participant Player
    participant Game
    participant Factory
    participant TrainStationExecution
    participant Port

    Player->>Game: Build Factory
    Game->>Factory: Initialize Factory
    Factory->>TrainStationExecution: Create station for itself
    Factory->>Game: Add TrainStationExecution to executions

    Note over Factory,Port: If Port is near Factory
    Port->>TrainStationExecution: Create station for Port
    Port->>Game: Add TrainStationExecution to executions

    loop Each tick
        TrainStationExecution->>TrainStationExecution: Check cooldown and spawn probability
        alt Can spawn train
            TrainStationExecution->>Game: Spawn train to random destination
        end
    end
Loading

Possibly related PRs

  • Automatic train stations #1353: Introduces the Factory unit type, automatic train stations for nearby structures, and removes manual creation, directly related to this update's features.
  • Add trains #1159: Adds the rail network system including factories, train stations, trains, and related UI and execution logic, foundational to this update.
  • Add gold fx when a tradeship lands #1322: Modifies gold bonus awarding logic in TrainStation handlers, related to the updated FactoryStopHandler gold calculation here.

Suggested labels

Feature - Revision, Balance Tweak, UI/UX

Suggested reviewers

  • evanpelle

Poem

🚂 New factories rise, their chimneys tall,
Linking rails to ports, answering the call.
Trains now spawn with careful thought,
Cooldowns and levels, not left to naught.
Gold rewards grow, icons shine bright—
All aboard for a balanced delight!


📜 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 8ce8d8a and a696585.

📒 Files selected for processing (1)
  • resources/lang/en.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • resources/lang/en.json
⏰ 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). (4)
  • GitHub Check: 🎨 Prettier
  • GitHub Check: 🔬 Test
  • GitHub Check: 🏗️ Build
  • GitHub Check: 🔍 ESLint

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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.

@DevelopingTom DevelopingTom changed the title Factory Factory spawns trains Jul 11, 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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0e9f97 and 0fac8b5.

📒 Files selected for processing (7)
  • resources/lang/en.json (2 hunks)
  • src/client/styles.css (1 hunks)
  • src/core/configuration/DefaultConfig.ts (1 hunks)
  • src/core/execution/FactoryExecution.ts (1 hunks)
  • src/core/execution/PortExecution.ts (2 hunks)
  • src/core/execution/TrainStationExecution.ts (2 hunks)
  • src/core/game/TrainStation.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: its-sii
PR: openfrontio/OpenFrontIO#1089
File: src/client/graphics/layers/ControlPanel.ts:160-183
Timestamp: 2025-06-07T20:01:52.720Z
Learning: The user its-sii prefers simpler, more readable code over complex type-safe approaches when the benefits don't justify the added complexity. They value maintainability and clarity in code implementation.
src/core/configuration/DefaultConfig.ts (1)
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.
resources/lang/en.json (1)
Learnt from: andrewNiziolek
PR: openfrontio/OpenFrontIO#1007
File: resources/lang/de.json:115-115
Timestamp: 2025-06-02T14:27:37.609Z
Learning: For OpenFrontIO project: When localization keys are renamed in language JSON files, the maintainers separate technical changes from translation content updates. They wait for community translators to update the actual translation values rather than attempting to translate in the same PR. This allows technical changes to proceed while ensuring accurate translations from native speakers.
🧬 Code Graph Analysis (2)
src/core/execution/PortExecution.ts (1)
src/core/execution/TrainStationExecution.ts (1)
  • TrainStationExecution (6-101)
src/core/game/TrainStation.ts (3)
src/core/game/Game.ts (1)
  • Game (606-687)
src/core/execution/TrainExecution.ts (1)
  • TrainExecution (14-238)
src/core/game/UnitImpl.ts (1)
  • level (362-364)
⏰ 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). (1)
  • GitHub Check: 🏗️ Build
🔇 Additional comments (8)
src/client/styles.css (1)

372-375: CSS styling follows established pattern correctly.

The factory icon styling matches the existing pattern used for other unit icons in the help modal. Implementation is clean and consistent.

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

5-5: Import addition is correct.

The TrainStationExecution import is properly added to support the new createStation functionality.

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

329-329: Train spawn rate reduction aligns with PR objectives.

The formula change reduces spawn rates by using a lower multiplier (20 vs 70) and gentler scaling (0.5 vs 0.8 exponent). This supports the new factory-based train spawning system mentioned in the PR objectives.

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

55-58: Simplified station creation logic is cleaner.

The removal of seed-based differentiation makes the code easier to understand. The factory gets train spawning enabled while nearby structures get basic train stations without spawning capability.

src/core/game/TrainStation.ts (1)

48-57: Standardized gold bonus calculation across all stop handlers.

The FactoryStopHandler now uses the same level-based gold bonus calculation as CityStopHandler and PortStopHandler. This creates consistent behavior across all station types.

resources/lang/en.json (1)

93-94: LGTM! Localization changes improve consistency.

The new Factory entries follow the established pattern, and the description updates make the text more consistent by using present tense ("Increases" instead of "Increase") and proper punctuation.

Also applies to: 414-416

src/core/execution/TrainStationExecution.ts (2)

51-59: Consider spawn rate scaling at high unit levels.

The current implementation gives each level a separate spawn chance, potentially creating exponential spawn rates. A level 5 unit has 5 independent chances to spawn, which might be too aggressive.

Consider using a single weighted chance instead:

-    for (let i = 0; i < this.unit!.level(); i++) {
-      if (this.random.chance(spawnRate)) {
-        return true;
-      }
-    }
-    return false;
+    const adjustedRate = Math.min(spawnRate * this.unit!.level(), 1.0);
+    return this.random.chance(adjustedRate);

32-96: Clean refactoring with good separation of concerns.

The extraction of spawn logic into dedicated private methods improves readability and testability. The cooldown mechanism is well-implemented (once lastSpawnTick is initialized).

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Jul 11, 2025
@evanpelle evanpelle added this to the v24 milestone Jul 14, 2025
Copy link
Collaborator

@evanpelle evanpelle left a comment

Choose a reason for hiding this comment

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

Thanks!

@github-project-automation github-project-automation bot moved this from Development to Final Review in OpenFront Release Management Jul 14, 2025
@evanpelle evanpelle merged commit 29b587c into openfrontio:main Jul 14, 2025
8 of 9 checks passed
@github-project-automation github-project-automation bot moved this from Final Review to Complete in OpenFront Release Management Jul 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 25, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2025
4 tasks
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.

3 participants