mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-21 14:25:06 +00:00
Rework trains to encourage alliances (#1697)
## Description:
This update encourages alliances by modifying how train-based trading
works. Trading is now restricted to allied networks, and allied trades
offer better rewards than self-trades, incentivizing cooperation.
Changes:
- Train destinations are now limited to stations owned by the player or
their allies.
- Delivering a train to one’s own station grants 4,000 gold.
- Delivering a train to an ally’s station grants 5,000 gold to both the
sender and the receiver.
This system encourages players to form alliances, especially with
factory-focused players.
## 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
- [x] 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:
IngloriousTom
This commit is contained in:
@@ -329,7 +329,7 @@ export class DefaultConfig implements Config {
|
||||
return Math.min(1400, Math.round(20 * Math.pow(numberOfStations, 0.5)));
|
||||
}
|
||||
trainGold(): Gold {
|
||||
return BigInt(10_000);
|
||||
return BigInt(4_000);
|
||||
}
|
||||
trainStationMinRange(): number {
|
||||
return 15;
|
||||
|
||||
@@ -32,6 +32,10 @@ export class TrainExecution implements Execution {
|
||||
private numCars: number,
|
||||
) {}
|
||||
|
||||
public owner(): Player {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
init(mg: Game, ticks: number): void {
|
||||
this.mg = mg;
|
||||
const stations = this.railNetwork.findStationsPath(
|
||||
|
||||
@@ -69,9 +69,9 @@ export type GameUpdate =
|
||||
|
||||
export interface BonusEventUpdate {
|
||||
type: GameUpdateType.BonusEvent;
|
||||
player: PlayerID;
|
||||
tile: TileRef;
|
||||
gold: number;
|
||||
workers: number;
|
||||
troops: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -704,9 +704,9 @@ export class PlayerImpl implements Player {
|
||||
if (tile) {
|
||||
this.mg.addUpdate({
|
||||
type: GameUpdateType.BonusEvent,
|
||||
player: this.id(),
|
||||
tile,
|
||||
gold: Number(toAdd),
|
||||
workers: 0,
|
||||
troops: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,8 +25,15 @@ class CityStopHandler implements TrainStopHandler {
|
||||
trainExecution: TrainExecution,
|
||||
): void {
|
||||
const level = BigInt(station.unit.level() + 1);
|
||||
const goldBonus = (mg.config().trainGold() * level) / this.factor;
|
||||
station.unit.owner().addGold(goldBonus, station.tile());
|
||||
let goldBonus = (mg.config().trainGold() * level) / this.factor;
|
||||
const stationOwner = station.unit.owner();
|
||||
const trainOwner = trainExecution.owner();
|
||||
// Share revenue with the station owner if it's not the current player
|
||||
if (stationOwner.isFriendly(trainOwner)) {
|
||||
goldBonus += BigInt(1_000); // Bonus for everybody when trading with an ally!
|
||||
stationOwner.addGold(goldBonus, station.tile());
|
||||
}
|
||||
trainOwner.addGold(goldBonus, station.tile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +46,15 @@ class PortStopHandler implements TrainStopHandler {
|
||||
trainExecution: TrainExecution,
|
||||
): void {
|
||||
const level = BigInt(station.unit.level() + 1);
|
||||
const goldBonus = (mg.config().trainGold() * level) / this.factor;
|
||||
station.unit.owner().addGold(goldBonus, station.tile());
|
||||
let goldBonus = (mg.config().trainGold() * level) / this.factor;
|
||||
const stationOwner = station.unit.owner();
|
||||
const trainOwner = trainExecution.owner();
|
||||
// Share revenue with the station owner if it's not the current player
|
||||
if (stationOwner.isFriendly(trainOwner)) {
|
||||
goldBonus += BigInt(1_000); // Bonus for everybody when trading with an ally!
|
||||
stationOwner.addGold(goldBonus, station.tile());
|
||||
}
|
||||
trainOwner.addGold(goldBonus, station.tile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +65,15 @@ class FactoryStopHandler implements TrainStopHandler {
|
||||
station: TrainStation,
|
||||
trainExecution: TrainExecution,
|
||||
): void {
|
||||
station.unit.owner().addGold(mg.config().trainGold(), station.tile());
|
||||
let goldBonus = mg.config().trainGold();
|
||||
const stationOwner = station.unit.owner();
|
||||
const trainOwner = trainExecution.owner();
|
||||
// Share revenue with the station owner if it's not the current player
|
||||
if (stationOwner.isFriendly(trainOwner)) {
|
||||
goldBonus += BigInt(1_000); // Bonus for everybody when trading with an ally!
|
||||
stationOwner.addGold(goldBonus, station.tile());
|
||||
}
|
||||
trainOwner.addGold(goldBonus, station.tile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +229,10 @@ export class Cluster {
|
||||
availableForTrade(player: Player): Set<TrainStation> {
|
||||
const tradingStations = new Set<TrainStation>();
|
||||
for (const station of this.stations) {
|
||||
if (station.tradeAvailable(player)) {
|
||||
if (
|
||||
station.unit.owner() === player ||
|
||||
station.unit.owner().isFriendly(player)
|
||||
) {
|
||||
tradingStations.add(station);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user