population fix

This commit is contained in:
1brucben
2025-05-08 00:09:04 +02:00
parent a3996d539f
commit c3ea0811eb
5 changed files with 23 additions and 2 deletions
+2
View File
@@ -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);
}
+1
View File
@@ -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
+12 -1
View File
@@ -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;
+2
View File
@@ -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.
+6 -1
View File
@@ -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())