-
Notifications
You must be signed in to change notification settings - Fork 707
Factory spawns trains #1408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Factory spawns trains #1408
Conversation
WalkthroughThis 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
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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
lastSpawnTickis initialized).
evanpelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description:
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
IngloriousTom