Add warehouses to cap food storage
[browser-rts.git] / src / render / kingdom-overview.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>