mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 16:56:38 +00:00
city test
This commit is contained in:
@@ -586,11 +586,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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -281,6 +281,7 @@ export interface UnitSpecificInfos {
|
||||
detonationDst?: TileRef; // Only for nukes
|
||||
warshipTarget?: Unit;
|
||||
cooldownDuration?: number;
|
||||
createdAtTick?: number; // Only for cities
|
||||
}
|
||||
|
||||
export interface Unit {
|
||||
@@ -314,6 +315,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;
|
||||
@@ -373,6 +375,7 @@ export interface Player {
|
||||
gold(): Gold;
|
||||
population(): number;
|
||||
adjustedPopulation(): number;
|
||||
maxPopulation(): number;
|
||||
workers(): number;
|
||||
troops(): number;
|
||||
targetTroopRatio(): number;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
@@ -640,6 +641,19 @@ 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user