Add frontier balance

This commit is contained in:
Anton Vakhrushev 2020-05-19 09:52:14 +03:00
parent 4c90af31aa
commit 3adabd6785
2 changed files with 49 additions and 26 deletions

View File

@ -120,23 +120,6 @@
<td class="right" v-text="renderGatheringTime(villageState.required.time)"></td>
</tr>
<tr class="required-line">
<td class="right">Баланс очереди:</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.lumber"></resource>
</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.clay"></resource>
</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.iron"></resource>
</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.crop"></resource>
</td>
<td class="right" v-text="renderGatheringTime(villageState.totalRequired.time)"></td>
</tr>
<tr v-for="queueState of villageState.queues" v-if="queueState.active" class="required-line">
<td class="right">{{ queueTitle(queueState.queue) }}:</td>
<td class="right">
@ -154,6 +137,40 @@
<td class="right" v-text="renderGatheringTime(queueState.firstTask.time)"></td>
</tr>
<tr class="required-line">
<td class="right">Баланс фронтира:</td>
<td class="right">
<resource :value="villageState.frontierRequired.balance.lumber"></resource>
</td>
<td class="right">
<resource :value="villageState.frontierRequired.balance.clay"></resource>
</td>
<td class="right">
<resource :value="villageState.frontierRequired.balance.iron"></resource>
</td>
<td class="right">
<resource :value="villageState.frontierRequired.balance.crop"></resource>
</td>
<td class="right" v-text="renderGatheringTime(villageState.frontierRequired.time)"></td>
</tr>
<tr class="required-line">
<td class="right">Баланс очереди:</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.lumber"></resource>
</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.clay"></resource>
</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.iron"></resource>
</td>
<td class="right">
<resource :value="villageState.totalRequired.balance.crop"></resource>
</td>
<td class="right" v-text="renderGatheringTime(villageState.totalRequired.time)"></td>
</tr>
<tr class="commitments-line" v-if="!villageState.commitments.empty()">
<td class="right">Обязательства:</td>
<td class="right">

View File

@ -62,6 +62,10 @@ interface VillageOwnState {
* Required resources for nearest task
*/
required: ResourceLineState;
/**
* Required resources for first tasks in production queues
*/
frontierRequired: ResourceLineState;
/**
* Required resources for all tasks
*/
@ -154,15 +158,15 @@ function createAllProductionQueueStates(villageId: number, storage: VillageStora
return result;
}
// function firstTaskRequirements(villageId: number, scheduler: Scheduler): Resources {
// let result = Resources.zero();
// for (let queue of Object.keys(ProductionQueue)) {
// const tasks = scheduler.getProductionQueueTasks(villageId, queue as ProductionQueue);
// const firstTaskResources = tasks.filter(() => true).reduce(taskResourceReducer, Resources.zero());
// result = result.add(firstTaskResources);
// }
// return result;
// }
function calcFrontierResources(villageId: number, scheduler: Scheduler): Resources {
let result = Resources.zero();
for (let queue of ProductionQueueTypes) {
const tasks = scheduler.getProductionQueueTasks(villageId, queue);
const firstTaskResources = tasks.slice(0, 1).reduce(taskResourceReducer, Resources.zero());
result = result.add(firstTaskResources);
}
return result;
}
function createVillageOwnState(village: Village, scheduler: Scheduler): VillageOwnState {
const storage = new VillageStorage(village.id);
@ -171,6 +175,7 @@ function createVillageOwnState(village: Village, scheduler: Scheduler): VillageO
const performance = storage.getResourcesPerformance();
const buildQueueInfo = storage.getBuildingQueueInfo();
const requiredResources = scheduler.getVillageRequiredResources(village.id);
const frontierResources = calcFrontierResources(village.id, scheduler);
const totalRequiredResources = scheduler.getTotalVillageRequiredResources(village.id);
return {
@ -180,6 +185,7 @@ function createVillageOwnState(village: Village, scheduler: Scheduler): VillageO
performance,
storage: calcStorageBalance(resources, Resources.fromStorage(resourceStorage), performance),
required: calcResourceBalance(requiredResources, resources, performance),
frontierRequired: calcResourceBalance(frontierResources, resources, performance),
totalRequired: calcResourceBalance(totalRequiredResources, resources, performance),
buildRemainingSeconds: buildQueueInfo.seconds,
incomingResources: calcIncomingResources(storage),