Skip to content

Commit 1b11387

Browse files
committed
Revert "AFK team mate: better ship handling + tests + bugfix (#2203)"
This reverts commit 896a8eb.
1 parent c3f47d1 commit 1b11387

File tree

11 files changed

+15
-413
lines changed

11 files changed

+15
-413
lines changed

src/core/configuration/DefaultConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ export class DefaultConfig implements Config {
680680

681681
if (attacker.isPlayer() && defender.isPlayer()) {
682682
if (defender.isDisconnected() && attacker.isOnSameTeam(defender)) {
683-
// No troop loss if defender is disconnected and on same team
683+
// No troop loss if defender is disconnected.
684684
mag = 0;
685685
}
686686
if (

src/core/execution/AttackExecution.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ export class AttackExecution implements Execution {
181181
this._owner.id(),
182182
);
183183
}
184-
if (this.removeTroops === false) {
185-
// startTroops are always added to attack troops at init but not always removed from owner troops
186-
// subtract startTroops from attack troops so we don't give back startTroops to owner that were never removed
187-
this.attack.setTroops(this.attack.troops() - (this.startTroops ?? 0));
188-
}
189-
190184
const survivors = this.attack.troops() - deaths;
191185
this._owner.addTroops(survivors);
192186
this.attack.delete();

src/core/execution/TransportShipExecution.ts

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ export class TransportShipExecution implements Execution {
3333

3434
private pathFinder: PathFinder;
3535

36-
private originalOwner: Player;
37-
3836
constructor(
3937
private attacker: Player,
4038
private targetID: PlayerID | null,
4139
private ref: TileRef,
4240
private startTroops: number,
4341
private src: TileRef | null,
44-
) {
45-
this.originalOwner = this.attacker;
46-
}
42+
) {}
4743

4844
activeDuringSpawnPhase(): boolean {
4945
return false;
@@ -177,43 +173,11 @@ export class TransportShipExecution implements Execution {
177173
}
178174
this.lastMove = ticks;
179175

180-
// Team mate can conquer disconnected player and get their ships
181-
// captureUnit has changed the owner of the unit, now update attacker
182-
if (
183-
this.originalOwner.isDisconnected() &&
184-
this.boat.owner() !== this.originalOwner &&
185-
this.boat.owner().isOnSameTeam(this.originalOwner)
186-
) {
187-
this.attacker = this.boat.owner();
188-
this.originalOwner = this.boat.owner(); // for when this owner disconnects too
189-
}
190-
191176
if (this.boat.retreating()) {
192-
// Ensure retreat source is valid for the new owner
193-
if (this.mg.owner(this.src!) !== this.attacker) {
194-
// Use bestTransportShipSpawn, not canBuild because of its max boats check etc
195-
const newSrc = this.attacker.bestTransportShipSpawn(this.dst);
196-
if (newSrc === false) {
197-
this.src = null;
198-
} else {
199-
this.src = newSrc;
200-
}
201-
}
177+
this.dst = this.src!; // src is guaranteed to be set at this point
202178

203-
if (this.src === null) {
204-
console.warn(
205-
`TransportShipExecution: retreating but no src found for new attacker`,
206-
);
207-
this.attacker.addTroops(this.boat.troops());
208-
this.boat.delete(false);
209-
this.active = false;
210-
return;
211-
} else {
212-
this.dst = this.src;
213-
214-
if (this.boat.targetTile() !== this.dst) {
215-
this.boat.setTargetTile(this.dst);
216-
}
179+
if (this.boat.targetTile() !== this.dst) {
180+
this.boat.setTargetTile(this.dst);
217181
}
218182
}
219183

src/core/execution/WarshipExecution.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export class WarshipExecution implements Execution {
5555
this.warship.delete();
5656
return;
5757
}
58+
if (this.warship.owner().isDisconnected()) {
59+
this.warship.delete();
60+
return;
61+
}
5862

5963
const hasPort = this.warship.owner().unitCount(UnitType.Port) > 0;
6064
if (hasPort) {
@@ -89,7 +93,7 @@ export class WarshipExecution implements Execution {
8993
if (
9094
unit.owner() === this.warship.owner() ||
9195
unit === this.warship ||
92-
unit.owner().isFriendly(this.warship.owner(), true) ||
96+
unit.owner().isFriendly(this.warship.owner()) ||
9397
this.alreadySentShell.has(unit)
9498
) {
9599
continue;

src/core/game/Game.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export interface Player {
587587
decayRelations(): void;
588588
isOnSameTeam(other: Player): boolean;
589589
// Either allied or on same team.
590-
isFriendly(other: Player, treatAFKFriendly?: boolean): boolean;
590+
isFriendly(other: Player): boolean;
591591
team(): Team | null;
592592
clan(): string | null;
593593
incomingAllianceRequests(): AllianceRequest[];

src/core/game/GameImpl.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -877,20 +877,6 @@ export class GameImpl implements Game {
877877
return this._railNetwork;
878878
}
879879
conquerPlayer(conqueror: Player, conquered: Player) {
880-
if (conquered.isDisconnected() && conqueror.isOnSameTeam(conquered)) {
881-
const ships = conquered
882-
.units()
883-
.filter(
884-
(u) =>
885-
u.type() === UnitType.Warship ||
886-
u.type() === UnitType.TransportShip,
887-
);
888-
889-
for (const ship of ships) {
890-
conqueror.captureUnit(ship);
891-
}
892-
}
893-
894880
const gold = conquered.gold();
895881
this.displayMessage(
896882
`Conquered ${conquered.displayName()} received ${renderNumber(

src/core/game/PlayerImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ export class PlayerImpl implements Player {
784784
return this._team === other.team();
785785
}
786786

787-
isFriendly(other: Player, treatAFKFriendly: boolean = false): boolean {
788-
if (other.isDisconnected() && !treatAFKFriendly) {
787+
isFriendly(other: Player): boolean {
788+
if (other.isDisconnected()) {
789789
return false;
790790
}
791791
return this.isOnSameTeam(other) || this.isAlliedWith(other);

src/core/game/TransportShipUtils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ export function bestShoreDeploymentSource(
148148
if (t === null) return false;
149149

150150
const candidates = candidateShoreTiles(gm, player, t);
151-
if (candidates.length === 0) return false;
152-
153151
const aStar = new MiniAStar(gm, gm.miniMap(), candidates, t, 1_000_000, 1);
154152
const result = aStar.compute();
155153
if (result !== PathFindResultType.Completed) {

0 commit comments

Comments
 (0)