mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-12 10:33:51 +00:00
fake humans retaliate against humans
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerrainType, TerraNullius, Tile} from "../Game"
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile} from "../Game"
|
||||
import {PseudoRandom} from "../PseudoRandom"
|
||||
import {and, bfs, dist, simpleHash} from "../Util";
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
@@ -14,6 +14,8 @@ export class FakeHumanExecution implements Execution {
|
||||
private neighborsTerraNullius = true
|
||||
private player: Player = null
|
||||
|
||||
private enemy: Player | null = null
|
||||
|
||||
|
||||
constructor(private playerInfo: PlayerInfo) {
|
||||
this.random = new PseudoRandom(simpleHash(playerInfo.id))
|
||||
@@ -49,6 +51,27 @@ export class FakeHumanExecution implements Execution {
|
||||
return
|
||||
}
|
||||
|
||||
if (ticks % 100 == 0) {
|
||||
this.enemy = null
|
||||
}
|
||||
|
||||
if (this.enemy == null) {
|
||||
this.enemy = this.mg.executions()
|
||||
.filter(e => e instanceof AttackExecution)
|
||||
.map(e => e as AttackExecution)
|
||||
.filter(e => e.targetID() == this.player.id())
|
||||
.map(e => e.owner())
|
||||
.find(enemy => enemy && enemy.type() == PlayerType.Human)
|
||||
}
|
||||
|
||||
if (this.enemy) {
|
||||
if (this.player.sharesBorderWith(this.enemy)) {
|
||||
this.sendAttack(this.enemy)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (this.neighborsTerraNullius) {
|
||||
for (const b of this.player.borderTiles()) {
|
||||
for (const n of b.neighbors()) {
|
||||
|
||||
Reference in New Issue
Block a user