combine battleship + destroyer => warship.

This commit is contained in:
Evan
2025-02-02 14:31:30 -08:00
parent af0d6a289a
commit c109d23f9f
14 changed files with 159 additions and 403 deletions
@@ -22,7 +22,7 @@ import { renderNumber, renderTroops } from "../../Utils";
function euclideanDistWorld(
coord: { x: number; y: number },
tileRef: TileRef,
game: GameView,
game: GameView
): number {
const x = game.x(tileRef);
const y = game.y(tileRef);
@@ -71,7 +71,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
init() {
this.eventBus.on(MouseMoveEvent, (e: MouseMoveEvent) =>
this.onMouseEvent(e),
this.onMouseEvent(e)
);
this._isActive = true;
}
@@ -111,7 +111,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
this.setVisible(true);
} else if (!this.game.isLand(tile)) {
const units = this.game
.units(UnitType.Destroyer, UnitType.Battleship, UnitType.TradeShip)
.units(UnitType.Warship, UnitType.TradeShip, UnitType.TransportShip)
.filter((u) => euclideanDistWorld(worldCoord, u.tile(), this.game) < 50)
.sort(distSortUnitWorld(worldCoord, this.game));
+26 -70
View File
@@ -36,7 +36,7 @@ export class UnitLayer implements Layer {
constructor(
private game: GameView,
private eventBus: EventBus,
private clientID: ClientID,
private clientID: ClientID
) {
this.theme = game.config().theme();
}
@@ -65,7 +65,7 @@ export class UnitLayer implements Layer {
-this.game.width() / 2,
-this.game.height() / 2,
this.game.width(),
this.game.height(),
this.game.height()
);
}
@@ -103,11 +103,8 @@ export class UnitLayer implements Layer {
case UnitType.TransportShip:
this.handleBoatEvent(unit);
break;
case UnitType.Destroyer:
this.handleDestroyerEvent(unit);
break;
case UnitType.Battleship:
this.handleBattleshipEvent(unit);
case UnitType.Warship:
this.handleWarShipEvent(unit);
break;
case UnitType.Shell:
this.handleShellEvent(unit);
@@ -122,54 +119,13 @@ export class UnitLayer implements Layer {
}
}
private handleDestroyerEvent(unit: UnitView) {
private handleWarShipEvent(unit: UnitView) {
const rel = this.relationship(unit);
// Clear previous area
for (const t of this.game.bfs(
unit.lastTile(),
euclDistFN(unit.lastTile(), 4),
)) {
this.clearCell(this.game.x(t), this.game.y(t));
}
if (!unit.isActive()) {
return;
}
// Paint border
for (const t of this.game.bfs(unit.tile(), euclDistFN(unit.tile(), 4))) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.borderColor(unit.owner().info()),
255,
);
}
// Paint territory
for (const t of this.game.bfs(
unit.tile(),
manhattanDistFN(unit.tile(), 3),
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
255,
);
}
}
private handleBattleshipEvent(unit: UnitView) {
const rel = this.relationship(unit);
// Clear previous area
for (const t of this.game.bfs(
unit.lastTile(),
euclDistFN(unit.lastTile(), 6),
euclDistFN(unit.lastTile(), 6)
)) {
this.clearCell(this.game.x(t), this.game.y(t));
}
@@ -185,21 +141,21 @@ export class UnitLayer implements Layer {
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
255,
255
);
}
// Paint border
for (const t of this.game.bfs(
unit.tile(),
manhattanDistFN(unit.tile(), 4),
manhattanDistFN(unit.tile(), 4)
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.borderColor(unit.owner().info()),
255,
255
);
}
@@ -210,7 +166,7 @@ export class UnitLayer implements Layer {
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
255,
255
);
}
}
@@ -236,14 +192,14 @@ export class UnitLayer implements Layer {
this.game.y(unit.tile()),
rel,
this.theme.borderColor(unit.owner().info()),
255,
255
);
this.paintCell(
this.game.x(unit.lastTile()),
this.game.y(unit.lastTile()),
rel,
this.theme.borderColor(unit.owner().info()),
255,
255
);
}
@@ -253,7 +209,7 @@ export class UnitLayer implements Layer {
// Clear previous area
for (const t of this.game.bfs(
unit.lastTile(),
euclDistFN(unit.lastTile(), 2),
euclDistFN(unit.lastTile(), 2)
)) {
this.clearCell(this.game.x(t), this.game.y(t));
}
@@ -266,7 +222,7 @@ export class UnitLayer implements Layer {
this.game.y(t),
rel,
this.theme.borderColor(unit.owner().info()),
255,
255
);
}
}
@@ -278,7 +234,7 @@ export class UnitLayer implements Layer {
// Clear previous area
for (const t of this.game.bfs(
unit.lastTile(),
euclDistFN(unit.lastTile(), 3),
euclDistFN(unit.lastTile(), 3)
)) {
this.clearCell(this.game.x(t), this.game.y(t));
}
@@ -287,28 +243,28 @@ export class UnitLayer implements Layer {
// Paint territory
for (const t of this.game.bfs(
unit.tile(),
manhattanDistFN(unit.tile(), 2),
manhattanDistFN(unit.tile(), 2)
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
255,
255
);
}
// Paint border
for (const t of this.game.bfs(
unit.tile(),
manhattanDistFN(unit.tile(), 1),
manhattanDistFN(unit.tile(), 1)
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.borderColor(unit.owner().info()),
255,
255
);
}
}
@@ -326,7 +282,7 @@ export class UnitLayer implements Layer {
// Clear previous area
for (const t of this.game.bfs(
unit.lastTile(),
manhattanDistFN(unit.lastTile(), 3),
manhattanDistFN(unit.lastTile(), 3)
)) {
this.clearCell(this.game.x(t), this.game.y(t));
}
@@ -339,35 +295,35 @@ export class UnitLayer implements Layer {
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
150,
150
);
}
// Paint border
for (const t of this.game.bfs(
unit.tile(),
manhattanDistFN(unit.tile(), 2),
manhattanDistFN(unit.tile(), 2)
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.borderColor(unit.owner().info()),
255,
255
);
}
// Paint territory
for (const t of this.game.bfs(
unit.tile(),
manhattanDistFN(unit.tile(), 1),
manhattanDistFN(unit.tile(), 1)
)) {
this.paintCell(
this.game.x(t),
this.game.y(t),
rel,
this.theme.territoryColor(unit.owner().info()),
255,
255
);
}
} else {
@@ -383,7 +339,7 @@ export class UnitLayer implements Layer {
y: number,
relationship: Relationship,
color: Colord,
alpha: number,
alpha: number
) {
this.clearCell(x, y);
if (this.alternateView) {
@@ -11,15 +11,13 @@ import {
import { BuildUnitIntentEvent } from "../../../Transport";
import atomBombIcon from "../../../../../resources/images/NukeIconWhite.svg";
import hydrogenBombIcon from "../../../../../resources/images/MushroomCloudIconWhite.svg";
import destroyerIcon from "../../../../../resources/images/DestroyerIconWhite.svg";
import battleshipIcon from "../../../../../resources/images/BattleshipIconWhite.svg";
import warshipIcon from "../../../../../resources/images/BattleshipIconWhite.svg";
import missileSiloIcon from "../../../../../resources/images/MissileSiloIconWhite.svg";
import goldCoinIcon from "../../../../../resources/images/GoldCoinIcon.svg";
import portIcon from "../../../../../resources/images/PortIcon.svg";
import shieldIcon from "../../../../../resources/images/ShieldIconWhite.svg";
import cityIcon from "../../../../../resources/images/CityIconWhite.svg";
import { renderNumber } from "../../../Utils";
import { ContextMenuEvent } from "../../../InputHandler";
import { GameView, PlayerView } from "../../../../core/game/GameView";
interface BuildItemDisplay {
@@ -31,8 +29,7 @@ const buildTable: BuildItemDisplay[][] = [
[
{ unitType: UnitType.AtomBomb, icon: atomBombIcon },
{ unitType: UnitType.HydrogenBomb, icon: hydrogenBombIcon },
{ unitType: UnitType.Destroyer, icon: destroyerIcon },
{ unitType: UnitType.Battleship, icon: battleshipIcon },
{ unitType: UnitType.Warship, icon: warshipIcon },
{ unitType: UnitType.Port, icon: portIcon },
{ unitType: UnitType.MissileSilo, icon: missileSiloIcon },
// { unitType: UnitType.DefensePost, icon: shieldIcon },
@@ -201,7 +198,7 @@ export class BuildMenu extends LitElement {
public onBuildSelected = (item: BuildItemDisplay) => {
this.eventBus.emit(
new BuildUnitIntentEvent(item.unitType, this.clickedCell),
new BuildUnitIntentEvent(item.unitType, this.clickedCell)
);
this.hideMenu();
};
@@ -233,7 +230,7 @@ export class BuildMenu extends LitElement {
? this.game
.unitInfo(item.unitType)
.cost(this.myPlayer)
: 0,
: 0
)}
<img
src=${goldCoinIcon}
@@ -244,10 +241,10 @@ export class BuildMenu extends LitElement {
/>
</span>
</button>
`,
`
)}
</div>
`,
`
)}
</div>
`;