mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 23:54:36 +00:00
only trade with allies
This commit is contained in:
@@ -179,11 +179,11 @@
|
||||
* add destroyer DONE 11/12/2024
|
||||
* add ports DONE 11/14/2024
|
||||
* destroyer spawn from port DONE 11/14/2024
|
||||
* create trade routes DONE 11/15/2024
|
||||
* add trade ship DONE 11/15/2024
|
||||
* trade ship gives gold when completes route DONE 11/15/2024
|
||||
* add missile silo
|
||||
* nuke spawns from missile silo
|
||||
* create trade routes
|
||||
* add trade ship
|
||||
* trade ship gives gold when completes route
|
||||
* destroyer can capture trade ships
|
||||
* add battleship
|
||||
* NPC has relations
|
||||
|
||||
+6
-1
@@ -3,7 +3,7 @@ import twemoji from 'twemoji';
|
||||
import DOMPurify from 'dompurify';
|
||||
|
||||
|
||||
import { Cell, Game, Player, TerraNullius, Tile } from "./game/Game";
|
||||
import { Cell, Game, Player, TerraNullius, Tile, Unit } from "./game/Game";
|
||||
import { number } from 'zod';
|
||||
|
||||
export function manhattanDist(c1: Cell, c2: Cell): number {
|
||||
@@ -45,6 +45,11 @@ export function distSort(target: Tile): (a: Tile, b: Tile) => number {
|
||||
}
|
||||
}
|
||||
|
||||
export function distSortUnit(target: Unit): (a: Unit, b: Unit) => number {
|
||||
return (a: Unit, b: Unit) => {
|
||||
return manhattanDist(a.tile().cell(), target.tile().cell()) - manhattanDist(b.tile().cell(), target.tile().cell());
|
||||
}
|
||||
}
|
||||
export function and(x: (tile: Tile) => boolean, y: (tile: Tile) => boolean): (tile: Tile) => boolean {
|
||||
return (tile: Tile) => x(tile) && y(tile)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
|
||||
import { AStar, PathFinder } from "../PathFinding";
|
||||
import { PseudoRandom } from "../PseudoRandom";
|
||||
import { distSort, manhattanDist } from "../Util";
|
||||
import { distSort, distSortUnit, manhattanDist } from "../Util";
|
||||
|
||||
export class DestroyerExecution implements Execution {
|
||||
private random: PseudoRandom
|
||||
@@ -56,7 +56,7 @@ export class DestroyerExecution implements Execution {
|
||||
if (this.target == null) {
|
||||
const ships = this.mg.units(UnitType.TransportShip)
|
||||
.filter(u => manhattanDist(u.tile().cell(), this.destroyer.tile().cell()) < 100)
|
||||
// .filter(u => u.owner() != this.destroyer.owner())
|
||||
.filter(u => u.owner() != this.destroyer.owner())
|
||||
.filter(u => u != this.destroyer)
|
||||
.filter(u => !u.owner().isAlliedWith(this.destroyer.owner()))
|
||||
if (ships.length == 0) {
|
||||
@@ -72,8 +72,7 @@ export class DestroyerExecution implements Execution {
|
||||
}
|
||||
return
|
||||
}
|
||||
// TODO: sort by distance
|
||||
this.target = ships[0]
|
||||
this.target = ships.sort(distSortUnit(this.destroyer))[0]
|
||||
}
|
||||
if (manhattanDist(this.destroyer.tile().cell(), this.target.tile().cell()) < 5) {
|
||||
this.target.delete()
|
||||
|
||||
@@ -57,12 +57,12 @@ export class PortExecution implements Execution {
|
||||
this.port.setOwner(this.port.tile().owner() as Player)
|
||||
}
|
||||
|
||||
const ports = this.mg.units(UnitType.Port)
|
||||
const allPorts = this.mg.units(UnitType.Port)
|
||||
.filter(u => u.owner() != this.player)
|
||||
if (ports.length == 0) {
|
||||
if (allPorts.length == 0) {
|
||||
return
|
||||
}
|
||||
for (const port of ports) {
|
||||
for (const port of allPorts) {
|
||||
if (this.computingPaths.has(port)) {
|
||||
const aStar = this.computingPaths.get(port)
|
||||
if (aStar.compute(10_000)) {
|
||||
@@ -76,8 +76,17 @@ export class PortExecution implements Execution {
|
||||
continue
|
||||
}
|
||||
}
|
||||
for (const port of this.portPaths.keys()) {
|
||||
if (!port.isActive()) {
|
||||
this.portPaths.delete(port)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.random.chance(50)) {
|
||||
const port = this.random.randElement(Array.from(this.portPaths.keys()))
|
||||
const port = this.random.randElement(
|
||||
Array.from(this.portPaths.keys())
|
||||
.filter(p => this.port.owner().isAlliedWith(p.owner()))
|
||||
)
|
||||
const path = this.portPaths.get(port)
|
||||
this.mg.addExecution(new TradeShipExecution(this._owner, this.port, port, path))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user