mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-28 05:49:47 +00:00
Discourage trading with nearby ports (#2381)
## Description: The **proximityBonusPortsNb** function increased the likelihood a tradeship would go to a nearby port. But now that trade gold is nerfed from nearby ports, we shouldn't encourage trading with ports that are too close. So now add another factor **tradeShipShortRangeDebuff** That cancels out the proximity bonus if the port is too close. Now tradeships are encouraged to go to ports that are close, but not too close. Also move tradingPorts method to the PortExecution class because that's the only place it's used. ## 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
This commit is contained in:
@@ -58,7 +58,7 @@ export class PortExecution implements Execution {
|
||||
return;
|
||||
}
|
||||
|
||||
const ports = this.player.tradingPorts(this.port);
|
||||
const ports = this.tradingPorts();
|
||||
|
||||
if (ports.length === 0) {
|
||||
return;
|
||||
@@ -103,4 +103,40 @@ export class PortExecution implements Execution {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// It's a probability list, so if an element appears twice it's because it's
|
||||
// twice more likely to be picked later.
|
||||
tradingPorts(): Unit[] {
|
||||
const ports = this.mg
|
||||
.players()
|
||||
.filter((p) => p !== this.port!.owner() && p.canTrade(this.port!.owner()))
|
||||
.flatMap((p) => p.units(UnitType.Port))
|
||||
.sort((p1, p2) => {
|
||||
return (
|
||||
this.mg.manhattanDist(this.port!.tile(), p1.tile()) -
|
||||
this.mg.manhattanDist(this.port!.tile(), p2.tile())
|
||||
);
|
||||
});
|
||||
|
||||
const weightedPorts: Unit[] = [];
|
||||
|
||||
for (const [i, otherPort] of ports.entries()) {
|
||||
const expanded = new Array(otherPort.level()).fill(otherPort);
|
||||
weightedPorts.push(...expanded);
|
||||
const tooClose =
|
||||
this.mg.manhattanDist(this.port!.tile(), otherPort.tile()) <
|
||||
this.mg.config().tradeShipShortRangeDebuff();
|
||||
const closeBonus =
|
||||
i < this.mg.config().proximityBonusPortsNb(ports.length);
|
||||
if (!tooClose && closeBonus) {
|
||||
// If the port is close, but not too close, add it again
|
||||
// to increase the chances of trading with it.
|
||||
weightedPorts.push(...expanded);
|
||||
}
|
||||
if (!tooClose && this.port!.owner().isFriendly(otherPort.owner())) {
|
||||
weightedPorts.push(...expanded);
|
||||
}
|
||||
}
|
||||
return weightedPorts;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user