Merge pull request #71 from mtpauly/resource-pass-plant-check
This commit is contained in:
commit
abdcd7354a
7 changed files with 62 additions and 14 deletions
2
.github/workflows/engine-publish.yml
vendored
2
.github/workflows/engine-publish.yml
vendored
|
|
@ -8,7 +8,7 @@ on:
|
|||
default: patch
|
||||
|
||||
env:
|
||||
node_version: 22
|
||||
node_version: 14
|
||||
|
||||
defaults:
|
||||
run:
|
||||
|
|
|
|||
6
.github/workflows/engine-test.yml
vendored
6
.github/workflows/engine-test.yml
vendored
|
|
@ -20,10 +20,8 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12'
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
node-version: '14'
|
||||
- run: corepack enable
|
||||
- run: pnpm install
|
||||
- run: pnpm build
|
||||
- run: pnpm lint
|
||||
|
|
|
|||
6
.github/workflows/prettier.yml
vendored
6
.github/workflows/prettier.yml
vendored
|
|
@ -6,9 +6,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
version: 5.17.1
|
||||
node-version: '22'
|
||||
- run: corepack enable
|
||||
- run: pnpm install
|
||||
- run: pnpm run prettier-check
|
||||
|
|
|
|||
2
.github/workflows/viewer-publish.yml
vendored
2
.github/workflows/viewer-publish.yml
vendored
|
|
@ -8,7 +8,7 @@ on:
|
|||
default: patch
|
||||
|
||||
env:
|
||||
node_version: 22
|
||||
node_version: 14
|
||||
|
||||
defaults:
|
||||
run:
|
||||
|
|
|
|||
4
.github/workflows/viewer-test.yml
vendored
4
.github/workflows/viewer-test.yml
vendored
|
|
@ -23,9 +23,7 @@ jobs:
|
|||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
- uses: pnpm/action-setup@v1.2.1
|
||||
with:
|
||||
version: 5.17.1
|
||||
- run: corepack enable
|
||||
- run: pnpm install
|
||||
# - run: pnpm lint
|
||||
# - run: pnpm test
|
||||
|
|
|
|||
3
.prettierignore
Normal file
3
.prettierignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pnpm-lock.yaml
|
||||
viewer/pnpm-lock.yaml
|
||||
engine/pnpm-lock.yaml
|
||||
|
|
@ -358,7 +358,7 @@
|
|||
<script lang="ts">
|
||||
import { Vue, Component, Prop, Watch, Provide, ProvideReactive, Ref } from 'vue-property-decorator';
|
||||
import { MoveName, ended, playersSortedByScore, reconstructState } from 'powergrid-engine';
|
||||
import type { GameState } from 'powergrid-engine';
|
||||
import type { GameState, Player } from 'powergrid-engine';
|
||||
import { EventEmitter } from 'events';
|
||||
import { UIData, Preferences } from '../types/ui-data';
|
||||
import { Card, House, Coal, Oil, Garbage, Uranium } from './pieces';
|
||||
|
|
@ -559,7 +559,14 @@ export default class Game extends Vue {
|
|||
this.confirmMessage = 'Are you sure you want to pass? You have unused power plants!';
|
||||
this.confirmVisible = true;
|
||||
return;
|
||||
} else if (
|
||||
}
|
||||
if (this.G.phase == Phase.Resources && !this.canPowerAllPlants(player)) {
|
||||
this.confirmMessage = 'Are you sure you want to skip buying resources without enough to power all your plants?';
|
||||
this.confirmVisible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.G.phase != Phase.Bureaucracy ||
|
||||
player.powerPlantsNotUsed.length == player.powerPlants.length
|
||||
) {
|
||||
|
|
@ -928,6 +935,48 @@ export default class Game extends Vue {
|
|||
}
|
||||
}
|
||||
|
||||
canPowerAllPlants(player: Player): boolean {
|
||||
// Calculate total resource requirements for all power plants
|
||||
let coalUsed = 0;
|
||||
let oilUsed = 0;
|
||||
let garbageUsed = 0;
|
||||
let uraniumUsed = 0;
|
||||
let hybridUsed = 0;
|
||||
for (const powerPlant of player.powerPlants) {
|
||||
switch (powerPlant.type) {
|
||||
case PowerPlantType.Coal:
|
||||
coalUsed += powerPlant.cost;
|
||||
break;
|
||||
case PowerPlantType.Oil:
|
||||
oilUsed += powerPlant.cost;
|
||||
break;
|
||||
case PowerPlantType.Garbage:
|
||||
garbageUsed += powerPlant.cost;
|
||||
break;
|
||||
case PowerPlantType.Uranium:
|
||||
uraniumUsed += powerPlant.cost;
|
||||
break;
|
||||
case PowerPlantType.Hybrid:
|
||||
hybridUsed += powerPlant.cost;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if player has enough resources, accounting for hybrid plants which can use either coal or oil
|
||||
if (coalUsed > player.coalLeft ||
|
||||
oilUsed > player.oilLeft ||
|
||||
garbageUsed > player.garbageLeft ||
|
||||
uraniumUsed > player.uraniumLeft) {
|
||||
return false;
|
||||
}
|
||||
const remainingCoal = player.coalLeft - coalUsed;
|
||||
const remainingOil = player.oilLeft - oilUsed;
|
||||
if (hybridUsed > remainingCoal + remainingOil) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
toggleSound() {
|
||||
const newSound = !this.preferences.sound;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue