From 8b2459a68101ffc9c256ce73ade44a104618d116 Mon Sep 17 00:00:00 2001 From: xangelo Date: Wed, 25 May 2022 09:09:36 -0400 Subject: [PATCH] Add warehouses to cap food storage --- src/render/kingdom-overview.ts | 13 ++++++++++++- src/repository/city.ts | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/render/kingdom-overview.ts b/src/render/kingdom-overview.ts index 2712e76..b019910 100644 --- a/src/render/kingdom-overview.ts +++ b/src/render/kingdom-overview.ts @@ -2,6 +2,15 @@ import { Account } from "../repository/accounts"; import { CityWithLocation, CityRepository } from "../repository/city"; import * as _ from 'lodash'; +function percent(curr: number, max: number, cap?: number): number { + const val = Math.ceil((curr/max) * 100); + if(cap && val > cap) { + return cap; + } + + return val; +} + type Usage = { foodUsagePerTick: number; foodProductionPerTick: number; @@ -56,7 +65,9 @@ export function renderKingomOverview(city: CityWithLocation & Usage, account: Ac Food - ${city.food.toLocaleString()} (${foodRateOfChange.toLocaleString()}) + + ${city.food.toLocaleString()} (${foodRateOfChange.toLocaleString()}) @ ${percent(city.food, city.warehouses, 100)}% Warehouse utilization + diff --git a/src/repository/city.ts b/src/repository/city.ts index d54a55c..28af69a 100644 --- a/src/repository/city.ts +++ b/src/repository/city.ts @@ -28,6 +28,7 @@ export type City = { sp_defenders: number; homes: number; farms: number; + warehouses: number; barracks: number; special_attacker_trainer: number; special_defender_trainer: number; @@ -74,7 +75,8 @@ export class CityRepository extends Repository { sp_attackers: 0, sp_defenders: 0, homes: 20, - farms: 0, + farms: 5, + warehouses: 5, barracks: 0, special_attacker_trainer: 0, special_defender_trainer: 0, @@ -324,6 +326,10 @@ where l.sector_id = ?`, [sector_id]); return city.homes * 25; } + maxFood(city: City): number { + return city.warehouses * 250; + } + async foodProductionPerTick(city: City): Promise { // eventually we should supply the warehouse formula // to calculate the max amount of food created per tick -- 2.25.1