Commit Graph

2757 Commits

Author SHA1 Message Date
scamiv 3c3af58155 tweaked values again 2025-11-22 22:33:06 +01:00
scamiv 1907c61fb4 Adjust train gold refill time and modify fare calculation logic
- Reduced the train gold refill time from 600 to 300 ticks for faster resource replenishment.
- Updated fare calculation to use a base length bonus and adjusted congestion fare logic, ensuring that only the net congestion premium is added to the fare.
2025-11-22 22:14:25 +01:00
scamiv ed67c0647d if cluster no longer contains the destination, invalidate this train immediately 2025-11-22 21:50:30 +01:00
scamiv d5d5588d09 reduce routing table max distance 2025-11-22 21:30:33 +01:00
scamiv 34e511deb3 reduce train max hops 2025-11-22 21:28:26 +01:00
scamiv 38abed125d experiment: distribute part of track profits 2025-11-22 21:20:23 +01:00
scamiv 21c9594788 Refactor recency penalty and profit estimation in TrainStation
- Adjusted recency penalties to be softer and decay faster, with a maximum penalty of 40% for immediate revisits.
- Introduced a new method to estimate expected profit for a station based on passenger demand and relationship with the train owner.
- Updated edge score calculation to incorporate expected profit and travel time cost, enhancing routing decisions.
2025-11-22 20:45:39 +01:00
scamiv ad5d5eecd0 tweaked profits 2025-11-22 20:27:22 +01:00
scamiv 3e69bbfc4f integrate the previous merges properly with pathing 2025-11-22 19:39:31 +01:00
scamiv 1a996c5ea1 reduce CONGESTION_EMA_ALPHA 2025-11-22 19:21:20 +01:00
scamiv eee3c5aad3 toggle TerritoryWebGLStatus with TogglePerformanceOverlayEvent 2025-11-22 18:30:27 +01:00
scamiv a769a1be20 Merge branch 'feature/train-station-demand' into trains-borders 2025-11-22 17:35:04 +01:00
scamiv a442deae0b Refactor Railroad and TrainStation classes to improve railroad management
- Replaced direct deletion of railroads with dedicated methods in TrainStation for better encapsulation.
- Added a mapping for quick lookup of railroads by neighboring stations.
- Updated clearRailroads and addRailroad methods to maintain consistency in railroad management.
2025-11-22 17:19:09 +01:00
scamiv 160c8b2e94 Color railroad segments based on cost and add changes required for that
Implement fare-only updates for railroads and enhance client-side coloring

- Introduce fare tracking in RailroadLayer and update rendering logic to handle fare-only updates.
- Modify FxLayer to skip effects for fare-only updates.
- Add fare calculation and update logic in Railroad and TrainExecution classes.
- Update RailTile interface to include optional fare property for client-side use.
- Ensure significant fare changes trigger updates to clients for visual feedback.
2025-11-22 17:17:47 +01:00
scamiv 5d87c2189c Enhance train count management and congestion tracking in Railroad
- Update increment and decrement methods in Railroad to accept current tick for congestion calculations.
- Implement exponential moving average for congestion to adjust fare based on train density.
- Modify TrainExecution to pass tick information when managing train counts.
2025-11-22 17:17:47 +01:00
scamiv e6736e4698 Simplify fare calculation logic by separating length and congestion components for better clarity. 2025-11-22 17:17:46 +01:00
scamiv 66af4715b1 sett the origin of player.addGold to center tile of railroad
remove message from message window
2025-11-22 17:17:45 +01:00
scamiv 3e744d62ed FXLayer also show messages for negative income in onBonusEvent 2025-11-22 17:17:44 +01:00
scamiv 2d2d0e8b5a Add dynamic railroad fares based on segment length and congestion
- Track train counts per railroad segment
- expose a fare API on segments
- charge players when entering each segment with visual feedback
2025-11-22 17:17:38 +01:00
scamiv 1f1e0341cf Add TerserPlugin to preserve layer class names in production builds
- Install terser-webpack-plugin dependency
- Configure keep_classnames with regex pattern for layer classes
- Preserve names for FrameProfiler layer identification in production
- Covers most layer classes with regex, handles exceptions explicitly
2025-11-22 17:14:37 +01:00
scamiv c3796acd9b Also listen to ContextMenuEvent for hoverHighlight 2025-11-22 17:14:35 +01:00
scamiv c3ff69df04 fffff 2025-11-22 17:14:34 +01:00
scamiv de085076c4 again 2025-11-22 17:14:33 +01:00
scamiv ba77ca9468 Updated tests/core/game/RailNetwork.test.ts station mock to include onStationRemoved, matching the production API.
Expanded tests/core/game/TrainStation.test.ts mocks: added game.x/y, ensured trainExecution.shareJourneyInfo() returns the expected structure, and gave the otherUnit mock a tile() for parity with real units.
2025-11-22 17:14:31 +01:00
scamiv 1528a91154 Fix arrival vs. termination handling to avoid wrong stats and double counting
The new station-aware routing introduced a bug where train arrivals were being
double-counted and termination conditions were incorrectly classified as arrivals.

