city pop dynamics

This commit is contained in:
1brucben
2025-05-09 20:32:01 +02:00
parent f28f83ca89
commit a27e7deae2
7 changed files with 38 additions and 6 deletions
+1 -5
View File
@@ -584,11 +584,7 @@ export class DefaultConfig implements Config {
}
maxPopulation(player: Player | PlayerView): number {
const maxPop =
player.type() == PlayerType.Human && this.infiniteTroops()
? 1_000_000_000
: 1 * (player.numTilesOwned() * 30 + 50000) +
player.units(UnitType.City).length * this.cityPopulationIncrease();
const maxPop = player.maxPopulation();
if (player.type() == PlayerType.Bot) {
return maxPop / 2;
+3 -1
View File
@@ -38,7 +38,9 @@ export class CityExecution implements Execution {
this.active = false;
return;
}
this.city = this.player.buildUnit(UnitType.City, 0, spawnTile);
this.city = this.player.buildUnit(UnitType.City, 0, spawnTile, {
createdAtTick: ticks,
});
}
if (!this.city.isActive()) {
this.active = false;
+3
View File
@@ -272,6 +272,7 @@ export interface UnitSpecificInfos {
detonationDst?: TileRef; // Only for nukes
warshipTarget?: Unit;
cooldownDuration?: number;
createdAtTick?: number; // Only for cities
}
export interface Unit {
@@ -305,6 +306,7 @@ export interface Unit {
setSafeFromPirates(): void; // Only for trade ships
isSafeFromPirates(): boolean; // Only for trade ships
detonationDst(): TileRef; // Only for nukes
createdAtTick(): number; // Only for cities
setMoveTarget(cell: TileRef): void;
moveTarget(): TileRef | null;
@@ -364,6 +366,7 @@ export interface Player {
gold(): Gold;
population(): number;
adjustedPopulation(): number;
maxPopulation(): number;
workers(): number;
troops(): number;
targetTroopRatio(): number;
+2
View File
@@ -74,6 +74,7 @@ export interface UnitUpdate {
health?: number;
constructionType?: UnitType;
ticksLeftInCooldown?: Tick;
createdAtTick?: number;
}
export interface AttackUpdate {
@@ -100,6 +101,7 @@ export interface PlayerUpdate {
gold: number;
population: number;
adjustedPopulation: number;
maxPopulation: number;
workers: number;
troops: number;
targetTroopRatio: number;
+7
View File
@@ -79,6 +79,10 @@ export class UnitView {
troops(): number {
return this.data.troops;
}
createdAtTick(): number | undefined {
return this.data.createdAtTick;
}
tile(): TileRef {
return this.data.pos;
}
@@ -228,6 +232,9 @@ export class PlayerView {
adjustedPopulation(): number {
return this.data.adjustedPopulation;
}
maxPopulation(): number {
return this.data.maxPopulation;
}
workers(): number {
return this.data.workers;
}
+15
View File
@@ -138,6 +138,7 @@ export class PlayerImpl implements Player {
gold: Number(this._gold),
population: this.population(),
adjustedPopulation: this.adjustedPopulation(),
maxPopulation: this.maxPopulation(),
workers: this.workers(),
troops: this.troops(),
targetTroopRatio: this.targetTroopRatio(),
@@ -643,6 +644,20 @@ export class PlayerImpl implements Player {
adjustedPopulation(): number {
return this.population() + this.boatTroops() + this.attackingTroops();
}
maxPopulation(): number {
let cityPop = 0;
for (const city of this.units(UnitType.City)) {
const created = city.createdAtTick();
const age = created != null ? this.mg.ticks() - created : Infinity;
const ramp = Math.min(age / 600, 1); // 60 seconds at 10 ticks/sec
cityPop += ramp * 500_000;
}
const base = this.numTilesOwned() * 30 + 50_000 + cityPop;
return base;
}
private attackingTroops(): number {
return this._outgoingAttacks
.filter((a) => a.isActive())
+7
View File
@@ -29,6 +29,7 @@ export class UnitImpl implements Unit {
private _detonationDst: TileRef | null = null; // Only for nukes
private _warshipTarget: Unit | null = null;
private _cooldownDuration: number | null = null;
private _createdAtTick: number;
constructor(
private _type: UnitType,
@@ -49,6 +50,8 @@ export class UnitImpl implements Unit {
this._safeFromPiratesCooldown = this.mg
.config()
.safeFromPiratesCooldownMax();
this._createdAtTick = unitsSpecificInfos.createdAtTick;
}
id() {
@@ -73,6 +76,7 @@ export class UnitImpl implements Unit {
warshipTargetId: warshipTarget ? warshipTarget.id() : null,
detonationDst: this.detonationDst(),
ticksLeftInCooldown: this.ticksLeftInCooldown(this._cooldownDuration),
createdAtTick: this._createdAtTick,
};
}
@@ -233,6 +237,9 @@ export class UnitImpl implements Unit {
setTargetedBySAM(targeted: boolean): void {
this._targetedBySAM = targeted;
}
createdAtTick(): number | undefined {
return this._createdAtTick;
}
targetedBySAM(): boolean {
return this._targetedBySAM;