mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 08:20:50 +00:00
added gold, troops, workers slider
This commit is contained in:
@@ -48,7 +48,7 @@
|
|||||||
593,
|
593,
|
||||||
473
|
473
|
||||||
],
|
],
|
||||||
"name": "Venezuala 🇻🇪",
|
"name": "Venezuela 🇻🇪",
|
||||||
"strength": 1
|
"strength": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ import { customElement, property, state } from 'lit/decorators.js';
|
|||||||
import { Layer } from './Layer';
|
import { Layer } from './Layer';
|
||||||
import { Game } from '../../../core/game/Game';
|
import { Game } from '../../../core/game/Game';
|
||||||
import { ClientID } from '../../../core/Schemas';
|
import { ClientID } from '../../../core/Schemas';
|
||||||
import { renderTroops } from '../Utils';
|
import { renderNumber, renderTroops } from '../Utils';
|
||||||
import { EventBus } from '../../../core/EventBus';
|
import { EventBus } from '../../../core/EventBus';
|
||||||
import { UIState } from '../UIState';
|
import { UIState } from '../UIState';
|
||||||
|
import { SendSetTargetTroopRatioEvent } from '../../Transport';
|
||||||
|
|
||||||
@customElement('control-panel')
|
@customElement('control-panel')
|
||||||
export class ControlPanel extends LitElement implements Layer {
|
export class ControlPanel extends LitElement implements Layer {
|
||||||
@@ -15,20 +16,39 @@ export class ControlPanel extends LitElement implements Layer {
|
|||||||
public uiState: UIState
|
public uiState: UIState
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
private targetTroopRatio = 50;
|
private attackRatio: number = .2;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private targetTroopRatio = 1;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _population: number;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _maxPopulation: number;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private popRate: number;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
private _troops: number;
|
private _troops: number;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
private _maxTroops: number;
|
private _workers: number;
|
||||||
|
|
||||||
@state()
|
|
||||||
private troopRate: number;
|
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
private _isVisible = false;
|
private _isVisible = false;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _manpower: number = 0;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _gold: number
|
||||||
|
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private _goldPerSecond: number
|
||||||
|
|
||||||
init(game: Game) {
|
init(game: Game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.attackRatio = .20
|
this.attackRatio = .20
|
||||||
@@ -43,10 +63,16 @@ export class ControlPanel extends LitElement implements Layer {
|
|||||||
|
|
||||||
const player = this.game.playerByClientID(this.clientID)
|
const player = this.game.playerByClientID(this.clientID)
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
this._isVisible = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this._population = player.population()
|
||||||
|
this._maxPopulation = this.game.config().maxPopulation(player)
|
||||||
|
this._gold = player.gold()
|
||||||
this._troops = player.troops()
|
this._troops = player.troops()
|
||||||
this._maxTroops = this.game.config().maxTroops(player)
|
this._workers = player.workers()
|
||||||
|
this.popRate = this.game.config().populationIncreaseRate(player) * 10
|
||||||
|
this._goldPerSecond = this.game.config().goldAdditionRate(player) * 10
|
||||||
}
|
}
|
||||||
|
|
||||||
onAttackRatioChange(newRatio: number) {
|
onAttackRatioChange(newRatio: number) {
|
||||||
@@ -67,7 +93,19 @@ export class ControlPanel extends LitElement implements Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetTroops(): number {
|
targetTroops(): number {
|
||||||
return this._manpower * this.targetTroopRatio / 100
|
return this._manpower * this.targetTroopRatio
|
||||||
|
}
|
||||||
|
|
||||||
|
onTroopChange(newRatio: number) {
|
||||||
|
this.eventBus.emit(new SendSetTargetTroopRatioEvent(newRatio))
|
||||||
|
}
|
||||||
|
|
||||||
|
delta(): number {
|
||||||
|
const d = this._population - this.targetTroops()
|
||||||
|
// if (Math.abs(d) < this._manpower / 200) {
|
||||||
|
// return 0
|
||||||
|
// }
|
||||||
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,16 +167,36 @@ export class ControlPanel extends LitElement implements Layer {
|
|||||||
<div class="control-panel ${this._isVisible ? '' : 'hidden'}">
|
<div class="control-panel ${this._isVisible ? '' : 'hidden'}">
|
||||||
<div class="control-panel-info">
|
<div class="control-panel-info">
|
||||||
<div class="info-row">
|
<div class="info-row">
|
||||||
<span class="info-label">Troops:</span>
|
<span class="info-label">Population:</span>
|
||||||
<span>${renderTroops(this._troops)} / ${renderTroops(this._maxTroops)}</span>
|
<span>${renderTroops(this._population)} / ${renderTroops(this._maxPopulation)}</span>
|
||||||
|
</div>
|
||||||
|
<div class="info-row">
|
||||||
|
<span class="info-label">Population/s:</span>
|
||||||
|
<span>${renderTroops(this.popRate)}</span>
|
||||||
|
</div>
|
||||||
|
<div class="info-row">
|
||||||
|
<span class="info-label">Gold:</span>
|
||||||
|
<span>${renderNumber(this._gold)}</span>
|
||||||
|
</div>
|
||||||
|
<div class="info-row">
|
||||||
|
<span class="info-label">Gold/s:</span>
|
||||||
|
<span>${renderNumber(this._goldPerSecond)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="slider-container">
|
<div class="slider-container">
|
||||||
<label for="numTroops">Troops: ${this.targetTroopRatio}% (${renderTroops(this.targetTroops()) + ", delta: " + renderTroops(this.delta())})</label>
|
<label for="numTroops">Troops: ${renderTroops(this._troops)} | Workers: ${renderTroops(this._workers)}</label>
|
||||||
<input type="range" id="numTroops" min="0" max="100" .value=${this.targetTroopRatio}
|
<input type="range" id="numTroops" min="1" max="10" .value=${this.targetTroopRatio * 10}
|
||||||
@input=${(e: Event) => {
|
@input=${(e: Event) => {
|
||||||
this.targetTroopRatio = parseInt((e.target as HTMLInputElement).value);
|
this.targetTroopRatio = parseInt((e.target as HTMLInputElement).value) / 10;
|
||||||
this.onTroopChange(this.targetTroopRatio / 100);
|
this.onTroopChange(this.targetTroopRatio);
|
||||||
|
}}>
|
||||||
|
</div>
|
||||||
|
<div class="slider-container">
|
||||||
|
<label for="numTroops">Attack Ratio: ${this.attackRatio * 100}%</label>
|
||||||
|
<input type="range" id="numTroops" min="1" max="10" value=${this.attackRatio * 10}
|
||||||
|
@input=${(e: Event) => {
|
||||||
|
this.attackRatio = parseInt((e.target as HTMLInputElement).value) / 10;
|
||||||
|
this.onAttackRatioChange(this.attackRatio);
|
||||||
}}>
|
}}>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export interface Config {
|
|||||||
numSpawnPhaseTurns(): number
|
numSpawnPhaseTurns(): number
|
||||||
|
|
||||||
startManpower(playerInfo: PlayerInfo): number
|
startManpower(playerInfo: PlayerInfo): number
|
||||||
manpowerAdditionRate(player: Player): number
|
populationIncreaseRate(player: Player): number
|
||||||
goldAdditionRate(player: Player): number
|
goldAdditionRate(player: Player): number
|
||||||
troopAdjustmentRate(player: Player): number
|
troopAdjustmentRate(player: Player): number
|
||||||
attackTilesPerTick(attacker: Player, defender: Player | TerraNullius, numAdjacentTilesWithEnemy: number): number
|
attackTilesPerTick(attacker: Player, defender: Player | TerraNullius, numAdjacentTilesWithEnemy: number): number
|
||||||
@@ -44,7 +44,7 @@ export interface Config {
|
|||||||
tilesPerTickUsed: number
|
tilesPerTickUsed: number
|
||||||
}
|
}
|
||||||
attackAmount(attacker: Player, defender: Player | TerraNullius): number
|
attackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||||
maxManpower(player: Player): number
|
maxPopulation(player: Player): number
|
||||||
boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number
|
boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||||
boatMaxDistance(): number
|
boatMaxDistance(): number
|
||||||
boatMaxNumber(): number
|
boatMaxNumber(): number
|
||||||
|
|||||||
@@ -130,21 +130,20 @@ export class DefaultConfig implements Config {
|
|||||||
return 25000
|
return 25000
|
||||||
}
|
}
|
||||||
|
|
||||||
maxManpower(player: Player): number {
|
maxPopulation(player: Player): number {
|
||||||
let max = Math.sqrt(player.numTilesOwned()) * 3000 + 50000
|
let maxPop = Math.sqrt(player.numTilesOwned()) * 3000 + 50000
|
||||||
const manpower = Math.min(max, 2_000_000)
|
|
||||||
if (player.type() == PlayerType.Bot) {
|
if (player.type() == PlayerType.Bot) {
|
||||||
return manpower
|
return maxPop
|
||||||
}
|
}
|
||||||
return manpower * 2
|
return maxPop * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
manpowerAdditionRate(player: Player): number {
|
populationIncreaseRate(player: Player): number {
|
||||||
let max = this.maxManpower(player)
|
let max = this.maxPopulation(player)
|
||||||
|
|
||||||
let toAdd = 10 + (player.totalManpower() + Math.sqrt(player.totalManpower() * player.numTilesOwned())) / 100
|
let toAdd = 10 + (player.population() + Math.sqrt(player.population() * player.numTilesOwned())) / 100
|
||||||
|
|
||||||
const ratio = 1 - (player.totalManpower() / max)
|
const ratio = 1 - (player.population() / max)
|
||||||
toAdd *= ratio
|
toAdd *= ratio
|
||||||
toAdd *= .5
|
toAdd *= .5
|
||||||
// console.log(`to add ${toAdd}`)
|
// console.log(`to add ${toAdd}`)
|
||||||
@@ -155,14 +154,17 @@ export class DefaultConfig implements Config {
|
|||||||
if (player.type() == PlayerType.Bot) {
|
if (player.type() == PlayerType.Bot) {
|
||||||
toAdd *= .7
|
toAdd *= .7
|
||||||
}
|
}
|
||||||
return toAdd
|
|
||||||
|
return Math.min(player.troops() + toAdd, max) - player.troops()
|
||||||
}
|
}
|
||||||
|
|
||||||
goldAdditionRate(player: Player): number {
|
goldAdditionRate(player: Player): number {
|
||||||
return (player.manpowerReserve() * 1.2 - player.troops()) / 1000
|
return Math.sqrt(player.workers() * player.numTilesOwned()) / 1000 + player.gold() * .001
|
||||||
}
|
}
|
||||||
|
|
||||||
troopAdjustmentRate(player: Player): number {
|
troopAdjustmentRate(player: Player): number {
|
||||||
const maxDiff = player.maxTroops() / 300
|
const maxDiff = this.maxPopulation(player) / 300
|
||||||
const target = player.maxTroops() * player.targetTroopRatio()
|
const target = player.population() * player.targetTroopRatio()
|
||||||
const diff = target - player.troops()
|
const diff = target - player.troops()
|
||||||
if (Math.abs(diff) < maxDiff) {
|
if (Math.abs(diff) < maxDiff) {
|
||||||
return diff
|
return diff
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { TargetPlayerExecution } from "./TargetPlayerExecution";
|
|||||||
import { EmojiExecution } from "./EmojiExecution";
|
import { EmojiExecution } from "./EmojiExecution";
|
||||||
import { DonateExecution } from "./DonateExecution";
|
import { DonateExecution } from "./DonateExecution";
|
||||||
import { NukeExecution } from "./NukeExecution";
|
import { NukeExecution } from "./NukeExecution";
|
||||||
|
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export class FakeHumanExecution implements Execution {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.player.troops() < this.mg.config().maxManpower(this.player) / 4) {
|
if (this.player.troops() < this.mg.config().maxPopulation(this.player) / 4) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,13 +30,14 @@ export class PlayerExecution implements Execution {
|
|||||||
if (ticks < this.config.numSpawnPhaseTurns()) {
|
if (ticks < this.config.numSpawnPhaseTurns()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const popInc = this.config.populationIncreaseRate(this.player)
|
||||||
|
|
||||||
this.player.addManpowerReserve(this.config.manpowerAdditionRate(this.player))
|
this.player.addWorkers(popInc * (1 - this.player.targetTroopRatio()))// (1 - this.player.targetTroopRatio()))
|
||||||
this.player.setMaxTroops(Math.max(this.player.numTilesOwned() * 100, 50000))
|
this.player.addTroops(popInc * this.player.targetTroopRatio())
|
||||||
this.player.addGold(this.config.goldAdditionRate(this.player))
|
this.player.addGold(this.config.goldAdditionRate(this.player))
|
||||||
const adjustRate = this.config.troopAdjustmentRate(this.player)
|
const adjustRate = this.config.troopAdjustmentRate(this.player)
|
||||||
this.player.addTroops(adjustRate)
|
this.player.addTroops(adjustRate)
|
||||||
this.player.removeManpowerReserve(adjustRate)
|
this.player.removeWorkers(adjustRate)
|
||||||
|
|
||||||
const alliances = Array.from(this.player.alliances())
|
const alliances = Array.from(this.player.alliances())
|
||||||
for (const alliance of alliances) {
|
for (const alliance of alliances) {
|
||||||
|
|||||||
+11
-10
@@ -167,7 +167,6 @@ export interface Player {
|
|||||||
clientID(): ClientID
|
clientID(): ClientID
|
||||||
id(): PlayerID
|
id(): PlayerID
|
||||||
type(): PlayerType
|
type(): PlayerType
|
||||||
troops(): number
|
|
||||||
boats(): Boat[]
|
boats(): Boat[]
|
||||||
ownsTile(cell: Cell): boolean
|
ownsTile(cell: Cell): boolean
|
||||||
isAlive(): boolean
|
isAlive(): boolean
|
||||||
@@ -196,17 +195,15 @@ export interface Player {
|
|||||||
outgoingEmojis(): EmojiMessage[]
|
outgoingEmojis(): EmojiMessage[]
|
||||||
canDonate(recipient: Player): boolean
|
canDonate(recipient: Player): boolean
|
||||||
gold(): Gold
|
gold(): Gold
|
||||||
totalManpower(): number
|
// Population = troops + workers
|
||||||
manpowerReserve(): number
|
population(): number
|
||||||
|
workers(): number
|
||||||
// Number between 0, 1
|
// Number between 0, 1
|
||||||
targetTroopRatio(): number
|
targetTroopRatio(): number
|
||||||
maxTroops(): number
|
troops(): number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MutablePlayer extends Player {
|
export interface MutablePlayer extends Player {
|
||||||
setTroops(troops: number): void
|
|
||||||
addTroops(troops: number): void
|
|
||||||
removeTroops(troops: number): number
|
|
||||||
conquer(tile: Tile): void
|
conquer(tile: Tile): void
|
||||||
relinquish(tile: Tile): void
|
relinquish(tile: Tile): void
|
||||||
executions(): Execution[]
|
executions(): Execution[]
|
||||||
@@ -224,12 +221,16 @@ export interface MutablePlayer extends Player {
|
|||||||
transitiveTargets(): MutablePlayer[]
|
transitiveTargets(): MutablePlayer[]
|
||||||
sendEmoji(recipient: Player | typeof AllPlayers, emoji: string): void
|
sendEmoji(recipient: Player | typeof AllPlayers, emoji: string): void
|
||||||
donate(recipient: MutablePlayer, troops: number): void
|
donate(recipient: MutablePlayer, troops: number): void
|
||||||
|
|
||||||
addGold(toAdd: Gold): void
|
addGold(toAdd: Gold): void
|
||||||
removeGold(toRemove: Gold): void
|
removeGold(toRemove: Gold): void
|
||||||
addManpowerReserve(toAdd: number): void
|
|
||||||
removeManpowerReserve(toRemove: number): void
|
addWorkers(toAdd: number): void
|
||||||
|
removeWorkers(toRemove: number): void
|
||||||
setTargetTroopRatio(target: number): void
|
setTargetTroopRatio(target: number): void
|
||||||
setMaxTroops(maxTroops: number): void
|
setTroops(troops: number): void
|
||||||
|
addTroops(troops: number): void
|
||||||
|
removeTroops(troops: number): number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Game {
|
export interface Game {
|
||||||
|
|||||||
+36
-41
@@ -1,4 +1,4 @@
|
|||||||
import { MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent, EmojiMessage, EmojiMessageEvent, AllPlayers, Currency } from "./Game";
|
import { MutablePlayer, Tile, PlayerInfo, PlayerID, PlayerType, Player, TerraNullius, Cell, Execution, AllianceRequest, MutableAllianceRequest, MutableAlliance, Alliance, Tick, TargetPlayerEvent, EmojiMessage, EmojiMessageEvent, AllPlayers, Gold } from "./Game";
|
||||||
import { ClientID } from "../Schemas";
|
import { ClientID } from "../Schemas";
|
||||||
import { processName, simpleHash } from "../Util";
|
import { processName, simpleHash } from "../Util";
|
||||||
import { CellString, GameImpl } from "./GameImpl";
|
import { CellString, GameImpl } from "./GameImpl";
|
||||||
@@ -22,9 +22,8 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
|
|
||||||
private _gold: Gold
|
private _gold: Gold
|
||||||
private _troops: number
|
private _troops: number
|
||||||
private _reserves: number
|
private _workers: number
|
||||||
private _targetTroopRatio: number
|
private _targetTroopRatio: number = 1
|
||||||
private _maxTroops: number
|
|
||||||
|
|
||||||
isTraitor_ = false
|
isTraitor_ = false
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
public _tiles: Map<CellString, Tile> = new Map<CellString, Tile>();
|
public _tiles: Map<CellString, Tile> = new Map<CellString, Tile>();
|
||||||
|
|
||||||
private _name: string;
|
private _name: string;
|
||||||
private _displayerName: string;
|
private _displayName: string;
|
||||||
|
|
||||||
public pastOutgoingAllianceRequests: AllianceRequest[] = []
|
public pastOutgoingAllianceRequests: AllianceRequest[] = []
|
||||||
|
|
||||||
@@ -44,20 +43,21 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
|
|
||||||
private sentDonations: Donation[] = []
|
private sentDonations: Donation[] = []
|
||||||
|
|
||||||
constructor(private gs: GameImpl, private readonly playerInfo: PlayerInfo, manpower: number) {
|
constructor(private gs: GameImpl, private readonly playerInfo: PlayerInfo, startPopulation: number) {
|
||||||
this._name = playerInfo.name;
|
this._name = playerInfo.name;
|
||||||
this._targetTroopRatio = .5
|
this._targetTroopRatio = 1
|
||||||
this._troops = manpower * this._targetTroopRatio;
|
this._troops = startPopulation * this._targetTroopRatio;
|
||||||
this._reserves = manpower * (1 - this._targetTroopRatio)
|
this._workers = startPopulation * (1 - this._targetTroopRatio)
|
||||||
this._gold = 0
|
this._gold = 0
|
||||||
this._maxTroops = 0
|
this._displayName = processName(this._name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
name(): string {
|
name(): string {
|
||||||
return this._name;
|
return this._name;
|
||||||
}
|
}
|
||||||
displayName(): string {
|
displayName(): string {
|
||||||
return this._displayerName
|
return this._displayName
|
||||||
}
|
}
|
||||||
|
|
||||||
clientID(): ClientID {
|
clientID(): ClientID {
|
||||||
@@ -118,22 +118,6 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
return Array.from(ns);
|
return Array.from(ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
addTroops(troops: number): void {
|
|
||||||
if (troops < 0) {
|
|
||||||
this.removeTroops(-1 * troops)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this._troops += Math.floor(troops);
|
|
||||||
}
|
|
||||||
removeTroops(troops: number): number {
|
|
||||||
if (troops <= 1) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
const toRemove = Math.floor(Math.min(this._troops - 1, troops))
|
|
||||||
this._troops -= toRemove;
|
|
||||||
return toRemove
|
|
||||||
}
|
|
||||||
|
|
||||||
isPlayer(): this is MutablePlayer { return true as const; }
|
isPlayer(): this is MutablePlayer { return true as const; }
|
||||||
ownsTile(cell: Cell): boolean { return this._tiles.has(cell.toString()); }
|
ownsTile(cell: Cell): boolean { return this._tiles.has(cell.toString()); }
|
||||||
setTroops(troops: number) { this._troops = Math.floor(troops); }
|
setTroops(troops: number) { this._troops = Math.floor(troops); }
|
||||||
@@ -145,7 +129,6 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
this.gs.relinquish(tile);
|
this.gs.relinquish(tile);
|
||||||
}
|
}
|
||||||
info(): PlayerInfo { return this.playerInfo; }
|
info(): PlayerInfo { return this.playerInfo; }
|
||||||
troops(): number { return this._troops; }
|
|
||||||
isAlive(): boolean { return this._tiles.size > 0; }
|
isAlive(): boolean { return this._tiles.size > 0; }
|
||||||
executions(): Execution[] {
|
executions(): Execution[] {
|
||||||
return this.gs.executions().filter(exec => exec.owner().id() == this.id());
|
return this.gs.executions().filter(exec => exec.owner().id() == this.id());
|
||||||
@@ -297,17 +280,17 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
this._gold -= toRemove
|
this._gold -= toRemove
|
||||||
}
|
}
|
||||||
|
|
||||||
totalManpower(): number {
|
population(): number {
|
||||||
return this._troops + this._reserves
|
return this._troops + this._workers
|
||||||
}
|
}
|
||||||
manpowerReserve(): number {
|
workers(): number {
|
||||||
return Math.max(1, this._reserves)
|
return Math.max(1, this._workers)
|
||||||
}
|
}
|
||||||
addManpowerReserve(toAdd: number): void {
|
addWorkers(toAdd: number): void {
|
||||||
this._reserves += toAdd
|
this._workers += toAdd
|
||||||
}
|
}
|
||||||
removeManpowerReserve(toRemove: number): void {
|
removeWorkers(toRemove: number): void {
|
||||||
this._reserves = Math.max(1, this._reserves - toRemove)
|
this._workers = Math.max(1, this._workers - toRemove)
|
||||||
}
|
}
|
||||||
|
|
||||||
targetTroopRatio(): number {
|
targetTroopRatio(): number {
|
||||||
@@ -321,15 +304,27 @@ export class PlayerImpl implements MutablePlayer {
|
|||||||
this._targetTroopRatio = target
|
this._targetTroopRatio = target
|
||||||
}
|
}
|
||||||
|
|
||||||
maxTroops(): number {
|
troops(): number { return this._troops; }
|
||||||
return this._maxTroops
|
|
||||||
|
addTroops(troops: number): void {
|
||||||
|
if (troops < 0) {
|
||||||
|
this.removeTroops(-1 * troops)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this._troops += Math.floor(troops);
|
||||||
}
|
}
|
||||||
setMaxTroops(maxTroops: number): void {
|
removeTroops(troops: number): number {
|
||||||
this._maxTroops = maxTroops
|
if (troops <= 1) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
const toRemove = Math.floor(Math.min(this._troops - 1, troops))
|
||||||
|
this._troops -= toRemove;
|
||||||
|
return toRemove
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hash(): number {
|
hash(): number {
|
||||||
return simpleHash(this.id()) * (this.totalManpower() + this.numTilesOwned());
|
return simpleHash(this.id()) * (this.population() + this.numTilesOwned());
|
||||||
}
|
}
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `Player:{name:${this.info().name},clientID:${this.info().clientID},isAlive:${this.isAlive()},troops:${this._troops},numTileOwned:${this.numTilesOwned()}}]`;
|
return `Player:{name:${this.info().name},clientID:${this.info().clientID},isAlive:${this.isAlive()},troops:${this._troops},numTileOwned:${this.numTilesOwned()}}]`;
|
||||||
|
|||||||
Reference in New Issue
Block a user