Problems fixed:
- targetReached() was called twice for successful arrivals: once in getNextTile()
  when destination was reached, and again in tick() when no tile was returned
- Trains removed due to hop limit were counted as successful arrivals
- Trains stuck with no routing options were counted as successful arrivals

Solution implemented:
- Introduced MoveResult union type with explicit cases: "move", "arrived",
  "hopLimit", "stuck" to clearly distinguish termination conditions
- Renamed getNextTile() to getNextStep() and changed return type to MoveResult
- Removed targetReached() call from navigation logic to prevent double counting
- Updated tick() method to use switch statement on MoveResult for proper handling
- Ensured recordTrainArrival() only called for actual destination arrivals
- Ensured recordTrainRemovedDueToHopLimit() only called for hop limit terminations
- Stuck trains are deleted without recording any arrival statistics

This ensures accurate train statistics tracking with the new routing system.
2025-11-22 17:14:30 +01:00
scamiv 27f2c7b7a3 Enhance train routing logic and memory management
- Added search radius
- Updated several properties in TrainStation class to be readonly for better immutability and clarity.
- Introduced heat decay interval and factor for more flexible heat management.
- pre-computed decay factors avoiding Math.pow in critical paths.
- Enhance logging
- Refined routing logic
- removed journeyPreviousStation property
- removed RecentArrivals
- unbounded StationTraffic.heat -> score can now be negative
2025-11-22 17:14:30 +01:00
scamiv 73826e0a5d removed journey source and replaced it with recent stations during journey transmission, journeySource wasnt loop proof 2025-11-22 17:14:28 +01:00
scamiv 56b7f7aa7b feat: Implement local train routing with discovery and greedy path selection
Replace fixed pathfinding with dynamic routing system featuring:
- Local greedy routing: Trains evaluate neighbors based on profit potential, traffic congestion, distance, and recent history
- Exploration capability: 10% randomness prevents suboptimal but discovers new routes
- Congestion avoidance: Trains naturally spread to less busy stations
- Loop prevention: Memory of recent visits prevents getting stuck
- Adaptive behavior: System responds to changing network conditions
- Enhanced journey tracking: Share complete route information instead of just start position

