Add warehouses to cap food storage
authorxangelo <git@xangelo.ca>
Wed, 25 May 2022 13:09:36 +0000 (09:09 -0400)
committerxangelo <git@xangelo.ca>
Wed, 25 May 2022 13:09:36 +0000 (09:09 -0400)
src/render/kingdom-overview.ts
src/repository/city.ts

index 2712e7643ae4cbdab9545df22863adf16e0d469e..b019910066f1b203c74867d1e294415f0cab1483 100644 (file)
@@ -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
        </tr>
        <tr>
                <th>Food</th>
-               <td>${city.food.toLocaleString()} (<span class="rate-of-change ${foodRateOfChange < 0 ? 'danger-text' : 'success-text'}">${foodRateOfChange.toLocaleString()}</span>)</td>
+               <td>
+    ${city.food.toLocaleString()} (<span class="rate-of-change ${foodRateOfChange < 0 ? 'danger-text' : 'success-text'}">${foodRateOfChange.toLocaleString()}</span>) @ ${percent(city.food, city.warehouses, 100)}% Warehouse utilization
+    </td>
        </tr>
        </table>
        </div>
index d54a55c1aae2067998cf3e1d18134e54cbefb280..28af69a252f387b1f77610f5751163a76e51a7a5 100644 (file)
@@ -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<City> {
             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<number> {
       // eventually we should supply the warehouse formula 
       // to calculate the max amount of food created per tick