mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 21:04:14 +00:00
population fix
This commit is contained in:
@@ -256,6 +256,8 @@ export class AttackExecution implements Execution {
|
||||
);
|
||||
numTilesPerTick -= tilesPerTickUsed;
|
||||
this.attack.setTroops(this.attack.troops() - attackerTroopLoss);
|
||||
this.attack.applyLosses(attackerTroopLoss);
|
||||
|
||||
if (this.target.isPlayer()) {
|
||||
this.target.removeTroops(defenderTroopLoss);
|
||||
}
|
||||
|
||||
@@ -182,6 +182,7 @@ export class NukeExecution implements Execution {
|
||||
.config()
|
||||
.nukeDeathFactor(attack.troops(), owner.numTilesOwned());
|
||||
attack.setTroops(attack.troops() - deaths);
|
||||
attack.applyLosses(deaths);
|
||||
});
|
||||
owner.units(UnitType.TransportShip).forEach((attack) => {
|
||||
const deaths = this.mg
|
||||
|
||||
@@ -7,13 +7,17 @@ export class AttackImpl implements Attack {
|
||||
public _retreating = false;
|
||||
public _retreated = false;
|
||||
|
||||
private _remainingTroops: number;
|
||||
|
||||
constructor(
|
||||
private _id: string,
|
||||
private _target: Player | TerraNullius,
|
||||
private _attacker: Player,
|
||||
private _troops: number,
|
||||
private _sourceTile: TileRef | null,
|
||||
) {}
|
||||
) {
|
||||
this._remainingTroops = _troops; // Start with full strength
|
||||
}
|
||||
|
||||
sourceTile(): TileRef | null {
|
||||
return this._sourceTile;
|
||||
@@ -31,6 +35,13 @@ export class AttackImpl implements Attack {
|
||||
setTroops(troops: number) {
|
||||
this._troops = troops;
|
||||
}
|
||||
remainingTroops(): number {
|
||||
return this._remainingTroops;
|
||||
}
|
||||
|
||||
applyLosses(losses: number): void {
|
||||
this._remainingTroops = Math.max(0, this._remainingTroops - losses);
|
||||
}
|
||||
|
||||
isActive() {
|
||||
return this._isActive;
|
||||
|
||||
@@ -214,6 +214,8 @@ export interface Attack {
|
||||
attacker(): Player;
|
||||
troops(): number;
|
||||
setTroops(troops: number): void;
|
||||
applyLosses(losses: number): void;
|
||||
remainingTroops(): number;
|
||||
isActive(): boolean;
|
||||
delete(): void;
|
||||
// The tile the attack originated from, mostly used for boat attacks.
|
||||
|
||||
@@ -645,8 +645,13 @@ export class PlayerImpl implements Player {
|
||||
private attackingTroops(): number {
|
||||
return this._outgoingAttacks
|
||||
.filter((a) => a.isActive())
|
||||
.reduce((sum, a) => sum + a.troops(), 0);
|
||||
.reduce(
|
||||
(sum, a) =>
|
||||
sum + (a instanceof AttackImpl ? a.remainingTroops() : a.troops()),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
private boatTroops(): number {
|
||||
return this.units(UnitType.TransportShip)
|
||||
.map((u) => u.troops())
|
||||
|
||||
Reference in New Issue
Block a user