Skip to content
Closed
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
3 changes: 2 additions & 1 deletion resources/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
},
"game_mode": {
"ffa": "Free for All",
"teams": "Teams"
"teams": "Teams",
"fog_of_war": "Kriegsnebel"
},
"select_lang": {
"title": "Sprache auswählen"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
},
"game_mode": {
"ffa": "Free for All",
"teams": "Teams"
"teams": "Teams",
"fog_of_war": "Fog of War"
},
"select_lang": {
"title": "Select Language"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
},
"game_mode": {
"ffa": "Todos contra todos",
"teams": "Equipos"
"teams": "Equipos",
"fog_of_war": "Niebla de guerra"
},
"select_lang": {
"title": "Selecciona idioma"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@
},
"game_mode": {
"ffa": "Chacun pour soi",
"teams": "Équipes"
"teams": "Équipes",
"fog_of_war": "Brouillard de guerre"
},
"select_lang": {
"title": "Sélectionner une langue"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@
},
"game_mode": {
"ffa": "バトルロワイヤル",
"teams": "チーム"
"teams": "チーム",
"fog_of_war": "戦争の霧"
},
"select_lang": {
"title": "言語を選択"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
},
"game_mode": {
"ffa": "Free for All",
"teams": "Equipes"
"teams": "Equipes",
"fog_of_war": "Nevoeiro de Guerra"
},
"select_lang": {
"title": "Selecionar idioma"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@
},
"game_mode": {
"ffa": "Каждый против каждого (FFA)",
"teams": "Команды"
"teams": "Команды",
"fog_of_war": "Туман войны"
},
"select_lang": {
"title": "Выберите язык"
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@
},
"game_mode": {
"ffa": "混战",
"teams": "团队"
"teams": "团队",
"fog_of_war": "战争迷雾"
},
"select_lang": {
"title": "选择语言"
Expand Down
56 changes: 42 additions & 14 deletions src/client/ClientGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { createPartialGameRecord, replacer } from "../core/Util";
import { ServerConfig } from "../core/configuration/Config";
import { getConfig } from "../core/configuration/ConfigLoader";
import { PlayerActions, UnitType } from "../core/game/Game";
import { GameMode, PlayerActions, UnitType } from "../core/game/Game";
import { TileRef } from "../core/game/GameMap";
import { GameMapLoader } from "../core/game/GameMapLoader";
import {
Expand Down Expand Up @@ -270,6 +270,15 @@ export class ClientGameRunner {

this.renderer.initialize();
this.input.initialize();

// Pass the game reference to the InputHandler
this.input.setGame(this.gameView);

// Pass the FogOfWarLayer reference to the InputHandler (if available)
if (this.renderer && this.renderer.fogOfWarLayer) {
this.input.setFogOfWarLayer(this.renderer.fogOfWarLayer);
}

this.worker.start((gu: GameUpdateViewData | ErrorUpdate) => {
if (this.lobby.gameStartInfo === undefined) {
throw new Error("missing gameStartInfo");
Expand Down Expand Up @@ -386,9 +395,10 @@ export class ClientGameRunner {
}

private inputEvent(event: MouseUpEvent) {
if (!this.isActive || this.renderer.uiState.ghostStructure !== null) {
if (!this.isActive) {
return;
}

const cell = this.renderer.transformHandler.screenToWorldCoordinates(
event.x,
event.y,
Expand All @@ -398,6 +408,24 @@ export class ClientGameRunner {
}
console.log(`clicked cell ${cell}`);
const tile = this.gameView.ref(cell.x, cell.y);

// Check if we are in Fog of War mode and if the position is completely fogged (fog = 1)
// Allow attacks even in areas with fog = 1
let isFoggedArea = false;
if (this.renderer && this.renderer.fogOfWarLayer &&
this.gameView.config().gameConfig().gameMode === GameMode.FogOfWar) {
const tileX = this.gameView.x(tile);
const tileY = this.gameView.y(tile);
const idx = tileY * this.gameView.width() + tileX;
const fogValue = this.renderer.fogOfWarLayer.getFogValueAt(idx);

// If fog is completely fogged (value 1), mark as fogged area
if (fogValue >= 1.0) {
isFoggedArea = true;
}
}

// Allow spawn in all modes, not just Fog of War mode
if (
this.gameView.isLand(tile) &&
!this.gameView.hasOwner(tile) &&
Expand All @@ -423,7 +451,7 @@ export class ClientGameRunner {
this.myPlayer.troops() * this.renderer.uiState.attackRatio,
),
);
} else if (this.canAutoBoat(actions, tile)) {
} else if (this.canBoatAttack(actions, tile)) {
this.sendBoatAttackIntent(tile);
}

Expand Down Expand Up @@ -519,7 +547,7 @@ export class ClientGameRunner {
}

this.myPlayer.actions(tile).then((actions) => {
if (this.canBoatAttack(actions) !== false) {
if (!actions.canAttack && this.canBoatAttack(actions, tile)) {
this.sendBoatAttackIntent(tile);
}
});
Expand Down Expand Up @@ -567,15 +595,19 @@ export class ClientGameRunner {
return this.gameView.ref(cell.x, cell.y);
}

private canBoatAttack(actions: PlayerActions): false | TileRef {
private canBoatAttack(actions: PlayerActions, tile: TileRef): boolean {
const bu = actions.buildableUnits.find(
(bu) => bu.type === UnitType.TransportShip,
);
if (bu === undefined) {
console.warn(`no transport ship buildable units`);
return false;
}
return bu.canBuild;
return (
bu.canBuild !== false &&
this.shouldBoat(tile, bu.canBuild) &&
this.gameView.isLand(tile)
);
}

private sendBoatAttackIntent(tile: TileRef) {
Expand All @@ -594,20 +626,16 @@ export class ClientGameRunner {
});
}

private canAutoBoat(actions: PlayerActions, tile: TileRef): boolean {
if (!this.gameView.isLand(tile)) return false;

const canBuild = this.canBoatAttack(actions);
if (canBuild === false) return false;

private shouldBoat(tile: TileRef, src: TileRef) {
// TODO: Global enable flag
// TODO: Global limit autoboat to nearby shore flag
// if (!enableAutoBoat) return false;
// if (!limitAutoBoatNear) return true;
const distanceSquared = this.gameView.euclideanDistSquared(tile, canBuild);
const distanceSquared = this.gameView.euclideanDistSquared(tile, src);
const limit = 100;
const limitSquared = limit * limit;
return distanceSquared < limitSquared;
if (distanceSquared > limitSquared) return false;
return true;
}

private onMouseMove(event: MouseMoveEvent) {
Expand Down
12 changes: 10 additions & 2 deletions src/client/HostLobbyModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class HostLobbyModal extends LitElement {
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M296 48H176.5C154.4 48 136 65.4 136 87.5V96h-7.5C106.4 96 88 113.4 88 135.5v288c0 22.1 18.4 40.5 40.5 40.5h208c22.1 0 39.5-18.4 39.5-40.5V416h8.5c22.1 0 39.5-18.4 39.5-40.5V176L296 48zm0 44.6l83.4 83.4H296V92.6zm48 330.9c0 4.7-3.4 8.5-7.5 8.5h-208c-4.4 0-8.5-4.1-8.5-8.5v-288c0-4.1 3.8-7.5 8.5-7.5h7.5v255.5c0 22.1 10.4 32.5 32.5 32.5H344v7.5zm48-48c0 4.7-3.4 8.5-7.5 8.5h-208c-4.4 0-8.5-4.1-8.5-8.5v-288c0-4.1 3.8-7.5 8.5-7.5H264v128h128v167.5z"
d="M296 48H176.5C154.4 48 136 65.4 136 87.5V96h-7.5C106.4 96 88 113.4 88 135.5v288c0 22.1 18.4 40.5 40.5 40.5h208c22.1 0 39.5-18.4 39.5-40.5V416h8.5c22.1 0 39.5-18.4 39.5-40.5V176L296 48zm0 44.6l83.4 83.4H296V92.6zm48 330.9c0 4.7-3.4 8.5-7.5 8.5h-208c-4.4 0-8.5-4.1-8.5-8.5v-288c0-4.1 3.8-7.5 8.5-7.5H264v128h128v167.5z"
></path>
</svg>
`
Expand Down Expand Up @@ -269,11 +269,19 @@ export class HostLobbyModal extends LitElement {
${translateText("game_mode.teams")}
</div>
</div>
<div
class="option-card ${this.gameMode === GameMode.FogOfWar ? "selected" : ""}"
@click=${() => this.handleGameModeSelection(GameMode.FogOfWar)}
>
<div class="option-card-title">
${translateText("game_mode.fog_of_war")}
</div>
</div>
</div>
</div>

${
this.gameMode === GameMode.FFA
this.gameMode === GameMode.FFA || this.gameMode === GameMode.FogOfWar
? ""
: html`
<!-- Team Count Selection -->
Expand Down
Loading