Includes BATMAN-style routing protocol (currently disabled) for future network-wide knowledge distribution.
2025-11-22 17:14:21 +01:00
scamiv 40b0fe990a TrainStationMapAdapter.cost(node) uses node.getPassengerDemandScore() so higher passenger demand and level → slightly lower traversal cost:
const demand = node.getPassengerDemandScore();
return 1 / (1 + 0.25 * demand);
2025-11-22 17:10:07 +01:00
scamiv 477704d768 add station passenger demand and time-based payouts
- Interpret trainGold as per-level max gold and add trainGoldRefillTime with a 60-tick full refill baseline
- Add per-station passenger pool with lazy tick-based refill and proportional depletion on train arrival
- Make city and port train payouts depend on station level, owner relation, and current passenger demand instead of flat values
- Expose getPassengerDemandScore for future logic
- Update TrainStation tests for the new config and payout behavior
2025-11-22 17:07:16 +01:00
evanpelle 930a79e31c Merge branch 'v27' 2025-11-21 20:22:40 -08:00
Evan 0b651b6941 Update copyright notice & footer (#2496)
## Description:

* Update copyright notice to "OpenFront and Contributors"

* remove the "how to play" on the footer, since that will be moved to
the death screen.

* Removed css and used tailwind instead for better mobile support


Describe the PR.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

evan
2025-11-21 20:22:17 -08:00
scamiv 33810e41c5 Optimize edge lookup railnetwork (#2493)
## Description:

This PR optimizes how the rail network looks up railroads connecting two
stations by introducing an O(1) neighbor→railroad map on `TrainStation`.
It also updates `getOrientedRailroad` and railroad deletion to use this
new API, avoiding repeated linear scans over all railroads attached to a
station.

### What changed

- **TrainStation neighbor→railroad index**
- Added `railroadByNeighbor: Map<TrainStation, Railroad>` to
`TrainStation` for quick edge lookup.
  - Kept `railroads: Set<Railroad>` for iteration and existing APIs.
  - Updated lifecycle methods to keep both data structures in sync:
    - `addRailroad(railRoad: Railroad)` now:
      - Adds to `railroads`.
- Computes the neighbor station (`railRoad.from === this ? railRoad.to :
railRoad.from`).
      - Stores the mapping in `railroadByNeighbor`.
    - `removeRailroad(railRoad: Railroad)` now:
      - Removes from `railroads`.
      - Removes the corresponding entry from `railroadByNeighbor`.
- `clearRailroads()` now clears both `railroads` and
`railroadByNeighbor`.
- Added `getRailroadTo(station: TrainStation): Railroad | null` to
retrieve the connecting railroad in O(1).

- **Use the new API in `TrainStation` and `Railroad`**
- `TrainStation.removeNeighboringRails(station)` now calls
`removeRailroad(toRemove)` instead of manually deleting from the set,
ensuring the map stays in sync.
- `Railroad.delete(game)` now calls `from.removeRailroad(this)` and
`to.removeRailroad(this)` instead of mutating the sets directly.

- **Refactor `getOrientedRailroad` to use O(1) lookup**
- Replaced a linear scan over `from.getRailroads()` with a direct
lookup:

    ```ts
    export function getOrientedRailroad(
      from: TrainStation,
      to: TrainStation,
    ): OrientedRailroad | null {
      const railroad = from.getRailroadTo(to);
      if (!railroad) return null;
// If tiles are stored from -> to, we go forward when railroad.to === to
      const forward = railroad.to === to;
      return new OrientedRailroad(railroad, forward);
    }
    ```

  - Behavior is preserved:
- `getRailroadTo` returns the same `Railroad` instance that was
previously found by scanning `getRailroads()`.
- Direction (`forward` vs reversed) is still derived from the
`Railroad.from` / `.to` fields in the same way as before.

### Motivation

- `getOrientedRailroad` and upcoming logic both need to resolve “the
railroad between station A and station B” frequently.
- The old pattern (`for (const railroad of from.getRailroads()) { ...
}`) was:
  - O(degree) per lookup,
  - Repeated in multiple places,
- Harder to maintain as more features (like fare-based costs) touch this
code.
- Centralizing edge lookup in a dedicated `railroadByNeighbor` map makes
this:
  - **O(1)** per lookup,
  - Less error-prone (one source of truth),
- Easier to reuse from new systems (e.g. train pathfinding, fare-aware
logic).

### Impact / Risk

- **Public behavior:** No functional change in how railroads are
created, deleted, or oriented; only the lookup mechanism changed.
- **Internal invariants:** Correctness relies on:
- All railroad creations using `addRailroad` on both endpoints (already
true via `RailNetworkImpl.connect`).
- All removals (`Railroad.delete`,
`TrainStation.removeNeighboringRails`, `disconnectFromNetwork`) using
`removeRailroad` / `clearRailroads`, which this PR updates.
- **Tests:** Existing `TrainStation` tests still pass; they exercise
`addRailroad`, `removeNeighboringRails`, and `getRailroads()`, which
continue to behave the same from the outside.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

DISCORD_USERNAME
2025-11-21 22:33:08 +00:00
Loacky 024285389a Implement donation troops/gold between human players after forming an alliance (#2450)
Resolves #2448 

Hi team,

I've implemented and locally tested the alliance-related changes
(including unit tests and some manual simulation with multiple browser
profiles).
Unfortunately I wasn't able to perform full end-to-end testing on the
live game server with two separate machines/accounts.

If someone on the team (or another contributor) can verify the alliance
flow with two real players, that would be greatly appreciated before
merging. Happy to hop on a call or provide any clarification needed.

Thanks!

## Description:

Fixed a race condition bug where donations (troops/gold) between human
players failed after forming an alliance. The issue was caused by a
one-tick delay in `AllianceRequestReplyExecution`: the alliance
acceptance logic ran in `tick()` instead of `init()`, meaning the
alliance wasn't created until the tick after the execution was added. If
a donation execution was added in the same turn as the alliance
acceptance, it would fail the `isFriendly()` check because the alliance
didn't exist yet.

**Root cause:** When human players formed alliances via reply, the
execution model delayed alliance creation by one tick, while bots called
`accept()` directly without this delay.

**Solution:** Moved alliance acceptance logic from `tick()` to `init()`
in `AllianceRequestReplyExecution.ts`, ensuring immediate alliance
creation and eliminating race conditions with donations.

**Changes:**
- Modified
`src/core/execution/alliance/AllianceRequestReplyExecution.ts` to
process alliance replies in `init()` instead of `tick()`
- Added comprehensive test suite `tests/AllianceDonation.test.ts` with 5
test cases covering donation scenarios after alliance formation (reply
and mutual request flows)
- All existing tests pass (323 total)

## Please complete the following:

- [x] I have added screenshots for all UI updates (N/A - backend logic
fix only)
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file (N/A - no user-facing text
changes)
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced


Discord: loacky
GitHub: @LoackyBit

---------

Co-authored-by: Evan <evanpelle@gmail.com>
2025-11-21 14:25:41 -08:00
evanpelle 92372b770b Merge branch 'v26' into v27 v0.27.0-beta7 v0.27.0-beta6 2025-11-21 14:08:43 -08:00
evanpelle 7d7ef40ae4 Merge branch 'v26' 2025-11-21 14:08:27 -08:00
evanpelle 44920f030b Bugfix: Kick player in private lobby not working
Nginx was stripping query params when routing requests to workers, so the creatorClientID param was stripped when creating a private game. This caused the game server to not know who the lobby owner was, so it rejected the kick requests.
2025-11-21 14:06:31 -08:00
Aotumuri b0e6661c97 mls (v4.9) (#2487)
## Description:

mls for v27
Version identifier within MLS: v4.9

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

aotumuri
2025-11-21 11:51:14 -08:00
evanpelle 26b965468f Only open news modal if the user has seen an existing version. This prevents brand new players from seeing the news popup.
Move NewsButton into NewsModal.ts
Refactor & simplify NewsButton
v0.27.0-beta4 v0.27.0-beta3 v0.27.0-beta5
2025-11-21 10:57:07 -08:00
evanpelle 9bd2b54ad7 Merge branch 'v27' 2025-11-20 20:11:56 -08:00
evanpelle a1640a421f Shorten long Nation names to fix failing tests 2025-11-20 19:58:38 -08:00
evanpelle c5b1bca6c6 fix z-index of homepage modals & buttons so modals always appear above the buttons 2025-11-20 19:35:07 -08:00
evanpelle c60b0bcb2b Bugfix: transport ships were not working on compact-maps because the shore & water was not processed on the downscaled map binaries 2025-11-20 19:21:48 -08:00
evanpelle cf7e658d3d Remove yenisei because there is no source in map-generate/assets so the map cannot be rebuilt 2025-11-20 19:18:37 -08:00
Lavodan f4a7788cdf Change wiki site from miraheze to openfront.wiki (#2483)
## Description:

Change the wiki site from the inactive openfront.miraheze.org to the new
openfront.wiki link.
Ideally for v27?

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

Lavodan
2025-11-20 16:50:10 -08:00
evanpelle 9287d0323d bugfix: emoji table was too small on firefox 2025-11-20 16:49:45 -08:00
Lavodan 8f04a60b89 Change wiki site from miraheze to openfront.wiki (#2483)
## Description:

Change the wiki site from the inactive openfront.miraheze.org to the new
openfront.wiki link.
Ideally for v27?

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

Lavodan
2025-11-20 16:34:29 -08:00
dependabot[bot] 2a3a56b0c7 Bump glob from 10.4.5 to 10.5.0 in the npm_and_yarn group across 1 directory (#2481)
Bumps the npm_and_yarn group with 1 update in the / directory:
[glob](https://github.com/isaacs/node-glob).

Updates `glob` from 10.4.5 to 10.5.0
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/isaacs/node-glob/commit/56774ef73b495eb0b17cdd0f42921f5ef62297c1"><code>56774ef</code></a>
10.5.0</li>
<li><a
href="https://github.com/isaacs/node-glob/commit/1e4e297342a09f2aa0ced87fcd4a70ddc325d75f"><code>1e4e297</code></a>
bin: Do not expose filenames to shell expansion</li>
<li>See full diff in <a
href="https://github.com/isaacs/node-glob/compare/v10.4.5...v10.5.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=glob&package-manager=npm_and_yarn&previous-version=10.4.5&new-version=10.5.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/openfrontio/OpenFrontIO/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-11-19 19:33:48 -08:00
FloPinguin 46bbc8f296 New Map! "Four Islands" 🏝️ (#2482)
## Description:

Made a type of map we don't already have: Small square map, one Island
in each corner. Could be great for boat gameplay or maybe even nuke
wars.

The special thing is: **All islands are exactly 25% of the territory!**
Was a lot of work drawing that in GIMP...

<img width="1164" height="1168" alt="Screenshot 2025-11-20 000839"
src="https://github.com/user-attachments/assets/ad8345c7-562d-49e8-b367-12be9274f3e4"
/>

<img width="1227" height="1222" alt="Screenshot 2025-11-20 000633"
src="https://github.com/user-attachments/assets/f7e2c58a-fcb3-4e07-91f2-aead5f497fad"
/>

<img width="361" height="288" alt="Screenshot 2025-11-20 000655"
src="https://github.com/user-attachments/assets/120f82ef-2d19-497b-8a31-819e30013c89"
/>

<img width="756" height="282" alt="Screenshot 2025-11-20 005949"
src="https://github.com/user-attachments/assets/8ee04da3-d5fa-4ec9-9e99-9e30ebda2b78"
/>

## Please complete the following:

- [X] I have added screenshots for all UI updates
- [X] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [X] I have added relevant tests to the test directory
- [X] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

FloPinguin

---------

Co-authored-by: Evan <evanpelle@gmail.com>
2025-11-19 19:33:05 -08:00
Abdallah Bahrawi 4463236e8b Lobby Team Preview UI (#2444)
Resolves #1092

## Description:

Added a team preview to the Host Lobby: players listed on the left,
teams on the right in two scrollable columns with color dots matching
in-game colors. Implemented accurate server-parity team assignment
(including clan grouping).

Screenshots:

<img width="817" height="519" alt="Screenshot 2025-11-13 173721"
src="https://github.com/user-attachments/assets/ec646238-7efa-4c8f-9c0a-171b61fd3f20"
/>

<img width="762" height="425" alt="Screenshot 2025-11-13 175400"
src="https://github.com/user-attachments/assets/ebdccb80-4c07-41d5-8f69-3ea983d4b243"
/>


## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

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

abodcraft1

---------

Co-authored-by: Evan <evanpelle@gmail.com>
2025-11-19 19:27:41 -08:00