mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 05:03:36 +00:00
removed remnants of defensive posture (to place in another branch)
This commit is contained in:
@@ -98,9 +98,6 @@ export class SendDonateGoldIntentEvent implements GameEvent {
|
||||
public readonly gold: number | null,
|
||||
) {}
|
||||
}
|
||||
export class SendSetDefensivePostureEvent {
|
||||
constructor(public readonly posture: "retreat" | "balanced" | "hold") {}
|
||||
}
|
||||
|
||||
export class SendDonateTroopsIntentEvent implements GameEvent {
|
||||
constructor(
|
||||
@@ -216,9 +213,6 @@ export class Transport {
|
||||
this.eventBus.on(MoveWarshipIntentEvent, (e) => {
|
||||
this.onMoveWarshipEvent(e);
|
||||
});
|
||||
this.eventBus.on(SendSetDefensivePostureEvent, (e) =>
|
||||
this.onSendSetDefensivePostureEvent(e),
|
||||
);
|
||||
}
|
||||
|
||||
private startPing() {
|
||||
@@ -558,14 +552,6 @@ export class Transport {
|
||||
});
|
||||
}
|
||||
|
||||
private onSendSetDefensivePostureEvent(event: SendSetDefensivePostureEvent) {
|
||||
this.sendIntent({
|
||||
type: "setDefensivePosture",
|
||||
clientID: this.lobbyConfig.clientID,
|
||||
posture: event.posture,
|
||||
});
|
||||
}
|
||||
|
||||
private sendIntent(intent: Intent) {
|
||||
if (this.isLocal || this.socket.readyState === WebSocket.OPEN) {
|
||||
const msg = ClientIntentMessageSchema.parse({
|
||||
|
||||
@@ -4,10 +4,7 @@ import { EventBus } from "../../../core/EventBus";
|
||||
import { GameView } from "../../../core/game/GameView";
|
||||
import { ClientID } from "../../../core/Schemas";
|
||||
import { AttackRatioEvent } from "../../InputHandler";
|
||||
import {
|
||||
SendSetDefensivePostureEvent,
|
||||
SendSetTargetTroopRatioEvent,
|
||||
} from "../../Transport";
|
||||
import { SendSetTargetTroopRatioEvent } from "../../Transport";
|
||||
import { renderNumber, renderTroops } from "../../Utils";
|
||||
import { UIState } from "../UIState";
|
||||
import { Layer } from "./Layer";
|
||||
@@ -25,9 +22,6 @@ export class ControlPanel extends LitElement implements Layer {
|
||||
@state()
|
||||
private targetTroopRatio = 0.95;
|
||||
|
||||
@state()
|
||||
private defensivePosture: "retreat" | "balanced" | "hold" = "balanced";
|
||||
|
||||
@state()
|
||||
private currentTroopRatio = 0.95;
|
||||
|
||||
@@ -71,8 +65,6 @@ export class ControlPanel extends LitElement implements Layer {
|
||||
this.targetTroopRatio = Number(
|
||||
localStorage.getItem("settings.troopRatio") ?? "0.95",
|
||||
);
|
||||
this.defensivePosture =
|
||||
(localStorage.getItem("settings.defensivePosture") as any) ?? "balanced";
|
||||
this.init_ = true;
|
||||
this.uiState.attackRatio = this.attackRatio;
|
||||
this.currentTroopRatio = this.targetTroopRatio;
|
||||
@@ -143,16 +135,6 @@ export class ControlPanel extends LitElement implements Layer {
|
||||
this.uiState.attackRatio = newRatio;
|
||||
}
|
||||
|
||||
private onPostureChange(e: Event) {
|
||||
const raw = (e.target as HTMLInputElement).value;
|
||||
|
||||
if (raw === "retreat" || raw === "balanced" || raw === "hold") {
|
||||
const value = raw as "retreat" | "balanced" | "hold";
|
||||
this.eventBus.emit(new SendSetDefensivePostureEvent(value));
|
||||
} else {
|
||||
console.warn(`Unexpected posture value: ${raw}`);
|
||||
}
|
||||
}
|
||||
renderLayer(context: CanvasRenderingContext2D) {
|
||||
// Render any necessary canvas elements
|
||||
}
|
||||
|
||||
+1
-11
@@ -28,8 +28,7 @@ export type Intent =
|
||||
| TargetTroopRatioIntent
|
||||
| BuildUnitIntent
|
||||
| EmbargoIntent
|
||||
| MoveWarshipIntent
|
||||
| SetDefensivePostureIntent;
|
||||
| MoveWarshipIntent;
|
||||
|
||||
export type AttackIntent = z.infer<typeof AttackIntentSchema>;
|
||||
export type CancelAttackIntent = z.infer<typeof CancelAttackIntentSchema>;
|
||||
@@ -53,9 +52,6 @@ export type MoveWarshipIntent = z.infer<typeof MoveWarshipIntentSchema>;
|
||||
|
||||
export type Turn = z.infer<typeof TurnSchema>;
|
||||
export type GameConfig = z.infer<typeof GameConfigSchema>;
|
||||
export type SetDefensivePostureIntent = z.infer<
|
||||
typeof SetDefensivePostureIntentSchema
|
||||
>;
|
||||
|
||||
export type ClientMessage =
|
||||
| ClientSendWinnerMessage
|
||||
@@ -272,11 +268,6 @@ export const MoveWarshipIntentSchema = BaseIntentSchema.extend({
|
||||
tile: z.number(),
|
||||
});
|
||||
|
||||
export const SetDefensivePostureIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal("setDefensivePosture"),
|
||||
posture: z.enum(["retreat", "balanced", "hold"]),
|
||||
});
|
||||
|
||||
const IntentSchema = z.union([
|
||||
AttackIntentSchema,
|
||||
CancelAttackIntentSchema,
|
||||
@@ -293,7 +284,6 @@ const IntentSchema = z.union([
|
||||
BuildUnitIntentSchema,
|
||||
EmbargoIntentSchema,
|
||||
MoveWarshipIntentSchema,
|
||||
SetDefensivePostureIntentSchema,
|
||||
]);
|
||||
|
||||
export const TurnSchema = z.object({
|
||||
|
||||
@@ -466,28 +466,9 @@ export class DefaultConfig implements Config {
|
||||
}
|
||||
|
||||
if (defenderIsPlayer) {
|
||||
let sharedloss = 1;
|
||||
let postureloss = 1;
|
||||
if (defenderIsPlayer) {
|
||||
const posture = defender.defensivePosture?.() ?? "balanced";
|
||||
switch (posture) {
|
||||
case "retreat":
|
||||
sharedloss = 0.5;
|
||||
postureloss = 0.7;
|
||||
break;
|
||||
case "balanced":
|
||||
sharedloss = 1.0;
|
||||
postureloss = 1;
|
||||
break;
|
||||
case "hold":
|
||||
sharedloss = 3;
|
||||
postureloss = 1.3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const defenderTroops = defender.troops();
|
||||
const defenderTiles = defender.numTilesOwned();
|
||||
const defenderdensity = (defenderTroops / defenderTiles) * sharedloss;
|
||||
const defenderdensity = defenderTroops / defenderTiles;
|
||||
const adjustedRatio = within(defenderTroops / attackTroops, 0.3, 10);
|
||||
|
||||
if (attacker.type() == PlayerType.Human) {
|
||||
@@ -506,7 +487,7 @@ export class DefaultConfig implements Config {
|
||||
defenderdensity *
|
||||
mag *
|
||||
(defender.isTraitor() ? this.traitorDefenseDebuff() : 1),
|
||||
defenderTroopLoss: postureloss * defenderdensity,
|
||||
defenderTroopLoss: defenderdensity,
|
||||
tilesPerTickUsed: within(
|
||||
4 * (defenderdensity * adjustedRatio) ** 0.5 * speed,
|
||||
10,
|
||||
|
||||
@@ -16,7 +16,6 @@ import { FakeHumanExecution } from "./FakeHumanExecution";
|
||||
import { MoveWarshipExecution } from "./MoveWarshipExecution";
|
||||
import { NoOpExecution } from "./NoOpExecution";
|
||||
import { RetreatExecution } from "./RetreatExecution";
|
||||
import { SetDefensivePostureExecution } from "./SetDefensivePostureExecution";
|
||||
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
|
||||
import { SpawnExecution } from "./SpawnExecution";
|
||||
import { TargetPlayerExecution } from "./TargetPlayerExecution";
|
||||
@@ -104,9 +103,6 @@ export class Executor {
|
||||
this.mg.ref(intent.x, intent.y),
|
||||
intent.unit,
|
||||
);
|
||||
case "setDefensivePosture":
|
||||
return new SetDefensivePostureExecution(playerID, intent.posture);
|
||||
|
||||
default:
|
||||
throw new Error(`intent type ${intent} not found`);
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import { Execution, Game, PlayerID } from "../game/Game";
|
||||
|
||||
export class SetDefensivePostureExecution implements Execution {
|
||||
constructor(
|
||||
private playerID: PlayerID,
|
||||
private posture: "retreat" | "balanced" | "hold",
|
||||
) {}
|
||||
|
||||
init(mg: Game, ticks: number): void {
|
||||
const player = mg.player(this.playerID);
|
||||
if (!player) {
|
||||
console.warn(
|
||||
`SetDefensivePostureExecution: player ${this.playerID} not found`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.setDefensivePosture) {
|
||||
console.warn(
|
||||
`SetDefensivePostureExecution: setDefensivePosture not defined on player`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
player.setDefensivePosture(this.posture);
|
||||
}
|
||||
tick(_ticks: number): void {
|
||||
// No-op: nothing happens over time
|
||||
}
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return false; // It's a one-time effect
|
||||
}
|
||||
|
||||
owner(): null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -361,8 +361,6 @@ export interface Player {
|
||||
workers(): number;
|
||||
troops(): number;
|
||||
targetTroopRatio(): number;
|
||||
defensivePosture(): "retreat" | "balanced" | "hold";
|
||||
setDefensivePosture(p: "retreat" | "balanced" | "hold"): void;
|
||||
addGold(toAdd: Gold): void;
|
||||
removeGold(toRemove: Gold): void;
|
||||
addWorkers(toAdd: number): void;
|
||||
|
||||
@@ -69,8 +69,6 @@ export class PlayerImpl implements Player {
|
||||
// 0 to 100
|
||||
private _targetTroopRatio: bigint;
|
||||
|
||||
private _defensivePosture: "retreat" | "balanced" | "hold" = "balanced";
|
||||
|
||||
markedTraitorTick = -1;
|
||||
|
||||
private embargoes: Set<PlayerID> = new Set();
|
||||
@@ -663,12 +661,6 @@ export class PlayerImpl implements Player {
|
||||
}
|
||||
this._targetTroopRatio = toInt(target * 100);
|
||||
}
|
||||
public defensivePosture(): "retreat" | "balanced" | "hold" {
|
||||
return this._defensivePosture;
|
||||
}
|
||||
public setDefensivePosture(p: "retreat" | "balanced" | "hold") {
|
||||
this._defensivePosture = p;
|
||||
}
|
||||
|
||||
troops(): number {
|
||||
return Number(this._troops);
|
||||
|
||||
Reference in New Issue
Block a user