Executions dont switch owner (#326)

when an building is taken over by another player the execution for it
doesnt change its owner this makes it so when a sam is captured it tries
to intercept your own nukes and doesnt intercept the ones by the
previous player

this change makes executions of buildings automaticly switch their owner
This commit is contained in:
Readixyee
2025-03-28 00:03:15 +01:00
committed by GitHub
parent b8e750e31e
commit 665a8c3823
13 changed files with 24 additions and 51 deletions
+3 -3
View File
@@ -44,10 +44,10 @@ export class CityExecution implements Execution {
this.active = false;
return;
}
}
owner(): Player {
return null;
if (this.player != this.city.owner()) {
this.player = this.city.owner();
}
}
isActive(): boolean {
+4 -4
View File
@@ -76,6 +76,10 @@ export class ConstructionExecution implements Execution {
return;
}
if (this.player != this.construction.owner()) {
this.player = this.construction.owner();
}
if (this.ticksUntilComplete == 0) {
this.player = this.construction.owner();
this.construction.delete(false);
@@ -123,10 +127,6 @@ export class ConstructionExecution implements Execution {
}
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
+3 -3
View File
@@ -45,10 +45,10 @@ export class DefensePostExecution implements Execution {
this.active = false;
return;
}
}
owner(): Player {
return null;
if (this.player != this.post.owner()) {
this.player = this.post.owner();
}
}
isActive(): boolean {
+4 -4
View File
@@ -42,11 +42,11 @@ export class MissileSiloExecution implements Execution {
return;
}
this.silo = this.player.buildUnit(UnitType.MissileSilo, 0, this.tile);
}
}
owner(): Player {
return null;
if (this.player != this.silo.owner()) {
this.player = this.silo.owner();
}
}
}
isActive(): boolean {
@@ -25,11 +25,6 @@ export class MoveWarshipExecution implements Execution {
this.active = false;
}
owner(): Player {
const warship = this.mg.units().find((u) => u.id() == this.unitId);
return warship ? warship.owner() : null;
}
isActive(): boolean {
return this.active;
}
+4 -4
View File
@@ -66,6 +66,10 @@ export class PortExecution implements Execution {
return;
}
if (this._owner != this.port.owner().id()) {
this._owner = this.port.owner().id();
}
const totalNbOfPorts = this.mg.units(UnitType.Port).length;
if (
!this.random.chance(this.mg.config().tradeShipSpawnRate(totalNbOfPorts))
@@ -88,10 +92,6 @@ export class PortExecution implements Execution {
);
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
+4 -4
View File
@@ -57,6 +57,10 @@ export class SAMLauncherExecution implements Execution {
return;
}
if (this.player != this.post.owner()) {
this.player = this.post.owner();
}
if (!this.pseudoRandom) {
this.pseudoRandom = new PseudoRandom(this.post.id());
}
@@ -133,10 +137,6 @@ export class SAMLauncherExecution implements Execution {
}
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
@@ -85,9 +85,6 @@ export class SAMMissileExecution implements Execution {
}
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
-3
View File
@@ -63,9 +63,6 @@ export class ShellExecution implements Execution {
}
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
-4
View File
@@ -151,10 +151,6 @@ export class TradeShipExecution implements Execution {
return;
}
owner(): Player {
return null;
}
isActive(): boolean {
return this.active;
}
+2 -7
View File
@@ -11,7 +11,6 @@ import {
import { PathFinder } from "../pathfinding/PathFinding";
import { PathFindResultType } from "../pathfinding/AStar";
import { PseudoRandom } from "../PseudoRandom";
import { distSort, distSortUnit } from "../Util";
import { consolex } from "../Consolex";
import { TileRef } from "../game/GameMap";
import { ShellExecution } from "./ShellExecution";
@@ -151,7 +150,7 @@ export class WarshipExecution implements Execution {
!this.alreadySentShell.has(unit) &&
(unit.type() !== UnitType.TradeShip || hasPort) &&
(unit.type() !== UnitType.TradeShip ||
unit.dstPort()?.owner() !== this.owner()),
unit.dstPort()?.owner() !== this._owner),
);
this.target =
@@ -229,7 +228,7 @@ export class WarshipExecution implements Execution {
);
switch (result.type) {
case PathFindResultType.Completed:
this.owner().captureUnit(this.target);
this._owner.captureUnit(this.target);
this.target = null;
return;
case PathFindResultType.NextTile:
@@ -244,10 +243,6 @@ export class WarshipExecution implements Execution {
}
}
owner(): Player {
return this._owner;
}
isActive(): boolean {
return this.active;
}
-2
View File
@@ -156,7 +156,6 @@ export interface Execution {
activeDuringSpawnPhase(): boolean;
init(mg: Game, ticks: number): void;
tick(ticks: number): void;
owner(): Player;
}
export interface Attack {
@@ -375,7 +374,6 @@ export interface Player {
executeRetreat(attackID: string): void;
// Misc
executions(): Execution[];
toUpdate(): PlayerUpdate;
playerProfile(): PlayerProfile;
canBoat(tile: TileRef): boolean;
-5
View File
@@ -285,11 +285,6 @@ export class PlayerImpl implements Player {
isAlive(): boolean {
return this._tiles.size > 0;
}
executions(): Execution[] {
return this.mg
.executions()
.filter((exec) => exec.owner().id() == this.id());
}
incomingAllianceRequests(): AllianceRequest[] {
return this.mg.allianceRequests.filter((ar) => ar.recipient() == this);