can attack terra nullius with boats

This commit is contained in:
evanpelle
2024-08-23 20:33:09 -07:00
parent 41d7c77d2d
commit 7bdad3577d
3 changed files with 25 additions and 15 deletions
+2
View File
@@ -46,7 +46,9 @@
* try vintage theme
* add shader to dim border
* remove player.info()
* give terranullius an ID, game.player() returns terranullius
* give time to (re) spawn at start of game
* store & delay tile updates for lag compensation
* BUG: ocean is considered TerraNullius ?
* BUG: fix hotreload (priority queue breaks it)
* PERF: use hierarchical a* search for boats
+10 -7
View File
@@ -190,13 +190,16 @@ export class ClientGame {
const owner = tile.owner()
const targetID = owner.isPlayer() ? owner.id() : null
if (tile.owner() != this.myPlayer && tile.isLand()) {
// const ocean = Array.from(bfs(tile, 4))
// .filter(t => t.isOcean)
// .sort((a, b) => manhattanDist(tile.cell(), a.cell()) - manhattanDist(tile.cell(), b.cell()))
// if (ocean.length > 0) {
// this.sendBoatAttackIntent(targetID, cell, this.config.player().boatAttackAmount(this.myPlayer, owner))
// return
// }
const tn = Array.from(bfs(tile, 6))
.filter(t => t.isOcean())
.filter(t => !t.hasOwner())
.sort((a, b) => manhattanDist(tile.cell(), a.cell()) - manhattanDist(tile.cell(), b.cell()))
.flatMap(t => t.neighbors())
.filter(n => n.isShore())
if (tn.length > 0) {
this.sendBoatAttackIntent(targetID, tn[0].cell(), this.config.player().boatAttackAmount(this.myPlayer, owner))
return
}
if (this.myPlayer.sharesBorderWith(tile.owner())) {
this.sendAttackIntent(targetID, cell, this.config.player().attackAmount(this.myPlayer, owner))
+13 -8
View File
@@ -1,5 +1,5 @@
import PriorityQueue from "priority-queue-typescript";
import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, Tile, TileEvent} from "../Game";
import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, TileEvent} from "../Game";
import {manhattanDist} from "../Util";
import {AttackExecution} from "./AttackExecution";
import {Config, PlayerConfig} from "../configuration/Config";
@@ -15,7 +15,7 @@ export class BoatAttackExecution implements Execution {
private mg: MutableGame
private attacker: MutablePlayer
private target: MutablePlayer
private target: MutablePlayer | TerraNullius
// TODO make private
public path: Tile[]
@@ -40,20 +40,25 @@ export class BoatAttackExecution implements Execution {
) { }
init(mg: MutableGame, ticks: number) {
if (this.targetID == null) {
throw new Error("attacking terranullius not supported")
}
this.lastMove = ticks
this.mg = mg
this.attacker = mg.player(this.attackerID)
this.target = mg.player(this.targetID)
if (this.targetID == null) {
this.target = mg.terraNullius()
} else {
this.target = mg.player(this.targetID)
}
this.troops = Math.min(this.troops, this.attacker.troops())
this.attacker.removeTroops(this.troops)
this.src = this.closestShoreTileToTarget(this.attacker, this.cell)
this.dst = this.closestShoreTileToTarget(this.target, this.cell)
if (this.target.isPlayer()) {
this.dst = this.closestShoreTileToTarget(this.target, this.cell)
} else {
this.dst = this.mg.tile(this.cell)
}
if (this.src == null || this.dst == null) {
this.active = false
@@ -64,7 +69,7 @@ export class BoatAttackExecution implements Execution {
this.path = this.aStarPre.reconstructPath()
if (this.path != null) {
console.log(`got path ${this.path.map(t => t.cell().toString())}`)
this.boat = this.attacker.addBoat(1000, this.src, this.target)
this.boat = this.attacker.addBoat(this.troops, this.src, this.target)
} else {
console.log('got null path')
this.active = false