Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@
"atom_bomb": "Atom Bomb",
"hydrogen_bomb": "Hydrogen Bomb",
"mirv": "MIRV",
"train": "Train",
"factory": "Factory"
},
"user_setting": {
Expand Down Expand Up @@ -446,7 +445,6 @@
"cooldown": "Cooldown",
"type": "Type",
"upgrade": "Upgrade",
"create_station": "Create Station",
"level": "Level"
},
"relation": {
Expand Down
5 changes: 1 addition & 4 deletions src/client/HostLobbyModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ export class HostLobbyModal extends LitElement {
@state() private copySuccess = false;
@state() private players: string[] = [];
@state() private useRandomMap: boolean = false;
@state() private disabledUnits: UnitType[] = [
UnitType.Factory,
UnitType.Train,
];
@state() private disabledUnits: UnitType[] = [UnitType.Factory];

private playersInterval: NodeJS.Timeout | null = null;
// Add a new timer for debouncing bot changes
Expand Down
5 changes: 1 addition & 4 deletions src/client/SinglePlayerModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export class SinglePlayerModal extends LitElement {
@state() private gameMode: GameMode = GameMode.FFA;
@state() private teamCount: number | typeof Duos = 2;

@state() private disabledUnits: UnitType[] = [
UnitType.Factory,
UnitType.Train,
];
@state() private disabledUnits: UnitType[] = [UnitType.Factory];

private userSettings: UserSettings = new UserSettings();

Expand Down
17 changes: 0 additions & 17 deletions src/client/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ export class SendUpgradeStructureIntentEvent implements GameEvent {
) {}
}

export class SendCreateTrainStationIntentEvent implements GameEvent {
constructor(public readonly unitId: number) {}
}

export class SendAllianceReplyIntentEvent implements GameEvent {
constructor(
// The original alliance requestor
Expand Down Expand Up @@ -211,9 +207,6 @@ export class Transport {
this.eventBus.on(SendUpgradeStructureIntentEvent, (e) =>
this.onSendUpgradeStructureIntent(e),
);
this.eventBus.on(SendCreateTrainStationIntentEvent, (e) =>
this.onSendCreateTrainStationIntent(e),
);
this.eventBus.on(SendBoatAttackIntentEvent, (e) =>
this.onSendBoatAttackIntent(e),
);
Expand Down Expand Up @@ -478,16 +471,6 @@ export class Transport {
});
}

private onSendCreateTrainStationIntent(
event: SendCreateTrainStationIntentEvent,
) {
this.sendIntent({
type: "create_station",
clientID: this.lobbyConfig.clientID,
unitId: event.unitId,
});
}

private onSendTargetPlayerIntent(event: SendTargetPlayerIntentEvent) {
this.sendIntent({
type: "targetPlayer",
Expand Down
43 changes: 0 additions & 43 deletions src/client/graphics/layers/UILayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { ProgressBar } from "../ProgressBar";
import { TransformHandler } from "../TransformHandler";
import { Layer } from "./Layer";

import trainStationBadge from "../../../../resources/images/buildings/badges/trainStationBadge.png";

const COLOR_PROGRESSION = [
"rgb(232, 25, 25)",
"rgb(240, 122, 25)",
Expand Down Expand Up @@ -49,31 +47,13 @@ export class UILayer implements Layer {

// Visual settings for selection
private readonly SELECTION_BOX_SIZE = 6; // Size of the selection box (should be larger than the warship)
private badges: Map<string, HTMLImageElement> = new Map();

constructor(
private game: GameView,
private eventBus: EventBus,
private transformHandler: TransformHandler,
) {
this.theme = game.config().theme();
this.loadBadges();
}

private loadBadge(badge: string): Promise<HTMLImageElement> {
return new Promise((resolve, reject) => {
const img = new Image();
img.src = badge;
img.onload = () => {
this.badges.set(badge, img);
resolve(img);
};
img.onerror = reject;
});
}

private async loadBadges() {
await Promise.all([this.loadBadge(trainStationBadge)]);
}

shouldTransform(): boolean {
Expand Down Expand Up @@ -165,35 +145,12 @@ export class UILayer implements Layer {
const endTick = this.game.config().SAMCooldown();
this.drawLoadingBar(unit, endTick);
}
this.drawBadges(unit);
break;
case UnitType.City:
case UnitType.Port:
case UnitType.Factory:
this.drawBadges(unit);
break;
default:
return;
}
}

private drawBadges(unit: UnitView) {
if (unit.hasTrainStation()) {
const icon = this.badges.get(trainStationBadge);
if (icon === undefined) {
return;
}
const startX = this.game.x(unit.tile()) - Math.floor(icon.width / 2) + 6;
const startY = this.game.y(unit.tile()) - Math.floor(icon.height / 2) - 6;

if (unit.isActive()) {
this.drawIcon(icon, unit, startX, startY);
} else {
this.clearIcon(icon, startX, startY);
}
}
}

private clearIcon(icon: HTMLImageElement, startX: number, startY: number) {
if (this.context !== null) {
this.context.clearRect(startX, startY, icon.width, icon.height);
Expand Down
1 change: 0 additions & 1 deletion src/client/utilities/RenderUnitTypeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const unitOptions: { type: UnitType; translationKey: string }[] = [
{ type: UnitType.AtomBomb, translationKey: "unit_type.atom_bomb" },
{ type: UnitType.HydrogenBomb, translationKey: "unit_type.hydrogen_bomb" },
{ type: UnitType.MIRV, translationKey: "unit_type.mirv" },
{ type: UnitType.Train, translationKey: "unit_type.train" },
{ type: UnitType.Factory, translationKey: "unit_type.factory" },
];

Expand Down
11 changes: 1 addition & 10 deletions src/core/Schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export type Intent =
| QuickChatIntent
| MoveWarshipIntent
| MarkDisconnectedIntent
| UpgradeStructureIntent
| CreateStationIntent;

| UpgradeStructureIntent;
export type AttackIntent = z.infer<typeof AttackIntentSchema>;
export type CancelAttackIntent = z.infer<typeof CancelAttackIntentSchema>;
export type SpawnIntent = z.infer<typeof SpawnIntentSchema>;
Expand All @@ -63,7 +61,6 @@ export type BuildUnitIntent = z.infer<typeof BuildUnitIntentSchema>;
export type UpgradeStructureIntent = z.infer<
typeof UpgradeStructureIntentSchema
>;
export type CreateStationIntent = z.infer<typeof CreateStationIntentSchema>;
export type MoveWarshipIntent = z.infer<typeof MoveWarshipIntentSchema>;
export type QuickChatIntent = z.infer<typeof QuickChatIntentSchema>;
export type MarkDisconnectedIntent = z.infer<
Expand Down Expand Up @@ -310,11 +307,6 @@ export const UpgradeStructureIntentSchema = BaseIntentSchema.extend({
unitId: z.number(),
});

export const CreateStationIntentSchema = BaseIntentSchema.extend({
type: z.literal("create_station"),
unitId: z.number(),
});

export const CancelAttackIntentSchema = BaseIntentSchema.extend({
type: z.literal("cancel_attack"),
attackID: z.string(),
Expand Down Expand Up @@ -360,7 +352,6 @@ const IntentSchema = z.discriminatedUnion("type", [
TargetTroopRatioIntentSchema,
BuildUnitIntentSchema,
UpgradeStructureIntentSchema,
CreateStationIntentSchema,
EmbargoIntentSchema,
MoveWarshipIntentSchema,
QuickChatIntentSchema,
Expand Down
5 changes: 4 additions & 1 deletion src/core/StatsSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const OtherUnitSchema = z.union([
z.literal("wshp"),
z.literal("silo"),
z.literal("saml"),
z.literal("fact"),
]);
export type OtherUnit = z.infer<typeof OtherUnitSchema>;
export type OtherUnitType =
Expand All @@ -45,7 +46,8 @@ export type OtherUnitType =
| UnitType.MissileSilo
| UnitType.Port
| UnitType.SAMLauncher
| UnitType.Warship;
| UnitType.Warship
| UnitType.Factory;

export const unitTypeToOtherUnit = {
[UnitType.City]: "city",
Expand All @@ -54,6 +56,7 @@ export const unitTypeToOtherUnit = {
[UnitType.Port]: "port",
[UnitType.SAMLauncher]: "saml",
[UnitType.Warship]: "wshp",
[UnitType.Factory]: "fact",
} as const satisfies Record<OtherUnitType, OtherUnit>;

// Attacks
Expand Down
2 changes: 1 addition & 1 deletion src/core/configuration/DefaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class DefaultConfig implements Config {
return Math.min(50, Math.round(10 * Math.pow(numberOfPorts, 0.6)));
}
trainSpawnRate(numberOfStations: number): number {
return Math.min(1400, Math.round(60 * Math.pow(numberOfStations, 0.8)));
return Math.min(1400, Math.round(70 * Math.pow(numberOfStations, 0.8)));
}
trainGold(): Gold {
return BigInt(10_000);
Expand Down
16 changes: 16 additions & 0 deletions src/core/execution/CityExecution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
import { TileRef } from "../game/GameMap";
import { TrainStationExecution } from "./TrainStationExecution";

export class CityExecution implements Execution {
private mg: Game;
Expand All @@ -24,6 +25,7 @@ export class CityExecution implements Execution {
return;
}
this.city = this.player.buildUnit(UnitType.City, spawnTile, {});
this.createStation();
}
if (!this.city.isActive()) {
this.active = false;
Expand All @@ -42,4 +44,18 @@ export class CityExecution implements Execution {
activeDuringSpawnPhase(): boolean {
return false;
}

createStation(): void {
if (this.city !== null) {
const nearbyFactory = this.mg.hasUnitNearby(
this.city.tile()!,
this.mg.config().trainStationMaxRange(),
UnitType.Factory,
this.player.id(),
);
if (nearbyFactory) {
this.mg.addExecution(new TrainStationExecution(this.city));
}
}
}
}
3 changes: 0 additions & 3 deletions src/core/execution/ExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { RetreatExecution } from "./RetreatExecution";
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
import { SpawnExecution } from "./SpawnExecution";
import { TargetPlayerExecution } from "./TargetPlayerExecution";
import { TrainStationExecution } from "./TrainStationExecution";
import { TransportShipExecution } from "./TransportShipExecution";
import { UpgradeStructureExecution } from "./UpgradeStructureExecution";

Expand Down Expand Up @@ -118,8 +117,6 @@ export class Executor {

case "upgrade_structure":
return new UpgradeStructureExecution(player, intent.unitId);
case "create_station":
return new TrainStationExecution(player, intent.unitId);
case "quick_chat":
return new QuickChatExecution(
player,
Expand Down
39 changes: 29 additions & 10 deletions src/core/execution/FactoryExecution.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import { Execution, Game, Player, Unit, UnitType } from "../game/Game";
import { TileRef } from "../game/GameMap";
import { TrainStationExecution } from "./TrainStationExecution";

export class FactoryExecution implements Execution {
private factory: Unit | null = null;
private active: boolean = true;

private game: Game;
constructor(
private player: Player,
private tile: TileRef,
) {}

init(mg: Game, ticks: number): void {
const spawnTile = this.player.canBuild(UnitType.Factory, this.tile);
if (spawnTile === false) {
console.warn("cannot build factory");
this.active = false;
return;
}
this.factory = this.player.buildUnit(UnitType.Factory, spawnTile, {});
this.game = mg;
}

tick(ticks: number): void {
if (this.factory === null) {
throw new Error("Not initialized");
if (!this.factory) {
const spawnTile = this.player.canBuild(UnitType.Factory, this.tile);
if (spawnTile === false) {
console.warn("cannot build factory");
this.active = false;
return;
}
this.factory = this.player.buildUnit(UnitType.Factory, spawnTile, {});
this.createStation();
}
if (!this.factory.isActive()) {
this.active = false;
Expand All @@ -41,4 +43,21 @@ export class FactoryExecution implements Execution {
activeDuringSpawnPhase(): boolean {
return false;
}

createStation(): void {
if (this.factory !== null) {
const structures = this.game.nearbyUnits(
this.factory.tile()!,
this.game.config().trainStationMaxRange(),
[UnitType.City, UnitType.Port, UnitType.Factory],
);
// Use different seeds or trains will spawn simultaneously
let seed = 0;
for (const { unit } of structures) {
if (!unit.hasTrainStation()) {
this.game.addExecution(new TrainStationExecution(unit, ++seed));
}
}
}
}
}
27 changes: 1 addition & 26 deletions src/core/execution/FakeHumanExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { ConstructionExecution } from "./ConstructionExecution";
import { EmojiExecution } from "./EmojiExecution";
import { NukeExecution } from "./NukeExecution";
import { SpawnExecution } from "./SpawnExecution";
import { TrainStationExecution } from "./TrainStationExecution";
import { TransportShipExecution } from "./TransportShipExecution";
import { closestTwoTiles } from "./Util";
import { BotBehavior } from "./utils/BotBehavior";
Expand Down Expand Up @@ -438,35 +437,11 @@ export class FakeHumanExecution implements Execution {
this.maybeSpawnStructure(UnitType.Port, 1) ||
this.maybeSpawnStructure(UnitType.City, 2) ||
this.maybeSpawnWarship() ||
this.maybeSpawnTrainStation() ||
this.maybeSpawnStructure(UnitType.Factory, 1) ||
this.maybeSpawnStructure(UnitType.MissileSilo, 1)
);
}

private maybeSpawnTrainStation(): boolean {
if (this.mg.config().isUnitDisabled(UnitType.Train)) {
return false;
}
if (this.player === null) throw new Error("not initialized");
const citiesWithoutStations = this.player.units().filter((unit) => {
switch (unit.type()) {
case UnitType.City:
case UnitType.Port:
case UnitType.Factory:
return !unit.hasTrainStation();
default:
return false;
}
});
if (citiesWithoutStations.length === 0) {
return false;
}
this.mg.addExecution(
new TrainStationExecution(this.player, citiesWithoutStations[0].id()),
);
return true;
}

private maybeSpawnStructure(type: UnitType, maxNum: number): boolean {
if (this.player === null) throw new Error("not initialized");
if (this.player.unitsOwned(type) >= maxNum) {
Expand Down
Loading
Loading