mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-09 02:03:13 +00:00
create troop slider
This commit is contained in:
@@ -159,6 +159,7 @@ export class AttackExecution implements Execution {
|
||||
this.troops -= attackerTroopLoss
|
||||
if (this.target.isPlayer()) {
|
||||
this.target.removeTroops(defenderTroopLoss)
|
||||
this.target.removeManpower(defenderTroopLoss)
|
||||
}
|
||||
this._owner.conquer(tileToConquer)
|
||||
this.checkDefenderDead()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {PriorityQueue} from "@datastructures-js/priority-queue";
|
||||
import {Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, TileEvent} from "../game/Game";
|
||||
import {and, bfs, manhattanDistWrapped, sourceDstOceanShore} from "../Util";
|
||||
import {AttackExecution} from "./AttackExecution";
|
||||
import {DisplayMessageEvent, MessageType} from "../../client/graphics/layers/EventsDisplay";
|
||||
import { PriorityQueue } from "@datastructures-js/priority-queue";
|
||||
import { Boat, Cell, Execution, MutableBoat, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile, TileEvent } from "../game/Game";
|
||||
import { and, bfs, manhattanDistWrapped, sourceDstOceanShore } from "../Util";
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/EventsDisplay";
|
||||
|
||||
export class BoatAttackExecution implements Execution {
|
||||
|
||||
@@ -145,14 +145,14 @@ export class BoatAttackExecution implements Execution {
|
||||
}
|
||||
|
||||
export class AStar {
|
||||
private openSet: PriorityQueue<{tile: Tile, fScore: number}>;
|
||||
private openSet: PriorityQueue<{ tile: Tile, fScore: number }>;
|
||||
private cameFrom: Map<Tile, Tile>;
|
||||
private gScore: Map<Tile, number>;
|
||||
private current: Tile | null;
|
||||
public completed: boolean;
|
||||
|
||||
constructor(private src: Tile, private dst: Tile) {
|
||||
this.openSet = new PriorityQueue<{tile: Tile, fScore: number}>(
|
||||
this.openSet = new PriorityQueue<{ tile: Tile, fScore: number }>(
|
||||
(a, b) => a.fScore - b.fScore
|
||||
);
|
||||
this.cameFrom = new Map<Tile, Tile>();
|
||||
@@ -161,7 +161,7 @@ export class AStar {
|
||||
this.completed = false;
|
||||
|
||||
this.gScore.set(src, 0);
|
||||
this.openSet.enqueue({tile: src, fScore: this.heuristic(src, dst)});
|
||||
this.openSet.enqueue({ tile: src, fScore: this.heuristic(src, dst) });
|
||||
}
|
||||
|
||||
compute(iterations: number): boolean {
|
||||
@@ -189,7 +189,7 @@ export class AStar {
|
||||
this.gScore.set(neighbor, tentativeGScore);
|
||||
const fScore = tentativeGScore + this.heuristic(neighbor, this.dst);
|
||||
|
||||
this.openSet.enqueue({tile: neighbor, fScore: fScore});
|
||||
this.openSet.enqueue({ tile: neighbor, fScore: fScore });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ export class Executor {
|
||||
return new DonateExecution(intent.sender, intent.recipient, intent.troops)
|
||||
} else if (intent.type == "nuke") {
|
||||
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude)
|
||||
} else if (intent.type == "troop_ratio") {
|
||||
return new SetTargetTroopRatioExecution(intent.player, intent.ratio)
|
||||
} else {
|
||||
throw new Error(`intent type ${intent} not found`)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class FakeHumanExecution implements Execution {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.player.troops() < this.mg.config().maxTroops(this.player) / 4) {
|
||||
if (this.player.troops() < this.mg.config().maxManpower(this.player) / 4) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, Tile} from "../game/Game";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {bfs, dist, euclideanDist, manhattanDist} from "../Util";
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, PlayerID, Tile } from "../game/Game";
|
||||
import { PseudoRandom } from "../PseudoRandom";
|
||||
import { bfs, dist, euclideanDist, manhattanDist } from "../Util";
|
||||
|
||||
export class NukeExecution implements Execution {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Config} from "../configuration/Config"
|
||||
import {Execution, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile} from "../game/Game"
|
||||
import {bfs, calculateBoundingBox, getMode, inscribed, simpleHash} from "../Util"
|
||||
import {GameImpl} from "../game/GameImpl"
|
||||
import { Config } from "../configuration/Config"
|
||||
import { Execution, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile } from "../game/Game"
|
||||
import { bfs, calculateBoundingBox, getMode, inscribed, simpleHash } from "../Util"
|
||||
import { GameImpl } from "../game/GameImpl"
|
||||
|
||||
export class PlayerExecution implements Execution {
|
||||
|
||||
@@ -30,7 +30,9 @@ export class PlayerExecution implements Execution {
|
||||
if (ticks < this.config.numSpawnPhaseTurns()) {
|
||||
return
|
||||
}
|
||||
this.player.setTroops(this.config.troopAdditionRate(this.player))
|
||||
this.player.addManpower(this.config.manpowerAdditionRate(this.player))
|
||||
this.player.addGold(this.config.goldAdditionRate(this.player))
|
||||
this.player.addTroops(this.config.troopAdjustmentRate(this.player))
|
||||
|
||||
const alliances = Array.from(this.player.alliances())
|
||||
for (const alliance of alliances) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Execution, MutableGame, MutablePlayer, PlayerID } from "../game/Game";
|
||||
|
||||
export class SetTargetTroopRatioExecution implements Execution {
|
||||
|
||||
private player: MutablePlayer
|
||||
|
||||
private active = true
|
||||
|
||||
constructor(private playerID: PlayerID, private targetTroopsRatio: number) { }
|
||||
|
||||
|
||||
init(mg: MutableGame, ticks: number): void {
|
||||
this.player = mg.player(this.playerID)
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
if (this.targetTroopsRatio < 0 || this.targetTroopsRatio > 1) {
|
||||
console.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`)
|
||||
} else {
|
||||
this.player.setTargetTroopRatio(this.targetTroopsRatio)
|
||||
}
|
||||
this.active = false
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo, PlayerType} from "../game/Game"
|
||||
import {BotExecution} from "./BotExecution"
|
||||
import {PlayerExecution} from "./PlayerExecution"
|
||||
import {getSpawnCells} from "./Util"
|
||||
import { Cell, Execution, MutableGame, MutablePlayer, PlayerInfo, PlayerType } from "../game/Game"
|
||||
import { BotExecution } from "./BotExecution"
|
||||
import { PlayerExecution } from "./PlayerExecution"
|
||||
import { getSpawnCells } from "./Util"
|
||||
|
||||
export class SpawnExecution implements Execution {
|
||||
|
||||
@@ -33,7 +33,7 @@ export class SpawnExecution implements Execution {
|
||||
return
|
||||
}
|
||||
|
||||
const player = this.mg.addPlayer(this.playerInfo, this.mg.config().startTroops(this.playerInfo))
|
||||
const player = this.mg.addPlayer(this.playerInfo, this.mg.config().startManpower(this.playerInfo))
|
||||
getSpawnCells(this.mg, this.cell).forEach(c => {
|
||||
player.conquer(this.mg.tile(c))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user