diff --git a/src/app/station/components/station-calculator.model.ts b/src/app/station/components/station-calculator.model.ts index 0f8fb40..4a54376 100644 --- a/src/app/station/components/station-calculator.model.ts +++ b/src/app/station/components/station-calculator.model.ts @@ -16,6 +16,7 @@ export interface StationResourceItemModel { efficiency: number; name: string; total: number; + type: String; } export interface StationResourceModel { @@ -37,6 +38,7 @@ export interface WareProductionData { efficiency: number; name: string; total: number; + type: String; } export interface StationProduction { @@ -150,10 +152,11 @@ export class ResourceCalculator { return { value: totalWorkforce, capacity: workforce }; } - static calculate(modules: StationModuleModel[], sunlight: number) { + static calculate(modules: StationModuleModel[], sunlight: number, partialWorkforce: number) { let work = this.calculateWorkforce(modules); - let multiplier = (work.capacity == 0 || work.value == 0) ? 0 : (work.capacity / work.value); + let multiplier = (work.capacity == 0 || work.value == 0) ? 0 : (partialWorkforce / work.value); + if (multiplier > 1) { multiplier = 1; } @@ -162,14 +165,26 @@ export class ResourceCalculator { if (modules.length > 0) { data = modules .map(x => { + let modifier = 1 + if(x.module?.type === "Habitation") { + let capacity = x.module.workForce.capacity * x.count + if(partialWorkforce >= capacity) { + partialWorkforce -= capacity + } else { + modifier = partialWorkforce / capacity + partialWorkforce = 0 + } + } + const values: StationResourceItemModel[] = x.needs .map(y => ({ ware: y.ware, count: x.count, amount: -y.amount, - efficiency: 100, + efficiency: modifier * 100, name: x.module.name, - total: x.count * -y.amount + total: x.count * -y.amount * modifier, + type: x.module.type }) ); @@ -194,7 +209,8 @@ export class ResourceCalculator { amount: production.amount, efficiency: efficiency * 100, name: x.module.name, - total: x.count * production.amount * efficiency + total: x.count * production.amount * efficiency, + type: x.module.type }); } } diff --git a/src/app/station/components/station-modules.component.ts b/src/app/station/components/station-modules.component.ts index 29ec9cf..ab10d2b 100644 --- a/src/app/station/components/station-modules.component.ts +++ b/src/app/station/components/station-modules.component.ts @@ -5,6 +5,7 @@ import { StationModule } from '../../shared/services/model/model'; import { ModuleService } from '../../shared/services/module.service'; import { WareService } from '../../shared/services/ware.service'; import { RECYCLING_MODULES, ResourceCalculator, StationModuleModel, StationResourceModel, WareGroupModel } from './station-calculator.model'; +import { StationSummaryService } from './station-summary/services/station-summary.service'; @Component({ selector: 'app-station-modules', @@ -23,7 +24,7 @@ export class StationModulesComponent implements OnInit { @Input() sunlight = 100; - constructor(private moduleService: ModuleService, private wareService: WareService) { + constructor(private moduleService: ModuleService, private wareService: WareService, private stationSummaryService: StationSummaryService) { } ngOnInit(): void { @@ -83,7 +84,8 @@ export class StationModulesComponent implements OnInit { } while (true) { - const resources: StationResourceModel[] = ResourceCalculator.calculate(this.modules, this.sunlight); + + const resources: StationResourceModel[] = ResourceCalculator.calculate(this.modules, this.sunlight, this.stationSummaryService.$partialWorkforce); let didChange = false; const modules = this.modules; diff --git a/src/app/station/components/station-resources/station-resources.component.html b/src/app/station/components/station-resources/station-resources.component.html index f2dc314..def1bf0 100644 --- a/src/app/station/components/station-resources/station-resources.component.html +++ b/src/app/station/components/station-resources/station-resources.component.html @@ -23,6 +23,9 @@ at {{ moduleRes.efficiency | number: '1.0-0' }}% efficiency + + at {{ moduleRes.efficiency | number: '1.0-0' }}% capacity + {{ (moduleRes.total) | number:'1.0-0' }} diff --git a/src/app/station/components/station-resources/station-resources.component.ts b/src/app/station/components/station-resources/station-resources.component.ts index c983920..0b42f76 100644 --- a/src/app/station/components/station-resources/station-resources.component.ts +++ b/src/app/station/components/station-resources/station-resources.component.ts @@ -73,7 +73,7 @@ export class StationResourcesComponent implements OnChanges, OnDestroy { this.partialWorkforce = workforce; } - this.resources = ResourceCalculator.calculate(this.modules, this.sunlight); + this.resources = ResourceCalculator.calculate(this.modules, this.sunlight, this.partialWorkforce); this.resources.forEach((x) => { x.expanded = this.expandState[x.items[0].ware.id]; }); diff --git a/src/app/station/components/station-summary/station-summary.component.ts b/src/app/station/components/station-summary/station-summary.component.ts index d64c990..1bc20c8 100644 --- a/src/app/station/components/station-summary/station-summary.component.ts +++ b/src/app/station/components/station-summary/station-summary.component.ts @@ -112,13 +112,21 @@ export class StationSummaryComponent implements OnChanges { } return acc; }, 0); - if (this.totalWorkforceCapacity != workforce) { + + const workforceNeeded = this.modules.reduce((acc, item) => { + if (item.module && item.module.workForce && item.module.workForce.max) { + return acc + item.count * item.module.workForce.max; + } + return acc; + }, 0); + + if (this.totalWorkforceCapacity != workforce || this.partialWorkforce != workforceNeeded) { this.totalWorkforceCapacity = workforce; - this.partialWorkforce = workforce; + this.partialWorkforce = workforceNeeded; } this.stationSummaryService.setPartialWorkforce(this.partialWorkforce); - const resources = ResourceCalculator.calculate(this.modules, this.sunlight); + const resources = ResourceCalculator.calculate(this.modules, this.sunlight, this.partialWorkforce); resources.sort((a, b) => this.wareService.compareWares(a.ware, b.ware)); resources.forEach((x) => {