ability to cancel construction and have a portion of the funds returned
[browser-rts.git] / src / render / kingdom-overview.ts
index c035f7cbcec60921063e74f6d41c164402965f9d..2e787d6bdf82daaebe49e27d11d21ef142463366 100644 (file)
@@ -1,7 +1,16 @@
 import { Account } from "../repository/accounts";
-import { CityWithLocation } from "../repository/city";
+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;
@@ -9,6 +18,8 @@ type Usage = {
   energyProductionPerTick: number;
 }
 
+const cityRepo = new CityRepository();
+
 export function renderKingomOverview(city: CityWithLocation & Usage, account: Account): string {
   const foodRateOfChange = city.foodProductionPerTick - city.foodUsagePerTick;
   const energyRateOfChange = city.energyProductionPerTick - city.energyUsagePerTick;
@@ -20,7 +31,7 @@ export function renderKingomOverview(city: CityWithLocation & Usage, account: Ac
                <th>Captain</th>
                <td>${account.username}</td>
                <th>Population</th>
-               <td>${city.population.toLocaleString()}/${_.max([city.farms * 70, city.population])}</td>
+               <td>${city.population.toLocaleString()}/${cityRepo.maxPopulation(city)}</td>
        </tr>
        <tr>
                <th>Space</th>
@@ -42,19 +53,24 @@ export function renderKingomOverview(city: CityWithLocation & Usage, account: Ac
        </tr>
        <tr>
                <th>Alloys</th>
-               <td>${city.alloys.toLocaleString()}</td>
+               <td>${city.alloys.toLocaleString()} @ ${percent(city.alloys, cityRepo.maxAlloy(city), 100)} % Ore Refiniery Utilization</td>
                <th>Special Attackers</th>
                <td>${city.sp_attackers.toLocaleString()}</td>
        </tr>
        <tr>
                <th>Energy</th>
-               <td>${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)</td>
+               <td>
+    ${city.energy.toLocaleString()} (<span class="rate-of-change ${energyRateOfChange < 0 ? 'danger-text' : 'success-text'}">${energyRateOfChange.toLocaleString()}</span>)
+    @ ${percent(city.energy, cityRepo.maxEnergy(city), 100)}% Accumulator Utilization
+    </td>
                <th>Special Defenders</th>
                <td>${city.sp_defenders.toLocaleString()}</td>
        </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, cityRepo.maxFood(city), 100)}% Warehouse utilization
+    </td>
        </tr>
        </table>
        </div>