Skip to content

Commit

Permalink
Homeworlds: Finally fix catastrophes
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Nov 11, 2023
1 parent 25d0e1f commit 201ef8e
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/games/homeworlds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,6 @@ export class HomeworldsGame extends GameBase {
// this normally happens during regular moves, but we have to also do it now that we're eliminating systems
const empties = this.systems.filter(s => s.ships.length === 0);
for (const sys of empties) {
for (const star of sys.stars) {
this.stash.add(...star);
}
this.delSystem(sys)
}

Expand Down Expand Up @@ -1472,9 +1469,6 @@ export class HomeworldsGame extends GameBase {
this.eliminated.push(oldSystem.owner!);
this.results.push({"type": "eliminated", "who": this.seat2name(oldSystem.owner)});
}
for (const star of oldSystem.stars) {
this.stash.add(...star);
}
this.delSystem(oldSystem);
}
// Instantiate system
Expand Down Expand Up @@ -1652,9 +1646,6 @@ export class HomeworldsGame extends GameBase {
this.eliminated.push(oldSystem.owner!);
this.results.push({"type": "eliminated", "who": this.seat2name(oldSystem.owner)});
}
for (const star of oldSystem.stars) {
this.stash.add(...star);
}
this.delSystem(oldSystem);
}
// Dock the ship in the new system
Expand Down Expand Up @@ -2158,9 +2149,6 @@ export class HomeworldsGame extends GameBase {
this.eliminated.push(system.owner!);
this.results.push({"type": "eliminated", "who": this.seat2name(system.owner)});
}
for (const star of system.stars) {
this.stash.add(...star);
}
this.delSystem(system);
}

Expand Down Expand Up @@ -2254,9 +2242,6 @@ export class HomeworldsGame extends GameBase {
this.eliminated.push(system.owner!);
this.results.push({"type": "eliminated", "who": this.seat2name(system.owner)});
}
for (const star of system.stars) {
this.stash.add(...star);
}
this.delSystem(system);
}

Expand Down Expand Up @@ -2421,6 +2406,16 @@ export class HomeworldsGame extends GameBase {
if (idx < 0) {
throw new Error(`Could not destroy the system '${sys.name}' because it does not appear to exist.`);
}
if (sys.stars.length > 0) {
for (const star of sys.stars) {
this.stash.add(...star);
}
}
if (sys.ships.length > 0) {
for (const ship of sys.ships) {
this.stash.add(ship.colour, ship.size);
}
}
this.systems.splice(idx, 1);
return this;
}
Expand Down

0 comments on commit 201ef8e

Please sign in to comment.