mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-08 23:03:19 +00:00
Merge branch 'main' of github.com:openfrontio/OpenFrontIO
This commit is contained in:
@@ -36,7 +36,7 @@ export class MissileSiloExecution implements Execution {
|
||||
if (this.silo == null) {
|
||||
if (!this.player.canBuild(UnitType.MissileSilo, this.tile)) {
|
||||
consolex.warn(
|
||||
`player ${this.player} cannot build port at ${this.tile}`,
|
||||
`player ${this.player} cannot build missile silo at ${this.tile}`,
|
||||
);
|
||||
this.active = false;
|
||||
return;
|
||||
|
||||
@@ -110,6 +110,7 @@ export class WarshipExecution implements Execution {
|
||||
return distSortUnit(this.mg, this.warship)(a, b);
|
||||
})[0] ?? null;
|
||||
|
||||
this.warship.setTarget(this.target);
|
||||
if (this.target == null || this.target.type() != UnitType.TradeShip) {
|
||||
// Patrol unless we are hunting down a tradeship
|
||||
const result = this.pathfinder.nextTile(
|
||||
|
||||
@@ -198,6 +198,8 @@ export class PlayerInfo {
|
||||
}
|
||||
|
||||
export interface Unit {
|
||||
id(): number;
|
||||
|
||||
// Properties
|
||||
type(): UnitType;
|
||||
troops(): number;
|
||||
@@ -214,6 +216,9 @@ export interface Unit {
|
||||
hasHealth(): boolean;
|
||||
health(): number;
|
||||
modifyHealth(delta: number): void;
|
||||
// State for warships (currently)
|
||||
setTarget(target: Unit): void;
|
||||
target(): Unit;
|
||||
|
||||
// Mutations
|
||||
setTroops(troops: number): void;
|
||||
|
||||
@@ -71,6 +71,7 @@ export interface UnitUpdate {
|
||||
isActive: boolean;
|
||||
health?: number;
|
||||
constructionType?: UnitType;
|
||||
targetId?: number;
|
||||
}
|
||||
|
||||
export interface AttackUpdate {
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
Player,
|
||||
PlayerActions,
|
||||
PlayerProfile,
|
||||
Unit,
|
||||
} from "./Game";
|
||||
import { AttackUpdate, PlayerUpdate } from "./GameUpdates";
|
||||
import { UnitUpdate } from "./GameUpdates";
|
||||
@@ -92,6 +91,9 @@ export class UnitView {
|
||||
constructionType(): UnitType | undefined {
|
||||
return this.data.constructionType;
|
||||
}
|
||||
targetId() {
|
||||
return this.data.targetId;
|
||||
}
|
||||
}
|
||||
|
||||
export class PlayerView {
|
||||
|
||||
@@ -11,6 +11,8 @@ export class UnitImpl implements Unit {
|
||||
private _active = true;
|
||||
private _health: bigint;
|
||||
private _lastTile: TileRef = null;
|
||||
// Currently only warship use it
|
||||
private _target: Unit = null;
|
||||
|
||||
private _constructionType: UnitType = undefined;
|
||||
|
||||
@@ -28,6 +30,10 @@ export class UnitImpl implements Unit {
|
||||
this._lastTile = _tile;
|
||||
}
|
||||
|
||||
id() {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
toUpdate(): UnitUpdate {
|
||||
return {
|
||||
type: GameUpdateType.Unit,
|
||||
@@ -40,6 +46,7 @@ export class UnitImpl implements Unit {
|
||||
lastPos: this._lastTile,
|
||||
health: this.hasHealth() ? Number(this._health) : undefined,
|
||||
constructionType: this._constructionType,
|
||||
targetId: this.target() ? this.target().id() : null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -150,4 +157,12 @@ export class UnitImpl implements Unit {
|
||||
dstPort(): Unit {
|
||||
return this._dstPort;
|
||||
}
|
||||
|
||||
setTarget(target: Unit) {
|
||||
this._target = target;
|
||||
}
|
||||
|
||||
target() {
|
||||
return this._target;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user