Skip to content
Open
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
8 changes: 8 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
"options_changed_no_achievements": "Custom settings – achievements disabled",
"gold_multiplier": "Gold multiplier",
"gold_multiplier_placeholder": "2.0x",
"port_gold_multiplier": "Port trade gold multiplier",
"port_gold_multiplier_placeholder": "1.0x",
"factory_gold_multiplier": "Factory gold multiplier",
"factory_gold_multiplier_placeholder": "1.0x",
"starting_gold": "Starting gold",
"starting_gold_placeholder": "5000000"
},
Expand Down Expand Up @@ -424,6 +428,10 @@
"teams_Quads": "Quads (teams of 4)",
"teams_Humans Vs Nations": "Humans vs Nations",
"starting_gold": "Starting gold",
"port_gold_multiplier": "Port trade gold multiplier",
"port_gold_multiplier_placeholder": "1.0x",
"factory_gold_multiplier": "Factory gold multiplier",
"factory_gold_multiplier_placeholder": "1.0x",
"crowded": "Crowded modifier"
},
"team_colors": {
Expand Down
104 changes: 104 additions & 0 deletions src/client/HostLobbyModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class HostLobbyModal extends BaseModal {
@state() private compactMap: boolean = false;
@state() private goldMultiplier: boolean = false;
@state() private goldMultiplierValue: number | undefined = undefined;
@state() private portGoldMultiplier: boolean = false;
@state() private portGoldMultiplierValue: number | undefined = undefined;
@state() private factoryGoldMultiplier: boolean = false;
@state() private factoryGoldMultiplierValue: number | undefined = undefined;
@state() private startingGold: boolean = false;
@state() private startingGoldValue: number | undefined = undefined;
@state() private lobbyId = "";
Expand Down Expand Up @@ -188,6 +192,42 @@ export class HostLobbyModal extends BaseModal {
.onChange=${this.handleGoldMultiplierValueChanges}
.onKeyDown=${this.handleGoldMultiplierValueKeyDown}
></toggle-input-card>`,
html`<toggle-input-card
.labelKey=${"host_modal.port_gold_multiplier"}
.checked=${this.portGoldMultiplier}
.inputId=${"port-gold-multiplier-value"}
.inputMin=${0.1}
.inputMax=${1000}
.inputStep=${"any"}
.inputValue=${this.portGoldMultiplierValue}
.inputAriaLabel=${translateText("host_modal.port_gold_multiplier")}
.inputPlaceholder=${translateText(
"host_modal.port_gold_multiplier_placeholder",
)}
.defaultInputValue=${1}
.minValidOnEnable=${0.1}
.onToggle=${this.handlePortGoldMultiplierToggle}
.onChange=${this.handlePortGoldMultiplierValueChanges}
.onKeyDown=${this.handlePortGoldMultiplierValueKeyDown}
></toggle-input-card>`,
html`<toggle-input-card
.labelKey=${"host_modal.factory_gold_multiplier"}
.checked=${this.factoryGoldMultiplier}
.inputId=${"factory-gold-multiplier-value"}
.inputMin=${0.1}
.inputMax=${1000}
.inputStep=${"any"}
.inputValue=${this.factoryGoldMultiplierValue}
.inputAriaLabel=${translateText("host_modal.factory_gold_multiplier")}
.inputPlaceholder=${translateText(
"host_modal.factory_gold_multiplier_placeholder",
)}
.defaultInputValue=${1}
.minValidOnEnable=${0.1}
.onToggle=${this.handleFactoryGoldMultiplierToggle}
.onChange=${this.handleFactoryGoldMultiplierValueChanges}
.onKeyDown=${this.handleFactoryGoldMultiplierValueKeyDown}
></toggle-input-card>`,
html`<toggle-input-card
.labelKey=${"single_modal.starting_gold"}
.checked=${this.startingGold}
Expand Down Expand Up @@ -453,6 +493,10 @@ export class HostLobbyModal extends BaseModal {
this.nationCount = 0;
this.goldMultiplier = false;
this.goldMultiplierValue = undefined;
this.portGoldMultiplier = false;
this.portGoldMultiplierValue = undefined;
this.factoryGoldMultiplier = false;
this.factoryGoldMultiplierValue = undefined;
this.startingGold = false;
this.startingGoldValue = undefined;

Expand Down Expand Up @@ -605,6 +649,24 @@ export class HostLobbyModal extends BaseModal {
this.putGameConfig();
};

private handlePortGoldMultiplierToggle = (
checked: boolean,
value: number | string | undefined,
) => {
this.portGoldMultiplier = checked;
this.portGoldMultiplierValue = toOptionalNumber(value);
this.putGameConfig();
};

private handleFactoryGoldMultiplierToggle = (
checked: boolean,
value: number | string | undefined,
) => {
this.factoryGoldMultiplier = checked;
this.factoryGoldMultiplierValue = toOptionalNumber(value);
this.putGameConfig();
};

private handleStartingGoldToggle = (
checked: boolean,
value: number | string | undefined,
Expand Down Expand Up @@ -632,6 +694,14 @@ export class HostLobbyModal extends BaseModal {
preventDisallowedKeys(e, ["+", "-", "e", "E"]);
};

private handlePortGoldMultiplierValueKeyDown = (e: KeyboardEvent) => {
preventDisallowedKeys(e, ["+", "-", "e", "E"]);
};

private handleFactoryGoldMultiplierValueKeyDown = (e: KeyboardEvent) => {
preventDisallowedKeys(e, ["+", "-", "e", "E"]);
};

private handleGoldMultiplierValueChanges = (e: Event) => {
const input = e.target as HTMLInputElement;
const value = parseBoundedFloatFromInput(input, { min: 0.1, max: 1000 });
Expand All @@ -645,6 +715,32 @@ export class HostLobbyModal extends BaseModal {
this.putGameConfig();
};

private handlePortGoldMultiplierValueChanges = (e: Event) => {
const input = e.target as HTMLInputElement;
const value = parseBoundedFloatFromInput(input, { min: 0.1, max: 1000 });

if (value === undefined) {
this.portGoldMultiplierValue = undefined;
input.value = "";
} else {
this.portGoldMultiplierValue = value;
}
this.putGameConfig();
};

private handleFactoryGoldMultiplierValueChanges = (e: Event) => {
const input = e.target as HTMLInputElement;
const value = parseBoundedFloatFromInput(input, { min: 0.1, max: 1000 });

if (value === undefined) {
this.factoryGoldMultiplierValue = undefined;
input.value = "";
} else {
this.factoryGoldMultiplierValue = value;
}
this.putGameConfig();
};

private handleStartingGoldValueKeyDown = (e: KeyboardEvent) => {
preventDisallowedKeys(e, ["-", "+", "e", "E"]);
};
Expand Down Expand Up @@ -775,6 +871,14 @@ export class HostLobbyModal extends BaseModal {
this.goldMultiplier === true
? this.goldMultiplierValue
: undefined,
portGoldMultiplier:
this.portGoldMultiplier === true
? this.portGoldMultiplierValue
: undefined,
factoryGoldMultiplier:
this.factoryGoldMultiplier === true
? this.factoryGoldMultiplierValue
: undefined,
startingGold:
this.startingGold === true ? this.startingGoldValue : undefined,
} satisfies Partial<GameConfig>,
Expand Down
109 changes: 109 additions & 0 deletions src/client/SinglePlayerModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const DEFAULT_OPTIONS = {
teamCount: 2 as TeamCountConfig,
goldMultiplier: false,
goldMultiplierValue: undefined as number | undefined,
portGoldMultiplier: false,
portGoldMultiplierValue: undefined as number | undefined,
factoryGoldMultiplier: false,
factoryGoldMultiplierValue: undefined as number | undefined,
startingGold: false,
startingGoldValue: undefined as number | undefined,
disabledUnits: [] as UnitType[],
Expand Down Expand Up @@ -82,6 +86,14 @@ export class SinglePlayerModal extends BaseModal {
@state() private goldMultiplier: boolean = DEFAULT_OPTIONS.goldMultiplier;
@state() private goldMultiplierValue: number | undefined =
DEFAULT_OPTIONS.goldMultiplierValue;
@state() private portGoldMultiplier: boolean =
DEFAULT_OPTIONS.portGoldMultiplier;
@state() private portGoldMultiplierValue: number | undefined =
DEFAULT_OPTIONS.portGoldMultiplierValue;
@state() private factoryGoldMultiplier: boolean =
DEFAULT_OPTIONS.factoryGoldMultiplier;
@state() private factoryGoldMultiplierValue: number | undefined =
DEFAULT_OPTIONS.factoryGoldMultiplierValue;
@state() private startingGold: boolean = DEFAULT_OPTIONS.startingGold;
@state() private startingGoldValue: number | undefined =
DEFAULT_OPTIONS.startingGoldValue;
Expand Down Expand Up @@ -200,6 +212,42 @@ export class SinglePlayerModal extends BaseModal {
.onChange=${this.handleGoldMultiplierValueChanges}
.onKeyDown=${this.handleGoldMultiplierValueKeyDown}
></toggle-input-card>`,
html`<toggle-input-card
.labelKey=${"single_modal.port_gold_multiplier"}
.checked=${this.portGoldMultiplier}
.inputId=${"port-gold-multiplier-value"}
.inputMin=${0.1}
.inputMax=${1000}
.inputStep=${"any"}
.inputValue=${this.portGoldMultiplierValue}
.inputAriaLabel=${translateText("single_modal.port_gold_multiplier")}
.inputPlaceholder=${translateText(
"single_modal.port_gold_multiplier_placeholder",
)}
.defaultInputValue=${1}
.minValidOnEnable=${0.1}
.onToggle=${this.handlePortGoldMultiplierToggle}
.onChange=${this.handlePortGoldMultiplierValueChanges}
.onKeyDown=${this.handlePortGoldMultiplierValueKeyDown}
></toggle-input-card>`,
html`<toggle-input-card
.labelKey=${"single_modal.factory_gold_multiplier"}
.checked=${this.factoryGoldMultiplier}
.inputId=${"factory-gold-multiplier-value"}
.inputMin=${0.1}
.inputMax=${1000}
.inputStep=${"any"}
.inputValue=${this.factoryGoldMultiplierValue}
.inputAriaLabel=${translateText("single_modal.factory_gold_multiplier")}
.inputPlaceholder=${translateText(
"single_modal.factory_gold_multiplier_placeholder",
)}
.defaultInputValue=${1}
.minValidOnEnable=${0.1}
.onToggle=${this.handleFactoryGoldMultiplierToggle}
.onChange=${this.handleFactoryGoldMultiplierValueChanges}
.onKeyDown=${this.handleFactoryGoldMultiplierValueKeyDown}
></toggle-input-card>`,
html`<toggle-input-card
.labelKey=${"single_modal.starting_gold"}
.checked=${this.startingGold}
Expand Down Expand Up @@ -378,6 +426,8 @@ export class SinglePlayerModal extends BaseModal {
this.randomSpawn !== DEFAULT_OPTIONS.randomSpawn ||
this.gameMode !== DEFAULT_OPTIONS.gameMode ||
this.goldMultiplier !== DEFAULT_OPTIONS.goldMultiplier ||
this.portGoldMultiplier !== DEFAULT_OPTIONS.portGoldMultiplier ||
this.factoryGoldMultiplier !== DEFAULT_OPTIONS.factoryGoldMultiplier ||
this.startingGold !== DEFAULT_OPTIONS.startingGold ||
this.disabledUnits.length > 0
);
Expand All @@ -402,6 +452,11 @@ export class SinglePlayerModal extends BaseModal {
this.disabledUnits = [...DEFAULT_OPTIONS.disabledUnits];
this.goldMultiplier = DEFAULT_OPTIONS.goldMultiplier;
this.goldMultiplierValue = DEFAULT_OPTIONS.goldMultiplierValue;
this.portGoldMultiplier = DEFAULT_OPTIONS.portGoldMultiplier;
this.portGoldMultiplierValue = DEFAULT_OPTIONS.portGoldMultiplierValue;
this.factoryGoldMultiplier = DEFAULT_OPTIONS.factoryGoldMultiplier;
this.factoryGoldMultiplierValue =
DEFAULT_OPTIONS.factoryGoldMultiplierValue;
this.startingGold = DEFAULT_OPTIONS.startingGold;
this.startingGoldValue = DEFAULT_OPTIONS.startingGoldValue;
}
Expand Down Expand Up @@ -514,6 +569,22 @@ export class SinglePlayerModal extends BaseModal {
this.goldMultiplierValue = toOptionalNumber(value);
};

private handlePortGoldMultiplierToggle = (
checked: boolean,
value: number | string | undefined,
) => {
this.portGoldMultiplier = checked;
this.portGoldMultiplierValue = toOptionalNumber(value);
};

private handleFactoryGoldMultiplierToggle = (
checked: boolean,
value: number | string | undefined,
) => {
this.factoryGoldMultiplier = checked;
this.factoryGoldMultiplierValue = toOptionalNumber(value);
};

private handleStartingGoldToggle = (
checked: boolean,
value: number | string | undefined,
Expand Down Expand Up @@ -550,6 +621,14 @@ export class SinglePlayerModal extends BaseModal {
preventDisallowedKeys(e, ["+", "-", "e", "E"]);
};

private handlePortGoldMultiplierValueKeyDown = (e: KeyboardEvent) => {
preventDisallowedKeys(e, ["+", "-", "e", "E"]);
};

private handleFactoryGoldMultiplierValueKeyDown = (e: KeyboardEvent) => {
preventDisallowedKeys(e, ["+", "-", "e", "E"]);
};

private handleGoldMultiplierValueChanges = (e: Event) => {
const input = e.target as HTMLInputElement;
const value = parseBoundedFloatFromInput(input, { min: 0.1, max: 1000 });
Expand All @@ -562,6 +641,30 @@ export class SinglePlayerModal extends BaseModal {
}
};

private handlePortGoldMultiplierValueChanges = (e: Event) => {
const input = e.target as HTMLInputElement;
const value = parseBoundedFloatFromInput(input, { min: 0.1, max: 1000 });

if (value === undefined) {
this.portGoldMultiplierValue = undefined;
input.value = "";
} else {
this.portGoldMultiplierValue = value;
}
};

private handleFactoryGoldMultiplierValueChanges = (e: Event) => {
const input = e.target as HTMLInputElement;
const value = parseBoundedFloatFromInput(input, { min: 0.1, max: 1000 });

if (value === undefined) {
this.factoryGoldMultiplierValue = undefined;
input.value = "";
} else {
this.factoryGoldMultiplierValue = value;
}
};

private handleStartingGoldValueKeyDown = (e: KeyboardEvent) => {
preventDisallowedKeys(e, ["-", "+", "e", "E"]);
};
Expand Down Expand Up @@ -689,6 +792,12 @@ export class SinglePlayerModal extends BaseModal {
...(this.goldMultiplier && this.goldMultiplierValue
? { goldMultiplier: this.goldMultiplierValue }
: {}),
...(this.portGoldMultiplier && this.portGoldMultiplierValue
? { portGoldMultiplier: this.portGoldMultiplierValue }
: {}),
...(this.factoryGoldMultiplier && this.factoryGoldMultiplierValue
? { factoryGoldMultiplier: this.factoryGoldMultiplierValue }
: {}),
...(this.startingGold && this.startingGoldValue !== undefined
? { startingGold: this.startingGoldValue }
: {}),
Expand Down
2 changes: 2 additions & 0 deletions src/core/Schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ export const GameConfigSchema = z.object({
disabledUnits: z.enum(UnitType).array().optional(),
playerTeams: TeamCountConfigSchema.optional(),
goldMultiplier: z.number().min(0.1).max(1000).optional(),
portGoldMultiplier: z.number().min(0.1).max(1000).optional(),
factoryGoldMultiplier: z.number().min(0.1).max(1000).optional(),
startingGold: z.number().int().min(0).max(1000000000).optional(),
});

Expand Down
2 changes: 2 additions & 0 deletions src/core/configuration/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export interface Config {
userSettings(): UserSettings;
playerTeams(): TeamCountConfig;
goldMultiplier(): number;
portGoldMultiplier(): number;
factoryGoldMultiplier(): number;
startingGold(playerInfo: PlayerInfo): Gold;

startManpower(playerInfo: PlayerInfo): number;
Expand Down
10 changes: 8 additions & 2 deletions src/core/configuration/DefaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ export class DefaultConfig implements Config {
goldMultiplier(): number {
return this._gameConfig.goldMultiplier ?? 1;
}
portGoldMultiplier(): number {
return this._gameConfig.portGoldMultiplier ?? 1;
}
factoryGoldMultiplier(): number {
return this._gameConfig.factoryGoldMultiplier ?? 1;
}
startingGold(playerInfo: PlayerInfo): Gold {
if (playerInfo.playerType === PlayerType.Bot) {
return 0n;
Expand All @@ -267,7 +273,7 @@ export class DefaultConfig implements Config {
return (numPlayerFactories + 10) * 18;
}
trainGold(rel: "self" | "team" | "ally" | "other"): Gold {
const multiplier = this.goldMultiplier();
const multiplier = this.goldMultiplier() * this.factoryGoldMultiplier();
let baseGold: bigint;
switch (rel) {
case "ally":
Expand Down Expand Up @@ -302,7 +308,7 @@ export class DefaultConfig implements Config {
const numPortBonus = numPorts - 1;
// Hyperbolic decay, midpoint at 5 ports, 3x bonus max.
const bonus = 1 + 2 * (numPortBonus / (numPortBonus + 5));
const multiplier = this.goldMultiplier();
const multiplier = this.goldMultiplier() * this.portGoldMultiplier();
return BigInt(Math.floor(baseGold * bonus * multiplier));
}

Expand Down
Loading
Loading